@to11ai/sdk 3.1.0-rc → 4.0.0-rc.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 (51) hide show
  1. package/README.md +30 -42
  2. package/dist/behaviors/store.d.ts +1 -1
  3. package/dist/client.cjs +17 -71
  4. package/dist/client.d.ts +16 -112
  5. package/dist/client.js +22 -72
  6. package/dist/config.d.ts +3 -6
  7. package/dist/errors.cjs +0 -72
  8. package/dist/errors.d.ts +0 -77
  9. package/dist/errors.js +0 -72
  10. package/dist/generated/index.d.ts +1 -1
  11. package/dist/generated/types.gen.d.ts +2962 -17155
  12. package/dist/generated/zod.gen.d.ts +2576 -11477
  13. package/dist/projectEnvironments/resource.cjs +0 -2
  14. package/dist/projectEnvironments/resource.d.ts +3 -12
  15. package/dist/projectEnvironments/resource.js +0 -2
  16. package/dist/projectEnvironments/types.d.ts +0 -2
  17. package/dist/{gateway.d.ts → prompts/convert.d.ts} +12 -75
  18. package/dist/prompts/resource.d.ts +7 -7
  19. package/dist/prompts/shape.d.ts +4 -5
  20. package/dist/prompts/types.d.ts +5 -17
  21. package/package.json +7 -24
  22. package/src/behaviors/store.ts +1 -1
  23. package/src/client.ts +36 -242
  24. package/src/config.ts +3 -9
  25. package/src/errors.ts +0 -132
  26. package/src/generated/index.ts +1 -1
  27. package/src/generated/types.gen.ts +2889 -17652
  28. package/src/generated/zod.gen.ts +1980 -9967
  29. package/src/projectEnvironments/resource.ts +3 -14
  30. package/src/projectEnvironments/types.ts +0 -2
  31. package/src/{gateway.ts → prompts/convert.ts} +18 -152
  32. package/src/prompts/resource.ts +10 -12
  33. package/src/prompts/shape.ts +4 -5
  34. package/src/prompts/types.ts +5 -17
  35. package/src/transport.ts +0 -133
  36. package/dist/context.d.ts +0 -124
  37. package/dist/gateway.cjs +0 -264
  38. package/dist/gateway.js +0 -226
  39. package/dist/routingRules/resource.d.ts +0 -64
  40. package/dist/routingRules/types.d.ts +0 -88
  41. package/dist/traceparent.d.ts +0 -61
  42. package/dist/usage/resource.cjs +0 -113
  43. package/dist/usage/resource.d.ts +0 -29
  44. package/dist/usage/resource.js +0 -78
  45. package/dist/usage/types.d.ts +0 -81
  46. package/src/context.ts +0 -196
  47. package/src/routingRules/resource.ts +0 -261
  48. package/src/routingRules/types.ts +0 -120
  49. package/src/traceparent.ts +0 -189
  50. package/src/usage/resource.ts +0 -183
  51. package/src/usage/types.ts +0 -121
@@ -111,8 +111,6 @@ class ProjectEnvironmentResource {
111
111
  body.description = rest.description;
112
112
  if (rest.isDefault !== undefined)
113
113
  body.isDefault = rest.isDefault;
114
- if (rest.isGatewayFallback !== undefined)
115
- body.isGatewayFallback = rest.isGatewayFallback;
116
114
  if (rest.sortOrder !== undefined)
117
115
  body.sortOrder = rest.sortOrder;
118
116
  const envelope = await this.transport.request("PATCH", projectEnvironmentPath(projectId, slug), { body });
@@ -37,10 +37,6 @@ export declare class ProjectEnvironmentResource {
37
37
  * `slug` must match lowercase-kebab (`a-z`, `0-9`, `-`, 1..63 chars).
38
38
  * Reserved system slugs (`prod`, `staging`) and any already-used slug
39
39
  * return 409 `ENVIRONMENT_SLUG_TAKEN`.
40
- *
41
- * Setting `isGatewayFallback: true` additionally requires the
42
- * `project:manage_default_environment` capability; the create use
43
- * case clears the flag on any other env in the same project.
44
40
  */
45
41
  create(input: CreateProjectEnvironmentInput): Promise<CreateProjectEnvironmentResult>;
46
42
  /**
@@ -49,11 +45,7 @@ export declare class ProjectEnvironmentResource {
49
45
  * - System envs (`isSystem: true`) reject `slug`/`isSystem`/immutable-
50
46
  * field mutations with 409 `SYSTEM_ENV_IMMUTABLE`.
51
47
  * - Renaming via `newSlug` triggers a 7-day alias row server-side so
52
- * in-flight gateway requests carrying the old slug keep resolving.
53
- * - Mutating `isGatewayFallback` requires the
54
- * `project:manage_default_environment` capability AND the target
55
- * env must have at least one live snapshot (else 409
56
- * `FALLBACK_ENV_NOT_READY`).
48
+ * the old slug keeps resolving.
57
49
  *
58
50
  * The SDK marshals `newSlug` onto the wire as `slug` (the API accepts
59
51
  * `slug` on the PATCH body for a rename — the URL slug stays the
@@ -64,9 +56,8 @@ export declare class ProjectEnvironmentResource {
64
56
  * Soft-archive an environment. The response carries the archived row
65
57
  * under `environment`.
66
58
  *
67
- * System envs (`isSystem: true`) and the current gateway-fallback env
68
- * cannot be archived; the API returns 409 `SYSTEM_ENV_IMMUTABLE` or
69
- * `CANNOT_ARCHIVE_GATEWAY_FALLBACK` respectively.
59
+ * System envs (`isSystem: true`) cannot be archived; the API returns
60
+ * 409 `SYSTEM_ENV_IMMUTABLE`.
70
61
  *
71
62
  * Uses `POST /:slug/archive` rather than `DELETE` so the server can
72
63
  * return a structured 200 with the archived row.
@@ -68,8 +68,6 @@ class ProjectEnvironmentResource {
68
68
  body.description = rest.description;
69
69
  if (rest.isDefault !== undefined)
70
70
  body.isDefault = rest.isDefault;
71
- if (rest.isGatewayFallback !== undefined)
72
- body.isGatewayFallback = rest.isGatewayFallback;
73
71
  if (rest.sortOrder !== undefined)
74
72
  body.sortOrder = rest.sortOrder;
75
73
  const envelope = await this.transport.request("PATCH", projectEnvironmentPath(projectId, slug), { body });
@@ -31,7 +31,6 @@ export interface CreateProjectEnvironmentInput {
31
31
  color?: string | null;
32
32
  description?: string | null;
33
33
  isDefault?: boolean;
34
- isGatewayFallback?: boolean;
35
34
  sortOrder?: number;
36
35
  }
37
36
  export type CreateProjectEnvironmentResult = ProjectEnvironment;
@@ -43,7 +42,6 @@ export interface UpdateProjectEnvironmentInput {
43
42
  color?: string | null;
44
43
  description?: string | null;
45
44
  isDefault?: boolean;
46
- isGatewayFallback?: boolean;
47
45
  sortOrder?: number;
48
46
  }
49
47
  export type UpdateProjectEnvironmentResult = ProjectEnvironment;
@@ -1,68 +1,9 @@
1
- import { type RenderedChatMessage, type ResolvedPrompt, type ResolvedToolDefinition, type UnknownRoleMode } from "./prompts/types";
2
- export interface GatewayAuthOptions {
3
- apiKey: string;
4
- projectId: string;
5
- /**
6
- * Optional environment slug routed via the gateway's `x-to11-env`
7
- * header. When omitted, the gateway falls back to the project's
8
- * `is_gateway_fallback=true` environment; if no fallback exists, the
9
- * request fails with `400 missing_env_no_project_default`.
10
- *
11
- * Slug validation matches the project-environments registry:
12
- * lowercase-kebab (`^[a-z0-9-]{1,63}$`). The SDK rejects empty /
13
- * whitespace-only values and any value that violates this slug rule
14
- * eagerly so misconfiguration surfaces before the request hits the wire.
15
- */
16
- env?: string;
17
- }
18
- /**
19
- * Build the auth headers required for every request through the to11 gateway.
20
- *
21
- * Includes `x-to11-env: <slug>` when `options.env` is set — see the
22
- * environments-registry spec for gateway routing semantics. Empty /
23
- * whitespace-only and registry-invalid env values (anything outside
24
- * `^[a-z0-9-]{1,63}$`) throw immediately so caller misconfiguration is loud.
25
- *
26
- * @example
27
- * const headers = gatewayAuthHeaders({ apiKey, projectId });
28
- * @example
29
- * const headers = gatewayAuthHeaders({ apiKey, projectId, env: "staging" });
30
- */
31
- export declare function gatewayAuthHeaders(options: GatewayAuthOptions): Record<string, string>;
32
1
  /**
33
- * Build prompt provenance headers from a `render()` result (or a format-shaped
34
- * result's `metadata`, unwrapped automatically).
35
- *
36
- * No provenance header is required, and the gateway rejects empty header
37
- * values — so each header is emitted only when its value is present and valid,
38
- * and the function never throws:
39
- * - `x-to11-prompt-id` — a non-empty string.
40
- * - `x-to11-prompt-version` — a finite number (a non-number/NaN is dropped
41
- * rather than stringified to junk like `"[object Object]"`).
42
- * - `x-to11-prompt-label` — the single label the prompt resolved through.
43
- * - `x-to11-prompt-slug` — the prompt's human-readable slug.
44
- *
45
- * An input with no usable provenance yields an empty header bag — the same as
46
- * a prompt-less `turn.headers()` call.
47
- *
48
- * @example
49
- * const result = await client.prompts.render(slug);
50
- * const headers = gatewayPromptHeaders(result);
2
+ * Provider-shape converters: reshape the provider-neutral resolved data
3
+ * (`tools`, rendered `messages`) into the shapes the OpenAI / Anthropic clients
4
+ * expect. Pure and side-effect free; they never send a request.
51
5
  */
52
- export interface GatewayPromptProvenance {
53
- promptId: string;
54
- version: number;
55
- /** The label the prompt resolved through (`latest` unless pinned). */
56
- label: string;
57
- /**
58
- * The prompt's human-readable slug (the `render()`/`resolve()` input). Present
59
- * on an enriched `render()` result; a legacy `ResolvedPrompt` omits it.
60
- */
61
- slug?: string;
62
- }
63
- export declare function gatewayPromptHeaders(prompt: GatewayPromptProvenance | {
64
- metadata: GatewayPromptProvenance;
65
- }): Record<string, string>;
6
+ import type { RenderedChatMessage, ResolvedPrompt, ResolvedToolDefinition, UnknownRoleMode } from "./types";
66
7
  /** OpenAI Chat Completions `tools[]` entry (`function` tool). */
67
8
  export interface OpenAITool {
68
9
  type: "function";
@@ -95,7 +36,7 @@ export interface OpenAIToolCall {
95
36
  * `ChatCompletionMessageParam[]` (a `render({ format: "openai" })` result spreads
96
37
  * straight into `openai.chat.completions.create({ messages })` with no cast).
97
38
  * The SDK carries no dependency on the `openai` package — this only mirrors its
98
- * shape. (Assignability is regression-guarded in `gateway.provider-types.test.ts`.)
39
+ * shape. (Assignability is regression-guarded in `convert.provider-types.test.ts`.)
99
40
  */
100
41
  export type OpenAIChatMessage = {
101
42
  role: "system";
@@ -237,9 +178,8 @@ export declare function toOpenAIMessages(messages: ReadonlyArray<RenderedChatMes
237
178
  * Shape rendered turns for the Anthropic Messages `messages` field.
238
179
  *
239
180
  * - `system` / `developer` turns are OMITTED — Anthropic carries instruction
240
- * content in the top-level `system` parameter, not the `messages` array
241
- * (mirrors the gateway's `developer`→`system` fold). Pass them to `system`
242
- * yourself.
181
+ * content in the top-level `system` parameter, not the `messages` array.
182
+ * Pass them to `system` yourself (see {@link toAnthropicSystem}).
243
183
  * - `user` → `{ role: "user", content }`.
244
184
  * - `assistant` with `toolCalls` → `{ role: "assistant", content: [text?,
245
185
  * ...tool_use] }`; without calls → `{ role: "assistant", content }`.
@@ -264,13 +204,10 @@ export declare function toAnthropicMessages(messages: ReadonlyArray<RenderedChat
264
204
  * when there is no system/developer content.
265
205
  *
266
206
  * @example
267
- * const res = await anthropic.messages.create(
268
- * {
269
- * ...prompt.config,
270
- * system: toAnthropicSystem(prompt.messages),
271
- * messages: toAnthropicMessages(prompt.messages),
272
- * },
273
- * { headers: to11.turn().headers(prompt) },
274
- * );
207
+ * const res = await anthropic.messages.create({
208
+ * ...prompt.config,
209
+ * system: toAnthropicSystem(prompt.messages),
210
+ * messages: toAnthropicMessages(prompt.messages),
211
+ * });
275
212
  */
276
213
  export declare function toAnthropicSystem(messages: ReadonlyArray<RenderedChatMessage>): string | undefined;
@@ -78,8 +78,7 @@ export declare class PromptResource<F extends RenderFormat | undefined = undefin
78
78
  /**
79
79
  * Skills across every project of `orgId` the caller may read prompts in,
80
80
  * each with the version its `latest` label serves at listing time. At most
81
- * `limit` rows (default 20, max 50): a picker, not a list to page. Projects
82
- * the read left out are listed in `excludedProjects`.
81
+ * `limit` rows (default 20, max 50): a picker, not a list to page.
83
82
  */
84
83
  listOrgPrompts(input: ListOrgPromptsInput): Promise<ListOrgPromptsResult>;
85
84
  /**
@@ -96,14 +95,15 @@ export declare class PromptResource<F extends RenderFormat | undefined = undefin
96
95
  * `{ messages, config, metadata }`; without one it is the neutral
97
96
  * `RenderedPrompt`. Serves `latest` unless the call pins a `label`.
98
97
  *
99
- * @example Render an OpenAI-shaped prompt and send it through the gateway
98
+ * @example Render an OpenAI-shaped prompt and send it with your own client
100
99
  * const prompt = await to11.prompts.render("weather-concierge", {
100
+ * format: "openai",
101
101
  * variables: { city: "NYC" },
102
102
  * });
103
- * const res = await openai.chat.completions.create(
104
- * { ...prompt.config, messages: prompt.messages },
105
- * { headers: to11.turn().headers(prompt) },
106
- * );
103
+ * const res = await openai.chat.completions.create({
104
+ * ...prompt.config,
105
+ * messages: prompt.messages,
106
+ * });
107
107
  */
108
108
  render(slug: string, options: RenderOptions & {
109
109
  format: "openai";
@@ -1,10 +1,9 @@
1
1
  /**
2
2
  * Format-at-load shaping: turn a neutral `RenderedPrompt` into a provider-shaped
3
3
  * `{ messages, config, metadata }` result the caller spreads into their own
4
- * provider `create()` call. Header-only — this only reshapes data, it never
5
- * sends a request. See docs/archive-2026-08/specs/2026-07-14-to11-2691-sdk-simpler-setup.md.
4
+ * provider `create()` call. This only reshapes data; it never sends a request.
6
5
  */
7
- import { type AnthropicMessage, type AnthropicTool, type AnthropicToolChoice, type ConvertMessagesOptions, type OpenAIChatMessage, type OpenAITool, type OpenAIToolChoice } from "../gateway";
6
+ import { type AnthropicMessage, type AnthropicTool, type AnthropicToolChoice, type ConvertMessagesOptions, type OpenAIChatMessage, type OpenAITool, type OpenAIToolChoice } from "./convert";
8
7
  import type { RenderedPrompt, RenderFormat } from "./types";
9
8
  /** Model params passed through verbatim from the resolved version's modelConfig. */
10
9
  export interface PromptConfig {
@@ -14,14 +13,14 @@ export interface PromptConfig {
14
13
  /** Any additional stored model-config keys are passed through unchanged. */
15
14
  [key: string]: unknown;
16
15
  }
17
- /** Prompt provenance for `turn.headers()` — kept apart from the request body. */
16
+ /** Prompt provenance (id, version, label, slug), kept apart from the request body. */
18
17
  export interface PromptMetadata {
19
18
  promptId: string;
20
19
  versionId: string;
21
20
  version: number;
22
21
  /** The label the prompt resolved through (`latest` unless pinned). */
23
22
  label: string;
24
- /** The prompt's human-readable slug — surfaced as `x-to11-prompt-slug`. */
23
+ /** The prompt's human-readable slug (the `render()` input). */
25
24
  slug: string;
26
25
  }
27
26
  /** OpenAI-shaped render result: spread `{ ...config, messages }` into create(). */
@@ -142,11 +142,8 @@ export type IterateLabelsInput = Omit<ListPromptLabelsInput, "cursor">;
142
142
  /** One page of a prompt's labels, by label name. Today only `latest`. */
143
143
  export type ListPromptLabelsResult = CursorPaginatedResult<PromptLabelPointer>;
144
144
  /**
145
- * Slug rule shared by the client `env` (the gateway's `x-to11-env` routing key)
146
- * and a `render()` label — lowercase-kebab, 1-63 chars. Both are routing keys,
147
- * and case-insensitive routing keys invite silent "production" vs "Production"
148
- * mismatches, so the rule is strict (no uppercase, no underscores) — do not
149
- * loosen.
145
+ * Slug rule for a `render()` label (the project-environments slug rule):
146
+ * lowercase-kebab, 1-63 chars, no uppercase, no underscores.
150
147
  */
151
148
  export declare const ENV_SLUG_REGEX: RegExp;
152
149
  export type BlockRenderRecord = Record<string, "rendered" | "dimmed">;
@@ -157,17 +154,9 @@ export interface RenderedPrompt {
157
154
  promptId: string;
158
155
  versionId: string;
159
156
  contentHash: string;
160
- /**
161
- * The label the prompt resolved through (`latest` unless the call pinned
162
- * one). Surfaced as `x-to11-prompt-label` by `gatewayPromptHeaders` /
163
- * `turn.headers()` (TO11-2725).
164
- */
157
+ /** The label the prompt resolved through (`latest` unless the call pinned one). */
165
158
  label: string;
166
- /**
167
- * The prompt's human-readable slug (the `render()` input). Surfaced as
168
- * `x-to11-prompt-slug` by `gatewayPromptHeaders` / `turn.headers()` so traces
169
- * carry a readable name alongside the opaque `promptId` (TO11-2727).
170
- */
159
+ /** The prompt's human-readable slug (the `render()` input). */
171
160
  slug: string;
172
161
  /**
173
162
  * The served version's model config (model, temperature, max_tokens, …),
@@ -196,8 +185,7 @@ export type ResolvedPromptEnvelope = GenResolvedPrompt;
196
185
  export interface RenderOptions {
197
186
  /**
198
187
  * Label to resolve this call's prompt version. `latest` (the newest version)
199
- * is the only label a prompt carries, and the default when omitted. The
200
- * client's `env` is gateway routing and never stands in for a label.
188
+ * is the only label a prompt carries, and the default when omitted.
201
189
  */
202
190
  label?: string;
203
191
  variables?: Record<string, unknown>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@to11ai/sdk",
3
- "version": "3.1.0-rc",
3
+ "version": "4.0.0-rc.1",
4
4
  "license": "MPL-2.0",
5
5
  "repository": {
6
6
  "type": "git",
@@ -44,14 +44,6 @@
44
44
  "require": "./dist/projectEnvironments/resource.cjs",
45
45
  "default": "./dist/projectEnvironments/resource.js"
46
46
  },
47
- "./usage": {
48
- "types": "./dist/usage/resource.d.ts",
49
- "bun": "./src/usage/resource.ts",
50
- "deno": "./src/usage/resource.ts",
51
- "import": "./dist/usage/resource.js",
52
- "require": "./dist/usage/resource.cjs",
53
- "default": "./dist/usage/resource.js"
54
- },
55
47
  "./errors": {
56
48
  "types": "./dist/errors.d.ts",
57
49
  "bun": "./src/errors.ts",
@@ -59,14 +51,6 @@
59
51
  "import": "./dist/errors.js",
60
52
  "require": "./dist/errors.cjs",
61
53
  "default": "./dist/errors.js"
62
- },
63
- "./gateway": {
64
- "types": "./dist/gateway.d.ts",
65
- "bun": "./src/gateway.ts",
66
- "deno": "./src/gateway.ts",
67
- "import": "./dist/gateway.js",
68
- "require": "./dist/gateway.cjs",
69
- "default": "./dist/gateway.js"
70
54
  }
71
55
  },
72
56
  "publishConfig": {
@@ -75,8 +59,8 @@
75
59
  "scripts": {
76
60
  "build": "bun run build:clean && bun run build:esm && bun run build:cjs && bun run build:types",
77
61
  "build:clean": "rm -rf dist",
78
- "build:esm": "bun build src/client.ts src/prompts/resource.ts src/projectEnvironments/resource.ts src/usage/resource.ts src/errors.ts src/gateway.ts --outdir dist --target node --format esm --external '*'",
79
- "build:cjs": "bun build src/client.ts src/prompts/resource.ts src/projectEnvironments/resource.ts src/usage/resource.ts src/errors.ts src/gateway.ts --outdir dist --target node --format cjs --external '*' --entry-naming '[dir]/[name].cjs'",
62
+ "build:esm": "bun build src/client.ts src/prompts/resource.ts src/projectEnvironments/resource.ts src/errors.ts --outdir dist --target node --format esm --external '*'",
63
+ "build:cjs": "bun build src/client.ts src/prompts/resource.ts src/projectEnvironments/resource.ts src/errors.ts --outdir dist --target node --format cjs --external '*' --entry-naming '[dir]/[name].cjs'",
80
64
  "build:types": "tsc -p tsconfig.build.json",
81
65
  "prepack": "bun run build",
82
66
  "codegen": "openapi-ts",
@@ -90,12 +74,11 @@
90
74
  "format": "biome format --write ."
91
75
  },
92
76
  "devDependencies": {
93
- "@anthropic-ai/sdk": "^0.137.0",
94
- "@biomejs/biome": "2.6.2",
77
+ "@anthropic-ai/sdk": "^1.14.0",
78
+ "@biomejs/biome": "2.6.9",
95
79
  "@hey-api/openapi-ts": "0.99.0",
96
- "@opentelemetry/api": "^1.9.1",
97
- "@types/bun": "^1.4.4",
98
- "openai": "^4.104.0",
80
+ "@types/bun": "^1.4.5",
81
+ "openai": "^7.64.0",
99
82
  "typescript": "^6.0.3"
100
83
  },
101
84
  "dependencies": {
@@ -3,7 +3,7 @@
3
3
  *
4
4
  * The to11 platform evaluates flags that influence *shipped-SDK behavior*
5
5
  * server-side and delivers their values on the optional `sdkBehavior` field of
6
- * the success envelope (PRD Decision 7). This SDK carries **no** LaunchDarkly
6
+ * the success envelope (PRD Decision 7). This SDK carries **no** feature-flag vendor
7
7
  * dependency and never connects to to11's control plane — it only reads the
8
8
  * value the server already evaluated.
9
9
  *