@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.cjs CHANGED
@@ -20,8 +20,16 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  // src/index.ts
21
21
  var index_exports = {};
22
22
  __export(index_exports, {
23
+ AgentAliasDependencyError: () => AgentAliasDependencyError,
24
+ AgentAliasNotFoundError: () => AgentAliasNotFoundError,
25
+ AgentAliasPreviewLimitError: () => AgentAliasPreviewLimitError,
26
+ AgentAliasRevisionMismatchError: () => AgentAliasRevisionMismatchError,
27
+ AgentAliasRevisionRequiredError: () => AgentAliasRevisionRequiredError,
28
+ AgentAliasesNamespace: () => AgentAliasesNamespace,
29
+ AgentDeploymentsNamespace: () => AgentDeploymentsNamespace,
23
30
  AgentDriftError: () => AgentDriftError,
24
31
  AgentEnsureConflictError: () => AgentEnsureConflictError,
32
+ AgentPromotionError: () => AgentPromotionError,
25
33
  AgentVersionsEndpoint: () => AgentVersionsEndpoint,
26
34
  AgentsEndpoint: () => AgentsEndpoint,
27
35
  AgentsNamespace: () => AgentsNamespace,
@@ -43,6 +51,7 @@ __export(index_exports, {
43
51
  DEFAULT_RECOVERY_AFTER_EMPTY_SESSIONS: () => DEFAULT_RECOVERY_AFTER_EMPTY_SESSIONS,
44
52
  DEFAULT_STALL_STOP_AFTER: () => DEFAULT_STALL_STOP_AFTER,
45
53
  DispatchEndpoint: () => DispatchEndpoint,
54
+ ENSURE_RELEASE_DEPLOY_CONFLICT_MESSAGE: () => ENSURE_RELEASE_DEPLOY_CONFLICT_MESSAGE,
46
55
  EvalBuilder: () => EvalBuilder,
47
56
  EvalEndpoint: () => EvalEndpoint,
48
57
  EvalRunner: () => EvalRunner,
@@ -60,6 +69,7 @@ __export(index_exports, {
60
69
  FlowsNamespace: () => FlowsNamespace,
61
70
  IntegrationsEndpoint: () => IntegrationsEndpoint,
62
71
  LEDGER_ARTIFACT_LINE_PREFIX: () => LEDGER_ARTIFACT_LINE_PREFIX,
72
+ LIVE_AGENT_ALIAS: () => LIVE_AGENT_ALIAS,
63
73
  LogsEndpoint: () => LogsEndpoint,
64
74
  ModelConfigsEndpoint: () => ModelConfigsEndpoint,
65
75
  ProductDriftError: () => ProductDriftError,
@@ -96,6 +106,8 @@ __export(index_exports, {
96
106
  TypedRecordsScope: () => TypedRecordsScope,
97
107
  UNIFIED_EVENTS_QUERY: () => UNIFIED_EVENTS_QUERY,
98
108
  UsersEndpoint: () => UsersEndpoint,
109
+ activateAgentPromotion: () => activateAgentPromotion,
110
+ agentAliasErrorCode: () => agentAliasErrorCode,
99
111
  applyGeneratedRuntimeToolProposalToDispatchRequest: () => applyGeneratedRuntimeToolProposalToDispatchRequest,
100
112
  attachRuntimeToolsToDispatchRequest: () => attachRuntimeToolsToDispatchRequest,
101
113
  buildAgentAdmissionHeaders: () => buildAgentAdmissionHeaders,
@@ -173,7 +185,10 @@ __export(index_exports, {
173
185
  parseLedgerArtifactRelativePath: () => parseLedgerArtifactRelativePath,
174
186
  parseOffloadedOutputId: () => parseOffloadedOutputId,
175
187
  parseSSEChunk: () => parseSSEChunk,
188
+ prepareAgentPromotion: () => prepareAgentPromotion,
176
189
  processStream: () => processStream,
190
+ promoteAgent: () => promoteAgent,
191
+ promotionIdempotencyKey: () => promotionIdempotencyKey,
177
192
  pullEval: () => pullEval,
178
193
  pullFpo: () => pullFpo,
179
194
  ranStep: () => ranStep,
@@ -191,6 +206,7 @@ __export(index_exports, {
191
206
  unregisterWorkflowHook: () => unregisterWorkflowHook,
192
207
  usedNoTools: () => usedNoTools,
193
208
  validJson: () => validJson,
209
+ validateAgentPromotion: () => validateAgentPromotion,
194
210
  withDetachedReconnect: () => withDetachedReconnect,
195
211
  withUnifiedEvents: () => withUnifiedEvents
196
212
  });
@@ -2251,6 +2267,310 @@ data: ${JSON.stringify({
2251
2267
  });
2252
2268
  }
2253
2269
 
2270
+ // src/agent-aliases-namespace.ts
2271
+ var LIVE_AGENT_ALIAS = "live";
2272
+ var AgentAliasRevisionMismatchError = class extends Error {
2273
+ constructor(body) {
2274
+ super(
2275
+ body.error ?? `Alias revision mismatch: expected ${body.expected}, found ${body.actual ?? "no alias"}.`
2276
+ );
2277
+ this.code = "alias_revision_mismatch";
2278
+ this.name = "AgentAliasRevisionMismatchError";
2279
+ this.expectedRevision = body.expected;
2280
+ this.actualRevision = body.actual;
2281
+ }
2282
+ };
2283
+ var AgentAliasRevisionRequiredError = class extends Error {
2284
+ constructor(message) {
2285
+ super(message);
2286
+ this.code = "alias_revision_required";
2287
+ this.name = "AgentAliasRevisionRequiredError";
2288
+ }
2289
+ };
2290
+ var AgentAliasNotFoundError = class extends Error {
2291
+ constructor(body) {
2292
+ super(body.error ?? `Alias "${body.alias}" was not found on agent ${body.agentId}.`);
2293
+ this.code = "alias_not_found";
2294
+ this.name = "AgentAliasNotFoundError";
2295
+ this.alias = body.alias;
2296
+ this.agentId = body.agentId;
2297
+ }
2298
+ };
2299
+ var AgentAliasPreviewLimitError = class extends Error {
2300
+ constructor(body) {
2301
+ super(
2302
+ body.error ?? `This ${body.scope} already has ${body.limit} active preview aliases, the maximum.`
2303
+ );
2304
+ this.code = "PREVIEW_ALIAS_LIMIT";
2305
+ this.name = "AgentAliasPreviewLimitError";
2306
+ this.scope = body.scope;
2307
+ this.limit = body.limit;
2308
+ this.active = body.active;
2309
+ }
2310
+ };
2311
+ var AgentAliasDependencyError = class extends Error {
2312
+ constructor(body) {
2313
+ super(body.error ?? "The version references a dependency that no longer resolves.");
2314
+ this.code = "alias_dependency_unresolved";
2315
+ this.name = "AgentAliasDependencyError";
2316
+ this.refs = body.refs ?? [];
2317
+ }
2318
+ };
2319
+ function asRecord(value) {
2320
+ return value !== null && typeof value === "object" && !Array.isArray(value) ? value : null;
2321
+ }
2322
+ function parseRequestError(err) {
2323
+ if (!(err instanceof Error)) return { status: null, body: null };
2324
+ const structured = err;
2325
+ if (typeof structured.statusCode === "number") {
2326
+ return { status: structured.statusCode, body: asRecord(structured.data) };
2327
+ }
2328
+ const match = err.message.match(/^API request failed: (\d{3}) .*? - ([\s\S]*)$/);
2329
+ if (!match) return { status: null, body: null };
2330
+ try {
2331
+ return { status: Number(match[1]), body: asRecord(JSON.parse(match[2])) };
2332
+ } catch {
2333
+ return { status: Number(match[1]), body: null };
2334
+ }
2335
+ }
2336
+ function asString(value, fallback) {
2337
+ return typeof value === "string" ? value : fallback;
2338
+ }
2339
+ function toAliasError(err, agentId, alias) {
2340
+ const { status, body } = parseRequestError(err);
2341
+ if (status === null) return null;
2342
+ const error = body && typeof body.error === "string" ? body.error : void 0;
2343
+ if (status === 412 && body && typeof body.expected === "number") {
2344
+ return new AgentAliasRevisionMismatchError({
2345
+ ...error !== void 0 ? { error } : {},
2346
+ expected: body.expected,
2347
+ actual: typeof body.actual === "number" ? body.actual : null
2348
+ });
2349
+ }
2350
+ if (status === 428) {
2351
+ return new AgentAliasRevisionRequiredError(
2352
+ error ?? "Updating an existing live alias requires an If-Match revision."
2353
+ );
2354
+ }
2355
+ if (status === 404 && body?.code === "alias_not_found") {
2356
+ return new AgentAliasNotFoundError({
2357
+ ...error !== void 0 ? { error } : {},
2358
+ alias: asString(body.alias, alias),
2359
+ agentId: asString(body.agentId, agentId)
2360
+ });
2361
+ }
2362
+ if (status === 429 && body?.code === "PREVIEW_ALIAS_LIMIT") {
2363
+ return new AgentAliasPreviewLimitError({
2364
+ ...error !== void 0 ? { error } : {},
2365
+ scope: body.scope === "organization" ? "organization" : "agent",
2366
+ limit: typeof body.limit === "number" ? body.limit : 0,
2367
+ active: typeof body.active === "number" ? body.active : 0
2368
+ });
2369
+ }
2370
+ if (status === 422 && body?.code === "alias_dependency_unresolved") {
2371
+ return new AgentAliasDependencyError({
2372
+ ...error !== void 0 ? { error } : {},
2373
+ refs: Array.isArray(body.refs) ? body.refs.filter((ref) => typeof ref === "string") : []
2374
+ });
2375
+ }
2376
+ return null;
2377
+ }
2378
+ var TYPED_ALIAS_ERRORS = [
2379
+ AgentAliasRevisionMismatchError,
2380
+ AgentAliasRevisionRequiredError,
2381
+ AgentAliasNotFoundError,
2382
+ AgentAliasDependencyError,
2383
+ AgentAliasPreviewLimitError
2384
+ ];
2385
+ function agentAliasErrorCode(err) {
2386
+ return TYPED_ALIAS_ERRORS.some((typed) => err instanceof typed) ? err.code : void 0;
2387
+ }
2388
+ function writeHeaders(input) {
2389
+ const headers = {};
2390
+ if (typeof input.revision === "number") headers["If-Match"] = String(input.revision);
2391
+ if (input.idempotencyKey) headers["Idempotency-Key"] = input.idempotencyKey;
2392
+ return headers;
2393
+ }
2394
+ function encode(value) {
2395
+ return encodeURIComponent(value);
2396
+ }
2397
+ var AgentAliasesNamespace = class {
2398
+ constructor(getTransport) {
2399
+ this.getTransport = getTransport;
2400
+ }
2401
+ /** List this agent's pointers, `live` first then previews by name. */
2402
+ async list(agentId, options = {}) {
2403
+ return this.getTransport().get(`/agents/${encode(agentId)}/aliases`, {
2404
+ ...options.includeArchived ? { includeArchived: "true" } : {},
2405
+ ...options.limit !== void 0 ? { limit: String(options.limit) } : {},
2406
+ ...options.cursor ? { cursor: options.cursor } : {}
2407
+ });
2408
+ }
2409
+ /**
2410
+ * Every agent in the organization carrying a pointer with this name, each
2411
+ * with the revision to quote back as `If-Match`. The read a PR-close cleanup
2412
+ * makes before archiving.
2413
+ */
2414
+ async listByName(alias, options = {}) {
2415
+ return this.getTransport().get("/agent-aliases", {
2416
+ alias,
2417
+ ...options.includeArchived ? { includeArchived: "true" } : {}
2418
+ });
2419
+ }
2420
+ /**
2421
+ * Archive this pointer on every agent in the organization that carries it,
2422
+ * each under the revision just read. A failure on one agent is reported and
2423
+ * the rest continue; a second run finds nothing active and archives nothing.
2424
+ */
2425
+ async archiveEverywhere(alias) {
2426
+ const listed = await this.listByName(alias);
2427
+ const rows = listed.data ?? [];
2428
+ const result = { alias, archived: [], failed: [] };
2429
+ for (const row of rows) {
2430
+ try {
2431
+ const archived = await this.archive(row.agentId, alias, { revision: row.revision });
2432
+ result.archived.push({
2433
+ agentId: row.agentId,
2434
+ agentName: row.agentName,
2435
+ revision: archived.revision,
2436
+ receiptId: archived.receiptId
2437
+ });
2438
+ } catch (err) {
2439
+ const code = agentAliasErrorCode(err);
2440
+ result.failed.push({
2441
+ agentId: row.agentId,
2442
+ agentName: row.agentName,
2443
+ error: err instanceof Error ? err.message : String(err),
2444
+ ...code ? { code } : {}
2445
+ });
2446
+ }
2447
+ }
2448
+ return result;
2449
+ }
2450
+ /** Read one pointer. A missing or archived alias throws, never falls back to live. */
2451
+ async get(agentId, alias, options = {}) {
2452
+ return this.run(
2453
+ agentId,
2454
+ alias,
2455
+ () => this.getTransport().get(`/agents/${encode(agentId)}/aliases/${encode(alias)}`, {
2456
+ ...options.includeArchived ? { includeArchived: "true" } : {}
2457
+ })
2458
+ );
2459
+ }
2460
+ /** Aim one pointer at one exact version, appending a deployment receipt. */
2461
+ async activate(agentId, alias, input) {
2462
+ const body = {
2463
+ versionId: input.versionId,
2464
+ ...input.reason ? { reason: input.reason } : {},
2465
+ ...input.promotion ? { promotion: input.promotion } : {}
2466
+ };
2467
+ return this.run(
2468
+ agentId,
2469
+ alias,
2470
+ () => this.getTransport().put(
2471
+ `/agents/${encode(agentId)}/aliases/${encode(alias)}`,
2472
+ body,
2473
+ writeHeaders(input)
2474
+ )
2475
+ );
2476
+ }
2477
+ /** Archive a preview pointer: it stops resolving but keeps its history. */
2478
+ async archive(agentId, alias, input = {}) {
2479
+ return this.run(
2480
+ agentId,
2481
+ alias,
2482
+ () => this.getTransport().delete(
2483
+ `/agents/${encode(agentId)}/aliases/${encode(alias)}`,
2484
+ void 0,
2485
+ writeHeaders(input)
2486
+ )
2487
+ );
2488
+ }
2489
+ /** Re-aim a pointer at the version its receipt history records before this one. */
2490
+ async rollback(agentId, alias, input = {}) {
2491
+ const body = {
2492
+ ...input.steps !== void 0 ? { steps: input.steps } : {},
2493
+ ...input.reason ? { reason: input.reason } : {}
2494
+ };
2495
+ return this.run(
2496
+ agentId,
2497
+ alias,
2498
+ () => this.getTransport().post(
2499
+ `/agents/${encode(agentId)}/aliases/${encode(alias)}/rollback`,
2500
+ body,
2501
+ writeHeaders(input)
2502
+ )
2503
+ );
2504
+ }
2505
+ /** The per-alias secret binding NAMES this pointer carries. Values are write-only. */
2506
+ async getBindings(agentId, alias) {
2507
+ return this.run(
2508
+ agentId,
2509
+ alias,
2510
+ () => this.getTransport().get(
2511
+ `/agents/${encode(agentId)}/aliases/${encode(alias)}/bindings`
2512
+ )
2513
+ );
2514
+ }
2515
+ /**
2516
+ * Replace the complete set of `{{secret:NAME}}` values executions resolve
2517
+ * when they reach this agent through this pointer, ahead of the organization
2518
+ * secret of the same name. A name you stop sending stops resolving.
2519
+ */
2520
+ async setBindings(agentId, alias, input) {
2521
+ const body = {
2522
+ bindings: input.bindings,
2523
+ ...input.reason ? { reason: input.reason } : {}
2524
+ };
2525
+ return this.run(
2526
+ agentId,
2527
+ alias,
2528
+ () => this.getTransport().put(
2529
+ `/agents/${encode(agentId)}/aliases/${encode(alias)}/bindings`,
2530
+ body,
2531
+ writeHeaders(input)
2532
+ )
2533
+ );
2534
+ }
2535
+ /** Drop every binding, so this pointer's executions fall back to organization secrets. */
2536
+ async clearBindings(agentId, alias, input = {}) {
2537
+ return this.run(
2538
+ agentId,
2539
+ alias,
2540
+ () => this.getTransport().delete(
2541
+ `/agents/${encode(agentId)}/aliases/${encode(alias)}/bindings`,
2542
+ void 0,
2543
+ writeHeaders(input)
2544
+ )
2545
+ );
2546
+ }
2547
+ async run(agentId, alias, call) {
2548
+ try {
2549
+ return await call();
2550
+ } catch (err) {
2551
+ const typed = toAliasError(err, agentId, alias);
2552
+ if (typed) throw typed;
2553
+ throw err;
2554
+ }
2555
+ }
2556
+ };
2557
+ var AgentDeploymentsNamespace = class {
2558
+ constructor(getTransport) {
2559
+ this.getTransport = getTransport;
2560
+ }
2561
+ /** Receipts newest first, cursor-paginated; filter to one pointer with `alias`. */
2562
+ async list(agentId, options = {}) {
2563
+ return this.getTransport().get(
2564
+ `/agents/${encode(agentId)}/deployments`,
2565
+ {
2566
+ ...options.alias ? { alias: options.alias } : {},
2567
+ ...options.limit !== void 0 ? { limit: String(options.limit) } : {},
2568
+ ...options.cursor ? { cursor: options.cursor } : {}
2569
+ }
2570
+ );
2571
+ }
2572
+ };
2573
+
2254
2574
  // src/generated-tool-gate.ts
2255
2575
  var TOOL_NAME_PATTERN = /^[A-Za-z][A-Za-z0-9_]{1,63}$/;
2256
2576
  var DEFAULT_MAX_CODE_LENGTH = 12e3;
@@ -2273,7 +2593,7 @@ var DEFAULT_ALLOWED_LANGUAGES = [
2273
2593
  function isObject(value) {
2274
2594
  return typeof value === "object" && value !== null && !Array.isArray(value);
2275
2595
  }
2276
- function asString(value) {
2596
+ function asString2(value) {
2277
2597
  return typeof value === "string" ? value.trim() : void 0;
2278
2598
  }
2279
2599
  function asNumber(value) {
@@ -2306,8 +2626,8 @@ function normalizeGeneratedProposal(proposal, violations) {
2306
2626
  violations.push("Generated tool proposal must be an object");
2307
2627
  return null;
2308
2628
  }
2309
- const name = asString(candidate.name);
2310
- const description = asString(candidate.description);
2629
+ const name = asString2(candidate.name);
2630
+ const description = asString2(candidate.description);
2311
2631
  const toolType = candidate.toolType;
2312
2632
  const parametersSchema = candidate.parametersSchema;
2313
2633
  if (!name) {
@@ -2342,7 +2662,7 @@ function normalizeGeneratedProposal(proposal, violations) {
2342
2662
  violations.push("Custom tool config is required");
2343
2663
  return null;
2344
2664
  }
2345
- const code = asString(config.code);
2665
+ const code = asString2(config.code);
2346
2666
  if (!code) {
2347
2667
  violations.push("Custom tool config.code is required");
2348
2668
  return null;
@@ -5819,6 +6139,8 @@ var _AgentsEndpoint = class _AgentsEndpoint {
5819
6139
  constructor(client) {
5820
6140
  this.client = client;
5821
6141
  this.TOOL_OUTPUT_INLINE_THRESHOLD = 500;
6142
+ this.aliases = new AgentAliasesNamespace(() => this.client);
6143
+ this.deployments = new AgentDeploymentsNamespace(() => this.client);
5822
6144
  }
5823
6145
  /**
5824
6146
  * List all agents for the authenticated user
@@ -9879,7 +10201,7 @@ var FlowDriftError = class extends Error {
9879
10201
  this.plan = plan;
9880
10202
  }
9881
10203
  };
9882
- function parseRequestError(err) {
10204
+ function parseRequestError2(err) {
9883
10205
  if (!(err instanceof Error)) return { status: null, body: null };
9884
10206
  const match = err.message.match(/^API request failed: (\d{3}) .*? - ([\s\S]*)$/);
9885
10207
  if (!match) return { status: null, body: null };
@@ -9890,7 +10212,7 @@ function parseRequestError(err) {
9890
10212
  }
9891
10213
  }
9892
10214
  function toConflictError(err) {
9893
- const { status, body } = parseRequestError(err);
10215
+ const { status, body } = parseRequestError2(err);
9894
10216
  if (status !== 409 || !isPlainObject(body)) return null;
9895
10217
  const code = body.code;
9896
10218
  if (code !== "external_modification" && code !== "remote_changed") return null;
@@ -11695,7 +12017,7 @@ var SkillDriftError = class extends Error {
11695
12017
  this.plan = plan;
11696
12018
  }
11697
12019
  };
11698
- function parseRequestError2(err) {
12020
+ function parseRequestError3(err) {
11699
12021
  if (!(err instanceof Error)) return { status: null, body: null };
11700
12022
  const match = err.message.match(/^API request failed: (\d{3}) .*? - ([\s\S]*)$/);
11701
12023
  if (!match) return { status: null, body: null };
@@ -11706,7 +12028,7 @@ function parseRequestError2(err) {
11706
12028
  }
11707
12029
  }
11708
12030
  function toConflictError2(err) {
11709
- const { status, body } = parseRequestError2(err);
12031
+ const { status, body } = parseRequestError3(err);
11710
12032
  if (status !== 409 || !isPlainObject(body)) return null;
11711
12033
  const code = body.code;
11712
12034
  if (code !== "external_modification" && code !== "remote_changed") return null;
@@ -12015,6 +12337,7 @@ var SkillsNamespace = class {
12015
12337
  };
12016
12338
 
12017
12339
  // src/agents-namespace.ts
12340
+ 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.';
12018
12341
  var AGENT_CONFIG_KEYS = [
12019
12342
  "contextManagement",
12020
12343
  "model",
@@ -12174,7 +12497,7 @@ var AgentDriftError = class extends Error {
12174
12497
  this.plan = plan;
12175
12498
  }
12176
12499
  };
12177
- function parseRequestError3(err) {
12500
+ function parseRequestError4(err) {
12178
12501
  if (!(err instanceof Error)) return { status: null, body: null };
12179
12502
  const match = err.message.match(/^API request failed: (\d{3}) .*? - ([\s\S]*)$/);
12180
12503
  if (!match) return { status: null, body: null };
@@ -12185,7 +12508,7 @@ function parseRequestError3(err) {
12185
12508
  }
12186
12509
  }
12187
12510
  function toConflictError3(err) {
12188
- const { status, body } = parseRequestError3(err);
12511
+ const { status, body } = parseRequestError4(err);
12189
12512
  if (status !== 409 || !isPlainObject2(body)) return null;
12190
12513
  const code = body.code;
12191
12514
  if (code !== "external_modification" && code !== "remote_changed") return null;
@@ -12205,6 +12528,9 @@ function memoFor4(client) {
12205
12528
  var AgentsNamespace = class {
12206
12529
  constructor(getClient) {
12207
12530
  this.getClient = getClient;
12531
+ const transport = () => this.getClient();
12532
+ this.aliases = new AgentAliasesNamespace(transport);
12533
+ this.deployments = new AgentDeploymentsNamespace(transport);
12208
12534
  }
12209
12535
  /**
12210
12536
  * Idempotently converge a definition onto the platform. Hash-first: probes
@@ -12214,10 +12540,14 @@ var AgentsNamespace = class {
12214
12540
  */
12215
12541
  async ensure(definition, options = {}) {
12216
12542
  const client = this.getClient();
12217
- const { dryRun, onConflict, release, expectedRemoteHash, version, expectNoChanges } = options;
12543
+ const { dryRun, onConflict, release, deploy, expectedRemoteHash, version, expectNoChanges } = options;
12544
+ if (release !== void 0 && deploy !== void 0) {
12545
+ throw new Error(ENSURE_RELEASE_DEPLOY_CONFLICT_MESSAGE);
12546
+ }
12218
12547
  const passthrough = {
12219
12548
  ...onConflict ? { onConflict } : {},
12220
12549
  ...release ? { release } : {},
12550
+ ...deploy ? { deploy } : {},
12221
12551
  ...expectedRemoteHash ? { expectedRemoteHash } : {},
12222
12552
  ...version ? { version } : {}
12223
12553
  };
@@ -12382,7 +12712,7 @@ var ToolDriftError = class extends Error {
12382
12712
  this.plan = plan;
12383
12713
  }
12384
12714
  };
12385
- function parseRequestError4(err) {
12715
+ function parseRequestError5(err) {
12386
12716
  if (!(err instanceof Error)) return { status: null, body: null };
12387
12717
  const match = err.message.match(/^API request failed: (\d{3}) .*? - ([\s\S]*)$/);
12388
12718
  if (!match) return { status: null, body: null };
@@ -12393,7 +12723,7 @@ function parseRequestError4(err) {
12393
12723
  }
12394
12724
  }
12395
12725
  function toConflictError4(err) {
12396
- const { status, body } = parseRequestError4(err);
12726
+ const { status, body } = parseRequestError5(err);
12397
12727
  if (status !== 409 || !isPlainObject(body)) return null;
12398
12728
  const code = body.code;
12399
12729
  if (code !== "external_modification" && code !== "remote_changed") return null;
@@ -12574,7 +12904,7 @@ var ProductDriftError = class extends Error {
12574
12904
  this.plan = plan;
12575
12905
  }
12576
12906
  };
12577
- function parseRequestError5(err) {
12907
+ function parseRequestError6(err) {
12578
12908
  if (!(err instanceof Error)) return { status: null, body: null };
12579
12909
  const match = err.message.match(/^API request failed: (\d{3}) .*? - ([\s\S]*)$/);
12580
12910
  if (!match) return { status: null, body: null };
@@ -12585,7 +12915,7 @@ function parseRequestError5(err) {
12585
12915
  }
12586
12916
  }
12587
12917
  function toConflictError5(err) {
12588
- const { status, body } = parseRequestError5(err);
12918
+ const { status, body } = parseRequestError6(err);
12589
12919
  if (status !== 409 || !isPlainObject(body)) return null;
12590
12920
  const code = body.code;
12591
12921
  if (code !== "external_modification" && code !== "remote_changed") return null;
@@ -12784,6 +13114,25 @@ var ProductsNamespace = class {
12784
13114
  async pullFpo(name) {
12785
13115
  return pullFpo(this.getClient(), name);
12786
13116
  }
13117
+ /**
13118
+ * One request for the first page of every activity source a product has:
13119
+ * conversations per conversational surface, executions per distinct agent.
13120
+ * Rows, cursors and `hasMore` match the per-source list endpoints, so a
13121
+ * caller continues any source with that source's own endpoint. A source that
13122
+ * fails carries an `error` instead of failing the response.
13123
+ *
13124
+ * @example
13125
+ * ```typescript
13126
+ * const { data } = await Runtype.products.activity('prd_123', { limit: 25 })
13127
+ * for (const surface of data.surfaces) console.log(surface.surfaceId, surface.data.length)
13128
+ * ```
13129
+ */
13130
+ async activity(productId, options = {}) {
13131
+ return this.getClient().get(
13132
+ `/products/${encodeURIComponent(productId)}/activity`,
13133
+ options.limit === void 0 ? void 0 : { limit: String(options.limit) }
13134
+ );
13135
+ }
12787
13136
  };
12788
13137
 
12789
13138
  // src/surfaces-ensure.ts
@@ -12884,7 +13233,7 @@ var SurfaceDriftError = class extends Error {
12884
13233
  this.plan = plan;
12885
13234
  }
12886
13235
  };
12887
- function parseRequestError6(err) {
13236
+ function parseRequestError7(err) {
12888
13237
  if (!(err instanceof Error)) return { status: null, body: null };
12889
13238
  const match = err.message.match(/^API request failed: (\d{3}) .*? - ([\s\S]*)$/);
12890
13239
  if (!match) return { status: null, body: null };
@@ -12895,7 +13244,7 @@ function parseRequestError6(err) {
12895
13244
  }
12896
13245
  }
12897
13246
  function toConflictError6(err) {
12898
- const { status, body } = parseRequestError6(err);
13247
+ const { status, body } = parseRequestError7(err);
12899
13248
  if (status !== 409 || !isPlainObject(body)) return null;
12900
13249
  const code = body.code;
12901
13250
  if (code !== "external_modification" && code !== "remote_changed") return null;
@@ -13067,11 +13416,11 @@ var RuntypeClient = class {
13067
13416
  /**
13068
13417
  * Generic PUT request
13069
13418
  */
13070
- async put(path, data) {
13419
+ async put(path, data, extraHeaders) {
13071
13420
  const url = this.buildUrl(path);
13072
13421
  const response = await this.makeRequest(url, {
13073
13422
  method: "PUT",
13074
- headers: this.headers,
13423
+ headers: { ...this.headers, ...extraHeaders },
13075
13424
  body: data ? JSON.stringify(data) : void 0
13076
13425
  });
13077
13426
  return response;
@@ -13091,11 +13440,12 @@ var RuntypeClient = class {
13091
13440
  /**
13092
13441
  * Generic DELETE request
13093
13442
  */
13094
- async delete(path) {
13443
+ async delete(path, data, extraHeaders) {
13095
13444
  const url = this.buildUrl(path);
13096
13445
  const response = await this.makeRequest(url, {
13097
13446
  method: "DELETE",
13098
- headers: this.headers
13447
+ headers: { ...this.headers, ...extraHeaders },
13448
+ body: data ? JSON.stringify(data) : void 0
13099
13449
  });
13100
13450
  return response;
13101
13451
  }
@@ -13548,6 +13898,180 @@ var Runtype = class {
13548
13898
  }
13549
13899
  };
13550
13900
 
13901
+ // src/agent-promotion.ts
13902
+ var MANIFEST_VERSION = 1;
13903
+ var RECEIPT_PAGE_SIZE = 50;
13904
+ var MAX_RECEIPT_PAGES = 20;
13905
+ var AgentPromotionError = class extends Error {
13906
+ constructor(message) {
13907
+ super(message);
13908
+ this.name = "AgentPromotionError";
13909
+ }
13910
+ };
13911
+ function assertManifest(manifest) {
13912
+ if (manifest?.manifest !== MANIFEST_VERSION) {
13913
+ throw new AgentPromotionError(
13914
+ `Unsupported promotion manifest version ${String(manifest?.manifest)}; expected ${MANIFEST_VERSION}.`
13915
+ );
13916
+ }
13917
+ }
13918
+ async function ensureInto(transport, body) {
13919
+ return transport.post("/agents/ensure", body);
13920
+ }
13921
+ async function prepareAgentPromotion(input) {
13922
+ if (input.alias === "live") {
13923
+ throw new AgentPromotionError(
13924
+ "prepare stages a candidate at a preview alias and never deploys: pass a non-live alias, then promote it with activate."
13925
+ );
13926
+ }
13927
+ const pulled = await input.source.get("/agents/pull", { name: input.name });
13928
+ const converged = await ensureInto(input.target, {
13929
+ name: input.name,
13930
+ definition: pulled.definition,
13931
+ deploy: { alias: input.alias },
13932
+ ...input.version ? { version: input.version } : {}
13933
+ });
13934
+ if (converged.result === "plan") {
13935
+ throw new AgentPromotionError("The target converge answered a plan; expected a write.");
13936
+ }
13937
+ const deployment = converged.deployment;
13938
+ if (!deployment?.versionId) {
13939
+ throw new AgentPromotionError(
13940
+ `The target converge did not stage a version at "${input.alias}"; nothing to promote.`
13941
+ );
13942
+ }
13943
+ return {
13944
+ manifest: MANIFEST_VERSION,
13945
+ name: input.name,
13946
+ createdAt: (/* @__PURE__ */ new Date()).toISOString(),
13947
+ source: {
13948
+ agentId: pulled.agentId,
13949
+ versionId: pulled.versionId,
13950
+ contentHash: pulled.contentHash,
13951
+ ...input.commit ? { commit: input.commit } : {}
13952
+ },
13953
+ target: {
13954
+ agentId: converged.agentId,
13955
+ versionId: deployment.versionId,
13956
+ alias: deployment.alias,
13957
+ revision: deployment.revision,
13958
+ contentHash: converged.contentHash
13959
+ }
13960
+ };
13961
+ }
13962
+ async function validateAgentPromotion(input) {
13963
+ assertManifest(input.manifest);
13964
+ const definition = input.definition ?? await repullStagedDefinition({
13965
+ ...input.source ? { source: input.source } : {},
13966
+ manifest: input.manifest
13967
+ });
13968
+ const planned = await ensureInto(input.target, {
13969
+ name: input.manifest.name,
13970
+ definition,
13971
+ dryRun: true,
13972
+ deploy: { alias: input.manifest.target.alias }
13973
+ });
13974
+ if (planned.result !== "plan") {
13975
+ throw new AgentPromotionError(`Expected a plan from the dry run, got '${planned.result}'.`);
13976
+ }
13977
+ const staged = await findStagedReceipt(input.target, input.manifest);
13978
+ if (!staged) {
13979
+ throw new AgentPromotionError(
13980
+ `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.`
13981
+ );
13982
+ }
13983
+ const refs = readReceiptRefs(staged);
13984
+ const unresolvedRefs = refs.filter((ref) => ref.resolvedId === null).map((ref) => ref.ref);
13985
+ return { ok: unresolvedRefs.length === 0, plan: planned, unresolvedRefs, refs };
13986
+ }
13987
+ async function repullStagedDefinition(input) {
13988
+ if (!input.source) {
13989
+ throw new AgentPromotionError(
13990
+ "validate needs the definition it planned: pass definition, or pass source credentials to re-pull it."
13991
+ );
13992
+ }
13993
+ const { name } = input.manifest;
13994
+ const pulled = await input.source.get("/agents/pull", { name });
13995
+ if (pulled.contentHash !== input.manifest.source.contentHash) {
13996
+ throw new AgentPromotionError(
13997
+ `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.`
13998
+ );
13999
+ }
14000
+ return pulled.definition;
14001
+ }
14002
+ async function findStagedReceipt(target, manifest) {
14003
+ const deployments = new AgentDeploymentsNamespace(() => target);
14004
+ let cursor;
14005
+ for (let page = 0; page < MAX_RECEIPT_PAGES; page += 1) {
14006
+ const answered = await deployments.list(manifest.target.agentId, {
14007
+ alias: manifest.target.alias,
14008
+ limit: RECEIPT_PAGE_SIZE,
14009
+ ...cursor ? { cursor } : {}
14010
+ });
14011
+ const found = answered.data.find(
14012
+ (receipt) => receipt.versionId === manifest.target.versionId
14013
+ );
14014
+ if (found) return found;
14015
+ const next = answered.pagination?.nextCursor;
14016
+ if (typeof next !== "string" || next.length === 0) return null;
14017
+ cursor = next;
14018
+ }
14019
+ return null;
14020
+ }
14021
+ function readReceiptRefs(receipt) {
14022
+ const dependencies = receipt?.dependencies;
14023
+ const refs = dependencies?.refs;
14024
+ if (!Array.isArray(refs)) return [];
14025
+ return refs.flatMap((entry) => {
14026
+ if (entry === null || typeof entry !== "object") return [];
14027
+ const row = entry;
14028
+ if (typeof row.ref !== "string") return [];
14029
+ return [
14030
+ {
14031
+ ref: row.ref,
14032
+ resolvedId: typeof row.resolvedId === "string" ? row.resolvedId : null,
14033
+ fingerprint: typeof row.fingerprint === "string" ? row.fingerprint : null
14034
+ }
14035
+ ];
14036
+ });
14037
+ }
14038
+ async function activateAgentPromotion(input) {
14039
+ assertManifest(input.manifest);
14040
+ const alias = input.alias ?? "live";
14041
+ const aliases = new AgentAliasesNamespace(() => input.target);
14042
+ const current = await aliases.get(input.manifest.target.agentId, alias).catch((error) => {
14043
+ if (error instanceof AgentAliasNotFoundError) return null;
14044
+ throw error;
14045
+ });
14046
+ return aliases.activate(input.manifest.target.agentId, alias, {
14047
+ versionId: input.manifest.target.versionId,
14048
+ ...current ? { revision: current.revision } : {},
14049
+ idempotencyKey: input.idempotencyKey ?? promotionIdempotencyKey(input.manifest, alias),
14050
+ ...input.reason ? { reason: input.reason } : {},
14051
+ promotion: {
14052
+ sourceAgentId: input.manifest.source.agentId,
14053
+ ...input.manifest.source.versionId ? { sourceVersionId: input.manifest.source.versionId } : {},
14054
+ sourceContentHash: input.manifest.source.contentHash,
14055
+ ...input.manifest.source.commit ? { sourceCommit: input.manifest.source.commit } : {}
14056
+ }
14057
+ });
14058
+ }
14059
+ function promotionIdempotencyKey(manifest, alias) {
14060
+ return `promote:${manifest.target.agentId}:${alias}:${manifest.target.versionId}`;
14061
+ }
14062
+ async function promoteAgent(input) {
14063
+ const manifest = await prepareAgentPromotion(input);
14064
+ const definition = await repullStagedDefinition({ source: input.source, manifest });
14065
+ const validation = await validateAgentPromotion({ target: input.target, manifest, definition });
14066
+ if (!input.activate) return { manifest, validation };
14067
+ const activation = await activateAgentPromotion({
14068
+ target: input.target,
14069
+ manifest,
14070
+ ...input.activate
14071
+ });
14072
+ return { manifest, validation, activation };
14073
+ }
14074
+
13551
14075
  // src/transform.ts
13552
14076
  function transformQueryParams(params) {
13553
14077
  const result = {};
@@ -13565,7 +14089,7 @@ function transformQueryParams(params) {
13565
14089
 
13566
14090
  // src/version.ts
13567
14091
  var FALLBACK_VERSION = "0.0.0";
13568
- var SDK_VERSION = "9.12.0".length > 0 ? "9.12.0" : FALLBACK_VERSION;
14092
+ var SDK_VERSION = "9.14.0".length > 0 ? "9.14.0" : FALLBACK_VERSION;
13569
14093
  var RUNTYPE_CLIENT_KIND = "sdk";
13570
14094
  var SDK_USER_AGENT = `runtype-sdk/${SDK_VERSION} (typescript)`;
13571
14095
 
@@ -13944,11 +14468,11 @@ var RuntypeClient2 = class {
13944
14468
  /**
13945
14469
  * Generic PUT request
13946
14470
  */
13947
- async put(path, data) {
14471
+ async put(path, data, extraHeaders) {
13948
14472
  const url = this.buildUrl(path);
13949
14473
  const response = await this.makeRequest(url, {
13950
14474
  method: "PUT",
13951
- headers: this.headers,
14475
+ headers: { ...this.headers, ...extraHeaders },
13952
14476
  body: data ? JSON.stringify(data) : void 0
13953
14477
  });
13954
14478
  return response;
@@ -13968,11 +14492,11 @@ var RuntypeClient2 = class {
13968
14492
  /**
13969
14493
  * Generic DELETE request
13970
14494
  */
13971
- async delete(path, data) {
14495
+ async delete(path, data, extraHeaders) {
13972
14496
  const url = this.buildUrl(path);
13973
14497
  const response = await this.makeRequest(url, {
13974
14498
  method: "DELETE",
13975
- headers: this.headers,
14499
+ headers: { ...this.headers, ...extraHeaders },
13976
14500
  body: data ? JSON.stringify(data) : void 0
13977
14501
  });
13978
14502
  return response;
@@ -14834,8 +15358,16 @@ var STEP_TYPE_TO_METHOD = {
14834
15358
  };
14835
15359
  // Annotate the CommonJS export names for ESM import in node:
14836
15360
  0 && (module.exports = {
15361
+ AgentAliasDependencyError,
15362
+ AgentAliasNotFoundError,
15363
+ AgentAliasPreviewLimitError,
15364
+ AgentAliasRevisionMismatchError,
15365
+ AgentAliasRevisionRequiredError,
15366
+ AgentAliasesNamespace,
15367
+ AgentDeploymentsNamespace,
14837
15368
  AgentDriftError,
14838
15369
  AgentEnsureConflictError,
15370
+ AgentPromotionError,
14839
15371
  AgentVersionsEndpoint,
14840
15372
  AgentsEndpoint,
14841
15373
  AgentsNamespace,
@@ -14857,6 +15389,7 @@ var STEP_TYPE_TO_METHOD = {
14857
15389
  DEFAULT_RECOVERY_AFTER_EMPTY_SESSIONS,
14858
15390
  DEFAULT_STALL_STOP_AFTER,
14859
15391
  DispatchEndpoint,
15392
+ ENSURE_RELEASE_DEPLOY_CONFLICT_MESSAGE,
14860
15393
  EvalBuilder,
14861
15394
  EvalEndpoint,
14862
15395
  EvalRunner,
@@ -14874,6 +15407,7 @@ var STEP_TYPE_TO_METHOD = {
14874
15407
  FlowsNamespace,
14875
15408
  IntegrationsEndpoint,
14876
15409
  LEDGER_ARTIFACT_LINE_PREFIX,
15410
+ LIVE_AGENT_ALIAS,
14877
15411
  LogsEndpoint,
14878
15412
  ModelConfigsEndpoint,
14879
15413
  ProductDriftError,
@@ -14910,6 +15444,8 @@ var STEP_TYPE_TO_METHOD = {
14910
15444
  TypedRecordsScope,
14911
15445
  UNIFIED_EVENTS_QUERY,
14912
15446
  UsersEndpoint,
15447
+ activateAgentPromotion,
15448
+ agentAliasErrorCode,
14913
15449
  applyGeneratedRuntimeToolProposalToDispatchRequest,
14914
15450
  attachRuntimeToolsToDispatchRequest,
14915
15451
  buildAgentAdmissionHeaders,
@@ -14987,7 +15523,10 @@ var STEP_TYPE_TO_METHOD = {
14987
15523
  parseLedgerArtifactRelativePath,
14988
15524
  parseOffloadedOutputId,
14989
15525
  parseSSEChunk,
15526
+ prepareAgentPromotion,
14990
15527
  processStream,
15528
+ promoteAgent,
15529
+ promotionIdempotencyKey,
14991
15530
  pullEval,
14992
15531
  pullFpo,
14993
15532
  ranStep,
@@ -15005,6 +15544,7 @@ var STEP_TYPE_TO_METHOD = {
15005
15544
  unregisterWorkflowHook,
15006
15545
  usedNoTools,
15007
15546
  validJson,
15547
+ validateAgentPromotion,
15008
15548
  withDetachedReconnect,
15009
15549
  withUnifiedEvents
15010
15550
  });