@tanstack/ai 0.52.3 → 0.53.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/esm/activities/summarize/chat-stream-summarize.js +2 -1
- package/dist/esm/activities/summarize/chat-stream-summarize.js.map +1 -1
- package/dist/esm/byok/define-provider.d.ts +6 -0
- package/dist/esm/byok/define-provider.js +2 -1
- package/dist/esm/byok/define-provider.js.map +1 -1
- package/dist/esm/byok/get-key.d.ts +7 -0
- package/dist/esm/byok/get-key.js +8 -1
- package/dist/esm/byok/get-key.js.map +1 -1
- package/dist/esm/byok/server.d.ts +1 -1
- package/dist/esm/byok/server.js +2 -2
- package/package.json +1 -1
- package/skills/ai-core/adapter-configuration/SKILL.md +13 -12
- package/skills/ai-core/structured-outputs/SKILL.md +1 -0
- package/src/activities/summarize/chat-stream-summarize.ts +2 -0
- package/src/byok/define-provider.ts +7 -0
- package/src/byok/get-key.ts +18 -0
- package/src/byok/server.ts +1 -1
|
@@ -48,7 +48,8 @@ var MAX_TOKENS_KEY_BY_ADAPTER = {
|
|
|
48
48
|
groq: "max_completion_tokens",
|
|
49
49
|
gemini: "maxOutputTokens",
|
|
50
50
|
openrouter: "maxCompletionTokens",
|
|
51
|
-
llmgateway: "max_tokens"
|
|
51
|
+
llmgateway: "max_tokens",
|
|
52
|
+
cloudflare: "max_tokens"
|
|
52
53
|
};
|
|
53
54
|
/**
|
|
54
55
|
* Every flat key any supported provider uses to cap output tokens (plus the
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chat-stream-summarize.js","names":[],"sources":["../../../../src/activities/summarize/chat-stream-summarize.ts"],"sourcesContent":["import { EventType } from '@ag-ui/core'\nimport { toRunErrorPayload } from '../error-payload'\nimport { MAX_TOKENS_KEYS } from '../../utilities/sampling-keys'\nimport { rebuildTokenUsage } from '../../utilities/ag-ui-usage'\nimport type { AdapterYieldChunk } from '../../utilities/adapter-yield-chunk'\nimport { tanstackMetadata } from '../../utilities/merge-metadata'\nimport { normalizeStreamChunk } from '../../utilities/normalize-stream-chunk'\nimport { BaseSummarizeAdapter } from './adapter'\nimport type {\n StreamChunk,\n SummarizationOptions,\n SummarizationResult,\n TextOptions,\n TokenUsage,\n} from '../../types'\n\nfunction consumeSpecSummarizeChunk(\n chunk: StreamChunk,\n state: { summary: string; model: string; usage: TokenUsage },\n): void {\n if (chunk.type === EventType.TEXT_MESSAGE_CONTENT) {\n if (chunk.delta) state.summary += chunk.delta\n return\n }\n\n const tanstack = tanstackMetadata(chunk)\n if (\n (chunk.type === EventType.RUN_STARTED ||\n chunk.type === EventType.RUN_FINISHED ||\n chunk.type === EventType.TEXT_MESSAGE_START) &&\n typeof tanstack?.model === 'string'\n ) {\n state.model = tanstack.model\n }\n\n if (chunk.type === EventType.RUN_FINISHED) {\n const rebuilt = rebuildTokenUsage(chunk.usage, tanstack?.usage)\n if (rebuilt) state.usage = rebuilt\n }\n}\n\nfunction throwRunError(\n chunk: Extract<StreamChunk, { type: 'RUN_ERROR' }>,\n): never {\n const message =\n typeof chunk.message === 'string' && chunk.message.length > 0\n ? chunk.message\n : 'Summarization failed'\n const err = new Error(message)\n if (typeof chunk.code === 'string') {\n ;(err as Error & { code?: string }).code = chunk.code\n }\n throw err\n}\n\n/**\n * Minimal contract for a text adapter that supports `chatStream`. Lets\n * `ChatStreamSummarizeAdapter` work with any text adapter without coupling\n * to a specific implementation.\n *\n * The provider-options shape is intentionally `any` here — the wrapper only\n * forwards `modelOptions` straight through, so a text adapter with a richer\n * per-model options type (e.g. `ResolveProviderOptions<TModel>`) is still\n * acceptable. Summarize-level type safety is enforced via\n * `SummarizationOptions<TProviderOptions>` on the wrapper itself.\n */\nexport interface ChatStreamCapable {\n chatStream: (options: TextOptions<any>) => AsyncIterable<AdapterYieldChunk>\n}\n\n/**\n * Provider-native max-output-tokens key per summarize-adapter `name`. summarize\n * is provider-agnostic and forwards `modelOptions` opaquely to the wrapped text\n * adapter, so `maxLength` must be written under the exact key the underlying\n * provider reads — no adapter reads a generic `maxTokens`. Ollama is the one\n * exception: it nests sampling under `options`, so it has no entry here and is\n * handled as a special nested case in `applyMaxLength`/`applyDefaultTemperature`.\n *\n * Keep in sync with each adapter's wire mapping:\n * - OpenAI (Responses): `max_output_tokens`\n * - Anthropic / Grok: `max_tokens`\n * - Groq: `max_completion_tokens`\n * - Gemini: `maxOutputTokens`\n * - OpenRouter: `maxCompletionTokens`\n * - LLM Gateway: `max_tokens`\n * - Ollama: nested `options.num_predict` (no entry — see `applyMaxLength`)\n */\nconst MAX_TOKENS_KEY_BY_ADAPTER: Record<string, string> = {\n openai: 'max_output_tokens',\n anthropic: 'max_tokens',\n grok: 'max_tokens',\n groq: 'max_completion_tokens',\n gemini: 'maxOutputTokens',\n openrouter: 'maxCompletionTokens',\n // LLM Gateway exposes an OpenAI-compatible Chat Completions surface whose\n // only output cap is `max_tokens` — it does not read `max_completion_tokens`.\n llmgateway: 'max_tokens',\n}\n\n/**\n * Every flat key any supported provider uses to cap output tokens (plus the\n * generic `maxTokens` spelling no adapter reads). Used to detect a\n * caller-supplied token limit so the summarize default never overrides an\n * explicit caller value. Shared with the OTel middleware via\n * `MAX_TOKENS_KEYS` so the two spelling sets cannot drift.\n */\nconst KNOWN_MAX_TOKENS_KEYS = MAX_TOKENS_KEYS\n\n/**\n * Whether `applyMaxLength` knows how to place a token limit for this adapter\n * `name` (either the nested Ollama shape or a flat provider-native key).\n * Used to surface a warning when `maxLength` would otherwise be silently\n * dropped for an unrecognised adapter name.\n */\nfunction isKnownMaxTokensAdapter(adapterName: string): boolean {\n return (\n adapterName === 'ollama' ||\n MAX_TOKENS_KEY_BY_ADAPTER[adapterName] !== undefined\n )\n}\n\n/**\n * Apply the low-temperature summarize default to a working copy of the\n * caller's `modelOptions`, placed where the wrapped provider actually reads\n * it (nested under `options` for Ollama, flat otherwise). The caller always\n * wins: if they already set `temperature` in that location, it is untouched.\n */\nfunction applyDefaultTemperature(\n adapterName: string,\n temperature: number,\n modelOptions: Record<string, unknown>,\n): Record<string, unknown> {\n const merged: Record<string, unknown> = { ...modelOptions }\n\n if (adapterName === 'ollama') {\n const existing =\n merged.options && typeof merged.options === 'object'\n ? (merged.options as Record<string, unknown>)\n : undefined\n if (existing && 'temperature' in existing) return merged\n merged.options = { temperature, ...existing }\n return merged\n }\n\n if ('temperature' in merged) return merged\n merged.temperature = temperature\n return merged\n}\n\n/**\n * Resolve `maxLength` to the provider-native max-output-tokens key for the\n * given summarize-adapter `name` (this wrapper's OWN `name`, not the wrapped\n * text adapter's) and merge it into a working copy of the caller's\n * `modelOptions`. The caller always wins: if they already set any recognised\n * token-limit key (flat or, for Ollama, nested `options.num_predict`), the\n * default is left untouched. Unknown/unrecognised adapter names fall back to\n * NOT setting a token key (the prompt hint still asks the model to stay under\n * `maxLength`) rather than writing a dead key no provider reads.\n *\n * Caveat (intentional): \"caller wins\" keys off ANY recognised spelling in\n * `KNOWN_MAX_TOKENS_KEYS`, but only the adapter's native key is read on the\n * wire. So a caller who sets a NON-native spelling for this provider — e.g.\n * `maxTokens`, or Anthropic's `max_tokens` against an OpenAI adapter — suppresses\n * the summarize default WITHOUT getting their own value applied either: neither\n * cap reaches the wire. This favours never clobbering a migration leftover over\n * guaranteeing a cap; the prompt-level hint still asks the model to stay under\n * `maxLength`. Rename the key to the provider-native spelling to forward it.\n */\nfunction applyMaxLength(\n adapterName: string,\n maxLength: number,\n modelOptions: Record<string, unknown>,\n): Record<string, unknown> {\n const merged: Record<string, unknown> = { ...modelOptions }\n\n if (adapterName === 'ollama') {\n // Honor a caller-set limit in either shape: a recognised flat key (e.g.\n // left over from a migration) or the nested `options.num_predict`.\n const callerSetFlatLimit = KNOWN_MAX_TOKENS_KEYS.some(\n (k) => typeof merged[k] === 'number',\n )\n const existing =\n merged.options && typeof merged.options === 'object'\n ? (merged.options as Record<string, unknown>)\n : undefined\n if (\n callerSetFlatLimit ||\n (existing && typeof existing.num_predict === 'number')\n ) {\n return merged\n }\n merged.options = { num_predict: maxLength, ...existing }\n return merged\n }\n\n const key = MAX_TOKENS_KEY_BY_ADAPTER[adapterName]\n if (key === undefined) return merged\n\n const callerSetLimit = KNOWN_MAX_TOKENS_KEYS.some(\n (k) => typeof merged[k] === 'number',\n )\n if (callerSetLimit) return merged\n\n merged[key] = maxLength\n return merged\n}\n\n/**\n * Extract the per-model `modelOptions` type a text adapter accepts. Used by\n * provider summarize factories so their `modelOptions` IntelliSense matches\n * what the underlying text adapter actually understands.\n */\nexport type InferTextProviderOptions<TAdapter> = TAdapter extends {\n '~types': { providerOptions: infer P }\n}\n ? P extends object\n ? P\n : object\n : object\n\n/**\n * Summarize adapter that wraps any `ChatStreamCapable` text adapter and\n * prompts it for summarization. Not tied to any wire format.\n */\nexport class ChatStreamSummarizeAdapter<\n TModel extends string,\n TProviderOptions extends object = Record<string, unknown>,\n> extends BaseSummarizeAdapter<TModel, TProviderOptions> {\n readonly name: string\n\n private readonly textAdapter: ChatStreamCapable\n\n constructor(\n textAdapter: ChatStreamCapable,\n model: TModel,\n name: string = 'chat-stream-summarize',\n ) {\n super({}, model)\n this.name = name\n this.textAdapter = textAdapter\n }\n\n async summarize(\n options: SummarizationOptions<TProviderOptions>,\n ): Promise<SummarizationResult> {\n const systemPrompt = this.buildSummarizationPrompt(options)\n\n const id = this.generateId()\n const state = {\n summary: '',\n model: options.model,\n usage: { promptTokens: 0, completionTokens: 0, totalTokens: 0 },\n }\n\n options.logger.request(\n `activity=summarize provider=${this.name} model=${options.model} text-length=${options.text.length} maxLength=${options.maxLength ?? 'unset'}`,\n { provider: this.name, model: options.model },\n )\n\n try {\n for await (const raw of this.textAdapter.chatStream(\n this.buildTextOptions(options, systemPrompt),\n )) {\n for (const chunk of normalizeStreamChunk(raw as AdapterYieldChunk)) {\n // Surface failures: the underlying chatStream emits RUN_ERROR instead\n // of throwing, so without this branch summarize() would return an\n // empty summary and pretend a failed run succeeded.\n if (chunk.type === EventType.RUN_ERROR) throwRunError(chunk)\n consumeSpecSummarizeChunk(chunk, state)\n }\n }\n } catch (error: unknown) {\n // Narrow before logging: raw SDK errors can carry request metadata\n // (including auth headers) which we must never surface to user loggers.\n options.logger.errors(`${this.name}.summarize fatal`, {\n error: toRunErrorPayload(error, `${this.name}.summarize failed`),\n source: `${this.name}.summarize`,\n })\n throw error\n }\n\n return {\n id,\n model: state.model,\n summary: state.summary,\n usage: state.usage,\n }\n }\n\n override async *summarizeStream(\n options: SummarizationOptions<TProviderOptions>,\n ): AsyncIterable<StreamChunk> {\n const systemPrompt = this.buildSummarizationPrompt(options)\n\n options.logger.request(\n `activity=summarizeStream provider=${this.name} model=${options.model} text-length=${options.text.length} maxLength=${options.maxLength ?? 'unset'}`,\n { provider: this.name, model: options.model },\n )\n\n const id = this.generateId()\n const state = {\n summary: '',\n model: options.model,\n usage: {\n promptTokens: 0,\n completionTokens: 0,\n totalTokens: 0,\n } satisfies SummarizationResult['usage'],\n }\n\n try {\n for await (const raw of this.textAdapter.chatStream(\n this.buildTextOptions(options, systemPrompt),\n )) {\n for (const chunk of normalizeStreamChunk(raw as AdapterYieldChunk)) {\n // Accumulate the same way `summarize()` does so consumers see deltas\n // AND the terminal `generation:result` event below carries the same\n // final summary that non-streaming returns.\n consumeSpecSummarizeChunk(chunk, state)\n\n // Emit the GenerationClient-shaped result event just before the\n // terminal RUN_FINISHED so subscribers (useSummarize) populate\n // `result` before flipping `status` to success.\n if (chunk.type === EventType.RUN_FINISHED) {\n yield {\n type: EventType.CUSTOM,\n name: 'generation:result',\n value: {\n id,\n model: state.model,\n summary: state.summary,\n usage: state.usage,\n } satisfies SummarizationResult,\n timestamp: Date.now(),\n }\n }\n\n yield chunk\n }\n }\n } catch (error: unknown) {\n options.logger.errors(`${this.name}.summarizeStream fatal`, {\n error: toRunErrorPayload(error, `${this.name}.summarizeStream failed`),\n source: `${this.name}.summarizeStream`,\n })\n throw error\n }\n }\n\n /**\n * Build the TextOptions passed to the underlying chatStream. Provider\n * `modelOptions` from the summarize call are forwarded as-is so knobs like\n * Anthropic cache headers, Gemini safety settings, or Ollama tuning params\n * still reach the wire layer.\n */\n protected buildTextOptions(\n options: SummarizationOptions<TProviderOptions>,\n systemPrompt: string,\n ): TextOptions<TProviderOptions> {\n // Sampling knobs now live in provider-native `modelOptions`. Apply the\n // low-temperature default where the wrapped provider actually reads it\n // (nested under `options` for Ollama, flat otherwise) so callers can still\n // override it. Resolving the placement from this summarize adapter's OWN\n // `name` keeps the default off the wire correctly per provider — a flat\n // `temperature` would be silently dropped by Ollama while still showing up\n // in OTel.\n let working: Record<string, unknown> = {\n ...(options.modelOptions as Record<string, unknown> | undefined),\n }\n working = applyDefaultTemperature(this.name, 0.3, working)\n // `maxLength` must reach the wire under the provider-native token key (it\n // differs per provider, and no adapter reads a generic `maxTokens`).\n // Resolve it from this summarize adapter's `name` (the constructor arg,\n // not the wrapped text adapter's name), never overriding a caller-supplied\n // token limit.\n if (options.maxLength !== undefined) {\n if (!isKnownMaxTokensAdapter(this.name)) {\n options.logger.warn(\n `summarize: maxLength=${options.maxLength} could not be mapped to a provider token key for adapter name \"${this.name}\" — it was dropped from modelOptions (the prompt still asks the model to stay under it). Construct ChatStreamSummarizeAdapter with a recognised provider name to forward the cap.`,\n { provider: this.name },\n )\n }\n working = applyMaxLength(this.name, options.maxLength, working)\n }\n const modelOptions = working as TProviderOptions\n\n return {\n model: options.model,\n messages: [{ role: 'user', content: options.text }],\n systemPrompts: [systemPrompt],\n modelOptions,\n logger: options.logger,\n // Forward the run identity so the wrapped chat stamps it onto RUN_STARTED\n // (chat uses `runId` as its `runIdOverride`). Conditional spreads keep the\n // fields absent when unset, under `exactOptionalPropertyTypes`.\n ...(options.runId !== undefined ? { runId: options.runId } : {}),\n ...(options.threadId !== undefined ? { threadId: options.threadId } : {}),\n }\n }\n\n protected buildSummarizationPrompt(\n options: SummarizationOptions<TProviderOptions>,\n ): string {\n let prompt = 'You are a professional summarizer. '\n\n switch (options.style) {\n case 'bullet-points':\n prompt += 'Provide a summary in bullet point format. '\n break\n case 'paragraph':\n prompt += 'Provide a summary in paragraph format. '\n break\n case 'concise':\n prompt += 'Provide a very concise summary in 1-2 sentences. '\n break\n case undefined:\n prompt += 'Provide a clear and concise summary. '\n break\n default:\n prompt += 'Provide a clear and concise summary. '\n }\n\n if (options.focus && options.focus.length > 0) {\n prompt += `Focus on the following aspects: ${options.focus.join(', ')}. `\n }\n\n if (options.maxLength) {\n prompt += `Keep the summary under ${options.maxLength} tokens. `\n }\n\n return prompt\n }\n}\n"],"mappings":";;;;;;;;AAgBA,SAAS,0BACP,OACA,OACM;CACN,IAAI,MAAM,SAAS,UAAU,sBAAsB;EACjD,IAAI,MAAM,OAAO,MAAM,WAAW,MAAM;EACxC;CACF;CAEA,MAAM,WAAW,iBAAiB,KAAK;CACvC,KACG,MAAM,SAAS,UAAU,eACxB,MAAM,SAAS,UAAU,gBACzB,MAAM,SAAS,UAAU,uBAC3B,OAAO,UAAU,UAAU,UAE3B,MAAM,QAAQ,SAAS;CAGzB,IAAI,MAAM,SAAS,UAAU,cAAc;EACzC,MAAM,UAAU,kBAAkB,MAAM,OAAO,UAAU,KAAK;EAC9D,IAAI,SAAS,MAAM,QAAQ;CAC7B;AACF;AAEA,SAAS,cACP,OACO;CACP,MAAM,UACJ,OAAO,MAAM,YAAY,YAAY,MAAM,QAAQ,SAAS,IACxD,MAAM,UACN;CACN,MAAM,MAAM,IAAI,MAAM,OAAO;CAC7B,IAAI,OAAO,MAAM,SAAS,UACvB,IAAmC,OAAO,MAAM;CAEnD,MAAM;AACR;;;;;;;;;;;;;;;;;;AAkCA,IAAM,4BAAoD;CACxD,QAAQ;CACR,WAAW;CACX,MAAM;CACN,MAAM;CACN,QAAQ;CACR,YAAY;CAGZ,YAAY;AACd;;;;;;;;AASA,IAAM,wBAAwB;;;;;;;AAQ9B,SAAS,wBAAwB,aAA8B;CAC7D,OACE,gBAAgB,YAChB,0BAA0B,iBAAiB,KAAA;AAE/C;;;;;;;AAQA,SAAS,wBACP,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,SAAS,GAC1C,UAAU,mCAAmC,QAAQ,MAAM,KAAK,IAAI,EAAE;EAGxE,IAAI,QAAQ,WACV,UAAU,0BAA0B,QAAQ,UAAU;EAGxD,OAAO;CACT;AACF"}
|
|
1
|
+
{"version":3,"file":"chat-stream-summarize.js","names":[],"sources":["../../../../src/activities/summarize/chat-stream-summarize.ts"],"sourcesContent":["import { EventType } from '@ag-ui/core'\nimport { toRunErrorPayload } from '../error-payload'\nimport { MAX_TOKENS_KEYS } from '../../utilities/sampling-keys'\nimport { rebuildTokenUsage } from '../../utilities/ag-ui-usage'\nimport type { AdapterYieldChunk } from '../../utilities/adapter-yield-chunk'\nimport { tanstackMetadata } from '../../utilities/merge-metadata'\nimport { normalizeStreamChunk } from '../../utilities/normalize-stream-chunk'\nimport { BaseSummarizeAdapter } from './adapter'\nimport type {\n StreamChunk,\n SummarizationOptions,\n SummarizationResult,\n TextOptions,\n TokenUsage,\n} from '../../types'\n\nfunction consumeSpecSummarizeChunk(\n chunk: StreamChunk,\n state: { summary: string; model: string; usage: TokenUsage },\n): void {\n if (chunk.type === EventType.TEXT_MESSAGE_CONTENT) {\n if (chunk.delta) state.summary += chunk.delta\n return\n }\n\n const tanstack = tanstackMetadata(chunk)\n if (\n (chunk.type === EventType.RUN_STARTED ||\n chunk.type === EventType.RUN_FINISHED ||\n chunk.type === EventType.TEXT_MESSAGE_START) &&\n typeof tanstack?.model === 'string'\n ) {\n state.model = tanstack.model\n }\n\n if (chunk.type === EventType.RUN_FINISHED) {\n const rebuilt = rebuildTokenUsage(chunk.usage, tanstack?.usage)\n if (rebuilt) state.usage = rebuilt\n }\n}\n\nfunction throwRunError(\n chunk: Extract<StreamChunk, { type: 'RUN_ERROR' }>,\n): never {\n const message =\n typeof chunk.message === 'string' && chunk.message.length > 0\n ? chunk.message\n : 'Summarization failed'\n const err = new Error(message)\n if (typeof chunk.code === 'string') {\n ;(err as Error & { code?: string }).code = chunk.code\n }\n throw err\n}\n\n/**\n * Minimal contract for a text adapter that supports `chatStream`. Lets\n * `ChatStreamSummarizeAdapter` work with any text adapter without coupling\n * to a specific implementation.\n *\n * The provider-options shape is intentionally `any` here — the wrapper only\n * forwards `modelOptions` straight through, so a text adapter with a richer\n * per-model options type (e.g. `ResolveProviderOptions<TModel>`) is still\n * acceptable. Summarize-level type safety is enforced via\n * `SummarizationOptions<TProviderOptions>` on the wrapper itself.\n */\nexport interface ChatStreamCapable {\n chatStream: (options: TextOptions<any>) => AsyncIterable<AdapterYieldChunk>\n}\n\n/**\n * Provider-native max-output-tokens key per summarize-adapter `name`. summarize\n * is provider-agnostic and forwards `modelOptions` opaquely to the wrapped text\n * adapter, so `maxLength` must be written under the exact key the underlying\n * provider reads — no adapter reads a generic `maxTokens`. Ollama is the one\n * exception: it nests sampling under `options`, so it has no entry here and is\n * handled as a special nested case in `applyMaxLength`/`applyDefaultTemperature`.\n *\n * Keep in sync with each adapter's wire mapping:\n * - OpenAI (Responses): `max_output_tokens`\n * - Anthropic / Grok: `max_tokens`\n * - Groq: `max_completion_tokens`\n * - Gemini: `maxOutputTokens`\n * - OpenRouter: `maxCompletionTokens`\n * - LLM Gateway: `max_tokens`\n * - Ollama: nested `options.num_predict` (no entry — see `applyMaxLength`)\n */\nconst MAX_TOKENS_KEY_BY_ADAPTER: Record<string, string> = {\n openai: 'max_output_tokens',\n anthropic: 'max_tokens',\n grok: 'max_tokens',\n groq: 'max_completion_tokens',\n gemini: 'maxOutputTokens',\n openrouter: 'maxCompletionTokens',\n // LLM Gateway exposes an OpenAI-compatible Chat Completions surface whose\n // only output cap is `max_tokens` — it does not read `max_completion_tokens`.\n llmgateway: 'max_tokens',\n // Workers AI's OpenAI-compatible Chat Completions surface reads `max_tokens`.\n cloudflare: 'max_tokens',\n}\n\n/**\n * Every flat key any supported provider uses to cap output tokens (plus the\n * generic `maxTokens` spelling no adapter reads). Used to detect a\n * caller-supplied token limit so the summarize default never overrides an\n * explicit caller value. Shared with the OTel middleware via\n * `MAX_TOKENS_KEYS` so the two spelling sets cannot drift.\n */\nconst KNOWN_MAX_TOKENS_KEYS = MAX_TOKENS_KEYS\n\n/**\n * Whether `applyMaxLength` knows how to place a token limit for this adapter\n * `name` (either the nested Ollama shape or a flat provider-native key).\n * Used to surface a warning when `maxLength` would otherwise be silently\n * dropped for an unrecognised adapter name.\n */\nfunction isKnownMaxTokensAdapter(adapterName: string): boolean {\n return (\n adapterName === 'ollama' ||\n MAX_TOKENS_KEY_BY_ADAPTER[adapterName] !== undefined\n )\n}\n\n/**\n * Apply the low-temperature summarize default to a working copy of the\n * caller's `modelOptions`, placed where the wrapped provider actually reads\n * it (nested under `options` for Ollama, flat otherwise). The caller always\n * wins: if they already set `temperature` in that location, it is untouched.\n */\nfunction applyDefaultTemperature(\n adapterName: string,\n temperature: number,\n modelOptions: Record<string, unknown>,\n): Record<string, unknown> {\n const merged: Record<string, unknown> = { ...modelOptions }\n\n if (adapterName === 'ollama') {\n const existing =\n merged.options && typeof merged.options === 'object'\n ? (merged.options as Record<string, unknown>)\n : undefined\n if (existing && 'temperature' in existing) return merged\n merged.options = { temperature, ...existing }\n return merged\n }\n\n if ('temperature' in merged) return merged\n merged.temperature = temperature\n return merged\n}\n\n/**\n * Resolve `maxLength` to the provider-native max-output-tokens key for the\n * given summarize-adapter `name` (this wrapper's OWN `name`, not the wrapped\n * text adapter's) and merge it into a working copy of the caller's\n * `modelOptions`. The caller always wins: if they already set any recognised\n * token-limit key (flat or, for Ollama, nested `options.num_predict`), the\n * default is left untouched. Unknown/unrecognised adapter names fall back to\n * NOT setting a token key (the prompt hint still asks the model to stay under\n * `maxLength`) rather than writing a dead key no provider reads.\n *\n * Caveat (intentional): \"caller wins\" keys off ANY recognised spelling in\n * `KNOWN_MAX_TOKENS_KEYS`, but only the adapter's native key is read on the\n * wire. So a caller who sets a NON-native spelling for this provider — e.g.\n * `maxTokens`, or Anthropic's `max_tokens` against an OpenAI adapter — suppresses\n * the summarize default WITHOUT getting their own value applied either: neither\n * cap reaches the wire. This favours never clobbering a migration leftover over\n * guaranteeing a cap; the prompt-level hint still asks the model to stay under\n * `maxLength`. Rename the key to the provider-native spelling to forward it.\n */\nfunction applyMaxLength(\n adapterName: string,\n maxLength: number,\n modelOptions: Record<string, unknown>,\n): Record<string, unknown> {\n const merged: Record<string, unknown> = { ...modelOptions }\n\n if (adapterName === 'ollama') {\n // Honor a caller-set limit in either shape: a recognised flat key (e.g.\n // left over from a migration) or the nested `options.num_predict`.\n const callerSetFlatLimit = KNOWN_MAX_TOKENS_KEYS.some(\n (k) => typeof merged[k] === 'number',\n )\n const existing =\n merged.options && typeof merged.options === 'object'\n ? (merged.options as Record<string, unknown>)\n : undefined\n if (\n callerSetFlatLimit ||\n (existing && typeof existing.num_predict === 'number')\n ) {\n return merged\n }\n merged.options = { num_predict: maxLength, ...existing }\n return merged\n }\n\n const key = MAX_TOKENS_KEY_BY_ADAPTER[adapterName]\n if (key === undefined) return merged\n\n const callerSetLimit = KNOWN_MAX_TOKENS_KEYS.some(\n (k) => typeof merged[k] === 'number',\n )\n if (callerSetLimit) return merged\n\n merged[key] = maxLength\n return merged\n}\n\n/**\n * Extract the per-model `modelOptions` type a text adapter accepts. Used by\n * provider summarize factories so their `modelOptions` IntelliSense matches\n * what the underlying text adapter actually understands.\n */\nexport type InferTextProviderOptions<TAdapter> = TAdapter extends {\n '~types': { providerOptions: infer P }\n}\n ? P extends object\n ? P\n : object\n : object\n\n/**\n * Summarize adapter that wraps any `ChatStreamCapable` text adapter and\n * prompts it for summarization. Not tied to any wire format.\n */\nexport class ChatStreamSummarizeAdapter<\n TModel extends string,\n TProviderOptions extends object = Record<string, unknown>,\n> extends BaseSummarizeAdapter<TModel, TProviderOptions> {\n readonly name: string\n\n private readonly textAdapter: ChatStreamCapable\n\n constructor(\n textAdapter: ChatStreamCapable,\n model: TModel,\n name: string = 'chat-stream-summarize',\n ) {\n super({}, model)\n this.name = name\n this.textAdapter = textAdapter\n }\n\n async summarize(\n options: SummarizationOptions<TProviderOptions>,\n ): Promise<SummarizationResult> {\n const systemPrompt = this.buildSummarizationPrompt(options)\n\n const id = this.generateId()\n const state = {\n summary: '',\n model: options.model,\n usage: { promptTokens: 0, completionTokens: 0, totalTokens: 0 },\n }\n\n options.logger.request(\n `activity=summarize provider=${this.name} model=${options.model} text-length=${options.text.length} maxLength=${options.maxLength ?? 'unset'}`,\n { provider: this.name, model: options.model },\n )\n\n try {\n for await (const raw of this.textAdapter.chatStream(\n this.buildTextOptions(options, systemPrompt),\n )) {\n for (const chunk of normalizeStreamChunk(raw as AdapterYieldChunk)) {\n // Surface failures: the underlying chatStream emits RUN_ERROR instead\n // of throwing, so without this branch summarize() would return an\n // empty summary and pretend a failed run succeeded.\n if (chunk.type === EventType.RUN_ERROR) throwRunError(chunk)\n consumeSpecSummarizeChunk(chunk, state)\n }\n }\n } catch (error: unknown) {\n // Narrow before logging: raw SDK errors can carry request metadata\n // (including auth headers) which we must never surface to user loggers.\n options.logger.errors(`${this.name}.summarize fatal`, {\n error: toRunErrorPayload(error, `${this.name}.summarize failed`),\n source: `${this.name}.summarize`,\n })\n throw error\n }\n\n return {\n id,\n model: state.model,\n summary: state.summary,\n usage: state.usage,\n }\n }\n\n override async *summarizeStream(\n options: SummarizationOptions<TProviderOptions>,\n ): AsyncIterable<StreamChunk> {\n const systemPrompt = this.buildSummarizationPrompt(options)\n\n options.logger.request(\n `activity=summarizeStream provider=${this.name} model=${options.model} text-length=${options.text.length} maxLength=${options.maxLength ?? 'unset'}`,\n { provider: this.name, model: options.model },\n )\n\n const id = this.generateId()\n const state = {\n summary: '',\n model: options.model,\n usage: {\n promptTokens: 0,\n completionTokens: 0,\n totalTokens: 0,\n } satisfies SummarizationResult['usage'],\n }\n\n try {\n for await (const raw of this.textAdapter.chatStream(\n this.buildTextOptions(options, systemPrompt),\n )) {\n for (const chunk of normalizeStreamChunk(raw as AdapterYieldChunk)) {\n // Accumulate the same way `summarize()` does so consumers see deltas\n // AND the terminal `generation:result` event below carries the same\n // final summary that non-streaming returns.\n consumeSpecSummarizeChunk(chunk, state)\n\n // Emit the GenerationClient-shaped result event just before the\n // terminal RUN_FINISHED so subscribers (useSummarize) populate\n // `result` before flipping `status` to success.\n if (chunk.type === EventType.RUN_FINISHED) {\n yield {\n type: EventType.CUSTOM,\n name: 'generation:result',\n value: {\n id,\n model: state.model,\n summary: state.summary,\n usage: state.usage,\n } satisfies SummarizationResult,\n timestamp: Date.now(),\n }\n }\n\n yield chunk\n }\n }\n } catch (error: unknown) {\n options.logger.errors(`${this.name}.summarizeStream fatal`, {\n error: toRunErrorPayload(error, `${this.name}.summarizeStream failed`),\n source: `${this.name}.summarizeStream`,\n })\n throw error\n }\n }\n\n /**\n * Build the TextOptions passed to the underlying chatStream. Provider\n * `modelOptions` from the summarize call are forwarded as-is so knobs like\n * Anthropic cache headers, Gemini safety settings, or Ollama tuning params\n * still reach the wire layer.\n */\n protected buildTextOptions(\n options: SummarizationOptions<TProviderOptions>,\n systemPrompt: string,\n ): TextOptions<TProviderOptions> {\n // Sampling knobs now live in provider-native `modelOptions`. Apply the\n // low-temperature default where the wrapped provider actually reads it\n // (nested under `options` for Ollama, flat otherwise) so callers can still\n // override it. Resolving the placement from this summarize adapter's OWN\n // `name` keeps the default off the wire correctly per provider — a flat\n // `temperature` would be silently dropped by Ollama while still showing up\n // in OTel.\n let working: Record<string, unknown> = {\n ...(options.modelOptions as Record<string, unknown> | undefined),\n }\n working = applyDefaultTemperature(this.name, 0.3, working)\n // `maxLength` must reach the wire under the provider-native token key (it\n // differs per provider, and no adapter reads a generic `maxTokens`).\n // Resolve it from this summarize adapter's `name` (the constructor arg,\n // not the wrapped text adapter's name), never overriding a caller-supplied\n // token limit.\n if (options.maxLength !== undefined) {\n if (!isKnownMaxTokensAdapter(this.name)) {\n options.logger.warn(\n `summarize: maxLength=${options.maxLength} could not be mapped to a provider token key for adapter name \"${this.name}\" — it was dropped from modelOptions (the prompt still asks the model to stay under it). Construct ChatStreamSummarizeAdapter with a recognised provider name to forward the cap.`,\n { provider: this.name },\n )\n }\n working = applyMaxLength(this.name, options.maxLength, working)\n }\n const modelOptions = working as TProviderOptions\n\n return {\n model: options.model,\n messages: [{ role: 'user', content: options.text }],\n systemPrompts: [systemPrompt],\n modelOptions,\n logger: options.logger,\n // Forward the run identity so the wrapped chat stamps it onto RUN_STARTED\n // (chat uses `runId` as its `runIdOverride`). Conditional spreads keep the\n // fields absent when unset, under `exactOptionalPropertyTypes`.\n ...(options.runId !== undefined ? { runId: options.runId } : {}),\n ...(options.threadId !== undefined ? { threadId: options.threadId } : {}),\n }\n }\n\n protected buildSummarizationPrompt(\n options: SummarizationOptions<TProviderOptions>,\n ): string {\n let prompt = 'You are a professional summarizer. '\n\n switch (options.style) {\n case 'bullet-points':\n prompt += 'Provide a summary in bullet point format. '\n break\n case 'paragraph':\n prompt += 'Provide a summary in paragraph format. '\n break\n case 'concise':\n prompt += 'Provide a very concise summary in 1-2 sentences. '\n break\n case undefined:\n prompt += 'Provide a clear and concise summary. '\n break\n default:\n prompt += 'Provide a clear and concise summary. '\n }\n\n if (options.focus && options.focus.length > 0) {\n prompt += `Focus on the following aspects: ${options.focus.join(', ')}. `\n }\n\n if (options.maxLength) {\n prompt += `Keep the summary under ${options.maxLength} tokens. `\n }\n\n return prompt\n }\n}\n"],"mappings":";;;;;;;;AAgBA,SAAS,0BACP,OACA,OACM;CACN,IAAI,MAAM,SAAS,UAAU,sBAAsB;EACjD,IAAI,MAAM,OAAO,MAAM,WAAW,MAAM;EACxC;CACF;CAEA,MAAM,WAAW,iBAAiB,KAAK;CACvC,KACG,MAAM,SAAS,UAAU,eACxB,MAAM,SAAS,UAAU,gBACzB,MAAM,SAAS,UAAU,uBAC3B,OAAO,UAAU,UAAU,UAE3B,MAAM,QAAQ,SAAS;CAGzB,IAAI,MAAM,SAAS,UAAU,cAAc;EACzC,MAAM,UAAU,kBAAkB,MAAM,OAAO,UAAU,KAAK;EAC9D,IAAI,SAAS,MAAM,QAAQ;CAC7B;AACF;AA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AAC;IAAE,MAAM;IAAQ,SAAS,QAAQ;GAAK,CAAC;GAClD,eAAe,CAAC,YAAY;GAC5B;GACA,QAAQ,QAAQ;GAIhB,GAAI,QAAQ,UAAU,KAAA,IAAY,EAAE,OAAO,QAAQ,MAAM,IAAI,CAAC;GAC9D,GAAI,QAAQ,aAAa,KAAA,IAAY,EAAE,UAAU,QAAQ,SAAS,IAAI,CAAC;EACzE;CACF;CAEA,yBACE,SACQ;EACR,IAAI,SAAS;EAEb,QAAQ,QAAQ,OAAhB;GACE,KAAK;IACH,UAAU;IACV;GACF,KAAK;IACH,UAAU;IACV;GACF,KAAK;IACH,UAAU;IACV;GACF,KAAK,KAAA;IACH,UAAU;IACV;GACF,SACE,UAAU;EACd;EAEA,IAAI,QAAQ,SAAS,QAAQ,MAAM,SAAS,GAC1C,UAAU,mCAAmC,QAAQ,MAAM,KAAK,IAAI,EAAE;EAGxE,IAAI,QAAQ,WACV,UAAU,0BAA0B,QAAQ,UAAU;EAGxD,OAAO;CACT;AACF"}
|
|
@@ -10,6 +10,11 @@ export interface ByokProvider<TId extends string = string> {
|
|
|
10
10
|
* values here. This object is imported on the client.
|
|
11
11
|
*/
|
|
12
12
|
readonly env?: ReadonlyArray<string>;
|
|
13
|
+
/**
|
|
14
|
+
* Other descriptors this credential needs. A send for this provider also
|
|
15
|
+
* carries their headers and prompts for each one that is missing.
|
|
16
|
+
*/
|
|
17
|
+
readonly with?: ReadonlyArray<ByokProvider>;
|
|
13
18
|
}
|
|
14
19
|
/**
|
|
15
20
|
* Input for {@link defineByokProvider}. `id` cannot be optional: if `TId`
|
|
@@ -19,5 +24,6 @@ export type ByokProviderInit<TId extends string> = {
|
|
|
19
24
|
readonly id: undefined extends TId ? never : TId;
|
|
20
25
|
readonly label: string;
|
|
21
26
|
readonly env?: string | ReadonlyArray<string>;
|
|
27
|
+
readonly with?: ReadonlyArray<ByokProvider>;
|
|
22
28
|
};
|
|
23
29
|
export declare function defineByokProvider<const TId extends string>(provider: ByokProviderInit<TId>): ByokProvider<TId>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"define-provider.js","names":[],"sources":["../../../src/byok/define-provider.ts"],"sourcesContent":["import { isProviderId } from './providers'\n\n/**\n * A BYOK provider declared by an adapter. `id` is the `x-byok-<id>` slug and\n * is required — `{ id?: string }` is not a {@link ByokProvider}.\n */\nexport interface ByokProvider<TId extends string = string> {\n readonly id: TId\n readonly label: string\n /**\n * Env var names the relay may read. Names only — never put `process.env`\n * values here. This object is imported on the client.\n */\n readonly env?: ReadonlyArray<string>\n}\n\n/**\n * Input for {@link defineByokProvider}. `id` cannot be optional: if `TId`\n * includes `undefined`, `id` becomes `never` and the object is unassignable.\n */\nexport type ByokProviderInit<TId extends string> = {\n readonly id: undefined extends TId ? never : TId\n readonly label: string\n readonly env?: string | ReadonlyArray<string>\n}\n\nfunction normalizeEnv(\n env: string | ReadonlyArray<string> | undefined,\n): ReadonlyArray<string> | undefined {\n if (env === undefined) return undefined\n return typeof env === 'string' ? [env] : env\n}\n\nexport function defineByokProvider<const TId extends string>(\n provider: ByokProviderInit<TId>,\n): ByokProvider<TId> {\n if (!isProviderId(provider.id)) {\n throw new Error(`Invalid BYOK provider id: ${String(provider.id)}`)\n }\n const env = normalizeEnv(provider.env)\n return {\n id: provider.id,\n label: provider.label,\n ...(env ? { env } : {}),\n }\n}\n"],"mappings":";;
|
|
1
|
+
{"version":3,"file":"define-provider.js","names":[],"sources":["../../../src/byok/define-provider.ts"],"sourcesContent":["import { isProviderId } from './providers'\n\n/**\n * A BYOK provider declared by an adapter. `id` is the `x-byok-<id>` slug and\n * is required — `{ id?: string }` is not a {@link ByokProvider}.\n */\nexport interface ByokProvider<TId extends string = string> {\n readonly id: TId\n readonly label: string\n /**\n * Env var names the relay may read. Names only — never put `process.env`\n * values here. This object is imported on the client.\n */\n readonly env?: ReadonlyArray<string>\n /**\n * Other descriptors this credential needs. A send for this provider also\n * carries their headers and prompts for each one that is missing.\n */\n readonly with?: ReadonlyArray<ByokProvider>\n}\n\n/**\n * Input for {@link defineByokProvider}. `id` cannot be optional: if `TId`\n * includes `undefined`, `id` becomes `never` and the object is unassignable.\n */\nexport type ByokProviderInit<TId extends string> = {\n readonly id: undefined extends TId ? never : TId\n readonly label: string\n readonly env?: string | ReadonlyArray<string>\n readonly with?: ReadonlyArray<ByokProvider>\n}\n\nfunction normalizeEnv(\n env: string | ReadonlyArray<string> | undefined,\n): ReadonlyArray<string> | undefined {\n if (env === undefined) return undefined\n return typeof env === 'string' ? [env] : env\n}\n\nexport function defineByokProvider<const TId extends string>(\n provider: ByokProviderInit<TId>,\n): ByokProvider<TId> {\n if (!isProviderId(provider.id)) {\n throw new Error(`Invalid BYOK provider id: ${String(provider.id)}`)\n }\n const env = normalizeEnv(provider.env)\n return {\n id: provider.id,\n label: provider.label,\n ...(env ? { env } : {}),\n ...(provider.with ? { with: provider.with } : {}),\n }\n}\n"],"mappings":";;AAgCA,SAAS,aACP,KACmC;CACnC,IAAI,QAAQ,KAAA,GAAW,OAAO,KAAA;CAC9B,OAAO,OAAO,QAAQ,WAAW,CAAC,GAAG,IAAI;AAC3C;AAEA,SAAgB,mBACd,UACmB;CACnB,IAAI,CAAC,aAAa,SAAS,EAAE,GAC3B,MAAM,IAAI,MAAM,6BAA6B,OAAO,SAAS,EAAE,GAAG;CAEpE,MAAM,MAAM,aAAa,SAAS,GAAG;CACrC,OAAO;EACL,IAAI,SAAS;EACb,OAAO,SAAS;EAChB,GAAI,MAAM,EAAE,IAAI,IAAI,CAAC;EACrB,GAAI,SAAS,OAAO,EAAE,MAAM,SAAS,KAAK,IAAI,CAAC;CACjD;AACF"}
|
|
@@ -8,3 +8,10 @@ import { ProviderId } from './providers.js';
|
|
|
8
8
|
* A slug is header-only.
|
|
9
9
|
*/
|
|
10
10
|
export declare function getByokKey(request: Request, provider: ProviderId | ByokProvider): string | null;
|
|
11
|
+
/**
|
|
12
|
+
* Read several keys at once, one per name. Same rules as {@link getByokKey}
|
|
13
|
+
* for each entry. Use it for a credential made of more than one value.
|
|
14
|
+
*/
|
|
15
|
+
export declare function getByokKeys<const TProviders extends Record<string, ProviderId | ByokProvider>>(request: Request, providers: TProviders): {
|
|
16
|
+
[K in keyof TProviders]: string | null;
|
|
17
|
+
};
|
package/dist/esm/byok/get-key.js
CHANGED
|
@@ -20,7 +20,14 @@ function getByokKey(request, provider) {
|
|
|
20
20
|
}
|
|
21
21
|
return null;
|
|
22
22
|
}
|
|
23
|
+
/**
|
|
24
|
+
* Read several keys at once, one per name. Same rules as {@link getByokKey}
|
|
25
|
+
* for each entry. Use it for a credential made of more than one value.
|
|
26
|
+
*/
|
|
27
|
+
function getByokKeys(request, providers) {
|
|
28
|
+
return Object.fromEntries(Object.entries(providers).map(([name, provider]) => [name, getByokKey(request, provider)]));
|
|
29
|
+
}
|
|
23
30
|
//#endregion
|
|
24
|
-
export { getByokKey };
|
|
31
|
+
export { getByokKey, getByokKeys };
|
|
25
32
|
|
|
26
33
|
//# sourceMappingURL=get-key.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-key.js","names":[],"sources":["../../../src/byok/get-key.ts"],"sourcesContent":["import { byokHeaderName, resolveProviderId } from './providers'\nimport type { ByokProvider } from './define-provider'\nimport type { ProviderId } from './providers'\n\n/**\n * Read a key on the relay. Import from `@tanstack/ai/byok/server` so this\n * `process.env` access is not in the client graph.\n *\n * The header wins. A {@link ByokProvider} then tries `provider.env` in order.\n * A slug is header-only.\n */\nexport function getByokKey(\n request: Request,\n provider: ProviderId | ByokProvider,\n): string | null {\n const value = request.headers.get(byokHeaderName(resolveProviderId(provider)))\n if (typeof value === 'string') {\n const trimmed = value.trim()\n if (trimmed.length > 0) return trimmed\n }\n if (typeof provider === 'string') return null\n for (const name of provider.env ?? []) {\n const envValue = process.env[name]\n if (typeof envValue === 'string' && envValue.length > 0) return envValue\n }\n return null\n}\n"],"mappings":";;;;;;;;;AAWA,SAAgB,WACd,SACA,UACe;CACf,MAAM,QAAQ,QAAQ,QAAQ,IAAI,eAAe,kBAAkB,QAAQ,CAAC,CAAC;CAC7E,IAAI,OAAO,UAAU,UAAU;EAC7B,MAAM,UAAU,MAAM,KAAK;EAC3B,IAAI,QAAQ,SAAS,GAAG,OAAO;CACjC;CACA,IAAI,OAAO,aAAa,UAAU,OAAO;CACzC,KAAK,MAAM,QAAQ,SAAS,OAAO,CAAC,GAAG;EACrC,MAAM,WAAW,QAAQ,IAAI;EAC7B,IAAI,OAAO,aAAa,YAAY,SAAS,SAAS,GAAG,OAAO;CAClE;CACA,OAAO;AACT"}
|
|
1
|
+
{"version":3,"file":"get-key.js","names":[],"sources":["../../../src/byok/get-key.ts"],"sourcesContent":["import { byokHeaderName, resolveProviderId } from './providers'\nimport type { ByokProvider } from './define-provider'\nimport type { ProviderId } from './providers'\n\n/**\n * Read a key on the relay. Import from `@tanstack/ai/byok/server` so this\n * `process.env` access is not in the client graph.\n *\n * The header wins. A {@link ByokProvider} then tries `provider.env` in order.\n * A slug is header-only.\n */\nexport function getByokKey(\n request: Request,\n provider: ProviderId | ByokProvider,\n): string | null {\n const value = request.headers.get(byokHeaderName(resolveProviderId(provider)))\n if (typeof value === 'string') {\n const trimmed = value.trim()\n if (trimmed.length > 0) return trimmed\n }\n if (typeof provider === 'string') return null\n for (const name of provider.env ?? []) {\n const envValue = process.env[name]\n if (typeof envValue === 'string' && envValue.length > 0) return envValue\n }\n return null\n}\n\n/**\n * Read several keys at once, one per name. Same rules as {@link getByokKey}\n * for each entry. Use it for a credential made of more than one value.\n */\nexport function getByokKeys<\n const TProviders extends Record<string, ProviderId | ByokProvider>,\n>(\n request: Request,\n providers: TProviders,\n): { [K in keyof TProviders]: string | null } {\n return Object.fromEntries(\n Object.entries(providers).map(([name, provider]) => [\n name,\n getByokKey(request, provider),\n ]),\n ) as { [K in keyof TProviders]: string | null }\n}\n"],"mappings":";;;;;;;;;AAWA,SAAgB,WACd,SACA,UACe;CACf,MAAM,QAAQ,QAAQ,QAAQ,IAAI,eAAe,kBAAkB,QAAQ,CAAC,CAAC;CAC7E,IAAI,OAAO,UAAU,UAAU;EAC7B,MAAM,UAAU,MAAM,KAAK;EAC3B,IAAI,QAAQ,SAAS,GAAG,OAAO;CACjC;CACA,IAAI,OAAO,aAAa,UAAU,OAAO;CACzC,KAAK,MAAM,QAAQ,SAAS,OAAO,CAAC,GAAG;EACrC,MAAM,WAAW,QAAQ,IAAI;EAC7B,IAAI,OAAO,aAAa,YAAY,SAAS,SAAS,GAAG,OAAO;CAClE;CACA,OAAO;AACT;;;;;AAMA,SAAgB,YAGd,SACA,WAC4C;CAC5C,OAAO,OAAO,YACZ,OAAO,QAAQ,SAAS,CAAC,CAAC,KAAK,CAAC,MAAM,cAAc,CAClD,MACA,WAAW,SAAS,QAAQ,CAC9B,CAAC,CACH;AACF"}
|
package/dist/esm/byok/server.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { byokMissing, isByokMissingBody } from "./missing.js";
|
|
2
|
-
import { getByokKey } from "./get-key.js";
|
|
3
|
-
export { byokMissing, getByokKey, isByokMissingBody };
|
|
2
|
+
import { getByokKey, getByokKeys } from "./get-key.js";
|
|
3
|
+
export { byokMissing, getByokKey, getByokKeys, isByokMissingBody };
|
package/package.json
CHANGED
|
@@ -73,18 +73,19 @@ top-level options on `chat()`. See the per-provider table in
|
|
|
73
73
|
Each provider has a dedicated package with tree-shakeable adapter factories.
|
|
74
74
|
The text adapter is the primary one for chat/completions:
|
|
75
75
|
|
|
76
|
-
| Provider | Package | Factory | Env Var
|
|
77
|
-
| ----------------- | -------------------------------- | ------------------------------------------- |
|
|
78
|
-
| OpenAI | `@tanstack/ai-openai` | `openaiText` | `OPENAI_API_KEY`
|
|
79
|
-
| Anthropic | `@tanstack/ai-anthropic` | `anthropicText` | `ANTHROPIC_API_KEY`
|
|
80
|
-
| Gemini | `@tanstack/ai-gemini` | `geminiText` | `GOOGLE_API_KEY` or `GEMINI_API_KEY`
|
|
81
|
-
| Grok (xAI) | `@tanstack/ai-grok` | `grokText` | `XAI_API_KEY`
|
|
82
|
-
| Groq | `@tanstack/ai-groq` | `groqText` | `GROQ_API_KEY`
|
|
83
|
-
| OpenRouter | `@tanstack/ai-openrouter` | `openRouterText` | `OPENROUTER_API_KEY`
|
|
84
|
-
| Ollama | `@tanstack/ai-ollama` | `ollamaText` | `OLLAMA_HOST` (default: `http://localhost:11434`)
|
|
85
|
-
| Bedrock | `@tanstack/ai-bedrock` | `bedrockText` | `BEDROCK_API_KEY` or `AWS_BEARER_TOKEN_BEDROCK`
|
|
86
|
-
| BytePlus | `@tanstack/ai-byteplus` | `byteplusText` | `ARK_API_KEY` (falls back to `BYTEPLUS_API_KEY`)
|
|
87
|
-
| OpenAI-compatible | `@tanstack/ai-openai/compatible` | `openaiCompatible` / `openaiCompatibleText` | provider-specific (passed via `apiKey`)
|
|
76
|
+
| Provider | Package | Factory | Env Var |
|
|
77
|
+
| ----------------- | -------------------------------- | ------------------------------------------- | -------------------------------------------------------------------------------------- |
|
|
78
|
+
| OpenAI | `@tanstack/ai-openai` | `openaiText` | `OPENAI_API_KEY` |
|
|
79
|
+
| Anthropic | `@tanstack/ai-anthropic` | `anthropicText` | `ANTHROPIC_API_KEY` |
|
|
80
|
+
| Gemini | `@tanstack/ai-gemini` | `geminiText` | `GOOGLE_API_KEY` or `GEMINI_API_KEY` |
|
|
81
|
+
| Grok (xAI) | `@tanstack/ai-grok` | `grokText` | `XAI_API_KEY` |
|
|
82
|
+
| Groq | `@tanstack/ai-groq` | `groqText` | `GROQ_API_KEY` |
|
|
83
|
+
| OpenRouter | `@tanstack/ai-openrouter` | `openRouterText` | `OPENROUTER_API_KEY` |
|
|
84
|
+
| Ollama | `@tanstack/ai-ollama` | `ollamaText` | `OLLAMA_HOST` (default: `http://localhost:11434`) |
|
|
85
|
+
| Bedrock | `@tanstack/ai-bedrock` | `bedrockText` | `BEDROCK_API_KEY` or `AWS_BEARER_TOKEN_BEDROCK` |
|
|
86
|
+
| BytePlus | `@tanstack/ai-byteplus` | `byteplusText` | `ARK_API_KEY` (falls back to `BYTEPLUS_API_KEY`) |
|
|
87
|
+
| OpenAI-compatible | `@tanstack/ai-openai/compatible` | `openaiCompatible` / `openaiCompatibleText` | provider-specific (passed via `apiKey`) |
|
|
88
|
+
| Cloudflare | `@tanstack/ai-cloudflare` | `cloudflareText` | `CLOUDFLARE_ACCOUNT_ID` + `CLOUDFLARE_API_TOKEN`, or `{ binding: env.AI }` in a Worker |
|
|
88
89
|
|
|
89
90
|
> **BytePlus uses two keys.** `byteplusText` / `byteplusVideo` /
|
|
90
91
|
> `byteplusImage` read `ARK_API_KEY` (ModelArk, `Authorization: Bearer`), but
|
|
@@ -192,6 +192,7 @@ The terminal event is a `CUSTOM` chunk: `{ type: 'CUSTOM', name: 'structured-out
|
|
|
192
192
|
| `@tanstack/ai-groq` | Legacy `structuredOutputStream` only (no tools — Groq's API rejects schema + tools + stream) |
|
|
193
193
|
| `@tanstack/ai-bedrock` | Separate native `structuredOutputStream` finalization through Converse or an OpenAI-compatible API |
|
|
194
194
|
| `@tanstack/ai-byteplus` | Native combined mode on supported models; unsupported models emit `RUN_ERROR` |
|
|
195
|
+
| `@tanstack/ai-cloudflare` | Native `structuredOutputStream` without tools; with tools, a separate finalization call (Workers AI models answer the tool turn in prose) |
|
|
195
196
|
| `@tanstack/ai-claude-code` | Combined + event source — `--json-schema` on the same harness turn. Read `useChat().final`. See Pattern 6. |
|
|
196
197
|
| `@tanstack/ai-codex` | Combined + event source — `--output-schema` on the same harness turn. Read `useChat().final`. See Pattern 6. |
|
|
197
198
|
| `@tanstack/ai-opencode` | Combined + event source — prompt-and-parse. Read `useChat().final`. See Pattern 6. |
|
|
@@ -95,6 +95,8 @@ const MAX_TOKENS_KEY_BY_ADAPTER: Record<string, string> = {
|
|
|
95
95
|
// LLM Gateway exposes an OpenAI-compatible Chat Completions surface whose
|
|
96
96
|
// only output cap is `max_tokens` — it does not read `max_completion_tokens`.
|
|
97
97
|
llmgateway: 'max_tokens',
|
|
98
|
+
// Workers AI's OpenAI-compatible Chat Completions surface reads `max_tokens`.
|
|
99
|
+
cloudflare: 'max_tokens',
|
|
98
100
|
}
|
|
99
101
|
|
|
100
102
|
/**
|
|
@@ -12,6 +12,11 @@ export interface ByokProvider<TId extends string = string> {
|
|
|
12
12
|
* values here. This object is imported on the client.
|
|
13
13
|
*/
|
|
14
14
|
readonly env?: ReadonlyArray<string>
|
|
15
|
+
/**
|
|
16
|
+
* Other descriptors this credential needs. A send for this provider also
|
|
17
|
+
* carries their headers and prompts for each one that is missing.
|
|
18
|
+
*/
|
|
19
|
+
readonly with?: ReadonlyArray<ByokProvider>
|
|
15
20
|
}
|
|
16
21
|
|
|
17
22
|
/**
|
|
@@ -22,6 +27,7 @@ export type ByokProviderInit<TId extends string> = {
|
|
|
22
27
|
readonly id: undefined extends TId ? never : TId
|
|
23
28
|
readonly label: string
|
|
24
29
|
readonly env?: string | ReadonlyArray<string>
|
|
30
|
+
readonly with?: ReadonlyArray<ByokProvider>
|
|
25
31
|
}
|
|
26
32
|
|
|
27
33
|
function normalizeEnv(
|
|
@@ -42,5 +48,6 @@ export function defineByokProvider<const TId extends string>(
|
|
|
42
48
|
id: provider.id,
|
|
43
49
|
label: provider.label,
|
|
44
50
|
...(env ? { env } : {}),
|
|
51
|
+
...(provider.with ? { with: provider.with } : {}),
|
|
45
52
|
}
|
|
46
53
|
}
|
package/src/byok/get-key.ts
CHANGED
|
@@ -25,3 +25,21 @@ export function getByokKey(
|
|
|
25
25
|
}
|
|
26
26
|
return null
|
|
27
27
|
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Read several keys at once, one per name. Same rules as {@link getByokKey}
|
|
31
|
+
* for each entry. Use it for a credential made of more than one value.
|
|
32
|
+
*/
|
|
33
|
+
export function getByokKeys<
|
|
34
|
+
const TProviders extends Record<string, ProviderId | ByokProvider>,
|
|
35
|
+
>(
|
|
36
|
+
request: Request,
|
|
37
|
+
providers: TProviders,
|
|
38
|
+
): { [K in keyof TProviders]: string | null } {
|
|
39
|
+
return Object.fromEntries(
|
|
40
|
+
Object.entries(providers).map(([name, provider]) => [
|
|
41
|
+
name,
|
|
42
|
+
getByokKey(request, provider),
|
|
43
|
+
]),
|
|
44
|
+
) as { [K in keyof TProviders]: string | null }
|
|
45
|
+
}
|
package/src/byok/server.ts
CHANGED