@jangts/agent-core 0.1.1 → 0.2.1
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 +25 -0
- package/LICENSE +55 -0
- package/NOTICE +6 -0
- package/README.md +8 -0
- package/development/docs/README.en.md +70 -0
- package/development/docs/README.md +1 -1
- package/development/docs/acceptance.en.md +34 -0
- package/development/docs/agent-development.en.md +42 -0
- package/development/docs/api/README.en.md +62 -0
- package/development/docs/api/advanced-agents.en.md +135 -0
- package/development/docs/api/context-processing.en.md +110 -0
- package/development/docs/api/core.en.md +274 -0
- package/development/docs/api/examples.en.md +118 -0
- package/development/docs/api/kits.en.md +183 -0
- package/development/docs/api/knowledge-answering.en.md +166 -0
- package/development/docs/api/mock.en.md +186 -0
- package/development/docs/api/observability.en.md +166 -0
- package/development/docs/api/reference.en.md +2235 -0
- package/development/docs/api/reference.md +1907 -1874
- package/development/docs/api/support.en.md +252 -0
- package/development/docs/api/support.md +27 -0
- package/development/docs/api/types.en.md +181 -0
- package/development/docs/api/workflow.en.md +188 -0
- package/development/docs/basic-usage.en.md +78 -0
- package/development/docs/create-app.en.md +76 -0
- package/development/docs/examples/offline-agent.en.md +273 -0
- package/development/docs/examples.en.md +36 -0
- package/development/docs/flows/knowledge-maintenance.en.md +38 -0
- package/development/docs/getting-started.en.md +71 -0
- package/development/docs/knowledge.en.md +89 -0
- package/development/docs/maintenance.en.md +62 -0
- package/development/docs/materials.en.md +38 -0
- package/development/docs/mechanisms.en.md +227 -0
- package/development/docs/memory-and-learning.en.md +42 -0
- package/development/docs/operations.en.md +51 -0
- package/development/docs/records.en.md +63 -0
- package/development/docs/registration.en.md +63 -0
- package/development/skills/agent-core-app/scripts/create-app.mjs +286 -70
- package/development/skills/agent-core-app/scripts/lib/knowledge.mjs +77 -16
- package/development/skills/agent-core-app/scripts/lib/source.mjs +30 -2
- package/development/skills/agent-core-app/scripts/plan.mjs +46 -12
- package/development/skills/agent-core-app/scripts/prepare-source.mjs +61 -10
- package/development/skills/agent-core-app/scripts/resources.mjs +62 -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 +17 -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 +33 -0
- package/dist/cjs/support/model/completion/index.js +28 -0
- package/dist/cjs/support/model/completion/session.js +107 -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.d.ts +6 -0
- package/dist/esm/diagnostics/catalog.js +17 -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 +39 -0
- package/dist/esm/structs/kits/search.d.ts +24 -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 +34 -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 +54 -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 +65 -3
- package/dist/esm/support/context/nodes.js +165 -36
- package/dist/esm/support/context/processing.d.ts +152 -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 +34 -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 +11 -0
- package/dist/esm/support/model/completion/default.js +30 -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 +16 -0
- package/dist/esm/support/model/completion/session.js +104 -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 +26 -2
- package/dist/esm/support/model/preview-rules.js +66 -16
- package/dist/esm/support/model/reply-preview.d.ts +22 -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 +28 -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 +7 -3
|
@@ -2,8 +2,18 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.WorkflowContractError = exports.route = exports.requireWorkflowValue = exports.AttemptBudget = exports.AgentWorkflow = void 0;
|
|
4
4
|
exports.defineWorkflow = defineWorkflow;
|
|
5
|
+
/**
|
|
6
|
+
* Derive unique route ids for one node.
|
|
7
|
+
*
|
|
8
|
+
* Explicit ids are reserved before any suffix is generated, so a generated `~2` id can
|
|
9
|
+
* never collide with an id that is already declared later in the same node. The first
|
|
10
|
+
* occurrence keeps its id; later duplicates are renamed deterministically in order.
|
|
11
|
+
*
|
|
12
|
+
* @param routes - Routes of one node, in declaration order.
|
|
13
|
+
* @returns One id per route, using undefined where the route declared none.
|
|
14
|
+
*/
|
|
5
15
|
function assignRouteIds(routes) {
|
|
6
|
-
const reserved = new Set(routes.map(route => route.id));
|
|
16
|
+
const reserved = new Set(routes.map((route) => route.id));
|
|
7
17
|
const used = new Set();
|
|
8
18
|
return routes.map(({ id }) => {
|
|
9
19
|
if (id === undefined)
|
|
@@ -17,17 +27,44 @@ function assignRouteIds(routes) {
|
|
|
17
27
|
return id;
|
|
18
28
|
});
|
|
19
29
|
}
|
|
30
|
+
/**
|
|
31
|
+
* Reject node fields that were renamed.
|
|
32
|
+
*
|
|
33
|
+
* Accepting `round` or `onError` silently would change budget and recovery behavior, so
|
|
34
|
+
* the older names are reported instead of being mapped.
|
|
35
|
+
*
|
|
36
|
+
* @param node - Node about to be registered.
|
|
37
|
+
* @throws TypeError When a renamed field is present.
|
|
38
|
+
*/
|
|
20
39
|
function validateNodeFields(node) {
|
|
21
40
|
if ('round' in node || 'onError' in node)
|
|
22
41
|
throw new TypeError(`Use startsRound and onErrorNodeId: ${node.id}`);
|
|
23
42
|
}
|
|
24
|
-
/**
|
|
43
|
+
/**
|
|
44
|
+
* Executable catalog: validate references and bounded cycles before any handler runs.
|
|
45
|
+
*
|
|
46
|
+
* Validation happens once, at construction, so traversal can assume every target exists
|
|
47
|
+
* and every cycle is budget-bounded.
|
|
48
|
+
*/
|
|
25
49
|
class AgentWorkflow {
|
|
50
|
+
/** Workflow id, also used in diagnostics and error messages. */
|
|
26
51
|
id;
|
|
52
|
+
/** First node visited; always starts a round. */
|
|
27
53
|
entryNodeId;
|
|
54
|
+
/** Optional revision passed through to diagnostics. */
|
|
28
55
|
revision;
|
|
56
|
+
/** Optional result guard; when present it must return exactly true. */
|
|
29
57
|
isResult;
|
|
30
58
|
nodes = new Map();
|
|
59
|
+
/**
|
|
60
|
+
* Build and validate a workflow.
|
|
61
|
+
*
|
|
62
|
+
* The entry node must start a round, because otherwise a workflow could loop forever
|
|
63
|
+
* without consuming the round budget. Renamed top-level fields are rejected as well.
|
|
64
|
+
*
|
|
65
|
+
* @param definition - Nodes, entry, id, optional revision and result guard.
|
|
66
|
+
* @throws TypeError When the definition, a node, a route or a graph invariant is invalid.
|
|
67
|
+
*/
|
|
31
68
|
constructor(definition) {
|
|
32
69
|
if ('entry' in definition || 'validateResult' in definition)
|
|
33
70
|
throw new TypeError('Use entryNodeId and isResult');
|
|
@@ -47,18 +84,33 @@ class AgentWorkflow {
|
|
|
47
84
|
this.checkReachability();
|
|
48
85
|
this.checkBoundedCycles();
|
|
49
86
|
}
|
|
87
|
+
/**
|
|
88
|
+
* Derive an extended workflow without mutating this catalog.
|
|
89
|
+
*
|
|
90
|
+
* Every node is copied with its callbacks rebound, so the new catalog keeps the same
|
|
91
|
+
* entry and result guard and can be composed repeatedly. Route overrides are keyed by
|
|
92
|
+
* node id and must name a node that exists after the merge.
|
|
93
|
+
*
|
|
94
|
+
* @param extension - Extension patch, or another workflow whose definitions are merged.
|
|
95
|
+
* @param routes - Route overrides keyed by node id.
|
|
96
|
+
* @returns A new, fully re-validated workflow.
|
|
97
|
+
* @throws TypeError When an override names an unknown node or a node is invalid.
|
|
98
|
+
*/
|
|
50
99
|
add(extension, routes = {}) {
|
|
51
100
|
const patch = extension instanceof AgentWorkflow ? { nodes: extension.definitions, routes } : extension;
|
|
52
101
|
for (const node of patch.nodes)
|
|
53
102
|
validateNodeFields(node);
|
|
54
103
|
const nodes = [...this.definitions, ...patch.nodes];
|
|
55
104
|
for (const id of Object.keys(patch.routes ?? {})) {
|
|
56
|
-
if (!nodes.some(node => node.id === id))
|
|
105
|
+
if (!nodes.some((node) => node.id === id))
|
|
57
106
|
throw new TypeError(`Unknown workflow route source: ${id}`);
|
|
58
107
|
}
|
|
59
108
|
return new AgentWorkflow({
|
|
60
|
-
id: this.id,
|
|
61
|
-
|
|
109
|
+
id: this.id,
|
|
110
|
+
revision: patch.revision,
|
|
111
|
+
entryNodeId: this.entryNodeId,
|
|
112
|
+
isResult: this.isResult,
|
|
113
|
+
nodes: nodes.map((node) => ({
|
|
62
114
|
id: node.id,
|
|
63
115
|
description: node.description,
|
|
64
116
|
name: node.name,
|
|
@@ -73,49 +125,117 @@ class AgentWorkflow {
|
|
|
73
125
|
})),
|
|
74
126
|
});
|
|
75
127
|
}
|
|
128
|
+
/**
|
|
129
|
+
* Look up a node that must exist.
|
|
130
|
+
*
|
|
131
|
+
* @param id - Node id.
|
|
132
|
+
* @returns The registered node.
|
|
133
|
+
* @throws TypeError When the node is unknown.
|
|
134
|
+
*/
|
|
76
135
|
require(id) {
|
|
77
136
|
const node = this.nodes.get(id);
|
|
78
137
|
if (!node)
|
|
79
138
|
throw new TypeError(`Unknown workflow node: ${id}`);
|
|
80
139
|
return node;
|
|
81
140
|
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
141
|
+
/** Frozen snapshot of all nodes, in registration order. */
|
|
142
|
+
get definitions() {
|
|
143
|
+
return Object.freeze([...this.nodes.values()]);
|
|
144
|
+
}
|
|
145
|
+
/** @returns A frozen array of node ids in registration order. */
|
|
146
|
+
ids() {
|
|
147
|
+
return Object.freeze([...this.nodes.keys()]);
|
|
148
|
+
}
|
|
149
|
+
/** @returns An iterator over the registered nodes. */
|
|
150
|
+
values() {
|
|
151
|
+
return this.nodes.values();
|
|
152
|
+
}
|
|
153
|
+
/** @returns An iterator over id/node pairs. */
|
|
154
|
+
entries() {
|
|
155
|
+
return this.nodes.entries();
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* @param id - Node id.
|
|
159
|
+
* @returns Whether the node is registered.
|
|
160
|
+
*/
|
|
161
|
+
has(id) {
|
|
162
|
+
return this.nodes.has(id);
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* @param id - Node id.
|
|
166
|
+
* @returns The node, or undefined when it is not registered.
|
|
167
|
+
*/
|
|
168
|
+
get(id) {
|
|
169
|
+
return this.nodes.get(id);
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Produce a serializable description of every node and route.
|
|
173
|
+
*
|
|
174
|
+
* Used by documentation and registration listings; it reports resolved ids and which
|
|
175
|
+
* routes are terminal or conditional, never the handler implementations.
|
|
176
|
+
*
|
|
177
|
+
* @returns An array of plain description objects in registration order.
|
|
178
|
+
*/
|
|
88
179
|
describe() {
|
|
89
|
-
return [...this.nodes.values()].map(node => ({
|
|
90
|
-
id: node.id,
|
|
91
|
-
|
|
92
|
-
|
|
180
|
+
return [...this.nodes.values()].map((node) => ({
|
|
181
|
+
id: node.id,
|
|
182
|
+
description: node.description,
|
|
183
|
+
...(node.name ? { name: node.name } : {}),
|
|
184
|
+
startsRound: node.startsRound === true,
|
|
185
|
+
onErrorNodeId: node.onErrorNodeId,
|
|
186
|
+
requires: node.requires ?? [],
|
|
187
|
+
provides: node.provides ?? [],
|
|
188
|
+
routes: node.routes.map((route) => ({
|
|
189
|
+
...(route.id !== undefined ? { id: route.id } : {}),
|
|
190
|
+
...(route.description !== undefined ? { description: route.description } : {}),
|
|
191
|
+
...(route.conditionId !== undefined ? { conditionId: route.conditionId } : {}),
|
|
192
|
+
targetNodeId: route.targetNodeId,
|
|
193
|
+
terminal: !!route.complete,
|
|
194
|
+
conditional: !!route.when,
|
|
195
|
+
})),
|
|
93
196
|
}));
|
|
94
197
|
}
|
|
198
|
+
/**
|
|
199
|
+
* Validate and freeze one node, then add it to the catalog.
|
|
200
|
+
*
|
|
201
|
+
* A route must be either a jump with a target or a completion, never both; an
|
|
202
|
+
* unconditional route must be last, because it would shadow every later route. Route
|
|
203
|
+
* ids and condition ids are resolved here so the engine never interpolates templates at
|
|
204
|
+
* run time.
|
|
205
|
+
*
|
|
206
|
+
* @param node - Node supplied by the workflow definition.
|
|
207
|
+
* @throws TypeError When the node, a route or a state contract is invalid.
|
|
208
|
+
*/
|
|
95
209
|
register(node) {
|
|
96
|
-
if (!node.id?.trim() ||
|
|
97
|
-
|
|
210
|
+
if (!node.id?.trim() ||
|
|
211
|
+
!node.description?.trim() ||
|
|
212
|
+
this.nodes.has(node.id) ||
|
|
213
|
+
!node.routes.length ||
|
|
214
|
+
(node.run !== undefined && typeof node.run !== 'function')) {
|
|
98
215
|
throw new TypeError('Invalid or duplicate workflow node');
|
|
99
216
|
}
|
|
100
217
|
validateNodeFields(node);
|
|
101
|
-
if (node.onErrorRouteId !== undefined && (!node.onErrorRouteId.trim() || !
|
|
218
|
+
if (node.onErrorRouteId !== undefined && (!node.onErrorRouteId.trim() || !node.onErrorNodeId))
|
|
102
219
|
throw new TypeError(`Invalid workflow error route identity: ${node.id}`);
|
|
103
220
|
const ids = assignRouteIds(node.routes);
|
|
104
221
|
for (const [index, route] of node.routes.entries()) {
|
|
105
|
-
if (
|
|
106
|
-
|
|
107
|
-
|
|
222
|
+
if ('to' in route ||
|
|
223
|
+
(route.id !== undefined && !route.id.trim()) ||
|
|
224
|
+
(route.conditionId !== undefined && (!route.conditionId.trim() || !route.when)))
|
|
108
225
|
throw new TypeError(`Invalid workflow route identity: ${node.id}`);
|
|
109
226
|
const hasTarget = typeof route.targetNodeId === 'string';
|
|
110
227
|
const hasCompletion = typeof route.complete === 'function';
|
|
111
228
|
const shadowsFollowingRoutes = !route.when && index !== node.routes.length - 1;
|
|
112
|
-
if (hasTarget === hasCompletion ||
|
|
113
|
-
||
|
|
229
|
+
if (hasTarget === hasCompletion ||
|
|
230
|
+
shadowsFollowingRoutes ||
|
|
231
|
+
(route.when !== undefined && typeof route.when !== 'function')) {
|
|
114
232
|
throw new TypeError(`Invalid or unreachable workflow route: ${node.id}`);
|
|
115
233
|
}
|
|
116
234
|
}
|
|
117
235
|
for (const fields of [node.requires, node.provides]) {
|
|
118
|
-
if (fields &&
|
|
236
|
+
if (fields &&
|
|
237
|
+
(fields.some((field) => typeof field !== 'string' || !field.trim()) ||
|
|
238
|
+
new Set(fields).size !== fields.length)) {
|
|
119
239
|
throw new TypeError(`Invalid workflow state contract: ${node.id}`);
|
|
120
240
|
}
|
|
121
241
|
}
|
|
@@ -128,29 +248,68 @@ class AgentWorkflow {
|
|
|
128
248
|
throw new TypeError(`Condition ID references a missing route ID: ${node.id}`);
|
|
129
249
|
return id;
|
|
130
250
|
});
|
|
131
|
-
const common = {
|
|
132
|
-
|
|
251
|
+
const common = {
|
|
252
|
+
id,
|
|
253
|
+
description: route.description,
|
|
254
|
+
conditionId,
|
|
255
|
+
when: route.when?.bind(route),
|
|
256
|
+
};
|
|
257
|
+
return Object.freeze(route.complete
|
|
258
|
+
? { ...common, complete: route.complete.bind(route) }
|
|
133
259
|
: { ...common, targetNodeId: route.targetNodeId });
|
|
134
260
|
}));
|
|
261
|
+
// The entry node starts a round unless it says otherwise; any other node starts one
|
|
262
|
+
// only when it declares it explicitly.
|
|
135
263
|
const startsRound = node.startsRound ?? (node.id === this.entryNodeId ? true : undefined);
|
|
136
|
-
this.nodes.set(node.id, Object.freeze({
|
|
137
|
-
|
|
264
|
+
this.nodes.set(node.id, Object.freeze({
|
|
265
|
+
...node,
|
|
266
|
+
id: node.id,
|
|
267
|
+
description: node.description,
|
|
268
|
+
name: node.name,
|
|
269
|
+
report: node.report?.bind(node),
|
|
270
|
+
startsRound,
|
|
271
|
+
onErrorRouteId: node.onErrorRouteId,
|
|
272
|
+
onErrorNodeId: node.onErrorNodeId,
|
|
273
|
+
run: node.run?.bind(node),
|
|
274
|
+
routes,
|
|
138
275
|
requires: node.requires ? Object.freeze([...node.requires]) : undefined,
|
|
139
276
|
provides: node.provides ? Object.freeze([...node.provides]) : undefined,
|
|
140
277
|
}));
|
|
141
278
|
}
|
|
279
|
+
/**
|
|
280
|
+
* Collect every node a visit can hand control to.
|
|
281
|
+
*
|
|
282
|
+
* Error targets are included so a recovery node is treated as reachable and is subject
|
|
283
|
+
* to the same cycle rule as a normal transition.
|
|
284
|
+
*
|
|
285
|
+
* @param node - Node whose outgoing edges are collected.
|
|
286
|
+
* @returns Target node ids, including the error node.
|
|
287
|
+
*/
|
|
142
288
|
targets(node) {
|
|
143
|
-
const targets = node.routes.flatMap(route => route.targetNodeId !== undefined ? [route.targetNodeId] : []);
|
|
289
|
+
const targets = node.routes.flatMap((route) => route.targetNodeId !== undefined ? [route.targetNodeId] : []);
|
|
144
290
|
if (node.onErrorNodeId !== undefined)
|
|
145
291
|
targets.push(node.onErrorNodeId);
|
|
146
292
|
return targets;
|
|
147
293
|
}
|
|
294
|
+
/**
|
|
295
|
+
* Require every route target to name a registered node.
|
|
296
|
+
*
|
|
297
|
+
* @throws TypeError When any target is unknown.
|
|
298
|
+
*/
|
|
148
299
|
checkReferences() {
|
|
149
300
|
for (const node of this.nodes.values()) {
|
|
150
301
|
for (const target of this.targets(node))
|
|
151
302
|
this.require(target);
|
|
152
303
|
}
|
|
153
304
|
}
|
|
305
|
+
/**
|
|
306
|
+
* Require every node to be reachable from the entry.
|
|
307
|
+
*
|
|
308
|
+
* An unreachable node is a declaration mistake: it would never run, yet it still
|
|
309
|
+
* appears in listings and documentation.
|
|
310
|
+
*
|
|
311
|
+
* @throws TypeError When any node cannot be reached.
|
|
312
|
+
*/
|
|
154
313
|
checkReachability() {
|
|
155
314
|
const reachable = new Set();
|
|
156
315
|
const visit = (id) => {
|
|
@@ -164,6 +323,11 @@ class AgentWorkflow {
|
|
|
164
323
|
if (reachable.size !== this.nodes.size)
|
|
165
324
|
throw new TypeError('Unreachable workflow node');
|
|
166
325
|
}
|
|
326
|
+
/**
|
|
327
|
+
* Require every cycle to cross a round boundary.
|
|
328
|
+
*
|
|
329
|
+
* @throws TypeError When a cycle can be traversed without ever starting a new round.
|
|
330
|
+
*/
|
|
167
331
|
checkBoundedCycles() {
|
|
168
332
|
// Graph traversal is procedural: every possible cycle, including error routes,
|
|
169
333
|
// must cross a round boundary so the engine can enforce the shared budget.
|
|
@@ -186,20 +350,47 @@ class AgentWorkflow {
|
|
|
186
350
|
}
|
|
187
351
|
}
|
|
188
352
|
exports.AgentWorkflow = AgentWorkflow;
|
|
353
|
+
/**
|
|
354
|
+
* Build a validated workflow from a definition.
|
|
355
|
+
*
|
|
356
|
+
* @param definition - Workflow definition; validated like the constructor argument.
|
|
357
|
+
* @returns A validated, immutable workflow catalog.
|
|
358
|
+
* @throws TypeError When the definition is invalid.
|
|
359
|
+
*/
|
|
189
360
|
function defineWorkflow(definition) {
|
|
190
361
|
return new AgentWorkflow(definition);
|
|
191
362
|
}
|
|
192
|
-
/**
|
|
363
|
+
/**
|
|
364
|
+
* Successful acquisitions consume attempts; a refused acquisition never grants another.
|
|
365
|
+
*
|
|
366
|
+
* `available` is a snapshot of the counter, not a reservation: a caller must still call
|
|
367
|
+
* `take` and honor its boolean result before acting.
|
|
368
|
+
*/
|
|
193
369
|
class AttemptBudget {
|
|
194
370
|
limit;
|
|
195
371
|
consumed = 0;
|
|
372
|
+
/**
|
|
373
|
+
* @param limit - Total attempts allowed; must be a nonnegative integer.
|
|
374
|
+
* @throws TypeError When `limit` is not a nonnegative integer.
|
|
375
|
+
*/
|
|
196
376
|
constructor(limit) {
|
|
197
377
|
this.limit = limit;
|
|
198
378
|
if (!Number.isInteger(limit) || limit < 0)
|
|
199
379
|
throw new TypeError('Attempt limit must be a nonnegative integer');
|
|
200
380
|
}
|
|
201
|
-
|
|
202
|
-
get
|
|
381
|
+
/** Attempts consumed so far. */
|
|
382
|
+
get used() {
|
|
383
|
+
return this.consumed;
|
|
384
|
+
}
|
|
385
|
+
/** Whether at least one attempt remains unspent. */
|
|
386
|
+
get available() {
|
|
387
|
+
return this.consumed < this.limit;
|
|
388
|
+
}
|
|
389
|
+
/**
|
|
390
|
+
* Consume one attempt if one remains.
|
|
391
|
+
*
|
|
392
|
+
* @returns True when the attempt was granted, false when the budget is exhausted.
|
|
393
|
+
*/
|
|
203
394
|
take() {
|
|
204
395
|
if (!this.available)
|
|
205
396
|
return false;
|
|
@@ -208,6 +399,7 @@ class AttemptBudget {
|
|
|
208
399
|
}
|
|
209
400
|
}
|
|
210
401
|
exports.AttemptBudget = AttemptBudget;
|
|
402
|
+
// Re-exported so workflow authors get state helpers and route builders from one module.
|
|
211
403
|
var state_js_1 = require("./state.js");
|
|
212
404
|
Object.defineProperty(exports, "requireWorkflowValue", { enumerable: true, get: function () { return state_js_1.requireWorkflowValue; } });
|
|
213
405
|
Object.defineProperty(exports, "route", { enumerable: true, get: function () { return state_js_1.route; } });
|
package/dist/cjs/index.js
CHANGED
|
@@ -37,6 +37,22 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
37
37
|
})();
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
39
|
exports.assembleContextPlan = exports.Support = exports.defineCandidateSelection = exports.ToolLifecycleRegistry = exports.defineTextSkillLoader = exports.defineRetrieval = exports.defineEvidenceProjection = exports.defineEvidenceChecklist = exports.assembleFragments = exports.defineRecoveryChain = exports.definePolicySet = exports.ValidationError = exports.BudgetError = exports.getErrorInfo = void 0;
|
|
40
|
+
/**
|
|
41
|
+
* Aggregate public entry of `@jangts/agent-core`: Core runtime contracts, one `Support`
|
|
42
|
+
* namespace with a few named Support helpers, and the declaration helpers of optional Kits.
|
|
43
|
+
*
|
|
44
|
+
* Layering. Core owns the runtime contracts Apps call (engine, model runner, capabilities,
|
|
45
|
+
* context, diagnostics) and the handler contracts Core calls back into the App. Support only
|
|
46
|
+
* supplies recommended implementations of those same contracts, so it is published as a single
|
|
47
|
+
* namespace instead of a second dispatch layer. Kits are optional business libraries reached
|
|
48
|
+
* through their own subpath entries; the Kit entries re-exported here are declaration helpers
|
|
49
|
+
* and standalone modules, not additional Core guarantees. Shared utilities are re-exported
|
|
50
|
+
* because they are needed alongside these contracts, and they carry no Agent semantics.
|
|
51
|
+
*
|
|
52
|
+
* Exports are grouped by responsibility, not by dependency order. Deep subpath entries
|
|
53
|
+
* (`/engine`, `/model`, `/tools`, `/context`, `/journal`, `/diagnostics`, `/kits/...`)
|
|
54
|
+
* resolve to the same implementations, so this file is a convenience surface only.
|
|
55
|
+
*/
|
|
40
56
|
__exportStar(require("./execution/engine.js"), exports);
|
|
41
57
|
var errors_js_1 = require("./errors.js");
|
|
42
58
|
Object.defineProperty(exports, "getErrorInfo", { enumerable: true, get: function () { return errors_js_1.getErrorInfo; } });
|
|
@@ -50,6 +66,8 @@ __exportStar(require("./model/index.js"), exports);
|
|
|
50
66
|
__exportStar(require("./capabilities/index.js"), exports);
|
|
51
67
|
__exportStar(require("./context/fragments.js"), exports);
|
|
52
68
|
__exportStar(require("./context/journal.js"), exports);
|
|
69
|
+
// Named re-export: the context barrel also forwards its Kit evidence helpers, which the
|
|
70
|
+
// root surface publishes separately below.
|
|
53
71
|
var assembly_js_1 = require("./context/assembly.js");
|
|
54
72
|
Object.defineProperty(exports, "assembleFragments", { enumerable: true, get: function () { return assembly_js_1.assembleFragments; } });
|
|
55
73
|
__exportStar(require("./support/context/assembly.js"), exports);
|
|
@@ -3,8 +3,27 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.Aggregation = void 0;
|
|
4
4
|
exports.mergeByKey = mergeByKey;
|
|
5
5
|
exports.defineQueryAggregation = defineQueryAggregation;
|
|
6
|
+
/**
|
|
7
|
+
* Aggregation Kit: fold several synchronous query results into one ordered item list.
|
|
8
|
+
*
|
|
9
|
+
* Place in the package: an optional App-side helper. Reads, selection rules and result
|
|
10
|
+
* semantics stay with the host; this module only sequences the calls and preserves order.
|
|
11
|
+
*
|
|
12
|
+
* Exports: `mergeByKey`, `defineQueryAggregation`, `Aggregation`.
|
|
13
|
+
*/
|
|
6
14
|
const synchronous_js_1 = require("../utils/synchronous.js");
|
|
7
|
-
/**
|
|
15
|
+
/**
|
|
16
|
+
* Merge duplicates without moving their first position; selection policy remains host-owned.
|
|
17
|
+
*
|
|
18
|
+
* The first occurrence of a key fixes the output position; `select` decides which item that
|
|
19
|
+
* position finally holds, so callers can prefer the newest or the most complete duplicate.
|
|
20
|
+
*
|
|
21
|
+
* @param items - Source items in the order the caller wants to display them.
|
|
22
|
+
* @param key - Key selector; items sharing a key collapse into one slot.
|
|
23
|
+
* @param select - Chooses the retained item from the incoming item and the earlier choice
|
|
24
|
+
* (`undefined` on the first occurrence).
|
|
25
|
+
* @returns One item per key, in first-occurrence order.
|
|
26
|
+
*/
|
|
8
27
|
function mergeByKey(items, key, select) {
|
|
9
28
|
const values = new Map();
|
|
10
29
|
for (const item of items) {
|
|
@@ -13,10 +32,30 @@ function mergeByKey(items, key, select) {
|
|
|
13
32
|
}
|
|
14
33
|
return [...values.values()];
|
|
15
34
|
}
|
|
16
|
-
/**
|
|
35
|
+
/**
|
|
36
|
+
* Compile one ordered read plan over a list of inputs.
|
|
37
|
+
*
|
|
38
|
+
* Ordered synchronous queries with optional stable-key merging; each real read stays
|
|
39
|
+
* host-owned. Inputs run sequentially in the given order, so a host can rely on a
|
|
40
|
+
* deterministic visit sequence. Without `key` every item is kept; with `key` the last write
|
|
41
|
+
* wins per key but the position of the first occurrence is retained.
|
|
42
|
+
*
|
|
43
|
+
* @param options - Read handler plus optional key/merge policy; handlers are bound to the
|
|
44
|
+
* options object so method-style implementations keep their `this`.
|
|
45
|
+
* @returns A frozen plan whose `collect` returns `{ total, items }`.
|
|
46
|
+
* @throws TypeError From `collect` when any handler returns a thenable: the whole plan is
|
|
47
|
+
* synchronous by contract, and an async handler cannot be awaited here.
|
|
48
|
+
*/
|
|
17
49
|
function defineQueryAggregation(options) {
|
|
18
50
|
const execute = options.execute.bind(options), keyFor = options.key?.bind(options), merge = options.merge?.bind(options);
|
|
19
51
|
return Object.freeze({
|
|
52
|
+
/**
|
|
53
|
+
* Run every input in order.
|
|
54
|
+
*
|
|
55
|
+
* @param inputs - Query inputs; order determines both read order and result order.
|
|
56
|
+
* @param context - Host context forwarded unchanged to `execute`, `key` and `merge`.
|
|
57
|
+
* @returns The merged items and their count.
|
|
58
|
+
*/
|
|
20
59
|
collect(inputs, context) {
|
|
21
60
|
const rows = [], merged = new Map();
|
|
22
61
|
for (const input of inputs)
|
|
@@ -26,11 +65,14 @@ function defineQueryAggregation(options) {
|
|
|
26
65
|
continue;
|
|
27
66
|
}
|
|
28
67
|
const key = (0, synchronous_js_1.synchronous)(keyFor(item, input, context), 'Aggregation keys must be synchronous');
|
|
29
|
-
merged.set(key, merge
|
|
68
|
+
merged.set(key, merge
|
|
69
|
+
? (0, synchronous_js_1.synchronous)(merge(item, merged.get(key), input, context), 'Aggregation merge must be synchronous')
|
|
70
|
+
: item);
|
|
30
71
|
}
|
|
31
72
|
const items = keyFor ? [...merged.values()] : rows;
|
|
32
73
|
return { total: items.length, items };
|
|
33
74
|
},
|
|
34
75
|
});
|
|
35
76
|
}
|
|
77
|
+
/** Namespace object for callers that prefer one import over named helpers. */
|
|
36
78
|
exports.Aggregation = Object.freeze({ defineQueryAggregation, mergeByKey });
|
|
@@ -1,14 +1,33 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.validateAnswerBatch = validateAnswerBatch;
|
|
4
|
+
/**
|
|
5
|
+
* Validate that one batch is well formed and fully covered.
|
|
6
|
+
*
|
|
7
|
+
* @param inputIds - Every input id the batch must answer; non-empty, unique, non-blank.
|
|
8
|
+
* @param items - Answer items; each must reference known inputs and together cover all of them.
|
|
9
|
+
* @param maxItems - Maximum allowed item count, a positive safe integer.
|
|
10
|
+
* @throws TypeError For an invalid limit or input ids, an empty or oversized item list,
|
|
11
|
+
* duplicate item ids, an unknown source status or input id, or an uncovered input.
|
|
12
|
+
*/
|
|
4
13
|
function validateAnswerBatch(inputIds, items, maxItems) {
|
|
5
|
-
if (!Number.isSafeInteger(maxItems) ||
|
|
14
|
+
if (!Number.isSafeInteger(maxItems) ||
|
|
15
|
+
maxItems < 1 ||
|
|
16
|
+
!inputIds.length ||
|
|
17
|
+
new Set(inputIds).size !== inputIds.length ||
|
|
18
|
+
inputIds.some((id) => typeof id !== 'string' || !id))
|
|
6
19
|
throw new TypeError('Invalid answer input ids or limit');
|
|
7
|
-
if (!items.length ||
|
|
20
|
+
if (!items.length ||
|
|
21
|
+
items.length > maxItems ||
|
|
22
|
+
new Set(items.map((item) => item.id)).size !== items.length)
|
|
8
23
|
throw new TypeError('Invalid answer item count or ids');
|
|
9
24
|
const covered = new Set();
|
|
10
25
|
for (const item of items) {
|
|
11
|
-
if (typeof item.id !== 'string' ||
|
|
26
|
+
if (typeof item.id !== 'string' ||
|
|
27
|
+
!item.id ||
|
|
28
|
+
!['ready', 'unavailable', 'conflict'].includes(item.sourceStatus) ||
|
|
29
|
+
!item.inputIds.length ||
|
|
30
|
+
new Set(item.inputIds).size !== item.inputIds.length)
|
|
12
31
|
throw new TypeError('Invalid answer item');
|
|
13
32
|
for (const id of item.inputIds) {
|
|
14
33
|
if (!inputIds.includes(id))
|
|
@@ -16,6 +35,6 @@ function validateAnswerBatch(inputIds, items, maxItems) {
|
|
|
16
35
|
covered.add(id);
|
|
17
36
|
}
|
|
18
37
|
}
|
|
19
|
-
if (inputIds.some(id => !covered.has(id)))
|
|
38
|
+
if (inputIds.some((id) => !covered.has(id)))
|
|
20
39
|
throw new TypeError('Answer tasks do not cover every input');
|
|
21
40
|
}
|
|
@@ -1,16 +1,39 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.snapshotAnswerCheck = snapshotAnswerCheck;
|
|
4
|
-
/**
|
|
4
|
+
/**
|
|
5
|
+
* Freeze and validate one check result.
|
|
6
|
+
*
|
|
7
|
+
* @param check - Check outcome: status, issues and an optional replacement value.
|
|
8
|
+
* @param checkId - Id stamped onto issues that do not carry their own, so the failing checker
|
|
9
|
+
* stays identifiable after aggregation.
|
|
10
|
+
* @returns A frozen copy with frozen issues and paths.
|
|
11
|
+
* @throws TypeError When the status is unknown, an issue is malformed, a `passed` result still
|
|
12
|
+
* reports issues, or a `failed` result reports none.
|
|
13
|
+
*/
|
|
5
14
|
function snapshotAnswerCheck(check, checkId) {
|
|
6
|
-
if (!check ||
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
15
|
+
if (!check ||
|
|
16
|
+
!['passed', 'failed', 'unavailable', 'not-run'].includes(check.status) ||
|
|
17
|
+
!Array.isArray(check.issues) ||
|
|
18
|
+
check.issues.some((issue) => !issue ||
|
|
19
|
+
typeof issue.code !== 'string' ||
|
|
20
|
+
!issue.code ||
|
|
21
|
+
typeof issue.message !== 'string' ||
|
|
22
|
+
(issue.path !== undefined &&
|
|
23
|
+
(!Array.isArray(issue.path) ||
|
|
24
|
+
issue.path.some((part) => typeof part !== 'string' && typeof part !== 'number')))) ||
|
|
25
|
+
(check.status === 'passed' && check.issues.length) ||
|
|
26
|
+
(check.status === 'failed' && !check.issues.length))
|
|
10
27
|
throw new TypeError('Invalid answer check result');
|
|
11
|
-
return Object.freeze({
|
|
12
|
-
|
|
13
|
-
|
|
28
|
+
return Object.freeze({
|
|
29
|
+
status: check.status,
|
|
30
|
+
...('value' in check ? { value: check.value } : {}),
|
|
31
|
+
issues: Object.freeze(check.issues.map((issue) => Object.freeze({
|
|
32
|
+
code: issue.code,
|
|
33
|
+
message: issue.message,
|
|
34
|
+
...(issue.checkId !== undefined || checkId !== undefined
|
|
35
|
+
? { checkId: issue.checkId ?? checkId }
|
|
36
|
+
: {}),
|
|
14
37
|
...(issue.path !== undefined ? { path: Object.freeze([...issue.path]) } : {}),
|
|
15
38
|
}))),
|
|
16
39
|
});
|
|
@@ -1,16 +1,37 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.defineAnswerCheckCatalog = defineAnswerCheckCatalog;
|
|
4
|
+
/**
|
|
5
|
+
* Answering Kit: a catalog of named value checkers with one aggregated result.
|
|
6
|
+
*
|
|
7
|
+
* Place in the package: part of the `answering` Kit. Checkers are App business rules; this
|
|
8
|
+
* module only registers them, runs a selected ordered subset and folds their statuses.
|
|
9
|
+
*
|
|
10
|
+
* Exports: `defineAnswerCheckCatalog`, and the answer checker types.
|
|
11
|
+
*/
|
|
4
12
|
const check_result_js_1 = require("./check-result.js");
|
|
5
13
|
const catalog_js_1 = require("../../utils/catalog.js");
|
|
6
14
|
const synchronous_js_1 = require("../../utils/synchronous.js");
|
|
15
|
+
/**
|
|
16
|
+
* Compile a checker catalog.
|
|
17
|
+
*
|
|
18
|
+
* A checker may return a replacement value; it is threaded into the next checker, so the
|
|
19
|
+
* selected ids behave like an ordered chain rather than independent assertions.
|
|
20
|
+
*
|
|
21
|
+
* @param definitions - Checkers with unique ids and a synchronous `check` handler.
|
|
22
|
+
* @returns A frozen catalog whose `check({ checkIds, value }, context)` folds the results.
|
|
23
|
+
* @throws TypeError For a missing handler or a duplicate id; from `check` for a repeated
|
|
24
|
+
* selected id, a non-synchronous checker or an invalid check result.
|
|
25
|
+
*/
|
|
7
26
|
function defineAnswerCheckCatalog(definitions) {
|
|
8
|
-
const checks = (0, catalog_js_1.readonlyCatalog)(definitions.map(check => {
|
|
27
|
+
const checks = (0, catalog_js_1.readonlyCatalog)(definitions.map((check) => {
|
|
9
28
|
if (typeof check.check !== 'function')
|
|
10
29
|
throw new TypeError('Invalid answer checker');
|
|
11
30
|
return Object.freeze({ id: check.id, check: check.check.bind(check) });
|
|
12
|
-
}), id => new TypeError(`Unknown answer checker: ${id}`));
|
|
13
|
-
return Object.freeze({
|
|
31
|
+
}), (id) => new TypeError(`Unknown answer checker: ${id}`));
|
|
32
|
+
return Object.freeze({
|
|
33
|
+
...checks,
|
|
34
|
+
// Severity only escalates: `failed` wins over `unavailable`, which wins over `passed`.
|
|
14
35
|
check(request, context) {
|
|
15
36
|
context.signal.throwIfAborted();
|
|
16
37
|
const issues = [];
|