groundswell 0.0.3 → 1.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 +26 -9
- package/dist/cache/cache-key.d.ts +20 -0
- package/dist/cache/cache-key.d.ts.map +1 -1
- package/dist/cache/cache-key.js +9 -0
- package/dist/cache/cache-key.js.map +1 -1
- package/dist/core/agent.d.ts +120 -29
- package/dist/core/agent.d.ts.map +1 -1
- package/dist/core/agent.js +584 -177
- package/dist/core/agent.js.map +1 -1
- package/dist/core/mcp-handler.d.ts +63 -5
- package/dist/core/mcp-handler.d.ts.map +1 -1
- package/dist/core/mcp-handler.js +184 -4
- package/dist/core/mcp-handler.js.map +1 -1
- package/dist/core/workflow-context.d.ts +6 -2
- package/dist/core/workflow-context.d.ts.map +1 -1
- package/dist/core/workflow-context.js +99 -4
- package/dist/core/workflow-context.js.map +1 -1
- package/dist/core/workflow.d.ts +315 -13
- package/dist/core/workflow.d.ts.map +1 -1
- package/dist/core/workflow.js +552 -30
- package/dist/core/workflow.js.map +1 -1
- package/dist/debugger/event-replayer.d.ts +422 -0
- package/dist/debugger/event-replayer.d.ts.map +1 -0
- package/dist/debugger/event-replayer.js +639 -0
- package/dist/debugger/event-replayer.js.map +1 -0
- package/dist/debugger/tree-debugger.d.ts +170 -1
- package/dist/debugger/tree-debugger.d.ts.map +1 -1
- package/dist/debugger/tree-debugger.js +423 -1
- package/dist/debugger/tree-debugger.js.map +1 -1
- package/dist/decorators/step.d.ts.map +1 -1
- package/dist/decorators/step.js +129 -47
- package/dist/decorators/step.js.map +1 -1
- package/dist/harnesses/claude-code-harness.d.ts +391 -0
- package/dist/harnesses/claude-code-harness.d.ts.map +1 -0
- package/dist/harnesses/claude-code-harness.js +1076 -0
- package/dist/harnesses/claude-code-harness.js.map +1 -0
- package/dist/harnesses/harness-registry.d.ts +440 -0
- package/dist/harnesses/harness-registry.d.ts.map +1 -0
- package/dist/harnesses/harness-registry.js +543 -0
- package/dist/harnesses/harness-registry.js.map +1 -0
- package/dist/harnesses/index.d.ts +12 -0
- package/dist/harnesses/index.d.ts.map +1 -0
- package/dist/harnesses/index.js +11 -0
- package/dist/harnesses/index.js.map +1 -0
- package/dist/harnesses/pi-harness.d.ts +219 -0
- package/dist/harnesses/pi-harness.d.ts.map +1 -0
- package/dist/harnesses/pi-harness.js +676 -0
- package/dist/harnesses/pi-harness.js.map +1 -0
- package/dist/harnesses/pi-schema-converter.d.ts +24 -0
- package/dist/harnesses/pi-schema-converter.d.ts.map +1 -0
- package/dist/harnesses/pi-schema-converter.js +81 -0
- package/dist/harnesses/pi-schema-converter.js.map +1 -0
- package/dist/harnesses/register-defaults.d.ts +24 -0
- package/dist/harnesses/register-defaults.d.ts.map +1 -0
- package/dist/harnesses/register-defaults.js +40 -0
- package/dist/harnesses/register-defaults.js.map +1 -0
- package/dist/harnesses/session-store.d.ts +201 -0
- package/dist/harnesses/session-store.d.ts.map +1 -0
- package/dist/harnesses/session-store.js +254 -0
- package/dist/harnesses/session-store.js.map +1 -0
- package/dist/index.d.ts +12 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +17 -0
- package/dist/index.js.map +1 -1
- package/dist/reflection/reflection.d.ts.map +1 -1
- package/dist/reflection/reflection.js +19 -4
- package/dist/reflection/reflection.js.map +1 -1
- package/dist/types/agent.d.ts +1253 -2
- package/dist/types/agent.d.ts.map +1 -1
- package/dist/types/agent.js +418 -1
- package/dist/types/agent.js.map +1 -1
- package/dist/types/decorators.d.ts +10 -1
- package/dist/types/decorators.d.ts.map +1 -1
- package/dist/types/events.d.ts +26 -0
- package/dist/types/events.d.ts.map +1 -1
- package/dist/types/harnesses.d.ts +474 -0
- package/dist/types/harnesses.d.ts.map +1 -0
- package/dist/types/harnesses.js +2 -0
- package/dist/types/harnesses.js.map +1 -0
- package/dist/types/index.d.ts +9 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +6 -0
- package/dist/types/index.js.map +1 -1
- package/dist/types/providers.d.ts +691 -0
- package/dist/types/providers.d.ts.map +1 -0
- package/dist/types/providers.js +14 -0
- package/dist/types/providers.js.map +1 -0
- package/dist/types/restart.d.ts +132 -0
- package/dist/types/restart.d.ts.map +1 -0
- package/dist/types/restart.js +2 -0
- package/dist/types/restart.js.map +1 -0
- package/dist/types/streaming.d.ts +194 -0
- package/dist/types/streaming.d.ts.map +1 -0
- package/dist/types/streaming.js +67 -0
- package/dist/types/streaming.js.map +1 -0
- package/dist/types/workflow-context.d.ts +137 -1
- package/dist/types/workflow-context.d.ts.map +1 -1
- package/dist/utils/agent-validation.d.ts +88 -0
- package/dist/utils/agent-validation.d.ts.map +1 -0
- package/dist/utils/agent-validation.js +87 -0
- package/dist/utils/agent-validation.js.map +1 -0
- package/dist/utils/delay.d.ts +7 -0
- package/dist/utils/delay.d.ts.map +1 -0
- package/dist/utils/delay.js +9 -0
- package/dist/utils/delay.js.map +1 -0
- package/dist/utils/harness-config.d.ts +180 -0
- package/dist/utils/harness-config.d.ts.map +1 -0
- package/dist/utils/harness-config.js +311 -0
- package/dist/utils/harness-config.js.map +1 -0
- package/dist/utils/index.d.ts +9 -1
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +8 -1
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/model-spec.d.ts +110 -0
- package/dist/utils/model-spec.d.ts.map +1 -0
- package/dist/utils/model-spec.js +149 -0
- package/dist/utils/model-spec.js.map +1 -0
- package/dist/utils/provider-config.d.ts +10 -0
- package/dist/utils/provider-config.d.ts.map +1 -0
- package/dist/utils/provider-config.js +10 -0
- package/dist/utils/provider-config.js.map +1 -0
- package/dist/utils/restart-analysis.d.ts +202 -0
- package/dist/utils/restart-analysis.d.ts.map +1 -0
- package/dist/utils/restart-analysis.js +426 -0
- package/dist/utils/restart-analysis.js.map +1 -0
- package/dist/utils/session-serialization.d.ts +118 -0
- package/dist/utils/session-serialization.d.ts.map +1 -0
- package/dist/utils/session-serialization.js +217 -0
- package/dist/utils/session-serialization.js.map +1 -0
- package/package.json +31 -5
- package/CHANGELOG.md +0 -188
- package/dist/__tests__/adversarial/attachChild-performance.test.d.ts +0 -16
- package/dist/__tests__/adversarial/attachChild-performance.test.d.ts.map +0 -1
- package/dist/__tests__/adversarial/attachChild-performance.test.js +0 -187
- package/dist/__tests__/adversarial/attachChild-performance.test.js.map +0 -1
- package/dist/__tests__/adversarial/circular-reference.test.d.ts +0 -13
- package/dist/__tests__/adversarial/circular-reference.test.d.ts.map +0 -1
- package/dist/__tests__/adversarial/circular-reference.test.js +0 -92
- package/dist/__tests__/adversarial/circular-reference.test.js.map +0 -1
- package/dist/__tests__/adversarial/complex-circular-reference.test.d.ts +0 -16
- package/dist/__tests__/adversarial/complex-circular-reference.test.d.ts.map +0 -1
- package/dist/__tests__/adversarial/complex-circular-reference.test.js +0 -127
- package/dist/__tests__/adversarial/complex-circular-reference.test.js.map +0 -1
- package/dist/__tests__/adversarial/concurrent-task-failures.test.d.ts +0 -21
- package/dist/__tests__/adversarial/concurrent-task-failures.test.d.ts.map +0 -1
- package/dist/__tests__/adversarial/concurrent-task-failures.test.js +0 -667
- package/dist/__tests__/adversarial/concurrent-task-failures.test.js.map +0 -1
- package/dist/__tests__/adversarial/deep-analysis.test.d.ts +0 -6
- package/dist/__tests__/adversarial/deep-analysis.test.d.ts.map +0 -1
- package/dist/__tests__/adversarial/deep-analysis.test.js +0 -877
- package/dist/__tests__/adversarial/deep-analysis.test.js.map +0 -1
- package/dist/__tests__/adversarial/deep-hierarchy-stress.test.d.ts +0 -13
- package/dist/__tests__/adversarial/deep-hierarchy-stress.test.d.ts.map +0 -1
- package/dist/__tests__/adversarial/deep-hierarchy-stress.test.js +0 -186
- package/dist/__tests__/adversarial/deep-hierarchy-stress.test.js.map +0 -1
- package/dist/__tests__/adversarial/e2e-prd-validation.test.d.ts +0 -6
- package/dist/__tests__/adversarial/e2e-prd-validation.test.d.ts.map +0 -1
- package/dist/__tests__/adversarial/e2e-prd-validation.test.js +0 -626
- package/dist/__tests__/adversarial/e2e-prd-validation.test.js.map +0 -1
- package/dist/__tests__/adversarial/edge-case.test.d.ts +0 -6
- package/dist/__tests__/adversarial/edge-case.test.d.ts.map +0 -1
- package/dist/__tests__/adversarial/edge-case.test.js +0 -857
- package/dist/__tests__/adversarial/edge-case.test.js.map +0 -1
- package/dist/__tests__/adversarial/error-merge-strategy.test.d.ts +0 -20
- package/dist/__tests__/adversarial/error-merge-strategy.test.d.ts.map +0 -1
- package/dist/__tests__/adversarial/error-merge-strategy.test.js +0 -907
- package/dist/__tests__/adversarial/error-merge-strategy.test.js.map +0 -1
- package/dist/__tests__/adversarial/incremental-performance.test.d.ts +0 -2
- package/dist/__tests__/adversarial/incremental-performance.test.d.ts.map +0 -1
- package/dist/__tests__/adversarial/incremental-performance.test.js +0 -113
- package/dist/__tests__/adversarial/incremental-performance.test.js.map +0 -1
- package/dist/__tests__/adversarial/node-map-update-benchmarks.test.d.ts +0 -22
- package/dist/__tests__/adversarial/node-map-update-benchmarks.test.d.ts.map +0 -1
- package/dist/__tests__/adversarial/node-map-update-benchmarks.test.js +0 -383
- package/dist/__tests__/adversarial/node-map-update-benchmarks.test.js.map +0 -1
- package/dist/__tests__/adversarial/observer-propagation.test.d.ts +0 -21
- package/dist/__tests__/adversarial/observer-propagation.test.d.ts.map +0 -1
- package/dist/__tests__/adversarial/observer-propagation.test.js +0 -404
- package/dist/__tests__/adversarial/observer-propagation.test.js.map +0 -1
- package/dist/__tests__/adversarial/parent-validation.test.d.ts +0 -13
- package/dist/__tests__/adversarial/parent-validation.test.d.ts.map +0 -1
- package/dist/__tests__/adversarial/parent-validation.test.js +0 -128
- package/dist/__tests__/adversarial/parent-validation.test.js.map +0 -1
- package/dist/__tests__/adversarial/prd-12-2-compliance.test.d.ts +0 -20
- package/dist/__tests__/adversarial/prd-12-2-compliance.test.d.ts.map +0 -1
- package/dist/__tests__/adversarial/prd-12-2-compliance.test.js +0 -482
- package/dist/__tests__/adversarial/prd-12-2-compliance.test.js.map +0 -1
- package/dist/__tests__/adversarial/prd-compliance.test.d.ts +0 -6
- package/dist/__tests__/adversarial/prd-compliance.test.d.ts.map +0 -1
- package/dist/__tests__/adversarial/prd-compliance.test.js +0 -886
- package/dist/__tests__/adversarial/prd-compliance.test.js.map +0 -1
- package/dist/__tests__/compatibility/backward-compatibility.test.d.ts +0 -22
- package/dist/__tests__/compatibility/backward-compatibility.test.d.ts.map +0 -1
- package/dist/__tests__/compatibility/backward-compatibility.test.js +0 -1843
- package/dist/__tests__/compatibility/backward-compatibility.test.js.map +0 -1
- package/dist/__tests__/helpers/index.d.ts +0 -10
- package/dist/__tests__/helpers/index.d.ts.map +0 -1
- package/dist/__tests__/helpers/index.js +0 -10
- package/dist/__tests__/helpers/index.js.map +0 -1
- package/dist/__tests__/helpers/tree-verification.d.ts +0 -90
- package/dist/__tests__/helpers/tree-verification.d.ts.map +0 -1
- package/dist/__tests__/helpers/tree-verification.js +0 -202
- package/dist/__tests__/helpers/tree-verification.js.map +0 -1
- package/dist/__tests__/integration/agent-workflow.test.d.ts +0 -2
- package/dist/__tests__/integration/agent-workflow.test.d.ts.map +0 -1
- package/dist/__tests__/integration/agent-workflow.test.js +0 -256
- package/dist/__tests__/integration/agent-workflow.test.js.map +0 -1
- package/dist/__tests__/integration/bidirectional-consistency.test.d.ts +0 -14
- package/dist/__tests__/integration/bidirectional-consistency.test.d.ts.map +0 -1
- package/dist/__tests__/integration/bidirectional-consistency.test.js +0 -668
- package/dist/__tests__/integration/bidirectional-consistency.test.js.map +0 -1
- package/dist/__tests__/integration/observer-logging.test.d.ts +0 -2
- package/dist/__tests__/integration/observer-logging.test.d.ts.map +0 -1
- package/dist/__tests__/integration/observer-logging.test.js +0 -517
- package/dist/__tests__/integration/observer-logging.test.js.map +0 -1
- package/dist/__tests__/integration/tree-mirroring.test.d.ts +0 -2
- package/dist/__tests__/integration/tree-mirroring.test.d.ts.map +0 -1
- package/dist/__tests__/integration/tree-mirroring.test.js +0 -117
- package/dist/__tests__/integration/tree-mirroring.test.js.map +0 -1
- package/dist/__tests__/integration/workflow-reparenting.test.d.ts +0 -12
- package/dist/__tests__/integration/workflow-reparenting.test.d.ts.map +0 -1
- package/dist/__tests__/integration/workflow-reparenting.test.js +0 -239
- package/dist/__tests__/integration/workflow-reparenting.test.js.map +0 -1
- package/dist/__tests__/unit/agent.test.d.ts +0 -2
- package/dist/__tests__/unit/agent.test.d.ts.map +0 -1
- package/dist/__tests__/unit/agent.test.js +0 -143
- package/dist/__tests__/unit/agent.test.js.map +0 -1
- package/dist/__tests__/unit/cache-key.test.d.ts +0 -5
- package/dist/__tests__/unit/cache-key.test.d.ts.map +0 -1
- package/dist/__tests__/unit/cache-key.test.js +0 -145
- package/dist/__tests__/unit/cache-key.test.js.map +0 -1
- package/dist/__tests__/unit/cache.test.d.ts +0 -5
- package/dist/__tests__/unit/cache.test.d.ts.map +0 -1
- package/dist/__tests__/unit/cache.test.js +0 -132
- package/dist/__tests__/unit/cache.test.js.map +0 -1
- package/dist/__tests__/unit/context.test.d.ts +0 -2
- package/dist/__tests__/unit/context.test.d.ts.map +0 -1
- package/dist/__tests__/unit/context.test.js +0 -220
- package/dist/__tests__/unit/context.test.js.map +0 -1
- package/dist/__tests__/unit/decorators.test.d.ts +0 -2
- package/dist/__tests__/unit/decorators.test.d.ts.map +0 -1
- package/dist/__tests__/unit/decorators.test.js +0 -162
- package/dist/__tests__/unit/decorators.test.js.map +0 -1
- package/dist/__tests__/unit/introspection-tools.test.d.ts +0 -5
- package/dist/__tests__/unit/introspection-tools.test.d.ts.map +0 -1
- package/dist/__tests__/unit/introspection-tools.test.js +0 -191
- package/dist/__tests__/unit/introspection-tools.test.js.map +0 -1
- package/dist/__tests__/unit/logger.test.d.ts +0 -2
- package/dist/__tests__/unit/logger.test.d.ts.map +0 -1
- package/dist/__tests__/unit/logger.test.js +0 -241
- package/dist/__tests__/unit/logger.test.js.map +0 -1
- package/dist/__tests__/unit/observable.test.d.ts +0 -2
- package/dist/__tests__/unit/observable.test.d.ts.map +0 -1
- package/dist/__tests__/unit/observable.test.js +0 -251
- package/dist/__tests__/unit/observable.test.js.map +0 -1
- package/dist/__tests__/unit/prompt.test.d.ts +0 -2
- package/dist/__tests__/unit/prompt.test.d.ts.map +0 -1
- package/dist/__tests__/unit/prompt.test.js +0 -113
- package/dist/__tests__/unit/prompt.test.js.map +0 -1
- package/dist/__tests__/unit/reflection.test.d.ts +0 -5
- package/dist/__tests__/unit/reflection.test.d.ts.map +0 -1
- package/dist/__tests__/unit/reflection.test.js +0 -160
- package/dist/__tests__/unit/reflection.test.js.map +0 -1
- package/dist/__tests__/unit/tree-debugger-incremental.test.d.ts +0 -2
- package/dist/__tests__/unit/tree-debugger-incremental.test.d.ts.map +0 -1
- package/dist/__tests__/unit/tree-debugger-incremental.test.js +0 -136
- package/dist/__tests__/unit/tree-debugger-incremental.test.js.map +0 -1
- package/dist/__tests__/unit/tree-debugger.test.d.ts +0 -2
- package/dist/__tests__/unit/tree-debugger.test.d.ts.map +0 -1
- package/dist/__tests__/unit/tree-debugger.test.js +0 -69
- package/dist/__tests__/unit/tree-debugger.test.js.map +0 -1
- package/dist/__tests__/unit/utils/workflow-error-utils.test.d.ts +0 -2
- package/dist/__tests__/unit/utils/workflow-error-utils.test.d.ts.map +0 -1
- package/dist/__tests__/unit/utils/workflow-error-utils.test.js +0 -154
- package/dist/__tests__/unit/utils/workflow-error-utils.test.js.map +0 -1
- package/dist/__tests__/unit/workflow-detachChild.test.d.ts +0 -2
- package/dist/__tests__/unit/workflow-detachChild.test.d.ts.map +0 -1
- package/dist/__tests__/unit/workflow-detachChild.test.js +0 -76
- package/dist/__tests__/unit/workflow-detachChild.test.js.map +0 -1
- package/dist/__tests__/unit/workflow-emitEvent-childDetached.test.d.ts +0 -2
- package/dist/__tests__/unit/workflow-emitEvent-childDetached.test.d.ts.map +0 -1
- package/dist/__tests__/unit/workflow-emitEvent-childDetached.test.js +0 -122
- package/dist/__tests__/unit/workflow-emitEvent-childDetached.test.js.map +0 -1
- package/dist/__tests__/unit/workflow-isDescendantOf.test.d.ts +0 -2
- package/dist/__tests__/unit/workflow-isDescendantOf.test.d.ts.map +0 -1
- package/dist/__tests__/unit/workflow-isDescendantOf.test.js +0 -140
- package/dist/__tests__/unit/workflow-isDescendantOf.test.js.map +0 -1
- package/dist/__tests__/unit/workflow.test.d.ts +0 -2
- package/dist/__tests__/unit/workflow.test.d.ts.map +0 -1
- package/dist/__tests__/unit/workflow.test.js +0 -330
- package/dist/__tests__/unit/workflow.test.js.map +0 -1
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// src/types/providers.ts — Backward-compatible deprecated alias shim (v1.2)
|
|
2
|
+
//
|
|
3
|
+
// Every Provider* symbol is either:
|
|
4
|
+
// Bucket A — @deprecated alias → structurally-identical Harness* counterpart (types/harnesses.ts)
|
|
5
|
+
// Bucket B — @deprecated superset union (ProviderId = HarnessId | legacy literals)
|
|
6
|
+
// Bucket C — KEPT CONCRETE (shape diverges or consumers depend on specifics)
|
|
7
|
+
//
|
|
8
|
+
// The ProviderResult family is already @deprecated → AgentResponse and is left byte-for-byte
|
|
9
|
+
// unchanged. ToolExecutionRequest / ToolExecutionResult are shared types re-exported from
|
|
10
|
+
// harnesses.ts (NOT renamed, NOT deprecated). ToolExecutor is a concrete util (not deprecated).
|
|
11
|
+
//
|
|
12
|
+
// NO runtime code. NO edits to any consumer file.
|
|
13
|
+
export {};
|
|
14
|
+
//# sourceMappingURL=providers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"providers.js","sourceRoot":"","sources":["../../src/types/providers.ts"],"names":[],"mappings":"AAAA,4EAA4E;AAC5E,EAAE;AACF,oCAAoC;AACpC,oGAAoG;AACpG,qFAAqF;AACrF,+EAA+E;AAC/E,EAAE;AACF,6FAA6F;AAC7F,2FAA2F;AAC3F,iGAAiG;AACjG,EAAE;AACF,mDAAmD"}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import type { WorkflowError } from './error.js';
|
|
2
|
+
/**
|
|
3
|
+
* Restart analysis result
|
|
4
|
+
*
|
|
5
|
+
* Provides error classification and restart recommendations for step retry logic.
|
|
6
|
+
* This interface encapsulates the decision-making process for determining whether
|
|
7
|
+
* a failed step should be retried, aborted, or require plan rebuilding.
|
|
8
|
+
*
|
|
9
|
+
* **Probability Interpretation**:
|
|
10
|
+
* - `0.0 - 0.3`: Low success probability - consider abort or rebuild
|
|
11
|
+
* - `0.4 - 0.6`: Moderate probability - retry with caution
|
|
12
|
+
* - `0.7 - 1.0`: High probability - safe to retry
|
|
13
|
+
*
|
|
14
|
+
* @example Transient error - safe to retry
|
|
15
|
+
* ```ts
|
|
16
|
+
* const analysis: RestartAnalysis = {
|
|
17
|
+
* shouldRestart: true,
|
|
18
|
+
* reason: 'Network timeout - likely transient',
|
|
19
|
+
* suggestedAction: 'retry',
|
|
20
|
+
* estimatedSuccessProbability: 0.8
|
|
21
|
+
* };
|
|
22
|
+
* ```
|
|
23
|
+
*
|
|
24
|
+
* @example Permanent error - should abort
|
|
25
|
+
* ```ts
|
|
26
|
+
* const analysis: RestartAnalysis = {
|
|
27
|
+
* shouldRestart: false,
|
|
28
|
+
* reason: 'Invalid API key - authentication will never succeed',
|
|
29
|
+
* suggestedAction: 'abort',
|
|
30
|
+
* estimatedSuccessProbability: 0.0
|
|
31
|
+
* };
|
|
32
|
+
* ```
|
|
33
|
+
*
|
|
34
|
+
* @example Recoverable but requires intervention
|
|
35
|
+
* ```ts
|
|
36
|
+
* const analysis: RestartAnalysis = {
|
|
37
|
+
* shouldRestart: true,
|
|
38
|
+
* reason: 'Rate limit exceeded - retry after backoff',
|
|
39
|
+
* suggestedAction: 'retry',
|
|
40
|
+
* estimatedSuccessProbability: 0.6
|
|
41
|
+
* };
|
|
42
|
+
* ```
|
|
43
|
+
*
|
|
44
|
+
* @see {@link ErrorCriterion} - For defining error matching criteria
|
|
45
|
+
* @remarks Used in stepRetry events and error analysis utilities
|
|
46
|
+
*/
|
|
47
|
+
export interface RestartAnalysis {
|
|
48
|
+
/** Whether the step should be restarted */
|
|
49
|
+
shouldRestart: boolean;
|
|
50
|
+
/** Human-readable reason for the restart decision */
|
|
51
|
+
reason: string;
|
|
52
|
+
/** Suggested action to take */
|
|
53
|
+
suggestedAction: 'retry' | 'abort' | 'rebuild';
|
|
54
|
+
/** Estimated probability of success (0-1) */
|
|
55
|
+
estimatedSuccessProbability: number;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Error matching criterion for step restart decisions
|
|
59
|
+
*
|
|
60
|
+
* Supports three patterns for error matching:
|
|
61
|
+
* 1. **By error code** - Exact string match or regex pattern matching
|
|
62
|
+
* 2. **By recoverable flag** - Match recoverable vs non-recoverable errors
|
|
63
|
+
* 3. **Custom predicate** - Function for complex matching logic
|
|
64
|
+
*
|
|
65
|
+
* @example Match by exact error code
|
|
66
|
+
* ```ts
|
|
67
|
+
* const criterion: ErrorCriterion = { code: 'RATE_LIMIT_EXCEEDED' };
|
|
68
|
+
* ```
|
|
69
|
+
*
|
|
70
|
+
* @example Match by regex pattern
|
|
71
|
+
* ```ts
|
|
72
|
+
* const criterion: ErrorCriterion = { code: /TIMEOUT|NETWORK_ERROR/ };
|
|
73
|
+
* ```
|
|
74
|
+
*
|
|
75
|
+
* @example Match by recoverable flag
|
|
76
|
+
* ```ts
|
|
77
|
+
* const criterion: ErrorCriterion = { recoverable: true };
|
|
78
|
+
* ```
|
|
79
|
+
*
|
|
80
|
+
* @example Custom predicate with complex logic
|
|
81
|
+
* ```ts
|
|
82
|
+
* const criterion: ErrorCriterion = (error) => {
|
|
83
|
+
* const isTemporary = error.message.includes('temporary');
|
|
84
|
+
* const isTimeout = error.code === 'TIMEOUT';
|
|
85
|
+
* const hasRetryableStatus = error.original?.status >= 500;
|
|
86
|
+
* return isTemporary || isTimeout || hasRetryableStatus;
|
|
87
|
+
* };
|
|
88
|
+
* ```
|
|
89
|
+
*
|
|
90
|
+
* @remarks
|
|
91
|
+
* **IMPORTANT**: Function types must come last in the discriminated union for proper
|
|
92
|
+
* TypeScript type narrowing. When checking criteria at runtime, always check
|
|
93
|
+
* `typeof criterion === 'function'` first before discriminant property checks.
|
|
94
|
+
*
|
|
95
|
+
* **Why functions must be last**:
|
|
96
|
+
* In JavaScript, functions can have properties. If a function has a `code` property,
|
|
97
|
+
* the discriminant check `'code' in criterion` would return `true`, causing TypeScript
|
|
98
|
+
* to incorrectly narrow the type. By placing functions last and checking them first
|
|
99
|
+
* at runtime, we ensure type safety.
|
|
100
|
+
*
|
|
101
|
+
* **Runtime checking pattern**:
|
|
102
|
+
* ```ts
|
|
103
|
+
* function matchesCriterion(
|
|
104
|
+
* criterion: ErrorCriterion,
|
|
105
|
+
* error: WorkflowError
|
|
106
|
+
* ): boolean {
|
|
107
|
+
* // Check function FIRST
|
|
108
|
+
* if (typeof criterion === 'function') {
|
|
109
|
+
* return criterion(error);
|
|
110
|
+
* }
|
|
111
|
+
* // Now safe to use discriminant checks
|
|
112
|
+
* if ('code' in criterion) {
|
|
113
|
+
* const codeMatch = criterion.code instanceof RegExp
|
|
114
|
+
* ? criterion.code.test(error.code || '')
|
|
115
|
+
* : error.code === criterion.code;
|
|
116
|
+
* return codeMatch;
|
|
117
|
+
* }
|
|
118
|
+
* if ('recoverable' in criterion) {
|
|
119
|
+
* return error.original?.recoverable === criterion.recoverable;
|
|
120
|
+
* }
|
|
121
|
+
* return false;
|
|
122
|
+
* }
|
|
123
|
+
* ```
|
|
124
|
+
*
|
|
125
|
+
* @see {@link RestartAnalysis} - For restart decision result type
|
|
126
|
+
*/
|
|
127
|
+
export type ErrorCriterion = {
|
|
128
|
+
code: string | RegExp;
|
|
129
|
+
} | {
|
|
130
|
+
recoverable: boolean;
|
|
131
|
+
} | ((error: WorkflowError) => boolean);
|
|
132
|
+
//# sourceMappingURL=restart.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"restart.d.ts","sourceRoot":"","sources":["../../src/types/restart.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAEhD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4CG;AACH,MAAM,WAAW,eAAe;IAC9B,2CAA2C;IAC3C,aAAa,EAAE,OAAO,CAAC;IAEvB,qDAAqD;IACrD,MAAM,EAAE,MAAM,CAAC;IAEf,+BAA+B;IAC/B,eAAe,EAAE,OAAO,GAAG,OAAO,GAAG,SAAS,CAAC;IAE/C,6CAA6C;IAC7C,2BAA2B,EAAE,MAAM,CAAC;CACrC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqEG;AACH,MAAM,MAAM,cAAc,GACtB;IAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAAA;CAAE,GACzB;IAAE,WAAW,EAAE,OAAO,CAAA;CAAE,GACxB,CAAC,CAAC,KAAK,EAAE,aAAa,KAAK,OAAO,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"restart.js","sourceRoot":"","sources":["../../src/types/restart.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Streaming types for LLM streaming responses
|
|
3
|
+
*
|
|
4
|
+
* Provides types and utilities for streaming responses from LLM providers.
|
|
5
|
+
* Uses TypeScript's built-in AsyncGenerator for efficient streaming.
|
|
6
|
+
*/
|
|
7
|
+
import type { AgentResponse } from './agent.js';
|
|
8
|
+
/**
|
|
9
|
+
* Stream event types for LLM streaming responses
|
|
10
|
+
*
|
|
11
|
+
* Discriminated union for type-safe event handling during streaming.
|
|
12
|
+
* Each event type has a unique `type` field for TypeScript narrowing.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```ts
|
|
16
|
+
* for await (const event of streamResult.stream) {
|
|
17
|
+
* switch (event.type) {
|
|
18
|
+
* case 'text_delta':
|
|
19
|
+
* console.log(event.delta); // Type-safe access to delta
|
|
20
|
+
* break;
|
|
21
|
+
* case 'tool_call_start':
|
|
22
|
+
* console.log(event.name); // Type-safe access to name
|
|
23
|
+
* break;
|
|
24
|
+
* }
|
|
25
|
+
* }
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
export type StreamEvent = {
|
|
29
|
+
type: 'text_delta';
|
|
30
|
+
delta: string;
|
|
31
|
+
index: number;
|
|
32
|
+
} | {
|
|
33
|
+
type: 'text_done';
|
|
34
|
+
text: string;
|
|
35
|
+
index: number;
|
|
36
|
+
} | {
|
|
37
|
+
type: 'tool_call_start';
|
|
38
|
+
id: string;
|
|
39
|
+
name: string;
|
|
40
|
+
index: number;
|
|
41
|
+
} | {
|
|
42
|
+
type: 'tool_call_delta';
|
|
43
|
+
id: string;
|
|
44
|
+
input: Record<string, unknown>;
|
|
45
|
+
} | {
|
|
46
|
+
type: 'tool_call_done';
|
|
47
|
+
id: string;
|
|
48
|
+
result: unknown;
|
|
49
|
+
} | {
|
|
50
|
+
type: 'metadata';
|
|
51
|
+
metadata: {
|
|
52
|
+
requestId?: string;
|
|
53
|
+
model?: string;
|
|
54
|
+
provider: string;
|
|
55
|
+
};
|
|
56
|
+
} | {
|
|
57
|
+
type: 'usage';
|
|
58
|
+
inputTokens: number;
|
|
59
|
+
outputTokens: number;
|
|
60
|
+
cacheTokens?: number;
|
|
61
|
+
} | {
|
|
62
|
+
type: 'done';
|
|
63
|
+
finishReason: 'stop' | 'length' | 'tool_calls' | 'error';
|
|
64
|
+
} | {
|
|
65
|
+
type: 'error';
|
|
66
|
+
error: Error;
|
|
67
|
+
code?: string;
|
|
68
|
+
retryable?: boolean;
|
|
69
|
+
};
|
|
70
|
+
/**
|
|
71
|
+
* AsyncStream interface for streaming responses
|
|
72
|
+
*
|
|
73
|
+
* Wraps AsyncGenerator with additional metadata and cancellation support.
|
|
74
|
+
* Designed for for-await...of consumption.
|
|
75
|
+
*
|
|
76
|
+
* @template T - The type of the final response data (from AsyncGenerator return)
|
|
77
|
+
*
|
|
78
|
+
* @example
|
|
79
|
+
* ```ts
|
|
80
|
+
* const streamResult = agent.stream(prompt);
|
|
81
|
+
*
|
|
82
|
+
* for await (const event of streamResult.stream) {
|
|
83
|
+
* if (event.type === 'text_delta') {
|
|
84
|
+
* process.stdout.write(event.delta);
|
|
85
|
+
* }
|
|
86
|
+
* }
|
|
87
|
+
*
|
|
88
|
+
* // Cancel stream if needed
|
|
89
|
+
* streamResult.controller?.abort();
|
|
90
|
+
* ```
|
|
91
|
+
*/
|
|
92
|
+
export interface AsyncStream<T> {
|
|
93
|
+
/**
|
|
94
|
+
* Async generator yielding stream events
|
|
95
|
+
*
|
|
96
|
+
* Consume with for await...of loop. The generator yields StreamEvent
|
|
97
|
+
* objects and returns the final AgentResponse<T> when complete.
|
|
98
|
+
*
|
|
99
|
+
* @example
|
|
100
|
+
* ```ts
|
|
101
|
+
* for await (const event of streamResult.stream) {
|
|
102
|
+
* switch (event.type) {
|
|
103
|
+
* case 'text_delta':
|
|
104
|
+
* console.log(event.delta);
|
|
105
|
+
* break;
|
|
106
|
+
* case 'done':
|
|
107
|
+
* console.log('Complete!');
|
|
108
|
+
* break;
|
|
109
|
+
* }
|
|
110
|
+
* }
|
|
111
|
+
* ```
|
|
112
|
+
*/
|
|
113
|
+
stream: AsyncGenerator<StreamEvent, AgentResponse<T>, unknown>;
|
|
114
|
+
/**
|
|
115
|
+
* Optional abort controller for cancellation
|
|
116
|
+
*
|
|
117
|
+
* Use to cancel an in-progress stream. The stream generator should
|
|
118
|
+
* check controller.signal.aborted and yield an error event or break.
|
|
119
|
+
*
|
|
120
|
+
* @example
|
|
121
|
+
* ```ts
|
|
122
|
+
* let eventCount = 0;
|
|
123
|
+
* for await (const event of streamResult.stream) {
|
|
124
|
+
* eventCount++;
|
|
125
|
+
* if (eventCount >= 10) {
|
|
126
|
+
* streamResult.controller?.abort();
|
|
127
|
+
* break;
|
|
128
|
+
* }
|
|
129
|
+
* }
|
|
130
|
+
* ```
|
|
131
|
+
*/
|
|
132
|
+
controller?: AbortController;
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Type guard for text delta events
|
|
136
|
+
*
|
|
137
|
+
* Narrows StreamEvent to text_delta type for type-safe access.
|
|
138
|
+
*
|
|
139
|
+
* @param event - The stream event to check
|
|
140
|
+
* @returns True if the event is a text_delta event
|
|
141
|
+
*
|
|
142
|
+
* @example
|
|
143
|
+
* ```ts
|
|
144
|
+
* if (isTextDeltaEvent(event)) {
|
|
145
|
+
* console.log(event.delta); // TypeScript knows delta exists
|
|
146
|
+
* console.log(event.index); // TypeScript knows index exists
|
|
147
|
+
* }
|
|
148
|
+
* ```
|
|
149
|
+
*/
|
|
150
|
+
export declare function isTextDeltaEvent(event: StreamEvent): event is Extract<StreamEvent, {
|
|
151
|
+
type: 'text_delta';
|
|
152
|
+
}>;
|
|
153
|
+
/**
|
|
154
|
+
* Type guard for tool call events
|
|
155
|
+
*
|
|
156
|
+
* Narrows StreamEvent to any tool call event type for type-safe access.
|
|
157
|
+
*
|
|
158
|
+
* @param event - The stream event to check
|
|
159
|
+
* @returns True if the event is a tool_call_start, tool_call_delta, or tool_call_done event
|
|
160
|
+
*
|
|
161
|
+
* @example
|
|
162
|
+
* ```ts
|
|
163
|
+
* if (isToolCallEvent(event)) {
|
|
164
|
+
* if (event.type === 'tool_call_start') {
|
|
165
|
+
* console.log(event.name); // TypeScript knows name exists
|
|
166
|
+
* }
|
|
167
|
+
* }
|
|
168
|
+
* ```
|
|
169
|
+
*/
|
|
170
|
+
export declare function isToolCallEvent(event: StreamEvent): event is Extract<StreamEvent, {
|
|
171
|
+
type: 'tool_call_start' | 'tool_call_delta' | 'tool_call_done';
|
|
172
|
+
}>;
|
|
173
|
+
/**
|
|
174
|
+
* Type guard for error events
|
|
175
|
+
*
|
|
176
|
+
* Narrows StreamEvent to error type for type-safe access.
|
|
177
|
+
*
|
|
178
|
+
* @param event - The stream event to check
|
|
179
|
+
* @returns True if the event is an error event
|
|
180
|
+
*
|
|
181
|
+
* @example
|
|
182
|
+
* ```ts
|
|
183
|
+
* if (isErrorEvent(event)) {
|
|
184
|
+
* console.error(event.error.message); // TypeScript knows error exists
|
|
185
|
+
* if (event.retryable) {
|
|
186
|
+
* // Retry logic
|
|
187
|
+
* }
|
|
188
|
+
* }
|
|
189
|
+
* ```
|
|
190
|
+
*/
|
|
191
|
+
export declare function isErrorEvent(event: StreamEvent): event is Extract<StreamEvent, {
|
|
192
|
+
type: 'error';
|
|
193
|
+
}>;
|
|
194
|
+
//# sourceMappingURL=streaming.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"streaming.d.ts","sourceRoot":"","sources":["../../src/types/streaming.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAEhD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,MAAM,WAAW,GAEnB;IAAE,IAAI,EAAE,YAAY,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GACpD;IAAE,IAAI,EAAE,WAAW,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GAGlD;IAAE,IAAI,EAAE,iBAAiB,CAAC;IAAC,EAAE,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GACpE;IAAE,IAAI,EAAE,iBAAiB,CAAC;IAAC,EAAE,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CAAE,GACvE;IAAE,IAAI,EAAE,gBAAgB,CAAC;IAAC,EAAE,EAAE,MAAM,CAAC;IAAC,MA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C,CAErJ;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,WAAW,GAAG,KAAK,IAAI,OAAO,CAAC,WAAW,EAAE;IAAE,IAAI,EAAE,OAAO,CAAA;CAAE,CAAC,CAEjG"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Streaming types for LLM streaming responses
|
|
3
|
+
*
|
|
4
|
+
* Provides types and utilities for streaming responses from LLM providers.
|
|
5
|
+
* Uses TypeScript's built-in AsyncGenerator for efficient streaming.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Type guard for text delta events
|
|
9
|
+
*
|
|
10
|
+
* Narrows StreamEvent to text_delta type for type-safe access.
|
|
11
|
+
*
|
|
12
|
+
* @param event - The stream event to check
|
|
13
|
+
* @returns True if the event is a text_delta event
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```ts
|
|
17
|
+
* if (isTextDeltaEvent(event)) {
|
|
18
|
+
* console.log(event.delta); // TypeScript knows delta exists
|
|
19
|
+
* console.log(event.index); // TypeScript knows index exists
|
|
20
|
+
* }
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
export function isTextDeltaEvent(event) {
|
|
24
|
+
return event.type === 'text_delta';
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Type guard for tool call events
|
|
28
|
+
*
|
|
29
|
+
* Narrows StreamEvent to any tool call event type for type-safe access.
|
|
30
|
+
*
|
|
31
|
+
* @param event - The stream event to check
|
|
32
|
+
* @returns True if the event is a tool_call_start, tool_call_delta, or tool_call_done event
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* ```ts
|
|
36
|
+
* if (isToolCallEvent(event)) {
|
|
37
|
+
* if (event.type === 'tool_call_start') {
|
|
38
|
+
* console.log(event.name); // TypeScript knows name exists
|
|
39
|
+
* }
|
|
40
|
+
* }
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
export function isToolCallEvent(event) {
|
|
44
|
+
return event.type === 'tool_call_start' || event.type === 'tool_call_delta' || event.type === 'tool_call_done';
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Type guard for error events
|
|
48
|
+
*
|
|
49
|
+
* Narrows StreamEvent to error type for type-safe access.
|
|
50
|
+
*
|
|
51
|
+
* @param event - The stream event to check
|
|
52
|
+
* @returns True if the event is an error event
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* ```ts
|
|
56
|
+
* if (isErrorEvent(event)) {
|
|
57
|
+
* console.error(event.error.message); // TypeScript knows error exists
|
|
58
|
+
* if (event.retryable) {
|
|
59
|
+
* // Retry logic
|
|
60
|
+
* }
|
|
61
|
+
* }
|
|
62
|
+
* ```
|
|
63
|
+
*/
|
|
64
|
+
export function isErrorEvent(event) {
|
|
65
|
+
return event.type === 'error';
|
|
66
|
+
}
|
|
67
|
+
//# sourceMappingURL=streaming.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"streaming.js","sourceRoot":"","sources":["../../src/types/streaming.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAgHH;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,gBAAgB,CAAC,KAAkB;IACjD,OAAO,KAAK,CAAC,IAAI,KAAK,YAAY,CAAC;AACrC,CAAC;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,eAAe,CAAC,KAAkB;IAChD,OAAO,KAAK,CAAC,IAAI,KAAK,iBAAiB,IAAI,KAAK,CAAC,IAAI,KAAK,iBAAiB,IAAI,KAAK,CAAC,IAAI,KAAK,gBAAgB,CAAC;AACjH,CAAC;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,UAAU,YAAY,CAAC,KAAkB;IAC7C,OAAO,KAAK,CAAC,IAAI,KAAK,OAAO,CAAC;AAChC,CAAC"}
|
|
@@ -6,6 +6,8 @@
|
|
|
6
6
|
*/
|
|
7
7
|
import type { WorkflowNode } from './workflow.js';
|
|
8
8
|
import type { ReflectionAPI } from './reflection.js';
|
|
9
|
+
import type { AgentResponse } from './agent.js';
|
|
10
|
+
import type { ErrorMergeStrategy } from './error-strategy.js';
|
|
9
11
|
export type { ReflectionAPI } from './reflection.js';
|
|
10
12
|
/**
|
|
11
13
|
* Handle for querying the event tree
|
|
@@ -61,7 +63,7 @@ export interface EventMetrics {
|
|
|
61
63
|
* Agent interface for context revision (minimal to avoid circular deps)
|
|
62
64
|
*/
|
|
63
65
|
export interface AgentLike {
|
|
64
|
-
prompt<T>(prompt: PromptLike<T>): Promise<T
|
|
66
|
+
prompt<T>(prompt: PromptLike<T>): Promise<AgentResponse<T>>;
|
|
65
67
|
}
|
|
66
68
|
/**
|
|
67
69
|
* Prompt interface for context revision (minimal to avoid circular deps)
|
|
@@ -116,6 +118,74 @@ export interface WorkflowContext {
|
|
|
116
118
|
*/
|
|
117
119
|
readonly reflection: ReflectionAPI;
|
|
118
120
|
}
|
|
121
|
+
/**
|
|
122
|
+
* Event history configuration for workflow execution
|
|
123
|
+
*
|
|
124
|
+
* @remarks
|
|
125
|
+
* When enabled, events are stored in memory and can be accessed via
|
|
126
|
+
* the workflow's replay functionality. Events include step execution,
|
|
127
|
+
* errors, agent prompts, tool invocations, and state changes.
|
|
128
|
+
*
|
|
129
|
+
* **Memory Management:**
|
|
130
|
+
* - Events are trimmed based on both count (`maxEvents`) and age (`maxAgeMs`)
|
|
131
|
+
* - Lazy trimming is used for performance (only trims when significantly over limit)
|
|
132
|
+
* - When disabled, no events are stored in history (still emitted to observers)
|
|
133
|
+
*
|
|
134
|
+
* **Performance Impact:**
|
|
135
|
+
* - Enabled: Minimal overhead (~1-2ms per event)
|
|
136
|
+
* - Disabled: Zero overhead
|
|
137
|
+
*
|
|
138
|
+
* @example Enable event history with defaults
|
|
139
|
+
* ```ts
|
|
140
|
+
* const config: WorkflowConfig = {
|
|
141
|
+
* name: 'MyWorkflow',
|
|
142
|
+
* eventHistory: { enabled: true }
|
|
143
|
+
* };
|
|
144
|
+
* ```
|
|
145
|
+
*
|
|
146
|
+
* @example Custom limits
|
|
147
|
+
* ```ts
|
|
148
|
+
* const config: WorkflowConfig = {
|
|
149
|
+
* name: 'MyWorkflow',
|
|
150
|
+
* eventHistory: {
|
|
151
|
+
* enabled: true,
|
|
152
|
+
* maxEvents: 500,
|
|
153
|
+
* maxAgeMs: 1800000 // 30 minutes
|
|
154
|
+
* }
|
|
155
|
+
* };
|
|
156
|
+
* ```
|
|
157
|
+
*/
|
|
158
|
+
export interface EventHistoryConfig {
|
|
159
|
+
/**
|
|
160
|
+
* Enable event history collection
|
|
161
|
+
*
|
|
162
|
+
* When false (default), no events are stored in history.
|
|
163
|
+
* Events are still emitted to observers in real-time.
|
|
164
|
+
*
|
|
165
|
+
* @default false
|
|
166
|
+
*/
|
|
167
|
+
enabled?: boolean;
|
|
168
|
+
/**
|
|
169
|
+
* Maximum number of events to store in history
|
|
170
|
+
*
|
|
171
|
+
* When the limit is exceeded, oldest events are removed first.
|
|
172
|
+
* Uses lazy trimming for performance (trims at 1.5x the limit).
|
|
173
|
+
*
|
|
174
|
+
* @default 1000
|
|
175
|
+
* @minimum 1
|
|
176
|
+
*/
|
|
177
|
+
maxEvents?: number;
|
|
178
|
+
/**
|
|
179
|
+
* Maximum age of events in milliseconds
|
|
180
|
+
*
|
|
181
|
+
* Events older than this are removed from history.
|
|
182
|
+
* Age is based on insertion time, not event timestamp.
|
|
183
|
+
*
|
|
184
|
+
* @default 3600000 (1 hour)
|
|
185
|
+
* @minimum 1000 (1 second)
|
|
186
|
+
*/
|
|
187
|
+
maxAgeMs?: number;
|
|
188
|
+
}
|
|
119
189
|
/**
|
|
120
190
|
* Configuration for creating a functional workflow
|
|
121
191
|
*/
|
|
@@ -124,6 +194,72 @@ export interface WorkflowConfig {
|
|
|
124
194
|
name?: string;
|
|
125
195
|
/** Enable reflection for this workflow */
|
|
126
196
|
enableReflection?: boolean;
|
|
197
|
+
/** Automatically validate AgentResponse results after agent.prompt() calls */
|
|
198
|
+
autoValidateResponses?: boolean;
|
|
199
|
+
/**
|
|
200
|
+
* Event history configuration
|
|
201
|
+
*
|
|
202
|
+
* @remarks
|
|
203
|
+
* Controls whether events are stored in memory for replay functionality.
|
|
204
|
+
* When disabled (default), events are still emitted to observers but not
|
|
205
|
+
* stored in the internal event history array.
|
|
206
|
+
*
|
|
207
|
+
* @example Enable with defaults
|
|
208
|
+
* ```ts
|
|
209
|
+
* const config: WorkflowConfig = {
|
|
210
|
+
* name: 'MyWorkflow',
|
|
211
|
+
* eventHistory: { enabled: true }
|
|
212
|
+
* };
|
|
213
|
+
* ```
|
|
214
|
+
*
|
|
215
|
+
* @example Custom limits
|
|
216
|
+
* ```ts
|
|
217
|
+
* const config: WorkflowConfig = {
|
|
218
|
+
* name: 'MyWorkflow',
|
|
219
|
+
* eventHistory: {
|
|
220
|
+
* enabled: true,
|
|
221
|
+
* maxEvents: 500,
|
|
222
|
+
* maxAgeMs: 1800000
|
|
223
|
+
* }
|
|
224
|
+
* };
|
|
225
|
+
* ```
|
|
226
|
+
*/
|
|
227
|
+
eventHistory?: EventHistoryConfig;
|
|
228
|
+
/**
|
|
229
|
+
* Strategy for merging multiple errors
|
|
230
|
+
*
|
|
231
|
+
* @remarks
|
|
232
|
+
* When provided, enables workflow-level error merge for multiple failures.
|
|
233
|
+
* Default: undefined (first error wins behavior).
|
|
234
|
+
*
|
|
235
|
+
* @example
|
|
236
|
+
* ```ts
|
|
237
|
+
* // Enable error merging with default strategy
|
|
238
|
+
* const config: WorkflowConfig = {
|
|
239
|
+
* name: 'MyWorkflow',
|
|
240
|
+
* errorMergeStrategy: { enabled: true }
|
|
241
|
+
* };
|
|
242
|
+
*
|
|
243
|
+
* // Enable with custom combine function
|
|
244
|
+
* const config: WorkflowConfig = {
|
|
245
|
+
* name: 'MyWorkflow',
|
|
246
|
+
* errorMergeStrategy: {
|
|
247
|
+
* enabled: true,
|
|
248
|
+
* combine: (errors) => ({
|
|
249
|
+
* message: `Custom: ${errors.length} failures`,
|
|
250
|
+
* // ... custom error object
|
|
251
|
+
* })
|
|
252
|
+
* }
|
|
253
|
+
* };
|
|
254
|
+
*
|
|
255
|
+
* // Default behavior (first error wins)
|
|
256
|
+
* const config: WorkflowConfig = {
|
|
257
|
+
* name: 'MyWorkflow'
|
|
258
|
+
* // errorMergeStrategy not provided = first error wins
|
|
259
|
+
* };
|
|
260
|
+
* ```
|
|
261
|
+
*/
|
|
262
|
+
errorMergeStrategy?: ErrorMergeStrategy;
|
|
127
263
|
}
|
|
128
264
|
/**
|
|
129
265
|
* Result from workflow execution
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"workflow-context.d.ts","sourceRoot":"","sources":["../../src/types/workflow-context.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAClD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"workflow-context.d.ts","sourceRoot":"","sources":["../../src/types/workflow-context.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAClD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AACrD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAChD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAG9D,YAAY,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAErD;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,kCAAkC;IAClC,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC;IAEzB;;;OAGG;IACH,OAAO,CAAC,EAAE,EAAE,MAAM,GAAG,SAAS,GAAG,SAAS,CAAC;IAE3C;;;OAGG;IACH,WAAW,CAAC,EAAE,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