@yourgpt/llm-sdk 2.5.1-beta.6 → 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.
Files changed (57) hide show
  1. package/README.md +77 -0
  2. package/dist/adapters/index.d.mts +54 -5
  3. package/dist/adapters/index.d.ts +54 -5
  4. package/dist/adapters/index.js +466 -169
  5. package/dist/adapters/index.mjs +466 -169
  6. package/dist/{base-C58Dsr9p.d.ts → base-BdTpUAWI.d.ts} +2 -1
  7. package/dist/{base-tNgbBaSo.d.mts → base-CkeT7u-O.d.mts} +2 -1
  8. package/dist/fallback/index.d.mts +4 -4
  9. package/dist/fallback/index.d.ts +4 -4
  10. package/dist/fallback/index.js +75 -39
  11. package/dist/fallback/index.mjs +75 -39
  12. package/dist/index.d.mts +8 -7
  13. package/dist/index.d.ts +8 -7
  14. package/dist/index.js +89 -30
  15. package/dist/index.mjs +89 -30
  16. package/dist/providers/anthropic/index.d.mts +3 -3
  17. package/dist/providers/anthropic/index.d.ts +3 -3
  18. package/dist/providers/azure/index.d.mts +3 -3
  19. package/dist/providers/azure/index.d.ts +3 -3
  20. package/dist/providers/azure/index.js +8 -3
  21. package/dist/providers/azure/index.mjs +8 -3
  22. package/dist/providers/fireworks/index.d.mts +3 -3
  23. package/dist/providers/fireworks/index.d.ts +3 -3
  24. package/dist/providers/fireworks/index.js +466 -169
  25. package/dist/providers/fireworks/index.mjs +466 -169
  26. package/dist/providers/google/index.d.mts +3 -3
  27. package/dist/providers/google/index.d.ts +3 -3
  28. package/dist/providers/google/index.js +466 -169
  29. package/dist/providers/google/index.mjs +466 -169
  30. package/dist/providers/ollama/index.d.mts +4 -4
  31. package/dist/providers/ollama/index.d.ts +4 -4
  32. package/dist/providers/openai/index.d.mts +6 -23
  33. package/dist/providers/openai/index.d.ts +6 -23
  34. package/dist/providers/openai/index.js +912 -500
  35. package/dist/providers/openai/index.mjs +912 -500
  36. package/dist/providers/openrouter/index.d.mts +3 -3
  37. package/dist/providers/openrouter/index.d.ts +3 -3
  38. package/dist/providers/openrouter/index.js +466 -169
  39. package/dist/providers/openrouter/index.mjs +466 -169
  40. package/dist/providers/togetherai/index.d.mts +3 -3
  41. package/dist/providers/togetherai/index.d.ts +3 -3
  42. package/dist/providers/togetherai/index.js +466 -169
  43. package/dist/providers/togetherai/index.mjs +466 -169
  44. package/dist/providers/xai/index.d.mts +3 -3
  45. package/dist/providers/xai/index.d.ts +3 -3
  46. package/dist/providers/xai/index.js +466 -169
  47. package/dist/providers/xai/index.mjs +466 -169
  48. package/dist/{types-BkQCSiIt.d.mts → types-BW3csYo5.d.mts} +22 -1
  49. package/dist/{types-BkQCSiIt.d.ts → types-BW3csYo5.d.ts} +22 -1
  50. package/dist/{types-B6dhnguR.d.mts → types-BWRYIvl_.d.mts} +11 -4
  51. package/dist/{types-CCxPmkmK.d.ts → types-CpXcT-tY.d.ts} +11 -4
  52. package/dist/{types-BQ31QIsA.d.ts → types-DA54bSmX.d.ts} +3 -11
  53. package/dist/{types-BSSiJW2o.d.mts → types-NOswlhm9.d.mts} +3 -11
  54. package/dist/yourgpt/index.d.mts +1 -1
  55. package/dist/yourgpt/index.d.ts +1 -1
  56. package/package.json +115 -48
  57. 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-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-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,11 +34,58 @@ 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;
40
+ /**
41
+ * Convert one message's content to Responses content parts.
42
+ *
43
+ * The Responses API does not accept Chat Completions content blocks: input
44
+ * parts are `input_text` / `input_image` (with a bare `image_url` string)
45
+ * rather than `text` / `image_url: { url }`. Passing the Chat Completions
46
+ * shape through unchanged makes the API reject the request, so anything
47
+ * array-shaped has to be translated rather than forwarded.
48
+ */
49
+ private toResponsesContent;
36
50
  private buildResponsesInput;
51
+ /** Preserve Copilot screenshot attachments on every OpenAI transport. */
52
+ private formatRawMessages;
53
+ /**
54
+ * Build the web_search tool for the Responses API, or undefined when web
55
+ * search is off.
56
+ *
57
+ * The Chat Completions path uses `web_search_preview`; the Responses API
58
+ * names the same built-in `web_search`. Without this, enabling web search
59
+ * alongside a gpt-5.4+ function tool silently did nothing, because routing
60
+ * to /v1/responses skipped the Chat Completions tool assembly entirely.
61
+ */
62
+ private buildResponsesWebSearchTool;
63
+ /**
64
+ * Extract url_citation annotations from Responses output items.
65
+ *
66
+ * Annotations hang off the output_text content parts rather than arriving as
67
+ * their own stream events, so both the streaming and non-streaming paths read
68
+ * them from the same place.
69
+ */
70
+ private collectResponsesCitations;
37
71
  private buildResponsesTools;
38
72
  private parseResponsesResult;
73
+ private buildResponsesPayload;
39
74
  private completeWithResponses;
75
+ /**
76
+ * Stream from /v1/responses as real SSE.
77
+ *
78
+ * The Responses API emits semantic events rather than Chat Completions
79
+ * deltas, so the interesting ones are:
80
+ * response.output_text.delta — incremental assistant text
81
+ * response.output_item.added — a function_call item begins (name/id)
82
+ * response.function_call_arguments.delta / .done — tool arguments
83
+ * response.completed — terminal, carries usage
84
+ *
85
+ * Tool calls are buffered and flushed as contiguous start→args→end triples
86
+ * because the runtime pairs action:args with the action:end that follows it.
87
+ */
88
+ private streamWithResponses;
40
89
  stream(request: ChatCompletionRequest): AsyncGenerator<StreamEvent>;
41
90
  complete(request: ChatCompletionRequest): Promise<CompletionResult>;
42
91
  }
@@ -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-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,11 +34,58 @@ 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;
40
+ /**
41
+ * Convert one message's content to Responses content parts.
42
+ *
43
+ * The Responses API does not accept Chat Completions content blocks: input
44
+ * parts are `input_text` / `input_image` (with a bare `image_url` string)
45
+ * rather than `text` / `image_url: { url }`. Passing the Chat Completions
46
+ * shape through unchanged makes the API reject the request, so anything
47
+ * array-shaped has to be translated rather than forwarded.
48
+ */
49
+ private toResponsesContent;
36
50
  private buildResponsesInput;
51
+ /** Preserve Copilot screenshot attachments on every OpenAI transport. */
52
+ private formatRawMessages;
53
+ /**
54
+ * Build the web_search tool for the Responses API, or undefined when web
55
+ * search is off.
56
+ *
57
+ * The Chat Completions path uses `web_search_preview`; the Responses API
58
+ * names the same built-in `web_search`. Without this, enabling web search
59
+ * alongside a gpt-5.4+ function tool silently did nothing, because routing
60
+ * to /v1/responses skipped the Chat Completions tool assembly entirely.
61
+ */
62
+ private buildResponsesWebSearchTool;
63
+ /**
64
+ * Extract url_citation annotations from Responses output items.
65
+ *
66
+ * Annotations hang off the output_text content parts rather than arriving as
67
+ * their own stream events, so both the streaming and non-streaming paths read
68
+ * them from the same place.
69
+ */
70
+ private collectResponsesCitations;
37
71
  private buildResponsesTools;
38
72
  private parseResponsesResult;
73
+ private buildResponsesPayload;
39
74
  private completeWithResponses;
75
+ /**
76
+ * Stream from /v1/responses as real SSE.
77
+ *
78
+ * The Responses API emits semantic events rather than Chat Completions
79
+ * deltas, so the interesting ones are:
80
+ * response.output_text.delta — incremental assistant text
81
+ * response.output_item.added — a function_call item begins (name/id)
82
+ * response.function_call_arguments.delta / .done — tool arguments
83
+ * response.completed — terminal, carries usage
84
+ *
85
+ * Tool calls are buffered and flushed as contiguous start→args→end triples
86
+ * because the runtime pairs action:args with the action:end that follows it.
87
+ */
88
+ private streamWithResponses;
40
89
  stream(request: ChatCompletionRequest): AsyncGenerator<StreamEvent>;
41
90
  complete(request: ChatCompletionRequest): Promise<CompletionResult>;
42
91
  }