@graphorin/agent 0.6.0 → 0.7.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/CHANGELOG.md +96 -0
- package/README.md +31 -11
- package/dist/errors/index.d.ts +17 -4
- package/dist/errors/index.d.ts.map +1 -1
- package/dist/errors/index.js +19 -3
- package/dist/errors/index.js.map +1 -1
- package/dist/factory.d.ts.map +1 -1
- package/dist/factory.js +153 -1930
- package/dist/factory.js.map +1 -1
- package/dist/fanout/index.d.ts +13 -1
- package/dist/fanout/index.d.ts.map +1 -1
- package/dist/fanout/index.js +13 -4
- package/dist/fanout/index.js.map +1 -1
- package/dist/index.d.ts +7 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +11 -9
- package/dist/index.js.map +1 -1
- package/dist/lateral-leak/index.js +1 -1
- package/dist/package.js +6 -0
- package/dist/package.js.map +1 -0
- package/dist/run-state/index.d.ts +32 -6
- package/dist/run-state/index.d.ts.map +1 -1
- package/dist/run-state/index.js +46 -22
- package/dist/run-state/index.js.map +1 -1
- package/dist/runtime/agent-surface.js +122 -0
- package/dist/runtime/agent-surface.js.map +1 -0
- package/dist/runtime/agent-to-tool.d.ts +51 -0
- package/dist/runtime/agent-to-tool.d.ts.map +1 -0
- package/dist/runtime/agent-to-tool.js +145 -0
- package/dist/runtime/agent-to-tool.js.map +1 -0
- package/dist/runtime/approvals.js +0 -0
- package/dist/runtime/approvals.js.map +1 -0
- package/dist/runtime/dispatch.js +108 -0
- package/dist/runtime/dispatch.js.map +1 -0
- package/dist/runtime/executor-wiring.js +128 -0
- package/dist/runtime/executor-wiring.js.map +1 -0
- package/dist/runtime/fallback-chain.js +139 -0
- package/dist/runtime/fallback-chain.js.map +1 -0
- package/dist/runtime/handoff.js +307 -0
- package/dist/runtime/handoff.js.map +1 -0
- package/dist/runtime/messages.d.ts +22 -0
- package/dist/runtime/messages.d.ts.map +1 -0
- package/dist/runtime/messages.js +204 -0
- package/dist/runtime/messages.js.map +1 -0
- package/dist/runtime/provider-events.js +117 -0
- package/dist/runtime/provider-events.js.map +1 -0
- package/dist/runtime/run-compaction.js +210 -0
- package/dist/runtime/run-compaction.js.map +1 -0
- package/dist/runtime/run-finish.js +48 -0
- package/dist/runtime/run-finish.js.map +1 -0
- package/dist/runtime/run-gates.js +336 -0
- package/dist/runtime/run-gates.js.map +1 -0
- package/dist/runtime/run-init.js +81 -0
- package/dist/runtime/run-init.js.map +1 -0
- package/dist/runtime/run-input.js +46 -0
- package/dist/runtime/run-input.js.map +1 -0
- package/dist/runtime/step-catalogue.js +173 -0
- package/dist/runtime/step-catalogue.js.map +1 -0
- package/dist/runtime/tool-call-walk.js +189 -0
- package/dist/runtime/tool-call-walk.js.map +1 -0
- package/dist/runtime/tool-wiring.js +159 -0
- package/dist/runtime/tool-wiring.js.map +1 -0
- package/dist/tooling/adapters.js +1 -1
- package/dist/tooling/dataflow.js +1 -1
- package/dist/tooling/policy.js +2 -0
- package/dist/tooling/policy.js.map +1 -1
- package/dist/types.d.ts +63 -13
- package/dist/types.d.ts.map +1 -1
- package/package.json +20 -20
- package/src/errors/index.ts +320 -0
- package/src/evaluator-optimizer/index.ts +212 -0
- package/src/factory.ts +957 -0
- package/src/fallback/index.ts +108 -0
- package/src/fanout/index.ts +523 -0
- package/src/filters/index.ts +347 -0
- package/src/index.ts +180 -0
- package/src/internal/ids.ts +46 -0
- package/src/internal/usage-accumulator.ts +90 -0
- package/src/lateral-leak/causality-monitor.ts +221 -0
- package/src/lateral-leak/index.ts +35 -0
- package/src/lateral-leak/merge-guard.ts +151 -0
- package/src/lateral-leak/protocol-guard.ts +222 -0
- package/src/preferred-model/index.ts +210 -0
- package/src/progress/index.ts +238 -0
- package/src/run-state/index.ts +607 -0
- package/src/runtime/agent-surface.ts +218 -0
- package/src/runtime/agent-to-tool.ts +323 -0
- package/src/runtime/approvals.ts +0 -0
- package/src/runtime/dispatch.ts +183 -0
- package/src/runtime/executor-wiring.ts +331 -0
- package/src/runtime/fallback-chain.ts +250 -0
- package/src/runtime/handoff.ts +428 -0
- package/src/runtime/messages.ts +309 -0
- package/src/runtime/provider-events.ts +175 -0
- package/src/runtime/run-compaction.ts +288 -0
- package/src/runtime/run-finish.ts +93 -0
- package/src/runtime/run-gates.ts +419 -0
- package/src/runtime/run-init.ts +169 -0
- package/src/runtime/run-input.ts +102 -0
- package/src/runtime/step-catalogue.ts +338 -0
- package/src/runtime/tool-call-walk.ts +301 -0
- package/src/runtime/tool-wiring.ts +218 -0
- package/src/testing/replay-provider.ts +121 -0
- package/src/tooling/adapters.ts +403 -0
- package/src/tooling/catalogue.ts +36 -0
- package/src/tooling/dataflow.ts +171 -0
- package/src/tooling/plan.ts +123 -0
- package/src/tooling/policy.ts +67 -0
- package/src/tooling/registry-build.ts +191 -0
- package/src/types.ts +696 -0
package/dist/tooling/policy.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { isUntrustedTrustClass } from "@graphorin/security/dataflow";
|
|
1
2
|
import { buildRuleOfTwoPolicy, evaluateToolArgumentPolicy } from "@graphorin/security/policy";
|
|
2
3
|
|
|
3
4
|
//#region src/tooling/policy.ts
|
|
@@ -32,6 +33,7 @@ function buildToolArgumentPolicy(toolPolicy, ruleOfTwo) {
|
|
|
32
33
|
toolName: input.toolName,
|
|
33
34
|
sideEffectClass: input.sideEffectClass,
|
|
34
35
|
sensitive: input.sensitive,
|
|
36
|
+
untrustedSource: isUntrustedTrustClass(input.trustClass),
|
|
35
37
|
args: input.args
|
|
36
38
|
}) };
|
|
37
39
|
return compiled?.capability !== void 0 ? {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"policy.js","names":["merged: ToolArgumentPolicy","guard: ToolArgumentPolicyGuard"],"sources":["../../src/tooling/policy.ts"],"sourcesContent":["/**\n * Agent-side adapter for the D4 tool-argument policy (Progent) and the\n * Rule-of-Two capability preset. Compiles `AgentConfig.toolPolicy` /\n * `AgentConfig.ruleOfTwo` into the structural\n * {@link ToolArgumentPolicyGuard} the tool executor consumes plus a\n * capability floor the run loop folds into its single-writer gate.\n *\n * The pure decision engine lives in `@graphorin/security/policy`; this\n * module is the thin binding, mirroring `tooling/dataflow.ts`.\n *\n * @packageDocumentation\n */\n\nimport {\n buildRuleOfTwoPolicy,\n evaluateToolArgumentPolicy,\n type PolicySideEffectClass,\n type RuleOfTwoProfile,\n type ToolArgumentPolicy,\n} from '@graphorin/security/policy';\nimport type { ToolArgumentPolicyGuard } from '@graphorin/tools/executor';\n\nexport type { RuleOfTwoProfile, ToolArgumentPolicy } from '@graphorin/security/policy';\n\n/**\n * Compile the agent's opt-in tool-argument policy + Rule-of-Two profile\n * into a single guard. `ruleOfTwo` is compiled first (yielding a base\n * policy + optional read-only floor); an explicit `toolPolicy` is\n * appended so its rules compose - a forbid in either always wins\n * (forbid-before-allow). Returns `{ guard: undefined }` when neither is\n * configured (zero overhead on the default path).\n */\nexport function buildToolArgumentPolicy(\n toolPolicy: ToolArgumentPolicy | undefined,\n ruleOfTwo: RuleOfTwoProfile | undefined,\n): { readonly guard: ToolArgumentPolicyGuard | undefined; readonly capabilityFloor?: 'read-only' } {\n if (toolPolicy === undefined && ruleOfTwo === undefined) {\n return { guard: undefined };\n }\n\n const compiled = ruleOfTwo !== undefined ? buildRuleOfTwoPolicy(ruleOfTwo) : undefined;\n const merged: ToolArgumentPolicy = {\n rules: [...(compiled?.policy.rules ?? []), ...(toolPolicy?.rules ?? [])],\n defaultDenySensitive:\n (compiled?.policy.defaultDenySensitive ?? false) ||\n (toolPolicy?.defaultDenySensitive ?? false),\n };\n\n const guard: ToolArgumentPolicyGuard = {\n evaluate: (input) =>\n evaluateToolArgumentPolicy(merged, {\n toolName: input.toolName,\n sideEffectClass: input.sideEffectClass as PolicySideEffectClass,\n sensitive: input.sensitive,\n args: input.args,\n }),\n };\n\n return compiled?.capability !== undefined\n ? { guard, capabilityFloor: compiled.capability }\n : { guard };\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"policy.js","names":["merged: ToolArgumentPolicy","guard: ToolArgumentPolicyGuard"],"sources":["../../src/tooling/policy.ts"],"sourcesContent":["/**\n * Agent-side adapter for the D4 tool-argument policy (Progent) and the\n * Rule-of-Two capability preset. Compiles `AgentConfig.toolPolicy` /\n * `AgentConfig.ruleOfTwo` into the structural\n * {@link ToolArgumentPolicyGuard} the tool executor consumes plus a\n * capability floor the run loop folds into its single-writer gate.\n *\n * The pure decision engine lives in `@graphorin/security/policy`; this\n * module is the thin binding, mirroring `tooling/dataflow.ts`.\n *\n * @packageDocumentation\n */\n\nimport { isUntrustedTrustClass } from '@graphorin/security/dataflow';\nimport {\n buildRuleOfTwoPolicy,\n evaluateToolArgumentPolicy,\n type PolicySideEffectClass,\n type RuleOfTwoProfile,\n type ToolArgumentPolicy,\n} from '@graphorin/security/policy';\nimport type { ToolArgumentPolicyGuard } from '@graphorin/tools/executor';\n\nexport type { RuleOfTwoProfile, ToolArgumentPolicy } from '@graphorin/security/policy';\n\n/**\n * Compile the agent's opt-in tool-argument policy + Rule-of-Two profile\n * into a single guard. `ruleOfTwo` is compiled first (yielding a base\n * policy + optional read-only floor); an explicit `toolPolicy` is\n * appended so its rules compose - a forbid in either always wins\n * (forbid-before-allow). Returns `{ guard: undefined }` when neither is\n * configured (zero overhead on the default path).\n */\nexport function buildToolArgumentPolicy(\n toolPolicy: ToolArgumentPolicy | undefined,\n ruleOfTwo: RuleOfTwoProfile | undefined,\n): { readonly guard: ToolArgumentPolicyGuard | undefined; readonly capabilityFloor?: 'read-only' } {\n if (toolPolicy === undefined && ruleOfTwo === undefined) {\n return { guard: undefined };\n }\n\n const compiled = ruleOfTwo !== undefined ? buildRuleOfTwoPolicy(ruleOfTwo) : undefined;\n const merged: ToolArgumentPolicy = {\n rules: [...(compiled?.policy.rules ?? []), ...(toolPolicy?.rules ?? [])],\n defaultDenySensitive:\n (compiled?.policy.defaultDenySensitive ?? false) ||\n (toolPolicy?.defaultDenySensitive ?? false),\n };\n\n const guard: ToolArgumentPolicyGuard = {\n evaluate: (input) =>\n evaluateToolArgumentPolicy(merged, {\n toolName: input.toolName,\n sideEffectClass: input.sideEffectClass as PolicySideEffectClass,\n sensitive: input.sensitive,\n // W-101: derived with the same taxonomy the taint engine uses,\n // so the Rule-of-Two untrustedInput leg and dataflow policy can\n // never disagree about what \"untrusted source\" means.\n untrustedSource: isUntrustedTrustClass(input.trustClass),\n args: input.args,\n }),\n };\n\n return compiled?.capability !== undefined\n ? { guard, capabilityFloor: compiled.capability }\n : { guard };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAiCA,SAAgB,wBACd,YACA,WACiG;AACjG,KAAI,eAAe,UAAa,cAAc,OAC5C,QAAO,EAAE,OAAO,QAAW;CAG7B,MAAM,WAAW,cAAc,SAAY,qBAAqB,UAAU,GAAG;CAC7E,MAAMA,SAA6B;EACjC,OAAO,CAAC,GAAI,UAAU,OAAO,SAAS,EAAE,EAAG,GAAI,YAAY,SAAS,EAAE,CAAE;EACxE,uBACG,UAAU,OAAO,wBAAwB,WACzC,YAAY,wBAAwB;EACxC;CAED,MAAMC,QAAiC,EACrC,WAAW,UACT,2BAA2B,QAAQ;EACjC,UAAU,MAAM;EAChB,iBAAiB,MAAM;EACvB,WAAW,MAAM;EAIjB,iBAAiB,sBAAsB,MAAM,WAAW;EACxD,MAAM,MAAM;EACb,CAAC,EACL;AAED,QAAO,UAAU,eAAe,SAC5B;EAAE;EAAO,iBAAiB,SAAS;EAAY,GAC/C,EAAE,OAAO"}
|
package/dist/types.d.ts
CHANGED
|
@@ -4,13 +4,13 @@ import { ChildResult, FanOutOptions, FanOutResult, MergeStrategy, PerChildBudget
|
|
|
4
4
|
import { CausalityMonitorConfig } from "./lateral-leak/causality-monitor.js";
|
|
5
5
|
import { ProgressIO, ProgressReadOptions, ProgressWriteOptions } from "./progress/index.js";
|
|
6
6
|
import * as _graphorin_core0 from "@graphorin/core";
|
|
7
|
-
import { AgentEvent, AgentResult, CheckpointStore, HandoffFilter, Message, ModelHint, ModelSpec, ProgressArtifactRef, Provider, ProviderCachePolicy, ReasoningRetention, RunContext, RunState, Sensitivity, StopCondition, Tool, ToolChoice, Tracer } from "@graphorin/core";
|
|
8
|
-
import {
|
|
7
|
+
import { AISpan, AgentEvent, AgentResult, AnyTool, CheckpointStore, HandoffFilter, Message, ModelHint, ModelSpec, ProgressArtifactRef, Provider, ProviderCachePolicy, ReasoningRetention, RunContext, RunState, Sensitivity, StopCondition, Tool, ToolChoice, Tracer } from "@graphorin/core";
|
|
8
|
+
import { Memory, PostCompactionHook } from "@graphorin/memory";
|
|
9
9
|
import { ResultReader } from "@graphorin/tools/result";
|
|
10
10
|
import { DataFlowPolicyConfig } from "@graphorin/security/dataflow";
|
|
11
|
+
import { InputGuardrail, OutputGuardrail } from "@graphorin/security/guardrails";
|
|
11
12
|
import { RuleOfTwoProfile, ToolArgumentPolicy } from "@graphorin/security/policy";
|
|
12
13
|
import { ToolRegistry } from "@graphorin/tools/registry";
|
|
13
|
-
import { Memory, PostCompactionHook } from "@graphorin/memory";
|
|
14
14
|
|
|
15
15
|
//#region src/types.d.ts
|
|
16
16
|
|
|
@@ -59,7 +59,7 @@ type PrepareStepHook<TDeps = unknown> = (ctx: RunContext<TDeps>) => Promise<Prep
|
|
|
59
59
|
/** @stable */
|
|
60
60
|
interface PrepareStepOverrides<TDeps = unknown> {
|
|
61
61
|
readonly provider?: Provider;
|
|
62
|
-
readonly tools?: ReadonlyArray<
|
|
62
|
+
readonly tools?: ReadonlyArray<AnyTool<TDeps>>;
|
|
63
63
|
readonly toolChoice?: ToolChoice;
|
|
64
64
|
readonly temperature?: number;
|
|
65
65
|
readonly maxTokens?: number;
|
|
@@ -92,7 +92,18 @@ interface SkillsRegistryLike {
|
|
|
92
92
|
type HandoffEntry<TDeps = unknown> = Agent<TDeps, any> | {
|
|
93
93
|
readonly target: Agent<TDeps, any>;
|
|
94
94
|
readonly inputFilter?: HandoffFilter;
|
|
95
|
+
/** W-036: which child events forward into the parent stream. */
|
|
96
|
+
readonly forwardEvents?: SubagentForwardPolicy;
|
|
95
97
|
};
|
|
98
|
+
/**
|
|
99
|
+
* W-036: sub-agent event-forwarding policy. `'lifecycle'` (default)
|
|
100
|
+
* forwards tool execution/approval, guardrail, lateral-leak,
|
|
101
|
+
* compaction and error events - never the high-frequency text deltas;
|
|
102
|
+
* `'all'` forwards everything; `'none'` keeps the child a black box.
|
|
103
|
+
*
|
|
104
|
+
* @stable
|
|
105
|
+
*/
|
|
106
|
+
type SubagentForwardPolicy = 'none' | 'lifecycle' | 'all';
|
|
96
107
|
/**
|
|
97
108
|
* The full options object accepted by {@link createAgent}.
|
|
98
109
|
*
|
|
@@ -109,12 +120,12 @@ interface AgentConfig<TDeps = unknown, TOutput = string> {
|
|
|
109
120
|
*/
|
|
110
121
|
readonly instructions: string | ((ctx: RunContext<TDeps>) => string | Promise<string>);
|
|
111
122
|
readonly provider: Provider;
|
|
112
|
-
readonly tools?: ReadonlyArray<
|
|
123
|
+
readonly tools?: ReadonlyArray<AnyTool<TDeps>>;
|
|
113
124
|
readonly skills?: SkillsRegistryLike;
|
|
114
125
|
readonly memory?: Memory;
|
|
115
126
|
/**
|
|
116
127
|
* Opt in to building the per-run system prompt from the memory
|
|
117
|
-
*
|
|
128
|
+
* `ContextEngine` (CE-1). When `true` **and** `memory` is wired, the
|
|
118
129
|
* runtime calls `memory.contextEngine.assemble(...)` once at run start: the
|
|
119
130
|
* agent's `instructions` become Layer 2 and the engine prepends the memory
|
|
120
131
|
* base and appends working blocks, procedural rules, skill cards, the
|
|
@@ -282,6 +293,17 @@ interface AgentConfig<TDeps = unknown, TOutput = string> {
|
|
|
282
293
|
readonly recordProviderResponses?: boolean;
|
|
283
294
|
readonly tracer?: Tracer;
|
|
284
295
|
readonly checkpointStore?: CheckpointStore;
|
|
296
|
+
/**
|
|
297
|
+
* What happens to the run's checkpoint thread when the run reaches a
|
|
298
|
+
* terminal status (W-005). `'keep'` (default) preserves the current
|
|
299
|
+
* behaviour: checkpoints survive for post-hoc debugging and
|
|
300
|
+
* process-restart resume. `'delete-on-terminal'` best-effort deletes
|
|
301
|
+
* the thread after `completed` / `failed` runs; `awaiting_approval`
|
|
302
|
+
* and `aborted` runs always keep theirs (the thread IS the resume
|
|
303
|
+
* state). Requires {@link AgentConfig.checkpointStore}.
|
|
304
|
+
* @default 'keep'
|
|
305
|
+
*/
|
|
306
|
+
readonly checkpointPolicy?: 'keep' | 'delete-on-terminal';
|
|
285
307
|
readonly sensitivity?: Sensitivity;
|
|
286
308
|
/**
|
|
287
309
|
* Agent-default capability restriction (D2). `'read-only'` builds a
|
|
@@ -336,8 +358,9 @@ type VerifierResult = {
|
|
|
336
358
|
* to the model (as a user message prefixed `[verifier:<id>]`) and the
|
|
337
359
|
* loop continues for up to `AgentConfig.maxVerifierRounds` extra rounds.
|
|
338
360
|
*
|
|
339
|
-
* A verifier that THROWS is treated as passed (
|
|
340
|
-
*
|
|
361
|
+
* A verifier that THROWS is treated as passed (the `verifier.result`
|
|
362
|
+
* event still fires with `ok: true`): a buggy verifier must never
|
|
363
|
+
* take down a run.
|
|
341
364
|
*
|
|
342
365
|
* @stable
|
|
343
366
|
*/
|
|
@@ -362,6 +385,16 @@ interface ApprovalDecision {
|
|
|
362
385
|
readonly toolCallId: string;
|
|
363
386
|
readonly granted: boolean;
|
|
364
387
|
readonly reason?: string;
|
|
388
|
+
/**
|
|
389
|
+
* W-001: echo of `ToolApproval.subRunToolCallId` for approvals that
|
|
390
|
+
* belong to a parked sub-agent run. Operators read the pair
|
|
391
|
+
* (`toolCallId`, `subRunToolCallId`) from `RunState.pendingApprovals`
|
|
392
|
+
* and return BOTH fields; decisions match on the composite key, so
|
|
393
|
+
* child-local toolCallId collisions across two parked children never
|
|
394
|
+
* cross-apply. A decision without this field applies only to the
|
|
395
|
+
* parent's own (unparked) approvals.
|
|
396
|
+
*/
|
|
397
|
+
readonly subRunToolCallId?: string;
|
|
365
398
|
}
|
|
366
399
|
/**
|
|
367
400
|
* Resume directive accepted by `agent.run(input | RunState, { directive })`.
|
|
@@ -400,6 +433,15 @@ interface AgentCallOptions<TDeps> {
|
|
|
400
433
|
* resuming a suspended run.
|
|
401
434
|
*/
|
|
402
435
|
readonly capability?: AgentCapability;
|
|
436
|
+
/**
|
|
437
|
+
* W-036: parent span for this run's `agent.run` root span - a
|
|
438
|
+
* multi-agent invocation forms ONE trace tree (the child's run span
|
|
439
|
+
* parents under the caller's step/tool span). The runtime supplies it
|
|
440
|
+
* automatically for handoffs and `toTool` sub-agents. Like
|
|
441
|
+
* `capability`, it is NOT persisted in `RunState`: re-supply on
|
|
442
|
+
* resume when stitching matters.
|
|
443
|
+
*/
|
|
444
|
+
readonly parentSpan?: AISpan;
|
|
403
445
|
}
|
|
404
446
|
/**
|
|
405
447
|
* Run-level capability restriction (D2 - the single-writer constraint
|
|
@@ -433,6 +475,8 @@ interface AgentToToolOptions {
|
|
|
433
475
|
* boundary at all).
|
|
434
476
|
*/
|
|
435
477
|
readonly inputFilter?: HandoffFilter;
|
|
478
|
+
/** W-036: which child events forward into the parent stream. */
|
|
479
|
+
readonly forwardEvents?: SubagentForwardPolicy;
|
|
436
480
|
/**
|
|
437
481
|
* Run the sub-agent under a restricted capability (D2): a
|
|
438
482
|
* `'read-only'` worker cannot execute or advertise writer tools. The
|
|
@@ -475,11 +519,17 @@ interface AbortOptions {
|
|
|
475
519
|
readonly drain?: boolean;
|
|
476
520
|
/**
|
|
477
521
|
* What to do with approvals that were already requested but not
|
|
478
|
-
* resolved at abort time.
|
|
522
|
+
* resolved at abort time (W-038).
|
|
479
523
|
*
|
|
480
|
-
* - `'deny'` (default) - auto-deny pending approvals
|
|
481
|
-
*
|
|
482
|
-
*
|
|
524
|
+
* - `'deny'` (default) - auto-deny pending approvals; each drained
|
|
525
|
+
* toolCallId gets a matching tool message so the transcript keeps
|
|
526
|
+
* no dangling `tool_use`, and the run ends `'aborted'`.
|
|
527
|
+
* - `'hold'` - keep the approvals on `RunState.pendingApprovals` of
|
|
528
|
+
* the `'aborted'` state; such a state re-enters the loop only via
|
|
529
|
+
* an explicit resume directive.
|
|
530
|
+
* - `'fail'` - reject the run with `RunError(code: 'run-aborted')`
|
|
531
|
+
* ONLY when approvals are actually pending; an abort with an empty
|
|
532
|
+
* queue ends `'aborted'`, never `'failed'`.
|
|
483
533
|
*/
|
|
484
534
|
readonly onPendingApprovals?: 'deny' | 'hold' | 'fail';
|
|
485
535
|
}
|
|
@@ -580,5 +630,5 @@ interface Agent<TDeps = unknown, TOutput = string> {
|
|
|
580
630
|
readonly registry?: ToolRegistry;
|
|
581
631
|
}
|
|
582
632
|
//#endregion
|
|
583
|
-
export { AbortOptions, Agent, AgentCallOptions, AgentCapability, AgentConfig, AgentInput, AgentToToolOptions, CompactOptions, CompactionApiResult, OutputSpec, PostCompactionHook$1 as PostCompactionHook, PrepareStepHook, PrepareStepOverrides, ResponseVerifier, ResumeDirective, SkillsRegistryLike, VerifierResult };
|
|
633
|
+
export { AbortOptions, Agent, AgentCallOptions, AgentCapability, AgentConfig, AgentInput, AgentToToolOptions, CompactOptions, CompactionApiResult, HandoffEntry, OutputSpec, PostCompactionHook$1 as PostCompactionHook, PrepareStepHook, PrepareStepOverrides, ResponseVerifier, ResumeDirective, SkillsRegistryLike, VerifierResult };
|
|
584
634
|
//# sourceMappingURL=types.d.ts.map
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","names":[],"sources":["../src/types.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"types.d.ts","names":[],"sources":["../src/types.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;;;;;;;AAyDA;;;;;AA0BA;;AACO,KAlCK,UAAA,GAkCL,MAAA,GAlC2B,OAkC3B,GAlCqC,aAkCrC,CAlCmD,OAkCnD,CAAA;;;;;;AACyD,UA5B/C,UA4B+C,CAAA,OAAA,CAA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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graphorin/agent",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"description": "Agent runtime for the Graphorin framework: createAgent({...}) factory, the typed model -> tool calls -> model loop, the AgentEvent<TOutput> discriminated event stream, steering / followUp queues, durable HITL approvals via runStateToJSON / runStateFromJSON, multi-agent handoffs (Agent.toTool, filter library, secrets isolation), agent-level model fallback chain, intra-loop reasoning preservation, post-compaction hook lifecycle, agent-step-level fan-out (Agent.fanOut + evaluatorOptimizer + progress artifacts), per-tool model-tier hint resolution, lateral-leak defense layer (CausalityMonitor + MergeAgentSidewaysInjectionGuard + protocol-guard), inbound-content sanitization preamble injection, and AbortSignal-aware hard-kill / drain cancellation. Created and maintained by Oleksiy Stepurenko.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Oleksiy Stepurenko",
|
|
@@ -33,8 +33,9 @@
|
|
|
33
33
|
"causality-monitor"
|
|
34
34
|
],
|
|
35
35
|
"type": "module",
|
|
36
|
+
"sideEffects": false,
|
|
36
37
|
"engines": {
|
|
37
|
-
"node": ">=22.
|
|
38
|
+
"node": ">=22.12.0"
|
|
38
39
|
},
|
|
39
40
|
"main": "./dist/index.js",
|
|
40
41
|
"module": "./dist/index.js",
|
|
@@ -42,64 +43,63 @@
|
|
|
42
43
|
"exports": {
|
|
43
44
|
".": {
|
|
44
45
|
"types": "./dist/index.d.ts",
|
|
45
|
-
"
|
|
46
|
+
"default": "./dist/index.js"
|
|
46
47
|
},
|
|
47
48
|
"./factory": {
|
|
48
49
|
"types": "./dist/factory.d.ts",
|
|
49
|
-
"
|
|
50
|
+
"default": "./dist/factory.js"
|
|
50
51
|
},
|
|
51
52
|
"./run-state": {
|
|
52
53
|
"types": "./dist/run-state/index.d.ts",
|
|
53
|
-
"
|
|
54
|
+
"default": "./dist/run-state/index.js"
|
|
54
55
|
},
|
|
55
56
|
"./filters": {
|
|
56
57
|
"types": "./dist/filters/index.d.ts",
|
|
57
|
-
"
|
|
58
|
+
"default": "./dist/filters/index.js"
|
|
58
59
|
},
|
|
59
60
|
"./fallback": {
|
|
60
61
|
"types": "./dist/fallback/index.d.ts",
|
|
61
|
-
"
|
|
62
|
+
"default": "./dist/fallback/index.js"
|
|
62
63
|
},
|
|
63
64
|
"./preferred-model": {
|
|
64
65
|
"types": "./dist/preferred-model/index.d.ts",
|
|
65
|
-
"
|
|
66
|
+
"default": "./dist/preferred-model/index.js"
|
|
66
67
|
},
|
|
67
68
|
"./fanout": {
|
|
68
69
|
"types": "./dist/fanout/index.d.ts",
|
|
69
|
-
"
|
|
70
|
+
"default": "./dist/fanout/index.js"
|
|
70
71
|
},
|
|
71
72
|
"./evaluator-optimizer": {
|
|
72
73
|
"types": "./dist/evaluator-optimizer/index.d.ts",
|
|
73
|
-
"
|
|
74
|
+
"default": "./dist/evaluator-optimizer/index.js"
|
|
74
75
|
},
|
|
75
76
|
"./progress": {
|
|
76
77
|
"types": "./dist/progress/index.d.ts",
|
|
77
|
-
"
|
|
78
|
+
"default": "./dist/progress/index.js"
|
|
78
79
|
},
|
|
79
80
|
"./lateral-leak": {
|
|
80
81
|
"types": "./dist/lateral-leak/index.d.ts",
|
|
81
|
-
"
|
|
82
|
+
"default": "./dist/lateral-leak/index.js"
|
|
82
83
|
},
|
|
83
84
|
"./errors": {
|
|
84
85
|
"types": "./dist/errors/index.d.ts",
|
|
85
|
-
"
|
|
86
|
+
"default": "./dist/errors/index.js"
|
|
86
87
|
},
|
|
87
88
|
"./package.json": "./package.json"
|
|
88
89
|
},
|
|
89
90
|
"files": [
|
|
90
91
|
"dist",
|
|
92
|
+
"src",
|
|
91
93
|
"README.md",
|
|
92
94
|
"CHANGELOG.md",
|
|
93
95
|
"LICENSE"
|
|
94
96
|
],
|
|
95
97
|
"dependencies": {
|
|
96
|
-
"@graphorin/core": "0.
|
|
97
|
-
"@graphorin/memory": "0.
|
|
98
|
-
"@graphorin/
|
|
99
|
-
"@graphorin/
|
|
100
|
-
"@graphorin/
|
|
101
|
-
"@graphorin/skills": "0.6.0",
|
|
102
|
-
"@graphorin/tools": "0.6.0"
|
|
98
|
+
"@graphorin/core": "0.7.0",
|
|
99
|
+
"@graphorin/memory": "0.7.0",
|
|
100
|
+
"@graphorin/security": "0.7.0",
|
|
101
|
+
"@graphorin/skills": "0.7.0",
|
|
102
|
+
"@graphorin/tools": "0.7.0"
|
|
103
103
|
},
|
|
104
104
|
"publishConfig": {
|
|
105
105
|
"access": "public",
|
|
@@ -0,0 +1,320 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Typed error surface for `@graphorin/agent`.
|
|
3
|
+
*
|
|
4
|
+
* Every error class extends the base {@link AgentRuntimeError} which is
|
|
5
|
+
* a thin wrapper around `Error` with a stable `code` discriminator so
|
|
6
|
+
* callers can `switch` on it without parsing messages.
|
|
7
|
+
*
|
|
8
|
+
* @packageDocumentation
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Stable code discriminator surfaced on every {@link AgentRuntimeError}.
|
|
13
|
+
*
|
|
14
|
+
* @stable
|
|
15
|
+
*/
|
|
16
|
+
export type AgentRuntimeErrorCode =
|
|
17
|
+
| 'invalid-config'
|
|
18
|
+
| 'invalid-preferred-model'
|
|
19
|
+
| 'invalid-fallback-policy'
|
|
20
|
+
| 'invalid-evaluator-optimizer-config'
|
|
21
|
+
| 'agent-resolution-failed'
|
|
22
|
+
| 'tool-not-found'
|
|
23
|
+
| 'handoff-target-not-found'
|
|
24
|
+
| 'multiple-handoffs-in-step'
|
|
25
|
+
| 'sub-run-resume-target-not-found'
|
|
26
|
+
| 'run-aborted'
|
|
27
|
+
| 'middleware-order-violation'
|
|
28
|
+
| 'progress-write-failed'
|
|
29
|
+
| 'merge-blocked'
|
|
30
|
+
| 'protocol-injection-rejected'
|
|
31
|
+
| 'run-state-version-unsupported'
|
|
32
|
+
| 'run-state-malformed'
|
|
33
|
+
| 'concurrent-run';
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Base class for every error thrown from `@graphorin/agent`.
|
|
37
|
+
*
|
|
38
|
+
* @stable
|
|
39
|
+
*/
|
|
40
|
+
export class AgentRuntimeError extends Error {
|
|
41
|
+
readonly code: AgentRuntimeErrorCode;
|
|
42
|
+
constructor(code: AgentRuntimeErrorCode, message: string, name = 'AgentRuntimeError') {
|
|
43
|
+
super(message);
|
|
44
|
+
this.name = name;
|
|
45
|
+
this.code = code;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Thrown by `createAgent({...})` when the supplied options fail
|
|
51
|
+
* structural validation (missing `provider`, empty `name`, an
|
|
52
|
+
* `outputType` of kind `'text'` carrying a `schema`, ...).
|
|
53
|
+
*
|
|
54
|
+
* @stable
|
|
55
|
+
*/
|
|
56
|
+
export class InvalidAgentConfigError extends AgentRuntimeError {
|
|
57
|
+
constructor(reason: string) {
|
|
58
|
+
super(
|
|
59
|
+
'invalid-config',
|
|
60
|
+
`Invalid createAgent({...}) options: ${reason}.`,
|
|
61
|
+
'InvalidAgentConfigError',
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Thrown by `createAgent({...})` when `preferredModel` carries an
|
|
68
|
+
* unknown literal (any value outside the `'fast' | 'balanced' |
|
|
69
|
+
* 'smart'` cost-tier vocabulary AND not a valid `ModelSpec`).
|
|
70
|
+
*
|
|
71
|
+
* @stable
|
|
72
|
+
*/
|
|
73
|
+
export class InvalidPreferredModelError extends AgentRuntimeError {
|
|
74
|
+
readonly value: unknown;
|
|
75
|
+
constructor(value: unknown) {
|
|
76
|
+
super(
|
|
77
|
+
'invalid-preferred-model',
|
|
78
|
+
`Invalid Agent.preferredModel: ${JSON.stringify(value)}. ` +
|
|
79
|
+
"Expected 'fast' | 'balanced' | 'smart' | ModelSpec.",
|
|
80
|
+
'InvalidPreferredModelError',
|
|
81
|
+
);
|
|
82
|
+
this.value = value;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Thrown by `evaluatorOptimizer({...})` when `maxIterations < 1` at
|
|
88
|
+
* construction time. The helper purposely surfaces the misuse early
|
|
89
|
+
* rather than failing on the first run.
|
|
90
|
+
*
|
|
91
|
+
* @stable
|
|
92
|
+
*/
|
|
93
|
+
export class EvaluatorOptimizerConfigError extends AgentRuntimeError {
|
|
94
|
+
constructor(reason: string) {
|
|
95
|
+
super(
|
|
96
|
+
'invalid-evaluator-optimizer-config',
|
|
97
|
+
`Invalid evaluatorOptimizer({...}) options: ${reason}.`,
|
|
98
|
+
'EvaluatorOptimizerConfigError',
|
|
99
|
+
);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Thrown by `runStateFromJSON(...)` when the agent name in the
|
|
105
|
+
* serialized state cannot be resolved against the supplied agent
|
|
106
|
+
* graph (renamed agent / removed handoff).
|
|
107
|
+
*
|
|
108
|
+
* @stable
|
|
109
|
+
*/
|
|
110
|
+
export class AgentResolutionError extends AgentRuntimeError {
|
|
111
|
+
readonly agentId: string;
|
|
112
|
+
constructor(agentId: string) {
|
|
113
|
+
super(
|
|
114
|
+
'agent-resolution-failed',
|
|
115
|
+
`runStateFromJSON: agent '${agentId}' is not registered in the supplied graph.`,
|
|
116
|
+
'AgentResolutionError',
|
|
117
|
+
);
|
|
118
|
+
this.agentId = agentId;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Thrown by the agent loop when the model emits a tool call referring
|
|
124
|
+
* to an unregistered tool (the model hallucinated a name).
|
|
125
|
+
*
|
|
126
|
+
* @stable
|
|
127
|
+
*/
|
|
128
|
+
export class ToolNotFoundError extends AgentRuntimeError {
|
|
129
|
+
readonly toolName: string;
|
|
130
|
+
constructor(toolName: string) {
|
|
131
|
+
super(
|
|
132
|
+
'tool-not-found',
|
|
133
|
+
`Tool '${toolName}' is not registered on this agent.`,
|
|
134
|
+
'ToolNotFoundError',
|
|
135
|
+
);
|
|
136
|
+
this.toolName = toolName;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Thrown when the model invokes more than one handoff (`transfer_to_*`)
|
|
142
|
+
* tool in a single response. Per the agent-loop documentation this is
|
|
143
|
+
* an error rather than a silent drop.
|
|
144
|
+
*
|
|
145
|
+
* @stable
|
|
146
|
+
*/
|
|
147
|
+
/**
|
|
148
|
+
* Thrown when a second `run()` / `stream()` starts while another run is
|
|
149
|
+
* in flight on the same `Agent` instance (AG-11). The public surface
|
|
150
|
+
* (`steer` / `followUp` / `abort` / `compact`) addresses "the run"
|
|
151
|
+
* without a run handle, so overlapping runs would share the abort
|
|
152
|
+
* controller, steer queue, and executor bridge - start the second run
|
|
153
|
+
* on its own `createAgent(...)` instance instead.
|
|
154
|
+
*
|
|
155
|
+
* @stable
|
|
156
|
+
*/
|
|
157
|
+
export class ConcurrentRunError extends AgentRuntimeError {
|
|
158
|
+
constructor() {
|
|
159
|
+
super(
|
|
160
|
+
'concurrent-run',
|
|
161
|
+
'This Agent instance already has a run in flight. One run per instance: await the active run (or abort it), or create a separate agent instance for parallel work.',
|
|
162
|
+
'ConcurrentRunError',
|
|
163
|
+
);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
export class MultipleHandoffsInStepError extends AgentRuntimeError {
|
|
168
|
+
readonly handoffNames: ReadonlyArray<string>;
|
|
169
|
+
constructor(handoffNames: ReadonlyArray<string>) {
|
|
170
|
+
super(
|
|
171
|
+
'multiple-handoffs-in-step',
|
|
172
|
+
`The model invoked multiple handoff tools in one step: ${handoffNames.join(', ')}.`,
|
|
173
|
+
'MultipleHandoffsInStepError',
|
|
174
|
+
);
|
|
175
|
+
this.handoffNames = handoffNames;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* Thrown when a resume directive routes a decision into a parked
|
|
181
|
+
* sub-agent run (W-001) but the resuming agent instance cannot resolve
|
|
182
|
+
* the target: the parked toolName matches neither a configured handoff
|
|
183
|
+
* target nor a `toTool` sub-agent tool. Resume a parked sub-run on the
|
|
184
|
+
* SAME parent instance (or an identically-configured one).
|
|
185
|
+
*
|
|
186
|
+
* @stable
|
|
187
|
+
*/
|
|
188
|
+
export class SubAgentResumeTargetNotFoundError extends AgentRuntimeError {
|
|
189
|
+
readonly toolName: string;
|
|
190
|
+
constructor(toolName: string, detail: string) {
|
|
191
|
+
super(
|
|
192
|
+
'sub-run-resume-target-not-found',
|
|
193
|
+
`Cannot resume parked sub-agent run for tool '${toolName}': ${detail}. Parked sub-runs resume only on a parent instance configured with the same handoff target or toTool sub-agent tool.`,
|
|
194
|
+
'SubAgentResumeTargetNotFoundError',
|
|
195
|
+
);
|
|
196
|
+
this.toolName = toolName;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* Thrown by `runStateFromJSON(...)` when the version field in the
|
|
202
|
+
* serialized state is from a future major version of the framework.
|
|
203
|
+
*
|
|
204
|
+
* @stable
|
|
205
|
+
*/
|
|
206
|
+
export class RunStateVersionUnsupportedError extends AgentRuntimeError {
|
|
207
|
+
readonly version: string;
|
|
208
|
+
readonly readerVersion: string;
|
|
209
|
+
constructor(version: string, readerVersion: string) {
|
|
210
|
+
super(
|
|
211
|
+
'run-state-version-unsupported',
|
|
212
|
+
`RunState version '${version}' is newer than reader '${readerVersion}'. ` +
|
|
213
|
+
'Upgrade @graphorin/agent to load this state.',
|
|
214
|
+
'RunStateVersionUnsupportedError',
|
|
215
|
+
);
|
|
216
|
+
this.version = version;
|
|
217
|
+
this.readerVersion = readerVersion;
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* Thrown by `runStateFromJSON(...)` when the supplied JSON does not
|
|
223
|
+
* shape-match the documented `SerializedRunState`.
|
|
224
|
+
*
|
|
225
|
+
* @stable
|
|
226
|
+
*/
|
|
227
|
+
export class RunStateMalformedError extends AgentRuntimeError {
|
|
228
|
+
constructor(reason: string) {
|
|
229
|
+
super('run-state-malformed', `Malformed RunState JSON: ${reason}.`, 'RunStateMalformedError');
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
/**
|
|
234
|
+
* Thrown by `Agent.fanOut(...)` when the configured
|
|
235
|
+
* `MergeAgentSidewaysInjectionGuard` fires with strictness
|
|
236
|
+
* `'detect-and-block'`.
|
|
237
|
+
*
|
|
238
|
+
* @stable
|
|
239
|
+
*/
|
|
240
|
+
export class MergeBlockedError extends AgentRuntimeError {
|
|
241
|
+
readonly fanOutId: string;
|
|
242
|
+
readonly reason: string;
|
|
243
|
+
constructor(fanOutId: string, reason: string) {
|
|
244
|
+
super(
|
|
245
|
+
'merge-blocked',
|
|
246
|
+
`Agent.fanOut('${fanOutId}') merge blocked by MergeAgentSidewaysInjectionGuard: ${reason}.`,
|
|
247
|
+
'MergeBlockedError',
|
|
248
|
+
);
|
|
249
|
+
this.fanOutId = fanOutId;
|
|
250
|
+
this.reason = reason;
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
/**
|
|
255
|
+
* Thrown by the protocol-injection guard when the operator selected
|
|
256
|
+
* the strictest deployment posture (`escapePolicy: 'reject'`) and a
|
|
257
|
+
* tool result body carries control characters at the corresponding
|
|
258
|
+
* outbound boundary.
|
|
259
|
+
*
|
|
260
|
+
* @stable
|
|
261
|
+
*/
|
|
262
|
+
export class ProtocolInjectionRejectError extends AgentRuntimeError {
|
|
263
|
+
readonly boundary: string;
|
|
264
|
+
readonly matchedPattern: string;
|
|
265
|
+
constructor(boundary: string, matchedPattern: string) {
|
|
266
|
+
super(
|
|
267
|
+
'protocol-injection-rejected',
|
|
268
|
+
`Protocol injection guard rejected output at the '${boundary}' boundary (matched ${matchedPattern}).`,
|
|
269
|
+
'ProtocolInjectionRejectError',
|
|
270
|
+
);
|
|
271
|
+
this.boundary = boundary;
|
|
272
|
+
this.matchedPattern = matchedPattern;
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
/**
|
|
277
|
+
* Thrown by `agent.progress.write(...)` when the atomic write fails
|
|
278
|
+
* (disk full, permission denied, ...). The partial `.tmp` file is
|
|
279
|
+
* unlinked before the error propagates.
|
|
280
|
+
*
|
|
281
|
+
* @stable
|
|
282
|
+
*/
|
|
283
|
+
export class ProgressWriteError extends AgentRuntimeError {
|
|
284
|
+
readonly path: string;
|
|
285
|
+
constructor(path: string, cause: unknown) {
|
|
286
|
+
const message = cause instanceof Error ? cause.message : String(cause);
|
|
287
|
+
super(
|
|
288
|
+
'progress-write-failed',
|
|
289
|
+
`agent.progress.write('${path}') failed: ${message}.`,
|
|
290
|
+
'ProgressWriteError',
|
|
291
|
+
);
|
|
292
|
+
this.path = path;
|
|
293
|
+
if (cause !== undefined) {
|
|
294
|
+
// Preserve the underlying cause for diagnostics.
|
|
295
|
+
Object.defineProperty(this, 'cause', {
|
|
296
|
+
value: cause,
|
|
297
|
+
enumerable: false,
|
|
298
|
+
configurable: true,
|
|
299
|
+
writable: true,
|
|
300
|
+
});
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
/**
|
|
306
|
+
* Thrown by `createAgent({...})` when the supplied
|
|
307
|
+
* `composeProviderMiddleware` chain violates the canonical inside-out
|
|
308
|
+
* ordering (DEC-145 / ADR-039).
|
|
309
|
+
*
|
|
310
|
+
* @stable
|
|
311
|
+
*/
|
|
312
|
+
export class ProviderMiddlewareOrderError extends AgentRuntimeError {
|
|
313
|
+
constructor(reason: string) {
|
|
314
|
+
super(
|
|
315
|
+
'middleware-order-violation',
|
|
316
|
+
`Provider middleware composition violated the inside-out ordering: ${reason}.`,
|
|
317
|
+
'ProviderMiddlewareOrderError',
|
|
318
|
+
);
|
|
319
|
+
}
|
|
320
|
+
}
|