@to11ai/sdk 2.0.0-rc.1 → 2.0.0-rc.3

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.
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Format-at-load shaping: turn a neutral `FetchedPrompt` into a provider-shaped
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
4
  * provider `create()` call. Header-only — this only reshapes data, it never
5
5
  * sends a request. See docs/product-specs/2026-07-14-to11-2691-sdk-simpler-setup.md.
@@ -21,7 +21,7 @@ import {
21
21
  toOpenAIToolChoice,
22
22
  toOpenAITools,
23
23
  } from "../gateway";
24
- import type { FetchedPrompt, RenderFormat } from "./types";
24
+ import type { RenderedPrompt, RenderFormat } from "./types";
25
25
 
26
26
  /** Model params passed through verbatim from the resolved version's modelConfig. */
27
27
  export interface PromptConfig {
@@ -42,6 +42,8 @@ export interface PromptMetadata {
42
42
  releaseId: string | null;
43
43
  /** The single label the prompt resolved through (env slug today). */
44
44
  label: string;
45
+ /** The prompt's human-readable slug — surfaced as `x-to11-prompt-slug`. */
46
+ slug: string;
45
47
  variantName?: string;
46
48
  }
47
49
 
@@ -75,7 +77,7 @@ export type RenderResult<F extends RenderFormat | undefined> =
75
77
  ? OpenAiRenderedPrompt
76
78
  : F extends "anthropic"
77
79
  ? AnthropicRenderedPrompt
78
- : FetchedPrompt;
80
+ : RenderedPrompt;
79
81
 
80
82
  function toPromptConfig(modelConfig: unknown): PromptConfig {
81
83
  return modelConfig !== null && typeof modelConfig === "object"
@@ -83,13 +85,14 @@ function toPromptConfig(modelConfig: unknown): PromptConfig {
83
85
  : {};
84
86
  }
85
87
 
86
- function toMetadata(prompt: FetchedPrompt): PromptMetadata {
88
+ function toMetadata(prompt: RenderedPrompt): PromptMetadata {
87
89
  const metadata: PromptMetadata = {
88
90
  promptId: prompt.promptId,
89
91
  versionId: prompt.versionId,
90
92
  version: prompt.version,
91
93
  releaseId: prompt.releaseId,
92
94
  label: prompt.label,
95
+ slug: prompt.slug,
93
96
  };
94
97
  if (prompt.variantName !== undefined)
95
98
  metadata.variantName = prompt.variantName;
@@ -97,7 +100,7 @@ function toMetadata(prompt: FetchedPrompt): PromptMetadata {
97
100
  }
98
101
 
99
102
  export function shapeOpenAI(
100
- prompt: FetchedPrompt,
103
+ prompt: RenderedPrompt,
101
104
  options: ConvertMessagesOptions = {},
102
105
  ): OpenAiRenderedPrompt {
103
106
  const result: OpenAiRenderedPrompt = {
@@ -115,7 +118,7 @@ export function shapeOpenAI(
115
118
  }
116
119
 
117
120
  export function shapeAnthropic(
118
- prompt: FetchedPrompt,
121
+ prompt: RenderedPrompt,
119
122
  options: ConvertMessagesOptions = {},
120
123
  ): AnthropicRenderedPrompt {
121
124
  const result: AnthropicRenderedPrompt = {
@@ -134,10 +137,10 @@ export function shapeAnthropic(
134
137
 
135
138
  /** Shape a fetched prompt for `format`, or return it neutral when unset. */
136
139
  export function shapePrompt(
137
- prompt: FetchedPrompt,
140
+ prompt: RenderedPrompt,
138
141
  format: RenderFormat | undefined,
139
142
  options: ConvertMessagesOptions = {},
140
- ): FetchedPrompt | OpenAiRenderedPrompt | AnthropicRenderedPrompt {
143
+ ): RenderedPrompt | OpenAiRenderedPrompt | AnthropicRenderedPrompt {
141
144
  switch (format) {
142
145
  case "openai":
143
146
  return shapeOpenAI(prompt, options);
@@ -6,7 +6,6 @@ import type {
6
6
  PromptLabelPointer as GenPromptLabelPointer,
7
7
  PromptVersion as GenPromptVersion,
8
8
  RenderedChatPrompt as GenRenderedChatPrompt,
9
- RenderedPrompt as GenRenderedPrompt,
10
9
  ResolvedPrompt as GenResolvedPrompt,
11
10
  ResolvedToolCall as GenResolvedToolCall,
12
11
  ResolvedToolDefinition as GenResolvedToolDefinition,
@@ -36,8 +35,6 @@ export type ChatMessage = TextChatMessage;
36
35
 
37
36
  export type RenderedChatMessage = GenRenderedChatPrompt["messages"][number];
38
37
 
39
- export type RenderedPrompt = GenRenderedPrompt;
40
-
41
38
  /** Provider shape for `prompts.render()` output. Omit for the neutral result. */
42
39
  export type RenderFormat = "openai" | "anthropic";
43
40
 
@@ -89,7 +86,7 @@ export interface PaginatedResult<T> {
89
86
  }
90
87
 
91
88
  export interface CreatePromptInput {
92
- projectId: string;
89
+ projectId?: string;
93
90
  name: string;
94
91
  slug: string;
95
92
  description?: string;
@@ -99,7 +96,7 @@ export interface CreatePromptInput {
99
96
  export type CreatePromptResult = Prompt;
100
97
 
101
98
  export interface ListPromptsInput {
102
- projectId: string;
99
+ projectId?: string;
103
100
  status?: PromptStatus;
104
101
  sortBy?: "createdAt" | "updatedAt" | "name";
105
102
  tags?: string;
@@ -110,14 +107,14 @@ export interface ListPromptsInput {
110
107
  export type ListPromptsResult = Prompt;
111
108
 
112
109
  export interface GetPromptInput {
113
- projectId: string;
110
+ projectId?: string;
114
111
  promptId: string;
115
112
  }
116
113
 
117
114
  export type GetPromptResult = Prompt;
118
115
 
119
116
  export interface UpdatePromptInput {
120
- projectId: string;
117
+ projectId?: string;
121
118
  promptId: string;
122
119
  name?: string;
123
120
  description?: string | null;
@@ -127,14 +124,14 @@ export interface UpdatePromptInput {
127
124
  export type UpdatePromptResult = Prompt;
128
125
 
129
126
  export interface ArchivePromptInput {
130
- projectId: string;
127
+ projectId?: string;
131
128
  promptId: string;
132
129
  }
133
130
 
134
131
  export type ArchivePromptResult = Prompt;
135
132
 
136
133
  export interface CreatePromptVersionInput {
137
- projectId: string;
134
+ projectId?: string;
138
135
  promptId: string;
139
136
  format: PromptFormat;
140
137
  templateJson: unknown;
@@ -146,14 +143,14 @@ export interface CreatePromptVersionInput {
146
143
  export type CreatePromptVersionResult = PromptVersion;
147
144
 
148
145
  export interface ListPromptVersionsInput {
149
- projectId: string;
146
+ projectId?: string;
150
147
  promptId: string;
151
148
  }
152
149
 
153
150
  export type ListPromptVersionsResult = PromptVersion[];
154
151
 
155
152
  export interface GetPromptVersionInput {
156
- projectId: string;
153
+ projectId?: string;
157
154
  promptId: string;
158
155
  versionNumber: number;
159
156
  }
@@ -161,7 +158,7 @@ export interface GetPromptVersionInput {
161
158
  export type GetPromptVersionResult = PromptVersion;
162
159
 
163
160
  export interface MovePromptLabelInput {
164
- projectId: string;
161
+ projectId?: string;
165
162
  promptId: string;
166
163
  label: string;
167
164
  versionId: string;
@@ -171,30 +168,17 @@ export interface MovePromptLabelInput {
171
168
  export type MovePromptLabelResult = PromptLabelPointer;
172
169
 
173
170
  export interface ListPromptLabelsInput {
174
- projectId: string;
171
+ projectId?: string;
175
172
  promptId: string;
176
173
  }
177
174
 
178
175
  export type ListPromptLabelsResult = PromptLabelPointer[];
179
176
 
180
- export interface ResolvePromptInput {
181
- projectId: string;
182
- slug: string;
183
- labels: string[];
184
- variables?: Record<string, unknown>;
185
- /** Set false to bypass the LRU cache for this call. Default: true */
186
- cache?: boolean;
187
- /** Fallback prompt served if the API is unreachable and cache is empty. */
188
- fallback?: ResolvedPrompt;
189
- }
190
-
191
- export type ResolvePromptResult = ResolvedPrompt;
192
-
193
177
  export const ENV_SLUG_REGEX = /^[a-z0-9-]{1,63}$/;
194
178
 
195
179
  export type BlockRenderRecord = Record<string, "rendered" | "dimmed">;
196
180
 
197
- export interface FetchedPrompt {
181
+ export interface RenderedPrompt {
198
182
  messages: RenderedChatMessage[];
199
183
  version: number;
200
184
  releaseId: string | null;
@@ -209,7 +193,12 @@ export interface FetchedPrompt {
209
193
  * `gatewayPromptHeaders` / `turn.headers()` (TO11-2725).
210
194
  */
211
195
  label: string;
212
- rendered: RenderedPrompt;
196
+ /**
197
+ * The prompt's human-readable slug (the `render()` input). Surfaced as
198
+ * `x-to11-prompt-slug` by `gatewayPromptHeaders` / `turn.headers()` so traces
199
+ * carry a readable name alongside the opaque `promptId` (TO11-2727).
200
+ */
201
+ slug: string;
213
202
  /**
214
203
  * The served version's model config (model, temperature, max_tokens, …),
215
204
  * passed through verbatim. Surfaced as `config` by `render({ format })`.
@@ -228,7 +217,7 @@ export interface FetchedPrompt {
228
217
  * into `toOpenAIToolChoice` / `toAnthropicToolChoice`.
229
218
  *
230
219
  * `NonNullable` because `normalizeResolvedEnvelope` maps wire-`null` to absent,
231
- * so a present `FetchedPrompt.toolChoice` is never `null` — callers get the
220
+ * so a present `RenderedPrompt.toolChoice` is never `null` — callers get the
232
221
  * key or nothing, and never have to branch on `null`.
233
222
  */
234
223
  toolChoice?: NonNullable<ResolvedPrompt["toolChoice"]>;
@@ -239,15 +228,16 @@ export type ResolvedPromptEnvelope = GenResolvedPrompt & {
239
228
  strategy?: "single" | "weighted";
240
229
  };
241
230
 
242
- export interface FetchPromptOptions {
231
+ export interface RenderOptions {
232
+ /** Serving environment for this call; overrides the client default. */
243
233
  env?: string;
234
+ /** Stable id so a weighted release sends the same caller to the same variant. */
244
235
  subject?: string;
245
236
  variables?: Record<string, unknown>;
237
+ /** Set false to bypass the LRU cache for this call. Default: true */
246
238
  cache?: boolean;
247
- fallback?: ResolvedPrompt | FetchedPrompt;
248
- }
249
-
250
- export interface RenderOptions extends FetchPromptOptions {
239
+ /** Prompt served if the API is unreachable on a network error and cache is empty. */
240
+ fallback?: RenderedPrompt;
251
241
  /** Provider shape for this call's output; overrides the client default. */
252
242
  format?: RenderFormat;
253
243
  /**
@@ -267,7 +257,7 @@ export type ProjectPromptLabelUsage = GenProjectPromptLabelUsage;
267
257
  export type PromptLabelEvent = GenPromptLabelEvent;
268
258
 
269
259
  export interface ListProjectPromptLabelsInput {
270
- projectId: string;
260
+ projectId?: string;
271
261
  /** Set true to include archived (soft-deleted) entries. Default: false. */
272
262
  includeArchived?: boolean;
273
263
  }
@@ -275,7 +265,7 @@ export interface ListProjectPromptLabelsInput {
275
265
  export type ListProjectPromptLabelsResult = ProjectPromptLabel[];
276
266
 
277
267
  export interface CreateProjectPromptLabelInput {
278
- projectId: string;
268
+ projectId?: string;
279
269
  label: string;
280
270
  isDefault?: boolean;
281
271
  description?: string;
@@ -285,14 +275,14 @@ export interface CreateProjectPromptLabelInput {
285
275
  export type CreateProjectPromptLabelResult = ProjectPromptLabel;
286
276
 
287
277
  export interface GetProjectPromptLabelInput {
288
- projectId: string;
278
+ projectId?: string;
289
279
  label: string;
290
280
  }
291
281
 
292
282
  export type GetProjectPromptLabelResult = ProjectPromptLabel;
293
283
 
294
284
  export interface UpdateProjectPromptLabelInput {
295
- projectId: string;
285
+ projectId?: string;
296
286
  label: string;
297
287
  isDefault?: boolean;
298
288
  description?: string | null;
@@ -302,14 +292,14 @@ export interface UpdateProjectPromptLabelInput {
302
292
  export type UpdateProjectPromptLabelResult = ProjectPromptLabel;
303
293
 
304
294
  export interface DeleteProjectPromptLabelInput {
305
- projectId: string;
295
+ projectId?: string;
306
296
  label: string;
307
297
  }
308
298
 
309
299
  export type DeleteProjectPromptLabelResult = ProjectPromptLabel;
310
300
 
311
301
  export interface ListProjectPromptLabelUsagesInput {
312
- projectId: string;
302
+ projectId?: string;
313
303
  label: string;
314
304
  }
315
305
 
@@ -318,7 +308,7 @@ export type ListProjectPromptLabelUsagesResult = ProjectPromptLabelUsage[];
318
308
  export type ListLabelEventsInput =
319
309
  | {
320
310
  scope: "label";
321
- projectId: string;
311
+ projectId?: string;
322
312
  promptId: string;
323
313
  label: string;
324
314
  page?: number;
@@ -328,7 +318,7 @@ export type ListLabelEventsInput =
328
318
  }
329
319
  | {
330
320
  scope: "prompt";
331
- projectId: string;
321
+ projectId?: string;
332
322
  promptId: string;
333
323
  label?: string;
334
324
  page?: number;
@@ -338,7 +328,7 @@ export type ListLabelEventsInput =
338
328
  }
339
329
  | {
340
330
  scope: "project";
341
- projectId: string;
331
+ projectId?: string;
342
332
  promptId?: string;
343
333
  label?: string;
344
334
  page?: number;