@web42/cli 0.2.5 → 0.2.7
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/commands/serve.js +36 -5
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
package/dist/commands/serve.js
CHANGED
|
@@ -10,13 +10,19 @@ import { requireAuth } from '../utils/config.js';
|
|
|
10
10
|
import { getConfig } from '../utils/config.js';
|
|
11
11
|
class OpenClawAgentExecutor {
|
|
12
12
|
opts;
|
|
13
|
+
verbose;
|
|
13
14
|
constructor(opts) {
|
|
14
15
|
this.opts = opts;
|
|
16
|
+
this.verbose = opts.verbose ?? false;
|
|
15
17
|
}
|
|
16
18
|
async execute(requestContext, eventBus) {
|
|
17
19
|
const { taskId, contextId, userMessage } = requestContext;
|
|
18
20
|
const userText = userMessage.parts
|
|
19
21
|
.find((p) => p.kind === 'text')?.text ?? '';
|
|
22
|
+
if (this.verbose) {
|
|
23
|
+
console.log(chalk.gray(`[verbose] → OpenClaw request: agent=${this.opts.openClawAgent} session=${contextId} port=${this.opts.openClawPort}`));
|
|
24
|
+
console.log(chalk.gray(`[verbose] → message text: "${userText.slice(0, 100)}"`));
|
|
25
|
+
}
|
|
20
26
|
let response;
|
|
21
27
|
try {
|
|
22
28
|
response = await fetch(`http://localhost:${this.opts.openClawPort}/v1/chat/completions`, {
|
|
@@ -25,7 +31,7 @@ class OpenClawAgentExecutor {
|
|
|
25
31
|
Authorization: `Bearer ${this.opts.openClawToken}`,
|
|
26
32
|
'Content-Type': 'application/json',
|
|
27
33
|
'x-openclaw-agent-id': this.opts.openClawAgent,
|
|
28
|
-
'x-openclaw-session-key': contextId
|
|
34
|
+
'x-openclaw-session-key': `agent:${this.opts.openClawAgent}:${contextId}`,
|
|
29
35
|
},
|
|
30
36
|
body: JSON.stringify({
|
|
31
37
|
model: 'openclaw',
|
|
@@ -38,12 +44,20 @@ class OpenClawAgentExecutor {
|
|
|
38
44
|
throw new Error(`OpenClaw is not reachable on port ${this.opts.openClawPort}. ` +
|
|
39
45
|
`Make sure it is running with chatCompletions enabled. (${String(err)})`);
|
|
40
46
|
}
|
|
47
|
+
if (this.verbose) {
|
|
48
|
+
console.log(chalk.gray(`[verbose] ← OpenClaw response: status=${response.status}`));
|
|
49
|
+
}
|
|
41
50
|
if (!response.ok) {
|
|
51
|
+
if (this.verbose) {
|
|
52
|
+
const body = await response.text().catch(() => '(unreadable)');
|
|
53
|
+
console.log(chalk.gray(`[verbose] ← response body: ${body}`));
|
|
54
|
+
}
|
|
42
55
|
throw new Error(`OpenClaw error: ${response.status} ${response.statusText}`);
|
|
43
56
|
}
|
|
44
57
|
const reader = response.body.getReader();
|
|
45
58
|
const decoder = new TextDecoder();
|
|
46
59
|
let buffer = '';
|
|
60
|
+
let tokenCount = 0;
|
|
47
61
|
while (true) {
|
|
48
62
|
const { done, value } = await reader.read();
|
|
49
63
|
if (done)
|
|
@@ -61,6 +75,7 @@ class OpenClawAgentExecutor {
|
|
|
61
75
|
const chunk = JSON.parse(data);
|
|
62
76
|
const token = chunk.choices?.[0]?.delta?.content;
|
|
63
77
|
if (token) {
|
|
78
|
+
tokenCount++;
|
|
64
79
|
eventBus.publish({
|
|
65
80
|
kind: 'artifact-update',
|
|
66
81
|
taskId,
|
|
@@ -77,6 +92,9 @@ class OpenClawAgentExecutor {
|
|
|
77
92
|
}
|
|
78
93
|
}
|
|
79
94
|
}
|
|
95
|
+
if (this.verbose) {
|
|
96
|
+
console.log(chalk.gray(`[verbose] ← stream complete: ${tokenCount} tokens received`));
|
|
97
|
+
}
|
|
80
98
|
eventBus.publish({
|
|
81
99
|
kind: 'status-update',
|
|
82
100
|
taskId,
|
|
@@ -122,7 +140,9 @@ export const serveCommand = new Command('serve')
|
|
|
122
140
|
.option('--openclaw-port <port>', 'OpenClaw gateway port', '18789')
|
|
123
141
|
.option('--openclaw-token <token>', 'OpenClaw gateway auth token (or set OPENCLAW_GATEWAY_TOKEN)')
|
|
124
142
|
.option('--openclaw-agent <id>', 'OpenClaw agent ID to target', 'main')
|
|
143
|
+
.option('--verbose', 'Enable verbose request/response logging')
|
|
125
144
|
.action(async (opts) => {
|
|
145
|
+
const verbose = opts.verbose ?? false;
|
|
126
146
|
// 1. Must be logged into web42
|
|
127
147
|
let token;
|
|
128
148
|
try {
|
|
@@ -189,17 +209,24 @@ export const serveCommand = new Command('serve')
|
|
|
189
209
|
const app = express();
|
|
190
210
|
// Auth: validate caller's web42 Bearer token against marketplace introspect endpoint
|
|
191
211
|
const userBuilder = async (req) => {
|
|
192
|
-
const
|
|
193
|
-
if (!
|
|
212
|
+
const callerToken = req.headers.authorization?.split(' ')[1];
|
|
213
|
+
if (!callerToken)
|
|
194
214
|
throw new Error('Missing token');
|
|
215
|
+
if (verbose) {
|
|
216
|
+
const masked = `${callerToken.slice(0, 8)}...`;
|
|
217
|
+
console.log(chalk.gray(`[verbose] userBuilder: token=${masked} → introspecting...`));
|
|
218
|
+
}
|
|
195
219
|
const res = await fetch(`${web42ApiUrl}/api/auth/introspect`, {
|
|
196
220
|
method: 'POST',
|
|
197
221
|
headers: { 'Content-Type': 'application/json' },
|
|
198
|
-
body: JSON.stringify({ token }),
|
|
222
|
+
body: JSON.stringify({ token: callerToken }),
|
|
199
223
|
});
|
|
200
224
|
if (!res.ok)
|
|
201
225
|
throw new Error('Introspect call failed');
|
|
202
226
|
const result = (await res.json());
|
|
227
|
+
if (verbose) {
|
|
228
|
+
console.log(chalk.gray(`[verbose] userBuilder: token=${callerToken.slice(0, 8)}... → active=${result.active} sub=${result.sub ?? '(none)'}`));
|
|
229
|
+
}
|
|
203
230
|
if (!result.active)
|
|
204
231
|
throw new Error('Unauthorized');
|
|
205
232
|
const userId = result.sub ?? '';
|
|
@@ -208,7 +235,7 @@ export const serveCommand = new Command('serve')
|
|
|
208
235
|
get userName() { return userId; },
|
|
209
236
|
};
|
|
210
237
|
};
|
|
211
|
-
const executor = new OpenClawAgentExecutor({ openClawPort, openClawToken, openClawAgent });
|
|
238
|
+
const executor = new OpenClawAgentExecutor({ openClawPort, openClawToken, openClawAgent, verbose });
|
|
212
239
|
const requestHandler = new DefaultRequestHandler(agentCard, new InMemoryTaskStore(), executor);
|
|
213
240
|
// 5. Mount A2A SDK handlers
|
|
214
241
|
app.use('/.well-known/agent-card.json', agentCardHandler({ agentCardProvider: requestHandler }));
|
|
@@ -223,6 +250,10 @@ export const serveCommand = new Command('serve')
|
|
|
223
250
|
console.log(chalk.dim(` Public: ${publicUrl}`));
|
|
224
251
|
console.log(chalk.dim(` Agent card: http://localhost:${port}/.well-known/agent-card.json`));
|
|
225
252
|
console.log(chalk.dim(` JSON-RPC: http://localhost:${port}/a2a/jsonrpc`));
|
|
253
|
+
if (verbose) {
|
|
254
|
+
console.log(chalk.gray(`[verbose] agent card url: http://localhost:${port}/.well-known/agent-card.json`));
|
|
255
|
+
console.log(chalk.gray(`[verbose] openclaw target: http://localhost:${openClawPort}/v1/chat/completions agent=${openClawAgent}`));
|
|
256
|
+
}
|
|
226
257
|
await publishLiveUrl({
|
|
227
258
|
apiUrl: web42ApiUrl,
|
|
228
259
|
token,
|
package/dist/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const CLI_VERSION = "0.2.
|
|
1
|
+
export declare const CLI_VERSION = "0.2.7";
|
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const CLI_VERSION = "0.2.
|
|
1
|
+
export const CLI_VERSION = "0.2.7";
|