@openclaw/muse 2026.11.7 → 2026.11.10-beta.2
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";
|
|
@@ -16,7 +16,7 @@ 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
|
-
|
|
19
|
+
// extensions/muse/src/events.ts
|
|
20
20
|
function assistantMessage(params, content, stopReason = "stop") {
|
|
21
21
|
return {
|
|
22
22
|
role: "assistant",
|
|
@@ -200,11 +200,9 @@ async function consumeTurn(turn, params, record) {
|
|
|
200
200
|
outcome: await turn.completed
|
|
201
201
|
};
|
|
202
202
|
}
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
//#endregion
|
|
207
|
-
//#region extensions/muse/src/runtime.ts
|
|
203
|
+
// extensions/muse/package.json
|
|
204
|
+
var version = "2026.11.10-beta.2";
|
|
205
|
+
// extensions/muse/src/runtime.ts
|
|
208
206
|
const RESUME_RETRY_KINDS = {
|
|
209
207
|
sessionInUse: true,
|
|
210
208
|
overloaded: true,
|
|
@@ -383,6 +381,7 @@ var MusePool = class {
|
|
|
383
381
|
host,
|
|
384
382
|
credentialIdentity,
|
|
385
383
|
sessions: /* @__PURE__ */ new Map(),
|
|
384
|
+
usageObservers: /* @__PURE__ */ new Map(),
|
|
386
385
|
users: 0,
|
|
387
386
|
dead: false,
|
|
388
387
|
closing: false,
|
|
@@ -394,7 +393,10 @@ var MusePool = class {
|
|
|
394
393
|
};
|
|
395
394
|
host.connection.onNotification((event) => {
|
|
396
395
|
const sessionId = event.params?.sessionId;
|
|
397
|
-
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
|
+
}
|
|
398
400
|
});
|
|
399
401
|
host.connection.onProtocolError(() => {
|
|
400
402
|
runtime.close();
|
|
@@ -426,8 +428,42 @@ var MusePool = class {
|
|
|
426
428
|
}));
|
|
427
429
|
}
|
|
428
430
|
};
|
|
429
|
-
|
|
430
|
-
|
|
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
|
|
431
467
|
function museDisplayName(modelId, displayLabel) {
|
|
432
468
|
const label = typeof displayLabel === "string" ? displayLabel : modelId;
|
|
433
469
|
if (label === modelId || modelId === "muse-wonder-full-1.0-contributor" && label === "muse-wonder-1.0-contributor") switch (modelId) {
|
|
@@ -484,8 +520,7 @@ var MuseCatalogReader = class {
|
|
|
484
520
|
await this.current?.pool.dispose();
|
|
485
521
|
}
|
|
486
522
|
};
|
|
487
|
-
|
|
488
|
-
//#region extensions/muse/harness.ts
|
|
523
|
+
// extensions/muse/harness.ts
|
|
489
524
|
/** Configuration Muse cannot honor; the message is safe and actionable for the chat user. */
|
|
490
525
|
function museRefusal(message) {
|
|
491
526
|
return new AgentHarnessPreflightError(message, {
|
|
@@ -602,6 +637,7 @@ function createMuseAgentHarness(options) {
|
|
|
602
637
|
let failure;
|
|
603
638
|
let activeAttachment;
|
|
604
639
|
const messages = [];
|
|
640
|
+
const tokenUsage = [];
|
|
605
641
|
let text = "";
|
|
606
642
|
let lastToolError;
|
|
607
643
|
let assistantTranscriptOwned = false;
|
|
@@ -693,6 +729,7 @@ function createMuseAgentHarness(options) {
|
|
|
693
729
|
options.logger?.warn(`${message}; started a new Muse session.`);
|
|
694
730
|
}
|
|
695
731
|
});
|
|
732
|
+
runtime.usageObservers.set(session.sessionId, (usage) => tokenUsage.push(usage));
|
|
696
733
|
assertDispatchActive();
|
|
697
734
|
let sessionContext = "";
|
|
698
735
|
if (freshSession) {
|
|
@@ -760,7 +797,7 @@ function createMuseAgentHarness(options) {
|
|
|
760
797
|
return selectApprovalChoice(request, decision);
|
|
761
798
|
});
|
|
762
799
|
session.onApprovalError((error) => {
|
|
763
|
-
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)}`);
|
|
764
801
|
stop().catch(() => runtime.close());
|
|
765
802
|
});
|
|
766
803
|
assertDispatchActive();
|
|
@@ -837,7 +874,9 @@ function createMuseAgentHarness(options) {
|
|
|
837
874
|
if (result.outcome.kind !== "completed") throw new Error(`Muse turn ended without a terminal result (${result.outcome.kind}).`);
|
|
838
875
|
if (result.outcome.params.terminal === "failed") {
|
|
839
876
|
const turnError = result.outcome.params.error;
|
|
840
|
-
|
|
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 } : {});
|
|
841
880
|
}
|
|
842
881
|
if (result.outcome.params.terminal === "cancelled" && !failure) aborted = true;
|
|
843
882
|
lifecycle.emitLifecycleTerminal({ phase: "end" });
|
|
@@ -856,10 +895,14 @@ function createMuseAgentHarness(options) {
|
|
|
856
895
|
signal?.removeEventListener("abort", onAbort);
|
|
857
896
|
active.delete(params.sessionId);
|
|
858
897
|
clearActiveEmbeddedRun(params.sessionId, handle, params.sessionKey, params.sessionFile, void 0, activeAttachment);
|
|
898
|
+
runtime.usageObservers.delete(session?.sessionId ?? "");
|
|
859
899
|
bound?.release();
|
|
860
900
|
lease.release();
|
|
861
901
|
}
|
|
862
|
-
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
|
+
}));
|
|
863
906
|
const interruption = timedOut ? {
|
|
864
907
|
kind: "timeout",
|
|
865
908
|
phase: "prompt",
|
|
@@ -872,7 +915,7 @@ function createMuseAgentHarness(options) {
|
|
|
872
915
|
if (failureMessage) options.logger?.warn(failureMessage);
|
|
873
916
|
const terminal = failureMessage ? agentHarnessAttemptTerminal.setFailure(interruption, {
|
|
874
917
|
source: "prompt",
|
|
875
|
-
error: new Error(failureMessage)
|
|
918
|
+
error: new Error(failureMessage, { cause: failure })
|
|
876
919
|
}) : interruption;
|
|
877
920
|
const lastAssistant = messages.findLast((message) => message.role === "assistant");
|
|
878
921
|
return {
|
|
@@ -886,6 +929,7 @@ function createMuseAgentHarness(options) {
|
|
|
886
929
|
assistantTranscriptIdempotencyKey: finalKey,
|
|
887
930
|
toolMetas,
|
|
888
931
|
lastToolError,
|
|
932
|
+
attemptUsage: museTurnUsage(tokenUsage, turn?.turnId),
|
|
889
933
|
cloudCodeAssistFormatError: false,
|
|
890
934
|
didSendViaMessagingTool: false,
|
|
891
935
|
itemLifecycle: {
|
|
@@ -996,5 +1040,4 @@ function createMuseAgentHarness(options) {
|
|
|
996
1040
|
}
|
|
997
1041
|
};
|
|
998
1042
|
}
|
|
999
|
-
//#endregion
|
|
1000
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-DiU0S8jL.mjs","sha256":"77d37c5e429930454703476fff6714656f766fa1c408dae55cc6626ee888cfee","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":"bcdf8f6f60982d31255a5a276f98e445520c8e27a51ebcfc0d4951f9de2d1e39","facadeSource":"extensions/muse/harness.ts","sources":[]},{"output":"index.js","sha256":"85ddb08cff7870d8cde0d201adb979809c2aa85693cd42d700e40f6548235027","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-DiU0S8jL.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-DiU0S8jL.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.2",
|
|
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.2"
|
|
28
28
|
},
|
|
29
29
|
"build": {
|
|
30
|
-
"openclawVersion": "2026.11.
|
|
30
|
+
"openclawVersion": "2026.11.10-beta.2",
|
|
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.2"
|
|
51
51
|
},
|
|
52
52
|
"peerDependenciesMeta": {
|
|
53
53
|
"openclaw": {
|