@xgjktech/xg-openclaw-harness-tools 0.3.2 → 0.3.5

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.
@@ -0,0 +1,15 @@
1
+ import { Type, type Static } from "typebox";
2
+ import type { AnyAgentTool } from "openclaw/plugin-sdk/plugin-entry";
3
+ import { type ActionStore, type PlanOrigin } from "@xgjktech/xg-openclaw-shared";
4
+ export declare const ActionDispatchParams: Type.TObject<{
5
+ action: Type.TUnion<[Type.TLiteral<"ui_refresh">, Type.TLiteral<"notification">, Type.TLiteral<"workflow_trigger">, Type.TLiteral<"form_fill">, Type.TString]>;
6
+ target: Type.TString;
7
+ topic: Type.TOptional<Type.TString>;
8
+ status: Type.TOptional<Type.TUnion<[Type.TLiteral<"completed">, Type.TLiteral<"running">, Type.TLiteral<"pending">, Type.TLiteral<"failed">]>>;
9
+ activeSessionOnly: Type.TOptional<Type.TBoolean>;
10
+ payloadData: Type.TRecord<"^.*$", Type.TUnknown>;
11
+ }>;
12
+ export type ActionDispatchParamsT = Static<typeof ActionDispatchParams>;
13
+ export declare const ACTION_DISPATCH_DESCRIPTION: string;
14
+ export declare function buildActionDispatchTool(store: ActionStore, origin?: PlanOrigin): AnyAgentTool;
15
+ //# sourceMappingURL=action-dispatch-tool.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"action-dispatch-tool.d.ts","sourceRoot":"","sources":["../src/action-dispatch-tool.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,KAAK,MAAM,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kCAAkC,CAAC;AACrE,OAAO,EAIL,KAAK,WAAW,EAChB,KAAK,UAAU,EAChB,MAAM,8BAA8B,CAAC;AAGtC,eAAO,MAAM,oBAAoB;;;;;;;EA+ChC,CAAC;AAEF,MAAM,MAAM,qBAAqB,GAAG,MAAM,CAAC,OAAO,oBAAoB,CAAC,CAAC;AAExE,eAAO,MAAM,2BAA2B,QAS5B,CAAC;AAMb,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,WAAW,EAAE,MAAM,CAAC,EAAE,UAAU,GAAG,YAAY,CA0D7F"}
@@ -0,0 +1,96 @@
1
+ import { randomUUID } from "node:crypto";
2
+ import { Type } from "typebox";
3
+ import { assertActionDispatchEventInvariants, } from "@xgjktech/xg-openclaw-shared";
4
+ import { toolJsonResult } from "./tool-json-result.js";
5
+ export const ActionDispatchParams = Type.Object({
6
+ action: Type.Union([
7
+ Type.Literal("ui_refresh"),
8
+ Type.Literal("notification"),
9
+ Type.Literal("workflow_trigger"),
10
+ Type.Literal("form_fill"),
11
+ Type.String({ description: "自定义扩展动作类型" }),
12
+ ], { description: "指令动作大类" }),
13
+ target: Type.String({
14
+ minLength: 1,
15
+ maxLength: 128,
16
+ description: "目标组件或页面标识 (必须严格等于前端注册的 target 标识,如 order_detail_panel)",
17
+ }),
18
+ topic: Type.Optional(Type.String({
19
+ maxLength: 64,
20
+ description: "业务主题/模块标识 (如 order_management, user_system)",
21
+ })),
22
+ status: Type.Optional(Type.Union([
23
+ Type.Literal("completed"),
24
+ Type.Literal("running"),
25
+ Type.Literal("pending"),
26
+ Type.Literal("failed"),
27
+ ], { default: "completed", description: "动作生命周期状态" })),
28
+ activeSessionOnly: Type.Optional(Type.Boolean({ default: true, description: "是否限制仅在当前激活前端窗口生效" })),
29
+ payloadData: Type.Record(Type.String(), Type.Unknown(), {
30
+ description: "传递给前端的具体业务数据键值对 (格式为 { data: { ... } })",
31
+ }),
32
+ }, { additionalProperties: false });
33
+ export const ACTION_DISPATCH_DESCRIPTION = [
34
+ "用途:分发通用动作指令(如 UI 局部刷新 ui_refresh、通知 notification、工作流触发 workflow_trigger、表单填充 form_fill 等)给前端客户端消费。",
35
+ "",
36
+ "参数要求:",
37
+ "- action: 动作类型枚举 (ui_refresh, notification, workflow_trigger, form_fill 或自定义扩展动作)。",
38
+ "- target: 目标组件或页面标识 (如 order_detail_panel)。",
39
+ "- payloadData: 包含要传递给前端业务数据的键值字典。",
40
+ "- activeSessionOnly: 默认为 true,限制仅在活跃前端窗口生效。",
41
+ "- status: 默认为 completed,异步长任务可用 running/pending/failed 表达状态变化。",
42
+ ].join("\n");
43
+ export function buildActionDispatchTool(store, origin) {
44
+ return {
45
+ name: "xg_action_dispatch",
46
+ label: "【xg-harness】动作指令分发",
47
+ description: ACTION_DISPATCH_DESCRIPTION,
48
+ parameters: ActionDispatchParams,
49
+ async execute(_toolCallId, rawParams) {
50
+ const params = rawParams;
51
+ try {
52
+ const eventId = `evt_${randomUUID()}`;
53
+ const now = new Date();
54
+ const version = now.getTime();
55
+ const status = params.status ?? "completed";
56
+ const event = {
57
+ eventId,
58
+ event: "action_dispatch",
59
+ action: params.action,
60
+ target: params.target,
61
+ version,
62
+ status,
63
+ scopeControl: {
64
+ activeSessionOnly: params.activeSessionOnly ?? true,
65
+ },
66
+ payload: {
67
+ data: params.payloadData,
68
+ },
69
+ timestamp: now.toISOString(),
70
+ };
71
+ if (params.topic !== undefined && params.topic.trim() !== "") {
72
+ event.topic = params.topic;
73
+ }
74
+ if (origin !== undefined) {
75
+ event.origin = origin;
76
+ }
77
+ assertActionDispatchEventInvariants(event);
78
+ store.set(event);
79
+ const result = {
80
+ ok: true,
81
+ eventId: event.eventId,
82
+ version: event.version,
83
+ event,
84
+ };
85
+ return toolJsonResult(result);
86
+ }
87
+ catch (e) {
88
+ const result = {
89
+ ok: false,
90
+ error: { code: "ACTION_DISPATCH_ERROR", detail: String(e.message) },
91
+ };
92
+ return toolJsonResult(result);
93
+ }
94
+ },
95
+ };
96
+ }
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAYA,wBAoCG"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAiBA,wBAqDG"}
package/dist/index.js CHANGED
@@ -1,23 +1,30 @@
1
1
  import { defineToolPlugin } from "openclaw/plugin-sdk/tool-plugin";
2
- import { resolvePlanDbPath, SqlitePlanStore } from "@xgjktech/xg-openclaw-shared";
2
+ import { resolvePlanDbPath, SqlitePlanStore, SqliteActionStore } from "@xgjktech/xg-openclaw-shared";
3
3
  import { PLAN_WRITE_DESCRIPTION, PlanWriteParams, buildPlanWriteTool } from "./plan-write-tool.js";
4
4
  import { PLAN_EXECUTE_DESCRIPTION, PlanExecuteParams, buildPlanExecuteTool, } from "./plan-execute-tool.js";
5
+ import { ACTION_DISPATCH_DESCRIPTION, ActionDispatchParams, buildActionDispatchTool, } from "./action-dispatch-tool.js";
5
6
  import { toPlanOrigin } from "./plan-origin.js";
6
7
  const PLUGIN_ID = "xg-harness-tools";
7
8
  export default defineToolPlugin({
8
9
  id: PLUGIN_ID,
9
10
  name: "XG Harness Tools",
10
- description: "企业工具插件:计划编写与查看(plan_write / plan_execute)",
11
+ description: "企业工具插件:计划管理与通用动作分发(plan_write / plan_execute / action_dispatch)",
11
12
  tools: (tool) => {
12
- // store 单例:defineToolPlugin 的 tools(...) 只在插件加载时调用一次,
13
- // 闭包在此建一次即可;factory 本身会在每次 agent attempt 重建工具集时重新调用。
14
- let store;
15
- const getStore = (api) => {
16
- if (store === undefined) {
13
+ let planStore;
14
+ let actionStore;
15
+ const getPlanStore = (api) => {
16
+ if (planStore === undefined) {
17
17
  const dbPath = resolvePlanDbPath(api.runtime.state.resolveStateDir());
18
- store = new SqlitePlanStore(dbPath);
18
+ planStore = new SqlitePlanStore(dbPath);
19
19
  }
20
- return store;
20
+ return planStore;
21
+ };
22
+ const getActionStore = (api) => {
23
+ if (actionStore === undefined) {
24
+ const dbPath = resolvePlanDbPath(api.runtime.state.resolveStateDir());
25
+ actionStore = new SqliteActionStore(dbPath);
26
+ }
27
+ return actionStore;
21
28
  };
22
29
  return [
23
30
  tool({
@@ -26,7 +33,7 @@ export default defineToolPlugin({
26
33
  description: PLAN_WRITE_DESCRIPTION,
27
34
  parameters: PlanWriteParams,
28
35
  optional: true,
29
- factory: ({ api, toolContext }) => buildPlanWriteTool(getStore(api), toPlanOrigin(toolContext)),
36
+ factory: ({ api, toolContext }) => buildPlanWriteTool(getPlanStore(api), toPlanOrigin(toolContext)),
30
37
  }),
31
38
  tool({
32
39
  name: "xg_plan_execute",
@@ -34,7 +41,15 @@ export default defineToolPlugin({
34
41
  description: PLAN_EXECUTE_DESCRIPTION,
35
42
  parameters: PlanExecuteParams,
36
43
  optional: true,
37
- factory: ({ api, toolContext }) => buildPlanExecuteTool({ store: getStore(api), origin: toPlanOrigin(toolContext) }),
44
+ factory: ({ api, toolContext }) => buildPlanExecuteTool({ store: getPlanStore(api), origin: toPlanOrigin(toolContext) }),
45
+ }),
46
+ tool({
47
+ name: "xg_action_dispatch",
48
+ label: "【xg-harness】动作指令分发",
49
+ description: ACTION_DISPATCH_DESCRIPTION,
50
+ parameters: ActionDispatchParams,
51
+ optional: true,
52
+ factory: ({ api, toolContext }) => buildActionDispatchTool(getActionStore(api), toPlanOrigin(toolContext)),
38
53
  }),
39
54
  ];
40
55
  },
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "id": "xg-harness-tools",
3
3
  "name": "XG Harness Tools",
4
- "description": "企业计划工具(plan_write / plan_execute)",
4
+ "description": "企业工具插件:计划管理与通用动作分发(plan_write / plan_execute / action_dispatch)",
5
5
  "version": "0.1.0",
6
6
  "configSchema": {
7
7
  "type": "object",
@@ -9,6 +9,6 @@
9
9
  "properties": {}
10
10
  },
11
11
  "contracts": {
12
- "tools": ["xg_plan_write", "xg_plan_execute"]
12
+ "tools": ["xg_plan_write", "xg_plan_execute", "xg_action_dispatch"]
13
13
  }
14
14
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@xgjktech/xg-openclaw-harness-tools",
3
- "version": "0.3.2",
4
- "description": "企业工具插件:plan_write / plan_execute 计划工具(OpenClaw 第三方工具插件)",
3
+ "version": "0.3.5",
4
+ "description": "企业工具插件:plan_write / plan_execute / action_dispatch(OpenClaw 第三方工具插件)",
5
5
  "license": "MIT",
6
6
  "type": "module",
7
7
  "engines": {
@@ -52,4 +52,4 @@
52
52
  "defaultChoice": "local"
53
53
  }
54
54
  }
55
- }
55
+ }