@to11ai/sdk 3.0.0-rc.8 → 3.0.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.
Files changed (42) hide show
  1. package/README.md +31 -4
  2. package/dist/client.cjs +29 -21
  3. package/dist/client.d.ts +6 -0
  4. package/dist/client.js +27 -19
  5. package/dist/errors.cjs +15 -16
  6. package/dist/errors.js +15 -15
  7. package/dist/gateway.cjs +11 -11
  8. package/dist/gateway.js +11 -11
  9. package/dist/generated/index.d.ts +1 -1
  10. package/dist/generated/types.gen.d.ts +9495 -4795
  11. package/dist/generated/zod.gen.d.ts +8260 -4911
  12. package/dist/pagination.d.ts +32 -0
  13. package/dist/projectEnvironments/resource.cjs +20 -2
  14. package/dist/projectEnvironments/resource.d.ts +21 -5
  15. package/dist/projectEnvironments/resource.js +20 -2
  16. package/dist/projectEnvironments/types.d.ts +14 -1
  17. package/dist/prompts/resource.cjs +49 -3
  18. package/dist/prompts/resource.d.ts +41 -2
  19. package/dist/prompts/resource.js +61 -5
  20. package/dist/prompts/types.d.ts +40 -15
  21. package/dist/routingRules/resource.d.ts +44 -2
  22. package/dist/routingRules/types.d.ts +33 -3
  23. package/dist/transport.d.ts +5 -1
  24. package/dist/usage/resource.cjs +113 -0
  25. package/dist/usage/resource.d.ts +29 -0
  26. package/dist/usage/resource.js +78 -0
  27. package/dist/usage/types.d.ts +81 -0
  28. package/package.json +14 -6
  29. package/src/client.ts +12 -0
  30. package/src/generated/index.ts +1 -1
  31. package/src/generated/types.gen.ts +9670 -4790
  32. package/src/generated/zod.gen.ts +6112 -3115
  33. package/src/pagination.ts +64 -0
  34. package/src/projectEnvironments/resource.ts +44 -9
  35. package/src/projectEnvironments/types.ts +19 -1
  36. package/src/prompts/resource.ts +149 -4
  37. package/src/prompts/types.ts +56 -15
  38. package/src/routingRules/resource.ts +77 -5
  39. package/src/routingRules/types.ts +35 -3
  40. package/src/transport.ts +14 -2
  41. package/src/usage/resource.ts +183 -0
  42. package/src/usage/types.ts +121 -0
@@ -0,0 +1,64 @@
1
+ import { To11aiError } from "./errors";
2
+
3
+ /**
4
+ * Keyset paging, as every cursor list in the API answers it. `nextCursor` is
5
+ * the opaque cursor of the next page and `null` on the last one; `limit` is
6
+ * the page size the server applied (its default when the call passed none,
7
+ * clamped to its max).
8
+ */
9
+ export interface CursorPaginationInfo {
10
+ nextCursor: string | null;
11
+ limit: number;
12
+ }
13
+
14
+ /** One page of a cursor list: `{ items, pagination: { nextCursor, limit } }`. */
15
+ export interface CursorPaginatedResult<T> {
16
+ items: T[];
17
+ pagination: CursorPaginationInfo;
18
+ }
19
+
20
+ /**
21
+ * Fetches one page. `cursor` is `undefined` for the first page and the
22
+ * previous page's `pagination.nextCursor` after that.
23
+ */
24
+ export type FetchCursorPage<T> = (
25
+ cursor: string | undefined,
26
+ ) => Promise<CursorPaginatedResult<T>>;
27
+
28
+ /**
29
+ * Walks a cursor list page by page, yielding each page as the server returned
30
+ * it. Stops after the page whose `nextCursor` is `null` or empty. Throws a
31
+ * `To11aiError` when the server hands back a cursor it already returned, so a
32
+ * misbehaving endpoint cannot loop the caller forever.
33
+ */
34
+ export async function* iterateCursorPages<T>(
35
+ fetchPage: FetchCursorPage<T>,
36
+ ): AsyncGenerator<CursorPaginatedResult<T>, void, undefined> {
37
+ const seen = new Set<string>();
38
+ let cursor: string | undefined;
39
+ for (;;) {
40
+ const page = await fetchPage(cursor);
41
+ yield page;
42
+ const next = page.pagination.nextCursor;
43
+ if (next === null || next === undefined || next === "") return;
44
+ if (seen.has(next)) {
45
+ throw new To11aiError(
46
+ `Cursor pagination returned a cursor it already returned ("${next}"); stopping to avoid an endless loop.`,
47
+ );
48
+ }
49
+ seen.add(next);
50
+ cursor = next;
51
+ }
52
+ }
53
+
54
+ /**
55
+ * Walks a cursor list and yields its items one by one, across every page.
56
+ * Same stop rules as `iterateCursorPages`.
57
+ */
58
+ export async function* iterateCursorItems<T>(
59
+ fetchPage: FetchCursorPage<T>,
60
+ ): AsyncGenerator<T, void, undefined> {
61
+ for await (const page of iterateCursorPages(fetchPage)) {
62
+ yield* page.items;
63
+ }
64
+ }
@@ -11,6 +11,7 @@
11
11
 
12
12
  import { z } from "zod";
13
13
  import { zProjectEnvironment } from "../generated/zod.gen";
14
+ import { iterateCursorItems } from "../pagination";
14
15
  import type { ApiEnvelope, Transport } from "../transport";
15
16
  import type {
16
17
  ArchiveProjectEnvironmentInput,
@@ -19,8 +20,10 @@ import type {
19
20
  CreateProjectEnvironmentResult,
20
21
  GetProjectEnvironmentInput,
21
22
  GetProjectEnvironmentResult,
23
+ IterateProjectEnvironmentsInput,
22
24
  ListProjectEnvironmentsInput,
23
25
  ListProjectEnvironmentsResult,
26
+ ProjectEnvironment,
24
27
  RestoreProjectEnvironmentInput,
25
28
  RestoreProjectEnvironmentResult,
26
29
  UpdateProjectEnvironmentInput,
@@ -35,6 +38,7 @@ export type {
35
38
  CreateProjectEnvironmentResult,
36
39
  GetProjectEnvironmentInput,
37
40
  GetProjectEnvironmentResult,
41
+ IterateProjectEnvironmentsInput,
38
42
  ListProjectEnvironmentsInput,
39
43
  ListProjectEnvironmentsResult,
40
44
  ProjectEnvironment,
@@ -44,6 +48,14 @@ export type {
44
48
  UpdateProjectEnvironmentResult,
45
49
  } from "./types";
46
50
 
51
+ const zProjectEnvironmentPage = z.object({
52
+ items: z.array(zProjectEnvironment),
53
+ pagination: z.object({
54
+ nextCursor: z.string().nullable(),
55
+ limit: z.number().int(),
56
+ }),
57
+ });
58
+
47
59
  function unwrap<T>(envelope: ApiEnvelope<T>): T {
48
60
  if (envelope.data === null || envelope.data === undefined) {
49
61
  throw new Error("API returned success but data is null");
@@ -73,30 +85,53 @@ export class ProjectEnvironmentResource {
73
85
  // ─── List ────────────────────────────────────────────────────────────────
74
86
 
75
87
  /**
76
- * List the project's environments. Excludes archived rows by default —
77
- * pass `includeArchived: true` to include rows with a non-null
78
- * `archivedAt` (used by the admin / restore UI).
88
+ * One page of the project's environments, in settings order (`sortOrder`,
89
+ * then `slug`). Excludes archived rows by default — pass
90
+ * `includeArchived: true` to include rows with a non-null `archivedAt`
91
+ * (used by the admin / restore UI). The result mirrors the wire shape,
92
+ * `{ items, pagination: { nextCursor, limit } }`; pass
93
+ * `pagination.nextCursor` back as `cursor` until it is `null`, or use
94
+ * `iterate()`.
79
95
  */
80
96
  async list(
81
97
  input: ListProjectEnvironmentsInput,
82
98
  ): Promise<ListProjectEnvironmentsResult> {
99
+ const query: Record<string, string | number> = {};
100
+ if (input.includeArchived) query.includeArchived = "true";
101
+ if (input.cursor !== undefined) query.cursor = input.cursor;
102
+ if (input.limit !== undefined) query.limit = input.limit;
83
103
  const envelope =
84
104
  await this.transport.request<ListProjectEnvironmentsResult>(
85
105
  "GET",
86
106
  projectEnvironmentsPath(input.projectId),
87
107
  {
88
- query: input.includeArchived
89
- ? { includeArchived: "true" }
90
- : undefined,
108
+ query,
91
109
  decode: (data) =>
92
- z
93
- .array(zProjectEnvironment)
94
- .parse(data) as ListProjectEnvironmentsResult,
110
+ zProjectEnvironmentPage.parse(
111
+ data,
112
+ ) as ListProjectEnvironmentsResult,
95
113
  },
96
114
  );
97
115
  return unwrap(envelope);
98
116
  }
99
117
 
118
+ /**
119
+ * Every environment of the project: walks `list()` page by page until
120
+ * `pagination.nextCursor` is `null` and yields one environment at a time.
121
+ * Throws a `To11aiError` if the server repeats a cursor.
122
+ *
123
+ * ```ts
124
+ * for await (const env of to11.projectEnvironments.iterate({ projectId })) {
125
+ * console.log(env.slug);
126
+ * }
127
+ * ```
128
+ */
129
+ iterate(
130
+ input: IterateProjectEnvironmentsInput,
131
+ ): AsyncGenerator<ProjectEnvironment, void, undefined> {
132
+ return iterateCursorItems((cursor) => this.list({ ...input, cursor }));
133
+ }
134
+
100
135
  // ─── Get ─────────────────────────────────────────────────────────────────
101
136
 
102
137
  async get(
@@ -2,6 +2,7 @@ import type {
2
2
  ArchiveProjectEnvironmentResult as GenArchiveProjectEnvironmentResult,
3
3
  ProjectEnvironment as GenProjectEnvironment,
4
4
  } from "../generated/types.gen";
5
+ import type { CursorPaginatedResult } from "../pagination";
5
6
 
6
7
  export type ProjectEnvironment = GenProjectEnvironment;
7
8
 
@@ -11,9 +12,26 @@ export type ArchiveProjectEnvironmentResult =
11
12
  export interface ListProjectEnvironmentsInput {
12
13
  projectId: string;
13
14
  includeArchived?: boolean;
15
+ /** `pagination.nextCursor` of the previous page. Omit for the first page. */
16
+ cursor?: string;
17
+ /** Page size. The server defaults to 100 and clamps to [1, 100]. */
18
+ limit?: number;
14
19
  }
15
20
 
16
- export type ListProjectEnvironmentsResult = ProjectEnvironment[];
21
+ /**
22
+ * Input of `iterate()`: `list()` without `cursor`, which the walk supplies.
23
+ */
24
+ export type IterateProjectEnvironmentsInput = Omit<
25
+ ListProjectEnvironmentsInput,
26
+ "cursor"
27
+ >;
28
+
29
+ /**
30
+ * One page of a project's environments, in settings order (`sortOrder`,
31
+ * then `slug`).
32
+ */
33
+ export type ListProjectEnvironmentsResult =
34
+ CursorPaginatedResult<ProjectEnvironment>;
17
35
 
18
36
  export interface GetProjectEnvironmentInput {
19
37
  projectId: string;
@@ -1,5 +1,16 @@
1
- import { To11aiApiError, To11aiNetworkError } from "../errors";
2
- import { zResolvedPrompt } from "../generated/zod.gen";
1
+ import {
2
+ To11aiApiError,
3
+ To11aiNetworkError,
4
+ To11aiValidationError,
5
+ } from "../errors";
6
+ import {
7
+ zOrgPromptsListOrgPromptsResponse,
8
+ zPromptsListPromptLabelsResponse,
9
+ zPromptsListPromptVersionsResponse,
10
+ zPromptsRenderSkillVersionResponse,
11
+ zResolvedPrompt,
12
+ } from "../generated/zod.gen";
13
+ import { iterateCursorItems } from "../pagination";
3
14
  import type { ApiEnvelope, Transport } from "../transport";
4
15
  import type {
5
16
  AnthropicRenderedPrompt,
@@ -18,6 +29,10 @@ import type {
18
29
  GetPromptResult,
19
30
  GetPromptVersionInput,
20
31
  GetPromptVersionResult,
32
+ IterateLabelsInput,
33
+ IterateVersionsInput,
34
+ ListOrgPromptsInput,
35
+ ListOrgPromptsResult,
21
36
  ListPromptLabelsInput,
22
37
  ListPromptLabelsResult,
23
38
  ListPromptsInput,
@@ -25,10 +40,14 @@ import type {
25
40
  ListPromptVersionsInput,
26
41
  ListPromptVersionsResult,
27
42
  PaginatedResult,
43
+ PromptLabelPointer,
44
+ PromptVersionSummary,
28
45
  RenderedChatMessage,
29
46
  RenderedPrompt,
47
+ RenderedSkillVersion,
30
48
  RenderFormat,
31
49
  RenderOptions,
50
+ RenderSkillVersionInput,
32
51
  ResolvedPrompt,
33
52
  ResolvedPromptEnvelope,
34
53
  UnknownRoleMode,
@@ -53,12 +72,17 @@ export type {
53
72
  GetPromptResult,
54
73
  GetPromptVersionInput,
55
74
  GetPromptVersionResult,
75
+ IterateLabelsInput,
76
+ IterateVersionsInput,
77
+ ListOrgPromptsInput,
78
+ ListOrgPromptsResult,
56
79
  ListPromptLabelsInput,
57
80
  ListPromptLabelsResult,
58
81
  ListPromptsInput,
59
82
  ListPromptsResult,
60
83
  ListPromptVersionsInput,
61
84
  ListPromptVersionsResult,
85
+ OrgPromptRow,
62
86
  PaginatedResult,
63
87
  PaginationInfo,
64
88
  Prompt,
@@ -69,8 +93,11 @@ export type {
69
93
  PromptVersionSummary,
70
94
  RenderedChatMessage,
71
95
  RenderedPrompt,
96
+ RenderedSkillFile,
97
+ RenderedSkillVersion,
72
98
  RenderFormat,
73
99
  RenderOptions,
100
+ RenderSkillVersionInput,
74
101
  ResolvedPrompt,
75
102
  ResolvedPromptEnvelope,
76
103
  ResolvedToolCall,
@@ -87,6 +114,13 @@ export type {
87
114
  */
88
115
  const LATEST_PROMPT_LABEL = "latest";
89
116
 
117
+ // The cursor pages, validated so a wrong-shaped response raises
118
+ // To11aiResponseValidationError instead of a TypeError while paging.
119
+ const versionsPage = zPromptsListPromptVersionsResponse.shape.data.unwrap();
120
+ const labelsPage = zPromptsListPromptLabelsResponse.shape.data.unwrap();
121
+ const orgPromptsData = zOrgPromptsListOrgPromptsResponse.shape.data.unwrap();
122
+ const skillVersionData = zPromptsRenderSkillVersionResponse.shape.data.unwrap();
123
+
90
124
  function unwrap<T>(envelope: ApiEnvelope<T>): T {
91
125
  if (envelope.data === null || envelope.data === undefined) {
92
126
  throw new Error("API returned success but data is null");
@@ -190,6 +224,23 @@ function liftFallbackToRendered(
190
224
  return { ...structuredClone(fallback), slug: fallback.slug || slug };
191
225
  }
192
226
 
227
+ /**
228
+ * `encodeURIComponent` leaves `.` alone, and URL parsing resolves a `.` or
229
+ * `..` segment, so such a path param would send the request to a different
230
+ * route. Refuse it before any request is made.
231
+ */
232
+ function rejectDotSegments(params: Record<string, string>): void {
233
+ for (const [name, value] of Object.entries(params)) {
234
+ if (value === "." || value === "..") {
235
+ throw new To11aiValidationError(
236
+ `[to11ai/sdk] \`${name}\` cannot be "${value}": a path segment of only dots`,
237
+ "invalid_path_param",
238
+ { param: name },
239
+ );
240
+ }
241
+ }
242
+ }
243
+
193
244
  function getProjectPromptPath(projectId: string, promptId: string): string {
194
245
  return `${getProjectPromptsPath(projectId)}/${encodeURIComponent(promptId)}`;
195
246
  }
@@ -369,11 +420,34 @@ export class PromptResource<F extends RenderFormat | undefined = undefined> {
369
420
  const envelope = await this.transport.request<ListPromptVersionsResult>(
370
421
  "GET",
371
422
  `${getProjectPromptPath(projectId, promptId)}/versions`,
372
- { query },
423
+ {
424
+ query,
425
+ decode: (data) => versionsPage.parse(data) as ListPromptVersionsResult,
426
+ },
373
427
  );
374
428
  return unwrap(envelope);
375
429
  }
376
430
 
431
+ /**
432
+ * Every version of a prompt, newest first, as summaries: walks
433
+ * `listVersions()` page by page until `pagination.nextCursor` is `null` and
434
+ * yields one `PromptVersionSummary` at a time. `limit` sets the page size of
435
+ * each request. Throws a `To11aiError` if the server repeats a cursor.
436
+ *
437
+ * ```ts
438
+ * for await (const version of to11.prompts.iterateVersions({ promptId })) {
439
+ * console.log(version.version);
440
+ * }
441
+ * ```
442
+ */
443
+ iterateVersions(
444
+ input: IterateVersionsInput,
445
+ ): AsyncGenerator<PromptVersionSummary, void, undefined> {
446
+ return iterateCursorItems((cursor) =>
447
+ this.listVersions({ ...input, cursor }),
448
+ );
449
+ }
450
+
377
451
  // ─── Get Version ──────────────────────────────────────────────────────────
378
452
 
379
453
  async getVersion(
@@ -390,14 +464,85 @@ export class PromptResource<F extends RenderFormat | undefined = undefined> {
390
464
 
391
465
  // ─── List Labels ──────────────────────────────────────────────────────────
392
466
 
467
+ /**
468
+ * One page of a prompt's labels, by label name (today only `latest`). The
469
+ * result mirrors the wire shape, `{ items, pagination: { nextCursor,
470
+ * limit } }`; pass `pagination.nextCursor` back as `cursor` until it is
471
+ * `null`, or use `iterateLabels()`.
472
+ */
393
473
  async listLabels(
394
474
  input: ListPromptLabelsInput,
395
475
  ): Promise<ListPromptLabelsResult> {
396
- const { projectId: perCallProjectId, promptId } = input;
476
+ const { projectId: perCallProjectId, promptId, cursor, limit } = input;
397
477
  const projectId = this.resolveProjectId(perCallProjectId);
478
+ const query: Record<string, string | number | undefined> = {};
479
+ if (cursor !== undefined) query.cursor = cursor;
480
+ if (limit !== undefined) query.limit = limit;
398
481
  const envelope = await this.transport.request<ListPromptLabelsResult>(
399
482
  "GET",
400
483
  `${getProjectPromptPath(projectId, promptId)}/labels`,
484
+ {
485
+ query,
486
+ decode: (data) => labelsPage.parse(data) as ListPromptLabelsResult,
487
+ },
488
+ );
489
+ return unwrap(envelope);
490
+ }
491
+
492
+ /**
493
+ * Every label of a prompt: walks `listLabels()` page by page until
494
+ * `pagination.nextCursor` is `null`. Throws a `To11aiError` if the server
495
+ * repeats a cursor.
496
+ */
497
+ iterateLabels(
498
+ input: IterateLabelsInput,
499
+ ): AsyncGenerator<PromptLabelPointer, void, undefined> {
500
+ return iterateCursorItems((cursor) =>
501
+ this.listLabels({ ...input, cursor }),
502
+ );
503
+ }
504
+
505
+ // ─── Org skills (TO11-3690) ───────────────────────────────────────────────
506
+
507
+ /**
508
+ * Skills across every project of `orgId` the caller may read prompts in,
509
+ * each with the version its `latest` label serves at listing time. At most
510
+ * `limit` rows (default 20, max 50): a picker, not a list to page. Projects
511
+ * the read left out are listed in `excludedProjects`.
512
+ */
513
+ async listOrgPrompts(
514
+ input: ListOrgPromptsInput,
515
+ ): Promise<ListOrgPromptsResult> {
516
+ const { orgId, kind, query, limit } = input;
517
+ const envelope = await this.transport.request<ListOrgPromptsResult>(
518
+ "GET",
519
+ `/v1/orgs/${encodeURIComponent(orgId)}/prompts`,
520
+ {
521
+ query: { kind, query, limit },
522
+ decode: (data) => orgPromptsData.parse(data) as ListOrgPromptsResult,
523
+ },
524
+ );
525
+ return unwrap(envelope);
526
+ }
527
+
528
+ /**
529
+ * One exact version of a skill, by slug, with its files. Pass the
530
+ * `version` `listOrgPrompts()` returned so the caller runs exactly the
531
+ * version it listed, whatever `latest` serves by then. A chat prompt at
532
+ * this address is a 409.
533
+ */
534
+ async renderSkillVersion(
535
+ input: RenderSkillVersionInput,
536
+ ): Promise<RenderedSkillVersion> {
537
+ const projectId = this.resolveProjectId(input.projectId);
538
+ rejectDotSegments({ projectId, slug: input.slug });
539
+ const envelope = await this.transport.request<RenderedSkillVersion>(
540
+ "POST",
541
+ `${getProjectPromptsPath(projectId)}/by-slug/${encodeURIComponent(input.slug)}/versions/${encodeURIComponent(String(input.version))}/render`,
542
+ {
543
+ body: {},
544
+ decode: (data) => skillVersionData.parse(data) as RenderedSkillVersion,
545
+ },
401
546
  );
402
547
  return unwrap(envelope);
403
548
  }
@@ -1,13 +1,18 @@
1
1
  import type {
2
+ OrgPromptRow as GenOrgPromptRow,
3
+ OrgPromptsResponse as GenOrgPromptsResponse,
2
4
  Prompt as GenPrompt,
3
5
  PromptLabelPointer as GenPromptLabelPointer,
4
6
  PromptVersion as GenPromptVersion,
5
7
  PromptVersionSummary as GenPromptVersionSummary,
6
8
  RenderedChatPrompt as GenRenderedChatPrompt,
9
+ RenderedSkillFile as GenRenderedSkillFile,
10
+ RenderedSkillVersion as GenRenderedSkillVersion,
7
11
  ResolvedPrompt as GenResolvedPrompt,
8
12
  ResolvedToolCall as GenResolvedToolCall,
9
13
  ResolvedToolDefinition as GenResolvedToolDefinition,
10
14
  } from "../generated/types.gen";
15
+ import type { CursorPaginatedResult } from "../pagination";
11
16
 
12
17
  export interface RowError {
13
18
  path: ReadonlyArray<string | number>;
@@ -88,20 +93,12 @@ export interface PaginatedResult<T> {
88
93
  pagination: PaginationInfo;
89
94
  }
90
95
 
91
- /**
92
- * Keyset paging, as the audit feeds use it. `nextCursor` is the opaque cursor
93
- * of the next page and `null` on the last one; `limit` is the page size the
94
- * server applied (its default when the call passed none, clamped to its max).
95
- */
96
- export interface CursorPaginationInfo {
97
- nextCursor: string | null;
98
- limit: number;
99
- }
100
-
101
- export interface CursorPaginatedResult<T> {
102
- items: T[];
103
- pagination: CursorPaginationInfo;
104
- }
96
+ // The cursor page shapes are shared by every cursor list; they live in
97
+ // `../pagination` and stay re-exported here for existing imports.
98
+ export type {
99
+ CursorPaginatedResult,
100
+ CursorPaginationInfo,
101
+ } from "../pagination";
105
102
 
106
103
  export interface CreatePromptInput {
107
104
  projectId?: string;
@@ -169,6 +166,12 @@ export interface ListPromptVersionsInput {
169
166
  limit?: number;
170
167
  }
171
168
 
169
+ /**
170
+ * Input of `iterateVersions()`: `listVersions()` without `cursor`, which the
171
+ * iterator manages. `limit` is the page size of each request.
172
+ */
173
+ export type IterateVersionsInput = Omit<ListPromptVersionsInput, "cursor">;
174
+
172
175
  /**
173
176
  * One page of a prompt's versions, newest first, as summaries. Read a
174
177
  * version's content with `getVersion()`.
@@ -187,9 +190,20 @@ export type GetPromptVersionResult = PromptVersion;
187
190
  export interface ListPromptLabelsInput {
188
191
  projectId?: string;
189
192
  promptId: string;
193
+ /** `pagination.nextCursor` of the previous page. Omit for the first page. */
194
+ cursor?: string;
195
+ /** Page size. The server defaults to 100 and clamps to [1, 100]. */
196
+ limit?: number;
190
197
  }
191
198
 
192
- export type ListPromptLabelsResult = PromptLabelPointer[];
199
+ /**
200
+ * Input of `iterateLabels()`: `listLabels()` without `cursor`, which the walk
201
+ * supplies.
202
+ */
203
+ export type IterateLabelsInput = Omit<ListPromptLabelsInput, "cursor">;
204
+
205
+ /** One page of a prompt's labels, by label name. Today only `latest`. */
206
+ export type ListPromptLabelsResult = CursorPaginatedResult<PromptLabelPointer>;
193
207
 
194
208
  /**
195
209
  * Slug rule shared by the client `env` (the gateway's `x-to11-env` routing key)
@@ -266,3 +280,30 @@ export interface RenderOptions {
266
280
  */
267
281
  onUnknownRole?: UnknownRoleMode;
268
282
  }
283
+
284
+ // ─── Org prompts (TO11-3690) ─────────────────────────────────────────────────
285
+
286
+ /** `GET /v1/orgs/:orgId/prompts`: skills across the projects the caller reads. */
287
+ export interface ListOrgPromptsInput {
288
+ readonly orgId: string;
289
+ /** Only `skill` today; the server's default. */
290
+ readonly kind?: "skill";
291
+ /** Case-insensitive substring of the skill's name or slug; 1–100 chars. */
292
+ readonly query?: string;
293
+ /** Default 20, max 50: a picker, not a list to page. */
294
+ readonly limit?: number;
295
+ }
296
+
297
+ /** One skill and the version its `latest` label serves at listing time. */
298
+ export type OrgPromptRow = GenOrgPromptRow;
299
+ export type ListOrgPromptsResult = GenOrgPromptsResponse;
300
+
301
+ /** Render one exact skill version (`OrgPromptRow.version`) by slug. */
302
+ export interface RenderSkillVersionInput {
303
+ readonly projectId: string;
304
+ readonly slug: string;
305
+ readonly version: number;
306
+ }
307
+
308
+ export type RenderedSkillVersion = GenRenderedSkillVersion;
309
+ export type RenderedSkillFile = GenRenderedSkillFile;
@@ -1,17 +1,26 @@
1
- import { z } from "zod";
2
- import { zRuleRelease, zRuleVersion } from "../generated/zod.gen";
1
+ import {
2
+ zRuleReleasesListRuleReleasesEnvResponse,
3
+ zRuleReleasesListRuleReleasesResponse,
4
+ zRuleVersion,
5
+ zRuleVersionsListRuleVersionsResponse,
6
+ } from "../generated/zod.gen";
7
+ import { iterateCursorItems } from "../pagination";
3
8
  import type { ApiEnvelope, Transport } from "../transport";
4
9
  import type {
5
10
  CreateRuleVersionInput,
6
11
  CreateRuleVersionResult,
7
12
  GetRuleVersionInput,
8
13
  GetRuleVersionResult,
14
+ IterateRuleReleasesInput,
15
+ IterateRuleVersionsInput,
9
16
  ListRuleReleasesInput,
10
17
  ListRuleReleasesResult,
11
18
  ListRuleVersionsInput,
12
19
  ListRuleVersionsResult,
13
20
  RollbackRuleReleaseInput,
14
21
  RollbackRuleReleaseResult,
22
+ RuleRelease,
23
+ RuleVersion,
15
24
  SetRuleReleaseInput,
16
25
  SetRuleReleaseResult,
17
26
  } from "./types";
@@ -21,6 +30,8 @@ export type {
21
30
  CreateRuleVersionResult,
22
31
  GetRuleVersionInput,
23
32
  GetRuleVersionResult,
33
+ IterateRuleReleasesInput,
34
+ IterateRuleVersionsInput,
24
35
  ListRuleReleasesInput,
25
36
  ListRuleReleasesResult,
26
37
  ListRuleVersionsInput,
@@ -42,6 +53,12 @@ export type {
42
53
  SetRuleReleaseResult,
43
54
  } from "./types";
44
55
 
56
+ // The page schemas are the `data` of the generated envelope schemas.
57
+ const versionsPage = zRuleVersionsListRuleVersionsResponse.shape.data.unwrap();
58
+ const releasesPage = zRuleReleasesListRuleReleasesResponse.shape.data.unwrap();
59
+ const releasesEnvPage =
60
+ zRuleReleasesListRuleReleasesEnvResponse.shape.data.unwrap();
61
+
45
62
  function unwrap<T>(envelope: ApiEnvelope<T>): T {
46
63
  if (envelope.data === null || envelope.data === undefined) {
47
64
  throw new Error("API returned success but data is null");
@@ -104,6 +121,13 @@ export class RoutingRuleVersionResource {
104
121
  return unwrap(envelope);
105
122
  }
106
123
 
124
+ /**
125
+ * One page of a rule's versions, newest first. The result mirrors the wire
126
+ * shape, `{ items, pagination: { nextCursor, limit } }`; pass
127
+ * `pagination.nextCursor` back as `cursor` until it is `null`. Pass only a
128
+ * cursor this list returned: a malformed or unreadable one answers 400
129
+ * `invalid_cursor`.
130
+ */
107
131
  async list(input: ListRuleVersionsInput): Promise<ListRuleVersionsResult> {
108
132
  const query: Record<string, string | number | undefined> = {};
109
133
  if (input.cursor !== undefined) query.cursor = input.cursor;
@@ -111,11 +135,32 @@ export class RoutingRuleVersionResource {
111
135
  const envelope = await this.transport.request<ListRuleVersionsResult>(
112
136
  "GET",
113
137
  versionsPath(input.projectId, input.ruleId),
114
- { query },
138
+ {
139
+ query,
140
+ decode: (data) => versionsPage.parse(data) as ListRuleVersionsResult,
141
+ },
115
142
  );
116
143
  return unwrap(envelope);
117
144
  }
118
145
 
146
+ /**
147
+ * Every version of a rule, newest first: walks `list()` page by page until
148
+ * `pagination.nextCursor` is `null` and yields one `RuleVersion` at a time.
149
+ * `limit` sets the page size of each request. Throws a `To11aiError` if the
150
+ * server repeats a cursor.
151
+ *
152
+ * ```ts
153
+ * for await (const version of rules.versions.iterate({ projectId, ruleId })) {
154
+ * console.log(version.version);
155
+ * }
156
+ * ```
157
+ */
158
+ iterate(
159
+ input: IterateRuleVersionsInput,
160
+ ): AsyncGenerator<RuleVersion, void, undefined> {
161
+ return iterateCursorItems((cursor) => this.list({ ...input, cursor }));
162
+ }
163
+
119
164
  async get(input: GetRuleVersionInput): Promise<GetRuleVersionResult> {
120
165
  const envelope = await this.transport.request<GetRuleVersionResult>(
121
166
  "GET",
@@ -157,10 +202,20 @@ export class RoutingRuleReleaseResource {
157
202
  return unwrap(envelope);
158
203
  }
159
204
 
205
+ /**
206
+ * One page of a rule's releases, newest first. Without `envSlug` it lists
207
+ * every environment's releases; with it, one environment's. The result
208
+ * mirrors the wire shape, `{ items, pagination: { nextCursor, limit } }`;
209
+ * pass `pagination.nextCursor` back as `cursor` until it is `null`. Pass
210
+ * only a cursor this list returned: a malformed or unreadable one answers
211
+ * 400 `invalid_cursor`, while a well-formed cursor from another list is
212
+ * accepted and continues from its position, which can skip releases.
213
+ */
160
214
  async list(input: ListRuleReleasesInput): Promise<ListRuleReleasesResult> {
161
215
  const query: Record<string, string | number | undefined> = {};
162
216
  if (input.cursor !== undefined) query.cursor = input.cursor;
163
217
  if (input.limit !== undefined) query.limit = input.limit;
218
+ const page = input.envSlug !== undefined ? releasesEnvPage : releasesPage;
164
219
  const path =
165
220
  input.envSlug !== undefined
166
221
  ? releasePath(input.projectId, input.ruleId, input.envSlug)
@@ -170,12 +225,29 @@ export class RoutingRuleReleaseResource {
170
225
  path,
171
226
  {
172
227
  query,
173
- decode: (data) =>
174
- z.array(zRuleRelease).parse(data) as ListRuleReleasesResult,
228
+ decode: (data) => page.parse(data) as ListRuleReleasesResult,
175
229
  },
176
230
  );
177
231
  return unwrap(envelope);
178
232
  }
233
+
234
+ /**
235
+ * Every release of a rule, newest first: walks `list()` page by page until
236
+ * `pagination.nextCursor` is `null` and yields one `RuleRelease` at a time.
237
+ * `limit` sets the page size of each request. Throws a `To11aiError` if the
238
+ * server repeats a cursor.
239
+ *
240
+ * ```ts
241
+ * for await (const release of rules.releases.iterate({ projectId, ruleId })) {
242
+ * console.log(release.envSlug, release.changeKind);
243
+ * }
244
+ * ```
245
+ */
246
+ iterate(
247
+ input: IterateRuleReleasesInput,
248
+ ): AsyncGenerator<RuleRelease, void, undefined> {
249
+ return iterateCursorItems((cursor) => this.list({ ...input, cursor }));
250
+ }
179
251
  }
180
252
 
181
253
  export class RoutingRulesResource {