@relayfx/sdk 0.3.5 → 0.3.6

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.
@@ -4,7 +4,7 @@ import {
4
4
  Service,
5
5
  Service1 as Service2,
6
6
  StateVersionConflict
7
- } from "./index-cyfx5y3r.js";
7
+ } from "./index-mtvz1bjn.js";
8
8
  import"./index-nb39b5ae.js";
9
9
 
10
10
  // src/http-server.ts
@@ -8,7 +8,7 @@ import {
8
8
  SqlFailure,
9
9
  make,
10
10
  normalizeAcquisitionCause
11
- } from "./index-cq8t8ka1.js";
11
+ } from "./index-e02krw55.js";
12
12
 
13
13
  // src/migration-errors.ts
14
14
  import { Cause, Effect, Function } from "effect";
@@ -51,7 +51,7 @@ import {
51
51
  followExecutionFrom,
52
52
  inputSchemaRef,
53
53
  outputSchemaRef
54
- } from "./index-cyfx5y3r.js";
54
+ } from "./index-mtvz1bjn.js";
55
55
  import {
56
56
  __export
57
57
  } from "./index-nb39b5ae.js";
@@ -10083,6 +10083,13 @@ var cancel3 = Effect42.fn("WaitService.cancel.call")(function* (input) {
10083
10083
  const service = yield* Service42;
10084
10084
  return yield* service.cancel(input);
10085
10085
  });
10086
+ // ../runtime/src/tool/tool-runtime-identifiers.ts
10087
+ var scopedPart = (value) => encodeURIComponent(value);
10088
+ var toolScope = (executionId, toolCallId) => `${scopedPart(executionId)}:${scopedPart(toolCallId)}`;
10089
+ var eventId = (executionId, toolCallId, kind) => exports_ids_schema.EventId.make(`event:${toolScope(executionId, toolCallId)}:${kind}`);
10090
+ var waitId = (kind, executionId, toolCallId) => exports_ids_schema.WaitId.make(`wait:${kind}:${toolScope(executionId, toolCallId)}`);
10091
+ var Identifiers = { eventId, waitId };
10092
+
10086
10093
  // ../runtime/src/tool/tool-runtime-service.ts
10087
10094
  var permissionNames = (permissions) => HashSet3.fromIterable(permissions.map((permission) => permission.name));
10088
10095
  var requiredPermissionNames = (tool) => tool.requiredPermissions ?? tool.definition.permissions.map((permission) => permission.name);
@@ -10117,7 +10124,7 @@ var preserveToolError = (toolName, error5) => {
10117
10124
  };
10118
10125
  var preserveRecordResultError = (error5) => error5._tag === "ToolRuntimeError" ? error5 : mapRepositoryError3(error5);
10119
10126
  var requestedEvent = (input) => ({
10120
- id: exports_ids_schema.EventId.make(`event:${input.call.id}:tool-requested`),
10127
+ id: Identifiers.eventId(input.executionId, input.call.id, "tool-requested"),
10121
10128
  execution_id: input.executionId,
10122
10129
  type: "tool.call.requested",
10123
10130
  sequence: input.eventSequence,
@@ -10135,7 +10142,7 @@ var ensureToolEvent = (eventLog, event) => eventLog.findByCursor({ executionId:
10135
10142
  onSome: (existing) => sameToolEventPayload(existing, event) ? Effect43.void : Effect43.fail(ToolRuntimeError.make({ message: "EventLogError" }))
10136
10143
  })));
10137
10144
  var resultEvent = (input, result, sequence) => ({
10138
- id: exports_ids_schema.EventId.make(`event:${input.call.id}:tool-result`),
10145
+ id: Identifiers.eventId(input.executionId, input.call.id, "tool-result"),
10139
10146
  execution_id: input.executionId,
10140
10147
  type: "tool.result.received",
10141
10148
  sequence,
@@ -10204,11 +10211,11 @@ var finalToolResult = (tool, input, idempotencyKey) => Effect43.gen(function* ()
10204
10211
  output: jsonValue2(output)
10205
10212
  };
10206
10213
  });
10207
- var approvalWaitId = (input) => exports_ids_schema.WaitId.make(`wait:approval:${input.call.id}`);
10208
- var permissionWaitId = (input) => exports_ids_schema.WaitId.make(`wait:permission:${input.call.id}`);
10214
+ var approvalWaitId = (input) => Identifiers.waitId("approval", input.executionId, input.call.id);
10215
+ var permissionWaitId = (input) => Identifiers.waitId("permission", input.executionId, input.call.id);
10209
10216
  var mapWaitServiceError = (error5) => ToolRuntimeError.make({ message: error5.message });
10210
- var approvalRequestedEvent = (input, waitId) => ({
10211
- id: exports_ids_schema.EventId.make(`event:${input.call.id}:approval-requested`),
10217
+ var approvalRequestedEvent = (input, waitId2) => ({
10218
+ id: Identifiers.eventId(input.executionId, input.call.id, "approval-requested"),
10212
10219
  execution_id: input.executionId,
10213
10220
  type: "tool.approval.requested",
10214
10221
  sequence: input.eventSequence + 2,
@@ -10216,13 +10223,13 @@ var approvalRequestedEvent = (input, waitId) => ({
10216
10223
  data: {
10217
10224
  tool_call_id: input.call.id,
10218
10225
  tool_name: input.call.name,
10219
- wait_id: waitId,
10226
+ wait_id: waitId2,
10220
10227
  input: input.call.input
10221
10228
  },
10222
10229
  created_at: input.createdAt + 2
10223
10230
  });
10224
10231
  var approvalResolvedEvent = (input, wait, approved) => ({
10225
- id: exports_ids_schema.EventId.make(`event:${input.call.id}:approval-resolved`),
10232
+ id: Identifiers.eventId(input.executionId, input.call.id, "approval-resolved"),
10226
10233
  execution_id: input.executionId,
10227
10234
  type: "tool.approval.resolved",
10228
10235
  sequence: input.eventSequence + 1,
@@ -10237,14 +10244,14 @@ var approvalResolvedEvent = (input, wait, approved) => ({
10237
10244
  created_at: input.createdAt + 1
10238
10245
  });
10239
10246
  var deniedReason = (state) => state === "timed_out" ? "Tool approval timed out" : state === "cancelled" ? "Tool approval cancelled" : "Tool approval denied";
10240
- var waitRequested = (input, waitId) => Effect43.fail(ToolExecutionWaitRequested.make({ tool_name: input.call.name, wait_id: waitId }));
10247
+ var waitRequested = (input, waitId2) => Effect43.fail(ToolExecutionWaitRequested.make({ tool_name: input.call.name, wait_id: waitId2 }));
10241
10248
  var hasPermissionApprovalBypass = (waits, input) => waits.get(permissionWaitId(input)).pipe(Effect43.mapError(mapWaitServiceError), Effect43.map((wait) => wait !== undefined && wait.state === "resolved" && wait.metadata.kind === "tool-permission" && wait.metadata.tool_call_id === input.call.id && wait.metadata.tool_name === input.call.name && (wait.metadata.answer === "Approved" || wait.metadata.answer === "Always")));
10242
10249
  var resolveApproval = (waits, eventLog, input) => Effect43.gen(function* () {
10243
- const waitId = approvalWaitId(input);
10244
- const existing = yield* waits.get(waitId).pipe(Effect43.mapError(mapWaitServiceError));
10250
+ const waitId2 = approvalWaitId(input);
10251
+ const existing = yield* waits.get(waitId2).pipe(Effect43.mapError(mapWaitServiceError));
10245
10252
  if (existing === undefined) {
10246
10253
  yield* waits.createDetached({
10247
- waitId,
10254
+ waitId: waitId2,
10248
10255
  executionId: input.executionId,
10249
10256
  mode: "event",
10250
10257
  correlationKey: input.call.id,
@@ -10257,11 +10264,11 @@ var resolveApproval = (waits, eventLog, input) => Effect43.gen(function* () {
10257
10264
  eventSequence: input.eventSequence + 1,
10258
10265
  createdAt: input.createdAt
10259
10266
  }).pipe(Effect43.mapError(mapWaitServiceError));
10260
- yield* appendIdempotentTo(eventLog, approvalRequestedEvent(input, waitId)).pipe(Effect43.mapError(mapEventLogError2));
10261
- return yield* waitRequested(input, waitId);
10267
+ yield* appendIdempotentTo(eventLog, approvalRequestedEvent(input, waitId2)).pipe(Effect43.mapError(mapEventLogError2));
10268
+ return yield* waitRequested(input, waitId2);
10262
10269
  }
10263
10270
  if (existing.state === "open") {
10264
- return yield* waitRequested(input, waitId);
10271
+ return yield* waitRequested(input, waitId2);
10265
10272
  }
10266
10273
  const approved = existing.state === "resolved" && existing.metadata.approved === true;
10267
10274
  yield* appendIdempotentTo(eventLog, approvalResolvedEvent(input, existing, approved)).pipe(Effect43.mapError(mapEventLogError2));
@@ -10356,7 +10363,7 @@ var placedTool = (modelTool, placement, options = {}) => ({
10356
10363
  });
10357
10364
  var clientTool = Function7.dual((args) => args.length > 1 || args.length === 1 && typeof args[0] === "object" && args[0] !== null && ("name" in args[0]), (modelTool, options = {}) => placedTool(modelTool, { kind: "client" }, options));
10358
10365
  var remoteTool = Function7.dual(2, (modelTool, options) => placedTool(modelTool, { kind: "remote", queue: options.queue }, options));
10359
- var placementWaitId = (input) => exports_ids_schema.WaitId.make(`wait:tool:${input.call.id}`);
10366
+ var placementWaitId = (input) => Identifiers.waitId("tool", input.executionId, input.call.id);
10360
10367
  var placementFailureResult = (input, message) => ({
10361
10368
  call_id: input.call.id,
10362
10369
  output: null,
@@ -10376,11 +10383,11 @@ var externalOutcomeResult = (call, input) => {
10376
10383
  return Schema40.decodeUnknownEffect(exports_tool_schema.resultSchema(call.definition.output_schema))(call.externalOutcome.output).pipe(Effect43.map((output) => ({ call_id: input.call.id, output: jsonValue2(output) })), Effect43.catch((error5) => Effect43.succeed(placementFailureResult(input, `invalid ${placement} result: ${error5.message}`))));
10377
10384
  };
10378
10385
  var runExternalTool = (repository, waits, call, input) => Effect43.gen(function* () {
10379
- const waitId = placementWaitId(input);
10380
- let wait = yield* waits.get(waitId).pipe(Effect43.mapError(mapWaitServiceError));
10386
+ const waitId2 = placementWaitId(input);
10387
+ let wait = yield* waits.get(waitId2).pipe(Effect43.mapError(mapWaitServiceError));
10381
10388
  if (wait === undefined) {
10382
10389
  wait = yield* waits.createDetached({
10383
- waitId,
10390
+ waitId: waitId2,
10384
10391
  executionId: input.executionId,
10385
10392
  mode: "event",
10386
10393
  correlationKey: input.call.id,
@@ -10397,12 +10404,12 @@ var runExternalTool = (repository, waits, call, input) => Effect43.gen(function*
10397
10404
  const waitingCall = call.state === "requested" ? yield* repository.prepareExternalWait({
10398
10405
  executionId: input.executionId,
10399
10406
  callId: input.call.id,
10400
- waitId,
10407
+ waitId: waitId2,
10401
10408
  availableAt: input.createdAt,
10402
10409
  updatedAt: input.createdAt
10403
10410
  }).pipe(Effect43.mapError(mapRepositoryError3)) : call;
10404
10411
  if (wait.state === "open")
10405
- return yield* waitRequested(input, waitId);
10412
+ return yield* waitRequested(input, waitId2);
10406
10413
  if (wait.state === "timed_out")
10407
10414
  return placementFailureResult(input, "Tool execution timed out");
10408
10415
  if (wait.state === "cancelled")
@@ -11462,10 +11469,10 @@ var presetMap = (agent) => new Map(Object.entries(agent.child_run_presets ?? {})
11462
11469
  ...preset.metadata === undefined ? {} : { metadata: preset.metadata }
11463
11470
  }
11464
11471
  ]));
11465
- var createJoinWait = Effect52.fn("SpawnChildRunTool.createJoinWait")(function* (config, input, id, waitId, createdAt) {
11472
+ var createJoinWait = Effect52.fn("SpawnChildRunTool.createJoinWait")(function* (config, input, id, waitId2, createdAt) {
11466
11473
  const eventSequence = yield* nextEventSequence(config.eventLog, input.execution_id);
11467
11474
  yield* config.waits.createDetached({
11468
- waitId,
11475
+ waitId: waitId2,
11469
11476
  executionId: input.execution_id,
11470
11477
  mode: "child",
11471
11478
  correlationKey: id,
@@ -11477,7 +11484,7 @@ var createJoinWait = Effect52.fn("SpawnChildRunTool.createJoinWait")(function* (
11477
11484
  createdAt
11478
11485
  }).pipe(Effect52.mapError(mapWaitError));
11479
11486
  });
11480
- var dispatchChild = Effect52.fn("SpawnChildRunTool.dispatchChild")(function* (config, input, id, definition, waitId) {
11487
+ var dispatchChild = Effect52.fn("SpawnChildRunTool.dispatchChild")(function* (config, input, id, definition, waitId2) {
11481
11488
  yield* config.dispatch({
11482
11489
  executionId: exports_ids_schema.ExecutionId.make(id),
11483
11490
  rootAddressId: input.address_id,
@@ -11493,7 +11500,7 @@ var dispatchChild = Effect52.fn("SpawnChildRunTool.dispatchChild")(function* (co
11493
11500
  metadata: {
11494
11501
  parent_execution_id: input.execution_id,
11495
11502
  child_execution_id: id,
11496
- parent_wait_id: waitId
11503
+ parent_wait_id: waitId2
11497
11504
  }
11498
11505
  }).pipe(Effect52.mapError((error5) => ToolRuntimeError.make({ message: String(error5) })));
11499
11506
  });
@@ -11517,10 +11524,10 @@ var run3 = Effect52.fn("SpawnChildRunTool.run")(function* (config, activeToolNam
11517
11524
  if (enforceStaticOrDynamic)
11518
11525
  yield* ensureStaticOrDynamic(input);
11519
11526
  const id = childExecutionId(context);
11520
- const waitId = childWaitId(id);
11521
- const existingWait = yield* config.waits.get(waitId).pipe(Effect52.mapError(mapWaitError));
11527
+ const waitId2 = childWaitId(id);
11528
+ const existingWait = yield* config.waits.get(waitId2).pipe(Effect52.mapError(mapWaitError));
11522
11529
  if (existingWait?.state === "open") {
11523
- return yield* ToolExecutionWaitRequested.make({ tool_name: activeToolName, wait_id: waitId });
11530
+ return yield* ToolExecutionWaitRequested.make({ tool_name: activeToolName, wait_id: waitId2 });
11524
11531
  }
11525
11532
  if (existingWait !== undefined)
11526
11533
  return yield* resultFromTerminal(config, id, existingWait);
@@ -11550,9 +11557,9 @@ var run3 = Effect52.fn("SpawnChildRunTool.run")(function* (config, activeToolNam
11550
11557
  createdAt: context.createdAt + 1
11551
11558
  }).pipe(Effect52.mapError((error5) => mapChildRunError(activeToolName, error5)));
11552
11559
  }
11553
- yield* createJoinWait(config, spawn, id, waitId, context.createdAt + 2);
11554
- yield* dispatchChild(config, spawn, id, definition, waitId);
11555
- return yield* ToolExecutionWaitRequested.make({ tool_name: activeToolName, wait_id: waitId });
11560
+ yield* createJoinWait(config, spawn, id, waitId2, context.createdAt + 2);
11561
+ yield* dispatchChild(config, spawn, id, definition, waitId2);
11562
+ return yield* ToolExecutionWaitRequested.make({ tool_name: activeToolName, wait_id: waitId2 });
11556
11563
  });
11557
11564
  var registeredTool = (config) => tool(toolName, {
11558
11565
  description: "Spawn a durable child run and wait for its terminal output.",
@@ -13353,9 +13360,9 @@ var ActivityNames = {
13353
13360
  accept: `${StartExecutionWorkflowName}/Accept`,
13354
13361
  cancel: (turn) => `${StartExecutionWorkflowName}/Cancel/${turn}`,
13355
13362
  checkCancel: (turn) => `${StartExecutionWorkflowName}/CheckCancel/${turn}`,
13356
- loadWaitBeforeSleep: (waitId) => `${StartExecutionWorkflowName}/LoadWaitBeforeSleep/${waitId}`,
13357
- loadWaitAfterWake: (waitId) => `${StartExecutionWorkflowName}/LoadWaitAfterWake/${waitId}`,
13358
- markWaiting: (waitId) => `${StartExecutionWorkflowName}/MarkWaiting/${waitId}`,
13363
+ loadWaitBeforeSleep: (waitId2) => `${StartExecutionWorkflowName}/LoadWaitBeforeSleep/${waitId2}`,
13364
+ loadWaitAfterWake: (waitId2) => `${StartExecutionWorkflowName}/LoadWaitAfterWake/${waitId2}`,
13365
+ markWaiting: (waitId2) => `${StartExecutionWorkflowName}/MarkWaiting/${waitId2}`,
13359
13366
  ensureWorkspace: `${StartExecutionWorkflowName}/EnsureWorkspace`,
13360
13367
  suspendWorkspace: (key4) => `${StartExecutionWorkflowName}/SuspendWorkspace/${key4}`,
13361
13368
  resumeWorkspace: (key4) => `${StartExecutionWorkflowName}/ResumeWorkspace/${key4}`,
@@ -13410,7 +13417,7 @@ var mapChildExecutionRepositoryError = (error5) => ExecutionWorkflowFailed.make(
13410
13417
  var mapSkillRegistryError = (error5) => ExecutionWorkflowFailed.make({ message: error5.message });
13411
13418
  var mapEventLogError6 = (error5) => ExecutionWorkflowFailed.make({ message: error5._tag });
13412
13419
  var mapWorkspaceError = (error5) => ExecutionWorkflowFailed.make({ message: error5._tag });
13413
- var waitSignal = (waitId) => DurableDeferred.make(`Relay/Execution/Wait/${waitId}`, {
13420
+ var waitSignal = (waitId2) => DurableDeferred.make(`Relay/Execution/Wait/${waitId2}`, {
13414
13421
  success: WaitSignal,
13415
13422
  error: ExecutionWorkflowFailed
13416
13423
  });
@@ -13484,8 +13491,8 @@ var acceptExecution = (input) => Activity.make({
13484
13491
  });
13485
13492
  var terminalExecutionStatuses = new Set(["completed", "failed", "cancelled"]);
13486
13493
  var waitIdFromRecord = (record2) => {
13487
- const waitId = record2.metadata.wait_id;
13488
- return typeof waitId === "string" ? exports_ids_schema.WaitId.make(waitId) : undefined;
13494
+ const waitId2 = record2.metadata.wait_id;
13495
+ return typeof waitId2 === "string" ? exports_ids_schema.WaitId.make(waitId2) : undefined;
13489
13496
  };
13490
13497
  var prepareCancellation = Effect67.fn("ExecutionWorkflow.prepareCancellation")(function* (input) {
13491
13498
  const repository = yield* exports_execution_repository.Service;
@@ -13633,11 +13640,11 @@ var loadCancellationRequested = (input, turn) => Activity.make({
13633
13640
  return record2?.metadata?.cancellation_requested === true;
13634
13641
  })
13635
13642
  });
13636
- var loadWait = (name, waitId) => Activity.make({
13643
+ var loadWait = (name, waitId2) => Activity.make({
13637
13644
  name,
13638
13645
  success: Schema61.UndefinedOr(WaitSnapshot),
13639
13646
  error: ExecutionWorkflowFailed,
13640
- execute: get11(waitId).pipe(Effect67.map((record2) => record2 === undefined ? undefined : toWaitSnapshot(record2)), Effect67.mapError(mapWaitError2))
13647
+ execute: get11(waitId2).pipe(Effect67.map((record2) => record2 === undefined ? undefined : toWaitSnapshot(record2)), Effect67.mapError(mapWaitError2))
13641
13648
  });
13642
13649
  var markWaiting = (input, repository, wait) => Activity.make({
13643
13650
  name: ActivityNames.markWaiting(wait.id),
@@ -13757,7 +13764,7 @@ var failWorkspace = (input, error5) => fail({
13757
13764
  }).pipe(Effect67.catch(() => Effect67.void));
13758
13765
  var attachWorkspace = (input) => attach({ executionId: input.execution_id, now: input.started_at }).pipe(Effect67.mapError(mapWorkspaceError));
13759
13766
  var sessionEntryScope = Function13.dual(2, (input, turn) => `${input.execution_id}:${workflowGenerationForStart(input)}:complete:${turn}`);
13760
- var completeExecution = (input, waitId, waitState, workspaceRuntimeLayer, turn, pendingSuspension) => Activity.make({
13767
+ var completeExecution = (input, waitId2, waitState, workspaceRuntimeLayer, turn, pendingSuspension) => Activity.make({
13761
13768
  name: ActivityNames.complete(turn),
13762
13769
  success: exports_execution_schema.Execution,
13763
13770
  error: ExecutionWorkflowFailed,
@@ -13811,8 +13818,8 @@ var completeExecution = (input, waitId, waitState, workspaceRuntimeLayer, turn,
13811
13818
  const program = activeProgram.pipe(Effect67.map((result) => ({
13812
13819
  metadata: {
13813
13820
  ...result.metadata,
13814
- ...waitId === undefined ? {} : { wait_id: waitId },
13815
- ...waitId === undefined || waitState === undefined ? {} : { wait_state: waitState }
13821
+ ...waitId2 === undefined ? {} : { wait_id: waitId2 },
13822
+ ...waitId2 === undefined || waitState === undefined ? {} : { wait_state: waitState }
13816
13823
  },
13817
13824
  nextEventSequence: result.nextEventSequence
13818
13825
  })), Effect67.catchTag("AgentLoopWaitRequested", (wait) => Effect67.succeed({
@@ -13906,8 +13913,8 @@ var terminalOutput = (execution) => {
13906
13913
  const output = execution.metadata?.model_output;
13907
13914
  return typeof output === "string" ? [exports_content_schema.text(output)] : [];
13908
13915
  };
13909
- var missingWait = (waitId) => ExecutionWorkflowFailed.make({ message: `Wait not found: ${waitId}` });
13910
- var stillOpen = (waitId) => ExecutionWorkflowFailed.make({ message: `Wait remained open after wake: ${waitId}` });
13916
+ var missingWait = (waitId2) => ExecutionWorkflowFailed.make({ message: `Wait not found: ${waitId2}` });
13917
+ var stillOpen = (waitId2) => ExecutionWorkflowFailed.make({ message: `Wait remained open after wake: ${waitId2}` });
13911
13918
  var resolveWaitState = Effect67.fn("ExecutionWorkflow.resolveWaitState")(function* (input, repository) {
13912
13919
  if (input.wait_id === undefined)
13913
13920
  return;
@@ -13930,32 +13937,32 @@ var resolveWaitState = Effect67.fn("ExecutionWorkflow.resolveWaitState")(functio
13930
13937
  return afterTerminal;
13931
13938
  });
13932
13939
  var waitIdFromExecution = (execution) => {
13933
- const waitId = execution.metadata?.wait_id;
13934
- return typeof waitId === "string" ? exports_ids_schema.WaitId.make(waitId) : undefined;
13940
+ const waitId2 = execution.metadata?.wait_id;
13941
+ return typeof waitId2 === "string" ? exports_ids_schema.WaitId.make(waitId2) : undefined;
13935
13942
  };
13936
13943
  var pendingSuspensionFromExecution = (execution) => {
13937
13944
  const pending = execution.metadata?.pending_agent_suspension;
13938
13945
  return Schema61.decodeUnknownOption(exports_agent_event.AgentSuspended)(pending).pipe(Option15.getOrUndefined);
13939
13946
  };
13940
- var finishCancelledWait = Effect67.fn("ExecutionWorkflow.finishCancelledWait")(function* (startInput, turn, waitId) {
13947
+ var finishCancelledWait = Effect67.fn("ExecutionWorkflow.finishCancelledWait")(function* (startInput, turn, waitId2) {
13941
13948
  const cancelled = yield* cancelExecution(startInput, turn, "wait cancelled");
13942
13949
  yield* releaseWorkspace(startInput);
13943
13950
  yield* notifyParent(startInput, "cancelled", []);
13944
13951
  return {
13945
13952
  execution_id: cancelled.id,
13946
13953
  status: cancelled.status,
13947
- wait_id: waitId,
13954
+ wait_id: waitId2,
13948
13955
  wait_state: "cancelled",
13949
13956
  ...cancelled.metadata === undefined ? {} : { metadata: cancelled.metadata }
13950
13957
  };
13951
13958
  });
13952
- var continueAsNew = (startInput, turn, waitId, pendingSuspension) => Activity.make({
13959
+ var continueAsNew = (startInput, turn, waitId2, pendingSuspension) => Activity.make({
13953
13960
  name: ActivityNames.continueAsNew(turn),
13954
13961
  success: StartResult,
13955
13962
  error: ExecutionWorkflowError,
13956
13963
  execute: StartExecutionWorkflow.execute({
13957
13964
  ...startInput,
13958
- wait_id: waitId,
13965
+ wait_id: waitId2,
13959
13966
  resume_suspension: pendingSuspension,
13960
13967
  workflow_generation: workflowGenerationForStart(startInput) + 1
13961
13968
  })
@@ -14016,8 +14023,8 @@ var runWorkflow = Effect67.fn("ExecutionWorkflow.run")(function* (input) {
14016
14023
  break;
14017
14024
  if (turn >= maxWaitTurns)
14018
14025
  return yield* ExecutionWorkflowFailed.make({ message: "Agent wait turn limit exceeded" });
14019
- const waitId = waitIdFromExecution(execution);
14020
- if (waitId === undefined)
14026
+ const waitId2 = waitIdFromExecution(execution);
14027
+ if (waitId2 === undefined)
14021
14028
  return yield* ExecutionWorkflowFailed.make({ message: "Waiting execution missing wait id" });
14022
14029
  pendingSuspension = pendingSuspensionFromExecution(execution);
14023
14030
  if (pendingSuspension === undefined) {
@@ -14027,14 +14034,14 @@ var runWorkflow = Effect67.fn("ExecutionWorkflow.run")(function* (input) {
14027
14034
  yield* failIncompatibleCheckpoint(startInput, error5);
14028
14035
  return yield* error5;
14029
14036
  }
14030
- activeWaitId = waitId;
14031
- waitState = yield* resolveWaitState({ ...startInput, wait_id: waitId }, repository);
14037
+ activeWaitId = waitId2;
14038
+ waitState = yield* resolveWaitState({ ...startInput, wait_id: waitId2 }, repository);
14032
14039
  if (waitState === "cancelled") {
14033
- return yield* finishCancelledWait(startInput, turn + 1, waitId);
14040
+ return yield* finishCancelledWait(startInput, turn + 1, waitId2);
14034
14041
  }
14035
14042
  turn += 1;
14036
14043
  if (continueAsNewAfterTurns !== undefined && turn >= continueAsNewAfterTurns) {
14037
- return yield* continueAsNew(startInput, turn, waitId, pendingSuspension);
14044
+ return yield* continueAsNew(startInput, turn, waitId2, pendingSuspension);
14038
14045
  }
14039
14046
  }
14040
14047
  yield* releaseWorkspace(startInput);
@@ -14053,11 +14060,11 @@ var awaitCanonicalSettledResult = Effect67.fn("ExecutionWorkflow.awaitCanonicalS
14053
14060
  until: (record2) => record2?.status === "waiting" || record2 !== undefined && terminalExecutionStatuses.has(record2.status)
14054
14061
  }));
14055
14062
  const canonicalWaitId = execution?.metadata?.wait_id;
14056
- const waitId = typeof canonicalWaitId === "string" ? exports_ids_schema.WaitId.make(canonicalWaitId) : input.wait_id;
14063
+ const waitId2 = typeof canonicalWaitId === "string" ? exports_ids_schema.WaitId.make(canonicalWaitId) : input.wait_id;
14057
14064
  const result = {
14058
14065
  execution_id: input.execution_id,
14059
14066
  status: execution?.status ?? "waiting",
14060
- ...waitId === undefined ? {} : { wait_id: waitId },
14067
+ ...waitId2 === undefined ? {} : { wait_id: waitId2 },
14061
14068
  ...execution?.metadata === undefined ? {} : { metadata: execution.metadata }
14062
14069
  };
14063
14070
  return result;
@@ -14095,14 +14102,14 @@ var startRequest = Effect67.fn("ExecutionWorkflow.startRequest")(function* (inpu
14095
14102
  }
14096
14103
  const workflowExecutionId2 = yield* activeWorkflowExecutionIdForExecution(input.execution_id);
14097
14104
  const existingWaitId = existing.metadata?.wait_id;
14098
- const waitId = typeof existingWaitId === "string" ? exports_ids_schema.WaitId.make(existingWaitId) : undefined;
14099
- if (existing.status === "waiting" && waitId !== undefined) {
14100
- const wait = yield* get11(waitId).pipe(Effect67.mapError(mapWaitError2));
14105
+ const waitId2 = typeof existingWaitId === "string" ? exports_ids_schema.WaitId.make(existingWaitId) : undefined;
14106
+ if (existing.status === "waiting" && waitId2 !== undefined) {
14107
+ const wait = yield* get11(waitId2).pipe(Effect67.mapError(mapWaitError2));
14101
14108
  const state = wait === undefined ? undefined : terminalWaitState(toWaitSnapshot(wait));
14102
14109
  if (state !== undefined) {
14103
14110
  yield* signalWait({
14104
14111
  workflow_execution_id: workflowExecutionId2,
14105
- wait_id: waitId,
14112
+ wait_id: waitId2,
14106
14113
  state,
14107
14114
  signaled_at: wait?.resolvedAt ?? input.started_at
14108
14115
  });
@@ -14241,9 +14248,9 @@ var makeLayer = (signalDependencies) => Layer63.effect(Service62, Effect69.gen(f
14241
14248
  const findOpenByCorrelation = envelopes.findOpenByCorrelation;
14242
14249
  const wait = findOpenByCorrelation === undefined ? undefined : yield* findOpenByCorrelation(input.executionId, `inbox:${input.executionId}`).pipe(Effect69.mapError((error5) => InboxDeliveryError.make({ execution_id: input.executionId, message: error5.message })));
14243
14250
  if (wait?.state === "open") {
14244
- const waitId = wait.id;
14251
+ const waitId2 = wait.id;
14245
14252
  const sequence = yield* nextSequence(eventLog, input.executionId).pipe(Effect69.mapError((error5) => InboxDeliveryError.make({ execution_id: input.executionId, message: error5._tag })));
14246
- const transition3 = yield* waits.wake({ waitId, resolvedAt: input.createdAt, eventSequence: sequence }).pipe(Effect69.mapError((error5) => InboxDeliveryError.make({
14253
+ const transition3 = yield* waits.wake({ waitId: waitId2, resolvedAt: input.createdAt, eventSequence: sequence }).pipe(Effect69.mapError((error5) => InboxDeliveryError.make({
14247
14254
  execution_id: input.executionId,
14248
14255
  message: error5._tag === "WaitNotFound" ? error5.wait_id : error5.message
14249
14256
  })));
@@ -14269,14 +14276,14 @@ var makeLayer = (signalDependencies) => Layer63.effect(Service62, Effect69.gen(f
14269
14276
  }),
14270
14277
  undrainedCount: (id) => repository.countUndrained(id).pipe(Effect69.mapError((error5) => InboxServiceError.make({ message: error5.message }))),
14271
14278
  reply: Effect69.fn("InboxService.reply")(function* (input) {
14272
- const waitId = exports_ids_schema.WaitId.make(input.replyToken);
14273
- const wait = yield* waits.get(waitId).pipe(Effect69.mapError(() => InboxReplyTokenInvalid.make({ reply_token: input.replyToken })));
14279
+ const waitId2 = exports_ids_schema.WaitId.make(input.replyToken);
14280
+ const wait = yield* waits.get(waitId2).pipe(Effect69.mapError(() => InboxReplyTokenInvalid.make({ reply_token: input.replyToken })));
14274
14281
  if (wait === undefined || wait.state !== "open" || wait.envelopeId === undefined)
14275
14282
  return yield* InboxReplyTokenInvalid.make({ reply_token: input.replyToken });
14276
14283
  const original = yield* envelopes.getEnvelope(wait.envelopeId).pipe(Effect69.mapError(() => InboxReplyTokenInvalid.make({ reply_token: input.replyToken })));
14277
14284
  if (original === undefined)
14278
14285
  return yield* InboxReplyTokenInvalid.make({ reply_token: input.replyToken });
14279
- const envelopeId = exports_ids_schema.EnvelopeId.make(`envelope:reply:${waitId}`);
14286
+ const envelopeId = exports_ids_schema.EnvelopeId.make(`envelope:reply:${waitId2}`);
14280
14287
  yield* envelopes.acceptEnvelope({
14281
14288
  envelope: {
14282
14289
  id: envelopeId,
@@ -14289,7 +14296,7 @@ var makeLayer = (signalDependencies) => Layer63.effect(Service62, Effect69.gen(f
14289
14296
  }
14290
14297
  }).pipe(Effect69.mapError((error5) => InboxDeliveryError.make({ execution_id: wait.executionId, message: error5.message })));
14291
14298
  const sequence = yield* nextSequence(eventLog, wait.executionId).pipe(Effect69.mapError((error5) => InboxDeliveryError.make({ execution_id: wait.executionId, message: error5._tag })));
14292
- const transition3 = yield* waits.wake({ waitId, resolvedAt: input.createdAt, eventSequence: sequence }).pipe(Effect69.mapError(() => InboxReplyTokenInvalid.make({ reply_token: input.replyToken })));
14299
+ const transition3 = yield* waits.wake({ waitId: waitId2, resolvedAt: input.createdAt, eventSequence: sequence }).pipe(Effect69.mapError(() => InboxReplyTokenInvalid.make({ reply_token: input.replyToken })));
14293
14300
  if (!transition3.transitioned)
14294
14301
  return yield* InboxReplyTokenInvalid.make({ reply_token: input.replyToken });
14295
14302
  if (signalDependencies !== undefined) {
@@ -14301,7 +14308,7 @@ var makeLayer = (signalDependencies) => Layer63.effect(Service62, Effect69.gen(f
14301
14308
  signaledAt: input.createdAt
14302
14309
  }).pipe(Effect69.provideService(exports_execution_repository.Service, signalDependencies.executionRepository), Effect69.mapError((error5) => InboxDeliveryError.make({ execution_id: wait.executionId, message: String(error5) })));
14303
14310
  }
14304
- return { envelope_id: envelopeId, execution_id: wait.executionId, wait_id: waitId };
14311
+ return { envelope_id: envelopeId, execution_id: wait.executionId, wait_id: waitId2 };
14305
14312
  })
14306
14313
  });
14307
14314
  }));
@@ -14454,8 +14461,8 @@ var registeredTool4 = (config) => tool(toolName4, {
14454
14461
  requiredPermissions: [permissionName4],
14455
14462
  metadata: { relay_core_tool: true },
14456
14463
  run: (input, context) => Effect72.gen(function* () {
14457
- const waitId = exports_ids_schema.WaitId.make(`wait:inbox:${context.call.id}`);
14458
- const existing = yield* config.waits.get(waitId).pipe(Effect72.mapError((error5) => ToolRuntimeError.make({ message: error5.message })));
14464
+ const waitId2 = exports_ids_schema.WaitId.make(`wait:inbox:${context.call.id}`);
14465
+ const existing = yield* config.waits.get(waitId2).pipe(Effect72.mapError((error5) => ToolRuntimeError.make({ message: error5.message })));
14459
14466
  const drain2 = () => config.inbox.drain({ executionId: context.executionId, drainId: context.call.id }).pipe(Effect72.mapError((error5) => ToolRuntimeError.make({ message: error5.message })));
14460
14467
  if (existing?.state === "timed_out")
14461
14468
  return { status: "timed_out", messages: [] };
@@ -14464,7 +14471,7 @@ var registeredTool4 = (config) => tool(toolName4, {
14464
14471
  return { status: "messages", messages: drained.map(project) };
14465
14472
  }
14466
14473
  if (existing?.state === "open")
14467
- return yield* ToolExecutionWaitRequested.make({ tool_name: toolName4, wait_id: waitId });
14474
+ return yield* ToolExecutionWaitRequested.make({ tool_name: toolName4, wait_id: waitId2 });
14468
14475
  const count = yield* config.inbox.undrainedCount(context.executionId).pipe(Effect72.mapError((error5) => ToolRuntimeError.make({ message: error5.message })));
14469
14476
  if (count > 0) {
14470
14477
  const drained = yield* drain2();
@@ -14472,7 +14479,7 @@ var registeredTool4 = (config) => tool(toolName4, {
14472
14479
  }
14473
14480
  if (existing === undefined)
14474
14481
  yield* config.waits.createDetached({
14475
- waitId,
14482
+ waitId: waitId2,
14476
14483
  executionId: context.executionId,
14477
14484
  mode: "event",
14478
14485
  correlationKey: `inbox:${context.executionId}`,
@@ -14482,13 +14489,13 @@ var registeredTool4 = (config) => tool(toolName4, {
14482
14489
  }).pipe(Effect72.mapError((error5) => ToolRuntimeError.make({ message: error5.message })));
14483
14490
  if ((yield* config.inbox.undrainedCount(context.executionId).pipe(Effect72.mapError((error5) => ToolRuntimeError.make({ message: error5.message })))) > 0) {
14484
14491
  const sequence = yield* config.eventLog.maxSequence(context.executionId).pipe(Effect72.map((value) => (value ?? -1) + 1), Effect72.mapError((error5) => ToolRuntimeError.make({ message: error5._tag })));
14485
- const transition3 = yield* config.waits.wake({ waitId, resolvedAt: context.createdAt, eventSequence: sequence }).pipe(Effect72.mapError((error5) => ToolRuntimeError.make({ message: error5._tag })));
14492
+ const transition3 = yield* config.waits.wake({ waitId: waitId2, resolvedAt: context.createdAt, eventSequence: sequence }).pipe(Effect72.mapError((error5) => ToolRuntimeError.make({ message: error5._tag })));
14486
14493
  if (transition3.transitioned) {
14487
14494
  const drained = yield* drain2();
14488
14495
  return { status: "messages", messages: drained.map(project) };
14489
14496
  }
14490
14497
  }
14491
- return yield* ToolExecutionWaitRequested.make({ tool_name: toolName4, wait_id: waitId });
14498
+ return yield* ToolExecutionWaitRequested.make({ tool_name: toolName4, wait_id: waitId2 });
14492
14499
  })
14493
14500
  });
14494
14501
 
@@ -14669,18 +14676,18 @@ var layer52 = Layer65.effect(Service64, Effect74.gen(function* () {
14669
14676
  });
14670
14677
  const envelope = envelopeFrom(input);
14671
14678
  const ready = readyFor(input, route);
14672
- const waitId = waitIdFor(input);
14679
+ const waitId2 = waitIdFor(input);
14673
14680
  const replayed = yield* repository.getEnvelope(envelope.id).pipe(Effect74.mapError(mapRepositoryError11));
14674
14681
  if (replayed !== undefined) {
14675
14682
  if (route.kind === "local-execution" && inbox._tag === "Some" && input.input.idempotency_key !== undefined) {
14676
- if (waitId !== undefined) {
14677
- yield* inbox.value.ensureReplyWait({ envelope, waitId }).pipe(Effect74.mapError((error5) => EnvelopeServiceError.make({ message: error5.message })));
14683
+ if (waitId2 !== undefined) {
14684
+ yield* inbox.value.ensureReplyWait({ envelope, waitId: waitId2 }).pipe(Effect74.mapError((error5) => EnvelopeServiceError.make({ message: error5.message })));
14678
14685
  }
14679
14686
  yield* inbox.value.deliver({
14680
14687
  executionId: exports_ids_schema.ExecutionId.make(route.route_key),
14681
14688
  envelope,
14682
14689
  idempotencyKey: input.input.idempotency_key,
14683
- ...waitId === undefined ? {} : { replyWaitId: waitId },
14690
+ ...waitId2 === undefined ? {} : { replyWaitId: waitId2 },
14684
14691
  eventSequence: input.eventSequence,
14685
14692
  createdAt: input.createdAt
14686
14693
  }).pipe(Effect74.mapError((error5) => EnvelopeServiceError.make({ message: error5.message })));
@@ -14688,7 +14695,7 @@ var layer52 = Layer65.effect(Service64, Effect74.gen(function* () {
14688
14695
  const recorded = {
14689
14696
  envelope_id: envelope.id,
14690
14697
  execution_id: envelope.execution_id,
14691
- ...waitId === undefined ? {} : { wait_id: waitId }
14698
+ ...waitId2 === undefined ? {} : { wait_id: waitId2 }
14692
14699
  };
14693
14700
  return Object.defineProperty(recorded, "route_kind", { value: route.kind });
14694
14701
  }
@@ -14701,17 +14708,17 @@ var layer52 = Layer65.effect(Service64, Effect74.gen(function* () {
14701
14708
  envelope,
14702
14709
  acceptance: {
14703
14710
  envelope,
14704
- ...waitId === undefined ? {} : { waitId }
14711
+ ...waitId2 === undefined ? {} : { waitId: waitId2 }
14705
14712
  },
14706
14713
  ...input.input.idempotency_key === undefined ? {} : { idempotencyKey: input.input.idempotency_key },
14707
- ...waitId === undefined ? {} : { replyWaitId: waitId },
14714
+ ...waitId2 === undefined ? {} : { replyWaitId: waitId2 },
14708
14715
  eventSequence: input.eventSequence,
14709
14716
  createdAt: input.createdAt
14710
14717
  }).pipe(Effect74.mapError((error5) => EnvelopeServiceError.make({ message: error5.message })));
14711
14718
  accepted2 = {
14712
14719
  envelope_id: envelope.id,
14713
14720
  execution_id: envelope.execution_id,
14714
- ...waitId === undefined ? {} : { wait_id: waitId }
14721
+ ...waitId2 === undefined ? {} : { wait_id: waitId2 }
14715
14722
  };
14716
14723
  if (delivery.deduplicated) {
14717
14724
  return Object.defineProperty(accepted2, "route_kind", { value: route.kind });
@@ -14719,7 +14726,7 @@ var layer52 = Layer65.effect(Service64, Effect74.gen(function* () {
14719
14726
  } else {
14720
14727
  accepted2 = yield* repository.acceptEnvelope({
14721
14728
  envelope,
14722
- ...waitId === undefined ? {} : { waitId },
14729
+ ...waitId2 === undefined ? {} : { waitId: waitId2 },
14723
14730
  ...ready === undefined ? {} : { ready }
14724
14731
  }).pipe(Effect74.mapError(mapRepositoryError11));
14725
14732
  }
@@ -14728,8 +14735,8 @@ var layer52 = Layer65.effect(Service64, Effect74.gen(function* () {
14728
14735
  if (ready !== undefined) {
14729
14736
  yield* appendIdempotentTo(eventLog, readyEvent(input, ready)).pipe(Effect74.mapError(mapEventLogError7));
14730
14737
  }
14731
- if (route.kind === "local-execution" && inbox._tag === "Some" && waitId !== undefined) {
14732
- yield* inbox.value.ensureReplyWait({ envelope, waitId }).pipe(Effect74.mapError((error5) => EnvelopeServiceError.make({ message: error5.message })));
14738
+ if (route.kind === "local-execution" && inbox._tag === "Some" && waitId2 !== undefined) {
14739
+ yield* inbox.value.ensureReplyWait({ envelope, waitId: waitId2 }).pipe(Effect74.mapError((error5) => EnvelopeServiceError.make({ message: error5.message })));
14733
14740
  }
14734
14741
  yield* recordEnvelopeSent(route.kind);
14735
14742
  return Object.defineProperty(accepted2, "route_kind", { value: route.kind });
@@ -14795,9 +14802,9 @@ var layerFromEpoch = (epoch) => exports_instructions.layer(epoch.baseline.length
14795
14802
  // ../runtime/src/agent/relay-permissions.ts
14796
14803
  import { Clock as Clock15, Effect as Effect76, Layer as Layer67, Option as Option16, Schema as Schema69 } from "effect";
14797
14804
  var jsonValue3 = (value) => Schema69.decodeUnknownSync(exports_shared_schema.JsonValue)(value === undefined ? null : value);
14798
- var waitIdForToolCall = (toolCallId) => exports_ids_schema.WaitId.make(`wait:permission:${toolCallId}`);
14805
+ var waitIdForToolCall = (executionId, toolCallId) => Identifiers.waitId("permission", executionId, toolCallId);
14799
14806
  var fallbackToolCallId = (request) => `${request.agentName}:${request.turn}:${request.tool}`;
14800
- var tokenFor = (request) => waitIdForToolCall(request.toolCallId ?? fallbackToolCallId(request));
14807
+ var tokenFor = (executionId, request) => waitIdForToolCall(executionId, request.toolCallId ?? fallbackToolCallId(request));
14801
14808
  var matchingRule = (rules, tool3, params) => {
14802
14809
  let matched;
14803
14810
  for (const rule of rules) {
@@ -14806,7 +14813,7 @@ var matchingRule = (rules, tool3, params) => {
14806
14813
  }
14807
14814
  return matched;
14808
14815
  };
14809
- var staticDecision = (ruleset, request) => {
14816
+ var staticDecision = (executionId, ruleset, request) => {
14810
14817
  const rule = matchingRule(ruleset.rules, request.tool, request.params);
14811
14818
  const level = rule?.level ?? ruleset.fallback ?? "ask";
14812
14819
  switch (level) {
@@ -14818,7 +14825,7 @@ var staticDecision = (ruleset, request) => {
14818
14825
  ...rule?.reason === undefined ? {} : { reason: rule.reason }
14819
14826
  };
14820
14827
  case "ask":
14821
- return { _tag: "Ask", token: tokenFor(request) };
14828
+ return { _tag: "Ask", token: tokenFor(executionId, request) };
14822
14829
  }
14823
14830
  };
14824
14831
  var evaluateDecision = Effect76.fn("RelayPermissions.evaluateDecision")(function* (config, request) {
@@ -14834,10 +14841,10 @@ var evaluateDecision = Effect76.fn("RelayPermissions.evaluateDecision")(function
14834
14841
  ...rule.reason === undefined ? {} : { reason: rule.reason }
14835
14842
  };
14836
14843
  case "ask":
14837
- return { _tag: "Ask", token: tokenFor(request) };
14844
+ return { _tag: "Ask", token: tokenFor(config.executionId, request) };
14838
14845
  }
14839
14846
  }
14840
- return staticDecision(config.ruleset, request);
14847
+ return staticDecision(config.executionId, config.ruleset, request);
14841
14848
  });
14842
14849
  var permissionError = (message) => exports_permissions.PermissionError.make({ message });
14843
14850
  var createdAtForSequence = (config, sequence) => config.startedAt + sequence - config.eventSequence;
@@ -14849,18 +14856,18 @@ var allocateEventSequence = Effect76.fn("RelayPermissions.allocateEventSequence"
14849
14856
  return sequence;
14850
14857
  });
14851
14858
  var resetAllocatorToLog = (config) => config.allocator.current.pipe(Effect76.flatMap((current2) => nextLoggedSequence(config.eventLog, config.executionId, current2)), Effect76.flatMap(config.allocator.resetTo));
14852
- var permissionRequestedCursor = (config, pending, waitId) => `${config.executionId}:permission:${pending.toolCallId ?? waitId}:requested`;
14859
+ var permissionRequestedCursor = (config, pending, waitId2) => `${config.executionId}:permission:${pending.toolCallId ?? waitId2}:requested`;
14853
14860
  var permissionResolvedCursor = (config, pending, wait) => `${config.executionId}:permission:${pending.toolCallId ?? wait.id}:resolved`;
14854
- var permissionRequestedEvent = (config, pending, waitId, sequence) => ({
14855
- id: exports_ids_schema.EventId.make(`event:${pending.toolCallId ?? waitId}:permission-requested`),
14861
+ var permissionRequestedEvent = (config, pending, waitId2, sequence) => ({
14862
+ id: Identifiers.eventId(config.executionId, pending.toolCallId ?? waitId2, "permission-requested"),
14856
14863
  execution_id: config.executionId,
14857
14864
  type: "permission.ask.requested",
14858
14865
  sequence,
14859
- cursor: permissionRequestedCursor(config, pending, waitId),
14866
+ cursor: permissionRequestedCursor(config, pending, waitId2),
14860
14867
  data: {
14861
14868
  tool_call_id: pending.toolCallId ?? pending.token,
14862
14869
  tool_name: pending.tool,
14863
- wait_id: waitId,
14870
+ wait_id: waitId2,
14864
14871
  input: jsonValue3(pending.params),
14865
14872
  agent_name: pending.agentName,
14866
14873
  scope: config.scope
@@ -14887,7 +14894,7 @@ var answerForWait = (wait) => {
14887
14894
  return { _tag: "Denied", reason: "Permission denied" };
14888
14895
  };
14889
14896
  var permissionResolvedEvent = (config, pending, wait, answer, sequence) => ({
14890
- id: exports_ids_schema.EventId.make(`event:${pending.toolCallId ?? wait.id}:permission-resolved`),
14897
+ id: Identifiers.eventId(config.executionId, pending.toolCallId ?? wait.id, "permission-resolved"),
14891
14898
  execution_id: config.executionId,
14892
14899
  type: "permission.ask.resolved",
14893
14900
  sequence,
@@ -14907,19 +14914,19 @@ var appendPermissionEvent = (config, event) => appendIdempotentTo(config.eventLo
14907
14914
  onNone: () => Effect76.fail(permissionError(error5.message)),
14908
14915
  onSome: (prior) => samePermissionEvent(prior, event) ? Effect76.succeed(prior) : Effect76.fail(permissionError(error5.message))
14909
14916
  })))), Effect76.mapError((error5) => permissionError(error5.message)), Effect76.tap(() => resetAllocatorToLog(config)));
14910
- var ensurePermissionRequestedEvent = Effect76.fn("RelayPermissions.ensurePermissionRequestedEvent")(function* (config, pending, waitId) {
14911
- const cursor = permissionRequestedCursor(config, pending, waitId);
14917
+ var ensurePermissionRequestedEvent = Effect76.fn("RelayPermissions.ensurePermissionRequestedEvent")(function* (config, pending, waitId2) {
14918
+ const cursor = permissionRequestedCursor(config, pending, waitId2);
14912
14919
  const existing = yield* findEventByCursor(config, cursor);
14913
14920
  if (Option16.isSome(existing))
14914
14921
  return;
14915
14922
  const requestedSequence = yield* allocateEventSequence(config);
14916
- yield* appendPermissionEvent(config, permissionRequestedEvent(config, pending, waitId, requestedSequence));
14923
+ yield* appendPermissionEvent(config, permissionRequestedEvent(config, pending, waitId2, requestedSequence));
14917
14924
  });
14918
14925
  var createAsk = Effect76.fn("RelayPermissions.createAsk")(function* (config, pending) {
14919
- const waitId = exports_ids_schema.WaitId.make(pending.token);
14926
+ const waitId2 = exports_ids_schema.WaitId.make(pending.token);
14920
14927
  const waitSequence = yield* allocateEventSequence(config);
14921
14928
  yield* config.waits.createDetached({
14922
- waitId,
14929
+ waitId: waitId2,
14923
14930
  executionId: config.executionId,
14924
14931
  mode: "event",
14925
14932
  correlationKey: pending.toolCallId ?? pending.token,
@@ -14934,17 +14941,17 @@ var createAsk = Effect76.fn("RelayPermissions.createAsk")(function* (config, pen
14934
14941
  eventSequence: waitSequence,
14935
14942
  createdAt: createdAtForSequence(config, waitSequence)
14936
14943
  }).pipe(Effect76.mapError((error5) => permissionError(error5.message)));
14937
- yield* ensurePermissionRequestedEvent(config, pending, waitId);
14944
+ yield* ensurePermissionRequestedEvent(config, pending, waitId2);
14938
14945
  });
14939
14946
  var awaitAnswer = Effect76.fn("RelayPermissions.awaitAnswer")(function* (config, pending) {
14940
- const waitId = exports_ids_schema.WaitId.make(pending.token);
14941
- const existing = yield* config.waits.get(waitId).pipe(Effect76.mapError((error5) => permissionError(error5.message)));
14947
+ const waitId2 = exports_ids_schema.WaitId.make(pending.token);
14948
+ const existing = yield* config.waits.get(waitId2).pipe(Effect76.mapError((error5) => permissionError(error5.message)));
14942
14949
  if (existing === undefined) {
14943
14950
  yield* createAsk(config, pending);
14944
14951
  return Option16.none();
14945
14952
  }
14946
14953
  if (existing.state === "open") {
14947
- yield* ensurePermissionRequestedEvent(config, pending, waitId);
14954
+ yield* ensurePermissionRequestedEvent(config, pending, waitId2);
14948
14955
  return Option16.none();
14949
14956
  }
14950
14957
  const answer = answerForWait(existing);
@@ -16344,16 +16351,16 @@ var make12 = Effect86.gen(function* () {
16344
16351
  }).pipe(Effect86.mapError(toSchedulerError));
16345
16352
  }).pipe(Effect86.withSpan("SchedulerService.dispatchStartExecution"));
16346
16353
  const dispatchWaitTransition = (schedule, now) => Effect86.gen(function* () {
16347
- const waitId = schedule.wait_id;
16348
- if (waitId === undefined) {
16354
+ const waitId2 = schedule.wait_id;
16355
+ if (waitId2 === undefined) {
16349
16356
  return yield* SchedulerError.make({ message: `Schedule ${schedule.id} is missing wait_id` });
16350
16357
  }
16351
- const wait = yield* waits.get(waitId).pipe(Effect86.mapError(toSchedulerError));
16358
+ const wait = yield* waits.get(waitId2).pipe(Effect86.mapError(toSchedulerError));
16352
16359
  if (wait === undefined || wait.state !== "open")
16353
16360
  return;
16354
16361
  const eventSequence = yield* nextEventSequence5(eventLog, wait.executionId);
16355
16362
  const metadata11 = dispatchMetadata(schedule);
16356
- const result = schedule.target_kind === "wake-wait" ? yield* waits.wake({ waitId, resolvedAt: now, eventSequence, metadata: metadata11 }).pipe(Effect86.mapError(toSchedulerError)) : yield* waits.timeout({ waitId, timedOutAt: now, eventSequence, metadata: metadata11 }).pipe(Effect86.mapError(toSchedulerError));
16363
+ const result = schedule.target_kind === "wake-wait" ? yield* waits.wake({ waitId: waitId2, resolvedAt: now, eventSequence, metadata: metadata11 }).pipe(Effect86.mapError(toSchedulerError)) : yield* waits.timeout({ waitId: waitId2, timedOutAt: now, eventSequence, metadata: metadata11 }).pipe(Effect86.mapError(toSchedulerError));
16357
16364
  if (!result.transitioned)
16358
16365
  return;
16359
16366
  yield* signalWorkflowWait({
@@ -17590,13 +17597,13 @@ var toToolWorkLease = (lease) => ({
17590
17597
  claim_expires_at: lease.claimExpiresAt,
17591
17598
  idempotency_key: lease.idempotencyKey
17592
17599
  });
17593
- var toolWaitId = (callId) => exports_ids_schema.WaitId.make(`wait:tool:${callId}`);
17600
+ var toolWaitId = (executionId, callId) => Identifiers.waitId("tool", executionId, callId);
17594
17601
  var acceptedWaitOutcome = (wait) => Schema83.decodeUnknownEffect(exports_tool_schema.ExternalOutcome)(wait.metadata.external_outcome).pipe(Effect90.mapError(toClientError));
17595
17602
  var resolveToolOutcomeWait = Effect90.fn("Client.resolveToolOutcomeWait")(function* (waits, eventLog, call, outcome, completedAt) {
17596
- const waitId = call.waitId ?? toolWaitId(call.call.id);
17597
- const wait = yield* waits.get(waitId).pipe(Effect90.mapError(toClientError));
17603
+ const waitId2 = call.waitId ?? toolWaitId(call.executionId, call.call.id);
17604
+ const wait = yield* waits.get(waitId2).pipe(Effect90.mapError(toClientError));
17598
17605
  if (wait === undefined)
17599
- return yield* ClientError.make({ message: `Tool wait not found: ${waitId}` });
17606
+ return yield* ClientError.make({ message: `Tool wait not found: ${waitId2}` });
17600
17607
  if (wait.executionId !== call.executionId) {
17601
17608
  return yield* ClientError.make({ message: `Tool wait does not match call: ${call.call.id}` });
17602
17609
  }
@@ -17612,7 +17619,7 @@ var resolveToolOutcomeWait = Effect90.fn("Client.resolveToolOutcomeWait")(functi
17612
17619
  }
17613
17620
  const eventSequence = yield* nextEventSequence6(eventLog, call.executionId);
17614
17621
  const resolved = yield* waits.wake({
17615
- waitId,
17622
+ waitId: waitId2,
17616
17623
  resolvedAt: completedAt,
17617
17624
  eventSequence,
17618
17625
  metadata: { kind: "tool-placement", external_outcome: outcome }
@@ -17757,10 +17764,10 @@ var childSpawnFingerprint = (record2) => {
17757
17764
  return typeof fingerprint === "string" ? fingerprint : undefined;
17758
17765
  };
17759
17766
  var createChildJoinWait = Effect90.fn("Client.createChildJoinWait")(function* (waits, eventLog, input, accepted2, createdAt) {
17760
- const waitId = childJoinWaitId(accepted2.child_execution_id);
17767
+ const waitId2 = childJoinWaitId(accepted2.child_execution_id);
17761
17768
  const eventSequence = yield* nextEventSequence6(eventLog, input.execution_id);
17762
17769
  yield* waits.createDetached({
17763
- waitId,
17770
+ waitId: waitId2,
17764
17771
  executionId: input.execution_id,
17765
17772
  mode: "child",
17766
17773
  correlationKey: accepted2.child_execution_id,
@@ -17771,7 +17778,7 @@ var createChildJoinWait = Effect90.fn("Client.createChildJoinWait")(function* (w
17771
17778
  eventSequence,
17772
17779
  createdAt
17773
17780
  }).pipe(Effect90.mapError(toClientError));
17774
- return waitId;
17781
+ return waitId2;
17775
17782
  });
17776
17783
  var reconcileExistingChildSpawn = Effect90.fn("Client.reconcileExistingChildSpawn")(function* (childExecutions, waits, eventLog, input) {
17777
17784
  const childExecutionId3 = childExecutionIdForSpawn(input);
@@ -1114,42 +1114,46 @@ var Classification = Schema17.Union([
1114
1114
  TimerWait,
1115
1115
  ExternalWait
1116
1116
  ]).annotate({ identifier: "Relay.WaitClassification" });
1117
- var suffixAfter = (waitId, namespace) => waitId.slice(namespace.length);
1117
+ var scopedToolCallId = (waitId, namespace) => {
1118
+ const scope = waitId.slice(namespace.length);
1119
+ const separator = scope.indexOf(":");
1120
+ return ToolCallId.make(decodeURIComponent(scope.slice(separator + 1)));
1121
+ };
1118
1122
  var classify = (input) => {
1119
1123
  const waitId = input.wait_id;
1120
1124
  if (waitId.startsWith("wait:permission:")) {
1121
1125
  return {
1122
1126
  kind: "permission",
1123
1127
  wait_id: waitId,
1124
- tool_call_id: ToolCallId.make(suffixAfter(waitId, "wait:permission:"))
1128
+ tool_call_id: scopedToolCallId(waitId, "wait:permission:")
1125
1129
  };
1126
1130
  }
1127
1131
  if (waitId.startsWith("wait:approval:")) {
1128
1132
  return {
1129
1133
  kind: "tool_approval",
1130
1134
  wait_id: waitId,
1131
- tool_call_id: ToolCallId.make(suffixAfter(waitId, "wait:approval:"))
1135
+ tool_call_id: scopedToolCallId(waitId, "wait:approval:")
1132
1136
  };
1133
1137
  }
1134
1138
  if (waitId.startsWith("wait:child:")) {
1135
1139
  return {
1136
1140
  kind: "child_join",
1137
1141
  wait_id: waitId,
1138
- child_execution_id: ChildExecutionId.make(suffixAfter(waitId, "wait:child:"))
1142
+ child_execution_id: ChildExecutionId.make(waitId.slice("wait:child:".length))
1139
1143
  };
1140
1144
  }
1141
1145
  if (waitId.startsWith("wait:inbox:")) {
1142
1146
  return {
1143
1147
  kind: "inbox",
1144
1148
  wait_id: waitId,
1145
- tool_call_id: ToolCallId.make(suffixAfter(waitId, "wait:inbox:"))
1149
+ tool_call_id: ToolCallId.make(waitId.slice("wait:inbox:".length))
1146
1150
  };
1147
1151
  }
1148
1152
  if (waitId.startsWith("wait:tool:")) {
1149
1153
  return {
1150
1154
  kind: "tool_placement",
1151
1155
  wait_id: waitId,
1152
- tool_call_id: ToolCallId.make(suffixAfter(waitId, "wait:tool:"))
1156
+ tool_call_id: scopedToolCallId(waitId, "wait:tool:")
1153
1157
  };
1154
1158
  }
1155
1159
  if (waitId.startsWith("wait:reply:") || input.envelope_id !== undefined && input.mode === "reply") {
package/dist/index.js CHANGED
@@ -13,7 +13,7 @@ import {
13
13
  exports_tool_runtime,
14
14
  exports_workflow_definition_host,
15
15
  makeDatabaseIdentity
16
- } from "./index-cq8t8ka1.js";
16
+ } from "./index-e02krw55.js";
17
17
  import {
18
18
  exports_model_registry
19
19
  } from "./index-8fpd6kvj.js";
@@ -40,7 +40,7 @@ import {
40
40
  exports_tool_schema,
41
41
  exports_wait_schema,
42
42
  exports_workflow_schema
43
- } from "./index-cyfx5y3r.js";
43
+ } from "./index-mtvz1bjn.js";
44
44
  import {
45
45
  __export
46
46
  } from "./index-nb39b5ae.js";
package/dist/mysql.js CHANGED
@@ -2,14 +2,14 @@
2
2
  import {
3
3
  database,
4
4
  normalizeMigrationCause
5
- } from "./index-5dqkw53p.js";
5
+ } from "./index-2vsf6dks.js";
6
6
  import {
7
7
  MigratorError,
8
8
  RuntimeMigrationError,
9
9
  SqlFailure
10
- } from "./index-cq8t8ka1.js";
10
+ } from "./index-e02krw55.js";
11
11
  import"./index-8fpd6kvj.js";
12
- import"./index-cyfx5y3r.js";
12
+ import"./index-mtvz1bjn.js";
13
13
  import"./index-nb39b5ae.js";
14
14
 
15
15
  // src/mysql.ts
package/dist/postgres.js CHANGED
@@ -2,7 +2,7 @@
2
2
  import {
3
3
  database,
4
4
  normalizeMigrationCause
5
- } from "./index-5dqkw53p.js";
5
+ } from "./index-2vsf6dks.js";
6
6
  import {
7
7
  Dialect,
8
8
  RuntimeMigrationError,
@@ -14,11 +14,11 @@ import {
14
14
  fromDbTimestamp,
15
15
  fromNullableDbTimestamp,
16
16
  timestampParam
17
- } from "./index-cq8t8ka1.js";
17
+ } from "./index-e02krw55.js";
18
18
  import"./index-8fpd6kvj.js";
19
19
  import {
20
20
  exports_ids_schema
21
- } from "./index-cyfx5y3r.js";
21
+ } from "./index-mtvz1bjn.js";
22
22
  import {
23
23
  __export
24
24
  } from "./index-nb39b5ae.js";
package/dist/sqlite.js CHANGED
@@ -2,7 +2,7 @@
2
2
  import {
3
3
  database,
4
4
  normalizeMigrationCause
5
- } from "./index-5dqkw53p.js";
5
+ } from "./index-2vsf6dks.js";
6
6
  import {
7
7
  DatabaseAlreadyOwned,
8
8
  RuntimeConfigurationError,
@@ -12,9 +12,9 @@ import {
12
12
  make,
13
13
  makeDatabaseIdentity,
14
14
  runtimeLayer
15
- } from "./index-cq8t8ka1.js";
15
+ } from "./index-e02krw55.js";
16
16
  import"./index-8fpd6kvj.js";
17
- import"./index-cyfx5y3r.js";
17
+ import"./index-mtvz1bjn.js";
18
18
  import"./index-nb39b5ae.js";
19
19
 
20
20
  // src/sqlite-runtime.ts
@@ -21,5 +21,4 @@ export interface Config {
21
21
  readonly startedAt: number;
22
22
  readonly eventSequence: Execution.ExecutionEventSequence;
23
23
  }
24
- export declare const waitIdForToolCall: (toolCallId: string) => string & import("effect/Brand").Brand<"Relay.WaitId">;
25
24
  export declare const layer: (config: Config) => Layer.Layer<Permissions.Permissions | Permissions.RuleStore, never, never>;
@@ -0,0 +1,9 @@
1
+ import { Ids } from "../../schema/index";
2
+ export type ToolWaitKind = "approval" | "permission" | "tool";
3
+ declare const eventId: (executionId: Ids.ExecutionId, toolCallId: Ids.ToolCallId | string, kind: "tool-requested" | "tool-result" | "approval-requested" | "approval-resolved" | "permission-requested" | "permission-resolved") => string & import("effect/Brand").Brand<"Relay.EventId">;
4
+ declare const waitId: (kind: ToolWaitKind, executionId: Ids.ExecutionId, toolCallId: Ids.ToolCallId | string) => string & import("effect/Brand").Brand<"Relay.WaitId">;
5
+ export declare const Identifiers: {
6
+ eventId: typeof eventId;
7
+ waitId: typeof waitId;
8
+ };
9
+ export {};
@@ -6,6 +6,7 @@ import { Service as EventLogService } from "../execution/event-log-service";
6
6
  import { Service as WaitServiceService } from "../wait/wait-service";
7
7
  export * from "./tool-runtime-contract";
8
8
  import { Service } from "./tool-runtime-contract";
9
+ export { Identifiers } from "./tool-runtime-identifiers";
9
10
  import type { DynamicToolOptions, PlacedToolOptions, RegisteredTool, RunInput, ToolkitRegistrationOptions, ToolOptions } from "./tool-runtime-contract";
10
11
  export declare const toolFromRegistered: (tool: RegisteredTool) => AiTool.Any;
11
12
  export declare const toolsFromToolkit: {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/package.json",
3
3
  "name": "@relayfx/sdk",
4
- "version": "0.3.5",
4
+ "version": "0.3.6",
5
5
  "description": "Effect-native durable execution SDK for addressable agents and tools",
6
6
  "type": "module",
7
7
  "exports": {