@yourgpt/llm-sdk 2.6.0-beta.1 → 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.
- package/README.md +112 -0
- package/dist/adapters/index.d.mts +5 -5
- package/dist/adapters/index.d.ts +5 -5
- package/dist/adapters/index.js +372 -39
- package/dist/adapters/index.mjs +372 -39
- package/dist/audio-BBSwnjo8.d.mts +92 -0
- package/dist/audio-BBSwnjo8.d.ts +92 -0
- package/dist/{base-CkeT7u-O.d.mts → base-BICaQaRS.d.mts} +7 -3
- package/dist/{base-BdTpUAWI.d.ts → base-CpRPB8u8.d.ts} +7 -3
- package/dist/fallback/index.d.mts +4 -4
- package/dist/fallback/index.d.ts +4 -4
- package/dist/index.d.mts +17 -35
- package/dist/index.d.ts +17 -35
- package/dist/index.js +229 -60
- package/dist/index.mjs +227 -61
- package/dist/providers/anthropic/index.d.mts +3 -3
- package/dist/providers/anthropic/index.d.ts +3 -3
- package/dist/providers/anthropic/index.js +123 -7
- package/dist/providers/anthropic/index.mjs +123 -7
- package/dist/providers/azure/index.d.mts +3 -3
- package/dist/providers/azure/index.d.ts +3 -3
- package/dist/providers/azure/index.js +101 -4
- package/dist/providers/azure/index.mjs +101 -4
- package/dist/providers/fireworks/index.d.mts +3 -3
- package/dist/providers/fireworks/index.d.ts +3 -3
- package/dist/providers/fireworks/index.js +321 -31
- package/dist/providers/fireworks/index.mjs +321 -31
- package/dist/providers/google/index.d.mts +3 -3
- package/dist/providers/google/index.d.ts +3 -3
- package/dist/providers/google/index.js +321 -31
- package/dist/providers/google/index.mjs +321 -31
- package/dist/providers/ollama/index.d.mts +4 -4
- package/dist/providers/ollama/index.d.ts +4 -4
- package/dist/providers/ollama/index.js +87 -2
- package/dist/providers/ollama/index.mjs +87 -2
- package/dist/providers/openai/index.d.mts +25 -6
- package/dist/providers/openai/index.d.ts +25 -6
- package/dist/providers/openai/index.js +750 -40
- package/dist/providers/openai/index.mjs +749 -41
- package/dist/providers/openrouter/index.d.mts +3 -3
- package/dist/providers/openrouter/index.d.ts +3 -3
- package/dist/providers/openrouter/index.js +321 -31
- package/dist/providers/openrouter/index.mjs +321 -31
- package/dist/providers/togetherai/index.d.mts +3 -3
- package/dist/providers/togetherai/index.d.ts +3 -3
- package/dist/providers/togetherai/index.js +321 -31
- package/dist/providers/togetherai/index.mjs +321 -31
- package/dist/providers/xai/index.d.mts +3 -3
- package/dist/providers/xai/index.d.ts +3 -3
- package/dist/providers/xai/index.js +321 -31
- package/dist/providers/xai/index.mjs +321 -31
- package/dist/{types-BWRYIvl_.d.mts → types-C3RgRbEC.d.mts} +1 -1
- package/dist/{types-CpXcT-tY.d.ts → types-DCFqkJAy.d.ts} +1 -1
- package/dist/{types-NOswlhm9.d.mts → types-DHQEMFHA.d.mts} +3 -3
- package/dist/{types-BW3csYo5.d.mts → types-Dg1Bcg1k.d.mts} +106 -3
- package/dist/{types-BW3csYo5.d.ts → types-Dg1Bcg1k.d.ts} +106 -3
- package/dist/{types-DA54bSmX.d.ts → types-Dikj3En4.d.ts} +3 -3
- package/dist/yourgpt/index.d.mts +1 -1
- package/dist/yourgpt/index.d.ts +1 -1
- package/docs/multimodal-and-audio.md +170 -0
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -44,6 +44,91 @@ endpoints keep Chat routing. Servers with different parameter rules can set
|
|
|
44
44
|
installed OpenAI client that exposes `responses.create`; older clients fail with
|
|
45
45
|
an actionable error. This routing does not add the separate Decisions API.
|
|
46
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
|
+
|
|
47
132
|
## Compatibility fallback
|
|
48
133
|
|
|
49
134
|
Transient failures retain bounded retries and fallback. Compatibility errors such
|
|
@@ -132,6 +217,25 @@ export async function POST(req: Request) {
|
|
|
132
217
|
}
|
|
133
218
|
```
|
|
134
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
|
+
|
|
135
239
|
## Selective Tool Loading
|
|
136
240
|
|
|
137
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.
|
|
@@ -203,3 +307,11 @@ Visit **[copilot-sdk.yourgpt.ai](https://copilot-sdk.yourgpt.ai)** for full docu
|
|
|
203
307
|
## License
|
|
204
308
|
|
|
205
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,13 @@
|
|
|
1
|
-
import { L as LLMAdapter, C as ChatCompletionRequest, a as CompletionResult } from '../base-
|
|
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-
|
|
3
|
-
import {
|
|
4
|
-
import { d as OllamaModelOptions } from '../types-
|
|
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 extends OpenAIParameterOptions {
|
|
10
|
+
interface OpenAIAdapterConfig extends OpenAIParameterOptions, OpenAITransportOptions {
|
|
11
11
|
organization?: string;
|
|
12
12
|
headers?: Record<string, string>;
|
|
13
13
|
apiKey: string;
|
package/dist/adapters/index.d.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { L as LLMAdapter, C as ChatCompletionRequest, a as CompletionResult } from '../base-
|
|
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-
|
|
3
|
-
import {
|
|
4
|
-
import { d as OllamaModelOptions } from '../types-
|
|
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 extends OpenAIParameterOptions {
|
|
10
|
+
interface OpenAIAdapterConfig extends OpenAIParameterOptions, OpenAITransportOptions {
|
|
11
11
|
organization?: string;
|
|
12
12
|
headers?: Record<string, string>;
|
|
13
13
|
apiKey: string;
|