@to11ai/sdk 0.0.2 → 0.1.1
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/LICENSE +373 -0
- package/README.md +91 -1
- package/dist/client.cjs +20 -5
- package/dist/client.d.ts +10 -1
- package/dist/client.js +26 -2
- package/dist/errors.cjs +89 -1
- package/dist/errors.d.ts +96 -0
- package/dist/errors.js +89 -1
- package/dist/gateway.cjs +8 -1
- package/dist/gateway.d.ts +19 -0
- package/dist/gateway.js +8 -1
- package/dist/projectEnvironments/resource.cjs +110 -0
- package/dist/projectEnvironments/resource.d.ts +67 -0
- package/dist/projectEnvironments/resource.js +70 -0
- package/dist/projectEnvironments/types.d.ts +121 -0
- package/dist/prompts/resource.cjs +81 -0
- package/dist/prompts/resource.d.ts +61 -2
- package/dist/prompts/resource.js +81 -0
- package/dist/prompts/types.d.ts +217 -3
- package/dist/routingRules/resource.cjs +131 -0
- package/dist/routingRules/resource.d.ts +22 -0
- package/dist/routingRules/resource.js +91 -0
- package/dist/routingRules/types.d.ts +169 -0
- package/dist/traceparent.d.ts +61 -0
- package/dist/transport.d.ts +6 -1
- package/package.json +25 -5
- package/src/client.ts +60 -1
- package/src/errors.ts +172 -0
- package/src/gateway.ts +29 -1
- package/src/projectEnvironments/resource.ts +220 -0
- package/src/projectEnvironments/types.ts +151 -0
- package/src/prompts/resource.ts +232 -0
- package/src/prompts/types.ts +270 -3
- package/src/routingRules/resource.ts +180 -0
- package/src/routingRules/types.ts +222 -0
- package/src/traceparent.ts +124 -0
- package/src/transport.ts +191 -5
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Project-scoped environment row as returned by
|
|
3
|
+
* `GET /v1/projects/:projectId/environments/:slug`.
|
|
4
|
+
*
|
|
5
|
+
* Notes:
|
|
6
|
+
* - `isSystem: true` for the seeded `prod` / `staging` rows. Those rows
|
|
7
|
+
* cannot be renamed, archived, or have their `slug`/`isSystem` mutated.
|
|
8
|
+
* - `isGatewayFallback: true` marks the env the gateway routes to when no
|
|
9
|
+
* `x-to11-env` header is supplied. At most one env per project may carry
|
|
10
|
+
* this flag; clearing the only fallback is rejected with 409
|
|
11
|
+
* `CANNOT_CLEAR_ONLY_GATEWAY_FALLBACK`.
|
|
12
|
+
* - `archivedAt` is `null` for live envs and an ISO-8601 timestamp for
|
|
13
|
+
* soft-archived ones.
|
|
14
|
+
*/
|
|
15
|
+
export interface ProjectEnvironment {
|
|
16
|
+
id: string;
|
|
17
|
+
projectId: string;
|
|
18
|
+
slug: string;
|
|
19
|
+
name: string;
|
|
20
|
+
color: string | null;
|
|
21
|
+
description: string | null;
|
|
22
|
+
isPointer: boolean;
|
|
23
|
+
requiresApproval: boolean;
|
|
24
|
+
isDefault: boolean;
|
|
25
|
+
isGatewayFallback: boolean;
|
|
26
|
+
sortOrder: number;
|
|
27
|
+
isSystem: boolean;
|
|
28
|
+
archivedAt: string | null;
|
|
29
|
+
createdBy: string;
|
|
30
|
+
updatedBy: string;
|
|
31
|
+
createdAt: string;
|
|
32
|
+
updatedAt: string;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Pointer-count payload attached to archive responses. `prompts` is real
|
|
36
|
+
* today; `rules` / `providers` are 0 in v1 (reserved for Wave 6+ specs to
|
|
37
|
+
* keep the response shape stable when those domains land).
|
|
38
|
+
*/
|
|
39
|
+
export interface LivePointerCounts {
|
|
40
|
+
prompts: number;
|
|
41
|
+
rules: number;
|
|
42
|
+
providers: number;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Response body for `POST /v1/projects/:projectId/environments/:slug/archive`.
|
|
46
|
+
* Carries the soft-archived environment plus the count of live pointers
|
|
47
|
+
* cascade-cleared by the archive operation (informational, for the
|
|
48
|
+
* confirmation modal in the web UI).
|
|
49
|
+
*/
|
|
50
|
+
export interface ArchiveProjectEnvironmentResult {
|
|
51
|
+
environment: ProjectEnvironment;
|
|
52
|
+
livePointerCounts: LivePointerCounts;
|
|
53
|
+
}
|
|
54
|
+
export interface ListProjectEnvironmentsInput {
|
|
55
|
+
projectId: string;
|
|
56
|
+
/**
|
|
57
|
+
* When `true`, the response includes archived envs (those with a
|
|
58
|
+
* non-null `archivedAt`). Default behavior excludes them.
|
|
59
|
+
*/
|
|
60
|
+
includeArchived?: boolean;
|
|
61
|
+
}
|
|
62
|
+
export type ListProjectEnvironmentsResult = ProjectEnvironment[];
|
|
63
|
+
export interface GetProjectEnvironmentInput {
|
|
64
|
+
projectId: string;
|
|
65
|
+
slug: string;
|
|
66
|
+
}
|
|
67
|
+
export type GetProjectEnvironmentResult = ProjectEnvironment;
|
|
68
|
+
/**
|
|
69
|
+
* Create input — must specify a unique `slug` matching lowercase-kebab
|
|
70
|
+
* (a-z, 0-9, hyphen, 1..63 chars). Reserved system slugs (`prod`,
|
|
71
|
+
* `staging`) are rejected by the API with `ENVIRONMENT_SLUG_TAKEN`.
|
|
72
|
+
*
|
|
73
|
+
* Setting `isGatewayFallback: true` here additionally requires the
|
|
74
|
+
* `project:manage_default_environment` capability; the create use case
|
|
75
|
+
* atomically clears the flag on any other env in the same project.
|
|
76
|
+
*/
|
|
77
|
+
export interface CreateProjectEnvironmentInput {
|
|
78
|
+
projectId: string;
|
|
79
|
+
slug: string;
|
|
80
|
+
name: string;
|
|
81
|
+
color?: string | null;
|
|
82
|
+
description?: string | null;
|
|
83
|
+
isPointer?: boolean;
|
|
84
|
+
requiresApproval?: boolean;
|
|
85
|
+
isDefault?: boolean;
|
|
86
|
+
isGatewayFallback?: boolean;
|
|
87
|
+
sortOrder?: number;
|
|
88
|
+
}
|
|
89
|
+
export type CreateProjectEnvironmentResult = ProjectEnvironment;
|
|
90
|
+
/**
|
|
91
|
+
* PATCH input — every field is optional. `slug` rename triggers a 7-day
|
|
92
|
+
* alias row server-side. System envs (`isSystem: true`) reject `slug`,
|
|
93
|
+
* `isSystem`, and other immutable-field mutations with
|
|
94
|
+
* `SYSTEM_ENV_IMMUTABLE`.
|
|
95
|
+
*
|
|
96
|
+
* As with `create`, mutating `isGatewayFallback` requires the additional
|
|
97
|
+
* `project:manage_default_environment` capability.
|
|
98
|
+
*/
|
|
99
|
+
export interface UpdateProjectEnvironmentInput {
|
|
100
|
+
projectId: string;
|
|
101
|
+
slug: string;
|
|
102
|
+
newSlug?: string;
|
|
103
|
+
name?: string;
|
|
104
|
+
color?: string | null;
|
|
105
|
+
description?: string | null;
|
|
106
|
+
isPointer?: boolean;
|
|
107
|
+
requiresApproval?: boolean;
|
|
108
|
+
isDefault?: boolean;
|
|
109
|
+
isGatewayFallback?: boolean;
|
|
110
|
+
sortOrder?: number;
|
|
111
|
+
}
|
|
112
|
+
export type UpdateProjectEnvironmentResult = ProjectEnvironment;
|
|
113
|
+
export interface ArchiveProjectEnvironmentInput {
|
|
114
|
+
projectId: string;
|
|
115
|
+
slug: string;
|
|
116
|
+
}
|
|
117
|
+
export interface RestoreProjectEnvironmentInput {
|
|
118
|
+
projectId: string;
|
|
119
|
+
slug: string;
|
|
120
|
+
}
|
|
121
|
+
export type RestoreProjectEnvironmentResult = ProjectEnvironment;
|
|
@@ -56,6 +56,33 @@ function getProjectPromptsPath(projectId) {
|
|
|
56
56
|
function getProjectPromptPath(projectId, promptId) {
|
|
57
57
|
return `${getProjectPromptsPath(projectId)}/${encodeURIComponent(promptId)}`;
|
|
58
58
|
}
|
|
59
|
+
function getProjectPromptLabelsPath(projectId) {
|
|
60
|
+
return `/v1/projects/${encodeURIComponent(projectId)}/prompt-labels`;
|
|
61
|
+
}
|
|
62
|
+
function getProjectPromptLabelPath(projectId, label) {
|
|
63
|
+
return `${getProjectPromptLabelsPath(projectId)}/${encodeURIComponent(label)}`;
|
|
64
|
+
}
|
|
65
|
+
function buildLabelEventsQuery(input) {
|
|
66
|
+
const params = new URLSearchParams;
|
|
67
|
+
if (input.page !== undefined)
|
|
68
|
+
params.set("page", String(input.page));
|
|
69
|
+
if (input.limit !== undefined)
|
|
70
|
+
params.set("limit", String(input.limit));
|
|
71
|
+
if (input.since !== undefined)
|
|
72
|
+
params.set("since", input.since);
|
|
73
|
+
if (input.until !== undefined)
|
|
74
|
+
params.set("until", input.until);
|
|
75
|
+
if (input.scope === "prompt" && input.label !== undefined) {
|
|
76
|
+
params.set("label", input.label);
|
|
77
|
+
}
|
|
78
|
+
if (input.scope === "project") {
|
|
79
|
+
if (input.label !== undefined)
|
|
80
|
+
params.set("label", input.label);
|
|
81
|
+
if (input.promptId !== undefined)
|
|
82
|
+
params.set("promptId", input.promptId);
|
|
83
|
+
}
|
|
84
|
+
return params.toString();
|
|
85
|
+
}
|
|
59
86
|
|
|
60
87
|
class PromptResource {
|
|
61
88
|
transport;
|
|
@@ -157,4 +184,58 @@ class PromptResource {
|
|
|
157
184
|
throw err;
|
|
158
185
|
}
|
|
159
186
|
}
|
|
187
|
+
async listProjectLabels(input) {
|
|
188
|
+
const { projectId, includeArchived } = input;
|
|
189
|
+
const envelope = await this.transport.request("GET", getProjectPromptLabelsPath(projectId), {
|
|
190
|
+
query: includeArchived ? { includeArchived: "true" } : undefined
|
|
191
|
+
});
|
|
192
|
+
return unwrap(envelope);
|
|
193
|
+
}
|
|
194
|
+
async createProjectLabel(input) {
|
|
195
|
+
const { projectId, ...body } = input;
|
|
196
|
+
const envelope = await this.transport.request("POST", getProjectPromptLabelsPath(projectId), { body });
|
|
197
|
+
return unwrap(envelope);
|
|
198
|
+
}
|
|
199
|
+
async getProjectLabel(input) {
|
|
200
|
+
const envelope = await this.transport.request("GET", getProjectPromptLabelPath(input.projectId, input.label));
|
|
201
|
+
return unwrap(envelope);
|
|
202
|
+
}
|
|
203
|
+
async updateProjectLabel(input) {
|
|
204
|
+
const { projectId, label, ...rest } = input;
|
|
205
|
+
const body = {};
|
|
206
|
+
if (rest.isDefault !== undefined)
|
|
207
|
+
body.isDefault = rest.isDefault;
|
|
208
|
+
if (rest.description !== undefined)
|
|
209
|
+
body.description = rest.description;
|
|
210
|
+
if (rest.displayColor !== undefined)
|
|
211
|
+
body.displayColor = rest.displayColor;
|
|
212
|
+
const envelope = await this.transport.request("PATCH", getProjectPromptLabelPath(projectId, label), { body });
|
|
213
|
+
return unwrap(envelope);
|
|
214
|
+
}
|
|
215
|
+
async deleteProjectLabel(input) {
|
|
216
|
+
const envelope = await this.transport.request("DELETE", getProjectPromptLabelPath(input.projectId, input.label));
|
|
217
|
+
return unwrap(envelope);
|
|
218
|
+
}
|
|
219
|
+
async listProjectLabelUsages(input) {
|
|
220
|
+
const envelope = await this.transport.request("GET", `${getProjectPromptLabelPath(input.projectId, input.label)}/usages`);
|
|
221
|
+
return unwrap(envelope);
|
|
222
|
+
}
|
|
223
|
+
async listLabelEvents(input) {
|
|
224
|
+
const projectSeg = encodeURIComponent(input.projectId);
|
|
225
|
+
let path;
|
|
226
|
+
switch (input.scope) {
|
|
227
|
+
case "label":
|
|
228
|
+
path = `/v1/projects/${projectSeg}/prompts/${encodeURIComponent(input.promptId)}/labels/${encodeURIComponent(input.label)}/events`;
|
|
229
|
+
break;
|
|
230
|
+
case "prompt":
|
|
231
|
+
path = `/v1/projects/${projectSeg}/prompts/${encodeURIComponent(input.promptId)}/label-events`;
|
|
232
|
+
break;
|
|
233
|
+
case "project":
|
|
234
|
+
path = `/v1/projects/${projectSeg}/label-events`;
|
|
235
|
+
break;
|
|
236
|
+
}
|
|
237
|
+
const query = buildLabelEventsQuery(input);
|
|
238
|
+
const envelope = await this.transport.request("GET", query ? `${path}?${query}` : path);
|
|
239
|
+
return unwrap(envelope);
|
|
240
|
+
}
|
|
160
241
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { Transport } from "../transport";
|
|
2
2
|
import type { CacheConfig } from "./cache";
|
|
3
|
-
import type { ArchivePromptInput, ArchivePromptResult, CreatePromptInput, CreatePromptResult, CreatePromptVersionInput, CreatePromptVersionResult, GetPromptInput, GetPromptResult, GetPromptVersionInput, GetPromptVersionResult, ListPromptLabelsInput, ListPromptLabelsResult, ListPromptsInput, ListPromptsResult, ListPromptVersionsInput, ListPromptVersionsResult, MovePromptLabelInput, MovePromptLabelResult, PaginatedResult, ResolvePromptInput, ResolvePromptResult, UpdatePromptInput, UpdatePromptResult } from "./types";
|
|
3
|
+
import type { ArchivePromptInput, ArchivePromptResult, CreateProjectPromptLabelInput, CreateProjectPromptLabelResult, CreatePromptInput, CreatePromptResult, CreatePromptVersionInput, CreatePromptVersionResult, DeleteProjectPromptLabelInput, DeleteProjectPromptLabelResult, GetProjectPromptLabelInput, GetProjectPromptLabelResult, GetPromptInput, GetPromptResult, GetPromptVersionInput, GetPromptVersionResult, ListLabelEventsInput, ListLabelEventsResult, ListProjectPromptLabelsInput, ListProjectPromptLabelsResult, ListProjectPromptLabelUsagesInput, ListProjectPromptLabelUsagesResult, ListPromptLabelsInput, ListPromptLabelsResult, ListPromptsInput, ListPromptsResult, ListPromptVersionsInput, ListPromptVersionsResult, MovePromptLabelInput, MovePromptLabelResult, PaginatedResult, ResolvePromptInput, ResolvePromptResult, UpdateProjectPromptLabelInput, UpdateProjectPromptLabelResult, UpdatePromptInput, UpdatePromptResult } from "./types";
|
|
4
4
|
export type { CacheConfig } from "./cache";
|
|
5
|
-
export type { ArchivePromptInput, ArchivePromptResult, ChatMessage, CreatePromptInput, CreatePromptResult, CreatePromptVersionInput, CreatePromptVersionResult, GetPromptInput, GetPromptResult, GetPromptVersionInput, GetPromptVersionResult, ListPromptLabelsInput, ListPromptLabelsResult, ListPromptsInput, ListPromptsResult, ListPromptVersionsInput, ListPromptVersionsResult, MovePromptLabelInput, MovePromptLabelResult, PaginatedResult, PaginationInfo, Prompt, PromptFormat, PromptLabelPointer, PromptStatus, PromptVersion, RenderedPrompt, ResolvedPrompt, ResolvePromptInput, ResolvePromptResult, UpdatePromptInput, UpdatePromptResult, } from "./types";
|
|
5
|
+
export type { ArchivePromptInput, ArchivePromptResult, ChatMessage, CreateProjectPromptLabelInput, CreateProjectPromptLabelResult, CreatePromptInput, CreatePromptResult, CreatePromptVersionInput, CreatePromptVersionResult, DeleteProjectPromptLabelInput, DeleteProjectPromptLabelResult, GetProjectPromptLabelInput, GetProjectPromptLabelResult, GetPromptInput, GetPromptResult, GetPromptVersionInput, GetPromptVersionResult, ListLabelEventsInput, ListLabelEventsResult, ListProjectPromptLabelsInput, ListProjectPromptLabelsResult, ListProjectPromptLabelUsagesInput, ListProjectPromptLabelUsagesResult, ListPromptLabelsInput, ListPromptLabelsResult, ListPromptsInput, ListPromptsResult, ListPromptVersionsInput, ListPromptVersionsResult, MovePromptLabelInput, MovePromptLabelResult, PaginatedResult, PaginationInfo, PaletteToken, ProjectPromptLabel, ProjectPromptLabelUsage, Prompt, PromptFormat, PromptLabelEvent, PromptLabelPointer, PromptStatus, PromptVersion, RenderedChatMessage, RenderedPrompt, ResolvedPrompt, ResolvePromptInput, ResolvePromptResult, RowError, TextChatMessage, TextChatRole, ToolChatMessage, UpdateProjectPromptLabelInput, UpdateProjectPromptLabelResult, UpdatePromptInput, UpdatePromptResult, } from "./types";
|
|
6
6
|
export declare class PromptResource {
|
|
7
7
|
private readonly transport;
|
|
8
8
|
private readonly cache;
|
|
@@ -18,4 +18,63 @@ export declare class PromptResource {
|
|
|
18
18
|
moveLabel(input: MovePromptLabelInput): Promise<MovePromptLabelResult>;
|
|
19
19
|
listLabels(input: ListPromptLabelsInput): Promise<ListPromptLabelsResult>;
|
|
20
20
|
resolve(input: ResolvePromptInput): Promise<ResolvePromptResult>;
|
|
21
|
+
/**
|
|
22
|
+
* List the project-level label registry.
|
|
23
|
+
*
|
|
24
|
+
* Excludes archived entries by default. Pass `includeArchived: true` to
|
|
25
|
+
* include rows with a non-null `archivedAt` (useful for admin / history
|
|
26
|
+
* affordances). Gated on `prompt:read` server-side.
|
|
27
|
+
*/
|
|
28
|
+
listProjectLabels(input: ListProjectPromptLabelsInput): Promise<ListProjectPromptLabelsResult>;
|
|
29
|
+
/**
|
|
30
|
+
* Create a new project label.
|
|
31
|
+
*
|
|
32
|
+
* Requires the `project:manage_labels` permission. Returns the canonical
|
|
33
|
+
* row as written to the registry (including server-assigned
|
|
34
|
+
* `displayColor` if not supplied).
|
|
35
|
+
*/
|
|
36
|
+
createProjectLabel(input: CreateProjectPromptLabelInput): Promise<CreateProjectPromptLabelResult>;
|
|
37
|
+
getProjectLabel(input: GetProjectPromptLabelInput): Promise<GetProjectPromptLabelResult>;
|
|
38
|
+
/**
|
|
39
|
+
* PATCH a project label.
|
|
40
|
+
*
|
|
41
|
+
* Note on `description` semantics: `undefined` means "do not change" —
|
|
42
|
+
* the SDK omits the field from the body in that case. Pass
|
|
43
|
+
* `description: ""` (empty string) or `description: null` to explicitly
|
|
44
|
+
* clear it (the server normalises both).
|
|
45
|
+
*/
|
|
46
|
+
updateProjectLabel(input: UpdateProjectPromptLabelInput): Promise<UpdateProjectPromptLabelResult>;
|
|
47
|
+
/**
|
|
48
|
+
* Archive (soft-delete) a project label.
|
|
49
|
+
*
|
|
50
|
+
* Returns the archived row (matches the `archive` pattern — the API
|
|
51
|
+
* returns 200 with the soft-deleted record so call sites can show
|
|
52
|
+
* "archived just now" without a follow-up GET). System labels
|
|
53
|
+
* (`isSystem: true`) cannot be archived; the server returns 409
|
|
54
|
+
* `PROJECT_LABEL_SYSTEM_NOT_DELETABLE` for those.
|
|
55
|
+
*/
|
|
56
|
+
deleteProjectLabel(input: DeleteProjectPromptLabelInput): Promise<DeleteProjectPromptLabelResult>;
|
|
57
|
+
/**
|
|
58
|
+
* List every prompt currently pointed at by `label`.
|
|
59
|
+
*
|
|
60
|
+
* Returns an empty list if no prompt references the label. Gated on
|
|
61
|
+
* `prompt:read` server-side.
|
|
62
|
+
*/
|
|
63
|
+
listProjectLabelUsages(input: ListProjectPromptLabelUsagesInput): Promise<ListProjectPromptLabelUsagesResult>;
|
|
64
|
+
/**
|
|
65
|
+
* List immutable label-movement events at one of three scopes.
|
|
66
|
+
*
|
|
67
|
+
* - `scope: "label"` — narrows to a single label on a single prompt.
|
|
68
|
+
* Requires `promptId` and `label`.
|
|
69
|
+
* - `scope: "prompt"` — all label moves on the prompt. Requires
|
|
70
|
+
* `promptId`. `label` is an optional server-side filter.
|
|
71
|
+
* - `scope: "project"` — all label moves in the project. `label` and
|
|
72
|
+
* `promptId` are optional filters.
|
|
73
|
+
*
|
|
74
|
+
* `since` / `until` are ISO-8601 timestamps. The server returns 422
|
|
75
|
+
* `INVALID_DATE_RANGE` if `since` is after `until`.
|
|
76
|
+
*
|
|
77
|
+
* Gated on `prompt:read` server-side.
|
|
78
|
+
*/
|
|
79
|
+
listLabelEvents(input: ListLabelEventsInput): Promise<ListLabelEventsResult>;
|
|
21
80
|
}
|
package/dist/prompts/resource.js
CHANGED
|
@@ -13,6 +13,33 @@ function getProjectPromptsPath(projectId) {
|
|
|
13
13
|
function getProjectPromptPath(projectId, promptId) {
|
|
14
14
|
return `${getProjectPromptsPath(projectId)}/${encodeURIComponent(promptId)}`;
|
|
15
15
|
}
|
|
16
|
+
function getProjectPromptLabelsPath(projectId) {
|
|
17
|
+
return `/v1/projects/${encodeURIComponent(projectId)}/prompt-labels`;
|
|
18
|
+
}
|
|
19
|
+
function getProjectPromptLabelPath(projectId, label) {
|
|
20
|
+
return `${getProjectPromptLabelsPath(projectId)}/${encodeURIComponent(label)}`;
|
|
21
|
+
}
|
|
22
|
+
function buildLabelEventsQuery(input) {
|
|
23
|
+
const params = new URLSearchParams;
|
|
24
|
+
if (input.page !== undefined)
|
|
25
|
+
params.set("page", String(input.page));
|
|
26
|
+
if (input.limit !== undefined)
|
|
27
|
+
params.set("limit", String(input.limit));
|
|
28
|
+
if (input.since !== undefined)
|
|
29
|
+
params.set("since", input.since);
|
|
30
|
+
if (input.until !== undefined)
|
|
31
|
+
params.set("until", input.until);
|
|
32
|
+
if (input.scope === "prompt" && input.label !== undefined) {
|
|
33
|
+
params.set("label", input.label);
|
|
34
|
+
}
|
|
35
|
+
if (input.scope === "project") {
|
|
36
|
+
if (input.label !== undefined)
|
|
37
|
+
params.set("label", input.label);
|
|
38
|
+
if (input.promptId !== undefined)
|
|
39
|
+
params.set("promptId", input.promptId);
|
|
40
|
+
}
|
|
41
|
+
return params.toString();
|
|
42
|
+
}
|
|
16
43
|
|
|
17
44
|
class PromptResource {
|
|
18
45
|
transport;
|
|
@@ -114,6 +141,60 @@ class PromptResource {
|
|
|
114
141
|
throw err;
|
|
115
142
|
}
|
|
116
143
|
}
|
|
144
|
+
async listProjectLabels(input) {
|
|
145
|
+
const { projectId, includeArchived } = input;
|
|
146
|
+
const envelope = await this.transport.request("GET", getProjectPromptLabelsPath(projectId), {
|
|
147
|
+
query: includeArchived ? { includeArchived: "true" } : undefined
|
|
148
|
+
});
|
|
149
|
+
return unwrap(envelope);
|
|
150
|
+
}
|
|
151
|
+
async createProjectLabel(input) {
|
|
152
|
+
const { projectId, ...body } = input;
|
|
153
|
+
const envelope = await this.transport.request("POST", getProjectPromptLabelsPath(projectId), { body });
|
|
154
|
+
return unwrap(envelope);
|
|
155
|
+
}
|
|
156
|
+
async getProjectLabel(input) {
|
|
157
|
+
const envelope = await this.transport.request("GET", getProjectPromptLabelPath(input.projectId, input.label));
|
|
158
|
+
return unwrap(envelope);
|
|
159
|
+
}
|
|
160
|
+
async updateProjectLabel(input) {
|
|
161
|
+
const { projectId, label, ...rest } = input;
|
|
162
|
+
const body = {};
|
|
163
|
+
if (rest.isDefault !== undefined)
|
|
164
|
+
body.isDefault = rest.isDefault;
|
|
165
|
+
if (rest.description !== undefined)
|
|
166
|
+
body.description = rest.description;
|
|
167
|
+
if (rest.displayColor !== undefined)
|
|
168
|
+
body.displayColor = rest.displayColor;
|
|
169
|
+
const envelope = await this.transport.request("PATCH", getProjectPromptLabelPath(projectId, label), { body });
|
|
170
|
+
return unwrap(envelope);
|
|
171
|
+
}
|
|
172
|
+
async deleteProjectLabel(input) {
|
|
173
|
+
const envelope = await this.transport.request("DELETE", getProjectPromptLabelPath(input.projectId, input.label));
|
|
174
|
+
return unwrap(envelope);
|
|
175
|
+
}
|
|
176
|
+
async listProjectLabelUsages(input) {
|
|
177
|
+
const envelope = await this.transport.request("GET", `${getProjectPromptLabelPath(input.projectId, input.label)}/usages`);
|
|
178
|
+
return unwrap(envelope);
|
|
179
|
+
}
|
|
180
|
+
async listLabelEvents(input) {
|
|
181
|
+
const projectSeg = encodeURIComponent(input.projectId);
|
|
182
|
+
let path;
|
|
183
|
+
switch (input.scope) {
|
|
184
|
+
case "label":
|
|
185
|
+
path = `/v1/projects/${projectSeg}/prompts/${encodeURIComponent(input.promptId)}/labels/${encodeURIComponent(input.label)}/events`;
|
|
186
|
+
break;
|
|
187
|
+
case "prompt":
|
|
188
|
+
path = `/v1/projects/${projectSeg}/prompts/${encodeURIComponent(input.promptId)}/label-events`;
|
|
189
|
+
break;
|
|
190
|
+
case "project":
|
|
191
|
+
path = `/v1/projects/${projectSeg}/label-events`;
|
|
192
|
+
break;
|
|
193
|
+
}
|
|
194
|
+
const query = buildLabelEventsQuery(input);
|
|
195
|
+
const envelope = await this.transport.request("GET", query ? `${path}?${query}` : path);
|
|
196
|
+
return unwrap(envelope);
|
|
197
|
+
}
|
|
117
198
|
}
|
|
118
199
|
export {
|
|
119
200
|
PromptResource
|
package/dist/prompts/types.d.ts
CHANGED
|
@@ -1,9 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Per-row pointer carried on 422 validation envelopes.
|
|
3
|
+
*
|
|
4
|
+
* The published `@to11ai/sdk` package does NOT depend on the internal
|
|
5
|
+
* `@to11/shared-kernel` workspace package (it would pull workspace-only
|
|
6
|
+
* types into a public npm release). The shape below is therefore
|
|
7
|
+
* declared identically to `RowError` in
|
|
8
|
+
* `packages/shared-kernel/src/schemas/api-schemas.ts` — keep them in
|
|
9
|
+
* lockstep when adding new fields.
|
|
10
|
+
*
|
|
11
|
+
* 422 responses for prompt-version writes carry an optional
|
|
12
|
+
* `error.rowErrors` array — one entry per failing field. Each row
|
|
13
|
+
* carries:
|
|
14
|
+
*
|
|
15
|
+
* - `path`: JSON-pointer-equivalent array, e.g.
|
|
16
|
+
* `["messages", 3, "name"]`.
|
|
17
|
+
* - `code`: stable identifier such as `tool_name_invalid_charset`
|
|
18
|
+
* or `messages_empty` — see the platform spec for the full set.
|
|
19
|
+
* - `message`: a human-readable summary.
|
|
20
|
+
*
|
|
21
|
+
* SDK consumers can detect the structured shape by inspecting
|
|
22
|
+
* `error.code === "validation_failed"` and walking `error.rowErrors`
|
|
23
|
+
* (always optional; absent on non-validation 422s).
|
|
24
|
+
*/
|
|
25
|
+
export interface RowError {
|
|
26
|
+
path: ReadonlyArray<string | number>;
|
|
27
|
+
code: string;
|
|
28
|
+
message: string;
|
|
29
|
+
}
|
|
1
30
|
export type PromptStatus = "active" | "archived";
|
|
2
31
|
export type PromptFormat = "text" | "chat";
|
|
3
|
-
|
|
4
|
-
|
|
32
|
+
/**
|
|
33
|
+
* Roles supported by `TextChatMessage`.
|
|
34
|
+
*
|
|
35
|
+
* V1 server contract: `developer` is accepted at the wire boundary and
|
|
36
|
+
* rendered as `user` in `:resolve` responses. The literal is preserved
|
|
37
|
+
* here so SDK consumers can author developer-tagged messages today and
|
|
38
|
+
* V2 can flip the rendered role without a wire-level break.
|
|
39
|
+
*/
|
|
40
|
+
export type TextChatRole = "system" | "user" | "assistant" | "developer";
|
|
41
|
+
/**
|
|
42
|
+
* Text-style chat message. Carries a Liquid template body in `content`.
|
|
43
|
+
*
|
|
44
|
+
* `disabled` skips the message at render time but preserves it through
|
|
45
|
+
* edit / list / get round-trips so authors can toggle messages without
|
|
46
|
+
* losing them.
|
|
47
|
+
*/
|
|
48
|
+
export interface TextChatMessage {
|
|
49
|
+
role: TextChatRole;
|
|
5
50
|
content: string;
|
|
51
|
+
disabled?: boolean;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Tool-call chat message. Structurally distinct from text messages: it
|
|
55
|
+
* carries `name` / `description` / `parameters` instead of `content`.
|
|
56
|
+
*
|
|
57
|
+
* - `name`: 1..200 chars, matches the tool name the gateway exposes to
|
|
58
|
+
* providers.
|
|
59
|
+
* - `description`: optional human-readable summary surfaced in the
|
|
60
|
+
* provider's tool-choice UI.
|
|
61
|
+
* - `parameters`: JSON Schema (an object) describing the tool's
|
|
62
|
+
* arguments. Not validated against the JSON Schema meta-schema at
|
|
63
|
+
* edit time — the gateway is the source of truth.
|
|
64
|
+
*/
|
|
65
|
+
export interface ToolChatMessage {
|
|
66
|
+
role: "tool";
|
|
67
|
+
name: string;
|
|
68
|
+
description?: string;
|
|
69
|
+
parameters: unknown;
|
|
70
|
+
disabled?: boolean;
|
|
6
71
|
}
|
|
72
|
+
/**
|
|
73
|
+
* Discriminated union of text and tool chat messages.
|
|
74
|
+
*
|
|
75
|
+
* Legacy `{role: "tool", content: "..."}` rows are auto-upgraded by the
|
|
76
|
+
* server on read: they decode as `{role: "tool", name: "(unnamed)",
|
|
77
|
+
* description: <legacy content>, parameters: {}}`. Writes always emit
|
|
78
|
+
* the new shape.
|
|
79
|
+
*/
|
|
80
|
+
export type ChatMessage = TextChatMessage | ToolChatMessage;
|
|
7
81
|
export interface Prompt {
|
|
8
82
|
id: string;
|
|
9
83
|
projectId: string;
|
|
@@ -35,12 +109,24 @@ export interface PromptLabelPointer {
|
|
|
35
109
|
updatedByUserId: string;
|
|
36
110
|
updatedAt: string;
|
|
37
111
|
}
|
|
112
|
+
/**
|
|
113
|
+
* A single message in a rendered chat prompt returned by `:resolve`.
|
|
114
|
+
*
|
|
115
|
+
* Always carries a flat `{role, content}` shape — even tool/developer
|
|
116
|
+
* messages, since the server normalises them at render time
|
|
117
|
+
* (V1 contract: tool messages are filtered, developer is mapped to user).
|
|
118
|
+
* The `role` literal stays wide so V2 changes are wire-compatible.
|
|
119
|
+
*/
|
|
120
|
+
export interface RenderedChatMessage {
|
|
121
|
+
role: "system" | "user" | "assistant" | "developer" | "tool";
|
|
122
|
+
content: string;
|
|
123
|
+
}
|
|
38
124
|
export type RenderedPrompt = {
|
|
39
125
|
format: "text";
|
|
40
126
|
text: string;
|
|
41
127
|
} | {
|
|
42
128
|
format: "chat";
|
|
43
|
-
messages:
|
|
129
|
+
messages: RenderedChatMessage[];
|
|
44
130
|
};
|
|
45
131
|
export interface ResolvedPrompt {
|
|
46
132
|
promptId: string;
|
|
@@ -140,3 +226,131 @@ export interface ResolvePromptInput {
|
|
|
140
226
|
fallback?: ResolvedPrompt;
|
|
141
227
|
}
|
|
142
228
|
export type ResolvePromptResult = ResolvedPrompt;
|
|
229
|
+
/** Palette token assigned to a project label for UI rendering. */
|
|
230
|
+
export type PaletteToken = "accent" | "red" | "orange" | "amber" | "green" | "teal" | "blue" | "indigo" | "purple" | "pink";
|
|
231
|
+
/**
|
|
232
|
+
* Project-level label registry entry.
|
|
233
|
+
*
|
|
234
|
+
* System labels (`isSystem: true`) cannot be archived. `archivedAt` is
|
|
235
|
+
* non-null for soft-deleted entries; the list endpoint excludes archived
|
|
236
|
+
* entries by default — pass `includeArchived: true` if the call site needs
|
|
237
|
+
* them (e.g. admin / history affordances).
|
|
238
|
+
*/
|
|
239
|
+
export interface ProjectPromptLabel {
|
|
240
|
+
projectId: string;
|
|
241
|
+
label: string;
|
|
242
|
+
isSystem: boolean;
|
|
243
|
+
isDefault: boolean;
|
|
244
|
+
description: string | null;
|
|
245
|
+
displayColor: PaletteToken;
|
|
246
|
+
createdByUserId: string;
|
|
247
|
+
createdAt: string;
|
|
248
|
+
updatedAt: string;
|
|
249
|
+
archivedAt: string | null;
|
|
250
|
+
}
|
|
251
|
+
/**
|
|
252
|
+
* A single prompt currently pointed at by a given project label.
|
|
253
|
+
*
|
|
254
|
+
* Returned by `GET /v1/projects/:projectId/prompt-labels/:label/usages`.
|
|
255
|
+
* `updatedAt` / `updatedByUserId` carry the last-move metadata so the UI
|
|
256
|
+
* can render a "moved 3 days ago by …" affordance without a second
|
|
257
|
+
* roundtrip.
|
|
258
|
+
*/
|
|
259
|
+
export interface ProjectPromptLabelUsage {
|
|
260
|
+
promptId: string;
|
|
261
|
+
promptSlug: string;
|
|
262
|
+
promptName: string;
|
|
263
|
+
versionId: string;
|
|
264
|
+
version: number;
|
|
265
|
+
updatedAt: string;
|
|
266
|
+
updatedByUserId: string;
|
|
267
|
+
}
|
|
268
|
+
/**
|
|
269
|
+
* An immutable history row for a single label movement.
|
|
270
|
+
*
|
|
271
|
+
* `fromVersionId` is `null` for the first time the label is pointed at a
|
|
272
|
+
* version (no prior pointer). `reason` is the optional caller-supplied
|
|
273
|
+
* audit string.
|
|
274
|
+
*/
|
|
275
|
+
export interface PromptLabelEvent {
|
|
276
|
+
id: string;
|
|
277
|
+
promptId: string;
|
|
278
|
+
label: string;
|
|
279
|
+
fromVersionId: string | null;
|
|
280
|
+
toVersionId: string;
|
|
281
|
+
movedByUserId: string;
|
|
282
|
+
movedAt: string;
|
|
283
|
+
reason: string | null;
|
|
284
|
+
}
|
|
285
|
+
export interface ListProjectPromptLabelsInput {
|
|
286
|
+
projectId: string;
|
|
287
|
+
/** Set true to include archived (soft-deleted) entries. Default: false. */
|
|
288
|
+
includeArchived?: boolean;
|
|
289
|
+
}
|
|
290
|
+
export type ListProjectPromptLabelsResult = ProjectPromptLabel[];
|
|
291
|
+
export interface CreateProjectPromptLabelInput {
|
|
292
|
+
projectId: string;
|
|
293
|
+
label: string;
|
|
294
|
+
isDefault?: boolean;
|
|
295
|
+
description?: string;
|
|
296
|
+
displayColor?: PaletteToken;
|
|
297
|
+
}
|
|
298
|
+
export type CreateProjectPromptLabelResult = ProjectPromptLabel;
|
|
299
|
+
export interface GetProjectPromptLabelInput {
|
|
300
|
+
projectId: string;
|
|
301
|
+
label: string;
|
|
302
|
+
}
|
|
303
|
+
export type GetProjectPromptLabelResult = ProjectPromptLabel;
|
|
304
|
+
export interface UpdateProjectPromptLabelInput {
|
|
305
|
+
projectId: string;
|
|
306
|
+
label: string;
|
|
307
|
+
isDefault?: boolean;
|
|
308
|
+
description?: string | null;
|
|
309
|
+
displayColor?: PaletteToken;
|
|
310
|
+
}
|
|
311
|
+
export type UpdateProjectPromptLabelResult = ProjectPromptLabel;
|
|
312
|
+
export interface DeleteProjectPromptLabelInput {
|
|
313
|
+
projectId: string;
|
|
314
|
+
label: string;
|
|
315
|
+
}
|
|
316
|
+
/**
|
|
317
|
+
* The DELETE endpoint returns 200 with the archived row (mirrors the
|
|
318
|
+
* `archivePrompt` pattern — call sites can show "archived just now"
|
|
319
|
+
* without a follow-up GET). System labels (`isSystem: true`) cannot be
|
|
320
|
+
* archived; the server returns 409 `PROJECT_LABEL_SYSTEM_NOT_DELETABLE`.
|
|
321
|
+
*/
|
|
322
|
+
export type DeleteProjectPromptLabelResult = ProjectPromptLabel;
|
|
323
|
+
export interface ListProjectPromptLabelUsagesInput {
|
|
324
|
+
projectId: string;
|
|
325
|
+
label: string;
|
|
326
|
+
}
|
|
327
|
+
export type ListProjectPromptLabelUsagesResult = ProjectPromptLabelUsage[];
|
|
328
|
+
export type ListLabelEventsInput = {
|
|
329
|
+
scope: "label";
|
|
330
|
+
projectId: string;
|
|
331
|
+
promptId: string;
|
|
332
|
+
label: string;
|
|
333
|
+
page?: number;
|
|
334
|
+
limit?: number;
|
|
335
|
+
since?: string;
|
|
336
|
+
until?: string;
|
|
337
|
+
} | {
|
|
338
|
+
scope: "prompt";
|
|
339
|
+
projectId: string;
|
|
340
|
+
promptId: string;
|
|
341
|
+
label?: string;
|
|
342
|
+
page?: number;
|
|
343
|
+
limit?: number;
|
|
344
|
+
since?: string;
|
|
345
|
+
until?: string;
|
|
346
|
+
} | {
|
|
347
|
+
scope: "project";
|
|
348
|
+
projectId: string;
|
|
349
|
+
promptId?: string;
|
|
350
|
+
label?: string;
|
|
351
|
+
page?: number;
|
|
352
|
+
limit?: number;
|
|
353
|
+
since?: string;
|
|
354
|
+
until?: string;
|
|
355
|
+
};
|
|
356
|
+
export type ListLabelEventsResult = PaginatedResult<PromptLabelEvent>;
|