@jangts/agent-core 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +18 -0
- package/README.md +59 -0
- package/development/docs/api/reference.md +1907 -1874
- package/development/docs/api/support.md +27 -0
- package/development/docs/assets/agent-core-icon.png +0 -0
- package/development/docs/assets/agent-core-logo.png +0 -0
- package/development/docs/assets/character-agent-core.png +0 -0
- package/development/skills/agent-core-app/scripts/create-app.mjs +267 -70
- package/development/skills/agent-core-app/scripts/lib/knowledge.mjs +40 -15
- package/development/skills/agent-core-app/scripts/lib/source.mjs +30 -2
- package/development/skills/agent-core-app/scripts/plan.mjs +37 -12
- package/development/skills/agent-core-app/scripts/prepare-source.mjs +61 -10
- package/development/skills/agent-core-app/scripts/resources.mjs +45 -17
- package/development/skills/agent-core-app/scripts/validate-knowledge.mjs +18 -1
- package/development/skills/agent-core-app/templates/catalog.json +36 -22
- package/dist/cjs/capabilities/index.js +13 -0
- package/dist/cjs/capabilities/invocation.js +80 -10
- package/dist/cjs/capabilities/model.js +126 -13
- package/dist/cjs/capabilities/tool-runtime.js +64 -12
- package/dist/cjs/capabilities/tools.js +266 -31
- package/dist/cjs/context/assembly.js +46 -5
- package/dist/cjs/context/audit.js +31 -6
- package/dist/cjs/context/fragments.js +54 -11
- package/dist/cjs/context/index.js +12 -0
- package/dist/cjs/context/journal.js +84 -7
- package/dist/cjs/context/plan.js +30 -2
- package/dist/cjs/diagnostics/catalog.js +11 -3
- package/dist/cjs/diagnostics/index.js +149 -29
- package/dist/cjs/diagnostics/sub-flow.js +240 -40
- package/dist/cjs/errors.js +99 -17
- package/dist/cjs/execution/branch.js +20 -4
- package/dist/cjs/execution/engine.js +470 -56
- package/dist/cjs/execution/events.js +136 -18
- package/dist/cjs/execution/index.js +7 -0
- package/dist/cjs/execution/reporting.js +75 -6
- package/dist/cjs/execution/state.js +161 -22
- package/dist/cjs/execution/workflow.js +224 -32
- package/dist/cjs/index.js +18 -0
- package/dist/cjs/kits/aggregation.js +45 -3
- package/dist/cjs/kits/answering/batch.js +23 -4
- package/dist/cjs/kits/answering/check-result.js +31 -8
- package/dist/cjs/kits/answering/checks.js +24 -3
- package/dist/cjs/kits/answering/flow.js +192 -36
- package/dist/cjs/kits/answering/index.js +19 -1
- package/dist/cjs/kits/answering/tasks.js +88 -13
- package/dist/cjs/kits/artifacts.js +36 -4
- package/dist/cjs/kits/candidates.js +47 -5
- package/dist/cjs/kits/delivery.js +40 -5
- package/dist/cjs/kits/durable.js +155 -31
- package/dist/cjs/kits/evidence.js +66 -15
- package/dist/cjs/kits/family.js +152 -22
- package/dist/cjs/kits/index.js +12 -1
- package/dist/cjs/kits/inference.js +104 -16
- package/dist/cjs/kits/intents/catalog.js +67 -16
- package/dist/cjs/kits/intents/index.js +11 -0
- package/dist/cjs/kits/intents/registry.js +188 -43
- package/dist/cjs/kits/intents/scopes.js +215 -46
- package/dist/cjs/kits/interaction/command.js +140 -36
- package/dist/cjs/kits/interaction/commands.js +86 -11
- package/dist/cjs/kits/interaction/handlers.js +27 -10
- package/dist/cjs/kits/interaction/index.js +10 -0
- package/dist/cjs/kits/interaction/transfer.js +80 -14
- package/dist/cjs/kits/knowledge/catalog.js +62 -11
- package/dist/cjs/kits/knowledge/index.js +16 -1
- package/dist/cjs/kits/knowledge/publication.js +99 -23
- package/dist/cjs/kits/knowledge/sections.js +33 -4
- package/dist/cjs/kits/normalization.js +51 -7
- package/dist/cjs/kits/policies.js +79 -15
- package/dist/cjs/kits/presentation/events.js +54 -10
- package/dist/cjs/kits/presentation/index.js +24 -1
- package/dist/cjs/kits/presentation/outputs.js +176 -38
- package/dist/cjs/kits/presentation/templates.js +33 -5
- package/dist/cjs/kits/presentation/variants.js +31 -2
- package/dist/cjs/kits/projection.js +63 -8
- package/dist/cjs/kits/rank-fusion.js +27 -4
- package/dist/cjs/kits/reflection-log-source.js +89 -16
- package/dist/cjs/kits/reflection.js +234 -60
- package/dist/cjs/kits/retrieval.js +98 -18
- package/dist/cjs/kits/search.js +180 -27
- package/dist/cjs/kits/text-skills.js +104 -19
- package/dist/cjs/kits/tools.js +415 -74
- package/dist/cjs/kits/vector-search.js +50 -16
- package/dist/cjs/mock/node.js +7 -1
- package/dist/cjs/mock/web.js +7 -1
- package/dist/cjs/mock.js +7 -1
- package/dist/cjs/model/binding.js +68 -17
- package/dist/cjs/model/call-budget.js +45 -4
- package/dist/cjs/model/decision-retry.js +19 -1
- package/dist/cjs/model/defaults.js +27 -4
- package/dist/cjs/model/index.js +7 -0
- package/dist/cjs/model/interactions/arguments.js +36 -1
- package/dist/cjs/model/interactions/json-object.js +48 -12
- package/dist/cjs/model/interactions/native-functions.js +52 -10
- package/dist/cjs/model/message-diagnostics.js +17 -4
- package/dist/cjs/model/options.js +9 -1
- package/dist/cjs/model/preparation.js +86 -12
- package/dist/cjs/model/runner.js +413 -79
- package/dist/cjs/model/selection-transport.js +48 -8
- package/dist/cjs/model/settings.js +67 -13
- package/dist/cjs/model/token-budget.js +69 -11
- package/dist/cjs/model/transports.js +59 -6
- package/dist/cjs/structs/common.js +11 -0
- package/dist/cjs/structs/debug.js +34 -5
- package/dist/cjs/structs/errors.js +26 -1
- package/dist/cjs/structs/index.js +11 -1
- package/dist/cjs/structs/kits/durable.js +7 -0
- package/dist/cjs/structs/kits/family.js +1 -0
- package/dist/cjs/structs/kits/interaction.js +8 -1
- package/dist/cjs/structs/kits/knowledge-publication.js +1 -0
- package/dist/cjs/structs/kits/reflection.js +18 -3
- package/dist/cjs/structs/model/chat-provider.js +6 -0
- package/dist/cjs/structs/support/model/completion.js +2 -0
- package/dist/cjs/structs/support/model/messages.js +2 -0
- package/dist/cjs/support/capabilities.js +43 -6
- package/dist/cjs/support/context/assembly.js +88 -16
- package/dist/cjs/support/context/compression.js +48 -6
- package/dist/cjs/support/context/fragments.js +6 -0
- package/dist/cjs/support/context/history.js +36 -1
- package/dist/cjs/support/context/index.js +11 -0
- package/dist/cjs/support/context/nodes.js +164 -35
- package/dist/cjs/support/context/processing.js +319 -61
- package/dist/cjs/support/context/selection-policy.js +98 -21
- package/dist/cjs/support/context/selection.js +61 -10
- package/dist/cjs/support/context/snapshot.js +29 -7
- package/dist/cjs/support/context/strategies.js +120 -28
- package/dist/cjs/support/index.js +9 -1
- package/dist/cjs/support/model/capabilities.js +20 -1
- package/dist/cjs/support/model/chat-completions.js +92 -20
- package/dist/cjs/support/model/children.js +34 -6
- package/dist/cjs/support/model/compatible-provider.js +189 -59
- package/dist/cjs/support/model/completion/calls.js +61 -0
- package/dist/cjs/support/model/completion/default.js +32 -0
- package/dist/cjs/support/model/completion/index.js +28 -0
- package/dist/cjs/support/model/completion/session.js +102 -0
- package/dist/cjs/support/model/index.js +12 -0
- package/dist/cjs/support/model/interactions/index.js +12 -1
- package/dist/cjs/support/model/interactions/json-object.js +6 -0
- package/dist/cjs/support/model/interactions/native-functions.js +6 -0
- package/dist/cjs/support/model/observer.js +32 -6
- package/dist/cjs/support/model/preview-rules.js +66 -16
- package/dist/cjs/support/model/reply-preview.js +77 -17
- package/dist/cjs/support/model/stage-transport.js +33 -7
- package/dist/cjs/support/model/strategies.js +75 -14
- package/dist/cjs/support/model/transports.js +53 -11
- package/dist/cjs/support/registration.js +49 -7
- package/dist/cjs/support/schema.js +46 -4
- package/dist/cjs/support/stream-events.js +60 -8
- package/dist/cjs/support/tool-runtime.js +6 -0
- package/dist/cjs/support/tools.js +79 -10
- package/dist/cjs/support/transport/index.js +7 -0
- package/dist/cjs/support/transport/json.js +28 -4
- package/dist/cjs/support/transport/sse.js +25 -2
- package/dist/cjs/utils/break-observer.js +20 -2
- package/dist/cjs/utils/cancellation.js +77 -9
- package/dist/cjs/utils/catalog.js +19 -4
- package/dist/cjs/utils/debug.js +14 -2
- package/dist/cjs/utils/index.js +8 -0
- package/dist/cjs/utils/interaction-definition.js +26 -6
- package/dist/cjs/utils/invocation.js +42 -4
- package/dist/cjs/utils/model-protocol.js +20 -1
- package/dist/cjs/utils/object.js +16 -0
- package/dist/cjs/utils/observer.js +22 -2
- package/dist/cjs/utils/protocol-registry.js +47 -4
- package/dist/cjs/utils/query-key.js +21 -2
- package/dist/cjs/utils/registration.js +18 -2
- package/dist/cjs/utils/rules.js +39 -11
- package/dist/cjs/utils/schema-adapter.js +25 -2
- package/dist/cjs/utils/synchronous.js +64 -7
- package/dist/cjs/utils/text.js +15 -1
- package/dist/esm/capabilities/index.d.ts +13 -0
- package/dist/esm/capabilities/index.js +13 -0
- package/dist/esm/capabilities/invocation.d.ts +16 -2
- package/dist/esm/capabilities/invocation.js +80 -10
- package/dist/esm/capabilities/model.d.ts +68 -1
- package/dist/esm/capabilities/model.js +126 -13
- package/dist/esm/capabilities/tool-runtime.d.ts +11 -0
- package/dist/esm/capabilities/tool-runtime.js +64 -12
- package/dist/esm/capabilities/tools.d.ts +96 -3
- package/dist/esm/capabilities/tools.js +267 -32
- package/dist/esm/context/assembly.d.ts +13 -2
- package/dist/esm/context/assembly.js +46 -5
- package/dist/esm/context/audit.d.ts +23 -1
- package/dist/esm/context/audit.js +31 -6
- package/dist/esm/context/fragments.d.ts +37 -3
- package/dist/esm/context/fragments.js +54 -11
- package/dist/esm/context/index.d.ts +12 -0
- package/dist/esm/context/index.js +12 -0
- package/dist/esm/context/journal.d.ts +32 -1
- package/dist/esm/context/journal.js +84 -7
- package/dist/esm/context/plan.d.ts +11 -1
- package/dist/esm/context/plan.js +30 -2
- package/dist/esm/diagnostics/catalog.js +11 -3
- package/dist/esm/diagnostics/index.d.ts +30 -2
- package/dist/esm/diagnostics/index.js +149 -29
- package/dist/esm/diagnostics/sub-flow.d.ts +41 -3
- package/dist/esm/diagnostics/sub-flow.js +240 -40
- package/dist/esm/errors.d.ts +22 -2
- package/dist/esm/errors.js +99 -17
- package/dist/esm/execution/branch.d.ts +19 -1
- package/dist/esm/execution/branch.js +20 -4
- package/dist/esm/execution/engine.d.ts +291 -5
- package/dist/esm/execution/engine.js +471 -57
- package/dist/esm/execution/events.d.ts +16 -2
- package/dist/esm/execution/events.js +136 -18
- package/dist/esm/execution/index.d.ts +7 -0
- package/dist/esm/execution/index.js +7 -0
- package/dist/esm/execution/reporting.d.ts +49 -1
- package/dist/esm/execution/reporting.js +75 -6
- package/dist/esm/execution/state.d.ts +126 -10
- package/dist/esm/execution/state.js +161 -22
- package/dist/esm/execution/workflow.d.ts +121 -3
- package/dist/esm/execution/workflow.js +224 -32
- package/dist/esm/index.d.ts +17 -1
- package/dist/esm/index.js +18 -0
- package/dist/esm/kits/aggregation.d.ts +34 -2
- package/dist/esm/kits/aggregation.js +45 -3
- package/dist/esm/kits/answering/batch.d.ts +17 -0
- package/dist/esm/kits/answering/batch.js +23 -4
- package/dist/esm/kits/answering/check-result.d.ts +18 -1
- package/dist/esm/kits/answering/check-result.js +31 -8
- package/dist/esm/kits/answering/checks.d.ts +11 -0
- package/dist/esm/kits/answering/checks.js +24 -3
- package/dist/esm/kits/answering/flow.d.ts +25 -2
- package/dist/esm/kits/answering/flow.js +192 -36
- package/dist/esm/kits/answering/index.d.ts +12 -0
- package/dist/esm/kits/answering/index.js +19 -1
- package/dist/esm/kits/answering/tasks.d.ts +32 -1
- package/dist/esm/kits/answering/tasks.js +88 -13
- package/dist/esm/kits/artifacts.d.ts +11 -0
- package/dist/esm/kits/artifacts.js +36 -4
- package/dist/esm/kits/candidates.d.ts +23 -1
- package/dist/esm/kits/candidates.js +47 -5
- package/dist/esm/kits/delivery.d.ts +34 -0
- package/dist/esm/kits/delivery.js +40 -5
- package/dist/esm/kits/durable.d.ts +19 -0
- package/dist/esm/kits/durable.js +155 -31
- package/dist/esm/kits/evidence.d.ts +28 -5
- package/dist/esm/kits/evidence.js +66 -15
- package/dist/esm/kits/family.d.ts +17 -1
- package/dist/esm/kits/family.js +152 -22
- package/dist/esm/kits/index.d.ts +12 -1
- package/dist/esm/kits/index.js +12 -1
- package/dist/esm/kits/inference.d.ts +64 -0
- package/dist/esm/kits/inference.js +104 -16
- package/dist/esm/kits/intents/catalog.d.ts +13 -1
- package/dist/esm/kits/intents/catalog.js +67 -16
- package/dist/esm/kits/intents/index.d.ts +11 -0
- package/dist/esm/kits/intents/index.js +11 -0
- package/dist/esm/kits/intents/registry.d.ts +61 -3
- package/dist/esm/kits/intents/registry.js +188 -43
- package/dist/esm/kits/intents/scopes.d.ts +73 -3
- package/dist/esm/kits/intents/scopes.js +215 -46
- package/dist/esm/kits/interaction/command.d.ts +38 -4
- package/dist/esm/kits/interaction/command.js +140 -36
- package/dist/esm/kits/interaction/commands.d.ts +66 -2
- package/dist/esm/kits/interaction/commands.js +86 -11
- package/dist/esm/kits/interaction/handlers.d.ts +19 -2
- package/dist/esm/kits/interaction/handlers.js +27 -10
- package/dist/esm/kits/interaction/index.d.ts +10 -0
- package/dist/esm/kits/interaction/index.js +10 -0
- package/dist/esm/kits/interaction/transfer.d.ts +39 -2
- package/dist/esm/kits/interaction/transfer.js +80 -14
- package/dist/esm/kits/knowledge/catalog.d.ts +13 -0
- package/dist/esm/kits/knowledge/catalog.js +62 -11
- package/dist/esm/kits/knowledge/index.d.ts +11 -0
- package/dist/esm/kits/knowledge/index.js +16 -1
- package/dist/esm/kits/knowledge/publication.d.ts +15 -1
- package/dist/esm/kits/knowledge/publication.js +99 -23
- package/dist/esm/kits/knowledge/sections.d.ts +31 -1
- package/dist/esm/kits/knowledge/sections.js +33 -4
- package/dist/esm/kits/normalization.d.ts +25 -2
- package/dist/esm/kits/normalization.js +51 -7
- package/dist/esm/kits/policies.d.ts +26 -3
- package/dist/esm/kits/policies.js +79 -15
- package/dist/esm/kits/presentation/events.d.ts +51 -4
- package/dist/esm/kits/presentation/events.js +54 -10
- package/dist/esm/kits/presentation/index.d.ts +12 -0
- package/dist/esm/kits/presentation/index.js +25 -2
- package/dist/esm/kits/presentation/outputs.d.ts +30 -1
- package/dist/esm/kits/presentation/outputs.js +176 -38
- package/dist/esm/kits/presentation/templates.d.ts +32 -3
- package/dist/esm/kits/presentation/templates.js +33 -5
- package/dist/esm/kits/presentation/variants.d.ts +29 -0
- package/dist/esm/kits/presentation/variants.js +31 -2
- package/dist/esm/kits/projection.d.ts +42 -5
- package/dist/esm/kits/projection.js +63 -8
- package/dist/esm/kits/rank-fusion.d.ts +21 -1
- package/dist/esm/kits/rank-fusion.js +28 -5
- package/dist/esm/kits/reflection-log-source.d.ts +28 -1
- package/dist/esm/kits/reflection-log-source.js +89 -16
- package/dist/esm/kits/reflection.d.ts +17 -1
- package/dist/esm/kits/reflection.js +235 -61
- package/dist/esm/kits/retrieval.d.ts +18 -2
- package/dist/esm/kits/retrieval.js +98 -18
- package/dist/esm/kits/search.d.ts +56 -3
- package/dist/esm/kits/search.js +180 -27
- package/dist/esm/kits/text-skills.d.ts +16 -2
- package/dist/esm/kits/text-skills.js +104 -19
- package/dist/esm/kits/tools.d.ts +122 -2
- package/dist/esm/kits/tools.js +416 -74
- package/dist/esm/kits/vector-search.d.ts +47 -1
- package/dist/esm/kits/vector-search.js +51 -17
- package/dist/esm/mock/node.d.ts +7 -0
- package/dist/esm/mock/node.js +7 -1
- package/dist/esm/mock/web.d.ts +7 -0
- package/dist/esm/mock/web.js +7 -1
- package/dist/esm/mock.d.ts +7 -0
- package/dist/esm/mock.js +7 -1
- package/dist/esm/model/binding.d.ts +32 -3
- package/dist/esm/model/binding.js +68 -17
- package/dist/esm/model/call-budget.d.ts +30 -2
- package/dist/esm/model/call-budget.js +45 -4
- package/dist/esm/model/decision-retry.d.ts +10 -1
- package/dist/esm/model/decision-retry.js +19 -1
- package/dist/esm/model/defaults.d.ts +13 -2
- package/dist/esm/model/defaults.js +27 -4
- package/dist/esm/model/index.d.ts +7 -0
- package/dist/esm/model/index.js +7 -0
- package/dist/esm/model/interactions/arguments.d.ts +27 -0
- package/dist/esm/model/interactions/arguments.js +36 -1
- package/dist/esm/model/interactions/json-object.d.ts +7 -1
- package/dist/esm/model/interactions/json-object.js +48 -12
- package/dist/esm/model/interactions/native-functions.d.ts +6 -0
- package/dist/esm/model/interactions/native-functions.js +52 -10
- package/dist/esm/model/message-diagnostics.d.ts +17 -1
- package/dist/esm/model/message-diagnostics.js +17 -4
- package/dist/esm/model/options.d.ts +18 -1
- package/dist/esm/model/options.js +9 -1
- package/dist/esm/model/preparation.d.ts +30 -2
- package/dist/esm/model/preparation.js +86 -12
- package/dist/esm/model/runner.d.ts +129 -5
- package/dist/esm/model/runner.js +414 -80
- package/dist/esm/model/selection-transport.d.ts +14 -1
- package/dist/esm/model/selection-transport.js +48 -8
- package/dist/esm/model/settings.d.ts +11 -0
- package/dist/esm/model/settings.js +67 -13
- package/dist/esm/model/token-budget.d.ts +59 -1
- package/dist/esm/model/token-budget.js +69 -11
- package/dist/esm/model/transports.d.ts +20 -2
- package/dist/esm/model/transports.js +59 -6
- package/dist/esm/structs/capabilities/invocation.d.ts +36 -0
- package/dist/esm/structs/capabilities/model.d.ts +27 -0
- package/dist/esm/structs/capabilities/tools.d.ts +38 -0
- package/dist/esm/structs/common.d.ts +62 -2
- package/dist/esm/structs/common.js +11 -0
- package/dist/esm/structs/context/fragments.d.ts +28 -0
- package/dist/esm/structs/context/journal.d.ts +28 -3
- package/dist/esm/structs/context/processing.d.ts +11 -0
- package/dist/esm/structs/debug.d.ts +58 -1
- package/dist/esm/structs/debug.js +34 -5
- package/dist/esm/structs/diagnostics.d.ts +119 -1
- package/dist/esm/structs/errors.d.ts +42 -1
- package/dist/esm/structs/errors.js +26 -1
- package/dist/esm/structs/execution/engine.d.ts +24 -1
- package/dist/esm/structs/execution/events.d.ts +12 -0
- package/dist/esm/structs/execution/workflow.d.ts +71 -0
- package/dist/esm/structs/index.d.ts +11 -1
- package/dist/esm/structs/index.js +11 -1
- package/dist/esm/structs/invocation.d.ts +30 -0
- package/dist/esm/structs/kits/aggregation.d.ts +12 -0
- package/dist/esm/structs/kits/answering/checks.d.ts +11 -0
- package/dist/esm/structs/kits/answering/flow.d.ts +35 -1
- package/dist/esm/structs/kits/answering/state.d.ts +21 -0
- package/dist/esm/structs/kits/answering/tasks.d.ts +21 -0
- package/dist/esm/structs/kits/artifacts.d.ts +14 -0
- package/dist/esm/structs/kits/candidates.d.ts +19 -0
- package/dist/esm/structs/kits/delivery.d.ts +22 -0
- package/dist/esm/structs/kits/durable.d.ts +56 -3
- package/dist/esm/structs/kits/durable.js +7 -0
- package/dist/esm/structs/kits/evidence.d.ts +23 -0
- package/dist/esm/structs/kits/family.d.ts +49 -1
- package/dist/esm/structs/kits/family.js +1 -0
- package/dist/esm/structs/kits/intents/catalog.d.ts +26 -0
- package/dist/esm/structs/kits/intents/registry.d.ts +34 -0
- package/dist/esm/structs/kits/intents/scopes.d.ts +36 -1
- package/dist/esm/structs/kits/interaction.d.ts +64 -0
- package/dist/esm/structs/kits/interaction.js +8 -1
- package/dist/esm/structs/kits/knowledge-publication.d.ts +43 -1
- package/dist/esm/structs/kits/knowledge-publication.js +1 -0
- package/dist/esm/structs/kits/knowledge.d.ts +39 -2
- package/dist/esm/structs/kits/normalization.d.ts +15 -0
- package/dist/esm/structs/kits/policies.d.ts +25 -1
- package/dist/esm/structs/kits/presentation/events.d.ts +28 -4
- package/dist/esm/structs/kits/presentation/outputs.d.ts +38 -1
- package/dist/esm/structs/kits/presentation/templates.d.ts +15 -0
- package/dist/esm/structs/kits/projection.d.ts +21 -0
- package/dist/esm/structs/kits/reflection.d.ts +61 -2
- package/dist/esm/structs/kits/reflection.js +18 -3
- package/dist/esm/structs/kits/retrieval.d.ts +38 -0
- package/dist/esm/structs/kits/search.d.ts +22 -0
- package/dist/esm/structs/kits/text-skills.d.ts +36 -0
- package/dist/esm/structs/kits/tools.d.ts +87 -0
- package/dist/esm/structs/model/chat-provider.d.ts +24 -1
- package/dist/esm/structs/model/chat-provider.js +6 -0
- package/dist/esm/structs/model/interactions.d.ts +38 -0
- package/dist/esm/structs/model/messages.d.ts +30 -0
- package/dist/esm/structs/model/runtime.d.ts +104 -6
- package/dist/esm/structs/support/capabilities.d.ts +19 -2
- package/dist/esm/structs/support/context-processing.d.ts +88 -9
- package/dist/esm/structs/support/context.d.ts +29 -1
- package/dist/esm/structs/support/model/completion.d.ts +50 -0
- package/dist/esm/structs/support/model/completion.js +1 -0
- package/dist/esm/structs/support/model/interactions.d.ts +13 -1
- package/dist/esm/structs/support/model/messages.d.ts +52 -0
- package/dist/esm/structs/support/model/messages.js +1 -0
- package/dist/esm/structs/support/model/provider-observer.d.ts +22 -1
- package/dist/esm/structs/support/model/provider.d.ts +71 -6
- package/dist/esm/structs/support/registration.d.ts +13 -0
- package/dist/esm/structs/support/schema.d.ts +14 -0
- package/dist/esm/structs/support/tools.d.ts +28 -0
- package/dist/esm/structs/support/transport/json.d.ts +16 -0
- package/dist/esm/structs/support/transport/sse.d.ts +15 -0
- package/dist/esm/structs/utils/rules.d.ts +19 -0
- package/dist/esm/support/capabilities.d.ts +25 -2
- package/dist/esm/support/capabilities.js +43 -6
- package/dist/esm/support/context/assembly.d.ts +35 -4
- package/dist/esm/support/context/assembly.js +88 -16
- package/dist/esm/support/context/compression.d.ts +17 -1
- package/dist/esm/support/context/compression.js +48 -6
- package/dist/esm/support/context/fragments.d.ts +6 -0
- package/dist/esm/support/context/fragments.js +6 -0
- package/dist/esm/support/context/history.d.ts +43 -0
- package/dist/esm/support/context/history.js +36 -1
- package/dist/esm/support/context/index.d.ts +13 -2
- package/dist/esm/support/context/index.js +12 -1
- package/dist/esm/support/context/nodes.d.ts +49 -3
- package/dist/esm/support/context/nodes.js +165 -36
- package/dist/esm/support/context/processing.d.ts +145 -1
- package/dist/esm/support/context/processing.js +320 -62
- package/dist/esm/support/context/selection-policy.d.ts +42 -2
- package/dist/esm/support/context/selection-policy.js +98 -21
- package/dist/esm/support/context/selection.d.ts +14 -1
- package/dist/esm/support/context/selection.js +61 -10
- package/dist/esm/support/context/snapshot.d.ts +23 -1
- package/dist/esm/support/context/snapshot.js +29 -7
- package/dist/esm/support/context/strategies.d.ts +35 -2
- package/dist/esm/support/context/strategies.js +120 -28
- package/dist/esm/support/index.d.ts +9 -1
- package/dist/esm/support/index.js +9 -1
- package/dist/esm/support/model/capabilities.d.ts +10 -0
- package/dist/esm/support/model/capabilities.js +20 -1
- package/dist/esm/support/model/chat-completions.d.ts +44 -15
- package/dist/esm/support/model/chat-completions.js +92 -20
- package/dist/esm/support/model/children.d.ts +32 -2
- package/dist/esm/support/model/children.js +34 -6
- package/dist/esm/support/model/compatible-provider.d.ts +29 -3
- package/dist/esm/support/model/compatible-provider.js +190 -60
- package/dist/esm/support/model/completion/calls.d.ts +40 -0
- package/dist/esm/support/model/completion/calls.js +58 -0
- package/dist/esm/support/model/completion/default.d.ts +10 -0
- package/dist/esm/support/model/completion/default.js +29 -0
- package/dist/esm/support/model/completion/index.d.ts +10 -0
- package/dist/esm/support/model/completion/index.js +22 -0
- package/dist/esm/support/model/completion/session.d.ts +11 -0
- package/dist/esm/support/model/completion/session.js +99 -0
- package/dist/esm/support/model/index.d.ts +14 -0
- package/dist/esm/support/model/index.js +12 -0
- package/dist/esm/support/model/interactions/index.d.ts +1 -1
- package/dist/esm/support/model/interactions/index.js +12 -1
- package/dist/esm/support/model/interactions/json-object.d.ts +6 -0
- package/dist/esm/support/model/interactions/json-object.js +6 -0
- package/dist/esm/support/model/interactions/native-functions.d.ts +6 -0
- package/dist/esm/support/model/interactions/native-functions.js +6 -0
- package/dist/esm/support/model/observer.d.ts +25 -2
- package/dist/esm/support/model/observer.js +32 -6
- package/dist/esm/support/model/preview-rules.d.ts +20 -2
- package/dist/esm/support/model/preview-rules.js +66 -16
- package/dist/esm/support/model/reply-preview.d.ts +15 -1
- package/dist/esm/support/model/reply-preview.js +77 -17
- package/dist/esm/support/model/stage-transport.d.ts +9 -1
- package/dist/esm/support/model/stage-transport.js +33 -7
- package/dist/esm/support/model/strategies.d.ts +24 -2
- package/dist/esm/support/model/strategies.js +75 -14
- package/dist/esm/support/model/transports.d.ts +17 -1
- package/dist/esm/support/model/transports.js +53 -11
- package/dist/esm/support/registration.d.ts +20 -1
- package/dist/esm/support/registration.js +49 -7
- package/dist/esm/support/schema.d.ts +31 -1
- package/dist/esm/support/schema.js +46 -4
- package/dist/esm/support/stream-events.d.ts +22 -1
- package/dist/esm/support/stream-events.js +60 -8
- package/dist/esm/support/tool-runtime.d.ts +6 -0
- package/dist/esm/support/tool-runtime.js +6 -0
- package/dist/esm/support/tools.d.ts +22 -0
- package/dist/esm/support/tools.js +79 -10
- package/dist/esm/support/transport/index.d.ts +7 -0
- package/dist/esm/support/transport/index.js +7 -0
- package/dist/esm/support/transport/json.d.ts +29 -2
- package/dist/esm/support/transport/json.js +28 -4
- package/dist/esm/support/transport/sse.d.ts +31 -1
- package/dist/esm/support/transport/sse.js +25 -2
- package/dist/esm/types.d.ts +9 -1
- package/dist/esm/utils/break-observer.d.ts +27 -2
- package/dist/esm/utils/break-observer.js +20 -2
- package/dist/esm/utils/cancellation.d.ts +56 -5
- package/dist/esm/utils/cancellation.js +77 -9
- package/dist/esm/utils/catalog.d.ts +20 -1
- package/dist/esm/utils/catalog.js +19 -4
- package/dist/esm/utils/debug.d.ts +20 -1
- package/dist/esm/utils/debug.js +14 -2
- package/dist/esm/utils/index.d.ts +8 -0
- package/dist/esm/utils/index.js +8 -0
- package/dist/esm/utils/interaction-definition.d.ts +18 -1
- package/dist/esm/utils/interaction-definition.js +26 -6
- package/dist/esm/utils/invocation.d.ts +36 -1
- package/dist/esm/utils/invocation.js +42 -4
- package/dist/esm/utils/model-protocol.d.ts +8 -0
- package/dist/esm/utils/model-protocol.js +20 -1
- package/dist/esm/utils/object.d.ts +16 -0
- package/dist/esm/utils/object.js +16 -0
- package/dist/esm/utils/observer.d.ts +19 -1
- package/dist/esm/utils/observer.js +22 -2
- package/dist/esm/utils/protocol-registry.d.ts +38 -1
- package/dist/esm/utils/protocol-registry.js +47 -4
- package/dist/esm/utils/query-key.d.ts +11 -1
- package/dist/esm/utils/query-key.js +21 -2
- package/dist/esm/utils/registration.d.ts +34 -2
- package/dist/esm/utils/registration.js +18 -2
- package/dist/esm/utils/rules.d.ts +81 -4
- package/dist/esm/utils/rules.js +39 -11
- package/dist/esm/utils/schema-adapter.d.ts +12 -1
- package/dist/esm/utils/schema-adapter.js +25 -2
- package/dist/esm/utils/synchronous.d.ts +60 -4
- package/dist/esm/utils/synchronous.js +64 -7
- package/dist/esm/utils/text.d.ts +15 -1
- package/dist/esm/utils/text.js +15 -1
- package/package.json +23 -3
|
@@ -1,13 +1,36 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/**
|
|
2
|
+
* Freeze and validate one check result.
|
|
3
|
+
*
|
|
4
|
+
* @param check - Check outcome: status, issues and an optional replacement value.
|
|
5
|
+
* @param checkId - Id stamped onto issues that do not carry their own, so the failing checker
|
|
6
|
+
* stays identifiable after aggregation.
|
|
7
|
+
* @returns A frozen copy with frozen issues and paths.
|
|
8
|
+
* @throws TypeError When the status is unknown, an issue is malformed, a `passed` result still
|
|
9
|
+
* reports issues, or a `failed` result reports none.
|
|
10
|
+
*/
|
|
2
11
|
export function snapshotAnswerCheck(check, checkId) {
|
|
3
|
-
if (!check ||
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
12
|
+
if (!check ||
|
|
13
|
+
!['passed', 'failed', 'unavailable', 'not-run'].includes(check.status) ||
|
|
14
|
+
!Array.isArray(check.issues) ||
|
|
15
|
+
check.issues.some((issue) => !issue ||
|
|
16
|
+
typeof issue.code !== 'string' ||
|
|
17
|
+
!issue.code ||
|
|
18
|
+
typeof issue.message !== 'string' ||
|
|
19
|
+
(issue.path !== undefined &&
|
|
20
|
+
(!Array.isArray(issue.path) ||
|
|
21
|
+
issue.path.some((part) => typeof part !== 'string' && typeof part !== 'number')))) ||
|
|
22
|
+
(check.status === 'passed' && check.issues.length) ||
|
|
23
|
+
(check.status === 'failed' && !check.issues.length))
|
|
7
24
|
throw new TypeError('Invalid answer check result');
|
|
8
|
-
return Object.freeze({
|
|
9
|
-
|
|
10
|
-
|
|
25
|
+
return Object.freeze({
|
|
26
|
+
status: check.status,
|
|
27
|
+
...('value' in check ? { value: check.value } : {}),
|
|
28
|
+
issues: Object.freeze(check.issues.map((issue) => Object.freeze({
|
|
29
|
+
code: issue.code,
|
|
30
|
+
message: issue.message,
|
|
31
|
+
...(issue.checkId !== undefined || checkId !== undefined
|
|
32
|
+
? { checkId: issue.checkId ?? checkId }
|
|
33
|
+
: {}),
|
|
11
34
|
...(issue.path !== undefined ? { path: Object.freeze([...issue.path]) } : {}),
|
|
12
35
|
}))),
|
|
13
36
|
});
|
|
@@ -1,6 +1,17 @@
|
|
|
1
1
|
import type { OperationContext } from '../../structs/common.js';
|
|
2
2
|
import type { AnswerCheck } from '../../structs/kits/answering/flow.js';
|
|
3
3
|
import type { AnswerChecker } from '../../structs/kits/answering/checks.js';
|
|
4
|
+
/**
|
|
5
|
+
* Compile a checker catalog.
|
|
6
|
+
*
|
|
7
|
+
* A checker may return a replacement value; it is threaded into the next checker, so the
|
|
8
|
+
* selected ids behave like an ordered chain rather than independent assertions.
|
|
9
|
+
*
|
|
10
|
+
* @param definitions - Checkers with unique ids and a synchronous `check` handler.
|
|
11
|
+
* @returns A frozen catalog whose `check({ checkIds, value }, context)` folds the results.
|
|
12
|
+
* @throws TypeError For a missing handler or a duplicate id; from `check` for a repeated
|
|
13
|
+
* selected id, a non-synchronous checker or an invalid check result.
|
|
14
|
+
*/
|
|
4
15
|
export declare function defineAnswerCheckCatalog<Value, App>(definitions: readonly AnswerChecker<Value, App>[]): Readonly<{
|
|
5
16
|
check(request: {
|
|
6
17
|
checkIds: readonly string[];
|
|
@@ -1,13 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Answering Kit: a catalog of named value checkers with one aggregated result.
|
|
3
|
+
*
|
|
4
|
+
* Place in the package: part of the `answering` Kit. Checkers are App business rules; this
|
|
5
|
+
* module only registers them, runs a selected ordered subset and folds their statuses.
|
|
6
|
+
*
|
|
7
|
+
* Exports: `defineAnswerCheckCatalog`, and the answer checker types.
|
|
8
|
+
*/
|
|
1
9
|
import { snapshotAnswerCheck } from './check-result.js';
|
|
2
10
|
import { readonlyCatalog } from '../../utils/catalog.js';
|
|
3
11
|
import { synchronous } from '../../utils/synchronous.js';
|
|
12
|
+
/**
|
|
13
|
+
* Compile a checker catalog.
|
|
14
|
+
*
|
|
15
|
+
* A checker may return a replacement value; it is threaded into the next checker, so the
|
|
16
|
+
* selected ids behave like an ordered chain rather than independent assertions.
|
|
17
|
+
*
|
|
18
|
+
* @param definitions - Checkers with unique ids and a synchronous `check` handler.
|
|
19
|
+
* @returns A frozen catalog whose `check({ checkIds, value }, context)` folds the results.
|
|
20
|
+
* @throws TypeError For a missing handler or a duplicate id; from `check` for a repeated
|
|
21
|
+
* selected id, a non-synchronous checker or an invalid check result.
|
|
22
|
+
*/
|
|
4
23
|
export function defineAnswerCheckCatalog(definitions) {
|
|
5
|
-
const checks = readonlyCatalog(definitions.map(check => {
|
|
24
|
+
const checks = readonlyCatalog(definitions.map((check) => {
|
|
6
25
|
if (typeof check.check !== 'function')
|
|
7
26
|
throw new TypeError('Invalid answer checker');
|
|
8
27
|
return Object.freeze({ id: check.id, check: check.check.bind(check) });
|
|
9
|
-
}), id => new TypeError(`Unknown answer checker: ${id}`));
|
|
10
|
-
return Object.freeze({
|
|
28
|
+
}), (id) => new TypeError(`Unknown answer checker: ${id}`));
|
|
29
|
+
return Object.freeze({
|
|
30
|
+
...checks,
|
|
31
|
+
// Severity only escalates: `failed` wins over `unavailable`, which wins over `passed`.
|
|
11
32
|
check(request, context) {
|
|
12
33
|
context.signal.throwIfAborted();
|
|
13
34
|
const issues = [];
|
|
@@ -1,10 +1,33 @@
|
|
|
1
1
|
import type { OperationContext } from '../../structs/common.js';
|
|
2
2
|
import type { AnswerFlowDefinition, AnswerItem, AnswerResult } from '../../structs/kits/answering/flow.js';
|
|
3
|
-
/**
|
|
3
|
+
/**
|
|
4
|
+
* Compile a reusable answer workflow.
|
|
5
|
+
*
|
|
6
|
+
* Reusable answer workflow. Requests own cells and repair budgets; models remain caller-owned.
|
|
7
|
+
* The flow runs at most `maxRepairs + 1` rounds: one generation pass, then one repair round per
|
|
8
|
+
* failing item set, and finally an explicit accepted/fallback/blocked result per item.
|
|
9
|
+
*
|
|
10
|
+
* @param definition - Batch limits, review policy, generation/check/review/fallback/canInvoke
|
|
11
|
+
* handlers and an optional observer; handlers are bound to this object.
|
|
12
|
+
* @returns A frozen flow whose `run({ inputIds, items }, context)` returns one result per item.
|
|
13
|
+
* @throws TypeError At construction for invalid limits or policy, or a missing handler; from
|
|
14
|
+
* `run` for an invalid batch, non-synchronous handlers, or generated/reviewed values that do
|
|
15
|
+
* not belong to the requested items.
|
|
16
|
+
*/
|
|
4
17
|
export declare function defineAnswerFlow<Data, Value, App = undefined>(definition: AnswerFlowDefinition<Data, Value, App>): Readonly<{
|
|
18
|
+
/**
|
|
19
|
+
* Run one answer batch.
|
|
20
|
+
*
|
|
21
|
+
* @param request - Input ids the batch must cover and the items to answer; validated before
|
|
22
|
+
* any handler runs.
|
|
23
|
+
* @param context - Operation context supplying app, signal and diagnostics.
|
|
24
|
+
* @returns One accepted, fallback or blocked result per item, in request order.
|
|
25
|
+
* @throws TypeError For an invalid batch or handler output, or when the repair budget is
|
|
26
|
+
* exhausted without a final result.
|
|
27
|
+
*/
|
|
5
28
|
run(request: {
|
|
6
29
|
inputIds: readonly string[];
|
|
7
30
|
items: readonly AnswerItem<Data>[];
|
|
8
31
|
}, context: OperationContext<App>): Promise<AnswerResult<Data, Value>[]>;
|
|
9
32
|
}>;
|
|
10
|
-
export type { AnswerFlowDefinition, AnswerCheck, AnswerItem, AnswerIssue, AnswerResult } from '../../structs/kits/answering/flow.js';
|
|
33
|
+
export type { AnswerFlowDefinition, AnswerCheck, AnswerItem, AnswerIssue, AnswerResult, } from '../../structs/kits/answering/flow.js';
|
|
@@ -1,3 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Answering Kit: the bounded generate → check → review → repair → deliver workflow.
|
|
3
|
+
*
|
|
4
|
+
* Place in the package: part of the `answering` Kit and the only module that composes the
|
|
5
|
+
* other answering pieces. Generation, checking, review, fallback and budget checks are App
|
|
6
|
+
* handlers; this module owns the stage graph, cell state, repair budget and result statuses.
|
|
7
|
+
*
|
|
8
|
+
* Exports: `defineAnswerFlow`, and the answer flow/item/result/check types.
|
|
9
|
+
*/
|
|
1
10
|
import { booleanResult, synchronous } from '../../utils/synchronous.js';
|
|
2
11
|
import { awaitWithSignal } from '../../utils/cancellation.js';
|
|
3
12
|
import { AgentCoreEngine } from '../../execution/engine.js';
|
|
@@ -6,13 +15,34 @@ import { validateAnswerBatch } from './batch.js';
|
|
|
6
15
|
import { snapshotAnswerCheck } from './check-result.js';
|
|
7
16
|
import { observeSafely } from '../../utils/observer.js';
|
|
8
17
|
const unavailable = () => ({ status: 'unavailable', issues: [] });
|
|
9
|
-
/**
|
|
18
|
+
/**
|
|
19
|
+
* Compile a reusable answer workflow.
|
|
20
|
+
*
|
|
21
|
+
* Reusable answer workflow. Requests own cells and repair budgets; models remain caller-owned.
|
|
22
|
+
* The flow runs at most `maxRepairs + 1` rounds: one generation pass, then one repair round per
|
|
23
|
+
* failing item set, and finally an explicit accepted/fallback/blocked result per item.
|
|
24
|
+
*
|
|
25
|
+
* @param definition - Batch limits, review policy, generation/check/review/fallback/canInvoke
|
|
26
|
+
* handlers and an optional observer; handlers are bound to this object.
|
|
27
|
+
* @returns A frozen flow whose `run({ inputIds, items }, context)` returns one result per item.
|
|
28
|
+
* @throws TypeError At construction for invalid limits or policy, or a missing handler; from
|
|
29
|
+
* `run` for an invalid batch, non-synchronous handlers, or generated/reviewed values that do
|
|
30
|
+
* not belong to the requested items.
|
|
31
|
+
*/
|
|
10
32
|
export function defineAnswerFlow(definition) {
|
|
11
33
|
const { maxItems, maxRepairs } = definition, reviewPolicy = definition.reviewPolicy ?? 'optional';
|
|
12
|
-
if (!Number.isSafeInteger(maxItems) ||
|
|
13
|
-
|
|
34
|
+
if (!Number.isSafeInteger(maxItems) ||
|
|
35
|
+
maxItems < 1 ||
|
|
36
|
+
!Number.isSafeInteger(maxRepairs) ||
|
|
37
|
+
maxRepairs < 0 ||
|
|
38
|
+
!['optional', 'required', 'off'].includes(reviewPolicy))
|
|
14
39
|
throw new TypeError('Invalid answer flow limits or policy');
|
|
15
|
-
for (const handler of [
|
|
40
|
+
for (const handler of [
|
|
41
|
+
definition.generate,
|
|
42
|
+
definition.check,
|
|
43
|
+
definition.fallback,
|
|
44
|
+
definition.canInvoke,
|
|
45
|
+
]) {
|
|
16
46
|
if (typeof handler !== 'function')
|
|
17
47
|
throw new TypeError('Missing answer flow handler');
|
|
18
48
|
}
|
|
@@ -26,9 +56,15 @@ export function defineAnswerFlow(definition) {
|
|
|
26
56
|
return value;
|
|
27
57
|
};
|
|
28
58
|
const issues = (cell) => {
|
|
29
|
-
const result = [
|
|
59
|
+
const result = [
|
|
60
|
+
...cell.local.issues,
|
|
61
|
+
...(cell.review.status === 'failed' ? cell.review.issues : []),
|
|
62
|
+
];
|
|
30
63
|
if (!cell.hasValue || cell.local.status !== 'passed')
|
|
31
|
-
result.push({
|
|
64
|
+
result.push({
|
|
65
|
+
code: !cell.hasValue ? 'ANSWER_MISSING' : 'ANSWER_LOCAL_CHECK',
|
|
66
|
+
message: 'No locally accepted value',
|
|
67
|
+
});
|
|
32
68
|
if ((reviewPolicy === 'required' || cell.knownReviewFailure) && cell.review.status !== 'passed')
|
|
33
69
|
result.push({ code: 'ANSWER_REVIEW_REQUIRED', message: 'Required review is unresolved' });
|
|
34
70
|
return result;
|
|
@@ -36,20 +72,26 @@ export function defineAnswerFlow(definition) {
|
|
|
36
72
|
function observe(stageId, cells, context) {
|
|
37
73
|
if (!observer)
|
|
38
74
|
return;
|
|
39
|
-
const results = cells.map(cell => ({
|
|
40
|
-
|
|
75
|
+
const results = cells.map((cell) => ({
|
|
76
|
+
item: cell.item,
|
|
77
|
+
value: cell.value,
|
|
78
|
+
status: 'blocked',
|
|
79
|
+
issues: issues(cell),
|
|
80
|
+
checks: { local: cell.local, review: cell.review },
|
|
81
|
+
}));
|
|
82
|
+
observeSafely((input) => observer(input, context), { stageId, results });
|
|
41
83
|
}
|
|
42
84
|
async function generate(cells, repair, context) {
|
|
43
85
|
context.signal.throwIfAborted();
|
|
44
86
|
if (!cells.length || !allowed(context))
|
|
45
87
|
return;
|
|
46
|
-
const previous = new Map(cells.flatMap(cell => !cell.hasValue ? [] : [[cell.item.id, cell.value]]));
|
|
47
|
-
const repairs = repair ? new Map(cells.map(cell => [cell.item.id, issues(cell)])) : undefined;
|
|
88
|
+
const previous = new Map(cells.flatMap((cell) => !cell.hasValue ? [] : [[cell.item.id, cell.value]]));
|
|
89
|
+
const repairs = repair ? new Map(cells.map((cell) => [cell.item.id, issues(cell)])) : undefined;
|
|
48
90
|
for (const cell of cells)
|
|
49
91
|
cell.generated = false;
|
|
50
92
|
let values;
|
|
51
93
|
try {
|
|
52
|
-
values = await awaitWithSignal(generateValues({ items: cells.map(cell => cell.item), repairs, previous }, context), context.signal);
|
|
94
|
+
values = await awaitWithSignal(generateValues({ items: cells.map((cell) => cell.item), repairs, previous }, context), context.signal);
|
|
53
95
|
}
|
|
54
96
|
catch {
|
|
55
97
|
context.signal.throwIfAborted();
|
|
@@ -57,7 +99,10 @@ export function defineAnswerFlow(definition) {
|
|
|
57
99
|
return;
|
|
58
100
|
}
|
|
59
101
|
context.signal.throwIfAborted();
|
|
60
|
-
if (!values ||
|
|
102
|
+
if (!values ||
|
|
103
|
+
typeof values.get !== 'function' ||
|
|
104
|
+
typeof values.keys !== 'function' ||
|
|
105
|
+
[...values.keys()].some((id) => !cells.some((cell) => cell.item.id === id)))
|
|
61
106
|
throw new TypeError('Invalid generated answer ownership');
|
|
62
107
|
for (const cell of cells) {
|
|
63
108
|
cell.hasValue = values.has(cell.item.id);
|
|
@@ -83,7 +128,7 @@ export function defineAnswerFlow(definition) {
|
|
|
83
128
|
}
|
|
84
129
|
async function review(cells, context) {
|
|
85
130
|
context.signal.throwIfAborted();
|
|
86
|
-
const selected = cells.filter(cell => cell.local.status === 'passed' && cell.hasValue);
|
|
131
|
+
const selected = cells.filter((cell) => cell.local.status === 'passed' && cell.hasValue);
|
|
87
132
|
if (!selected.length)
|
|
88
133
|
return;
|
|
89
134
|
if (reviewPolicy === 'off') {
|
|
@@ -98,7 +143,7 @@ export function defineAnswerFlow(definition) {
|
|
|
98
143
|
}
|
|
99
144
|
let checks;
|
|
100
145
|
try {
|
|
101
|
-
checks = await awaitWithSignal(reviewValues({ items: selected.map(cell => ({ item: cell.item, value: cell.value })) }, context), context.signal);
|
|
146
|
+
checks = await awaitWithSignal(reviewValues({ items: selected.map((cell) => ({ item: cell.item, value: cell.value })) }, context), context.signal);
|
|
102
147
|
}
|
|
103
148
|
catch {
|
|
104
149
|
context.signal.throwIfAborted();
|
|
@@ -107,7 +152,10 @@ export function defineAnswerFlow(definition) {
|
|
|
107
152
|
return;
|
|
108
153
|
}
|
|
109
154
|
context.signal.throwIfAborted();
|
|
110
|
-
if (!checks ||
|
|
155
|
+
if (!checks ||
|
|
156
|
+
typeof checks.get !== 'function' ||
|
|
157
|
+
typeof checks.keys !== 'function' ||
|
|
158
|
+
[...checks.keys()].some((id) => !selected.some((cell) => cell.item.id === id)))
|
|
111
159
|
throw new TypeError('Invalid answer review ownership');
|
|
112
160
|
const checked = new Map([...checks].map(([id, result]) => [id, snapshotAnswerCheck(result)]));
|
|
113
161
|
for (const cell of selected) {
|
|
@@ -118,32 +166,140 @@ export function defineAnswerFlow(definition) {
|
|
|
118
166
|
cell.knownReviewFailure = false;
|
|
119
167
|
}
|
|
120
168
|
}
|
|
121
|
-
const workflow = defineWorkflow({
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
{
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
169
|
+
const workflow = defineWorkflow({
|
|
170
|
+
id: 'answer-flow',
|
|
171
|
+
entryNodeId: 'generate',
|
|
172
|
+
nodes: [
|
|
173
|
+
{
|
|
174
|
+
id: 'generate',
|
|
175
|
+
description: 'Generate available items',
|
|
176
|
+
startsRound: true,
|
|
177
|
+
run: async (state, context) => {
|
|
178
|
+
await generate(state.cells.filter((cell) => cell.item.sourceStatus === 'ready'), false, context);
|
|
179
|
+
},
|
|
180
|
+
routes: [{ id: 'to-validate', targetNodeId: 'validate' }],
|
|
181
|
+
},
|
|
182
|
+
{
|
|
183
|
+
id: 'validate',
|
|
184
|
+
description: 'Check values and retain sanitized output',
|
|
185
|
+
run: (state, context) => {
|
|
186
|
+
check(state.cells.filter((cell) => cell.item.sourceStatus === 'ready'), context);
|
|
187
|
+
},
|
|
188
|
+
routes: [{ id: 'to-review', targetNodeId: 'review' }],
|
|
189
|
+
},
|
|
190
|
+
{
|
|
191
|
+
id: 'review',
|
|
192
|
+
description: 'Review locally accepted values',
|
|
193
|
+
run: async (state, context) => {
|
|
194
|
+
await review(state.cells.filter((cell) => cell.item.sourceStatus === 'ready'), context);
|
|
195
|
+
observe('checked', state.cells, context);
|
|
196
|
+
},
|
|
197
|
+
routes: [{ id: 'to-select-repair', targetNodeId: 'select-repair' }],
|
|
198
|
+
},
|
|
199
|
+
{
|
|
200
|
+
id: 'select-repair',
|
|
201
|
+
description: 'Select only failed available items',
|
|
202
|
+
run: (state) => ({
|
|
203
|
+
pending: state.cells.filter((cell) => cell.item.sourceStatus === 'ready' && issues(cell).length > 0),
|
|
204
|
+
}),
|
|
205
|
+
routes: [
|
|
206
|
+
{
|
|
207
|
+
id: 'to-repair',
|
|
208
|
+
conditionId: '{nid}.{rid}',
|
|
209
|
+
when: (state, context) => state.pending.length > 0 && state.repairBudget.available && allowed(context),
|
|
210
|
+
targetNodeId: 'repair',
|
|
211
|
+
},
|
|
212
|
+
{ id: 'to-deliver', targetNodeId: 'deliver' },
|
|
213
|
+
],
|
|
214
|
+
},
|
|
215
|
+
{
|
|
216
|
+
id: 'repair',
|
|
217
|
+
description: 'Use one bounded repair attempt',
|
|
218
|
+
startsRound: true,
|
|
219
|
+
run: async (state, context) => {
|
|
220
|
+
if (!state.repairBudget.take())
|
|
221
|
+
throw new TypeError('Answer repair budget exhausted');
|
|
222
|
+
await generate(state.pending, true, context);
|
|
223
|
+
},
|
|
224
|
+
routes: [{ id: 'to-recheck', targetNodeId: 'recheck' }],
|
|
225
|
+
},
|
|
226
|
+
{
|
|
227
|
+
id: 'recheck',
|
|
228
|
+
description: 'Recheck only repaired items',
|
|
229
|
+
run: async (state, context) => {
|
|
230
|
+
const generated = state.pending.filter((cell) => cell.generated);
|
|
231
|
+
check(generated, context);
|
|
232
|
+
await review(generated, context);
|
|
233
|
+
observe('repaired', state.pending, context);
|
|
234
|
+
},
|
|
235
|
+
routes: [{ id: 'to-select-repair', targetNodeId: 'select-repair' }],
|
|
236
|
+
},
|
|
237
|
+
{
|
|
238
|
+
id: 'deliver',
|
|
239
|
+
description: 'Return accepted values or explicit fallback states',
|
|
240
|
+
run: (state, context) => ({
|
|
241
|
+
result: state.cells.map((cell) => {
|
|
130
242
|
context.signal.throwIfAborted();
|
|
131
243
|
const errors = issues(cell);
|
|
132
244
|
if (cell.item.sourceStatus === 'ready' && !errors.length && cell.hasValue)
|
|
133
|
-
return {
|
|
245
|
+
return {
|
|
246
|
+
item: cell.item,
|
|
247
|
+
value: cell.value,
|
|
248
|
+
status: 'accepted',
|
|
249
|
+
issues: errors,
|
|
250
|
+
checks: { local: cell.local, review: cell.review },
|
|
251
|
+
};
|
|
134
252
|
const outcome = synchronous(fallbackValue({ item: cell.item, issues: errors }, context), 'Answer fallback must be synchronous');
|
|
135
|
-
if (!outcome ||
|
|
253
|
+
if (!outcome ||
|
|
254
|
+
typeof outcome.handled !== 'boolean' ||
|
|
255
|
+
(outcome.handled && !('value' in outcome)))
|
|
136
256
|
throw new TypeError('Invalid answer fallback outcome');
|
|
137
|
-
return {
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
257
|
+
return {
|
|
258
|
+
item: cell.item,
|
|
259
|
+
value: outcome.handled ? outcome.value : undefined,
|
|
260
|
+
status: outcome.handled ? 'fallback' : 'blocked',
|
|
261
|
+
issues: errors,
|
|
262
|
+
checks: { local: cell.local, review: cell.review },
|
|
263
|
+
};
|
|
264
|
+
}),
|
|
265
|
+
}),
|
|
266
|
+
routes: [{ id: 'complete', complete: (state) => state.result }],
|
|
267
|
+
},
|
|
268
|
+
],
|
|
269
|
+
});
|
|
270
|
+
return Object.freeze({
|
|
271
|
+
/**
|
|
272
|
+
* Run one answer batch.
|
|
273
|
+
*
|
|
274
|
+
* @param request - Input ids the batch must cover and the items to answer; validated before
|
|
275
|
+
* any handler runs.
|
|
276
|
+
* @param context - Operation context supplying app, signal and diagnostics.
|
|
277
|
+
* @returns One accepted, fallback or blocked result per item, in request order.
|
|
278
|
+
* @throws TypeError For an invalid batch or handler output, or when the repair budget is
|
|
279
|
+
* exhausted without a final result.
|
|
280
|
+
*/
|
|
281
|
+
async run(request, context) {
|
|
141
282
|
context.signal.throwIfAborted();
|
|
142
283
|
validateAnswerBatch(request.inputIds, request.items, maxItems);
|
|
143
|
-
const cells = request.items.map(item => ({
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
284
|
+
const cells = request.items.map((item) => ({
|
|
285
|
+
item: Object.freeze({
|
|
286
|
+
id: item.id,
|
|
287
|
+
data: item.data,
|
|
288
|
+
sourceStatus: item.sourceStatus,
|
|
289
|
+
inputIds: Object.freeze([...item.inputIds]),
|
|
290
|
+
}),
|
|
291
|
+
hasValue: false,
|
|
292
|
+
local: { status: 'not-run', issues: [] },
|
|
293
|
+
review: { status: 'not-run', issues: [] },
|
|
294
|
+
knownReviewFailure: false,
|
|
295
|
+
}));
|
|
296
|
+
return new AgentCoreEngine({
|
|
297
|
+
maxRounds: maxRepairs + 1,
|
|
298
|
+
errors: { exhausted: () => new TypeError('Answer flow exhausted') },
|
|
299
|
+
execution: { signal: context.signal, diagnostics: context.diagnostics },
|
|
300
|
+
})
|
|
301
|
+
.bindWorkflow(workflow, context.app)
|
|
302
|
+
.run({ cells, pending: [], repairBudget: new AttemptBudget(maxRepairs) });
|
|
303
|
+
},
|
|
304
|
+
});
|
|
149
305
|
}
|
|
@@ -1,3 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Answering Kit entry: batch validation, per-value checks, task/reader catalogs and the
|
|
3
|
+
* generate-check-review-repair workflow.
|
|
4
|
+
*
|
|
5
|
+
* Place in the package: an optional App-side library for answering a bounded batch of items.
|
|
6
|
+
* Models, readers, checks, fallbacks and repair policy are supplied by the App; this module
|
|
7
|
+
* owns their composition, bounds and status aggregation. Core never imports it.
|
|
8
|
+
*
|
|
9
|
+
* Exports: everything from `./flow.js`, `./tasks.js`, `./batch.js` and `./checks.js`, plus the
|
|
10
|
+
* `Answering` namespace object.
|
|
11
|
+
*/
|
|
1
12
|
export * from './flow.js';
|
|
2
13
|
export * from './tasks.js';
|
|
3
14
|
export * from './batch.js';
|
|
@@ -6,6 +17,7 @@ import { defineAnswerTaskCatalog, defineAnswerReaderCatalog } from './tasks.js';
|
|
|
6
17
|
import { defineAnswerCheckCatalog } from './checks.js';
|
|
7
18
|
import { defineAnswerFlow } from './flow.js';
|
|
8
19
|
import { validateAnswerBatch } from './batch.js';
|
|
20
|
+
/** Namespace object for callers that prefer one import over named helpers. */
|
|
9
21
|
export declare const Answering: Readonly<{
|
|
10
22
|
defineAnswerTaskCatalog: typeof defineAnswerTaskCatalog;
|
|
11
23
|
defineAnswerReaderCatalog: typeof defineAnswerReaderCatalog;
|
|
@@ -1,3 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Answering Kit entry: batch validation, per-value checks, task/reader catalogs and the
|
|
3
|
+
* generate-check-review-repair workflow.
|
|
4
|
+
*
|
|
5
|
+
* Place in the package: an optional App-side library for answering a bounded batch of items.
|
|
6
|
+
* Models, readers, checks, fallbacks and repair policy are supplied by the App; this module
|
|
7
|
+
* owns their composition, bounds and status aggregation. Core never imports it.
|
|
8
|
+
*
|
|
9
|
+
* Exports: everything from `./flow.js`, `./tasks.js`, `./batch.js` and `./checks.js`, plus the
|
|
10
|
+
* `Answering` namespace object.
|
|
11
|
+
*/
|
|
1
12
|
export * from './flow.js';
|
|
2
13
|
export * from './tasks.js';
|
|
3
14
|
export * from './batch.js';
|
|
@@ -6,4 +17,11 @@ import { defineAnswerTaskCatalog, defineAnswerReaderCatalog } from './tasks.js';
|
|
|
6
17
|
import { defineAnswerCheckCatalog } from './checks.js';
|
|
7
18
|
import { defineAnswerFlow } from './flow.js';
|
|
8
19
|
import { validateAnswerBatch } from './batch.js';
|
|
9
|
-
|
|
20
|
+
/** Namespace object for callers that prefer one import over named helpers. */
|
|
21
|
+
export const Answering = Object.freeze({
|
|
22
|
+
defineAnswerTaskCatalog,
|
|
23
|
+
defineAnswerReaderCatalog,
|
|
24
|
+
defineAnswerCheckCatalog,
|
|
25
|
+
defineAnswerFlow,
|
|
26
|
+
validateAnswerBatch,
|
|
27
|
+
});
|
|
@@ -1,13 +1,34 @@
|
|
|
1
1
|
import type { OperationContext } from '../../structs/common.js';
|
|
2
2
|
import type { AnswerTaskDefinition, AnswerReader, AnswerTaskPorts } from '../../structs/kits/answering/tasks.js';
|
|
3
|
-
/**
|
|
3
|
+
/**
|
|
4
|
+
* Compile a reader catalog.
|
|
5
|
+
*
|
|
6
|
+
* @param definitions - Readers with unique ids and a `read` handler.
|
|
7
|
+
* @returns A frozen catalog; unknown ids fail through `require`.
|
|
8
|
+
* @throws TypeError When a reader has no `read` handler.
|
|
9
|
+
*/
|
|
4
10
|
export declare function defineAnswerReaderCatalog<Input, Evidence, App, Data = unknown>(definitions: readonly AnswerReader<Input, Evidence, App, Data>[]): import("../../index.js").ReadonlyCatalog<{
|
|
5
11
|
id: string;
|
|
6
12
|
read: (input: Input, context: OperationContext<App> & {
|
|
7
13
|
readonly task: Readonly<AnswerTaskDefinition<Input, Data>>;
|
|
8
14
|
}) => import("../../index.js").MaybePromise<Evidence>;
|
|
9
15
|
}>;
|
|
16
|
+
/**
|
|
17
|
+
* Compile the answer task catalog from its declarations and shared ports.
|
|
18
|
+
*
|
|
19
|
+
* Task ids, schemas, readers, outputs and checks have one compiled authority: a task can only
|
|
20
|
+
* reference a reader or check that the ports actually registered, and metadata is cloned and
|
|
21
|
+
* frozen so later mutation by the caller cannot change a registered task.
|
|
22
|
+
*
|
|
23
|
+
* @param definitions - Task declarations with identity, reader/output/scope references,
|
|
24
|
+
* intent ids, check ids, input schema and metadata.
|
|
25
|
+
* @param ports - Registered readers, checks, outputs and an optional definition assertion.
|
|
26
|
+
* @returns A frozen catalog extended with `describe`, `read` and `readAsync`.
|
|
27
|
+
* @throws TypeError For a task with missing identity, an unknown reader/output/check, empty or
|
|
28
|
+
* duplicate intent ids, a duplicate check id, or a failed definition assertion.
|
|
29
|
+
*/
|
|
10
30
|
export declare function defineAnswerTaskCatalog<Input, Evidence, App, Data = unknown>(definitions: readonly AnswerTaskDefinition<Input, Data>[], ports: AnswerTaskPorts<Input, Evidence, App, Data>): Readonly<{
|
|
31
|
+
/** Task metadata with the JSON schema flattened for model or admin presentation. */
|
|
11
32
|
describe: () => {
|
|
12
33
|
inputJsonSchema: Readonly<Record<string, unknown>>;
|
|
13
34
|
id: string;
|
|
@@ -19,10 +40,20 @@ export declare function defineAnswerTaskCatalog<Input, Evidence, App, Data = unk
|
|
|
19
40
|
checkIds: readonly any[];
|
|
20
41
|
metadata: Data;
|
|
21
42
|
}[];
|
|
43
|
+
/**
|
|
44
|
+
* Read evidence through a task's registered reader, synchronously.
|
|
45
|
+
*
|
|
46
|
+
* @throws TypeError For an unknown task, a parse failure, or a reader returning a Promise.
|
|
47
|
+
*/
|
|
22
48
|
read(request: {
|
|
23
49
|
taskId: string;
|
|
24
50
|
input: unknown;
|
|
25
51
|
}, context: OperationContext<App>): Evidence;
|
|
52
|
+
/**
|
|
53
|
+
* Read evidence through a task's registered reader, awaiting an async reader.
|
|
54
|
+
*
|
|
55
|
+
* @throws TypeError For an unknown task or a parse failure; aborts with the caller's signal.
|
|
56
|
+
*/
|
|
26
57
|
readAsync(request: {
|
|
27
58
|
taskId: string;
|
|
28
59
|
input: unknown;
|