@runtypelabs/sdk 9.12.0 → 9.14.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.
package/dist/index.mjs CHANGED
@@ -2053,6 +2053,310 @@ data: ${JSON.stringify({
2053
2053
  });
2054
2054
  }
2055
2055
 
2056
+ // src/agent-aliases-namespace.ts
2057
+ var LIVE_AGENT_ALIAS = "live";
2058
+ var AgentAliasRevisionMismatchError = class extends Error {
2059
+ constructor(body) {
2060
+ super(
2061
+ body.error ?? `Alias revision mismatch: expected ${body.expected}, found ${body.actual ?? "no alias"}.`
2062
+ );
2063
+ this.code = "alias_revision_mismatch";
2064
+ this.name = "AgentAliasRevisionMismatchError";
2065
+ this.expectedRevision = body.expected;
2066
+ this.actualRevision = body.actual;
2067
+ }
2068
+ };
2069
+ var AgentAliasRevisionRequiredError = class extends Error {
2070
+ constructor(message) {
2071
+ super(message);
2072
+ this.code = "alias_revision_required";
2073
+ this.name = "AgentAliasRevisionRequiredError";
2074
+ }
2075
+ };
2076
+ var AgentAliasNotFoundError = class extends Error {
2077
+ constructor(body) {
2078
+ super(body.error ?? `Alias "${body.alias}" was not found on agent ${body.agentId}.`);
2079
+ this.code = "alias_not_found";
2080
+ this.name = "AgentAliasNotFoundError";
2081
+ this.alias = body.alias;
2082
+ this.agentId = body.agentId;
2083
+ }
2084
+ };
2085
+ var AgentAliasPreviewLimitError = class extends Error {
2086
+ constructor(body) {
2087
+ super(
2088
+ body.error ?? `This ${body.scope} already has ${body.limit} active preview aliases, the maximum.`
2089
+ );
2090
+ this.code = "PREVIEW_ALIAS_LIMIT";
2091
+ this.name = "AgentAliasPreviewLimitError";
2092
+ this.scope = body.scope;
2093
+ this.limit = body.limit;
2094
+ this.active = body.active;
2095
+ }
2096
+ };
2097
+ var AgentAliasDependencyError = class extends Error {
2098
+ constructor(body) {
2099
+ super(body.error ?? "The version references a dependency that no longer resolves.");
2100
+ this.code = "alias_dependency_unresolved";
2101
+ this.name = "AgentAliasDependencyError";
2102
+ this.refs = body.refs ?? [];
2103
+ }
2104
+ };
2105
+ function asRecord(value) {
2106
+ return value !== null && typeof value === "object" && !Array.isArray(value) ? value : null;
2107
+ }
2108
+ function parseRequestError(err) {
2109
+ if (!(err instanceof Error)) return { status: null, body: null };
2110
+ const structured = err;
2111
+ if (typeof structured.statusCode === "number") {
2112
+ return { status: structured.statusCode, body: asRecord(structured.data) };
2113
+ }
2114
+ const match = err.message.match(/^API request failed: (\d{3}) .*? - ([\s\S]*)$/);
2115
+ if (!match) return { status: null, body: null };
2116
+ try {
2117
+ return { status: Number(match[1]), body: asRecord(JSON.parse(match[2])) };
2118
+ } catch {
2119
+ return { status: Number(match[1]), body: null };
2120
+ }
2121
+ }
2122
+ function asString(value, fallback) {
2123
+ return typeof value === "string" ? value : fallback;
2124
+ }
2125
+ function toAliasError(err, agentId, alias) {
2126
+ const { status, body } = parseRequestError(err);
2127
+ if (status === null) return null;
2128
+ const error = body && typeof body.error === "string" ? body.error : void 0;
2129
+ if (status === 412 && body && typeof body.expected === "number") {
2130
+ return new AgentAliasRevisionMismatchError({
2131
+ ...error !== void 0 ? { error } : {},
2132
+ expected: body.expected,
2133
+ actual: typeof body.actual === "number" ? body.actual : null
2134
+ });
2135
+ }
2136
+ if (status === 428) {
2137
+ return new AgentAliasRevisionRequiredError(
2138
+ error ?? "Updating an existing live alias requires an If-Match revision."
2139
+ );
2140
+ }
2141
+ if (status === 404 && body?.code === "alias_not_found") {
2142
+ return new AgentAliasNotFoundError({
2143
+ ...error !== void 0 ? { error } : {},
2144
+ alias: asString(body.alias, alias),
2145
+ agentId: asString(body.agentId, agentId)
2146
+ });
2147
+ }
2148
+ if (status === 429 && body?.code === "PREVIEW_ALIAS_LIMIT") {
2149
+ return new AgentAliasPreviewLimitError({
2150
+ ...error !== void 0 ? { error } : {},
2151
+ scope: body.scope === "organization" ? "organization" : "agent",
2152
+ limit: typeof body.limit === "number" ? body.limit : 0,
2153
+ active: typeof body.active === "number" ? body.active : 0
2154
+ });
2155
+ }
2156
+ if (status === 422 && body?.code === "alias_dependency_unresolved") {
2157
+ return new AgentAliasDependencyError({
2158
+ ...error !== void 0 ? { error } : {},
2159
+ refs: Array.isArray(body.refs) ? body.refs.filter((ref) => typeof ref === "string") : []
2160
+ });
2161
+ }
2162
+ return null;
2163
+ }
2164
+ var TYPED_ALIAS_ERRORS = [
2165
+ AgentAliasRevisionMismatchError,
2166
+ AgentAliasRevisionRequiredError,
2167
+ AgentAliasNotFoundError,
2168
+ AgentAliasDependencyError,
2169
+ AgentAliasPreviewLimitError
2170
+ ];
2171
+ function agentAliasErrorCode(err) {
2172
+ return TYPED_ALIAS_ERRORS.some((typed) => err instanceof typed) ? err.code : void 0;
2173
+ }
2174
+ function writeHeaders(input) {
2175
+ const headers = {};
2176
+ if (typeof input.revision === "number") headers["If-Match"] = String(input.revision);
2177
+ if (input.idempotencyKey) headers["Idempotency-Key"] = input.idempotencyKey;
2178
+ return headers;
2179
+ }
2180
+ function encode(value) {
2181
+ return encodeURIComponent(value);
2182
+ }
2183
+ var AgentAliasesNamespace = class {
2184
+ constructor(getTransport) {
2185
+ this.getTransport = getTransport;
2186
+ }
2187
+ /** List this agent's pointers, `live` first then previews by name. */
2188
+ async list(agentId, options = {}) {
2189
+ return this.getTransport().get(`/agents/${encode(agentId)}/aliases`, {
2190
+ ...options.includeArchived ? { includeArchived: "true" } : {},
2191
+ ...options.limit !== void 0 ? { limit: String(options.limit) } : {},
2192
+ ...options.cursor ? { cursor: options.cursor } : {}
2193
+ });
2194
+ }
2195
+ /**
2196
+ * Every agent in the organization carrying a pointer with this name, each
2197
+ * with the revision to quote back as `If-Match`. The read a PR-close cleanup
2198
+ * makes before archiving.
2199
+ */
2200
+ async listByName(alias, options = {}) {
2201
+ return this.getTransport().get("/agent-aliases", {
2202
+ alias,
2203
+ ...options.includeArchived ? { includeArchived: "true" } : {}
2204
+ });
2205
+ }
2206
+ /**
2207
+ * Archive this pointer on every agent in the organization that carries it,
2208
+ * each under the revision just read. A failure on one agent is reported and
2209
+ * the rest continue; a second run finds nothing active and archives nothing.
2210
+ */
2211
+ async archiveEverywhere(alias) {
2212
+ const listed = await this.listByName(alias);
2213
+ const rows = listed.data ?? [];
2214
+ const result = { alias, archived: [], failed: [] };
2215
+ for (const row of rows) {
2216
+ try {
2217
+ const archived = await this.archive(row.agentId, alias, { revision: row.revision });
2218
+ result.archived.push({
2219
+ agentId: row.agentId,
2220
+ agentName: row.agentName,
2221
+ revision: archived.revision,
2222
+ receiptId: archived.receiptId
2223
+ });
2224
+ } catch (err) {
2225
+ const code = agentAliasErrorCode(err);
2226
+ result.failed.push({
2227
+ agentId: row.agentId,
2228
+ agentName: row.agentName,
2229
+ error: err instanceof Error ? err.message : String(err),
2230
+ ...code ? { code } : {}
2231
+ });
2232
+ }
2233
+ }
2234
+ return result;
2235
+ }
2236
+ /** Read one pointer. A missing or archived alias throws, never falls back to live. */
2237
+ async get(agentId, alias, options = {}) {
2238
+ return this.run(
2239
+ agentId,
2240
+ alias,
2241
+ () => this.getTransport().get(`/agents/${encode(agentId)}/aliases/${encode(alias)}`, {
2242
+ ...options.includeArchived ? { includeArchived: "true" } : {}
2243
+ })
2244
+ );
2245
+ }
2246
+ /** Aim one pointer at one exact version, appending a deployment receipt. */
2247
+ async activate(agentId, alias, input) {
2248
+ const body = {
2249
+ versionId: input.versionId,
2250
+ ...input.reason ? { reason: input.reason } : {},
2251
+ ...input.promotion ? { promotion: input.promotion } : {}
2252
+ };
2253
+ return this.run(
2254
+ agentId,
2255
+ alias,
2256
+ () => this.getTransport().put(
2257
+ `/agents/${encode(agentId)}/aliases/${encode(alias)}`,
2258
+ body,
2259
+ writeHeaders(input)
2260
+ )
2261
+ );
2262
+ }
2263
+ /** Archive a preview pointer: it stops resolving but keeps its history. */
2264
+ async archive(agentId, alias, input = {}) {
2265
+ return this.run(
2266
+ agentId,
2267
+ alias,
2268
+ () => this.getTransport().delete(
2269
+ `/agents/${encode(agentId)}/aliases/${encode(alias)}`,
2270
+ void 0,
2271
+ writeHeaders(input)
2272
+ )
2273
+ );
2274
+ }
2275
+ /** Re-aim a pointer at the version its receipt history records before this one. */
2276
+ async rollback(agentId, alias, input = {}) {
2277
+ const body = {
2278
+ ...input.steps !== void 0 ? { steps: input.steps } : {},
2279
+ ...input.reason ? { reason: input.reason } : {}
2280
+ };
2281
+ return this.run(
2282
+ agentId,
2283
+ alias,
2284
+ () => this.getTransport().post(
2285
+ `/agents/${encode(agentId)}/aliases/${encode(alias)}/rollback`,
2286
+ body,
2287
+ writeHeaders(input)
2288
+ )
2289
+ );
2290
+ }
2291
+ /** The per-alias secret binding NAMES this pointer carries. Values are write-only. */
2292
+ async getBindings(agentId, alias) {
2293
+ return this.run(
2294
+ agentId,
2295
+ alias,
2296
+ () => this.getTransport().get(
2297
+ `/agents/${encode(agentId)}/aliases/${encode(alias)}/bindings`
2298
+ )
2299
+ );
2300
+ }
2301
+ /**
2302
+ * Replace the complete set of `{{secret:NAME}}` values executions resolve
2303
+ * when they reach this agent through this pointer, ahead of the organization
2304
+ * secret of the same name. A name you stop sending stops resolving.
2305
+ */
2306
+ async setBindings(agentId, alias, input) {
2307
+ const body = {
2308
+ bindings: input.bindings,
2309
+ ...input.reason ? { reason: input.reason } : {}
2310
+ };
2311
+ return this.run(
2312
+ agentId,
2313
+ alias,
2314
+ () => this.getTransport().put(
2315
+ `/agents/${encode(agentId)}/aliases/${encode(alias)}/bindings`,
2316
+ body,
2317
+ writeHeaders(input)
2318
+ )
2319
+ );
2320
+ }
2321
+ /** Drop every binding, so this pointer's executions fall back to organization secrets. */
2322
+ async clearBindings(agentId, alias, input = {}) {
2323
+ return this.run(
2324
+ agentId,
2325
+ alias,
2326
+ () => this.getTransport().delete(
2327
+ `/agents/${encode(agentId)}/aliases/${encode(alias)}/bindings`,
2328
+ void 0,
2329
+ writeHeaders(input)
2330
+ )
2331
+ );
2332
+ }
2333
+ async run(agentId, alias, call) {
2334
+ try {
2335
+ return await call();
2336
+ } catch (err) {
2337
+ const typed = toAliasError(err, agentId, alias);
2338
+ if (typed) throw typed;
2339
+ throw err;
2340
+ }
2341
+ }
2342
+ };
2343
+ var AgentDeploymentsNamespace = class {
2344
+ constructor(getTransport) {
2345
+ this.getTransport = getTransport;
2346
+ }
2347
+ /** Receipts newest first, cursor-paginated; filter to one pointer with `alias`. */
2348
+ async list(agentId, options = {}) {
2349
+ return this.getTransport().get(
2350
+ `/agents/${encode(agentId)}/deployments`,
2351
+ {
2352
+ ...options.alias ? { alias: options.alias } : {},
2353
+ ...options.limit !== void 0 ? { limit: String(options.limit) } : {},
2354
+ ...options.cursor ? { cursor: options.cursor } : {}
2355
+ }
2356
+ );
2357
+ }
2358
+ };
2359
+
2056
2360
  // src/generated-tool-gate.ts
2057
2361
  var TOOL_NAME_PATTERN = /^[A-Za-z][A-Za-z0-9_]{1,63}$/;
2058
2362
  var DEFAULT_MAX_CODE_LENGTH = 12e3;
@@ -2075,7 +2379,7 @@ var DEFAULT_ALLOWED_LANGUAGES = [
2075
2379
  function isObject(value) {
2076
2380
  return typeof value === "object" && value !== null && !Array.isArray(value);
2077
2381
  }
2078
- function asString(value) {
2382
+ function asString2(value) {
2079
2383
  return typeof value === "string" ? value.trim() : void 0;
2080
2384
  }
2081
2385
  function asNumber(value) {
@@ -2108,8 +2412,8 @@ function normalizeGeneratedProposal(proposal, violations) {
2108
2412
  violations.push("Generated tool proposal must be an object");
2109
2413
  return null;
2110
2414
  }
2111
- const name = asString(candidate.name);
2112
- const description = asString(candidate.description);
2415
+ const name = asString2(candidate.name);
2416
+ const description = asString2(candidate.description);
2113
2417
  const toolType = candidate.toolType;
2114
2418
  const parametersSchema = candidate.parametersSchema;
2115
2419
  if (!name) {
@@ -2144,7 +2448,7 @@ function normalizeGeneratedProposal(proposal, violations) {
2144
2448
  violations.push("Custom tool config is required");
2145
2449
  return null;
2146
2450
  }
2147
- const code = asString(config.code);
2451
+ const code = asString2(config.code);
2148
2452
  if (!code) {
2149
2453
  violations.push("Custom tool config.code is required");
2150
2454
  return null;
@@ -5621,6 +5925,8 @@ var _AgentsEndpoint = class _AgentsEndpoint {
5621
5925
  constructor(client) {
5622
5926
  this.client = client;
5623
5927
  this.TOOL_OUTPUT_INLINE_THRESHOLD = 500;
5928
+ this.aliases = new AgentAliasesNamespace(() => this.client);
5929
+ this.deployments = new AgentDeploymentsNamespace(() => this.client);
5624
5930
  }
5625
5931
  /**
5626
5932
  * List all agents for the authenticated user
@@ -9681,7 +9987,7 @@ var FlowDriftError = class extends Error {
9681
9987
  this.plan = plan;
9682
9988
  }
9683
9989
  };
9684
- function parseRequestError(err) {
9990
+ function parseRequestError2(err) {
9685
9991
  if (!(err instanceof Error)) return { status: null, body: null };
9686
9992
  const match = err.message.match(/^API request failed: (\d{3}) .*? - ([\s\S]*)$/);
9687
9993
  if (!match) return { status: null, body: null };
@@ -9692,7 +9998,7 @@ function parseRequestError(err) {
9692
9998
  }
9693
9999
  }
9694
10000
  function toConflictError(err) {
9695
- const { status, body } = parseRequestError(err);
10001
+ const { status, body } = parseRequestError2(err);
9696
10002
  if (status !== 409 || !isPlainObject(body)) return null;
9697
10003
  const code = body.code;
9698
10004
  if (code !== "external_modification" && code !== "remote_changed") return null;
@@ -11497,7 +11803,7 @@ var SkillDriftError = class extends Error {
11497
11803
  this.plan = plan;
11498
11804
  }
11499
11805
  };
11500
- function parseRequestError2(err) {
11806
+ function parseRequestError3(err) {
11501
11807
  if (!(err instanceof Error)) return { status: null, body: null };
11502
11808
  const match = err.message.match(/^API request failed: (\d{3}) .*? - ([\s\S]*)$/);
11503
11809
  if (!match) return { status: null, body: null };
@@ -11508,7 +11814,7 @@ function parseRequestError2(err) {
11508
11814
  }
11509
11815
  }
11510
11816
  function toConflictError2(err) {
11511
- const { status, body } = parseRequestError2(err);
11817
+ const { status, body } = parseRequestError3(err);
11512
11818
  if (status !== 409 || !isPlainObject(body)) return null;
11513
11819
  const code = body.code;
11514
11820
  if (code !== "external_modification" && code !== "remote_changed") return null;
@@ -11817,6 +12123,7 @@ var SkillsNamespace = class {
11817
12123
  };
11818
12124
 
11819
12125
  // src/agents-namespace.ts
12126
+ var ENSURE_RELEASE_DEPLOY_CONFLICT_MESSAGE = 'Provide either release or deploy, not both. release is a compatibility input; use deploy: { alias: "live" } instead of release: "publish", and omit both to save without activating.';
11820
12127
  var AGENT_CONFIG_KEYS = [
11821
12128
  "contextManagement",
11822
12129
  "model",
@@ -11976,7 +12283,7 @@ var AgentDriftError = class extends Error {
11976
12283
  this.plan = plan;
11977
12284
  }
11978
12285
  };
11979
- function parseRequestError3(err) {
12286
+ function parseRequestError4(err) {
11980
12287
  if (!(err instanceof Error)) return { status: null, body: null };
11981
12288
  const match = err.message.match(/^API request failed: (\d{3}) .*? - ([\s\S]*)$/);
11982
12289
  if (!match) return { status: null, body: null };
@@ -11987,7 +12294,7 @@ function parseRequestError3(err) {
11987
12294
  }
11988
12295
  }
11989
12296
  function toConflictError3(err) {
11990
- const { status, body } = parseRequestError3(err);
12297
+ const { status, body } = parseRequestError4(err);
11991
12298
  if (status !== 409 || !isPlainObject2(body)) return null;
11992
12299
  const code = body.code;
11993
12300
  if (code !== "external_modification" && code !== "remote_changed") return null;
@@ -12007,6 +12314,9 @@ function memoFor4(client) {
12007
12314
  var AgentsNamespace = class {
12008
12315
  constructor(getClient) {
12009
12316
  this.getClient = getClient;
12317
+ const transport = () => this.getClient();
12318
+ this.aliases = new AgentAliasesNamespace(transport);
12319
+ this.deployments = new AgentDeploymentsNamespace(transport);
12010
12320
  }
12011
12321
  /**
12012
12322
  * Idempotently converge a definition onto the platform. Hash-first: probes
@@ -12016,10 +12326,14 @@ var AgentsNamespace = class {
12016
12326
  */
12017
12327
  async ensure(definition, options = {}) {
12018
12328
  const client = this.getClient();
12019
- const { dryRun, onConflict, release, expectedRemoteHash, version, expectNoChanges } = options;
12329
+ const { dryRun, onConflict, release, deploy, expectedRemoteHash, version, expectNoChanges } = options;
12330
+ if (release !== void 0 && deploy !== void 0) {
12331
+ throw new Error(ENSURE_RELEASE_DEPLOY_CONFLICT_MESSAGE);
12332
+ }
12020
12333
  const passthrough = {
12021
12334
  ...onConflict ? { onConflict } : {},
12022
12335
  ...release ? { release } : {},
12336
+ ...deploy ? { deploy } : {},
12023
12337
  ...expectedRemoteHash ? { expectedRemoteHash } : {},
12024
12338
  ...version ? { version } : {}
12025
12339
  };
@@ -12184,7 +12498,7 @@ var ToolDriftError = class extends Error {
12184
12498
  this.plan = plan;
12185
12499
  }
12186
12500
  };
12187
- function parseRequestError4(err) {
12501
+ function parseRequestError5(err) {
12188
12502
  if (!(err instanceof Error)) return { status: null, body: null };
12189
12503
  const match = err.message.match(/^API request failed: (\d{3}) .*? - ([\s\S]*)$/);
12190
12504
  if (!match) return { status: null, body: null };
@@ -12195,7 +12509,7 @@ function parseRequestError4(err) {
12195
12509
  }
12196
12510
  }
12197
12511
  function toConflictError4(err) {
12198
- const { status, body } = parseRequestError4(err);
12512
+ const { status, body } = parseRequestError5(err);
12199
12513
  if (status !== 409 || !isPlainObject(body)) return null;
12200
12514
  const code = body.code;
12201
12515
  if (code !== "external_modification" && code !== "remote_changed") return null;
@@ -12376,7 +12690,7 @@ var ProductDriftError = class extends Error {
12376
12690
  this.plan = plan;
12377
12691
  }
12378
12692
  };
12379
- function parseRequestError5(err) {
12693
+ function parseRequestError6(err) {
12380
12694
  if (!(err instanceof Error)) return { status: null, body: null };
12381
12695
  const match = err.message.match(/^API request failed: (\d{3}) .*? - ([\s\S]*)$/);
12382
12696
  if (!match) return { status: null, body: null };
@@ -12387,7 +12701,7 @@ function parseRequestError5(err) {
12387
12701
  }
12388
12702
  }
12389
12703
  function toConflictError5(err) {
12390
- const { status, body } = parseRequestError5(err);
12704
+ const { status, body } = parseRequestError6(err);
12391
12705
  if (status !== 409 || !isPlainObject(body)) return null;
12392
12706
  const code = body.code;
12393
12707
  if (code !== "external_modification" && code !== "remote_changed") return null;
@@ -12586,6 +12900,25 @@ var ProductsNamespace = class {
12586
12900
  async pullFpo(name) {
12587
12901
  return pullFpo(this.getClient(), name);
12588
12902
  }
12903
+ /**
12904
+ * One request for the first page of every activity source a product has:
12905
+ * conversations per conversational surface, executions per distinct agent.
12906
+ * Rows, cursors and `hasMore` match the per-source list endpoints, so a
12907
+ * caller continues any source with that source's own endpoint. A source that
12908
+ * fails carries an `error` instead of failing the response.
12909
+ *
12910
+ * @example
12911
+ * ```typescript
12912
+ * const { data } = await Runtype.products.activity('prd_123', { limit: 25 })
12913
+ * for (const surface of data.surfaces) console.log(surface.surfaceId, surface.data.length)
12914
+ * ```
12915
+ */
12916
+ async activity(productId, options = {}) {
12917
+ return this.getClient().get(
12918
+ `/products/${encodeURIComponent(productId)}/activity`,
12919
+ options.limit === void 0 ? void 0 : { limit: String(options.limit) }
12920
+ );
12921
+ }
12589
12922
  };
12590
12923
 
12591
12924
  // src/surfaces-ensure.ts
@@ -12686,7 +13019,7 @@ var SurfaceDriftError = class extends Error {
12686
13019
  this.plan = plan;
12687
13020
  }
12688
13021
  };
12689
- function parseRequestError6(err) {
13022
+ function parseRequestError7(err) {
12690
13023
  if (!(err instanceof Error)) return { status: null, body: null };
12691
13024
  const match = err.message.match(/^API request failed: (\d{3}) .*? - ([\s\S]*)$/);
12692
13025
  if (!match) return { status: null, body: null };
@@ -12697,7 +13030,7 @@ function parseRequestError6(err) {
12697
13030
  }
12698
13031
  }
12699
13032
  function toConflictError6(err) {
12700
- const { status, body } = parseRequestError6(err);
13033
+ const { status, body } = parseRequestError7(err);
12701
13034
  if (status !== 409 || !isPlainObject(body)) return null;
12702
13035
  const code = body.code;
12703
13036
  if (code !== "external_modification" && code !== "remote_changed") return null;
@@ -12869,11 +13202,11 @@ var RuntypeClient = class {
12869
13202
  /**
12870
13203
  * Generic PUT request
12871
13204
  */
12872
- async put(path, data) {
13205
+ async put(path, data, extraHeaders) {
12873
13206
  const url = this.buildUrl(path);
12874
13207
  const response = await this.makeRequest(url, {
12875
13208
  method: "PUT",
12876
- headers: this.headers,
13209
+ headers: { ...this.headers, ...extraHeaders },
12877
13210
  body: data ? JSON.stringify(data) : void 0
12878
13211
  });
12879
13212
  return response;
@@ -12893,11 +13226,12 @@ var RuntypeClient = class {
12893
13226
  /**
12894
13227
  * Generic DELETE request
12895
13228
  */
12896
- async delete(path) {
13229
+ async delete(path, data, extraHeaders) {
12897
13230
  const url = this.buildUrl(path);
12898
13231
  const response = await this.makeRequest(url, {
12899
13232
  method: "DELETE",
12900
- headers: this.headers
13233
+ headers: { ...this.headers, ...extraHeaders },
13234
+ body: data ? JSON.stringify(data) : void 0
12901
13235
  });
12902
13236
  return response;
12903
13237
  }
@@ -13350,6 +13684,180 @@ var Runtype = class {
13350
13684
  }
13351
13685
  };
13352
13686
 
13687
+ // src/agent-promotion.ts
13688
+ var MANIFEST_VERSION = 1;
13689
+ var RECEIPT_PAGE_SIZE = 50;
13690
+ var MAX_RECEIPT_PAGES = 20;
13691
+ var AgentPromotionError = class extends Error {
13692
+ constructor(message) {
13693
+ super(message);
13694
+ this.name = "AgentPromotionError";
13695
+ }
13696
+ };
13697
+ function assertManifest(manifest) {
13698
+ if (manifest?.manifest !== MANIFEST_VERSION) {
13699
+ throw new AgentPromotionError(
13700
+ `Unsupported promotion manifest version ${String(manifest?.manifest)}; expected ${MANIFEST_VERSION}.`
13701
+ );
13702
+ }
13703
+ }
13704
+ async function ensureInto(transport, body) {
13705
+ return transport.post("/agents/ensure", body);
13706
+ }
13707
+ async function prepareAgentPromotion(input) {
13708
+ if (input.alias === "live") {
13709
+ throw new AgentPromotionError(
13710
+ "prepare stages a candidate at a preview alias and never deploys: pass a non-live alias, then promote it with activate."
13711
+ );
13712
+ }
13713
+ const pulled = await input.source.get("/agents/pull", { name: input.name });
13714
+ const converged = await ensureInto(input.target, {
13715
+ name: input.name,
13716
+ definition: pulled.definition,
13717
+ deploy: { alias: input.alias },
13718
+ ...input.version ? { version: input.version } : {}
13719
+ });
13720
+ if (converged.result === "plan") {
13721
+ throw new AgentPromotionError("The target converge answered a plan; expected a write.");
13722
+ }
13723
+ const deployment = converged.deployment;
13724
+ if (!deployment?.versionId) {
13725
+ throw new AgentPromotionError(
13726
+ `The target converge did not stage a version at "${input.alias}"; nothing to promote.`
13727
+ );
13728
+ }
13729
+ return {
13730
+ manifest: MANIFEST_VERSION,
13731
+ name: input.name,
13732
+ createdAt: (/* @__PURE__ */ new Date()).toISOString(),
13733
+ source: {
13734
+ agentId: pulled.agentId,
13735
+ versionId: pulled.versionId,
13736
+ contentHash: pulled.contentHash,
13737
+ ...input.commit ? { commit: input.commit } : {}
13738
+ },
13739
+ target: {
13740
+ agentId: converged.agentId,
13741
+ versionId: deployment.versionId,
13742
+ alias: deployment.alias,
13743
+ revision: deployment.revision,
13744
+ contentHash: converged.contentHash
13745
+ }
13746
+ };
13747
+ }
13748
+ async function validateAgentPromotion(input) {
13749
+ assertManifest(input.manifest);
13750
+ const definition = input.definition ?? await repullStagedDefinition({
13751
+ ...input.source ? { source: input.source } : {},
13752
+ manifest: input.manifest
13753
+ });
13754
+ const planned = await ensureInto(input.target, {
13755
+ name: input.manifest.name,
13756
+ definition,
13757
+ dryRun: true,
13758
+ deploy: { alias: input.manifest.target.alias }
13759
+ });
13760
+ if (planned.result !== "plan") {
13761
+ throw new AgentPromotionError(`Expected a plan from the dry run, got '${planned.result}'.`);
13762
+ }
13763
+ const staged = await findStagedReceipt(input.target, input.manifest);
13764
+ if (!staged) {
13765
+ throw new AgentPromotionError(
13766
+ `No deployment receipt for version ${input.manifest.target.versionId} at "${input.manifest.target.alias}" on agent ${input.manifest.target.agentId}. The staged candidate is gone, so there is nothing to validate; re-run prepare.`
13767
+ );
13768
+ }
13769
+ const refs = readReceiptRefs(staged);
13770
+ const unresolvedRefs = refs.filter((ref) => ref.resolvedId === null).map((ref) => ref.ref);
13771
+ return { ok: unresolvedRefs.length === 0, plan: planned, unresolvedRefs, refs };
13772
+ }
13773
+ async function repullStagedDefinition(input) {
13774
+ if (!input.source) {
13775
+ throw new AgentPromotionError(
13776
+ "validate needs the definition it planned: pass definition, or pass source credentials to re-pull it."
13777
+ );
13778
+ }
13779
+ const { name } = input.manifest;
13780
+ const pulled = await input.source.get("/agents/pull", { name });
13781
+ if (pulled.contentHash !== input.manifest.source.contentHash) {
13782
+ throw new AgentPromotionError(
13783
+ `The source definition changed since this promotion was prepared: the manifest was staged from ${input.manifest.source.contentHash}, and "${name}" now hashes to ${pulled.contentHash}. Re-run prepare so the artifact you validate is the one you staged.`
13784
+ );
13785
+ }
13786
+ return pulled.definition;
13787
+ }
13788
+ async function findStagedReceipt(target, manifest) {
13789
+ const deployments = new AgentDeploymentsNamespace(() => target);
13790
+ let cursor;
13791
+ for (let page = 0; page < MAX_RECEIPT_PAGES; page += 1) {
13792
+ const answered = await deployments.list(manifest.target.agentId, {
13793
+ alias: manifest.target.alias,
13794
+ limit: RECEIPT_PAGE_SIZE,
13795
+ ...cursor ? { cursor } : {}
13796
+ });
13797
+ const found = answered.data.find(
13798
+ (receipt) => receipt.versionId === manifest.target.versionId
13799
+ );
13800
+ if (found) return found;
13801
+ const next = answered.pagination?.nextCursor;
13802
+ if (typeof next !== "string" || next.length === 0) return null;
13803
+ cursor = next;
13804
+ }
13805
+ return null;
13806
+ }
13807
+ function readReceiptRefs(receipt) {
13808
+ const dependencies = receipt?.dependencies;
13809
+ const refs = dependencies?.refs;
13810
+ if (!Array.isArray(refs)) return [];
13811
+ return refs.flatMap((entry) => {
13812
+ if (entry === null || typeof entry !== "object") return [];
13813
+ const row = entry;
13814
+ if (typeof row.ref !== "string") return [];
13815
+ return [
13816
+ {
13817
+ ref: row.ref,
13818
+ resolvedId: typeof row.resolvedId === "string" ? row.resolvedId : null,
13819
+ fingerprint: typeof row.fingerprint === "string" ? row.fingerprint : null
13820
+ }
13821
+ ];
13822
+ });
13823
+ }
13824
+ async function activateAgentPromotion(input) {
13825
+ assertManifest(input.manifest);
13826
+ const alias = input.alias ?? "live";
13827
+ const aliases = new AgentAliasesNamespace(() => input.target);
13828
+ const current = await aliases.get(input.manifest.target.agentId, alias).catch((error) => {
13829
+ if (error instanceof AgentAliasNotFoundError) return null;
13830
+ throw error;
13831
+ });
13832
+ return aliases.activate(input.manifest.target.agentId, alias, {
13833
+ versionId: input.manifest.target.versionId,
13834
+ ...current ? { revision: current.revision } : {},
13835
+ idempotencyKey: input.idempotencyKey ?? promotionIdempotencyKey(input.manifest, alias),
13836
+ ...input.reason ? { reason: input.reason } : {},
13837
+ promotion: {
13838
+ sourceAgentId: input.manifest.source.agentId,
13839
+ ...input.manifest.source.versionId ? { sourceVersionId: input.manifest.source.versionId } : {},
13840
+ sourceContentHash: input.manifest.source.contentHash,
13841
+ ...input.manifest.source.commit ? { sourceCommit: input.manifest.source.commit } : {}
13842
+ }
13843
+ });
13844
+ }
13845
+ function promotionIdempotencyKey(manifest, alias) {
13846
+ return `promote:${manifest.target.agentId}:${alias}:${manifest.target.versionId}`;
13847
+ }
13848
+ async function promoteAgent(input) {
13849
+ const manifest = await prepareAgentPromotion(input);
13850
+ const definition = await repullStagedDefinition({ source: input.source, manifest });
13851
+ const validation = await validateAgentPromotion({ target: input.target, manifest, definition });
13852
+ if (!input.activate) return { manifest, validation };
13853
+ const activation = await activateAgentPromotion({
13854
+ target: input.target,
13855
+ manifest,
13856
+ ...input.activate
13857
+ });
13858
+ return { manifest, validation, activation };
13859
+ }
13860
+
13353
13861
  // src/transform.ts
13354
13862
  function transformQueryParams(params) {
13355
13863
  const result = {};
@@ -13367,7 +13875,7 @@ function transformQueryParams(params) {
13367
13875
 
13368
13876
  // src/version.ts
13369
13877
  var FALLBACK_VERSION = "0.0.0";
13370
- var SDK_VERSION = "9.12.0".length > 0 ? "9.12.0" : FALLBACK_VERSION;
13878
+ var SDK_VERSION = "9.14.0".length > 0 ? "9.14.0" : FALLBACK_VERSION;
13371
13879
  var RUNTYPE_CLIENT_KIND = "sdk";
13372
13880
  var SDK_USER_AGENT = `runtype-sdk/${SDK_VERSION} (typescript)`;
13373
13881
 
@@ -13746,11 +14254,11 @@ var RuntypeClient2 = class {
13746
14254
  /**
13747
14255
  * Generic PUT request
13748
14256
  */
13749
- async put(path, data) {
14257
+ async put(path, data, extraHeaders) {
13750
14258
  const url = this.buildUrl(path);
13751
14259
  const response = await this.makeRequest(url, {
13752
14260
  method: "PUT",
13753
- headers: this.headers,
14261
+ headers: { ...this.headers, ...extraHeaders },
13754
14262
  body: data ? JSON.stringify(data) : void 0
13755
14263
  });
13756
14264
  return response;
@@ -13770,11 +14278,11 @@ var RuntypeClient2 = class {
13770
14278
  /**
13771
14279
  * Generic DELETE request
13772
14280
  */
13773
- async delete(path, data) {
14281
+ async delete(path, data, extraHeaders) {
13774
14282
  const url = this.buildUrl(path);
13775
14283
  const response = await this.makeRequest(url, {
13776
14284
  method: "DELETE",
13777
- headers: this.headers,
14285
+ headers: { ...this.headers, ...extraHeaders },
13778
14286
  body: data ? JSON.stringify(data) : void 0
13779
14287
  });
13780
14288
  return response;
@@ -14635,8 +15143,16 @@ var STEP_TYPE_TO_METHOD = {
14635
15143
  "memory-summary": "memorySummary"
14636
15144
  };
14637
15145
  export {
15146
+ AgentAliasDependencyError,
15147
+ AgentAliasNotFoundError,
15148
+ AgentAliasPreviewLimitError,
15149
+ AgentAliasRevisionMismatchError,
15150
+ AgentAliasRevisionRequiredError,
15151
+ AgentAliasesNamespace,
15152
+ AgentDeploymentsNamespace,
14638
15153
  AgentDriftError,
14639
15154
  AgentEnsureConflictError,
15155
+ AgentPromotionError,
14640
15156
  AgentVersionsEndpoint,
14641
15157
  AgentsEndpoint,
14642
15158
  AgentsNamespace,
@@ -14658,6 +15174,7 @@ export {
14658
15174
  DEFAULT_RECOVERY_AFTER_EMPTY_SESSIONS,
14659
15175
  DEFAULT_STALL_STOP_AFTER,
14660
15176
  DispatchEndpoint,
15177
+ ENSURE_RELEASE_DEPLOY_CONFLICT_MESSAGE,
14661
15178
  EvalBuilder,
14662
15179
  EvalEndpoint,
14663
15180
  EvalRunner,
@@ -14675,6 +15192,7 @@ export {
14675
15192
  FlowsNamespace,
14676
15193
  IntegrationsEndpoint,
14677
15194
  LEDGER_ARTIFACT_LINE_PREFIX,
15195
+ LIVE_AGENT_ALIAS,
14678
15196
  LogsEndpoint,
14679
15197
  ModelConfigsEndpoint,
14680
15198
  ProductDriftError,
@@ -14711,6 +15229,8 @@ export {
14711
15229
  TypedRecordsScope,
14712
15230
  UNIFIED_EVENTS_QUERY,
14713
15231
  UsersEndpoint,
15232
+ activateAgentPromotion,
15233
+ agentAliasErrorCode,
14714
15234
  applyGeneratedRuntimeToolProposalToDispatchRequest,
14715
15235
  attachRuntimeToolsToDispatchRequest,
14716
15236
  buildAgentAdmissionHeaders,
@@ -14788,7 +15308,10 @@ export {
14788
15308
  parseLedgerArtifactRelativePath,
14789
15309
  parseOffloadedOutputId,
14790
15310
  parseSSEChunk,
15311
+ prepareAgentPromotion,
14791
15312
  processStream,
15313
+ promoteAgent,
15314
+ promotionIdempotencyKey,
14792
15315
  pullEval,
14793
15316
  pullFpo,
14794
15317
  ranStep,
@@ -14806,6 +15329,7 @@ export {
14806
15329
  unregisterWorkflowHook,
14807
15330
  usedNoTools,
14808
15331
  validJson,
15332
+ validateAgentPromotion,
14809
15333
  withDetachedReconnect,
14810
15334
  withUnifiedEvents
14811
15335
  };