Repository navigation
Add dependency-free TypeScript token providers and client adapters - #519
Merged
Merged
Conversation
Preserve legacy HTTP factories while adding opt-in token providers and configured Chat Completions/Responses clients with multimodal prompts and shared metadata/filtering behavior. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues remain for the TypeScript authentication and configured-client integration changes.
No open issues 🎉
What changed in this PR
Adds dependency-free authentication and configured-client integration to TypeScript, complementing the separate Python work without changing Python code.
Changes:
- Adds synchronous/asynchronous bearer-token providers to HTTP factories, resolving tokens for each attempt while preserving existing transport controls.
- Adds caller-owned Chat Completions and Responses client adapters with text/image prompt mapping and shared completion, metadata, and filtering parsing.
- Adds offline regression coverage and documents authentication, client ownership, and error behavior.
| File | Description |
|---|---|
typescript/tests/model.test.mjs |
Tests token providers, client adapters, prompt mapping, errors, and compatibility. |
typescript/test/metadata.test.ts |
Tests usage accounting, filtering, and multimodal context across repair attempts. |
typescript/src/model.ts |
Implements token providers, structural client contracts, adapters, and shared completion parsing. |
typescript/README.md |
Introduces authentication reuse and links to integration examples. |
typescript/metadata.md |
Clarifies metadata accounting for caller-owned clients and HTTP token providers. |
site/src/docs/typescript/basic-usage.md |
Documents integration examples, supported prompts, and control ownership. |
Review effort: Balanced
Cover whitespace, trailing newlines, control characters, non-ASCII values, and valid printable-ASCII boundaries without changing legacy API-key handling. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Apply the Python review's shared event-loop guidance to TypeScript without changing provider invocation or the existing malformed-token guard. Add pending-Promise regressions for all HTTP factory paths. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Tal Zaccai (TalZaccai)
approved these changes
Nov 4, 2026
This was referenced Nov 4, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Add TypeScript parity for the dependency-free authentication/client-injection approach in #516, in a separate branch/worktree. This PR changes only TypeScript and directly related documentation; it does not expand the Python PR.
TokenProvideroption to the OpenAI and Azure HTTP factories. Passundefinedfor the API-key argument to opt in; resolve a raw bearer token for each HTTP attempt, including retries.createOpenAILanguageModelFromClientwith structuralChatCompletionClientandResponsesClientcontracts. Reuse an existing configured client without importing/installing an SDK in TypeChat.Compatibility and ownership
identityvalues are unchanged. API keys and token providers are mutually exclusive.complete, preserving the caller's instance, endpoint/API version, authentication, retries/timeouts, and lifecycle. They do not reconfigure/close the client or add a retry/timeout layer. Client exceptions and cancellation propagate unchanged.responsesmember. SDK response metadata reflects resolved responses visible to TypeChat, not retries hidden inside the supplied SDK.Validation
Using the repository-pinned Node.js 24.22.1:
npm run build- passed.tsc -p test- passed.node --test tests\model.test.mjs out\metadata.test.js out\failure.test.js- 182 passed, including legacy behavior, sync/async providers, per-attempt tokens, malformed bearer strings rejected before dispatch, network limits, both client API shapes, images, ownership, errors/cancellation, filtering, metadata, and translator repair.OpenAI/AzureOpenAIclients - passed. Four mocked calls covered both API shapes, image mapping, rotating Azure bearer tokens, preserved client configuration, and metadata.The SDK used for that independent check was installed only in a separate tool directory; repository tests do not require it. The build, unit, and SDK-mock checks above were offline.
Manual live Azure identity validation (2026-11-03)
Tested commit: 91f3b26.
All four live checks passed against a real identity-configured Azure deployment:
AzureOpenAIclientOpenAIclientReal Entra access-token acquisition and bearer-only request headers were observed; no Azure OpenAI API-key headers were used. All outputs passed TypeChat schema validation on the first model request, and the image results matched the expected color. There were four actual model requests, with no model-request retries or repairs required.
Not exercised: expiry-driven token renewal. These were manual live smoke tests, not additional CI requirements. Private endpoint, deployment, configuration, and credential details are intentionally omitted.
Review follow-up (2026-11-03)
The malformed-token issue reported on the Python PR was already covered by the TS guard in 91f3b26, including trailing-newline/control/non-ASCII regressions across all HTTP factory paths.
5324d14 also applies the shared blocking-provider concern even though TS had no open review threads:
async/a Promise does not offload it.Separate Python follow-ups
These are tracking issues only, not additional Python implementation work in this PR. Related context: #216 and #516. Human review is required; no merge is requested.