@to11ai/sdk 0.5.0 → 0.7.0

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.
@@ -267,21 +267,37 @@ export type PromptVersion = {
267
267
  version: number;
268
268
  };
269
269
 
270
+ export type RenderedAssistantMessage = {
271
+ content?: string | null;
272
+ role: 'assistant';
273
+ toolCalls?: Array<ResolvedToolCall> | null;
274
+ };
275
+
276
+ export type RenderedChatMessage = RenderedTextMessage | RenderedAssistantMessage | RenderedToolMessage;
277
+
270
278
  export type RenderedChatPrompt = {
271
279
  format: 'chat';
272
- messages: Array<{
273
- content: string;
274
- role: 'system' | 'user' | 'assistant' | 'developer' | 'tool';
275
- }>;
280
+ messages: Array<RenderedChatMessage>;
276
281
  };
277
282
 
278
283
  export type RenderedPrompt = RenderedTextPrompt | RenderedChatPrompt;
279
284
 
285
+ export type RenderedTextMessage = {
286
+ content: string;
287
+ role: 'system' | 'user' | 'developer';
288
+ };
289
+
280
290
  export type RenderedTextPrompt = {
281
291
  format: 'text';
282
292
  text: string;
283
293
  };
284
294
 
295
+ export type RenderedToolMessage = {
296
+ content: string;
297
+ role: 'tool';
298
+ toolCallId: string;
299
+ };
300
+
285
301
  export type ResolvedPrompt = {
286
302
  blockRenderRecord?: {
287
303
  [key: string]: 'rendered' | 'dimmed';
@@ -292,11 +308,28 @@ export type ResolvedPrompt = {
292
308
  releaseId: string;
293
309
  rendered: RenderedPrompt;
294
310
  subjectHash?: string | null;
311
+ tools?: Array<ResolvedToolDefinition> | null;
295
312
  variantName?: string | null;
296
313
  version: number;
297
314
  versionId: string;
298
315
  };
299
316
 
317
+ export type ResolvedToolCall = {
318
+ arguments: {
319
+ [key: string]: unknown;
320
+ };
321
+ id: string;
322
+ name: string;
323
+ };
324
+
325
+ export type ResolvedToolDefinition = {
326
+ description?: string | null;
327
+ name: string;
328
+ parameters: {
329
+ [key: string]: unknown;
330
+ };
331
+ };
332
+
300
333
  export type RuleModelBinding = {
301
334
  modelId: string;
302
335
  provider: RuleProviderRef;
@@ -9826,7 +9859,7 @@ export type ProjectAuditListProjectAuditEventsResponses = {
9826
9859
  providerSlug: string | null;
9827
9860
  reason: string | null;
9828
9861
  resourceId: string;
9829
- resourceType: 'provider' | 'credential' | 'prompt' | 'rule' | 'env';
9862
+ resourceType: 'provider' | 'credential' | 'prompt' | 'rule' | 'env' | 'role' | 'api_key' | 'project' | 'organization' | 'organization_invitation' | 'workspace' | 'data_center' | 'cost_rate';
9830
9863
  scheduledAt: string | null;
9831
9864
  scheduledBy: string | null;
9832
9865
  }>;
@@ -9873,7 +9906,7 @@ export type ProjectAuditExportExportProjectAuditEventsData = {
9873
9906
  provider_id?: string | null;
9874
9907
  credential_id?: string | null;
9875
9908
  actor_id?: string | null;
9876
- resource_type?: 'provider' | 'credential' | 'prompt' | 'rule' | 'env' | null;
9909
+ resource_type?: 'provider' | 'credential' | 'prompt' | 'rule' | 'env' | 'role' | 'api_key' | 'project' | 'organization' | 'organization_invitation' | 'workspace' | 'data_center' | 'cost_rate' | null;
9877
9910
  event_type?: string | null;
9878
9911
  since?: string | null;
9879
9912
  until?: string | null;
@@ -15451,11 +15484,21 @@ export type PromptsGetPromptVersionDiffResponses = {
15451
15484
  name: string;
15452
15485
  op: 'add';
15453
15486
  role: 'system' | 'user' | 'assistant' | 'developer' | 'tool';
15487
+ toolCalls?: Array<{
15488
+ arguments: {
15489
+ [key: string]: unknown;
15490
+ };
15491
+ id: string;
15492
+ name: string;
15493
+ }> | null;
15454
15494
  toolSchema?: {
15495
+ content?: string | null;
15455
15496
  description?: string | null;
15456
- parameters: {
15497
+ parameters?: {
15457
15498
  [key: string]: unknown;
15458
- };
15499
+ } | null;
15500
+ toolCallId?: string | null;
15501
+ toolKind?: 'definition' | 'result' | null;
15459
15502
  } | null;
15460
15503
  } | {
15461
15504
  condition: {
@@ -15465,11 +15508,21 @@ export type PromptsGetPromptVersionDiffResponses = {
15465
15508
  name: string;
15466
15509
  op: 'remove';
15467
15510
  role: 'system' | 'user' | 'assistant' | 'developer' | 'tool';
15511
+ toolCalls?: Array<{
15512
+ arguments: {
15513
+ [key: string]: unknown;
15514
+ };
15515
+ id: string;
15516
+ name: string;
15517
+ }> | null;
15468
15518
  toolSchema?: {
15519
+ content?: string | null;
15469
15520
  description?: string | null;
15470
- parameters: {
15521
+ parameters?: {
15471
15522
  [key: string]: unknown;
15472
- };
15523
+ } | null;
15524
+ toolCallId?: string | null;
15525
+ toolKind?: 'definition' | 'result' | null;
15473
15526
  } | null;
15474
15527
  } | {
15475
15528
  after: string;
@@ -15497,19 +15550,42 @@ export type PromptsGetPromptVersionDiffResponses = {
15497
15550
  op: 'edit_required';
15498
15551
  } | {
15499
15552
  after: {
15553
+ content?: string | null;
15500
15554
  description?: string | null;
15501
- parameters: {
15555
+ parameters?: {
15502
15556
  [key: string]: unknown;
15503
- };
15557
+ } | null;
15558
+ toolCallId?: string | null;
15559
+ toolKind?: 'definition' | 'result' | null;
15504
15560
  };
15505
15561
  before: {
15562
+ content?: string | null;
15506
15563
  description?: string | null;
15507
- parameters: {
15564
+ parameters?: {
15508
15565
  [key: string]: unknown;
15509
- };
15566
+ } | null;
15567
+ toolCallId?: string | null;
15568
+ toolKind?: 'definition' | 'result' | null;
15510
15569
  };
15511
15570
  name: string;
15512
15571
  op: 'edit_tool_schema';
15572
+ } | {
15573
+ after: Array<{
15574
+ arguments: {
15575
+ [key: string]: unknown;
15576
+ };
15577
+ id: string;
15578
+ name: string;
15579
+ }>;
15580
+ before: Array<{
15581
+ arguments: {
15582
+ [key: string]: unknown;
15583
+ };
15584
+ id: string;
15585
+ name: string;
15586
+ }>;
15587
+ name: string;
15588
+ op: 'edit_tool_calls';
15513
15589
  } | {
15514
15590
  fromIndex: number;
15515
15591
  name: string;
@@ -15978,6 +16054,7 @@ export type PromptsResolvePromptData = {
15978
16054
  context?: {
15979
16055
  [key: string]: string | number | boolean;
15980
16056
  } | null;
16057
+ developerRole?: 'user' | 'developer' | 'system' | null;
15981
16058
  labels: Array<string>;
15982
16059
  slug: string;
15983
16060
  subject?: string | null;
@@ -18477,10 +18554,13 @@ export type RoutingMetricsGetRoutingProviderMetricsResponses = {
18477
18554
  data: Array<{
18478
18555
  calls7dTotal: number;
18479
18556
  daily: Array<number>;
18557
+ errorCount: number;
18558
+ errorRate: number;
18480
18559
  latencyP50Ms: number | null;
18481
18560
  latencyP95Ms: number | null;
18482
18561
  providerId: string;
18483
18562
  requests: number;
18563
+ spend7dUsd: number | null;
18484
18564
  }> | null;
18485
18565
  error: {
18486
18566
  code: string;
@@ -293,18 +293,13 @@ export const zPromptVersion = z.object({
293
293
  version: z.int().gt(0).lte(2147483647)
294
294
  });
295
295
 
296
- export const zRenderedChatPrompt = z.object({
297
- format: z.enum(['chat']),
298
- messages: z.array(z.object({
299
- content: z.string(),
300
- role: z.enum([
301
- 'system',
302
- 'user',
303
- 'assistant',
304
- 'developer',
305
- 'tool'
306
- ])
307
- }))
296
+ export const zRenderedTextMessage = z.object({
297
+ content: z.string(),
298
+ role: z.enum([
299
+ 'system',
300
+ 'user',
301
+ 'developer'
302
+ ])
308
303
  });
309
304
 
310
305
  export const zRenderedTextPrompt = z.object({
@@ -312,11 +307,46 @@ export const zRenderedTextPrompt = z.object({
312
307
  text: z.string()
313
308
  });
314
309
 
310
+ export const zRenderedToolMessage = z.object({
311
+ content: z.string(),
312
+ role: z.enum(['tool']),
313
+ toolCallId: z.string()
314
+ });
315
+
316
+ export const zResolvedToolCall = z.object({
317
+ arguments: z.record(z.string(), z.unknown()),
318
+ id: z.string(),
319
+ name: z.string()
320
+ });
321
+
322
+ export const zRenderedAssistantMessage = z.object({
323
+ content: z.string().nullish(),
324
+ role: z.enum(['assistant']),
325
+ toolCalls: z.array(zResolvedToolCall).nullish()
326
+ });
327
+
328
+ export const zRenderedChatMessage = z.union([
329
+ zRenderedTextMessage,
330
+ zRenderedAssistantMessage,
331
+ zRenderedToolMessage
332
+ ]);
333
+
334
+ export const zRenderedChatPrompt = z.object({
335
+ format: z.enum(['chat']),
336
+ messages: z.array(zRenderedChatMessage)
337
+ });
338
+
315
339
  export const zRenderedPrompt = z.union([
316
340
  zRenderedTextPrompt,
317
341
  zRenderedChatPrompt
318
342
  ]);
319
343
 
344
+ export const zResolvedToolDefinition = z.object({
345
+ description: z.string().nullish(),
346
+ name: z.string(),
347
+ parameters: z.record(z.string(), z.unknown())
348
+ });
349
+
320
350
  export const zResolvedPrompt = z.object({
321
351
  blockRenderRecord: z.record(z.string(), z.enum(['rendered', 'dimmed'])).nullish(),
322
352
  contentHash: z.string(),
@@ -325,6 +355,7 @@ export const zResolvedPrompt = z.object({
325
355
  releaseId: z.string(),
326
356
  rendered: zRenderedPrompt,
327
357
  subjectHash: z.string().nullish(),
358
+ tools: z.array(zResolvedToolDefinition).nullish(),
328
359
  variantName: z.string().nullish(),
329
360
  version: z.number(),
330
361
  versionId: z.string()
@@ -5088,7 +5119,15 @@ export const zProjectAuditListProjectAuditEventsResponse = z.object({
5088
5119
  'credential',
5089
5120
  'prompt',
5090
5121
  'rule',
5091
- 'env'
5122
+ 'env',
5123
+ 'role',
5124
+ 'api_key',
5125
+ 'project',
5126
+ 'organization',
5127
+ 'organization_invitation',
5128
+ 'workspace',
5129
+ 'data_center',
5130
+ 'cost_rate'
5092
5131
  ]),
5093
5132
  scheduledAt: z.string().nullable(),
5094
5133
  scheduledBy: z.string().nullable()
@@ -5135,7 +5174,15 @@ export const zProjectAuditExportExportProjectAuditEventsQuery = z.object({
5135
5174
  'credential',
5136
5175
  'prompt',
5137
5176
  'rule',
5138
- 'env'
5177
+ 'env',
5178
+ 'role',
5179
+ 'api_key',
5180
+ 'project',
5181
+ 'organization',
5182
+ 'organization_invitation',
5183
+ 'workspace',
5184
+ 'data_center',
5185
+ 'cost_rate'
5139
5186
  ]).nullish(),
5140
5187
  event_type: z.string().nullish(),
5141
5188
  since: z.string().nullish(),
@@ -7907,9 +7954,17 @@ export const zPromptsGetPromptVersionDiffResponse = z.object({
7907
7954
  'developer',
7908
7955
  'tool'
7909
7956
  ]),
7957
+ toolCalls: z.array(z.object({
7958
+ arguments: z.record(z.string(), z.unknown()),
7959
+ id: z.string(),
7960
+ name: z.string()
7961
+ })).nullish(),
7910
7962
  toolSchema: z.object({
7963
+ content: z.string().nullish(),
7911
7964
  description: z.string().nullish(),
7912
- parameters: z.record(z.string(), z.unknown())
7965
+ parameters: z.record(z.string(), z.unknown()).nullish(),
7966
+ toolCallId: z.string().nullish(),
7967
+ toolKind: z.enum(['definition', 'result']).nullish()
7913
7968
  }).nullish()
7914
7969
  }),
7915
7970
  z.object({
@@ -7926,9 +7981,17 @@ export const zPromptsGetPromptVersionDiffResponse = z.object({
7926
7981
  'developer',
7927
7982
  'tool'
7928
7983
  ]),
7984
+ toolCalls: z.array(z.object({
7985
+ arguments: z.record(z.string(), z.unknown()),
7986
+ id: z.string(),
7987
+ name: z.string()
7988
+ })).nullish(),
7929
7989
  toolSchema: z.object({
7990
+ content: z.string().nullish(),
7930
7991
  description: z.string().nullish(),
7931
- parameters: z.record(z.string(), z.unknown())
7992
+ parameters: z.record(z.string(), z.unknown()).nullish(),
7993
+ toolCallId: z.string().nullish(),
7994
+ toolKind: z.enum(['definition', 'result']).nullish()
7932
7995
  }).nullish()
7933
7996
  }),
7934
7997
  z.object({
@@ -7973,16 +8036,36 @@ export const zPromptsGetPromptVersionDiffResponse = z.object({
7973
8036
  }),
7974
8037
  z.object({
7975
8038
  after: z.object({
8039
+ content: z.string().nullish(),
7976
8040
  description: z.string().nullish(),
7977
- parameters: z.record(z.string(), z.unknown())
8041
+ parameters: z.record(z.string(), z.unknown()).nullish(),
8042
+ toolCallId: z.string().nullish(),
8043
+ toolKind: z.enum(['definition', 'result']).nullish()
7978
8044
  }),
7979
8045
  before: z.object({
8046
+ content: z.string().nullish(),
7980
8047
  description: z.string().nullish(),
7981
- parameters: z.record(z.string(), z.unknown())
8048
+ parameters: z.record(z.string(), z.unknown()).nullish(),
8049
+ toolCallId: z.string().nullish(),
8050
+ toolKind: z.enum(['definition', 'result']).nullish()
7982
8051
  }),
7983
8052
  name: z.string(),
7984
8053
  op: z.enum(['edit_tool_schema'])
7985
8054
  }),
8055
+ z.object({
8056
+ after: z.array(z.object({
8057
+ arguments: z.record(z.string(), z.unknown()),
8058
+ id: z.string(),
8059
+ name: z.string()
8060
+ })),
8061
+ before: z.array(z.object({
8062
+ arguments: z.record(z.string(), z.unknown()),
8063
+ id: z.string(),
8064
+ name: z.string()
8065
+ })),
8066
+ name: z.string(),
8067
+ op: z.enum(['edit_tool_calls'])
8068
+ }),
7986
8069
  z.object({
7987
8070
  fromIndex: z.number(),
7988
8071
  name: z.string(),
@@ -8236,6 +8319,11 @@ export const zPromptsResolvePromptBody = z.object({
8236
8319
  z.number(),
8237
8320
  z.boolean()
8238
8321
  ])).nullish(),
8322
+ developerRole: z.enum([
8323
+ 'user',
8324
+ 'developer',
8325
+ 'system'
8326
+ ]).nullish(),
8239
8327
  labels: z.array(z.string().min(1).max(64).regex(/^[a-zA-Z0-9_-]+$/)).min(1).max(10),
8240
8328
  slug: z.string().min(1),
8241
8329
  subject: z.string().min(1).nullish(),
@@ -9689,10 +9777,13 @@ export const zRoutingMetricsGetRoutingProviderMetricsResponse = z.object({
9689
9777
  data: z.array(z.object({
9690
9778
  calls7dTotal: z.number(),
9691
9779
  daily: z.array(z.number()),
9780
+ errorCount: z.number(),
9781
+ errorRate: z.number(),
9692
9782
  latencyP50Ms: z.number().nullable(),
9693
9783
  latencyP95Ms: z.number().nullable(),
9694
9784
  providerId: z.string(),
9695
- requests: z.number()
9785
+ requests: z.number(),
9786
+ spend7dUsd: z.number().nullable()
9696
9787
  })).nullable(),
9697
9788
  error: z.object({
9698
9789
  code: z.string(),
@@ -65,11 +65,14 @@ export function buildFetchCacheKey(
65
65
  context?: PromptContext,
66
66
  subject?: string,
67
67
  variables?: Record<string, unknown>,
68
+ developerRole?: string,
68
69
  ): string {
69
70
  const base = buildCacheKey(projectId, slug, [env], variables);
70
71
  const ctxPart =
71
72
  context !== undefined ? JSON.stringify(sortObjectKeys(context)) : null;
72
- return `fetch|${base}|${JSON.stringify(env)}|${JSON.stringify(ctxPart)}|${JSON.stringify(subject ?? null)}`;
73
+ // `developerRole` partitions the cache; coalesce the default so omitted and
74
+ // `"user"` (the documented default) share one entry, not two.
75
+ return `fetch|${base}|${JSON.stringify(env)}|${JSON.stringify(ctxPart)}|${JSON.stringify(subject ?? null)}|${JSON.stringify(developerRole ?? "user")}`;
73
76
  }
74
77
 
75
78
  function sortObjectKeys(obj: unknown): unknown {
@@ -104,6 +104,8 @@ export type {
104
104
  RenderedPrompt,
105
105
  ResolvedPrompt,
106
106
  ResolvedPromptEnvelope,
107
+ ResolvedToolCall,
108
+ ResolvedToolDefinition,
107
109
  ResolvePromptInput,
108
110
  ResolvePromptResult,
109
111
  RowError,
@@ -123,6 +125,7 @@ const zResolvedPromptLegacy = zResolvedPrompt.pick({
123
125
  labels: true,
124
126
  contentHash: true,
125
127
  rendered: true,
128
+ tools: true,
126
129
  });
127
130
 
128
131
  const zResolvedPromptEnvelope = zResolvedPrompt
@@ -178,6 +181,12 @@ 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
+ }
181
190
  // Set `variantName` only when it is a non-empty string, so the key is
182
191
  // genuinely absent for `single`-strategy releases (R5: present IFF weighted —
183
192
  // never `null`, never `""`). A `null`/`""` from the wire is normalized to
@@ -477,6 +486,7 @@ export class PromptResource {
477
486
  variables,
478
487
  cache: useCache = true,
479
488
  fallback,
489
+ developerRole,
480
490
  } = options;
481
491
 
482
492
  const cacheKey = buildFetchCacheKey(
@@ -486,6 +496,7 @@ export class PromptResource {
486
496
  context,
487
497
  subject,
488
498
  variables,
499
+ developerRole,
489
500
  );
490
501
 
491
502
  if (useCache) {
@@ -500,6 +511,7 @@ export class PromptResource {
500
511
  if (context !== undefined) body.context = context;
501
512
  if (subject !== undefined) body.subject = subject;
502
513
  if (variables !== undefined) body.variables = variables;
514
+ if (developerRole !== undefined) body.developerRole = developerRole;
503
515
 
504
516
  try {
505
517
  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 {
@@ -44,9 +46,28 @@ export type RenderedChatMessage = GenRenderedChatPrompt["messages"][number];
44
46
 
45
47
  export type RenderedPrompt = GenRenderedPrompt;
46
48
 
49
+ /**
50
+ * A provider-neutral tool definition (`{ name, description?, parameters }`),
51
+ * sourced from authored tool-definition blocks. Surfaced on the resolved
52
+ * contract and shaped for a provider via `toOpenAITools` / `toAnthropicTools`.
53
+ */
54
+ export type ResolvedToolDefinition = GenResolvedToolDefinition;
55
+
56
+ /**
57
+ * A structured assistant tool call (`{ id, name, arguments }`) carried inline
58
+ * on a rendered `assistant` turn (few-shot multi-tool history).
59
+ */
60
+ export type ResolvedToolCall = GenResolvedToolCall;
61
+
47
62
  export type ResolvedPrompt = Pick<
48
63
  GenResolvedPrompt,
49
- "promptId" | "versionId" | "version" | "labels" | "contentHash" | "rendered"
64
+ | "promptId"
65
+ | "versionId"
66
+ | "version"
67
+ | "labels"
68
+ | "contentHash"
69
+ | "rendered"
70
+ | "tools"
50
71
  >;
51
72
 
52
73
  export interface PaginationInfo {
@@ -180,6 +201,12 @@ export interface FetchedPrompt {
180
201
  contentHash: string;
181
202
  labels: string[];
182
203
  rendered: RenderedPrompt;
204
+ /**
205
+ * Provider-neutral tool definitions lifted from authored tool-definition
206
+ * blocks. Absent (rather than `[]`) when the resolved version declares no
207
+ * tools. Shape for a provider with `toOpenAITools` / `toAnthropicTools`.
208
+ */
209
+ tools?: ResolvedToolDefinition[];
183
210
  }
184
211
 
185
212
  export type ResolvedPromptEnvelope = GenResolvedPrompt & {
@@ -187,6 +214,14 @@ export type ResolvedPromptEnvelope = GenResolvedPrompt & {
187
214
  strategy?: "single" | "weighted";
188
215
  };
189
216
 
217
+ /**
218
+ * How an authored `developer` block is rendered. The caller controls this
219
+ * per-call because it knows the upstream it targets. Omitted ⇒ `"user"`
220
+ * (back-compatible; safe for any upstream). `"developer"` preserves the role
221
+ * (OpenAI); `"system"` folds it into a system message.
222
+ */
223
+ export type DeveloperRole = "user" | "developer" | "system";
224
+
190
225
  export interface FetchPromptOptions {
191
226
  env?: string;
192
227
  context?: PromptContext;
@@ -194,6 +229,12 @@ export interface FetchPromptOptions {
194
229
  variables?: Record<string, unknown>;
195
230
  cache?: boolean;
196
231
  fallback?: ResolvedPrompt | FetchedPrompt;
232
+ /**
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.
236
+ */
237
+ developerRole?: DeveloperRole;
197
238
  }
198
239
 
199
240
  export type PaletteToken = ProjectPromptLabel["displayColor"];