@yourgpt/llm-sdk 2.6.0-beta.2 → 2.6.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.
Files changed (74) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +87 -17
  3. package/dist/adapters/index.d.mts +11 -13
  4. package/dist/adapters/index.d.ts +11 -13
  5. package/dist/adapters/index.js +406 -114
  6. package/dist/adapters/index.mjs +406 -114
  7. package/dist/audio-K-Z3-Bce.d.mts +191 -0
  8. package/dist/audio-K-Z3-Bce.d.ts +191 -0
  9. package/dist/{base-BICaQaRS.d.mts → base-6LzczuCg.d.ts} +8 -1
  10. package/dist/{base-CpRPB8u8.d.ts → base-DySbTP8C.d.mts} +8 -1
  11. package/dist/decisions-CJzOt87t.d.mts +137 -0
  12. package/dist/decisions-CJzOt87t.d.ts +137 -0
  13. package/dist/fallback/index.d.mts +4 -4
  14. package/dist/fallback/index.d.ts +4 -4
  15. package/dist/http-BQxUT5A9.d.mts +9 -0
  16. package/dist/http-BQxUT5A9.d.ts +9 -0
  17. package/dist/index.d.mts +17 -9
  18. package/dist/index.d.ts +17 -9
  19. package/dist/index.js +698 -205
  20. package/dist/index.mjs +695 -206
  21. package/dist/providers/anthropic/index.d.mts +7 -4
  22. package/dist/providers/anthropic/index.d.ts +7 -4
  23. package/dist/providers/anthropic/index.js +389 -115
  24. package/dist/providers/anthropic/index.mjs +389 -115
  25. package/dist/providers/azure/index.d.mts +3 -3
  26. package/dist/providers/azure/index.d.ts +3 -3
  27. package/dist/providers/cloudflare/index.d.mts +11 -0
  28. package/dist/providers/cloudflare/index.d.ts +11 -0
  29. package/dist/providers/cloudflare/index.js +743 -0
  30. package/dist/providers/cloudflare/index.mjs +741 -0
  31. package/dist/providers/fireworks/index.d.mts +3 -3
  32. package/dist/providers/fireworks/index.d.ts +3 -3
  33. package/dist/providers/fireworks/index.js +181 -60
  34. package/dist/providers/fireworks/index.mjs +181 -60
  35. package/dist/providers/google/index.d.mts +3 -3
  36. package/dist/providers/google/index.d.ts +3 -3
  37. package/dist/providers/google/index.js +181 -60
  38. package/dist/providers/google/index.mjs +181 -60
  39. package/dist/providers/ollama/index.d.mts +4 -4
  40. package/dist/providers/ollama/index.d.ts +4 -4
  41. package/dist/providers/openai/index.d.mts +38 -6
  42. package/dist/providers/openai/index.d.ts +38 -6
  43. package/dist/providers/openai/index.js +1451 -85
  44. package/dist/providers/openai/index.mjs +1449 -86
  45. package/dist/providers/openrouter/index.d.mts +21 -4
  46. package/dist/providers/openrouter/index.d.ts +21 -4
  47. package/dist/providers/openrouter/index.js +1040 -131
  48. package/dist/providers/openrouter/index.mjs +1040 -132
  49. package/dist/providers/togetherai/index.d.mts +3 -3
  50. package/dist/providers/togetherai/index.d.ts +3 -3
  51. package/dist/providers/togetherai/index.js +181 -60
  52. package/dist/providers/togetherai/index.mjs +181 -60
  53. package/dist/providers/typesafe/index.d.mts +8 -0
  54. package/dist/providers/typesafe/index.d.ts +8 -0
  55. package/dist/providers/typesafe/index.js +735 -0
  56. package/dist/providers/typesafe/index.mjs +733 -0
  57. package/dist/providers/xai/index.d.mts +3 -3
  58. package/dist/providers/xai/index.d.ts +3 -3
  59. package/dist/providers/xai/index.js +181 -60
  60. package/dist/providers/xai/index.mjs +181 -60
  61. package/dist/{types-DCFqkJAy.d.ts → types-B0y6VZSQ.d.ts} +1 -1
  62. package/dist/{types-DHQEMFHA.d.mts → types-BXQMtaCX.d.ts} +17 -3
  63. package/dist/{types-C3RgRbEC.d.mts → types-BY6BVhFg.d.mts} +1 -1
  64. package/dist/{types-Dikj3En4.d.ts → types-C7_qVSSd.d.mts} +17 -3
  65. package/dist/{types-Dg1Bcg1k.d.mts → types-D7lzMMLu.d.mts} +13 -1
  66. package/dist/{types-Dg1Bcg1k.d.ts → types-D7lzMMLu.d.ts} +13 -1
  67. package/dist/yourgpt/index.d.mts +1 -1
  68. package/dist/yourgpt/index.d.ts +1 -1
  69. package/docs/decisions.md +174 -0
  70. package/docs/media.md +201 -0
  71. package/docs/multimodal-and-audio.md +9 -2
  72. package/package.json +34 -12
  73. package/dist/audio-BBSwnjo8.d.mts +0 -92
  74. package/dist/audio-BBSwnjo8.d.ts +0 -92
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 YourGPT
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -2,6 +2,13 @@
2
2
 
3
3
  Multi-provider LLM SDK with streaming. One API, any provider.
4
4
 
5
+ ## Release availability
6
+
7
+ The examples below describe the SDK source on `main`. See
8
+ [versions and compatibility](https://copilot-sdk.yourgpt.ai/docs/llm-sdk/beta-upgrade)
9
+ for published npm versions and feature availability. The
10
+ [Feature Lab](https://copilot-sdk.yourgpt.ai/playground/features) runs the workspace source.
11
+
5
12
  ## Installation
6
13
 
7
14
  ```bash
@@ -15,8 +22,10 @@ npm install @yourgpt/llm-sdk @anthropic-ai/sdk
15
22
  The SDK normalizes token limits and sampling options for recognized OpenAI model
16
23
  families, including GPT-6. Reasoning stays enabled by default. An unsupported
17
24
  `temperature` is omitted with a warning; the SDK does not silently disable
18
- reasoning. Use `onWarning` in the OpenAI provider configuration to handle these
19
- warnings yourself.
25
+ reasoning. Responses also omits `message.output_text.logprobs` from `include`
26
+ while reasoning is enabled, preserving other requested fields and encrypted
27
+ replay state. Use `onWarning` in the OpenAI provider configuration to handle
28
+ these warnings yourself.
20
29
 
21
30
  For a model that supports non-reasoning mode, select it explicitly when sampling
22
31
  control is required:
@@ -83,12 +92,28 @@ existing option; `responses.reasoningSummary` requests a reasoning summary.
83
92
 
84
93
  **Stateless replay:** use `store: false` and preserve the returned message objects,
85
94
  including `providerMetadata`. Each assistant's `providerMetadata.openai.response`
86
- contains the response ID, ordered native output items, raw usage, status and
87
- refusals. Completed encrypted reasoning, native search items, citations and
88
- function-call IDs survive the next turn. Automatic tool loops retain them too.
89
- Streams use completed items, never partially streamed reasoning. Models may
90
- return no reasoning items on simple requests; the SDK preserves what is returned.
91
- Do not edit opaque output items or carry them across unrelated conversations.
95
+ contains minimal ordered continuation items, including function-call IDs, assistant
96
+ phase and completed encrypted reasoning. It excludes the raw response envelope,
97
+ native usage, logprobs, reasoning summaries and output-text annotations. Native
98
+ tool state needed for replay is retained with diagnostic fields removed. Streams
99
+ use completed items, never partially streamed reasoning. Keep this state intact
100
+ and within its original conversation; do not treat it as trusted authorization.
101
+
102
+ The separate **server-side model result** `providerMetadata` still contains the
103
+ full response ID, status, native usage and output for diagnostics and stored
104
+ continuation. Do not forward that complete model result to a public client.
105
+ `runtime.chat()` retains top-level `usage` for billing and `events` for debugging;
106
+ after billing, omit both before serializing it:
107
+
108
+ ```ts
109
+ const result = await runtime.chat(request);
110
+ await recordBilling(result.usage);
111
+ const { usage, events, ...clientResult } = result;
112
+ return Response.json(clientResult);
113
+ ```
114
+
115
+ SSE response helpers omit usage by default. `runtime.stream(...).toResponse({
116
+ includeUsage: true })` explicitly enables it for a server-controlled raw API.
92
117
 
93
118
  `generateText().response.messages` now includes the final assistant turn as well
94
119
  as tool turns. `streamText().response` returns the same complete history after
@@ -101,7 +126,8 @@ storage adapter stores display/tool records and does **not** yet guarantee
101
126
  lossless Responses replay after a remote session reload.
102
127
 
103
128
  **Stored continuation:** explicitly use `store: true`, take the returned
104
- `providerMetadata.openai.response.id`, and pass it as
129
+ `generateText(...).providerMetadata.openai.response.id` (the server result, not
130
+ the saved message metadata), and pass it as
105
131
  `openai: { responses: { previousResponseId: id } }` on the next call. Send only new
106
132
  input after that response, and resend system instructions; do not also resend
107
133
  its entire history. The SDK does not automatically advance or persist response
@@ -116,9 +142,12 @@ support remain model-specific. Raw usage preserves cache/reasoning breakdowns;
116
142
  this does not add pricing/accounting logic.
117
143
 
118
144
  Modern Responses accepts image URLs, data URLs/bytes, and file URL/base64 inputs.
119
- This does not add generalized image-bearing function results, native MCP approval
120
- flows, background jobs, or Decisions. Failed/incomplete/cancelled streams do not
121
- produce executable partial function calls or a successful final result.
145
+ Function results can return images through `toModelOutput` or `_aiContent` on
146
+ OpenAI Responses and Anthropic. Native Decisions uses the separate
147
+ `experimental_decide` API described in [the Decisions guide](./docs/decisions.md).
148
+ Native MCP approval flows and background jobs are not covered by this integration.
149
+ Failed/incomplete/cancelled streams do not produce executable partial function
150
+ calls or a successful final result.
122
151
 
123
152
  The contracts were checked against [OpenAI conversation state](https://developers.openai.com/api/docs/guides/conversation-state),
124
153
  [Responses request fields](https://developers.openai.com/api/reference/resources/responses/methods/create),
@@ -151,7 +180,7 @@ const adapter = createFallbackChain({
151
180
  const e = error as { status?: number; code?: string; param?: string };
152
181
  return (
153
182
  e?.status === 400 &&
154
- e.code === "unsupported_parameter" &&
183
+ ["unsupported_parameter", "unsupported_value"].includes(e.code ?? "") &&
155
184
  e.param === "temperature"
156
185
  );
157
186
  },
@@ -165,6 +194,12 @@ errors after stream output or tool events never retry or switch models. Provider
165
194
  status/code/parameter fields survive OpenAI streaming errors; raw error causes
166
195
  are retained only in-process and omitted from JSON/SSE output.
167
196
 
197
+ The live parameter regression checks both OpenAI error codes above. In particular,
198
+ GPT-6 Luna returns `unsupported_value` when `temperature: 0` is deliberately sent
199
+ with reasoning enabled. Normal SDK requests omit that unsupported parameter.
200
+ `TRAINING_CONFLICT` is application policy: a provider error must not be interpreted
201
+ as a successful guardrail decision or automatically become `respond`.
202
+
168
203
  Stream readers and final-result promises share one execution, including tool
169
204
  execution. Later readers replay retained stream parts; pass an abort signal to
170
205
  cancel generation. Cancellation during a tool stops subsequent tools and rejects
@@ -222,7 +257,10 @@ or `{ role: "system", content: "..." }` messages. It combines them into
222
257
  Anthropic's top-level `system` field: the request's nonempty `systemPrompt` (or
223
258
  the runtime default) first, followed by system messages in order. System messages
224
259
  are removed from the conversation sent to Anthropic. This applies to `chat`,
225
- `generate`, `stream`, and `processChat`.
260
+ `generate`, `stream`, and `processChat`. If the same text is supplied through both
261
+ forms, the explicit prompt is sent once. Null, non-text values and unsupported
262
+ system blocks are ignored for proxy compatibility; valid text blocks are retained.
263
+ Repeated message-only instructions are preserved in order.
226
264
 
227
265
  ```ts
228
266
  const decision = await runtime.chat({
@@ -232,8 +270,10 @@ const decision = await runtime.chat({
232
270
  ```
233
271
 
234
272
  The published `2.6.0-beta.1` Runtime adapter silently dropped system-role
235
- messages; use the explicit `systemPrompt` form above until you upgrade to a release
236
- containing this fix. The separate `generateText`/`streamText` Anthropic provider
273
+ messages. Version `2.6.0-beta.2` first fixed that; use `2.6.0-beta.3` for its
274
+ compatibility corrections, including tolerant system content and deduplication
275
+ of identical explicit/system-role instructions.
276
+ The separate `generateText`/`streamText` Anthropic provider
237
277
  already handles system-role messages.
238
278
 
239
279
  ## Selective Tool Loading
@@ -314,4 +354,34 @@ Tools can return native image content using `toModelOutput` or the existing `_ai
314
354
 
315
355
  `generateSpeech` / `transcribe` are separate server audio helpers, with `openaiSpeech` / `openaiTranscription` factories from `@yourgpt/llm-sdk/openai`. They support cancellation, validated encoded audio, and response metadata. Copilot's `VoiceRecorder` and `transcribeRecording` provide recorded microphone input and a reviewable transcript.
316
356
 
317
- See [image and audio contracts, examples, and limitations](./docs/multimodal-and-audio.md). Realtime voice calls and image generation are separate follow-ups.
357
+ See [image and audio contracts, examples, and limitations](./docs/multimodal-and-audio.md).
358
+ For realtime voice calls and image generation, see [the media guide](./docs/media.md).
359
+
360
+ ### Native Decisions
361
+
362
+ `experimental_decide` provides native boolean, choice, and score questions with
363
+ OpenAI, TypeSafe/Jev, OpenRouter, and Cloudflare adapters. It preserves named
364
+ answers, distributions, refusals, provider confidence and usage. See the
365
+ [Decisions guide](./docs/decisions.md) for supported inputs, provider-specific
366
+ limits and the skills-demo example.
367
+
368
+ ### Images and realtime voice
369
+
370
+ `generateImage` / `openaiImage` add image generation and editing.
371
+ `openaiRealtime` creates server-side WebRTC sessions or short-lived credentials.
372
+ Copilot supplies `RealtimeVoiceSession` and `useRealtimeVoice` for browser calls,
373
+ transcripts, tool approval and cleanup. See [the media guide](docs/media.md).
374
+
375
+ ### Compatibility fixes
376
+
377
+ OpenAI-compatible Chat transports preserve raw structured tool-message content
378
+ instead of coercing arrays or objects to `[object Object]`. The SDK's explicit
379
+ `modelOutput` representation still uses provider-specific conversion. This does
380
+ not make every provider accept arbitrary object content; the provider validates
381
+ its own schema. Use its supported content-part format for live calls.
382
+
383
+ Malformed Responses function calls are rejected before tool execution with
384
+ `status: 502`, `code: "INVALID_PROVIDER_RESPONSE"`. The fallback chain can retry or
385
+ fall back according to its configured policy before any content has been emitted.
386
+ It does not switch models after streaming content or tool execution has started.
387
+ `generateText` also accepts model results that omit the optional `toolCalls` field.
@@ -1,7 +1,7 @@
1
- import { L as LLMAdapter, C as ChatCompletionRequest, a as CompletionResult } from '../base-BICaQaRS.mjs';
2
- export { A as AdapterFactory, l as AnthropicContentBlock, O as OpenAIContentBlock, j as attachmentToAnthropicDocument, i as attachmentToAnthropicImage, k as attachmentToOpenAIImage, f as formatMessages, c as formatMessagesForAnthropic, d as formatMessagesForOpenAI, b as formatTools, h as hasImageAttachments, g as hasMediaAttachments, m as messageToAnthropicContent, e as messageToOpenAIContent } from '../base-BICaQaRS.mjs';
3
- import { ae as OpenAIParameterOptions, O as OpenAITransportOptions, W as WebSearchConfig, i as StreamEvent } from '../types-Dg1Bcg1k.mjs';
4
- import { d as OllamaModelOptions } from '../types-DHQEMFHA.mjs';
1
+ import { L as LLMAdapter, C as ChatCompletionRequest, a as CompletionResult } from '../base-DySbTP8C.mjs';
2
+ export { A as AdapterFactory, l as AnthropicContentBlock, O as OpenAIContentBlock, j as attachmentToAnthropicDocument, i as attachmentToAnthropicImage, k as attachmentToOpenAIImage, f as formatMessages, c as formatMessagesForAnthropic, d as formatMessagesForOpenAI, b as formatTools, h as hasImageAttachments, g as hasMediaAttachments, m as messageToAnthropicContent, e as messageToOpenAIContent } from '../base-DySbTP8C.mjs';
3
+ import { ae as OpenAIParameterOptions, O as OpenAITransportOptions, W as WebSearchConfig, i as StreamEvent } from '../types-D7lzMMLu.mjs';
4
+ import { o as AnthropicThinking, d as OllamaModelOptions } from '../types-C7_qVSSd.mjs';
5
5
  import 'zod';
6
6
 
7
7
  /**
@@ -9,6 +9,8 @@ import 'zod';
9
9
  */
10
10
  interface OpenAIAdapterConfig extends OpenAIParameterOptions, OpenAITransportOptions {
11
11
  organization?: string;
12
+ project?: string;
13
+ timeout?: number;
12
14
  headers?: Record<string, string>;
13
15
  apiKey: string;
14
16
  model?: string;
@@ -94,14 +96,6 @@ declare class OpenAIAdapter implements LLMAdapter {
94
96
  */
95
97
  declare function createOpenAIAdapter(config: OpenAIAdapterConfig): OpenAIAdapter;
96
98
 
97
- /**
98
- * Extended thinking configuration
99
- */
100
- interface ThinkingConfig {
101
- type: "enabled";
102
- /** Budget for thinking tokens (minimum 1024) */
103
- budgetTokens?: number;
104
- }
105
99
  /**
106
100
  * Anthropic adapter configuration
107
101
  */
@@ -110,8 +104,12 @@ interface AnthropicAdapterConfig {
110
104
  model?: string;
111
105
  /** Base URL for API endpoint */
112
106
  baseUrl?: string;
107
+ timeout?: number;
108
+ headers?: Record<string, string>;
109
+ cacheControl?: boolean;
113
110
  /** Enable extended thinking (for Claude 3.7 Sonnet, Claude 4) */
114
- thinking?: ThinkingConfig;
111
+ thinking?: AnthropicThinking;
112
+ effort?: "low" | "medium" | "high" | "xhigh" | "max";
115
113
  temperature?: number;
116
114
  maxTokens?: number;
117
115
  /**
@@ -1,7 +1,7 @@
1
- import { L as LLMAdapter, C as ChatCompletionRequest, a as CompletionResult } from '../base-CpRPB8u8.js';
2
- export { A as AdapterFactory, l as AnthropicContentBlock, O as OpenAIContentBlock, j as attachmentToAnthropicDocument, i as attachmentToAnthropicImage, k as attachmentToOpenAIImage, f as formatMessages, c as formatMessagesForAnthropic, d as formatMessagesForOpenAI, b as formatTools, h as hasImageAttachments, g as hasMediaAttachments, m as messageToAnthropicContent, e as messageToOpenAIContent } from '../base-CpRPB8u8.js';
3
- import { ae as OpenAIParameterOptions, O as OpenAITransportOptions, W as WebSearchConfig, i as StreamEvent } from '../types-Dg1Bcg1k.js';
4
- import { d as OllamaModelOptions } from '../types-Dikj3En4.js';
1
+ import { L as LLMAdapter, C as ChatCompletionRequest, a as CompletionResult } from '../base-6LzczuCg.js';
2
+ export { A as AdapterFactory, l as AnthropicContentBlock, O as OpenAIContentBlock, j as attachmentToAnthropicDocument, i as attachmentToAnthropicImage, k as attachmentToOpenAIImage, f as formatMessages, c as formatMessagesForAnthropic, d as formatMessagesForOpenAI, b as formatTools, h as hasImageAttachments, g as hasMediaAttachments, m as messageToAnthropicContent, e as messageToOpenAIContent } from '../base-6LzczuCg.js';
3
+ import { ae as OpenAIParameterOptions, O as OpenAITransportOptions, W as WebSearchConfig, i as StreamEvent } from '../types-D7lzMMLu.js';
4
+ import { o as AnthropicThinking, d as OllamaModelOptions } from '../types-BXQMtaCX.js';
5
5
  import 'zod';
6
6
 
7
7
  /**
@@ -9,6 +9,8 @@ import 'zod';
9
9
  */
10
10
  interface OpenAIAdapterConfig extends OpenAIParameterOptions, OpenAITransportOptions {
11
11
  organization?: string;
12
+ project?: string;
13
+ timeout?: number;
12
14
  headers?: Record<string, string>;
13
15
  apiKey: string;
14
16
  model?: string;
@@ -94,14 +96,6 @@ declare class OpenAIAdapter implements LLMAdapter {
94
96
  */
95
97
  declare function createOpenAIAdapter(config: OpenAIAdapterConfig): OpenAIAdapter;
96
98
 
97
- /**
98
- * Extended thinking configuration
99
- */
100
- interface ThinkingConfig {
101
- type: "enabled";
102
- /** Budget for thinking tokens (minimum 1024) */
103
- budgetTokens?: number;
104
- }
105
99
  /**
106
100
  * Anthropic adapter configuration
107
101
  */
@@ -110,8 +104,12 @@ interface AnthropicAdapterConfig {
110
104
  model?: string;
111
105
  /** Base URL for API endpoint */
112
106
  baseUrl?: string;
107
+ timeout?: number;
108
+ headers?: Record<string, string>;
109
+ cacheControl?: boolean;
113
110
  /** Enable extended thinking (for Claude 3.7 Sonnet, Claude 4) */
114
- thinking?: ThinkingConfig;
111
+ thinking?: AnthropicThinking;
112
+ effort?: "low" | "medium" | "high" | "xhigh" | "max";
115
113
  temperature?: number;
116
114
  maxTokens?: number;
117
115
  /**