@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
|
@@ -1,67 +1,159 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Context strategy presets: derive a validated reduction policy from history declarations.
|
|
3
|
+
*
|
|
4
|
+
* A strategy describes one historical fragment (its ID, JSON field and how much to keep) and
|
|
5
|
+
* generates either a trim step (`recent`) or a compression step (`continuity`). Generated steps and
|
|
6
|
+
* any explicit overrides are validated together, so the result can be passed straight to the
|
|
7
|
+
* context processing nodes.
|
|
8
|
+
*
|
|
9
|
+
* Main exports: `contextHistoryStrategies`, `createContextStrategy` and the strategy types.
|
|
10
|
+
*/
|
|
1
11
|
import { validateContextPolicy } from './processing.js';
|
|
2
12
|
import { breakWhile } from '../../utils/rules.js';
|
|
3
|
-
/**
|
|
13
|
+
/**
|
|
14
|
+
* Named history presets.
|
|
15
|
+
*
|
|
16
|
+
* `targetRatio` is the fraction of the fragment's own `maxChars` used as the reduction target;
|
|
17
|
+
* `keepGroups` is how many most-recent groups always stay verbatim. Both are local admission
|
|
18
|
+
* heuristics, not claims about semantic retention.
|
|
19
|
+
*/
|
|
4
20
|
export const contextHistoryStrategies = Object.freeze({
|
|
5
21
|
compact: Object.freeze({ targetRatio: 0.25, keepGroups: 1 }),
|
|
6
22
|
balanced: Object.freeze({ targetRatio: 0.5, keepGroups: 3 }),
|
|
7
23
|
extended: Object.freeze({ targetRatio: 0.75, keepGroups: 6 }),
|
|
8
24
|
});
|
|
9
25
|
function recent({ id, targetChars, preserve }) {
|
|
10
|
-
return {
|
|
26
|
+
return {
|
|
27
|
+
step: { id: `${id}.window`, kind: 'trim', fragmentId: id, targetChars, ...preserve },
|
|
28
|
+
compressors: [],
|
|
29
|
+
};
|
|
11
30
|
}
|
|
12
31
|
function continuity({ options, id, targetChars, preserve }) {
|
|
13
32
|
const compressor = options.compressor;
|
|
14
33
|
breakWhile(!compressor, 'Continuity strategy requires a compressor');
|
|
15
|
-
return {
|
|
34
|
+
return {
|
|
35
|
+
step: {
|
|
36
|
+
id: `${id}.summary`,
|
|
37
|
+
kind: 'compress',
|
|
38
|
+
fragmentId: id,
|
|
39
|
+
targetChars,
|
|
40
|
+
handlerId: compressor.id,
|
|
41
|
+
preserve,
|
|
42
|
+
},
|
|
43
|
+
compressors: [compressor],
|
|
44
|
+
};
|
|
16
45
|
}
|
|
17
46
|
/** The declared alternatives drive default selection and the generated operations together. */
|
|
18
47
|
const contextStrategyCatalog = {
|
|
19
48
|
recent: { operation: 'trim', build: recent },
|
|
20
49
|
continuity: { operation: 'compress', build: continuity },
|
|
21
50
|
};
|
|
22
|
-
/**
|
|
51
|
+
/**
|
|
52
|
+
* Build a reduction policy from one or more history declarations.
|
|
53
|
+
*
|
|
54
|
+
* `recent` keeps a window of recent groups; `continuity` summarizes older groups while preserving
|
|
55
|
+
* the most recent originals. Neither preset claims semantic quality, only bounded input size.
|
|
56
|
+
*
|
|
57
|
+
* @param options One history declaration or an array of them. With an array, shared processing
|
|
58
|
+
* settings must be passed in `settings`, not on individual items.
|
|
59
|
+
* @param settings Shared policy settings, overridden by single-item fields when one item is given.
|
|
60
|
+
* @returns A frozen strategy with the policy, its compressors and selectors.
|
|
61
|
+
* @throws {Error} When no history is declared, shared settings appear on array items, a preset or
|
|
62
|
+
* allowance is invalid, or the generated selection has no matching step.
|
|
63
|
+
* @throws {ValidationError} When the resulting policy fails Core validation.
|
|
64
|
+
*/
|
|
23
65
|
export function createContextStrategy(options, settings = {}) {
|
|
24
|
-
const definitions = Array.isArray(options)
|
|
66
|
+
const definitions = Array.isArray(options)
|
|
67
|
+
? options
|
|
68
|
+
: [options];
|
|
25
69
|
breakWhile(!definitions.length, 'Context strategy requires at least one history');
|
|
26
70
|
const single = definitions.length === 1 ? definitions[0] : undefined;
|
|
27
71
|
// Array items generate operations; global processing settings belong to the second argument.
|
|
28
|
-
if (!single &&
|
|
72
|
+
if (!single &&
|
|
73
|
+
definitions.some((item) => [
|
|
74
|
+
'selection',
|
|
75
|
+
'steps',
|
|
76
|
+
'selectors',
|
|
77
|
+
'compressors',
|
|
78
|
+
'triggerChars',
|
|
79
|
+
'targetInputChars',
|
|
80
|
+
'triggerTokens',
|
|
81
|
+
'targetInputTokens',
|
|
82
|
+
].some((key) => key in item))) {
|
|
29
83
|
throw new TypeError('Configure shared context strategy settings in the second argument');
|
|
30
84
|
}
|
|
31
85
|
const config = {};
|
|
32
|
-
const keys = [
|
|
86
|
+
const keys = [
|
|
87
|
+
'selection',
|
|
88
|
+
'steps',
|
|
89
|
+
'selectors',
|
|
90
|
+
'compressors',
|
|
91
|
+
'triggerChars',
|
|
92
|
+
'targetInputChars',
|
|
93
|
+
'triggerTokens',
|
|
94
|
+
'targetInputTokens',
|
|
95
|
+
];
|
|
33
96
|
for (const source of [single, settings])
|
|
34
97
|
if (source)
|
|
35
98
|
for (const key of keys)
|
|
36
99
|
if (key in source)
|
|
37
100
|
config[key] = source[key];
|
|
38
101
|
const configured = config;
|
|
39
|
-
const generated = configured.steps !== undefined
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
102
|
+
const generated = configured.steps !== undefined
|
|
103
|
+
? []
|
|
104
|
+
: definitions.map((options) => {
|
|
105
|
+
const { kind, fragment, field } = options;
|
|
106
|
+
const preset = options.preset;
|
|
107
|
+
breakWhile(preset !== undefined && !Object.hasOwn(contextHistoryStrategies, preset), 'Unknown history strategy preset');
|
|
108
|
+
breakWhile(!Number.isSafeInteger(fragment.maxChars) || fragment.maxChars < 1, 'History strategy requires a positive fragment allowance');
|
|
109
|
+
const defaults = preset === undefined ? undefined : contextHistoryStrategies[preset];
|
|
110
|
+
const id = fragment.id, targetChars = options.targetChars ??
|
|
111
|
+
(defaults
|
|
112
|
+
? Math.max(1, Math.floor(fragment.maxChars * defaults.targetRatio))
|
|
113
|
+
: fragment.maxChars);
|
|
114
|
+
const grouping = options.grouping ?? { kind: 'user-turn' };
|
|
115
|
+
const preserve = {
|
|
116
|
+
field,
|
|
117
|
+
keepGroups: options.keepGroups ?? defaults?.keepGroups ?? 1,
|
|
118
|
+
grouping: grouping.kind === 'fixed'
|
|
119
|
+
? { kind: grouping.kind, size: grouping.size }
|
|
120
|
+
: { kind: grouping.kind },
|
|
121
|
+
};
|
|
122
|
+
breakWhile(!Object.hasOwn(contextStrategyCatalog, kind), 'Unknown context strategy');
|
|
123
|
+
return contextStrategyCatalog[kind].build({ options, id, targetChars, preserve });
|
|
124
|
+
});
|
|
125
|
+
const steps = configured.steps ?? generated.map((item) => item.step);
|
|
126
|
+
// A single step needs no selection decision; several steps keep declared order.
|
|
127
|
+
const selection = configured.selection ??
|
|
128
|
+
(steps.length === 1
|
|
129
|
+
? { mode: 'fixed', kind: steps[0].kind }
|
|
130
|
+
: { mode: 'sequence' });
|
|
131
|
+
const compressors = [
|
|
132
|
+
...generated.flatMap((item) => item.compressors),
|
|
133
|
+
...(configured.compressors ?? []),
|
|
134
|
+
];
|
|
55
135
|
const unique = new Map();
|
|
56
136
|
for (const compressor of compressors) {
|
|
137
|
+
// The same handler may be referenced by several steps; a different object under one ID is
|
|
138
|
+
// ambiguous for the policy, so it is rejected instead of silently replaced.
|
|
57
139
|
breakWhile(unique.has(compressor.id) && unique.get(compressor.id) !== compressor, `Conflicting context compressor: ${compressor.id}`);
|
|
58
140
|
unique.set(compressor.id, compressor);
|
|
59
141
|
}
|
|
60
142
|
const selectors = [...(configured.selectors ?? [])];
|
|
61
|
-
const policy = {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
143
|
+
const policy = {
|
|
144
|
+
mode: 'reduce',
|
|
145
|
+
steps: [...steps],
|
|
146
|
+
selection,
|
|
147
|
+
triggerChars: configured.triggerChars,
|
|
148
|
+
targetInputChars: configured.targetInputChars,
|
|
149
|
+
triggerTokens: configured.triggerTokens,
|
|
150
|
+
targetInputTokens: configured.targetInputTokens,
|
|
151
|
+
};
|
|
152
|
+
breakWhile(selection.mode === 'fixed' && !steps.some((step) => step.kind === selection.kind), 'Context strategy selection has no matching operation');
|
|
65
153
|
validateContextPolicy(policy, [...unique.values()], selectors);
|
|
66
|
-
return Object.freeze({
|
|
154
|
+
return Object.freeze({
|
|
155
|
+
policy,
|
|
156
|
+
compressors: Object.freeze([...unique.values()]),
|
|
157
|
+
selectors: Object.freeze(selectors),
|
|
158
|
+
});
|
|
67
159
|
}
|
|
@@ -1,4 +1,12 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/**
|
|
2
|
+
* Support entry point: app-side helpers that build Core-compatible configuration and handlers.
|
|
3
|
+
*
|
|
4
|
+
* Applications import from here and pass the results to Core. Core never imports this module;
|
|
5
|
+
* the helpers follow Core contracts and do not introduce a second scheduling protocol.
|
|
6
|
+
*
|
|
7
|
+
* Main exports: model transports and providers, context assembly and processing policies,
|
|
8
|
+
* registration and capability catalogs, tool definition helpers, schema adapters and transports.
|
|
9
|
+
*/
|
|
2
10
|
export * from './model/index.js';
|
|
3
11
|
export * from './context/index.js';
|
|
4
12
|
export * from './registration.js';
|
|
@@ -1,4 +1,12 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/**
|
|
2
|
+
* Support entry point: app-side helpers that build Core-compatible configuration and handlers.
|
|
3
|
+
*
|
|
4
|
+
* Applications import from here and pass the results to Core. Core never imports this module;
|
|
5
|
+
* the helpers follow Core contracts and do not introduce a second scheduling protocol.
|
|
6
|
+
*
|
|
7
|
+
* Main exports: model transports and providers, context assembly and processing policies,
|
|
8
|
+
* registration and capability catalogs, tool definition helpers, schema adapters and transports.
|
|
9
|
+
*/
|
|
2
10
|
export * from './model/index.js';
|
|
3
11
|
export * from './context/index.js';
|
|
4
12
|
export * from './registration.js';
|
|
@@ -3,5 +3,15 @@ import type { ModelCapabilityRegistration, ModelCapabilityCatalog } from '../../
|
|
|
3
3
|
type CapabilityOutput<Definition> = Definition extends {
|
|
4
4
|
resolve(...args: any[]): infer Output;
|
|
5
5
|
} ? Output : never;
|
|
6
|
+
/**
|
|
7
|
+
* Build a sealed capability catalog from typed declarations.
|
|
8
|
+
*
|
|
9
|
+
* @param definitions Capabilities in declaration order; each needs a unique ID, a description and
|
|
10
|
+
* an object-rooted input schema.
|
|
11
|
+
* @returns A frozen catalog exposing the registered definitions, lookup by ID and `resolve`.
|
|
12
|
+
* @throws {TypeError} When a declaration is invalid or duplicated, or when `require` receives an
|
|
13
|
+
* unknown ID.
|
|
14
|
+
* @throws {Error} When a resolver is asynchronous.
|
|
15
|
+
*/
|
|
6
16
|
export declare function defineModelCapabilities<const Definitions extends readonly ModelCapabilityRegistration[]>(definitions: Definitions): ModelCapabilityCatalog<CapabilityOutput<Definitions[number]>>;
|
|
7
17
|
export {};
|
|
@@ -1,9 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Model capability catalog: seal a typed declaration list into a reusable catalog.
|
|
3
|
+
*
|
|
4
|
+
* The catalog is a frozen snapshot, so mutating the original declaration list cannot widen the
|
|
5
|
+
* result type or add capabilities at runtime. Resolution stays inside Core's registry; Support only
|
|
6
|
+
* projects the declarations and their output type.
|
|
7
|
+
*
|
|
8
|
+
* Main export: `defineModelCapabilities`.
|
|
9
|
+
*/
|
|
1
10
|
import { readonlyCatalog } from '../../utils/catalog.js';
|
|
2
11
|
import { ModelCapabilityRegistry } from '../../capabilities/model.js';
|
|
12
|
+
/**
|
|
13
|
+
* Build a sealed capability catalog from typed declarations.
|
|
14
|
+
*
|
|
15
|
+
* @param definitions Capabilities in declaration order; each needs a unique ID, a description and
|
|
16
|
+
* an object-rooted input schema.
|
|
17
|
+
* @returns A frozen catalog exposing the registered definitions, lookup by ID and `resolve`.
|
|
18
|
+
* @throws {TypeError} When a declaration is invalid or duplicated, or when `require` receives an
|
|
19
|
+
* unknown ID.
|
|
20
|
+
* @throws {Error} When a resolver is asynchronous.
|
|
21
|
+
*/
|
|
3
22
|
export function defineModelCapabilities(definitions) {
|
|
4
23
|
const registry = new ModelCapabilityRegistry(definitions).seal();
|
|
5
24
|
return Object.freeze({
|
|
6
|
-
...readonlyCatalog(registry.definitions, id => new TypeError(`Unknown model capability: ${id}`)),
|
|
25
|
+
...readonlyCatalog(registry.definitions, (id) => new TypeError(`Unknown model capability: ${id}`)),
|
|
7
26
|
resolve: (selection, stage) => registry.resolve(selection, stage),
|
|
8
27
|
});
|
|
9
28
|
}
|
|
@@ -1,18 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OpenAI-compatible chat-completions wire mapping.
|
|
3
|
+
*
|
|
4
|
+
* Pure format conversion: request fields, streamed deltas and message payloads. Credentials, HTTP,
|
|
5
|
+
* retries and business policy stay with the host; nothing here reads configuration or performs I/O.
|
|
6
|
+
*
|
|
7
|
+
* Main exports: `chatCompletionFunctionOptions`, `chatCompletionParts` and
|
|
8
|
+
* `chatCompletionMessages`.
|
|
9
|
+
*/
|
|
1
10
|
import type { ModelMessage, ModelOptions, ModelPart } from '../../structs/model/messages.js';
|
|
2
|
-
|
|
11
|
+
import type { ProviderMessage } from '../../structs/support/model/messages.js';
|
|
12
|
+
/**
|
|
13
|
+
* Build the tool-selection request fields for a function-calling stage.
|
|
14
|
+
*
|
|
15
|
+
* The adapter expects exactly one function call per response, so tool use is required and parallel
|
|
16
|
+
* calls are disabled.
|
|
17
|
+
*
|
|
18
|
+
* @param options Model options; absent `functions` means the stage has no tools.
|
|
19
|
+
* @returns Tool fields to merge into the request body, or an empty object.
|
|
20
|
+
* @throws {TypeError} When `functions` is present but empty.
|
|
21
|
+
*/
|
|
3
22
|
export declare function chatCompletionFunctionOptions(options: ModelOptions): Record<string, unknown>;
|
|
23
|
+
/**
|
|
24
|
+
* Convert one streamed `choice.delta` into Core model parts.
|
|
25
|
+
*
|
|
26
|
+
* Text is emitted only when non-empty; each tool-call fragment carries its index so Core can
|
|
27
|
+
* reassemble arguments that arrive across chunks.
|
|
28
|
+
*
|
|
29
|
+
* @param delta Raw `delta` value from a chat-completions chunk.
|
|
30
|
+
* @returns Text and function-call-delta parts; an unrelated shape yields an empty array.
|
|
31
|
+
* @throws {ValidationError} When `tool_calls` or one of its entries has an invalid shape.
|
|
32
|
+
*/
|
|
4
33
|
export declare function chatCompletionParts(delta: unknown): ModelPart[];
|
|
5
|
-
/**
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
34
|
+
/**
|
|
35
|
+
* Map Core and provider messages to chat-completions message payloads.
|
|
36
|
+
*
|
|
37
|
+
* Only declared message fields are sent. Assistant tool declarations become nested
|
|
38
|
+
* `tool_calls`, and tool results become `tool_call_id`; both are rewritten explicitly rather than
|
|
39
|
+
* forwarded as-is. Messages with images become a content-block array; images are accepted only on
|
|
40
|
+
* user messages and only as `http(s)` or `data:image` URLs.
|
|
41
|
+
*
|
|
42
|
+
* @param messages Messages in prompt order, either Core messages or provider tool-thread messages.
|
|
43
|
+
* @returns Wire messages with `images` removed and content blocks where needed.
|
|
44
|
+
* @throws {TypeError} When a role and field do not belong together, or an image URL or detail level
|
|
45
|
+
* is invalid.
|
|
46
|
+
*/
|
|
47
|
+
export declare function chatCompletionMessages(messages: readonly (ModelMessage | ProviderMessage)[]): Record<string, unknown>[];
|
|
@@ -1,17 +1,41 @@
|
|
|
1
1
|
import { ValidationError } from '../../structs/errors.js';
|
|
2
|
-
/**
|
|
2
|
+
/**
|
|
3
|
+
* Build the tool-selection request fields for a function-calling stage.
|
|
4
|
+
*
|
|
5
|
+
* The adapter expects exactly one function call per response, so tool use is required and parallel
|
|
6
|
+
* calls are disabled.
|
|
7
|
+
*
|
|
8
|
+
* @param options Model options; absent `functions` means the stage has no tools.
|
|
9
|
+
* @returns Tool fields to merge into the request body, or an empty object.
|
|
10
|
+
* @throws {TypeError} When `functions` is present but empty.
|
|
11
|
+
*/
|
|
3
12
|
export function chatCompletionFunctionOptions(options) {
|
|
4
13
|
if (!options.functions)
|
|
5
14
|
return {};
|
|
6
15
|
if (!options.functions.length)
|
|
7
16
|
throw new TypeError('Empty model function catalog');
|
|
8
17
|
return {
|
|
9
|
-
tools: options.functions.map(fn => ({ type: 'function', function: fn })),
|
|
10
|
-
tool_choice: 'required',
|
|
18
|
+
tools: options.functions.map((fn) => ({ type: 'function', function: fn })),
|
|
19
|
+
tool_choice: 'required',
|
|
20
|
+
parallel_tool_calls: false,
|
|
11
21
|
};
|
|
12
22
|
}
|
|
23
|
+
/**
|
|
24
|
+
* Convert one streamed `choice.delta` into Core model parts.
|
|
25
|
+
*
|
|
26
|
+
* Text is emitted only when non-empty; each tool-call fragment carries its index so Core can
|
|
27
|
+
* reassemble arguments that arrive across chunks.
|
|
28
|
+
*
|
|
29
|
+
* @param delta Raw `delta` value from a chat-completions chunk.
|
|
30
|
+
* @returns Text and function-call-delta parts; an unrelated shape yields an empty array.
|
|
31
|
+
* @throws {ValidationError} When `tool_calls` or one of its entries has an invalid shape.
|
|
32
|
+
*/
|
|
13
33
|
export function chatCompletionParts(delta) {
|
|
14
|
-
const fail = () => {
|
|
34
|
+
const fail = () => {
|
|
35
|
+
throw new ValidationError([
|
|
36
|
+
{ code: 'MODEL_PROTOCOL', message: 'Invalid function call stream' },
|
|
37
|
+
]);
|
|
38
|
+
};
|
|
15
39
|
if (!delta || typeof delta !== 'object' || Array.isArray(delta))
|
|
16
40
|
return [];
|
|
17
41
|
const value = delta;
|
|
@@ -25,16 +49,21 @@ export function chatCompletionParts(delta) {
|
|
|
25
49
|
if (!item || typeof item !== 'object' || Array.isArray(item))
|
|
26
50
|
fail();
|
|
27
51
|
const call = item;
|
|
28
|
-
if (!Number.isInteger(call.index) ||
|
|
29
|
-
|
|
30
|
-
|
|
52
|
+
if (!Number.isInteger(call.index) ||
|
|
53
|
+
call.index < 0 ||
|
|
54
|
+
(call.id !== undefined && (typeof call.id !== 'string' || !call.id)) ||
|
|
55
|
+
(call.type !== undefined && call.type !== 'function'))
|
|
31
56
|
fail();
|
|
32
|
-
if (call.function !== undefined &&
|
|
57
|
+
if (call.function !== undefined &&
|
|
58
|
+
(!call.function || typeof call.function !== 'object' || Array.isArray(call.function)))
|
|
33
59
|
fail();
|
|
34
60
|
const fn = (call.function ?? {});
|
|
35
|
-
if ((fn.name !== undefined && typeof fn.name !== 'string') ||
|
|
61
|
+
if ((fn.name !== undefined && typeof fn.name !== 'string') ||
|
|
62
|
+
(fn.arguments !== undefined && typeof fn.arguments !== 'string'))
|
|
36
63
|
fail();
|
|
37
|
-
parts.push({
|
|
64
|
+
parts.push({
|
|
65
|
+
type: 'function-call-delta',
|
|
66
|
+
index: call.index,
|
|
38
67
|
...(call.id !== undefined ? { id: call.id } : {}),
|
|
39
68
|
...(fn.name !== undefined ? { name: fn.name } : {}),
|
|
40
69
|
...(fn.arguments !== undefined ? { arguments: fn.arguments } : {}),
|
|
@@ -43,21 +72,64 @@ export function chatCompletionParts(delta) {
|
|
|
43
72
|
}
|
|
44
73
|
return parts;
|
|
45
74
|
}
|
|
46
|
-
/**
|
|
75
|
+
/**
|
|
76
|
+
* Map Core and provider messages to chat-completions message payloads.
|
|
77
|
+
*
|
|
78
|
+
* Only declared message fields are sent. Assistant tool declarations become nested
|
|
79
|
+
* `tool_calls`, and tool results become `tool_call_id`; both are rewritten explicitly rather than
|
|
80
|
+
* forwarded as-is. Messages with images become a content-block array; images are accepted only on
|
|
81
|
+
* user messages and only as `http(s)` or `data:image` URLs.
|
|
82
|
+
*
|
|
83
|
+
* @param messages Messages in prompt order, either Core messages or provider tool-thread messages.
|
|
84
|
+
* @returns Wire messages with `images` removed and content blocks where needed.
|
|
85
|
+
* @throws {TypeError} When a role and field do not belong together, or an image URL or detail level
|
|
86
|
+
* is invalid.
|
|
87
|
+
*/
|
|
47
88
|
export function chatCompletionMessages(messages) {
|
|
48
|
-
return messages.map((
|
|
89
|
+
return messages.map((message) => {
|
|
90
|
+
const { role, content, images, toolCalls, toolCallId } = message;
|
|
91
|
+
if (!['system', 'user', 'assistant', 'tool'].includes(role) || typeof content !== 'string')
|
|
92
|
+
throw new TypeError('Invalid provider message role or content');
|
|
93
|
+
if (toolCallId !== undefined && role !== 'tool')
|
|
94
|
+
throw new TypeError('Tool results require the tool role');
|
|
95
|
+
if (role === 'tool' && (typeof toolCallId !== 'string' || !toolCallId))
|
|
96
|
+
throw new TypeError('Tool results require a tool call id');
|
|
97
|
+
if (toolCalls !== undefined && role !== 'assistant')
|
|
98
|
+
throw new TypeError('Tool calls require an assistant message');
|
|
99
|
+
const wire = { role, content };
|
|
100
|
+
if (toolCallId !== undefined)
|
|
101
|
+
wire.tool_call_id = toolCallId;
|
|
102
|
+
if (toolCalls !== undefined)
|
|
103
|
+
wire.tool_calls = toolCalls.map((call) => {
|
|
104
|
+
if (!call ||
|
|
105
|
+
typeof call.id !== 'string' ||
|
|
106
|
+
!call.id ||
|
|
107
|
+
typeof call.name !== 'string' ||
|
|
108
|
+
!call.name ||
|
|
109
|
+
typeof call.arguments !== 'string')
|
|
110
|
+
throw new TypeError('Invalid tool call');
|
|
111
|
+
return {
|
|
112
|
+
id: call.id,
|
|
113
|
+
type: 'function',
|
|
114
|
+
function: { name: call.name, arguments: call.arguments },
|
|
115
|
+
};
|
|
116
|
+
});
|
|
49
117
|
if (!images?.length)
|
|
50
|
-
return
|
|
51
|
-
if (
|
|
118
|
+
return wire;
|
|
119
|
+
if (role !== 'user')
|
|
52
120
|
throw new TypeError('Images require a user message');
|
|
53
121
|
for (const image of images) {
|
|
54
|
-
if (!image.url ||
|
|
55
|
-
|
|
122
|
+
if (!image.url ||
|
|
123
|
+
!/^(https?:\/\/|data:image\/)/i.test(image.url) ||
|
|
124
|
+
(image.detail !== undefined && !['auto', 'low', 'high', 'original'].includes(image.detail)))
|
|
56
125
|
throw new TypeError('Invalid model image');
|
|
57
126
|
}
|
|
58
|
-
return {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
127
|
+
return {
|
|
128
|
+
...wire,
|
|
129
|
+
content: [
|
|
130
|
+
{ type: 'text', text: content },
|
|
131
|
+
...images.map((image) => ({ type: 'image_url', image_url: image })),
|
|
132
|
+
],
|
|
133
|
+
};
|
|
62
134
|
});
|
|
63
135
|
}
|
|
@@ -1,15 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Child model-task group: run several Core child calls with bounded concurrency.
|
|
3
|
+
*
|
|
4
|
+
* Each task receives a Core child runner created from the parent's limits, so budgets, timeouts,
|
|
5
|
+
* transports and cancellation remain Core behavior. This module only schedules the group and
|
|
6
|
+
* orders acceptance and commit; it is optional app-side composition, not another scheduler
|
|
7
|
+
* protocol.
|
|
8
|
+
*
|
|
9
|
+
* Main exports: `runChildren` and its task/option types.
|
|
10
|
+
*/
|
|
1
11
|
import type { ModelRunner } from '../../model/runner.js';
|
|
2
12
|
import type { ModelChildOptions } from '../../structs/model/runtime.js';
|
|
3
13
|
import type { MaybePromise } from '../../structs/common.js';
|
|
4
14
|
export interface ModelChildTask<Value> extends ModelChildOptions {
|
|
15
|
+
/**
|
|
16
|
+
* Work executed with the child runner bound to this task's limits.
|
|
17
|
+
*
|
|
18
|
+
* The supplied signal also aborts when a sibling fails, so long work should observe it.
|
|
19
|
+
*/
|
|
5
20
|
run(model: ModelRunner, signal: AbortSignal): MaybePromise<Value>;
|
|
6
21
|
}
|
|
7
22
|
export interface ModelChildrenOptions<Value> {
|
|
23
|
+
/** Parallel workers; defaults to, and may not exceed, the parent's concurrency limit. */
|
|
8
24
|
readonly concurrency?: number;
|
|
25
|
+
/** Optional caller cancellation, combined with the parent signal and group failure. */
|
|
9
26
|
readonly signal?: AbortSignal;
|
|
27
|
+
/** Called as each task finishes, before commit; must settle with `void`. */
|
|
10
28
|
accept?(value: Value, id: string): MaybePromise<void>;
|
|
11
|
-
/** Called in declaration order after every result is accepted
|
|
29
|
+
/** Called in declaration order after every result is accepted; App owns atomicity/receipts. */
|
|
12
30
|
commit?(value: Value, id: string): MaybePromise<void>;
|
|
13
31
|
}
|
|
14
|
-
/**
|
|
32
|
+
/**
|
|
33
|
+
* Run child tasks concurrently and return their values in declaration order.
|
|
34
|
+
*
|
|
35
|
+
* The first failure aborts the remaining group, but an already in-flight commit is still awaited
|
|
36
|
+
* because cancellation does not mean the write was rolled back.
|
|
37
|
+
*
|
|
38
|
+
* @param parent Parent runner supplying child creation, limits and cancellation.
|
|
39
|
+
* @param tasks Tasks to run; IDs must be unique and non-blank.
|
|
40
|
+
* @param options Concurrency, extra cancellation and accept/commit hooks.
|
|
41
|
+
* @returns Frozen values in declaration order.
|
|
42
|
+
* @throws {Error} When the concurrency, a task declaration or a duplicate ID is invalid.
|
|
43
|
+
* @throws The first task's error, or the combined signal's abort reason.
|
|
44
|
+
*/
|
|
15
45
|
export declare function runChildren<Value>(parent: Pick<ModelRunner, 'createChild' | 'childLimits' | 'signal'>, tasks: readonly ModelChildTask<Value>[], options?: ModelChildrenOptions<Value>): Promise<readonly Value[]>;
|
|
@@ -1,17 +1,41 @@
|
|
|
1
1
|
import { awaitWithSignal, awaitAssertion, combineSignals } from '../../utils/cancellation.js';
|
|
2
2
|
import { assertion } from '../../utils/synchronous.js';
|
|
3
3
|
import { breakWhile } from '../../utils/rules.js';
|
|
4
|
-
/**
|
|
4
|
+
/**
|
|
5
|
+
* Run child tasks concurrently and return their values in declaration order.
|
|
6
|
+
*
|
|
7
|
+
* The first failure aborts the remaining group, but an already in-flight commit is still awaited
|
|
8
|
+
* because cancellation does not mean the write was rolled back.
|
|
9
|
+
*
|
|
10
|
+
* @param parent Parent runner supplying child creation, limits and cancellation.
|
|
11
|
+
* @param tasks Tasks to run; IDs must be unique and non-blank.
|
|
12
|
+
* @param options Concurrency, extra cancellation and accept/commit hooks.
|
|
13
|
+
* @returns Frozen values in declaration order.
|
|
14
|
+
* @throws {Error} When the concurrency, a task declaration or a duplicate ID is invalid.
|
|
15
|
+
* @throws The first task's error, or the combined signal's abort reason.
|
|
16
|
+
*/
|
|
5
17
|
export async function runChildren(parent, tasks, options = {}) {
|
|
6
18
|
const concurrency = options.concurrency ?? parent.childLimits.maxConcurrentCalls;
|
|
7
|
-
breakWhile(!Number.isSafeInteger(concurrency) ||
|
|
19
|
+
breakWhile(!Number.isSafeInteger(concurrency) ||
|
|
20
|
+
concurrency < 1 ||
|
|
21
|
+
concurrency > parent.childLimits.maxConcurrentCalls, 'Child group concurrency exceeds the parent policy');
|
|
8
22
|
const accept = options.accept?.bind(options), commit = options.commit?.bind(options);
|
|
9
|
-
const definitions = tasks.map(task => {
|
|
23
|
+
const definitions = tasks.map((task) => {
|
|
10
24
|
const { id, maxCalls, reserveCalls, timeoutMs, transports, diagnostics, signal, run } = task;
|
|
11
25
|
breakWhile(typeof id !== 'string' || !id.trim() || typeof run !== 'function', 'Invalid child task');
|
|
12
|
-
return {
|
|
26
|
+
return {
|
|
27
|
+
id,
|
|
28
|
+
maxCalls,
|
|
29
|
+
reserveCalls,
|
|
30
|
+
timeoutMs,
|
|
31
|
+
transports: transports === undefined ? undefined : [...transports],
|
|
32
|
+
diagnostics,
|
|
33
|
+
signal,
|
|
34
|
+
run: run.bind(task),
|
|
35
|
+
};
|
|
13
36
|
});
|
|
14
|
-
breakWhile(new Set(definitions.map(task => task.id)).size !== definitions.length, 'Duplicate child task id');
|
|
37
|
+
breakWhile(new Set(definitions.map((task) => task.id)).size !== definitions.length, 'Duplicate child task id');
|
|
38
|
+
// One group controller so the first failure cancels every sibling worker at once.
|
|
15
39
|
const cancellation = new AbortController();
|
|
16
40
|
const signal = combineSignals(parent.signal, cancellation.signal, options.signal);
|
|
17
41
|
signal.throwIfAborted();
|
|
@@ -22,12 +46,16 @@ export async function runChildren(parent, tasks, options = {}) {
|
|
|
22
46
|
const index = next++, definition = definitions[index];
|
|
23
47
|
try {
|
|
24
48
|
signal.throwIfAborted();
|
|
25
|
-
const child = parent.createChild({
|
|
49
|
+
const child = parent.createChild({
|
|
50
|
+
...definition,
|
|
51
|
+
signal: combineSignals(signal, definition.signal),
|
|
52
|
+
});
|
|
26
53
|
const value = await awaitWithSignal(definition.run(child, child.signal), child.signal);
|
|
27
54
|
child.signal.throwIfAborted();
|
|
28
55
|
if (accept)
|
|
29
56
|
await awaitAssertion(() => accept(value, definition.id), child.signal, 'Child acceptance must return void');
|
|
30
57
|
child.signal.throwIfAborted();
|
|
58
|
+
// Index by declaration position so completion order never changes the result order.
|
|
31
59
|
values[index] = value;
|
|
32
60
|
}
|
|
33
61
|
catch (error) {
|
|
@@ -1,12 +1,38 @@
|
|
|
1
1
|
import type { CompatibleModelProviderOptions } from '../../structs/support/model/provider.js';
|
|
2
2
|
import { ChatProvider, type ModelProviderContext } from '../../structs/model/chat-provider.js';
|
|
3
3
|
import type { ModelMessage, ModelPart } from '../../structs/model/messages.js';
|
|
4
|
-
|
|
4
|
+
import type { ProviderMessage } from '../../structs/support/model/messages.js';
|
|
5
|
+
/**
|
|
6
|
+
* HTTP/SSE lifecycle shared by hosts. Apps supply config and user-visible error mapping only.
|
|
7
|
+
*
|
|
8
|
+
* A static configuration is validated and frozen in the constructor. A configuration function is
|
|
9
|
+
* called once per request instead, so credentials and models may rotate between calls.
|
|
10
|
+
*/
|
|
5
11
|
export declare class CompatibleModelProvider extends ChatProvider {
|
|
6
12
|
private readonly configuration;
|
|
7
13
|
private readonly ports;
|
|
14
|
+
/**
|
|
15
|
+
* Create a provider.
|
|
16
|
+
*
|
|
17
|
+
* @param options Static or per-request configuration, optional ports and observation/error hooks.
|
|
18
|
+
* @throws {TypeError} When a static configuration is invalid (for example `maxTokens`,
|
|
19
|
+
* reserved request-body fields, unsupported reasoning format or invalid budgets).
|
|
20
|
+
*/
|
|
8
21
|
constructor(options: CompatibleModelProviderOptions);
|
|
9
22
|
private failure;
|
|
10
|
-
|
|
23
|
+
/**
|
|
24
|
+
* Stream one chat-completions response as Core model parts.
|
|
25
|
+
*
|
|
26
|
+
* The method validates the effective request and yields parts as they arrive. Whether the
|
|
27
|
+
* finished stream is acceptable is decided by the configured completion policy, which defaults
|
|
28
|
+
* to the legacy rules. A stream that ends without the end-of-stream marker is incomplete, not a
|
|
29
|
+
* partial success.
|
|
30
|
+
*
|
|
31
|
+
* @param messages Prompt messages in order, including provider tool-thread messages.
|
|
32
|
+
* @param context Provider context with signal, call options and diagnostics/observer ports.
|
|
33
|
+
* @yields Text chunks and function-call deltas as they arrive.
|
|
34
|
+
* @throws The classified provider error (see `MODEL_*` codes) or the signal's abort reason.
|
|
35
|
+
*/
|
|
36
|
+
stream(messages: readonly (ModelMessage | ProviderMessage)[], context: ModelProviderContext): AsyncIterable<ModelPart>;
|
|
11
37
|
}
|
|
12
|
-
export type { ModelProviderErrorCode, ModelProviderFailure, CompatibleModelConfig, CompatibleModelPorts, CompatibleModelProviderOptions, ProviderReasoningLevel, ProviderReasoningStrategy } from '../../structs/support/model/provider.js';
|
|
38
|
+
export type { ModelProviderErrorCode, ModelProviderFailure, CompatibleModelConfig, CompatibleModelPorts, CompatibleModelProviderOptions, ProviderReasoningLevel, ProviderReasoningStrategy, } from '../../structs/support/model/provider.js';
|