agentfootprint 10.2.0 → 10.3.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/CAPABILITIES.md +1 -0
- package/dist/adapters/llm/AnthropicProvider.js +11 -2
- package/dist/adapters/llm/AnthropicProvider.js.map +1 -1
- package/dist/adapters/llm/BrowserAnthropicProvider.js +11 -2
- package/dist/adapters/llm/BrowserAnthropicProvider.js.map +1 -1
- package/dist/adapters/llm/MockProvider.js +11 -1
- package/dist/adapters/llm/MockProvider.js.map +1 -1
- package/dist/adapters/llm/anthropicMessagesWire.js +19 -0
- package/dist/adapters/llm/anthropicMessagesWire.js.map +1 -1
- package/dist/adapters/llm/anthropicModels.js +48 -14
- package/dist/adapters/llm/anthropicModels.js.map +1 -1
- package/dist/adapters/llm/wireManifest.js +8 -2
- package/dist/adapters/llm/wireManifest.js.map +1 -1
- package/dist/adapters/nativeOutputSchema.js +80 -0
- package/dist/adapters/nativeOutputSchema.js.map +1 -0
- package/dist/adapters/requestRefusal.js +2 -0
- package/dist/adapters/requestRefusal.js.map +1 -1
- package/dist/adapters/types.js.map +1 -1
- package/dist/core/Agent.js +74 -22
- package/dist/core/Agent.js.map +1 -1
- package/dist/core/agent/AgentBuilder.js +23 -0
- package/dist/core/agent/AgentBuilder.js.map +1 -1
- package/dist/core/agent/buildDynamicAgentChart.js +5 -0
- package/dist/core/agent/buildDynamicAgentChart.js.map +1 -1
- package/dist/core/agent/findings/reserved.js +50 -1
- package/dist/core/agent/findings/reserved.js.map +1 -1
- package/dist/core/agent/nativeOutputFormat.js +389 -0
- package/dist/core/agent/nativeOutputFormat.js.map +1 -0
- package/dist/core/agent/outputEnforcement.js +35 -1
- package/dist/core/agent/outputEnforcement.js.map +1 -1
- package/dist/core/agent/stages/answerValidation.js +14 -4
- package/dist/core/agent/stages/answerValidation.js.map +1 -1
- package/dist/core/agent/stages/callLLM.js +24 -0
- package/dist/core/agent/stages/callLLM.js.map +1 -1
- package/dist/core/agent/stages/outputRetry.js +1 -0
- package/dist/core/agent/stages/outputRetry.js.map +1 -1
- package/dist/core/agent/stages/route.js +33 -10
- package/dist/core/agent/stages/route.js.map +1 -1
- package/dist/core/outputSchema.js.map +1 -1
- package/dist/esm/adapters/llm/AnthropicProvider.d.ts +3 -0
- package/dist/esm/adapters/llm/AnthropicProvider.js +12 -3
- package/dist/esm/adapters/llm/AnthropicProvider.js.map +1 -1
- package/dist/esm/adapters/llm/BrowserAnthropicProvider.d.ts +3 -0
- package/dist/esm/adapters/llm/BrowserAnthropicProvider.js +12 -3
- package/dist/esm/adapters/llm/BrowserAnthropicProvider.js.map +1 -1
- package/dist/esm/adapters/llm/MockProvider.d.ts +7 -0
- package/dist/esm/adapters/llm/MockProvider.js +11 -1
- package/dist/esm/adapters/llm/MockProvider.js.map +1 -1
- package/dist/esm/adapters/llm/anthropicMessagesWire.d.ts +13 -0
- package/dist/esm/adapters/llm/anthropicMessagesWire.js +19 -0
- package/dist/esm/adapters/llm/anthropicMessagesWire.js.map +1 -1
- package/dist/esm/adapters/llm/anthropicModels.d.ts +36 -3
- package/dist/esm/adapters/llm/anthropicModels.js +46 -13
- package/dist/esm/adapters/llm/anthropicModels.js.map +1 -1
- package/dist/esm/adapters/llm/wireManifest.d.ts +9 -1
- package/dist/esm/adapters/llm/wireManifest.js +8 -2
- package/dist/esm/adapters/llm/wireManifest.js.map +1 -1
- package/dist/esm/adapters/nativeOutputSchema.d.ts +66 -0
- package/dist/esm/adapters/nativeOutputSchema.js +75 -0
- package/dist/esm/adapters/nativeOutputSchema.js.map +1 -0
- package/dist/esm/adapters/requestRefusal.js +2 -0
- package/dist/esm/adapters/requestRefusal.js.map +1 -1
- package/dist/esm/adapters/types.d.ts +40 -0
- package/dist/esm/adapters/types.js.map +1 -1
- package/dist/esm/core/Agent.d.ts +16 -0
- package/dist/esm/core/Agent.js +74 -22
- package/dist/esm/core/Agent.js.map +1 -1
- package/dist/esm/core/agent/AgentBuilder.js +23 -0
- package/dist/esm/core/agent/AgentBuilder.js.map +1 -1
- package/dist/esm/core/agent/buildDynamicAgentChart.js +5 -0
- package/dist/esm/core/agent/buildDynamicAgentChart.js.map +1 -1
- package/dist/esm/core/agent/findings/reserved.d.ts +16 -0
- package/dist/esm/core/agent/findings/reserved.js +48 -0
- package/dist/esm/core/agent/findings/reserved.js.map +1 -1
- package/dist/esm/core/agent/nativeOutputFormat.d.ts +85 -0
- package/dist/esm/core/agent/nativeOutputFormat.js +384 -0
- package/dist/esm/core/agent/nativeOutputFormat.js.map +1 -0
- package/dist/esm/core/agent/outputEnforcement.d.ts +33 -1
- package/dist/esm/core/agent/outputEnforcement.js +33 -0
- package/dist/esm/core/agent/outputEnforcement.js.map +1 -1
- package/dist/esm/core/agent/stages/answerValidation.d.ts +1 -1
- package/dist/esm/core/agent/stages/answerValidation.js +14 -4
- package/dist/esm/core/agent/stages/answerValidation.js.map +1 -1
- package/dist/esm/core/agent/stages/callLLM.d.ts +9 -1
- package/dist/esm/core/agent/stages/callLLM.js +24 -0
- package/dist/esm/core/agent/stages/callLLM.js.map +1 -1
- package/dist/esm/core/agent/stages/outputRetry.js +1 -0
- package/dist/esm/core/agent/stages/outputRetry.js.map +1 -1
- package/dist/esm/core/agent/stages/route.js +34 -11
- package/dist/esm/core/agent/stages/route.js.map +1 -1
- package/dist/esm/core/agent/types.d.ts +19 -3
- package/dist/esm/core/outputSchema.d.ts +30 -3
- package/dist/esm/core/outputSchema.js.map +1 -1
- package/dist/esm/lib/time-travel/receipt.d.ts +11 -0
- package/dist/esm/lib/time-travel/receipt.js +8 -2
- package/dist/esm/lib/time-travel/receipt.js.map +1 -1
- package/dist/esm/providers.d.ts +1 -0
- package/dist/esm/providers.js +1 -0
- package/dist/esm/providers.js.map +1 -1
- package/dist/esm/resilience/withCircuitBreaker.js +7 -0
- package/dist/esm/resilience/withCircuitBreaker.js.map +1 -1
- package/dist/esm/resilience/withFallback.js +10 -0
- package/dist/esm/resilience/withFallback.js.map +1 -1
- package/dist/esm/resilience/withRetry.js +8 -0
- package/dist/esm/resilience/withRetry.js.map +1 -1
- package/dist/lib/time-travel/receipt.js +8 -2
- package/dist/lib/time-travel/receipt.js.map +1 -1
- package/dist/providers.js +4 -1
- package/dist/providers.js.map +1 -1
- package/dist/resilience/withCircuitBreaker.js +7 -0
- package/dist/resilience/withCircuitBreaker.js.map +1 -1
- package/dist/resilience/withFallback.js +10 -0
- package/dist/resilience/withFallback.js.map +1 -1
- package/dist/resilience/withRetry.js +8 -0
- package/dist/resilience/withRetry.js.map +1 -1
- package/dist/types/adapters/llm/AnthropicProvider.d.ts +3 -0
- package/dist/types/adapters/llm/AnthropicProvider.d.ts.map +1 -1
- package/dist/types/adapters/llm/BrowserAnthropicProvider.d.ts +3 -0
- package/dist/types/adapters/llm/BrowserAnthropicProvider.d.ts.map +1 -1
- package/dist/types/adapters/llm/MockProvider.d.ts +7 -0
- package/dist/types/adapters/llm/MockProvider.d.ts.map +1 -1
- package/dist/types/adapters/llm/anthropicMessagesWire.d.ts +13 -0
- package/dist/types/adapters/llm/anthropicMessagesWire.d.ts.map +1 -1
- package/dist/types/adapters/llm/anthropicModels.d.ts +36 -3
- package/dist/types/adapters/llm/anthropicModels.d.ts.map +1 -1
- package/dist/types/adapters/llm/wireManifest.d.ts +9 -1
- package/dist/types/adapters/llm/wireManifest.d.ts.map +1 -1
- package/dist/types/adapters/nativeOutputSchema.d.ts +67 -0
- package/dist/types/adapters/nativeOutputSchema.d.ts.map +1 -0
- package/dist/types/adapters/requestRefusal.d.ts.map +1 -1
- package/dist/types/adapters/types.d.ts +40 -0
- package/dist/types/adapters/types.d.ts.map +1 -1
- package/dist/types/core/Agent.d.ts +16 -0
- package/dist/types/core/Agent.d.ts.map +1 -1
- package/dist/types/core/agent/AgentBuilder.d.ts.map +1 -1
- package/dist/types/core/agent/buildDynamicAgentChart.d.ts.map +1 -1
- package/dist/types/core/agent/findings/reserved.d.ts +16 -0
- package/dist/types/core/agent/findings/reserved.d.ts.map +1 -1
- package/dist/types/core/agent/nativeOutputFormat.d.ts +86 -0
- package/dist/types/core/agent/nativeOutputFormat.d.ts.map +1 -0
- package/dist/types/core/agent/outputEnforcement.d.ts +33 -1
- package/dist/types/core/agent/outputEnforcement.d.ts.map +1 -1
- package/dist/types/core/agent/stages/answerValidation.d.ts +1 -1
- package/dist/types/core/agent/stages/answerValidation.d.ts.map +1 -1
- package/dist/types/core/agent/stages/callLLM.d.ts +9 -1
- package/dist/types/core/agent/stages/callLLM.d.ts.map +1 -1
- package/dist/types/core/agent/stages/outputRetry.d.ts.map +1 -1
- package/dist/types/core/agent/stages/route.d.ts.map +1 -1
- package/dist/types/core/agent/types.d.ts +19 -3
- package/dist/types/core/agent/types.d.ts.map +1 -1
- package/dist/types/core/outputSchema.d.ts +30 -3
- package/dist/types/core/outputSchema.d.ts.map +1 -1
- package/dist/types/lib/time-travel/receipt.d.ts +11 -0
- package/dist/types/lib/time-travel/receipt.d.ts.map +1 -1
- package/dist/types/providers.d.ts +1 -0
- package/dist/types/providers.d.ts.map +1 -1
- package/dist/types/resilience/withCircuitBreaker.d.ts.map +1 -1
- package/dist/types/resilience/withFallback.d.ts.map +1 -1
- package/dist/types/resilience/withRetry.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* nativeOutputFormat — the ONE builder of the JSON Schema that
|
|
3
|
+
* `.outputSchema(parser, { strategy: 'native' })` sends as the provider's
|
|
4
|
+
* structured-output format (Anthropic's `output_config.format`).
|
|
5
|
+
*
|
|
6
|
+
* Pattern: pure transform over plain JSON, run once at build
|
|
7
|
+
* (`AgentBuilder · resolveOutputEnforcement`); no scope, no I/O.
|
|
8
|
+
* Role: core/ agent leaf. Its input is the SAME schema the `'tool-forced'`
|
|
9
|
+
* strategy puts on its synthetic tool (`outputEnforcement.ts ·
|
|
10
|
+
* resolveJsonSchema`: the `jsonSchema` option, else the parser's own
|
|
11
|
+
* `toJsonSchema()`), and the SAME parser judges every answer after —
|
|
12
|
+
* so the wire copy may be looser than the contract, never different
|
|
13
|
+
* from it.
|
|
14
|
+
*
|
|
15
|
+
* THE RULES, from Anthropic's structured-outputs page ("JSON Schema
|
|
16
|
+
* limitations", fetched 2026-10-14 —
|
|
17
|
+
* https://platform.claude.com/docs/en/build-with-claude/structured-outputs),
|
|
18
|
+
* and the shape of the SDK's own transform (`@anthropic-ai/sdk` ·
|
|
19
|
+
* `transformJSONSchema`, which moves what the API does not take into the
|
|
20
|
+
* description):
|
|
21
|
+
* - KEPT: `type`, `properties`, `required`, `items`, `anyOf`, `allOf`,
|
|
22
|
+
* local `$ref` with `$defs` / `definitions`, `enum` and `const` of
|
|
23
|
+
* scalars, `default`, `description`, `title`, the ten supported string
|
|
24
|
+
* `format`s, `minItems` of 0 or 1, and a `pattern` with no backreference,
|
|
25
|
+
* lookaround or word boundary. `oneOf` is sent as `anyOf`.
|
|
26
|
+
* - CLOSED: every object gets `additionalProperties: false` — the only value
|
|
27
|
+
* the API takes.
|
|
28
|
+
* - MOVED INTO THE DESCRIPTION, on the wire copy only: every constraint the
|
|
29
|
+
* API does not take (`minimum`, `maximum`, `multipleOf`, `minLength`,
|
|
30
|
+
* `maxLength`, `minItems` above 1 — sent as 1 —, `maxItems`, an
|
|
31
|
+
* unsupported `format` or `pattern`, …). The model still reads them; the
|
|
32
|
+
* parser still enforces them.
|
|
33
|
+
* - REFUSED BY NAME (`NativeOutputSchemaError`): what the API cannot express
|
|
34
|
+
* — a recursive schema, an external or dangling `$ref` (checked on the
|
|
35
|
+
* source AND on the wire copy, whose renamed paths a reference could
|
|
36
|
+
* miss), an `enum` or `const` holding an object or array, `allOf` beside
|
|
37
|
+
* a `$ref`, a node with no type (an open `unknown` value), and an object
|
|
38
|
+
* with open keys (`additionalProperties` given a schema, `true` or `{}`
|
|
39
|
+
* on an object naming no properties, a bare `{ type: 'object' }`, or
|
|
40
|
+
* `patternProperties`: closing it would make every map empty while the
|
|
41
|
+
* parser accepted it).
|
|
42
|
+
* - DROPPED: the meta keys `$schema`, `$id`, `$comment`, `$anchor`.
|
|
43
|
+
*
|
|
44
|
+
* THE RESERVED `_findings` KEY. With `.findings()` armed, the instruction tells
|
|
45
|
+
* the model it may carry its standings on a JSON answer as a top-level
|
|
46
|
+
* `_findings.previous`. Under `additionalProperties: false` a key the schema
|
|
47
|
+
* does not name cannot be written at all, so the answer standings would stop
|
|
48
|
+
* without a sound. Armed, the root gains the optional `_findings` property
|
|
49
|
+
* the served contract allows (`findings/reserved.ts · findingsAnswerSchema`) —
|
|
50
|
+
* unless the author's schema names its own `_findings`, which wins; a root
|
|
51
|
+
* that is not an object cannot carry it and is refused. Unarmed, the schema
|
|
52
|
+
* is the author's alone.
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* nativeOutputFormat(
|
|
56
|
+
* { type: 'object', properties: { n: { type: 'integer', minimum: 1 } }, required: ['n'] },
|
|
57
|
+
* { findings: false },
|
|
58
|
+
* );
|
|
59
|
+
* // { type: 'json_schema', schema: { type: 'object',
|
|
60
|
+
* // properties: { n: { type: 'integer', description: '{minimum: 1}' } },
|
|
61
|
+
* // required: ['n'], additionalProperties: false } }
|
|
62
|
+
*/
|
|
63
|
+
type Json = Readonly<Record<string, unknown>>;
|
|
64
|
+
/** What `LLMRequest.outputFormat` carries. */
|
|
65
|
+
export interface NativeOutputFormat {
|
|
66
|
+
readonly type: 'json_schema';
|
|
67
|
+
readonly schema: Json;
|
|
68
|
+
}
|
|
69
|
+
/** A schema the provider's structured output cannot express, named. */
|
|
70
|
+
export declare class NativeOutputSchemaError extends Error {
|
|
71
|
+
/** JSON-pointer-like path of the node refused (`'#'` is the root). */
|
|
72
|
+
readonly path: string;
|
|
73
|
+
constructor(path: string, reason: string);
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* The structured-output format for `jsonSchema`, made API-compatible as the
|
|
77
|
+
* file header lists, with the reserved `_findings` property when the findings
|
|
78
|
+
* ledger is armed. Deep-frozen; the input is never edited.
|
|
79
|
+
*
|
|
80
|
+
* @throws NativeOutputSchemaError naming the node the API cannot express.
|
|
81
|
+
*/
|
|
82
|
+
export declare function nativeOutputFormat(jsonSchema: Json, arms: {
|
|
83
|
+
readonly findings: boolean;
|
|
84
|
+
}): NativeOutputFormat;
|
|
85
|
+
export {};
|
|
@@ -0,0 +1,384 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* nativeOutputFormat — the ONE builder of the JSON Schema that
|
|
3
|
+
* `.outputSchema(parser, { strategy: 'native' })` sends as the provider's
|
|
4
|
+
* structured-output format (Anthropic's `output_config.format`).
|
|
5
|
+
*
|
|
6
|
+
* Pattern: pure transform over plain JSON, run once at build
|
|
7
|
+
* (`AgentBuilder · resolveOutputEnforcement`); no scope, no I/O.
|
|
8
|
+
* Role: core/ agent leaf. Its input is the SAME schema the `'tool-forced'`
|
|
9
|
+
* strategy puts on its synthetic tool (`outputEnforcement.ts ·
|
|
10
|
+
* resolveJsonSchema`: the `jsonSchema` option, else the parser's own
|
|
11
|
+
* `toJsonSchema()`), and the SAME parser judges every answer after —
|
|
12
|
+
* so the wire copy may be looser than the contract, never different
|
|
13
|
+
* from it.
|
|
14
|
+
*
|
|
15
|
+
* THE RULES, from Anthropic's structured-outputs page ("JSON Schema
|
|
16
|
+
* limitations", fetched 2026-10-14 —
|
|
17
|
+
* https://platform.claude.com/docs/en/build-with-claude/structured-outputs),
|
|
18
|
+
* and the shape of the SDK's own transform (`@anthropic-ai/sdk` ·
|
|
19
|
+
* `transformJSONSchema`, which moves what the API does not take into the
|
|
20
|
+
* description):
|
|
21
|
+
* - KEPT: `type`, `properties`, `required`, `items`, `anyOf`, `allOf`,
|
|
22
|
+
* local `$ref` with `$defs` / `definitions`, `enum` and `const` of
|
|
23
|
+
* scalars, `default`, `description`, `title`, the ten supported string
|
|
24
|
+
* `format`s, `minItems` of 0 or 1, and a `pattern` with no backreference,
|
|
25
|
+
* lookaround or word boundary. `oneOf` is sent as `anyOf`.
|
|
26
|
+
* - CLOSED: every object gets `additionalProperties: false` — the only value
|
|
27
|
+
* the API takes.
|
|
28
|
+
* - MOVED INTO THE DESCRIPTION, on the wire copy only: every constraint the
|
|
29
|
+
* API does not take (`minimum`, `maximum`, `multipleOf`, `minLength`,
|
|
30
|
+
* `maxLength`, `minItems` above 1 — sent as 1 —, `maxItems`, an
|
|
31
|
+
* unsupported `format` or `pattern`, …). The model still reads them; the
|
|
32
|
+
* parser still enforces them.
|
|
33
|
+
* - REFUSED BY NAME (`NativeOutputSchemaError`): what the API cannot express
|
|
34
|
+
* — a recursive schema, an external or dangling `$ref` (checked on the
|
|
35
|
+
* source AND on the wire copy, whose renamed paths a reference could
|
|
36
|
+
* miss), an `enum` or `const` holding an object or array, `allOf` beside
|
|
37
|
+
* a `$ref`, a node with no type (an open `unknown` value), and an object
|
|
38
|
+
* with open keys (`additionalProperties` given a schema, `true` or `{}`
|
|
39
|
+
* on an object naming no properties, a bare `{ type: 'object' }`, or
|
|
40
|
+
* `patternProperties`: closing it would make every map empty while the
|
|
41
|
+
* parser accepted it).
|
|
42
|
+
* - DROPPED: the meta keys `$schema`, `$id`, `$comment`, `$anchor`.
|
|
43
|
+
*
|
|
44
|
+
* THE RESERVED `_findings` KEY. With `.findings()` armed, the instruction tells
|
|
45
|
+
* the model it may carry its standings on a JSON answer as a top-level
|
|
46
|
+
* `_findings.previous`. Under `additionalProperties: false` a key the schema
|
|
47
|
+
* does not name cannot be written at all, so the answer standings would stop
|
|
48
|
+
* without a sound. Armed, the root gains the optional `_findings` property
|
|
49
|
+
* the served contract allows (`findings/reserved.ts · findingsAnswerSchema`) —
|
|
50
|
+
* unless the author's schema names its own `_findings`, which wins; a root
|
|
51
|
+
* that is not an object cannot carry it and is refused. Unarmed, the schema
|
|
52
|
+
* is the author's alone.
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* nativeOutputFormat(
|
|
56
|
+
* { type: 'object', properties: { n: { type: 'integer', minimum: 1 } }, required: ['n'] },
|
|
57
|
+
* { findings: false },
|
|
58
|
+
* );
|
|
59
|
+
* // { type: 'json_schema', schema: { type: 'object',
|
|
60
|
+
* // properties: { n: { type: 'integer', description: '{minimum: 1}' } },
|
|
61
|
+
* // required: ['n'], additionalProperties: false } }
|
|
62
|
+
*/
|
|
63
|
+
import { findingsAnswerSchema } from './findings/reserved.js';
|
|
64
|
+
import { RESERVED_ANSWER_KEY } from './findings/types.js';
|
|
65
|
+
/** A schema the provider's structured output cannot express, named. */
|
|
66
|
+
export class NativeOutputSchemaError extends Error {
|
|
67
|
+
/** JSON-pointer-like path of the node refused (`'#'` is the root). */
|
|
68
|
+
path;
|
|
69
|
+
constructor(path, reason) {
|
|
70
|
+
super(`AgentBuilder.outputSchema: strategy 'native' sends the schema as Anthropic's ` +
|
|
71
|
+
`output_config.format, and the node at ${path} cannot be expressed there: ${reason} ` +
|
|
72
|
+
`Change the schema, or use { strategy: 'instruct', retries: N }, which takes any ` +
|
|
73
|
+
`parser and judges the same contract.`);
|
|
74
|
+
this.name = 'NativeOutputSchemaError';
|
|
75
|
+
this.path = path;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
const SUPPORTED_FORMATS = new Set([
|
|
79
|
+
'date-time',
|
|
80
|
+
'time',
|
|
81
|
+
'date',
|
|
82
|
+
'duration',
|
|
83
|
+
'email',
|
|
84
|
+
'hostname',
|
|
85
|
+
'uri',
|
|
86
|
+
'ipv4',
|
|
87
|
+
'ipv6',
|
|
88
|
+
'uuid',
|
|
89
|
+
]);
|
|
90
|
+
const META_KEYS = new Set(['$schema', '$id', '$comment', '$anchor']);
|
|
91
|
+
/** Annotations kept as they are (the docs list `default`; the rest are words). */
|
|
92
|
+
const KEPT_AS_IS = new Set(['description', 'title', 'default', 'required']);
|
|
93
|
+
function isObject(value) {
|
|
94
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
95
|
+
}
|
|
96
|
+
function isObjectNode(node) {
|
|
97
|
+
const type = node.type;
|
|
98
|
+
return (type === 'object' ||
|
|
99
|
+
(Array.isArray(type) && type.includes('object')) ||
|
|
100
|
+
isObject(node.properties));
|
|
101
|
+
}
|
|
102
|
+
/** A pattern the API's regex subset refuses: a backreference, lookaround or word boundary. */
|
|
103
|
+
function unsupportedPattern(pattern) {
|
|
104
|
+
for (let i = 0; i < pattern.length; i++) {
|
|
105
|
+
const ch = pattern[i];
|
|
106
|
+
if (ch === '\\') {
|
|
107
|
+
const next = pattern[i + 1];
|
|
108
|
+
if (next !== undefined && /[1-9kbB]/.test(next))
|
|
109
|
+
return true;
|
|
110
|
+
i++;
|
|
111
|
+
continue;
|
|
112
|
+
}
|
|
113
|
+
if (ch === '(' && pattern[i + 1] === '?') {
|
|
114
|
+
const rest = pattern.slice(i + 2, i + 4);
|
|
115
|
+
if (rest.startsWith('=') || rest.startsWith('!') || rest === '<=' || rest === '<!')
|
|
116
|
+
return true;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
return false;
|
|
120
|
+
}
|
|
121
|
+
function deepFreeze(value) {
|
|
122
|
+
if (typeof value === 'object' && value !== null && !Object.isFrozen(value)) {
|
|
123
|
+
Object.freeze(value);
|
|
124
|
+
for (const child of Object.values(value))
|
|
125
|
+
deepFreeze(child);
|
|
126
|
+
}
|
|
127
|
+
return value;
|
|
128
|
+
}
|
|
129
|
+
// ─── Refusals that need the whole schema: $ref resolution ─────────────
|
|
130
|
+
function resolvePointer(root, ref) {
|
|
131
|
+
if (ref === '#')
|
|
132
|
+
return root;
|
|
133
|
+
if (!ref.startsWith('#/'))
|
|
134
|
+
return undefined;
|
|
135
|
+
let node = root;
|
|
136
|
+
for (const raw of ref.slice(2).split('/')) {
|
|
137
|
+
let key;
|
|
138
|
+
try {
|
|
139
|
+
key = decodeURIComponent(raw).replace(/~1/g, '/').replace(/~0/g, '~');
|
|
140
|
+
}
|
|
141
|
+
catch {
|
|
142
|
+
return undefined; // a malformed escape points at nothing — refused by name below
|
|
143
|
+
}
|
|
144
|
+
if (typeof node !== 'object' || node === null)
|
|
145
|
+
return undefined;
|
|
146
|
+
node = node[key];
|
|
147
|
+
}
|
|
148
|
+
return node;
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Refuse an external, dangling or recursive `$ref`. A depth-first walk that
|
|
152
|
+
* expands each local reference with the chain of references being expanded
|
|
153
|
+
* (`open`); meeting one of them again is recursion. A reference fully
|
|
154
|
+
* expanded once without meeting itself is `settled` and not walked again.
|
|
155
|
+
*/
|
|
156
|
+
function assertReferencesExpressible(root, copy) {
|
|
157
|
+
const settled = new Set();
|
|
158
|
+
const open = new Set();
|
|
159
|
+
const walk = (node, path) => {
|
|
160
|
+
if (Array.isArray(node)) {
|
|
161
|
+
node.forEach((child, i) => walk(child, `${path}/${i}`));
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
if (!isObject(node))
|
|
165
|
+
return;
|
|
166
|
+
const ref = node.$ref;
|
|
167
|
+
if (typeof ref === 'string') {
|
|
168
|
+
if (!ref.startsWith('#')) {
|
|
169
|
+
throw new NativeOutputSchemaError(path, `'$ref': '${ref}' is an external reference, and only references inside the ` +
|
|
170
|
+
`schema ('#/$defs/…') are supported.`);
|
|
171
|
+
}
|
|
172
|
+
if (open.has(ref)) {
|
|
173
|
+
throw new NativeOutputSchemaError(path, `'$ref': '${ref}' refers back into a definition it is part of — a recursive ` +
|
|
174
|
+
`schema, which is not supported.`);
|
|
175
|
+
}
|
|
176
|
+
if (!settled.has(ref)) {
|
|
177
|
+
const target = resolvePointer(root, ref);
|
|
178
|
+
if (!isObject(target)) {
|
|
179
|
+
throw new NativeOutputSchemaError(path, copy === 'source'
|
|
180
|
+
? `'$ref': '${ref}' points at nothing in this schema.`
|
|
181
|
+
: `'$ref': '${ref}' points into a part of the schema the wire copy does not ` +
|
|
182
|
+
`keep at that path (oneOf is sent as anyOf; keywords the API does not take ` +
|
|
183
|
+
`move into the description). Point it at a $defs entry.`);
|
|
184
|
+
}
|
|
185
|
+
open.add(ref);
|
|
186
|
+
walk(target, ref);
|
|
187
|
+
open.delete(ref);
|
|
188
|
+
settled.add(ref);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
// Definitions are walked too, referenced or not: a definition that
|
|
192
|
+
// reaches itself is recursive either way, and an unreferenced one is
|
|
193
|
+
// still sent.
|
|
194
|
+
for (const [key, child] of Object.entries(node)) {
|
|
195
|
+
if (key !== '$ref')
|
|
196
|
+
walk(child, `${path}/${key}`);
|
|
197
|
+
}
|
|
198
|
+
};
|
|
199
|
+
open.add('#');
|
|
200
|
+
walk(root, '#');
|
|
201
|
+
}
|
|
202
|
+
// ─── The node transform ───────────────────────────────────────────────
|
|
203
|
+
function describe(node, moved) {
|
|
204
|
+
const entries = Object.entries(moved);
|
|
205
|
+
if (entries.length === 0)
|
|
206
|
+
return;
|
|
207
|
+
const words = `{${entries.map(([k, v]) => `${k}: ${JSON.stringify(v)}`).join(', ')}}`;
|
|
208
|
+
const existing = typeof node.description === 'string' ? node.description : undefined;
|
|
209
|
+
node.description = existing ? `${existing}\n\n${words}` : words;
|
|
210
|
+
}
|
|
211
|
+
function transformNode(node, path) {
|
|
212
|
+
if (!isObject(node)) {
|
|
213
|
+
throw new NativeOutputSchemaError(path, 'a schema must be an object, and this one is not.');
|
|
214
|
+
}
|
|
215
|
+
const has = (key) => Object.prototype.hasOwnProperty.call(node, key);
|
|
216
|
+
if (!has('type') &&
|
|
217
|
+
!has('anyOf') &&
|
|
218
|
+
!has('oneOf') &&
|
|
219
|
+
!has('allOf') &&
|
|
220
|
+
!has('$ref') &&
|
|
221
|
+
!has('enum') &&
|
|
222
|
+
!has('const')) {
|
|
223
|
+
throw new NativeOutputSchemaError(path, 'it has no type — an open value (z.unknown(), z.any(), {}) is any JSON at all, which ' +
|
|
224
|
+
'the structured output cannot decode without recursion. Give it a type.');
|
|
225
|
+
}
|
|
226
|
+
if (Array.isArray(node.enum) && node.enum.some((v) => typeof v === 'object' && v !== null)) {
|
|
227
|
+
throw new NativeOutputSchemaError(path, 'its enum holds an object or an array; enum values must be strings, numbers, ' +
|
|
228
|
+
'booleans or null.');
|
|
229
|
+
}
|
|
230
|
+
if (typeof node.const === 'object' && node.const !== null) {
|
|
231
|
+
throw new NativeOutputSchemaError(path, 'its const is an object or an array; a const must be a string, number, boolean or null.');
|
|
232
|
+
}
|
|
233
|
+
if (has('allOf') &&
|
|
234
|
+
Array.isArray(node.allOf) &&
|
|
235
|
+
node.allOf.some((s) => isObject(s) && has$ref(s))) {
|
|
236
|
+
throw new NativeOutputSchemaError(path, 'allOf with a $ref inside it is not supported.');
|
|
237
|
+
}
|
|
238
|
+
// Open keys: a map whose entries the API could never produce once closed.
|
|
239
|
+
// A value schema for the extra keys, a pattern for them, or an object that
|
|
240
|
+
// names no properties and does not say it is closed (`{ type: 'object' }`,
|
|
241
|
+
// `additionalProperties: true` or `{}` — zod's `z.record(…)` emits these).
|
|
242
|
+
const namesNoProperties = !isObject(node.properties) || Object.keys(node.properties).length === 0;
|
|
243
|
+
if (has('patternProperties') ||
|
|
244
|
+
(isObject(node.additionalProperties) && Object.keys(node.additionalProperties).length > 0) ||
|
|
245
|
+
(isObjectNode(node) && namesNoProperties && node.additionalProperties !== false)) {
|
|
246
|
+
throw new NativeOutputSchemaError(path, 'it is an object with open keys (a record or map: additionalProperties given a schema ' +
|
|
247
|
+
'or left open, or patternProperties). The API takes only additionalProperties: false, ' +
|
|
248
|
+
'which would make every such map empty while the parser accepted it. Name the keys as ' +
|
|
249
|
+
'properties.');
|
|
250
|
+
}
|
|
251
|
+
// A reference stands alone, as the SDK's transform sends it: its target
|
|
252
|
+
// carries the shape, and siblings beside a `$ref` are not part of the subset
|
|
253
|
+
// — except the definitions it may point into (a root `$ref` beside its
|
|
254
|
+
// `definitions`, as zod-to-json-schema writes with a name).
|
|
255
|
+
if (has('$ref')) {
|
|
256
|
+
const ref = { $ref: node.$ref };
|
|
257
|
+
for (const key of ['$defs', 'definitions']) {
|
|
258
|
+
if (isObject(node[key]))
|
|
259
|
+
ref[key] = transformDefinitions(node[key], `${path}/${key}`);
|
|
260
|
+
}
|
|
261
|
+
return ref;
|
|
262
|
+
}
|
|
263
|
+
const out = {};
|
|
264
|
+
const moved = {};
|
|
265
|
+
for (const [key, value] of Object.entries(node)) {
|
|
266
|
+
if (META_KEYS.has(key))
|
|
267
|
+
continue;
|
|
268
|
+
switch (key) {
|
|
269
|
+
case 'type':
|
|
270
|
+
case 'enum':
|
|
271
|
+
case 'const':
|
|
272
|
+
out[key] = value;
|
|
273
|
+
break;
|
|
274
|
+
case 'properties':
|
|
275
|
+
if (isObject(value)) {
|
|
276
|
+
out.properties = Object.fromEntries(Object.entries(value).map(([name, child]) => [
|
|
277
|
+
name,
|
|
278
|
+
transformNode(child, `${path}/properties/${name}`),
|
|
279
|
+
]));
|
|
280
|
+
}
|
|
281
|
+
else
|
|
282
|
+
moved[key] = value;
|
|
283
|
+
break;
|
|
284
|
+
case 'items':
|
|
285
|
+
if (isObject(value))
|
|
286
|
+
out.items = transformNode(value, `${path}/items`);
|
|
287
|
+
else
|
|
288
|
+
moved[key] = value;
|
|
289
|
+
break;
|
|
290
|
+
case 'anyOf':
|
|
291
|
+
case 'oneOf':
|
|
292
|
+
case 'allOf':
|
|
293
|
+
if (Array.isArray(value)) {
|
|
294
|
+
const target = key === 'allOf' ? 'allOf' : 'anyOf';
|
|
295
|
+
out[target] = value.map((child, i) => transformNode(child, `${path}/${key}/${i}`));
|
|
296
|
+
}
|
|
297
|
+
else
|
|
298
|
+
moved[key] = value;
|
|
299
|
+
break;
|
|
300
|
+
case '$defs':
|
|
301
|
+
case 'definitions':
|
|
302
|
+
if (isObject(value))
|
|
303
|
+
out[key] = transformDefinitions(value, `${path}/${key}`);
|
|
304
|
+
else
|
|
305
|
+
moved[key] = value;
|
|
306
|
+
break;
|
|
307
|
+
case 'format':
|
|
308
|
+
if (SUPPORTED_FORMATS.has(value))
|
|
309
|
+
out.format = value;
|
|
310
|
+
else
|
|
311
|
+
moved[key] = value;
|
|
312
|
+
break;
|
|
313
|
+
case 'pattern':
|
|
314
|
+
if (typeof value === 'string' && !unsupportedPattern(value))
|
|
315
|
+
out.pattern = value;
|
|
316
|
+
else
|
|
317
|
+
moved[key] = value;
|
|
318
|
+
break;
|
|
319
|
+
case 'minItems':
|
|
320
|
+
if (value === 0 || value === 1)
|
|
321
|
+
out.minItems = value;
|
|
322
|
+
else {
|
|
323
|
+
moved[key] = value;
|
|
324
|
+
if (typeof value === 'number' && value > 1)
|
|
325
|
+
out.minItems = 1;
|
|
326
|
+
}
|
|
327
|
+
break;
|
|
328
|
+
case 'additionalProperties':
|
|
329
|
+
// `true`, `{}` or `false`: closed below. A schema was refused above.
|
|
330
|
+
break;
|
|
331
|
+
default:
|
|
332
|
+
if (KEPT_AS_IS.has(key))
|
|
333
|
+
out[key] = value;
|
|
334
|
+
else
|
|
335
|
+
moved[key] = value;
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
if (isObjectNode(node)) {
|
|
339
|
+
if (out.properties === undefined)
|
|
340
|
+
out.properties = {};
|
|
341
|
+
out.additionalProperties = false;
|
|
342
|
+
}
|
|
343
|
+
describe(out, moved);
|
|
344
|
+
return out;
|
|
345
|
+
}
|
|
346
|
+
function transformDefinitions(defs, path) {
|
|
347
|
+
return Object.fromEntries(Object.entries(defs).map(([name, child]) => [name, transformNode(child, `${path}/${name}`)]));
|
|
348
|
+
}
|
|
349
|
+
function has$ref(node) {
|
|
350
|
+
return Object.prototype.hasOwnProperty.call(node, '$ref');
|
|
351
|
+
}
|
|
352
|
+
// ─── The one entry point ──────────────────────────────────────────────
|
|
353
|
+
/**
|
|
354
|
+
* The structured-output format for `jsonSchema`, made API-compatible as the
|
|
355
|
+
* file header lists, with the reserved `_findings` property when the findings
|
|
356
|
+
* ledger is armed. Deep-frozen; the input is never edited.
|
|
357
|
+
*
|
|
358
|
+
* @throws NativeOutputSchemaError naming the node the API cannot express.
|
|
359
|
+
*/
|
|
360
|
+
export function nativeOutputFormat(jsonSchema, arms) {
|
|
361
|
+
let source = jsonSchema;
|
|
362
|
+
if (arms.findings) {
|
|
363
|
+
if (!isObjectNode(jsonSchema)) {
|
|
364
|
+
throw new NativeOutputSchemaError('#', `.findings() lets a JSON answer carry its standings as a top-level ` +
|
|
365
|
+
`'${RESERVED_ANSWER_KEY}' property, and this root is not an object schema with ` +
|
|
366
|
+
`properties, so the structured output would refuse the key and the standings would ` +
|
|
367
|
+
`stop. Give the answer an object root.`);
|
|
368
|
+
}
|
|
369
|
+
const properties = isObject(jsonSchema.properties) ? jsonSchema.properties : {};
|
|
370
|
+
if (!Object.prototype.hasOwnProperty.call(properties, RESERVED_ANSWER_KEY)) {
|
|
371
|
+
source = {
|
|
372
|
+
...jsonSchema,
|
|
373
|
+
properties: { ...properties, [RESERVED_ANSWER_KEY]: findingsAnswerSchema() },
|
|
374
|
+
};
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
assertReferencesExpressible(source, 'source');
|
|
378
|
+
const schema = transformNode(source, '#');
|
|
379
|
+
// And again on what is SENT: a reference into a path the copy renamed or
|
|
380
|
+
// moved would dangle on the wire, a 400 on every call.
|
|
381
|
+
assertReferencesExpressible(schema, 'wire');
|
|
382
|
+
return deepFreeze({ type: 'json_schema', schema });
|
|
383
|
+
}
|
|
384
|
+
//# sourceMappingURL=nativeOutputFormat.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nativeOutputFormat.js","sourceRoot":"","sources":["../../../../src/core/agent/nativeOutputFormat.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6DG;AAEH,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAU1D,uEAAuE;AACvE,MAAM,OAAO,uBAAwB,SAAQ,KAAK;IAChD,sEAAsE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E;aAC7E,CAAC;QACJ,CAAC;IACH,CAAC;IACD,2BAA2B,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;IAC9C,MAAM,MAAM,GAAG,aAAa,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC1C,yEAAyE;IACzE,uDAAuD;IACvD,2BAA2B,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC5C,OAAO,UAAU,CAAC,EAAE,IAAI,EAAE,aAAsB,EAAE,MAAM,EAAE,CAAC,CAAC;AAC9D,CAAC"}
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
* after it — there is no trailing sentence for injected text to pre-empt.
|
|
34
34
|
* Identical reasoning, identical shape, to the compaction frame.
|
|
35
35
|
*/
|
|
36
|
-
import type { LLMMessage, LLMResponse, LLMToolSchema } from '../../adapters/types.js';
|
|
36
|
+
import type { LLMMessage, LLMRequest, LLMResponse, LLMToolSchema } from '../../adapters/types.js';
|
|
37
37
|
import { type OutputSchemaParser } from '../outputSchema.js';
|
|
38
38
|
/**
|
|
39
39
|
* One row per final-answer attempt an enforcing agent made, in order.
|
|
@@ -76,7 +76,21 @@ export interface OutputAttempt {
|
|
|
76
76
|
* converge.
|
|
77
77
|
*/
|
|
78
78
|
readonly brokenBy?: string;
|
|
79
|
+
/**
|
|
80
|
+
* Set when the attempt failed because the provider STOPPED, not because the
|
|
81
|
+
* text failed the parser: a `strategy: 'native'` answer that ended with a
|
|
82
|
+
* {@link NativeStopReason}, where the structured-output format does not
|
|
83
|
+
* hold. Such an answer fails even when it parses; a `'refusal'` is never
|
|
84
|
+
* re-asked (the row is `'exhausted'` at once).
|
|
85
|
+
*/
|
|
86
|
+
readonly stopReason?: NativeStopReason;
|
|
79
87
|
}
|
|
88
|
+
/**
|
|
89
|
+
* The stops under which a structured-output format does not hold: a refusal,
|
|
90
|
+
* and the two truncations — the answer's own cap (`'max_tokens'`) and the
|
|
91
|
+
* context window (`'model_context_window_exceeded'`).
|
|
92
|
+
*/
|
|
93
|
+
export type NativeStopReason = 'refusal' | 'max_tokens' | 'model_context_window_exceeded';
|
|
80
94
|
/** The scope surface this file needs. Structurally a `TypedScope<AgentState>`. */
|
|
81
95
|
export interface OutputLedgerScope {
|
|
82
96
|
outputAttempts?: readonly OutputAttempt[];
|
|
@@ -97,7 +111,22 @@ export interface OutputFailure {
|
|
|
97
111
|
* friends attach the real error there); fall back to the wrapper's. */
|
|
98
112
|
readonly error: string;
|
|
99
113
|
readonly path?: string;
|
|
114
|
+
/** The provider's stop that failed the attempt — see `OutputAttempt.stopReason`. */
|
|
115
|
+
readonly stopReason?: NativeStopReason;
|
|
100
116
|
}
|
|
117
|
+
/**
|
|
118
|
+
* Fail a `strategy: 'native'` answer by its stop reason, before the parser.
|
|
119
|
+
*
|
|
120
|
+
* Anthropic's structured-outputs page: on `stop_reason: "refusal"` "the output
|
|
121
|
+
* may not match your schema because the refusal message takes precedence",
|
|
122
|
+
* and on `"max_tokens"` "the output may be incomplete and not match your
|
|
123
|
+
* schema". So the format was not in force for this text, and an answer that
|
|
124
|
+
* happens to parse is still not one the format produced — delivering it as
|
|
125
|
+
* constrained would be a silent pass. Returns `undefined` under any other
|
|
126
|
+
* strategy or stop. The words are the library's own, naming the stop; the
|
|
127
|
+
* failure then takes the ordinary path (retry, or exhausted and unmet).
|
|
128
|
+
*/
|
|
129
|
+
export declare function nativeStopFailure(enforcement: Pick<ResolvedOutputEnforcement, 'outputFormat'>, stopReason: string | undefined): OutputFailure | undefined;
|
|
101
130
|
/**
|
|
102
131
|
* Flatten whatever the parser threw into {@link OutputFailure}.
|
|
103
132
|
*
|
|
@@ -178,6 +207,9 @@ export interface ResolvedOutputEnforcement {
|
|
|
178
207
|
readonly retries: number;
|
|
179
208
|
/** The synthetic tool, pre-built. Present only under `'tool-forced'`. */
|
|
180
209
|
readonly schemaTool?: LLMToolSchema;
|
|
210
|
+
/** The structured-output format, pre-built by `nativeOutputFormat`.
|
|
211
|
+
* Present only under `'native'`. */
|
|
212
|
+
readonly outputFormat?: NonNullable<LLMRequest['outputFormat']>;
|
|
181
213
|
/** True when `.outputFallback()` is configured. The decider carries it so
|
|
182
214
|
* the unmet-contract signal can say that a tier exists which `run()` does
|
|
183
215
|
* not reach — the fallback itself lives at the caller's boundary. */
|
|
@@ -50,6 +50,39 @@ export function recordOutputAttempt(scope, row) {
|
|
|
50
50
|
// deep-proxy view, and the commit must be detached plain data.
|
|
51
51
|
scope.outputAttempts = [...prev, row];
|
|
52
52
|
}
|
|
53
|
+
/**
|
|
54
|
+
* Fail a `strategy: 'native'` answer by its stop reason, before the parser.
|
|
55
|
+
*
|
|
56
|
+
* Anthropic's structured-outputs page: on `stop_reason: "refusal"` "the output
|
|
57
|
+
* may not match your schema because the refusal message takes precedence",
|
|
58
|
+
* and on `"max_tokens"` "the output may be incomplete and not match your
|
|
59
|
+
* schema". So the format was not in force for this text, and an answer that
|
|
60
|
+
* happens to parse is still not one the format produced — delivering it as
|
|
61
|
+
* constrained would be a silent pass. Returns `undefined` under any other
|
|
62
|
+
* strategy or stop. The words are the library's own, naming the stop; the
|
|
63
|
+
* failure then takes the ordinary path (retry, or exhausted and unmet).
|
|
64
|
+
*/
|
|
65
|
+
export function nativeStopFailure(enforcement, stopReason) {
|
|
66
|
+
if (enforcement.outputFormat === undefined)
|
|
67
|
+
return undefined;
|
|
68
|
+
if (stopReason !== 'refusal' &&
|
|
69
|
+
stopReason !== 'max_tokens' &&
|
|
70
|
+
stopReason !== 'model_context_window_exceeded')
|
|
71
|
+
return undefined;
|
|
72
|
+
// Quoted to the model on a re-ask (`buildCorrectiveTurn`), so it states the
|
|
73
|
+
// past fact only — no advice to the developer, no destination.
|
|
74
|
+
return {
|
|
75
|
+
stage: 'schema-validate',
|
|
76
|
+
error: stopReason === 'refusal'
|
|
77
|
+
? "The provider stopped with stop_reason 'refusal': the model declined, and the " +
|
|
78
|
+
'structured-output format does not hold for a refusal, so this text is not accepted ' +
|
|
79
|
+
'as the answer even where it parses.'
|
|
80
|
+
: `The provider stopped with stop_reason '${stopReason}': the answer was cut off ` +
|
|
81
|
+
'before it was complete, so the structured-output format does not hold for it and it ' +
|
|
82
|
+
'is not accepted even where it parses.',
|
|
83
|
+
stopReason,
|
|
84
|
+
};
|
|
85
|
+
}
|
|
53
86
|
/**
|
|
54
87
|
* Flatten whatever the parser threw into {@link OutputFailure}.
|
|
55
88
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"outputEnforcement.js","sourceRoot":"","sources":["../../../../src/core/agent/outputEnforcement.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AAGH,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAC5C,OAAO,EAAE,iBAAiB,EAA2B,MAAM,oBAAoB,CAAC;AAChF,OAAO,EAAE,yBAAyB,EAAE,MAAM,2BAA2B,CAAC;AACtE,OAAO,EAAE,mBAAmB,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;
|
|
1
|
+
{"version":3,"file":"outputEnforcement.js","sourceRoot":"","sources":["../../../../src/core/agent/outputEnforcement.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AAGH,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAC5C,OAAO,EAAE,iBAAiB,EAA2B,MAAM,oBAAoB,CAAC;AAChF,OAAO,EAAE,yBAAyB,EAAE,MAAM,2BAA2B,CAAC;AACtE,OAAO,EAAE,mBAAmB,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAmErF;;;;;;GAMG;AACH,MAAM,UAAU,mBAAmB,CAAC,KAAwB,EAAE,GAAkB;IAC9E,MAAM,IAAI,GAAI,KAAK,CAAC,cAAuD,IAAI,EAAE,CAAC;IAClF,2EAA2E;IAC3E,+DAA+D;IAC/D,KAAK,CAAC,cAAc,GAAG,CAAC,GAAG,IAAI,EAAE,GAAG,CAAC,CA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GAAG,EAAE,CAAC;QACb,OAAO,eAAe,CAAC,GAAG,CAAC,CAAC;IAC9B,CAAC;AACH,CAAC"}
|
|
@@ -12,4 +12,4 @@ import type { RouteBranch } from './route.js';
|
|
|
12
12
|
* as its result, and a composition mounting the chart took `'final'` for the
|
|
13
13
|
* agent's answer. Routed on, the chart ends with no answer and the verdict in
|
|
14
14
|
* its state (`core/terminalVerdict.ts`). */
|
|
15
|
-
export declare function withAnswerValidation(decide: (scope: TypedScope<AgentState>) => RouteBranch | Promise<RouteBranch>, config: ResolvedAnswerValidation, parser: OutputSchemaParser<unknown> | undefined, store: ArtifactStore | undefined, hasOutstandingConsent: () => boolean): (scope: TypedScope<AgentState>) => Promise<RouteBranch>;
|
|
15
|
+
export declare function withAnswerValidation(decide: (scope: TypedScope<AgentState>) => RouteBranch | Promise<RouteBranch>, config: ResolvedAnswerValidation, parser: OutputSchemaParser<unknown> | undefined, store: ArtifactStore | undefined, hasOutstandingConsent: () => boolean, nativeOutput?: boolean): (scope: TypedScope<AgentState>) => Promise<RouteBranch>;
|