@to11ai/sdk 2.0.0-rc.3 → 2.0.0-rc.5

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.
@@ -1351,9 +1351,9 @@ export declare const zApiKeysListApiKeysResponse: z.ZodObject<{
1351
1351
  image: z.ZodNullable<z.ZodString>;
1352
1352
  initials: z.ZodString;
1353
1353
  kind: z.ZodEnum<{
1354
- unknown: "unknown";
1355
1354
  api_key: "api_key";
1356
1355
  user: "user";
1356
+ unknown: "unknown";
1357
1357
  }>;
1358
1358
  name: z.ZodString;
1359
1359
  }, z.core.$strip>>;
@@ -7840,9 +7840,9 @@ export declare const zPromptsListPromptsResponse: z.ZodObject<{
7840
7840
  lastModifiedByDisplayName: z.ZodNullable<z.ZodString>;
7841
7841
  lastModifiedByImage: z.ZodNullable<z.ZodString>;
7842
7842
  lastModifiedByType: z.ZodNullable<z.ZodEnum<{
7843
- unknown: "unknown";
7844
7843
  api_key: "api_key";
7845
7844
  user: "user";
7845
+ unknown: "unknown";
7846
7846
  }>>;
7847
7847
  lastModifiedByUserId: z.ZodNullable<z.ZodString>;
7848
7848
  latestVersion: z.ZodNullable<z.ZodNumber>;
@@ -9280,6 +9280,49 @@ export declare const zCredentialLifecycleRestoreCredentialResponse: z.ZodObject<
9280
9280
  }, z.core.$strip>>>;
9281
9281
  success: z.ZodBoolean;
9282
9282
  }, z.core.$strip>;
9283
+ export declare const zProviderDisconnectDisconnectProviderBody: z.ZodObject<{
9284
+ environmentIds: z.ZodArray<z.ZodString>;
9285
+ reason: z.ZodOptional<z.ZodNullable<z.ZodString>>;
9286
+ }, z.core.$strip>;
9287
+ export declare const zProviderDisconnectDisconnectProviderPath: z.ZodObject<{
9288
+ projectId: z.ZodString;
9289
+ providerId: z.ZodString;
9290
+ }, z.core.$strip>;
9291
+ /**
9292
+ * Success
9293
+ */
9294
+ export declare const zProviderDisconnectDisconnectProviderResponse: z.ZodObject<{
9295
+ code: z.ZodNumber;
9296
+ data: z.ZodNullable<z.ZodObject<{
9297
+ closedEnvs: z.ZodArray<z.ZodObject<{
9298
+ envSlug: z.ZodString;
9299
+ environmentId: z.ZodString;
9300
+ }, z.core.$strip>>;
9301
+ providerId: z.ZodString;
9302
+ remainingActiveCount: z.ZodNumber;
9303
+ }, z.core.$strip>>;
9304
+ error: z.ZodNullable<z.ZodObject<{
9305
+ code: z.ZodString;
9306
+ details: z.ZodOptional<z.ZodNullable<z.ZodUnknown>>;
9307
+ message: z.ZodString;
9308
+ rowErrors: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodObject<{
9309
+ code: z.ZodString;
9310
+ message: z.ZodString;
9311
+ path: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
9312
+ }, z.core.$strip>>>>;
9313
+ }, z.core.$strip>>;
9314
+ pagination: z.ZodNullable<z.ZodObject<{
9315
+ limit: z.ZodInt;
9316
+ page: z.ZodInt;
9317
+ total: z.ZodInt;
9318
+ totalPages: z.ZodInt;
9319
+ }, z.core.$strip>>;
9320
+ sdkBehavior: z.ZodOptional<z.ZodNullable<z.ZodObject<{
9321
+ flags: z.ZodRecord<z.ZodString, z.ZodUnknown>;
9322
+ v: z.ZodInt;
9323
+ }, z.core.$strip>>>;
9324
+ success: z.ZodBoolean;
9325
+ }, z.core.$strip>;
9283
9326
  export declare const zCredentialAttachmentsListEligibleCredentialsPath: z.ZodObject<{
9284
9327
  projectId: z.ZodString;
9285
9328
  providerId: z.ZodString;
@@ -10027,9 +10070,9 @@ export declare const zRoutingProvidersListRoutingProvidersResponse: z.ZodObject<
10027
10070
  createdByDisplay: z.ZodNullable<z.ZodString>;
10028
10071
  createdByImage: z.ZodNullable<z.ZodString>;
10029
10072
  createdByType: z.ZodOptional<z.ZodNullable<z.ZodEnum<{
10030
- unknown: "unknown";
10031
10073
  api_key: "api_key";
10032
10074
  user: "user";
10075
+ unknown: "unknown";
10033
10076
  }>>>;
10034
10077
  currentConfigVersion: z.ZodOptional<z.ZodNullable<z.ZodInt>>;
10035
10078
  displayName: z.ZodString;
@@ -10093,9 +10136,9 @@ export declare const zRoutingProvidersListRoutingProvidersResponse: z.ZodObject<
10093
10136
  updatedByDisplay: z.ZodNullable<z.ZodString>;
10094
10137
  updatedByImage: z.ZodNullable<z.ZodString>;
10095
10138
  updatedByType: z.ZodOptional<z.ZodNullable<z.ZodEnum<{
10096
- unknown: "unknown";
10097
10139
  api_key: "api_key";
10098
10140
  user: "user";
10141
+ unknown: "unknown";
10099
10142
  }>>>;
10100
10143
  }, z.core.$strip>>>;
10101
10144
  error: z.ZodNullable<z.ZodObject<{
@@ -10168,9 +10211,9 @@ export declare const zRoutingProvidersCreateRoutingProviderResponse: z.ZodObject
10168
10211
  createdByDisplay: z.ZodNullable<z.ZodString>;
10169
10212
  createdByImage: z.ZodNullable<z.ZodString>;
10170
10213
  createdByType: z.ZodOptional<z.ZodNullable<z.ZodEnum<{
10171
- unknown: "unknown";
10172
10214
  api_key: "api_key";
10173
10215
  user: "user";
10216
+ unknown: "unknown";
10174
10217
  }>>>;
10175
10218
  currentConfigVersion: z.ZodOptional<z.ZodNullable<z.ZodInt>>;
10176
10219
  displayName: z.ZodString;
@@ -10244,9 +10287,9 @@ export declare const zRoutingProvidersCreateRoutingProviderResponse: z.ZodObject
10244
10287
  updatedByDisplay: z.ZodNullable<z.ZodString>;
10245
10288
  updatedByImage: z.ZodNullable<z.ZodString>;
10246
10289
  updatedByType: z.ZodOptional<z.ZodNullable<z.ZodEnum<{
10247
- unknown: "unknown";
10248
10290
  api_key: "api_key";
10249
10291
  user: "user";
10292
+ unknown: "unknown";
10250
10293
  }>>>;
10251
10294
  }, z.core.$strip>>;
10252
10295
  error: z.ZodNullable<z.ZodObject<{
@@ -10398,9 +10441,9 @@ export declare const zRoutingProvidersConnectRoutingProviderResponse: z.ZodObjec
10398
10441
  createdByDisplay: z.ZodNullable<z.ZodString>;
10399
10442
  createdByImage: z.ZodNullable<z.ZodString>;
10400
10443
  createdByType: z.ZodOptional<z.ZodNullable<z.ZodEnum<{
10401
- unknown: "unknown";
10402
10444
  api_key: "api_key";
10403
10445
  user: "user";
10446
+ unknown: "unknown";
10404
10447
  }>>>;
10405
10448
  currentConfigVersion: z.ZodOptional<z.ZodNullable<z.ZodInt>>;
10406
10449
  displayName: z.ZodString;
@@ -10464,9 +10507,9 @@ export declare const zRoutingProvidersConnectRoutingProviderResponse: z.ZodObjec
10464
10507
  updatedByDisplay: z.ZodNullable<z.ZodString>;
10465
10508
  updatedByImage: z.ZodNullable<z.ZodString>;
10466
10509
  updatedByType: z.ZodOptional<z.ZodNullable<z.ZodEnum<{
10467
- unknown: "unknown";
10468
10510
  api_key: "api_key";
10469
10511
  user: "user";
10512
+ unknown: "unknown";
10470
10513
  }>>>;
10471
10514
  }, z.core.$strip>;
10472
10515
  publishWarning: z.ZodOptional<z.ZodNullable<z.ZodObject<{
@@ -10730,9 +10773,9 @@ export declare const zRoutingProvidersGetRoutingProviderResponse: z.ZodObject<{
10730
10773
  createdByDisplay: z.ZodNullable<z.ZodString>;
10731
10774
  createdByImage: z.ZodNullable<z.ZodString>;
10732
10775
  createdByType: z.ZodOptional<z.ZodNullable<z.ZodEnum<{
10733
- unknown: "unknown";
10734
10776
  api_key: "api_key";
10735
10777
  user: "user";
10778
+ unknown: "unknown";
10736
10779
  }>>>;
10737
10780
  currentConfigVersion: z.ZodOptional<z.ZodNullable<z.ZodInt>>;
10738
10781
  displayName: z.ZodString;
@@ -10796,9 +10839,9 @@ export declare const zRoutingProvidersGetRoutingProviderResponse: z.ZodObject<{
10796
10839
  updatedByDisplay: z.ZodNullable<z.ZodString>;
10797
10840
  updatedByImage: z.ZodNullable<z.ZodString>;
10798
10841
  updatedByType: z.ZodOptional<z.ZodNullable<z.ZodEnum<{
10799
- unknown: "unknown";
10800
10842
  api_key: "api_key";
10801
10843
  user: "user";
10844
+ unknown: "unknown";
10802
10845
  }>>>;
10803
10846
  }, z.core.$strip>>;
10804
10847
  error: z.ZodNullable<z.ZodObject<{
@@ -10866,9 +10909,9 @@ export declare const zRoutingProvidersUpdateRoutingProviderResponse: z.ZodObject
10866
10909
  createdByDisplay: z.ZodNullable<z.ZodString>;
10867
10910
  createdByImage: z.ZodNullable<z.ZodString>;
10868
10911
  createdByType: z.ZodOptional<z.ZodNullable<z.ZodEnum<{
10869
- unknown: "unknown";
10870
10912
  api_key: "api_key";
10871
10913
  user: "user";
10914
+ unknown: "unknown";
10872
10915
  }>>>;
10873
10916
  currentConfigVersion: z.ZodOptional<z.ZodNullable<z.ZodInt>>;
10874
10917
  displayName: z.ZodString;
@@ -10942,9 +10985,9 @@ export declare const zRoutingProvidersUpdateRoutingProviderResponse: z.ZodObject
10942
10985
  updatedByDisplay: z.ZodNullable<z.ZodString>;
10943
10986
  updatedByImage: z.ZodNullable<z.ZodString>;
10944
10987
  updatedByType: z.ZodOptional<z.ZodNullable<z.ZodEnum<{
10945
- unknown: "unknown";
10946
10988
  api_key: "api_key";
10947
10989
  user: "user";
10990
+ unknown: "unknown";
10948
10991
  }>>>;
10949
10992
  }, z.core.$strip>>;
10950
10993
  error: z.ZodNullable<z.ZodObject<{
@@ -42,13 +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");
49
47
  var import_shape = require("./shape");
50
48
  var import_types = require("./types");
51
- 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 });
52
50
  function unwrap(envelope) {
53
51
  if (envelope.data === null || envelope.data === undefined) {
54
52
  throw new Error("API returned success but data is null");
@@ -128,14 +126,12 @@ function buildLabelEventsQuery(input) {
128
126
 
129
127
  class PromptResource {
130
128
  transport;
131
- cache;
132
129
  projectId;
133
130
  env;
134
131
  format;
135
132
  onUnknownRole;
136
- constructor(transport, cacheConfig, config) {
133
+ constructor(transport, config) {
137
134
  this.transport = transport;
138
- this.cache = new import_cache.PromptCache(cacheConfig);
139
135
  this.projectId = config?.projectId;
140
136
  this.env = config?.env;
141
137
  this.format = config?.format;
@@ -230,21 +226,15 @@ class PromptResource {
230
226
  if (this.projectId === undefined || this.projectId.trim() === "") {
231
227
  throw new Error("[to11ai/sdk] `prompts.render()` requires a `projectId` on the client — pass it to createClient({ projectId, ... }).");
232
228
  }
233
- const env = options.env ?? this.env;
234
- if (env === undefined) {
235
- throw import_errors.EnvNotFoundError.missing();
229
+ const label = options.label ?? this.env;
230
+ if (label === undefined) {
231
+ throw new import_errors.MissingLabelError;
236
232
  }
237
- if (!import_types.ENV_SLUG_REGEX.test(env)) {
238
- 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)}`);
239
235
  }
240
- const { subject, variables, cache: useCache = true, fallback } = options;
241
- const cacheKey = import_cache.buildRenderCacheKey(this.projectId, slug, env, subject, variables);
242
- if (useCache) {
243
- const cached = this.cache.get(cacheKey);
244
- if (cached)
245
- return structuredClone(cached);
246
- }
247
- const body = { slug, labels: [env] };
236
+ const { subject, variables, fallback } = options;
237
+ const body = { slug, labels: [label] };
248
238
  if (subject !== undefined)
249
239
  body.subject = subject;
250
240
  if (variables !== undefined)
@@ -255,15 +245,10 @@ class PromptResource {
255
245
  decode: (data) => zResolvedPromptEnvelope.parse(data)
256
246
  });
257
247
  const raw = unwrap(envelope);
258
- const result = normalizeResolvedEnvelope(raw, slug);
259
- const isWeighted = raw.strategy === "weighted" || result.variantName !== undefined;
260
- const cacheable = !(isWeighted && subject === undefined);
261
- if (useCache && cacheable) {
262
- this.cache.set(cacheKey, structuredClone(result));
263
- }
264
- return result;
248
+ return normalizeResolvedEnvelope(raw, slug);
265
249
  } catch (err) {
266
- if (err instanceof import_errors.To11aiNetworkError && fallback !== undefined) {
250
+ const transient = err instanceof import_errors.To11aiNetworkError || err instanceof import_errors.To11aiApiError && err.statusCode >= 500;
251
+ if (transient && fallback !== undefined) {
267
252
  return liftFallbackToRendered(fallback, slug);
268
253
  }
269
254
  throw err;
@@ -1,9 +1,7 @@
1
1
  import type { Transport } from "../transport";
2
- import type { CacheConfig } from "./cache";
3
2
  import type { AnthropicRenderedPrompt, OpenAiRenderedPrompt, RenderResult } from "./shape";
4
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";
5
- export type { CacheConfig } from "./cache";
6
- export type { ArchivePromptInput, ArchivePromptResult, BlockRenderRecord, 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, RenderFormat, RenderOptions, ResolvedPrompt, ResolvedPromptEnvelope, ResolvedToolCall, ResolvedToolDefinition, RowError, TextChatMessage, TextChatRole, 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";
7
5
  /**
8
6
  * Init-time config for the env-aware `render()` surface (TO11-980 / S9).
9
7
  *
@@ -26,12 +24,11 @@ export interface PromptResourceConfig {
26
24
  }
27
25
  export declare class PromptResource<F extends RenderFormat | undefined = undefined> {
28
26
  private readonly transport;
29
- private readonly cache;
30
27
  private readonly projectId;
31
28
  private readonly env;
32
29
  private readonly format;
33
30
  private readonly onUnknownRole;
34
- constructor(transport: Transport, cacheConfig?: CacheConfig, config?: Omit<PromptResourceConfig, "format"> & {
31
+ constructor(transport: Transport, config?: Omit<PromptResourceConfig, "format"> & {
35
32
  format?: F;
36
33
  });
37
34
  /**
@@ -76,17 +73,14 @@ export declare class PromptResource<F extends RenderFormat | undefined = undefin
76
73
  render(slug: string, options?: RenderOptions): Promise<RenderResult<F>>;
77
74
  /**
78
75
  * Env-aware resolution → neutral `RenderedPrompt`. Carries the resolve /
79
- * cache / offline-fallback logic; `render()` is the public shaping surface.
76
+ * offline-fallback logic; `render()` is the public shaping surface.
80
77
  *
81
- * - **env→label wire mapping:** the resolve route is label-based
78
+ * - **label wire mapping:** the resolve route is label-based
82
79
  * (`/v1/projects/:projectId/prompts:resolve`, body `labels[]`); the
83
- * resolved env slug is sent as the single resolution label.
84
- * - **No silent fallback (R4):** if no env is resolvable (none at init AND
85
- * none per call) this throws `EnvNotFoundError` CLIENT-side, eagerly,
86
- * before any transport call.
87
- * - **Cache (D8):** caches `single`-strategy releases and weighted releases
88
- * WITH a `subject`; BYPASSES the cache for weighted releases with NO
89
- * `subject` (a uniform-random assignment must not be pinned for the TTL).
80
+ * resolved label is sent as the single resolution 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.
90
84
  */
91
85
  private resolveToRendered;
92
86
  /**
@@ -1,11 +1,13 @@
1
1
  // src/prompts/resource.ts
2
- import { z } from "zod";
3
- import { EnvNotFoundError, To11aiNetworkError } from "../errors";
2
+ import {
3
+ MissingLabelError,
4
+ To11aiApiError,
5
+ To11aiNetworkError
6
+ } from "../errors";
4
7
  import { zResolvedPrompt } from "../generated/zod.gen";
5
- import { buildRenderCacheKey, PromptCache } from "./cache";
6
8
  import { shapePrompt } from "./shape";
7
9
  import { ENV_SLUG_REGEX } from "./types";
8
- var zResolvedPromptEnvelope = zResolvedPrompt.partial({ releaseId: true }).extend({ strategy: z.enum(["single", "weighted"]).optional() });
10
+ var zResolvedPromptEnvelope = zResolvedPrompt.partial({ releaseId: true });
9
11
  function unwrap(envelope) {
10
12
  if (envelope.data === null || envelope.data === undefined) {
11
13
  throw new Error("API returned success but data is null");
@@ -85,14 +87,12 @@ function buildLabelEventsQuery(input) {
85
87
 
86
88
  class PromptResource {
87
89
  transport;
88
- cache;
89
90
  projectId;
90
91
  env;
91
92
  format;
92
93
  onUnknownRole;
93
- constructor(transport, cacheConfig, config) {
94
+ constructor(transport, config) {
94
95
  this.transport = transport;
95
- this.cache = new PromptCache(cacheConfig);
96
96
  this.projectId = config?.projectId;
97
97
  this.env = config?.env;
98
98
  this.format = config?.format;
@@ -187,21 +187,15 @@ class PromptResource {
187
187
  if (this.projectId === undefined || this.projectId.trim() === "") {
188
188
  throw new Error("[to11ai/sdk] `prompts.render()` requires a `projectId` on the client — pass it to createClient({ projectId, ... }).");
189
189
  }
190
- const env = options.env ?? this.env;
191
- if (env === undefined) {
192
- throw EnvNotFoundError.missing();
190
+ const label = options.label ?? this.env;
191
+ if (label === undefined) {
192
+ throw new MissingLabelError;
193
193
  }
194
- if (!ENV_SLUG_REGEX.test(env)) {
195
- throw new Error(`[to11ai/sdk] \`env\` must match ${ENV_SLUG_REGEX} (lowercase-kebab, 1-63 chars). Received: ${JSON.stringify(env)}`);
194
+ if (!ENV_SLUG_REGEX.test(label)) {
195
+ throw new Error(`[to11ai/sdk] \`label\` must match ${ENV_SLUG_REGEX} (lowercase-kebab, 1-63 chars). Received: ${JSON.stringify(label)}`);
196
196
  }
197
- const { subject, variables, cache: useCache = true, fallback } = options;
198
- const cacheKey = buildRenderCacheKey(this.projectId, slug, env, subject, variables);
199
- if (useCache) {
200
- const cached = this.cache.get(cacheKey);
201
- if (cached)
202
- return structuredClone(cached);
203
- }
204
- const body = { slug, labels: [env] };
197
+ const { subject, variables, fallback } = options;
198
+ const body = { slug, labels: [label] };
205
199
  if (subject !== undefined)
206
200
  body.subject = subject;
207
201
  if (variables !== undefined)
@@ -212,15 +206,10 @@ class PromptResource {
212
206
  decode: (data) => zResolvedPromptEnvelope.parse(data)
213
207
  });
214
208
  const raw = unwrap(envelope);
215
- const result = normalizeResolvedEnvelope(raw, slug);
216
- const isWeighted = raw.strategy === "weighted" || result.variantName !== undefined;
217
- const cacheable = !(isWeighted && subject === undefined);
218
- if (useCache && cacheable) {
219
- this.cache.set(cacheKey, structuredClone(result));
220
- }
221
- return result;
209
+ return normalizeResolvedEnvelope(raw, slug);
222
210
  } catch (err) {
223
- if (err instanceof To11aiNetworkError && fallback !== undefined) {
211
+ const transient = err instanceof To11aiNetworkError || err instanceof To11aiApiError && err.statusCode >= 500;
212
+ if (transient && fallback !== undefined) {
224
213
  return liftFallbackToRendered(fallback, slug);
225
214
  }
226
215
  throw err;
@@ -52,5 +52,5 @@ export interface AnthropicRenderedPrompt {
52
52
  export type RenderResult<F extends RenderFormat | undefined> = F extends "openai" ? OpenAiRenderedPrompt : F extends "anthropic" ? AnthropicRenderedPrompt : RenderedPrompt;
53
53
  export declare function shapeOpenAI(prompt: RenderedPrompt, options?: ConvertMessagesOptions): OpenAiRenderedPrompt;
54
54
  export declare function shapeAnthropic(prompt: RenderedPrompt, options?: ConvertMessagesOptions): AnthropicRenderedPrompt;
55
- /** Shape a fetched prompt for `format`, or return it neutral when unset. */
55
+ /** Shape a rendered prompt for `format`, or return it neutral when unset. */
56
56
  export declare function shapePrompt(prompt: RenderedPrompt, format: RenderFormat | undefined, options?: ConvertMessagesOptions): RenderedPrompt | OpenAiRenderedPrompt | AnthropicRenderedPrompt;
@@ -9,13 +9,12 @@ export type PromptStatus = Prompt["status"];
9
9
  export type PromptVersion = GenPromptVersion;
10
10
  export type PromptFormat = PromptVersion["format"];
11
11
  export type PromptLabelPointer = GenPromptLabelPointer;
12
- export type TextChatRole = "system" | "user" | "assistant" | "developer";
13
- export interface TextChatMessage {
14
- role: TextChatRole;
12
+ export type ChatRole = "system" | "user" | "assistant" | "developer";
13
+ export interface ChatMessage {
14
+ role: ChatRole;
15
15
  content: string;
16
16
  disabled?: boolean;
17
17
  }
18
- export type ChatMessage = TextChatMessage;
19
18
  export type RenderedChatMessage = GenRenderedChatPrompt["messages"][number];
20
19
  /** Provider shape for `prompts.render()` output. Omit for the neutral result. */
21
20
  export type RenderFormat = "openai" | "anthropic";
@@ -118,6 +117,13 @@ export interface ListPromptLabelsInput {
118
117
  promptId: string;
119
118
  }
120
119
  export type ListPromptLabelsResult = PromptLabelPointer[];
120
+ /**
121
+ * Slug rule for a `render()` label — lowercase-kebab, 1-63 chars. Env slugs are
122
+ * a special case of a label value, so labels are held to the same strict rule
123
+ * (no uppercase, no underscores): a label is a routing key, and case-insensitive
124
+ * routing keys invite silent "production" vs "Production" mismatches. Intentionally
125
+ * strict — do not loosen.
126
+ */
121
127
  export declare const ENV_SLUG_REGEX: RegExp;
122
128
  export type BlockRenderRecord = Record<string, "rendered" | "dimmed">;
123
129
  export interface RenderedPrompt {
@@ -164,19 +170,17 @@ export interface RenderedPrompt {
164
170
  */
165
171
  toolChoice?: NonNullable<ResolvedPrompt["toolChoice"]>;
166
172
  }
167
- export type ResolvedPromptEnvelope = GenResolvedPrompt & {
168
- /** Active release strategy. Used to decide weighted-no-subject cache bypass (D8). */
169
- strategy?: "single" | "weighted";
170
- };
173
+ export type ResolvedPromptEnvelope = GenResolvedPrompt;
171
174
  export interface RenderOptions {
172
- /** Serving environment for this call; overrides the client default. */
173
- env?: string;
175
+ /**
176
+ * Label to resolve this call's prompt version; overrides the client default.
177
+ * When omitted, falls back to the client's `env` (env is a label value).
178
+ */
179
+ label?: string;
174
180
  /** Stable id so a weighted release sends the same caller to the same variant. */
175
181
  subject?: string;
176
182
  variables?: Record<string, unknown>;
177
- /** Set false to bypass the LRU cache for this call. Default: true */
178
- cache?: boolean;
179
- /** Prompt served if the API is unreachable on a network error and cache is empty. */
183
+ /** Prompt served if the API is unreachable on a network error. */
180
184
  fallback?: RenderedPrompt;
181
185
  /** Provider shape for this call's output; overrides the client default. */
182
186
  format?: RenderFormat;
@@ -1,11 +1,7 @@
1
1
  import type { BehaviorStore } from "./behaviors/store";
2
- export type AuthConfig = {
2
+ export interface AuthConfig {
3
3
  readonly apiKey: string;
4
- readonly getAccessToken?: never;
5
- } | {
6
- readonly getAccessToken: () => Promise<string>;
7
- readonly apiKey?: never;
8
- };
4
+ }
9
5
  export interface TransportConfig {
10
6
  readonly baseUrl: string;
11
7
  readonly auth: AuthConfig;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@to11ai/sdk",
3
- "version": "2.0.0-rc.3",
3
+ "version": "2.0.0-rc.5",
4
4
  "license": "MPL-2.0",
5
5
  "repository": {
6
6
  "type": "git",
@@ -44,14 +44,6 @@
44
44
  "require": "./dist/projectEnvironments/resource.cjs",
45
45
  "default": "./dist/projectEnvironments/resource.js"
46
46
  },
47
- "./routingRules": {
48
- "types": "./dist/routingRules/resource.d.ts",
49
- "bun": "./src/routingRules/resource.ts",
50
- "deno": "./src/routingRules/resource.ts",
51
- "import": "./dist/routingRules/resource.js",
52
- "require": "./dist/routingRules/resource.cjs",
53
- "default": "./dist/routingRules/resource.js"
54
- },
55
47
  "./errors": {
56
48
  "types": "./dist/errors.d.ts",
57
49
  "bun": "./src/errors.ts",
@@ -75,8 +67,8 @@
75
67
  "scripts": {
76
68
  "build": "bun run build:clean && bun run build:esm && bun run build:cjs && bun run build:types",
77
69
  "build:clean": "rm -rf dist",
78
- "build:esm": "bun build src/client.ts src/prompts/resource.ts src/projectEnvironments/resource.ts src/routingRules/resource.ts src/errors.ts src/gateway.ts --outdir dist --target node --format esm --external '*'",
79
- "build:cjs": "bun build src/client.ts src/prompts/resource.ts src/projectEnvironments/resource.ts src/routingRules/resource.ts src/errors.ts src/gateway.ts --outdir dist --target node --format cjs --external '*' --entry-naming '[dir]/[name].cjs'",
70
+ "build:esm": "bun build src/client.ts src/prompts/resource.ts src/projectEnvironments/resource.ts src/errors.ts src/gateway.ts --outdir dist --target node --format esm --external '*'",
71
+ "build:cjs": "bun build src/client.ts src/prompts/resource.ts src/projectEnvironments/resource.ts src/errors.ts src/gateway.ts --outdir dist --target node --format cjs --external '*' --entry-naming '[dir]/[name].cjs'",
80
72
  "build:types": "tsc -p tsconfig.build.json",
81
73
  "prepack": "bun run build",
82
74
  "codegen": "openapi-ts",
@@ -90,10 +82,12 @@
90
82
  "format": "biome format --write ."
91
83
  },
92
84
  "devDependencies": {
85
+ "@anthropic-ai/sdk": "^0.39.0",
93
86
  "@biomejs/biome": "2.4.16",
94
87
  "@hey-api/openapi-ts": "0.98.2",
95
88
  "@opentelemetry/api": "^1.9.1",
96
89
  "@types/bun": "^1.3.14",
90
+ "openai": "^4.67.0",
97
91
  "typescript": "^6.0.3"
98
92
  },
99
93
  "dependencies": {