@to11ai/sdk 1.1.0 → 2.0.0-rc.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.
@@ -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,7 +35,17 @@ export type ChatMessage = TextChatMessage;
36
35
 
37
36
  export type RenderedChatMessage = GenRenderedChatPrompt["messages"][number];
38
37
 
39
- export type RenderedPrompt = GenRenderedPrompt;
38
+ /** Provider shape for `prompts.render()` output. Omit for the neutral result. */
39
+ export type RenderFormat = "openai" | "anthropic";
40
+
41
+ /**
42
+ * Policy for a message whose role is outside the known set
43
+ * (`system | user | assistant | developer | tool`) when converting to a
44
+ * provider shape. `"drop"` (default) omits it silently; `"warn"` omits it and
45
+ * emits a `console.warn`; `"error"` throws `UnknownRoleError`. Applies to the
46
+ * standalone converters and to `render({ format })`.
47
+ */
48
+ export type UnknownRoleMode = "drop" | "warn" | "error";
40
49
 
41
50
  /**
42
51
  * A provider-neutral tool definition (`{ name, description?, parameters }`),
@@ -56,11 +65,12 @@ export type ResolvedPrompt = Pick<
56
65
  | "promptId"
57
66
  | "versionId"
58
67
  | "version"
59
- | "labels"
68
+ | "label"
60
69
  | "contentHash"
61
70
  | "rendered"
62
71
  | "tools"
63
72
  | "toolChoice"
73
+ | "modelConfig"
64
74
  >;
65
75
 
66
76
  export interface PaginationInfo {
@@ -164,24 +174,11 @@ export interface ListPromptLabelsInput {
164
174
 
165
175
  export type ListPromptLabelsResult = PromptLabelPointer[];
166
176
 
167
- export interface ResolvePromptInput {
168
- projectId: string;
169
- slug: string;
170
- labels: string[];
171
- variables?: Record<string, unknown>;
172
- /** Set false to bypass the LRU cache for this call. Default: true */
173
- cache?: boolean;
174
- /** Fallback prompt served if the API is unreachable and cache is empty. */
175
- fallback?: ResolvedPrompt;
176
- }
177
-
178
- export type ResolvePromptResult = ResolvedPrompt;
179
-
180
177
  export const ENV_SLUG_REGEX = /^[a-z0-9-]{1,63}$/;
181
178
 
182
179
  export type BlockRenderRecord = Record<string, "rendered" | "dimmed">;
183
180
 
184
- export interface FetchedPrompt {
181
+ export interface RenderedPrompt {
185
182
  messages: RenderedChatMessage[];
186
183
  version: number;
187
184
  releaseId: string | null;
@@ -190,8 +187,24 @@ export interface FetchedPrompt {
190
187
  promptId: string;
191
188
  versionId: string;
192
189
  contentHash: string;
193
- labels: string[];
194
- rendered: RenderedPrompt;
190
+ /**
191
+ * The single label the prompt resolved through — the env slug today, a real
192
+ * label once labels ship. Surfaced as `x-to11-prompt-label` by
193
+ * `gatewayPromptHeaders` / `turn.headers()` (TO11-2725).
194
+ */
195
+ label: string;
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;
202
+ /**
203
+ * The served version's model config (model, temperature, max_tokens, …),
204
+ * passed through verbatim. Surfaced as `config` by `render({ format })`.
205
+ * Optional: absent when a pre-`modelConfig` API omits it.
206
+ */
207
+ modelConfig?: unknown;
195
208
  /**
196
209
  * Provider-neutral tool definitions lifted from authored tool-definition
197
210
  * blocks. Absent (rather than `[]`) when the resolved version declares no
@@ -204,7 +217,7 @@ export interface FetchedPrompt {
204
217
  * into `toOpenAIToolChoice` / `toAnthropicToolChoice`.
205
218
  *
206
219
  * `NonNullable` because `normalizeResolvedEnvelope` maps wire-`null` to absent,
207
- * so a present `FetchedPrompt.toolChoice` is never `null` — callers get the
220
+ * so a present `RenderedPrompt.toolChoice` is never `null` — callers get the
208
221
  * key or nothing, and never have to branch on `null`.
209
222
  */
210
223
  toolChoice?: NonNullable<ResolvedPrompt["toolChoice"]>;
@@ -215,26 +228,24 @@ export type ResolvedPromptEnvelope = GenResolvedPrompt & {
215
228
  strategy?: "single" | "weighted";
216
229
  };
217
230
 
218
- /**
219
- * How an authored `developer` block is rendered. The caller controls this
220
- * per-call because it knows the upstream it targets. Omitted ⇒ `"user"`
221
- * (back-compatible; safe for any upstream). `"developer"` preserves the role
222
- * (OpenAI); `"system"` folds it into a system message.
223
- */
224
- export type DeveloperRole = "user" | "developer" | "system";
225
-
226
- export interface FetchPromptOptions {
231
+ export interface RenderOptions {
232
+ /** Serving environment for this call; overrides the client default. */
227
233
  env?: string;
234
+ /** Stable id so a weighted release sends the same caller to the same variant. */
228
235
  subject?: string;
229
236
  variables?: Record<string, unknown>;
237
+ /** Set false to bypass the LRU cache for this call. Default: true */
230
238
  cache?: boolean;
231
- fallback?: ResolvedPrompt | FetchedPrompt;
239
+ /** Prompt served if the API is unreachable on a network error and cache is empty. */
240
+ fallback?: RenderedPrompt;
241
+ /** Provider shape for this call's output; overrides the client default. */
242
+ format?: RenderFormat;
232
243
  /**
233
- * How authored `developer` blocks render. Default `"user"`. Forwarded on the
234
- * resolve request and folded into the cache key so two calls differing only
235
- * by `developerRole` never share a cached result.
244
+ * How to handle a message with an unrecognized role while shaping for a
245
+ * provider (`format` set). Overrides the client default; defaults to `"drop"`.
246
+ * Only meaningful with a `format` — the neutral result runs no converter.
236
247
  */
237
- developerRole?: DeveloperRole;
248
+ onUnknownRole?: UnknownRoleMode;
238
249
  }
239
250
 
240
251
  export type PaletteToken = ProjectPromptLabel["displayColor"];