@wagemule/daemon 0.1.8 → 0.1.9
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/main.cjs +106 -14
- package/dist/main.cjs.map +3 -3
- package/package.json +1 -1
package/dist/main.cjs
CHANGED
|
@@ -1837,7 +1837,11 @@ var KimiAdapter = class {
|
|
|
1837
1837
|
});
|
|
1838
1838
|
this.lines = import_node_readline4.default.createInterface({ input: this.child.stdout });
|
|
1839
1839
|
this.lines.on("line", (line) => this.handleLine(line));
|
|
1840
|
-
this.writeWire("initialize", {
|
|
1840
|
+
this.writeWire("initialize", {
|
|
1841
|
+
protocol_version: "1.10",
|
|
1842
|
+
client: { name: "wm-daemon", version: "0.0.1" },
|
|
1843
|
+
capabilities: { supports_question: false, supports_plan_mode: false }
|
|
1844
|
+
});
|
|
1841
1845
|
}
|
|
1842
1846
|
async prompt(input) {
|
|
1843
1847
|
const startInput = this.startInput;
|
|
@@ -1878,8 +1882,17 @@ var KimiAdapter = class {
|
|
|
1878
1882
|
if (input.abortSignal?.aborted) throw new Error("Runtime aborted");
|
|
1879
1883
|
input.abortSignal?.addEventListener("abort", abortHandler, { once: true });
|
|
1880
1884
|
events.push({ type: "task_delivered", content: input.prompt });
|
|
1881
|
-
this.writeWire("prompt", {
|
|
1885
|
+
this.active.promptRequestId = this.writeWire("prompt", { user_input: input.prompt });
|
|
1882
1886
|
await withTimeout(turnFinished, input.timeoutMs ?? 18e4, "Kimi wire turn timeout");
|
|
1887
|
+
if (this.active.errorMessage) {
|
|
1888
|
+
return {
|
|
1889
|
+
status: this.active.status ?? "runtime_error",
|
|
1890
|
+
finalMessage,
|
|
1891
|
+
runtimeSessionId: this.sessionId,
|
|
1892
|
+
events,
|
|
1893
|
+
errorMessage: this.active.errorMessage
|
|
1894
|
+
};
|
|
1895
|
+
}
|
|
1883
1896
|
return { status: "ok", finalMessage, runtimeSessionId: this.sessionId, events };
|
|
1884
1897
|
} catch (error) {
|
|
1885
1898
|
return {
|
|
@@ -1908,20 +1921,29 @@ var KimiAdapter = class {
|
|
|
1908
1921
|
this.child = null;
|
|
1909
1922
|
}
|
|
1910
1923
|
writeWire(method, params) {
|
|
1911
|
-
|
|
1924
|
+
const id = String(this.nextId++);
|
|
1925
|
+
this.child?.stdin.write(`${JSON.stringify({ jsonrpc: "2.0", id, method, params })}
|
|
1912
1926
|
`);
|
|
1927
|
+
return id;
|
|
1913
1928
|
}
|
|
1914
1929
|
handleLine(line) {
|
|
1915
|
-
const parsed =
|
|
1930
|
+
const parsed = parseKimiWireLine(line);
|
|
1916
1931
|
if (!parsed) return;
|
|
1917
|
-
if (parsed.sessionId) this.sessionId = parsed.sessionId;
|
|
1918
1932
|
const active = this.active;
|
|
1919
1933
|
const runInput = active?.runInput ?? (this.startInput ? { ...this.startInput, prompt: "" } : void 0);
|
|
1920
1934
|
if (!runInput) return;
|
|
1935
|
+
if (parsed.errorMessage && active && parsed.id === active.promptRequestId) {
|
|
1936
|
+
active.errorMessage = parsed.errorMessage;
|
|
1937
|
+
active.status = "runtime_error";
|
|
1938
|
+
active.events.push({ type: "runtime_error", content: parsed.errorMessage, data: parsed.data });
|
|
1939
|
+
runInput.onEvent?.({ type: "runtime_error", content: parsed.errorMessage, data: parsed.data });
|
|
1940
|
+
active.finish();
|
|
1941
|
+
return;
|
|
1942
|
+
}
|
|
1921
1943
|
if (active) {
|
|
1922
1944
|
if (parsed.appendFinalMessage) active.append(parsed.appendFinalMessage);
|
|
1923
1945
|
if (parsed.finalMessage) active.set(parsed.finalMessage);
|
|
1924
|
-
if (parsed.events.some((event) => event.type === "turn_finished")) active.finish();
|
|
1946
|
+
if (parsed.finished || parsed.events.some((event) => event.type === "turn_finished")) active.finish();
|
|
1925
1947
|
for (const event of parsed.events) {
|
|
1926
1948
|
active.events.push(event);
|
|
1927
1949
|
runInput.onEvent?.(event);
|
|
@@ -1929,6 +1951,67 @@ var KimiAdapter = class {
|
|
|
1929
1951
|
}
|
|
1930
1952
|
}
|
|
1931
1953
|
};
|
|
1954
|
+
function parseKimiWireLine(line) {
|
|
1955
|
+
if (!line.trim()) return void 0;
|
|
1956
|
+
let value;
|
|
1957
|
+
try {
|
|
1958
|
+
value = JSON.parse(line);
|
|
1959
|
+
} catch {
|
|
1960
|
+
return {
|
|
1961
|
+
appendFinalMessage: `${line}
|
|
1962
|
+
`,
|
|
1963
|
+
events: [{ type: "runtime_stdout", content: line }]
|
|
1964
|
+
};
|
|
1965
|
+
}
|
|
1966
|
+
const msg = value;
|
|
1967
|
+
const id = typeof msg.id === "string" ? msg.id : void 0;
|
|
1968
|
+
if (msg.error && typeof msg.error === "object") {
|
|
1969
|
+
const error = msg.error;
|
|
1970
|
+
return {
|
|
1971
|
+
id,
|
|
1972
|
+
errorMessage: typeof error.message === "string" ? error.message : "Kimi wire request failed",
|
|
1973
|
+
data: msg,
|
|
1974
|
+
events: []
|
|
1975
|
+
};
|
|
1976
|
+
}
|
|
1977
|
+
if (msg.result && typeof msg.result === "object") {
|
|
1978
|
+
const result = msg.result;
|
|
1979
|
+
const status = typeof result.status === "string" ? result.status : void 0;
|
|
1980
|
+
return {
|
|
1981
|
+
id,
|
|
1982
|
+
finished: status === "finished" || status === "cancelled" || status === "max_steps_reached",
|
|
1983
|
+
data: msg,
|
|
1984
|
+
events: status ? [{ type: "turn_finished", data: { runtime: "kimi", status, result } }] : [{ type: "runtime_started", data: { runtime: "kimi", result } }]
|
|
1985
|
+
};
|
|
1986
|
+
}
|
|
1987
|
+
if (msg.method !== "event" || !msg.params || typeof msg.params !== "object") {
|
|
1988
|
+
return { id, events: [{ type: "runtime_event", data: msg }] };
|
|
1989
|
+
}
|
|
1990
|
+
const params = msg.params;
|
|
1991
|
+
const eventType = typeof params.type === "string" ? params.type : "runtime_event";
|
|
1992
|
+
const payload = params.payload && typeof params.payload === "object" ? params.payload : {};
|
|
1993
|
+
const text = stringValue5(payload.text) ?? stringValue5(payload.content) ?? stringValue5(payload.message) ?? stringValue5(payload.delta?.text);
|
|
1994
|
+
if ((eventType === "TextPart" || eventType === "ContentPart") && text) {
|
|
1995
|
+
return {
|
|
1996
|
+
appendFinalMessage: text,
|
|
1997
|
+
events: [{ type: "assistant_delta", content: text, data: msg }]
|
|
1998
|
+
};
|
|
1999
|
+
}
|
|
2000
|
+
if (eventType === "TurnEnd") {
|
|
2001
|
+
return { finished: true, events: [{ type: "turn_finished", data: msg }] };
|
|
2002
|
+
}
|
|
2003
|
+
return {
|
|
2004
|
+
events: [{ type: kimiEventName(eventType), content: text, data: msg }]
|
|
2005
|
+
};
|
|
2006
|
+
}
|
|
2007
|
+
function kimiEventName(eventType) {
|
|
2008
|
+
if (/tool/i.test(eventType)) return "tool_progress";
|
|
2009
|
+
if (/begin|status|loading|retry|compaction|hook|notification/i.test(eventType)) return "runtime_event";
|
|
2010
|
+
return eventType;
|
|
2011
|
+
}
|
|
2012
|
+
function stringValue5(value) {
|
|
2013
|
+
return typeof value === "string" ? value : void 0;
|
|
2014
|
+
}
|
|
1932
2015
|
function kimiAgentYaml() {
|
|
1933
2016
|
return [
|
|
1934
2017
|
"version: 1",
|
|
@@ -3853,21 +3936,21 @@ function renderRuntimeLine(context, line) {
|
|
|
3853
3936
|
function extractTextFromRuntimeJsonLine(line) {
|
|
3854
3937
|
try {
|
|
3855
3938
|
const record = JSON.parse(line);
|
|
3856
|
-
const direct =
|
|
3939
|
+
const direct = stringValue6(record.result ?? record.text ?? record.content);
|
|
3857
3940
|
if (direct) return direct;
|
|
3858
3941
|
const message = record.message;
|
|
3859
|
-
const messageText = message ?
|
|
3942
|
+
const messageText = message ? stringValue6(message.text ?? message.content) : void 0;
|
|
3860
3943
|
if (messageText) return messageText;
|
|
3861
3944
|
const content = Array.isArray(message?.content) ? message?.content : [];
|
|
3862
3945
|
const parts = content.map(
|
|
3863
|
-
(part) => typeof part === "object" && part ?
|
|
3946
|
+
(part) => typeof part === "object" && part ? stringValue6(part.text) : void 0
|
|
3864
3947
|
).filter(Boolean);
|
|
3865
3948
|
return parts.length > 0 ? parts.join("") : void 0;
|
|
3866
3949
|
} catch {
|
|
3867
3950
|
return line;
|
|
3868
3951
|
}
|
|
3869
3952
|
}
|
|
3870
|
-
function
|
|
3953
|
+
function stringValue6(value) {
|
|
3871
3954
|
return typeof value === "string" && value.length > 0 ? value : void 0;
|
|
3872
3955
|
}
|
|
3873
3956
|
function writeLine(context, line) {
|
|
@@ -3891,7 +3974,7 @@ var import_ws = __toESM(require("ws"));
|
|
|
3891
3974
|
// package.json
|
|
3892
3975
|
var package_default = {
|
|
3893
3976
|
name: "@wagemule/daemon",
|
|
3894
|
-
version: "0.1.
|
|
3977
|
+
version: "0.1.9",
|
|
3895
3978
|
private: false,
|
|
3896
3979
|
description: "Wage Mule local daemon for connecting local agent runtimes to Workspace Server.",
|
|
3897
3980
|
main: "./dist/main.cjs",
|
|
@@ -4311,20 +4394,24 @@ ${stderr}`);
|
|
|
4311
4394
|
};
|
|
4312
4395
|
function parseKimiModelConfig(configText) {
|
|
4313
4396
|
const ids = [];
|
|
4397
|
+
const labels = /* @__PURE__ */ new Map();
|
|
4314
4398
|
let defaultModel;
|
|
4315
4399
|
let section;
|
|
4400
|
+
let currentModelKey;
|
|
4316
4401
|
for (const rawLine of configText.split(/\r?\n/)) {
|
|
4317
4402
|
const line = stripYamlComment(rawLine).trim();
|
|
4318
4403
|
if (!line) continue;
|
|
4319
4404
|
const table = line.match(/^\[models\.([^\]]+)]$/);
|
|
4320
4405
|
if (table) {
|
|
4321
|
-
|
|
4322
|
-
|
|
4406
|
+
currentModelKey = unquote(table[1].trim());
|
|
4407
|
+
section = `models.${currentModelKey}`;
|
|
4408
|
+
pushUnique(ids, currentModelKey);
|
|
4323
4409
|
continue;
|
|
4324
4410
|
}
|
|
4325
4411
|
const anyTable = line.match(/^\[([^\]]+)]$/);
|
|
4326
4412
|
if (anyTable) {
|
|
4327
4413
|
section = anyTable[1]?.trim();
|
|
4414
|
+
currentModelKey = void 0;
|
|
4328
4415
|
continue;
|
|
4329
4416
|
}
|
|
4330
4417
|
const defaultModelLine = line.match(/^default_model\s*=\s*["']?([^"']+)["']?\s*$/);
|
|
@@ -4333,7 +4420,11 @@ function parseKimiModelConfig(configText) {
|
|
|
4333
4420
|
pushUnique(ids, defaultModel);
|
|
4334
4421
|
continue;
|
|
4335
4422
|
}
|
|
4336
|
-
if (section?.startsWith("models."))
|
|
4423
|
+
if (section?.startsWith("models.")) {
|
|
4424
|
+
const model2 = line.match(/^model\s*=\s*["']?([^"']+)["']?\s*$/);
|
|
4425
|
+
if (model2 && currentModelKey) labels.set(currentModelKey, model2[1].trim());
|
|
4426
|
+
continue;
|
|
4427
|
+
}
|
|
4337
4428
|
const model = line.match(/^model\s*=\s*["']?([^"']+)["']?\s*$/);
|
|
4338
4429
|
if (model) {
|
|
4339
4430
|
const value = model[1]?.trim();
|
|
@@ -4348,6 +4439,7 @@ function parseKimiModelConfig(configText) {
|
|
|
4348
4439
|
}
|
|
4349
4440
|
const models = ids.map((id) => ({
|
|
4350
4441
|
...defaultReasoningModel(id, id === defaultModel),
|
|
4442
|
+
label: labels.get(id) ?? id,
|
|
4351
4443
|
default: id === defaultModel ? true : void 0
|
|
4352
4444
|
}));
|
|
4353
4445
|
return { models: normalizeDefault(models, defaultModel), defaultModel };
|