dsh-agent-toolkit 0.2.3 → 0.2.4
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/lib/client.js +72 -72
- package/lib/index.js +64 -13
- package/lib/index.js.map +1 -1
- package/package.json +1 -1
package/lib/client.js
CHANGED
|
@@ -67,15 +67,15 @@ window.__ModuleLoader__.load({
|
|
|
67
67
|
document.head.appendChild(tag);
|
|
68
68
|
}
|
|
69
69
|
var delegate_card_module_css_default = {
|
|
70
|
-
"result": "_8wQUq_result",
|
|
71
|
-
"chip": "_8wQUq_chip",
|
|
72
|
-
"summary": "_8wQUq_summary",
|
|
73
|
-
"childLink": "_8wQUq_childLink",
|
|
74
70
|
"prompt": "_8wQUq_prompt",
|
|
75
71
|
"row": "_8wQUq_row",
|
|
72
|
+
"result": "_8wQUq_result",
|
|
76
73
|
"body": "_8wQUq_body",
|
|
74
|
+
"visuallyHidden": "_8wQUq_visuallyHidden",
|
|
75
|
+
"childLink": "_8wQUq_childLink",
|
|
76
|
+
"chip": "_8wQUq_chip",
|
|
77
77
|
"root": "_8wQUq_root",
|
|
78
|
-
"
|
|
78
|
+
"summary": "_8wQUq_summary"
|
|
79
79
|
};
|
|
80
80
|
//#endregion
|
|
81
81
|
//#region src/client/delegate/delegate-card.tsx
|
|
@@ -311,8 +311,8 @@ window.__ModuleLoader__.load({
|
|
|
311
311
|
document.head.appendChild(tag);
|
|
312
312
|
}
|
|
313
313
|
var entry_module_css_default$1 = {
|
|
314
|
-
"
|
|
315
|
-
"
|
|
314
|
+
"rail": "VJWWsa_rail",
|
|
315
|
+
"trigger": "VJWWsa_trigger"
|
|
316
316
|
};
|
|
317
317
|
//#endregion
|
|
318
318
|
//#region src/client/shared/entry.tsx
|
|
@@ -411,33 +411,33 @@ window.__ModuleLoader__.load({
|
|
|
411
411
|
document.head.appendChild(tag);
|
|
412
412
|
}
|
|
413
413
|
var agents_module_css_default = {
|
|
414
|
-
"
|
|
415
|
-
"builtinBadge": "KsfSLW_builtinBadge",
|
|
416
|
-
"actions": "KsfSLW_actions",
|
|
417
|
-
"field": "KsfSLW_field",
|
|
414
|
+
"readonlyId": "KsfSLW_readonlyId",
|
|
418
415
|
"listPane": "KsfSLW_listPane",
|
|
419
|
-
"
|
|
420
|
-
"
|
|
421
|
-
"toolGrid": "KsfSLW_toolGrid",
|
|
416
|
+
"agentRowActive": "KsfSLW_agentRowActive",
|
|
417
|
+
"agentDesc": "KsfSLW_agentDesc",
|
|
422
418
|
"split": "KsfSLW_split",
|
|
419
|
+
"toolGrid": "KsfSLW_toolGrid",
|
|
423
420
|
"block": "KsfSLW_block",
|
|
424
|
-
"
|
|
425
|
-
"
|
|
426
|
-
"
|
|
421
|
+
"toolCheck": "KsfSLW_toolCheck",
|
|
422
|
+
"blockTitle": "KsfSLW_blockTitle",
|
|
423
|
+
"hint": "KsfSLW_hint",
|
|
427
424
|
"dangerButton": "KsfSLW_dangerButton",
|
|
428
|
-
"textarea": "KsfSLW_textarea",
|
|
429
|
-
"toolGroupSet": "KsfSLW_toolGroupSet",
|
|
430
|
-
"editor": "KsfSLW_editor",
|
|
431
425
|
"input": "KsfSLW_input",
|
|
432
|
-
"
|
|
426
|
+
"textarea": "KsfSLW_textarea",
|
|
427
|
+
"editorPane": "KsfSLW_editorPane",
|
|
428
|
+
"field": "KsfSLW_field",
|
|
429
|
+
"dialog": "KsfSLW_dialog",
|
|
430
|
+
"error": "KsfSLW_error",
|
|
433
431
|
"agentRow": "KsfSLW_agentRow",
|
|
434
432
|
"agentName": "KsfSLW_agentName",
|
|
435
|
-
"
|
|
436
|
-
"
|
|
433
|
+
"editor": "KsfSLW_editor",
|
|
434
|
+
"select": "KsfSLW_select",
|
|
435
|
+
"actions": "KsfSLW_actions",
|
|
437
436
|
"createButton": "KsfSLW_createButton",
|
|
438
|
-
"
|
|
439
|
-
"
|
|
440
|
-
"
|
|
437
|
+
"toolMode": "KsfSLW_toolMode",
|
|
438
|
+
"builtinBadge": "KsfSLW_builtinBadge",
|
|
439
|
+
"toolGroupSet": "KsfSLW_toolGroupSet",
|
|
440
|
+
"toolGroupTitle": "KsfSLW_toolGroupTitle"
|
|
441
441
|
};
|
|
442
442
|
//#endregion
|
|
443
443
|
//#region src/client/agents/AgentEditor.tsx
|
|
@@ -951,24 +951,24 @@ window.__ModuleLoader__.load({
|
|
|
951
951
|
document.head.appendChild(tag);
|
|
952
952
|
}
|
|
953
953
|
var prompt_module_css_default = {
|
|
954
|
-
"
|
|
954
|
+
"editor": "VZk1fa_editor",
|
|
955
|
+
"error": "VZk1fa_error",
|
|
956
|
+
"editorPane": "VZk1fa_editorPane",
|
|
955
957
|
"tab": "VZk1fa_tab",
|
|
956
|
-
"textarea": "VZk1fa_textarea",
|
|
957
|
-
"hint": "VZk1fa_hint",
|
|
958
958
|
"layerOrder": "VZk1fa_layerOrder",
|
|
959
|
-
"
|
|
960
|
-
"tabs": "VZk1fa_tabs",
|
|
961
|
-
"actions": "VZk1fa_actions",
|
|
962
|
-
"tabActive": "VZk1fa_tabActive",
|
|
963
|
-
"listPane": "VZk1fa_listPane",
|
|
964
|
-
"layerRowActive": "VZk1fa_layerRowActive",
|
|
959
|
+
"field": "VZk1fa_field",
|
|
965
960
|
"dialog": "VZk1fa_dialog",
|
|
961
|
+
"listPane": "VZk1fa_listPane",
|
|
962
|
+
"hint": "VZk1fa_hint",
|
|
963
|
+
"tabs": "VZk1fa_tabs",
|
|
964
|
+
"layerRow": "VZk1fa_layerRow",
|
|
966
965
|
"split": "VZk1fa_split",
|
|
967
|
-
"
|
|
968
|
-
"editorPane": "VZk1fa_editorPane",
|
|
969
|
-
"error": "VZk1fa_error",
|
|
966
|
+
"tabActive": "VZk1fa_tabActive",
|
|
970
967
|
"layerName": "VZk1fa_layerName",
|
|
971
|
-
"
|
|
968
|
+
"textarea": "VZk1fa_textarea",
|
|
969
|
+
"actions": "VZk1fa_actions",
|
|
970
|
+
"layerRowActive": "VZk1fa_layerRowActive",
|
|
971
|
+
"readonlyTag": "VZk1fa_readonlyTag"
|
|
972
972
|
};
|
|
973
973
|
//#endregion
|
|
974
974
|
//#region src/client/prompt/PromptLayersModal.tsx
|
|
@@ -1310,8 +1310,8 @@ window.__ModuleLoader__.load({
|
|
|
1310
1310
|
document.head.appendChild(tag);
|
|
1311
1311
|
}
|
|
1312
1312
|
var entry_module_css_default = {
|
|
1313
|
-
"
|
|
1314
|
-
"
|
|
1313
|
+
"trigger": "QVHFVG_trigger",
|
|
1314
|
+
"rail": "QVHFVG_rail"
|
|
1315
1315
|
};
|
|
1316
1316
|
//#endregion
|
|
1317
1317
|
//#region ../usage/src/client/shared/entry.tsx
|
|
@@ -1452,13 +1452,13 @@ window.__ModuleLoader__.load({
|
|
|
1452
1452
|
document.head.appendChild(tag);
|
|
1453
1453
|
}
|
|
1454
1454
|
var chart_module_css_default = {
|
|
1455
|
-
"chartTheme": "_8LXSJW_chartTheme",
|
|
1456
1455
|
"swatchCached": "_8LXSJW_swatchCached",
|
|
1456
|
+
"legend": "_8LXSJW_legend",
|
|
1457
1457
|
"swatchFresh": "_8LXSJW_swatchFresh",
|
|
1458
1458
|
"tooltipTitle": "_8LXSJW_tooltipTitle",
|
|
1459
|
-
"legend": "_8LXSJW_legend",
|
|
1460
1459
|
"tooltip": "_8LXSJW_tooltip",
|
|
1461
|
-
"tooltipTotal": "_8LXSJW_tooltipTotal"
|
|
1460
|
+
"tooltipTotal": "_8LXSJW_tooltipTotal",
|
|
1461
|
+
"chartTheme": "_8LXSJW_chartTheme"
|
|
1462
1462
|
};
|
|
1463
1463
|
//#endregion
|
|
1464
1464
|
//#region \0dsh-css:D:\work\github\dsh\dsh-agent-toolkit\packages\usage\src\client\usage\ActivityHeatmap.module.css.mjs
|
|
@@ -1472,14 +1472,14 @@ window.__ModuleLoader__.load({
|
|
|
1472
1472
|
document.head.appendChild(tag);
|
|
1473
1473
|
}
|
|
1474
1474
|
var ActivityHeatmap_module_css_default = {
|
|
1475
|
-
"level0": "hjrYrq_level0",
|
|
1476
|
-
"months": "hjrYrq_months",
|
|
1477
|
-
"level3": "hjrYrq_level3",
|
|
1478
1475
|
"level2": "hjrYrq_level2",
|
|
1479
1476
|
"level4": "hjrYrq_level4",
|
|
1480
|
-
"
|
|
1477
|
+
"level0": "hjrYrq_level0",
|
|
1481
1478
|
"grid": "hjrYrq_grid",
|
|
1482
|
-
"
|
|
1479
|
+
"months": "hjrYrq_months",
|
|
1480
|
+
"week": "hjrYrq_week",
|
|
1481
|
+
"level3": "hjrYrq_level3",
|
|
1482
|
+
"level1": "hjrYrq_level1"
|
|
1483
1483
|
};
|
|
1484
1484
|
//#endregion
|
|
1485
1485
|
//#region ../usage/src/client/usage/ActivityHeatmap.tsx
|
|
@@ -52516,19 +52516,19 @@ ${te.current.stack}
|
|
|
52516
52516
|
document.head.appendChild(tag);
|
|
52517
52517
|
}
|
|
52518
52518
|
var UsageModal_module_css_default = {
|
|
52519
|
-
"
|
|
52519
|
+
"dialog": "MODeXa_dialog",
|
|
52520
52520
|
"dateLabel": "MODeXa_dateLabel",
|
|
52521
|
-
"
|
|
52522
|
-
"tab": "MODeXa_tab",
|
|
52523
|
-
"rowName": "MODeXa_rowName",
|
|
52521
|
+
"pagerButton": "MODeXa_pagerButton",
|
|
52524
52522
|
"compaction": "MODeXa_compaction",
|
|
52525
52523
|
"tabActive": "MODeXa_tabActive",
|
|
52524
|
+
"rowName": "MODeXa_rowName",
|
|
52526
52525
|
"sectionTitle": "MODeXa_sectionTitle",
|
|
52527
|
-
"rowCalls": "MODeXa_rowCalls",
|
|
52528
|
-
"dialog": "MODeXa_dialog",
|
|
52529
|
-
"pagerButton": "MODeXa_pagerButton",
|
|
52530
52526
|
"tabs": "MODeXa_tabs",
|
|
52531
|
-
"
|
|
52527
|
+
"row": "MODeXa_row",
|
|
52528
|
+
"total": "MODeXa_total",
|
|
52529
|
+
"rowCalls": "MODeXa_rowCalls",
|
|
52530
|
+
"pager": "MODeXa_pager",
|
|
52531
|
+
"tab": "MODeXa_tab"
|
|
52532
52532
|
};
|
|
52533
52533
|
//#endregion
|
|
52534
52534
|
//#region ../usage/src/client/usage/UsageModal.tsx
|
|
@@ -55153,29 +55153,29 @@ ${te.current.stack}
|
|
|
55153
55153
|
document.head.appendChild(tag);
|
|
55154
55154
|
}
|
|
55155
55155
|
var bots_module_css_default = {
|
|
55156
|
-
"tabActive": "vTbXga_tabActive",
|
|
55157
55156
|
"botRow": "vTbXga_botRow",
|
|
55158
|
-
"
|
|
55157
|
+
"tabActive": "vTbXga_tabActive",
|
|
55158
|
+
"dialog": "vTbXga_dialog",
|
|
55159
|
+
"error": "vTbXga_error",
|
|
55160
|
+
"group": "vTbXga_group",
|
|
55161
|
+
"createButton": "vTbXga_createButton",
|
|
55159
55162
|
"tabs": "vTbXga_tabs",
|
|
55160
|
-
"
|
|
55163
|
+
"stepSeparator": "vTbXga_stepSeparator",
|
|
55164
|
+
"stepActive": "vTbXga_stepActive",
|
|
55161
55165
|
"hint": "vTbXga_hint",
|
|
55166
|
+
"botName": "vTbXga_botName",
|
|
55167
|
+
"select": "vTbXga_select",
|
|
55162
55168
|
"channelBadge": "vTbXga_channelBadge",
|
|
55163
|
-
"
|
|
55169
|
+
"scanSection": "vTbXga_scanSection",
|
|
55170
|
+
"textarea": "vTbXga_textarea",
|
|
55171
|
+
"steps": "vTbXga_steps",
|
|
55164
55172
|
"field": "vTbXga_field",
|
|
55165
55173
|
"formActions": "vTbXga_formActions",
|
|
55166
|
-
"createButton": "vTbXga_createButton",
|
|
55167
55174
|
"tab": "vTbXga_tab",
|
|
55168
|
-
"
|
|
55169
|
-
"
|
|
55170
|
-
"group": "vTbXga_group",
|
|
55175
|
+
"step": "vTbXga_step",
|
|
55176
|
+
"groupTitle": "vTbXga_groupTitle",
|
|
55171
55177
|
"input": "vTbXga_input",
|
|
55172
|
-
"
|
|
55173
|
-
"error": "vTbXga_error",
|
|
55174
|
-
"stepSeparator": "vTbXga_stepSeparator",
|
|
55175
|
-
"dialog": "vTbXga_dialog",
|
|
55176
|
-
"steps": "vTbXga_steps",
|
|
55177
|
-
"botName": "vTbXga_botName",
|
|
55178
|
-
"textarea": "vTbXga_textarea"
|
|
55178
|
+
"status": "vTbXga_status"
|
|
55179
55179
|
};
|
|
55180
55180
|
//#endregion
|
|
55181
55181
|
//#region src/client/bots/BotForm.tsx
|
package/lib/index.js
CHANGED
|
@@ -12,6 +12,7 @@ import { SessionId } from "@deepseek-ai/dsh-session";
|
|
|
12
12
|
import { credentialRef } from "@deepseek-ai/dsh-credentials";
|
|
13
13
|
import * as lark from "@larksuiteoapi/node-sdk";
|
|
14
14
|
import { randomBytes, randomUUID } from "node:crypto";
|
|
15
|
+
import { bindScopeParent, createScope, scopeOf } from "@deepseek-ai/dsh-scope";
|
|
15
16
|
import { setupUsage } from "@dsh-agent-toolkit/token-usage";
|
|
16
17
|
//#region src/agents/store.ts
|
|
17
18
|
/** agents 注册表存储域声明:记录 schema + domain 布局的单一来源。 */
|
|
@@ -1668,18 +1669,15 @@ function setupCreateAgentCommand(ctx, deps) {
|
|
|
1668
1669
|
//#region src/channels/agent-setup.ts
|
|
1669
1670
|
/** bot 会话角色 persona 的 scoped 段名:与全局 persona 层同名,scoped 注册即 shadow 覆盖主 Agent persona。 */
|
|
1670
1671
|
const TOOLKIT_PERSONA_SECTION = "prompt-stack:persona";
|
|
1671
|
-
/** 默认加载器:复刻 preset mount 的模块解析——loader 的 unwrapExports 取 `default ?? 命名导出模块`。 */
|
|
1672
|
-
async function loadToolModule(specifier) {
|
|
1673
|
-
const mod = await import(specifier);
|
|
1674
|
-
return mod.default ?? mod;
|
|
1675
|
-
}
|
|
1676
1672
|
/**
|
|
1677
|
-
* 组合 agent
|
|
1678
|
-
*
|
|
1679
|
-
* 顺序敏感:restrict
|
|
1673
|
+
* 组合 agent 作用域:先把 agent scope 父链挂到基础工具行 standing scope(工具成为
|
|
1674
|
+
* 继承面),再叠 bot 的 persona 与 tools 白名单。
|
|
1675
|
+
* 顺序敏感:restrict 必须在 join 之后——宿主 tools.restrict() 只校验并过滤继承面
|
|
1676
|
+
* (global + 祖先 scope 层),own 层(agentCtx 直接挂载)的名字既不可 restrict 也
|
|
1677
|
+
* 不受 restrict 影响,直接挂进 agentCtx 的白名单会抛 unknown global tools。
|
|
1680
1678
|
*/
|
|
1681
|
-
async function setupAgentScope(agentCtx, hooks,
|
|
1682
|
-
|
|
1679
|
+
async function setupAgentScope(agentCtx, hooks, toolsScope) {
|
|
1680
|
+
await toolsScope.join(agentCtx);
|
|
1683
1681
|
if (hooks.persona !== void 0) agentCtx.systemPrompt.section({
|
|
1684
1682
|
name: TOOLKIT_PERSONA_SECTION,
|
|
1685
1683
|
order: 10,
|
|
@@ -2747,6 +2745,55 @@ var BotRuntime = class {
|
|
|
2747
2745
|
}
|
|
2748
2746
|
};
|
|
2749
2747
|
//#endregion
|
|
2748
|
+
//#region src/channels/tool-scope.ts
|
|
2749
|
+
/** 默认加载器:复刻 preset mount 的模块解析——loader 的 unwrapExports 取 `default ?? 命名导出模块`。 */
|
|
2750
|
+
async function loadToolModule(specifier) {
|
|
2751
|
+
const mod = await import(specifier);
|
|
2752
|
+
return mod.default ?? mod;
|
|
2753
|
+
}
|
|
2754
|
+
/** 建一个 bot 会话共用的工具行 standing scope(所有 bot 会话挂同一套 BASIC_TOOLS)。 */
|
|
2755
|
+
function createToolsScope(ctx, loadTool = loadToolModule) {
|
|
2756
|
+
let scope;
|
|
2757
|
+
let mount;
|
|
2758
|
+
let generation = 0;
|
|
2759
|
+
function ensure() {
|
|
2760
|
+
mount ??= (async () => {
|
|
2761
|
+
const key = {
|
|
2762
|
+
origin: "dsh-agent-toolkit",
|
|
2763
|
+
kind: "bots-tools",
|
|
2764
|
+
gen: ++generation
|
|
2765
|
+
};
|
|
2766
|
+
const created = createScope(ctx, key);
|
|
2767
|
+
scope = created;
|
|
2768
|
+
try {
|
|
2769
|
+
for (const tool of BASIC_TOOLS) await created.ctx.plugin(await loadTool(tool.id), tool.config);
|
|
2770
|
+
} catch (error) {
|
|
2771
|
+
if (scope === created) scope = void 0;
|
|
2772
|
+
mount = void 0;
|
|
2773
|
+
await created.dispose().catch(() => void 0);
|
|
2774
|
+
throw error;
|
|
2775
|
+
}
|
|
2776
|
+
return key;
|
|
2777
|
+
})();
|
|
2778
|
+
return mount;
|
|
2779
|
+
}
|
|
2780
|
+
return {
|
|
2781
|
+
async join(agentCtx) {
|
|
2782
|
+
const agentKey = scopeOf(agentCtx);
|
|
2783
|
+
if (agentKey === void 0) throw new Error("tools-scope: refusing to join an unscoped agent context; per-agent composition requires a scope key");
|
|
2784
|
+
const standing = await ensure();
|
|
2785
|
+
bindScopeParent(agentKey, standing);
|
|
2786
|
+
return standing;
|
|
2787
|
+
},
|
|
2788
|
+
async dispose() {
|
|
2789
|
+
mount = void 0;
|
|
2790
|
+
const current = scope;
|
|
2791
|
+
scope = void 0;
|
|
2792
|
+
await current?.dispose();
|
|
2793
|
+
}
|
|
2794
|
+
};
|
|
2795
|
+
}
|
|
2796
|
+
//#endregion
|
|
2750
2797
|
//#region src/bots/api.ts
|
|
2751
2798
|
/** 浏览器半 RPC:单前缀路由 /dsh-agent-toolkit/api/bots + 内部路径分发。 */
|
|
2752
2799
|
const MAX_BODY_BYTES = 65536;
|
|
@@ -3089,21 +3136,22 @@ function setupBots(ctx, config, deps) {
|
|
|
3089
3136
|
await ctx.credentials.set(credentialRef(ref), secret);
|
|
3090
3137
|
return ref;
|
|
3091
3138
|
};
|
|
3092
|
-
/** 创作期注入已迁至 agent-setup.ts
|
|
3139
|
+
/** 创作期注入已迁至 agent-setup.ts + tool-scope.ts(基础工具行 standing scope 挂载 + persona/tools),preset 机制整体移除。 */
|
|
3140
|
+
const toolsScope = createToolsScope(ctx);
|
|
3093
3141
|
const agentsPort = {
|
|
3094
3142
|
async create(input) {
|
|
3095
3143
|
return adaptAgent(await ctx.agents.create({
|
|
3096
3144
|
sessionId: SessionId(input.sessionId),
|
|
3097
3145
|
meta: { cwd: input.cwd },
|
|
3098
3146
|
...input.agentOptions !== void 0 ? { agentOptions: input.agentOptions } : {},
|
|
3099
|
-
setup: (agentCtx) => setupAgentScope(agentCtx, input.hooks)
|
|
3147
|
+
setup: (agentCtx) => setupAgentScope(agentCtx, input.hooks, toolsScope)
|
|
3100
3148
|
}));
|
|
3101
3149
|
},
|
|
3102
3150
|
async resume(input) {
|
|
3103
3151
|
return adaptAgent(await ctx.agents.resume({
|
|
3104
3152
|
resumeSessionId: SessionId(input.sessionId),
|
|
3105
3153
|
...input.agentOptions !== void 0 ? { agentOptions: input.agentOptions } : {},
|
|
3106
|
-
setup: (agentCtx) => setupAgentScope(agentCtx, input.hooks)
|
|
3154
|
+
setup: (agentCtx) => setupAgentScope(agentCtx, input.hooks, toolsScope)
|
|
3107
3155
|
}));
|
|
3108
3156
|
}
|
|
3109
3157
|
};
|
|
@@ -3207,6 +3255,9 @@ function setupBots(ctx, config, deps) {
|
|
|
3207
3255
|
});
|
|
3208
3256
|
return () => dispose();
|
|
3209
3257
|
});
|
|
3258
|
+
ctx.effect(() => async () => {
|
|
3259
|
+
await toolsScope.dispose();
|
|
3260
|
+
});
|
|
3210
3261
|
ctx.effect(() => async () => {
|
|
3211
3262
|
registerAppService.dispose();
|
|
3212
3263
|
});
|