@autonome-research/thread-phase 3.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 +226 -0
- package/dist/agent/index.d.ts +28 -0
- package/dist/agent/index.d.ts.map +1 -0
- package/dist/agent/index.js +28 -0
- package/dist/agent/index.js.map +1 -0
- package/dist/agent/openai-adapter.d.ts +15 -0
- package/dist/agent/openai-adapter.d.ts.map +1 -0
- package/dist/agent/openai-adapter.js +57 -0
- package/dist/agent/openai-adapter.js.map +1 -0
- package/dist/agent/parse-json.d.ts +12 -0
- package/dist/agent/parse-json.d.ts.map +1 -0
- package/dist/agent/parse-json.js +31 -0
- package/dist/agent/parse-json.js.map +1 -0
- package/dist/agent/retry.d.ts +15 -0
- package/dist/agent/retry.d.ts.map +1 -0
- package/dist/agent/retry.js +35 -0
- package/dist/agent/retry.js.map +1 -0
- package/dist/agent/runner.d.ts +25 -0
- package/dist/agent/runner.d.ts.map +1 -0
- package/dist/agent/runner.js +270 -0
- package/dist/agent/runner.js.map +1 -0
- package/dist/agent/stream-consumer.d.ts +57 -0
- package/dist/agent/stream-consumer.d.ts.map +1 -0
- package/dist/agent/stream-consumer.js +126 -0
- package/dist/agent/stream-consumer.js.map +1 -0
- package/dist/agent/types.d.ts +135 -0
- package/dist/agent/types.d.ts.map +1 -0
- package/dist/agent/types.js +9 -0
- package/dist/agent/types.js.map +1 -0
- package/dist/agent-runner.d.ts +10 -0
- package/dist/agent-runner.d.ts.map +1 -0
- package/dist/agent-runner.js +10 -0
- package/dist/agent-runner.js.map +1 -0
- package/dist/agents/capability.d.ts +36 -0
- package/dist/agents/capability.d.ts.map +1 -0
- package/dist/agents/capability.js +51 -0
- package/dist/agents/capability.js.map +1 -0
- package/dist/agents/event-bus.d.ts +20 -0
- package/dist/agents/event-bus.d.ts.map +1 -0
- package/dist/agents/event-bus.js +40 -0
- package/dist/agents/event-bus.js.map +1 -0
- package/dist/agents/index.d.ts +23 -0
- package/dist/agents/index.d.ts.map +1 -0
- package/dist/agents/index.js +33 -0
- package/dist/agents/index.js.map +1 -0
- package/dist/agents/inference-adapter.d.ts +52 -0
- package/dist/agents/inference-adapter.d.ts.map +1 -0
- package/dist/agents/inference-adapter.js +209 -0
- package/dist/agents/inference-adapter.js.map +1 -0
- package/dist/agents/job-store-bridge.d.ts +44 -0
- package/dist/agents/job-store-bridge.d.ts.map +1 -0
- package/dist/agents/job-store-bridge.js +58 -0
- package/dist/agents/job-store-bridge.js.map +1 -0
- package/dist/agents/memory.d.ts +40 -0
- package/dist/agents/memory.d.ts.map +1 -0
- package/dist/agents/memory.js +14 -0
- package/dist/agents/memory.js.map +1 -0
- package/dist/agents/protocol.d.ts +302 -0
- package/dist/agents/protocol.d.ts.map +1 -0
- package/dist/agents/protocol.js +36 -0
- package/dist/agents/protocol.js.map +1 -0
- package/dist/agents/run-helpers.d.ts +70 -0
- package/dist/agents/run-helpers.d.ts.map +1 -0
- package/dist/agents/run-helpers.js +131 -0
- package/dist/agents/run-helpers.js.map +1 -0
- package/dist/agents/serialize-error.d.ts +18 -0
- package/dist/agents/serialize-error.d.ts.map +1 -0
- package/dist/agents/serialize-error.js +27 -0
- package/dist/agents/serialize-error.js.map +1 -0
- package/dist/agents/structured-output.d.ts +90 -0
- package/dist/agents/structured-output.d.ts.map +1 -0
- package/dist/agents/structured-output.js +101 -0
- package/dist/agents/structured-output.js.map +1 -0
- package/dist/agents/test-utils/conformance.d.ts +59 -0
- package/dist/agents/test-utils/conformance.d.ts.map +1 -0
- package/dist/agents/test-utils/conformance.js +207 -0
- package/dist/agents/test-utils/conformance.js.map +1 -0
- package/dist/agents/test-utils/index.d.ts +12 -0
- package/dist/agents/test-utils/index.d.ts.map +1 -0
- package/dist/agents/test-utils/index.js +12 -0
- package/dist/agents/test-utils/index.js.map +1 -0
- package/dist/agents/test-utils/mock-agent.d.ts +66 -0
- package/dist/agents/test-utils/mock-agent.d.ts.map +1 -0
- package/dist/agents/test-utils/mock-agent.js +244 -0
- package/dist/agents/test-utils/mock-agent.js.map +1 -0
- package/dist/agents/thread.d.ts +57 -0
- package/dist/agents/thread.d.ts.map +1 -0
- package/dist/agents/thread.js +128 -0
- package/dist/agents/thread.js.map +1 -0
- package/dist/agents/turn-accumulator.d.ts +94 -0
- package/dist/agents/turn-accumulator.d.ts.map +1 -0
- package/dist/agents/turn-accumulator.js +150 -0
- package/dist/agents/turn-accumulator.js.map +1 -0
- package/dist/agents/with-memory.d.ts +55 -0
- package/dist/agents/with-memory.d.ts.map +1 -0
- package/dist/agents/with-memory.js +155 -0
- package/dist/agents/with-memory.js.map +1 -0
- package/dist/agents/with-thread.d.ts +45 -0
- package/dist/agents/with-thread.d.ts.map +1 -0
- package/dist/agents/with-thread.js +70 -0
- package/dist/agents/with-thread.js.map +1 -0
- package/dist/cache.d.ts +47 -0
- package/dist/cache.d.ts.map +1 -0
- package/dist/cache.js +81 -0
- package/dist/cache.js.map +1 -0
- package/dist/context/compressor.d.ts +36 -0
- package/dist/context/compressor.d.ts.map +1 -0
- package/dist/context/compressor.js +158 -0
- package/dist/context/compressor.js.map +1 -0
- package/dist/context/index.d.ts +4 -0
- package/dist/context/index.d.ts.map +1 -0
- package/dist/context/index.js +4 -0
- package/dist/context/index.js.map +1 -0
- package/dist/context/result-capper.d.ts +32 -0
- package/dist/context/result-capper.d.ts.map +1 -0
- package/dist/context/result-capper.js +50 -0
- package/dist/context/result-capper.js.map +1 -0
- package/dist/context/token-budget.d.ts +81 -0
- package/dist/context/token-budget.d.ts.map +1 -0
- package/dist/context/token-budget.js +99 -0
- package/dist/context/token-budget.js.map +1 -0
- package/dist/helpers/caller.d.ts +18 -0
- package/dist/helpers/caller.d.ts.map +1 -0
- package/dist/helpers/caller.js +40 -0
- package/dist/helpers/caller.js.map +1 -0
- package/dist/helpers/hook.d.ts +73 -0
- package/dist/helpers/hook.d.ts.map +1 -0
- package/dist/helpers/hook.js +244 -0
- package/dist/helpers/hook.js.map +1 -0
- package/dist/helpers/index.d.ts +12 -0
- package/dist/helpers/index.d.ts.map +1 -0
- package/dist/helpers/index.js +11 -0
- package/dist/helpers/index.js.map +1 -0
- package/dist/helpers/one-shot.d.ts +27 -0
- package/dist/helpers/one-shot.d.ts.map +1 -0
- package/dist/helpers/one-shot.js +43 -0
- package/dist/helpers/one-shot.js.map +1 -0
- package/dist/helpers/schedule.d.ts +59 -0
- package/dist/helpers/schedule.d.ts.map +1 -0
- package/dist/helpers/schedule.js +118 -0
- package/dist/helpers/schedule.js.map +1 -0
- package/dist/helpers/types.d.ts +34 -0
- package/dist/helpers/types.d.ts.map +1 -0
- package/dist/helpers/types.js +11 -0
- package/dist/helpers/types.js.map +1 -0
- package/dist/index.d.ts +26 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +37 -0
- package/dist/index.js.map +1 -0
- package/dist/inference.d.ts +27 -0
- package/dist/inference.d.ts.map +1 -0
- package/dist/inference.js +34 -0
- package/dist/inference.js.map +1 -0
- package/dist/messages.d.ts +64 -0
- package/dist/messages.d.ts.map +1 -0
- package/dist/messages.js +17 -0
- package/dist/messages.js.map +1 -0
- package/dist/orchestrator.d.ts +56 -0
- package/dist/orchestrator.d.ts.map +1 -0
- package/dist/orchestrator.js +62 -0
- package/dist/orchestrator.js.map +1 -0
- package/dist/patterns/bounded-fanout-of.d.ts +61 -0
- package/dist/patterns/bounded-fanout-of.d.ts.map +1 -0
- package/dist/patterns/bounded-fanout-of.js +142 -0
- package/dist/patterns/bounded-fanout-of.js.map +1 -0
- package/dist/patterns/bounded-fanout.d.ts +111 -0
- package/dist/patterns/bounded-fanout.d.ts.map +1 -0
- package/dist/patterns/bounded-fanout.js +151 -0
- package/dist/patterns/bounded-fanout.js.map +1 -0
- package/dist/patterns/index.d.ts +14 -0
- package/dist/patterns/index.d.ts.map +1 -0
- package/dist/patterns/index.js +13 -0
- package/dist/patterns/index.js.map +1 -0
- package/dist/patterns/intent-gate.d.ts +27 -0
- package/dist/patterns/intent-gate.d.ts.map +1 -0
- package/dist/patterns/intent-gate.js +32 -0
- package/dist/patterns/intent-gate.js.map +1 -0
- package/dist/patterns/match.d.ts +30 -0
- package/dist/patterns/match.d.ts.map +1 -0
- package/dist/patterns/match.js +58 -0
- package/dist/patterns/match.js.map +1 -0
- package/dist/patterns/parallel-fanout.d.ts +28 -0
- package/dist/patterns/parallel-fanout.d.ts.map +1 -0
- package/dist/patterns/parallel-fanout.js +24 -0
- package/dist/patterns/parallel-fanout.js.map +1 -0
- package/dist/patterns/parallel-phases.d.ts +27 -0
- package/dist/patterns/parallel-phases.d.ts.map +1 -0
- package/dist/patterns/parallel-phases.js +77 -0
- package/dist/patterns/parallel-phases.js.map +1 -0
- package/dist/patterns/preflight-confidence.d.ts +20 -0
- package/dist/patterns/preflight-confidence.d.ts.map +1 -0
- package/dist/patterns/preflight-confidence.js +38 -0
- package/dist/patterns/preflight-confidence.js.map +1 -0
- package/dist/patterns/spot-check.d.ts +19 -0
- package/dist/patterns/spot-check.d.ts.map +1 -0
- package/dist/patterns/spot-check.js +33 -0
- package/dist/patterns/spot-check.js.map +1 -0
- package/dist/patterns/sub-pipeline.d.ts +84 -0
- package/dist/patterns/sub-pipeline.d.ts.map +1 -0
- package/dist/patterns/sub-pipeline.js +90 -0
- package/dist/patterns/sub-pipeline.js.map +1 -0
- package/dist/patterns/synthesize-with-followup.d.ts +35 -0
- package/dist/patterns/synthesize-with-followup.d.ts.map +1 -0
- package/dist/patterns/synthesize-with-followup.js +45 -0
- package/dist/patterns/synthesize-with-followup.js.map +1 -0
- package/dist/patterns/while-condition.d.ts +31 -0
- package/dist/patterns/while-condition.d.ts.map +1 -0
- package/dist/patterns/while-condition.js +59 -0
- package/dist/patterns/while-condition.js.map +1 -0
- package/dist/patterns/with-retry.d.ts +37 -0
- package/dist/patterns/with-retry.d.ts.map +1 -0
- package/dist/patterns/with-retry.js +73 -0
- package/dist/patterns/with-retry.js.map +1 -0
- package/dist/phase.d.ts +78 -0
- package/dist/phase.d.ts.map +1 -0
- package/dist/phase.js +36 -0
- package/dist/phase.js.map +1 -0
- package/dist/session/index.d.ts +5 -0
- package/dist/session/index.d.ts.map +1 -0
- package/dist/session/index.js +4 -0
- package/dist/session/index.js.map +1 -0
- package/dist/session/job-runner.d.ts +67 -0
- package/dist/session/job-runner.d.ts.map +1 -0
- package/dist/session/job-runner.js +131 -0
- package/dist/session/job-runner.js.map +1 -0
- package/dist/session/job-store.d.ts +98 -0
- package/dist/session/job-store.d.ts.map +1 -0
- package/dist/session/job-store.js +37 -0
- package/dist/session/job-store.js.map +1 -0
- package/dist/session/sqlite-job-store.d.ts +40 -0
- package/dist/session/sqlite-job-store.d.ts.map +1 -0
- package/dist/session/sqlite-job-store.js +200 -0
- package/dist/session/sqlite-job-store.js.map +1 -0
- package/dist/session/sse.d.ts +60 -0
- package/dist/session/sse.d.ts.map +1 -0
- package/dist/session/sse.js +97 -0
- package/dist/session/sse.js.map +1 -0
- package/dist/tools/index.d.ts +2 -0
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/index.js +2 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/tools/registry.d.ts +44 -0
- package/dist/tools/registry.d.ts.map +1 -0
- package/dist/tools/registry.js +74 -0
- package/dist/tools/registry.js.map +1 -0
- package/dist/triggers/index.d.ts +15 -0
- package/dist/triggers/index.d.ts.map +1 -0
- package/dist/triggers/index.js +14 -0
- package/dist/triggers/index.js.map +1 -0
- package/dist/triggers/run-trigger.d.ts +86 -0
- package/dist/triggers/run-trigger.d.ts.map +1 -0
- package/dist/triggers/run-trigger.js +146 -0
- package/dist/triggers/run-trigger.js.map +1 -0
- package/dist/triggers/timer-trigger.d.ts +46 -0
- package/dist/triggers/timer-trigger.d.ts.map +1 -0
- package/dist/triggers/timer-trigger.js +74 -0
- package/dist/triggers/timer-trigger.js.map +1 -0
- package/dist/triggers/types.d.ts +61 -0
- package/dist/triggers/types.d.ts.map +1 -0
- package/dist/triggers/types.js +23 -0
- package/dist/triggers/types.js.map +1 -0
- package/package.json +64 -0
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Convert a thrown value into the wire-friendly `SerializableError` shape
|
|
3
|
+
* that adapters emit on `error` events. Walks the `cause` chain so wrapped
|
|
4
|
+
* errors don't lose context across the subprocess boundary.
|
|
5
|
+
*
|
|
6
|
+
* @internal
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Normalize any thrown value to a `SerializableError`. Non-`Error` throws
|
|
10
|
+
* become `{ name: 'NonError', message: String(err) }` so the field shape
|
|
11
|
+
* stays uniform — consumers can rely on `name` and `message` always being
|
|
12
|
+
* present.
|
|
13
|
+
*
|
|
14
|
+
* @internal
|
|
15
|
+
*/
|
|
16
|
+
export function serializeError(err) {
|
|
17
|
+
if (err instanceof Error) {
|
|
18
|
+
return {
|
|
19
|
+
name: err.name,
|
|
20
|
+
message: err.message,
|
|
21
|
+
stack: err.stack,
|
|
22
|
+
cause: err.cause !== undefined ? serializeError(err.cause) : undefined,
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
return { name: 'NonError', message: String(err) };
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=serialize-error.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serialize-error.js","sourceRoot":"","sources":["../../src/agents/serialize-error.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAIH;;;;;;;GAOG;AACH,MAAM,UAAU,cAAc,CAAC,GAAY;IACzC,IAAI,GAAG,YAAY,KAAK,EAAE,CAAC;QACzB,OAAO;YACL,IAAI,EAAE,GAAG,CAAC,IAAI;YACd,OAAO,EAAE,GAAG,CAAC,OAAO;YACpB,KAAK,EAAE,GAAG,CAAC,KAAK;YAChB,KAAK,EAAE,GAAG,CAAC,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,cAAc,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS;SACvE,CAAC;IACJ,CAAC;IACD,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC;AACpD,CAAC"}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Prompted structured-output helpers.
|
|
3
|
+
*
|
|
4
|
+
* Adapters that declare `structuredOutput: 'prompted'` cannot ask the
|
|
5
|
+
* underlying runtime for a JSON-schema-constrained response, so they instead
|
|
6
|
+
* inject an instruction into the system prompt and parse the agent's final
|
|
7
|
+
* text afterward. This module owns both halves: `applyStructuredOutputPrompt`
|
|
8
|
+
* augments the prompt; `parseStructuredFromText` (and the convenience
|
|
9
|
+
* `parseStructured`) extract and validate the payload.
|
|
10
|
+
*
|
|
11
|
+
* The contract: the agent emits its final answer inside a single
|
|
12
|
+
* `<response>...</response>` block. Free-form reasoning may precede it.
|
|
13
|
+
* Retries on parse failure are not executed here — that is an adapter-level
|
|
14
|
+
* concern (the adapter calls `followUp()` with the parse error and retries).
|
|
15
|
+
*
|
|
16
|
+
* @internal
|
|
17
|
+
*/
|
|
18
|
+
import type { AgentRunResult } from './protocol.js';
|
|
19
|
+
/**
|
|
20
|
+
* Configuration for the prompted structured-output path.
|
|
21
|
+
*
|
|
22
|
+
* @internal
|
|
23
|
+
*/
|
|
24
|
+
export interface StructuredOutputConfig {
|
|
25
|
+
/**
|
|
26
|
+
* JSON Schema describing the expected payload, or a free-form description
|
|
27
|
+
* string. Used to render the instruction; not validated by this module —
|
|
28
|
+
* callers supply `validate` if they want a check.
|
|
29
|
+
*/
|
|
30
|
+
schema: Record<string, unknown> | string;
|
|
31
|
+
/**
|
|
32
|
+
* Optional caller-supplied validator. When provided, `parseStructured`
|
|
33
|
+
* runs it on the extracted JSON and throws `StructuredOutputParseError`
|
|
34
|
+
* if it returns false. Default is identity (no validation).
|
|
35
|
+
*/
|
|
36
|
+
validate?: (data: unknown) => boolean;
|
|
37
|
+
/**
|
|
38
|
+
* Retries are NOT executed by this module — they are an adapter-level
|
|
39
|
+
* concern. Documented here so adapters can read the intended count.
|
|
40
|
+
* Default: 1.
|
|
41
|
+
*/
|
|
42
|
+
retries?: number;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Distinct error for the prompted-output path. Carries the offending text
|
|
46
|
+
* window so callers can decide whether to retry.
|
|
47
|
+
*
|
|
48
|
+
* @internal
|
|
49
|
+
*/
|
|
50
|
+
export declare class StructuredOutputParseError extends Error {
|
|
51
|
+
window: string;
|
|
52
|
+
constructor(message: string, window: string);
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Append the prompted-output instruction to a system prompt. The instruction
|
|
56
|
+
* tells the agent to emit a single `<response>...</response>` block whose
|
|
57
|
+
* contents are JSON conforming to the schema, after any free-form text.
|
|
58
|
+
*
|
|
59
|
+
* String schemas are embedded verbatim; object schemas are JSON-stringified
|
|
60
|
+
* with 2-space indent. The instruction is separated from the existing prompt
|
|
61
|
+
* by a blank line.
|
|
62
|
+
*
|
|
63
|
+
* @internal
|
|
64
|
+
*/
|
|
65
|
+
export declare function applyStructuredOutputPrompt(systemPrompt: string, spec: StructuredOutputConfig): string;
|
|
66
|
+
/**
|
|
67
|
+
* Extract the last `<response>...</response>` block from arbitrary text.
|
|
68
|
+
* Returns the inner content (trimmed) on match, or `null` when no block is
|
|
69
|
+
* present. Taking the LAST match makes the parser robust to wrapped thinking
|
|
70
|
+
* and accidental example tags earlier in the output.
|
|
71
|
+
*
|
|
72
|
+
* @internal
|
|
73
|
+
*/
|
|
74
|
+
export declare function extractResponseBlock(text: string): string | null;
|
|
75
|
+
/**
|
|
76
|
+
* Extract, parse, and optionally validate a structured payload from arbitrary
|
|
77
|
+
* agent text. Throws `StructuredOutputParseError` on extraction failure, JSON
|
|
78
|
+
* parse failure, or validator rejection.
|
|
79
|
+
*
|
|
80
|
+
* @internal
|
|
81
|
+
*/
|
|
82
|
+
export declare function parseStructuredFromText(text: string, spec: StructuredOutputConfig): unknown;
|
|
83
|
+
/**
|
|
84
|
+
* Convenience wrapper: same as `parseStructuredFromText` but reads the text
|
|
85
|
+
* from a completed `AgentRunResult`.
|
|
86
|
+
*
|
|
87
|
+
* @internal
|
|
88
|
+
*/
|
|
89
|
+
export declare function parseStructured(result: AgentRunResult, spec: StructuredOutputConfig): unknown;
|
|
90
|
+
//# sourceMappingURL=structured-output.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"structured-output.d.ts","sourceRoot":"","sources":["../../src/agents/structured-output.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAEpD;;;;GAIG;AACH,MAAM,WAAW,sBAAsB;IACrC;;;;OAIG;IACH,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC;IACzC;;;;OAIG;IACH,QAAQ,CAAC,EAAE,CAAC,IAAI,EAAE,OAAO,KAAK,OAAO,CAAC;IACtC;;;;OAIG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;;;;GAKG;AACH,qBAAa,0BAA2B,SAAQ,KAAK;IACf,MAAM,EAAE,MAAM;gBAAtC,OAAO,EAAE,MAAM,EAAS,MAAM,EAAE,MAAM;CAInD;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,2BAA2B,CACzC,YAAY,EAAE,MAAM,EACpB,IAAI,EAAE,sBAAsB,GAC3B,MAAM,CAUR;AAED;;;;;;;GAOG;AACH,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAOhE;AAED;;;;;;GAMG;AACH,wBAAgB,uBAAuB,CACrC,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,sBAAsB,GAC3B,OAAO,CAeT;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,CAC7B,MAAM,EAAE,cAAc,EACtB,IAAI,EAAE,sBAAsB,GAC3B,OAAO,CAET"}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Prompted structured-output helpers.
|
|
3
|
+
*
|
|
4
|
+
* Adapters that declare `structuredOutput: 'prompted'` cannot ask the
|
|
5
|
+
* underlying runtime for a JSON-schema-constrained response, so they instead
|
|
6
|
+
* inject an instruction into the system prompt and parse the agent's final
|
|
7
|
+
* text afterward. This module owns both halves: `applyStructuredOutputPrompt`
|
|
8
|
+
* augments the prompt; `parseStructuredFromText` (and the convenience
|
|
9
|
+
* `parseStructured`) extract and validate the payload.
|
|
10
|
+
*
|
|
11
|
+
* The contract: the agent emits its final answer inside a single
|
|
12
|
+
* `<response>...</response>` block. Free-form reasoning may precede it.
|
|
13
|
+
* Retries on parse failure are not executed here — that is an adapter-level
|
|
14
|
+
* concern (the adapter calls `followUp()` with the parse error and retries).
|
|
15
|
+
*
|
|
16
|
+
* @internal
|
|
17
|
+
*/
|
|
18
|
+
/**
|
|
19
|
+
* Distinct error for the prompted-output path. Carries the offending text
|
|
20
|
+
* window so callers can decide whether to retry.
|
|
21
|
+
*
|
|
22
|
+
* @internal
|
|
23
|
+
*/
|
|
24
|
+
export class StructuredOutputParseError extends Error {
|
|
25
|
+
window;
|
|
26
|
+
constructor(message, window) {
|
|
27
|
+
super(message);
|
|
28
|
+
this.window = window;
|
|
29
|
+
this.name = 'StructuredOutputParseError';
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Append the prompted-output instruction to a system prompt. The instruction
|
|
34
|
+
* tells the agent to emit a single `<response>...</response>` block whose
|
|
35
|
+
* contents are JSON conforming to the schema, after any free-form text.
|
|
36
|
+
*
|
|
37
|
+
* String schemas are embedded verbatim; object schemas are JSON-stringified
|
|
38
|
+
* with 2-space indent. The instruction is separated from the existing prompt
|
|
39
|
+
* by a blank line.
|
|
40
|
+
*
|
|
41
|
+
* @internal
|
|
42
|
+
*/
|
|
43
|
+
export function applyStructuredOutputPrompt(systemPrompt, spec) {
|
|
44
|
+
const schemaText = typeof spec.schema === 'string' ? spec.schema : JSON.stringify(spec.schema, null, 2);
|
|
45
|
+
const instruction = 'When finished, emit your final answer as a single <response>...</response> block ' +
|
|
46
|
+
'whose contents are valid JSON conforming to:\n' +
|
|
47
|
+
schemaText +
|
|
48
|
+
'\nDo not include any text after the closing tag.';
|
|
49
|
+
const base = systemPrompt.trimEnd();
|
|
50
|
+
return base.length > 0 ? `${base}\n\n${instruction}` : instruction;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Extract the last `<response>...</response>` block from arbitrary text.
|
|
54
|
+
* Returns the inner content (trimmed) on match, or `null` when no block is
|
|
55
|
+
* present. Taking the LAST match makes the parser robust to wrapped thinking
|
|
56
|
+
* and accidental example tags earlier in the output.
|
|
57
|
+
*
|
|
58
|
+
* @internal
|
|
59
|
+
*/
|
|
60
|
+
export function extractResponseBlock(text) {
|
|
61
|
+
const re = /<response>([\s\S]*?)<\/response>/g;
|
|
62
|
+
let last = null;
|
|
63
|
+
for (const match of text.matchAll(re)) {
|
|
64
|
+
last = match[1] ?? '';
|
|
65
|
+
}
|
|
66
|
+
return last === null ? null : last.trim();
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Extract, parse, and optionally validate a structured payload from arbitrary
|
|
70
|
+
* agent text. Throws `StructuredOutputParseError` on extraction failure, JSON
|
|
71
|
+
* parse failure, or validator rejection.
|
|
72
|
+
*
|
|
73
|
+
* @internal
|
|
74
|
+
*/
|
|
75
|
+
export function parseStructuredFromText(text, spec) {
|
|
76
|
+
const block = extractResponseBlock(text);
|
|
77
|
+
if (block === null) {
|
|
78
|
+
throw new StructuredOutputParseError('no <response> block in output', text.slice(-500));
|
|
79
|
+
}
|
|
80
|
+
let parsed;
|
|
81
|
+
try {
|
|
82
|
+
parsed = JSON.parse(block);
|
|
83
|
+
}
|
|
84
|
+
catch {
|
|
85
|
+
throw new StructuredOutputParseError('invalid JSON in <response>', block);
|
|
86
|
+
}
|
|
87
|
+
if (spec.validate && !spec.validate(parsed)) {
|
|
88
|
+
throw new StructuredOutputParseError('payload rejected by validator', block);
|
|
89
|
+
}
|
|
90
|
+
return parsed;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Convenience wrapper: same as `parseStructuredFromText` but reads the text
|
|
94
|
+
* from a completed `AgentRunResult`.
|
|
95
|
+
*
|
|
96
|
+
* @internal
|
|
97
|
+
*/
|
|
98
|
+
export function parseStructured(result, spec) {
|
|
99
|
+
return parseStructuredFromText(result.text, spec);
|
|
100
|
+
}
|
|
101
|
+
//# sourceMappingURL=structured-output.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"structured-output.js","sourceRoot":"","sources":["../../src/agents/structured-output.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AA8BH;;;;;GAKG;AACH,MAAM,OAAO,0BAA2B,SAAQ,KAAK;IACf;IAApC,YAAY,OAAe,EAAS,MAAc;QAChD,KAAK,CAAC,OAAO,CAAC,CAAC;QADmB,WAAM,GAAN,MAAM,CAAQ;QAEhD,IAAI,CAAC,IAAI,GAAG,4BAA4B,CAAC;IAC3C,CAAC;CACF;AAED;;;;;;;;;;GAUG;AACH,MAAM,UAAU,2BAA2B,CACzC,YAAoB,EACpB,IAA4B;IAE5B,MAAM,UAAU,GACd,OAAO,IAAI,CAAC,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;IACvF,MAAM,WAAW,GACf,mFAAmF;QACnF,gDAAgD;QAChD,UAAU;QACV,kDAAkD,CAAC;IACrD,MAAM,IAAI,GAAG,YAAY,CAAC,OAAO,EAAE,CAAC;IACpC,OAAO,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,IA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,OAAO,uBAAuB,CAAC,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;AACpD,CAAC"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parameterized vitest suite that asserts an `AgentAdapter` honors the
|
|
3
|
+
* protocol's lifecycle invariants. Both in-tree tests and the sibling
|
|
4
|
+
* `@autonome-research/thread-phase-agents` package import this and call it from a `describe`
|
|
5
|
+
* or top-level test file.
|
|
6
|
+
*
|
|
7
|
+
* Invariants asserted (see `protocol.ts` for the canonical statements):
|
|
8
|
+
* - exactly one `agent_start` at the head of the stream,
|
|
9
|
+
* - exactly one `agent_end` at the tail of the stream,
|
|
10
|
+
* - `result` resolves and never rejects,
|
|
11
|
+
* - `result.finishReason` matches `agent_end.reason`,
|
|
12
|
+
* - `abort()` is idempotent and yields `finishReason: 'aborted'`,
|
|
13
|
+
* - `options.signal` is observed,
|
|
14
|
+
* - `options.eventBus` mirrors the full event stream,
|
|
15
|
+
* - every event carries `source === meta.id`,
|
|
16
|
+
* - the `events` AsyncIterable terminates,
|
|
17
|
+
* - `events` is single-consumer (second iteration attempt throws),
|
|
18
|
+
* - `events` iterator `return()` cleanly closes the stream,
|
|
19
|
+
* - `result` resolves even when `events` is never iterated.
|
|
20
|
+
*
|
|
21
|
+
* Adapters that can synthesize internal-error runs supply `buildErrorConfig`
|
|
22
|
+
* to additionally assert the resolve-not-reject invariant on the error path.
|
|
23
|
+
*
|
|
24
|
+
* @internal
|
|
25
|
+
*/
|
|
26
|
+
import type { AgentAdapterMeta } from '../protocol.js';
|
|
27
|
+
/**
|
|
28
|
+
* Per-adapter config-builder. Each invocation must return a fresh config
|
|
29
|
+
* suitable for one run. Caller controls how prompts/messages are shaped.
|
|
30
|
+
*
|
|
31
|
+
* @internal
|
|
32
|
+
*/
|
|
33
|
+
export type ConformanceConfigBuilder<TConfig> = () => TConfig;
|
|
34
|
+
/**
|
|
35
|
+
* Options for running the conformance suite against an adapter.
|
|
36
|
+
*
|
|
37
|
+
* @internal
|
|
38
|
+
*/
|
|
39
|
+
export interface RunConformanceSuiteOptions<TConfig> {
|
|
40
|
+
meta: AgentAdapterMeta<TConfig>;
|
|
41
|
+
buildConfig: ConformanceConfigBuilder<TConfig>;
|
|
42
|
+
/**
|
|
43
|
+
* Optional: build a config that should produce a runner-internal error.
|
|
44
|
+
* Used to test the "result resolves rather than rejects on error" invariant.
|
|
45
|
+
* If omitted, that test is skipped. Sibling adapters that can't reliably
|
|
46
|
+
* trigger an internal error may omit this safely.
|
|
47
|
+
*/
|
|
48
|
+
buildErrorConfig?: ConformanceConfigBuilder<TConfig>;
|
|
49
|
+
/** Per-test timeout in ms. Default 10_000. */
|
|
50
|
+
timeoutMs?: number;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Run the full conformance suite against an adapter. Registers its own
|
|
54
|
+
* `describe` block.
|
|
55
|
+
*
|
|
56
|
+
* @internal
|
|
57
|
+
*/
|
|
58
|
+
export declare function runAdapterConformance<TConfig>(opts: RunConformanceSuiteOptions<TConfig>): void;
|
|
59
|
+
//# sourceMappingURL=conformance.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"conformance.d.ts","sourceRoot":"","sources":["../../../src/agents/test-utils/conformance.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAGH,OAAO,KAAK,EACV,gBAAgB,EAIjB,MAAM,gBAAgB,CAAC;AAGxB;;;;;GAKG;AACH,MAAM,MAAM,wBAAwB,CAAC,OAAO,IAAI,MAAM,OAAO,CAAC;AAE9D;;;;GAIG;AACH,MAAM,WAAW,0BAA0B,CAAC,OAAO;IACjD,IAAI,EAAE,gBAAgB,CAAC,OAAO,CAAC,CAAC;IAChC,WAAW,EAAE,wBAAwB,CAAC,OAAO,CAAC,CAAC;IAC/C;;;;;OAKG;IACH,gBAAgB,CAAC,EAAE,wBAAwB,CAAC,OAAO,CAAC,CAAC;IACrD,8CAA8C;IAC9C,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;;;;GAKG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,EAC3C,IAAI,EAAE,0BAA0B,CAAC,OAAO,CAAC,GACxC,IAAI,CA6ON"}
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parameterized vitest suite that asserts an `AgentAdapter` honors the
|
|
3
|
+
* protocol's lifecycle invariants. Both in-tree tests and the sibling
|
|
4
|
+
* `@autonome-research/thread-phase-agents` package import this and call it from a `describe`
|
|
5
|
+
* or top-level test file.
|
|
6
|
+
*
|
|
7
|
+
* Invariants asserted (see `protocol.ts` for the canonical statements):
|
|
8
|
+
* - exactly one `agent_start` at the head of the stream,
|
|
9
|
+
* - exactly one `agent_end` at the tail of the stream,
|
|
10
|
+
* - `result` resolves and never rejects,
|
|
11
|
+
* - `result.finishReason` matches `agent_end.reason`,
|
|
12
|
+
* - `abort()` is idempotent and yields `finishReason: 'aborted'`,
|
|
13
|
+
* - `options.signal` is observed,
|
|
14
|
+
* - `options.eventBus` mirrors the full event stream,
|
|
15
|
+
* - every event carries `source === meta.id`,
|
|
16
|
+
* - the `events` AsyncIterable terminates,
|
|
17
|
+
* - `events` is single-consumer (second iteration attempt throws),
|
|
18
|
+
* - `events` iterator `return()` cleanly closes the stream,
|
|
19
|
+
* - `result` resolves even when `events` is never iterated.
|
|
20
|
+
*
|
|
21
|
+
* Adapters that can synthesize internal-error runs supply `buildErrorConfig`
|
|
22
|
+
* to additionally assert the resolve-not-reject invariant on the error path.
|
|
23
|
+
*
|
|
24
|
+
* @internal
|
|
25
|
+
*/
|
|
26
|
+
import { describe, it, expect } from 'vitest';
|
|
27
|
+
import { createEventBus } from '../event-bus.js';
|
|
28
|
+
/**
|
|
29
|
+
* Run the full conformance suite against an adapter. Registers its own
|
|
30
|
+
* `describe` block.
|
|
31
|
+
*
|
|
32
|
+
* @internal
|
|
33
|
+
*/
|
|
34
|
+
export function runAdapterConformance(opts) {
|
|
35
|
+
const { meta, buildConfig, buildErrorConfig } = opts;
|
|
36
|
+
const timeout = opts.timeoutMs ?? 10_000;
|
|
37
|
+
describe(`AgentAdapter conformance: ${meta.id}`, () => {
|
|
38
|
+
it('emits agent_start as the first event with source === meta.id', async () => {
|
|
39
|
+
const run = meta.adapter(buildConfig());
|
|
40
|
+
const events = await collectEvents(run);
|
|
41
|
+
expect(events.length).toBeGreaterThan(0);
|
|
42
|
+
expect(events[0].type).toBe('agent_start');
|
|
43
|
+
expect(events[0].source).toBe(meta.id);
|
|
44
|
+
await run.result;
|
|
45
|
+
}, timeout);
|
|
46
|
+
it('emits exactly one agent_end and it is the last event', async () => {
|
|
47
|
+
const run = meta.adapter(buildConfig());
|
|
48
|
+
const events = await collectEvents(run);
|
|
49
|
+
const ends = events.filter((e) => e.type === 'agent_end');
|
|
50
|
+
expect(ends).toHaveLength(1);
|
|
51
|
+
expect(events[events.length - 1].type).toBe('agent_end');
|
|
52
|
+
await run.result;
|
|
53
|
+
}, timeout);
|
|
54
|
+
it('result resolves and never rejects', async () => {
|
|
55
|
+
const run = meta.adapter(buildConfig());
|
|
56
|
+
// Drain events in parallel so result can settle.
|
|
57
|
+
const [, result] = await Promise.all([collectEvents(run), run.result]);
|
|
58
|
+
expect(result).toBeDefined();
|
|
59
|
+
// Sanity: finishReason is one of the known values.
|
|
60
|
+
expect(typeof result.finishReason).toBe('string');
|
|
61
|
+
}, timeout);
|
|
62
|
+
it('result.finishReason matches agent_end.reason', async () => {
|
|
63
|
+
const run = meta.adapter(buildConfig());
|
|
64
|
+
const [events, result] = await Promise.all([collectEvents(run), run.result]);
|
|
65
|
+
const end = events.find((e) => e.type === 'agent_end');
|
|
66
|
+
expect(end).toBeDefined();
|
|
67
|
+
if (end && end.type === 'agent_end') {
|
|
68
|
+
expect(end.reason).toBe(result.finishReason);
|
|
69
|
+
}
|
|
70
|
+
}, timeout);
|
|
71
|
+
it('abort() is idempotent and produces finishReason: "aborted"', async () => {
|
|
72
|
+
const run = meta.adapter(buildConfig());
|
|
73
|
+
// Abort synchronously so adapters of any speed observe it before
|
|
74
|
+
// they finish. Real consumers that abort mid-run hit a slower path;
|
|
75
|
+
// the invariant we care about here is "abort wins, twice is fine".
|
|
76
|
+
run.abort();
|
|
77
|
+
run.abort(); // second call must not throw
|
|
78
|
+
const [, result] = await Promise.all([collectEvents(run), run.result]);
|
|
79
|
+
expect(result.finishReason).toBe('aborted');
|
|
80
|
+
}, timeout);
|
|
81
|
+
it('honors AbortSignal from options', async () => {
|
|
82
|
+
const controller = new AbortController();
|
|
83
|
+
controller.abort();
|
|
84
|
+
const options = { signal: controller.signal };
|
|
85
|
+
const run = meta.adapter(buildConfig(), options);
|
|
86
|
+
const [, result] = await Promise.all([collectEvents(run), run.result]);
|
|
87
|
+
expect(result.finishReason).toBe('aborted');
|
|
88
|
+
}, timeout);
|
|
89
|
+
it('mirrors every event to options.eventBus', async () => {
|
|
90
|
+
const bus = createEventBus();
|
|
91
|
+
const seen = [];
|
|
92
|
+
bus.on((event) => {
|
|
93
|
+
seen.push(event);
|
|
94
|
+
});
|
|
95
|
+
const run = meta.adapter(buildConfig(), { eventBus: bus });
|
|
96
|
+
const [streamed] = await Promise.all([collectEvents(run), run.result]);
|
|
97
|
+
// Bus must observe at least every type the stream did. The contract
|
|
98
|
+
// is "all events mirrored" — assert equal counts per type to avoid
|
|
99
|
+
// ordering subtleties between sync emit and async iteration.
|
|
100
|
+
expect(seen.length).toBe(streamed.length);
|
|
101
|
+
const streamTypes = streamed.map((e) => e.type).sort();
|
|
102
|
+
const busTypes = seen.map((e) => e.type).sort();
|
|
103
|
+
expect(busTypes).toEqual(streamTypes);
|
|
104
|
+
}, timeout);
|
|
105
|
+
it('every event has source === meta.id', async () => {
|
|
106
|
+
const run = meta.adapter(buildConfig());
|
|
107
|
+
const [events] = await Promise.all([collectEvents(run), run.result]);
|
|
108
|
+
for (const event of events) {
|
|
109
|
+
expect(event.source).toBe(meta.id);
|
|
110
|
+
}
|
|
111
|
+
}, timeout);
|
|
112
|
+
it('events AsyncIterable terminates', async () => {
|
|
113
|
+
const run = meta.adapter(buildConfig());
|
|
114
|
+
// collectEvents itself iterates to done — if it returns, the
|
|
115
|
+
// iterable terminated. Add an explicit timeout as a guard.
|
|
116
|
+
const events = await withTimeout(collectEvents(run), timeout, 'events iterable did not terminate');
|
|
117
|
+
expect(Array.isArray(events)).toBe(true);
|
|
118
|
+
await run.result;
|
|
119
|
+
}, timeout);
|
|
120
|
+
it('events is single-consumer — second iteration attempt throws', async () => {
|
|
121
|
+
const run = meta.adapter(buildConfig());
|
|
122
|
+
// First call must succeed.
|
|
123
|
+
run.events[Symbol.asyncIterator]();
|
|
124
|
+
// Second call must throw synchronously — splitting the stream
|
|
125
|
+
// across two consumers is a silent bug, so the protocol fails
|
|
126
|
+
// loudly. Callers wanting multi-cast wire AgentEventBus instead.
|
|
127
|
+
expect(() => run.events[Symbol.asyncIterator]()).toThrow();
|
|
128
|
+
// Drain so the run completes before the test ends.
|
|
129
|
+
await run.result.catch(() => undefined);
|
|
130
|
+
}, timeout);
|
|
131
|
+
it('events iterator return() cleanly closes the stream', async () => {
|
|
132
|
+
const run = meta.adapter(buildConfig());
|
|
133
|
+
const iter = run.events[Symbol.asyncIterator]();
|
|
134
|
+
// Pull at least one event so the run is in flight, then abandon.
|
|
135
|
+
await withTimeout(iter.next(), timeout, 'first next() did not resolve');
|
|
136
|
+
await iter.return?.();
|
|
137
|
+
// Invariant: result still resolves. Whether the run was aborted
|
|
138
|
+
// by the early return is an adapter-design choice (mockAgent
|
|
139
|
+
// aborts; inferenceAgent lets the run complete) — but `result`
|
|
140
|
+
// must not deadlock either way.
|
|
141
|
+
const result = await withTimeout(run.result, timeout, 'result did not resolve after iterator.return()');
|
|
142
|
+
expect(result).toBeDefined();
|
|
143
|
+
}, timeout);
|
|
144
|
+
it('result resolves even when events is never iterated', async () => {
|
|
145
|
+
const run = meta.adapter(buildConfig());
|
|
146
|
+
// No collectEvents call — adapters that block on consumption
|
|
147
|
+
// would deadlock here. The protocol requires events to queue
|
|
148
|
+
// (or drop) without blocking the producer.
|
|
149
|
+
const result = await withTimeout(run.result, timeout, 'result did not resolve without events iteration');
|
|
150
|
+
expect(result).toBeDefined();
|
|
151
|
+
}, timeout);
|
|
152
|
+
if (buildErrorConfig) {
|
|
153
|
+
it('result resolves rather than rejects on adapter-internal error', async () => {
|
|
154
|
+
const run = meta.adapter(buildErrorConfig());
|
|
155
|
+
let threw = false;
|
|
156
|
+
let result;
|
|
157
|
+
try {
|
|
158
|
+
const [collected, r] = await Promise.all([collectEvents(run), run.result]);
|
|
159
|
+
result = r;
|
|
160
|
+
const errorBeforeEnd = collected.some((e, i) => e.type === 'error' &&
|
|
161
|
+
collected.findIndex((x) => x.type === 'agent_end') > i);
|
|
162
|
+
expect(errorBeforeEnd).toBe(true);
|
|
163
|
+
}
|
|
164
|
+
catch {
|
|
165
|
+
threw = true;
|
|
166
|
+
}
|
|
167
|
+
expect(threw).toBe(false);
|
|
168
|
+
expect(result?.finishReason).toBe('error');
|
|
169
|
+
}, timeout);
|
|
170
|
+
}
|
|
171
|
+
if (meta.capabilities.resumption !== 'none') {
|
|
172
|
+
it('agent_start or agent_end carries a resumeToken whose kind matches the declared resumption', async () => {
|
|
173
|
+
const run = meta.adapter(buildConfig());
|
|
174
|
+
const [events] = await Promise.all([collectEvents(run), run.result]);
|
|
175
|
+
const lifecycle = events.filter((e) => e.type === 'agent_start' || e.type === 'agent_end');
|
|
176
|
+
const token = lifecycle.map((e) => e.resumeToken).find((t) => t !== undefined);
|
|
177
|
+
expect(token).toBeDefined();
|
|
178
|
+
if (token) {
|
|
179
|
+
expect(token.kind).toBe(meta.capabilities.resumption);
|
|
180
|
+
}
|
|
181
|
+
}, timeout);
|
|
182
|
+
}
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
// ---------------------------------------------------------------------------
|
|
186
|
+
// helpers
|
|
187
|
+
// ---------------------------------------------------------------------------
|
|
188
|
+
async function collectEvents(run) {
|
|
189
|
+
const out = [];
|
|
190
|
+
for await (const event of run.events) {
|
|
191
|
+
out.push(event);
|
|
192
|
+
}
|
|
193
|
+
return out;
|
|
194
|
+
}
|
|
195
|
+
function withTimeout(p, ms, label) {
|
|
196
|
+
return new Promise((resolve, reject) => {
|
|
197
|
+
const t = setTimeout(() => reject(new Error(`timeout: ${label} after ${ms}ms`)), ms);
|
|
198
|
+
p.then((v) => {
|
|
199
|
+
clearTimeout(t);
|
|
200
|
+
resolve(v);
|
|
201
|
+
}, (e) => {
|
|
202
|
+
clearTimeout(t);
|
|
203
|
+
reject(e);
|
|
204
|
+
});
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
//# sourceMappingURL=conformance.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"conformance.js","sourceRoot":"","sources":["../../../src/agents/test-utils/conformance.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAO9C,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AA6BjD;;;;;GAKG;AACH,MAAM,UAAU,qBAAqB,CACnC,IAAyC;IAEzC,MAAM,EAAE,IAAI,EAAE,WAAW,EAAE,gBAAgB,EAAE,GAAG,IAAI,CAAC;IACrD,MAAM,OAAO,GAAG,IAAI,CAAC,SAAS,IAAI,MAAM,CAAC;IAEzC,QAAQ,CAAC,6BAA6B,IAAI,CAAC,EAAE,EAAE,EAAE,GAAG,EAAE;QACpD,EAAE,CACA,8DAA8D,EAC9D,KAAK,IAAI,EAAE;YACT,MAAM,GAAG,GAAG,IAAI,CAAC,OAAO,CAAC,WAAW,EAAE,CAAC,CAAC;YACxC,MAAM,MAAM,GAAG,MAAM,aAAa,CAAC,GAAG,CAAC,CAAC;YACxC,MAAM,CAAC,MAAM,CAAC,M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AAW,CAAI,CAAa,EAAE,EAAU,EAAE,KAAa;IAC9D,OAAO,IAAI,OAAO,CAAI,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACxC,MAAM,CAAC,GAAG,UAAU,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,YAAY,KAAK,UAAU,EAAE,IAAI,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;QACrF,CAAC,CAAC,IAAI,CACJ,CAAC,CAAC,EAAE,EAAE;YACJ,YAAY,CAAC,CAAC,CAAC,CAAC;YAChB,OAAO,CAAC,CAAC,CAAC,CAAC;QACb,CAAC,EACD,CAAC,CAAC,EAAE,EAAE;YACJ,YAAY,CAAC,CAAC,CAAC,CAAC;YAChB,MAAM,CAAC,CAAC,CAAC,CAAC;QACZ,CAAC,CACF,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Test utilities for the AgentAdapter protocol.
|
|
3
|
+
*
|
|
4
|
+
* Importers (in-tree tests and the sibling `@autonome-research/thread-phase-agents` package)
|
|
5
|
+
* pull `createMockAgent` for scripted adapter behavior and
|
|
6
|
+
* `runAdapterConformance` for protocol-contract assertions.
|
|
7
|
+
*
|
|
8
|
+
* @internal
|
|
9
|
+
*/
|
|
10
|
+
export { createMockAgent, MOCK_DEFAULT_CAPABILITIES, type CreateMockAgentOptions, type MockAgentConfig, } from './mock-agent.js';
|
|
11
|
+
export { runAdapterConformance, type ConformanceConfigBuilder, type RunConformanceSuiteOptions, } from './conformance.js';
|
|
12
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/agents/test-utils/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EACL,eAAe,EACf,yBAAyB,EACzB,KAAK,sBAAsB,EAC3B,KAAK,eAAe,GACrB,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EACL,qBAAqB,EACrB,KAAK,wBAAwB,EAC7B,KAAK,0BAA0B,GAChC,MAAM,kBAAkB,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Test utilities for the AgentAdapter protocol.
|
|
3
|
+
*
|
|
4
|
+
* Importers (in-tree tests and the sibling `@autonome-research/thread-phase-agents` package)
|
|
5
|
+
* pull `createMockAgent` for scripted adapter behavior and
|
|
6
|
+
* `runAdapterConformance` for protocol-contract assertions.
|
|
7
|
+
*
|
|
8
|
+
* @internal
|
|
9
|
+
*/
|
|
10
|
+
export { createMockAgent, MOCK_DEFAULT_CAPABILITIES, } from './mock-agent.js';
|
|
11
|
+
export { runAdapterConformance, } from './conformance.js';
|
|
12
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/agents/test-utils/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EACL,eAAe,EACf,yBAAyB,GAG1B,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EACL,qBAAqB,GAGtB,MAAM,kBAAkB,CAAC"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Scripted `AgentAdapter` for tests.
|
|
3
|
+
*
|
|
4
|
+
* `createMockAgent` returns a `AgentAdapterMeta` whose adapter replays a
|
|
5
|
+
* configured sequence of `AgentEvent`s and resolves with a configured
|
|
6
|
+
* `AgentRunResult`. The mock honors the protocol's lifecycle invariants:
|
|
7
|
+
* exactly one `agent_start`, exactly one trailing `agent_end`, `result`
|
|
8
|
+
* always resolves, `abort()` is idempotent, `options.signal` is observed.
|
|
9
|
+
*
|
|
10
|
+
* Used by in-tree tests targeting the AgentAdapter surface and by the
|
|
11
|
+
* conformance suite as the self-test adapter.
|
|
12
|
+
*
|
|
13
|
+
* @internal
|
|
14
|
+
*/
|
|
15
|
+
import { type AgentAdapterMeta, type AgentCapabilities, type AgentEvent, type AgentRunResult } from '../protocol.js';
|
|
16
|
+
/**
|
|
17
|
+
* Scripted invocation of the mock adapter. The adapter emits exactly the
|
|
18
|
+
* events in `events`, in order, then resolves `result` with the scripted
|
|
19
|
+
* value. Lifecycle events (`agent_start`, `agent_end`) are added by the
|
|
20
|
+
* adapter — do not include them in `events`.
|
|
21
|
+
*
|
|
22
|
+
* @internal
|
|
23
|
+
*/
|
|
24
|
+
export interface MockAgentConfig {
|
|
25
|
+
/** Events to emit, in order. Should NOT include agent_start or agent_end. */
|
|
26
|
+
events: ReadonlyArray<AgentEvent>;
|
|
27
|
+
/** Final result. agent_end.reason will mirror result.finishReason. */
|
|
28
|
+
result: AgentRunResult;
|
|
29
|
+
/**
|
|
30
|
+
* Delay in ms between scripted events. 0 = a microtask hop per event.
|
|
31
|
+
* Default 0. Use a positive value to exercise consumers that need to
|
|
32
|
+
* interleave with async work.
|
|
33
|
+
*/
|
|
34
|
+
perEventDelayMs?: number;
|
|
35
|
+
/**
|
|
36
|
+
* If set, the adapter throws this when called. Used to test how callers
|
|
37
|
+
* handle adapter-construction-time failures (vs run-time errors which
|
|
38
|
+
* should still resolve `result`).
|
|
39
|
+
*/
|
|
40
|
+
throwOnConstruct?: Error;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Override knobs for the mock adapter's metadata. Defaults match a minimal
|
|
44
|
+
* adapter: `streaming: 'text'`, `cancellation: 'cooperative'`,
|
|
45
|
+
* `resumption: 'none'`, `structuredOutput: 'none'`.
|
|
46
|
+
*
|
|
47
|
+
* @internal
|
|
48
|
+
*/
|
|
49
|
+
export interface CreateMockAgentOptions {
|
|
50
|
+
id?: string;
|
|
51
|
+
capabilities?: Partial<AgentCapabilities>;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Default capabilities used when none are overridden.
|
|
55
|
+
*
|
|
56
|
+
* @internal
|
|
57
|
+
*/
|
|
58
|
+
export declare const MOCK_DEFAULT_CAPABILITIES: AgentCapabilities;
|
|
59
|
+
/**
|
|
60
|
+
* Build a mock adapter suitable for testing pattern code and any consumer
|
|
61
|
+
* targeting the AgentAdapter protocol.
|
|
62
|
+
*
|
|
63
|
+
* @internal
|
|
64
|
+
*/
|
|
65
|
+
export declare function createMockAgent(opts?: CreateMockAgentOptions): AgentAdapterMeta<MockAgentConfig>;
|
|
66
|
+
//# sourceMappingURL=mock-agent.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mock-agent.d.ts","sourceRoot":"","sources":["../../../src/agents/test-utils/mock-agent.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAEL,KAAK,gBAAgB,EACrB,KAAK,iBAAiB,EACtB,KAAK,UAAU,EAGf,KAAK,cAAc,EACpB,MAAM,gBAAgB,CAAC;AAExB;;;;;;;GAOG;AACH,MAAM,WAAW,eAAe;IAC9B,6EAA6E;IAC7E,MAAM,EAAE,aAAa,CAAC,UAAU,CAAC,CAAC;IAClC,sEAAsE;IACtE,MAAM,EAAE,cAAc,CAAC;IACvB;;;;OAIG;IACH,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB;;;;OAIG;IACH,gBAAgB,CAAC,EAAE,KAAK,CAAC;CAC1B;AAED;;;;;;GAMG;AACH,MAAM,WAAW,sBAAsB;IACrC,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,YAAY,CAAC,EAAE,OAAO,CAAC,iBAAiB,CAAC,CAAC;CAC3C;AAED;;;;GAIG;AACH,eAAO,MAAM,yBAAyB,EAAE,iBAKvC,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,eAAe,CAC7B,IAAI,GAAE,sBAA2B,GAChC,gBAAgB,CAAC,eAAe,CAAC,CAuMnC"}
|