@to11ai/sdk 1.1.0 → 2.0.0-rc.2
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 +88 -18
- package/dist/client.d.ts +141 -39
- package/dist/client.js +94 -19
- package/dist/config.d.ts +9 -0
- package/dist/context.d.ts +124 -0
- package/dist/errors.cjs +18 -1
- package/dist/errors.d.ts +18 -1
- package/dist/errors.js +18 -1
- package/dist/gateway.cjs +65 -22
- package/dist/gateway.d.ts +65 -9
- package/dist/gateway.js +65 -22
- package/dist/generated/index.d.ts +1 -1
- package/dist/generated/types.gen.d.ts +1299 -167
- package/dist/generated/zod.gen.d.ts +393 -232
- package/dist/prompts/cache.d.ts +9 -10
- package/dist/prompts/resource.cjs +29 -67
- package/dist/prompts/resource.d.ts +52 -32
- package/dist/prompts/resource.js +30 -68
- package/dist/prompts/shape.d.ts +56 -0
- package/dist/prompts/types.d.ts +44 -31
- package/package.json +1 -1
- package/src/client.ts +337 -82
- package/src/config.ts +13 -0
- package/src/context.ts +198 -0
- package/src/errors.ts +33 -3
- package/src/gateway.ts +148 -33
- package/src/generated/index.ts +1 -1
- package/src/generated/types.gen.ts +1310 -167
- package/src/generated/zod.gen.ts +361 -271
- package/src/prompts/cache.ts +11 -15
- package/src/prompts/resource.ts +129 -142
- package/src/prompts/shape.ts +152 -0
- package/src/prompts/types.ts +45 -34
package/dist/prompts/types.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ProjectPromptLabel as GenProjectPromptLabel, ProjectPromptLabelUsage as GenProjectPromptLabelUsage, Prompt as GenPrompt, PromptLabelEvent as GenPromptLabelEvent, PromptLabelPointer as GenPromptLabelPointer, PromptVersion as GenPromptVersion, RenderedChatPrompt as GenRenderedChatPrompt,
|
|
1
|
+
import type { ProjectPromptLabel as GenProjectPromptLabel, ProjectPromptLabelUsage as GenProjectPromptLabelUsage, Prompt as GenPrompt, PromptLabelEvent as GenPromptLabelEvent, PromptLabelPointer as GenPromptLabelPointer, PromptVersion as GenPromptVersion, RenderedChatPrompt as GenRenderedChatPrompt, ResolvedPrompt as GenResolvedPrompt, ResolvedToolCall as GenResolvedToolCall, ResolvedToolDefinition as GenResolvedToolDefinition } from "../generated/types.gen";
|
|
2
2
|
export interface RowError {
|
|
3
3
|
path: ReadonlyArray<string | number>;
|
|
4
4
|
code: string;
|
|
@@ -17,7 +17,16 @@ export interface TextChatMessage {
|
|
|
17
17
|
}
|
|
18
18
|
export type ChatMessage = TextChatMessage;
|
|
19
19
|
export type RenderedChatMessage = GenRenderedChatPrompt["messages"][number];
|
|
20
|
-
|
|
20
|
+
/** Provider shape for `prompts.render()` output. Omit for the neutral result. */
|
|
21
|
+
export type RenderFormat = "openai" | "anthropic";
|
|
22
|
+
/**
|
|
23
|
+
* Policy for a message whose role is outside the known set
|
|
24
|
+
* (`system | user | assistant | developer | tool`) when converting to a
|
|
25
|
+
* provider shape. `"drop"` (default) omits it silently; `"warn"` omits it and
|
|
26
|
+
* emits a `console.warn`; `"error"` throws `UnknownRoleError`. Applies to the
|
|
27
|
+
* standalone converters and to `render({ format })`.
|
|
28
|
+
*/
|
|
29
|
+
export type UnknownRoleMode = "drop" | "warn" | "error";
|
|
21
30
|
/**
|
|
22
31
|
* A provider-neutral tool definition (`{ name, description?, parameters }`),
|
|
23
32
|
* sourced from authored tool-definition blocks. Surfaced on the resolved
|
|
@@ -29,7 +38,7 @@ export type ResolvedToolDefinition = GenResolvedToolDefinition;
|
|
|
29
38
|
* on a rendered `assistant` turn (few-shot multi-tool history).
|
|
30
39
|
*/
|
|
31
40
|
export type ResolvedToolCall = GenResolvedToolCall;
|
|
32
|
-
export type ResolvedPrompt = Pick<GenResolvedPrompt, "promptId" | "versionId" | "version" | "
|
|
41
|
+
export type ResolvedPrompt = Pick<GenResolvedPrompt, "promptId" | "versionId" | "version" | "label" | "contentHash" | "rendered" | "tools" | "toolChoice" | "modelConfig">;
|
|
33
42
|
export interface PaginationInfo {
|
|
34
43
|
page: number;
|
|
35
44
|
limit: number;
|
|
@@ -109,20 +118,9 @@ export interface ListPromptLabelsInput {
|
|
|
109
118
|
promptId: string;
|
|
110
119
|
}
|
|
111
120
|
export type ListPromptLabelsResult = PromptLabelPointer[];
|
|
112
|
-
export interface ResolvePromptInput {
|
|
113
|
-
projectId: string;
|
|
114
|
-
slug: string;
|
|
115
|
-
labels: string[];
|
|
116
|
-
variables?: Record<string, unknown>;
|
|
117
|
-
/** Set false to bypass the LRU cache for this call. Default: true */
|
|
118
|
-
cache?: boolean;
|
|
119
|
-
/** Fallback prompt served if the API is unreachable and cache is empty. */
|
|
120
|
-
fallback?: ResolvedPrompt;
|
|
121
|
-
}
|
|
122
|
-
export type ResolvePromptResult = ResolvedPrompt;
|
|
123
121
|
export declare const ENV_SLUG_REGEX: RegExp;
|
|
124
122
|
export type BlockRenderRecord = Record<string, "rendered" | "dimmed">;
|
|
125
|
-
export interface
|
|
123
|
+
export interface RenderedPrompt {
|
|
126
124
|
messages: RenderedChatMessage[];
|
|
127
125
|
version: number;
|
|
128
126
|
releaseId: string | null;
|
|
@@ -131,8 +129,24 @@ export interface FetchedPrompt {
|
|
|
131
129
|
promptId: string;
|
|
132
130
|
versionId: string;
|
|
133
131
|
contentHash: string;
|
|
134
|
-
|
|
135
|
-
|
|
132
|
+
/**
|
|
133
|
+
* The single label the prompt resolved through — the env slug today, a real
|
|
134
|
+
* label once labels ship. Surfaced as `x-to11-prompt-label` by
|
|
135
|
+
* `gatewayPromptHeaders` / `turn.headers()` (TO11-2725).
|
|
136
|
+
*/
|
|
137
|
+
label: string;
|
|
138
|
+
/**
|
|
139
|
+
* The prompt's human-readable slug (the `render()` input). Surfaced as
|
|
140
|
+
* `x-to11-prompt-slug` by `gatewayPromptHeaders` / `turn.headers()` so traces
|
|
141
|
+
* carry a readable name alongside the opaque `promptId` (TO11-2727).
|
|
142
|
+
*/
|
|
143
|
+
slug: string;
|
|
144
|
+
/**
|
|
145
|
+
* The served version's model config (model, temperature, max_tokens, …),
|
|
146
|
+
* passed through verbatim. Surfaced as `config` by `render({ format })`.
|
|
147
|
+
* Optional: absent when a pre-`modelConfig` API omits it.
|
|
148
|
+
*/
|
|
149
|
+
modelConfig?: unknown;
|
|
136
150
|
/**
|
|
137
151
|
* Provider-neutral tool definitions lifted from authored tool-definition
|
|
138
152
|
* blocks. Absent (rather than `[]`) when the resolved version declares no
|
|
@@ -145,7 +159,7 @@ export interface FetchedPrompt {
|
|
|
145
159
|
* into `toOpenAIToolChoice` / `toAnthropicToolChoice`.
|
|
146
160
|
*
|
|
147
161
|
* `NonNullable` because `normalizeResolvedEnvelope` maps wire-`null` to absent,
|
|
148
|
-
* so a present `
|
|
162
|
+
* so a present `RenderedPrompt.toolChoice` is never `null` — callers get the
|
|
149
163
|
* key or nothing, and never have to branch on `null`.
|
|
150
164
|
*/
|
|
151
165
|
toolChoice?: NonNullable<ResolvedPrompt["toolChoice"]>;
|
|
@@ -154,25 +168,24 @@ export type ResolvedPromptEnvelope = GenResolvedPrompt & {
|
|
|
154
168
|
/** Active release strategy. Used to decide weighted-no-subject cache bypass (D8). */
|
|
155
169
|
strategy?: "single" | "weighted";
|
|
156
170
|
};
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
* per-call because it knows the upstream it targets. Omitted ⇒ `"user"`
|
|
160
|
-
* (back-compatible; safe for any upstream). `"developer"` preserves the role
|
|
161
|
-
* (OpenAI); `"system"` folds it into a system message.
|
|
162
|
-
*/
|
|
163
|
-
export type DeveloperRole = "user" | "developer" | "system";
|
|
164
|
-
export interface FetchPromptOptions {
|
|
171
|
+
export interface RenderOptions {
|
|
172
|
+
/** Serving environment for this call; overrides the client default. */
|
|
165
173
|
env?: string;
|
|
174
|
+
/** Stable id so a weighted release sends the same caller to the same variant. */
|
|
166
175
|
subject?: string;
|
|
167
176
|
variables?: Record<string, unknown>;
|
|
177
|
+
/** Set false to bypass the LRU cache for this call. Default: true */
|
|
168
178
|
cache?: boolean;
|
|
169
|
-
|
|
179
|
+
/** Prompt served if the API is unreachable on a network error and cache is empty. */
|
|
180
|
+
fallback?: RenderedPrompt;
|
|
181
|
+
/** Provider shape for this call's output; overrides the client default. */
|
|
182
|
+
format?: RenderFormat;
|
|
170
183
|
/**
|
|
171
|
-
* How
|
|
172
|
-
*
|
|
173
|
-
*
|
|
184
|
+
* How to handle a message with an unrecognized role while shaping for a
|
|
185
|
+
* provider (`format` set). Overrides the client default; defaults to `"drop"`.
|
|
186
|
+
* Only meaningful with a `format` — the neutral result runs no converter.
|
|
174
187
|
*/
|
|
175
|
-
|
|
188
|
+
onUnknownRole?: UnknownRoleMode;
|
|
176
189
|
}
|
|
177
190
|
export type PaletteToken = ProjectPromptLabel["displayColor"];
|
|
178
191
|
export type ProjectPromptLabel = GenProjectPromptLabel;
|