@yielded/agent-workflow 0.1.0-beta.166 → 0.1.0-beta.168

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.
@@ -6,14 +6,14 @@ import { BindingUnavailable } from "@yielded/agent/agent-registration";
6
6
  import { DigestError } from "@yielded/agent/digest";
7
7
  import { DurableRuntimeFailpointError } from "@yielded/agent/durable-failpoint";
8
8
  import { OperationDenied } from "@yielded/agent/operation-authorizer";
9
- import { AdmissionConflict, AdmissionPolicyError, LedgerError, SettlementConflict } from "@yielded/agent/submission-ledger";
10
- import { AppendConflict, FenceRejected, ThreadNotMaterialized, ThreadStoreError } from "@yielded/agent/thread-store";
9
+ import { AdmissionConflict, AdmissionPolicyError, LedgerError, OwnershipLost, SettlementConflict } from "@yielded/agent/submission-ledger";
10
+ import { AppendConflict, ThreadNotMaterialized, ThreadStoreError } from "@yielded/agent/thread-store";
11
11
  import { Effect, Schema } from "effect";
12
12
  declare namespace AgentWorkflow_d_exports {
13
13
  export { Error, execute };
14
14
  }
15
15
  /** Schema for the exact typed failure channel of execute, suitable for Workflow.make({ error }). */
16
- export declare const Error: Schema.Union<readonly [typeof AgentInputError, typeof AgentOutputError, typeof AdmissionConflict, typeof AdmissionPolicyError, typeof AppendConflict, typeof BindingUnavailable, typeof DigestError, typeof DurableRuntimeFailpointError, typeof FenceRejected, typeof LedgerError, typeof OperationDenied, typeof SettlementConflict, typeof ThreadNotMaterialized, typeof ThreadStoreError, typeof WorkflowDispatchError, typeof WorkflowAdmissionClosed, typeof WorkflowExecutionFailure]>;
16
+ export declare const Error: Schema.Union<readonly [typeof AgentInputError, typeof AgentOutputError, typeof AdmissionConflict, typeof AdmissionPolicyError, typeof AppendConflict, typeof BindingUnavailable, typeof DigestError, typeof DurableRuntimeFailpointError, typeof LedgerError, typeof OwnershipLost, typeof OperationDenied, typeof SettlementConflict, typeof ThreadNotMaterialized, typeof ThreadStoreError, typeof WorkflowDispatchError, typeof WorkflowAdmissionClosed, typeof WorkflowExecutionFailure]>;
17
17
  export type Error = typeof Error.Type;
18
18
  /**
19
19
  * Run a registered agent inside a native Workflow.toLayer handler. One stable name identifies
@@ -24,7 +24,7 @@ export type Error = typeof Error.Type;
24
24
  * Pass the exact Agent Definition instance used in runtime registration; a same-ID copy fails
25
25
  * with BindingUnavailable before input encoding or admission.
26
26
  */
27
- export declare const execute: <Input extends Schema.Top, Output extends Schema.Top>(agent: WorkflowAgent<Input, Output>, input: Input["Type"], options: WorkflowExecuteOptions) => Effect.Effect<Output["Type"], AdmissionConflict | AdmissionPolicyError | AgentInputError | AgentOutputError | AppendConflict | BindingUnavailable | DigestError | DurableRuntimeFailpointError | FenceRejected | LedgerError | OperationDenied | SettlementConflict | ThreadNotMaterialized | ThreadStoreError | WorkflowAdmissionClosed | WorkflowDispatchError | WorkflowExecutionFailure, WorkflowAgentHost | import("effect/workflow/WorkflowEngine").WorkflowEngine | import("effect/workflow/WorkflowEngine").WorkflowInstance | Input["EncodingServices"] | Output["DecodingServices"]>;
27
+ export declare const execute: <Input extends Schema.Top, Output extends Schema.Top>(agent: WorkflowAgent<Input, Output>, input: Input["Type"], options: WorkflowExecuteOptions) => Effect.Effect<Output["Type"], AdmissionConflict | AdmissionPolicyError | AgentInputError | AgentOutputError | AppendConflict | BindingUnavailable | DigestError | DurableRuntimeFailpointError | LedgerError | OperationDenied | OwnershipLost | SettlementConflict | ThreadNotMaterialized | ThreadStoreError | WorkflowAdmissionClosed | WorkflowDispatchError | WorkflowExecutionFailure, WorkflowAgentHost | import("effect/workflow/WorkflowEngine").WorkflowEngine | import("effect/workflow/WorkflowEngine").WorkflowInstance | Input["EncodingServices"] | Output["DecodingServices"]>;
28
28
  //#endregion
29
29
  export { AgentWorkflow_d_exports as t };
30
30
  //# sourceMappingURL=AgentWorkflow.d.mts.map
@@ -1,14 +1,14 @@
1
1
  import { t as __exportAll } from "./rolldown-runtime-D7D4PA-g.mjs";
2
2
  import { WorkflowDispatchError } from "./WorkflowDispatch.mjs";
3
- import { n as WorkflowAgentHost, t as WorkflowAdmissionClosed } from "./WorkflowAgentHost-CqS43Ufw.mjs";
3
+ import { n as WorkflowAgentHost, t as WorkflowAdmissionClosed } from "./WorkflowAgentHost-DTcWCdU2.mjs";
4
4
  import { WorkflowExecutionFailure } from "./WorkflowExecution.mjs";
5
5
  import { AgentInputError, AgentOutputError } from "@yielded/agent/agent-error";
6
6
  import { BindingUnavailable } from "@yielded/agent/agent-registration";
7
7
  import { DigestError } from "@yielded/agent/digest";
8
8
  import { DurableRuntimeFailpointError } from "@yielded/agent/durable-failpoint";
9
9
  import { OperationDenied } from "@yielded/agent/operation-authorizer";
10
- import { AdmissionConflict, AdmissionPolicyError, LedgerError, SettlementConflict } from "@yielded/agent/submission-ledger";
11
- import { AppendConflict, FenceRejected, ThreadNotMaterialized, ThreadStoreError } from "@yielded/agent/thread-store";
10
+ import { AdmissionConflict, AdmissionPolicyError, LedgerError, OwnershipLost, SettlementConflict } from "@yielded/agent/submission-ledger";
11
+ import { AppendConflict, ThreadNotMaterialized, ThreadStoreError } from "@yielded/agent/thread-store";
12
12
  import { Effect, Schema } from "effect";
13
13
  //#region src/AgentWorkflow.ts
14
14
  var AgentWorkflow_exports = /* @__PURE__ */ __exportAll({
@@ -25,8 +25,8 @@ const Error = Schema.Union([
25
25
  BindingUnavailable,
26
26
  DigestError,
27
27
  DurableRuntimeFailpointError,
28
- FenceRejected,
29
28
  LedgerError,
29
+ OwnershipLost,
30
30
  OperationDenied,
31
31
  SettlementConflict,
32
32
  ThreadNotMaterialized,
@@ -44,7 +44,7 @@ const Error = Schema.Union([
44
44
  * Pass the exact Agent Definition instance used in runtime registration; a same-ID copy fails
45
45
  * with BindingUnavailable before input encoding or admission.
46
46
  */
47
- const execute = Effect.fn("AgentWorkflow.execute")(function* (agent, input, options) {
47
+ const execute = Effect.fnUntraced(function* (agent, input, options) {
48
48
  return yield* (yield* WorkflowAgentHost).execute(agent, input, options);
49
49
  });
50
50
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"AgentWorkflow.mjs","names":[],"sources":["../src/AgentWorkflow.ts"],"sourcesContent":["import { AgentInputError, AgentOutputError } from \"@yielded/agent/agent-error\";\nimport { BindingUnavailable } from \"@yielded/agent/agent-registration\";\nimport { DigestError } from \"@yielded/agent/digest\";\nimport { DurableRuntimeFailpointError } from \"@yielded/agent/durable-failpoint\";\nimport { OperationDenied } from \"@yielded/agent/operation-authorizer\";\nimport {\n AdmissionConflict,\n AdmissionPolicyError,\n LedgerError,\n SettlementConflict,\n} from \"@yielded/agent/submission-ledger\";\nimport {\n AppendConflict,\n FenceRejected,\n ThreadNotMaterialized,\n ThreadStoreError,\n} from \"@yielded/agent/thread-store\";\nimport { Effect, Schema } from \"effect\";\n\nimport { WorkflowAdmissionClosed, WorkflowAgentHost } from \"./WorkflowAgentHost.ts\";\nimport { WorkflowDispatchError } from \"./WorkflowDispatch.ts\";\nimport {\n WorkflowExecutionFailure,\n type WorkflowAgent,\n type WorkflowExecuteOptions,\n} from \"./WorkflowExecution.ts\";\n\n/** Schema for the exact typed failure channel of execute, suitable for Workflow.make({ error }). */\nexport const Error = Schema.Union([\n AgentInputError,\n AgentOutputError,\n AdmissionConflict,\n AdmissionPolicyError,\n AppendConflict,\n BindingUnavailable,\n DigestError,\n DurableRuntimeFailpointError,\n FenceRejected,\n LedgerError,\n OperationDenied,\n SettlementConflict,\n ThreadNotMaterialized,\n ThreadStoreError,\n WorkflowDispatchError,\n WorkflowAdmissionClosed,\n WorkflowExecutionFailure,\n]);\n\nexport type Error = typeof Error.Type;\n\n/**\n * Run a registered agent inside a native Workflow.toLayer handler. One stable name identifies\n * one submission in that parent execution. Replays verify admission identity and decode the\n * canonical output again. Pending work suspends through Effect DurableDeferred; neither\n * suspension nor parent interruption aborts accepted agent work. Use the host's authorized abort.\n * Provide WorkflowAgentHost at the application boundary, sharing the parent's WorkflowEngine.\n * Pass the exact Agent Definition instance used in runtime registration; a same-ID copy fails\n * with BindingUnavailable before input encoding or admission.\n */\nexport const execute = Effect.fn(\"AgentWorkflow.execute\")(function* <\n Input extends Schema.Top,\n Output extends Schema.Top,\n>(agent: WorkflowAgent<Input, Output>, input: Input[\"Type\"], options: WorkflowExecuteOptions) {\n const host = yield* WorkflowAgentHost;\n\n return yield* host.execute(agent, input, options);\n});\n"],"mappings":";;;;;;;;;;;;;;;;;;AA4BA,MAAa,QAAQ,OAAO,MAAM;CAChC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC;;;;;;;;;;AAaD,MAAa,UAAU,OAAO,GAAG,uBAAuB,CAAC,CAAC,WAGxD,OAAqC,OAAsB,SAAiC;CAG5F,OAAO,QAAO,OAFM,kBAAA,CAED,QAAQ,OAAO,OAAO,OAAO;AAClD,CAAC"}
1
+ {"version":3,"file":"AgentWorkflow.mjs","names":[],"sources":["../src/AgentWorkflow.ts"],"sourcesContent":["import { AgentInputError, AgentOutputError } from \"@yielded/agent/agent-error\";\nimport { BindingUnavailable } from \"@yielded/agent/agent-registration\";\nimport { DigestError } from \"@yielded/agent/digest\";\nimport { DurableRuntimeFailpointError } from \"@yielded/agent/durable-failpoint\";\nimport { OperationDenied } from \"@yielded/agent/operation-authorizer\";\nimport {\n AdmissionConflict,\n AdmissionPolicyError,\n LedgerError,\n OwnershipLost,\n SettlementConflict,\n} from \"@yielded/agent/submission-ledger\";\nimport {\n AppendConflict,\n ThreadNotMaterialized,\n ThreadStoreError,\n} from \"@yielded/agent/thread-store\";\nimport { Effect, Schema } from \"effect\";\n\nimport { WorkflowAdmissionClosed, WorkflowAgentHost } from \"./WorkflowAgentHost.ts\";\nimport { WorkflowDispatchError } from \"./WorkflowDispatch.ts\";\nimport {\n WorkflowExecutionFailure,\n type WorkflowAgent,\n type WorkflowExecuteOptions,\n} from \"./WorkflowExecution.ts\";\n\n/** Schema for the exact typed failure channel of execute, suitable for Workflow.make({ error }). */\nexport const Error = Schema.Union([\n AgentInputError,\n AgentOutputError,\n AdmissionConflict,\n AdmissionPolicyError,\n AppendConflict,\n BindingUnavailable,\n DigestError,\n DurableRuntimeFailpointError,\n LedgerError,\n OwnershipLost,\n OperationDenied,\n SettlementConflict,\n ThreadNotMaterialized,\n ThreadStoreError,\n WorkflowDispatchError,\n WorkflowAdmissionClosed,\n WorkflowExecutionFailure,\n]);\n\nexport type Error = typeof Error.Type;\n\n/**\n * Run a registered agent inside a native Workflow.toLayer handler. One stable name identifies\n * one submission in that parent execution. Replays verify admission identity and decode the\n * canonical output again. Pending work suspends through Effect DurableDeferred; neither\n * suspension nor parent interruption aborts accepted agent work. Use the host's authorized abort.\n * Provide WorkflowAgentHost at the application boundary, sharing the parent's WorkflowEngine.\n * Pass the exact Agent Definition instance used in runtime registration; a same-ID copy fails\n * with BindingUnavailable before input encoding or admission.\n */\nexport const execute = Effect.fnUntraced(function* <\n Input extends Schema.Top,\n Output extends Schema.Top,\n>(agent: WorkflowAgent<Input, Output>, input: Input[\"Type\"], options: WorkflowExecuteOptions) {\n const host = yield* WorkflowAgentHost;\n\n return yield* host.execute(agent, input, options);\n});\n"],"mappings":";;;;;;;;;;;;;;;;;;AA4BA,MAAa,QAAQ,OAAO,MAAM;CAChC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC;;;;;;;;;;AAaD,MAAa,UAAU,OAAO,WAAW,WAGvC,OAAqC,OAAsB,SAAiC;CAG5F,OAAO,QAAO,OAFM,kBAAA,CAED,QAAQ,OAAO,OAAO,OAAO;AAClD,CAAC"}
@@ -44,7 +44,7 @@ const nativeOperation = (operation, effect) => effect.pipe(Effect.catchDefect((c
44
44
  message: "Workflow engine operation failed",
45
45
  cause
46
46
  }))));
47
- const makeHost = Effect.fn("WorkflowAgentHost.make")(function* (options) {
47
+ const makeHost = Effect.fnUntraced(function* (options) {
48
48
  const config = yield* Schema.decodeEffect(WorkflowHostConfig)({
49
49
  deploymentId: options.deploymentId,
50
50
  principal: options.principal,
@@ -76,14 +76,14 @@ const makeHost = Effect.fn("WorkflowAgentHost.make")(function* (options) {
76
76
  operation,
77
77
  message: "Workflow dispatch operation timed out; accepted work remains recoverable"
78
78
  }))));
79
- const validateReceipt = Effect.fn("WorkflowAgentHost.validateReceipt")(function* (receipt) {
79
+ const validateReceipt = Effect.fnUntraced(function* (receipt) {
80
80
  const found = yield* ledger.lookup(SubmissionLookupById.make({ submissionId: receipt.submissionId }));
81
81
  if (Option.isNone(found) || found.value.deploymentId !== config.deploymentId || found.value.threadId !== receipt.threadId || found.value.receiptId !== receipt.receiptId || found.value.queueSequence !== receipt.queueSequence) return yield* WorkflowDispatchError.make({
82
82
  operation: "identity",
83
83
  message: "Workflow Receipt does not match its authoritative deployment and Submission"
84
84
  });
85
85
  });
86
- yield* engine.register(workflow, Effect.fn("WorkflowAgentHost.execute")(function* (payload, executionId) {
86
+ yield* engine.register(workflow, Effect.fnUntraced(function* (payload, executionId) {
87
87
  yield* Effect.annotateCurrentSpan({
88
88
  "workflow.execution.id": executionId,
89
89
  "agent.submission.id": payload.receipt.submissionId,
@@ -117,7 +117,7 @@ const makeHost = Effect.fn("WorkflowAgentHost.make")(function* (options) {
117
117
  const instance = yield* WorkflowEngine.WorkflowInstance;
118
118
  return yield* Workflow.suspend(instance);
119
119
  }));
120
- const intentFor = Effect.fn("WorkflowAgentHost.intentFor")(function* (receipt) {
120
+ const intentFor = Effect.fnUntraced(function* (receipt) {
121
121
  const payload = new WorkflowSubmission({
122
122
  version: 1,
123
123
  deploymentId: config.deploymentId,
@@ -130,7 +130,7 @@ const makeHost = Effect.fn("WorkflowAgentHost.make")(function* (options) {
130
130
  executionId
131
131
  });
132
132
  });
133
- const dispatchIntent = Effect.fn("WorkflowAgentHost.dispatch")(function* (requested) {
133
+ const dispatchIntent = Effect.fnUntraced(function* (requested) {
134
134
  let intent = requested;
135
135
  const expected = yield* intentFor(intent.receipt);
136
136
  if (intent.executionId !== expected.executionId || intent.deploymentId !== expected.deploymentId || intent.workflowName !== expected.workflowName) return yield* new WorkflowDispatchError({
@@ -206,13 +206,13 @@ const makeHost = Effect.fn("WorkflowAgentHost.make")(function* (options) {
206
206
  }));
207
207
  yield* trigger.register(repair.pipe(Effect.asVoid, Effect.catchCause((cause) => Cause.hasInterruptsOnly(cause) ? Effect.interrupt : Effect.logError("Workflow dispatch repair failed; durable obligations remain", cause))));
208
208
  yield* Effect.addFinalizer(() => Ref.set(admission, false));
209
- const submit = Effect.fn("WorkflowAgentHost.submit")(function* (agent, input, options) {
209
+ const submit = Effect.fnUntraced(function* (agent, input, options) {
210
210
  if (!(yield* Ref.get(admission))) return yield* new WorkflowAdmissionClosed({ message: "The Workflow host is shutting down" });
211
211
  const receipt = yield* runtime.submit(agent, input, options);
212
212
  yield* dispatchIntent(yield* intentFor(receipt));
213
213
  return receipt;
214
214
  });
215
- const execute = Effect.fn("AgentWorkflow.execute")(function* (agent, input, options) {
215
+ const execute = Effect.fnUntraced(function* (agent, input, options) {
216
216
  if ((yield* WorkflowEngine.WorkflowEngine) !== engine) return yield* new WorkflowExecutionFailure({
217
217
  reason: "engine-mismatch",
218
218
  message: "Agent host and parent workflow must share one WorkflowEngine Layer"
@@ -277,7 +277,7 @@ const makeHost = Effect.fn("WorkflowAgentHost.make")(function* (options) {
277
277
  resolveUnknown: runtime.resolveUnknown,
278
278
  submissionStatus: runtime.submissionStatus,
279
279
  repair,
280
- executionId: Effect.fn("WorkflowAgentHost.executionId")((receipt) => intentFor(receipt).pipe(Effect.map((intent) => intent.executionId)))
280
+ executionId: (receipt) => intentFor(receipt).pipe(Effect.map((intent) => intent.executionId))
281
281
  });
282
282
  });
283
283
  /**
@@ -295,4 +295,4 @@ var WorkflowAgentHost = class WorkflowAgentHost extends Context.Service()("@effe
295
295
  //#endregion
296
296
  export { WorkflowHostConfigError as i, WorkflowAgentHost as n, WorkflowAgentHost_exports as r, WorkflowAdmissionClosed as t };
297
297
 
298
- //# sourceMappingURL=WorkflowAgentHost-CqS43Ufw.mjs.map
298
+ //# sourceMappingURL=WorkflowAgentHost-DTcWCdU2.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"WorkflowAgentHost-DTcWCdU2.mjs","names":[],"sources":["../src/internal/completion.ts","../src/WorkflowAgentHost.ts"],"sourcesContent":["import { DurableDeferred } from \"effect/workflow\";\n\nimport { WorkflowSettlementReference } from \"../WorkflowDispatch.ts\";\n\n/** Native deferred results contain only canonical identities, never a second agent result. */\nexport const workflowCompletion = (name: string) =>\n DurableDeferred.make(name, { success: WorkflowSettlementReference });\n","import { AgentOutputError } from \"@yielded/agent/agent-error\";\nimport { type BindingUnavailable } from \"@yielded/agent/agent-registration\";\nimport { digestJson } from \"@yielded/agent/digest\";\nimport {\n DurableAgentRuntime,\n DurableRuntimeConfig,\n Receipt,\n type DurableAwaitFailure,\n type DurableSubmitAgent,\n type DurableSubmitFailure,\n type DurableSubmitOptions,\n} from \"@yielded/agent/durable-agent-runtime\";\nimport { ThreadId } from \"@yielded/agent/identifiers\";\nimport { DeploymentId } from \"@yielded/agent/records\";\nimport {\n IdempotencyKey,\n Principal,\n SubmissionLedger,\n SubmissionLookupById,\n} from \"@yielded/agent/submission-ledger\";\nimport {\n Cause,\n Context,\n Crypto,\n Effect,\n Exit,\n Layer,\n Option,\n RcMap,\n Ref,\n Result,\n Schema,\n Semaphore,\n Stream,\n} from \"effect\";\nimport { DurableDeferred, Workflow, WorkflowEngine } from \"effect/workflow\";\n\nimport { workflowCompletion } from \"./internal/completion.ts\";\nimport {\n WorkflowDispatchError,\n WorkflowDispatchFailpoint,\n WorkflowDispatchIntent,\n WorkflowDispatchScan,\n WorkflowDispatchStore,\n WorkflowRepairReport,\n WorkflowRepairTrigger,\n WorkflowSettlementReference,\n WorkflowSubmission,\n} from \"./WorkflowDispatch.ts\";\nimport {\n WorkflowExecutionFailure,\n type WorkflowAgent,\n type WorkflowExecuteOptions,\n} from \"./WorkflowExecution.ts\";\n\nconst WorkflowHostConfig = Schema.Struct({\n deploymentId: DeploymentId,\n principal: Principal,\n workflowName: Schema.NonEmptyString,\n executionConcurrency: Schema.Int.check(Schema.isBetween({ minimum: 1, maximum: 64 })),\n repairBatchSize: Schema.Int.check(Schema.isBetween({ minimum: 1, maximum: 1000 })),\n dispatchTimeoutMillis: Schema.Int.check(Schema.isBetween({ minimum: 1, maximum: 300_000 })),\n});\n\nexport class WorkflowHostConfigError extends Schema.TaggedError<WorkflowHostConfigError>()(\n \"WorkflowHostConfigError\",\n { message: Schema.String },\n) {}\n\nexport class WorkflowAdmissionClosed extends Schema.TaggedError<WorkflowAdmissionClosed>()(\n \"WorkflowAdmissionClosed\",\n { message: Schema.String },\n) {}\n\nexport interface WorkflowAgentHostOptions {\n readonly deploymentId: string;\n /** Application-owned identity for submissions from AgentWorkflow.execute. */\n readonly principal: string;\n /** Stable versioned name prefix. The native name also includes deploymentId. */\n readonly workflowName?: string;\n /** Concurrent Attempts within this host Layer instance, not a fleet-wide limit. Default 1. */\n readonly executionConcurrency?: number;\n /** Maximum entries per scan per repair invocation. Default 32. */\n readonly repairBatchSize?: number;\n /** Bound each dispatch or scan, including a retrying native engine. Default 10000 ms. */\n readonly dispatchTimeoutMillis?: number;\n}\n\nexport type WorkflowRepairFailure = WorkflowDispatchError | DurableAwaitFailure;\n\nconst nativeOperation = <A, E, R>(operation: string, effect: Effect.Effect<A, E, R>) =>\n effect.pipe(\n Effect.catchDefect((cause) =>\n Effect.fail(\n new WorkflowDispatchError({\n operation,\n message: \"Workflow engine operation failed\",\n cause,\n }),\n ),\n ),\n );\n\nconst makeHost = Effect.fnUntraced(function* (options: WorkflowAgentHostOptions) {\n const config = yield* Schema.decodeEffect(WorkflowHostConfig)({\n deploymentId: options.deploymentId,\n principal: options.principal,\n workflowName: options.workflowName ?? \"effect-agent/Submission/v1\",\n executionConcurrency: options.executionConcurrency ?? 1,\n repairBatchSize: options.repairBatchSize ?? 32,\n dispatchTimeoutMillis: options.dispatchTimeoutMillis ?? 10_000,\n }).pipe(Effect.mapError((error) => new WorkflowHostConfigError({ message: error.message })));\n\n const runtime = yield* DurableAgentRuntime;\n const crypto = yield* Crypto.Crypto;\n const runtimeConfig = yield* DurableRuntimeConfig;\n const ledger = yield* SubmissionLedger;\n const engine = yield* WorkflowEngine.WorkflowEngine;\n const dispatch = yield* WorkflowDispatchStore;\n const trigger = yield* WorkflowRepairTrigger;\n const failpoint = yield* WorkflowDispatchFailpoint;\n\n if (runtimeConfig.deploymentId !== config.deploymentId) {\n return yield* new WorkflowHostConfigError({\n message: \"Workflow and durable runtime deploymentId must match\",\n });\n }\n const permits = yield* Semaphore.make(config.executionConcurrency);\n const lanes = yield* RcMap.make({ lookup: (_threadId: ThreadId) => Semaphore.make(1) });\n const repairPermit = yield* Semaphore.make(1);\n const admission = yield* Ref.make(true);\n const nativeName = `${config.workflowName}/deployment/${config.deploymentId.length}:${config.deploymentId}`;\n\n const workflow = Workflow.make(nativeName, {\n payload: WorkflowSubmission,\n success: WorkflowSettlementReference,\n idempotencyKey: ({ deploymentId, receipt }) =>\n `v1/${deploymentId.length}:${deploymentId}/${receipt.submissionId}`,\n }).annotate(Workflow.SuspendOnFailure, true);\n\n const bounded = <A, E, R>(operation: string, effect: Effect.Effect<A, E, R>) =>\n nativeOperation(operation, effect).pipe(\n Effect.timeout(config.dispatchTimeoutMillis),\n Effect.catchTag(\"TimeoutError\", () =>\n Effect.fail(\n WorkflowDispatchError.make({\n operation,\n message: \"Workflow dispatch operation timed out; accepted work remains recoverable\",\n }),\n ),\n ),\n );\n\n const validateReceipt = Effect.fnUntraced(function* (receipt: Receipt) {\n const found = yield* ledger.lookup(\n SubmissionLookupById.make({ submissionId: receipt.submissionId }),\n );\n\n if (\n Option.isNone(found) ||\n found.value.deploymentId !== config.deploymentId ||\n found.value.threadId !== receipt.threadId ||\n found.value.receiptId !== receipt.receiptId ||\n found.value.queueSequence !== receipt.queueSequence\n ) {\n return yield* WorkflowDispatchError.make({\n operation: \"identity\",\n message: \"Workflow Receipt does not match its authoritative deployment and Submission\",\n });\n }\n });\n\n // No Activities: rerun journal recovery directly on every native resume. The upstream\n // failure annotation suspends infrastructure failures and defects instead of settling them.\n yield* engine.register(\n workflow,\n Effect.fnUntraced(function* (payload, executionId) {\n yield* Effect.annotateCurrentSpan({\n \"workflow.execution.id\": executionId,\n \"agent.submission.id\": payload.receipt.submissionId,\n \"agent.thread.id\": payload.receipt.threadId,\n });\n if (payload.deploymentId !== config.deploymentId) {\n return yield* Effect.die(\"Workflow payload belongs to another deployment\");\n }\n if (executionId !== (yield* workflow.executionId(payload))) {\n return yield* Effect.die(\"Workflow execution identity does not match its Submission\");\n }\n yield* validateReceipt(payload.receipt).pipe(Effect.orDie);\n const initial = yield* runtime.inspectSubmissionStatus(payload.receipt).pipe(Effect.orDie);\n\n if (initial._tag === \"settled\") {\n return new WorkflowSettlementReference({\n version: 1,\n submissionId: initial.settlement.submissionId,\n threadId: payload.receipt.threadId,\n settlementId: initial.settlement.settlementId,\n });\n }\n\n const status = yield* Effect.scoped(\n Effect.gen(function* () {\n // Serialize recovery and processing for one Thread even when a ledger allows\n // same-producer takeover. Followers wait without consuming a global permit.\n const lane = yield* RcMap.get(lanes, payload.receipt.threadId);\n\n return yield* lane.withPermit(\n permits.withPermit(\n Effect.scoped(\n Effect.gen(function* () {\n yield* runtime.recoverSubmission(payload.receipt.submissionId);\n const recovered = yield* runtime.inspectSubmissionStatus(payload.receipt);\n\n if (recovered._tag === \"settled\") return recovered;\n yield* runtime.processThreadHead(payload.receipt.threadId);\n\n return yield* runtime.inspectSubmissionStatus(payload.receipt);\n }),\n ),\n ),\n );\n }),\n ).pipe(Effect.orDie);\n\n if (status._tag === \"settled\") {\n return new WorkflowSettlementReference({\n version: 1,\n submissionId: status.settlement.submissionId,\n threadId: payload.receipt.threadId,\n settlementId: status.settlement.settlementId,\n });\n }\n // Release the permit and Attempt Scope before native suspension, whose lifetime may\n // outlast this process. Completion is never inferred from an empty processing result.\n const instance = yield* WorkflowEngine.WorkflowInstance;\n\n return yield* Workflow.suspend(instance);\n }),\n );\n\n const intentFor = Effect.fnUntraced(function* (receipt: Receipt) {\n const payload = new WorkflowSubmission({\n version: 1,\n deploymentId: config.deploymentId,\n receipt,\n });\n\n const executionId = yield* workflow.executionId(payload);\n\n return new WorkflowDispatchIntent({\n ...payload,\n workflowName: nativeName,\n executionId,\n });\n });\n\n const dispatchIntent = Effect.fnUntraced(\n function* (\n requested: WorkflowDispatchIntent,\n ): Effect.fn.Return<boolean, WorkflowRepairFailure> {\n let intent = requested;\n const expected = yield* intentFor(intent.receipt);\n\n if (\n intent.executionId !== expected.executionId ||\n intent.deploymentId !== expected.deploymentId ||\n intent.workflowName !== expected.workflowName\n ) {\n return yield* new WorkflowDispatchError({\n operation: \"dispatch\",\n message: \"Dispatch identity does not match the configured Workflow\",\n });\n }\n yield* validateReceipt(intent.receipt);\n yield* failpoint.hit(\"intent:before-persist\", intent);\n intent = yield* dispatch.put(intent);\n yield* failpoint.hit(\"intent:after-persist\", intent);\n yield* failpoint.hit(\"launch:before\", intent);\n // Submission lifetime belongs to the durable host. Strip the optional parent\n // instance so upstream child interruption cannot cancel this recovery workflow.\n yield* nativeOperation(\n \"execute\",\n engine\n .execute(workflow, {\n executionId: intent.executionId,\n payload: new WorkflowSubmission(intent),\n discard: true,\n })\n .pipe(\n Effect.updateContext((context: Context.Context<never>) =>\n Context.omit(WorkflowEngine.WorkflowInstance)(context),\n ),\n ),\n );\n yield* failpoint.hit(\"launch:after\", intent);\n // Resume before suspension may be a no-op. Keep the intent and retry on a later trigger.\n yield* nativeOperation(\"resume\", engine.resume(workflow, intent.executionId));\n yield* failpoint.hit(\"completion:before-observe\", intent);\n const result = yield* nativeOperation(\"poll\", engine.poll(workflow, intent.executionId));\n\n yield* failpoint.hit(\"completion:after-observe\", intent);\n if (Option.isNone(result) || result.value._tag !== \"Complete\") return false;\n if (Exit.isFailure(result.value.exit)) {\n return yield* new WorkflowDispatchError({\n operation: \"completion\",\n message: \"Native Workflow completed without a Settlement reference; intent retained\",\n cause: result.value.exit.cause,\n });\n }\n const status = yield* runtime.inspectSubmissionStatus(intent.receipt);\n const reference = result.value.exit.value;\n\n if (\n status._tag !== \"settled\" ||\n reference.version !== 1 ||\n reference.submissionId !== intent.receipt.submissionId ||\n reference.threadId !== intent.receipt.threadId ||\n reference.settlementId !== status.settlement.settlementId\n ) {\n return yield* new WorkflowDispatchError({\n operation: \"completion\",\n message: \"Native completion disagrees with canonical Settlement; intent retained\",\n });\n }\n if (intent.completionToken !== undefined) {\n yield* failpoint.hit(\"completion:before-notify\", intent);\n yield* nativeOperation(\n \"notify\",\n DurableDeferred.succeed(workflowCompletion(\"settlement\"), {\n token: intent.completionToken,\n value: reference,\n }).pipe(Effect.provideService(WorkflowEngine.WorkflowEngine, engine)),\n );\n yield* failpoint.hit(\"completion:after-notify\", intent);\n }\n yield* failpoint.hit(\"cleanup:before\", intent);\n yield* dispatch.remove(intent);\n yield* failpoint.hit(\"cleanup:after\", intent);\n\n return true;\n },\n (effect) => bounded(\"dispatch\", effect),\n );\n\n let submissionOffset = 0;\n let intentCursor: string | undefined;\n\n const repair = repairPermit.withPermit(\n Effect.gen(function* () {\n // Respect adapter ordering, which may differ from JavaScript string comparison.\n // Deletions may defer a row until the next wrap; restarts repeat idempotent work.\n const discovery = yield* bounded(\n \"scanSubmissions\",\n ledger.scanNonterminal.pipe(\n Stream.filter((row) => row.deploymentId === config.deploymentId),\n Stream.drop(submissionOffset),\n Stream.take(config.repairBatchSize),\n Stream.runCollect,\n ),\n ).pipe(Effect.result);\n\n const submissions = Result.isSuccess(discovery) ? discovery.success : [];\n\n if (Result.isSuccess(discovery)) {\n submissionOffset =\n submissions.length < config.repairBatchSize ? 0 : submissionOffset + submissions.length;\n }\n\n const discovered = yield* Effect.forEach(submissions, (row) =>\n Effect.flatMap(intentFor(new Receipt(row)), dispatchIntent).pipe(Effect.result),\n );\n\n const outstanding = yield* bounded(\n \"scanIntents\",\n dispatch.scan(\n new WorkflowDispatchScan({\n deploymentId: config.deploymentId,\n workflowName: nativeName,\n ...(intentCursor === undefined ? {} : { after: intentCursor }),\n limit: config.repairBatchSize,\n }),\n ),\n ).pipe(Effect.result);\n\n const intents = Result.isSuccess(outstanding) ? outstanding.success : [];\n\n if (Result.isSuccess(outstanding))\n intentCursor =\n intents.length < config.repairBatchSize\n ? undefined\n : intents[intents.length - 1]?.executionId;\n\n const inspected = yield* Effect.forEach(intents, (intent) =>\n dispatchIntent(intent).pipe(Effect.result),\n );\n\n const results = [...discovered, ...inspected];\n\n if (Result.isFailure(discovery)) return yield* discovery.failure;\n if (Result.isFailure(outstanding)) return yield* outstanding.failure;\n const failure = results.find(Result.isFailure);\n\n if (failure !== undefined) return yield* Effect.fail(failure.failure);\n\n return new WorkflowRepairReport({\n discovered: submissions.length,\n inspected: intents.length,\n completed: results.filter((result) => Result.isSuccess(result) && result.success).length,\n });\n }),\n );\n\n yield* trigger.register(\n repair.pipe(\n Effect.asVoid,\n Effect.catchCause((cause) =>\n Cause.hasInterruptsOnly(cause)\n ? Effect.interrupt\n : Effect.logError(\"Workflow dispatch repair failed; durable obligations remain\", cause),\n ),\n ),\n );\n yield* Effect.addFinalizer(() => Ref.set(admission, false));\n\n const submit = Effect.fnUntraced(function* <InputSchema extends Schema.Top>(\n agent: DurableSubmitAgent<InputSchema>,\n input: InputSchema[\"Type\"],\n options: DurableSubmitOptions,\n ): Effect.fn.Return<\n Receipt,\n DurableSubmitFailure | WorkflowRepairFailure | WorkflowAdmissionClosed,\n InputSchema[\"EncodingServices\"]\n > {\n if (!(yield* Ref.get(admission))) {\n return yield* new WorkflowAdmissionClosed({ message: \"The Workflow host is shutting down\" });\n }\n const receipt = yield* runtime.submit(agent, input, options);\n\n yield* dispatchIntent(yield* intentFor(receipt));\n\n return receipt;\n });\n\n const execute = Effect.fnUntraced(function* <Input extends Schema.Top, Output extends Schema.Top>(\n agent: WorkflowAgent<Input, Output>,\n input: Input[\"Type\"],\n options: WorkflowExecuteOptions,\n ) {\n const parentEngine = yield* WorkflowEngine.WorkflowEngine;\n\n if (parentEngine !== engine) {\n return yield* new WorkflowExecutionFailure({\n reason: \"engine-mismatch\",\n message: \"Agent host and parent workflow must share one WorkflowEngine Layer\",\n });\n }\n\n const name = yield* Schema.decodeEffect(Schema.NonEmptyString)(options.name).pipe(\n Effect.mapError(\n () =>\n new WorkflowExecutionFailure({\n reason: \"invalid-name\",\n message: \"Workflow agent steps need a nonempty stable name\",\n }),\n ),\n );\n\n const completion = workflowCompletion(`effect-agent/${name}`);\n const completionToken = yield* DurableDeferred.token(completion);\n\n // Agent identity and input deliberately do not participate: changing either on replay\n // must conflict with the original admission rather than launch new external work.\n const identity = yield* digestJson([\n config.deploymentId,\n config.principal,\n completionToken,\n ]).pipe(Effect.provideService(Crypto.Crypto, crypto));\n\n if (!(yield* Ref.get(admission))) {\n return yield* new WorkflowAdmissionClosed({ message: \"The Workflow host is shutting down\" });\n }\n\n const receipt = yield* runtime.submitRegistered({ definition: agent }, input, {\n threadId: ThreadId.make(`workflow/${identity}`),\n idempotencyKey: IdempotencyKey.make(identity),\n principal: config.principal,\n });\n\n yield* Effect.annotateCurrentSpan({\n \"agent.submission.id\": receipt.submissionId,\n \"agent.workflow.step\": name,\n });\n yield* runtime.submissionStatus(receipt);\n yield* dispatchIntent(\n new WorkflowDispatchIntent({ ...(yield* intentFor(receipt)), completionToken }),\n );\n\n // The deferred stores only a reference. Always reauthorize and read canonical data,\n // including on replay after the workflow engine has cached the notification.\n const reference = yield* DurableDeferred.await(completion);\n\n const record = yield* runtime.settlementRecord(receipt);\n\n if (\n reference.submissionId !== receipt.submissionId ||\n reference.threadId !== receipt.threadId ||\n reference.settlementId !== record.settlementId\n ) {\n return yield* new WorkflowDispatchError({\n operation: \"result\",\n message: \"Workflow completion disagrees with canonical Settlement\",\n });\n }\n if (record.outcome === \"failed\") {\n return yield* new WorkflowExecutionFailure({\n reason: \"failed\",\n message: \"Agent submission failed\",\n receipt,\n failure: record.result,\n });\n }\n if (record.outcome === \"aborted\") {\n return yield* new WorkflowExecutionFailure({\n reason: \"aborted\",\n message: \"Agent submission was aborted\",\n receipt,\n });\n }\n if (record.result === undefined) {\n return yield* new WorkflowExecutionFailure({\n reason: \"missing-output\",\n message: \"Completed submission has no independent output\",\n receipt,\n });\n }\n\n return yield* Schema.decodeEffect(agent.output)(record.result).pipe(\n Effect.mapError(\n (cause) =>\n new AgentOutputError({\n message: `Cannot decode canonical agent output: ${cause.message}`,\n }),\n ),\n );\n });\n\n return WorkflowAgentHost.of({\n execute,\n submit,\n awaitSettlement: runtime.awaitSettlement,\n observe: runtime.observe,\n abort: runtime.abort,\n resolveApproval: runtime.resolveApproval,\n resolveUnknown: runtime.resolveUnknown,\n submissionStatus: runtime.submissionStatus,\n repair,\n executionId: (receipt: Receipt) =>\n intentFor(receipt).pipe(Effect.map((intent) => intent.executionId)),\n });\n});\n\n/**\n * Optional engine-independent host. Supply the upstream WorkflowEngine, the existing\n * durable runtime and ledger, durable dispatch storage, and a host-owned repair trigger.\n * Do not also start the ordinary Node worker loop. Waiter interruption only detaches;\n * abort and resolutions retain the runtime's authorization and durable intent protocol.\n */\nexport class WorkflowAgentHost extends Context.Service<\n WorkflowAgentHost,\n {\n readonly execute: <Input extends Schema.Top, Output extends Schema.Top>(\n agent: WorkflowAgent<Input, Output>,\n input: Input[\"Type\"],\n options: WorkflowExecuteOptions,\n ) => Effect.Effect<\n Output[\"Type\"],\n | DurableSubmitFailure\n | BindingUnavailable\n | DurableAwaitFailure\n | WorkflowDispatchError\n | WorkflowAdmissionClosed\n | WorkflowExecutionFailure\n | AgentOutputError,\n | Input[\"EncodingServices\"]\n | Output[\"DecodingServices\"]\n | WorkflowEngine.WorkflowInstance\n | WorkflowEngine.WorkflowEngine\n >;\n readonly submit: <InputSchema extends Schema.Top>(\n agent: DurableSubmitAgent<InputSchema>,\n input: InputSchema[\"Type\"],\n options: DurableSubmitOptions,\n ) => Effect.Effect<\n Receipt,\n DurableSubmitFailure | WorkflowRepairFailure | WorkflowAdmissionClosed,\n InputSchema[\"EncodingServices\"]\n >;\n readonly awaitSettlement: DurableAgentRuntime[\"Service\"][\"awaitSettlement\"];\n readonly observe: DurableAgentRuntime[\"Service\"][\"observe\"];\n readonly abort: DurableAgentRuntime[\"Service\"][\"abort\"];\n readonly resolveApproval: DurableAgentRuntime[\"Service\"][\"resolveApproval\"];\n readonly resolveUnknown: DurableAgentRuntime[\"Service\"][\"resolveUnknown\"];\n readonly submissionStatus: DurableAgentRuntime[\"Service\"][\"submissionStatus\"];\n readonly repair: Effect.Effect<WorkflowRepairReport, WorkflowRepairFailure>;\n readonly executionId: (receipt: Receipt) => Effect.Effect<string>;\n }\n>()(\"@effect-agent/workflow/WorkflowAgentHost\") {\n /** Drive the injected runtime, whose Layer owns executable registrations and their services. */\n static layer(options: WorkflowAgentHostOptions) {\n return Layer.effect(WorkflowAgentHost)(makeHost(options));\n }\n}\n"],"mappings":";;;;;;;;;;;;;;AAKA,MAAa,sBAAsB,SACjC,gBAAgB,KAAK,MAAM,EAAE,SAAS,4BAA4B,CAAC;;;;;;;;ACiDrE,MAAM,qBAAqB,OAAO,OAAO;CACvC,cAAc;CACd,WAAW;CACX,cAAc,OAAO;CACrB,sBAAsB,OAAO,IAAI,MAAM,OAAO,UAAU;EAAE,SAAS;EAAG,SAAS;CAAG,CAAC,CAAC;CACpF,iBAAiB,OAAO,IAAI,MAAM,OAAO,UAAU;EAAE,SAAS;EAAG,SAAS;CAAK,CAAC,CAAC;CACjF,uBAAuB,OAAO,IAAI,MAAM,OAAO,UAAU;EAAE,SAAS;EAAG,SAAS;CAAQ,CAAC,CAAC;AAC5F,CAAC;AAED,IAAa,0BAAb,cAA6C,OAAO,YAAqC,CAAC,CACxF,2BACA,EAAE,SAAS,OAAO,OAAO,CAC3B,CAAC,CAAC,CAAC;AAEH,IAAa,0BAAb,cAA6C,OAAO,YAAqC,CAAC,CACxF,2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AI,OAAO,YAAY,UACrB,OAAO,OAAO,IAAI,yBAAyB;GACzC,QAAQ;GACR,SAAS;GACT;GACA,SAAS,OAAO;EAClB,CAAC;EAEH,IAAI,OAAO,YAAY,WACrB,OAAO,OAAO,IAAI,yBAAyB;GACzC,QAAQ;GACR,SAAS;GACT;EACF,CAAC;EAEH,IAAI,OAAO,WAAW,KAAA,GACpB,OAAO,OAAO,IAAI,yBAAyB;GACzC,QAAQ;GACR,SAAS;GACT;EACF,CAAC;EAGH,OAAO,OAAO,OAAO,aAAa,MAAM,MAAM,CAAC,CAAC,OAAO,MAAM,CAAC,CAAC,KAC7D,OAAO,UACJ,UACC,IAAI,iBAAiB,EACnB,SAAS,yCAAyC,MAAM,UAC1D,CAAC,CACL,CACF;CACF,CAAC;CAED,OAAO,kBAAkB,GAAG;EAC1B;EACA;EACA,iBAAiB,QAAQ;EACzB,SAAS,QAAQ;EACjB,OAAO,QAAQ;EACf,iBAAiB,QAAQ;EACzB,gBAAgB,QAAQ;EACxB,kBAAkB,QAAQ;EAC1B;EACA,cAAc,YACZ,UAAU,OAAO,CAAC,CAAC,KAAK,OAAO,KAAK,WAAW,OAAO,WAAW,CAAC;CACtE,CAAC;AACH,CAAC;;;;;;;AAQD,IAAa,oBAAb,MAAa,0BAA0B,QAAQ,QAuC7C,CAAC,CAAC,0CAA0C,CAAC,CAAC;;CAE9C,OAAO,MAAM,SAAmC;EAC9C,OAAO,MAAM,OAAO,iBAAiB,CAAC,CAAC,SAAS,OAAO,CAAC;CAC1D;AACF"}
@@ -1,4 +1,4 @@
1
1
  import "./WorkflowDispatch.mjs";
2
- import { i as WorkflowHostConfigError, n as WorkflowAgentHost, t as WorkflowAdmissionClosed } from "./WorkflowAgentHost-CqS43Ufw.mjs";
2
+ import { i as WorkflowHostConfigError, n as WorkflowAgentHost, t as WorkflowAdmissionClosed } from "./WorkflowAgentHost-DTcWCdU2.mjs";
3
3
  import "./WorkflowExecution.mjs";
4
4
  export { WorkflowAdmissionClosed, WorkflowAgentHost, WorkflowHostConfigError };
package/dist/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  import { t as WorkflowDispatch_exports } from "./WorkflowDispatch.mjs";
2
- import { r as WorkflowAgentHost_exports } from "./WorkflowAgentHost-CqS43Ufw.mjs";
2
+ import { r as WorkflowAgentHost_exports } from "./WorkflowAgentHost-DTcWCdU2.mjs";
3
3
  import { t as WorkflowExecution_exports } from "./WorkflowExecution.mjs";
4
4
  import { t as AgentWorkflow_exports } from "./AgentWorkflow.mjs";
5
5
  export { AgentWorkflow_exports as AgentWorkflow, WorkflowAgentHost_exports as WorkflowAgentHost, WorkflowDispatch_exports as WorkflowDispatch, WorkflowExecution_exports as WorkflowExecution };
package/package.json CHANGED
@@ -1 +1 @@
1
- {"name":"@yielded/agent-workflow","version":"0.1.0-beta.166","dependencies":{"@yielded/agent":"0.1.0-beta.166"},"devDependencies":{"@effect/platform-node":"4.0.0","@effect/vitest":"4.0.0","@yielded/agent-storage-memory":"0.1.0-beta.166","effect":"4.0.0","typescript":"7.0.2","vite-plus":"0.3.3"},"peerDependencies":{"effect":"^4.0.0"},"exports":{".":{"types":"./dist/index.d.mts","default":"./dist/index.mjs"},"./agent-workflow":{"types":"./dist/AgentWorkflow.d.mts","default":"./dist/AgentWorkflow.mjs"},"./workflow-agent-host":{"types":"./dist/WorkflowAgentHost.d.mts","default":"./dist/WorkflowAgentHost.mjs"},"./workflow-dispatch":{"types":"./dist/WorkflowDispatch.d.mts","default":"./dist/WorkflowDispatch.mjs"},"./workflow-execution":{"types":"./dist/WorkflowExecution.d.mts","default":"./dist/WorkflowExecution.mjs"}},"description":"Effect Workflow execution for the existing durable Agent runtime.","license":"MIT","repository":{"type":"git","url":"git+https://github.com/yielded-dev/agent.git","directory":"packages/workflow"},"files":["dist","src"],"type":"module","sideEffects":[],"publishConfig":{"access":"public"},"scripts":{"build":"vp pack","check":"tsc --noEmit -p tsconfig.json","test":"vp test --passWithNoTests"}}
1
+ {"name":"@yielded/agent-workflow","version":"0.1.0-beta.168","dependencies":{"@yielded/agent":"0.1.0-beta.168"},"devDependencies":{"@effect/platform-node":"4.0.3","@effect/vitest":"4.0.3","@yielded/agent-storage-memory":"0.1.0-beta.168","effect":"4.0.3","typescript":"7.0.2","vite":"npm:@voidzero-dev/vite-plus-core@1.1.0","vite-plus":"1.1.0","vitest":"5.0.3"},"peerDependencies":{"effect":"^4.0.0"},"exports":{".":{"types":"./dist/index.d.mts","default":"./dist/index.mjs"},"./agent-workflow":{"types":"./dist/AgentWorkflow.d.mts","default":"./dist/AgentWorkflow.mjs"},"./workflow-agent-host":{"types":"./dist/WorkflowAgentHost.d.mts","default":"./dist/WorkflowAgentHost.mjs"},"./workflow-dispatch":{"types":"./dist/WorkflowDispatch.d.mts","default":"./dist/WorkflowDispatch.mjs"},"./workflow-execution":{"types":"./dist/WorkflowExecution.d.mts","default":"./dist/WorkflowExecution.mjs"}},"description":"Effect Workflow execution for the existing durable Agent runtime.","license":"MIT","repository":{"type":"git","url":"git+https://github.com/yielded-dev/agent.git","directory":"packages/workflow"},"files":["dist","src"],"type":"module","sideEffects":[],"publishConfig":{"access":"public"},"scripts":{"build":"vp pack","check":"tsc --noEmit -p tsconfig.json","test":"vp test --passWithNoTests"}}
@@ -7,11 +7,11 @@ import {
7
7
  AdmissionConflict,
8
8
  AdmissionPolicyError,
9
9
  LedgerError,
10
+ OwnershipLost,
10
11
  SettlementConflict,
11
12
  } from "@yielded/agent/submission-ledger";
12
13
  import {
13
14
  AppendConflict,
14
- FenceRejected,
15
15
  ThreadNotMaterialized,
16
16
  ThreadStoreError,
17
17
  } from "@yielded/agent/thread-store";
@@ -35,8 +35,8 @@ export const Error = Schema.Union([
35
35
  BindingUnavailable,
36
36
  DigestError,
37
37
  DurableRuntimeFailpointError,
38
- FenceRejected,
39
38
  LedgerError,
39
+ OwnershipLost,
40
40
  OperationDenied,
41
41
  SettlementConflict,
42
42
  ThreadNotMaterialized,
@@ -57,7 +57,7 @@ export type Error = typeof Error.Type;
57
57
  * Pass the exact Agent Definition instance used in runtime registration; a same-ID copy fails
58
58
  * with BindingUnavailable before input encoding or admission.
59
59
  */
60
- export const execute = Effect.fn("AgentWorkflow.execute")(function* <
60
+ export const execute = Effect.fnUntraced(function* <
61
61
  Input extends Schema.Top,
62
62
  Output extends Schema.Top,
63
63
  >(agent: WorkflowAgent<Input, Output>, input: Input["Type"], options: WorkflowExecuteOptions) {
@@ -101,7 +101,7 @@ const nativeOperation = <A, E, R>(operation: string, effect: Effect.Effect<A, E,
101
101
  ),
102
102
  );
103
103
 
104
- const makeHost = Effect.fn("WorkflowAgentHost.make")(function* (options: WorkflowAgentHostOptions) {
104
+ const makeHost = Effect.fnUntraced(function* (options: WorkflowAgentHostOptions) {
105
105
  const config = yield* Schema.decodeEffect(WorkflowHostConfig)({
106
106
  deploymentId: options.deploymentId,
107
107
  principal: options.principal,
@@ -151,9 +151,7 @@ const makeHost = Effect.fn("WorkflowAgentHost.make")(function* (options: Workflo
151
151
  ),
152
152
  );
153
153
 
154
- const validateReceipt = Effect.fn("WorkflowAgentHost.validateReceipt")(function* (
155
- receipt: Receipt,
156
- ) {
154
+ const validateReceipt = Effect.fnUntraced(function* (receipt: Receipt) {
157
155
  const found = yield* ledger.lookup(
158
156
  SubmissionLookupById.make({ submissionId: receipt.submissionId }),
159
157
  );
@@ -176,7 +174,7 @@ const makeHost = Effect.fn("WorkflowAgentHost.make")(function* (options: Workflo
176
174
  // failure annotation suspends infrastructure failures and defects instead of settling them.
177
175
  yield* engine.register(
178
176
  workflow,
179
- Effect.fn("WorkflowAgentHost.execute")(function* (payload, executionId) {
177
+ Effect.fnUntraced(function* (payload, executionId) {
180
178
  yield* Effect.annotateCurrentSpan({
181
179
  "workflow.execution.id": executionId,
182
180
  "agent.submission.id": payload.receipt.submissionId,
@@ -240,7 +238,7 @@ const makeHost = Effect.fn("WorkflowAgentHost.make")(function* (options: Workflo
240
238
  }),
241
239
  );
242
240
 
243
- const intentFor = Effect.fn("WorkflowAgentHost.intentFor")(function* (receipt: Receipt) {
241
+ const intentFor = Effect.fnUntraced(function* (receipt: Receipt) {
244
242
  const payload = new WorkflowSubmission({
245
243
  version: 1,
246
244
  deploymentId: config.deploymentId,
@@ -256,7 +254,7 @@ const makeHost = Effect.fn("WorkflowAgentHost.make")(function* (options: Workflo
256
254
  });
257
255
  });
258
256
 
259
- const dispatchIntent = Effect.fn("WorkflowAgentHost.dispatch")(
257
+ const dispatchIntent = Effect.fnUntraced(
260
258
  function* (
261
259
  requested: WorkflowDispatchIntent,
262
260
  ): Effect.fn.Return<boolean, WorkflowRepairFailure> {
@@ -424,7 +422,7 @@ const makeHost = Effect.fn("WorkflowAgentHost.make")(function* (options: Workflo
424
422
  );
425
423
  yield* Effect.addFinalizer(() => Ref.set(admission, false));
426
424
 
427
- const submit = Effect.fn("WorkflowAgentHost.submit")(function* <InputSchema extends Schema.Top>(
425
+ const submit = Effect.fnUntraced(function* <InputSchema extends Schema.Top>(
428
426
  agent: DurableSubmitAgent<InputSchema>,
429
427
  input: InputSchema["Type"],
430
428
  options: DurableSubmitOptions,
@@ -443,10 +441,11 @@ const makeHost = Effect.fn("WorkflowAgentHost.make")(function* (options: Workflo
443
441
  return receipt;
444
442
  });
445
443
 
446
- const execute = Effect.fn("AgentWorkflow.execute")(function* <
447
- Input extends Schema.Top,
448
- Output extends Schema.Top,
449
- >(agent: WorkflowAgent<Input, Output>, input: Input["Type"], options: WorkflowExecuteOptions) {
444
+ const execute = Effect.fnUntraced(function* <Input extends Schema.Top, Output extends Schema.Top>(
445
+ agent: WorkflowAgent<Input, Output>,
446
+ input: Input["Type"],
447
+ options: WorkflowExecuteOptions,
448
+ ) {
450
449
  const parentEngine = yield* WorkflowEngine.WorkflowEngine;
451
450
 
452
451
  if (parentEngine !== engine) {
@@ -555,9 +554,8 @@ const makeHost = Effect.fn("WorkflowAgentHost.make")(function* (options: Workflo
555
554
  resolveUnknown: runtime.resolveUnknown,
556
555
  submissionStatus: runtime.submissionStatus,
557
556
  repair,
558
- executionId: Effect.fn("WorkflowAgentHost.executionId")((receipt: Receipt) =>
557
+ executionId: (receipt: Receipt) =>
559
558
  intentFor(receipt).pipe(Effect.map((intent) => intent.executionId)),
560
- ),
561
559
  });
562
560
  });
563
561
 
@@ -1 +0,0 @@
1
- {"version":3,"file":"WorkflowAgentHost-CqS43Ufw.mjs","names":[],"sources":["../src/internal/completion.ts","../src/WorkflowAgentHost.ts"],"sourcesContent":["import { DurableDeferred } from \"effect/workflow\";\n\nimport { WorkflowSettlementReference } from \"../WorkflowDispatch.ts\";\n\n/** Native deferred results contain only canonical identities, never a second agent result. */\nexport const workflowCompletion = (name: string) =>\n DurableDeferred.make(name, { success: WorkflowSettlementReference });\n","import { AgentOutputError } from \"@yielded/agent/agent-error\";\nimport { type BindingUnavailable } from \"@yielded/agent/agent-registration\";\nimport { digestJson } from \"@yielded/agent/digest\";\nimport {\n DurableAgentRuntime,\n DurableRuntimeConfig,\n Receipt,\n type DurableAwaitFailure,\n type DurableSubmitAgent,\n type DurableSubmitFailure,\n type DurableSubmitOptions,\n} from \"@yielded/agent/durable-agent-runtime\";\nimport { ThreadId } from \"@yielded/agent/identifiers\";\nimport { DeploymentId } from \"@yielded/agent/records\";\nimport {\n IdempotencyKey,\n Principal,\n SubmissionLedger,\n SubmissionLookupById,\n} from \"@yielded/agent/submission-ledger\";\nimport {\n Cause,\n Context,\n Crypto,\n Effect,\n Exit,\n Layer,\n Option,\n RcMap,\n Ref,\n Result,\n Schema,\n Semaphore,\n Stream,\n} from \"effect\";\nimport { DurableDeferred, Workflow, WorkflowEngine } from \"effect/workflow\";\n\nimport { workflowCompletion } from \"./internal/completion.ts\";\nimport {\n WorkflowDispatchError,\n WorkflowDispatchFailpoint,\n WorkflowDispatchIntent,\n WorkflowDispatchScan,\n WorkflowDispatchStore,\n WorkflowRepairReport,\n WorkflowRepairTrigger,\n WorkflowSettlementReference,\n WorkflowSubmission,\n} from \"./WorkflowDispatch.ts\";\nimport {\n WorkflowExecutionFailure,\n type WorkflowAgent,\n type WorkflowExecuteOptions,\n} from \"./WorkflowExecution.ts\";\n\nconst WorkflowHostConfig = Schema.Struct({\n deploymentId: DeploymentId,\n principal: Principal,\n workflowName: Schema.NonEmptyString,\n executionConcurrency: Schema.Int.check(Schema.isBetween({ minimum: 1, maximum: 64 })),\n repairBatchSize: Schema.Int.check(Schema.isBetween({ minimum: 1, maximum: 1000 })),\n dispatchTimeoutMillis: Schema.Int.check(Schema.isBetween({ minimum: 1, maximum: 300_000 })),\n});\n\nexport class WorkflowHostConfigError extends Schema.TaggedError<WorkflowHostConfigError>()(\n \"WorkflowHostConfigError\",\n { message: Schema.String },\n) {}\n\nexport class WorkflowAdmissionClosed extends Schema.TaggedError<WorkflowAdmissionClosed>()(\n \"WorkflowAdmissionClosed\",\n { message: Schema.String },\n) {}\n\nexport interface WorkflowAgentHostOptions {\n readonly deploymentId: string;\n /** Application-owned identity for submissions from AgentWorkflow.execute. */\n readonly principal: string;\n /** Stable versioned name prefix. The native name also includes deploymentId. */\n readonly workflowName?: string;\n /** Concurrent Attempts within this host Layer instance, not a fleet-wide limit. Default 1. */\n readonly executionConcurrency?: number;\n /** Maximum entries per scan per repair invocation. Default 32. */\n readonly repairBatchSize?: number;\n /** Bound each dispatch or scan, including a retrying native engine. Default 10000 ms. */\n readonly dispatchTimeoutMillis?: number;\n}\n\nexport type WorkflowRepairFailure = WorkflowDispatchError | DurableAwaitFailure;\n\nconst nativeOperation = <A, E, R>(operation: string, effect: Effect.Effect<A, E, R>) =>\n effect.pipe(\n Effect.catchDefect((cause) =>\n Effect.fail(\n new WorkflowDispatchError({\n operation,\n message: \"Workflow engine operation failed\",\n cause,\n }),\n ),\n ),\n );\n\nconst makeHost = Effect.fn(\"WorkflowAgentHost.make\")(function* (options: WorkflowAgentHostOptions) {\n const config = yield* Schema.decodeEffect(WorkflowHostConfig)({\n deploymentId: options.deploymentId,\n principal: options.principal,\n workflowName: options.workflowName ?? \"effect-agent/Submission/v1\",\n executionConcurrency: options.executionConcurrency ?? 1,\n repairBatchSize: options.repairBatchSize ?? 32,\n dispatchTimeoutMillis: options.dispatchTimeoutMillis ?? 10_000,\n }).pipe(Effect.mapError((error) => new WorkflowHostConfigError({ message: error.message })));\n\n const runtime = yield* DurableAgentRuntime;\n const crypto = yield* Crypto.Crypto;\n const runtimeConfig = yield* DurableRuntimeConfig;\n const ledger = yield* SubmissionLedger;\n const engine = yield* WorkflowEngine.WorkflowEngine;\n const dispatch = yield* WorkflowDispatchStore;\n const trigger = yield* WorkflowRepairTrigger;\n const failpoint = yield* WorkflowDispatchFailpoint;\n\n if (runtimeConfig.deploymentId !== config.deploymentId) {\n return yield* new WorkflowHostConfigError({\n message: \"Workflow and durable runtime deploymentId must match\",\n });\n }\n const permits = yield* Semaphore.make(config.executionConcurrency);\n const lanes = yield* RcMap.make({ lookup: (_threadId: ThreadId) => Semaphore.make(1) });\n const repairPermit = yield* Semaphore.make(1);\n const admission = yield* Ref.make(true);\n const nativeName = `${config.workflowName}/deployment/${config.deploymentId.length}:${config.deploymentId}`;\n\n const workflow = Workflow.make(nativeName, {\n payload: WorkflowSubmission,\n success: WorkflowSettlementReference,\n idempotencyKey: ({ deploymentId, receipt }) =>\n `v1/${deploymentId.length}:${deploymentId}/${receipt.submissionId}`,\n }).annotate(Workflow.SuspendOnFailure, true);\n\n const bounded = <A, E, R>(operation: string, effect: Effect.Effect<A, E, R>) =>\n nativeOperation(operation, effect).pipe(\n Effect.timeout(config.dispatchTimeoutMillis),\n Effect.catchTag(\"TimeoutError\", () =>\n Effect.fail(\n WorkflowDispatchError.make({\n operation,\n message: \"Workflow dispatch operation timed out; accepted work remains recoverable\",\n }),\n ),\n ),\n );\n\n const validateReceipt = Effect.fn(\"WorkflowAgentHost.validateReceipt\")(function* (\n receipt: Receipt,\n ) {\n const found = yield* ledger.lookup(\n SubmissionLookupById.make({ submissionId: receipt.submissionId }),\n );\n\n if (\n Option.isNone(found) ||\n found.value.deploymentId !== config.deploymentId ||\n found.value.threadId !== receipt.threadId ||\n found.value.receiptId !== receipt.receiptId ||\n found.value.queueSequence !== receipt.queueSequence\n ) {\n return yield* WorkflowDispatchError.make({\n operation: \"identity\",\n message: \"Workflow Receipt does not match its authoritative deployment and Submission\",\n });\n }\n });\n\n // No Activities: rerun journal recovery directly on every native resume. The upstream\n // failure annotation suspends infrastructure failures and defects instead of settling them.\n yield* engine.register(\n workflow,\n Effect.fn(\"WorkflowAgentHost.execute\")(function* (payload, executionId) {\n yield* Effect.annotateCurrentSpan({\n \"workflow.execution.id\": executionId,\n \"agent.submission.id\": payload.receipt.submissionId,\n \"agent.thread.id\": payload.receipt.threadId,\n });\n if (payload.deploymentId !== config.deploymentId) {\n return yield* Effect.die(\"Workflow payload belongs to another deployment\");\n }\n if (executionId !== (yield* workflow.executionId(payload))) {\n return yield* Effect.die(\"Workflow execution identity does not match its Submission\");\n }\n yield* validateReceipt(payload.receipt).pipe(Effect.orDie);\n const initial = yield* runtime.inspectSubmissionStatus(payload.receipt).pipe(Effect.orDie);\n\n if (initial._tag === \"settled\") {\n return new WorkflowSettlementReference({\n version: 1,\n submissionId: initial.settlement.submissionId,\n threadId: payload.receipt.threadId,\n settlementId: initial.settlement.settlementId,\n });\n }\n\n const status = yield* Effect.scoped(\n Effect.gen(function* () {\n // Serialize recovery and processing for one Thread even when a ledger allows\n // same-producer takeover. Followers wait without consuming a global permit.\n const lane = yield* RcMap.get(lanes, payload.receipt.threadId);\n\n return yield* lane.withPermit(\n permits.withPermit(\n Effect.scoped(\n Effect.gen(function* () {\n yield* runtime.recoverSubmission(payload.receipt.submissionId);\n const recovered = yield* runtime.inspectSubmissionStatus(payload.receipt);\n\n if (recovered._tag === \"settled\") return recovered;\n yield* runtime.processThreadHead(payload.receipt.threadId);\n\n return yield* runtime.inspectSubmissionStatus(payload.receipt);\n }),\n ),\n ),\n );\n }),\n ).pipe(Effect.orDie);\n\n if (status._tag === \"settled\") {\n return new WorkflowSettlementReference({\n version: 1,\n submissionId: status.settlement.submissionId,\n threadId: payload.receipt.threadId,\n settlementId: status.settlement.settlementId,\n });\n }\n // Release the permit and Attempt Scope before native suspension, whose lifetime may\n // outlast this process. Completion is never inferred from an empty processing result.\n const instance = yield* WorkflowEngine.WorkflowInstance;\n\n return yield* Workflow.suspend(instance);\n }),\n );\n\n const intentFor = Effect.fn(\"WorkflowAgentHost.intentFor\")(function* (receipt: Receipt) {\n const payload = new WorkflowSubmission({\n version: 1,\n deploymentId: config.deploymentId,\n receipt,\n });\n\n const executionId = yield* workflow.executionId(payload);\n\n return new WorkflowDispatchIntent({\n ...payload,\n workflowName: nativeName,\n executionId,\n });\n });\n\n const dispatchIntent = Effect.fn(\"WorkflowAgentHost.dispatch\")(\n function* (\n requested: WorkflowDispatchIntent,\n ): Effect.fn.Return<boolean, WorkflowRepairFailure> {\n let intent = requested;\n const expected = yield* intentFor(intent.receipt);\n\n if (\n intent.executionId !== expected.executionId ||\n intent.deploymentId !== expected.deploymentId ||\n intent.workflowName !== expected.workflowName\n ) {\n return yield* new WorkflowDispatchError({\n operation: \"dispatch\",\n message: \"Dispatch identity does not match the configured Workflow\",\n });\n }\n yield* validateReceipt(intent.receipt);\n yield* failpoint.hit(\"intent:before-persist\", intent);\n intent = yield* dispatch.put(intent);\n yield* failpoint.hit(\"intent:after-persist\", intent);\n yield* failpoint.hit(\"launch:before\", intent);\n // Submission lifetime belongs to the durable host. Strip the optional parent\n // instance so upstream child interruption cannot cancel this recovery workflow.\n yield* nativeOperation(\n \"execute\",\n engine\n .execute(workflow, {\n executionId: intent.executionId,\n payload: new WorkflowSubmission(intent),\n discard: true,\n })\n .pipe(\n Effect.updateContext((context: Context.Context<never>) =>\n Context.omit(WorkflowEngine.WorkflowInstance)(context),\n ),\n ),\n );\n yield* failpoint.hit(\"launch:after\", intent);\n // Resume before suspension may be a no-op. Keep the intent and retry on a later trigger.\n yield* nativeOperation(\"resume\", engine.resume(workflow, intent.executionId));\n yield* failpoint.hit(\"completion:before-observe\", intent);\n const result = yield* nativeOperation(\"poll\", engine.poll(workflow, intent.executionId));\n\n yield* failpoint.hit(\"completion:after-observe\", intent);\n if (Option.isNone(result) || result.value._tag !== \"Complete\") return false;\n if (Exit.isFailure(result.value.exit)) {\n return yield* new WorkflowDispatchError({\n operation: \"completion\",\n message: \"Native Workflow completed without a Settlement reference; intent retained\",\n cause: result.value.exit.cause,\n });\n }\n const status = yield* runtime.inspectSubmissionStatus(intent.receipt);\n const reference = result.value.exit.value;\n\n if (\n status._tag !== \"settled\" ||\n reference.version !== 1 ||\n reference.submissionId !== intent.receipt.submissionId ||\n reference.threadId !== intent.receipt.threadId ||\n reference.settlementId !== status.settlement.settlementId\n ) {\n return yield* new WorkflowDispatchError({\n operation: \"completion\",\n message: \"Native completion disagrees with canonical Settlement; intent retained\",\n });\n }\n if (intent.completionToken !== undefined) {\n yield* failpoint.hit(\"completion:before-notify\", intent);\n yield* nativeOperation(\n \"notify\",\n DurableDeferred.succeed(workflowCompletion(\"settlement\"), {\n token: intent.completionToken,\n value: reference,\n }).pipe(Effect.provideService(WorkflowEngine.WorkflowEngine, engine)),\n );\n yield* failpoint.hit(\"completion:after-notify\", intent);\n }\n yield* failpoint.hit(\"cleanup:before\", intent);\n yield* dispatch.remove(intent);\n yield* failpoint.hit(\"cleanup:after\", intent);\n\n return true;\n },\n (effect) => bounded(\"dispatch\", effect),\n );\n\n let submissionOffset = 0;\n let intentCursor: string | undefined;\n\n const repair = repairPermit.withPermit(\n Effect.gen(function* () {\n // Respect adapter ordering, which may differ from JavaScript string comparison.\n // Deletions may defer a row until the next wrap; restarts repeat idempotent work.\n const discovery = yield* bounded(\n \"scanSubmissions\",\n ledger.scanNonterminal.pipe(\n Stream.filter((row) => row.deploymentId === config.deploymentId),\n Stream.drop(submissionOffset),\n Stream.take(config.repairBatchSize),\n Stream.runCollect,\n ),\n ).pipe(Effect.result);\n\n const submissions = Result.isSuccess(discovery) ? discovery.success : [];\n\n if (Result.isSuccess(discovery)) {\n submissionOffset =\n submissions.length < config.repairBatchSize ? 0 : submissionOffset + submissions.length;\n }\n\n const discovered = yield* Effect.forEach(submissions, (row) =>\n Effect.flatMap(intentFor(new Receipt(row)), dispatchIntent).pipe(Effect.result),\n );\n\n const outstanding = yield* bounded(\n \"scanIntents\",\n dispatch.scan(\n new WorkflowDispatchScan({\n deploymentId: config.deploymentId,\n workflowName: nativeName,\n ...(intentCursor === undefined ? {} : { after: intentCursor }),\n limit: config.repairBatchSize,\n }),\n ),\n ).pipe(Effect.result);\n\n const intents = Result.isSuccess(outstanding) ? outstanding.success : [];\n\n if (Result.isSuccess(outstanding))\n intentCursor =\n intents.length < config.repairBatchSize\n ? undefined\n : intents[intents.length - 1]?.executionId;\n\n const inspected = yield* Effect.forEach(intents, (intent) =>\n dispatchIntent(intent).pipe(Effect.result),\n );\n\n const results = [...discovered, ...inspected];\n\n if (Result.isFailure(discovery)) return yield* discovery.failure;\n if (Result.isFailure(outstanding)) return yield* outstanding.failure;\n const failure = results.find(Result.isFailure);\n\n if (failure !== undefined) return yield* Effect.fail(failure.failure);\n\n return new WorkflowRepairReport({\n discovered: submissions.length,\n inspected: intents.length,\n completed: results.filter((result) => Result.isSuccess(result) && result.success).length,\n });\n }),\n );\n\n yield* trigger.register(\n repair.pipe(\n Effect.asVoid,\n Effect.catchCause((cause) =>\n Cause.hasInterruptsOnly(cause)\n ? Effect.interrupt\n : Effect.logError(\"Workflow dispatch repair failed; durable obligations remain\", cause),\n ),\n ),\n );\n yield* Effect.addFinalizer(() => Ref.set(admission, false));\n\n const submit = Effect.fn(\"WorkflowAgentHost.submit\")(function* <InputSchema extends Schema.Top>(\n agent: DurableSubmitAgent<InputSchema>,\n input: InputSchema[\"Type\"],\n options: DurableSubmitOptions,\n ): Effect.fn.Return<\n Receipt,\n DurableSubmitFailure | WorkflowRepairFailure | WorkflowAdmissionClosed,\n InputSchema[\"EncodingServices\"]\n > {\n if (!(yield* Ref.get(admission))) {\n return yield* new WorkflowAdmissionClosed({ message: \"The Workflow host is shutting down\" });\n }\n const receipt = yield* runtime.submit(agent, input, options);\n\n yield* dispatchIntent(yield* intentFor(receipt));\n\n return receipt;\n });\n\n const execute = Effect.fn(\"AgentWorkflow.execute\")(function* <\n Input extends Schema.Top,\n Output extends Schema.Top,\n >(agent: WorkflowAgent<Input, Output>, input: Input[\"Type\"], options: WorkflowExecuteOptions) {\n const parentEngine = yield* WorkflowEngine.WorkflowEngine;\n\n if (parentEngine !== engine) {\n return yield* new WorkflowExecutionFailure({\n reason: \"engine-mismatch\",\n message: \"Agent host and parent workflow must share one WorkflowEngine Layer\",\n });\n }\n\n const name = yield* Schema.decodeEffect(Schema.NonEmptyString)(options.name).pipe(\n Effect.mapError(\n () =>\n new WorkflowExecutionFailure({\n reason: \"invalid-name\",\n message: \"Workflow agent steps need a nonempty stable name\",\n }),\n ),\n );\n\n const completion = workflowCompletion(`effect-agent/${name}`);\n const completionToken = yield* DurableDeferred.token(completion);\n\n // Agent identity and input deliberately do not participate: changing either on replay\n // must conflict with the original admission rather than launch new external work.\n const identity = yield* digestJson([\n config.deploymentId,\n config.principal,\n completionToken,\n ]).pipe(Effect.provideService(Crypto.Crypto, crypto));\n\n if (!(yield* Ref.get(admission))) {\n return yield* new WorkflowAdmissionClosed({ message: \"The Workflow host is shutting down\" });\n }\n\n const receipt = yield* runtime.submitRegistered({ definition: agent }, input, {\n threadId: ThreadId.make(`workflow/${identity}`),\n idempotencyKey: IdempotencyKey.make(identity),\n principal: config.principal,\n });\n\n yield* Effect.annotateCurrentSpan({\n \"agent.submission.id\": receipt.submissionId,\n \"agent.workflow.step\": name,\n });\n yield* runtime.submissionStatus(receipt);\n yield* dispatchIntent(\n new WorkflowDispatchIntent({ ...(yield* intentFor(receipt)), completionToken }),\n );\n\n // The deferred stores only a reference. Always reauthorize and read canonical data,\n // including on replay after the workflow engine has cached the notification.\n const reference = yield* DurableDeferred.await(completion);\n\n const record = yield* runtime.settlementRecord(receipt);\n\n if (\n reference.submissionId !== receipt.submissionId ||\n reference.threadId !== receipt.threadId ||\n reference.settlementId !== record.settlementId\n ) {\n return yield* new WorkflowDispatchError({\n operation: \"result\",\n message: \"Workflow completion disagrees with canonical Settlement\",\n });\n }\n if (record.outcome === \"failed\") {\n return yield* new WorkflowExecutionFailure({\n reason: \"failed\",\n message: \"Agent submission failed\",\n receipt,\n failure: record.result,\n });\n }\n if (record.outcome === \"aborted\") {\n return yield* new WorkflowExecutionFailure({\n reason: \"aborted\",\n message: \"Agent submission was aborted\",\n receipt,\n });\n }\n if (record.result === undefined) {\n return yield* new WorkflowExecutionFailure({\n reason: \"missing-output\",\n message: \"Completed submission has no independent output\",\n receipt,\n });\n }\n\n return yield* Schema.decodeEffect(agent.output)(record.result).pipe(\n Effect.mapError(\n (cause) =>\n new AgentOutputError({\n message: `Cannot decode canonical agent output: ${cause.message}`,\n }),\n ),\n );\n });\n\n return WorkflowAgentHost.of({\n execute,\n submit,\n awaitSettlement: runtime.awaitSettlement,\n observe: runtime.observe,\n abort: runtime.abort,\n resolveApproval: runtime.resolveApproval,\n resolveUnknown: runtime.resolveUnknown,\n submissionStatus: runtime.submissionStatus,\n repair,\n executionId: Effect.fn(\"WorkflowAgentHost.executionId\")((receipt: Receipt) =>\n intentFor(receipt).pipe(Effect.map((intent) => intent.executionId)),\n ),\n });\n});\n\n/**\n * Optional engine-independent host. Supply the upstream WorkflowEngine, the existing\n * durable runtime and ledger, durable dispatch storage, and a host-owned repair trigger.\n * Do not also start the ordinary Node worker loop. Waiter interruption only detaches;\n * abort and resolutions retain the runtime's authorization and durable intent protocol.\n */\nexport class WorkflowAgentHost extends Context.Service<\n WorkflowAgentHost,\n {\n readonly execute: <Input extends Schema.Top, Output extends Schema.Top>(\n agent: WorkflowAgent<Input, Output>,\n input: Input[\"Type\"],\n options: WorkflowExecuteOptions,\n ) => Effect.Effect<\n Output[\"Type\"],\n | DurableSubmitFailure\n | BindingUnavailable\n | DurableAwaitFailure\n | WorkflowDispatchError\n | WorkflowAdmissionClosed\n | WorkflowExecutionFailure\n | AgentOutputError,\n | Input[\"EncodingServices\"]\n | Output[\"DecodingServices\"]\n | WorkflowEngine.WorkflowInstance\n | WorkflowEngine.WorkflowEngine\n >;\n readonly submit: <InputSchema extends Schema.Top>(\n agent: DurableSubmitAgent<InputSchema>,\n input: InputSchema[\"Type\"],\n options: DurableSubmitOptions,\n ) => Effect.Effect<\n Receipt,\n DurableSubmitFailure | WorkflowRepairFailure | WorkflowAdmissionClosed,\n InputSchema[\"EncodingServices\"]\n >;\n readonly awaitSettlement: DurableAgentRuntime[\"Service\"][\"awaitSettlement\"];\n readonly observe: DurableAgentRuntime[\"Service\"][\"observe\"];\n readonly abort: DurableAgentRuntime[\"Service\"][\"abort\"];\n readonly resolveApproval: DurableAgentRuntime[\"Service\"][\"resolveApproval\"];\n readonly resolveUnknown: DurableAgentRuntime[\"Service\"][\"resolveUnknown\"];\n readonly submissionStatus: DurableAgentRuntime[\"Service\"][\"submissionStatus\"];\n readonly repair: Effect.Effect<WorkflowRepairReport, WorkflowRepairFailure>;\n readonly executionId: (receipt: Receipt) => Effect.Effect<string>;\n }\n>()(\"@effect-agent/workflow/WorkflowAgentHost\") {\n /** Drive the injected runtime, whose Layer owns executable registrations and their services. */\n static layer(options: WorkflowAgentHostOptions) {\n return Layer.effect(WorkflowAgentHost)(makeHost(options));\n }\n}\n"],"mappings":";;;;;;;;;;;;;;AAKA,MAAa,sBAAsB,SACjC,gBAAgB,KAAK,MAAM,EAAE,SAAS,4BAA4B,CAAC;;;;;;;;ACiDrE,MAAM,qBAAqB,OAAO,OAAO;CACvC,cAAc;CACd,WAAW;CACX,cAAc,OAAO;CACrB,sBAAsB,OAAO,IAAI,MAAM,OAAO,UAAU;EAAE,SAAS;EAAG,SAAS;CAAG,CAAC,CAAC;CACpF,iBAAiB,OAAO,IAAI,MAAM,OAAO,UAAU;EAAE,SAAS;EAAG,SAAS;CAAK,CAAC,CAAC;CACjF,uBAAuB,OAAO,IAAI,MAAM,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