@jangts/agent-core 0.1.1 → 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/development/docs/api/reference.md +1907 -1874
- package/development/docs/api/support.md +27 -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 +3 -2
|
@@ -3,52 +3,88 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.VectorSearch = void 0;
|
|
4
4
|
const synchronous_js_1 = require("../utils/synchronous.js");
|
|
5
5
|
const rules_js_1 = require("../utils/rules.js");
|
|
6
|
+
/**
|
|
7
|
+
* Validate a vector and normalize it to unit length.
|
|
8
|
+
*
|
|
9
|
+
* Scaling by the largest component first keeps the squared sum inside the float range for
|
|
10
|
+
* long vectors, so normalization cannot overflow to Infinity.
|
|
11
|
+
*/
|
|
6
12
|
function normalize(vector, dimensions) {
|
|
7
13
|
(0, rules_js_1.breakWhile)(!Array.isArray(vector) ||
|
|
8
14
|
vector.length !== dimensions ||
|
|
9
|
-
Array.from(vector).some((n) => typeof n !==
|
|
15
|
+
Array.from(vector).some((n) => typeof n !== 'number' || !Number.isFinite(n)), 'Invalid vector dimensions or values');
|
|
10
16
|
const scale = Math.max(...vector.map(Math.abs));
|
|
11
|
-
(0, rules_js_1.breakWhile)(scale === 0,
|
|
17
|
+
(0, rules_js_1.breakWhile)(scale === 0, 'Zero vector cannot be searched');
|
|
12
18
|
const norm = Math.sqrt(vector.reduce((sum, n) => sum + (n / scale) ** 2, 0));
|
|
13
19
|
return Float32Array.from(vector, (n) => n / scale / norm);
|
|
14
20
|
}
|
|
15
|
-
/**
|
|
21
|
+
/**
|
|
22
|
+
* Exact cosine search for a bounded embedded corpus. Identity and metadata are App-owned.
|
|
23
|
+
*
|
|
24
|
+
* Vectors arrive as plain arrays and are stored normalized in `Float32Array` form, so query
|
|
25
|
+
* time only needs a dot product per candidate.
|
|
26
|
+
*/
|
|
16
27
|
class VectorSearch {
|
|
17
28
|
entries = new Map();
|
|
29
|
+
/** The declared space; compare it before mixing vectors from another source. */
|
|
18
30
|
space;
|
|
31
|
+
/**
|
|
32
|
+
* @param space - Non-blank identity and dimensions (1..16384) of the corpus.
|
|
33
|
+
* @throws TypeError When the space declaration is invalid.
|
|
34
|
+
*/
|
|
19
35
|
constructor(space) {
|
|
20
36
|
(0, rules_js_1.breakWhile)(!space.identity?.trim() ||
|
|
21
37
|
!Number.isSafeInteger(space.dimensions) ||
|
|
22
38
|
space.dimensions < 1 ||
|
|
23
|
-
space.dimensions > 16384,
|
|
39
|
+
space.dimensions > 16384, 'Invalid vector space');
|
|
24
40
|
this.space = Object.freeze({ identity: space.identity, dimensions: space.dimensions });
|
|
25
41
|
}
|
|
42
|
+
/**
|
|
43
|
+
* Insert or replace one document and its embedding.
|
|
44
|
+
*
|
|
45
|
+
* @param document - Document with a non-blank string `id`; it is cloned before being stored.
|
|
46
|
+
* @param vector - Raw vector for this space.
|
|
47
|
+
* @throws TypeError For a blank/missing id, a vector of the wrong width, a non-finite
|
|
48
|
+
* component, or an all-zero vector (cosine is undefined for it).
|
|
49
|
+
*/
|
|
26
50
|
upsert({ document, vector }) {
|
|
27
|
-
(0, rules_js_1.breakWhile)(!document?.id?.trim(),
|
|
51
|
+
(0, rules_js_1.breakWhile)(!document?.id?.trim(), 'Invalid vector document id');
|
|
28
52
|
this.entries.set(document.id, {
|
|
29
53
|
document: structuredClone(document),
|
|
30
54
|
vector: normalize(vector, this.space.dimensions),
|
|
31
55
|
});
|
|
32
56
|
}
|
|
57
|
+
/** Remove one document; returns whether it was present. */
|
|
33
58
|
remove(id) {
|
|
34
59
|
return this.entries.delete(id);
|
|
35
60
|
}
|
|
61
|
+
/** Drop the whole corpus while keeping the declared space. */
|
|
36
62
|
clear() {
|
|
37
63
|
this.entries.clear();
|
|
38
64
|
}
|
|
65
|
+
/**
|
|
66
|
+
* Score every candidate and return the best hits.
|
|
67
|
+
*
|
|
68
|
+
* @param options - Query vector plus limit, filter, minimum score and optional grouping.
|
|
69
|
+
* @returns At most `limit` hits, best score first, ties broken by id.
|
|
70
|
+
* @throws TypeError For an invalid limit, a missing filter, an out-of-range `minScore`, a
|
|
71
|
+
* vector the space rejects, a non-synchronous filter or grouper, or a non-string group.
|
|
72
|
+
*/
|
|
39
73
|
search(options) {
|
|
40
74
|
const { vector } = options;
|
|
41
75
|
(0, rules_js_1.breakWhile)(!Number.isSafeInteger(options.limit) ||
|
|
42
76
|
options.limit < 1 ||
|
|
43
77
|
options.limit > 1000 ||
|
|
44
|
-
typeof options.filter !==
|
|
78
|
+
typeof options.filter !== 'function' ||
|
|
45
79
|
(options.minScore !== undefined &&
|
|
46
|
-
(!Number.isFinite(options.minScore) ||
|
|
47
|
-
options.minScore < -1 ||
|
|
48
|
-
options.minScore > 1)), "Invalid vector query");
|
|
80
|
+
(!Number.isFinite(options.minScore) || options.minScore < -1 || options.minScore > 1)), 'Invalid vector query');
|
|
49
81
|
const query = normalize(vector, this.space.dimensions), groups = new Map();
|
|
50
82
|
for (const [id, { document, vector: value }] of this.entries) {
|
|
51
|
-
|
|
83
|
+
// One isolated snapshot per candidate serves filter, grouping and the
|
|
84
|
+
// returned hit; filters and groupers are typed readonly, so sharing it
|
|
85
|
+
// removes the redundant clones without exposing the index.
|
|
86
|
+
const candidate = structuredClone(document);
|
|
87
|
+
const allowed = (0, synchronous_js_1.booleanResult)(options.filter(candidate), 'Vector filters must be synchronous', 'Vector filters must return boolean');
|
|
52
88
|
if (!allowed)
|
|
53
89
|
continue;
|
|
54
90
|
let score = 0;
|
|
@@ -57,18 +93,16 @@ class VectorSearch {
|
|
|
57
93
|
score = Math.max(-1, Math.min(1, score));
|
|
58
94
|
if (score < (options.minScore ?? -1))
|
|
59
95
|
continue;
|
|
60
|
-
const group = (0, synchronous_js_1.synchronous)(options.groupBy?.(
|
|
96
|
+
const group = (0, synchronous_js_1.synchronous)(options.groupBy?.(candidate), 'Vector grouping must be synchronous') ?? id;
|
|
61
97
|
if (typeof group !== 'string')
|
|
62
98
|
throw new TypeError('Vector groups must be strings');
|
|
63
99
|
const prior = groups.get(group);
|
|
64
|
-
if (!prior ||
|
|
65
|
-
|
|
66
|
-
(score === prior.score && id < prior.id))
|
|
67
|
-
groups.set(group, { id, score, document });
|
|
100
|
+
if (!prior || score > prior.score || (score === prior.score && id < prior.id))
|
|
101
|
+
groups.set(group, { id, score, document: candidate });
|
|
68
102
|
}
|
|
69
103
|
return [...groups.values()]
|
|
70
104
|
.sort((a, b) => b.score - a.score || a.id.localeCompare(b.id))
|
|
71
|
-
.slice(0, options.limit)
|
|
105
|
+
.slice(0, options.limit);
|
|
72
106
|
}
|
|
73
107
|
}
|
|
74
108
|
exports.VectorSearch = VectorSearch;
|
package/dist/cjs/mock/node.js
CHANGED
|
@@ -14,5 +14,11 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
|
|
17
|
+
/**
|
|
18
|
+
* Node adapter of the optional Mock Kit (`@jangts/agent-core/mock/node`).
|
|
19
|
+
*
|
|
20
|
+
* Re-exports the mock-gpt Node surface only: server and request-handler creators plus their
|
|
21
|
+
* option types. It starts real HTTP servers and therefore requires a Node runtime. Core
|
|
22
|
+
* execution does not import it.
|
|
23
|
+
*/
|
|
18
24
|
__exportStar(require("@jangts/mock-gpt/node"), exports);
|
package/dist/cjs/mock/web.js
CHANGED
|
@@ -14,5 +14,11 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
|
|
17
|
+
/**
|
|
18
|
+
* Web adapter of the optional Mock Kit (`@jangts/agent-core/mock/web`).
|
|
19
|
+
*
|
|
20
|
+
* Re-exports the mock-gpt web-content surface only: page sources, the public-address check and
|
|
21
|
+
* their option types. Fetching external pages needs a Node runtime with network access; Core
|
|
22
|
+
* execution does not import it.
|
|
23
|
+
*/
|
|
18
24
|
__exportStar(require("@jangts/mock-gpt/web"), exports);
|
package/dist/cjs/mock.js
CHANGED
|
@@ -14,5 +14,11 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
|
|
17
|
+
/**
|
|
18
|
+
* Optional Mock Kit entry: a configurable mock response SDK with optional API adapters.
|
|
19
|
+
*
|
|
20
|
+
* This file is a pass-through to `@jangts/mock-gpt`; Core execution never imports it, and it
|
|
21
|
+
* carries no production defaults. Platform-specific adapters live in `./mock/node.js` and
|
|
22
|
+
* `./mock/web.js`, which are separate subpath entries (`/mock/node`, `/mock/web`).
|
|
23
|
+
*/
|
|
18
24
|
__exportStar(require("@jangts/mock-gpt"), exports);
|
|
@@ -2,47 +2,98 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.compiledModelBinding = exports.modelBindingId = void 0;
|
|
4
4
|
exports.snapshotModelBinding = snapshotModelBinding;
|
|
5
|
+
/**
|
|
6
|
+
* Compile validated model settings into an immutable binding.
|
|
7
|
+
*
|
|
8
|
+
* The runner must not observe configuration changes after construction, so every
|
|
9
|
+
* option, callback and transport is snapshotted here — once per engine or runner.
|
|
10
|
+
* Lifecycle state (call counters, journals, budgets) stays outside the binding.
|
|
11
|
+
*
|
|
12
|
+
* Exports: the `ModelBinding` interface, the internal `modelBindingId` and
|
|
13
|
+
* `compiledModelBinding` symbols, and `snapshotModelBinding`.
|
|
14
|
+
*/
|
|
5
15
|
const defaults_js_1 = require("./defaults.js");
|
|
6
16
|
const settings_js_1 = require("./settings.js");
|
|
7
17
|
const transports_js_1 = require("./transports.js");
|
|
8
18
|
const token_budget_js_1 = require("./token-budget.js");
|
|
9
|
-
/**
|
|
19
|
+
/**
|
|
20
|
+
* Brand carrying the configured model id through copy operations.
|
|
21
|
+
*
|
|
22
|
+
* Only Core passes compiled definitions; it is not a public configuration alternative.
|
|
23
|
+
*/
|
|
10
24
|
exports.modelBindingId = Symbol('model-binding-id');
|
|
25
|
+
/** Escape hatch that lets the engine hand an already compiled binding to a runner. */
|
|
11
26
|
exports.compiledModelBinding = Symbol('compiled-model-binding');
|
|
12
|
-
/**
|
|
27
|
+
/**
|
|
28
|
+
* Compile runner options into a frozen binding.
|
|
29
|
+
*
|
|
30
|
+
* Fixed configuration and callbacks are pinned without cloning or freezing App services:
|
|
31
|
+
* providers and sinks stay live objects, only their method receivers are bound. Optional
|
|
32
|
+
* child limits are filled from the defaults before validation, and transports are
|
|
33
|
+
* normalized and checked for duplicate ids, including the built-in text transport.
|
|
34
|
+
*
|
|
35
|
+
* @param options - Runner options as supplied by the App or by the engine.
|
|
36
|
+
* @returns A frozen binding shared by every runner created from these options.
|
|
37
|
+
* @throws TypeError When child limits, the token budget or a transport is invalid.
|
|
38
|
+
* @throws ValidationError When the token budget contract is incomplete.
|
|
39
|
+
*/
|
|
13
40
|
function snapshotModelBinding(options) {
|
|
14
41
|
const resolved = (0, settings_js_1.resolveModelSettings)(options);
|
|
15
|
-
if (options.children !== undefined &&
|
|
42
|
+
if (options.children !== undefined &&
|
|
43
|
+
(!options.children || typeof options.children !== 'object' || Array.isArray(options.children)))
|
|
16
44
|
throw new TypeError('Invalid child execution policy');
|
|
17
45
|
const sourceChildren = options.children;
|
|
18
46
|
const children = Object.freeze({
|
|
19
|
-
maxDepth: sourceChildren?.maxDepth === undefined
|
|
20
|
-
|
|
21
|
-
|
|
47
|
+
maxDepth: sourceChildren?.maxDepth === undefined
|
|
48
|
+
? defaults_js_1.modelRunnerDefaults.children.maxDepth
|
|
49
|
+
: sourceChildren.maxDepth,
|
|
50
|
+
maxConcurrentCalls: sourceChildren?.maxConcurrentCalls === undefined
|
|
51
|
+
? defaults_js_1.modelRunnerDefaults.children.maxConcurrentCalls
|
|
52
|
+
: sourceChildren.maxConcurrentCalls,
|
|
53
|
+
maxChildren: sourceChildren?.maxChildren === undefined
|
|
54
|
+
? defaults_js_1.modelRunnerDefaults.children.maxChildren
|
|
55
|
+
: sourceChildren.maxChildren,
|
|
22
56
|
});
|
|
23
|
-
if (!Number.isSafeInteger(children.maxDepth) ||
|
|
24
|
-
|
|
25
|
-
|
|
57
|
+
if (!Number.isSafeInteger(children.maxDepth) ||
|
|
58
|
+
children.maxDepth < 0 ||
|
|
59
|
+
!Number.isSafeInteger(children.maxConcurrentCalls) ||
|
|
60
|
+
children.maxConcurrentCalls < 1 ||
|
|
61
|
+
!Number.isSafeInteger(children.maxChildren) ||
|
|
62
|
+
children.maxChildren < 1)
|
|
26
63
|
throw new TypeError('Invalid child execution policy');
|
|
27
64
|
const ports = resolved.ports;
|
|
28
65
|
const sourceBudget = ports.tokenBudget;
|
|
29
66
|
const countTokens = sourceBudget?.countTokens;
|
|
30
|
-
const tokenBudget = sourceBudget &&
|
|
31
|
-
|
|
32
|
-
|
|
67
|
+
const tokenBudget = sourceBudget &&
|
|
68
|
+
Object.freeze({
|
|
69
|
+
counterId: sourceBudget.counterId,
|
|
70
|
+
contextWindowTokens: sourceBudget.contextWindowTokens,
|
|
71
|
+
safetyMarginTokens: sourceBudget.safetyMarginTokens,
|
|
72
|
+
countTokens: typeof countTokens === 'function' ? countTokens.bind(sourceBudget) : countTokens,
|
|
73
|
+
});
|
|
33
74
|
if (tokenBudget)
|
|
34
75
|
(0, token_budget_js_1.validateModelTokenBudget)(tokenBudget);
|
|
35
76
|
const ids = new Set([defaults_js_1.defaultTextTransport.id]);
|
|
36
|
-
const transports = Object.freeze((ports.transports ?? []).map(source => {
|
|
77
|
+
const transports = Object.freeze((ports.transports ?? []).map((source) => {
|
|
37
78
|
const definition = (0, transports_js_1.normalizeModelTransport)(source);
|
|
38
79
|
if (ids.has(definition.id))
|
|
39
80
|
throw new TypeError('Invalid or duplicate model transport');
|
|
40
81
|
ids.add(definition.id);
|
|
41
82
|
return Object.freeze({ source, definition });
|
|
42
83
|
}));
|
|
43
|
-
return Object.freeze({
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
84
|
+
return Object.freeze({
|
|
85
|
+
provider: resolved.provider,
|
|
86
|
+
config: resolved.config,
|
|
87
|
+
children,
|
|
88
|
+
maxInputChars: resolved.maxInputChars,
|
|
89
|
+
maxOutputTokens: resolved.maxOutputTokens,
|
|
90
|
+
tokenBudget,
|
|
91
|
+
transports,
|
|
92
|
+
ports: Object.freeze({
|
|
93
|
+
maxSchemaChars: ports.maxSchemaChars,
|
|
94
|
+
onOutput: ports.onOutput,
|
|
95
|
+
inputBudgetError: ports.inputBudgetError,
|
|
96
|
+
outputBudgetError: ports.outputBudgetError,
|
|
97
|
+
}),
|
|
47
98
|
});
|
|
48
99
|
}
|
|
@@ -1,26 +1,66 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.parentModelBudget = exports.ModelCallBudget = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Request-local model call accounting.
|
|
6
|
+
*
|
|
7
|
+
* A budget can have a parent, which makes sibling children compete for the same
|
|
8
|
+
* ancestor allowance. Charging is synchronous: there is no await between the check and
|
|
9
|
+
* the counter update, so two concurrent consumers cannot both spend the last call.
|
|
10
|
+
*
|
|
11
|
+
* Exports: `ModelCallBudget` and the `parentModelBudget` hand-off symbol.
|
|
12
|
+
*/
|
|
4
13
|
const errors_js_1 = require("../structs/errors.js");
|
|
5
14
|
const rules_js_1 = require("../utils/rules.js");
|
|
6
|
-
/**
|
|
7
|
-
*
|
|
15
|
+
/**
|
|
16
|
+
* Request-local attempt ledger.
|
|
17
|
+
*
|
|
18
|
+
* `reserve` is capacity kept available to the parent: a child with a reserve cannot
|
|
19
|
+
* consume the calls its ancestor still needs for its own turn.
|
|
20
|
+
*/
|
|
8
21
|
class ModelCallBudget {
|
|
9
22
|
limit;
|
|
10
23
|
parent;
|
|
11
24
|
reserve;
|
|
12
25
|
consumed = 0;
|
|
26
|
+
/**
|
|
27
|
+
* @param limit - Calls this ledger may consume; nonnegative safe integer.
|
|
28
|
+
* @param parent - Ancestor ledger charged alongside every local take.
|
|
29
|
+
* @param reserve - Calls of the parent's remaining capacity this ledger must leave untouched.
|
|
30
|
+
* @throws Error When `limit` or `reserve` is not a nonnegative safe integer.
|
|
31
|
+
*/
|
|
13
32
|
constructor(limit, parent, reserve = 0) {
|
|
14
33
|
this.limit = limit;
|
|
15
34
|
this.parent = parent;
|
|
16
35
|
this.reserve = reserve;
|
|
17
36
|
(0, rules_js_1.breakWhile)(!Number.isSafeInteger(limit) || limit < 0 || !Number.isSafeInteger(reserve) || reserve < 0, 'Invalid model call budget');
|
|
18
37
|
}
|
|
19
|
-
|
|
38
|
+
/** Calls already charged to this ledger only. */
|
|
39
|
+
get used() {
|
|
40
|
+
return this.consumed;
|
|
41
|
+
}
|
|
42
|
+
/** Calls still available after the local limit and the parent's reserve are applied. */
|
|
20
43
|
get remaining() {
|
|
21
44
|
return Math.max(0, Math.min(this.limit - this.consumed, this.parent ? this.parent.remaining - this.reserve : Infinity));
|
|
22
45
|
}
|
|
23
|
-
|
|
46
|
+
/**
|
|
47
|
+
* Derive a child ledger that also charges this one.
|
|
48
|
+
*
|
|
49
|
+
* @param limit - Calls the child may consume.
|
|
50
|
+
* @param reserve - Calls of this ledger's remaining capacity the child must leave free.
|
|
51
|
+
* @returns A new ledger linked to this instance.
|
|
52
|
+
*/
|
|
53
|
+
child(limit, reserve) {
|
|
54
|
+
return new ModelCallBudget(limit, this, reserve);
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Charge one call to this ledger and every ancestor.
|
|
58
|
+
*
|
|
59
|
+
* The parent is charged first so a failure cannot leave the child counter advanced
|
|
60
|
+
* while the ancestor rejected the charge.
|
|
61
|
+
*
|
|
62
|
+
* @throws BudgetError When no call is available on this ledger or an ancestor.
|
|
63
|
+
*/
|
|
24
64
|
take() {
|
|
25
65
|
(0, rules_js_1.breakWhile)(this.remaining < 1, () => new errors_js_1.BudgetError());
|
|
26
66
|
this.parent?.take();
|
|
@@ -28,4 +68,5 @@ class ModelCallBudget {
|
|
|
28
68
|
}
|
|
29
69
|
}
|
|
30
70
|
exports.ModelCallBudget = ModelCallBudget;
|
|
71
|
+
/** Carries an inherited budget into a child runner that was not created by `child`. */
|
|
31
72
|
exports.parentModelBudget = Symbol('parentModelBudget');
|
|
@@ -1,8 +1,26 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.retryMultipleModelCalls = retryMultipleModelCalls;
|
|
4
|
+
/**
|
|
5
|
+
* Single retry point for rejected parallel model proposals.
|
|
6
|
+
*
|
|
7
|
+
* A provider may answer with more than one tool call. The protocol rejects that answer
|
|
8
|
+
* before any tool runs, so retrying is safe and must happen here — after a tool had
|
|
9
|
+
* executed, a retry could duplicate side effects.
|
|
10
|
+
*
|
|
11
|
+
* Exports: `retryMultipleModelCalls`.
|
|
12
|
+
*/
|
|
4
13
|
const errors_js_1 = require("../errors.js");
|
|
5
|
-
/**
|
|
14
|
+
/**
|
|
15
|
+
* Retry once when the failure is a rejected multi-call proposal.
|
|
16
|
+
*
|
|
17
|
+
* Only the `MODEL_MULTIPLE_CALLS` code is retried; every other failure is rethrown
|
|
18
|
+
* unchanged. The caller owns the fallback prompt and the budget it consumes.
|
|
19
|
+
*
|
|
20
|
+
* @param request - `invoke` performs the first attempt; `retry` performs the fallback.
|
|
21
|
+
* @returns The first successful value.
|
|
22
|
+
* @throws The original error when it is not a multi-call rejection, or the fallback error.
|
|
23
|
+
*/
|
|
6
24
|
async function retryMultipleModelCalls(request) {
|
|
7
25
|
try {
|
|
8
26
|
return await request.invoke();
|
|
@@ -1,13 +1,36 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.defaultTextTransport = exports.modelRunnerDefaults = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Baseline model runtime limits.
|
|
6
|
+
*
|
|
7
|
+
* These are conservative runtime defaults, not a claim about any provider's context
|
|
8
|
+
* window; a host that knows its model must override them explicitly.
|
|
9
|
+
*
|
|
10
|
+
* Exports: `modelRunnerDefaults` and `defaultTextTransport`.
|
|
11
|
+
*/
|
|
4
12
|
const transports_js_1 = require("./transports.js");
|
|
5
|
-
/**
|
|
13
|
+
/**
|
|
14
|
+
* Frozen default limits.
|
|
15
|
+
*
|
|
16
|
+
* `maxCalls` bounds one request's model calls, `callTimeoutMs` stays below the
|
|
17
|
+
* 32-bit timer limit, and the child limits cap fan-out per request. `stage` is the
|
|
18
|
+
* fallback stage id used when a call does not name one.
|
|
19
|
+
*/
|
|
6
20
|
exports.modelRunnerDefaults = Object.freeze({
|
|
7
|
-
maxCalls: 8,
|
|
8
|
-
|
|
21
|
+
maxCalls: 8,
|
|
22
|
+
callTimeoutMs: 30000,
|
|
23
|
+
maxInputChars: 32000,
|
|
24
|
+
maxOutputChars: 16000,
|
|
25
|
+
maxSchemaChars: 16000,
|
|
26
|
+
maxOutputTokens: 1024,
|
|
9
27
|
stage: 'model',
|
|
10
28
|
children: Object.freeze({ maxDepth: 1, maxConcurrentCalls: 1, maxChildren: 32 }),
|
|
11
29
|
});
|
|
12
|
-
/**
|
|
30
|
+
/**
|
|
31
|
+
* Built-in plain-text transport.
|
|
32
|
+
*
|
|
33
|
+
* Core owns ordinary text execution, so no App-side adapter is required for the
|
|
34
|
+
* default single-prompt call shape.
|
|
35
|
+
*/
|
|
13
36
|
exports.defaultTextTransport = (0, transports_js_1.createPlainTextTransport)('core:plain-text');
|
package/dist/cjs/model/index.js
CHANGED
|
@@ -15,6 +15,13 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
exports.modelRunnerDefaults = void 0;
|
|
18
|
+
/**
|
|
19
|
+
* Public surface of the model protocol layer.
|
|
20
|
+
*
|
|
21
|
+
* Re-exports the runner, the provider and transport contracts, the interaction
|
|
22
|
+
* adapters and the defaults. Everything that interprets model output passes through
|
|
23
|
+
* this module, so consumers should not import the individual files.
|
|
24
|
+
*/
|
|
18
25
|
__exportStar(require("./runner.js"), exports);
|
|
19
26
|
__exportStar(require("../structs/model/chat-provider.js"), exports);
|
|
20
27
|
__exportStar(require("../support/model/compatible-provider.js"), exports);
|
|
@@ -3,12 +3,38 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.object = object;
|
|
4
4
|
exports.parse = parse;
|
|
5
5
|
exports.wireName = wireName;
|
|
6
|
+
/**
|
|
7
|
+
* Shared argument decoding for interaction adapters.
|
|
8
|
+
*
|
|
9
|
+
* Every adapter ultimately produces the same pair — capability id and argument
|
|
10
|
+
* object — so parsing, validation and wire naming live here instead of being repeated
|
|
11
|
+
* per wire format.
|
|
12
|
+
*
|
|
13
|
+
* Exports: `object`, `parse` and `wireName`.
|
|
14
|
+
*/
|
|
6
15
|
const model_protocol_js_1 = require("../../utils/model-protocol.js");
|
|
16
|
+
/**
|
|
17
|
+
* Require a plain argument object.
|
|
18
|
+
*
|
|
19
|
+
* @param value - Candidate value.
|
|
20
|
+
* @returns The value typed as a string-keyed record.
|
|
21
|
+
* @throws ValidationError When the value is not a non-array object.
|
|
22
|
+
*/
|
|
7
23
|
function object(value) {
|
|
8
24
|
if (!value || typeof value !== 'object' || Array.isArray(value))
|
|
9
25
|
(0, model_protocol_js_1.modelProtocolError)('Model arguments must be an object');
|
|
10
26
|
return value;
|
|
11
27
|
}
|
|
28
|
+
/**
|
|
29
|
+
* Parse a complete JSON argument payload.
|
|
30
|
+
*
|
|
31
|
+
* Incomplete JSON is rejected rather than repaired, because a truncated stream must not
|
|
32
|
+
* be executed as a plausible partial call.
|
|
33
|
+
*
|
|
34
|
+
* @param raw - Complete JSON text.
|
|
35
|
+
* @returns The parsed argument object.
|
|
36
|
+
* @throws ValidationError When the text is not complete JSON or not an object.
|
|
37
|
+
*/
|
|
12
38
|
function parse(raw) {
|
|
13
39
|
let value;
|
|
14
40
|
try {
|
|
@@ -19,7 +45,16 @@ function parse(raw) {
|
|
|
19
45
|
}
|
|
20
46
|
return object(value);
|
|
21
47
|
}
|
|
22
|
-
|
|
48
|
+
/**
|
|
49
|
+
* Map a business capability id onto a wire-safe function name.
|
|
50
|
+
*
|
|
51
|
+
* Business ids are not constrained by the wire protocol's naming alphabet or length, so
|
|
52
|
+
* an already valid id is returned unchanged and any other id is sanitized and suffixed
|
|
53
|
+
* with an FNV-1a hash. The hash keeps distinct ids distinct after sanitizing.
|
|
54
|
+
*
|
|
55
|
+
* @param id - Registered capability id.
|
|
56
|
+
* @returns A name matching the protocol's expected pattern.
|
|
57
|
+
*/
|
|
23
58
|
function wireName(id) {
|
|
24
59
|
if (/^[a-zA-Z0-9_-]{1,64}$/.test(id))
|
|
25
60
|
return id;
|
|
@@ -1,32 +1,68 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.jsonObjectInteraction = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Interaction adapter for providers without native tool calling.
|
|
6
|
+
*
|
|
7
|
+
* Instead of function declarations, the capability list is embedded in the instruction
|
|
8
|
+
* and the model must answer with one JSON envelope. The envelope belongs to this
|
|
9
|
+
* adapter, not to application messages, so switching adapters never changes App code.
|
|
10
|
+
*
|
|
11
|
+
* Exports: `jsonObjectInteraction`.
|
|
12
|
+
*/
|
|
4
13
|
const model_protocol_js_1 = require("../../utils/model-protocol.js");
|
|
5
14
|
const arguments_js_1 = require("./arguments.js");
|
|
6
|
-
/**
|
|
15
|
+
/**
|
|
16
|
+
* Adapter that reads a single capability call out of a JSON object response.
|
|
17
|
+
*
|
|
18
|
+
* `strictArguments` is false because the wire format carries no schema enforcement; the
|
|
19
|
+
* adapter validates the envelope shape itself and leaves argument validation to the
|
|
20
|
+
* capability's own schema.
|
|
21
|
+
*/
|
|
7
22
|
exports.jsonObjectInteraction = Object.freeze({
|
|
8
23
|
id: 'json-object',
|
|
9
24
|
features: Object.freeze({ strictArguments: false }),
|
|
25
|
+
/**
|
|
26
|
+
* Build the instruction and response collector for one stage.
|
|
27
|
+
*
|
|
28
|
+
* @param capabilities - Capabilities registered for this stage; must be non-empty.
|
|
29
|
+
* @returns JSON mode options, the measured instruction and the collector factory.
|
|
30
|
+
*/
|
|
10
31
|
prepare(capabilities) {
|
|
11
|
-
const declarations = capabilities.map(({ id, description, inputSchema }) => ({
|
|
32
|
+
const declarations = capabilities.map(({ id, description, inputSchema }) => ({
|
|
33
|
+
id,
|
|
34
|
+
description,
|
|
35
|
+
input: inputSchema.jsonSchema,
|
|
36
|
+
}));
|
|
12
37
|
// Keep the wire shape after potentially long schemas so it cannot be mistaken
|
|
13
38
|
// for a schema definition or a bare capability argument object.
|
|
14
|
-
const instruction = 'Registered capabilities: ' +
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
39
|
+
const instruction = 'Registered capabilities: ' +
|
|
40
|
+
JSON.stringify(declarations) +
|
|
41
|
+
'\nReturn exactly one JSON object with exactly these two fields: {"capability":"registered id","input":{...}}. ' +
|
|
42
|
+
'Choose capability from ' +
|
|
43
|
+
JSON.stringify(capabilities.map((capability) => capability.id)) +
|
|
44
|
+
"; input is the chosen capability's actual argument object matching its input schema. " +
|
|
45
|
+
'Do not return the schema, response_format, an array, multiple calls, prose or fences. The outer object must contain capability and input.';
|
|
19
46
|
return {
|
|
20
|
-
options: { json: true },
|
|
47
|
+
options: { json: true },
|
|
48
|
+
schemaChars: instruction.length,
|
|
49
|
+
instruction,
|
|
21
50
|
createResponse() {
|
|
22
51
|
let raw = '';
|
|
23
52
|
return {
|
|
24
|
-
get outputChars() {
|
|
25
|
-
|
|
26
|
-
|
|
53
|
+
get outputChars() {
|
|
54
|
+
return raw.length;
|
|
55
|
+
},
|
|
56
|
+
push(part) {
|
|
57
|
+
if (typeof part !== 'string')
|
|
58
|
+
(0, model_protocol_js_1.modelProtocolError)('JSON interaction does not accept native call events');
|
|
59
|
+
raw += part;
|
|
60
|
+
},
|
|
27
61
|
finish() {
|
|
28
62
|
const value = (0, arguments_js_1.parse)(raw);
|
|
29
|
-
if (Object.keys(value).length !== 2 ||
|
|
63
|
+
if (Object.keys(value).length !== 2 ||
|
|
64
|
+
typeof value.capability !== 'string' ||
|
|
65
|
+
!Object.hasOwn(value, 'input'))
|
|
30
66
|
(0, model_protocol_js_1.modelProtocolError)('Invalid model selection envelope');
|
|
31
67
|
return { capabilityId: value.capability, input: (0, arguments_js_1.object)(value.input) };
|
|
32
68
|
},
|