@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,6 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.defineAnswerFlow = defineAnswerFlow;
|
|
4
|
+
/**
|
|
5
|
+
* Answering Kit: the bounded generate → check → review → repair → deliver workflow.
|
|
6
|
+
*
|
|
7
|
+
* Place in the package: part of the `answering` Kit and the only module that composes the
|
|
8
|
+
* other answering pieces. Generation, checking, review, fallback and budget checks are App
|
|
9
|
+
* handlers; this module owns the stage graph, cell state, repair budget and result statuses.
|
|
10
|
+
*
|
|
11
|
+
* Exports: `defineAnswerFlow`, and the answer flow/item/result/check types.
|
|
12
|
+
*/
|
|
4
13
|
const synchronous_js_1 = require("../../utils/synchronous.js");
|
|
5
14
|
const cancellation_js_1 = require("../../utils/cancellation.js");
|
|
6
15
|
const engine_js_1 = require("../../execution/engine.js");
|
|
@@ -9,13 +18,34 @@ const batch_js_1 = require("./batch.js");
|
|
|
9
18
|
const check_result_js_1 = require("./check-result.js");
|
|
10
19
|
const observer_js_1 = require("../../utils/observer.js");
|
|
11
20
|
const unavailable = () => ({ status: 'unavailable', issues: [] });
|
|
12
|
-
/**
|
|
21
|
+
/**
|
|
22
|
+
* Compile a reusable answer workflow.
|
|
23
|
+
*
|
|
24
|
+
* Reusable answer workflow. Requests own cells and repair budgets; models remain caller-owned.
|
|
25
|
+
* The flow runs at most `maxRepairs + 1` rounds: one generation pass, then one repair round per
|
|
26
|
+
* failing item set, and finally an explicit accepted/fallback/blocked result per item.
|
|
27
|
+
*
|
|
28
|
+
* @param definition - Batch limits, review policy, generation/check/review/fallback/canInvoke
|
|
29
|
+
* handlers and an optional observer; handlers are bound to this object.
|
|
30
|
+
* @returns A frozen flow whose `run({ inputIds, items }, context)` returns one result per item.
|
|
31
|
+
* @throws TypeError At construction for invalid limits or policy, or a missing handler; from
|
|
32
|
+
* `run` for an invalid batch, non-synchronous handlers, or generated/reviewed values that do
|
|
33
|
+
* not belong to the requested items.
|
|
34
|
+
*/
|
|
13
35
|
function defineAnswerFlow(definition) {
|
|
14
36
|
const { maxItems, maxRepairs } = definition, reviewPolicy = definition.reviewPolicy ?? 'optional';
|
|
15
|
-
if (!Number.isSafeInteger(maxItems) ||
|
|
16
|
-
|
|
37
|
+
if (!Number.isSafeInteger(maxItems) ||
|
|
38
|
+
maxItems < 1 ||
|
|
39
|
+
!Number.isSafeInteger(maxRepairs) ||
|
|
40
|
+
maxRepairs < 0 ||
|
|
41
|
+
!['optional', 'required', 'off'].includes(reviewPolicy))
|
|
17
42
|
throw new TypeError('Invalid answer flow limits or policy');
|
|
18
|
-
for (const handler of [
|
|
43
|
+
for (const handler of [
|
|
44
|
+
definition.generate,
|
|
45
|
+
definition.check,
|
|
46
|
+
definition.fallback,
|
|
47
|
+
definition.canInvoke,
|
|
48
|
+
]) {
|
|
19
49
|
if (typeof handler !== 'function')
|
|
20
50
|
throw new TypeError('Missing answer flow handler');
|
|
21
51
|
}
|
|
@@ -29,9 +59,15 @@ function defineAnswerFlow(definition) {
|
|
|
29
59
|
return value;
|
|
30
60
|
};
|
|
31
61
|
const issues = (cell) => {
|
|
32
|
-
const result = [
|
|
62
|
+
const result = [
|
|
63
|
+
...cell.local.issues,
|
|
64
|
+
...(cell.review.status === 'failed' ? cell.review.issues : []),
|
|
65
|
+
];
|
|
33
66
|
if (!cell.hasValue || cell.local.status !== 'passed')
|
|
34
|
-
result.push({
|
|
67
|
+
result.push({
|
|
68
|
+
code: !cell.hasValue ? 'ANSWER_MISSING' : 'ANSWER_LOCAL_CHECK',
|
|
69
|
+
message: 'No locally accepted value',
|
|
70
|
+
});
|
|
35
71
|
if ((reviewPolicy === 'required' || cell.knownReviewFailure) && cell.review.status !== 'passed')
|
|
36
72
|
result.push({ code: 'ANSWER_REVIEW_REQUIRED', message: 'Required review is unresolved' });
|
|
37
73
|
return result;
|
|
@@ -39,20 +75,26 @@ function defineAnswerFlow(definition) {
|
|
|
39
75
|
function observe(stageId, cells, context) {
|
|
40
76
|
if (!observer)
|
|
41
77
|
return;
|
|
42
|
-
const results = cells.map(cell => ({
|
|
43
|
-
|
|
78
|
+
const results = cells.map((cell) => ({
|
|
79
|
+
item: cell.item,
|
|
80
|
+
value: cell.value,
|
|
81
|
+
status: 'blocked',
|
|
82
|
+
issues: issues(cell),
|
|
83
|
+
checks: { local: cell.local, review: cell.review },
|
|
84
|
+
}));
|
|
85
|
+
(0, observer_js_1.observeSafely)((input) => observer(input, context), { stageId, results });
|
|
44
86
|
}
|
|
45
87
|
async function generate(cells, repair, context) {
|
|
46
88
|
context.signal.throwIfAborted();
|
|
47
89
|
if (!cells.length || !allowed(context))
|
|
48
90
|
return;
|
|
49
|
-
const previous = new Map(cells.flatMap(cell => !cell.hasValue ? [] : [[cell.item.id, cell.value]]));
|
|
50
|
-
const repairs = repair ? new Map(cells.map(cell => [cell.item.id, issues(cell)])) : undefined;
|
|
91
|
+
const previous = new Map(cells.flatMap((cell) => !cell.hasValue ? [] : [[cell.item.id, cell.value]]));
|
|
92
|
+
const repairs = repair ? new Map(cells.map((cell) => [cell.item.id, issues(cell)])) : undefined;
|
|
51
93
|
for (const cell of cells)
|
|
52
94
|
cell.generated = false;
|
|
53
95
|
let values;
|
|
54
96
|
try {
|
|
55
|
-
values = await (0, cancellation_js_1.awaitWithSignal)(generateValues({ items: cells.map(cell => cell.item), repairs, previous }, context), context.signal);
|
|
97
|
+
values = await (0, cancellation_js_1.awaitWithSignal)(generateValues({ items: cells.map((cell) => cell.item), repairs, previous }, context), context.signal);
|
|
56
98
|
}
|
|
57
99
|
catch {
|
|
58
100
|
context.signal.throwIfAborted();
|
|
@@ -60,7 +102,10 @@ function defineAnswerFlow(definition) {
|
|
|
60
102
|
return;
|
|
61
103
|
}
|
|
62
104
|
context.signal.throwIfAborted();
|
|
63
|
-
if (!values ||
|
|
105
|
+
if (!values ||
|
|
106
|
+
typeof values.get !== 'function' ||
|
|
107
|
+
typeof values.keys !== 'function' ||
|
|
108
|
+
[...values.keys()].some((id) => !cells.some((cell) => cell.item.id === id)))
|
|
64
109
|
throw new TypeError('Invalid generated answer ownership');
|
|
65
110
|
for (const cell of cells) {
|
|
66
111
|
cell.hasValue = values.has(cell.item.id);
|
|
@@ -86,7 +131,7 @@ function defineAnswerFlow(definition) {
|
|
|
86
131
|
}
|
|
87
132
|
async function review(cells, context) {
|
|
88
133
|
context.signal.throwIfAborted();
|
|
89
|
-
const selected = cells.filter(cell => cell.local.status === 'passed' && cell.hasValue);
|
|
134
|
+
const selected = cells.filter((cell) => cell.local.status === 'passed' && cell.hasValue);
|
|
90
135
|
if (!selected.length)
|
|
91
136
|
return;
|
|
92
137
|
if (reviewPolicy === 'off') {
|
|
@@ -101,7 +146,7 @@ function defineAnswerFlow(definition) {
|
|
|
101
146
|
}
|
|
102
147
|
let checks;
|
|
103
148
|
try {
|
|
104
|
-
checks = await (0, cancellation_js_1.awaitWithSignal)(reviewValues({ items: selected.map(cell => ({ item: cell.item, value: cell.value })) }, context), context.signal);
|
|
149
|
+
checks = await (0, cancellation_js_1.awaitWithSignal)(reviewValues({ items: selected.map((cell) => ({ item: cell.item, value: cell.value })) }, context), context.signal);
|
|
105
150
|
}
|
|
106
151
|
catch {
|
|
107
152
|
context.signal.throwIfAborted();
|
|
@@ -110,7 +155,10 @@ function defineAnswerFlow(definition) {
|
|
|
110
155
|
return;
|
|
111
156
|
}
|
|
112
157
|
context.signal.throwIfAborted();
|
|
113
|
-
if (!checks ||
|
|
158
|
+
if (!checks ||
|
|
159
|
+
typeof checks.get !== 'function' ||
|
|
160
|
+
typeof checks.keys !== 'function' ||
|
|
161
|
+
[...checks.keys()].some((id) => !selected.some((cell) => cell.item.id === id)))
|
|
114
162
|
throw new TypeError('Invalid answer review ownership');
|
|
115
163
|
const checked = new Map([...checks].map(([id, result]) => [id, (0, check_result_js_1.snapshotAnswerCheck)(result)]));
|
|
116
164
|
for (const cell of selected) {
|
|
@@ -121,32 +169,140 @@ function defineAnswerFlow(definition) {
|
|
|
121
169
|
cell.knownReviewFailure = false;
|
|
122
170
|
}
|
|
123
171
|
}
|
|
124
|
-
const workflow = (0, workflow_js_1.defineWorkflow)({
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
{
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
172
|
+
const workflow = (0, workflow_js_1.defineWorkflow)({
|
|
173
|
+
id: 'answer-flow',
|
|
174
|
+
entryNodeId: 'generate',
|
|
175
|
+
nodes: [
|
|
176
|
+
{
|
|
177
|
+
id: 'generate',
|
|
178
|
+
description: 'Generate available items',
|
|
179
|
+
startsRound: true,
|
|
180
|
+
run: async (state, context) => {
|
|
181
|
+
await generate(state.cells.filter((cell) => cell.item.sourceStatus === 'ready'), false, context);
|
|
182
|
+
},
|
|
183
|
+
routes: [{ id: 'to-validate', targetNodeId: 'validate' }],
|
|
184
|
+
},
|
|
185
|
+
{
|
|
186
|
+
id: 'validate',
|
|
187
|
+
description: 'Check values and retain sanitized output',
|
|
188
|
+
run: (state, context) => {
|
|
189
|
+
check(state.cells.filter((cell) => cell.item.sourceStatus === 'ready'), context);
|
|
190
|
+
},
|
|
191
|
+
routes: [{ id: 'to-review', targetNodeId: 'review' }],
|
|
192
|
+
},
|
|
193
|
+
{
|
|
194
|
+
id: 'review',
|
|
195
|
+
description: 'Review locally accepted values',
|
|
196
|
+
run: async (state, context) => {
|
|
197
|
+
await review(state.cells.filter((cell) => cell.item.sourceStatus === 'ready'), context);
|
|
198
|
+
observe('checked', state.cells, context);
|
|
199
|
+
},
|
|
200
|
+
routes: [{ id: 'to-select-repair', targetNodeId: 'select-repair' }],
|
|
201
|
+
},
|
|
202
|
+
{
|
|
203
|
+
id: 'select-repair',
|
|
204
|
+
description: 'Select only failed available items',
|
|
205
|
+
run: (state) => ({
|
|
206
|
+
pending: state.cells.filter((cell) => cell.item.sourceStatus === 'ready' && issues(cell).length > 0),
|
|
207
|
+
}),
|
|
208
|
+
routes: [
|
|
209
|
+
{
|
|
210
|
+
id: 'to-repair',
|
|
211
|
+
conditionId: '{nid}.{rid}',
|
|
212
|
+
when: (state, context) => state.pending.length > 0 && state.repairBudget.available && allowed(context),
|
|
213
|
+
targetNodeId: 'repair',
|
|
214
|
+
},
|
|
215
|
+
{ id: 'to-deliver', targetNodeId: 'deliver' },
|
|
216
|
+
],
|
|
217
|
+
},
|
|
218
|
+
{
|
|
219
|
+
id: 'repair',
|
|
220
|
+
description: 'Use one bounded repair attempt',
|
|
221
|
+
startsRound: true,
|
|
222
|
+
run: async (state, context) => {
|
|
223
|
+
if (!state.repairBudget.take())
|
|
224
|
+
throw new TypeError('Answer repair budget exhausted');
|
|
225
|
+
await generate(state.pending, true, context);
|
|
226
|
+
},
|
|
227
|
+
routes: [{ id: 'to-recheck', targetNodeId: 'recheck' }],
|
|
228
|
+
},
|
|
229
|
+
{
|
|
230
|
+
id: 'recheck',
|
|
231
|
+
description: 'Recheck only repaired items',
|
|
232
|
+
run: async (state, context) => {
|
|
233
|
+
const generated = state.pending.filter((cell) => cell.generated);
|
|
234
|
+
check(generated, context);
|
|
235
|
+
await review(generated, context);
|
|
236
|
+
observe('repaired', state.pending, context);
|
|
237
|
+
},
|
|
238
|
+
routes: [{ id: 'to-select-repair', targetNodeId: 'select-repair' }],
|
|
239
|
+
},
|
|
240
|
+
{
|
|
241
|
+
id: 'deliver',
|
|
242
|
+
description: 'Return accepted values or explicit fallback states',
|
|
243
|
+
run: (state, context) => ({
|
|
244
|
+
result: state.cells.map((cell) => {
|
|
133
245
|
context.signal.throwIfAborted();
|
|
134
246
|
const errors = issues(cell);
|
|
135
247
|
if (cell.item.sourceStatus === 'ready' && !errors.length && cell.hasValue)
|
|
136
|
-
return {
|
|
248
|
+
return {
|
|
249
|
+
item: cell.item,
|
|
250
|
+
value: cell.value,
|
|
251
|
+
status: 'accepted',
|
|
252
|
+
issues: errors,
|
|
253
|
+
checks: { local: cell.local, review: cell.review },
|
|
254
|
+
};
|
|
137
255
|
const outcome = (0, synchronous_js_1.synchronous)(fallbackValue({ item: cell.item, issues: errors }, context), 'Answer fallback must be synchronous');
|
|
138
|
-
if (!outcome ||
|
|
256
|
+
if (!outcome ||
|
|
257
|
+
typeof outcome.handled !== 'boolean' ||
|
|
258
|
+
(outcome.handled && !('value' in outcome)))
|
|
139
259
|
throw new TypeError('Invalid answer fallback outcome');
|
|
140
|
-
return {
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
260
|
+
return {
|
|
261
|
+
item: cell.item,
|
|
262
|
+
value: outcome.handled ? outcome.value : undefined,
|
|
263
|
+
status: outcome.handled ? 'fallback' : 'blocked',
|
|
264
|
+
issues: errors,
|
|
265
|
+
checks: { local: cell.local, review: cell.review },
|
|
266
|
+
};
|
|
267
|
+
}),
|
|
268
|
+
}),
|
|
269
|
+
routes: [{ id: 'complete', complete: (state) => state.result }],
|
|
270
|
+
},
|
|
271
|
+
],
|
|
272
|
+
});
|
|
273
|
+
return Object.freeze({
|
|
274
|
+
/**
|
|
275
|
+
* Run one answer batch.
|
|
276
|
+
*
|
|
277
|
+
* @param request - Input ids the batch must cover and the items to answer; validated before
|
|
278
|
+
* any handler runs.
|
|
279
|
+
* @param context - Operation context supplying app, signal and diagnostics.
|
|
280
|
+
* @returns One accepted, fallback or blocked result per item, in request order.
|
|
281
|
+
* @throws TypeError For an invalid batch or handler output, or when the repair budget is
|
|
282
|
+
* exhausted without a final result.
|
|
283
|
+
*/
|
|
284
|
+
async run(request, context) {
|
|
144
285
|
context.signal.throwIfAborted();
|
|
145
286
|
(0, batch_js_1.validateAnswerBatch)(request.inputIds, request.items, maxItems);
|
|
146
|
-
const cells = request.items.map(item => ({
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
287
|
+
const cells = request.items.map((item) => ({
|
|
288
|
+
item: Object.freeze({
|
|
289
|
+
id: item.id,
|
|
290
|
+
data: item.data,
|
|
291
|
+
sourceStatus: item.sourceStatus,
|
|
292
|
+
inputIds: Object.freeze([...item.inputIds]),
|
|
293
|
+
}),
|
|
294
|
+
hasValue: false,
|
|
295
|
+
local: { status: 'not-run', issues: [] },
|
|
296
|
+
review: { status: 'not-run', issues: [] },
|
|
297
|
+
knownReviewFailure: false,
|
|
298
|
+
}));
|
|
299
|
+
return new engine_js_1.AgentCoreEngine({
|
|
300
|
+
maxRounds: maxRepairs + 1,
|
|
301
|
+
errors: { exhausted: () => new TypeError('Answer flow exhausted') },
|
|
302
|
+
execution: { signal: context.signal, diagnostics: context.diagnostics },
|
|
303
|
+
})
|
|
304
|
+
.bindWorkflow(workflow, context.app)
|
|
305
|
+
.run({ cells, pending: [], repairBudget: new workflow_js_1.AttemptBudget(maxRepairs) });
|
|
306
|
+
},
|
|
307
|
+
});
|
|
152
308
|
}
|
|
@@ -15,6 +15,17 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
exports.Answering = void 0;
|
|
18
|
+
/**
|
|
19
|
+
* Answering Kit entry: batch validation, per-value checks, task/reader catalogs and the
|
|
20
|
+
* generate-check-review-repair workflow.
|
|
21
|
+
*
|
|
22
|
+
* Place in the package: an optional App-side library for answering a bounded batch of items.
|
|
23
|
+
* Models, readers, checks, fallbacks and repair policy are supplied by the App; this module
|
|
24
|
+
* owns their composition, bounds and status aggregation. Core never imports it.
|
|
25
|
+
*
|
|
26
|
+
* Exports: everything from `./flow.js`, `./tasks.js`, `./batch.js` and `./checks.js`, plus the
|
|
27
|
+
* `Answering` namespace object.
|
|
28
|
+
*/
|
|
18
29
|
__exportStar(require("./flow.js"), exports);
|
|
19
30
|
__exportStar(require("./tasks.js"), exports);
|
|
20
31
|
__exportStar(require("./batch.js"), exports);
|
|
@@ -23,4 +34,11 @@ const tasks_js_1 = require("./tasks.js");
|
|
|
23
34
|
const checks_js_1 = require("./checks.js");
|
|
24
35
|
const flow_js_1 = require("./flow.js");
|
|
25
36
|
const batch_js_1 = require("./batch.js");
|
|
26
|
-
|
|
37
|
+
/** Namespace object for callers that prefer one import over named helpers. */
|
|
38
|
+
exports.Answering = Object.freeze({
|
|
39
|
+
defineAnswerTaskCatalog: tasks_js_1.defineAnswerTaskCatalog,
|
|
40
|
+
defineAnswerReaderCatalog: tasks_js_1.defineAnswerReaderCatalog,
|
|
41
|
+
defineAnswerCheckCatalog: checks_js_1.defineAnswerCheckCatalog,
|
|
42
|
+
defineAnswerFlow: flow_js_1.defineAnswerFlow,
|
|
43
|
+
validateAnswerBatch: batch_js_1.validateAnswerBatch,
|
|
44
|
+
});
|
|
@@ -2,36 +2,84 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.defineAnswerReaderCatalog = defineAnswerReaderCatalog;
|
|
4
4
|
exports.defineAnswerTaskCatalog = defineAnswerTaskCatalog;
|
|
5
|
+
/**
|
|
6
|
+
* Answering Kit: answer tasks, their readers, schemas and metadata.
|
|
7
|
+
*
|
|
8
|
+
* Place in the package: part of the `answering` Kit. A task binds an intent set, a scope, an
|
|
9
|
+
* output contract, check ids and a reader; this module compiles that binding, validates the
|
|
10
|
+
* reader ids and exposes read/describe entry points. Readers stay App-owned I/O.
|
|
11
|
+
*
|
|
12
|
+
* Exports: `defineAnswerReaderCatalog`, `defineAnswerTaskCatalog`, and the task/reader types.
|
|
13
|
+
*/
|
|
5
14
|
const catalog_js_1 = require("../../utils/catalog.js");
|
|
6
15
|
const synchronous_js_1 = require("../../utils/synchronous.js");
|
|
7
16
|
const object_js_1 = require("../../utils/object.js");
|
|
8
17
|
const cancellation_js_1 = require("../../utils/cancellation.js");
|
|
9
18
|
const schema_adapter_js_1 = require("../../utils/schema-adapter.js");
|
|
10
|
-
/**
|
|
19
|
+
/**
|
|
20
|
+
* Compile a reader catalog.
|
|
21
|
+
*
|
|
22
|
+
* @param definitions - Readers with unique ids and a `read` handler.
|
|
23
|
+
* @returns A frozen catalog; unknown ids fail through `require`.
|
|
24
|
+
* @throws TypeError When a reader has no `read` handler.
|
|
25
|
+
*/
|
|
11
26
|
function defineAnswerReaderCatalog(definitions) {
|
|
12
|
-
return (0, catalog_js_1.readonlyCatalog)(definitions.map(reader => {
|
|
27
|
+
return (0, catalog_js_1.readonlyCatalog)(definitions.map((reader) => {
|
|
13
28
|
if (typeof reader.read !== 'function')
|
|
14
29
|
throw new TypeError('Invalid answer reader');
|
|
15
30
|
return Object.freeze({ id: reader.id, read: reader.read.bind(reader) });
|
|
16
|
-
}), id => new TypeError(`Unknown answer reader: ${id}`));
|
|
31
|
+
}), (id) => new TypeError(`Unknown answer reader: ${id}`));
|
|
17
32
|
}
|
|
33
|
+
/**
|
|
34
|
+
* Compile the answer task catalog from its declarations and shared ports.
|
|
35
|
+
*
|
|
36
|
+
* Task ids, schemas, readers, outputs and checks have one compiled authority: a task can only
|
|
37
|
+
* reference a reader or check that the ports actually registered, and metadata is cloned and
|
|
38
|
+
* frozen so later mutation by the caller cannot change a registered task.
|
|
39
|
+
*
|
|
40
|
+
* @param definitions - Task declarations with identity, reader/output/scope references,
|
|
41
|
+
* intent ids, check ids, input schema and metadata.
|
|
42
|
+
* @param ports - Registered readers, checks, outputs and an optional definition assertion.
|
|
43
|
+
* @returns A frozen catalog extended with `describe`, `read` and `readAsync`.
|
|
44
|
+
* @throws TypeError For a task with missing identity, an unknown reader/output/check, empty or
|
|
45
|
+
* duplicate intent ids, a duplicate check id, or a failed definition assertion.
|
|
46
|
+
*/
|
|
18
47
|
function defineAnswerTaskCatalog(definitions, ports) {
|
|
19
48
|
const readers = defineAnswerReaderCatalog([...ports.readers.values()]);
|
|
20
49
|
const checkIds = ports.checks.ids();
|
|
21
50
|
const assertDefinition = ports.assertDefinition?.bind(ports);
|
|
22
51
|
const outputs = new Set(ports.outputs.ids());
|
|
23
|
-
const tasks = definitions.map(definition => {
|
|
24
|
-
if (!definition.id?.trim() ||
|
|
25
|
-
|
|
26
|
-
|
|
52
|
+
const tasks = definitions.map((definition) => {
|
|
53
|
+
if (!definition.id?.trim() ||
|
|
54
|
+
!definition.description?.trim() ||
|
|
55
|
+
!readers.has(definition.readerId) ||
|
|
56
|
+
!outputs.has(definition.outputId) ||
|
|
57
|
+
!Array.isArray(definition.intentIds) ||
|
|
58
|
+
!definition.intentIds.length ||
|
|
59
|
+
definition.intentIds.some((id) => typeof id !== 'string' || !id.trim()) ||
|
|
60
|
+
new Set(definition.intentIds).size !== definition.intentIds.length ||
|
|
61
|
+
!Array.isArray(definition.checkIds) ||
|
|
62
|
+
new Set(definition.checkIds).size !== definition.checkIds.length ||
|
|
63
|
+
definition.checkIds.some((id) => !checkIds.includes(id)))
|
|
27
64
|
throw new TypeError(`Invalid answer task: ${definition.id}`);
|
|
28
65
|
const metadata = structuredClone(definition.metadata);
|
|
29
66
|
(0, object_js_1.freezeSchema)(metadata);
|
|
30
|
-
const task = Object.freeze({
|
|
67
|
+
const task = Object.freeze({
|
|
68
|
+
...definition,
|
|
69
|
+
id: definition.id,
|
|
70
|
+
description: definition.description,
|
|
71
|
+
readerId: definition.readerId,
|
|
72
|
+
outputId: definition.outputId,
|
|
73
|
+
scopeId: definition.scopeId,
|
|
74
|
+
intentIds: Object.freeze([...definition.intentIds]),
|
|
75
|
+
checkIds: Object.freeze([...definition.checkIds]),
|
|
76
|
+
inputSchema: (0, schema_adapter_js_1.snapshotSchemaAdapter)(definition.inputSchema),
|
|
77
|
+
metadata,
|
|
78
|
+
});
|
|
31
79
|
(0, synchronous_js_1.assertion)(assertDefinition?.(task), 'Task assertions must return void synchronously');
|
|
32
80
|
return task;
|
|
33
81
|
});
|
|
34
|
-
const catalog = (0, catalog_js_1.readonlyCatalog)(tasks, id => new TypeError(`Unknown answer task: ${id}`));
|
|
82
|
+
const catalog = (0, catalog_js_1.readonlyCatalog)(tasks, (id) => new TypeError(`Unknown answer task: ${id}`));
|
|
35
83
|
const prepare = (request, context) => {
|
|
36
84
|
context.signal.throwIfAborted();
|
|
37
85
|
const task = catalog.require(request.taskId);
|
|
@@ -39,17 +87,44 @@ function defineAnswerTaskCatalog(definitions, ports) {
|
|
|
39
87
|
context.signal.throwIfAborted();
|
|
40
88
|
return { input, task, reader: readers.require(task.readerId) };
|
|
41
89
|
};
|
|
42
|
-
return Object.freeze({
|
|
43
|
-
|
|
90
|
+
return Object.freeze({
|
|
91
|
+
...catalog,
|
|
92
|
+
/** Task metadata with the JSON schema flattened for model or admin presentation. */
|
|
93
|
+
describe: () => tasks.map(({ inputSchema, ...task }) => ({
|
|
94
|
+
...task,
|
|
95
|
+
inputJsonSchema: inputSchema.jsonSchema,
|
|
96
|
+
})),
|
|
97
|
+
/**
|
|
98
|
+
* Read evidence through a task's registered reader, synchronously.
|
|
99
|
+
*
|
|
100
|
+
* @throws TypeError For an unknown task, a parse failure, or a reader returning a Promise.
|
|
101
|
+
*/
|
|
44
102
|
read(request, context) {
|
|
45
103
|
const { input, task, reader } = prepare(request, context);
|
|
46
|
-
const value = (0, synchronous_js_1.synchronous)(reader.read(input, {
|
|
104
|
+
const value = (0, synchronous_js_1.synchronous)(reader.read(input, {
|
|
105
|
+
...context,
|
|
106
|
+
app: context.app,
|
|
107
|
+
signal: context.signal,
|
|
108
|
+
diagnostics: context.diagnostics,
|
|
109
|
+
task,
|
|
110
|
+
}), 'Synchronous answer readers must not return a Promise');
|
|
47
111
|
context.signal.throwIfAborted();
|
|
48
112
|
return value;
|
|
49
113
|
},
|
|
114
|
+
/**
|
|
115
|
+
* Read evidence through a task's registered reader, awaiting an async reader.
|
|
116
|
+
*
|
|
117
|
+
* @throws TypeError For an unknown task or a parse failure; aborts with the caller's signal.
|
|
118
|
+
*/
|
|
50
119
|
async readAsync(request, context) {
|
|
51
120
|
const { input, task, reader } = prepare(request, context);
|
|
52
|
-
const value = await (0, cancellation_js_1.awaitWithSignal)(reader.read(input, {
|
|
121
|
+
const value = await (0, cancellation_js_1.awaitWithSignal)(reader.read(input, {
|
|
122
|
+
...context,
|
|
123
|
+
app: context.app,
|
|
124
|
+
signal: context.signal,
|
|
125
|
+
diagnostics: context.diagnostics,
|
|
126
|
+
task,
|
|
127
|
+
}), context.signal);
|
|
53
128
|
context.signal.throwIfAborted();
|
|
54
129
|
return value;
|
|
55
130
|
},
|
|
@@ -2,19 +2,41 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Artifacts = void 0;
|
|
4
4
|
exports.defineArtifactCatalog = defineArtifactCatalog;
|
|
5
|
+
/**
|
|
6
|
+
* Artifacts Kit: resolve opaque artifact references through App-registered resolvers.
|
|
7
|
+
*
|
|
8
|
+
* Place in the package: an optional App-side library. A reference only names a resolver and
|
|
9
|
+
* an artifact; the resolver, not this module, establishes access, provenance and whether the
|
|
10
|
+
* referenced revision is still current. Nothing is cached or persisted here.
|
|
11
|
+
*
|
|
12
|
+
* Exports: `defineArtifactCatalog`, `Artifacts`, and the artifact reference/resolver types.
|
|
13
|
+
*/
|
|
5
14
|
const cancellation_js_1 = require("../utils/cancellation.js");
|
|
6
15
|
const catalog_js_1 = require("../utils/catalog.js");
|
|
7
16
|
function snapshotArtifactReference(reference) {
|
|
8
17
|
if (!reference || typeof reference !== 'object')
|
|
9
18
|
throw new TypeError('Invalid artifact reference');
|
|
10
19
|
const { resolverId, artifactId, revision } = reference;
|
|
11
|
-
if (typeof resolverId !== 'string' ||
|
|
12
|
-
|
|
20
|
+
if (typeof resolverId !== 'string' ||
|
|
21
|
+
!resolverId.trim() ||
|
|
22
|
+
typeof artifactId !== 'string' ||
|
|
23
|
+
!artifactId.trim() ||
|
|
24
|
+
(revision !== undefined && (typeof revision !== 'string' || !revision.trim())))
|
|
13
25
|
throw new TypeError('Invalid artifact reference');
|
|
14
26
|
return Object.freeze({ resolverId, artifactId, ...(revision === undefined ? {} : { revision }) });
|
|
15
27
|
}
|
|
28
|
+
/**
|
|
29
|
+
* Compile a catalog of artifact resolvers plus a checked `resolve` entry point.
|
|
30
|
+
*
|
|
31
|
+
* @param definitions - Resolvers keyed by their own non-empty `id`; duplicate ids are rejected
|
|
32
|
+
* by the underlying catalog.
|
|
33
|
+
* @returns A frozen catalog (`ids`/`has`/`get`/`require`/`values`/`entries`) extended with
|
|
34
|
+
* `resolve(reference, context)`.
|
|
35
|
+
* @throws TypeError At construction for malformed resolver definitions, and from `resolve`
|
|
36
|
+
* for an unknown resolver, an invalid reference snapshot, or a missing `OperationContext`.
|
|
37
|
+
*/
|
|
16
38
|
function defineArtifactCatalog(definitions) {
|
|
17
|
-
const compiled = definitions.map(definition => {
|
|
39
|
+
const compiled = definitions.map((definition) => {
|
|
18
40
|
if (!definition || typeof definition !== 'object')
|
|
19
41
|
throw new TypeError('Use an artifact resolver id and OperationContext');
|
|
20
42
|
const { id, resolve } = definition;
|
|
@@ -22,7 +44,16 @@ function defineArtifactCatalog(definitions) {
|
|
|
22
44
|
throw new TypeError('Invalid artifact resolver');
|
|
23
45
|
return Object.freeze({ id, resolve: resolve.bind(definition) });
|
|
24
46
|
});
|
|
25
|
-
const catalog = (0, catalog_js_1.readonlyCatalog)(compiled, id => new TypeError(`Unregistered artifact resolver: ${id}`));
|
|
47
|
+
const catalog = (0, catalog_js_1.readonlyCatalog)(compiled, (id) => new TypeError(`Unregistered artifact resolver: ${id}`));
|
|
48
|
+
/**
|
|
49
|
+
* Resolve one reference through its registered resolver.
|
|
50
|
+
*
|
|
51
|
+
* @param reference - Resolver id, artifact id and optional revision; snapshotted and frozen
|
|
52
|
+
* before the call so a handler cannot observe later mutation.
|
|
53
|
+
* @param context - Operation context supplying the abort signal.
|
|
54
|
+
* @returns The resolver's value.
|
|
55
|
+
* @throws TypeError For a malformed reference or context, or an unknown resolver id.
|
|
56
|
+
*/
|
|
26
57
|
async function resolve(reference, context) {
|
|
27
58
|
if (!context?.signal)
|
|
28
59
|
throw new TypeError('Artifact resolution requires OperationContext');
|
|
@@ -35,4 +66,5 @@ function defineArtifactCatalog(definitions) {
|
|
|
35
66
|
}
|
|
36
67
|
return Object.freeze({ ...catalog, resolve });
|
|
37
68
|
}
|
|
69
|
+
/** Namespace object for callers that prefer one import over named helpers. */
|
|
38
70
|
exports.Artifacts = Object.freeze({ defineArtifactCatalog });
|
|
@@ -3,7 +3,19 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.Candidates = void 0;
|
|
4
4
|
exports.defineCandidateSelection = defineCandidateSelection;
|
|
5
5
|
const rules_js_1 = require("../utils/rules.js");
|
|
6
|
-
/**
|
|
6
|
+
/**
|
|
7
|
+
* Compile an alternative-proposal envelope contract.
|
|
8
|
+
*
|
|
9
|
+
* Alternative proposals are bounded and shallow; accepting a task closes this capability.
|
|
10
|
+
* A value that is not an object, or that does not carry the candidate field, is treated as a
|
|
11
|
+
* single implicit candidate and returned as-is. Once the envelope is present it must contain
|
|
12
|
+
* only that field, and its array must hold between `minCandidates` (default 1) and
|
|
13
|
+
* `maxCandidates` distinct candidate objects that do not themselves repeat the field.
|
|
14
|
+
*
|
|
15
|
+
* @param definition - Field name, bounds, optional error wording and diagnostic tags.
|
|
16
|
+
* @returns A frozen selector exposing `field`, the resolved bounds and `parse`.
|
|
17
|
+
* @throws TypeError When the field name or bounds are invalid.
|
|
18
|
+
*/
|
|
7
19
|
function defineCandidateSelection(definition) {
|
|
8
20
|
const { field, error: configuredError, maxCandidates: max } = definition;
|
|
9
21
|
const error = typeof configuredError === 'function' ? configuredError.bind(definition) : configuredError;
|
|
@@ -11,8 +23,22 @@ function defineCandidateSelection(definition) {
|
|
|
11
23
|
const tags = [...(definition.tags ?? [])];
|
|
12
24
|
(0, rules_js_1.breakWhile)([
|
|
13
25
|
{ occur: () => !field.trim(), error: 'Missing candidate field' },
|
|
14
|
-
{
|
|
26
|
+
{
|
|
27
|
+
occur: [
|
|
28
|
+
() => !Number.isSafeInteger(min) || !Number.isSafeInteger(max),
|
|
29
|
+
() => min < 1 || max < min,
|
|
30
|
+
],
|
|
31
|
+
error: 'Invalid candidate bounds',
|
|
32
|
+
},
|
|
15
33
|
]);
|
|
34
|
+
/**
|
|
35
|
+
* Unpack the candidates from one parsed reply value.
|
|
36
|
+
*
|
|
37
|
+
* @param request - The raw value plus whether proposals are still allowed at this point.
|
|
38
|
+
* @returns The candidate list, or `[value]` when no envelope is present.
|
|
39
|
+
* @throws TypeError When `allowed` is not boolean, or when the envelope is disallowed,
|
|
40
|
+
* malformed, out of bounds or contains nested candidate envelopes.
|
|
41
|
+
*/
|
|
16
42
|
function parse({ value, allowed }) {
|
|
17
43
|
if (typeof allowed !== 'boolean')
|
|
18
44
|
throw new TypeError('Candidate availability must be boolean');
|
|
@@ -21,9 +47,24 @@ function defineCandidateSelection(definition) {
|
|
|
21
47
|
const candidates = value[field];
|
|
22
48
|
(0, rules_js_1.breakWhile)([
|
|
23
49
|
{ occur: () => !allowed, error, tags: ['availability'] },
|
|
24
|
-
{
|
|
25
|
-
|
|
26
|
-
|
|
50
|
+
{
|
|
51
|
+
occur: () => Array.isArray(value) || Object.keys(value).length !== 1,
|
|
52
|
+
error,
|
|
53
|
+
tags: ['envelope'],
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
occur: [
|
|
57
|
+
() => !Array.isArray(candidates),
|
|
58
|
+
() => candidates.length < min || candidates.length > max,
|
|
59
|
+
],
|
|
60
|
+
error,
|
|
61
|
+
tags: ['selection'],
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
occur: () => candidates.some((candidate) => invalidCandidate(candidate, field)),
|
|
65
|
+
error,
|
|
66
|
+
tags: ['members'],
|
|
67
|
+
},
|
|
27
68
|
], tags);
|
|
28
69
|
return candidates;
|
|
29
70
|
}
|
|
@@ -34,4 +75,5 @@ function invalidCandidate(value, field) {
|
|
|
34
75
|
return true;
|
|
35
76
|
return Object.hasOwn(value, field);
|
|
36
77
|
}
|
|
78
|
+
/** Namespace object for callers that prefer one import over named helpers. */
|
|
37
79
|
exports.Candidates = Object.freeze({ defineCandidateSelection });
|