@jangts/agent-core 0.1.1 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +25 -0
- package/LICENSE +55 -0
- package/NOTICE +6 -0
- package/README.md +8 -0
- package/development/docs/README.en.md +70 -0
- package/development/docs/README.md +1 -1
- package/development/docs/acceptance.en.md +34 -0
- package/development/docs/agent-development.en.md +42 -0
- package/development/docs/api/README.en.md +62 -0
- package/development/docs/api/advanced-agents.en.md +135 -0
- package/development/docs/api/context-processing.en.md +110 -0
- package/development/docs/api/core.en.md +274 -0
- package/development/docs/api/examples.en.md +118 -0
- package/development/docs/api/kits.en.md +183 -0
- package/development/docs/api/knowledge-answering.en.md +166 -0
- package/development/docs/api/mock.en.md +186 -0
- package/development/docs/api/observability.en.md +166 -0
- package/development/docs/api/reference.en.md +2235 -0
- package/development/docs/api/reference.md +1907 -1874
- package/development/docs/api/support.en.md +252 -0
- package/development/docs/api/support.md +27 -0
- package/development/docs/api/types.en.md +181 -0
- package/development/docs/api/workflow.en.md +188 -0
- package/development/docs/basic-usage.en.md +78 -0
- package/development/docs/create-app.en.md +76 -0
- package/development/docs/examples/offline-agent.en.md +273 -0
- package/development/docs/examples.en.md +36 -0
- package/development/docs/flows/knowledge-maintenance.en.md +38 -0
- package/development/docs/getting-started.en.md +71 -0
- package/development/docs/knowledge.en.md +89 -0
- package/development/docs/maintenance.en.md +62 -0
- package/development/docs/materials.en.md +38 -0
- package/development/docs/mechanisms.en.md +227 -0
- package/development/docs/memory-and-learning.en.md +42 -0
- package/development/docs/operations.en.md +51 -0
- package/development/docs/records.en.md +63 -0
- package/development/docs/registration.en.md +63 -0
- package/development/skills/agent-core-app/scripts/create-app.mjs +286 -70
- package/development/skills/agent-core-app/scripts/lib/knowledge.mjs +77 -16
- package/development/skills/agent-core-app/scripts/lib/source.mjs +30 -2
- package/development/skills/agent-core-app/scripts/plan.mjs +46 -12
- package/development/skills/agent-core-app/scripts/prepare-source.mjs +61 -10
- package/development/skills/agent-core-app/scripts/resources.mjs +62 -17
- package/development/skills/agent-core-app/scripts/validate-knowledge.mjs +18 -1
- package/development/skills/agent-core-app/templates/catalog.json +36 -22
- package/dist/cjs/capabilities/index.js +13 -0
- package/dist/cjs/capabilities/invocation.js +80 -10
- package/dist/cjs/capabilities/model.js +126 -13
- package/dist/cjs/capabilities/tool-runtime.js +64 -12
- package/dist/cjs/capabilities/tools.js +266 -31
- package/dist/cjs/context/assembly.js +46 -5
- package/dist/cjs/context/audit.js +31 -6
- package/dist/cjs/context/fragments.js +54 -11
- package/dist/cjs/context/index.js +12 -0
- package/dist/cjs/context/journal.js +84 -7
- package/dist/cjs/context/plan.js +30 -2
- package/dist/cjs/diagnostics/catalog.js +17 -3
- package/dist/cjs/diagnostics/index.js +149 -29
- package/dist/cjs/diagnostics/sub-flow.js +240 -40
- package/dist/cjs/errors.js +99 -17
- package/dist/cjs/execution/branch.js +20 -4
- package/dist/cjs/execution/engine.js +470 -56
- package/dist/cjs/execution/events.js +136 -18
- package/dist/cjs/execution/index.js +7 -0
- package/dist/cjs/execution/reporting.js +75 -6
- package/dist/cjs/execution/state.js +161 -22
- package/dist/cjs/execution/workflow.js +224 -32
- package/dist/cjs/index.js +18 -0
- package/dist/cjs/kits/aggregation.js +45 -3
- package/dist/cjs/kits/answering/batch.js +23 -4
- package/dist/cjs/kits/answering/check-result.js +31 -8
- package/dist/cjs/kits/answering/checks.js +24 -3
- package/dist/cjs/kits/answering/flow.js +192 -36
- package/dist/cjs/kits/answering/index.js +19 -1
- package/dist/cjs/kits/answering/tasks.js +88 -13
- package/dist/cjs/kits/artifacts.js +36 -4
- package/dist/cjs/kits/candidates.js +47 -5
- package/dist/cjs/kits/delivery.js +40 -5
- package/dist/cjs/kits/durable.js +155 -31
- package/dist/cjs/kits/evidence.js +66 -15
- package/dist/cjs/kits/family.js +152 -22
- package/dist/cjs/kits/index.js +12 -1
- package/dist/cjs/kits/inference.js +104 -16
- package/dist/cjs/kits/intents/catalog.js +67 -16
- package/dist/cjs/kits/intents/index.js +11 -0
- package/dist/cjs/kits/intents/registry.js +188 -43
- package/dist/cjs/kits/intents/scopes.js +215 -46
- package/dist/cjs/kits/interaction/command.js +140 -36
- package/dist/cjs/kits/interaction/commands.js +86 -11
- package/dist/cjs/kits/interaction/handlers.js +27 -10
- package/dist/cjs/kits/interaction/index.js +10 -0
- package/dist/cjs/kits/interaction/transfer.js +80 -14
- package/dist/cjs/kits/knowledge/catalog.js +62 -11
- package/dist/cjs/kits/knowledge/index.js +16 -1
- package/dist/cjs/kits/knowledge/publication.js +99 -23
- package/dist/cjs/kits/knowledge/sections.js +33 -4
- package/dist/cjs/kits/normalization.js +51 -7
- package/dist/cjs/kits/policies.js +79 -15
- package/dist/cjs/kits/presentation/events.js +54 -10
- package/dist/cjs/kits/presentation/index.js +24 -1
- package/dist/cjs/kits/presentation/outputs.js +176 -38
- package/dist/cjs/kits/presentation/templates.js +33 -5
- package/dist/cjs/kits/presentation/variants.js +31 -2
- package/dist/cjs/kits/projection.js +63 -8
- package/dist/cjs/kits/rank-fusion.js +27 -4
- package/dist/cjs/kits/reflection-log-source.js +89 -16
- package/dist/cjs/kits/reflection.js +234 -60
- package/dist/cjs/kits/retrieval.js +98 -18
- package/dist/cjs/kits/search.js +180 -27
- package/dist/cjs/kits/text-skills.js +104 -19
- package/dist/cjs/kits/tools.js +415 -74
- package/dist/cjs/kits/vector-search.js +50 -16
- package/dist/cjs/mock/node.js +7 -1
- package/dist/cjs/mock/web.js +7 -1
- package/dist/cjs/mock.js +7 -1
- package/dist/cjs/model/binding.js +68 -17
- package/dist/cjs/model/call-budget.js +45 -4
- package/dist/cjs/model/decision-retry.js +19 -1
- package/dist/cjs/model/defaults.js +27 -4
- package/dist/cjs/model/index.js +7 -0
- package/dist/cjs/model/interactions/arguments.js +36 -1
- package/dist/cjs/model/interactions/json-object.js +48 -12
- package/dist/cjs/model/interactions/native-functions.js +52 -10
- package/dist/cjs/model/message-diagnostics.js +17 -4
- package/dist/cjs/model/options.js +9 -1
- package/dist/cjs/model/preparation.js +86 -12
- package/dist/cjs/model/runner.js +413 -79
- package/dist/cjs/model/selection-transport.js +48 -8
- package/dist/cjs/model/settings.js +67 -13
- package/dist/cjs/model/token-budget.js +69 -11
- package/dist/cjs/model/transports.js +59 -6
- package/dist/cjs/structs/common.js +11 -0
- package/dist/cjs/structs/debug.js +34 -5
- package/dist/cjs/structs/errors.js +26 -1
- package/dist/cjs/structs/index.js +11 -1
- package/dist/cjs/structs/kits/durable.js +7 -0
- package/dist/cjs/structs/kits/family.js +1 -0
- package/dist/cjs/structs/kits/interaction.js +8 -1
- package/dist/cjs/structs/kits/knowledge-publication.js +1 -0
- package/dist/cjs/structs/kits/reflection.js +18 -3
- package/dist/cjs/structs/model/chat-provider.js +6 -0
- package/dist/cjs/structs/support/model/completion.js +2 -0
- package/dist/cjs/structs/support/model/messages.js +2 -0
- package/dist/cjs/support/capabilities.js +43 -6
- package/dist/cjs/support/context/assembly.js +88 -16
- package/dist/cjs/support/context/compression.js +48 -6
- package/dist/cjs/support/context/fragments.js +6 -0
- package/dist/cjs/support/context/history.js +36 -1
- package/dist/cjs/support/context/index.js +11 -0
- package/dist/cjs/support/context/nodes.js +164 -35
- package/dist/cjs/support/context/processing.js +319 -61
- package/dist/cjs/support/context/selection-policy.js +98 -21
- package/dist/cjs/support/context/selection.js +61 -10
- package/dist/cjs/support/context/snapshot.js +29 -7
- package/dist/cjs/support/context/strategies.js +120 -28
- package/dist/cjs/support/index.js +9 -1
- package/dist/cjs/support/model/capabilities.js +20 -1
- package/dist/cjs/support/model/chat-completions.js +92 -20
- package/dist/cjs/support/model/children.js +34 -6
- package/dist/cjs/support/model/compatible-provider.js +189 -59
- package/dist/cjs/support/model/completion/calls.js +61 -0
- package/dist/cjs/support/model/completion/default.js +33 -0
- package/dist/cjs/support/model/completion/index.js +28 -0
- package/dist/cjs/support/model/completion/session.js +107 -0
- package/dist/cjs/support/model/index.js +12 -0
- package/dist/cjs/support/model/interactions/index.js +12 -1
- package/dist/cjs/support/model/interactions/json-object.js +6 -0
- package/dist/cjs/support/model/interactions/native-functions.js +6 -0
- package/dist/cjs/support/model/observer.js +32 -6
- package/dist/cjs/support/model/preview-rules.js +66 -16
- package/dist/cjs/support/model/reply-preview.js +77 -17
- package/dist/cjs/support/model/stage-transport.js +33 -7
- package/dist/cjs/support/model/strategies.js +75 -14
- package/dist/cjs/support/model/transports.js +53 -11
- package/dist/cjs/support/registration.js +49 -7
- package/dist/cjs/support/schema.js +46 -4
- package/dist/cjs/support/stream-events.js +60 -8
- package/dist/cjs/support/tool-runtime.js +6 -0
- package/dist/cjs/support/tools.js +79 -10
- package/dist/cjs/support/transport/index.js +7 -0
- package/dist/cjs/support/transport/json.js +28 -4
- package/dist/cjs/support/transport/sse.js +25 -2
- package/dist/cjs/utils/break-observer.js +20 -2
- package/dist/cjs/utils/cancellation.js +77 -9
- package/dist/cjs/utils/catalog.js +19 -4
- package/dist/cjs/utils/debug.js +14 -2
- package/dist/cjs/utils/index.js +8 -0
- package/dist/cjs/utils/interaction-definition.js +26 -6
- package/dist/cjs/utils/invocation.js +42 -4
- package/dist/cjs/utils/model-protocol.js +20 -1
- package/dist/cjs/utils/object.js +16 -0
- package/dist/cjs/utils/observer.js +22 -2
- package/dist/cjs/utils/protocol-registry.js +47 -4
- package/dist/cjs/utils/query-key.js +21 -2
- package/dist/cjs/utils/registration.js +18 -2
- package/dist/cjs/utils/rules.js +39 -11
- package/dist/cjs/utils/schema-adapter.js +25 -2
- package/dist/cjs/utils/synchronous.js +64 -7
- package/dist/cjs/utils/text.js +15 -1
- package/dist/esm/capabilities/index.d.ts +13 -0
- package/dist/esm/capabilities/index.js +13 -0
- package/dist/esm/capabilities/invocation.d.ts +16 -2
- package/dist/esm/capabilities/invocation.js +80 -10
- package/dist/esm/capabilities/model.d.ts +68 -1
- package/dist/esm/capabilities/model.js +126 -13
- package/dist/esm/capabilities/tool-runtime.d.ts +11 -0
- package/dist/esm/capabilities/tool-runtime.js +64 -12
- package/dist/esm/capabilities/tools.d.ts +96 -3
- package/dist/esm/capabilities/tools.js +267 -32
- package/dist/esm/context/assembly.d.ts +13 -2
- package/dist/esm/context/assembly.js +46 -5
- package/dist/esm/context/audit.d.ts +23 -1
- package/dist/esm/context/audit.js +31 -6
- package/dist/esm/context/fragments.d.ts +37 -3
- package/dist/esm/context/fragments.js +54 -11
- package/dist/esm/context/index.d.ts +12 -0
- package/dist/esm/context/index.js +12 -0
- package/dist/esm/context/journal.d.ts +32 -1
- package/dist/esm/context/journal.js +84 -7
- package/dist/esm/context/plan.d.ts +11 -1
- package/dist/esm/context/plan.js +30 -2
- package/dist/esm/diagnostics/catalog.d.ts +6 -0
- package/dist/esm/diagnostics/catalog.js +17 -3
- package/dist/esm/diagnostics/index.d.ts +30 -2
- package/dist/esm/diagnostics/index.js +149 -29
- package/dist/esm/diagnostics/sub-flow.d.ts +41 -3
- package/dist/esm/diagnostics/sub-flow.js +240 -40
- package/dist/esm/errors.d.ts +22 -2
- package/dist/esm/errors.js +99 -17
- package/dist/esm/execution/branch.d.ts +19 -1
- package/dist/esm/execution/branch.js +20 -4
- package/dist/esm/execution/engine.d.ts +291 -5
- package/dist/esm/execution/engine.js +471 -57
- package/dist/esm/execution/events.d.ts +16 -2
- package/dist/esm/execution/events.js +136 -18
- package/dist/esm/execution/index.d.ts +7 -0
- package/dist/esm/execution/index.js +7 -0
- package/dist/esm/execution/reporting.d.ts +49 -1
- package/dist/esm/execution/reporting.js +75 -6
- package/dist/esm/execution/state.d.ts +126 -10
- package/dist/esm/execution/state.js +161 -22
- package/dist/esm/execution/workflow.d.ts +121 -3
- package/dist/esm/execution/workflow.js +224 -32
- package/dist/esm/index.d.ts +17 -1
- package/dist/esm/index.js +18 -0
- package/dist/esm/kits/aggregation.d.ts +34 -2
- package/dist/esm/kits/aggregation.js +45 -3
- package/dist/esm/kits/answering/batch.d.ts +17 -0
- package/dist/esm/kits/answering/batch.js +23 -4
- package/dist/esm/kits/answering/check-result.d.ts +18 -1
- package/dist/esm/kits/answering/check-result.js +31 -8
- package/dist/esm/kits/answering/checks.d.ts +11 -0
- package/dist/esm/kits/answering/checks.js +24 -3
- package/dist/esm/kits/answering/flow.d.ts +25 -2
- package/dist/esm/kits/answering/flow.js +192 -36
- package/dist/esm/kits/answering/index.d.ts +12 -0
- package/dist/esm/kits/answering/index.js +19 -1
- package/dist/esm/kits/answering/tasks.d.ts +32 -1
- package/dist/esm/kits/answering/tasks.js +88 -13
- package/dist/esm/kits/artifacts.d.ts +11 -0
- package/dist/esm/kits/artifacts.js +36 -4
- package/dist/esm/kits/candidates.d.ts +23 -1
- package/dist/esm/kits/candidates.js +47 -5
- package/dist/esm/kits/delivery.d.ts +34 -0
- package/dist/esm/kits/delivery.js +40 -5
- package/dist/esm/kits/durable.d.ts +19 -0
- package/dist/esm/kits/durable.js +155 -31
- package/dist/esm/kits/evidence.d.ts +28 -5
- package/dist/esm/kits/evidence.js +66 -15
- package/dist/esm/kits/family.d.ts +17 -1
- package/dist/esm/kits/family.js +152 -22
- package/dist/esm/kits/index.d.ts +12 -1
- package/dist/esm/kits/index.js +12 -1
- package/dist/esm/kits/inference.d.ts +64 -0
- package/dist/esm/kits/inference.js +104 -16
- package/dist/esm/kits/intents/catalog.d.ts +13 -1
- package/dist/esm/kits/intents/catalog.js +67 -16
- package/dist/esm/kits/intents/index.d.ts +11 -0
- package/dist/esm/kits/intents/index.js +11 -0
- package/dist/esm/kits/intents/registry.d.ts +61 -3
- package/dist/esm/kits/intents/registry.js +188 -43
- package/dist/esm/kits/intents/scopes.d.ts +73 -3
- package/dist/esm/kits/intents/scopes.js +215 -46
- package/dist/esm/kits/interaction/command.d.ts +38 -4
- package/dist/esm/kits/interaction/command.js +140 -36
- package/dist/esm/kits/interaction/commands.d.ts +66 -2
- package/dist/esm/kits/interaction/commands.js +86 -11
- package/dist/esm/kits/interaction/handlers.d.ts +19 -2
- package/dist/esm/kits/interaction/handlers.js +27 -10
- package/dist/esm/kits/interaction/index.d.ts +10 -0
- package/dist/esm/kits/interaction/index.js +10 -0
- package/dist/esm/kits/interaction/transfer.d.ts +39 -2
- package/dist/esm/kits/interaction/transfer.js +80 -14
- package/dist/esm/kits/knowledge/catalog.d.ts +13 -0
- package/dist/esm/kits/knowledge/catalog.js +62 -11
- package/dist/esm/kits/knowledge/index.d.ts +11 -0
- package/dist/esm/kits/knowledge/index.js +16 -1
- package/dist/esm/kits/knowledge/publication.d.ts +15 -1
- package/dist/esm/kits/knowledge/publication.js +99 -23
- package/dist/esm/kits/knowledge/sections.d.ts +31 -1
- package/dist/esm/kits/knowledge/sections.js +33 -4
- package/dist/esm/kits/normalization.d.ts +25 -2
- package/dist/esm/kits/normalization.js +51 -7
- package/dist/esm/kits/policies.d.ts +26 -3
- package/dist/esm/kits/policies.js +79 -15
- package/dist/esm/kits/presentation/events.d.ts +51 -4
- package/dist/esm/kits/presentation/events.js +54 -10
- package/dist/esm/kits/presentation/index.d.ts +12 -0
- package/dist/esm/kits/presentation/index.js +25 -2
- package/dist/esm/kits/presentation/outputs.d.ts +30 -1
- package/dist/esm/kits/presentation/outputs.js +176 -38
- package/dist/esm/kits/presentation/templates.d.ts +32 -3
- package/dist/esm/kits/presentation/templates.js +33 -5
- package/dist/esm/kits/presentation/variants.d.ts +29 -0
- package/dist/esm/kits/presentation/variants.js +31 -2
- package/dist/esm/kits/projection.d.ts +42 -5
- package/dist/esm/kits/projection.js +63 -8
- package/dist/esm/kits/rank-fusion.d.ts +21 -1
- package/dist/esm/kits/rank-fusion.js +28 -5
- package/dist/esm/kits/reflection-log-source.d.ts +28 -1
- package/dist/esm/kits/reflection-log-source.js +89 -16
- package/dist/esm/kits/reflection.d.ts +17 -1
- package/dist/esm/kits/reflection.js +235 -61
- package/dist/esm/kits/retrieval.d.ts +18 -2
- package/dist/esm/kits/retrieval.js +98 -18
- package/dist/esm/kits/search.d.ts +56 -3
- package/dist/esm/kits/search.js +180 -27
- package/dist/esm/kits/text-skills.d.ts +16 -2
- package/dist/esm/kits/text-skills.js +104 -19
- package/dist/esm/kits/tools.d.ts +122 -2
- package/dist/esm/kits/tools.js +416 -74
- package/dist/esm/kits/vector-search.d.ts +47 -1
- package/dist/esm/kits/vector-search.js +51 -17
- package/dist/esm/mock/node.d.ts +7 -0
- package/dist/esm/mock/node.js +7 -1
- package/dist/esm/mock/web.d.ts +7 -0
- package/dist/esm/mock/web.js +7 -1
- package/dist/esm/mock.d.ts +7 -0
- package/dist/esm/mock.js +7 -1
- package/dist/esm/model/binding.d.ts +32 -3
- package/dist/esm/model/binding.js +68 -17
- package/dist/esm/model/call-budget.d.ts +30 -2
- package/dist/esm/model/call-budget.js +45 -4
- package/dist/esm/model/decision-retry.d.ts +10 -1
- package/dist/esm/model/decision-retry.js +19 -1
- package/dist/esm/model/defaults.d.ts +13 -2
- package/dist/esm/model/defaults.js +27 -4
- package/dist/esm/model/index.d.ts +7 -0
- package/dist/esm/model/index.js +7 -0
- package/dist/esm/model/interactions/arguments.d.ts +27 -0
- package/dist/esm/model/interactions/arguments.js +36 -1
- package/dist/esm/model/interactions/json-object.d.ts +7 -1
- package/dist/esm/model/interactions/json-object.js +48 -12
- package/dist/esm/model/interactions/native-functions.d.ts +6 -0
- package/dist/esm/model/interactions/native-functions.js +52 -10
- package/dist/esm/model/message-diagnostics.d.ts +17 -1
- package/dist/esm/model/message-diagnostics.js +17 -4
- package/dist/esm/model/options.d.ts +18 -1
- package/dist/esm/model/options.js +9 -1
- package/dist/esm/model/preparation.d.ts +30 -2
- package/dist/esm/model/preparation.js +86 -12
- package/dist/esm/model/runner.d.ts +129 -5
- package/dist/esm/model/runner.js +414 -80
- package/dist/esm/model/selection-transport.d.ts +14 -1
- package/dist/esm/model/selection-transport.js +48 -8
- package/dist/esm/model/settings.d.ts +11 -0
- package/dist/esm/model/settings.js +67 -13
- package/dist/esm/model/token-budget.d.ts +59 -1
- package/dist/esm/model/token-budget.js +69 -11
- package/dist/esm/model/transports.d.ts +20 -2
- package/dist/esm/model/transports.js +59 -6
- package/dist/esm/structs/capabilities/invocation.d.ts +36 -0
- package/dist/esm/structs/capabilities/model.d.ts +27 -0
- package/dist/esm/structs/capabilities/tools.d.ts +38 -0
- package/dist/esm/structs/common.d.ts +62 -2
- package/dist/esm/structs/common.js +11 -0
- package/dist/esm/structs/context/fragments.d.ts +28 -0
- package/dist/esm/structs/context/journal.d.ts +28 -3
- package/dist/esm/structs/context/processing.d.ts +11 -0
- package/dist/esm/structs/debug.d.ts +58 -1
- package/dist/esm/structs/debug.js +34 -5
- package/dist/esm/structs/diagnostics.d.ts +119 -1
- package/dist/esm/structs/errors.d.ts +42 -1
- package/dist/esm/structs/errors.js +26 -1
- package/dist/esm/structs/execution/engine.d.ts +24 -1
- package/dist/esm/structs/execution/events.d.ts +12 -0
- package/dist/esm/structs/execution/workflow.d.ts +71 -0
- package/dist/esm/structs/index.d.ts +11 -1
- package/dist/esm/structs/index.js +11 -1
- package/dist/esm/structs/invocation.d.ts +30 -0
- package/dist/esm/structs/kits/aggregation.d.ts +12 -0
- package/dist/esm/structs/kits/answering/checks.d.ts +11 -0
- package/dist/esm/structs/kits/answering/flow.d.ts +35 -1
- package/dist/esm/structs/kits/answering/state.d.ts +21 -0
- package/dist/esm/structs/kits/answering/tasks.d.ts +21 -0
- package/dist/esm/structs/kits/artifacts.d.ts +14 -0
- package/dist/esm/structs/kits/candidates.d.ts +19 -0
- package/dist/esm/structs/kits/delivery.d.ts +22 -0
- package/dist/esm/structs/kits/durable.d.ts +56 -3
- package/dist/esm/structs/kits/durable.js +7 -0
- package/dist/esm/structs/kits/evidence.d.ts +23 -0
- package/dist/esm/structs/kits/family.d.ts +49 -1
- package/dist/esm/structs/kits/family.js +1 -0
- package/dist/esm/structs/kits/intents/catalog.d.ts +26 -0
- package/dist/esm/structs/kits/intents/registry.d.ts +34 -0
- package/dist/esm/structs/kits/intents/scopes.d.ts +36 -1
- package/dist/esm/structs/kits/interaction.d.ts +64 -0
- package/dist/esm/structs/kits/interaction.js +8 -1
- package/dist/esm/structs/kits/knowledge-publication.d.ts +43 -1
- package/dist/esm/structs/kits/knowledge-publication.js +1 -0
- package/dist/esm/structs/kits/knowledge.d.ts +39 -2
- package/dist/esm/structs/kits/normalization.d.ts +15 -0
- package/dist/esm/structs/kits/policies.d.ts +25 -1
- package/dist/esm/structs/kits/presentation/events.d.ts +28 -4
- package/dist/esm/structs/kits/presentation/outputs.d.ts +38 -1
- package/dist/esm/structs/kits/presentation/templates.d.ts +15 -0
- package/dist/esm/structs/kits/projection.d.ts +21 -0
- package/dist/esm/structs/kits/reflection.d.ts +61 -2
- package/dist/esm/structs/kits/reflection.js +18 -3
- package/dist/esm/structs/kits/retrieval.d.ts +39 -0
- package/dist/esm/structs/kits/search.d.ts +24 -0
- package/dist/esm/structs/kits/text-skills.d.ts +36 -0
- package/dist/esm/structs/kits/tools.d.ts +87 -0
- package/dist/esm/structs/model/chat-provider.d.ts +24 -1
- package/dist/esm/structs/model/chat-provider.js +6 -0
- package/dist/esm/structs/model/interactions.d.ts +38 -0
- package/dist/esm/structs/model/messages.d.ts +34 -0
- package/dist/esm/structs/model/runtime.d.ts +104 -6
- package/dist/esm/structs/support/capabilities.d.ts +19 -2
- package/dist/esm/structs/support/context-processing.d.ts +88 -9
- package/dist/esm/structs/support/context.d.ts +29 -1
- package/dist/esm/structs/support/model/completion.d.ts +50 -0
- package/dist/esm/structs/support/model/completion.js +1 -0
- package/dist/esm/structs/support/model/interactions.d.ts +13 -1
- package/dist/esm/structs/support/model/messages.d.ts +54 -0
- package/dist/esm/structs/support/model/messages.js +1 -0
- package/dist/esm/structs/support/model/provider-observer.d.ts +22 -1
- package/dist/esm/structs/support/model/provider.d.ts +71 -6
- package/dist/esm/structs/support/registration.d.ts +13 -0
- package/dist/esm/structs/support/schema.d.ts +14 -0
- package/dist/esm/structs/support/tools.d.ts +28 -0
- package/dist/esm/structs/support/transport/json.d.ts +16 -0
- package/dist/esm/structs/support/transport/sse.d.ts +15 -0
- package/dist/esm/structs/utils/rules.d.ts +19 -0
- package/dist/esm/support/capabilities.d.ts +25 -2
- package/dist/esm/support/capabilities.js +43 -6
- package/dist/esm/support/context/assembly.d.ts +35 -4
- package/dist/esm/support/context/assembly.js +88 -16
- package/dist/esm/support/context/compression.d.ts +17 -1
- package/dist/esm/support/context/compression.js +48 -6
- package/dist/esm/support/context/fragments.d.ts +6 -0
- package/dist/esm/support/context/fragments.js +6 -0
- package/dist/esm/support/context/history.d.ts +43 -0
- package/dist/esm/support/context/history.js +36 -1
- package/dist/esm/support/context/index.d.ts +13 -2
- package/dist/esm/support/context/index.js +12 -1
- package/dist/esm/support/context/nodes.d.ts +65 -3
- package/dist/esm/support/context/nodes.js +165 -36
- package/dist/esm/support/context/processing.d.ts +152 -1
- package/dist/esm/support/context/processing.js +320 -62
- package/dist/esm/support/context/selection-policy.d.ts +42 -2
- package/dist/esm/support/context/selection-policy.js +98 -21
- package/dist/esm/support/context/selection.d.ts +14 -1
- package/dist/esm/support/context/selection.js +61 -10
- package/dist/esm/support/context/snapshot.d.ts +23 -1
- package/dist/esm/support/context/snapshot.js +29 -7
- package/dist/esm/support/context/strategies.d.ts +35 -2
- package/dist/esm/support/context/strategies.js +120 -28
- package/dist/esm/support/index.d.ts +9 -1
- package/dist/esm/support/index.js +9 -1
- package/dist/esm/support/model/capabilities.d.ts +10 -0
- package/dist/esm/support/model/capabilities.js +20 -1
- package/dist/esm/support/model/chat-completions.d.ts +44 -15
- package/dist/esm/support/model/chat-completions.js +92 -20
- package/dist/esm/support/model/children.d.ts +34 -2
- package/dist/esm/support/model/children.js +34 -6
- package/dist/esm/support/model/compatible-provider.d.ts +29 -3
- package/dist/esm/support/model/compatible-provider.js +190 -60
- package/dist/esm/support/model/completion/calls.d.ts +40 -0
- package/dist/esm/support/model/completion/calls.js +58 -0
- package/dist/esm/support/model/completion/default.d.ts +11 -0
- package/dist/esm/support/model/completion/default.js +30 -0
- package/dist/esm/support/model/completion/index.d.ts +10 -0
- package/dist/esm/support/model/completion/index.js +22 -0
- package/dist/esm/support/model/completion/session.d.ts +16 -0
- package/dist/esm/support/model/completion/session.js +104 -0
- package/dist/esm/support/model/index.d.ts +14 -0
- package/dist/esm/support/model/index.js +12 -0
- package/dist/esm/support/model/interactions/index.d.ts +1 -1
- package/dist/esm/support/model/interactions/index.js +12 -1
- package/dist/esm/support/model/interactions/json-object.d.ts +6 -0
- package/dist/esm/support/model/interactions/json-object.js +6 -0
- package/dist/esm/support/model/interactions/native-functions.d.ts +6 -0
- package/dist/esm/support/model/interactions/native-functions.js +6 -0
- package/dist/esm/support/model/observer.d.ts +25 -2
- package/dist/esm/support/model/observer.js +32 -6
- package/dist/esm/support/model/preview-rules.d.ts +26 -2
- package/dist/esm/support/model/preview-rules.js +66 -16
- package/dist/esm/support/model/reply-preview.d.ts +22 -1
- package/dist/esm/support/model/reply-preview.js +77 -17
- package/dist/esm/support/model/stage-transport.d.ts +9 -1
- package/dist/esm/support/model/stage-transport.js +33 -7
- package/dist/esm/support/model/strategies.d.ts +28 -2
- package/dist/esm/support/model/strategies.js +75 -14
- package/dist/esm/support/model/transports.d.ts +17 -1
- package/dist/esm/support/model/transports.js +53 -11
- package/dist/esm/support/registration.d.ts +20 -1
- package/dist/esm/support/registration.js +49 -7
- package/dist/esm/support/schema.d.ts +31 -1
- package/dist/esm/support/schema.js +46 -4
- package/dist/esm/support/stream-events.d.ts +22 -1
- package/dist/esm/support/stream-events.js +60 -8
- package/dist/esm/support/tool-runtime.d.ts +6 -0
- package/dist/esm/support/tool-runtime.js +6 -0
- package/dist/esm/support/tools.d.ts +22 -0
- package/dist/esm/support/tools.js +79 -10
- package/dist/esm/support/transport/index.d.ts +7 -0
- package/dist/esm/support/transport/index.js +7 -0
- package/dist/esm/support/transport/json.d.ts +29 -2
- package/dist/esm/support/transport/json.js +28 -4
- package/dist/esm/support/transport/sse.d.ts +31 -1
- package/dist/esm/support/transport/sse.js +25 -2
- package/dist/esm/types.d.ts +9 -1
- package/dist/esm/utils/break-observer.d.ts +27 -2
- package/dist/esm/utils/break-observer.js +20 -2
- package/dist/esm/utils/cancellation.d.ts +56 -5
- package/dist/esm/utils/cancellation.js +77 -9
- package/dist/esm/utils/catalog.d.ts +20 -1
- package/dist/esm/utils/catalog.js +19 -4
- package/dist/esm/utils/debug.d.ts +20 -1
- package/dist/esm/utils/debug.js +14 -2
- package/dist/esm/utils/index.d.ts +8 -0
- package/dist/esm/utils/index.js +8 -0
- package/dist/esm/utils/interaction-definition.d.ts +18 -1
- package/dist/esm/utils/interaction-definition.js +26 -6
- package/dist/esm/utils/invocation.d.ts +36 -1
- package/dist/esm/utils/invocation.js +42 -4
- package/dist/esm/utils/model-protocol.d.ts +8 -0
- package/dist/esm/utils/model-protocol.js +20 -1
- package/dist/esm/utils/object.d.ts +16 -0
- package/dist/esm/utils/object.js +16 -0
- package/dist/esm/utils/observer.d.ts +19 -1
- package/dist/esm/utils/observer.js +22 -2
- package/dist/esm/utils/protocol-registry.d.ts +38 -1
- package/dist/esm/utils/protocol-registry.js +47 -4
- package/dist/esm/utils/query-key.d.ts +11 -1
- package/dist/esm/utils/query-key.js +21 -2
- package/dist/esm/utils/registration.d.ts +34 -2
- package/dist/esm/utils/registration.js +18 -2
- package/dist/esm/utils/rules.d.ts +81 -4
- package/dist/esm/utils/rules.js +39 -11
- package/dist/esm/utils/schema-adapter.d.ts +12 -1
- package/dist/esm/utils/schema-adapter.js +25 -2
- package/dist/esm/utils/synchronous.d.ts +60 -4
- package/dist/esm/utils/synchronous.js +64 -7
- package/dist/esm/utils/text.d.ts +15 -1
- package/dist/esm/utils/text.js +15 -1
- package/package.json +7 -3
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# Result delivery, diagnostics, and operations
|
|
2
|
+
|
|
3
|
+
[Back to development handbook](README.md) · [Core API](api/core.md) · [Support API](api/support.md)
|
|
4
|
+
|
|
5
|
+
## Boundary of each run
|
|
6
|
+
|
|
7
|
+
Keep startup manifests separate from per-request state. For each request, establish identity, the allowed knowledge view, an `AbortSignal`, model/tool budget, and source and output state. Credentials, endpoints, model characteristics, and error mapping for connecting to the Provider are managed by the App server, and user materials or model parameters are not allowed to override these configurations.
|
|
8
|
+
|
|
9
|
+
Consider rounds, model call counts, timeouts, message and output characters, schema size, and business tool quotas separately. Repair, review, and fallback also consume budget; a step called "recovery" cannot mean unlimited retries. Core's model call budget covers only calls that actually pass through that runner; external HTTP, background jobs, and model calls made by the App itself must be limited by the App.
|
|
10
|
+
|
|
11
|
+
Cancellation must reach the actual model and business I/O; for writes already started, cancellation does not mean rollback. The App should be able to judge whether an operation has executed by idempotency key/real receipt, and query state before retrying. Synchronous ToolRegistry does not wait for arbitrary Promises; asynchronous business logic should be placed in suitable asynchronous handlers/nodes and must not fake synchronous success.
|
|
12
|
+
|
|
13
|
+
## Verify facts first, then form presentable output
|
|
14
|
+
|
|
15
|
+
```text
|
|
16
|
+
Parsed model proposal
|
|
17
|
+
→ authorization and real execution
|
|
18
|
+
→ input/output contracts and source checks
|
|
19
|
+
→ generate candidate reply
|
|
20
|
+
→ completeness/business fact checks
|
|
21
|
+
→ program binds sources, action states, and links
|
|
22
|
+
→ deliver in the form chosen by the App
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
A Knowledge Snapshot is a source reference, a tool event is an execution record, and model text is a candidate explanation; the three do not substitute for each other. Answering's tasks, checks, and bounded repair help organize this chain; the concrete fact checks are provided by the App. See the [knowledge answering API](api/knowledge-answering.md) for the relevant local contracts.
|
|
26
|
+
|
|
27
|
+
Presentation/Interaction is an optional Kit. InteractionProtocol/CommandCatalog does not determine how the App exchanges data between front end and back end; when used, the App registers commands, parsing, and presentation implementations, and still needs actual receipts from the peer. The App may also directly adopt its own HTTP/SSE/event protocol.
|
|
28
|
+
|
|
29
|
+
## Error exits
|
|
30
|
+
|
|
31
|
+
| Actual cause | Program handling | Direction of user-facing wording |
|
|
32
|
+
| --- | --- | --- |
|
|
33
|
+
| Source not provided or not allowed to read | Do not widen permissions, do not generate fake facts | State which kind of available knowledge is missing |
|
|
34
|
+
| Parameters or output violate the contract | Record the specific stage and code; repair or end within budget | State the actual action not completed this time |
|
|
35
|
+
| Provider stream break/timeout | Save known execution state, retry with bounds | Reply incomplete, can retry |
|
|
36
|
+
| Insufficient budget/read limit exceeded | Narrow the legal scope or split the task | State the scope limit; no silent truncation |
|
|
37
|
+
| User cancellation | Stop cancellable work, verify executed operations | State clearly that it stopped and what is confirmed |
|
|
38
|
+
|
|
39
|
+
Error messages should not show internal schemas, tokens, call protocols, or stack traces verbatim. Logs keep machine-locatable fields, and user copy keeps the accurate cause; not every failure should be described as a connectivity problem.
|
|
40
|
+
|
|
41
|
+
## What observation and persistence each own
|
|
42
|
+
|
|
43
|
+
Core's run records/diagnostics and Support's Provider observer provide observation boundaries; they do not automatically create a log database. The App decides whether to output to the console, files, telemetry systems, or a persistent repository, and how to authorize queries, redaction, and retention. `breakWhile` tags are classification hints for interruption, not permission or rule filtering switches; follow the [Support reference](api/support.md).
|
|
44
|
+
|
|
45
|
+
It is recommended to correlate request/run, stage, model or tool call ID, business error code, knowledge revision/snapshot id, and actual duration. By default do not collect credentials, full prompts, user materials, or model body text; when body-text diagnostics are needed, the product must explicitly enable and limit the scope. Observation callbacks should not change business returns or escalate a record failure into duplicate execution.
|
|
46
|
+
|
|
47
|
+
## Publication and recovery
|
|
48
|
+
|
|
49
|
+
Deliver code manifests, knowledge, task references, and configuration as one verifiable version. Validate references before publication and prepare a rollback version; new requests switch to the new catalog while existing requests hold old snapshots. Whether multi-file or database publication is atomic is implemented by the App; the Knowledge in-memory catalog itself provides no storage transactions.
|
|
50
|
+
|
|
51
|
+
When the App publishes, also state the enabled capabilities, knowledge version, configuration, and changes in externally visible behavior; the new version must still preserve the original permissions, budget, cancellation, and delivery guarantees.
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
# App data format examples
|
|
2
|
+
|
|
3
|
+
The JSON below only explains field design for App-owned records; it does not participate in runtime loading, register capabilities, or create data tables. Core does not require this storage format.
|
|
4
|
+
|
|
5
|
+
Use null/empty arrays to indicate not yet provided, and do not fabricate facts from example default values. Field names, states, and versions are defined and validated by the App itself.
|
|
6
|
+
|
|
7
|
+
## Material record
|
|
8
|
+
|
|
9
|
+
Original, extraction status, ownership, lifecycle, and publication status.
|
|
10
|
+
|
|
11
|
+
```json
|
|
12
|
+
{
|
|
13
|
+
"schemaVersion": 1,
|
|
14
|
+
"id": null,
|
|
15
|
+
"ownerId": null,
|
|
16
|
+
"scope": "private",
|
|
17
|
+
"original": { "reference": null, "mediaType": null, "contentSha256": null, "receivedAt": null },
|
|
18
|
+
"extraction": { "status": "pending", "revision": null, "text": null, "caveats": [] },
|
|
19
|
+
"lifetime": "turn",
|
|
20
|
+
"expiresAt": null,
|
|
21
|
+
"publication": { "status": "unpublished", "documentId": null }
|
|
22
|
+
}
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## User preferences
|
|
26
|
+
|
|
27
|
+
Accumulated interaction preferences, source watermark, and version.
|
|
28
|
+
|
|
29
|
+
```json
|
|
30
|
+
{
|
|
31
|
+
"schemaVersion": 1,
|
|
32
|
+
"ownerId": null,
|
|
33
|
+
"revision": null,
|
|
34
|
+
"summary": null,
|
|
35
|
+
"sourceWindow": { "after": null, "through": null, "references": [] },
|
|
36
|
+
"updatedAt": null,
|
|
37
|
+
"expiresAt": null,
|
|
38
|
+
"status": "uninitialized"
|
|
39
|
+
}
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## Experience candidate
|
|
43
|
+
|
|
44
|
+
Experience source, applicability, validation, and publication status.
|
|
45
|
+
|
|
46
|
+
```json
|
|
47
|
+
{
|
|
48
|
+
"schemaVersion": 1,
|
|
49
|
+
"id": null,
|
|
50
|
+
"ownerId": null,
|
|
51
|
+
"revision": null,
|
|
52
|
+
"status": "candidate",
|
|
53
|
+
"claim": null,
|
|
54
|
+
"applicability": [],
|
|
55
|
+
"sources": [],
|
|
56
|
+
"counterexamples": [],
|
|
57
|
+
"conflicts": [],
|
|
58
|
+
"validation": { "status": "pending", "references": [] },
|
|
59
|
+
"publication": { "approvedBy": null, "approvedAt": null, "documentId": null }
|
|
60
|
+
}
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
User preferences cannot carry identity and permissions; experience candidates are not published automatically; raw materials do not automatically enter shared knowledge. See [Knowledge maintenance](maintenance.md), [Materials](materials.md), and [Continuous accumulation](memory-and-learning.md).
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
# Registration, assembly, and execution
|
|
2
|
+
|
|
3
|
+
[Back to development handbook](README.md)
|
|
4
|
+
|
|
5
|
+
## Ordinary tool integration
|
|
6
|
+
|
|
7
|
+
Prefer putting static tool definitions in a separate, readable, typed manifest, preserving item types with Support.defineTool, and assembling with Support.defineToolCatalog. Each item contains id, kind, description, inputSchema, authorize, execute, and parseOutput; inputSchema provides both jsonSchema and parse; model capabilities and execution registration consume the same definition. For complete code see [Tool integration](basic-usage.md#tools-are-declared-only-once).
|
|
8
|
+
|
|
9
|
+
Create catalog.bind({ app: context, execution: { signal } }) per request; the model first produces a ToolProposal, and the App then calls runtime.invoke. The latter reuses Core ToolRegistry.invokeAsync, performing input parsing, actual authorization, execution, and output checks in order. When the available set changes, use catalog.select(ids) to project the same manifest, and still check the real identity at execution. This Support adapter does not replace workflows or the business specifications of Kits.
|
|
10
|
+
|
|
11
|
+
## Two different kinds of registration
|
|
12
|
+
|
|
13
|
+
| Registered object | Purpose | Update method |
|
|
14
|
+
| --- | --- | --- |
|
|
15
|
+
| Tools/model capabilities/workflows/checks/output | Declare what the program can do, when it is available, what it accepts, and who implements it | The App compiles manifests and provides the available set by stage and real identity |
|
|
16
|
+
| Documents/sections/knowledge versions | Declare what content a given read can see | The App loads sources and creates a Knowledge catalog; on update, explicitly rebuild the catalog and related views |
|
|
17
|
+
|
|
18
|
+
Adding one knowledge document usually does not require adding a tool. Keep a single `knowledge.read`, and let the catalog authorized for this round provide legal document/section IDs. The model may propose read requests from the provided set, but cannot use them to register arbitrary new handlers, discover disk directories, or publish knowledge.
|
|
19
|
+
|
|
20
|
+
## What a manifest should state
|
|
21
|
+
|
|
22
|
+
At minimum it should be possible to read: stable identifier, purpose, input and output, real execution entry, availability conditions, read scope, side effects, errors, and receipts. Derive the model-visible catalog, schema, and reference validation from the manifest wherever possible; do not maintain one prompt capability list and another actual execution list.
|
|
23
|
+
|
|
24
|
+
- `ModelCapabilityRegistry` registers the structures the model can propose along with `inputSchema` and `resolve`. inputSchema.jsonSchema is used for model declarations; business parsing, value ranges, and authorization must still be enforced by the program.
|
|
25
|
+
- `ToolRegistry` registers `id/kind/parseInput/execute/parseOutput`. invoke is for synchronous implementations; invokeAsync waits for asynchronous execution before checking output and recording results; do not hand a Promise to the synchronous entry as a completed result.
|
|
26
|
+
- `AgentCoreEngine` workflow nodes declare `requires/provides/routes/onErrorNodeId`. Only updates that pass cancellation and state contract checks are committed; branches are selected in declaration order.
|
|
27
|
+
- `Support.defineContextFragments` assembles request input and fragments. Trust, source, and budget must be correctly labeled by the App; client self-reporting alone is not acceptable.
|
|
28
|
+
- Knowledge, Answering, Presentation, Interaction, Intents, and Tools each own local contracts and are chosen according to business needs. They are not automatically installed by Core.
|
|
29
|
+
|
|
30
|
+
For named constructors, static helpers, and instance methods see [Core](api/core.md), [Support](api/support.md), and [Kit](api/kits.md).
|
|
31
|
+
|
|
32
|
+
## Separate model proposals from actual execution
|
|
33
|
+
|
|
34
|
+
```text
|
|
35
|
+
Server establishes identity and the available capability view
|
|
36
|
+
→ model proposes capability + parameters
|
|
37
|
+
→ Core collects the complete response, validates with inputSchema.parse, then calls the registered resolve
|
|
38
|
+
→ App selects the actual execution entry
|
|
39
|
+
→ tool parameter parsing → authorization by server-side identity → execute → output checks
|
|
40
|
+
→ program records actual sources/execution receipts
|
|
41
|
+
→ generation, checks, binding, and delivery
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
`parse` should not incidentally perform writes, send messages, or call business tools. Nor should a success receipt be generated merely because the model says it is "done". Using the Interaction Kit for cross-end actions merely selects an optional exchange specification; the App still needs to implement peer handlers, identity, permissions, and confirmation of actual results.
|
|
45
|
+
|
|
46
|
+
## Static manifests and in-request views
|
|
47
|
+
|
|
48
|
+
Known tools and local protocols are suitable for registration at startup. Authorization, page environment, current tenant, and allowed knowledge change per request and should be projected into the visible set during this round's assembly. Model visibility limits do not replace execution-time authorization.
|
|
49
|
+
|
|
50
|
+
When new documents must be available immediately: load new knowledge → validate catalog and task references → build a new version catalog → atomically switch the App's current reference. Existing requests keep their old catalog and snapshots; new requests use the new catalog. Do not mix body text, schema, sources, and revisions from before and after the reload within the same answer.
|
|
51
|
+
|
|
52
|
+
When program capabilities must genuinely be added dynamically, the App explicitly decides the code source, publication, and registration point, and reconstructs the corresponding registry. The library has no model-driven arbitrary code installation, automatic file discovery, or hot-unloading platform.
|
|
53
|
+
|
|
54
|
+
## Checks at startup and per request
|
|
55
|
+
|
|
56
|
+
| Timing | What to check |
|
|
57
|
+
| --- | --- |
|
|
58
|
+
| Startup/publication | Whether handlers exist; whether node and output references are valid; whether knowledge/sections exist; whether the Skill's tools are actually registered; whether parameter schema and parser agree |
|
|
59
|
+
| Request start | Identity, knowledge access scope, budget, signal, current catalog revision, and capability set |
|
|
60
|
+
| Before real execution | Current permissions, resource ownership, parameter value ranges, and necessary confirmation |
|
|
61
|
+
| Before delivery | Tool result contracts, sources and numbers, generated fields, program-bound fields, output completeness |
|
|
62
|
+
|
|
63
|
+
A Kit's validator can only validate the local structure it knows about. It does not know your tenants, storage paths, data permissions, or business facts; these checks cannot be omitted just because "a creator was used".
|
|
@@ -1,149 +1,365 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Scaffold or compare an App that uses `@jangts/agent-core`.
|
|
3
|
+
*
|
|
4
|
+
* Resolves the SDK the target project depends on, renders the selected template into a staging
|
|
5
|
+
* directory and only then renames it into place, so a failed or concurrent run never leaves a
|
|
6
|
+
* half-written app. `--check` compares the managed files against the recorded receipt instead of
|
|
7
|
+
* writing. Nothing here installs dependencies, calls a model or publishes content.
|
|
8
|
+
*
|
|
9
|
+
* Usage: see `usage` below; run directly or import `createApplication`.
|
|
10
|
+
*/
|
|
1
11
|
import { createHash } from 'node:crypto';
|
|
2
12
|
import { execFile } from 'node:child_process';
|
|
3
13
|
import { promisify } from 'node:util';
|
|
4
|
-
import {
|
|
14
|
+
import {
|
|
15
|
+
lstat,
|
|
16
|
+
mkdir,
|
|
17
|
+
mkdtemp,
|
|
18
|
+
readFile,
|
|
19
|
+
readdir,
|
|
20
|
+
rename,
|
|
21
|
+
rm,
|
|
22
|
+
rmdir,
|
|
23
|
+
writeFile,
|
|
24
|
+
} from 'node:fs/promises';
|
|
5
25
|
import { basename, dirname, isAbsolute, join, relative, resolve, sep } from 'node:path';
|
|
6
26
|
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
7
27
|
import { resolveSdkResources } from './resources.mjs';
|
|
8
28
|
|
|
9
|
-
const execute = promisify(execFile),
|
|
10
|
-
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
29
|
+
const execute = promisify(execFile),
|
|
30
|
+
receiptName = 'agent-core.template.json';
|
|
31
|
+
const usage =
|
|
32
|
+
'node create-app.mjs TARGET [--name PACKAGE_NAME] [--purpose TEXT] [--template node-ts] [--sdk-from PROJECT] [--source UTF8_FILE --id DOCUMENT_ID] [--write | --check]';
|
|
33
|
+
const hash = (value) => createHash('sha256').update(value).digest('hex');
|
|
34
|
+
const pathInside = (value) =>
|
|
35
|
+
typeof value === 'string' &&
|
|
36
|
+
!!value &&
|
|
37
|
+
!isAbsolute(value) &&
|
|
38
|
+
!value.includes('\\') &&
|
|
39
|
+
value.split('/').every((part) => !!part && !['.', '..'].includes(part));
|
|
40
|
+
async function exists(path) {
|
|
41
|
+
try {
|
|
42
|
+
return await lstat(path);
|
|
43
|
+
} catch (error) {
|
|
44
|
+
if (error.code !== 'ENOENT') throw error;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
15
47
|
function inputs(name, purpose) {
|
|
16
|
-
if (
|
|
17
|
-
|
|
48
|
+
if (
|
|
49
|
+
typeof name !== 'string' ||
|
|
50
|
+
name.length > 214 ||
|
|
51
|
+
!/^(?:@[a-z0-9][a-z0-9._-]*\/)?[a-z0-9][a-z0-9._-]*$/.test(name)
|
|
52
|
+
)
|
|
53
|
+
throw new TypeError('Use a lowercase npm package name');
|
|
54
|
+
if (typeof purpose !== 'string' || purpose.length > 800 || !purpose.trim())
|
|
55
|
+
throw new TypeError('Use a purpose of 1–800 characters');
|
|
18
56
|
return { name, purpose: purpose.trim() };
|
|
19
57
|
}
|
|
20
58
|
function parse(args, cwd) {
|
|
21
59
|
if (!args.length || args[0].startsWith('--')) throw new TypeError(usage);
|
|
22
|
-
const values = {},
|
|
60
|
+
const values = {},
|
|
61
|
+
switches = new Set(['--write', '--check']),
|
|
62
|
+
options = new Set(['--name', '--purpose', '--template', '--sdk-from', '--source', '--id']);
|
|
23
63
|
for (let index = 1; index < args.length; index++) {
|
|
24
64
|
const key = args[index];
|
|
25
65
|
if (Object.hasOwn(values, key)) throw new TypeError(`Duplicate option: ${key}`);
|
|
26
66
|
if (switches.has(key)) values[key] = true;
|
|
27
|
-
else if (options.has(key) && args[index + 1] !== undefined && !args[index + 1].startsWith('--'))
|
|
67
|
+
else if (options.has(key) && args[index + 1] !== undefined && !args[index + 1].startsWith('--'))
|
|
68
|
+
values[key] = args[++index];
|
|
28
69
|
else throw new TypeError(usage);
|
|
29
70
|
}
|
|
30
|
-
if (
|
|
31
|
-
|
|
71
|
+
if (
|
|
72
|
+
(values['--write'] && values['--check']) ||
|
|
73
|
+
!!values['--source'] !== !!values['--id'] ||
|
|
74
|
+
(values['--check'] &&
|
|
75
|
+
['--name', '--purpose', '--source', '--id'].some((key) => Object.hasOwn(values, key)))
|
|
76
|
+
)
|
|
77
|
+
throw new TypeError(usage);
|
|
32
78
|
return { target: resolve(cwd, args[0]), values };
|
|
33
79
|
}
|
|
34
80
|
async function emptyTarget(target) {
|
|
35
81
|
const item = await exists(target);
|
|
36
|
-
if (item && (!item.isDirectory() || item.isSymbolicLink() || (await readdir(target)).length))
|
|
82
|
+
if (item && (!item.isDirectory() || item.isSymbolicLink() || (await readdir(target)).length))
|
|
83
|
+
throw new Error(
|
|
84
|
+
'TARGET must be absent or an empty real directory; existing files are preserved',
|
|
85
|
+
);
|
|
37
86
|
}
|
|
38
87
|
async function templateResources(resources, id) {
|
|
39
88
|
const root = join(resources.sdk.root, 'development/skills/agent-core-app');
|
|
40
89
|
const catalog = JSON.parse(await readFile(join(root, 'templates/catalog.json'), 'utf8'));
|
|
41
|
-
if (catalog.schemaVersion !== 1 || !Array.isArray(catalog.templates))
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
90
|
+
if (catalog.schemaVersion !== 1 || !Array.isArray(catalog.templates))
|
|
91
|
+
throw new Error('Unsupported template catalog');
|
|
92
|
+
const template = catalog.templates.find((item) => item.id === id);
|
|
93
|
+
if (
|
|
94
|
+
!template ||
|
|
95
|
+
typeof template.revision !== 'string' ||
|
|
96
|
+
!pathInside(template.directory) ||
|
|
97
|
+
!Array.isArray(template.files) ||
|
|
98
|
+
template.files.some(
|
|
99
|
+
(file) =>
|
|
100
|
+
!pathInside(file.source) ||
|
|
101
|
+
!pathInside(file.target) ||
|
|
102
|
+
!['template', 'skill'].includes(file.origin),
|
|
103
|
+
) ||
|
|
104
|
+
new Set(template.files.map((file) => file.target)).size !== template.files.length ||
|
|
105
|
+
template.files.some((file) => file.target === receiptName)
|
|
106
|
+
)
|
|
107
|
+
throw new Error('Invalid or unknown template');
|
|
46
108
|
return { root, template };
|
|
47
109
|
}
|
|
48
110
|
async function render(resources, definition, input) {
|
|
49
111
|
const manifest = JSON.parse(await readFile(join(resources.sdk.root, 'package.json'), 'utf8'));
|
|
50
|
-
if (
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
112
|
+
if (
|
|
113
|
+
manifest.name !== '@jangts/agent-core' ||
|
|
114
|
+
manifest.version !== resources.sdk.version ||
|
|
115
|
+
typeof manifest.devDependencies?.typescript !== 'string'
|
|
116
|
+
)
|
|
117
|
+
throw new Error('SDK manifest does not describe the selected template dependencies');
|
|
118
|
+
const configuration = {
|
|
119
|
+
name: input.name,
|
|
120
|
+
purpose: input.purpose,
|
|
121
|
+
maxCalls: 4,
|
|
122
|
+
maxRounds: 8,
|
|
123
|
+
callTimeoutMs: 30000,
|
|
124
|
+
maxInputChars: 48000,
|
|
125
|
+
maxOutputChars: 8000,
|
|
126
|
+
};
|
|
127
|
+
const substitutions = {
|
|
128
|
+
__APP_CONFIG__: JSON.stringify(configuration, null, 2),
|
|
129
|
+
__PACKAGE_NAME__: JSON.stringify(input.name),
|
|
130
|
+
__SDK_VERSION__: JSON.stringify(manifest.version),
|
|
131
|
+
__TYPESCRIPT_VERSION__: JSON.stringify(manifest.devDependencies.typescript),
|
|
132
|
+
};
|
|
133
|
+
return Promise.all(
|
|
134
|
+
definition.template.files.map(async (file) => {
|
|
135
|
+
const source =
|
|
136
|
+
file.origin === 'skill'
|
|
137
|
+
? join(definition.root, file.source)
|
|
138
|
+
: join(definition.root, 'templates', definition.template.directory, file.source);
|
|
139
|
+
const info = await lstat(source);
|
|
140
|
+
if (!info.isFile() || info.isSymbolicLink())
|
|
141
|
+
throw new Error('Template assets must be regular files');
|
|
142
|
+
let content = new TextDecoder('utf-8', { fatal: true }).decode(await readFile(source));
|
|
143
|
+
// One pass: user-provided purpose text cannot become another substitution instruction.
|
|
144
|
+
if (file.origin === 'template')
|
|
145
|
+
content = content.replace(
|
|
146
|
+
/__APP_CONFIG__|__PACKAGE_NAME__|__SDK_VERSION__|__TYPESCRIPT_VERSION__/g,
|
|
147
|
+
(token) => substitutions[token],
|
|
148
|
+
);
|
|
149
|
+
const bytes = Buffer.from(content);
|
|
150
|
+
return { path: file.target, bytes, sha256: hash(bytes) };
|
|
151
|
+
}),
|
|
152
|
+
);
|
|
63
153
|
}
|
|
64
154
|
async function compare(target, resources, definition) {
|
|
65
155
|
const directory = await lstat(target);
|
|
66
|
-
if (!directory.isDirectory() || directory.isSymbolicLink())
|
|
67
|
-
|
|
68
|
-
|
|
156
|
+
if (!directory.isDirectory() || directory.isSymbolicLink())
|
|
157
|
+
throw new Error('TARGET must be a real directory');
|
|
158
|
+
const receiptPath = join(target, receiptName),
|
|
159
|
+
info = await lstat(receiptPath);
|
|
160
|
+
if (!info.isFile() || info.isSymbolicLink())
|
|
161
|
+
throw new Error('Template receipt must be a regular file');
|
|
69
162
|
const receipt = JSON.parse(await readFile(receiptPath, 'utf8'));
|
|
70
|
-
if (
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
163
|
+
if (
|
|
164
|
+
receipt.schemaVersion !== 1 ||
|
|
165
|
+
receipt.template?.id !== definition.template.id ||
|
|
166
|
+
!Array.isArray(receipt.files) ||
|
|
167
|
+
receipt.files.some((file) => !pathInside(file.path) || !/^[a-f0-9]{64}$/.test(file.sha256)) ||
|
|
168
|
+
new Set(receipt.files.map((file) => file.path)).size !== receipt.files.length
|
|
169
|
+
)
|
|
170
|
+
throw new Error('Invalid template receipt');
|
|
171
|
+
const files = await render(
|
|
172
|
+
resources,
|
|
173
|
+
definition,
|
|
174
|
+
inputs(receipt.inputs?.name, receipt.inputs?.purpose),
|
|
175
|
+
);
|
|
176
|
+
const baseline = new Map(receipt.files.map((file) => [file.path, file.sha256])),
|
|
177
|
+
currentTemplate = new Map(files.map((file) => [file.path, file.sha256]));
|
|
75
178
|
const changes = [];
|
|
76
179
|
for (const path of [...new Set([...baseline.keys(), ...currentTemplate.keys()])].sort()) {
|
|
77
|
-
if (!currentTemplate.has(path)) {
|
|
180
|
+
if (!currentTemplate.has(path)) {
|
|
181
|
+
changes.push({
|
|
182
|
+
path,
|
|
183
|
+
state: 'not-in-current-template',
|
|
184
|
+
baselineSha256: baseline.get(path),
|
|
185
|
+
templateChanged: true,
|
|
186
|
+
});
|
|
187
|
+
continue;
|
|
188
|
+
}
|
|
78
189
|
// Reject symlinks at every managed path component, without reading their destinations.
|
|
79
190
|
let blocked = false;
|
|
80
191
|
for (let index = 1; index <= path.split('/').length; index++) {
|
|
81
192
|
const part = await exists(join(target, ...path.split('/').slice(0, index)));
|
|
82
|
-
if (part?.isSymbolicLink()) {
|
|
193
|
+
if (part?.isSymbolicLink()) {
|
|
194
|
+
blocked = true;
|
|
195
|
+
break;
|
|
196
|
+
}
|
|
83
197
|
}
|
|
84
198
|
const item = blocked ? undefined : await exists(join(target, path));
|
|
85
199
|
const actual = item?.isFile() ? hash(await readFile(join(target, path))) : undefined;
|
|
86
|
-
changes.push({
|
|
87
|
-
|
|
200
|
+
changes.push({
|
|
201
|
+
path,
|
|
202
|
+
state: blocked
|
|
203
|
+
? 'symlink'
|
|
204
|
+
: actual === undefined
|
|
205
|
+
? 'missing'
|
|
206
|
+
: actual === baseline.get(path)
|
|
207
|
+
? 'unchanged'
|
|
208
|
+
: 'modified',
|
|
209
|
+
baselineSha256: baseline.get(path),
|
|
210
|
+
currentSha256: actual,
|
|
211
|
+
templateSha256: currentTemplate.get(path),
|
|
212
|
+
templateChanged: currentTemplate.get(path) !== baseline.get(path),
|
|
213
|
+
});
|
|
88
214
|
}
|
|
89
|
-
return {
|
|
215
|
+
return {
|
|
216
|
+
status: 'checked',
|
|
217
|
+
target,
|
|
218
|
+
installed: { template: receipt.template, sdk: receipt.sdk },
|
|
219
|
+
available: {
|
|
220
|
+
template: { id: definition.template.id, revision: definition.template.revision },
|
|
221
|
+
sdk: { name: manifestName, version: resources.sdk.version },
|
|
222
|
+
},
|
|
223
|
+
files: changes,
|
|
224
|
+
changedFiles: [],
|
|
225
|
+
};
|
|
90
226
|
}
|
|
91
227
|
const manifestName = '@jangts/agent-core';
|
|
228
|
+
/**
|
|
229
|
+
* Create or check a generated application directory.
|
|
230
|
+
*
|
|
231
|
+
* @param args CLI arguments: `TARGET` plus optional flags described by `usage`.
|
|
232
|
+
* @param cwd Directory relative paths are resolved against; defaults to the process cwd.
|
|
233
|
+
* @returns A plan (`--write` omitted), a comparison (`--check`) or the creation result.
|
|
234
|
+
* @throws {TypeError} When arguments, names, the target or the source file are invalid.
|
|
235
|
+
* @throws {Error} When the template, receipt or SDK manifest is unsupported or inconsistent.
|
|
236
|
+
*/
|
|
92
237
|
export async function createApplication(args, cwd = process.cwd()) {
|
|
93
238
|
const { target, values } = parse(args, cwd);
|
|
94
|
-
if (basename(target) === '.local')
|
|
239
|
+
if (basename(target) === '.local')
|
|
240
|
+
throw new TypeError(
|
|
241
|
+
'Choose an application directory outside the temporary .local directory itself',
|
|
242
|
+
);
|
|
95
243
|
const resources = await resolveSdkResources(resolve(cwd, values['--sdk-from'] ?? '.'));
|
|
96
244
|
const definition = await templateResources(resources, values['--template'] ?? 'node-ts');
|
|
97
245
|
if (values['--check']) return compare(target, resources, definition);
|
|
98
246
|
await emptyTarget(target);
|
|
99
|
-
const defaultName =
|
|
100
|
-
|
|
247
|
+
const defaultName =
|
|
248
|
+
basename(target)
|
|
249
|
+
.toLowerCase()
|
|
250
|
+
.replace(/[^a-z0-9._-]+/g, '-')
|
|
251
|
+
.replace(/^[._-]+|[._-]+$/g, '') || 'agent-app';
|
|
252
|
+
const input = inputs(
|
|
253
|
+
values['--name'] ?? defaultName,
|
|
254
|
+
values['--purpose'] ?? '依据当前问题和获准读取的资料提供帮助。',
|
|
255
|
+
);
|
|
101
256
|
const files = await render(resources, definition, input);
|
|
102
257
|
let source;
|
|
103
258
|
if (values['--source']) {
|
|
104
259
|
const path = resolve(cwd, values['--source']);
|
|
105
|
-
const info = await lstat(path);
|
|
106
|
-
|
|
260
|
+
const info = await lstat(path);
|
|
261
|
+
if (!info.isFile() || info.isSymbolicLink() || info.size > 32000)
|
|
262
|
+
throw new TypeError('Source must be a regular UTF-8 file within 32000 bytes');
|
|
263
|
+
const library = await import(
|
|
264
|
+
pathToFileURL(join(dirname(resources.knowledgeLoader), 'source.mjs'))
|
|
265
|
+
);
|
|
107
266
|
source = await library.readSuppliedSource(path, values['--id'], 32000);
|
|
108
267
|
const knowledge = await import(pathToFileURL(resources.knowledgeLoader));
|
|
109
|
-
const policy = JSON.parse(
|
|
268
|
+
const policy = JSON.parse(
|
|
269
|
+
files.find((file) => file.path === 'knowledge/knowledge.config.json').bytes.toString('utf8'),
|
|
270
|
+
);
|
|
110
271
|
knowledge.compileApplicationKnowledge([source.document], policy);
|
|
111
272
|
}
|
|
112
|
-
const receipt = {
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
273
|
+
const receipt = {
|
|
274
|
+
schemaVersion: 1,
|
|
275
|
+
template: { id: definition.template.id, revision: definition.template.revision },
|
|
276
|
+
sdk: { name: manifestName, version: resources.sdk.version },
|
|
277
|
+
inputs: input,
|
|
278
|
+
files: files.map(({ path, sha256 }) => ({ path, sha256 })),
|
|
279
|
+
};
|
|
280
|
+
const plan = {
|
|
281
|
+
status: 'planned',
|
|
282
|
+
target,
|
|
283
|
+
...receipt,
|
|
284
|
+
files: [...receipt.files, { path: receiptName }],
|
|
285
|
+
source: source
|
|
286
|
+
? {
|
|
287
|
+
documentId: values['--id'],
|
|
288
|
+
originalName: source.name,
|
|
289
|
+
sha256: source.digest,
|
|
290
|
+
status: 'candidate-only',
|
|
291
|
+
}
|
|
292
|
+
: null,
|
|
293
|
+
changedFiles: [],
|
|
294
|
+
installedDependencies: false,
|
|
295
|
+
modelCalled: false,
|
|
296
|
+
published: false,
|
|
297
|
+
};
|
|
118
298
|
if (!values['--write']) return plan;
|
|
119
|
-
const parent = dirname(target),
|
|
299
|
+
const parent = dirname(target),
|
|
300
|
+
temporary = join(parent, '.local');
|
|
120
301
|
await mkdir(parent, { recursive: true });
|
|
121
|
-
let madeTemporary = false,
|
|
302
|
+
let madeTemporary = false,
|
|
303
|
+
staging;
|
|
122
304
|
try {
|
|
123
|
-
try {
|
|
124
|
-
|
|
305
|
+
try {
|
|
306
|
+
await mkdir(temporary);
|
|
307
|
+
madeTemporary = true;
|
|
308
|
+
} catch (error) {
|
|
309
|
+
if (error.code !== 'EEXIST') throw error;
|
|
310
|
+
}
|
|
311
|
+
const info = await lstat(temporary);
|
|
312
|
+
if (!info.isDirectory() || info.isSymbolicLink())
|
|
313
|
+
throw new Error('Temporary directory must be a real directory');
|
|
125
314
|
staging = await mkdtemp(join(temporary, 'agent-core-create-'));
|
|
126
|
-
for (const file of files) {
|
|
315
|
+
for (const file of files) {
|
|
316
|
+
await mkdir(dirname(join(staging, file.path)), { recursive: true });
|
|
317
|
+
await writeFile(join(staging, file.path), file.bytes, { flag: 'wx' });
|
|
318
|
+
}
|
|
127
319
|
let candidate;
|
|
128
320
|
if (source) {
|
|
129
321
|
const snapshot = join(staging, '.local/initial-source', source.name);
|
|
130
|
-
await mkdir(dirname(snapshot), { recursive: true });
|
|
131
|
-
|
|
322
|
+
await mkdir(dirname(snapshot), { recursive: true });
|
|
323
|
+
await writeFile(snapshot, source.bytes, { flag: 'wx' });
|
|
324
|
+
const output = await execute(process.execPath, [
|
|
325
|
+
resources.tools['prepare-source'],
|
|
326
|
+
join(staging, 'knowledge'),
|
|
327
|
+
'--source',
|
|
328
|
+
snapshot,
|
|
329
|
+
'--id',
|
|
330
|
+
values['--id'],
|
|
331
|
+
]);
|
|
132
332
|
candidate = relative(staging, JSON.parse(output.stdout).candidate);
|
|
133
|
-
if (!pathInside(candidate.split(sep).join('/')))
|
|
333
|
+
if (!pathInside(candidate.split(sep).join('/')))
|
|
334
|
+
throw new Error('Candidate escaped the generated project');
|
|
134
335
|
await rm(join(staging, '.local/initial-source'), { recursive: true });
|
|
135
336
|
await rmdir(join(staging, '.local'));
|
|
136
337
|
}
|
|
137
|
-
await writeFile(
|
|
338
|
+
await writeFile(
|
|
339
|
+
join(staging, receiptName),
|
|
340
|
+
JSON.stringify({ ...receipt, createdAtMs: Date.now() }, null, 2) + '\n',
|
|
341
|
+
{ flag: 'wx' },
|
|
342
|
+
);
|
|
138
343
|
// Recheck before the atomic directory rename; a concurrent writer's non-empty target is preserved.
|
|
139
|
-
await emptyTarget(target);
|
|
140
|
-
|
|
344
|
+
await emptyTarget(target);
|
|
345
|
+
await rename(staging, target);
|
|
346
|
+
staging = undefined;
|
|
347
|
+
return {
|
|
348
|
+
...plan,
|
|
349
|
+
status: 'created',
|
|
350
|
+
changedFiles: [...files.map((file) => file.path), receiptName],
|
|
351
|
+
...(candidate ? { candidate: join(target, candidate) } : {}),
|
|
352
|
+
};
|
|
141
353
|
} finally {
|
|
142
354
|
if (staging) await rm(staging, { recursive: true });
|
|
143
355
|
if (madeTemporary) await rmdir(temporary).catch(() => {});
|
|
144
356
|
}
|
|
145
357
|
}
|
|
146
358
|
if (process.argv[1] && resolve(process.argv[1]) === fileURLToPath(import.meta.url)) {
|
|
147
|
-
try {
|
|
148
|
-
|
|
359
|
+
try {
|
|
360
|
+
console.log(JSON.stringify(await createApplication(process.argv.slice(2)), null, 2));
|
|
361
|
+
} catch (error) {
|
|
362
|
+
console.error(error instanceof Error ? error.message : String(error));
|
|
363
|
+
process.exitCode = 1;
|
|
364
|
+
}
|
|
149
365
|
}
|