@twsxtd/hapi-openclaw 0.1.5 → 0.1.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/index.js +21 -6
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -302,11 +302,13 @@ class RealOpenClawAdapter {
|
|
|
302
302
|
namespace;
|
|
303
303
|
runtime;
|
|
304
304
|
callbackClient;
|
|
305
|
+
logger;
|
|
305
306
|
supportsApprovals = false;
|
|
306
|
-
constructor(namespace, runtime, callbackClient) {
|
|
307
|
+
constructor(namespace, runtime, callbackClient, logger) {
|
|
307
308
|
this.namespace = namespace;
|
|
308
309
|
this.runtime = runtime;
|
|
309
310
|
this.callbackClient = callbackClient;
|
|
311
|
+
this.logger = logger;
|
|
310
312
|
}
|
|
311
313
|
async ensureDefaultConversation(externalUserKey) {
|
|
312
314
|
return {
|
|
@@ -322,6 +324,7 @@ class RealOpenClawAdapter {
|
|
|
322
324
|
throw new ConversationBusyError;
|
|
323
325
|
}
|
|
324
326
|
const namespace = getStateNamespace(action.conversationId, this.namespace);
|
|
327
|
+
this.logger.info(`[${namespace}] hapi-openclaw send-message start conversation=${action.conversationId}`);
|
|
325
328
|
await this.callbackClient.postEvent(createStateEvent({
|
|
326
329
|
namespace,
|
|
327
330
|
conversationId: action.conversationId,
|
|
@@ -331,14 +334,19 @@ class RealOpenClawAdapter {
|
|
|
331
334
|
try {
|
|
332
335
|
const config = this.runtime.config.loadConfig();
|
|
333
336
|
const agentId = parseHapiSessionKey(action.conversationId)?.agentId ?? getDefaultAgentId();
|
|
334
|
-
const workspaceDir = this.runtime.agent.
|
|
335
|
-
|
|
337
|
+
const workspaceDir = (await this.runtime.agent.ensureAgentWorkspace({
|
|
338
|
+
dir: this.runtime.agent.resolveAgentWorkspaceDir(config, agentId)
|
|
339
|
+
})).dir;
|
|
340
|
+
const agentDir = this.runtime.agent.resolveAgentDir(config, agentId);
|
|
336
341
|
const { sessionId, sessionFile } = await ensureSessionBinding(this.runtime, action.conversationId, agentId);
|
|
337
|
-
|
|
342
|
+
this.logger.info(`[${namespace}] hapi-openclaw runEmbeddedPiAgent sessionId=${sessionId} agentId=${agentId}`);
|
|
343
|
+
const result = await this.runtime.agent.runEmbeddedPiAgent({
|
|
338
344
|
sessionId,
|
|
339
345
|
sessionKey: action.conversationId,
|
|
340
346
|
sessionFile,
|
|
341
347
|
workspaceDir,
|
|
348
|
+
agentDir,
|
|
349
|
+
config,
|
|
342
350
|
agentId,
|
|
343
351
|
prompt: action.text,
|
|
344
352
|
timeoutMs: this.runtime.agent.resolveAgentTimeoutMs({ cfg: config }),
|
|
@@ -347,6 +355,7 @@ class RealOpenClawAdapter {
|
|
|
347
355
|
});
|
|
348
356
|
const runError = result.meta.error?.message?.trim() || null;
|
|
349
357
|
if (runError) {
|
|
358
|
+
this.logger.warn(`[${namespace}] hapi-openclaw run failed conversation=${action.conversationId}: ${runError}`);
|
|
350
359
|
if (adapterState.finishRun(action.conversationId)) {
|
|
351
360
|
await this.callbackClient.postEvent(createStateEvent({
|
|
352
361
|
namespace,
|
|
@@ -357,6 +366,7 @@ class RealOpenClawAdapter {
|
|
|
357
366
|
}
|
|
358
367
|
return;
|
|
359
368
|
}
|
|
369
|
+
this.logger.info(`[${namespace}] hapi-openclaw run completed conversation=${action.conversationId}` + (result.meta.finalAssistantVisibleText ? ` finalText=${JSON.stringify(result.meta.finalAssistantVisibleText)}` : ""));
|
|
360
370
|
if (result.meta.finalAssistantVisibleText) {
|
|
361
371
|
await delay(RUN_COMPLETION_SETTLE_MS);
|
|
362
372
|
}
|
|
@@ -370,6 +380,7 @@ class RealOpenClawAdapter {
|
|
|
370
380
|
}
|
|
371
381
|
} catch (error2) {
|
|
372
382
|
const message = error2 instanceof Error ? error2.message : "OpenClaw embedded run failed";
|
|
383
|
+
this.logger.error(`[${namespace}] hapi-openclaw send-message error conversation=${action.conversationId}: ${message}`);
|
|
373
384
|
if (adapterState.finishRun(action.conversationId)) {
|
|
374
385
|
await this.callbackClient.postEvent(createStateEvent({
|
|
375
386
|
namespace,
|
|
@@ -2201,6 +2212,7 @@ function createPluginApp(deps) {
|
|
|
2201
2212
|
retryAfterMs: null
|
|
2202
2213
|
};
|
|
2203
2214
|
deps.idempotencyCache.set(idempotencyKey, ack);
|
|
2215
|
+
deps.logger.info(`[${deps.namespace}] hapi-openclaw accepted send-message conversation=${body.conversationId} localMessageId=${body.localMessageId}`);
|
|
2204
2216
|
queueMicrotask(() => {
|
|
2205
2217
|
deps.runtime.sendMessage({
|
|
2206
2218
|
kind: "send-message",
|
|
@@ -2211,8 +2223,10 @@ function createPluginApp(deps) {
|
|
|
2211
2223
|
await dispatchMaybeEvents(deps.callbackClient, events);
|
|
2212
2224
|
}).catch((error2) => {
|
|
2213
2225
|
if (error2 instanceof ConversationBusyError) {
|
|
2226
|
+
deps.logger.warn(`[${deps.namespace}] hapi-openclaw conversation busy conversation=${body.conversationId}`);
|
|
2214
2227
|
return;
|
|
2215
2228
|
}
|
|
2229
|
+
deps.logger.error(`[${deps.namespace}] hapi-openclaw send-message task failed conversation=${body.conversationId}: ` + (error2 instanceof Error ? error2.message : String(error2)));
|
|
2216
2230
|
});
|
|
2217
2231
|
});
|
|
2218
2232
|
return c.json(ack);
|
|
@@ -2307,7 +2321,7 @@ function resolveRegisteredPluginConfig(api) {
|
|
|
2307
2321
|
function registerPluginRoutes(api) {
|
|
2308
2322
|
const config = resolveRegisteredPluginConfig(api);
|
|
2309
2323
|
const callbackClient = new HapiCallbackClient(config.hapiBaseUrl, config.sharedSecret);
|
|
2310
|
-
const runtime = new RealOpenClawAdapter(config.namespace, api.runtime, callbackClient);
|
|
2324
|
+
const runtime = new RealOpenClawAdapter(config.namespace, api.runtime, callbackClient, api.logger);
|
|
2311
2325
|
const app = createPluginApp({
|
|
2312
2326
|
sharedSecret: config.sharedSecret,
|
|
2313
2327
|
namespace: config.namespace,
|
|
@@ -2315,7 +2329,8 @@ function registerPluginRoutes(api) {
|
|
|
2315
2329
|
runtime,
|
|
2316
2330
|
idempotencyCache: new Map,
|
|
2317
2331
|
prototypeCaptureSessionKey: config.prototypeCaptureSessionKey,
|
|
2318
|
-
prototypeCaptureFileName: config.prototypeCaptureFileName
|
|
2332
|
+
prototypeCaptureFileName: config.prototypeCaptureFileName,
|
|
2333
|
+
logger: api.logger
|
|
2319
2334
|
});
|
|
2320
2335
|
api.registerHttpRoute({
|
|
2321
2336
|
path: "/hapi",
|