@to11ai/sdk 3.0.0-rc.8 → 3.0.0-rc.9

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.
package/dist/client.cjs CHANGED
@@ -39,6 +39,8 @@ var __export = (target, all) => {
39
39
  // src/client.ts
40
40
  var exports_client = {};
41
41
  __export(exports_client, {
42
+ iterateCursorPages: () => import_pagination.iterateCursorPages,
43
+ iterateCursorItems: () => import_pagination.iterateCursorItems,
42
44
  gatewayPromptHeaders: () => import_gateway2.gatewayPromptHeaders,
43
45
  gatewayAuthHeaders: () => import_gateway2.gatewayAuthHeaders,
44
46
  createClient: () => createClient,
@@ -72,6 +74,7 @@ var import_transport = require("./transport");
72
74
  var import_context2 = require("./context");
73
75
  var import_errors = require("./errors");
74
76
  var import_gateway2 = require("./gateway");
77
+ var import_pagination = require("./pagination");
75
78
  var import_resource3 = require("./projectEnvironments/resource");
76
79
  var import_resource4 = require("./prompts/resource");
77
80
  var import_types2 = require("./prompts/types");
package/dist/client.d.ts CHANGED
@@ -8,6 +8,8 @@ export type { PromptHasNoVersionsReason, PromptNotFoundReason, PromptPolicyViola
8
8
  export { LabelNotFoundError, PromptHasNoVersionsError, PromptNotFoundError, PromptPolicyViolationError, To11aiApiError, To11aiAuthError, To11aiError, To11aiNetworkError, To11aiRateLimitError, To11aiValidationError, UnknownRoleError, } from "./errors";
9
9
  export type { ConvertMessagesOptions, GatewayAuthOptions } from "./gateway";
10
10
  export { gatewayAuthHeaders, gatewayPromptHeaders } from "./gateway";
11
+ export type { CursorPaginatedResult, CursorPaginationInfo, FetchCursorPage, } from "./pagination";
12
+ export { iterateCursorItems, iterateCursorPages } from "./pagination";
11
13
  export type { ArchiveProjectEnvironmentInput, ArchiveProjectEnvironmentResult, CreateProjectEnvironmentInput, CreateProjectEnvironmentResult, GetProjectEnvironmentInput, GetProjectEnvironmentResult, ListProjectEnvironmentsInput, ListProjectEnvironmentsResult, ProjectEnvironment, RestoreProjectEnvironmentInput, RestoreProjectEnvironmentResult, UpdateProjectEnvironmentInput, UpdateProjectEnvironmentResult, } from "./projectEnvironments/resource";
12
14
  export { ProjectEnvironmentResource } from "./projectEnvironments/resource";
13
15
  export type { PromptResourceConfig } from "./prompts/resource";
package/dist/client.js CHANGED
@@ -26,6 +26,7 @@ import {
26
26
  UnknownRoleError
27
27
  } from "./errors";
28
28
  import { gatewayAuthHeaders as gatewayAuthHeaders2, gatewayPromptHeaders } from "./gateway";
29
+ import { iterateCursorItems, iterateCursorPages } from "./pagination";
29
30
  import { ProjectEnvironmentResource as ProjectEnvironmentResource2 } from "./projectEnvironments/resource";
30
31
  import { PromptResource as PromptResource2 } from "./prompts/resource";
31
32
  import { ENV_SLUG_REGEX as ENV_SLUG_REGEX2 } from "./prompts/types";
@@ -129,6 +130,8 @@ function createClient(options = {}) {
129
130
  };
130
131
  }
131
132
  export {
133
+ iterateCursorPages,
134
+ iterateCursorItems,
132
135
  gatewayPromptHeaders,
133
136
  gatewayAuthHeaders2 as gatewayAuthHeaders,
134
137
  createClient,
@@ -1695,7 +1695,7 @@ export type ApiKeysListApiKeysData = {
1695
1695
  expiry?: string | null;
1696
1696
  q?: string | null;
1697
1697
  cursor?: string | null;
1698
- limit: string;
1698
+ limit?: number | null;
1699
1699
  includeRevoked: 'true' | 'false';
1700
1700
  includeCounts: 'true' | 'false';
1701
1701
  };
@@ -1765,7 +1765,7 @@ export type ApiKeysListApiKeysResponses = {
1765
1765
  revoked: number;
1766
1766
  rotating: number;
1767
1767
  };
1768
- keys: Array<{
1768
+ items: Array<{
1769
1769
  calls7d: number;
1770
1770
  createdAt: string;
1771
1771
  createdBy: {
@@ -1797,7 +1797,10 @@ export type ApiKeysListApiKeysResponses = {
1797
1797
  status: 'active' | 'revoked' | 'rotating' | 'expired';
1798
1798
  workspaceId: string | null;
1799
1799
  }>;
1800
- nextCursor: string | null;
1800
+ pagination: {
1801
+ limit: number;
1802
+ nextCursor: string | null;
1803
+ };
1801
1804
  viewerScopeAccess: 'none' | 'scoped' | 'full';
1802
1805
  } | null;
1803
1806
  error: {
@@ -4530,8 +4533,8 @@ export type OrgAuditListOrgAuditEventsData = {
4530
4533
  workspace_id?: string | null;
4531
4534
  since?: string | null;
4532
4535
  until?: string | null;
4533
- limit?: string | null;
4534
4536
  cursor?: string | null;
4537
+ limit?: number | null;
4535
4538
  };
4536
4539
  url: '/v1/orgs/{orgId}/audit';
4537
4540
  };
@@ -4609,6 +4612,7 @@ export type OrgAuditListOrgAuditEventsResponses = {
4609
4612
  workspaceId: string | null;
4610
4613
  }>;
4611
4614
  pagination: {
4615
+ limit: number;
4612
4616
  nextCursor: string | null;
4613
4617
  };
4614
4618
  } | null;
@@ -6515,12 +6519,10 @@ export type ProjectsListProjectsByOrgData = {
6515
6519
  orgId: string;
6516
6520
  };
6517
6521
  query?: {
6518
- page?: number | null;
6522
+ cursor?: string | null;
6519
6523
  limit?: number | null;
6520
6524
  search?: string | null;
6521
- sortDir?: 'asc' | 'desc' | null;
6522
6525
  status?: string | null;
6523
- sortBy?: 'createdAt' | 'updatedAt' | 'name' | 'slug' | null;
6524
6526
  workspaceSlug?: string | null;
6525
6527
  slug?: string | null;
6526
6528
  };
@@ -6583,19 +6585,25 @@ export type ProjectsListProjectsByOrgResponses = {
6583
6585
  */
6584
6586
  200: {
6585
6587
  code: number;
6586
- data: Array<{
6587
- createdAt: string;
6588
- id: string;
6589
- name: string;
6590
- organizationId: string;
6591
- slug: string;
6592
- status: 'active' | 'archived' | 'deleted';
6593
- updatedAt: string;
6594
- workspaceId: string;
6595
- workspaceName: string;
6596
- workspaceSlug: string;
6597
- workspaceStatus: 'active' | 'archived' | 'deleted';
6598
- }> | null;
6588
+ data: {
6589
+ items: Array<{
6590
+ createdAt: string;
6591
+ id: string;
6592
+ name: string;
6593
+ organizationId: string;
6594
+ slug: string;
6595
+ status: 'active' | 'archived' | 'deleted';
6596
+ updatedAt: string;
6597
+ workspaceId: string;
6598
+ workspaceName: string;
6599
+ workspaceSlug: string;
6600
+ workspaceStatus: 'active' | 'archived' | 'deleted';
6601
+ }>;
6602
+ pagination: {
6603
+ limit: number;
6604
+ nextCursor: string | null;
6605
+ };
6606
+ } | null;
6599
6607
  error: {
6600
6608
  code: string;
6601
6609
  details?: unknown | null;
@@ -1338,7 +1338,7 @@ export declare const zApiKeysListApiKeysQuery: z.ZodObject<{
1338
1338
  expiry: z.ZodOptional<z.ZodNullable<z.ZodString>>;
1339
1339
  q: z.ZodOptional<z.ZodNullable<z.ZodString>>;
1340
1340
  cursor: z.ZodOptional<z.ZodNullable<z.ZodString>>;
1341
- limit: z.ZodString;
1341
+ limit: z.ZodOptional<z.ZodNullable<z.ZodInt>>;
1342
1342
  includeRevoked: z.ZodEnum<{
1343
1343
  true: "true";
1344
1344
  false: "false";
@@ -1360,7 +1360,7 @@ export declare const zApiKeysListApiKeysResponse: z.ZodObject<{
1360
1360
  revoked: z.ZodNumber;
1361
1361
  rotating: z.ZodNumber;
1362
1362
  }, z.core.$strip>;
1363
- keys: z.ZodArray<z.ZodObject<{
1363
+ items: z.ZodArray<z.ZodObject<{
1364
1364
  calls7d: z.ZodNumber;
1365
1365
  createdAt: z.ZodString;
1366
1366
  createdBy: z.ZodNullable<z.ZodObject<{
@@ -1409,7 +1409,10 @@ export declare const zApiKeysListApiKeysResponse: z.ZodObject<{
1409
1409
  }>;
1410
1410
  workspaceId: z.ZodNullable<z.ZodString>;
1411
1411
  }, z.core.$strip>>;
1412
- nextCursor: z.ZodNullable<z.ZodString>;
1412
+ pagination: z.ZodObject<{
1413
+ limit: z.ZodInt;
1414
+ nextCursor: z.ZodNullable<z.ZodString>;
1415
+ }, z.core.$strip>;
1413
1416
  viewerScopeAccess: z.ZodEnum<{
1414
1417
  none: "none";
1415
1418
  scoped: "scoped";
@@ -2743,8 +2746,8 @@ export declare const zOrgAuditListOrgAuditEventsQuery: z.ZodObject<{
2743
2746
  workspace_id: z.ZodOptional<z.ZodNullable<z.ZodString>>;
2744
2747
  since: z.ZodOptional<z.ZodNullable<z.ZodString>>;
2745
2748
  until: z.ZodOptional<z.ZodNullable<z.ZodString>>;
2746
- limit: z.ZodOptional<z.ZodNullable<z.ZodString>>;
2747
2749
  cursor: z.ZodOptional<z.ZodNullable<z.ZodString>>;
2750
+ limit: z.ZodOptional<z.ZodNullable<z.ZodInt>>;
2748
2751
  }, z.core.$strip>;
2749
2752
  /**
2750
2753
  * Success
@@ -2782,6 +2785,7 @@ export declare const zOrgAuditListOrgAuditEventsResponse: z.ZodObject<{
2782
2785
  workspaceId: z.ZodNullable<z.ZodString>;
2783
2786
  }, z.core.$strip>>;
2784
2787
  pagination: z.ZodObject<{
2788
+ limit: z.ZodInt;
2785
2789
  nextCursor: z.ZodNullable<z.ZodString>;
2786
2790
  }, z.core.$strip>;
2787
2791
  }, z.core.$strip>>;
@@ -3787,20 +3791,10 @@ export declare const zProjectsListProjectsByOrgPath: z.ZodObject<{
3787
3791
  orgId: z.ZodString;
3788
3792
  }, z.core.$strip>;
3789
3793
  export declare const zProjectsListProjectsByOrgQuery: z.ZodObject<{
3790
- page: z.ZodOptional<z.ZodNullable<z.ZodInt>>;
3794
+ cursor: z.ZodOptional<z.ZodNullable<z.ZodString>>;
3791
3795
  limit: z.ZodOptional<z.ZodNullable<z.ZodInt>>;
3792
3796
  search: z.ZodOptional<z.ZodNullable<z.ZodString>>;
3793
- sortDir: z.ZodOptional<z.ZodNullable<z.ZodEnum<{
3794
- asc: "asc";
3795
- desc: "desc";
3796
- }>>>;
3797
3797
  status: z.ZodOptional<z.ZodNullable<z.ZodString>>;
3798
- sortBy: z.ZodOptional<z.ZodNullable<z.ZodEnum<{
3799
- name: "name";
3800
- createdAt: "createdAt";
3801
- updatedAt: "updatedAt";
3802
- slug: "slug";
3803
- }>>>;
3804
3798
  workspaceSlug: z.ZodOptional<z.ZodNullable<z.ZodString>>;
3805
3799
  slug: z.ZodOptional<z.ZodNullable<z.ZodString>>;
3806
3800
  }, z.core.$strip>;
@@ -3809,27 +3803,33 @@ export declare const zProjectsListProjectsByOrgQuery: z.ZodObject<{
3809
3803
  */
3810
3804
  export declare const zProjectsListProjectsByOrgResponse: z.ZodObject<{
3811
3805
  code: z.ZodNumber;
3812
- data: z.ZodNullable<z.ZodArray<z.ZodObject<{
3813
- createdAt: z.ZodISODateTime;
3814
- id: z.ZodString;
3815
- name: z.ZodString;
3816
- organizationId: z.ZodString;
3817
- slug: z.ZodString;
3818
- status: z.ZodEnum<{
3819
- active: "active";
3820
- archived: "archived";
3821
- deleted: "deleted";
3822
- }>;
3823
- updatedAt: z.ZodISODateTime;
3824
- workspaceId: z.ZodString;
3825
- workspaceName: z.ZodString;
3826
- workspaceSlug: z.ZodString;
3827
- workspaceStatus: z.ZodEnum<{
3828
- active: "active";
3829
- archived: "archived";
3830
- deleted: "deleted";
3831
- }>;
3832
- }, z.core.$strip>>>;
3806
+ data: z.ZodNullable<z.ZodObject<{
3807
+ items: z.ZodArray<z.ZodObject<{
3808
+ createdAt: z.ZodISODateTime;
3809
+ id: z.ZodString;
3810
+ name: z.ZodString;
3811
+ organizationId: z.ZodString;
3812
+ slug: z.ZodString;
3813
+ status: z.ZodEnum<{
3814
+ active: "active";
3815
+ archived: "archived";
3816
+ deleted: "deleted";
3817
+ }>;
3818
+ updatedAt: z.ZodISODateTime;
3819
+ workspaceId: z.ZodString;
3820
+ workspaceName: z.ZodString;
3821
+ workspaceSlug: z.ZodString;
3822
+ workspaceStatus: z.ZodEnum<{
3823
+ active: "active";
3824
+ archived: "archived";
3825
+ deleted: "deleted";
3826
+ }>;
3827
+ }, z.core.$strip>>;
3828
+ pagination: z.ZodObject<{
3829
+ limit: z.ZodInt;
3830
+ nextCursor: z.ZodNullable<z.ZodString>;
3831
+ }, z.core.$strip>;
3832
+ }, z.core.$strip>>;
3833
3833
  error: z.ZodNullable<z.ZodObject<{
3834
3834
  code: z.ZodString;
3835
3835
  details: z.ZodOptional<z.ZodNullable<z.ZodUnknown>>;
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Keyset paging, as every cursor list in the API answers it. `nextCursor` is
3
+ * the opaque cursor of the next page and `null` on the last one; `limit` is
4
+ * the page size the server applied (its default when the call passed none,
5
+ * clamped to its max).
6
+ */
7
+ export interface CursorPaginationInfo {
8
+ nextCursor: string | null;
9
+ limit: number;
10
+ }
11
+ /** One page of a cursor list: `{ items, pagination: { nextCursor, limit } }`. */
12
+ export interface CursorPaginatedResult<T> {
13
+ items: T[];
14
+ pagination: CursorPaginationInfo;
15
+ }
16
+ /**
17
+ * Fetches one page. `cursor` is `undefined` for the first page and the
18
+ * previous page's `pagination.nextCursor` after that.
19
+ */
20
+ export type FetchCursorPage<T> = (cursor: string | undefined) => Promise<CursorPaginatedResult<T>>;
21
+ /**
22
+ * Walks a cursor list page by page, yielding each page as the server returned
23
+ * it. Stops after the page whose `nextCursor` is `null` or empty. Throws a
24
+ * `To11aiError` when the server hands back a cursor it already returned, so a
25
+ * misbehaving endpoint cannot loop the caller forever.
26
+ */
27
+ export declare function iterateCursorPages<T>(fetchPage: FetchCursorPage<T>): AsyncGenerator<CursorPaginatedResult<T>, void, undefined>;
28
+ /**
29
+ * Walks a cursor list and yields its items one by one, across every page.
30
+ * Same stop rules as `iterateCursorPages`.
31
+ */
32
+ export declare function iterateCursorItems<T>(fetchPage: FetchCursorPage<T>): AsyncGenerator<T, void, undefined>;
@@ -44,6 +44,7 @@ __export(exports_resource, {
44
44
  module.exports = __toCommonJS(exports_resource);
45
45
  var import_errors = require("../errors");
46
46
  var import_zod = require("../generated/zod.gen");
47
+ var import_pagination = require("../pagination");
47
48
  var import_shape = require("./shape");
48
49
  var import_types = require("./types");
49
50
  var LATEST_PROMPT_LABEL = "latest";
@@ -170,6 +171,9 @@ class PromptResource {
170
171
  const envelope = await this.transport.request("GET", `${getProjectPromptPath(projectId, promptId)}/versions`, { query });
171
172
  return unwrap(envelope);
172
173
  }
174
+ iterateVersions(input) {
175
+ return import_pagination.iterateCursorItems((cursor) => this.listVersions({ ...input, cursor }));
176
+ }
173
177
  async getVersion(input) {
174
178
  const { projectId: perCallProjectId, promptId, versionNumber } = input;
175
179
  const projectId = this.resolveProjectId(perCallProjectId);
@@ -1,7 +1,7 @@
1
1
  import type { Transport } from "../transport";
2
2
  import type { AnthropicRenderedPrompt, OpenAiRenderedPrompt, RenderResult } from "./shape";
3
- import type { ArchivePromptInput, ArchivePromptResult, CreatePromptInput, CreatePromptResult, CreatePromptVersionInput, CreatePromptVersionResult, GetPromptInput, GetPromptResult, GetPromptVersionInput, GetPromptVersionResult, ListPromptLabelsInput, ListPromptLabelsResult, ListPromptsInput, ListPromptsResult, ListPromptVersionsInput, ListPromptVersionsResult, PaginatedResult, RenderFormat, RenderOptions, UnknownRoleMode, UpdatePromptInput, UpdatePromptResult } from "./types";
4
- export type { ArchivePromptInput, ArchivePromptResult, BlockRenderRecord, ChatMessage, ChatRole, CreatePromptInput, CreatePromptResult, CreatePromptVersionInput, CreatePromptVersionResult, CursorPaginatedResult, CursorPaginationInfo, GetPromptInput, GetPromptResult, GetPromptVersionInput, GetPromptVersionResult, ListPromptLabelsInput, ListPromptLabelsResult, ListPromptsInput, ListPromptsResult, ListPromptVersionsInput, ListPromptVersionsResult, PaginatedResult, PaginationInfo, Prompt, PromptFormat, PromptLabelPointer, PromptStatus, PromptVersion, PromptVersionSummary, RenderedChatMessage, RenderedPrompt, RenderFormat, RenderOptions, ResolvedPrompt, ResolvedPromptEnvelope, ResolvedToolCall, ResolvedToolDefinition, RowError, UnknownRoleMode, UpdatePromptInput, UpdatePromptResult, } from "./types";
3
+ import type { ArchivePromptInput, ArchivePromptResult, CreatePromptInput, CreatePromptResult, CreatePromptVersionInput, CreatePromptVersionResult, GetPromptInput, GetPromptResult, GetPromptVersionInput, GetPromptVersionResult, IterateVersionsInput, ListPromptLabelsInput, ListPromptLabelsResult, ListPromptsInput, ListPromptsResult, ListPromptVersionsInput, ListPromptVersionsResult, PaginatedResult, PromptVersionSummary, RenderFormat, RenderOptions, UnknownRoleMode, UpdatePromptInput, UpdatePromptResult } from "./types";
4
+ export type { ArchivePromptInput, ArchivePromptResult, BlockRenderRecord, ChatMessage, ChatRole, CreatePromptInput, CreatePromptResult, CreatePromptVersionInput, CreatePromptVersionResult, CursorPaginatedResult, CursorPaginationInfo, GetPromptInput, GetPromptResult, GetPromptVersionInput, GetPromptVersionResult, IterateVersionsInput, ListPromptLabelsInput, ListPromptLabelsResult, ListPromptsInput, ListPromptsResult, ListPromptVersionsInput, ListPromptVersionsResult, PaginatedResult, PaginationInfo, Prompt, PromptFormat, PromptLabelPointer, PromptStatus, PromptVersion, PromptVersionSummary, RenderedChatMessage, RenderedPrompt, RenderFormat, RenderOptions, ResolvedPrompt, ResolvedPromptEnvelope, ResolvedToolCall, ResolvedToolDefinition, RowError, UnknownRoleMode, UpdatePromptInput, UpdatePromptResult, } from "./types";
5
5
  /**
6
6
  * Init-time config for the `render()` surface (TO11-980 / S9).
7
7
  *
@@ -48,6 +48,19 @@ export declare class PromptResource<F extends RenderFormat | undefined = undefin
48
48
  * version's content with `getVersion()`.
49
49
  */
50
50
  listVersions(input: ListPromptVersionsInput): Promise<ListPromptVersionsResult>;
51
+ /**
52
+ * Every version of a prompt, newest first, as summaries: walks
53
+ * `listVersions()` page by page until `pagination.nextCursor` is `null` and
54
+ * yields one `PromptVersionSummary` at a time. `limit` sets the page size of
55
+ * each request. Throws a `To11aiError` if the server repeats a cursor.
56
+ *
57
+ * ```ts
58
+ * for await (const version of to11.prompts.iterateVersions({ promptId })) {
59
+ * console.log(version.version);
60
+ * }
61
+ * ```
62
+ */
63
+ iterateVersions(input: IterateVersionsInput): AsyncGenerator<PromptVersionSummary, void, undefined>;
51
64
  getVersion(input: GetPromptVersionInput): Promise<GetPromptVersionResult>;
52
65
  listLabels(input: ListPromptLabelsInput): Promise<ListPromptLabelsResult>;
53
66
  /**
@@ -1,6 +1,7 @@
1
1
  // src/prompts/resource.ts
2
2
  import { To11aiApiError, To11aiNetworkError } from "../errors";
3
3
  import { zResolvedPrompt } from "../generated/zod.gen";
4
+ import { iterateCursorItems } from "../pagination";
4
5
  import { shapePrompt } from "./shape";
5
6
  import { ENV_SLUG_REGEX } from "./types";
6
7
  var LATEST_PROMPT_LABEL = "latest";
@@ -127,6 +128,9 @@ class PromptResource {
127
128
  const envelope = await this.transport.request("GET", `${getProjectPromptPath(projectId, promptId)}/versions`, { query });
128
129
  return unwrap(envelope);
129
130
  }
131
+ iterateVersions(input) {
132
+ return iterateCursorItems((cursor) => this.listVersions({ ...input, cursor }));
133
+ }
130
134
  async getVersion(input) {
131
135
  const { projectId: perCallProjectId, promptId, versionNumber } = input;
132
136
  const projectId = this.resolveProjectId(perCallProjectId);
@@ -1,4 +1,5 @@
1
1
  import type { Prompt as GenPrompt, PromptLabelPointer as GenPromptLabelPointer, PromptVersion as GenPromptVersion, PromptVersionSummary as GenPromptVersionSummary, RenderedChatPrompt as GenRenderedChatPrompt, ResolvedPrompt as GenResolvedPrompt, ResolvedToolCall as GenResolvedToolCall, ResolvedToolDefinition as GenResolvedToolDefinition } from "../generated/types.gen";
2
+ import type { CursorPaginatedResult } from "../pagination";
2
3
  export interface RowError {
3
4
  path: ReadonlyArray<string | number>;
4
5
  code: string;
@@ -55,19 +56,7 @@ export interface PaginatedResult<T> {
55
56
  items: T[];
56
57
  pagination: PaginationInfo;
57
58
  }
58
- /**
59
- * Keyset paging, as the audit feeds use it. `nextCursor` is the opaque cursor
60
- * of the next page and `null` on the last one; `limit` is the page size the
61
- * server applied (its default when the call passed none, clamped to its max).
62
- */
63
- export interface CursorPaginationInfo {
64
- nextCursor: string | null;
65
- limit: number;
66
- }
67
- export interface CursorPaginatedResult<T> {
68
- items: T[];
69
- pagination: CursorPaginationInfo;
70
- }
59
+ export type { CursorPaginatedResult, CursorPaginationInfo, } from "../pagination";
71
60
  export interface CreatePromptInput {
72
61
  projectId?: string;
73
62
  name: string;
@@ -121,6 +110,11 @@ export interface ListPromptVersionsInput {
121
110
  /** Page size. The server defaults to 50 and clamps to 100. */
122
111
  limit?: number;
123
112
  }
113
+ /**
114
+ * Input of `iterateVersions()`: `listVersions()` without `cursor`, which the
115
+ * iterator manages. `limit` is the page size of each request.
116
+ */
117
+ export type IterateVersionsInput = Omit<ListPromptVersionsInput, "cursor">;
124
118
  /**
125
119
  * One page of a prompt's versions, newest first, as summaries. Read a
126
120
  * version's content with `getVersion()`.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@to11ai/sdk",
3
- "version": "3.0.0-rc.8",
3
+ "version": "3.0.0-rc.9",
4
4
  "license": "MPL-2.0",
5
5
  "repository": {
6
6
  "type": "git",
package/src/client.ts CHANGED
@@ -40,6 +40,12 @@ export {
40
40
  } from "./errors";
41
41
  export type { ConvertMessagesOptions, GatewayAuthOptions } from "./gateway";
42
42
  export { gatewayAuthHeaders, gatewayPromptHeaders } from "./gateway";
43
+ export type {
44
+ CursorPaginatedResult,
45
+ CursorPaginationInfo,
46
+ FetchCursorPage,
47
+ } from "./pagination";
48
+ export { iterateCursorItems, iterateCursorPages } from "./pagination";
43
49
  export type {
44
50
  ArchiveProjectEnvironmentInput,
45
51
  ArchiveProjectEnvironmentResult,
@@ -1808,7 +1808,7 @@ export type ApiKeysListApiKeysData = {
1808
1808
  expiry?: string | null;
1809
1809
  q?: string | null;
1810
1810
  cursor?: string | null;
1811
- limit: string;
1811
+ limit?: number | null;
1812
1812
  includeRevoked: 'true' | 'false';
1813
1813
  includeCounts: 'true' | 'false';
1814
1814
  };
@@ -1881,7 +1881,7 @@ export type ApiKeysListApiKeysResponses = {
1881
1881
  revoked: number;
1882
1882
  rotating: number;
1883
1883
  };
1884
- keys: Array<{
1884
+ items: Array<{
1885
1885
  calls7d: number;
1886
1886
  createdAt: string;
1887
1887
  createdBy: {
@@ -1913,7 +1913,10 @@ export type ApiKeysListApiKeysResponses = {
1913
1913
  status: 'active' | 'revoked' | 'rotating' | 'expired';
1914
1914
  workspaceId: string | null;
1915
1915
  }>;
1916
- nextCursor: string | null;
1916
+ pagination: {
1917
+ limit: number;
1918
+ nextCursor: string | null;
1919
+ };
1917
1920
  viewerScopeAccess: 'none' | 'scoped' | 'full';
1918
1921
  } | null;
1919
1922
  error: {
@@ -4778,8 +4781,8 @@ export type OrgAuditListOrgAuditEventsData = {
4778
4781
  workspace_id?: string | null;
4779
4782
  since?: string | null;
4780
4783
  until?: string | null;
4781
- limit?: string | null;
4782
4784
  cursor?: string | null;
4785
+ limit?: number | null;
4783
4786
  };
4784
4787
  url: '/v1/orgs/{orgId}/audit';
4785
4788
  };
@@ -4860,6 +4863,7 @@ export type OrgAuditListOrgAuditEventsResponses = {
4860
4863
  workspaceId: string | null;
4861
4864
  }>;
4862
4865
  pagination: {
4866
+ limit: number;
4863
4867
  nextCursor: string | null;
4864
4868
  };
4865
4869
  } | null;
@@ -6853,12 +6857,10 @@ export type ProjectsListProjectsByOrgData = {
6853
6857
  orgId: string;
6854
6858
  };
6855
6859
  query?: {
6856
- page?: number | null;
6860
+ cursor?: string | null;
6857
6861
  limit?: number | null;
6858
6862
  search?: string | null;
6859
- sortDir?: 'asc' | 'desc' | null;
6860
6863
  status?: string | null;
6861
- sortBy?: 'createdAt' | 'updatedAt' | 'name' | 'slug' | null;
6862
6864
  workspaceSlug?: string | null;
6863
6865
  slug?: string | null;
6864
6866
  };
@@ -6924,19 +6926,25 @@ export type ProjectsListProjectsByOrgResponses = {
6924
6926
  */
6925
6927
  200: {
6926
6928
  code: number;
6927
- data: Array<{
6928
- createdAt: string;
6929
- id: string;
6930
- name: string;
6931
- organizationId: string;
6932
- slug: string;
6933
- status: 'active' | 'archived' | 'deleted';
6934
- updatedAt: string;
6935
- workspaceId: string;
6936
- workspaceName: string;
6937
- workspaceSlug: string;
6938
- workspaceStatus: 'active' | 'archived' | 'deleted';
6939
- }> | null;
6929
+ data: {
6930
+ items: Array<{
6931
+ createdAt: string;
6932
+ id: string;
6933
+ name: string;
6934
+ organizationId: string;
6935
+ slug: string;
6936
+ status: 'active' | 'archived' | 'deleted';
6937
+ updatedAt: string;
6938
+ workspaceId: string;
6939
+ workspaceName: string;
6940
+ workspaceSlug: string;
6941
+ workspaceStatus: 'active' | 'archived' | 'deleted';
6942
+ }>;
6943
+ pagination: {
6944
+ limit: number;
6945
+ nextCursor: string | null;
6946
+ };
6947
+ } | null;
6940
6948
  error: {
6941
6949
  code: string;
6942
6950
  details?: unknown | null;
@@ -1021,7 +1021,7 @@ export const zApiKeysListApiKeysQuery = z.object({
1021
1021
  expiry: z.string().nullish(),
1022
1022
  q: z.string().nullish(),
1023
1023
  cursor: z.string().nullish(),
1024
- limit: z.string(),
1024
+ limit: z.int().nullish(),
1025
1025
  includeRevoked: z.enum(['true', 'false']),
1026
1026
  includeCounts: z.enum(['true', 'false'])
1027
1027
  });
@@ -1038,7 +1038,7 @@ export const zApiKeysListApiKeysResponse = z.object({
1038
1038
  revoked: z.number(),
1039
1039
  rotating: z.number()
1040
1040
  }),
1041
- keys: z.array(z.object({
1041
+ items: z.array(z.object({
1042
1042
  calls7d: z.number(),
1043
1043
  createdAt: z.string(),
1044
1044
  createdBy: z.object({
@@ -1084,7 +1084,10 @@ export const zApiKeysListApiKeysResponse = z.object({
1084
1084
  ]),
1085
1085
  workspaceId: z.string().nullable()
1086
1086
  })),
1087
- nextCursor: z.string().nullable(),
1087
+ pagination: z.object({
1088
+ limit: z.int().gte(1).lte(100),
1089
+ nextCursor: z.string().nullable()
1090
+ }),
1088
1091
  viewerScopeAccess: z.enum([
1089
1092
  'none',
1090
1093
  'scoped',
@@ -2404,8 +2407,8 @@ export const zOrgAuditListOrgAuditEventsQuery = z.object({
2404
2407
  workspace_id: z.string().nullish(),
2405
2408
  since: z.string().nullish(),
2406
2409
  until: z.string().nullish(),
2407
- limit: z.string().nullish(),
2408
- cursor: z.string().nullish()
2410
+ cursor: z.string().nullish(),
2411
+ limit: z.int().nullish()
2409
2412
  });
2410
2413
 
2411
2414
  /**
@@ -2441,6 +2444,7 @@ export const zOrgAuditListOrgAuditEventsResponse = z.object({
2441
2444
  workspaceId: z.string().nullable()
2442
2445
  })),
2443
2446
  pagination: z.object({
2447
+ limit: z.int().gte(1).lte(100),
2444
2448
  nextCursor: z.string().nullable()
2445
2449
  })
2446
2450
  }).nullable(),
@@ -3444,17 +3448,10 @@ export const zProjectsListProjectsByOrgPath = z.object({
3444
3448
  });
3445
3449
 
3446
3450
  export const zProjectsListProjectsByOrgQuery = z.object({
3447
- page: z.int().nullish(),
3451
+ cursor: z.string().nullish(),
3448
3452
  limit: z.int().nullish(),
3449
3453
  search: z.string().nullish(),
3450
- sortDir: z.enum(['asc', 'desc']).nullish(),
3451
3454
  status: z.string().nullish(),
3452
- sortBy: z.enum([
3453
- 'createdAt',
3454
- 'updatedAt',
3455
- 'name',
3456
- 'slug'
3457
- ]).nullish(),
3458
3455
  workspaceSlug: z.string().nullish(),
3459
3456
  slug: z.string().nullish()
3460
3457
  });
@@ -3464,27 +3461,33 @@ export const zProjectsListProjectsByOrgQuery = z.object({
3464
3461
  */
3465
3462
  export const zProjectsListProjectsByOrgResponse = z.object({
3466
3463
  code: z.number(),
3467
- data: z.array(z.object({
3468
- createdAt: z.iso.datetime(),
3469
- id: z.string(),
3470
- name: z.string().min(1).max(120),
3471
- organizationId: z.string(),
3472
- slug: z.string().min(1).max(120),
3473
- status: z.enum([
3474
- 'active',
3475
- 'archived',
3476
- 'deleted'
3477
- ]),
3478
- updatedAt: z.iso.datetime(),
3479
- workspaceId: z.string(),
3480
- workspaceName: z.string().min(1).max(120),
3481
- workspaceSlug: z.string().min(1).max(120),
3482
- workspaceStatus: z.enum([
3483
- 'active',
3484
- 'archived',
3485
- 'deleted'
3486
- ])
3487
- })).nullable(),
3464
+ data: z.object({
3465
+ items: z.array(z.object({
3466
+ createdAt: z.iso.datetime(),
3467
+ id: z.string(),
3468
+ name: z.string().min(1).max(120),
3469
+ organizationId: z.string(),
3470
+ slug: z.string().min(1).max(120),
3471
+ status: z.enum([
3472
+ 'active',
3473
+ 'archived',
3474
+ 'deleted'
3475
+ ]),
3476
+ updatedAt: z.iso.datetime(),
3477
+ workspaceId: z.string(),
3478
+ workspaceName: z.string().min(1).max(120),
3479
+ workspaceSlug: z.string().min(1).max(120),
3480
+ workspaceStatus: z.enum([
3481
+ 'active',
3482
+ 'archived',
3483
+ 'deleted'
3484
+ ])
3485
+ })),
3486
+ pagination: z.object({
3487
+ limit: z.int().gte(1).lte(100),
3488
+ nextCursor: z.string().nullable()
3489
+ })
3490
+ }).nullable(),
3488
3491
  error: z.object({
3489
3492
  code: z.string(),
3490
3493
  details: z.unknown().nullish(),
@@ -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
+ }
@@ -1,5 +1,6 @@
1
1
  import { To11aiApiError, To11aiNetworkError } from "../errors";
2
2
  import { zResolvedPrompt } from "../generated/zod.gen";
3
+ import { iterateCursorItems } from "../pagination";
3
4
  import type { ApiEnvelope, Transport } from "../transport";
4
5
  import type {
5
6
  AnthropicRenderedPrompt,
@@ -18,6 +19,7 @@ import type {
18
19
  GetPromptResult,
19
20
  GetPromptVersionInput,
20
21
  GetPromptVersionResult,
22
+ IterateVersionsInput,
21
23
  ListPromptLabelsInput,
22
24
  ListPromptLabelsResult,
23
25
  ListPromptsInput,
@@ -25,6 +27,7 @@ import type {
25
27
  ListPromptVersionsInput,
26
28
  ListPromptVersionsResult,
27
29
  PaginatedResult,
30
+ PromptVersionSummary,
28
31
  RenderedChatMessage,
29
32
  RenderedPrompt,
30
33
  RenderFormat,
@@ -53,6 +56,7 @@ export type {
53
56
  GetPromptResult,
54
57
  GetPromptVersionInput,
55
58
  GetPromptVersionResult,
59
+ IterateVersionsInput,
56
60
  ListPromptLabelsInput,
57
61
  ListPromptLabelsResult,
58
62
  ListPromptsInput,
@@ -374,6 +378,26 @@ export class PromptResource<F extends RenderFormat | undefined = undefined> {
374
378
  return unwrap(envelope);
375
379
  }
376
380
 
381
+ /**
382
+ * Every version of a prompt, newest first, as summaries: walks
383
+ * `listVersions()` page by page until `pagination.nextCursor` is `null` and
384
+ * yields one `PromptVersionSummary` at a time. `limit` sets the page size of
385
+ * each request. Throws a `To11aiError` if the server repeats a cursor.
386
+ *
387
+ * ```ts
388
+ * for await (const version of to11.prompts.iterateVersions({ promptId })) {
389
+ * console.log(version.version);
390
+ * }
391
+ * ```
392
+ */
393
+ iterateVersions(
394
+ input: IterateVersionsInput,
395
+ ): AsyncGenerator<PromptVersionSummary, void, undefined> {
396
+ return iterateCursorItems((cursor) =>
397
+ this.listVersions({ ...input, cursor }),
398
+ );
399
+ }
400
+
377
401
  // ─── Get Version ──────────────────────────────────────────────────────────
378
402
 
379
403
  async getVersion(
@@ -8,6 +8,7 @@ import type {
8
8
  ResolvedToolCall as GenResolvedToolCall,
9
9
  ResolvedToolDefinition as GenResolvedToolDefinition,
10
10
  } from "../generated/types.gen";
11
+ import type { CursorPaginatedResult } from "../pagination";
11
12
 
12
13
  export interface RowError {
13
14
  path: ReadonlyArray<string | number>;
@@ -88,20 +89,12 @@ export interface PaginatedResult<T> {
88
89
  pagination: PaginationInfo;
89
90
  }
90
91
 
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
- }
92
+ // The cursor page shapes are shared by every cursor list; they live in
93
+ // `../pagination` and stay re-exported here for existing imports.
94
+ export type {
95
+ CursorPaginatedResult,
96
+ CursorPaginationInfo,
97
+ } from "../pagination";
105
98
 
106
99
  export interface CreatePromptInput {
107
100
  projectId?: string;
@@ -169,6 +162,12 @@ export interface ListPromptVersionsInput {
169
162
  limit?: number;
170
163
  }
171
164
 
165
+ /**
166
+ * Input of `iterateVersions()`: `listVersions()` without `cursor`, which the
167
+ * iterator manages. `limit` is the page size of each request.
168
+ */
169
+ export type IterateVersionsInput = Omit<ListPromptVersionsInput, "cursor">;
170
+
172
171
  /**
173
172
  * One page of a prompt's versions, newest first, as summaries. Read a
174
173
  * version's content with `getVersion()`.