@xgjktech/xg-openclaw-harness-tools 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/plan-origin.d.ts +9 -0
- package/dist/plan-origin.d.ts.map +1 -0
- package/dist/plan-origin.js +33 -0
- package/dist/plan-write-tool.d.ts +2 -2
- package/dist/plan-write-tool.d.ts.map +1 -1
- package/dist/plan-write-tool.js +11 -4
- package/package.json +2 -2
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAYA,wBAwDG"}
|
package/dist/index.js
CHANGED
|
@@ -2,6 +2,7 @@ import { defineToolPlugin } from "openclaw/plugin-sdk/tool-plugin";
|
|
|
2
2
|
import { resolvePlanDbPath, SqlitePlanStore } 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 { toPlanOrigin } from "./plan-origin.js";
|
|
5
6
|
const PLUGIN_ID = "xg-harness-tools";
|
|
6
7
|
export default defineToolPlugin({
|
|
7
8
|
id: PLUGIN_ID,
|
|
@@ -25,7 +26,7 @@ export default defineToolPlugin({
|
|
|
25
26
|
description: PLAN_WRITE_DESCRIPTION,
|
|
26
27
|
parameters: PlanWriteParams,
|
|
27
28
|
optional: true,
|
|
28
|
-
factory: ({ api }) => buildPlanWriteTool(getStore(api)),
|
|
29
|
+
factory: ({ api, toolContext }) => buildPlanWriteTool(getStore(api), toPlanOrigin(toolContext)),
|
|
29
30
|
}),
|
|
30
31
|
tool({
|
|
31
32
|
name: "xg_plan_execute",
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { PlanOrigin } from "@xgjktech/xg-openclaw-shared";
|
|
2
|
+
/** 从工具工厂 ctx 采集来源上下文。全字段皆空时返回 undefined(不落空对象)。 */
|
|
3
|
+
export declare function toPlanOrigin(toolContext: {
|
|
4
|
+
sessionKey?: string;
|
|
5
|
+
messageChannel?: string;
|
|
6
|
+
agentAccountId?: string;
|
|
7
|
+
deliveryContext?: unknown;
|
|
8
|
+
}): PlanOrigin | undefined;
|
|
9
|
+
//# sourceMappingURL=plan-origin.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plan-origin.d.ts","sourceRoot":"","sources":["../src/plan-origin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,8BAA8B,CAAC;AAa/D,mDAAmD;AACnD,wBAAgB,YAAY,CAAC,WAAW,EAAE;IACxC,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,eAAe,CAAC,EAAE,OAAO,CAAC;CAC3B,GAAG,UAAU,GAAG,SAAS,CAuBzB"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
function nonEmptyString(value) {
|
|
2
|
+
return typeof value === "string" && value.trim() !== "" ? value : undefined;
|
|
3
|
+
}
|
|
4
|
+
function readDeliveryField(deliveryContext, field) {
|
|
5
|
+
if (typeof deliveryContext !== "object" || deliveryContext === null || Array.isArray(deliveryContext)) {
|
|
6
|
+
return undefined;
|
|
7
|
+
}
|
|
8
|
+
return deliveryContext[field];
|
|
9
|
+
}
|
|
10
|
+
/** 从工具工厂 ctx 采集来源上下文。全字段皆空时返回 undefined(不落空对象)。 */
|
|
11
|
+
export function toPlanOrigin(toolContext) {
|
|
12
|
+
const deliveryContext = toolContext.deliveryContext;
|
|
13
|
+
const channel = nonEmptyString(readDeliveryField(deliveryContext, "channel")) ??
|
|
14
|
+
nonEmptyString(toolContext.messageChannel);
|
|
15
|
+
const to = nonEmptyString(readDeliveryField(deliveryContext, "to"));
|
|
16
|
+
const accountId = nonEmptyString(readDeliveryField(deliveryContext, "accountId")) ??
|
|
17
|
+
nonEmptyString(toolContext.agentAccountId);
|
|
18
|
+
const rawThreadId = readDeliveryField(deliveryContext, "threadId");
|
|
19
|
+
const threadId = typeof rawThreadId === "number" ? String(rawThreadId) : nonEmptyString(rawThreadId);
|
|
20
|
+
const sessionKey = nonEmptyString(toolContext.sessionKey);
|
|
21
|
+
const origin = {};
|
|
22
|
+
if (channel !== undefined)
|
|
23
|
+
origin.channel = channel;
|
|
24
|
+
if (to !== undefined)
|
|
25
|
+
origin.to = to;
|
|
26
|
+
if (accountId !== undefined)
|
|
27
|
+
origin.accountId = accountId;
|
|
28
|
+
if (threadId !== undefined)
|
|
29
|
+
origin.threadId = threadId;
|
|
30
|
+
if (sessionKey !== undefined)
|
|
31
|
+
origin.sessionKey = sessionKey;
|
|
32
|
+
return Object.keys(origin).length === 0 ? undefined : origin;
|
|
33
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Type, type Static } from "typebox";
|
|
2
2
|
import type { AnyAgentTool } from "openclaw/plugin-sdk/plugin-entry";
|
|
3
|
-
import { type PlanStore } from "@xgjktech/xg-openclaw-shared";
|
|
3
|
+
import { type PlanOrigin, type PlanStore } from "@xgjktech/xg-openclaw-shared";
|
|
4
4
|
export declare const PlanWriteParams: Type.TObject<{
|
|
5
5
|
planId: Type.TOptional<Type.TString>;
|
|
6
6
|
goal: Type.TString;
|
|
@@ -16,5 +16,5 @@ export declare const PlanWriteParams: Type.TObject<{
|
|
|
16
16
|
}>;
|
|
17
17
|
export type PlanWriteParamsT = Static<typeof PlanWriteParams>;
|
|
18
18
|
export declare const PLAN_WRITE_DESCRIPTION: string;
|
|
19
|
-
export declare function buildPlanWriteTool(store: PlanStore): AnyAgentTool;
|
|
19
|
+
export declare function buildPlanWriteTool(store: PlanStore, origin?: PlanOrigin): AnyAgentTool;
|
|
20
20
|
//# sourceMappingURL=plan-write-tool.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plan-write-tool.d.ts","sourceRoot":"","sources":["../src/plan-write-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,SAAS,EAKf,MAAM,8BAA8B,CAAC;AAoCtC,eAAO,MAAM,eAAe;;;;;;;;;;;;EAS3B,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG,MAAM,CAAC,OAAO,eAAe,CAAC,CAAC;AAE9D,eAAO,MAAM,sBAAsB,QAcvB,CAAC;
|
|
1
|
+
{"version":3,"file":"plan-write-tool.d.ts","sourceRoot":"","sources":["../src/plan-write-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,UAAU,EACf,KAAK,SAAS,EAKf,MAAM,8BAA8B,CAAC;AAoCtC,eAAO,MAAM,eAAe;;;;;;;;;;;;EAS3B,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG,MAAM,CAAC,OAAO,eAAe,CAAC,CAAC;AAE9D,eAAO,MAAM,sBAAsB,QAcvB,CAAC;AAkDb,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,SAAS,EAAE,MAAM,CAAC,EAAE,UAAU,GAAG,YAAY,CAwCtF"}
|
package/dist/plan-write-tool.js
CHANGED
|
@@ -56,17 +56,24 @@ function toTask(input) {
|
|
|
56
56
|
}
|
|
57
57
|
return task;
|
|
58
58
|
}
|
|
59
|
-
function buildPlan(params, existing, planId) {
|
|
59
|
+
function buildPlan(params, existing, planId, origin) {
|
|
60
60
|
const now = new Date().toISOString();
|
|
61
|
-
|
|
61
|
+
const plan = {
|
|
62
62
|
planId,
|
|
63
63
|
goal: params.goal,
|
|
64
64
|
createdAt: existing?.createdAt ?? now,
|
|
65
65
|
updatedAt: now,
|
|
66
66
|
tasks: params.tasks.map(toTask),
|
|
67
67
|
};
|
|
68
|
+
// 改写已有计划时保留原 origin(改写是内容编辑,不是重新发起);
|
|
69
|
+
// 仅当旧计划本就没有 origin(旧数据补齐)才写入本次采集到的 origin。
|
|
70
|
+
const resolvedOrigin = existing !== undefined ? (existing.origin ?? origin) : origin;
|
|
71
|
+
if (resolvedOrigin !== undefined) {
|
|
72
|
+
plan.origin = resolvedOrigin;
|
|
73
|
+
}
|
|
74
|
+
return plan;
|
|
68
75
|
}
|
|
69
|
-
export function buildPlanWriteTool(store) {
|
|
76
|
+
export function buildPlanWriteTool(store, origin) {
|
|
70
77
|
return {
|
|
71
78
|
name: "xg_plan_write",
|
|
72
79
|
label: "【xg-harness】编写计划",
|
|
@@ -87,7 +94,7 @@ export function buildPlanWriteTool(store) {
|
|
|
87
94
|
}
|
|
88
95
|
}
|
|
89
96
|
const planId = params.planId ?? randomUUID();
|
|
90
|
-
const plan = buildPlan(params, existing, planId);
|
|
97
|
+
const plan = buildPlan(params, existing, planId, origin);
|
|
91
98
|
assertPlanInvariants(plan);
|
|
92
99
|
store.set(plan);
|
|
93
100
|
const result = { ok: true, planId: plan.planId, plan };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xgjktech/xg-openclaw-harness-tools",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "企业工具插件:plan_write / plan_execute 计划工具(OpenClaw 第三方工具插件)",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
29
|
"typebox": "1.1.39",
|
|
30
|
-
"@xgjktech/xg-openclaw-shared": "^0.
|
|
30
|
+
"@xgjktech/xg-openclaw-shared": "^0.2.0"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
33
|
"@types/node": "^22.19.0",
|