@to11ai/sdk 0.1.1 → 0.2.0

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.
Files changed (42) hide show
  1. package/dist/behaviors/store.d.ts +62 -0
  2. package/dist/client.cjs +37 -4
  3. package/dist/client.d.ts +41 -2
  4. package/dist/client.js +45 -4
  5. package/dist/errors.cjs +90 -1
  6. package/dist/errors.d.ts +142 -0
  7. package/dist/errors.js +90 -1
  8. package/dist/gateway.cjs +12 -0
  9. package/dist/gateway.d.ts +26 -12
  10. package/dist/gateway.js +14 -0
  11. package/dist/generated/index.d.ts +1 -0
  12. package/dist/generated/types.gen.d.ts +22974 -0
  13. package/dist/generated/zod.gen.d.ts +13531 -0
  14. package/dist/projectEnvironments/resource.cjs +7 -2
  15. package/dist/projectEnvironments/resource.js +7 -2
  16. package/dist/projectEnvironments/types.d.ts +4 -75
  17. package/dist/prompts/cache.d.ts +24 -3
  18. package/dist/prompts/resource.cjs +101 -3
  19. package/dist/prompts/resource.d.ts +47 -3
  20. package/dist/prompts/resource.js +103 -5
  21. package/dist/prompts/types.d.ts +36 -177
  22. package/dist/routingRules/resource.cjs +9 -2
  23. package/dist/routingRules/resource.js +9 -2
  24. package/dist/routingRules/types.d.ts +12 -123
  25. package/dist/transport.d.ts +23 -0
  26. package/package.json +23 -12
  27. package/src/behaviors/store.ts +175 -0
  28. package/src/client.ts +115 -3
  29. package/src/errors.ts +261 -0
  30. package/src/gateway.ts +54 -12
  31. package/src/generated/index.ts +3 -0
  32. package/src/generated/types.gen.ts +24083 -0
  33. package/src/generated/zod.gen.ts +12648 -0
  34. package/src/projectEnvironments/resource.ts +10 -0
  35. package/src/projectEnvironments/types.ts +9 -91
  36. package/src/prompts/cache.ts +39 -4
  37. package/src/prompts/resource.ts +258 -5
  38. package/src/prompts/types.ts +56 -237
  39. package/src/routingRules/resource.ts +10 -1
  40. package/src/routingRules/types.ts +21 -155
  41. package/src/traceparent.ts +69 -4
  42. package/src/transport.ts +188 -3
@@ -1,67 +1,20 @@
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
- */
1
+ import type { ProjectPromptLabel as GenProjectPromptLabel, ProjectPromptLabelUsage as GenProjectPromptLabelUsage, Prompt as GenPrompt, PromptLabelEvent as GenPromptLabelEvent, PromptLabelPointer as GenPromptLabelPointer, PromptVersion as GenPromptVersion, RenderedChatPrompt as GenRenderedChatPrompt, RenderedPrompt as GenRenderedPrompt, ResolvedPrompt as GenResolvedPrompt } from "../generated/types.gen";
25
2
  export interface RowError {
26
3
  path: ReadonlyArray<string | number>;
27
4
  code: string;
28
5
  message: string;
29
6
  }
30
- export type PromptStatus = "active" | "archived";
31
- export type PromptFormat = "text" | "chat";
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
- */
7
+ export type Prompt = GenPrompt;
8
+ export type PromptStatus = Prompt["status"];
9
+ export type PromptVersion = GenPromptVersion;
10
+ export type PromptFormat = PromptVersion["format"];
11
+ export type PromptLabelPointer = GenPromptLabelPointer;
40
12
  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
13
  export interface TextChatMessage {
49
14
  role: TextChatRole;
50
15
  content: string;
51
16
  disabled?: boolean;
52
17
  }
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
18
  export interface ToolChatMessage {
66
19
  role: "tool";
67
20
  name: string;
@@ -69,73 +22,10 @@ export interface ToolChatMessage {
69
22
  parameters: unknown;
70
23
  disabled?: boolean;
71
24
  }
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
25
  export type ChatMessage = TextChatMessage | ToolChatMessage;
81
- export interface Prompt {
82
- id: string;
83
- projectId: string;
84
- name: string;
85
- slug: string;
86
- description: string | null;
87
- tags: string[];
88
- status: PromptStatus;
89
- createdByUserId: string;
90
- createdAt: string;
91
- updatedAt: string;
92
- }
93
- export interface PromptVersion {
94
- id: string;
95
- promptId: string;
96
- version: number;
97
- format: PromptFormat;
98
- templateJson: unknown;
99
- variablesSchema: unknown;
100
- modelConfig: unknown;
101
- changelog: string | null;
102
- createdByUserId: string;
103
- createdAt: string;
104
- }
105
- export interface PromptLabelPointer {
106
- promptId: string;
107
- label: string;
108
- versionId: string;
109
- updatedByUserId: string;
110
- updatedAt: string;
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
- }
124
- export type RenderedPrompt = {
125
- format: "text";
126
- text: string;
127
- } | {
128
- format: "chat";
129
- messages: RenderedChatMessage[];
130
- };
131
- export interface ResolvedPrompt {
132
- promptId: string;
133
- versionId: string;
134
- version: number;
135
- labels: string[];
136
- contentHash: string;
137
- rendered: RenderedPrompt;
138
- }
26
+ export type RenderedChatMessage = GenRenderedChatPrompt["messages"][number];
27
+ export type RenderedPrompt = GenRenderedPrompt;
28
+ export type ResolvedPrompt = Pick<GenResolvedPrompt, "promptId" | "versionId" | "version" | "labels" | "contentHash" | "rendered">;
139
29
  export interface PaginationInfo {
140
30
  page: number;
141
31
  limit: number;
@@ -226,62 +116,37 @@ export interface ResolvePromptInput {
226
116
  fallback?: ResolvedPrompt;
227
117
  }
228
118
  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 {
119
+ export declare const ENV_SLUG_REGEX: RegExp;
120
+ export type BlockRenderRecord = Record<string, "rendered" | "dimmed">;
121
+ export type PromptContext = Record<string, string | number | boolean>;
122
+ export interface FetchedPrompt {
123
+ messages: RenderedChatMessage[];
124
+ version: number;
125
+ releaseId: string | null;
126
+ variantName?: string;
127
+ blockRenderRecord: BlockRenderRecord;
260
128
  promptId: string;
261
- promptSlug: string;
262
- promptName: string;
263
129
  versionId: string;
264
- version: number;
265
- updatedAt: string;
266
- updatedByUserId: string;
130
+ contentHash: string;
131
+ labels: string[];
132
+ rendered: RenderedPrompt;
267
133
  }
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;
134
+ export type ResolvedPromptEnvelope = GenResolvedPrompt & {
135
+ /** Active release strategy. Used to decide weighted-no-subject cache bypass (D8). */
136
+ strategy?: "single" | "weighted";
137
+ };
138
+ export interface FetchPromptOptions {
139
+ env?: string;
140
+ context?: PromptContext;
141
+ subject?: string;
142
+ variables?: Record<string, unknown>;
143
+ cache?: boolean;
144
+ fallback?: ResolvedPrompt | FetchedPrompt;
284
145
  }
146
+ export type PaletteToken = ProjectPromptLabel["displayColor"];
147
+ export type ProjectPromptLabel = GenProjectPromptLabel;
148
+ export type ProjectPromptLabelUsage = GenProjectPromptLabelUsage;
149
+ export type PromptLabelEvent = GenPromptLabelEvent;
285
150
  export interface ListProjectPromptLabelsInput {
286
151
  projectId: string;
287
152
  /** Set true to include archived (soft-deleted) entries. Default: false. */
@@ -313,12 +178,6 @@ export interface DeleteProjectPromptLabelInput {
313
178
  projectId: string;
314
179
  label: string;
315
180
  }
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
181
  export type DeleteProjectPromptLabelResult = ProjectPromptLabel;
323
182
  export interface ListProjectPromptLabelUsagesInput {
324
183
  projectId: string;
@@ -44,6 +44,8 @@ __export(exports_resource, {
44
44
  RoutingRuleReleaseResource: () => RoutingRuleReleaseResource
45
45
  });
46
46
  module.exports = __toCommonJS(exports_resource);
47
+ var import_zod = require("zod");
48
+ var import_zod2 = require("../generated/zod.gen");
47
49
  function unwrap(envelope) {
48
50
  if (envelope.data === null || envelope.data === undefined) {
49
51
  throw new Error("API returned success but data is null");
@@ -89,7 +91,9 @@ class RoutingRuleVersionResource {
89
91
  return unwrap(envelope);
90
92
  }
91
93
  async get(input) {
92
- const envelope = await this.transport.request("GET", versionPath(input.projectId, input.ruleId, input.versionId));
94
+ const envelope = await this.transport.request("GET", versionPath(input.projectId, input.ruleId, input.versionId), {
95
+ decode: (data) => import_zod2.zRuleVersion.parse(data)
96
+ });
93
97
  return unwrap(envelope);
94
98
  }
95
99
  }
@@ -116,7 +120,10 @@ class RoutingRuleReleaseResource {
116
120
  if (input.limit !== undefined)
117
121
  query.limit = input.limit;
118
122
  const path = input.envSlug !== undefined ? releasePath(input.projectId, input.ruleId, input.envSlug) : releasesPath(input.projectId, input.ruleId);
119
- const envelope = await this.transport.request("GET", path, { query });
123
+ const envelope = await this.transport.request("GET", path, {
124
+ query,
125
+ decode: (data) => import_zod.z.array(import_zod2.zRuleRelease).parse(data)
126
+ });
120
127
  return unwrap(envelope);
121
128
  }
122
129
  }
@@ -1,4 +1,6 @@
1
1
  // src/routingRules/resource.ts
2
+ import { z } from "zod";
3
+ import { zRuleRelease, zRuleVersion } from "../generated/zod.gen";
2
4
  function unwrap(envelope) {
3
5
  if (envelope.data === null || envelope.data === undefined) {
4
6
  throw new Error("API returned success but data is null");
@@ -44,7 +46,9 @@ class RoutingRuleVersionResource {
44
46
  return unwrap(envelope);
45
47
  }
46
48
  async get(input) {
47
- const envelope = await this.transport.request("GET", versionPath(input.projectId, input.ruleId, input.versionId));
49
+ const envelope = await this.transport.request("GET", versionPath(input.projectId, input.ruleId, input.versionId), {
50
+ decode: (data) => zRuleVersion.parse(data)
51
+ });
48
52
  return unwrap(envelope);
49
53
  }
50
54
  }
@@ -71,7 +75,10 @@ class RoutingRuleReleaseResource {
71
75
  if (input.limit !== undefined)
72
76
  query.limit = input.limit;
73
77
  const path = input.envSlug !== undefined ? releasePath(input.projectId, input.ruleId, input.envSlug) : releasesPath(input.projectId, input.ruleId);
74
- const envelope = await this.transport.request("GET", path, { query });
78
+ const envelope = await this.transport.request("GET", path, {
79
+ query,
80
+ decode: (data) => z.array(zRuleRelease).parse(data)
81
+ });
75
82
  return unwrap(envelope);
76
83
  }
77
84
  }
@@ -1,88 +1,9 @@
1
- /**
2
- * Reference to a provider config bound to a specific environment. Mirrors
3
- * `RuleProviderRef` in the API domain model. `envSlug` is optional — when
4
- * omitted, the gateway falls back to the project's `is_gateway_fallback`
5
- * environment.
6
- */
7
- export interface RuleProviderRef {
8
- providerId: string;
9
- envSlug?: string;
10
- }
11
- /**
12
- * Per-variant model binding inside a rule snapshot. Identifies which
13
- * `(provider, model)` pair serves a strategy variant; the gateway resolves
14
- * the actual credential at request time. `weight` is intentionally
15
- * permissive (0..100 in v1) so weighted/experimental strategies can evolve
16
- * without a SDK churn.
17
- */
18
- export interface RuleModelBinding {
19
- modelId: string;
20
- provider: RuleProviderRef;
21
- weight?: number;
22
- }
23
- export type RuleStrategy = "single" | "weighted" | "fallback" | "experiment";
24
- /**
25
- * Frozen rule snapshot — the JSONB payload stored in
26
- * `rule_versions.snapshot_json`. Mirrors the API domain `RuleSnapshot`:
27
- *
28
- * * `alias` — optional `function::<alias>` indirection (S1).
29
- * * `strategy` — `single`, `weighted`, `fallback`, `experiment`.
30
- * * `endpoint` — `chat`, `embeddings`, …
31
- * * `variants[]` | `steps[]` | `chain[]` — strategy-shape arrays.
32
- * * `when` — optional condition AST that gates the rule.
33
- * * `retry` — optional `{ maxRetries?, backoffBaseMs?, retryableStatusCodes? }`.
34
- * * `modelBindings[]` — which `(providerId, modelId, envSlug)` serves each variant.
35
- * * `providerRefs[]` — flat denormalized list of referenced providers.
36
- *
37
- * No credential field exists; the gateway resolves credentials lazily from
38
- * the per-env `routing_snapshots` ciphertext.
39
- */
40
- export interface RuleSnapshot {
41
- alias?: string;
42
- strategy: RuleStrategy | string;
43
- endpoint: string;
44
- variants?: unknown[];
45
- steps?: unknown[];
46
- chain?: unknown[];
47
- when?: unknown;
48
- retry?: {
49
- maxRetries?: number;
50
- backoffBaseMs?: number;
51
- retryableStatusCodes?: number[];
52
- };
53
- modelBindings?: RuleModelBinding[];
54
- providerRefs?: RuleProviderRef[];
55
- }
56
- /**
57
- * The persisted form of a rule version row as returned by
58
- * `GET /v1/projects/:projectId/routing/rules/:ruleId/versions/:versionId`.
59
- *
60
- * `version` is monotonic per `ruleId` — the server allocates it inside a
61
- * `SELECT MAX … FOR UPDATE` transaction. `snapshotJson` is typed as
62
- * `unknown` to mirror the API contract (the storage path persists JSONB
63
- * verbatim); callers that need the typed shape should cast through
64
- * `RuleSnapshot`.
65
- */
66
- export interface RuleVersion {
67
- id: string;
68
- ruleId: string;
69
- version: number;
70
- snapshotJson: unknown;
71
- description: string | null;
72
- createdBy: string;
73
- /** ISO-8601 timestamp. */
74
- createdAt: string;
75
- }
76
- /**
77
- * Wire input accepted by
78
- * `POST /v1/projects/:p/routing/rules/:ruleId/versions`. Requires the
79
- * `routing:write` capability.
80
- *
81
- * `snapshot` is the cleartext snapshot JSON the gateway uses to resolve
82
- * runtime traffic — stored verbatim in `rule_versions.snapshot_json`.
83
- * `description` is an optional commit message; the API surfaces it on the
84
- * audit timeline.
85
- */
1
+ import type { RuleModelBinding as GenRuleModelBinding, RuleProviderRef as GenRuleProviderRef, RuleRelease as GenRuleRelease, RuleReleaseWeight as GenRuleReleaseWeight, RuleSnapshot as GenRuleSnapshot, RuleVersion as GenRuleVersion } from "../generated/types.gen";
2
+ export type RuleProviderRef = GenRuleProviderRef;
3
+ export type RuleModelBinding = GenRuleModelBinding;
4
+ export type RuleStrategy = GenRuleSnapshot["strategy"];
5
+ export type RuleSnapshot = GenRuleSnapshot;
6
+ export type RuleVersion = GenRuleVersion;
86
7
  export interface CreateRuleVersionInput {
87
8
  projectId: string;
88
9
  ruleId: string;
@@ -90,22 +11,10 @@ export interface CreateRuleVersionInput {
90
11
  description?: string;
91
12
  }
92
13
  export type CreateRuleVersionResult = RuleVersion;
93
- /**
94
- * Cursor-paginated list input. `cursor` is the `version` number BELOW which
95
- * to fetch (keyset pagination — pass the last item's `version` to continue).
96
- * `limit` is clamped server-side to `MAX_LIST_LIMIT` (200 at the time of
97
- * writing); default is 50.
98
- */
99
14
  export interface ListRuleVersionsInput {
100
15
  projectId: string;
101
16
  ruleId: string;
102
- /**
103
- * The `version` number BELOW which to fetch (the route uses a keyset
104
- * `WHERE version < cursor` clause and returns versions in `version DESC`
105
- * order). Omit for the first page.
106
- */
107
17
  cursor?: number;
108
- /** Page size. Server clamps to `[1, MAX_LIST_LIMIT]`. */
109
18
  limit?: number;
110
19
  }
111
20
  export type ListRuleVersionsResult = RuleVersion[];
@@ -115,32 +24,12 @@ export interface GetRuleVersionInput {
115
24
  versionId: string;
116
25
  }
117
26
  export type GetRuleVersionResult = RuleVersion;
118
- export type RuleReleaseStrategy = "single" | "weighted";
119
- export type RuleReleaseChangeKind = "release_initial" | "release_promoted" | "release_rolled_back" | "release_weight_changed";
120
- export type RuleReleaseApprovalStatus = "committed" | "pending" | "rejected";
121
- export type RuleReleaseActorType = "user" | "api_key" | "worker";
122
- export interface RuleReleaseWeight {
123
- versionId: string;
124
- weight: number;
125
- }
126
- export interface RuleRelease {
127
- id: string;
128
- ruleId: string;
129
- environmentId: string;
130
- envSlug: string;
131
- strategy: RuleReleaseStrategy;
132
- versionId: string | null;
133
- weights: RuleReleaseWeight[] | null;
134
- changeKind: RuleReleaseChangeKind;
135
- priorReleaseId: string | null;
136
- actorId: string;
137
- actorType: RuleReleaseActorType;
138
- reason: string | null;
139
- approvalStatus: RuleReleaseApprovalStatus;
140
- activeFrom: string | null;
141
- activeTo: string | null;
142
- createdAt: string;
143
- }
27
+ export type RuleReleaseStrategy = GenRuleRelease["strategy"];
28
+ export type RuleReleaseChangeKind = GenRuleRelease["changeKind"];
29
+ export type RuleReleaseApprovalStatus = GenRuleRelease["approvalStatus"];
30
+ export type RuleReleaseActorType = GenRuleRelease["actorType"];
31
+ export type RuleReleaseWeight = GenRuleReleaseWeight;
32
+ export type RuleRelease = GenRuleRelease;
144
33
  export interface SetRuleReleaseInput {
145
34
  projectId: string;
146
35
  ruleId: string;
@@ -1,3 +1,4 @@
1
+ import type { BehaviorStore } from "./behaviors/store";
1
2
  export type AuthConfig = {
2
3
  readonly apiKey: string;
3
4
  readonly getAccessToken?: never;
@@ -17,6 +18,12 @@ export interface TransportConfig {
17
18
  * attempt. Default: 3
18
19
  */
19
20
  readonly maxRetries?: number;
21
+ /**
22
+ * Optional behavior store updated from each successful response's
23
+ * `sdkBehavior` field (TO11-2100). When omitted, server-delivered behavior
24
+ * values are simply not captured.
25
+ */
26
+ readonly behaviorStore?: BehaviorStore;
20
27
  }
21
28
  /** Standard API envelope returned by the to11ai server. */
22
29
  export interface ApiEnvelope<T = unknown> {
@@ -34,16 +41,32 @@ export interface ApiEnvelope<T = unknown> {
34
41
  readonly total: number;
35
42
  readonly totalPages: number;
36
43
  } | null;
44
+ /**
45
+ * Optional, additively-versioned server-evaluated SDK-behavior values
46
+ * (TO11-2100). Present only when the server has behavior flags to deliver;
47
+ * an unknown `v` is ignored by the SDK. See `behaviors/store.ts`.
48
+ */
49
+ readonly sdkBehavior?: {
50
+ readonly v: number;
51
+ readonly flags: Record<string, unknown>;
52
+ };
37
53
  }
38
54
  export declare class Transport {
39
55
  private readonly baseUrl;
40
56
  private readonly auth;
41
57
  private readonly timeoutMs;
42
58
  private readonly maxRetries;
59
+ private readonly behaviorStore;
43
60
  constructor(config: TransportConfig);
44
61
  private buildHeaders;
45
62
  request<T>(method: string, path: string, options?: {
46
63
  query?: Record<string, string | number | boolean | undefined>;
47
64
  body?: unknown;
65
+ /**
66
+ * Runtime validator for the envelope `data` on a 2xx response. When
67
+ * supplied, the decoded value replaces `data`; a thrown decoder error
68
+ * surfaces as `To11aiResponseValidationError`.
69
+ */
70
+ decode?: (data: unknown) => T;
48
71
  }): Promise<ApiEnvelope<T>>;
49
72
  }
package/package.json CHANGED
@@ -1,11 +1,16 @@
1
1
  {
2
2
  "name": "@to11ai/sdk",
3
- "version": "0.1.1",
3
+ "version": "0.2.0",
4
4
  "license": "MPL-2.0",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "git+https://github.com/to11ai/platform.git",
8
+ "directory": "packages/js-sdk"
9
+ },
5
10
  "type": "module",
6
11
  "main": "./dist/client.cjs",
7
12
  "module": "./dist/client.js",
8
- "types": "./src/client.ts",
13
+ "types": "./dist/client.d.ts",
9
14
  "files": [
10
15
  "dist",
11
16
  "src",
@@ -16,7 +21,7 @@
16
21
  ],
17
22
  "exports": {
18
23
  ".": {
19
- "types": "./src/client.ts",
24
+ "types": "./dist/client.d.ts",
20
25
  "bun": "./src/client.ts",
21
26
  "deno": "./src/client.ts",
22
27
  "import": "./dist/client.js",
@@ -24,7 +29,7 @@
24
29
  "default": "./dist/client.js"
25
30
  },
26
31
  "./prompts": {
27
- "types": "./src/prompts/resource.ts",
32
+ "types": "./dist/prompts/resource.d.ts",
28
33
  "bun": "./src/prompts/resource.ts",
29
34
  "deno": "./src/prompts/resource.ts",
30
35
  "import": "./dist/prompts/resource.js",
@@ -32,7 +37,7 @@
32
37
  "default": "./dist/prompts/resource.js"
33
38
  },
34
39
  "./projectEnvironments": {
35
- "types": "./src/projectEnvironments/resource.ts",
40
+ "types": "./dist/projectEnvironments/resource.d.ts",
36
41
  "bun": "./src/projectEnvironments/resource.ts",
37
42
  "deno": "./src/projectEnvironments/resource.ts",
38
43
  "import": "./dist/projectEnvironments/resource.js",
@@ -40,7 +45,7 @@
40
45
  "default": "./dist/projectEnvironments/resource.js"
41
46
  },
42
47
  "./routingRules": {
43
- "types": "./src/routingRules/resource.ts",
48
+ "types": "./dist/routingRules/resource.d.ts",
44
49
  "bun": "./src/routingRules/resource.ts",
45
50
  "deno": "./src/routingRules/resource.ts",
46
51
  "import": "./dist/routingRules/resource.js",
@@ -48,7 +53,7 @@
48
53
  "default": "./dist/routingRules/resource.js"
49
54
  },
50
55
  "./errors": {
51
- "types": "./src/errors.ts",
56
+ "types": "./dist/errors.d.ts",
52
57
  "bun": "./src/errors.ts",
53
58
  "deno": "./src/errors.ts",
54
59
  "import": "./dist/errors.js",
@@ -56,7 +61,7 @@
56
61
  "default": "./dist/errors.js"
57
62
  },
58
63
  "./gateway": {
59
- "types": "./src/gateway.ts",
64
+ "types": "./dist/gateway.d.ts",
60
65
  "bun": "./src/gateway.ts",
61
66
  "deno": "./src/gateway.ts",
62
67
  "import": "./dist/gateway.js",
@@ -74,6 +79,8 @@
74
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'",
75
80
  "build:types": "tsc -p tsconfig.build.json",
76
81
  "prepack": "bun run build",
82
+ "codegen": "openapi-ts",
83
+ "codegen:check": "bun run codegen && git diff --exit-code -- src/generated && test -z \"$(git ls-files --others --exclude-standard -- src/generated)\"",
77
84
  "test": "bun test",
78
85
  "test:coverage": "bun test --coverage --coverage-reporter=text --coverage-reporter=lcov",
79
86
  "typecheck": "bun x tsc --noEmit",
@@ -83,9 +90,13 @@
83
90
  "format": "biome format --write ."
84
91
  },
85
92
  "devDependencies": {
86
- "@biomejs/biome": "2.4.15",
87
- "@opentelemetry/api": "^1.9.0",
88
- "@types/bun": "^1.3.13",
89
- "typescript": "^5.9.3"
93
+ "@biomejs/biome": "2.4.16",
94
+ "@hey-api/openapi-ts": "0.98.2",
95
+ "@opentelemetry/api": "^1.9.1",
96
+ "@types/bun": "^1.3.14",
97
+ "typescript": "^6.0.3"
98
+ },
99
+ "dependencies": {
100
+ "zod": "4.4.3"
90
101
  }
91
102
  }