@to11ai/sdk 3.0.0-rc.7 → 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 +3 -0
- package/dist/client.d.ts +2 -0
- package/dist/client.js +3 -0
- package/dist/generated/index.d.ts +1 -1
- package/dist/generated/types.gen.d.ts +102 -28
- package/dist/generated/zod.gen.d.ts +50 -44
- package/dist/pagination.d.ts +32 -0
- package/dist/prompts/resource.cjs +4 -0
- package/dist/prompts/resource.d.ts +15 -2
- package/dist/prompts/resource.js +4 -0
- package/dist/prompts/types.d.ts +7 -13
- package/package.json +1 -1
- package/src/client.ts +6 -0
- package/src/generated/index.ts +1 -1
- package/src/generated/types.gen.ts +107 -28
- package/src/generated/zod.gen.ts +52 -66
- package/src/pagination.ts +64 -0
- package/src/prompts/resource.ts +24 -0
- package/src/prompts/types.ts +13 -14
package/src/generated/zod.gen.ts
CHANGED
|
@@ -562,6 +562,13 @@ export const zApiKeysGetApiKeyOpenIdConfigResponse = z.object({
|
|
|
562
562
|
subject_types_supported: z.array(z.string())
|
|
563
563
|
});
|
|
564
564
|
|
|
565
|
+
/**
|
|
566
|
+
* Success
|
|
567
|
+
*/
|
|
568
|
+
export const zDiscoveryGetDiscoveryResponse = z.object({
|
|
569
|
+
dashboardUrl: z.string().nullish()
|
|
570
|
+
});
|
|
571
|
+
|
|
565
572
|
/**
|
|
566
573
|
* Success
|
|
567
574
|
*/
|
|
@@ -996,14 +1003,8 @@ export const zCostRateAdminResyncProjectScopeMapResponse = z.object({
|
|
|
996
1003
|
|
|
997
1004
|
export const zApiKeysListApiKeysQuery = z.object({
|
|
998
1005
|
orgId: z.string().nullish(),
|
|
999
|
-
workspaceIds: z.
|
|
1000
|
-
|
|
1001
|
-
z.string()
|
|
1002
|
-
]).nullish(),
|
|
1003
|
-
projectIds: z.union([
|
|
1004
|
-
z.array(z.string()),
|
|
1005
|
-
z.string()
|
|
1006
|
-
]).nullish(),
|
|
1006
|
+
workspaceIds: z.array(z.string()).nullish(),
|
|
1007
|
+
projectIds: z.array(z.string()).nullish(),
|
|
1007
1008
|
scope: z.enum([
|
|
1008
1009
|
'platform',
|
|
1009
1010
|
'org',
|
|
@@ -1020,7 +1021,7 @@ export const zApiKeysListApiKeysQuery = z.object({
|
|
|
1020
1021
|
expiry: z.string().nullish(),
|
|
1021
1022
|
q: z.string().nullish(),
|
|
1022
1023
|
cursor: z.string().nullish(),
|
|
1023
|
-
limit: z.
|
|
1024
|
+
limit: z.int().nullish(),
|
|
1024
1025
|
includeRevoked: z.enum(['true', 'false']),
|
|
1025
1026
|
includeCounts: z.enum(['true', 'false'])
|
|
1026
1027
|
});
|
|
@@ -1037,7 +1038,7 @@ export const zApiKeysListApiKeysResponse = z.object({
|
|
|
1037
1038
|
revoked: z.number(),
|
|
1038
1039
|
rotating: z.number()
|
|
1039
1040
|
}),
|
|
1040
|
-
|
|
1041
|
+
items: z.array(z.object({
|
|
1041
1042
|
calls7d: z.number(),
|
|
1042
1043
|
createdAt: z.string(),
|
|
1043
1044
|
createdBy: z.object({
|
|
@@ -1083,7 +1084,10 @@ export const zApiKeysListApiKeysResponse = z.object({
|
|
|
1083
1084
|
]),
|
|
1084
1085
|
workspaceId: z.string().nullable()
|
|
1085
1086
|
})),
|
|
1086
|
-
|
|
1087
|
+
pagination: z.object({
|
|
1088
|
+
limit: z.int().gte(1).lte(100),
|
|
1089
|
+
nextCursor: z.string().nullable()
|
|
1090
|
+
}),
|
|
1087
1091
|
viewerScopeAccess: z.enum([
|
|
1088
1092
|
'none',
|
|
1089
1093
|
'scoped',
|
|
@@ -2403,8 +2407,8 @@ export const zOrgAuditListOrgAuditEventsQuery = z.object({
|
|
|
2403
2407
|
workspace_id: z.string().nullish(),
|
|
2404
2408
|
since: z.string().nullish(),
|
|
2405
2409
|
until: z.string().nullish(),
|
|
2406
|
-
|
|
2407
|
-
|
|
2410
|
+
cursor: z.string().nullish(),
|
|
2411
|
+
limit: z.int().nullish()
|
|
2408
2412
|
});
|
|
2409
2413
|
|
|
2410
2414
|
/**
|
|
@@ -2440,6 +2444,7 @@ export const zOrgAuditListOrgAuditEventsResponse = z.object({
|
|
|
2440
2444
|
workspaceId: z.string().nullable()
|
|
2441
2445
|
})),
|
|
2442
2446
|
pagination: z.object({
|
|
2447
|
+
limit: z.int().gte(1).lte(100),
|
|
2443
2448
|
nextCursor: z.string().nullable()
|
|
2444
2449
|
})
|
|
2445
2450
|
}).nullable(),
|
|
@@ -3443,17 +3448,10 @@ export const zProjectsListProjectsByOrgPath = z.object({
|
|
|
3443
3448
|
});
|
|
3444
3449
|
|
|
3445
3450
|
export const zProjectsListProjectsByOrgQuery = z.object({
|
|
3446
|
-
|
|
3451
|
+
cursor: z.string().nullish(),
|
|
3447
3452
|
limit: z.int().nullish(),
|
|
3448
3453
|
search: z.string().nullish(),
|
|
3449
|
-
sortDir: z.enum(['asc', 'desc']).nullish(),
|
|
3450
3454
|
status: z.string().nullish(),
|
|
3451
|
-
sortBy: z.enum([
|
|
3452
|
-
'createdAt',
|
|
3453
|
-
'updatedAt',
|
|
3454
|
-
'name',
|
|
3455
|
-
'slug'
|
|
3456
|
-
]).nullish(),
|
|
3457
3455
|
workspaceSlug: z.string().nullish(),
|
|
3458
3456
|
slug: z.string().nullish()
|
|
3459
3457
|
});
|
|
@@ -3463,27 +3461,33 @@ export const zProjectsListProjectsByOrgQuery = z.object({
|
|
|
3463
3461
|
*/
|
|
3464
3462
|
export const zProjectsListProjectsByOrgResponse = z.object({
|
|
3465
3463
|
code: z.number(),
|
|
3466
|
-
data: z.
|
|
3467
|
-
|
|
3468
|
-
|
|
3469
|
-
|
|
3470
|
-
|
|
3471
|
-
|
|
3472
|
-
|
|
3473
|
-
|
|
3474
|
-
|
|
3475
|
-
|
|
3476
|
-
|
|
3477
|
-
|
|
3478
|
-
|
|
3479
|
-
|
|
3480
|
-
|
|
3481
|
-
|
|
3482
|
-
|
|
3483
|
-
|
|
3484
|
-
|
|
3485
|
-
|
|
3486
|
-
|
|
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(),
|
|
3487
3491
|
error: z.object({
|
|
3488
3492
|
code: z.string(),
|
|
3489
3493
|
details: z.unknown().nullish(),
|
|
@@ -11956,24 +11960,15 @@ export const zTracesListTracesQuery = z.object({
|
|
|
11956
11960
|
]).nullish(),
|
|
11957
11961
|
provider: z.union([
|
|
11958
11962
|
z.string(),
|
|
11959
|
-
z.
|
|
11960
|
-
z.array(z.string()),
|
|
11961
|
-
z.string()
|
|
11962
|
-
])
|
|
11963
|
+
z.array(z.string())
|
|
11963
11964
|
]).nullish(),
|
|
11964
11965
|
model: z.union([
|
|
11965
11966
|
z.string(),
|
|
11966
|
-
z.
|
|
11967
|
-
z.array(z.string()),
|
|
11968
|
-
z.string()
|
|
11969
|
-
])
|
|
11967
|
+
z.array(z.string())
|
|
11970
11968
|
]).nullish(),
|
|
11971
11969
|
promptRef: z.union([
|
|
11972
11970
|
z.string(),
|
|
11973
|
-
z.
|
|
11974
|
-
z.array(z.string()),
|
|
11975
|
-
z.string()
|
|
11976
|
-
])
|
|
11971
|
+
z.array(z.string())
|
|
11977
11972
|
]).nullish(),
|
|
11978
11973
|
sessionId: z.string().min(1).max(256).nullish(),
|
|
11979
11974
|
minTokens: z.string().nullish(),
|
|
@@ -12171,24 +12166,15 @@ export const zTracesListTracePromptFacetsQuery = z.object({
|
|
|
12171
12166
|
]).nullish(),
|
|
12172
12167
|
provider: z.union([
|
|
12173
12168
|
z.string(),
|
|
12174
|
-
z.
|
|
12175
|
-
z.array(z.string()),
|
|
12176
|
-
z.string()
|
|
12177
|
-
])
|
|
12169
|
+
z.array(z.string())
|
|
12178
12170
|
]).nullish(),
|
|
12179
12171
|
model: z.union([
|
|
12180
12172
|
z.string(),
|
|
12181
|
-
z.
|
|
12182
|
-
z.array(z.string()),
|
|
12183
|
-
z.string()
|
|
12184
|
-
])
|
|
12173
|
+
z.array(z.string())
|
|
12185
12174
|
]).nullish(),
|
|
12186
12175
|
promptRef: z.union([
|
|
12187
12176
|
z.string(),
|
|
12188
|
-
z.
|
|
12189
|
-
z.array(z.string()),
|
|
12190
|
-
z.string()
|
|
12191
|
-
])
|
|
12177
|
+
z.array(z.string())
|
|
12192
12178
|
]).nullish(),
|
|
12193
12179
|
sessionId: z.string().min(1).max(256).nullish(),
|
|
12194
12180
|
minTokens: z.string().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
|
+
}
|
package/src/prompts/resource.ts
CHANGED
|
@@ -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(
|
package/src/prompts/types.ts
CHANGED
|
@@ -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
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
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()`.
|