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,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Agent response validation utilities
|
|
3
|
+
*
|
|
4
|
+
* Provides pure, side-effect-free functions for validating AgentResponse
|
|
5
|
+
* instances using Zod schemas. The utilities enable both Agent and Workflow
|
|
6
|
+
* classes to perform validation without duplicating code.
|
|
7
|
+
*
|
|
8
|
+
* @module agent-validation
|
|
9
|
+
*/
|
|
10
|
+
import type { AgentResponse } from '../types/agent.js';
|
|
11
|
+
import { z } from 'zod';
|
|
12
|
+
/**
|
|
13
|
+
* Validation result type for agent response validation
|
|
14
|
+
*
|
|
15
|
+
* Provides structured validation result with boolean validity flag
|
|
16
|
+
* and optional ZodError for detailed error information.
|
|
17
|
+
*/
|
|
18
|
+
export interface ValidationResult {
|
|
19
|
+
/** Whether the response is valid according to the schema */
|
|
20
|
+
valid: boolean;
|
|
21
|
+
/** Zod validation errors (present when valid is false) */
|
|
22
|
+
errors?: z.ZodError;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Validate an AgentResponse against a Zod schema
|
|
26
|
+
*
|
|
27
|
+
* This is a pure, side-effect-free function that validates AgentResponse
|
|
28
|
+
* instances using Zod schemas. It returns a structured ValidationResult
|
|
29
|
+
* with validity flag and optional error details.
|
|
30
|
+
*
|
|
31
|
+
* **Validation Flow:**
|
|
32
|
+
* 1. Create AgentResponseSchema using provided dataSchema
|
|
33
|
+
* 2. Call schema.safeParse(response) for non-throwing validation
|
|
34
|
+
* 3. Return { valid: true } if validation succeeds
|
|
35
|
+
* 4. Return { valid: false, errors: ZodError } if validation fails
|
|
36
|
+
*
|
|
37
|
+
* **Pure Function Guarantee:**
|
|
38
|
+
* - Deterministic: Same input always produces same output
|
|
39
|
+
* - No side effects: Doesn't modify inputs, emit events, or log
|
|
40
|
+
* - No external dependencies: Doesn't use Date.now(), Math.random(), etc.
|
|
41
|
+
*
|
|
42
|
+
* @template T - The type of response data
|
|
43
|
+
* @param response - The AgentResponse to validate
|
|
44
|
+
* @param dataSchema - The Zod schema for the response data (defaults to z.unknown())
|
|
45
|
+
* @returns Structured validation result with validity flag and optional errors
|
|
46
|
+
*
|
|
47
|
+
* @example Valid response
|
|
48
|
+
* ```ts
|
|
49
|
+
* const response: AgentResponse<string> = {
|
|
50
|
+
* status: 'success',
|
|
51
|
+
* data: 'Hello, World!',
|
|
52
|
+
* error: null,
|
|
53
|
+
* metadata: { agentId: 'agent-123', timestamp: Date.now() }
|
|
54
|
+
* };
|
|
55
|
+
*
|
|
56
|
+
* const result = validateAgentResponse(response);
|
|
57
|
+
* // Returns: { valid: true }
|
|
58
|
+
* ```
|
|
59
|
+
*
|
|
60
|
+
* @example Invalid response
|
|
61
|
+
* ```ts
|
|
62
|
+
* const response = {
|
|
63
|
+
* status: 'success',
|
|
64
|
+
* data: null, // Invalid: data should be string, not null
|
|
65
|
+
* error: null,
|
|
66
|
+
* metadata: { agentId: 'agent-123', timestamp: Date.now() }
|
|
67
|
+
* };
|
|
68
|
+
*
|
|
69
|
+
* const result = validateAgentResponse(response, z.string());
|
|
70
|
+
* // Returns: { valid: false, errors: ZodError }
|
|
71
|
+
* ```
|
|
72
|
+
*
|
|
73
|
+
* @remarks
|
|
74
|
+
* **Integration with Agent.validateResponse():**
|
|
75
|
+
* This utility is called by Agent.validateResponse() which adds:
|
|
76
|
+
* - console.error logging with agentId
|
|
77
|
+
* - INTERNAL_ERROR response creation on validation failure
|
|
78
|
+
*
|
|
79
|
+
* **Integration with Workflow.validateAgentResponse():**
|
|
80
|
+
* This utility is called by Workflow.validateAgentResponse() which adds:
|
|
81
|
+
* - invalidResponse event emission
|
|
82
|
+
* - WorkflowError creation with INVALID_RESPONSE_FORMAT context
|
|
83
|
+
*
|
|
84
|
+
* @see {@link AgentResponseSchema} - Schema factory used for validation
|
|
85
|
+
* @see {@link ValidationResult} - Return type structure
|
|
86
|
+
*/
|
|
87
|
+
export declare function validateAgentResponse<T>(response: AgentResponse<T>, dataSchema?: z.ZodTypeAny): ValidationResult;
|
|
88
|
+
//# sourceMappingURL=agent-validation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent-validation.d.ts","sourceRoot":"","sources":["../../src/utils/agent-validation.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAEvD,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB;;;;;GAKG;AACH,MAAM,WAAW,gBAAgB;IAC/B,4DAA4D;IAC5D,KAAK,EAAE,OAAO,CAAC;IACf,0DAA0D;IAC1D,MAAM,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC;CACrB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8DG;AACH,wBAAgB,qBAAqB,CAAC,CAAC,EACrC,QAAQ,EAAE,aAAa,CAAC,CAAC,CAAC,EAC1B,UAAU,GAAE,CAAC,CAAC,UAAwB,GACrC,gBAAgB,CAclB"}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Agent response validation utilities
|
|
3
|
+
*
|
|
4
|
+
* Provides pure, side-effect-free functions for validating AgentResponse
|
|
5
|
+
* instances using Zod schemas. The utilities enable both Agent and Workflow
|
|
6
|
+
* classes to perform validation without duplicating code.
|
|
7
|
+
*
|
|
8
|
+
* @module agent-validation
|
|
9
|
+
*/
|
|
10
|
+
import { AgentResponseSchema } from '../types/agent.js';
|
|
11
|
+
import { z } from 'zod';
|
|
12
|
+
/**
|
|
13
|
+
* Validate an AgentResponse against a Zod schema
|
|
14
|
+
*
|
|
15
|
+
* This is a pure, side-effect-free function that validates AgentResponse
|
|
16
|
+
* instances using Zod schemas. It returns a structured ValidationResult
|
|
17
|
+
* with validity flag and optional error details.
|
|
18
|
+
*
|
|
19
|
+
* **Validation Flow:**
|
|
20
|
+
* 1. Create AgentResponseSchema using provided dataSchema
|
|
21
|
+
* 2. Call schema.safeParse(response) for non-throwing validation
|
|
22
|
+
* 3. Return { valid: true } if validation succeeds
|
|
23
|
+
* 4. Return { valid: false, errors: ZodError } if validation fails
|
|
24
|
+
*
|
|
25
|
+
* **Pure Function Guarantee:**
|
|
26
|
+
* - Deterministic: Same input always produces same output
|
|
27
|
+
* - No side effects: Doesn't modify inputs, emit events, or log
|
|
28
|
+
* - No external dependencies: Doesn't use Date.now(), Math.random(), etc.
|
|
29
|
+
*
|
|
30
|
+
* @template T - The type of response data
|
|
31
|
+
* @param response - The AgentResponse to validate
|
|
32
|
+
* @param dataSchema - The Zod schema for the response data (defaults to z.unknown())
|
|
33
|
+
* @returns Structured validation result with validity flag and optional errors
|
|
34
|
+
*
|
|
35
|
+
* @example Valid response
|
|
36
|
+
* ```ts
|
|
37
|
+
* const response: AgentResponse<string> = {
|
|
38
|
+
* status: 'success',
|
|
39
|
+
* data: 'Hello, World!',
|
|
40
|
+
* error: null,
|
|
41
|
+
* metadata: { agentId: 'agent-123', timestamp: Date.now() }
|
|
42
|
+
* };
|
|
43
|
+
*
|
|
44
|
+
* const result = validateAgentResponse(response);
|
|
45
|
+
* // Returns: { valid: true }
|
|
46
|
+
* ```
|
|
47
|
+
*
|
|
48
|
+
* @example Invalid response
|
|
49
|
+
* ```ts
|
|
50
|
+
* const response = {
|
|
51
|
+
* status: 'success',
|
|
52
|
+
* data: null, // Invalid: data should be string, not null
|
|
53
|
+
* error: null,
|
|
54
|
+
* metadata: { agentId: 'agent-123', timestamp: Date.now() }
|
|
55
|
+
* };
|
|
56
|
+
*
|
|
57
|
+
* const result = validateAgentResponse(response, z.string());
|
|
58
|
+
* // Returns: { valid: false, errors: ZodError }
|
|
59
|
+
* ```
|
|
60
|
+
*
|
|
61
|
+
* @remarks
|
|
62
|
+
* **Integration with Agent.validateResponse():**
|
|
63
|
+
* This utility is called by Agent.validateResponse() which adds:
|
|
64
|
+
* - console.error logging with agentId
|
|
65
|
+
* - INTERNAL_ERROR response creation on validation failure
|
|
66
|
+
*
|
|
67
|
+
* **Integration with Workflow.validateAgentResponse():**
|
|
68
|
+
* This utility is called by Workflow.validateAgentResponse() which adds:
|
|
69
|
+
* - invalidResponse event emission
|
|
70
|
+
* - WorkflowError creation with INVALID_RESPONSE_FORMAT context
|
|
71
|
+
*
|
|
72
|
+
* @see {@link AgentResponseSchema} - Schema factory used for validation
|
|
73
|
+
* @see {@link ValidationResult} - Return type structure
|
|
74
|
+
*/
|
|
75
|
+
export function validateAgentResponse(response, dataSchema = z.unknown()) {
|
|
76
|
+
// Create schema for this response type
|
|
77
|
+
const schema = AgentResponseSchema(dataSchema);
|
|
78
|
+
// Validate response against schema (non-throwing)
|
|
79
|
+
const validation = schema.safeParse(response);
|
|
80
|
+
if (validation.success) {
|
|
81
|
+
// Response is valid
|
|
82
|
+
return { valid: true };
|
|
83
|
+
}
|
|
84
|
+
// Validation failed - return structured error
|
|
85
|
+
return { valid: false, errors: validation.error };
|
|
86
|
+
}
|
|
87
|
+
//# sourceMappingURL=agent-validation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent-validation.js","sourceRoot":"","sources":["../../src/utils/agent-validation.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAGH,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AACxD,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAexB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8DG;AACH,MAAM,UAAU,qBAAqB,CACnC,QAA0B,EAC1B,aAA2B,CAAC,CAAC,OAAO,EAAE;IAEtC,uCAAuC;IACvC,MAAM,MAAM,GAAG,mBAAmB,CAAC,UAAU,CAAC,CAAC;IAE/C,kDAAkD;IAClD,MAAM,UAAU,GAAG,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;IAE9C,IAAI,UAAU,CAAC,OAAO,EAAE,CAAC;QACvB,oBAAoB;QACpB,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;IACzB,CAAC;IAED,8CAA8C;IAC9C,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,UAAU,CAAC,KAAK,EAAE,CAAC;AACpD,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"delay.d.ts","sourceRoot":"","sources":["../../src/utils/delay.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,wBAAgB,KAAK,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAE/C"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates a promise that resolves after a specified delay
|
|
3
|
+
* @param ms - Delay in milliseconds
|
|
4
|
+
* @returns Promise that resolves after delay
|
|
5
|
+
*/
|
|
6
|
+
export function delay(ms) {
|
|
7
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=delay.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"delay.js","sourceRoot":"","sources":["../../src/utils/delay.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,UAAU,KAAK,CAAC,EAAU;IAC9B,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,CAAC;AAC3D,CAAC"}
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Harness configuration cascade utilities (PRD §7.6 / §7.7).
|
|
3
|
+
*
|
|
4
|
+
* ## Dual-Cascade Architecture
|
|
5
|
+
*
|
|
6
|
+
* This module provides the v1.2 canonical harness-configuration functions that operate
|
|
7
|
+
* on the `GlobalHarnessConfig` / `HarnessId` / `HarnessOptions` types. It also contains
|
|
8
|
+
* deprecated legacy aliases (`configureProviders` / `getGlobalProviderConfig` /
|
|
9
|
+
* `resolveProviderConfig` / `resetGlobalConfig`) that preserve backward compatibility
|
|
10
|
+
* with existing consumers (`agent.ts`, legacy test files) during the migration.
|
|
11
|
+
*
|
|
12
|
+
* ## Dual-Singleton Design (Scope Decision)
|
|
13
|
+
*
|
|
14
|
+
* The legacy and harness functions validate **disjoint id sets**:
|
|
15
|
+
* - `configureHarnesses` accepts only `'pi' | 'claude-code'`
|
|
16
|
+
* - `configureProviders` accepts the full `ProviderId` superset (including `'anthropic'`)
|
|
17
|
+
*
|
|
18
|
+
* Existing consumers (agent.ts, 4 integration/override test files) pass `'anthropic'`
|
|
19
|
+
* through `configureProviders`. Making it delegate to `configureHarnesses` would throw and break
|
|
20
|
+
* those consumers, which are out of scope for this task (owned by P3.M1 / P4.M1).
|
|
21
|
+
*
|
|
22
|
+
* Therefore, **`configureProviders` keeps its own module-private singleton** with permissive
|
|
23
|
+
* validation, while `resolveProviderConfig` safely delegates to `resolveHarnessConfig` (which
|
|
24
|
+
* performs NO id validation — it treats ids as opaque string keys).
|
|
25
|
+
*
|
|
26
|
+
* Once P3.M1 rewires agent.ts to read the harness path and P4.M1 removes the legacy literals,
|
|
27
|
+
* the legacy singleton can be deleted and the aliases collapse to true delegation.
|
|
28
|
+
*
|
|
29
|
+
* @see {@link GlobalHarnessConfig} in types/harnesses.ts
|
|
30
|
+
* @see {@link GlobalProviderConfig} in types/providers.ts
|
|
31
|
+
*/
|
|
32
|
+
import type { GlobalHarnessConfig, HarnessId, HarnessOptions } from '../types/harnesses.js';
|
|
33
|
+
import type { GlobalProviderConfig, ProviderId, ProviderOptions } from '../types/providers.js';
|
|
34
|
+
/**
|
|
35
|
+
* Configure the global harness settings.
|
|
36
|
+
*
|
|
37
|
+
* Validates and stores the harness configuration. Should be called once at
|
|
38
|
+
* application startup. The harness cascade (PRD §7.7) uses this as the lowest
|
|
39
|
+
* priority layer — agent and prompt overrides take precedence.
|
|
40
|
+
*
|
|
41
|
+
* ## Validation
|
|
42
|
+
*
|
|
43
|
+
* - `defaultHarness` must be `'pi'` or `'claude-code'`
|
|
44
|
+
* - `harnessDefaults` keys (if present) must be valid `HarnessId` values
|
|
45
|
+
* - `defaultModelProvider` is an **open set** (any string) — NOT validated (PRD §7.8)
|
|
46
|
+
*
|
|
47
|
+
* @param config - Global harness configuration
|
|
48
|
+
* @throws {Error} If `defaultHarness` is invalid
|
|
49
|
+
* @throws {Error} If `harnessDefaults` contains invalid harness IDs
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* ```ts
|
|
53
|
+
* import { configureHarnesses } from 'groundswell';
|
|
54
|
+
*
|
|
55
|
+
* configureHarnesses({
|
|
56
|
+
* defaultHarness: 'pi',
|
|
57
|
+
* defaultModelProvider: 'anthropic',
|
|
58
|
+
* harnessDefaults: {
|
|
59
|
+
* 'claude-code': { apiKey: process.env.ANTHROPIC_API_KEY },
|
|
60
|
+
* },
|
|
61
|
+
* });
|
|
62
|
+
* ```
|
|
63
|
+
*/
|
|
64
|
+
export declare function configureHarnesses(config: GlobalHarnessConfig): void;
|
|
65
|
+
/**
|
|
66
|
+
* Get the current global harness configuration.
|
|
67
|
+
*
|
|
68
|
+
* Returns the configured value if `configureHarnesses()` was called, otherwise
|
|
69
|
+
* returns the default configuration. **Never returns null.**
|
|
70
|
+
*
|
|
71
|
+
* @returns Current global harness configuration
|
|
72
|
+
*
|
|
73
|
+
* @example
|
|
74
|
+
* ```ts
|
|
75
|
+
* const config = getGlobalHarnessConfig();
|
|
76
|
+
* console.log(config.defaultHarness); // 'pi' (default)
|
|
77
|
+
* ```
|
|
78
|
+
*/
|
|
79
|
+
export declare function getGlobalHarnessConfig(): GlobalHarnessConfig;
|
|
80
|
+
/**
|
|
81
|
+
* Resolve harness configuration via the PRD §7.7 cascade.
|
|
82
|
+
*
|
|
83
|
+
* A **pure function** — takes `globalConfig` as a parameter and does NOT read
|
|
84
|
+
* the singleton. This purity enables both `resolveHarnessConfig` and the legacy
|
|
85
|
+
* `resolveProviderConfig` (which delegates to this function) to work correctly.
|
|
86
|
+
*
|
|
87
|
+
* ## Provider Resolution (nullish coalescing — prompt wins)
|
|
88
|
+
*
|
|
89
|
+
* ```ts
|
|
90
|
+
* const harness = promptHarness ?? agentHarness ?? globalConfig.defaultHarness;
|
|
91
|
+
* ```
|
|
92
|
+
*
|
|
93
|
+
* ## Options Merge (object spread — last write wins)
|
|
94
|
+
*
|
|
95
|
+
* ```ts
|
|
96
|
+
* const options = {
|
|
97
|
+
* ...globalConfig.harnessDefaults?.[harness], // base
|
|
98
|
+
* ...agentOptions, // middle
|
|
99
|
+
* ...promptOptions, // top
|
|
100
|
+
* };
|
|
101
|
+
* ```
|
|
102
|
+
*
|
|
103
|
+
* @param globalConfig - Global harness configuration
|
|
104
|
+
* @param agentHarness - Agent-level harness override (optional)
|
|
105
|
+
* @param agentOptions - Agent-level options override (optional)
|
|
106
|
+
* @param promptHarness - Prompt-level harness override (optional)
|
|
107
|
+
* @param promptOptions - Prompt-level options override (optional)
|
|
108
|
+
* @returns Resolved harness and merged options
|
|
109
|
+
*/
|
|
110
|
+
export declare function resolveHarnessConfig(globalConfig: GlobalHarnessConfig, agentHarness?: HarnessId, agentOptions?: HarnessOptions, promptHarness?: HarnessId, promptOptions?: HarnessOptions): {
|
|
111
|
+
harness: HarnessId;
|
|
112
|
+
options: HarnessOptions;
|
|
113
|
+
};
|
|
114
|
+
/**
|
|
115
|
+
* Reset the global harness configuration to defaults.
|
|
116
|
+
*
|
|
117
|
+
* **FOR TESTING PURPOSES ONLY.**
|
|
118
|
+
*
|
|
119
|
+
* @internal
|
|
120
|
+
*/
|
|
121
|
+
export declare function resetGlobalHarnessConfig(): void;
|
|
122
|
+
/**
|
|
123
|
+
* Configure global provider settings.
|
|
124
|
+
*
|
|
125
|
+
* @deprecated Since v1.2. Use {@link configureHarnesses}.
|
|
126
|
+
*
|
|
127
|
+
* This function keeps its **own module-private singleton** (`globalProviderConfig`)
|
|
128
|
+
* with permissive `ProviderId` validation. It does NOT delegate to
|
|
129
|
+
* `configureHarnesses` because the harness validator rejects `'anthropic'`,
|
|
130
|
+
* which existing consumers still pass.
|
|
131
|
+
*
|
|
132
|
+
* @param config - Global provider configuration
|
|
133
|
+
* @throws {Error} If `defaultProvider` is invalid
|
|
134
|
+
* @throws {Error} If `providerDefaults` contains invalid provider IDs
|
|
135
|
+
*/
|
|
136
|
+
export declare function configureProviders(config: GlobalProviderConfig): void;
|
|
137
|
+
/**
|
|
138
|
+
* Get the current global provider configuration.
|
|
139
|
+
*
|
|
140
|
+
* @deprecated Since v1.2. Use {@link getGlobalHarnessConfig}.
|
|
141
|
+
*
|
|
142
|
+
* Reads the legacy `globalProviderConfig` singleton. Returns the configured value
|
|
143
|
+
* if `configureProviders()` was called, otherwise the legacy default
|
|
144
|
+
* (`defaultProvider: 'anthropic'`). **Never returns null.**
|
|
145
|
+
*
|
|
146
|
+
* @returns Current global provider configuration
|
|
147
|
+
*/
|
|
148
|
+
export declare function getGlobalProviderConfig(): GlobalProviderConfig;
|
|
149
|
+
/**
|
|
150
|
+
* Resolve provider configuration via the cascade.
|
|
151
|
+
*
|
|
152
|
+
* @deprecated Since v1.2. Use {@link resolveHarnessConfig}.
|
|
153
|
+
*
|
|
154
|
+
* **Delegates to {@link resolveHarnessConfig}** — the cascade algorithm is shared.
|
|
155
|
+
* Translates the `GlobalProviderConfig` shape to `GlobalHarnessConfig` (field renames),
|
|
156
|
+
* calls `resolveHarnessConfig` (which performs NO id validation — safe for legacy literals),
|
|
157
|
+
* and maps the result back to `{ provider, options }`.
|
|
158
|
+
*
|
|
159
|
+
* @param globalConfig - Global provider configuration from configureProviders()
|
|
160
|
+
* @param agentProvider - Agent-level provider override (optional)
|
|
161
|
+
* @param agentOptions - Agent-level options override (optional)
|
|
162
|
+
* @param promptProvider - Prompt-level provider override (optional)
|
|
163
|
+
* @param promptOptions - Prompt-level options override (optional)
|
|
164
|
+
* @returns Resolved provider and merged options
|
|
165
|
+
*/
|
|
166
|
+
export declare function resolveProviderConfig(globalConfig: GlobalProviderConfig, agentProvider?: ProviderId, agentOptions?: ProviderOptions, promptProvider?: ProviderId, promptOptions?: ProviderOptions): {
|
|
167
|
+
provider: ProviderId;
|
|
168
|
+
options: ProviderOptions;
|
|
169
|
+
};
|
|
170
|
+
/**
|
|
171
|
+
* Reset global configuration to defaults.
|
|
172
|
+
*
|
|
173
|
+
* @deprecated Since v1.2. Use {@link resetGlobalHarnessConfig}.
|
|
174
|
+
*
|
|
175
|
+
* **FOR TESTING PURPOSES ONLY.**
|
|
176
|
+
*
|
|
177
|
+
* @internal
|
|
178
|
+
*/
|
|
179
|
+
export declare function resetGlobalConfig(): void;
|
|
180
|
+
//# sourceMappingURL=harness-config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"harness-config.d.ts","sourceRoot":"","sources":["../../src/utils/harness-config.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AAGH,OAAO,KAAK,EACV,mBAAmB,EACnB,SAAS,EACT,cAAc,EACf,MAAM,uBAAuB,CAAC;AAG/B,OAAO,KAAK,EACV,oBAAoB,EACpB,UAAU,EACV,eAAe,EAChB,MAAM,uBAAuB,CAAC;AA4C/B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,mBAAmB,GAAG,IAAI,CAuBpE;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,sBAAsB,IAAI,mBAAmB,CAE5D;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,wBAAgB,oBAAoB,CAClC,YAAY,EAAE,mBAAmB,EACjC,YAAY,CAAC,EAAE,SAAS,EACxB,YAAY,CAAC,EAAE,cAAc,EAC7B,aAAa,CAAC,EAAE,SAAS,EACzB,aAAa,CAAC,EAAE,cAAc,GAC7B;IAAE,OAAO,EAAE,SAAS,CAAC;IAAC,OAAO,EAAE,cAAc,CAAA;CAAE,CAejD;AAED;;;;;;GAMG;AACH,wBAAgB,wBAAwB,IAAI,IAAI,CAE/C;AAiDD;;;;;;;;;;;;;GAaG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,oBAAoB,GAAG,IAAI,CAuBrE;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,uBAAuB,IAAI,oBAAoB,CAE9D;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,qBAAqB,CACnC,YAAY,EAAE,oBAAoB,EAClC,aAAa,CAAC,EAAE,UAAU,EAC1B,YAAY,CAAC,EAAE,eAAe,EAC9B,cAAc,CAAC,EAAE,UAAU,EAC3B,aAAa,CAAC,EAAE,eAAe,GAC9B;IAAE,QAAQ,EAAE,UAAU,CAAC;IAAC,OAAO,EAAE,eAAe,CAAA;CAAE,CAmBpD;AAED;;;;;;;;GAQG;AACH,wBAAgB,iBAAiB,IAAI,IAAI,CAExC"}
|