@archmax-ai/harness 0.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +219 -0
- package/dist/agent.d.ts +174 -0
- package/dist/agent.js +140 -0
- package/dist/agent.js.map +1 -0
- package/dist/assembly/compose.d.ts +170 -0
- package/dist/assembly/compose.js +391 -0
- package/dist/assembly/compose.js.map +1 -0
- package/dist/assembly/delegation-registry.d.ts +5 -0
- package/dist/assembly/delegation-registry.js +118 -0
- package/dist/assembly/delegation-registry.js.map +1 -0
- package/dist/assembly/index.d.ts +192 -0
- package/dist/assembly/index.js +265 -0
- package/dist/assembly/index.js.map +1 -0
- package/dist/assembly/plain.d.ts +7 -0
- package/dist/assembly/plain.js +41 -0
- package/dist/assembly/plain.js.map +1 -0
- package/dist/authoring-skill/archmax-harness/README.md +76 -0
- package/dist/authoring-skill/archmax-harness/SKILL.md +241 -0
- package/dist/authoring-skill/archmax-harness/references/backend-integration.md +626 -0
- package/dist/authoring-skill/archmax-harness/references/cases.md +41 -0
- package/dist/authoring-skill/archmax-harness/references/diagnostics.md +51 -0
- package/dist/authoring-skill/archmax-harness/references/hook-and-test-scripts.md +1070 -0
- package/dist/authoring-skill/archmax-harness/references/hooks-and-scripts.md +82 -0
- package/dist/authoring-skill/archmax-harness/references/wiring.md +101 -0
- package/dist/authoring-skill/archmax-harness/references/workflow-schema.md +1631 -0
- package/dist/authoring-skill/archmax-harness/references/workflow-yaml.md +241 -0
- package/dist/behaviour/support.d.ts +232 -0
- package/dist/behaviour/support.js +339 -0
- package/dist/behaviour/support.js.map +1 -0
- package/dist/cli/banner.d.ts +11 -0
- package/dist/cli/banner.js +29 -0
- package/dist/cli/banner.js.map +1 -0
- package/dist/cli/bootstrap.d.ts +33 -0
- package/dist/cli/bootstrap.js +153 -0
- package/dist/cli/bootstrap.js.map +1 -0
- package/dist/cli/command.d.ts +39 -0
- package/dist/cli/command.js +97 -0
- package/dist/cli/command.js.map +1 -0
- package/dist/cli/state-flow.d.ts +46 -0
- package/dist/cli/state-flow.js +268 -0
- package/dist/cli/state-flow.js.map +1 -0
- package/dist/cli/style.d.ts +41 -0
- package/dist/cli/style.js +64 -0
- package/dist/cli/style.js.map +1 -0
- package/dist/cli/turn.d.ts +41 -0
- package/dist/cli/turn.js +161 -0
- package/dist/cli/turn.js.map +1 -0
- package/dist/cli.d.ts +10 -0
- package/dist/cli.js +426 -0
- package/dist/cli.js.map +1 -0
- package/dist/core/code-description.d.ts +22 -0
- package/dist/core/code-description.js +38 -0
- package/dist/core/code-description.js.map +1 -0
- package/dist/core/deepagents.d.ts +183 -0
- package/dist/core/deepagents.js +128 -0
- package/dist/core/deepagents.js.map +1 -0
- package/dist/core/events.d.ts +350 -0
- package/dist/core/events.js +205 -0
- package/dist/core/events.js.map +1 -0
- package/dist/core/frontmatter.d.ts +15 -0
- package/dist/core/frontmatter.js +32 -0
- package/dist/core/frontmatter.js.map +1 -0
- package/dist/core/listing-redact.d.ts +37 -0
- package/dist/core/listing-redact.js +88 -0
- package/dist/core/listing-redact.js.map +1 -0
- package/dist/core/match.d.ts +26 -0
- package/dist/core/match.js +75 -0
- package/dist/core/match.js.map +1 -0
- package/dist/core/message-readers.d.ts +84 -0
- package/dist/core/message-readers.js +159 -0
- package/dist/core/message-readers.js.map +1 -0
- package/dist/core/messages.d.ts +49 -0
- package/dist/core/messages.js +85 -0
- package/dist/core/messages.js.map +1 -0
- package/dist/core/mount-prompt.d.ts +28 -0
- package/dist/core/mount-prompt.js +55 -0
- package/dist/core/mount-prompt.js.map +1 -0
- package/dist/core/mount-redact.d.ts +28 -0
- package/dist/core/mount-redact.js +32 -0
- package/dist/core/mount-redact.js.map +1 -0
- package/dist/core/mounts.d.ts +88 -0
- package/dist/core/mounts.js +147 -0
- package/dist/core/mounts.js.map +1 -0
- package/dist/core/path-mapping.d.ts +52 -0
- package/dist/core/path-mapping.js +113 -0
- package/dist/core/path-mapping.js.map +1 -0
- package/dist/core/platform-prompt.generated.d.ts +2 -0
- package/dist/core/platform-prompt.generated.js +4 -0
- package/dist/core/platform-prompt.generated.js.map +1 -0
- package/dist/core/prompt.d.ts +42 -0
- package/dist/core/prompt.js +75 -0
- package/dist/core/prompt.js.map +1 -0
- package/dist/core/session-id.d.ts +38 -0
- package/dist/core/session-id.js +61 -0
- package/dist/core/session-id.js.map +1 -0
- package/dist/core/session-store.d.ts +85 -0
- package/dist/core/session-store.js +149 -0
- package/dist/core/session-store.js.map +1 -0
- package/dist/core/session-zone.d.ts +54 -0
- package/dist/core/session-zone.js +82 -0
- package/dist/core/session-zone.js.map +1 -0
- package/dist/core/skill-prompt.d.ts +31 -0
- package/dist/core/skill-prompt.js +54 -0
- package/dist/core/skill-prompt.js.map +1 -0
- package/dist/core/skill-redact.d.ts +15 -0
- package/dist/core/skill-redact.js +27 -0
- package/dist/core/skill-redact.js.map +1 -0
- package/dist/core/skills.d.ts +172 -0
- package/dist/core/skills.js +214 -0
- package/dist/core/skills.js.map +1 -0
- package/dist/core/tool-mocks.d.ts +23 -0
- package/dist/core/tool-mocks.js +39 -0
- package/dist/core/tool-mocks.js.map +1 -0
- package/dist/core/tool-telemetry.d.ts +16 -0
- package/dist/core/tool-telemetry.js +40 -0
- package/dist/core/tool-telemetry.js.map +1 -0
- package/dist/core/usage.d.ts +114 -0
- package/dist/core/usage.js +226 -0
- package/dist/core/usage.js.map +1 -0
- package/dist/core/workspace-context.d.ts +136 -0
- package/dist/core/workspace-context.js +178 -0
- package/dist/core/workspace-context.js.map +1 -0
- package/dist/core/workspace-prompt.d.ts +7 -0
- package/dist/core/workspace-prompt.js +102 -0
- package/dist/core/workspace-prompt.js.map +1 -0
- package/dist/core/workspace-router.d.ts +61 -0
- package/dist/core/workspace-router.js +145 -0
- package/dist/core/workspace-router.js.map +1 -0
- package/dist/core/workspace.d.ts +85 -0
- package/dist/core/workspace.js +193 -0
- package/dist/core/workspace.js.map +1 -0
- package/dist/core/zones.d.ts +181 -0
- package/dist/core/zones.js +202 -0
- package/dist/core/zones.js.map +1 -0
- package/dist/env.d.ts +99 -0
- package/dist/env.js +271 -0
- package/dist/env.js.map +1 -0
- package/dist/index.d.ts +265 -0
- package/dist/index.js +197 -0
- package/dist/index.js.map +1 -0
- package/dist/kernel/kernel.d.ts +192 -0
- package/dist/kernel/kernel.js +751 -0
- package/dist/kernel/kernel.js.map +1 -0
- package/dist/lifecycle/hook-shape.d.ts +44 -0
- package/dist/lifecycle/hook-shape.js +66 -0
- package/dist/lifecycle/hook-shape.js.map +1 -0
- package/dist/lifecycle/runner.d.ts +177 -0
- package/dist/lifecycle/runner.js +372 -0
- package/dist/lifecycle/runner.js.map +1 -0
- package/dist/lifecycle/transcript.d.ts +27 -0
- package/dist/lifecycle/transcript.js +43 -0
- package/dist/lifecycle/transcript.js.map +1 -0
- package/dist/machine/allow.d.ts +65 -0
- package/dist/machine/allow.js +107 -0
- package/dist/machine/allow.js.map +1 -0
- package/dist/machine/delegation.d.ts +9 -0
- package/dist/machine/delegation.js +10 -0
- package/dist/machine/delegation.js.map +1 -0
- package/dist/machine/diagnostic.d.ts +14 -0
- package/dist/machine/diagnostic.js +2 -0
- package/dist/machine/diagnostic.js.map +1 -0
- package/dist/machine/lint-spec.d.ts +4 -0
- package/dist/machine/lint-spec.js +266 -0
- package/dist/machine/lint-spec.js.map +1 -0
- package/dist/machine/load-spec.d.ts +90 -0
- package/dist/machine/load-spec.js +120 -0
- package/dist/machine/load-spec.js.map +1 -0
- package/dist/machine/machine.d.ts +273 -0
- package/dist/machine/machine.js +551 -0
- package/dist/machine/machine.js.map +1 -0
- package/dist/machine/mount-grants.d.ts +25 -0
- package/dist/machine/mount-grants.js +24 -0
- package/dist/machine/mount-grants.js.map +1 -0
- package/dist/machine/slug.d.ts +14 -0
- package/dist/machine/slug.js +17 -0
- package/dist/machine/slug.js.map +1 -0
- package/dist/machine/spec-schema.d.ts +662 -0
- package/dist/machine/spec-schema.js +717 -0
- package/dist/machine/spec-schema.js.map +1 -0
- package/dist/machine/tool-names.d.ts +98 -0
- package/dist/machine/tool-names.js +144 -0
- package/dist/machine/tool-names.js.map +1 -0
- package/dist/machine/triggers.d.ts +114 -0
- package/dist/machine/triggers.js +165 -0
- package/dist/machine/triggers.js.map +1 -0
- package/dist/machine/types.d.ts +186 -0
- package/dist/machine/types.js +12 -0
- package/dist/machine/types.js.map +1 -0
- package/dist/machine/validate-spec.d.ts +42 -0
- package/dist/machine/validate-spec.js +29 -0
- package/dist/machine/validate-spec.js.map +1 -0
- package/dist/machine/variables.d.ts +196 -0
- package/dist/machine/variables.js +415 -0
- package/dist/machine/variables.js.map +1 -0
- package/dist/public/cli.d.ts +15 -0
- package/dist/public/cli.js +14 -0
- package/dist/public/cli.js.map +1 -0
- package/dist/public/messages.d.ts +33 -0
- package/dist/public/messages.js +33 -0
- package/dist/public/messages.js.map +1 -0
- package/dist/public/sandbox.d.ts +99 -0
- package/dist/public/sandbox.js +32 -0
- package/dist/public/sandbox.js.map +1 -0
- package/dist/public/spec.d.ts +147 -0
- package/dist/public/spec.js +149 -0
- package/dist/public/spec.js.map +1 -0
- package/dist/public/testing.d.ts +71 -0
- package/dist/public/testing.js +39 -0
- package/dist/public/testing.js.map +1 -0
- package/dist/rubrics/rubrics.d.ts +135 -0
- package/dist/rubrics/rubrics.js +145 -0
- package/dist/rubrics/rubrics.js.map +1 -0
- package/dist/runtime/contract.d.ts +73 -0
- package/dist/runtime/contract.js +96 -0
- package/dist/runtime/contract.js.map +1 -0
- package/dist/sandbox/assets/parts/core.js +22 -0
- package/dist/sandbox/assets/parts/lifecycle-hook.js +47 -0
- package/dist/sandbox/bridge.d.ts +16 -0
- package/dist/sandbox/bridge.js +95 -0
- package/dist/sandbox/bridge.js.map +1 -0
- package/dist/sandbox/executor.d.ts +46 -0
- package/dist/sandbox/executor.js +119 -0
- package/dist/sandbox/executor.js.map +1 -0
- package/dist/sandbox/imports.d.ts +33 -0
- package/dist/sandbox/imports.js +67 -0
- package/dist/sandbox/imports.js.map +1 -0
- package/dist/sandbox/prelude.d.ts +12 -0
- package/dist/sandbox/prelude.js +51 -0
- package/dist/sandbox/prelude.js.map +1 -0
- package/dist/sandbox/ptc-gateway.d.ts +104 -0
- package/dist/sandbox/ptc-gateway.js +167 -0
- package/dist/sandbox/ptc-gateway.js.map +1 -0
- package/dist/sandbox/runtime.d.ts +59 -0
- package/dist/sandbox/runtime.js +51 -0
- package/dist/sandbox/runtime.js.map +1 -0
- package/dist/sandbox/tools.d.ts +34 -0
- package/dist/sandbox/tools.js +147 -0
- package/dist/sandbox/tools.js.map +1 -0
- package/dist/sessions/operations.d.ts +79 -0
- package/dist/sessions/operations.js +121 -0
- package/dist/sessions/operations.js.map +1 -0
- package/dist/sessions/resolve.d.ts +97 -0
- package/dist/sessions/resolve.js +145 -0
- package/dist/sessions/resolve.js.map +1 -0
- package/dist/sessions/resume.d.ts +242 -0
- package/dist/sessions/resume.js +288 -0
- package/dist/sessions/resume.js.map +1 -0
- package/dist/sessions/scope.d.ts +99 -0
- package/dist/sessions/scope.js +145 -0
- package/dist/sessions/scope.js.map +1 -0
- package/dist/sessions/summary.d.ts +65 -0
- package/dist/sessions/summary.js +56 -0
- package/dist/sessions/summary.js.map +1 -0
- package/dist/testing/assertions.d.ts +30 -0
- package/dist/testing/assertions.js +231 -0
- package/dist/testing/assertions.js.map +1 -0
- package/dist/testing/case-document.d.ts +141 -0
- package/dist/testing/case-document.js +51 -0
- package/dist/testing/case-document.js.map +1 -0
- package/dist/testing/case-schema.d.ts +29 -0
- package/dist/testing/case-schema.js +519 -0
- package/dist/testing/case-schema.js.map +1 -0
- package/dist/testing/discovery.d.ts +10 -0
- package/dist/testing/discovery.js +24 -0
- package/dist/testing/discovery.js.map +1 -0
- package/dist/testing/driver.d.ts +78 -0
- package/dist/testing/driver.js +117 -0
- package/dist/testing/driver.js.map +1 -0
- package/dist/testing/grade.d.ts +116 -0
- package/dist/testing/grade.js +261 -0
- package/dist/testing/grade.js.map +1 -0
- package/dist/testing/interpreter.d.ts +55 -0
- package/dist/testing/interpreter.js +103 -0
- package/dist/testing/interpreter.js.map +1 -0
- package/dist/testing/mock-middleware.d.ts +5 -0
- package/dist/testing/mock-middleware.js +33 -0
- package/dist/testing/mock-middleware.js.map +1 -0
- package/dist/testing/runner.d.ts +205 -0
- package/dist/testing/runner.js +266 -0
- package/dist/testing/runner.js.map +1 -0
- package/dist/testing/target.d.ts +27 -0
- package/dist/testing/target.js +21 -0
- package/dist/testing/target.js.map +1 -0
- package/dist/validate/validate.d.ts +41 -0
- package/dist/validate/validate.js +669 -0
- package/dist/validate/validate.js.map +1 -0
- package/dist/workflow/agent-tools.d.ts +10 -0
- package/dist/workflow/agent-tools.js +10 -0
- package/dist/workflow/agent-tools.js.map +1 -0
- package/dist/workflow/checkpointer.d.ts +52 -0
- package/dist/workflow/checkpointer.js +200 -0
- package/dist/workflow/checkpointer.js.map +1 -0
- package/dist/workflow/control-tools.d.ts +174 -0
- package/dist/workflow/control-tools.js +468 -0
- package/dist/workflow/control-tools.js.map +1 -0
- package/dist/workflow/governance.d.ts +104 -0
- package/dist/workflow/governance.js +546 -0
- package/dist/workflow/governance.js.map +1 -0
- package/dist/workflow/middleware.d.ts +85 -0
- package/dist/workflow/middleware.js +283 -0
- package/dist/workflow/middleware.js.map +1 -0
- package/dist/workflow/on-error.d.ts +25 -0
- package/dist/workflow/on-error.js +58 -0
- package/dist/workflow/on-error.js.map +1 -0
- package/dist/workflow/parks.d.ts +46 -0
- package/dist/workflow/parks.js +513 -0
- package/dist/workflow/parks.js.map +1 -0
- package/dist/workflow/paths.d.ts +67 -0
- package/dist/workflow/paths.js +108 -0
- package/dist/workflow/paths.js.map +1 -0
- package/dist/workflow/prompt-cache.d.ts +70 -0
- package/dist/workflow/prompt-cache.js +103 -0
- package/dist/workflow/prompt-cache.js.map +1 -0
- package/dist/workflow/prompt-pruning.d.ts +20 -0
- package/dist/workflow/prompt-pruning.js +83 -0
- package/dist/workflow/prompt-pruning.js.map +1 -0
- package/dist/workflow/render-prompt.d.ts +45 -0
- package/dist/workflow/render-prompt.js +140 -0
- package/dist/workflow/render-prompt.js.map +1 -0
- package/dist/workflow/runtime-config.d.ts +7 -0
- package/dist/workflow/runtime-config.js +9 -0
- package/dist/workflow/runtime-config.js.map +1 -0
- package/dist/workflow/session-artifacts.d.ts +90 -0
- package/dist/workflow/session-artifacts.js +134 -0
- package/dist/workflow/session-artifacts.js.map +1 -0
- package/dist/workflow/session-view.d.ts +31 -0
- package/dist/workflow/session-view.js +94 -0
- package/dist/workflow/session-view.js.map +1 -0
- package/dist/workflow/snapshot.d.ts +14 -0
- package/dist/workflow/snapshot.js +97 -0
- package/dist/workflow/snapshot.js.map +1 -0
- package/dist/workflow/state.d.ts +347 -0
- package/dist/workflow/state.js +322 -0
- package/dist/workflow/state.js.map +1 -0
- package/dist/workflow/sub-workflow.d.ts +174 -0
- package/dist/workflow/sub-workflow.js +392 -0
- package/dist/workflow/sub-workflow.js.map +1 -0
- package/dist/workflow/tool-service.d.ts +48 -0
- package/dist/workflow/tool-service.js +291 -0
- package/dist/workflow/tool-service.js.map +1 -0
- package/dist/workflow/turn-boundary.d.ts +39 -0
- package/dist/workflow/turn-boundary.js +128 -0
- package/dist/workflow/turn-boundary.js.map +1 -0
- package/dist/workflow/turn-runner.d.ts +40 -0
- package/dist/workflow/turn-runner.js +122 -0
- package/dist/workflow/turn-runner.js.map +1 -0
- package/dist/workflow/workflow-tools.d.ts +46 -0
- package/dist/workflow/workflow-tools.js +90 -0
- package/dist/workflow/workflow-tools.js.map +1 -0
- package/package.json +119 -0
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import type { StructuredTool } from "@langchain/core/tools";
|
|
2
|
+
import type { AgentMiddleware } from "langchain";
|
|
3
|
+
import type { ScriptExecutor } from "../sandbox/executor.js";
|
|
4
|
+
import type { PtcToolGateway } from "../sandbox/ptc-gateway.js";
|
|
5
|
+
import { LifecycleRunner, type HookExecutor, type HookScriptResolver } from "../lifecycle/runner.js";
|
|
6
|
+
import type { WorkflowMachine } from "../machine/machine.js";
|
|
7
|
+
import type { Rubric } from "../rubrics/rubrics.js";
|
|
8
|
+
import type { Workspace } from "../core/workspace.js";
|
|
9
|
+
import { type WorkflowEventHandler } from "../core/events.js";
|
|
10
|
+
import type { VariableStore } from "../machine/variables.js";
|
|
11
|
+
import type { SubWorkflowDispatcher } from "./sub-workflow.js";
|
|
12
|
+
import type { GovernanceRule } from "../kernel/kernel.js";
|
|
13
|
+
import { type MountPrefixes } from "../core/mounts.js";
|
|
14
|
+
import type { SkillRegistry } from "../core/skills.js";
|
|
15
|
+
import { type PricingTable } from "../core/usage.js";
|
|
16
|
+
import { type PromptShaping, type StateModels } from "./governance.js";
|
|
17
|
+
export type { PromptShaping, StateModels } from "./governance.js";
|
|
18
|
+
export { resolveToolName } from "./governance.js";
|
|
19
|
+
export { pruneUndisclosedToolSections, upstreamSectionsFor, type PruneResult } from "./prompt-pruning.js";
|
|
20
|
+
export interface WorkflowInstrumentation {
|
|
21
|
+
/**
|
|
22
|
+
* The suspension site: the one middleware that calls `interrupt()`. It must be
|
|
23
|
+
* the FIRST middleware in the agent's array that declares an `afterModel` hook:
|
|
24
|
+
* hook nodes run in array order before the model and in reverse after it, so
|
|
25
|
+
* that position puts every hook that emits before the one that suspends, and
|
|
26
|
+
* makes the final router honour this hook's `jumpTo` when a resume continues
|
|
27
|
+
* to the model.
|
|
28
|
+
*/
|
|
29
|
+
parkMiddleware: AgentMiddleware;
|
|
30
|
+
/** The governance middleware proper; assembled after {@link parkMiddleware}. */
|
|
31
|
+
middleware: AgentMiddleware;
|
|
32
|
+
tools: StructuredTool[];
|
|
33
|
+
lifecycle: LifecycleRunner;
|
|
34
|
+
/** Release every per-session resource (idempotent; safe for sessions that never ran). */
|
|
35
|
+
dispose(sessionId: string): void;
|
|
36
|
+
}
|
|
37
|
+
export interface WorkflowMiddlewareOptions {
|
|
38
|
+
machine: WorkflowMachine;
|
|
39
|
+
/** Serves the agent's own `archmax_eval`/`archmax_run` over the agent workspace. */
|
|
40
|
+
executor: ScriptExecutor;
|
|
41
|
+
/** The workflow's grading rubrics, dispatched by a `{ rubric: … }` hook. */
|
|
42
|
+
rubrics?: Map<string, Rubric>;
|
|
43
|
+
ptcNames: string[];
|
|
44
|
+
/** Consumer rules, evaluated after the safety and `policy` rules, before per-state defaults. */
|
|
45
|
+
policyRules?: GovernanceRule[];
|
|
46
|
+
/** The workspace's resolved mount keys, so the kernel's read-only rule can classify authored paths. */
|
|
47
|
+
mountPrefixes?: MountPrefixes;
|
|
48
|
+
/** The workspace's skills: one table for what the kernel refuses, the prompt names, a listing returns. */
|
|
49
|
+
skills?: SkillRegistry;
|
|
50
|
+
/** Custom hook-kind executors registered alongside the built-in `script`/`rubric`. */
|
|
51
|
+
hookExecutors?: Record<string, HookExecutor>;
|
|
52
|
+
/** Script executor for lifecycle hooks, reading from the authoring backend. Defaults to {@link executor}. */
|
|
53
|
+
hookExecutor?: ScriptExecutor;
|
|
54
|
+
/** Resolves a hook's declared `script:` to its authoring-backend path. */
|
|
55
|
+
resolveHookScript?: HookScriptResolver;
|
|
56
|
+
/** Governs the `tools.*` calls hook scripts make and carries the live per-session context. */
|
|
57
|
+
ptcGateway?: PtcToolGateway;
|
|
58
|
+
/** Runs delegated machines. Omitted, a delegation call falls through to the tool's own body. */
|
|
59
|
+
subWorkflows?: SubWorkflowDispatcher;
|
|
60
|
+
/** Lifecycle event subscriber (default: console rendering). */
|
|
61
|
+
onEvent?: WorkflowEventHandler;
|
|
62
|
+
/** How the model-facing payload is shaped for this assembly. */
|
|
63
|
+
promptShaping?: PromptShaping;
|
|
64
|
+
/** Which model each state's calls run on; omitted, every call uses the graph's own. */
|
|
65
|
+
stateModels?: StateModels;
|
|
66
|
+
/** Workspace backend for writing the spec snapshot into the session zone. */
|
|
67
|
+
workspace?: Workspace;
|
|
68
|
+
/** The `workflows/<slug>/` name, used only to name the machine in a refusal. */
|
|
69
|
+
workflowName?: string;
|
|
70
|
+
/** The assembly-time default trigger, used when an invocation supplies none. */
|
|
71
|
+
trigger?: {
|
|
72
|
+
id: string;
|
|
73
|
+
};
|
|
74
|
+
/** Host-seeded run variables, applied at each turn boundary (already locked). */
|
|
75
|
+
seededVariables?: VariableStore;
|
|
76
|
+
/** Token prices used to attach `costUsd` to usage events. */
|
|
77
|
+
pricing?: PricingTable;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* In-graph governance for the Deep Agent: the turn boundary, per-state tool
|
|
81
|
+
* disclosure and the kernel's verdict on every call, lifecycle hooks, the
|
|
82
|
+
* control tools, budgets, `on_error` routing, and every park's commit, closing
|
|
83
|
+
* turn and suspension.
|
|
84
|
+
*/
|
|
85
|
+
export declare function createWorkflowInstrumentation(opts: WorkflowMiddlewareOptions): WorkflowInstrumentation;
|
|
@@ -0,0 +1,283 @@
|
|
|
1
|
+
import { RemoveMessage } from "@langchain/core/messages";
|
|
2
|
+
import { v4 as uuidv4 } from "@langchain/core/utils/uuid";
|
|
3
|
+
import { createMiddleware } from "langchain";
|
|
4
|
+
import { LifecycleRunner } from "../lifecycle/runner.js";
|
|
5
|
+
import { createWorkflowEventEmitter } from "../core/events.js";
|
|
6
|
+
import { createControlTools, SET_VARIABLES_TOOL } from "./control-tools.js";
|
|
7
|
+
import { currentWorkflowState, isReplyOnly, pendingParkOf, readRunUsage, readVariables, readWorkflowState, WORKFLOW_STATUSES, workflowStateSchema, } from "./state.js";
|
|
8
|
+
import { sessionScopeFrom } from "../sessions/scope.js";
|
|
9
|
+
import { contentToString, isAiMessage, isRuntimeNote, lastMessageIsHuman, runtimeNote } from "../core/messages.js";
|
|
10
|
+
import { NO_MOUNTS } from "../core/mounts.js";
|
|
11
|
+
import { addSummaries, extractUsage, summarizeUsage } from "../core/usage.js";
|
|
12
|
+
import { routeFailure } from "./on-error.js";
|
|
13
|
+
import { servePark, suspendIfParked } from "./parks.js";
|
|
14
|
+
import { openTurn } from "./turn-boundary.js";
|
|
15
|
+
import { beforeVetoReason, budgetExhaustedReason, buildRunnableConfig, createGovernance, } from "./governance.js";
|
|
16
|
+
export { resolveToolName } from "./governance.js";
|
|
17
|
+
export { pruneUndisclosedToolSections, upstreamSectionsFor } from "./prompt-pruning.js";
|
|
18
|
+
/**
|
|
19
|
+
* The id a message will be committed under, assigning one when it arrived
|
|
20
|
+
* without: LangGraph's reducer does the same at commit, so the id on the event
|
|
21
|
+
* and in the transcript are one value.
|
|
22
|
+
*/
|
|
23
|
+
function committedMessageId(msg) {
|
|
24
|
+
const id = msg.id;
|
|
25
|
+
if (typeof id === "string" && id)
|
|
26
|
+
return id;
|
|
27
|
+
const assigned = uuidv4();
|
|
28
|
+
msg.id = assigned;
|
|
29
|
+
// The reducer keeps `lc_kwargs.id` in step with `id`.
|
|
30
|
+
const kwargs = msg.lc_kwargs;
|
|
31
|
+
if (kwargs && typeof kwargs === "object")
|
|
32
|
+
kwargs.id = assigned;
|
|
33
|
+
return assigned;
|
|
34
|
+
}
|
|
35
|
+
/** Whether an AI message still carries tool calls the tools node has to answer. */
|
|
36
|
+
function callsTools(message) {
|
|
37
|
+
const calls = message?.tool_calls;
|
|
38
|
+
return Array.isArray(calls) && calls.length > 0;
|
|
39
|
+
}
|
|
40
|
+
/** The middleware's declared hook result type — the update, however typed. */
|
|
41
|
+
const asHookResult = (update) => update;
|
|
42
|
+
/**
|
|
43
|
+
* In-graph governance for the Deep Agent: the turn boundary, per-state tool
|
|
44
|
+
* disclosure and the kernel's verdict on every call, lifecycle hooks, the
|
|
45
|
+
* control tools, budgets, `on_error` routing, and every park's commit, closing
|
|
46
|
+
* turn and suspension.
|
|
47
|
+
*/
|
|
48
|
+
export function createWorkflowInstrumentation(opts) {
|
|
49
|
+
const { machine, executor, rubrics = new Map(), ptcNames, ptcGateway, subWorkflows, onEvent, pricing, stateModels } = opts;
|
|
50
|
+
const emit = createWorkflowEventEmitter(onEvent);
|
|
51
|
+
const lifecycleHooks = machine.lifecycleHooks();
|
|
52
|
+
const lifecycle = new LifecycleRunner(machine, opts.hookExecutor ?? executor, rubrics, ptcNames, opts.hookExecutors, onEvent, ...(opts.resolveHookScript ? [{ resolveScript: opts.resolveHookScript }] : []));
|
|
53
|
+
if (Object.keys(lifecycleHooks).length > 0) {
|
|
54
|
+
emit({
|
|
55
|
+
type: "hooks-summary",
|
|
56
|
+
summary: Object.entries(lifecycleHooks)
|
|
57
|
+
.map(([s, l]) => `${s}(${[l.before && "before", l.after && "after"].filter(Boolean).join("+")})`)
|
|
58
|
+
.join(", "),
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
const sessionIdOf = (runtime) => sessionScopeFrom(runtime).sessionId;
|
|
62
|
+
const configOf = (runtime) => buildRunnableConfig((runtime ?? {}));
|
|
63
|
+
const governance = createGovernance({
|
|
64
|
+
machine,
|
|
65
|
+
emit,
|
|
66
|
+
lifecycle,
|
|
67
|
+
policyRules: opts.policyRules ?? [],
|
|
68
|
+
mountPrefixes: opts.mountPrefixes ?? NO_MOUNTS,
|
|
69
|
+
skills: opts.skills ?? new Map(),
|
|
70
|
+
shaping: opts.promptShaping ?? {},
|
|
71
|
+
...(opts.stateModels ? { stateModels: opts.stateModels } : {}),
|
|
72
|
+
...(ptcGateway ? { ptcGateway } : {}),
|
|
73
|
+
...(subWorkflows ? { subWorkflows } : {}),
|
|
74
|
+
sessionIdOf,
|
|
75
|
+
});
|
|
76
|
+
const parkCtx = {
|
|
77
|
+
machine,
|
|
78
|
+
emit,
|
|
79
|
+
...(subWorkflows ? { dispatcher: subWorkflows } : {}),
|
|
80
|
+
sessionIdOf,
|
|
81
|
+
configOf,
|
|
82
|
+
};
|
|
83
|
+
const failureCtx = { machine, emit, sessionIdOf };
|
|
84
|
+
const turnCtx = {
|
|
85
|
+
machine,
|
|
86
|
+
emit,
|
|
87
|
+
onEvent,
|
|
88
|
+
...(opts.workspace ? { workspace: opts.workspace } : {}),
|
|
89
|
+
...(opts.workflowName ? { workflowName: opts.workflowName } : {}),
|
|
90
|
+
...(opts.trigger ? { defaultTrigger: opts.trigger } : {}),
|
|
91
|
+
...(opts.seededVariables ? { seededVariables: opts.seededVariables } : {}),
|
|
92
|
+
};
|
|
93
|
+
/**
|
|
94
|
+
* The suspension site. Its `beforeModel` runs first of all before-model hooks
|
|
95
|
+
* and its `afterModel` last of all after-model hooks, so by the time it looks
|
|
96
|
+
* at a park every record is committed and every event emitted, and the only
|
|
97
|
+
* thing it does before `interrupt()` is read state — which is what makes its
|
|
98
|
+
* re-execution on resume repeat nothing.
|
|
99
|
+
*/
|
|
100
|
+
const parkMiddleware = createMiddleware({
|
|
101
|
+
name: "WorkflowParkMiddleware",
|
|
102
|
+
stateSchema: workflowStateSchema,
|
|
103
|
+
beforeModel: {
|
|
104
|
+
canJumpTo: ["end"],
|
|
105
|
+
hook: async (state, runtime) => asHookResult(await suspendIfParked(parkCtx, state, runtime, "before-model")),
|
|
106
|
+
},
|
|
107
|
+
afterModel: {
|
|
108
|
+
canJumpTo: ["model"],
|
|
109
|
+
hook: async (state, runtime) => asHookResult(await suspendIfParked(parkCtx, state, runtime, "after-model")),
|
|
110
|
+
},
|
|
111
|
+
});
|
|
112
|
+
const middleware = createMiddleware({
|
|
113
|
+
name: "WorkflowMiddleware",
|
|
114
|
+
stateSchema: workflowStateSchema,
|
|
115
|
+
// The turn boundary: once per invoke, never on a resume.
|
|
116
|
+
beforeAgent: {
|
|
117
|
+
canJumpTo: ["end"],
|
|
118
|
+
hook: async (state, runtime) => asHookResult(await openTurn(turnCtx, state, runtime)),
|
|
119
|
+
},
|
|
120
|
+
beforeModel: {
|
|
121
|
+
canJumpTo: ["end"],
|
|
122
|
+
hook: (state, runtime) => {
|
|
123
|
+
const fields = readWorkflowState(state);
|
|
124
|
+
const workflowState = currentWorkflowState(state, machine.entry);
|
|
125
|
+
// A park in progress: the closing turn it owes, or a delegated child's decision to present.
|
|
126
|
+
const served = servePark(parkCtx, state, runtime, "before-model");
|
|
127
|
+
if (served)
|
|
128
|
+
return asHookResult(served);
|
|
129
|
+
// A reply-only turn is owed exactly one model call; anything after the
|
|
130
|
+
// person's message means it has been spent.
|
|
131
|
+
if (isReplyOnly(state)) {
|
|
132
|
+
return asHookResult(lastMessageIsHuman(state.messages ?? []) ? undefined : { jumpTo: "end" });
|
|
133
|
+
}
|
|
134
|
+
// The exact per-state turn budget: this call would be one too many.
|
|
135
|
+
const maxTurns = machine.spec.states[workflowState]?.budget?.maxTurns;
|
|
136
|
+
const spent = fields.stateTurns?.state === workflowState ? fields.stateTurns.count : 0;
|
|
137
|
+
if (maxTurns != null && spent + 1 > maxTurns) {
|
|
138
|
+
const routed = routeFailure(failureCtx, state, runtime, workflowState, `state '${workflowState}' exhausted its turn budget (maxTurns: ${maxTurns})`, "before-model");
|
|
139
|
+
// The error handler's first call is the one about to be made.
|
|
140
|
+
if (routed.workflowState)
|
|
141
|
+
routed.stateTurns = { state: routed.workflowState, count: 1 };
|
|
142
|
+
return asHookResult(routed);
|
|
143
|
+
}
|
|
144
|
+
return asHookResult({ stateTurns: { state: workflowState, count: spent + 1 } });
|
|
145
|
+
},
|
|
146
|
+
},
|
|
147
|
+
wrapModelCall: governance.wrapModelCall,
|
|
148
|
+
wrapToolCall: governance.wrapToolCall,
|
|
149
|
+
afterModel: {
|
|
150
|
+
canJumpTo: ["model"],
|
|
151
|
+
hook: async (state, runtime) => {
|
|
152
|
+
const fields = readWorkflowState(state);
|
|
153
|
+
const workflowState = currentWorkflowState(state, machine.entry);
|
|
154
|
+
const messages = state.messages ?? [];
|
|
155
|
+
const last = messages[messages.length - 1];
|
|
156
|
+
const update = {};
|
|
157
|
+
// 1. Report the message the model just produced and what it cost. Usage is
|
|
158
|
+
// committed as the new total: the channel is last-value and this hook is its one writer.
|
|
159
|
+
if (last && isAiMessage(last) && !isRuntimeNote(last)) {
|
|
160
|
+
const text = contentToString(last.content).trim();
|
|
161
|
+
if (text)
|
|
162
|
+
emit({ type: "agent-text", state: workflowState, text, messageId: committedMessageId(last) });
|
|
163
|
+
const extracted = extractUsage(last);
|
|
164
|
+
if (extracted) {
|
|
165
|
+
// What the response said, else what we asked the endpoint to run,
|
|
166
|
+
// else nothing. The reported id leads deliberately — a proxy may
|
|
167
|
+
// serve an alias, a fallback or a load-balanced deployment, and what
|
|
168
|
+
// it served is the honest thing to price — but a response naming no
|
|
169
|
+
// model must not cost the call its price when assembly knows which
|
|
170
|
+
// model it built. The id used is reported, so a host can attribute
|
|
171
|
+
// the call to a model rather than to nothing.
|
|
172
|
+
const modelId = extracted.model ?? stateModels?.idFor(workflowState);
|
|
173
|
+
const summary = summarizeUsage(extracted.usage, pricing, modelId);
|
|
174
|
+
emit({
|
|
175
|
+
type: "model-usage",
|
|
176
|
+
state: workflowState,
|
|
177
|
+
...summary,
|
|
178
|
+
...(modelId ? { model: modelId } : {}),
|
|
179
|
+
});
|
|
180
|
+
update.usage = addSummaries(readRunUsage(state), summary);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
// 2. A model call that ran out of its time budget: the marker leaves the transcript, the failure routes.
|
|
184
|
+
const exhausted = budgetExhaustedReason(last);
|
|
185
|
+
if (exhausted !== undefined && typeof last?.id === "string") {
|
|
186
|
+
const routed = routeFailure(failureCtx, state, runtime, workflowState, exhausted, "after-model");
|
|
187
|
+
return asHookResult({
|
|
188
|
+
...update,
|
|
189
|
+
...routed,
|
|
190
|
+
messages: [new RemoveMessage({ id: last.id }), ...(routed.messages ?? [])],
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
// 3. A `before` hook refused this state: the model never ran, so nothing
|
|
194
|
+
// below applies. Routed like any terminal rejection — the refusal text
|
|
195
|
+
// stays in the transcript as the reply the person is owed, unlike the
|
|
196
|
+
// budget marker above, which stood in for an answer that never came.
|
|
197
|
+
const refusedEntry = beforeVetoReason(last);
|
|
198
|
+
if (refusedEntry !== undefined) {
|
|
199
|
+
return asHookResult({
|
|
200
|
+
...update,
|
|
201
|
+
...routeFailure(failureCtx, state, runtime, workflowState, refusedEntry, "after-model"),
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
// 4. A park's closing or answering turn was just spent.
|
|
205
|
+
const served = servePark(parkCtx, state, runtime, "after-model");
|
|
206
|
+
if (served)
|
|
207
|
+
return asHookResult({ ...update, ...served });
|
|
208
|
+
if (pendingParkOf(state) || (fields.pendingDelegations ?? []).length > 0) {
|
|
209
|
+
return asHookResult(update);
|
|
210
|
+
}
|
|
211
|
+
// 5. The run ends here only when the model finished — no tool calls pending — in a state that is not parked.
|
|
212
|
+
if (!last || !isAiMessage(last) || callsTools(last) || isReplyOnly(state)) {
|
|
213
|
+
return asHookResult(update);
|
|
214
|
+
}
|
|
215
|
+
// A rejection a tool committed (a terminal kernel block, an exhausted park
|
|
216
|
+
// budget, a failed sub-run) routes once the model has finished in the failing state.
|
|
217
|
+
if (fields.rejected) {
|
|
218
|
+
return asHookResult({
|
|
219
|
+
...update,
|
|
220
|
+
...routeFailure(failureCtx, state, runtime, workflowState, fields.rejected, "after-model"),
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
// A terminal state has no `archmax_advance` out of it, so its `after` hook
|
|
224
|
+
// runs at completion: `correct` hands the state back with a note, a
|
|
225
|
+
// terminal failure routes through `on_error`.
|
|
226
|
+
if (machine.isTerminal(workflowState) && lifecycleHooks[workflowState]?.after?.length) {
|
|
227
|
+
const ctx = governance.lifecycleCtx(sessionIdOf(runtime), state, messages);
|
|
228
|
+
const reject = await lifecycle.runPhase(workflowState, "after", ctx, undefined, true);
|
|
229
|
+
if (reject) {
|
|
230
|
+
if (reject.terminal) {
|
|
231
|
+
return asHookResult({
|
|
232
|
+
...update,
|
|
233
|
+
iterations: ctx.iterations,
|
|
234
|
+
...routeFailure(failureCtx, state, runtime, workflowState, reject.reason, "after-model"),
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
return asHookResult({
|
|
238
|
+
...update,
|
|
239
|
+
messages: runtimeNote("after", `[after] The '${workflowState}' completion check did not pass: ${reject.reason}. ` +
|
|
240
|
+
`Revise your work and produce a corrected final response.`),
|
|
241
|
+
iterations: ctx.iterations,
|
|
242
|
+
jumpTo: "model",
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
update.iterations = ctx.iterations;
|
|
246
|
+
}
|
|
247
|
+
// The exit half of the trigger's signature, checked where a run completes — never at a park.
|
|
248
|
+
const unsetReturns = (machine.returnsForTrigger(fields.trigger?.id ?? "") ?? []).filter((name) => readVariables(state)[name] === undefined);
|
|
249
|
+
if (unsetReturns.length > 0) {
|
|
250
|
+
const reason = `Completed in state '${workflowState}' without setting ` +
|
|
251
|
+
`${unsetReturns.map((n) => `'${n}'`).join(", ")}, which trigger ` +
|
|
252
|
+
`'${fields.trigger?.id}' declares in its 'returns'. Set ` +
|
|
253
|
+
`${unsetReturns.length === 1 ? "it" : "them"} with '${SET_VARIABLES_TOOL}' before ` +
|
|
254
|
+
`finishing.`;
|
|
255
|
+
return asHookResult({ ...update, rejected: reason, status: WORKFLOW_STATUSES.rejected });
|
|
256
|
+
}
|
|
257
|
+
emit({ type: "state-leave", state: workflowState, next: workflowState });
|
|
258
|
+
return asHookResult({ ...update, status: WORKFLOW_STATUSES.completed });
|
|
259
|
+
},
|
|
260
|
+
},
|
|
261
|
+
// Flush this turn's staged `beforeDone` entries as one state update.
|
|
262
|
+
afterAgent: (state, runtime) => {
|
|
263
|
+
const staged = governance.endTurn(sessionIdOf(runtime));
|
|
264
|
+
if (!staged)
|
|
265
|
+
return undefined;
|
|
266
|
+
return { beforeDone: { ...(readWorkflowState(state).beforeDone ?? {}), ...staged } };
|
|
267
|
+
},
|
|
268
|
+
});
|
|
269
|
+
return {
|
|
270
|
+
parkMiddleware,
|
|
271
|
+
middleware,
|
|
272
|
+
tools: createControlTools(),
|
|
273
|
+
lifecycle,
|
|
274
|
+
dispose: (sessionId) => {
|
|
275
|
+
// Requested per session, so it sweeps the session and every sub-run session nested beneath it.
|
|
276
|
+
for (const scope of new Set([...governance.release(sessionId), sessionId])) {
|
|
277
|
+
ptcGateway?.release(scope);
|
|
278
|
+
lifecycle.dispose(scope);
|
|
279
|
+
}
|
|
280
|
+
},
|
|
281
|
+
};
|
|
282
|
+
}
|
|
283
|
+
//# sourceMappingURL=middleware.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"middleware.js","sourceRoot":"","sources":["../../src/workflow/middleware.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AACzD,OAAO,EAAE,EAAE,IAAI,MAAM,EAAE,MAAM,4BAA4B,CAAC;AAC1D,OAAO,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAI7C,OAAO,EAAE,eAAe,EAA8C,MAAM,wBAAwB,CAAC;AAIrG,OAAO,EAAE,0BAA0B,EAA6B,MAAM,mBAAmB,CAAC;AAC1F,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAE5E,OAAO,EACL,oBAAoB,EACpB,WAAW,EACX,aAAa,EACb,YAAY,EACZ,aAAa,EACb,iBAAiB,EACjB,iBAAiB,EACjB,mBAAmB,GAEpB,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACxD,OAAO,EAAE,eAAe,EAAE,WAAW,EAAE,aAAa,EAAE,kBAAkB,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAEnH,OAAO,EAAE,SAAS,EAAsB,MAAM,mBAAmB,CAAC;AAGlE,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,cAAc,EAAqB,MAAM,kBAAkB,CAAC;AACjG,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,EAAE,SAAS,EAAE,eAAe,EAAoB,MAAM,YAAY,CAAC;AAC1E,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OAAO,EACL,gBAAgB,EAChB,qBAAqB,EACrB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+
* recover from in place arrives here as a `reason`; the run routes to the
|
|
4
|
+
* declared `on_error` target with an `[error]` runtime note, or ends rejected.
|
|
5
|
+
* Fail-closed either way: nothing continues in the state that failed.
|
|
6
|
+
*/
|
|
7
|
+
import type { WorkflowEventEmitter } from "../core/events.js";
|
|
8
|
+
import type { WorkflowMachine } from "../machine/machine.js";
|
|
9
|
+
import { type WorkflowUpdate } from "./state.js";
|
|
10
|
+
/** Which hook is routing: decides how the loop continues after the update. */
|
|
11
|
+
export type HookSite = "before-model" | "after-model";
|
|
12
|
+
export interface FailureRoutingContext {
|
|
13
|
+
machine: WorkflowMachine;
|
|
14
|
+
emit: WorkflowEventEmitter;
|
|
15
|
+
/** The session the failing hook is executing for, for the park it may open. */
|
|
16
|
+
sessionIdOf(runtime: unknown): string;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* The update that settles a failed state. With an `on_error` target: the note,
|
|
20
|
+
* the new position, an `on_error` trail step, every park record cleared, and —
|
|
21
|
+
* from `afterModel`, where the loop would otherwise exit — a jump back to the
|
|
22
|
+
* model. Without one: `rejected`; `beforeModel` ends the turn outright. A human
|
|
23
|
+
* `on_error` target is presented at once, with the closing message owed.
|
|
24
|
+
*/
|
|
25
|
+
export declare function routeFailure(ctx: FailureRoutingContext, state: unknown, runtime: unknown, from: string, reason: string, site: HookSite): WorkflowUpdate;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { runtimeNote } from "../core/messages.js";
|
|
2
|
+
import { decisionRecordFor } from "./parks.js";
|
|
3
|
+
import { readWorkflowState, WORKFLOW_STATUSES, } from "./state.js";
|
|
4
|
+
/**
|
|
5
|
+
* The update that settles a failed state. With an `on_error` target: the note,
|
|
6
|
+
* the new position, an `on_error` trail step, every park record cleared, and —
|
|
7
|
+
* from `afterModel`, where the loop would otherwise exit — a jump back to the
|
|
8
|
+
* model. Without one: `rejected`; `beforeModel` ends the turn outright. A human
|
|
9
|
+
* `on_error` target is presented at once, with the closing message owed.
|
|
10
|
+
*/
|
|
11
|
+
export function routeFailure(ctx, state, runtime, from, reason, site) {
|
|
12
|
+
const errorTarget = ctx.machine.onError(from);
|
|
13
|
+
if (!errorTarget) {
|
|
14
|
+
return {
|
|
15
|
+
rejected: reason,
|
|
16
|
+
status: WORKFLOW_STATUSES.rejected,
|
|
17
|
+
...(site === "before-model" ? { jumpTo: "end" } : {}),
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
ctx.emit({ type: "state-error-routed", state: from, to: errorTarget, reason });
|
|
21
|
+
ctx.emit({ type: "state-leave", state: from, next: errorTarget });
|
|
22
|
+
ctx.emit({ type: "state-enter", state: errorTarget });
|
|
23
|
+
const routed = {
|
|
24
|
+
messages: runtimeNote("error", `[error] The '${from}' state failed: ${reason}. Routing to the '${errorTarget}' error handler.`),
|
|
25
|
+
workflowState: errorTarget,
|
|
26
|
+
rejected: null,
|
|
27
|
+
status: WORKFLOW_STATUSES.running,
|
|
28
|
+
pendingInput: null,
|
|
29
|
+
pendingDecision: null,
|
|
30
|
+
pendingDelegations: null,
|
|
31
|
+
parkPhase: null,
|
|
32
|
+
replyOnly: null,
|
|
33
|
+
stateTurns: null,
|
|
34
|
+
auditTrail: [
|
|
35
|
+
{ to: errorTarget, kind: "on_error", reason, ts: Date.now() },
|
|
36
|
+
],
|
|
37
|
+
...(site === "after-model" ? { jumpTo: "model" } : {}),
|
|
38
|
+
};
|
|
39
|
+
if (!ctx.machine.isHumanState(errorTarget))
|
|
40
|
+
return routed;
|
|
41
|
+
const seq = (readWorkflowState(state).decisionCount ?? 0) + 1;
|
|
42
|
+
ctx.emit({
|
|
43
|
+
type: "parked",
|
|
44
|
+
node: errorTarget,
|
|
45
|
+
state: errorTarget,
|
|
46
|
+
sessionId: ctx.sessionIdOf(runtime),
|
|
47
|
+
awaiting: "decision",
|
|
48
|
+
});
|
|
49
|
+
return {
|
|
50
|
+
...routed,
|
|
51
|
+
pendingDecision: decisionRecordFor(ctx.machine, errorTarget, seq),
|
|
52
|
+
decisionCount: seq,
|
|
53
|
+
status: WORKFLOW_STATUSES.awaitingDecision,
|
|
54
|
+
parkPhase: "suspend",
|
|
55
|
+
replyOnly: true,
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=on-error.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"on-error.js","sourceRoot":"","sources":["../../src/workflow/on-error.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAElD,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAC/C,OAAO,EACL,iBAAiB,EACjB,iBAAiB,GAGlB,MAAM,YAAY,CAAC;AAYpB;;;;;;GAMG;AACH,MAAM,UAAU,YAAY,CAC1B,GAA0B,EAC1B,KAAc,EACd,OAAgB,EAChB,IAAY,EACZ,MAAc,EACd,IAAc;IAEd,MAAM,WAAW,GAAG,GAAG,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IAC9C,IAAI,CAAC,WAAW,EAAE,CAAC;QACjB,OAAO;YACL,QAAQ,EAAE,MAAM;YAChB,MAAM,EAAE,iBAAiB,CAAC,QAAQ;YAClC,GAAG,CAAC,IAAI,KAAK,cAAc,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;SACtD,CAAC;IACJ,CAAC;IACD,GAAG,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,oBAAoB,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE,EAAE,WAAW,EAAE,MAAM,EAAE,CAAC,CAAC;IAC/E,GAAG,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,aAAa,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,WAAW,EAAE,CAAC,CAAC;IAClE,GAAG,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,aAAa,EAAE,KAAK,EAAE,WAAW,EAAE,CA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S,EAAE,IAAI;KAChB,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { RunnableConfig } from "@langchain/core/runnables";
|
|
2
|
+
import type { WorkflowEventEmitter } from "../core/events.js";
|
|
3
|
+
import type { WorkflowMachine } from "../machine/machine.js";
|
|
4
|
+
import type { HookSite } from "./on-error.js";
|
|
5
|
+
import { type PendingDecision, type PendingInput, type WorkflowUpdate } from "./state.js";
|
|
6
|
+
import { type SubWorkflowDispatcher } from "./sub-workflow.js";
|
|
7
|
+
/**
|
|
8
|
+
* The pending-decision record for a human state: its declared transitions and
|
|
9
|
+
* evidence (the author's list leads and is never displaced), plus whatever the
|
|
10
|
+
* transition attached, duplicates removed keeping first position.
|
|
11
|
+
*/
|
|
12
|
+
export declare function decisionRecordFor(machine: WorkflowMachine, state: string, seq: number, attached?: readonly string[]): PendingDecision;
|
|
13
|
+
/** The pending-input record for a state the agent parked with `archmax_wait`. */
|
|
14
|
+
export declare function inputRecordFor(machine: WorkflowMachine, state: string, reason: string, resumeAt?: string): PendingInput;
|
|
15
|
+
/**
|
|
16
|
+
* What a reply-only turn is told. Four shapes of park reach this — handing the
|
|
17
|
+
* run to a person, being routed to one by a decision, waiting for something
|
|
18
|
+
* from outside, and answering someone while a person decides — each with its
|
|
19
|
+
* own first sentence. The last paragraph is the same in all: it is what stands
|
|
20
|
+
* between a parked run and a model that would rather keep working.
|
|
21
|
+
*/
|
|
22
|
+
export declare function replyOnlyDirective(machine: WorkflowMachine, state: unknown): string;
|
|
23
|
+
export interface ParkContext {
|
|
24
|
+
machine: WorkflowMachine;
|
|
25
|
+
emit: WorkflowEventEmitter;
|
|
26
|
+
/** Resumes a parked child; absent in an assembly that cannot run sub-workflows. */
|
|
27
|
+
dispatcher?: SubWorkflowDispatcher;
|
|
28
|
+
/** The session a hook is executing for, read from its runtime. */
|
|
29
|
+
sessionIdOf(runtime: unknown): string;
|
|
30
|
+
/** The runnable config a hook's runtime stands for, for a child's resume. */
|
|
31
|
+
configOf(runtime: unknown): RunnableConfig;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Move a park along, deterministically on state. Before the model: a record in
|
|
35
|
+
* phase `closing` gets its closing turn; a delegated child that parked becomes
|
|
36
|
+
* the pending decision and gets its closing turn. After the model: a reply-only
|
|
37
|
+
* turn that just spoke is spent, and an answer to a person's message is reported.
|
|
38
|
+
*/
|
|
39
|
+
export declare function servePark(ctx: ParkContext, state: unknown, runtime: unknown, site: HookSite): WorkflowUpdate | undefined;
|
|
40
|
+
/**
|
|
41
|
+
* The suspension site: with a record in phase `suspend` and nothing owed, park
|
|
42
|
+
* the session on it. `interrupt()` throws on first arrival — the session parks
|
|
43
|
+
* durably — and on resume returns what a surface resumed with, which
|
|
44
|
+
* {@link applyResume} turns into the run's continuation.
|
|
45
|
+
*/
|
|
46
|
+
export declare function suspendIfParked(ctx: ParkContext, state: unknown, runtime: unknown, site: HookSite): Promise<WorkflowUpdate | undefined>;
|