@to11ai/sdk 0.6.0 → 0.8.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.
@@ -104,12 +104,13 @@ export type {
104
104
  RenderedPrompt,
105
105
  ResolvedPrompt,
106
106
  ResolvedPromptEnvelope,
107
+ ResolvedToolCall,
108
+ ResolvedToolDefinition,
107
109
  ResolvePromptInput,
108
110
  ResolvePromptResult,
109
111
  RowError,
110
112
  TextChatMessage,
111
113
  TextChatRole,
112
- ToolChatMessage,
113
114
  UpdateProjectPromptLabelInput,
114
115
  UpdateProjectPromptLabelResult,
115
116
  UpdatePromptInput,
@@ -123,6 +124,8 @@ const zResolvedPromptLegacy = zResolvedPrompt.pick({
123
124
  labels: true,
124
125
  contentHash: true,
125
126
  rendered: true,
127
+ tools: true,
128
+ toolChoice: true,
126
129
  });
127
130
 
128
131
  const zResolvedPromptEnvelope = zResolvedPrompt
@@ -178,6 +181,19 @@ function normalizeResolvedEnvelope(
178
181
  labels: raw.labels,
179
182
  rendered: raw.rendered,
180
183
  };
184
+ // `tools` is present IFF the resolved version declares tool definitions; the
185
+ // wire may send `null` (or omit it) — normalize both to absent so callers
186
+ // can `?? []` once via the converters rather than guarding `null`.
187
+ if (raw.tools != null && raw.tools.length > 0) {
188
+ result.tools = raw.tools;
189
+ }
190
+ // `toolChoice` mirrors `tools`: present IFF the resolved version declares a
191
+ // directive. The wire may send `null` (or omit it); normalize both to absent
192
+ // so callers feed `toOpenAIToolChoice` / `toAnthropicToolChoice` (which map
193
+ // `null`/`undefined` → omit) without a separate guard.
194
+ if (raw.toolChoice != null) {
195
+ result.toolChoice = raw.toolChoice;
196
+ }
181
197
  // Set `variantName` only when it is a non-empty string, so the key is
182
198
  // genuinely absent for `single`-strategy releases (R5: present IFF weighted —
183
199
  // never `null`, never `""`). A `null`/`""` from the wire is normalized to
@@ -477,6 +493,7 @@ export class PromptResource {
477
493
  variables,
478
494
  cache: useCache = true,
479
495
  fallback,
496
+ developerRole,
480
497
  } = options;
481
498
 
482
499
  const cacheKey = buildFetchCacheKey(
@@ -486,6 +503,7 @@ export class PromptResource {
486
503
  context,
487
504
  subject,
488
505
  variables,
506
+ developerRole,
489
507
  );
490
508
 
491
509
  if (useCache) {
@@ -500,6 +518,7 @@ export class PromptResource {
500
518
  if (context !== undefined) body.context = context;
501
519
  if (subject !== undefined) body.subject = subject;
502
520
  if (variables !== undefined) body.variables = variables;
521
+ if (developerRole !== undefined) body.developerRole = developerRole;
503
522
 
504
523
  try {
505
524
  const envelope = await this.transport.request<ResolvedPromptEnvelope>(
@@ -8,6 +8,8 @@ import type {
8
8
  RenderedChatPrompt as GenRenderedChatPrompt,
9
9
  RenderedPrompt as GenRenderedPrompt,
10
10
  ResolvedPrompt as GenResolvedPrompt,
11
+ ResolvedToolCall as GenResolvedToolCall,
12
+ ResolvedToolDefinition as GenResolvedToolDefinition,
11
13
  } from "../generated/types.gen";
12
14
 
13
15
  export interface RowError {
@@ -30,23 +32,35 @@ export interface TextChatMessage {
30
32
  disabled?: boolean;
31
33
  }
32
34
 
33
- export interface ToolChatMessage {
34
- role: "tool";
35
- name: string;
36
- description?: string;
37
- parameters: unknown;
38
- disabled?: boolean;
39
- }
40
-
41
- export type ChatMessage = TextChatMessage | ToolChatMessage;
35
+ export type ChatMessage = TextChatMessage;
42
36
 
43
37
  export type RenderedChatMessage = GenRenderedChatPrompt["messages"][number];
44
38
 
45
39
  export type RenderedPrompt = GenRenderedPrompt;
46
40
 
41
+ /**
42
+ * A provider-neutral tool definition (`{ name, description?, parameters }`),
43
+ * sourced from authored tool-definition blocks. Surfaced on the resolved
44
+ * contract and shaped for a provider via `toOpenAITools` / `toAnthropicTools`.
45
+ */
46
+ export type ResolvedToolDefinition = GenResolvedToolDefinition;
47
+
48
+ /**
49
+ * A structured assistant tool call (`{ id, name, arguments }`) carried inline
50
+ * on a rendered `assistant` turn (few-shot multi-tool history).
51
+ */
52
+ export type ResolvedToolCall = GenResolvedToolCall;
53
+
47
54
  export type ResolvedPrompt = Pick<
48
55
  GenResolvedPrompt,
49
- "promptId" | "versionId" | "version" | "labels" | "contentHash" | "rendered"
56
+ | "promptId"
57
+ | "versionId"
58
+ | "version"
59
+ | "labels"
60
+ | "contentHash"
61
+ | "rendered"
62
+ | "tools"
63
+ | "toolChoice"
50
64
  >;
51
65
 
52
66
  export interface PaginationInfo {
@@ -112,6 +126,9 @@ export interface CreatePromptVersionInput {
112
126
  format: PromptFormat;
113
127
  templateJson: unknown;
114
128
  variablesSchema: unknown;
129
+ // TO11-2609: server-trusted, gating-only context schema (scalar/enum keys).
130
+ // Optional on write; omitted → no context keys.
131
+ contextSchema?: unknown;
115
132
  modelConfig?: unknown;
116
133
  changelog?: string;
117
134
  }
@@ -180,6 +197,22 @@ export interface FetchedPrompt {
180
197
  contentHash: string;
181
198
  labels: string[];
182
199
  rendered: RenderedPrompt;
200
+ /**
201
+ * Provider-neutral tool definitions lifted from authored tool-definition
202
+ * blocks. Absent (rather than `[]`) when the resolved version declares no
203
+ * tools. Shape for a provider with `toOpenAITools` / `toAnthropicTools`.
204
+ */
205
+ tools?: ResolvedToolDefinition[];
206
+ /**
207
+ * Provider-neutral tool-choice directive lifted from the resolved version.
208
+ * Absent (rather than `null`) when the version declares none. Feed straight
209
+ * into `toOpenAIToolChoice` / `toAnthropicToolChoice`.
210
+ *
211
+ * `NonNullable` because `normalizeResolvedEnvelope` maps wire-`null` to absent,
212
+ * so a present `FetchedPrompt.toolChoice` is never `null` — callers get the
213
+ * key or nothing, and never have to branch on `null`.
214
+ */
215
+ toolChoice?: NonNullable<ResolvedPrompt["toolChoice"]>;
183
216
  }
184
217
 
185
218
  export type ResolvedPromptEnvelope = GenResolvedPrompt & {
@@ -187,6 +220,14 @@ export type ResolvedPromptEnvelope = GenResolvedPrompt & {
187
220
  strategy?: "single" | "weighted";
188
221
  };
189
222
 
223
+ /**
224
+ * How an authored `developer` block is rendered. The caller controls this
225
+ * per-call because it knows the upstream it targets. Omitted ⇒ `"user"`
226
+ * (back-compatible; safe for any upstream). `"developer"` preserves the role
227
+ * (OpenAI); `"system"` folds it into a system message.
228
+ */
229
+ export type DeveloperRole = "user" | "developer" | "system";
230
+
190
231
  export interface FetchPromptOptions {
191
232
  env?: string;
192
233
  context?: PromptContext;
@@ -194,6 +235,12 @@ export interface FetchPromptOptions {
194
235
  variables?: Record<string, unknown>;
195
236
  cache?: boolean;
196
237
  fallback?: ResolvedPrompt | FetchedPrompt;
238
+ /**
239
+ * How authored `developer` blocks render. Default `"user"`. Forwarded on the
240
+ * resolve request and folded into the cache key so two calls differing only
241
+ * by `developerRole` never share a cached result.
242
+ */
243
+ developerRole?: DeveloperRole;
197
244
  }
198
245
 
199
246
  export type PaletteToken = ProjectPromptLabel["displayColor"];