@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.
@@ -1,4 +1,4 @@
1
- import type { ProjectPromptLabel as GenProjectPromptLabel, ProjectPromptLabelUsage as GenProjectPromptLabelUsage, Prompt as GenPrompt, PromptLabelEvent as GenPromptLabelEvent, PromptLabelPointer as GenPromptLabelPointer, PromptVersion as GenPromptVersion, RenderedChatPrompt as GenRenderedChatPrompt, RenderedPrompt as GenRenderedPrompt, ResolvedPrompt as GenResolvedPrompt, ResolvedToolCall as GenResolvedToolCall, ResolvedToolDefinition as GenResolvedToolDefinition } from "../generated/types.gen";
1
+ import type { ProjectPromptLabel as GenProjectPromptLabel, ProjectPromptLabelUsage as GenProjectPromptLabelUsage, Prompt as GenPrompt, PromptLabelEvent as GenPromptLabelEvent, PromptLabelPointer as GenPromptLabelPointer, PromptVersion as GenPromptVersion, RenderedChatPrompt as GenRenderedChatPrompt, ResolvedPrompt as GenResolvedPrompt, ResolvedToolCall as GenResolvedToolCall, ResolvedToolDefinition as GenResolvedToolDefinition } from "../generated/types.gen";
2
2
  export interface RowError {
3
3
  path: ReadonlyArray<string | number>;
4
4
  code: string;
@@ -17,7 +17,16 @@ export interface TextChatMessage {
17
17
  }
18
18
  export type ChatMessage = TextChatMessage;
19
19
  export type RenderedChatMessage = GenRenderedChatPrompt["messages"][number];
20
- export type RenderedPrompt = GenRenderedPrompt;
20
+ /** Provider shape for `prompts.render()` output. Omit for the neutral result. */
21
+ export type RenderFormat = "openai" | "anthropic";
22
+ /**
23
+ * Policy for a message whose role is outside the known set
24
+ * (`system | user | assistant | developer | tool`) when converting to a
25
+ * provider shape. `"drop"` (default) omits it silently; `"warn"` omits it and
26
+ * emits a `console.warn`; `"error"` throws `UnknownRoleError`. Applies to the
27
+ * standalone converters and to `render({ format })`.
28
+ */
29
+ export type UnknownRoleMode = "drop" | "warn" | "error";
21
30
  /**
22
31
  * A provider-neutral tool definition (`{ name, description?, parameters }`),
23
32
  * sourced from authored tool-definition blocks. Surfaced on the resolved
@@ -29,7 +38,7 @@ export type ResolvedToolDefinition = GenResolvedToolDefinition;
29
38
  * on a rendered `assistant` turn (few-shot multi-tool history).
30
39
  */
31
40
  export type ResolvedToolCall = GenResolvedToolCall;
32
- export type ResolvedPrompt = Pick<GenResolvedPrompt, "promptId" | "versionId" | "version" | "labels" | "contentHash" | "rendered" | "tools" | "toolChoice">;
41
+ export type ResolvedPrompt = Pick<GenResolvedPrompt, "promptId" | "versionId" | "version" | "label" | "contentHash" | "rendered" | "tools" | "toolChoice" | "modelConfig">;
33
42
  export interface PaginationInfo {
34
43
  page: number;
35
44
  limit: number;
@@ -109,20 +118,9 @@ export interface ListPromptLabelsInput {
109
118
  promptId: string;
110
119
  }
111
120
  export type ListPromptLabelsResult = PromptLabelPointer[];
112
- export interface ResolvePromptInput {
113
- projectId: string;
114
- slug: string;
115
- labels: string[];
116
- variables?: Record<string, unknown>;
117
- /** Set false to bypass the LRU cache for this call. Default: true */
118
- cache?: boolean;
119
- /** Fallback prompt served if the API is unreachable and cache is empty. */
120
- fallback?: ResolvedPrompt;
121
- }
122
- export type ResolvePromptResult = ResolvedPrompt;
123
121
  export declare const ENV_SLUG_REGEX: RegExp;
124
122
  export type BlockRenderRecord = Record<string, "rendered" | "dimmed">;
125
- export interface FetchedPrompt {
123
+ export interface RenderedPrompt {
126
124
  messages: RenderedChatMessage[];
127
125
  version: number;
128
126
  releaseId: string | null;
@@ -131,8 +129,24 @@ export interface FetchedPrompt {
131
129
  promptId: string;
132
130
  versionId: string;
133
131
  contentHash: string;
134
- labels: string[];
135
- rendered: RenderedPrompt;
132
+ /**
133
+ * The single label the prompt resolved through — the env slug today, a real
134
+ * label once labels ship. Surfaced as `x-to11-prompt-label` by
135
+ * `gatewayPromptHeaders` / `turn.headers()` (TO11-2725).
136
+ */
137
+ label: string;
138
+ /**
139
+ * The prompt's human-readable slug (the `render()` input). Surfaced as
140
+ * `x-to11-prompt-slug` by `gatewayPromptHeaders` / `turn.headers()` so traces
141
+ * carry a readable name alongside the opaque `promptId` (TO11-2727).
142
+ */
143
+ slug: string;
144
+ /**
145
+ * The served version's model config (model, temperature, max_tokens, …),
146
+ * passed through verbatim. Surfaced as `config` by `render({ format })`.
147
+ * Optional: absent when a pre-`modelConfig` API omits it.
148
+ */
149
+ modelConfig?: unknown;
136
150
  /**
137
151
  * Provider-neutral tool definitions lifted from authored tool-definition
138
152
  * blocks. Absent (rather than `[]`) when the resolved version declares no
@@ -145,7 +159,7 @@ export interface FetchedPrompt {
145
159
  * into `toOpenAIToolChoice` / `toAnthropicToolChoice`.
146
160
  *
147
161
  * `NonNullable` because `normalizeResolvedEnvelope` maps wire-`null` to absent,
148
- * so a present `FetchedPrompt.toolChoice` is never `null` — callers get the
162
+ * so a present `RenderedPrompt.toolChoice` is never `null` — callers get the
149
163
  * key or nothing, and never have to branch on `null`.
150
164
  */
151
165
  toolChoice?: NonNullable<ResolvedPrompt["toolChoice"]>;
@@ -154,25 +168,24 @@ export type ResolvedPromptEnvelope = GenResolvedPrompt & {
154
168
  /** Active release strategy. Used to decide weighted-no-subject cache bypass (D8). */
155
169
  strategy?: "single" | "weighted";
156
170
  };
157
- /**
158
- * How an authored `developer` block is rendered. The caller controls this
159
- * per-call because it knows the upstream it targets. Omitted ⇒ `"user"`
160
- * (back-compatible; safe for any upstream). `"developer"` preserves the role
161
- * (OpenAI); `"system"` folds it into a system message.
162
- */
163
- export type DeveloperRole = "user" | "developer" | "system";
164
- export interface FetchPromptOptions {
171
+ export interface RenderOptions {
172
+ /** Serving environment for this call; overrides the client default. */
165
173
  env?: string;
174
+ /** Stable id so a weighted release sends the same caller to the same variant. */
166
175
  subject?: string;
167
176
  variables?: Record<string, unknown>;
177
+ /** Set false to bypass the LRU cache for this call. Default: true */
168
178
  cache?: boolean;
169
- fallback?: ResolvedPrompt | FetchedPrompt;
179
+ /** Prompt served if the API is unreachable on a network error and cache is empty. */
180
+ fallback?: RenderedPrompt;
181
+ /** Provider shape for this call's output; overrides the client default. */
182
+ format?: RenderFormat;
170
183
  /**
171
- * How authored `developer` blocks render. Default `"user"`. Forwarded on the
172
- * resolve request and folded into the cache key so two calls differing only
173
- * by `developerRole` never share a cached result.
184
+ * How to handle a message with an unrecognized role while shaping for a
185
+ * provider (`format` set). Overrides the client default; defaults to `"drop"`.
186
+ * Only meaningful with a `format` — the neutral result runs no converter.
174
187
  */
175
- developerRole?: DeveloperRole;
188
+ onUnknownRole?: UnknownRoleMode;
176
189
  }
177
190
  export type PaletteToken = ProjectPromptLabel["displayColor"];
178
191
  export type ProjectPromptLabel = GenProjectPromptLabel;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@to11ai/sdk",
3
- "version": "1.1.0",
3
+ "version": "2.0.0-rc.2",
4
4
  "license": "MPL-2.0",
5
5
  "repository": {
6
6
  "type": "git",