Port upstream examples (PR #512) and Azure Managed Identity docs (PR #498)#36
Port upstream examples (PR #512) and Azure Managed Identity docs (PR #498)#36
Conversation
Port upstream scenarios from PR #512 as Clojure examples: - file_attachments.clj: file attachments with :attachments in send options - session_resume.clj: session resume with resume-session - infinite_sessions.clj: infinite sessions with compaction thresholds - lifecycle_hooks.clj: all 6 lifecycle hooks - reasoning_effort.clj: reasoning effort config Port Azure Managed Identity BYOK guide from upstream PR #498: - doc/auth/azure-managed-identity.md with Clojure examples - Updated BYOK limitations to link to workaround - Updated doc/auth/index.md and doc/index.md Updated run-all-examples.sh, examples/README.md, and CHANGELOG.md. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This pull request ports two upstream changes from the Node.js copilot-sdk to the Clojure implementation: 5 new example files demonstrating SDK features (file attachments, session resume, infinite sessions, lifecycle hooks, and reasoning effort), and comprehensive documentation for Azure Managed Identity authentication with BYOK. The changes align with the project's goal of maintaining API parity with the upstream SDK while adapting idiomatically to Clojure.
Changes:
- Added 5 new runnable examples with documentation covering previously undocumented SDK features
- Added Azure Managed Identity authentication guide showing how to use bearer tokens with DefaultAzureCredential
- Updated BYOK documentation to reference the Managed Identity workaround instead of listing it as unsupported
Reviewed changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
examples/file_attachments.clj |
New example demonstrating file attachment feature using :attachments in send options |
examples/session_resume.clj |
New example showing session persistence and resume by ID |
examples/infinite_sessions.clj |
New example demonstrating context compaction with configurable thresholds |
examples/lifecycle_hooks.clj |
New example demonstrating all 6 lifecycle hooks (session start/end, tool use, prompts, errors) |
examples/reasoning_effort.clj |
New example showing :reasoning-effort configuration option |
run-all-examples.sh |
Added 5 new examples to the test script |
examples/README.md |
Added comprehensive documentation for Examples 12-16 with usage instructions and walkthroughs; clarified that script runs 14 examples (1-9, 12-16) |
doc/auth/azure-managed-identity.md |
New guide showing Azure Managed Identity pattern with DefaultAzureCredential and bearer token refresh (contains critical bug with duplicate .getToken call) |
doc/auth/byok.md |
Updated limitations section to reference Managed Identity workaround instead of listing it as unsupported |
doc/auth/index.md |
Added link to Azure Managed Identity guide in Next Steps section |
doc/index.md |
Added Azure Managed Identity guide to authentication documentation links |
CHANGELOG.md |
Added entries for both upstream PRs (#498 and #512) with appropriate upstream sync annotations |
… README wording - Remove duplicate .getToken call in azure-managed-identity.md - Remove explicit destroy! in session_resume.clj (with-client handles cleanup) - Fix example range wording in README.md (1-9 and 12-16, not 1-14) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 12 out of 12 changed files in this pull request and generated 3 comments.
Comments suppressed due to low confidence (2)
examples/lifecycle_hooks.clj:38
- Same issue as above: hook input keys are kebab-cased.
(:toolName data)will be nil; use:tool-name.
:on-post-tool-use
(fn [data _ctx]
(println "✅ Hook: post-tool-use —" (:toolName data))
(record! :on-post-tool-use data))
doc/auth/azure-managed-identity.md:55
- The Azure Identity SDK’s
TokenCredential.getToken(TokenRequestContext)returns a reactiveMono<AccessToken>, not anAccessToken. As written,get-azure-tokenreturns a Mono and(.getToken (get-azure-token))will fail. Block (or otherwise await) the Mono to obtain anAccessToken, then call.getTokenon that value.
(defn get-azure-token
"Obtain a short-lived bearer token from Entra ID."
[]
(let [credential (.build (DefaultAzureCredentialBuilder.))
context (doto (TokenRequestContext.)
(.addScopes (into-array String [cognitive-services-scope])))]
(.getToken credential context)))
(def foundry-url (System/getenv "AZURE_AI_FOUNDRY_RESOURCE_URL"))
(copilot/with-client-session [session
{:model "gpt-4.1"
:provider {:provider-type :openai
:base-url (str foundry-url "/openai/v1/")
:bearer-token (.getToken (get-azure-token))
:wire-api :responses}}]
(println (h/query "Hello from Managed Identity!" :session session)))
…ation - azure-managed-identity.md: .getToken returns Mono<AccessToken>, need .block() then .getToken() to extract the token string - lifecycle_hooks.clj: wire data is normalized to kebab-case, use :tool-name not :toolName Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Fix Maven coordinates in azure-managed-identity.md to use io.github.copilot-community-sdk/copilot-sdk-clojure - Remove unused github.copilot-sdk.helpers require from session_resume.clj - Update README.md bullet to reflect actual cleanup mechanism (with-client Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
BYOK accepts both API keys and bearer tokens, so 'key-based only' was inaccurate. Reword to clarify BYOK uses static credentials you supply but doesn't natively perform identity provider flows. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Summary
Ports two upstream changes to the Clojure SDK:
New examples (upstream PR github/copilot-sdk#512)
5 new Clojure examples covering SDK features that lacked dedicated examples:
file_attachments.clj:attachmentsin send optionssession_resume.cljresume-session+ context verificationinfinite_sessions.cljlifecycle_hooks.cljreasoning_effort.clj"low"/"medium"/"high"/"xhigh")Azure Managed Identity docs (upstream PR github/copilot-sdk#498)
doc/auth/azure-managed-identity.md— shows how to useDefaultAzureCredential(Java Azure Identity SDK) with short-lived bearer tokens for Azure AI Foundry BYOKdoc/auth/byok.mdlimitations to link to the workarounddoc/auth/index.mdanddoc/index.mdOther updates
run-all-examples.sh— added all 5 new examplesexamples/README.md— added Examples 12–16 with usage and walkthroughsCHANGELOG.md— added entries for both upstream PRsValidation
bb validate-docspasses