@love-moon/ai-sdk 0.13.3 → 0.15.0
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/CHANGELOG.md +82 -0
- package/dist/client.d.ts +5 -0
- package/dist/client.js +22 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/providers/chat-web-session.d.ts +18 -0
- package/dist/providers/chat-web-session.js +44 -1
- package/dist/providers/claude-agent-sdk-session.d.ts +34 -0
- package/dist/providers/claude-agent-sdk-session.js +33 -0
- package/dist/providers/codex-app-server-session.d.ts +76 -6
- package/dist/providers/codex-app-server-session.js +114 -14
- package/dist/providers/codex-exec-session.d.ts +14 -0
- package/dist/providers/codex-exec-session.js +20 -1
- package/dist/providers/copilot-sdk-session.d.ts +21 -0
- package/dist/providers/copilot-sdk-session.js +55 -12
- package/dist/providers/dsh-sdk-session.d.ts +53 -3
- package/dist/providers/dsh-sdk-session.js +24 -1
- package/dist/providers/kimi-cli-session.d.ts +22 -0
- package/dist/providers/kimi-cli-session.js +23 -1
- package/dist/providers/kimi-print-session.d.ts +13 -0
- package/dist/providers/kimi-print-session.js +29 -0
- package/dist/providers/kimi-slash-commands.d.ts +1 -0
- package/dist/providers/kimi-slash-commands.js +23 -0
- package/dist/providers/opencode-sdk-session.d.ts +52 -3
- package/dist/providers/opencode-sdk-session.js +33 -1
- package/dist/resume/claude.d.ts +8 -0
- package/dist/resume/claude.js +28 -1
- package/dist/resume/codex.d.ts +8 -0
- package/dist/resume/codex.js +37 -1
- package/dist/resume/index.d.ts +8 -0
- package/dist/resume/shared.d.ts +18 -0
- package/dist/resume/shared.js +65 -1
- package/dist/shared.d.ts +46 -0
- package/dist/shared.js +18 -1
- package/dist/transports/codex-app-server-transport.js +22 -1
- package/dist/transports/kimi-wire-transport.d.ts +12 -0
- package/dist/transports/kimi-wire-transport.js +40 -1
- package/dist/turn-usage.d.ts +31 -0
- package/dist/turn-usage.js +44 -0
- package/dist/worker.js +1 -1
- package/package.json +3 -3
|
@@ -37,6 +37,45 @@ function quoteShellArg(value) {
|
|
|
37
37
|
}
|
|
38
38
|
return `'${normalized.replace(/'/g, `'\\''`)}'`;
|
|
39
39
|
}
|
|
40
|
+
/**
|
|
41
|
+
* Drop resume flags from the configured command line. The session id is owned
|
|
42
|
+
* by the caller (we always append our own `--session=`), so a configured
|
|
43
|
+
* `--continue`/`--session`/`--resume` would silently reattach a fresh session —
|
|
44
|
+
* e.g. a `/clear` — to the previous conversation.
|
|
45
|
+
*
|
|
46
|
+
* Only those flags are touched. Notably `-c` is kimi's alias for
|
|
47
|
+
* `--prompt`/`--command` (it takes a value), not a continue switch, so it is
|
|
48
|
+
* passed through untouched — dropping the flag alone would leave its value
|
|
49
|
+
* behind as a stray positional argument.
|
|
50
|
+
*/
|
|
51
|
+
export function filterKimiWireBaseArgs(args) {
|
|
52
|
+
const filtered = [];
|
|
53
|
+
let skipNext = false;
|
|
54
|
+
for (const rawArg of Array.isArray(args) ? args : []) {
|
|
55
|
+
const arg = String(rawArg || "");
|
|
56
|
+
if (!arg) {
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
if (skipNext) {
|
|
60
|
+
skipNext = false;
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
if (arg === "--continue" || arg === "-C") {
|
|
64
|
+
continue;
|
|
65
|
+
}
|
|
66
|
+
if (arg === "--session" || arg === "-S" || arg === "--resume" || arg === "-r") {
|
|
67
|
+
skipNext = true;
|
|
68
|
+
continue;
|
|
69
|
+
}
|
|
70
|
+
if (arg.startsWith("--session=") ||
|
|
71
|
+
arg.startsWith("--resume=") ||
|
|
72
|
+
["-S", "-r"].some((prefix) => arg.startsWith(prefix) && arg.length > prefix.length)) {
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
filtered.push(arg);
|
|
76
|
+
}
|
|
77
|
+
return filtered;
|
|
78
|
+
}
|
|
40
79
|
export class KimiWireTransport extends EventEmitter {
|
|
41
80
|
constructor(options = {}) {
|
|
42
81
|
super();
|
|
@@ -55,7 +94,7 @@ export class KimiWireTransport extends EventEmitter {
|
|
|
55
94
|
throw new Error("Invalid kimi command");
|
|
56
95
|
}
|
|
57
96
|
this.command = command;
|
|
58
|
-
this.baseArgs = args;
|
|
97
|
+
this.baseArgs = filterKimiWireBaseArgs(args);
|
|
59
98
|
this.env = options.env && typeof options.env === "object" ? { ...options.env } : {};
|
|
60
99
|
this.sessionId =
|
|
61
100
|
typeof options.sessionId === "string" && options.sessionId.trim()
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @typedef {object} TurnUsageSummary
|
|
3
|
+
* @property {number} tokens Everything the turn read and wrote.
|
|
4
|
+
* @property {number} [inputTokens] All input the model read, cached or not.
|
|
5
|
+
* @property {number} [cachedInputTokens] The part of `inputTokens` served from the prompt cache.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Normalizes one turn's provider usage; the input cache hit ratio is
|
|
9
|
+
* `cachedInputTokens / inputTokens`. Claude's `input_tokens` excludes cache
|
|
10
|
+
* reads and writes, so its input is all three; the Codex provider reports
|
|
11
|
+
* per-turn deltas whose `turnInputTokens` already include the cached ones.
|
|
12
|
+
* Unknown shapes → null.
|
|
13
|
+
*
|
|
14
|
+
* @param {unknown} usage
|
|
15
|
+
* @returns {TurnUsageSummary | null}
|
|
16
|
+
*/
|
|
17
|
+
export function summarizeTurnUsage(usage: unknown): TurnUsageSummary | null;
|
|
18
|
+
export type TurnUsageSummary = {
|
|
19
|
+
/**
|
|
20
|
+
* Everything the turn read and wrote.
|
|
21
|
+
*/
|
|
22
|
+
tokens: number;
|
|
23
|
+
/**
|
|
24
|
+
* All input the model read, cached or not.
|
|
25
|
+
*/
|
|
26
|
+
inputTokens?: number | undefined;
|
|
27
|
+
/**
|
|
28
|
+
* The part of `inputTokens` served from the prompt cache.
|
|
29
|
+
*/
|
|
30
|
+
cachedInputTokens?: number | undefined;
|
|
31
|
+
};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @typedef {object} TurnUsageSummary
|
|
3
|
+
* @property {number} tokens Everything the turn read and wrote.
|
|
4
|
+
* @property {number} [inputTokens] All input the model read, cached or not.
|
|
5
|
+
* @property {number} [cachedInputTokens] The part of `inputTokens` served from the prompt cache.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Normalizes one turn's provider usage; the input cache hit ratio is
|
|
9
|
+
* `cachedInputTokens / inputTokens`. Claude's `input_tokens` excludes cache
|
|
10
|
+
* reads and writes, so its input is all three; the Codex provider reports
|
|
11
|
+
* per-turn deltas whose `turnInputTokens` already include the cached ones.
|
|
12
|
+
* Unknown shapes → null.
|
|
13
|
+
*
|
|
14
|
+
* @param {unknown} usage
|
|
15
|
+
* @returns {TurnUsageSummary | null}
|
|
16
|
+
*/
|
|
17
|
+
export function summarizeTurnUsage(usage) {
|
|
18
|
+
if (!usage || typeof usage !== "object") {
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
const read = (key) => {
|
|
22
|
+
const value = Number(/** @type {Record<string, unknown>} */ (usage)[key]);
|
|
23
|
+
return Number.isFinite(value) ? value : null;
|
|
24
|
+
};
|
|
25
|
+
const turnTotal = read("turnTotalTokens");
|
|
26
|
+
if (turnTotal !== null) {
|
|
27
|
+
const inputTokens = read("turnInputTokens");
|
|
28
|
+
const cachedInputTokens = read("turnCachedInputTokens");
|
|
29
|
+
return inputTokens !== null && cachedInputTokens !== null
|
|
30
|
+
? { tokens: turnTotal, inputTokens, cachedInputTokens }
|
|
31
|
+
: { tokens: turnTotal };
|
|
32
|
+
}
|
|
33
|
+
const [input, cacheWrite, cacheRead, output] = [
|
|
34
|
+
"input_tokens",
|
|
35
|
+
"cache_creation_input_tokens",
|
|
36
|
+
"cache_read_input_tokens",
|
|
37
|
+
"output_tokens",
|
|
38
|
+
].map(read);
|
|
39
|
+
if ([input, cacheWrite, cacheRead, output].every((value) => value === null)) {
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
const inputTokens = (input ?? 0) + (cacheWrite ?? 0) + (cacheRead ?? 0);
|
|
43
|
+
return { tokens: inputTokens + (output ?? 0), inputTokens, cachedInputTokens: cacheRead ?? 0 };
|
|
44
|
+
}
|
package/dist/worker.js
CHANGED
|
@@ -76,7 +76,7 @@ async function handleRequest(message) {
|
|
|
76
76
|
throw new Error(`Unsupported worker method: ${method}`);
|
|
77
77
|
}
|
|
78
78
|
const args = Array.isArray(message.args) ? [...message.args] : [];
|
|
79
|
-
if (method === "runTurn" || method === "runGoal" || method === "runCompact") {
|
|
79
|
+
if (method === "runTurn" || method === "runGoal" || method === "runCompact" || method === "runClear") {
|
|
80
80
|
const firstArg = args[0];
|
|
81
81
|
const options = args[1] && typeof args[1] === "object" ? { ...args[1] } : {};
|
|
82
82
|
options.onProgress = (payload) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@love-moon/ai-sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.15.0",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/lovemoon-ai/conductor.git"
|
|
@@ -53,12 +53,12 @@
|
|
|
53
53
|
"zod": "^4.1.5"
|
|
54
54
|
},
|
|
55
55
|
"optionalDependencies": {
|
|
56
|
-
"@love-moon/chat-web": "^0.
|
|
56
|
+
"@love-moon/chat-web": "^0.15.0"
|
|
57
57
|
},
|
|
58
58
|
"devDependencies": {
|
|
59
59
|
"@types/node": "^22.10.2",
|
|
60
60
|
"tsx": "^4.20.6",
|
|
61
61
|
"typescript": "^5.6.3"
|
|
62
62
|
},
|
|
63
|
-
"gitCommitId": "
|
|
63
|
+
"gitCommitId": "a097cd6"
|
|
64
64
|
}
|