@to11ai/sdk 1.1.0 → 2.0.0-rc.10

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.
@@ -42,22 +42,11 @@ __export(exports_resource, {
42
42
  PromptResource: () => PromptResource
43
43
  });
44
44
  module.exports = __toCommonJS(exports_resource);
45
- var import_zod = require("zod");
46
45
  var import_errors = require("../errors");
47
- var import_zod2 = require("../generated/zod.gen");
48
- var import_cache = require("./cache");
46
+ var import_zod = require("../generated/zod.gen");
47
+ var import_shape = require("./shape");
49
48
  var import_types = require("./types");
50
- var zResolvedPromptLegacy = import_zod2.zResolvedPrompt.pick({
51
- promptId: true,
52
- versionId: true,
53
- version: true,
54
- labels: true,
55
- contentHash: true,
56
- rendered: true,
57
- tools: true,
58
- toolChoice: true
59
- });
60
- var zResolvedPromptEnvelope = import_zod2.zResolvedPrompt.partial({ releaseId: true }).extend({ strategy: import_zod.z.enum(["single", "weighted"]).optional() });
49
+ var zResolvedPromptEnvelope = import_zod.zResolvedPrompt.partial({ releaseId: true });
61
50
  function unwrap(envelope) {
62
51
  if (envelope.data === null || envelope.data === undefined) {
63
52
  throw new Error("API returned success but data is null");
@@ -68,12 +57,12 @@ function getProjectPromptsPath(projectId) {
68
57
  return `/v1/projects/${encodeURIComponent(projectId)}/prompts`;
69
58
  }
70
59
  function renderedToMessages(rendered) {
71
- if (rendered.format === "chat") {
72
- return rendered.messages;
60
+ if (rendered.format !== "chat") {
61
+ throw new Error("[to11ai/sdk] Unsupported non-chat prompt format; author the prompt as chat blocks.");
73
62
  }
74
- return [{ role: "user", content: rendered.text }];
63
+ return rendered.messages;
75
64
  }
76
- function normalizeResolvedEnvelope(raw) {
65
+ function normalizeResolvedEnvelope(raw, slug) {
77
66
  const provenance = raw;
78
67
  const result = {
79
68
  messages: renderedToMessages(raw.rendered),
@@ -83,8 +72,9 @@ function normalizeResolvedEnvelope(raw) {
83
72
  promptId: raw.promptId,
84
73
  versionId: raw.versionId,
85
74
  contentHash: raw.contentHash,
86
- labels: raw.labels,
87
- rendered: raw.rendered
75
+ label: raw.label,
76
+ slug,
77
+ modelConfig: provenance.modelConfig
88
78
  };
89
79
  if (raw.tools != null && raw.tools.length > 0) {
90
80
  result.tools = raw.tools;
@@ -97,11 +87,11 @@ function normalizeResolvedEnvelope(raw) {
97
87
  }
98
88
  return result;
99
89
  }
100
- function liftFallbackToFetched(fallback) {
101
- if ("messages" in fallback) {
102
- return structuredClone(fallback);
90
+ function liftFallbackToRendered(fallback, slug) {
91
+ if (!Array.isArray(fallback.messages)) {
92
+ throw new Error("[to11ai/sdk] `fallback` must be a RenderedPrompt (as returned by render()); the legacy resolve() shape is no longer supported.");
103
93
  }
104
- return normalizeResolvedEnvelope(fallback);
94
+ return { ...structuredClone(fallback), slug: fallback.slug || slug };
105
95
  }
106
96
  function getProjectPromptPath(projectId, promptId) {
107
97
  return `${getProjectPromptsPath(projectId)}/${encodeURIComponent(promptId)}`;
@@ -136,22 +126,33 @@ function buildLabelEventsQuery(input) {
136
126
 
137
127
  class PromptResource {
138
128
  transport;
139
- cache;
140
129
  projectId;
141
130
  env;
142
- constructor(transport, cacheConfig, config) {
131
+ format;
132
+ onUnknownRole;
133
+ constructor(transport, config) {
143
134
  this.transport = transport;
144
- this.cache = new import_cache.PromptCache(cacheConfig);
145
135
  this.projectId = config?.projectId;
146
136
  this.env = config?.env;
137
+ this.format = config?.format;
138
+ this.onUnknownRole = config?.onUnknownRole;
139
+ }
140
+ resolveProjectId(perCall) {
141
+ const projectId = perCall ?? this.projectId;
142
+ if (projectId === undefined || projectId.trim() === "") {
143
+ throw new Error("[to11ai/sdk] this call needs a `projectId` — pass it on the call or bind one via createClient({ projectId, ... }).");
144
+ }
145
+ return projectId.trim();
147
146
  }
148
147
  async create(input) {
149
- const { projectId, ...body } = input;
148
+ const { projectId: perCallProjectId, ...body } = input;
149
+ const projectId = this.resolveProjectId(perCallProjectId);
150
150
  const envelope = await this.transport.request("POST", getProjectPromptsPath(projectId), { body });
151
151
  return unwrap(envelope);
152
152
  }
153
- async list(input) {
154
- const { projectId, ...queryRest } = input;
153
+ async list(input = {}) {
154
+ const { projectId: perCallProjectId, ...queryRest } = input;
155
+ const projectId = this.resolveProjectId(perCallProjectId);
155
156
  const envelope = await this.transport.request("GET", getProjectPromptsPath(projectId), {
156
157
  query: {
157
158
  ...queryRest
@@ -168,146 +169,111 @@ class PromptResource {
168
169
  return { items, pagination };
169
170
  }
170
171
  async get(input) {
171
- const { projectId, promptId } = input;
172
+ const { projectId: perCallProjectId, promptId } = input;
173
+ const projectId = this.resolveProjectId(perCallProjectId);
172
174
  const envelope = await this.transport.request("GET", getProjectPromptPath(projectId, promptId));
173
175
  return unwrap(envelope);
174
176
  }
175
177
  async update(input) {
176
- const { projectId, promptId, ...body } = input;
178
+ const { projectId: perCallProjectId, promptId, ...body } = input;
179
+ const projectId = this.resolveProjectId(perCallProjectId);
177
180
  const envelope = await this.transport.request("PATCH", getProjectPromptPath(projectId, promptId), { body });
178
181
  return unwrap(envelope);
179
182
  }
180
183
  async archive(input) {
181
- const { projectId, promptId } = input;
184
+ const { projectId: perCallProjectId, promptId } = input;
185
+ const projectId = this.resolveProjectId(perCallProjectId);
182
186
  const envelope = await this.transport.request("DELETE", getProjectPromptPath(projectId, promptId));
183
187
  return unwrap(envelope);
184
188
  }
185
189
  async createVersion(input) {
186
- const { projectId, promptId, ...body } = input;
190
+ const { projectId: perCallProjectId, promptId, ...body } = input;
191
+ const projectId = this.resolveProjectId(perCallProjectId);
187
192
  const envelope = await this.transport.request("POST", `${getProjectPromptPath(projectId, promptId)}/versions`, { body });
188
193
  return unwrap(envelope);
189
194
  }
190
195
  async listVersions(input) {
191
- const { projectId, promptId } = input;
196
+ const { projectId: perCallProjectId, promptId } = input;
197
+ const projectId = this.resolveProjectId(perCallProjectId);
192
198
  const envelope = await this.transport.request("GET", `${getProjectPromptPath(projectId, promptId)}/versions`);
193
199
  return unwrap(envelope);
194
200
  }
195
201
  async getVersion(input) {
196
- const { projectId, promptId, versionNumber } = input;
202
+ const { projectId: perCallProjectId, promptId, versionNumber } = input;
203
+ const projectId = this.resolveProjectId(perCallProjectId);
197
204
  const envelope = await this.transport.request("GET", `${getProjectPromptPath(projectId, promptId)}/versions/${encodeURIComponent(String(versionNumber))}`);
198
205
  return unwrap(envelope);
199
206
  }
200
207
  async moveLabel(input) {
201
- const { projectId, promptId, label, ...body } = input;
208
+ const { projectId: perCallProjectId, promptId, label, ...body } = input;
209
+ const projectId = this.resolveProjectId(perCallProjectId);
202
210
  const envelope = await this.transport.request("PUT", `${getProjectPromptPath(projectId, promptId)}/labels/${encodeURIComponent(label)}`, { body });
203
211
  return unwrap(envelope);
204
212
  }
205
213
  async listLabels(input) {
206
- const { projectId, promptId } = input;
214
+ const { projectId: perCallProjectId, promptId } = input;
215
+ const projectId = this.resolveProjectId(perCallProjectId);
207
216
  const envelope = await this.transport.request("GET", `${getProjectPromptPath(projectId, promptId)}/labels`);
208
217
  return unwrap(envelope);
209
218
  }
210
- async fetch(slug, options = {}) {
219
+ async render(slug, options = {}) {
220
+ const rendered = await this.resolveToRendered(slug, options);
221
+ return import_shape.shapePrompt(rendered, options.format ?? this.format, {
222
+ onUnknownRole: options.onUnknownRole ?? this.onUnknownRole
223
+ });
224
+ }
225
+ async resolveToRendered(slug, options = {}) {
211
226
  if (this.projectId === undefined || this.projectId.trim() === "") {
212
- throw new Error("[to11ai/sdk] `prompts.fetch()` requires a `projectId` on the client — pass it to createClient({ projectId, ... }).");
227
+ throw new Error("[to11ai/sdk] `prompts.render()` requires a `projectId` on the client — pass it to createClient({ projectId, ... }).");
213
228
  }
214
- const env = options.env ?? this.env;
215
- if (env === undefined) {
216
- throw import_errors.EnvNotFoundError.missing();
229
+ const label = options.label ?? this.env;
230
+ if (label === undefined) {
231
+ throw new import_errors.MissingLabelError;
217
232
  }
218
- if (!import_types.ENV_SLUG_REGEX.test(env)) {
219
- throw new Error(`[to11ai/sdk] \`env\` must match ${import_types.ENV_SLUG_REGEX} (lowercase-kebab, 1-63 chars). Received: ${JSON.stringify(env)}`);
233
+ if (!import_types.ENV_SLUG_REGEX.test(label)) {
234
+ throw new Error(`[to11ai/sdk] \`label\` must match ${import_types.ENV_SLUG_REGEX} (lowercase-kebab, 1-63 chars). Received: ${JSON.stringify(label)}`);
220
235
  }
221
- const {
222
- subject,
223
- variables,
224
- cache: useCache = true,
225
- fallback,
226
- developerRole
227
- } = options;
228
- const cacheKey = import_cache.buildFetchCacheKey(this.projectId, slug, env, subject, variables, developerRole);
229
- if (useCache) {
230
- const cached = this.cache.get(cacheKey);
231
- if (cached && "messages" in cached)
232
- return structuredClone(cached);
233
- }
234
- const body = { slug, labels: [env] };
235
- if (subject !== undefined)
236
- body.subject = subject;
236
+ const { variables, fallback } = options;
237
+ const body = {};
237
238
  if (variables !== undefined)
238
239
  body.variables = variables;
239
- if (developerRole !== undefined)
240
- body.developerRole = developerRole;
241
240
  try {
242
- const envelope = await this.transport.request("POST", `${getProjectPromptsPath(this.projectId)}:resolve`, {
241
+ const envelope = await this.transport.request("POST", `${getProjectPromptsPath(this.projectId)}/by-slug/${encodeURIComponent(slug)}/labels/${encodeURIComponent(label)}/render`, {
243
242
  body,
244
243
  decode: (data) => zResolvedPromptEnvelope.parse(data)
245
244
  });
246
245
  const raw = unwrap(envelope);
247
- const result = normalizeResolvedEnvelope(raw);
248
- const isWeighted = raw.strategy === "weighted" || result.variantName !== undefined;
249
- const cacheable = !(isWeighted && subject === undefined);
250
- if (useCache && cacheable) {
251
- this.cache.set(cacheKey, structuredClone(result));
252
- }
253
- return result;
254
- } catch (err) {
255
- if (err instanceof import_errors.To11aiNetworkError && fallback !== undefined) {
256
- return liftFallbackToFetched(fallback);
257
- }
258
- throw err;
259
- }
260
- }
261
- async resolve(input) {
262
- const {
263
- projectId,
264
- slug,
265
- labels,
266
- variables,
267
- cache: useCache = true,
268
- fallback
269
- } = input;
270
- const cacheKey = import_cache.buildCacheKey(projectId, slug, labels, variables);
271
- if (useCache) {
272
- const cached = this.cache.get(cacheKey);
273
- if (cached && !("messages" in cached))
274
- return structuredClone(cached);
275
- }
276
- try {
277
- const envelope = await this.transport.request("POST", `${getProjectPromptsPath(projectId)}:resolve`, {
278
- body: { slug, labels, variables },
279
- decode: (data) => zResolvedPromptLegacy.parse(data)
280
- });
281
- const result = unwrap(envelope);
282
- if (useCache) {
283
- this.cache.set(cacheKey, structuredClone(result));
284
- }
285
- return result;
246
+ return normalizeResolvedEnvelope(raw, slug);
286
247
  } catch (err) {
287
- if (err instanceof import_errors.To11aiNetworkError && fallback !== undefined) {
288
- return fallback;
248
+ const transient = err instanceof import_errors.To11aiNetworkError || err instanceof import_errors.To11aiApiError && err.statusCode >= 500;
249
+ if (transient && fallback !== undefined) {
250
+ return liftFallbackToRendered(fallback, slug);
289
251
  }
290
252
  throw err;
291
253
  }
292
254
  }
293
- async listProjectLabels(input) {
294
- const { projectId, includeArchived } = input;
255
+ async listProjectLabels(input = {}) {
256
+ const { projectId: perCallProjectId, includeArchived } = input;
257
+ const projectId = this.resolveProjectId(perCallProjectId);
295
258
  const envelope = await this.transport.request("GET", getProjectPromptLabelsPath(projectId), {
296
259
  query: includeArchived ? { includeArchived: "true" } : undefined
297
260
  });
298
261
  return unwrap(envelope);
299
262
  }
300
263
  async createProjectLabel(input) {
301
- const { projectId, ...body } = input;
264
+ const { projectId: perCallProjectId, ...body } = input;
265
+ const projectId = this.resolveProjectId(perCallProjectId);
302
266
  const envelope = await this.transport.request("POST", getProjectPromptLabelsPath(projectId), { body });
303
267
  return unwrap(envelope);
304
268
  }
305
269
  async getProjectLabel(input) {
306
- const envelope = await this.transport.request("GET", getProjectPromptLabelPath(input.projectId, input.label));
270
+ const projectId = this.resolveProjectId(input.projectId);
271
+ const envelope = await this.transport.request("GET", getProjectPromptLabelPath(projectId, input.label));
307
272
  return unwrap(envelope);
308
273
  }
309
274
  async updateProjectLabel(input) {
310
- const { projectId, label, ...rest } = input;
275
+ const { projectId: perCallProjectId, label, ...rest } = input;
276
+ const projectId = this.resolveProjectId(perCallProjectId);
311
277
  const body = {};
312
278
  if (rest.isDefault !== undefined)
313
279
  body.isDefault = rest.isDefault;
@@ -319,15 +285,16 @@ class PromptResource {
319
285
  return unwrap(envelope);
320
286
  }
321
287
  async deleteProjectLabel(input) {
322
- const envelope = await this.transport.request("DELETE", getProjectPromptLabelPath(input.projectId, input.label));
288
+ const projectId = this.resolveProjectId(input.projectId);
289
+ const envelope = await this.transport.request("DELETE", getProjectPromptLabelPath(projectId, input.label));
323
290
  return unwrap(envelope);
324
291
  }
325
292
  async listProjectLabelUsages(input) {
326
- const envelope = await this.transport.request("GET", `${getProjectPromptLabelPath(input.projectId, input.label)}/usages`);
293
+ const envelope = await this.transport.request("GET", `${getProjectPromptLabelPath(this.resolveProjectId(input.projectId), input.label)}/usages`);
327
294
  return unwrap(envelope);
328
295
  }
329
296
  async listLabelEvents(input) {
330
- const projectSeg = encodeURIComponent(input.projectId);
297
+ const projectSeg = encodeURIComponent(this.resolveProjectId(input.projectId));
331
298
  let path;
332
299
  switch (input.scope) {
333
300
  case "label":
@@ -1,29 +1,45 @@
1
1
  import type { Transport } from "../transport";
2
- import type { CacheConfig } from "./cache";
3
- import type { ArchivePromptInput, ArchivePromptResult, CreateProjectPromptLabelInput, CreateProjectPromptLabelResult, CreatePromptInput, CreatePromptResult, CreatePromptVersionInput, CreatePromptVersionResult, DeleteProjectPromptLabelInput, DeleteProjectPromptLabelResult, FetchedPrompt, FetchPromptOptions, 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
- export type { CacheConfig } from "./cache";
5
- export type { ArchivePromptInput, ArchivePromptResult, BlockRenderRecord, ChatMessage, CreateProjectPromptLabelInput, CreateProjectPromptLabelResult, CreatePromptInput, CreatePromptResult, CreatePromptVersionInput, CreatePromptVersionResult, DeleteProjectPromptLabelInput, DeleteProjectPromptLabelResult, FetchedPrompt, FetchPromptOptions, 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, ResolvedPromptEnvelope, ResolvedToolCall, ResolvedToolDefinition, ResolvePromptInput, ResolvePromptResult, RowError, TextChatMessage, TextChatRole, UpdateProjectPromptLabelInput, UpdateProjectPromptLabelResult, UpdatePromptInput, UpdatePromptResult, } from "./types";
2
+ import type { AnthropicRenderedPrompt, OpenAiRenderedPrompt, RenderResult } from "./shape";
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, RenderFormat, RenderOptions, UnknownRoleMode, UpdateProjectPromptLabelInput, UpdateProjectPromptLabelResult, UpdatePromptInput, UpdatePromptResult } from "./types";
4
+ export type { ArchivePromptInput, ArchivePromptResult, BlockRenderRecord, ChatMessage, ChatRole, 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, RenderFormat, RenderOptions, ResolvedPrompt, ResolvedPromptEnvelope, ResolvedToolCall, ResolvedToolDefinition, RowError, UnknownRoleMode, UpdateProjectPromptLabelInput, UpdateProjectPromptLabelResult, UpdatePromptInput, UpdatePromptResult, } from "./types";
6
5
  /**
7
- * Init-time config for the env-aware `fetch()` surface (TO11-980 / S9).
6
+ * Init-time config for the env-aware `render()` surface (TO11-980 / S9).
8
7
  *
9
8
  * `projectId` and `env` come from `createClient`. `projectId` is required for
10
- * `fetch()` (it builds the project-scoped resolve path); `env` is the default
11
- * serving environment inherited by every `fetch(slug)` call.
9
+ * `render()` (it builds the project-scoped resolve path); `env` is the default
10
+ * serving environment inherited by every `render(slug)` call.
12
11
  */
13
12
  export interface PromptResourceConfig {
14
- /** Project the client is bound to. Required for `fetch()`; validated at createClient. */
13
+ /** Project the client is bound to. Required for `render()`; validated at createClient. */
15
14
  projectId?: string;
16
- /** Default serving env for `fetch()`. Validated against ENV_SLUG_REGEX at createClient. */
15
+ /** Default serving env for `render()`. Validated against ENV_SLUG_REGEX at createClient. */
17
16
  env?: string;
17
+ /** Default provider shape for `render()` output. Per-call override allowed. */
18
+ format?: RenderFormat;
19
+ /**
20
+ * Default unknown-role policy for `render({ format })` output conversion.
21
+ * Per-call override allowed; defaults to `"drop"`.
22
+ */
23
+ onUnknownRole?: UnknownRoleMode;
18
24
  }
19
- export declare class PromptResource {
25
+ export declare class PromptResource<F extends RenderFormat | undefined = undefined> {
20
26
  private readonly transport;
21
- private readonly cache;
22
27
  private readonly projectId;
23
28
  private readonly env;
24
- constructor(transport: Transport, cacheConfig?: CacheConfig, config?: PromptResourceConfig);
29
+ private readonly format;
30
+ private readonly onUnknownRole;
31
+ constructor(transport: Transport, config?: Omit<PromptResourceConfig, "format"> & {
32
+ format?: F;
33
+ });
34
+ /**
35
+ * Resolve the project for a control-plane call: the per-call `projectId`
36
+ * wins, else the client-bound one from `createClient({ projectId })`. Throws
37
+ * if neither is set. Mirrors how `render()` resolves its project, so every
38
+ * method honors the bound `projectId` and callers need not repeat it.
39
+ */
40
+ private resolveProjectId;
25
41
  create(input: CreatePromptInput): Promise<CreatePromptResult>;
26
- list(input: ListPromptsInput): Promise<PaginatedResult<ListPromptsResult>>;
42
+ list(input?: ListPromptsInput): Promise<PaginatedResult<ListPromptsResult>>;
27
43
  get(input: GetPromptInput): Promise<GetPromptResult>;
28
44
  update(input: UpdatePromptInput): Promise<UpdatePromptResult>;
29
45
  archive(input: ArchivePromptInput): Promise<ArchivePromptResult>;
@@ -33,35 +49,40 @@ export declare class PromptResource {
33
49
  moveLabel(input: MovePromptLabelInput): Promise<MovePromptLabelResult>;
34
50
  listLabels(input: ListPromptLabelsInput): Promise<ListPromptLabelsResult>;
35
51
  /**
36
- * Resolve a prompt for the client's configured `projectId` + `env`
37
- * (Style-A). The ergonomic slug-first surface: env is configured once at
38
- * `createClient` and inherited here, with an optional per-call override.
39
- *
40
- * - **env→label wire mapping (correction #3):** the resolve route is
41
- * label-based (`/v1/projects/:projectId/prompts:resolve`, body
42
- * `labels[]`); it does NOT accept a top-level `env` field. The resolved
43
- * env slug (lowercase-kebab — a valid label name) is therefore sent as
44
- * the single resolution label: body `{ slug, labels: [env], subject?,
45
- * variables? }`.
46
- * - **No silent fallback (R4):** if no env is resolvable (none at init AND
47
- * none per call) this throws `EnvNotFoundError` (`reason.source =
48
- * "missing"`) CLIENT-side, eagerly, before any transport call.
49
- * - **Cache (D8):** caches `single`-strategy releases and weighted releases
50
- * WITH a `subject`; BYPASSES the cache for weighted releases with NO
51
- * `subject` (a uniform-random assignment must not be pinned for the TTL).
52
+ * Resolve and (optionally) shape a prompt for the client's configured
53
+ * `projectId` + `env`, in one control-plane request. With a `format` (per
54
+ * call or inherited from the client) the result is provider-shaped
55
+ * `{ messages, config, metadata }`; without one it is the neutral
56
+ * `RenderedPrompt`. Resolves by the client's configured `env`.
52
57
  *
53
- * Prefer this over the deprecated `resolve()`.
58
+ * @example Render an OpenAI-shaped prompt and send it through the gateway
59
+ * const prompt = await to11.prompts.render("weather-concierge", {
60
+ * variables: { city: "NYC" },
61
+ * });
62
+ * const res = await openai.chat.completions.create(
63
+ * { ...prompt.config, messages: prompt.messages },
64
+ * { headers: to11.turn().headers(prompt) },
65
+ * );
54
66
  */
55
- fetch(slug: string, options?: FetchPromptOptions): Promise<FetchedPrompt>;
67
+ render(slug: string, options: RenderOptions & {
68
+ format: "openai";
69
+ }): Promise<OpenAiRenderedPrompt>;
70
+ render(slug: string, options: RenderOptions & {
71
+ format: "anthropic";
72
+ }): Promise<AnthropicRenderedPrompt>;
73
+ render(slug: string, options?: RenderOptions): Promise<RenderResult<F>>;
56
74
  /**
57
- * @deprecated Use {@link PromptResource.fetch | `prompts.fetch(slug,
58
- * options?)`} instead. `resolve()` is env-agnostic (no `env` / `subject`,
59
- * no enriched release/variant provenance, no typed-env errors)
60
- * and is retained only for back-compat. It is NOT subject to the R4
61
- * no-silent-fallback env gate (it has no env concept). New code should
62
- * configure `projectId` + `env` at `createClient` and call `fetch()`.
75
+ * Env-aware resolution → neutral `RenderedPrompt`. Carries the resolve /
76
+ * offline-fallback logic; `render()` is the public shaping surface.
77
+ *
78
+ * - **wire mapping (TO11-2743):** posts to the path-addressed render route
79
+ * (`/v1/projects/:projectId/prompts/by-slug/:slug/labels/:label/render`),
80
+ * body `{ variables? }`. The resolved label is the single path label.
81
+ * - **No silent fallback (R4):** if no label is resolvable (none per call
82
+ * AND no client `env` fallback) this throws `MissingLabelError`
83
+ * CLIENT-side, eagerly, before any transport call.
63
84
  */
64
- resolve(input: ResolvePromptInput): Promise<ResolvePromptResult>;
85
+ private resolveToRendered;
65
86
  /**
66
87
  * List the project-level label registry.
67
88
  *
@@ -69,7 +90,7 @@ export declare class PromptResource {
69
90
  * include rows with a non-null `archivedAt` (useful for admin / history
70
91
  * affordances). Gated on `prompt:read` server-side.
71
92
  */
72
- listProjectLabels(input: ListProjectPromptLabelsInput): Promise<ListProjectPromptLabelsResult>;
93
+ listProjectLabels(input?: ListProjectPromptLabelsInput): Promise<ListProjectPromptLabelsResult>;
73
94
  /**
74
95
  * Create a new project label.
75
96
  *