@yourgpt/llm-sdk 2.6.0-beta.3 → 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 +46 -10
  3. package/dist/adapters/index.d.mts +11 -13
  4. package/dist/adapters/index.d.ts +11 -13
  5. package/dist/adapters/index.js +327 -100
  6. package/dist/adapters/index.mjs +327 -100
  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 +14 -8
  18. package/dist/index.d.ts +14 -8
  19. package/dist/index.js +599 -195
  20. package/dist/index.mjs +596 -196
  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 +383 -102
  24. package/dist/providers/anthropic/index.mjs +383 -102
  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 +108 -59
  34. package/dist/providers/fireworks/index.mjs +108 -59
  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 +108 -59
  38. package/dist/providers/google/index.mjs +108 -59
  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 +1378 -84
  44. package/dist/providers/openai/index.mjs +1376 -85
  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 +967 -130
  48. package/dist/providers/openrouter/index.mjs +967 -131
  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 +108 -59
  52. package/dist/providers/togetherai/index.mjs +108 -59
  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 +108 -59
  60. package/dist/providers/xai/index.mjs +108 -59
  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:
@@ -133,9 +142,12 @@ support remain model-specific. Raw usage preserves cache/reasoning breakdowns;
133
142
  this does not add pricing/accounting logic.
134
143
 
135
144
  Modern Responses accepts image URLs, data URLs/bytes, and file URL/base64 inputs.
136
- This does not add generalized image-bearing function results, native MCP approval
137
- flows, background jobs, or Decisions. Failed/incomplete/cancelled streams do not
138
- 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.
139
151
 
140
152
  The contracts were checked against [OpenAI conversation state](https://developers.openai.com/api/docs/guides/conversation-state),
141
153
  [Responses request fields](https://developers.openai.com/api/reference/resources/responses/methods/create),
@@ -168,7 +180,7 @@ const adapter = createFallbackChain({
168
180
  const e = error as { status?: number; code?: string; param?: string };
169
181
  return (
170
182
  e?.status === 400 &&
171
- e.code === "unsupported_parameter" &&
183
+ ["unsupported_parameter", "unsupported_value"].includes(e.code ?? "") &&
172
184
  e.param === "temperature"
173
185
  );
174
186
  },
@@ -182,6 +194,12 @@ errors after stream output or tool events never retry or switch models. Provider
182
194
  status/code/parameter fields survive OpenAI streaming errors; raw error causes
183
195
  are retained only in-process and omitted from JSON/SSE output.
184
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
+
185
203
  Stream readers and final-result promises share one execution, including tool
186
204
  execution. Later readers replay retained stream parts; pass an abort signal to
187
205
  cancel generation. Cancellation during a tool stops subsequent tools and rejects
@@ -252,8 +270,10 @@ const decision = await runtime.chat({
252
270
  ```
253
271
 
254
272
  The published `2.6.0-beta.1` Runtime adapter silently dropped system-role
255
- messages; use the explicit `systemPrompt` form above until you upgrade to a release
256
- 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
257
277
  already handles system-role messages.
258
278
 
259
279
  ## Selective Tool Loading
@@ -334,9 +354,25 @@ Tools can return native image content using `toModelOutput` or the existing `_ai
334
354
 
335
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.
336
356
 
337
- 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).
338
374
 
339
- ### Beta compatibility fixes
375
+ ### Compatibility fixes
340
376
 
341
377
  OpenAI-compatible Chat transports preserve raw structured tool-message content
342
378
  instead of coercing arrays or objects to `[object Object]`. The SDK's explicit
@@ -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
  /**