@to11ai/sdk 3.0.0-rc.9 → 3.1.0-rc
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/README.md +31 -4
- package/dist/client.cjs +28 -23
- package/dist/client.d.ts +4 -0
- package/dist/client.js +26 -21
- package/dist/errors.cjs +15 -16
- package/dist/errors.js +15 -15
- package/dist/gateway.cjs +11 -11
- package/dist/gateway.js +11 -11
- package/dist/generated/index.d.ts +1 -1
- package/dist/generated/types.gen.d.ts +9486 -4788
- package/dist/generated/zod.gen.d.ts +8451 -5096
- package/dist/projectEnvironments/resource.cjs +20 -2
- package/dist/projectEnvironments/resource.d.ts +21 -5
- package/dist/projectEnvironments/resource.js +20 -2
- package/dist/projectEnvironments/types.d.ts +14 -1
- package/dist/prompts/resource.cjs +45 -3
- package/dist/prompts/resource.d.ts +28 -2
- package/dist/prompts/resource.js +57 -5
- package/dist/prompts/types.d.ts +33 -2
- package/dist/routingRules/resource.d.ts +44 -2
- package/dist/routingRules/types.d.ts +33 -3
- package/dist/transport.d.ts +5 -1
- package/dist/usage/resource.cjs +113 -0
- package/dist/usage/resource.d.ts +29 -0
- package/dist/usage/resource.js +78 -0
- package/dist/usage/types.d.ts +81 -0
- package/package.json +14 -6
- package/src/client.ts +6 -0
- package/src/generated/index.ts +1 -1
- package/src/generated/types.gen.ts +9726 -4848
- package/src/generated/zod.gen.ts +6109 -3109
- package/src/projectEnvironments/resource.ts +44 -9
- package/src/projectEnvironments/types.ts +19 -1
- package/src/prompts/resource.ts +125 -4
- package/src/prompts/types.ts +43 -1
- package/src/routingRules/resource.ts +77 -5
- package/src/routingRules/types.ts +35 -3
- package/src/transport.ts +14 -2
- package/src/usage/resource.ts +183 -0
- package/src/usage/types.ts +121 -0
|
@@ -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
|
-
*
|
|
77
|
-
*
|
|
78
|
-
* `
|
|
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
|
|
89
|
-
? { includeArchived: "true" }
|
|
90
|
-
: undefined,
|
|
108
|
+
query,
|
|
91
109
|
decode: (data) =>
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
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
|
-
|
|
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;
|
package/src/prompts/resource.ts
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
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";
|
|
3
13
|
import { iterateCursorItems } from "../pagination";
|
|
4
14
|
import type { ApiEnvelope, Transport } from "../transport";
|
|
5
15
|
import type {
|
|
@@ -19,7 +29,10 @@ import type {
|
|
|
19
29
|
GetPromptResult,
|
|
20
30
|
GetPromptVersionInput,
|
|
21
31
|
GetPromptVersionResult,
|
|
32
|
+
IterateLabelsInput,
|
|
22
33
|
IterateVersionsInput,
|
|
34
|
+
ListOrgPromptsInput,
|
|
35
|
+
ListOrgPromptsResult,
|
|
23
36
|
ListPromptLabelsInput,
|
|
24
37
|
ListPromptLabelsResult,
|
|
25
38
|
ListPromptsInput,
|
|
@@ -27,11 +40,14 @@ import type {
|
|
|
27
40
|
ListPromptVersionsInput,
|
|
28
41
|
ListPromptVersionsResult,
|
|
29
42
|
PaginatedResult,
|
|
43
|
+
PromptLabelPointer,
|
|
30
44
|
PromptVersionSummary,
|
|
31
45
|
RenderedChatMessage,
|
|
32
46
|
RenderedPrompt,
|
|
47
|
+
RenderedSkillVersion,
|
|
33
48
|
RenderFormat,
|
|
34
49
|
RenderOptions,
|
|
50
|
+
RenderSkillVersionInput,
|
|
35
51
|
ResolvedPrompt,
|
|
36
52
|
ResolvedPromptEnvelope,
|
|
37
53
|
UnknownRoleMode,
|
|
@@ -56,13 +72,17 @@ export type {
|
|
|
56
72
|
GetPromptResult,
|
|
57
73
|
GetPromptVersionInput,
|
|
58
74
|
GetPromptVersionResult,
|
|
75
|
+
IterateLabelsInput,
|
|
59
76
|
IterateVersionsInput,
|
|
77
|
+
ListOrgPromptsInput,
|
|
78
|
+
ListOrgPromptsResult,
|
|
60
79
|
ListPromptLabelsInput,
|
|
61
80
|
ListPromptLabelsResult,
|
|
62
81
|
ListPromptsInput,
|
|
63
82
|
ListPromptsResult,
|
|
64
83
|
ListPromptVersionsInput,
|
|
65
84
|
ListPromptVersionsResult,
|
|
85
|
+
OrgPromptRow,
|
|
66
86
|
PaginatedResult,
|
|
67
87
|
PaginationInfo,
|
|
68
88
|
Prompt,
|
|
@@ -73,8 +93,11 @@ export type {
|
|
|
73
93
|
PromptVersionSummary,
|
|
74
94
|
RenderedChatMessage,
|
|
75
95
|
RenderedPrompt,
|
|
96
|
+
RenderedSkillFile,
|
|
97
|
+
RenderedSkillVersion,
|
|
76
98
|
RenderFormat,
|
|
77
99
|
RenderOptions,
|
|
100
|
+
RenderSkillVersionInput,
|
|
78
101
|
ResolvedPrompt,
|
|
79
102
|
ResolvedPromptEnvelope,
|
|
80
103
|
ResolvedToolCall,
|
|
@@ -91,6 +114,13 @@ export type {
|
|
|
91
114
|
*/
|
|
92
115
|
const LATEST_PROMPT_LABEL = "latest";
|
|
93
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
|
+
|
|
94
124
|
function unwrap<T>(envelope: ApiEnvelope<T>): T {
|
|
95
125
|
if (envelope.data === null || envelope.data === undefined) {
|
|
96
126
|
throw new Error("API returned success but data is null");
|
|
@@ -194,6 +224,23 @@ function liftFallbackToRendered(
|
|
|
194
224
|
return { ...structuredClone(fallback), slug: fallback.slug || slug };
|
|
195
225
|
}
|
|
196
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
|
+
|
|
197
244
|
function getProjectPromptPath(projectId: string, promptId: string): string {
|
|
198
245
|
return `${getProjectPromptsPath(projectId)}/${encodeURIComponent(promptId)}`;
|
|
199
246
|
}
|
|
@@ -373,7 +420,10 @@ export class PromptResource<F extends RenderFormat | undefined = undefined> {
|
|
|
373
420
|
const envelope = await this.transport.request<ListPromptVersionsResult>(
|
|
374
421
|
"GET",
|
|
375
422
|
`${getProjectPromptPath(projectId, promptId)}/versions`,
|
|
376
|
-
{
|
|
423
|
+
{
|
|
424
|
+
query,
|
|
425
|
+
decode: (data) => versionsPage.parse(data) as ListPromptVersionsResult,
|
|
426
|
+
},
|
|
377
427
|
);
|
|
378
428
|
return unwrap(envelope);
|
|
379
429
|
}
|
|
@@ -414,14 +464,85 @@ export class PromptResource<F extends RenderFormat | undefined = undefined> {
|
|
|
414
464
|
|
|
415
465
|
// ─── List Labels ──────────────────────────────────────────────────────────
|
|
416
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
|
+
*/
|
|
417
473
|
async listLabels(
|
|
418
474
|
input: ListPromptLabelsInput,
|
|
419
475
|
): Promise<ListPromptLabelsResult> {
|
|
420
|
-
const { projectId: perCallProjectId, promptId } = input;
|
|
476
|
+
const { projectId: perCallProjectId, promptId, cursor, limit } = input;
|
|
421
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;
|
|
422
481
|
const envelope = await this.transport.request<ListPromptLabelsResult>(
|
|
423
482
|
"GET",
|
|
424
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
|
+
},
|
|
425
546
|
);
|
|
426
547
|
return unwrap(envelope);
|
|
427
548
|
}
|
package/src/prompts/types.ts
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
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,
|
|
@@ -186,9 +190,20 @@ export type GetPromptVersionResult = PromptVersion;
|
|
|
186
190
|
export interface ListPromptLabelsInput {
|
|
187
191
|
projectId?: string;
|
|
188
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;
|
|
189
197
|
}
|
|
190
198
|
|
|
191
|
-
|
|
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>;
|
|
192
207
|
|
|
193
208
|
/**
|
|
194
209
|
* Slug rule shared by the client `env` (the gateway's `x-to11-env` routing key)
|
|
@@ -265,3 +280,30 @@ export interface RenderOptions {
|
|
|
265
280
|
*/
|
|
266
281
|
onUnknownRole?: UnknownRoleMode;
|
|
267
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 {
|
|
2
|
-
|
|
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
|
-
{
|
|
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 {
|
|
@@ -6,6 +6,7 @@ import type {
|
|
|
6
6
|
RuleSnapshot as GenRuleSnapshot,
|
|
7
7
|
RuleVersion as GenRuleVersion,
|
|
8
8
|
} from "../generated/types.gen";
|
|
9
|
+
import type { CursorPaginatedResult } from "../pagination";
|
|
9
10
|
|
|
10
11
|
export type RuleProviderRef = GenRuleProviderRef;
|
|
11
12
|
|
|
@@ -26,14 +27,29 @@ export interface CreateRuleVersionInput {
|
|
|
26
27
|
|
|
27
28
|
export type CreateRuleVersionResult = RuleVersion;
|
|
28
29
|
|
|
30
|
+
/**
|
|
31
|
+
* Input of `versions.list()`. `cursor` is the previous page's
|
|
32
|
+
* `pagination.nextCursor`; `limit` is the page size (the server clamps it
|
|
33
|
+
* into 1..100 and defaults to 50).
|
|
34
|
+
*/
|
|
29
35
|
export interface ListRuleVersionsInput {
|
|
30
36
|
projectId: string;
|
|
31
37
|
ruleId: string;
|
|
32
|
-
cursor?:
|
|
38
|
+
cursor?: string;
|
|
33
39
|
limit?: number;
|
|
34
40
|
}
|
|
35
41
|
|
|
36
|
-
|
|
42
|
+
/**
|
|
43
|
+
* Input of `versions.iterate()`: `versions.list()` without `cursor`, which the
|
|
44
|
+
* iterator manages. `limit` is the page size of each request.
|
|
45
|
+
*/
|
|
46
|
+
export type IterateRuleVersionsInput = Omit<ListRuleVersionsInput, "cursor">;
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* One page of a rule's versions, newest first (`version` descending):
|
|
50
|
+
* `{ items, pagination: { nextCursor, limit } }`.
|
|
51
|
+
*/
|
|
52
|
+
export type ListRuleVersionsResult = CursorPaginatedResult<RuleVersion>;
|
|
37
53
|
|
|
38
54
|
export interface GetRuleVersionInput {
|
|
39
55
|
projectId: string;
|
|
@@ -77,6 +93,12 @@ export interface RollbackRuleReleaseInput {
|
|
|
77
93
|
|
|
78
94
|
export type RollbackRuleReleaseResult = RuleRelease;
|
|
79
95
|
|
|
96
|
+
/**
|
|
97
|
+
* Input of `releases.list()`. Without `envSlug` the call lists the rule's
|
|
98
|
+
* releases across every environment; with it, one environment's. `cursor` is
|
|
99
|
+
* the previous page's `pagination.nextCursor`; `limit` is the page size (the
|
|
100
|
+
* server clamps it into 1..100 and defaults to 50).
|
|
101
|
+
*/
|
|
80
102
|
export interface ListRuleReleasesInput {
|
|
81
103
|
projectId: string;
|
|
82
104
|
ruleId: string;
|
|
@@ -85,4 +107,14 @@ export interface ListRuleReleasesInput {
|
|
|
85
107
|
limit?: number;
|
|
86
108
|
}
|
|
87
109
|
|
|
88
|
-
|
|
110
|
+
/**
|
|
111
|
+
* Input of `releases.iterate()`: `releases.list()` without `cursor`, which the
|
|
112
|
+
* iterator manages. `limit` is the page size of each request.
|
|
113
|
+
*/
|
|
114
|
+
export type IterateRuleReleasesInput = Omit<ListRuleReleasesInput, "cursor">;
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* One page of a rule's releases, newest first:
|
|
118
|
+
* `{ items, pagination: { nextCursor, limit } }`.
|
|
119
|
+
*/
|
|
120
|
+
export type ListRuleReleasesResult = CursorPaginatedResult<RuleRelease>;
|
package/src/transport.ts
CHANGED
|
@@ -393,7 +393,14 @@ export class Transport {
|
|
|
393
393
|
method: string,
|
|
394
394
|
path: string,
|
|
395
395
|
options?: {
|
|
396
|
-
|
|
396
|
+
/**
|
|
397
|
+
* Query params. An array value repeats the param once per element
|
|
398
|
+
* (`?groupBy=model&groupBy=project`); `undefined` or `null` omits it.
|
|
399
|
+
*/
|
|
400
|
+
query?: Record<
|
|
401
|
+
string,
|
|
402
|
+
string | number | boolean | ReadonlyArray<string> | null | undefined
|
|
403
|
+
>;
|
|
397
404
|
body?: unknown;
|
|
398
405
|
/**
|
|
399
406
|
* Runtime validator for the envelope `data` on a 2xx response. When
|
|
@@ -408,7 +415,12 @@ export class Transport {
|
|
|
408
415
|
|
|
409
416
|
if (options?.query) {
|
|
410
417
|
for (const [key, value] of Object.entries(options.query)) {
|
|
411
|
-
|
|
418
|
+
// `null` too: an untyped caller's null means "not set", and
|
|
419
|
+
// `typeof null` is "object", which the array branch would iterate.
|
|
420
|
+
if (value === undefined || value === null) continue;
|
|
421
|
+
if (Array.isArray(value)) {
|
|
422
|
+
for (const item of value) url.searchParams.append(key, item);
|
|
423
|
+
} else {
|
|
412
424
|
url.searchParams.set(key, String(value));
|
|
413
425
|
}
|
|
414
426
|
}
|