@jangts/agent-core 0.3.6 → 0.5.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 +20 -0
- package/README.md +5 -5
- package/development/docs/README.en.md +2 -2
- package/development/docs/acceptance.en.md +2 -2
- package/development/docs/agent-development.en.md +1 -1
- package/development/docs/api/README.en.md +4 -2
- package/development/docs/api/README.md +2 -0
- package/development/docs/api/configuration-in-workflow.en.md +403 -0
- package/development/docs/api/configuration-in-workflow.md +403 -0
- package/development/docs/api/core.en.md +7 -7
- package/development/docs/api/core.md +6 -6
- package/development/docs/api/decorators.en.md +20 -0
- package/development/docs/api/decorators.md +20 -0
- package/development/docs/api/examples.en.md +1 -1
- package/development/docs/api/examples.md +1 -1
- package/development/docs/api/kits.en.md +22 -4
- package/development/docs/api/kits.md +22 -4
- package/development/docs/api/knowledge-answering.en.md +4 -1
- package/development/docs/api/knowledge-answering.md +4 -1
- package/development/docs/api/mock.en.md +2 -0
- package/development/docs/api/mock.md +2 -0
- package/development/docs/api/reference.en.md +508 -410
- package/development/docs/api/reference.md +508 -410
- package/development/docs/api/support.en.md +55 -9
- package/development/docs/api/support.md +53 -7
- package/development/docs/api/types.en.md +35 -1
- package/development/docs/api/types.md +43 -0
- package/development/docs/basic-usage.en.md +1 -1
- package/development/docs/basic-usage.md +1 -1
- package/development/docs/create-app.en.md +1 -1
- package/development/docs/examples/registration/associated.mjs +8 -0
- package/development/docs/examples/registration/independent.mjs +20 -0
- package/development/docs/examples/registration/protocol.mjs +48 -0
- package/development/docs/examples/registration/run.mjs +47 -0
- package/development/docs/examples/registration/tools.mjs +75 -0
- package/development/docs/examples/registration/workflow.mjs +109 -0
- package/development/docs/flows/knowledge-maintenance.en.md +1 -1
- package/development/docs/materials.en.md +1 -1
- package/development/docs/mechanisms.en.md +2 -2
- package/development/docs/mechanisms.md +1 -1
- package/development/docs/operations.en.md +1 -1
- package/development/docs/records.en.md +1 -1
- package/development/docs/registration.en.md +4 -4
- package/development/docs/registration.md +2 -2
- package/development/skills/agent-core-app/SKILL.md +4 -4
- package/development/skills/agent-core-app/templates/node-ts/README.md.tpl +1 -1
- package/development/skills/agent-core-app/templates/node-ts/src/catalog.ts.tpl +2 -2
- package/development/skills/agent-core-app/templates/node-ts/test/app.test.mjs.tpl +1 -1
- package/dist/cjs/capabilities/index.js +5 -12
- package/dist/cjs/capabilities/model.js +56 -12
- package/dist/cjs/capabilities/tool-conditions.js +65 -0
- package/dist/cjs/capabilities/tool-runtime.js +10 -3
- package/dist/cjs/context/audit.js +5 -8
- package/dist/cjs/context/index.js +3 -4
- package/dist/cjs/index.js +21 -17
- package/dist/cjs/kits/answering/tasks.js +5 -5
- package/dist/cjs/kits/domains/catalog.js +113 -0
- package/dist/cjs/kits/domains/index.js +20 -0
- package/dist/cjs/kits/{intents → domains}/registry.js +77 -31
- package/dist/cjs/kits/{intents → domains}/scopes.js +21 -21
- package/dist/cjs/kits/index.js +14 -13
- package/dist/cjs/kits/presentation/formats.js +110 -0
- package/dist/cjs/kits/presentation/index.js +10 -5
- package/dist/cjs/kits/reflection.js +2 -2
- package/dist/cjs/kits/text-blocks.js +101 -0
- package/dist/cjs/kits/tools.js +246 -158
- package/dist/cjs/model/index.js +2 -6
- package/dist/cjs/model/interactions/calls.js +61 -0
- package/dist/cjs/model/interactions/json-object.js +11 -11
- package/dist/cjs/model/interactions/native-functions.js +17 -23
- package/dist/cjs/model/message-diagnostics.js +13 -3
- package/dist/cjs/model/options.js +2 -0
- package/dist/cjs/model/preparation.js +39 -6
- package/dist/cjs/model/runner.js +14 -0
- package/dist/cjs/model/selection-transport.js +4 -4
- package/dist/cjs/model/token-budget.js +3 -0
- package/dist/cjs/model/transports.js +3 -2
- package/dist/cjs/structs/index.js +7 -6
- package/dist/cjs/structs/kits/presentation/formats.js +2 -0
- package/dist/cjs/structs/kits/text-blocks.js +11 -0
- package/dist/cjs/structs/model/session.js +11 -0
- package/dist/cjs/structs/support/associations.js +2 -0
- package/dist/cjs/support/associations.js +79 -0
- package/dist/cjs/support/context/snapshot.js +11 -1
- package/dist/cjs/support/decorators/index.js +45 -3
- package/dist/cjs/support/index.js +1 -0
- package/dist/cjs/support/model/capabilities.js +35 -5
- package/dist/cjs/support/model/chat-completions.js +11 -2
- package/dist/cjs/support/model/completion/calls.js +10 -56
- package/dist/cjs/support/model/preview-rules.js +11 -11
- package/dist/cjs/support/model/reply-preview.js +3 -3
- package/dist/cjs/support/model/session.js +152 -0
- package/dist/cjs/support/model/stage-transport.js +8 -8
- package/dist/cjs/support/model/transports.js +5 -2
- package/dist/cjs/support/tools.js +42 -17
- package/dist/esm/capabilities/index.d.ts +5 -10
- package/dist/esm/capabilities/index.js +5 -9
- package/dist/esm/capabilities/model.d.ts +17 -13
- package/dist/esm/capabilities/model.js +54 -10
- package/dist/esm/capabilities/tool-conditions.d.ts +9 -0
- package/dist/esm/capabilities/tool-conditions.js +59 -0
- package/dist/esm/capabilities/tool-runtime.js +10 -3
- package/dist/esm/capabilities/tools.d.ts +3 -3
- package/dist/esm/context/audit.js +5 -8
- package/dist/esm/context/index.d.ts +3 -4
- package/dist/esm/context/index.js +3 -4
- package/dist/esm/index.d.ts +19 -13
- package/dist/esm/index.js +18 -15
- package/dist/esm/kits/answering/tasks.d.ts +6 -6
- package/dist/esm/kits/answering/tasks.js +5 -5
- package/dist/esm/kits/domains/catalog.d.ts +42 -0
- package/dist/esm/kits/domains/catalog.js +110 -0
- package/dist/esm/kits/domains/index.d.ts +4 -0
- package/dist/esm/kits/domains/index.js +4 -0
- package/dist/esm/kits/domains/registry.d.ts +100 -0
- package/dist/esm/kits/{intents → domains}/registry.js +77 -31
- package/dist/esm/kits/{intents → domains}/scopes.d.ts +18 -18
- package/dist/esm/kits/{intents → domains}/scopes.js +21 -21
- package/dist/esm/kits/index.d.ts +6 -5
- package/dist/esm/kits/index.js +6 -5
- package/dist/esm/kits/presentation/formats.d.ts +42 -0
- package/dist/esm/kits/presentation/formats.js +105 -0
- package/dist/esm/kits/presentation/index.d.ts +14 -5
- package/dist/esm/kits/presentation/index.js +10 -5
- package/dist/esm/kits/reflection.js +3 -3
- package/dist/esm/kits/text-blocks.d.ts +24 -0
- package/dist/esm/kits/text-blocks.js +97 -0
- package/dist/esm/kits/tools.d.ts +69 -52
- package/dist/esm/kits/tools.js +246 -158
- package/dist/esm/model/index.d.ts +2 -6
- package/dist/esm/model/index.js +2 -6
- package/dist/esm/model/interactions/calls.d.ts +40 -0
- package/dist/esm/model/interactions/calls.js +58 -0
- package/dist/esm/model/interactions/json-object.js +11 -11
- package/dist/esm/model/interactions/native-functions.js +17 -23
- package/dist/esm/model/message-diagnostics.d.ts +6 -5
- package/dist/esm/model/message-diagnostics.js +13 -3
- package/dist/esm/model/options.js +2 -0
- package/dist/esm/model/preparation.js +39 -6
- package/dist/esm/model/runner.js +14 -0
- package/dist/esm/model/selection-transport.js +4 -4
- package/dist/esm/model/token-budget.js +3 -0
- package/dist/esm/model/transports.d.ts +2 -1
- package/dist/esm/model/transports.js +3 -2
- package/dist/esm/structs/capabilities/invocation.d.ts +1 -1
- package/dist/esm/structs/capabilities/model.d.ts +42 -11
- package/dist/esm/structs/capabilities/tools.d.ts +9 -4
- package/dist/esm/structs/common.d.ts +1 -1
- package/dist/esm/structs/index.d.ts +7 -6
- package/dist/esm/structs/index.js +7 -6
- package/dist/esm/structs/kits/answering/tasks.d.ts +2 -2
- package/dist/esm/structs/kits/{intents → domains}/catalog.d.ts +20 -20
- package/dist/esm/structs/kits/{intents → domains}/registry.d.ts +24 -21
- package/dist/esm/structs/kits/{intents → domains}/scopes.d.ts +9 -9
- package/dist/esm/structs/kits/presentation/formats.d.ts +42 -0
- package/dist/esm/structs/kits/presentation/formats.js +1 -0
- package/dist/esm/structs/kits/text-blocks.d.ts +25 -0
- package/dist/esm/structs/kits/text-blocks.js +10 -0
- package/dist/esm/structs/kits/tools.d.ts +82 -83
- package/dist/esm/structs/model/interactions.d.ts +18 -11
- package/dist/esm/structs/model/messages.d.ts +34 -2
- package/dist/esm/structs/model/runtime.d.ts +7 -0
- package/dist/esm/structs/model/session.d.ts +29 -0
- package/dist/esm/structs/model/session.js +10 -0
- package/dist/esm/structs/support/associations.d.ts +22 -0
- package/dist/esm/structs/support/associations.js +1 -0
- package/dist/esm/structs/support/model/interactions.d.ts +2 -2
- package/dist/esm/structs/support/model/messages.d.ts +6 -13
- package/dist/esm/structs/support/tools.d.ts +23 -23
- package/dist/esm/support/associations.d.ts +26 -0
- package/dist/esm/support/associations.js +76 -0
- package/dist/esm/support/context/snapshot.js +11 -1
- package/dist/esm/support/decorators/index.d.ts +13 -2
- package/dist/esm/support/decorators/index.js +40 -3
- package/dist/esm/support/decorators/pool.d.ts +6 -5
- package/dist/esm/support/decorators/types.d.ts +3 -1
- package/dist/esm/support/index.d.ts +1 -0
- package/dist/esm/support/index.js +1 -0
- package/dist/esm/support/model/capabilities.d.ts +8 -3
- package/dist/esm/support/model/capabilities.js +35 -5
- package/dist/esm/support/model/chat-completions.js +11 -2
- package/dist/esm/support/model/completion/calls.d.ts +6 -34
- package/dist/esm/support/model/completion/calls.js +8 -55
- package/dist/esm/support/model/index.d.ts +1 -1
- package/dist/esm/support/model/preview-rules.d.ts +13 -8
- package/dist/esm/support/model/preview-rules.js +11 -11
- package/dist/esm/support/model/reply-preview.d.ts +2 -2
- package/dist/esm/support/model/reply-preview.js +3 -3
- package/dist/esm/support/model/session.d.ts +61 -0
- package/dist/esm/support/model/session.js +148 -0
- package/dist/esm/support/model/stage-transport.d.ts +1 -1
- package/dist/esm/support/model/stage-transport.js +9 -9
- package/dist/esm/support/model/transports.d.ts +2 -0
- package/dist/esm/support/model/transports.js +2 -1
- package/dist/esm/support/tools.d.ts +11 -3
- package/dist/esm/support/tools.js +43 -18
- package/dist/esm/utils/catalog.d.ts +1 -1
- package/package.json +20 -6
- package/dist/cjs/execution/index.js +0 -30
- package/dist/cjs/kits/intents/catalog.js +0 -82
- package/dist/cjs/kits/intents/index.js +0 -35
- package/dist/esm/execution/index.d.ts +0 -11
- package/dist/esm/execution/index.js +0 -11
- package/dist/esm/kits/intents/catalog.d.ts +0 -39
- package/dist/esm/kits/intents/catalog.js +0 -79
- package/dist/esm/kits/intents/index.d.ts +0 -22
- package/dist/esm/kits/intents/index.js +0 -18
- package/dist/esm/kits/intents/registry.d.ts +0 -88
- /package/dist/cjs/structs/kits/{intents → domains}/catalog.js +0 -0
- /package/dist/cjs/structs/kits/{intents → domains}/registry.js +0 -0
- /package/dist/cjs/structs/kits/{intents → domains}/scopes.js +0 -0
- /package/dist/esm/structs/kits/{intents → domains}/catalog.js +0 -0
- /package/dist/esm/structs/kits/{intents → domains}/registry.js +0 -0
- /package/dist/esm/structs/kits/{intents → domains}/scopes.js +0 -0
package/dist/cjs/kits/index.js
CHANGED
|
@@ -14,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.reciprocalRankFusion = exports.VectorSearch = exports.ModelCalls = exports.TextSearch = exports.TextSkills = exports.Candidates = exports.Policies = exports.Evidence = exports.Retrieval = exports.Aggregation = exports.Projection = exports.Delivery = exports.Normalization = exports.Presentation = exports.Answering = exports.Knowledge = exports.Tools = exports.
|
|
17
|
+
exports.reciprocalRankFusion = exports.VectorSearch = exports.ModelCalls = exports.TextBlocks = exports.TextSearch = exports.TextSkills = exports.Candidates = exports.Policies = exports.Evidence = exports.Retrieval = exports.Aggregation = exports.Projection = exports.Delivery = exports.Normalization = exports.Presentation = exports.Answering = exports.Knowledge = exports.Tools = exports.Interaction = void 0;
|
|
18
18
|
/**
|
|
19
19
|
* Explicit bulk Kit entry.
|
|
20
20
|
*
|
|
@@ -22,23 +22,22 @@ exports.reciprocalRankFusion = exports.VectorSearch = exports.ModelCalls = expor
|
|
|
22
22
|
* path; this file only exists for callers that prefer one import for the whole set. Core
|
|
23
23
|
* never imports from this directory, so nothing here becomes a runtime requirement.
|
|
24
24
|
*
|
|
25
|
-
* Exports: the Kit namespaces (`Interaction`, `
|
|
25
|
+
* Exports: the Kit namespaces (`Interaction`, `Tools`, `Knowledge`, `Answering`,
|
|
26
26
|
* `Presentation`, `Normalization`, `Delivery`, `Projection`, `Aggregation`, `Retrieval`,
|
|
27
|
-
* `Evidence`, `Policies`, `Candidates`, `TextSkills`, `TextSearch`, `
|
|
28
|
-
* `VectorSearch`) plus every Kit type. Individual Kit paths stay the default.
|
|
27
|
+
* `Evidence`, `Policies`, `Candidates`, `TextSkills`, `TextSearch`, `TextBlocks`,
|
|
28
|
+
* `ModelCalls`, `VectorSearch`) plus every Kit type. Individual Kit paths stay the default.
|
|
29
29
|
*/
|
|
30
30
|
var index_js_1 = require("./interaction/index.js");
|
|
31
31
|
Object.defineProperty(exports, "Interaction", { enumerable: true, get: function () { return index_js_1.Interaction; } });
|
|
32
|
-
|
|
33
|
-
Object.defineProperty(exports, "Intents", { enumerable: true, get: function () { return index_js_2.Intents; } });
|
|
32
|
+
__exportStar(require("./domains/index.js"), exports);
|
|
34
33
|
var tools_js_1 = require("./tools.js");
|
|
35
34
|
Object.defineProperty(exports, "Tools", { enumerable: true, get: function () { return tools_js_1.Tools; } });
|
|
36
|
-
var
|
|
37
|
-
Object.defineProperty(exports, "Knowledge", { enumerable: true, get: function () { return
|
|
38
|
-
var
|
|
39
|
-
Object.defineProperty(exports, "Answering", { enumerable: true, get: function () { return
|
|
40
|
-
var
|
|
41
|
-
Object.defineProperty(exports, "Presentation", { enumerable: true, get: function () { return
|
|
35
|
+
var index_js_2 = require("./knowledge/index.js");
|
|
36
|
+
Object.defineProperty(exports, "Knowledge", { enumerable: true, get: function () { return index_js_2.Knowledge; } });
|
|
37
|
+
var index_js_3 = require("./answering/index.js");
|
|
38
|
+
Object.defineProperty(exports, "Answering", { enumerable: true, get: function () { return index_js_3.Answering; } });
|
|
39
|
+
var index_js_4 = require("./presentation/index.js");
|
|
40
|
+
Object.defineProperty(exports, "Presentation", { enumerable: true, get: function () { return index_js_4.Presentation; } });
|
|
42
41
|
var normalization_js_1 = require("./normalization.js");
|
|
43
42
|
Object.defineProperty(exports, "Normalization", { enumerable: true, get: function () { return normalization_js_1.Normalization; } });
|
|
44
43
|
var delivery_js_1 = require("./delivery.js");
|
|
@@ -60,9 +59,11 @@ Object.defineProperty(exports, "TextSkills", { enumerable: true, get: function (
|
|
|
60
59
|
var search_js_1 = require("./search.js");
|
|
61
60
|
Object.defineProperty(exports, "TextSearch", { enumerable: true, get: function () { return search_js_1.TextSearch; } });
|
|
62
61
|
__exportStar(require("./search.js"), exports);
|
|
62
|
+
var text_blocks_js_1 = require("./text-blocks.js");
|
|
63
|
+
Object.defineProperty(exports, "TextBlocks", { enumerable: true, get: function () { return text_blocks_js_1.TextBlocks; } });
|
|
64
|
+
__exportStar(require("./text-blocks.js"), exports);
|
|
63
65
|
// Types remain available with either individual or explicit bulk imports.
|
|
64
66
|
__exportStar(require("./interaction/index.js"), exports);
|
|
65
|
-
__exportStar(require("./intents/index.js"), exports);
|
|
66
67
|
__exportStar(require("./tools.js"), exports);
|
|
67
68
|
__exportStar(require("./knowledge/index.js"), exports);
|
|
68
69
|
__exportStar(require("./answering/index.js"), exports);
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.replyFormatChecks = void 0;
|
|
4
|
+
exports.mergeReplyBubbles = mergeReplyBubbles;
|
|
5
|
+
exports.defineReplyFormats = defineReplyFormats;
|
|
6
|
+
/**
|
|
7
|
+
* Presentation Kit: template-bound reply formats and their shared checks.
|
|
8
|
+
*
|
|
9
|
+
* Place in the package: part of the `presentation` Kit. A format is declared only where the App
|
|
10
|
+
* owns a template for the final reply; `resolve` returns `undefined` for every other reply, so the
|
|
11
|
+
* caller has no output-format requirement and does not re-ask the model. Apps keep their own copy,
|
|
12
|
+
* limits and checks; this module only compiles the declarations and evaluates failures.
|
|
13
|
+
*
|
|
14
|
+
* Exports: `defineReplyFormats`, `replyFormatChecks`, `mergeReplyBubbles`, and their types.
|
|
15
|
+
*/
|
|
16
|
+
const rules_js_1 = require("../../utils/rules.js");
|
|
17
|
+
const validId = (id) => typeof id === 'string' && /^[a-z][a-z0-9-]*$/.test(id);
|
|
18
|
+
/**
|
|
19
|
+
* Checks shared by text replies. Limits stay with the App template; only the comparison lives here.
|
|
20
|
+
*/
|
|
21
|
+
exports.replyFormatChecks = Object.freeze({
|
|
22
|
+
/**
|
|
23
|
+
* Every bubble is non-empty and the total (primary text included) stays within the limit.
|
|
24
|
+
*
|
|
25
|
+
* @param totalLimit - Maximum bubble count including the primary text.
|
|
26
|
+
* @returns The reusable `bubbles` check.
|
|
27
|
+
*/
|
|
28
|
+
bubbles(totalLimit) {
|
|
29
|
+
(0, rules_js_1.breakWhile)(!Number.isSafeInteger(totalLimit) || totalLimit < 1, 'Bubble limit must be a positive integer');
|
|
30
|
+
return Object.freeze({
|
|
31
|
+
id: 'bubbles',
|
|
32
|
+
description: `回复气泡总数不超过 ${totalLimit} 条且每条非空。`,
|
|
33
|
+
accepts: (bubbles) => bubbles.length >= 1 &&
|
|
34
|
+
bubbles.length <= totalLimit &&
|
|
35
|
+
bubbles.every((text) => typeof text === 'string' && !!text.trim()),
|
|
36
|
+
});
|
|
37
|
+
},
|
|
38
|
+
/**
|
|
39
|
+
* The joined reply stays within the app's text budget.
|
|
40
|
+
*
|
|
41
|
+
* @param maxChars - Maximum total characters across bubbles.
|
|
42
|
+
* @returns The reusable `text-budget` check.
|
|
43
|
+
*/
|
|
44
|
+
textBudget(maxChars) {
|
|
45
|
+
(0, rules_js_1.breakWhile)(!Number.isSafeInteger(maxChars) || maxChars < 1, 'Text budget must be a positive integer');
|
|
46
|
+
return Object.freeze({
|
|
47
|
+
id: 'text-budget',
|
|
48
|
+
description: `回复正文总长不超过 ${maxChars} 字符。`,
|
|
49
|
+
accepts: (bubbles) => bubbles.reduce((length, text) => length + (typeof text === 'string' ? text.length : 0), 0) <= maxChars,
|
|
50
|
+
});
|
|
51
|
+
},
|
|
52
|
+
});
|
|
53
|
+
/**
|
|
54
|
+
* Normalize a reply that has no declared format: drop blank bubbles and merge overflow into the
|
|
55
|
+
* last allowed one. Text content is preserved.
|
|
56
|
+
*
|
|
57
|
+
* @param bubbles - Primary text followed by follow-up bubbles.
|
|
58
|
+
* @param limit - Maximum number of bubbles to keep.
|
|
59
|
+
* @returns Non-empty bubbles within the limit.
|
|
60
|
+
*/
|
|
61
|
+
function mergeReplyBubbles(bubbles, limit) {
|
|
62
|
+
(0, rules_js_1.breakWhile)(!Number.isSafeInteger(limit) || limit < 1, 'Bubble limit must be a positive integer');
|
|
63
|
+
const kept = bubbles.map((text) => text.trim()).filter(Boolean);
|
|
64
|
+
// 超出部分按原顺序合并到最后一条允许的气泡,不改变正文内容。
|
|
65
|
+
if (kept.length > limit)
|
|
66
|
+
kept.push(kept.splice(limit - 1).join('\n\n'));
|
|
67
|
+
return kept;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Compile reply formats so that checks run only for templates the current turn uses.
|
|
71
|
+
*
|
|
72
|
+
* @param options - Declared formats and the checks their ids refer to.
|
|
73
|
+
* @returns A frozen catalog with `resolve(context)`.
|
|
74
|
+
* @throws TypeError For duplicate or invalid ids, a format without checks, an unknown check id,
|
|
75
|
+
* or a non-function `when`/`accepts`.
|
|
76
|
+
*/
|
|
77
|
+
function defineReplyFormats(options) {
|
|
78
|
+
const { formats, checks } = options;
|
|
79
|
+
(0, rules_js_1.breakWhile)(!formats?.length || !checks?.length, 'Reply formats require formats and checks');
|
|
80
|
+
const checkMap = new Map();
|
|
81
|
+
for (const check of checks) {
|
|
82
|
+
(0, rules_js_1.breakWhile)(!validId(check.id) || checkMap.has(check.id) || typeof check.accepts !== 'function', 'Invalid reply format check');
|
|
83
|
+
checkMap.set(check.id, Object.freeze({ ...check, accepts: check.accepts.bind(check) }));
|
|
84
|
+
}
|
|
85
|
+
const seen = new Set();
|
|
86
|
+
const compiled = formats.map((format) => {
|
|
87
|
+
(0, rules_js_1.breakWhile)(!validId(format.id) ||
|
|
88
|
+
seen.has(format.id) ||
|
|
89
|
+
typeof format.when !== 'function' ||
|
|
90
|
+
!format.checks?.length ||
|
|
91
|
+
format.checks.some((id) => !checkMap.has(id)), 'Invalid reply format');
|
|
92
|
+
seen.add(format.id);
|
|
93
|
+
const required = Object.freeze([...format.checks]);
|
|
94
|
+
return Object.freeze({
|
|
95
|
+
id: format.id,
|
|
96
|
+
description: format.description,
|
|
97
|
+
checks: required,
|
|
98
|
+
when: format.when,
|
|
99
|
+
inspect(bubbles) {
|
|
100
|
+
return required.map((id) => checkMap.get(id)).filter((check) => !check.accepts(bubbles));
|
|
101
|
+
},
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
return Object.freeze({
|
|
105
|
+
/** The template this turn uses, or `undefined` when it has no output-format requirement. */
|
|
106
|
+
resolve(context) {
|
|
107
|
+
return compiled.find((format) => format.when(context));
|
|
108
|
+
},
|
|
109
|
+
});
|
|
110
|
+
}
|
|
@@ -16,27 +16,32 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
exports.Presentation = void 0;
|
|
18
18
|
/**
|
|
19
|
-
* Presentation Kit entry: output contracts, text templates, semantic slots,
|
|
20
|
-
* reply/chunk event stream.
|
|
19
|
+
* Presentation Kit entry: output contracts, text templates, semantic slots, reply formats,
|
|
20
|
+
* variants and the reply/chunk event stream.
|
|
21
21
|
*
|
|
22
22
|
* Place in the package: an optional App-side library for shaping what the user finally sees.
|
|
23
23
|
* The App owns copy, styling and transport; this directory owns contract validation, template
|
|
24
|
-
* substitution, variant selection and the bubble/chunk protocol.
|
|
24
|
+
* substitution, format checks, variant selection and the bubble/chunk protocol.
|
|
25
25
|
*
|
|
26
|
-
* Exports: everything from `./outputs.js`, `./variants.js`, `./templates.js` and
|
|
27
|
-
* plus the `Presentation` namespace object.
|
|
26
|
+
* Exports: everything from `./outputs.js`, `./formats.js`, `./variants.js`, `./templates.js` and
|
|
27
|
+
* `./events.js`, plus the `Presentation` namespace object.
|
|
28
28
|
*/
|
|
29
29
|
__exportStar(require("./outputs.js"), exports);
|
|
30
|
+
__exportStar(require("./formats.js"), exports);
|
|
30
31
|
__exportStar(require("./variants.js"), exports);
|
|
31
32
|
__exportStar(require("./templates.js"), exports);
|
|
32
33
|
__exportStar(require("./events.js"), exports);
|
|
33
34
|
const outputs_js_1 = require("./outputs.js");
|
|
35
|
+
const formats_js_1 = require("./formats.js");
|
|
34
36
|
const templates_js_1 = require("./templates.js");
|
|
35
37
|
const variants_js_1 = require("./variants.js");
|
|
36
38
|
const events_js_1 = require("./events.js");
|
|
37
39
|
/** Namespace object for callers that prefer one import over named helpers. */
|
|
38
40
|
exports.Presentation = Object.freeze({
|
|
39
41
|
defineOutputCatalog: outputs_js_1.defineOutputCatalog,
|
|
42
|
+
defineReplyFormats: formats_js_1.defineReplyFormats,
|
|
43
|
+
replyFormatChecks: formats_js_1.replyFormatChecks,
|
|
44
|
+
mergeReplyBubbles: formats_js_1.mergeReplyBubbles,
|
|
40
45
|
defineTextTemplate: templates_js_1.defineTextTemplate,
|
|
41
46
|
defineSemanticSlots: templates_js_1.defineSemanticSlots,
|
|
42
47
|
selectVariant: variants_js_1.selectVariant,
|
|
@@ -229,7 +229,7 @@ function defineReflection(definition) {
|
|
|
229
229
|
...extraTools,
|
|
230
230
|
];
|
|
231
231
|
const catalog = (0, tools_js_1.defineToolCatalog)(toolDefinitions);
|
|
232
|
-
const
|
|
232
|
+
const modelTools = (0, capabilities_js_1.defineModelTools)([
|
|
233
233
|
...catalog.definitions.map((tool) => ({
|
|
234
234
|
id: tool.id,
|
|
235
235
|
description: tool.description,
|
|
@@ -248,7 +248,7 @@ function defineReflection(definition) {
|
|
|
248
248
|
]);
|
|
249
249
|
const transport = (0, selection_transport_js_1.createModelTransport)({
|
|
250
250
|
id: 'core:reflection',
|
|
251
|
-
|
|
251
|
+
tools: modelTools,
|
|
252
252
|
adapter: json_object_js_1.jsonObjectInteraction,
|
|
253
253
|
});
|
|
254
254
|
const child = model.createChild({
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TextBlocks = void 0;
|
|
4
|
+
exports.splitTextBlocks = splitTextBlocks;
|
|
5
|
+
/**
|
|
6
|
+
* Text Blocks Kit: structure-aware splitting for long plain text.
|
|
7
|
+
*
|
|
8
|
+
* Place in the package: an optional App-side helper used before a long document is paged
|
|
9
|
+
* into a model or indexed for retrieval. The Kit owns boundary selection, block numbering
|
|
10
|
+
* and exact reassembly; file reading, paging, search, storage and prompt wording stay with
|
|
11
|
+
* the App. No model call or Core dependency is involved.
|
|
12
|
+
*
|
|
13
|
+
* Exports: `splitTextBlocks`, `TextBlocks` and the block option/result types.
|
|
14
|
+
*/
|
|
15
|
+
const rules_js_1 = require("../utils/rules.js");
|
|
16
|
+
/**
|
|
17
|
+
* Whether one line starts a new structural section.
|
|
18
|
+
*
|
|
19
|
+
* @param line - A full line including its trailing newline.
|
|
20
|
+
* @returns `true` for Markdown headings and horizontal rules.
|
|
21
|
+
*/
|
|
22
|
+
function headingLine(line) {
|
|
23
|
+
return /^\s*#{1,6}\s/.test(line) || /^\s*(?:[-*_]{3,}|={3,})\s*$/.test(line);
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Split long plain text on structural boundaries.
|
|
27
|
+
*
|
|
28
|
+
* Headings and horizontal rules start a new block, blank lines end the current one, and all
|
|
29
|
+
* other lines break only when the target size would be exceeded. A single line longer than
|
|
30
|
+
* the target becomes its own block so that paging can cut it into fragments later without
|
|
31
|
+
* splitting the line into unrelated sections. Concatenating every block reproduces the input
|
|
32
|
+
* exactly: no truncation, padding or dropped whitespace.
|
|
33
|
+
*
|
|
34
|
+
* The input must be plain text; binaries and rich documents are read elsewhere.
|
|
35
|
+
*
|
|
36
|
+
* @param text - Decoded source text.
|
|
37
|
+
* @param options - Target block size in characters.
|
|
38
|
+
* @returns Blocks in source order, each with one-based `number` and source offsets. Empty
|
|
39
|
+
* text returns an empty list.
|
|
40
|
+
* @throws TypeError When the text is not a string or `targetChars` is not a positive integer.
|
|
41
|
+
*/
|
|
42
|
+
function splitTextBlocks(text, options) {
|
|
43
|
+
(0, rules_js_1.breakWhile)(typeof text !== 'string' ||
|
|
44
|
+
!options ||
|
|
45
|
+
!Number.isSafeInteger(options.targetChars) ||
|
|
46
|
+
options.targetChars < 1, 'Text block splitting requires text and a positive integer target size');
|
|
47
|
+
const targetChars = options.targetChars;
|
|
48
|
+
const blocks = [];
|
|
49
|
+
let buffer = '';
|
|
50
|
+
let bufferStart = 0;
|
|
51
|
+
let cursor = 0;
|
|
52
|
+
const flush = () => {
|
|
53
|
+
if (!buffer)
|
|
54
|
+
return;
|
|
55
|
+
const previous = blocks.at(-1);
|
|
56
|
+
if (!buffer.trim() && previous) {
|
|
57
|
+
// Whitespace-only blocks carry no section, so they stay attached to the previous block
|
|
58
|
+
// instead of becoming a block the reader has to page through.
|
|
59
|
+
blocks[blocks.length - 1] = {
|
|
60
|
+
...previous,
|
|
61
|
+
text: previous.text + buffer,
|
|
62
|
+
end: previous.end + buffer.length,
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
blocks.push({ number: blocks.length + 1, text: buffer, start: bufferStart, end: cursor });
|
|
67
|
+
}
|
|
68
|
+
buffer = '';
|
|
69
|
+
};
|
|
70
|
+
// Keeping a line's trailing newline makes every block reassemble into the original text,
|
|
71
|
+
// including CRLF input.
|
|
72
|
+
for (const line of text.match(/[^\n]*\n|[^\n]+$/g) ?? []) {
|
|
73
|
+
if (line.length > targetChars) {
|
|
74
|
+
flush();
|
|
75
|
+
blocks.push({
|
|
76
|
+
number: blocks.length + 1,
|
|
77
|
+
text: line,
|
|
78
|
+
start: cursor,
|
|
79
|
+
end: cursor + line.length,
|
|
80
|
+
});
|
|
81
|
+
cursor += line.length;
|
|
82
|
+
continue;
|
|
83
|
+
}
|
|
84
|
+
if (headingLine(line))
|
|
85
|
+
flush();
|
|
86
|
+
if (buffer.length + line.length > targetChars)
|
|
87
|
+
flush();
|
|
88
|
+
if (!buffer)
|
|
89
|
+
bufferStart = cursor;
|
|
90
|
+
buffer += line;
|
|
91
|
+
cursor += line.length;
|
|
92
|
+
if ((!line.trim() || headingLine(line)) && buffer.length >= targetChars / 2)
|
|
93
|
+
flush();
|
|
94
|
+
else if (buffer.length >= targetChars)
|
|
95
|
+
flush();
|
|
96
|
+
}
|
|
97
|
+
flush();
|
|
98
|
+
return blocks;
|
|
99
|
+
}
|
|
100
|
+
/** Namespace form of the Kit, for callers that prefer one aggregate entry. */
|
|
101
|
+
exports.TextBlocks = { split: splitTextBlocks };
|