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