@yourgpt/llm-sdk 2.6.0-beta.0 → 2.6.0-beta.1
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 +77 -0
- package/dist/adapters/index.d.mts +11 -13
- package/dist/adapters/index.d.ts +11 -13
- package/dist/adapters/index.js +255 -164
- package/dist/adapters/index.mjs +255 -164
- package/dist/{base-C58Dsr9p.d.ts → base-BdTpUAWI.d.ts} +2 -1
- package/dist/{base-tNgbBaSo.d.mts → base-CkeT7u-O.d.mts} +2 -1
- package/dist/fallback/index.d.mts +4 -4
- package/dist/fallback/index.d.ts +4 -4
- package/dist/fallback/index.js +75 -39
- package/dist/fallback/index.mjs +75 -39
- package/dist/index.d.mts +8 -7
- package/dist/index.d.ts +8 -7
- package/dist/index.js +75 -28
- package/dist/index.mjs +75 -28
- package/dist/providers/anthropic/index.d.mts +3 -3
- package/dist/providers/anthropic/index.d.ts +3 -3
- package/dist/providers/azure/index.d.mts +3 -3
- package/dist/providers/azure/index.d.ts +3 -3
- package/dist/providers/fireworks/index.d.mts +3 -3
- package/dist/providers/fireworks/index.d.ts +3 -3
- package/dist/providers/fireworks/index.js +255 -164
- package/dist/providers/fireworks/index.mjs +255 -164
- package/dist/providers/google/index.d.mts +3 -3
- package/dist/providers/google/index.d.ts +3 -3
- package/dist/providers/google/index.js +255 -164
- package/dist/providers/google/index.mjs +255 -164
- package/dist/providers/ollama/index.d.mts +4 -4
- package/dist/providers/ollama/index.d.ts +4 -4
- package/dist/providers/openai/index.d.mts +6 -23
- package/dist/providers/openai/index.d.ts +6 -23
- package/dist/providers/openai/index.js +656 -450
- package/dist/providers/openai/index.mjs +656 -450
- package/dist/providers/openrouter/index.d.mts +3 -3
- package/dist/providers/openrouter/index.d.ts +3 -3
- package/dist/providers/openrouter/index.js +255 -164
- package/dist/providers/openrouter/index.mjs +255 -164
- package/dist/providers/togetherai/index.d.mts +3 -3
- package/dist/providers/togetherai/index.d.ts +3 -3
- package/dist/providers/togetherai/index.js +255 -164
- package/dist/providers/togetherai/index.mjs +255 -164
- package/dist/providers/xai/index.d.mts +3 -3
- package/dist/providers/xai/index.d.ts +3 -3
- package/dist/providers/xai/index.js +255 -164
- package/dist/providers/xai/index.mjs +255 -164
- package/dist/{types-BkQCSiIt.d.mts → types-BW3csYo5.d.mts} +22 -1
- package/dist/{types-BkQCSiIt.d.ts → types-BW3csYo5.d.ts} +22 -1
- package/dist/{types-B6dhnguR.d.mts → types-BWRYIvl_.d.mts} +11 -4
- package/dist/{types-CCxPmkmK.d.ts → types-CpXcT-tY.d.ts} +11 -4
- package/dist/{types-BQ31QIsA.d.ts → types-DA54bSmX.d.ts} +3 -11
- package/dist/{types-BSSiJW2o.d.mts → types-NOswlhm9.d.mts} +3 -11
- package/dist/yourgpt/index.d.mts +1 -1
- package/dist/yourgpt/index.d.ts +1 -1
- package/package.json +115 -48
- package/LICENSE +0 -21
package/README.md
CHANGED
|
@@ -10,6 +10,83 @@ 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
|
+
## Compatibility fallback
|
|
48
|
+
|
|
49
|
+
Transient failures retain bounded retries and fallback. Compatibility errors such
|
|
50
|
+
as an unsupported parameter stop by default. To advance to another model for a
|
|
51
|
+
specific compatibility error without repeating the same invalid request, use
|
|
52
|
+
`fallbackErrors` independently of `retryableErrors`:
|
|
53
|
+
|
|
54
|
+
```ts
|
|
55
|
+
import { createFallbackChain } from "@yourgpt/llm-sdk/fallback";
|
|
56
|
+
import { createOpenAI } from "@yourgpt/llm-sdk/openai";
|
|
57
|
+
|
|
58
|
+
const provider = createOpenAI();
|
|
59
|
+
const adapter = createFallbackChain({
|
|
60
|
+
models: [
|
|
61
|
+
provider.languageModel("gpt-6-luna"),
|
|
62
|
+
provider.languageModel("gpt-4o"),
|
|
63
|
+
],
|
|
64
|
+
retries: 2,
|
|
65
|
+
fallbackErrors(error) {
|
|
66
|
+
const e = error as { status?: number; code?: string; param?: string };
|
|
67
|
+
return (
|
|
68
|
+
e?.status === 400 &&
|
|
69
|
+
e.code === "unsupported_parameter" &&
|
|
70
|
+
e.param === "temperature"
|
|
71
|
+
);
|
|
72
|
+
},
|
|
73
|
+
});
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
This is an additional fallback policy for otherwise non-retryable errors. It does
|
|
77
|
+
not disable transient retries. Keep the predicate narrow; do not match every 400
|
|
78
|
+
or use `retryableErrors: () => true` for compatibility failures. Cancellation and
|
|
79
|
+
errors after stream output or tool events never retry or switch models. Provider
|
|
80
|
+
status/code/parameter fields survive OpenAI streaming errors; raw error causes
|
|
81
|
+
are retained only in-process and omitted from JSON/SSE output.
|
|
82
|
+
|
|
83
|
+
Stream readers and final-result promises share one execution, including tool
|
|
84
|
+
execution. Later readers replay retained stream parts; pass an abort signal to
|
|
85
|
+
cancel generation. Cancellation during a tool stops subsequent tools and rejects
|
|
86
|
+
the result rather than reporting a successful completion.
|
|
87
|
+
`pnpm --filter @yourgpt/llm-sdk test` builds the package and
|
|
88
|
+
runs offline provider/fallback regression tests without real API credentials.
|
|
89
|
+
|
|
13
90
|
## Quick Start
|
|
14
91
|
|
|
15
92
|
```ts
|
|
@@ -1,13 +1,15 @@
|
|
|
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 { W as WebSearchConfig, g as StreamEvent } from '../types-
|
|
4
|
-
import { d as OllamaModelOptions } from '../types-
|
|
1
|
+
import { L as LLMAdapter, C as ChatCompletionRequest, a as CompletionResult } from '../base-CkeT7u-O.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-CkeT7u-O.mjs';
|
|
3
|
+
import { a7 as OpenAIParameterOptions, W as WebSearchConfig, g as StreamEvent } from '../types-BW3csYo5.mjs';
|
|
4
|
+
import { d as OllamaModelOptions } from '../types-NOswlhm9.mjs';
|
|
5
5
|
import 'zod';
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* OpenAI adapter configuration
|
|
9
9
|
*/
|
|
10
|
-
interface OpenAIAdapterConfig {
|
|
10
|
+
interface OpenAIAdapterConfig extends OpenAIParameterOptions {
|
|
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.
|
package/dist/adapters/index.d.ts
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
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 { W as WebSearchConfig, g as StreamEvent } from '../types-
|
|
4
|
-
import { d as OllamaModelOptions } from '../types-
|
|
1
|
+
import { L as LLMAdapter, C as ChatCompletionRequest, a as CompletionResult } from '../base-BdTpUAWI.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-BdTpUAWI.js';
|
|
3
|
+
import { a7 as OpenAIParameterOptions, W as WebSearchConfig, g as StreamEvent } from '../types-BW3csYo5.js';
|
|
4
|
+
import { d as OllamaModelOptions } from '../types-DA54bSmX.js';
|
|
5
5
|
import 'zod';
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* OpenAI adapter configuration
|
|
9
9
|
*/
|
|
10
|
-
interface OpenAIAdapterConfig {
|
|
10
|
+
interface OpenAIAdapterConfig extends OpenAIParameterOptions {
|
|
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.
|