@twsxtd/hapi-openclaw 0.1.7 → 0.1.8
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 +42 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -251,6 +251,8 @@ function stripReplyToCurrentPrefix(text) {
|
|
|
251
251
|
// src/openclawAdapter.ts
|
|
252
252
|
var CONVERSATION_TITLE = "OpenClaw";
|
|
253
253
|
var RUN_COMPLETION_SETTLE_MS = 50;
|
|
254
|
+
var DEFAULT_PROVIDER = "openai";
|
|
255
|
+
var DEFAULT_MODEL = "gpt-5.4";
|
|
254
256
|
|
|
255
257
|
class ConversationBusyError extends Error {
|
|
256
258
|
constructor() {
|
|
@@ -275,6 +277,42 @@ function getStateNamespace(sessionKey, fallbackNamespace) {
|
|
|
275
277
|
function delay(ms) {
|
|
276
278
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
277
279
|
}
|
|
280
|
+
function readPrimaryModelRef(value) {
|
|
281
|
+
if (typeof value === "string" && value.trim().length > 0) {
|
|
282
|
+
return value.trim();
|
|
283
|
+
}
|
|
284
|
+
if (typeof value === "object" && value !== null && !Array.isArray(value)) {
|
|
285
|
+
const primary = value.primary;
|
|
286
|
+
return typeof primary === "string" && primary.trim().length > 0 ? primary.trim() : null;
|
|
287
|
+
}
|
|
288
|
+
return null;
|
|
289
|
+
}
|
|
290
|
+
function resolvePreferredModelRef(config, agentId) {
|
|
291
|
+
const agents = typeof config.agents === "object" && config.agents !== null ? config.agents : null;
|
|
292
|
+
const list = Array.isArray(agents?.list) ? agents.list : [];
|
|
293
|
+
const matchedAgent = list.find((entry) => {
|
|
294
|
+
return typeof entry === "object" && entry !== null && entry.id === agentId;
|
|
295
|
+
});
|
|
296
|
+
const defaults = typeof agents?.defaults === "object" && agents.defaults !== null ? agents.defaults : null;
|
|
297
|
+
const rawRef = readPrimaryModelRef(matchedAgent?.model) ?? readPrimaryModelRef(defaults?.model);
|
|
298
|
+
if (!rawRef) {
|
|
299
|
+
return {
|
|
300
|
+
provider: DEFAULT_PROVIDER,
|
|
301
|
+
model: DEFAULT_MODEL
|
|
302
|
+
};
|
|
303
|
+
}
|
|
304
|
+
const separatorIndex = rawRef.indexOf("/");
|
|
305
|
+
if (separatorIndex <= 0 || separatorIndex === rawRef.length - 1) {
|
|
306
|
+
return {
|
|
307
|
+
provider: DEFAULT_PROVIDER,
|
|
308
|
+
model: rawRef
|
|
309
|
+
};
|
|
310
|
+
}
|
|
311
|
+
return {
|
|
312
|
+
provider: rawRef.slice(0, separatorIndex).trim() || DEFAULT_PROVIDER,
|
|
313
|
+
model: rawRef.slice(separatorIndex + 1).trim() || DEFAULT_MODEL
|
|
314
|
+
};
|
|
315
|
+
}
|
|
278
316
|
async function ensureSessionBinding(runtime, sessionKey, agentId) {
|
|
279
317
|
const storePath = runtime.agent.session.resolveStorePath(undefined, { agentId });
|
|
280
318
|
const store = runtime.agent.session.loadSessionStore(storePath);
|
|
@@ -338,8 +376,9 @@ class RealOpenClawAdapter {
|
|
|
338
376
|
dir: this.runtime.agent.resolveAgentWorkspaceDir(config, agentId)
|
|
339
377
|
})).dir;
|
|
340
378
|
const agentDir = this.runtime.agent.resolveAgentDir(config, agentId);
|
|
379
|
+
const modelRef = resolvePreferredModelRef(config, agentId);
|
|
341
380
|
const { sessionId, sessionFile } = await ensureSessionBinding(this.runtime, action.conversationId, agentId);
|
|
342
|
-
this.logger.info(`[${namespace}] hapi-openclaw runEmbeddedPiAgent sessionId=${sessionId} agentId=${agentId}`);
|
|
381
|
+
this.logger.info(`[${namespace}] hapi-openclaw runEmbeddedPiAgent sessionId=${sessionId} agentId=${agentId} ` + `provider=${modelRef.provider} model=${modelRef.model}`);
|
|
343
382
|
const result = await this.runtime.agent.runEmbeddedPiAgent({
|
|
344
383
|
sessionId,
|
|
345
384
|
sessionKey: action.conversationId,
|
|
@@ -349,6 +388,8 @@ class RealOpenClawAdapter {
|
|
|
349
388
|
config,
|
|
350
389
|
agentId,
|
|
351
390
|
prompt: action.text,
|
|
391
|
+
provider: modelRef.provider,
|
|
392
|
+
model: modelRef.model,
|
|
352
393
|
timeoutMs: this.runtime.agent.resolveAgentTimeoutMs({ cfg: config }),
|
|
353
394
|
runId: randomUUID(),
|
|
354
395
|
trigger: "user"
|