@openclaw/muse 2026.11.5 → 2026.11.10-beta.1
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.
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { isRecord } from "openclaw/plugin-sdk/string-coerce-runtime";
|
|
2
2
|
import fs, { realpath } from "node:fs/promises";
|
|
3
3
|
import { createAgentHarnessAttemptLifecycle, emitAgentHarnessAttemptEvent, makeZeroUsageSnapshot, resolveAgentHarnessHistoryLimits } from "openclaw/plugin-sdk/agent-harness-attempt-runtime";
|
|
4
|
-
import { AgentHarnessPreflightError, agentHarnessAttemptTerminal, clearActiveEmbeddedRun, embeddedAgentLog, execPolicy, projectAgentToolActivity, resolveBootstrapContextForRun, setActiveEmbeddedRun } from "openclaw/plugin-sdk/agent-harness-runtime";
|
|
4
|
+
import { AgentHarnessPreflightError, agentHarnessAttemptTerminal, clearActiveEmbeddedRun, embeddedAgentLog, execPolicy, normalizeUsage, projectAgentToolActivity, resolveBootstrapContextForRun, setActiveEmbeddedRun } from "openclaw/plugin-sdk/agent-harness-runtime";
|
|
5
5
|
import { createNativeSessionCommitFinalizer } from "openclaw/plugin-sdk/agent-harness-session-runtime";
|
|
6
6
|
import { resolveAgentConfig, resolveSessionAgentIdsStrict } from "openclaw/plugin-sdk/agent-scope-runtime";
|
|
7
7
|
import { SessionManager } from "openclaw/plugin-sdk/agent-sessions";
|
|
@@ -15,7 +15,8 @@ import { createHash } from "node:crypto";
|
|
|
15
15
|
import path from "node:path";
|
|
16
16
|
import { MspError, Session, readSessionDurability, spawnMspConnection } from "@muse-code/sdk";
|
|
17
17
|
import { resolveStateDir } from "openclaw/plugin-sdk/state-paths";
|
|
18
|
-
|
|
18
|
+
import { racePromiseWithAbortSignal } from "openclaw/plugin-sdk/time-runtime";
|
|
19
|
+
// extensions/muse/src/events.ts
|
|
19
20
|
function assistantMessage(params, content, stopReason = "stop") {
|
|
20
21
|
return {
|
|
21
22
|
role: "assistant",
|
|
@@ -199,11 +200,9 @@ async function consumeTurn(turn, params, record) {
|
|
|
199
200
|
outcome: await turn.completed
|
|
200
201
|
};
|
|
201
202
|
}
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
//#endregion
|
|
206
|
-
//#region extensions/muse/src/runtime.ts
|
|
203
|
+
// extensions/muse/package.json
|
|
204
|
+
var version = "2026.11.10-beta.1";
|
|
205
|
+
// extensions/muse/src/runtime.ts
|
|
207
206
|
const RESUME_RETRY_KINDS = {
|
|
208
207
|
sessionInUse: true,
|
|
209
208
|
overloaded: true,
|
|
@@ -370,15 +369,19 @@ var MusePool = class {
|
|
|
370
369
|
};
|
|
371
370
|
signal.addEventListener("abort", abort, { once: true });
|
|
372
371
|
try {
|
|
373
|
-
const host = await handshake.initialize({
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
372
|
+
const host = await handshake.initialize({
|
|
373
|
+
clientInfo: {
|
|
374
|
+
name: "openclaw",
|
|
375
|
+
version
|
|
376
|
+
},
|
|
377
|
+
capabilities: { userInputDialogs: false }
|
|
378
|
+
});
|
|
377
379
|
signal.throwIfAborted();
|
|
378
380
|
const runtime = {
|
|
379
381
|
host,
|
|
380
382
|
credentialIdentity,
|
|
381
383
|
sessions: /* @__PURE__ */ new Map(),
|
|
384
|
+
usageObservers: /* @__PURE__ */ new Map(),
|
|
382
385
|
users: 0,
|
|
383
386
|
dead: false,
|
|
384
387
|
closing: false,
|
|
@@ -390,7 +393,10 @@ var MusePool = class {
|
|
|
390
393
|
};
|
|
391
394
|
host.connection.onNotification((event) => {
|
|
392
395
|
const sessionId = event.params?.sessionId;
|
|
393
|
-
if (typeof sessionId === "string")
|
|
396
|
+
if (typeof sessionId === "string") {
|
|
397
|
+
if (event.method === "session/tokenUsage") runtime.usageObservers.get(sessionId)?.(event.params);
|
|
398
|
+
runtime.sessions.get(sessionId)?.apply(event);
|
|
399
|
+
}
|
|
394
400
|
});
|
|
395
401
|
host.connection.onProtocolError(() => {
|
|
396
402
|
runtime.close();
|
|
@@ -422,8 +428,42 @@ var MusePool = class {
|
|
|
422
428
|
}));
|
|
423
429
|
}
|
|
424
430
|
};
|
|
425
|
-
|
|
426
|
-
|
|
431
|
+
// extensions/muse/src/usage.ts
|
|
432
|
+
const tokenCount = (value) => typeof value === "number" && Number.isSafeInteger(value) && value >= 0 ? value : void 0;
|
|
433
|
+
/** One MSP `session/tokenUsage` (one per model completion) for this turn, or undefined. */
|
|
434
|
+
function readMuseCompletionUsage(params, turnId) {
|
|
435
|
+
if (!turnId || !isRecord(params) || params.turnId !== turnId) return;
|
|
436
|
+
const prompt = tokenCount(params.promptTokens);
|
|
437
|
+
const total = tokenCount(params.totalTokens);
|
|
438
|
+
const reasoning = isRecord(params.usage) ? tokenCount(params.usage.reasoningTokens) : void 0;
|
|
439
|
+
return prompt !== void 0 && total !== void 0 && total >= prompt ? {
|
|
440
|
+
prompt,
|
|
441
|
+
total,
|
|
442
|
+
reasoning: reasoning ?? 0
|
|
443
|
+
} : void 0;
|
|
444
|
+
}
|
|
445
|
+
function museTurnUsage(notices, turnId) {
|
|
446
|
+
const completions = notices.flatMap((notice) => readMuseCompletionUsage(notice, turnId) ?? []);
|
|
447
|
+
const last = completions.at(-1);
|
|
448
|
+
if (!last) return;
|
|
449
|
+
const sum = (key) => completions.reduce((total, completion) => total + completion[key], 0);
|
|
450
|
+
const usage = normalizeUsage({
|
|
451
|
+
usageReport: { state: "available" },
|
|
452
|
+
input: sum("prompt"),
|
|
453
|
+
output: sum("total") - sum("prompt"),
|
|
454
|
+
reasoningTokens: sum("reasoning"),
|
|
455
|
+
total: sum("total")
|
|
456
|
+
});
|
|
457
|
+
return usage && {
|
|
458
|
+
...usage,
|
|
459
|
+
contextUsage: {
|
|
460
|
+
state: "available",
|
|
461
|
+
promptTokens: last.prompt,
|
|
462
|
+
totalTokens: last.total
|
|
463
|
+
}
|
|
464
|
+
};
|
|
465
|
+
}
|
|
466
|
+
// extensions/muse/src/verify-setup.ts
|
|
427
467
|
function museDisplayName(modelId, displayLabel) {
|
|
428
468
|
const label = typeof displayLabel === "string" ? displayLabel : modelId;
|
|
429
469
|
if (label === modelId || modelId === "muse-wonder-full-1.0-contributor" && label === "muse-wonder-1.0-contributor") switch (modelId) {
|
|
@@ -435,6 +475,9 @@ function museDisplayName(modelId, displayLabel) {
|
|
|
435
475
|
}
|
|
436
476
|
/** One lifecycle owner for read-only catalog hosts; every read still asks Meta for live access. */
|
|
437
477
|
var MuseCatalogReader = class {
|
|
478
|
+
constructor() {
|
|
479
|
+
this.retireWhenIdle = /* @__PURE__ */ new WeakSet();
|
|
480
|
+
}
|
|
438
481
|
async read(ctx) {
|
|
439
482
|
ctx.signal.throwIfAborted();
|
|
440
483
|
ctx.assertCurrent();
|
|
@@ -451,14 +494,10 @@ var MuseCatalogReader = class {
|
|
|
451
494
|
ctx.assertCurrent();
|
|
452
495
|
}
|
|
453
496
|
const lease = await this.current.pool.acquire(void 0, void 0, true, ctx.signal);
|
|
454
|
-
const abort = () => {
|
|
455
|
-
lease.runtime.close();
|
|
456
|
-
};
|
|
457
|
-
ctx.signal.addEventListener("abort", abort, { once: true });
|
|
458
497
|
try {
|
|
459
498
|
ctx.signal.throwIfAborted();
|
|
460
499
|
ctx.assertCurrent();
|
|
461
|
-
const catalog = await lease.runtime.host.connection.request("model/list", {});
|
|
500
|
+
const catalog = await racePromiseWithAbortSignal(lease.runtime.host.connection.request("model/list", {}), ctx.signal, (aborted) => aborted.reason);
|
|
462
501
|
ctx.signal.throwIfAborted();
|
|
463
502
|
ctx.assertCurrent();
|
|
464
503
|
if (catalog.source !== "providerCatalog" || catalog.providerId !== "meta" || !Array.isArray(catalog.models)) throw new Error("Muse Code could not authenticate. Sign in again to access Meta models.");
|
|
@@ -469,8 +508,9 @@ var MuseCatalogReader = class {
|
|
|
469
508
|
nativeRuntime: "muse"
|
|
470
509
|
}] : []);
|
|
471
510
|
} finally {
|
|
472
|
-
ctx.signal.
|
|
511
|
+
if (ctx.signal.aborted) this.retireWhenIdle.add(lease.runtime);
|
|
473
512
|
lease.release();
|
|
513
|
+
if (lease.runtime.users === 0 && this.retireWhenIdle.has(lease.runtime)) await lease.runtime.close();
|
|
474
514
|
}
|
|
475
515
|
}
|
|
476
516
|
async verify(ctx) {
|
|
@@ -480,8 +520,7 @@ var MuseCatalogReader = class {
|
|
|
480
520
|
await this.current?.pool.dispose();
|
|
481
521
|
}
|
|
482
522
|
};
|
|
483
|
-
|
|
484
|
-
//#region extensions/muse/harness.ts
|
|
523
|
+
// extensions/muse/harness.ts
|
|
485
524
|
/** Configuration Muse cannot honor; the message is safe and actionable for the chat user. */
|
|
486
525
|
function museRefusal(message) {
|
|
487
526
|
return new AgentHarnessPreflightError(message, {
|
|
@@ -598,6 +637,7 @@ function createMuseAgentHarness(options) {
|
|
|
598
637
|
let failure;
|
|
599
638
|
let activeAttachment;
|
|
600
639
|
const messages = [];
|
|
640
|
+
const tokenUsage = [];
|
|
601
641
|
let text = "";
|
|
602
642
|
let lastToolError;
|
|
603
643
|
let assistantTranscriptOwned = false;
|
|
@@ -689,6 +729,7 @@ function createMuseAgentHarness(options) {
|
|
|
689
729
|
options.logger?.warn(`${message}; started a new Muse session.`);
|
|
690
730
|
}
|
|
691
731
|
});
|
|
732
|
+
runtime.usageObservers.set(session.sessionId, (usage) => tokenUsage.push(usage));
|
|
692
733
|
assertDispatchActive();
|
|
693
734
|
let sessionContext = "";
|
|
694
735
|
if (freshSession) {
|
|
@@ -756,7 +797,7 @@ function createMuseAgentHarness(options) {
|
|
|
756
797
|
return selectApprovalChoice(request, decision);
|
|
757
798
|
});
|
|
758
799
|
session.onApprovalError((error) => {
|
|
759
|
-
failure = /* @__PURE__ */ new Error(`Muse approval failed (${error.kind}): ${error.kind === "unofferedChoice" ? `choice ${error.choiceId} was not offered` : formatErrorMessage(error.error)}`);
|
|
800
|
+
failure = /* @__PURE__ */ new Error(`Muse approval failed (${error.kind}): ${error.kind === "unofferedChoice" ? `choice ${error.choiceId} was not offered` : error.kind === "feedbackNotAccepted" ? `choice ${error.choiceId} does not accept feedback` : formatErrorMessage(error.error)}`);
|
|
760
801
|
stop().catch(() => runtime.close());
|
|
761
802
|
});
|
|
762
803
|
assertDispatchActive();
|
|
@@ -833,7 +874,9 @@ function createMuseAgentHarness(options) {
|
|
|
833
874
|
if (result.outcome.kind !== "completed") throw new Error(`Muse turn ended without a terminal result (${result.outcome.kind}).`);
|
|
834
875
|
if (result.outcome.params.terminal === "failed") {
|
|
835
876
|
const turnError = result.outcome.params.error;
|
|
836
|
-
|
|
877
|
+
const quota = turnError?.quota;
|
|
878
|
+
const authRequired = turnError?.kind === "authRequired";
|
|
879
|
+
throw Object.assign(new Error(quota ? `Muse usage limit reached (${quota.limitKind}); resets at ${new Date(quota.resetsAtMs).toISOString()}. ${turnError.message}` : authRequired ? `Muse Code is not signed in on the Gateway host (${turnError.message}). Run \`muse login\` there, or set META_API_KEY for the Gateway.` : turnError?.message ?? result.outcome.params.reason ?? "Muse model request failed. Run muse to check login and model access."), quota ? { status: 429 } : authRequired ? { status: 401 } : {});
|
|
837
880
|
}
|
|
838
881
|
if (result.outcome.params.terminal === "cancelled" && !failure) aborted = true;
|
|
839
882
|
lifecycle.emitLifecycleTerminal({ phase: "end" });
|
|
@@ -852,10 +895,14 @@ function createMuseAgentHarness(options) {
|
|
|
852
895
|
signal?.removeEventListener("abort", onAbort);
|
|
853
896
|
active.delete(params.sessionId);
|
|
854
897
|
clearActiveEmbeddedRun(params.sessionId, handle, params.sessionKey, params.sessionFile, void 0, activeAttachment);
|
|
898
|
+
runtime.usageObservers.delete(session?.sessionId ?? "");
|
|
855
899
|
bound?.release();
|
|
856
900
|
lease.release();
|
|
857
901
|
}
|
|
858
|
-
const toolMetas = messages.filter((message) => message.role === "toolResult").map((message) => ({
|
|
902
|
+
const toolMetas = messages.filter((message) => message.role === "toolResult").map((message) => ({
|
|
903
|
+
toolName: message.toolName,
|
|
904
|
+
isError: message.isError
|
|
905
|
+
}));
|
|
859
906
|
const interruption = timedOut ? {
|
|
860
907
|
kind: "timeout",
|
|
861
908
|
phase: "prompt",
|
|
@@ -868,7 +915,7 @@ function createMuseAgentHarness(options) {
|
|
|
868
915
|
if (failureMessage) options.logger?.warn(failureMessage);
|
|
869
916
|
const terminal = failureMessage ? agentHarnessAttemptTerminal.setFailure(interruption, {
|
|
870
917
|
source: "prompt",
|
|
871
|
-
error: new Error(failureMessage)
|
|
918
|
+
error: new Error(failureMessage, { cause: failure })
|
|
872
919
|
}) : interruption;
|
|
873
920
|
const lastAssistant = messages.findLast((message) => message.role === "assistant");
|
|
874
921
|
return {
|
|
@@ -882,6 +929,7 @@ function createMuseAgentHarness(options) {
|
|
|
882
929
|
assistantTranscriptIdempotencyKey: finalKey,
|
|
883
930
|
toolMetas,
|
|
884
931
|
lastToolError,
|
|
932
|
+
attemptUsage: museTurnUsage(tokenUsage, turn?.turnId),
|
|
885
933
|
cloudCodeAssistFormatError: false,
|
|
886
934
|
didSendViaMessagingTool: false,
|
|
887
935
|
itemLifecycle: {
|
|
@@ -992,5 +1040,4 @@ function createMuseAgentHarness(options) {
|
|
|
992
1040
|
}
|
|
993
1041
|
};
|
|
994
1042
|
}
|
|
995
|
-
//#endregion
|
|
996
1043
|
export { createMuseAgentHarness as t };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"entries":[{"output":"harness.js","source":"extensions/muse/harness.ts"},{"output":"index.js","source":"extensions/muse/index.ts"}],"chunks":[{"output":".setup/harness-
|
|
1
|
+
{"version":3,"entries":[{"output":"harness.js","source":"extensions/muse/harness.ts"},{"output":"index.js","source":"extensions/muse/index.ts"}],"chunks":[{"output":".setup/harness-CzfspMQy.mjs","sha256":"b86ffcb92277541e663caf227f5908f1c2d5d99b913d0ce12a591ef4d658eeb4","facadeSource":null,"sources":["extensions/muse/harness.ts","extensions/muse/package.json","extensions/muse/src/events.ts","extensions/muse/src/runtime.ts","extensions/muse/src/usage.ts","extensions/muse/src/verify-setup.ts"]},{"output":"harness.js","sha256":"3d60e27fd5cceeff58b2fc6fd3ac1338158db3d2940ec79b3571a3bf919a84a6","facadeSource":"extensions/muse/harness.ts","sources":[]},{"output":"index.js","sha256":"00c73cb0a6bef9e8f20ad5a8af5748aac87a2f3f7081e8895da13a311fb7a67d","facadeSource":"extensions/muse/index.ts","sources":["extensions/muse/index.ts"]}],"unrenderedSources":[]}
|
package/dist/harness.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { t as createMuseAgentHarness } from "./.setup/harness-
|
|
1
|
+
export { t as createMuseAgentHarness } from "./.setup/harness-CzfspMQy.mjs";
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { t as createMuseAgentHarness } from "./.setup/harness-
|
|
1
|
+
import { t as createMuseAgentHarness } from "./.setup/harness-CzfspMQy.mjs";
|
|
2
2
|
import { definePluginEntry } from "openclaw/plugin-sdk/plugin-entry";
|
|
3
3
|
import { isRecord } from "openclaw/plugin-sdk/string-coerce-runtime";
|
|
4
|
-
|
|
4
|
+
// extensions/muse/index.ts
|
|
5
5
|
var muse_default = definePluginEntry({
|
|
6
6
|
id: "muse",
|
|
7
7
|
name: "Muse Code agent runtime",
|
|
@@ -38,5 +38,4 @@ var muse_default = definePluginEntry({
|
|
|
38
38
|
api.registerAgentHarness(harness);
|
|
39
39
|
}
|
|
40
40
|
});
|
|
41
|
-
//#endregion
|
|
42
41
|
export { muse_default as default };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openclaw/muse",
|
|
3
|
-
"version": "2026.11.
|
|
3
|
+
"version": "2026.11.10-beta.1",
|
|
4
4
|
"description": "OpenClaw Muse Code agent runtime plugin (registers a `muse` AgentHarness backed by @muse-code/sdk over the Muse Session Protocol to the Muse Code CLI)",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
},
|
|
9
9
|
"type": "module",
|
|
10
10
|
"dependencies": {
|
|
11
|
-
"@muse-code/sdk": "1.4.
|
|
11
|
+
"@muse-code/sdk": "1.4.14"
|
|
12
12
|
},
|
|
13
13
|
"devDependencies": {
|
|
14
14
|
"@openclaw/plugin-sdk": "workspace:*"
|
|
@@ -24,10 +24,10 @@
|
|
|
24
24
|
"minHostVersion": ">=2026.10.2"
|
|
25
25
|
},
|
|
26
26
|
"compat": {
|
|
27
|
-
"pluginApi": ">=2026.11.
|
|
27
|
+
"pluginApi": ">=2026.11.10-beta.1"
|
|
28
28
|
},
|
|
29
29
|
"build": {
|
|
30
|
-
"openclawVersion": "2026.11.
|
|
30
|
+
"openclawVersion": "2026.11.10-beta.1",
|
|
31
31
|
"bundledDist": false
|
|
32
32
|
},
|
|
33
33
|
"release": {
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
"assets/activity.svg"
|
|
48
48
|
],
|
|
49
49
|
"peerDependencies": {
|
|
50
|
-
"openclaw": ">=2026.11.
|
|
50
|
+
"openclaw": ">=2026.11.10-beta.1"
|
|
51
51
|
},
|
|
52
52
|
"peerDependenciesMeta": {
|
|
53
53
|
"openclaw": {
|