@yourgpt/llm-sdk 2.6.0-beta.0 → 2.6.0-beta.2

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 (64) hide show
  1. package/README.md +189 -0
  2. package/dist/adapters/index.d.mts +11 -13
  3. package/dist/adapters/index.d.ts +11 -13
  4. package/dist/adapters/index.js +610 -186
  5. package/dist/adapters/index.mjs +610 -186
  6. package/dist/audio-BBSwnjo8.d.mts +92 -0
  7. package/dist/audio-BBSwnjo8.d.ts +92 -0
  8. package/dist/{base-tNgbBaSo.d.mts → base-BICaQaRS.d.mts} +8 -3
  9. package/dist/{base-C58Dsr9p.d.ts → base-CpRPB8u8.d.ts} +8 -3
  10. package/dist/fallback/index.d.mts +4 -4
  11. package/dist/fallback/index.d.ts +4 -4
  12. package/dist/fallback/index.js +75 -39
  13. package/dist/fallback/index.mjs +75 -39
  14. package/dist/index.d.mts +18 -35
  15. package/dist/index.d.ts +18 -35
  16. package/dist/index.js +304 -88
  17. package/dist/index.mjs +302 -89
  18. package/dist/providers/anthropic/index.d.mts +3 -3
  19. package/dist/providers/anthropic/index.d.ts +3 -3
  20. package/dist/providers/anthropic/index.js +123 -7
  21. package/dist/providers/anthropic/index.mjs +123 -7
  22. package/dist/providers/azure/index.d.mts +3 -3
  23. package/dist/providers/azure/index.d.ts +3 -3
  24. package/dist/providers/azure/index.js +101 -4
  25. package/dist/providers/azure/index.mjs +101 -4
  26. package/dist/providers/fireworks/index.d.mts +3 -3
  27. package/dist/providers/fireworks/index.d.ts +3 -3
  28. package/dist/providers/fireworks/index.js +559 -178
  29. package/dist/providers/fireworks/index.mjs +559 -178
  30. package/dist/providers/google/index.d.mts +3 -3
  31. package/dist/providers/google/index.d.ts +3 -3
  32. package/dist/providers/google/index.js +559 -178
  33. package/dist/providers/google/index.mjs +559 -178
  34. package/dist/providers/ollama/index.d.mts +4 -4
  35. package/dist/providers/ollama/index.d.ts +4 -4
  36. package/dist/providers/ollama/index.js +87 -2
  37. package/dist/providers/ollama/index.mjs +87 -2
  38. package/dist/providers/openai/index.d.mts +25 -23
  39. package/dist/providers/openai/index.d.ts +25 -23
  40. package/dist/providers/openai/index.js +1397 -481
  41. package/dist/providers/openai/index.mjs +1396 -482
  42. package/dist/providers/openrouter/index.d.mts +3 -3
  43. package/dist/providers/openrouter/index.d.ts +3 -3
  44. package/dist/providers/openrouter/index.js +559 -178
  45. package/dist/providers/openrouter/index.mjs +559 -178
  46. package/dist/providers/togetherai/index.d.mts +3 -3
  47. package/dist/providers/togetherai/index.d.ts +3 -3
  48. package/dist/providers/togetherai/index.js +559 -178
  49. package/dist/providers/togetherai/index.mjs +559 -178
  50. package/dist/providers/xai/index.d.mts +3 -3
  51. package/dist/providers/xai/index.d.ts +3 -3
  52. package/dist/providers/xai/index.js +559 -178
  53. package/dist/providers/xai/index.mjs +559 -178
  54. package/dist/{types-B6dhnguR.d.mts → types-C3RgRbEC.d.mts} +11 -4
  55. package/dist/{types-CCxPmkmK.d.ts → types-DCFqkJAy.d.ts} +11 -4
  56. package/dist/{types-BQ31QIsA.d.ts → types-DHQEMFHA.d.mts} +3 -11
  57. package/dist/{types-BkQCSiIt.d.mts → types-Dg1Bcg1k.d.mts} +127 -3
  58. package/dist/{types-BkQCSiIt.d.ts → types-Dg1Bcg1k.d.ts} +127 -3
  59. package/dist/{types-BSSiJW2o.d.mts → types-Dikj3En4.d.ts} +3 -11
  60. package/dist/yourgpt/index.d.mts +1 -1
  61. package/dist/yourgpt/index.d.ts +1 -1
  62. package/docs/multimodal-and-audio.md +170 -0
  63. package/package.json +117 -49
  64. package/LICENSE +0 -21
package/README.md CHANGED
@@ -10,6 +10,168 @@ npm install @yourgpt/llm-sdk @anthropic-ai/sdk
10
10
 
11
11
  > For other providers (OpenAI, Google, xAI), see [Providers Documentation](https://copilot-sdk.yourgpt.ai/docs/providers).
12
12
 
13
+ ## OpenAI reasoning parameters
14
+
15
+ The SDK normalizes token limits and sampling options for recognized OpenAI model
16
+ families, including GPT-6. Reasoning stays enabled by default. An unsupported
17
+ `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.
20
+
21
+ For a model that supports non-reasoning mode, select it explicitly when sampling
22
+ control is required:
23
+
24
+ ```ts
25
+ import { generateText } from "@yourgpt/llm-sdk";
26
+ import { openai } from "@yourgpt/llm-sdk/openai";
27
+
28
+ const result = await generateText({
29
+ model: openai("gpt-6-luna"),
30
+ prompt: "Classify this request.",
31
+ reasoningEffort: "none",
32
+ temperature: 0,
33
+ });
34
+ ```
35
+
36
+ `reasoningEffort` can also be set on `createOpenAI(...)` or `OpenAIAdapter` and
37
+ overridden in a Runtime request's `config`. Unsupported `none`/`minimal` settings
38
+ for recognized reasoning models fail before the provider request.
39
+
40
+ On OpenAI's own endpoint, GPT-5.4+ and GPT-6 tool requests with reasoning use the
41
+ existing Responses transport, in both Runtime and modern generation. Custom
42
+ endpoints keep Chat routing. Servers with different parameter rules can set
43
+ `parameterPolicy: "passthrough"` on the OpenAI provider. Responses requires an
44
+ installed OpenAI client that exposes `responses.create`; older clients fail with
45
+ an actionable error. This routing does not add the separate Decisions API.
46
+
47
+ ## OpenAI Responses and continuation
48
+
49
+ Select Responses explicitly, including calls without tools:
50
+
51
+ ```ts
52
+ import { generateText, streamText } from "@yourgpt/llm-sdk";
53
+ import { openai, createOpenAI } from "@yourgpt/llm-sdk/openai";
54
+
55
+ const model = openai("gpt-6-luna", {
56
+ api: "responses",
57
+ responses: { store: false },
58
+ });
59
+ const first = await generateText({ model, prompt: "Remember code ORBIT-42." });
60
+ const next = await streamText({
61
+ model,
62
+ messages: [
63
+ ...first.response.messages,
64
+ { role: "user", content: "What was the code?" },
65
+ ],
66
+ });
67
+ console.log(await next.text);
68
+ const history = (await next.response).messages;
69
+ const providerState = await next.providerMetadata;
70
+ ```
71
+
72
+ `api` accepts `"auto"` (the existing default routing), `"chat"`, and `"responses"`.
73
+ Responses options also select Responses. Default custom-endpoint routing remains
74
+ Chat; opt into Responses only when that endpoint implements it. Azure and other
75
+ compatible services are not certified by the OpenAI tests. Supplying
76
+ Responses-only options with `api: "chat"` fails before a network request.
77
+
78
+ The same options work on `createOpenAI({ api, responses })` for Runtime, and on
79
+ `OpenAIAdapter`. Per-call overrides use `generateText({ openai: { api, responses },
80
+ ... })` or `runtime.chat({ config: { openai: { api, responses } }, ... })`.
81
+ Request values override provider defaults. `reasoningEffort` remains a separate
82
+ existing option; `responses.reasoningSummary` requests a reasoning summary.
83
+
84
+ **Stateless replay:** use `store: false` and preserve the returned message objects,
85
+ 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.
92
+
93
+ `generateText().response.messages` now includes the final assistant turn as well
94
+ as tool turns. `streamText().response` returns the same complete history after
95
+ consuming its shared execution; accessing it does not make a second API call.
96
+ The Copilot client preserves provider state through JSON/SSE tool continuation
97
+ and serialized UI-message restoration. Custom `StorageAdapter` implementations
98
+ must retain `StorageMessage.metadata.providerMetadata`; map it back to the
99
+ message's top-level `providerMetadata` when restoring. The existing YourGPT cloud
100
+ storage adapter stores display/tool records and does **not** yet guarantee
101
+ lossless Responses replay after a remote session reload.
102
+
103
+ **Stored continuation:** explicitly use `store: true`, take the returned
104
+ `providerMetadata.openai.response.id`, and pass it as
105
+ `openai: { responses: { previousResponseId: id } }` on the next call. Send only new
106
+ input after that response, and resend system instructions; do not also resend
107
+ its entire history. The SDK does not automatically advance or persist response
108
+ IDs. If `store` is omitted, the provider default is unchanged (OpenAI currently
109
+ stores Responses by default).
110
+
111
+ Other supported Responses options are `include`, `promptCacheKey`,
112
+ `promptCacheOptions` (`mode`, `ttl`) and legacy `promptCacheRetention`
113
+ (`"in_memory"` or `"24h"`). With `store: false`, `reasoning.encrypted_content` is
114
+ included automatically. Cache options are forwarded; availability and retention
115
+ support remain model-specific. Raw usage preserves cache/reasoning breakdowns;
116
+ this does not add pricing/accounting logic.
117
+
118
+ 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.
122
+
123
+ The contracts were checked against [OpenAI conversation state](https://developers.openai.com/api/docs/guides/conversation-state),
124
+ [Responses request fields](https://developers.openai.com/api/reference/resources/responses/methods/create),
125
+ and [Vercel's OpenAI provider](https://ai-sdk.dev/providers/ai-sdk-providers/openai).
126
+ Offline checks run with `pnpm --filter @yourgpt/llm-sdk test`; Copilot integration
127
+ checks run with `pnpm test:compatibility` after building both SDKs. The optional
128
+ `test/live/responses.cjs` runner requires `RUN_OPENAI_LIVE=1` and a privately
129
+ supplied `OPENAI_API_KEY`; it makes real requests and deletes its synthetic stored
130
+ responses after testing continuation.
131
+
132
+ ## Compatibility fallback
133
+
134
+ Transient failures retain bounded retries and fallback. Compatibility errors such
135
+ as an unsupported parameter stop by default. To advance to another model for a
136
+ specific compatibility error without repeating the same invalid request, use
137
+ `fallbackErrors` independently of `retryableErrors`:
138
+
139
+ ```ts
140
+ import { createFallbackChain } from "@yourgpt/llm-sdk/fallback";
141
+ import { createOpenAI } from "@yourgpt/llm-sdk/openai";
142
+
143
+ const provider = createOpenAI();
144
+ const adapter = createFallbackChain({
145
+ models: [
146
+ provider.languageModel("gpt-6-luna"),
147
+ provider.languageModel("gpt-4o"),
148
+ ],
149
+ retries: 2,
150
+ fallbackErrors(error) {
151
+ const e = error as { status?: number; code?: string; param?: string };
152
+ return (
153
+ e?.status === 400 &&
154
+ e.code === "unsupported_parameter" &&
155
+ e.param === "temperature"
156
+ );
157
+ },
158
+ });
159
+ ```
160
+
161
+ This is an additional fallback policy for otherwise non-retryable errors. It does
162
+ not disable transient retries. Keep the predicate narrow; do not match every 400
163
+ or use `retryableErrors: () => true` for compatibility failures. Cancellation and
164
+ errors after stream output or tool events never retry or switch models. Provider
165
+ status/code/parameter fields survive OpenAI streaming errors; raw error causes
166
+ are retained only in-process and omitted from JSON/SSE output.
167
+
168
+ Stream readers and final-result promises share one execution, including tool
169
+ execution. Later readers replay retained stream parts; pass an abort signal to
170
+ cancel generation. Cancellation during a tool stops subsequent tools and rejects
171
+ the result rather than reporting a successful completion.
172
+ `pnpm --filter @yourgpt/llm-sdk test` builds the package and
173
+ runs offline provider/fallback regression tests without real API credentials.
174
+
13
175
  ## Quick Start
14
176
 
15
177
  ```ts
@@ -55,6 +217,25 @@ export async function POST(req: Request) {
55
217
  }
56
218
  ```
57
219
 
220
+ For Anthropic, Runtime accepts system instructions through either `systemPrompt`
221
+ or `{ role: "system", content: "..." }` messages. It combines them into
222
+ Anthropic's top-level `system` field: the request's nonempty `systemPrompt` (or
223
+ the runtime default) first, followed by system messages in order. System messages
224
+ are removed from the conversation sent to Anthropic. This applies to `chat`,
225
+ `generate`, `stream`, and `processChat`.
226
+
227
+ ```ts
228
+ const decision = await runtime.chat({
229
+ systemPrompt: "Classify the email. Do not answer it.",
230
+ messages: [{ role: "user", content: emailContext }],
231
+ });
232
+ ```
233
+
234
+ 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
237
+ already handles system-role messages.
238
+
58
239
  ## Selective Tool Loading
59
240
 
60
241
  `llm-sdk` can now narrow tools before they reach the provider. This is opt-in and works with both local ranking and provider-native hints.
@@ -126,3 +307,11 @@ Visit **[copilot-sdk.yourgpt.ai](https://copilot-sdk.yourgpt.ai)** for full docu
126
307
  ## License
127
308
 
128
309
  MIT
310
+
311
+ ### Image tool results and recorded audio
312
+
313
+ Tools can return native image content using `toModelOutput` or the existing `_aiContent` field. Supported endpoints are OpenAI Responses and Anthropic. Raw application results remain available, and model-facing output survives tool continuation and serialized history. Unsupported endpoints reject image output explicitly.
314
+
315
+ `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
+
317
+ See [image and audio contracts, examples, and limitations](./docs/multimodal-and-audio.md). Realtime voice calls and image generation are separate follow-ups.
@@ -1,13 +1,15 @@
1
- import { L as LLMAdapter, C as ChatCompletionRequest, a as CompletionResult } from '../base-tNgbBaSo.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-tNgbBaSo.mjs';
3
- import { W as WebSearchConfig, g as StreamEvent } from '../types-BkQCSiIt.mjs';
4
- import { d as OllamaModelOptions } from '../types-BSSiJW2o.mjs';
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';
5
5
  import 'zod';
6
6
 
7
7
  /**
8
8
  * OpenAI adapter configuration
9
9
  */
10
- interface OpenAIAdapterConfig {
10
+ interface OpenAIAdapterConfig extends OpenAIParameterOptions, OpenAITransportOptions {
11
+ organization?: string;
12
+ headers?: Record<string, string>;
11
13
  apiKey: string;
12
14
  model?: string;
13
15
  baseUrl?: string;
@@ -32,15 +34,9 @@ declare class OpenAIAdapter implements LLMAdapter {
32
34
  constructor(config: OpenAIAdapterConfig);
33
35
  private static resolveProviderName;
34
36
  private getClient;
37
+ private parameterOptions;
38
+ private toolDefinitions;
35
39
  private shouldUseResponsesApi;
36
- /**
37
- * Whether this model rejects function tools on /v1/chat/completions.
38
- *
39
- * Applies to OpenAI proper only — the adapter is reused for OpenAI-compatible
40
- * providers (Azure, xAI, Google, Fireworks) whose endpoints have no such
41
- * restriction and may not implement /v1/responses at all.
42
- */
43
- private requiresResponsesApiForTools;
44
40
  /**
45
41
  * Convert one message's content to Responses content parts.
46
42
  *
@@ -52,6 +48,8 @@ declare class OpenAIAdapter implements LLMAdapter {
52
48
  */
53
49
  private toResponsesContent;
54
50
  private buildResponsesInput;
51
+ /** Preserve Copilot screenshot attachments on every OpenAI transport. */
52
+ private formatRawMessages;
55
53
  /**
56
54
  * Build the web_search tool for the Responses API, or undefined when web
57
55
  * search is off.
@@ -1,13 +1,15 @@
1
- import { L as LLMAdapter, C as ChatCompletionRequest, a as CompletionResult } from '../base-C58Dsr9p.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-C58Dsr9p.js';
3
- import { W as WebSearchConfig, g as StreamEvent } from '../types-BkQCSiIt.js';
4
- import { d as OllamaModelOptions } from '../types-BQ31QIsA.js';
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';
5
5
  import 'zod';
6
6
 
7
7
  /**
8
8
  * OpenAI adapter configuration
9
9
  */
10
- interface OpenAIAdapterConfig {
10
+ interface OpenAIAdapterConfig extends OpenAIParameterOptions, OpenAITransportOptions {
11
+ organization?: string;
12
+ headers?: Record<string, string>;
11
13
  apiKey: string;
12
14
  model?: string;
13
15
  baseUrl?: string;
@@ -32,15 +34,9 @@ declare class OpenAIAdapter implements LLMAdapter {
32
34
  constructor(config: OpenAIAdapterConfig);
33
35
  private static resolveProviderName;
34
36
  private getClient;
37
+ private parameterOptions;
38
+ private toolDefinitions;
35
39
  private shouldUseResponsesApi;
36
- /**
37
- * Whether this model rejects function tools on /v1/chat/completions.
38
- *
39
- * Applies to OpenAI proper only — the adapter is reused for OpenAI-compatible
40
- * providers (Azure, xAI, Google, Fireworks) whose endpoints have no such
41
- * restriction and may not implement /v1/responses at all.
42
- */
43
- private requiresResponsesApiForTools;
44
40
  /**
45
41
  * Convert one message's content to Responses content parts.
46
42
  *
@@ -52,6 +48,8 @@ declare class OpenAIAdapter implements LLMAdapter {
52
48
  */
53
49
  private toResponsesContent;
54
50
  private buildResponsesInput;
51
+ /** Preserve Copilot screenshot attachments on every OpenAI transport. */
52
+ private formatRawMessages;
55
53
  /**
56
54
  * Build the web_search tool for the Responses API, or undefined when web
57
55
  * search is off.