@lobu/worker 6.1.1 → 7.1.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.
Files changed (124) hide show
  1. package/dist/core/error-handler.d.ts +0 -4
  2. package/dist/core/error-handler.d.ts.map +1 -1
  3. package/dist/core/error-handler.js +4 -15
  4. package/dist/core/error-handler.js.map +1 -1
  5. package/dist/core/types.d.ts +1 -19
  6. package/dist/core/types.d.ts.map +1 -1
  7. package/dist/core/types.js +0 -4
  8. package/dist/core/types.js.map +1 -1
  9. package/dist/core/workspace.d.ts +2 -11
  10. package/dist/core/workspace.d.ts.map +1 -1
  11. package/dist/core/workspace.js +14 -36
  12. package/dist/core/workspace.js.map +1 -1
  13. package/dist/embedded/just-bash-bootstrap.d.ts.map +1 -1
  14. package/dist/embedded/just-bash-bootstrap.js +60 -6
  15. package/dist/embedded/just-bash-bootstrap.js.map +1 -1
  16. package/dist/embedded/mcp-cli-commands.d.ts.map +1 -1
  17. package/dist/embedded/mcp-cli-commands.js +3 -38
  18. package/dist/embedded/mcp-cli-commands.js.map +1 -1
  19. package/dist/gateway/gateway-integration.js +4 -4
  20. package/dist/gateway/gateway-integration.js.map +1 -1
  21. package/dist/gateway/message-batcher.d.ts.map +1 -1
  22. package/dist/gateway/message-batcher.js +3 -5
  23. package/dist/gateway/message-batcher.js.map +1 -1
  24. package/dist/gateway/sse-client.d.ts +1 -0
  25. package/dist/gateway/sse-client.d.ts.map +1 -1
  26. package/dist/gateway/sse-client.js +52 -8
  27. package/dist/gateway/sse-client.js.map +1 -1
  28. package/dist/index.d.ts.map +1 -1
  29. package/dist/index.js +7 -24
  30. package/dist/index.js.map +1 -1
  31. package/dist/instructions/builder.d.ts.map +1 -1
  32. package/dist/instructions/builder.js +2 -1
  33. package/dist/instructions/builder.js.map +1 -1
  34. package/dist/openclaw/plugin-loader.d.ts.map +1 -1
  35. package/dist/openclaw/plugin-loader.js +8 -19
  36. package/dist/openclaw/plugin-loader.js.map +1 -1
  37. package/dist/openclaw/processor.d.ts.map +1 -1
  38. package/dist/openclaw/processor.js +2 -0
  39. package/dist/openclaw/processor.js.map +1 -1
  40. package/dist/openclaw/sandbox-leak.d.ts.map +1 -1
  41. package/dist/openclaw/sandbox-leak.js +1 -6
  42. package/dist/openclaw/sandbox-leak.js.map +1 -1
  43. package/dist/openclaw/session-context.d.ts.map +1 -1
  44. package/dist/openclaw/session-context.js +3 -0
  45. package/dist/openclaw/session-context.js.map +1 -1
  46. package/dist/openclaw/tool-policy.d.ts.map +1 -1
  47. package/dist/openclaw/tool-policy.js +5 -11
  48. package/dist/openclaw/tool-policy.js.map +1 -1
  49. package/dist/openclaw/worker.d.ts +0 -1
  50. package/dist/openclaw/worker.d.ts.map +1 -1
  51. package/dist/openclaw/worker.js +19 -85
  52. package/dist/openclaw/worker.js.map +1 -1
  53. package/dist/server.d.ts.map +1 -1
  54. package/dist/server.js +3 -40
  55. package/dist/server.js.map +1 -1
  56. package/dist/shared/audio-provider-suggestions.d.ts.map +1 -1
  57. package/dist/shared/audio-provider-suggestions.js +4 -6
  58. package/dist/shared/audio-provider-suggestions.js.map +1 -1
  59. package/dist/shared/tool-implementations.d.ts.map +1 -1
  60. package/dist/shared/tool-implementations.js +99 -37
  61. package/dist/shared/tool-implementations.js.map +1 -1
  62. package/package.json +14 -4
  63. package/src/__tests__/audio-provider-suggestions.test.ts +199 -0
  64. package/src/__tests__/custom-tools.test.ts +92 -0
  65. package/src/__tests__/embedded-just-bash-bootstrap.test.ts +128 -0
  66. package/src/__tests__/embedded-mcp-cli-bash.test.ts +179 -0
  67. package/src/__tests__/embedded-tools.test.ts +744 -0
  68. package/src/__tests__/exec-sandbox-extra.test.ts +0 -0
  69. package/src/__tests__/exec-sandbox.test.ts +550 -0
  70. package/src/__tests__/generated-media.test.ts +142 -0
  71. package/src/__tests__/instructions.test.ts +60 -0
  72. package/src/__tests__/mcp-cli-commands-extra.test.ts +478 -0
  73. package/src/__tests__/mcp-cli-commands.test.ts +383 -0
  74. package/src/__tests__/mcp-tool-call.test.ts +423 -0
  75. package/src/__tests__/memory-flush-harden.test.ts +367 -0
  76. package/src/__tests__/memory-flush-runtime.test.ts +138 -0
  77. package/src/__tests__/memory-flush.test.ts +64 -0
  78. package/src/__tests__/message-batcher.test.ts +247 -0
  79. package/src/__tests__/model-resolver-harden.test.ts +197 -0
  80. package/src/__tests__/model-resolver.test.ts +156 -0
  81. package/src/__tests__/processor-harden.test.ts +259 -0
  82. package/src/__tests__/processor.test.ts +225 -0
  83. package/src/__tests__/replace-base-prompt-identity.test.ts +41 -0
  84. package/src/__tests__/sandbox-leak-harden.test.ts +200 -0
  85. package/src/__tests__/sandbox-leak.test.ts +167 -0
  86. package/src/__tests__/setup.ts +102 -0
  87. package/src/__tests__/sse-client-harden.test.ts +588 -0
  88. package/src/__tests__/sse-client.test.ts +90 -0
  89. package/src/__tests__/tool-implementations.test.ts +196 -0
  90. package/src/__tests__/tool-policy-edge-cases.test.ts +263 -0
  91. package/src/__tests__/tool-policy.test.ts +269 -0
  92. package/src/__tests__/worker.test.ts +89 -0
  93. package/src/core/error-handler.ts +47 -0
  94. package/src/core/project-scanner.ts +65 -0
  95. package/src/core/types.ts +94 -0
  96. package/src/core/workspace.ts +66 -0
  97. package/src/embedded/exec-sandbox.ts +372 -0
  98. package/src/embedded/just-bash-bootstrap.ts +575 -0
  99. package/src/embedded/mcp-cli-commands.ts +405 -0
  100. package/src/gateway/gateway-integration.ts +298 -0
  101. package/src/gateway/message-batcher.ts +123 -0
  102. package/src/gateway/sse-client.ts +988 -0
  103. package/src/gateway/types.ts +68 -0
  104. package/src/index.ts +123 -0
  105. package/src/instructions/builder.ts +44 -0
  106. package/src/instructions/providers.ts +27 -0
  107. package/src/modules/lifecycle.ts +92 -0
  108. package/src/openclaw/custom-tools.ts +315 -0
  109. package/src/openclaw/instructions.ts +36 -0
  110. package/src/openclaw/model-resolver.ts +150 -0
  111. package/src/openclaw/plugin-loader.ts +423 -0
  112. package/src/openclaw/processor.ts +199 -0
  113. package/src/openclaw/sandbox-leak.ts +100 -0
  114. package/src/openclaw/session-context.ts +323 -0
  115. package/src/openclaw/tool-policy.ts +241 -0
  116. package/src/openclaw/tools.ts +277 -0
  117. package/src/openclaw/worker.ts +1836 -0
  118. package/src/server.ts +330 -0
  119. package/src/shared/audio-provider-suggestions.ts +130 -0
  120. package/src/shared/processor-utils.ts +33 -0
  121. package/src/shared/provider-auth-hints.ts +68 -0
  122. package/src/shared/tool-display-config.ts +75 -0
  123. package/src/shared/tool-implementations.ts +981 -0
  124. package/src/shared/worker-env-keys.ts +8 -0
@@ -0,0 +1,179 @@
1
+ import { afterEach, describe, expect, test } from "bun:test";
2
+ import fs from "node:fs";
3
+ import os from "node:os";
4
+ import path from "node:path";
5
+ import type { McpToolDef } from "@lobu/core";
6
+ import {
7
+ buildMcpCliCommands,
8
+ type McpCliDeps,
9
+ type McpRuntimeRef,
10
+ } from "../embedded/mcp-cli-commands";
11
+ import type { GatewayParams } from "../shared/tool-implementations";
12
+
13
+ const tempDirs: string[] = [];
14
+
15
+ afterEach(() => {
16
+ for (const dir of tempDirs.splice(0)) {
17
+ fs.rmSync(dir, { recursive: true, force: true });
18
+ }
19
+ });
20
+
21
+ const gw: GatewayParams = {
22
+ gatewayUrl: "http://gateway",
23
+ workerToken: "worker-token",
24
+ channelId: "channel-1",
25
+ conversationId: "conversation-1",
26
+ platform: "telegram",
27
+ };
28
+
29
+ const searchKnowledge: McpToolDef = {
30
+ name: "search_memory",
31
+ description: "Search memory",
32
+ inputSchema: {
33
+ type: "object",
34
+ properties: { query: { type: "string" } },
35
+ required: ["query"],
36
+ },
37
+ };
38
+
39
+ async function buildBash(options: {
40
+ ref: McpRuntimeRef;
41
+ callTool: (
42
+ mcpId: string,
43
+ toolName: string,
44
+ payload: Record<string, unknown>
45
+ ) => Promise<{ content: Array<{ type: "text"; text: string }> }>;
46
+ }) {
47
+ const { Bash, ReadWriteFs, defineCommand } = await import("just-bash");
48
+ const tmp = fs.mkdtempSync(path.join(os.tmpdir(), "lobu-mcp-cli-"));
49
+ tempDirs.push(tmp);
50
+
51
+ const callTool: McpCliDeps["callTool"] = async (
52
+ _gw,
53
+ mcpId,
54
+ toolName,
55
+ payload
56
+ ) => options.callTool(mcpId, toolName, payload);
57
+
58
+ const cliCommands = buildMcpCliCommands(options.ref, gw, { callTool });
59
+
60
+ const customCommands = cliCommands.map((c) =>
61
+ defineCommand(c.name, async (args: string[], ctx) => {
62
+ return c.execute(args, {
63
+ stdin: typeof ctx.stdin === "string" ? ctx.stdin : "",
64
+ });
65
+ })
66
+ );
67
+
68
+ const bash = new Bash({
69
+ fs: new ReadWriteFs({ root: tmp }),
70
+ cwd: "/",
71
+ env: { PATH: "/usr/bin:/bin" },
72
+ customCommands,
73
+ });
74
+
75
+ return bash;
76
+ }
77
+
78
+ describe("embedded MCP CLI through real just-bash", () => {
79
+ test("heredoc JSON on stdin reaches the handler as a parsed object", async () => {
80
+ const ref: McpRuntimeRef = {
81
+ current: {
82
+ mcpTools: { lobu: [searchKnowledge] },
83
+ mcpStatus: [],
84
+ mcpContext: {},
85
+ },
86
+ };
87
+ const calls: Array<{ payload: Record<string, unknown> }> = [];
88
+ const bash = await buildBash({
89
+ ref,
90
+ callTool: async (_mcpId, _toolName, payload) => {
91
+ calls.push({ payload });
92
+ return { content: [{ type: "text", text: "hit" }] };
93
+ },
94
+ });
95
+
96
+ const result = await bash.exec(
97
+ `lobu search_memory <<'EOF'
98
+ {"query":"architecture"}
99
+ EOF`,
100
+ { cwd: "/" }
101
+ );
102
+
103
+ expect(result.exitCode).toBe(0);
104
+ expect(result.stdout.trim()).toBe("hit");
105
+ expect(calls).toEqual([{ payload: { query: "architecture" } }]);
106
+ });
107
+
108
+ test("echo … | <server> <tool> routes the piped JSON into the handler", async () => {
109
+ const ref: McpRuntimeRef = {
110
+ current: {
111
+ mcpTools: { lobu: [searchKnowledge] },
112
+ mcpStatus: [],
113
+ mcpContext: {},
114
+ },
115
+ };
116
+ const calls: Array<{ payload: Record<string, unknown> }> = [];
117
+ const bash = await buildBash({
118
+ ref,
119
+ callTool: async (_mcpId, _toolName, payload) => {
120
+ calls.push({ payload });
121
+ return { content: [{ type: "text", text: "ok" }] };
122
+ },
123
+ });
124
+
125
+ const result = await bash.exec(
126
+ `echo '{"query":"piped"}' | lobu search_memory`,
127
+ { cwd: "/" }
128
+ );
129
+
130
+ expect(result.exitCode).toBe(0);
131
+ expect(calls).toEqual([{ payload: { query: "piped" } }]);
132
+ });
133
+
134
+ test("<server> --help lists the discovered tools", async () => {
135
+ const ref: McpRuntimeRef = {
136
+ current: {
137
+ mcpTools: { lobu: [searchKnowledge] },
138
+ mcpStatus: [
139
+ {
140
+ id: "lobu",
141
+ name: "Lobu",
142
+ requiresAuth: true,
143
+ requiresInput: false,
144
+ authenticated: true,
145
+ configured: true,
146
+ },
147
+ ],
148
+ mcpContext: {},
149
+ },
150
+ };
151
+ const bash = await buildBash({
152
+ ref,
153
+ callTool: async () => ({ content: [] }),
154
+ });
155
+
156
+ const result = await bash.exec("lobu --help", { cwd: "/" });
157
+ expect(result.exitCode).toBe(0);
158
+ expect(result.stdout).toContain("search_memory");
159
+ expect(result.stdout).toContain("auth login|check|logout");
160
+ });
161
+
162
+ test("unknown subcommand exits with stderr diagnostic", async () => {
163
+ const ref: McpRuntimeRef = {
164
+ current: {
165
+ mcpTools: { lobu: [] },
166
+ mcpStatus: [],
167
+ mcpContext: {},
168
+ },
169
+ };
170
+ const bash = await buildBash({
171
+ ref,
172
+ callTool: async () => ({ content: [] }),
173
+ });
174
+
175
+ const result = await bash.exec("lobu mystery", { cwd: "/" });
176
+ expect(result.exitCode).toBe(2);
177
+ expect(result.stderr).toContain("unknown tool");
178
+ });
179
+ });