@troykelly/openclaw-projects 0.0.48 → 0.0.50
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/register-openclaw.d.ts +30 -0
- package/dist/register-openclaw.d.ts.map +1 -1
- package/dist/register-openclaw.js +39 -9
- package/dist/register-openclaw.js.map +1 -1
- package/dist/tools/notebooks.js +3 -3
- package/dist/tools/notebooks.js.map +1 -1
- package/dist/tools/notes.d.ts.map +1 -1
- package/dist/tools/notes.js +6 -5
- package/dist/tools/notes.js.map +1 -1
- package/dist/tools/relationships.d.ts +6 -0
- package/dist/tools/relationships.d.ts.map +1 -1
- package/dist/tools/relationships.js +6 -4
- package/dist/tools/relationships.js.map +1 -1
- package/dist/tools/terminal-connections.js +5 -5
- package/dist/tools/terminal-connections.js.map +1 -1
- package/openclaw.plugin.json +1 -1
- package/package.json +1 -1
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
* - Hooks registered via `api.on()` (modern) or `api.registerHook()` (legacy fallback)
|
|
8
8
|
* - CLI registered via `api.registerCli()`
|
|
9
9
|
*/
|
|
10
|
+
import { z } from 'zod';
|
|
10
11
|
import { type ApiClient } from './api-client.js';
|
|
11
12
|
import { type PluginConfig } from './config.js';
|
|
12
13
|
import { type Logger } from './logger.js';
|
|
@@ -36,6 +37,35 @@ interface PluginState {
|
|
|
36
37
|
/** Track whether session data was already captured to avoid double-capture (#2052) */
|
|
37
38
|
sessionCapturedKeys: Set<string>;
|
|
38
39
|
}
|
|
40
|
+
/**
|
|
41
|
+
* Zod schema enforcing the gateway contract: every content block
|
|
42
|
+
* must have type "text" and a non-empty text string (#2230).
|
|
43
|
+
*/
|
|
44
|
+
export declare const AgentToolResultSchema: z.ZodObject<{
|
|
45
|
+
content: z.ZodArray<z.ZodObject<{
|
|
46
|
+
type: z.ZodLiteral<"text">;
|
|
47
|
+
text: z.ZodString;
|
|
48
|
+
}, "strip", z.ZodTypeAny, {
|
|
49
|
+
type: "text";
|
|
50
|
+
text: string;
|
|
51
|
+
}, {
|
|
52
|
+
type: "text";
|
|
53
|
+
text: string;
|
|
54
|
+
}>, "many">;
|
|
55
|
+
isError: z.ZodOptional<z.ZodBoolean>;
|
|
56
|
+
}, "strip", z.ZodTypeAny, {
|
|
57
|
+
content: {
|
|
58
|
+
type: "text";
|
|
59
|
+
text: string;
|
|
60
|
+
}[];
|
|
61
|
+
isError?: boolean | undefined;
|
|
62
|
+
}, {
|
|
63
|
+
content: {
|
|
64
|
+
type: "text";
|
|
65
|
+
text: string;
|
|
66
|
+
}[];
|
|
67
|
+
isError?: boolean | undefined;
|
|
68
|
+
}>;
|
|
39
69
|
/**
|
|
40
70
|
* Convert internal ToolResult format to AgentToolResult format expected by OpenClaw Gateway.
|
|
41
71
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"register-openclaw.d.ts","sourceRoot":"","sources":["../src/register-openclaw.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;
|
|
1
|
+
{"version":3,"file":"register-openclaw.d.ts","sourceRoot":"","sources":["../src/register-openclaw.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,CAAC,EAAY,MAAM,KAAK,CAAC;AAClC,OAAO,EAAE,KAAK,SAAS,EAAmB,MAAM,iBAAiB,CAAC;AAClE,OAAO,EAAE,KAAK,YAAY,EAA2G,MAAM,aAAa,CAAC;AAQzJ,OAAO,EAAgB,KAAK,MAAM,EAAE,MAAM,aAAa,CAAC;AAwExD,OAAO,KAAK,EACV,eAAe,EAEf,UAAU,EAcV,iBAAiB,EAGjB,UAAU,EACX,MAAM,yBAAyB,CAAC;AAajC,8CAA8C;AAC9C,UAAU,WAAW;IACnB,MAAM,EAAE,YAAY,CAAC;IACrB,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,SAAS,CAAC;IACrB,oEAAoE;IACpE,OAAO,EAAE,MAAM,CAAC;IAChB,uGAAuG;IACvG,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,4GAA4G;IAC5G,iBAAiB,EAAE;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,EAAE,CAAA;KAAE,CAAC;IACzD,oEAAoE;IACpE,eAAe,EAAE,OAAO,CAAC;IACzB,mEAAmE;IACnE,sBAAsB,EAAE,MAAM,CAAC;IAC/B,2DAA2D;IAC3D,eAAe,EAAE,OAAO,CAAC;IACzB,gEAAgE;IAChE,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,sFAAsF;IACtF,mBAAmB,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;CAClC;AAED;;;GAGG;AACH,eAAO,MAAM,qBAAqB;;;;;;;;;;;;;;;;;;;;;;;;EAUhC,CAAC;AAEH;;;;;;;;;;GAUG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,UAAU,GAAG,eAAe,CA6CrE;AAoiDD;;;;GAIG;AACH,wBAAsB,sBAAsB,CAAC,KAAK,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,CA6C9E;AAwxED;;;;;GAKG;AACH,eAAO,MAAM,gBAAgB,EAAE,iBAwqD9B,CAAC;AAEF,yDAAyD;AACzD,eAAe,gBAAgB,CAAC;AAEhC,2CAA2C;AAC3C,eAAO,MAAM,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAwCnB,CAAC"}
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* - Hooks registered via `api.on()` (modern) or `api.registerHook()` (legacy fallback)
|
|
8
8
|
* - CLI registered via `api.registerCli()`
|
|
9
9
|
*/
|
|
10
|
-
import { ZodError } from 'zod';
|
|
10
|
+
import { z, ZodError } from 'zod';
|
|
11
11
|
import { createApiClient } from './api-client.js';
|
|
12
12
|
import { redactConfig, resolveConfigSecretsSync, resolveNamespaceConfig, validateRawConfig } from './config.js';
|
|
13
13
|
import { extractContext, getUserScopeKey, resolveAgentId } from './context.js';
|
|
@@ -39,6 +39,19 @@ import { blendScores, computeGeoScore, haversineDistanceKm } from './utils/geo.j
|
|
|
39
39
|
import { createBoundaryMarkers, detectInjectionPatternsAsync, sanitizeMessageForContext, sanitizeMetadataField, wrapExternalMessage, } from './utils/injection-protection.js';
|
|
40
40
|
import { injectionLogLimiter } from './utils/injection-log-rate-limiter.js';
|
|
41
41
|
import { reverseGeocode } from './utils/nominatim.js';
|
|
42
|
+
/**
|
|
43
|
+
* Zod schema enforcing the gateway contract: every content block
|
|
44
|
+
* must have type "text" and a non-empty text string (#2230).
|
|
45
|
+
*/
|
|
46
|
+
export const AgentToolResultSchema = z.object({
|
|
47
|
+
content: z
|
|
48
|
+
.array(z.object({
|
|
49
|
+
type: z.literal('text'),
|
|
50
|
+
text: z.string().min(1),
|
|
51
|
+
}))
|
|
52
|
+
.min(1),
|
|
53
|
+
isError: z.boolean().optional(),
|
|
54
|
+
});
|
|
42
55
|
/**
|
|
43
56
|
* Convert internal ToolResult format to AgentToolResult format expected by OpenClaw Gateway.
|
|
44
57
|
*
|
|
@@ -51,9 +64,10 @@ import { reverseGeocode } from './utils/nominatim.js';
|
|
|
51
64
|
* `estimateMessageChars` (#2220, #2228).
|
|
52
65
|
*/
|
|
53
66
|
export function toAgentToolResult(result) {
|
|
67
|
+
let candidate;
|
|
54
68
|
if (result.success && result.data) {
|
|
55
69
|
let text;
|
|
56
|
-
if (typeof result.data.content === 'string') {
|
|
70
|
+
if (typeof result.data.content === 'string' && result.data.content.length > 0) {
|
|
57
71
|
text = result.data.content;
|
|
58
72
|
}
|
|
59
73
|
else {
|
|
@@ -66,16 +80,32 @@ export function toAgentToolResult(result) {
|
|
|
66
80
|
text = String(result.data);
|
|
67
81
|
}
|
|
68
82
|
}
|
|
83
|
+
candidate = { content: [{ type: 'text', text }] };
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
// For errors, format the error message
|
|
87
|
+
const errorText = result.error && String(result.error).trim()
|
|
88
|
+
? String(result.error)
|
|
89
|
+
: 'An unexpected error occurred';
|
|
90
|
+
candidate = {
|
|
91
|
+
content: [{ type: 'text', text: `Error: ${errorText}` }],
|
|
92
|
+
isError: true,
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
// Runtime guard: validate the output matches the gateway contract (#2230).
|
|
96
|
+
const parsed = AgentToolResultSchema.safeParse(candidate);
|
|
97
|
+
if (!parsed.success) {
|
|
98
|
+
// Do NOT throw — returning an error result is safer than crashing.
|
|
99
|
+
// Log enough context to diagnose which tool produced bad output.
|
|
100
|
+
const dataShape = result.data ? Object.keys(result.data).join(',') : 'none';
|
|
101
|
+
console.error(`[openclaw-plugin] toAgentToolResult: output failed schema validation (#2230). ` +
|
|
102
|
+
`success=${result.success} dataKeys=${dataShape} zodError=${parsed.error.message}`);
|
|
69
103
|
return {
|
|
70
|
-
content: [{ type: 'text', text }],
|
|
104
|
+
content: [{ type: 'text', text: '(invalid tool result)' }],
|
|
105
|
+
isError: true,
|
|
71
106
|
};
|
|
72
107
|
}
|
|
73
|
-
|
|
74
|
-
const errorText = result.error ?? 'An unexpected error occurred';
|
|
75
|
-
return {
|
|
76
|
-
content: [{ type: 'text', text: `Error: ${errorText}` }],
|
|
77
|
-
isError: true,
|
|
78
|
-
};
|
|
108
|
+
return candidate;
|
|
79
109
|
}
|
|
80
110
|
/** Namespace property for store/create tools (Issue #1428) */
|
|
81
111
|
const namespaceProperty = {
|