@love-moon/ai-sdk 0.2.23 → 0.2.25

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@love-moon/ai-sdk",
3
- "version": "0.2.23",
3
+ "version": "0.2.25",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -25,5 +25,5 @@
25
25
  "@types/node": "^22.10.2",
26
26
  "typescript": "^5.6.3"
27
27
  },
28
- "gitCommitId": "e1d19e3"
28
+ "gitCommitId": "6d7b348"
29
29
  }
package/dist/resume.d.ts DELETED
@@ -1,26 +0,0 @@
1
- export function resumeProviderForBackend(backend: any): "codex" | "claude" | "copilot" | null;
2
- export function findSessionPath(provider: any, sessionId: any, options?: {}): Promise<any>;
3
- export function findCodexSessionPath(sessionId: any, options?: {}): Promise<string | null>;
4
- export function findClaudeSessionPath(sessionId: any, options?: {}): Promise<any>;
5
- export function findCopilotSessionPath(sessionId: any, options?: {}): Promise<string | null>;
6
- export function resolveSessionRunDirectory(sessionPath: any): Promise<string>;
7
- export function inspectResumeTarget(backend: any, sessionId: any, options?: {}): Promise<{
8
- provider: string;
9
- sessionId: string;
10
- sessionPath: any;
11
- cwd: string;
12
- debugMetadata: {
13
- cwdSource: string;
14
- sessionPath: any;
15
- };
16
- }>;
17
- export function resolveResumeContext(backend: any, sessionId: any, options?: {}): Promise<{
18
- provider: string;
19
- sessionId: string;
20
- sessionPath: any;
21
- cwd: string;
22
- debugMetadata: {
23
- cwdSource: string;
24
- sessionPath: any;
25
- };
26
- }>;
package/dist/resume.js DELETED
@@ -1,380 +0,0 @@
1
- import fs from "node:fs";
2
- import { promises as fsp } from "node:fs";
3
- import os from "node:os";
4
- import path from "node:path";
5
- import readline from "node:readline";
6
- import yaml from "js-yaml";
7
- function normalizeBackend(backend) {
8
- return String(backend || "").trim().toLowerCase();
9
- }
10
- function resolveHomeDir(options) {
11
- if (options?.homeDir) {
12
- return options.homeDir;
13
- }
14
- return os.homedir();
15
- }
16
- function normalizeSessionId(sessionId) {
17
- return typeof sessionId === "string" ? sessionId.trim() : "";
18
- }
19
- export function resumeProviderForBackend(backend) {
20
- const normalizedBackend = normalizeBackend(backend);
21
- if (normalizedBackend === "codex" || normalizedBackend === "code") {
22
- return "codex";
23
- }
24
- if (normalizedBackend === "claude" || normalizedBackend === "claude-code") {
25
- return "claude";
26
- }
27
- if (normalizedBackend === "copilot") {
28
- return "copilot";
29
- }
30
- return null;
31
- }
32
- export async function findSessionPath(provider, sessionId, options = {}) {
33
- const normalizedProvider = String(provider || "").trim().toLowerCase();
34
- if (normalizedProvider === "codex") {
35
- return findCodexSessionPath(sessionId, options);
36
- }
37
- if (normalizedProvider === "claude") {
38
- return findClaudeSessionPath(sessionId, options);
39
- }
40
- if (normalizedProvider === "copilot") {
41
- return findCopilotSessionPath(sessionId, options);
42
- }
43
- throw new Error(`Unsupported provider: ${provider}`);
44
- }
45
- export async function findCodexSessionPath(sessionId, options = {}) {
46
- const normalizedSessionId = normalizeSessionId(sessionId);
47
- if (!normalizedSessionId) {
48
- return null;
49
- }
50
- const homeDir = resolveHomeDir(options);
51
- const sessionsDir = options.codexSessionsDir || path.join(homeDir, ".codex", "sessions");
52
- return findCodexSessionFile(sessionsDir, normalizedSessionId);
53
- }
54
- export async function findClaudeSessionPath(sessionId, options = {}) {
55
- const normalizedSessionId = normalizeSessionId(sessionId);
56
- if (!normalizedSessionId) {
57
- return null;
58
- }
59
- const homeDir = resolveHomeDir(options);
60
- const projectsDir = options.claudeProjectsDir || path.join(homeDir, ".claude", "projects");
61
- const sessionEntries = await findClaudeSessionEntries(projectsDir, normalizedSessionId);
62
- if (sessionEntries.length > 0) {
63
- return sessionEntries[0]?.source || null;
64
- }
65
- const tasksDir = options.claudeTasksDir || path.join(homeDir, ".claude", "tasks");
66
- const directTaskDir = path.join(tasksDir, normalizedSessionId);
67
- if (await pathExists(directTaskDir, "directory")) {
68
- return directTaskDir;
69
- }
70
- return null;
71
- }
72
- export async function findCopilotSessionPath(sessionId, options = {}) {
73
- const normalizedSessionId = normalizeSessionId(sessionId);
74
- if (!normalizedSessionId) {
75
- return null;
76
- }
77
- const homeDir = resolveHomeDir(options);
78
- const sessionStateDir = options.copilotSessionStateDir || path.join(homeDir, ".copilot", "session-state");
79
- const directJsonlPath = path.join(sessionStateDir, `${normalizedSessionId}.jsonl`);
80
- if (await pathExists(directJsonlPath, "file")) {
81
- return directJsonlPath;
82
- }
83
- const directSessionDir = path.join(sessionStateDir, normalizedSessionId);
84
- if (await pathExists(directSessionDir, "directory")) {
85
- return directSessionDir;
86
- }
87
- return findPathByName(sessionStateDir, normalizedSessionId);
88
- }
89
- export async function resolveSessionRunDirectory(sessionPath) {
90
- const normalizedPath = typeof sessionPath === "string" ? sessionPath.trim() : "";
91
- if (!normalizedPath) {
92
- throw new Error("Invalid session path");
93
- }
94
- let stats;
95
- try {
96
- stats = await fsp.stat(normalizedPath);
97
- }
98
- catch {
99
- throw new Error(`Session path does not exist: ${normalizedPath}`);
100
- }
101
- return stats.isDirectory() ? normalizedPath : path.dirname(normalizedPath);
102
- }
103
- export async function inspectResumeTarget(backend, sessionId, options = {}) {
104
- return resolveResumeContext(backend, sessionId, options);
105
- }
106
- export async function resolveResumeContext(backend, sessionId, options = {}) {
107
- const normalizedSessionId = normalizeSessionId(sessionId);
108
- if (!normalizedSessionId) {
109
- throw new Error("--resume requires a session id");
110
- }
111
- const provider = resumeProviderForBackend(backend);
112
- if (!provider) {
113
- throw new Error(`--resume is not supported for backend "${backend}"`);
114
- }
115
- const sessionPath = await findSessionPath(provider, normalizedSessionId, options);
116
- if (!sessionPath) {
117
- throw new Error(`Invalid --resume session id for ${provider}: ${normalizedSessionId}`);
118
- }
119
- const cwdFromSession = await extractResumeCwdFromSession(provider, sessionPath, normalizedSessionId);
120
- const fallbackCwd = await resolveSessionRunDirectory(sessionPath);
121
- const cwd = cwdFromSession || fallbackCwd;
122
- if (!(await isExistingDirectory(cwd))) {
123
- throw new Error(`Resume workspace path does not exist: ${cwd}`);
124
- }
125
- return {
126
- provider,
127
- sessionId: normalizedSessionId,
128
- sessionPath,
129
- cwd,
130
- debugMetadata: {
131
- cwdSource: cwdFromSession ? "session" : "session_path",
132
- sessionPath,
133
- },
134
- };
135
- }
136
- async function isExistingDirectory(targetPath) {
137
- const normalizedPath = typeof targetPath === "string" ? targetPath.trim() : "";
138
- if (!normalizedPath) {
139
- return false;
140
- }
141
- try {
142
- const stats = await fsp.stat(normalizedPath);
143
- return stats.isDirectory();
144
- }
145
- catch {
146
- return false;
147
- }
148
- }
149
- async function extractCodexResumeCwd(sessionPath) {
150
- if (!sessionPath.endsWith(".jsonl")) {
151
- return null;
152
- }
153
- const rl = readline.createInterface({
154
- input: fs.createReadStream(sessionPath),
155
- crlfDelay: Infinity,
156
- });
157
- for await (const line of rl) {
158
- const trimmed = line.trim();
159
- if (!trimmed) {
160
- continue;
161
- }
162
- let entry;
163
- try {
164
- entry = JSON.parse(trimmed);
165
- }
166
- catch {
167
- continue;
168
- }
169
- const maybeCwd = entry?.type === "session_meta" ? entry?.payload?.cwd : null;
170
- if (typeof maybeCwd === "string" && maybeCwd.trim()) {
171
- return maybeCwd.trim();
172
- }
173
- }
174
- return null;
175
- }
176
- async function extractClaudeResumeCwd(sessionPath, sessionId) {
177
- if (!sessionPath.endsWith(".jsonl")) {
178
- return null;
179
- }
180
- const rl = readline.createInterface({
181
- input: fs.createReadStream(sessionPath),
182
- crlfDelay: Infinity,
183
- });
184
- for await (const line of rl) {
185
- const trimmed = line.trim();
186
- if (!trimmed) {
187
- continue;
188
- }
189
- let entry;
190
- try {
191
- entry = JSON.parse(trimmed);
192
- }
193
- catch {
194
- continue;
195
- }
196
- const idMatches = String(entry?.sessionId || "").trim() === sessionId;
197
- const maybeCwd = entry?.cwd;
198
- if (idMatches && typeof maybeCwd === "string" && maybeCwd.trim()) {
199
- return maybeCwd.trim();
200
- }
201
- }
202
- return null;
203
- }
204
- async function extractCopilotResumeCwd(sessionPath) {
205
- let stats;
206
- try {
207
- stats = await fsp.stat(sessionPath);
208
- }
209
- catch {
210
- return null;
211
- }
212
- if (stats.isDirectory()) {
213
- const workspaceYamlPath = path.join(sessionPath, "workspace.yaml");
214
- try {
215
- const yamlContent = await fsp.readFile(workspaceYamlPath, "utf8");
216
- const parsed = yaml.load(yamlContent);
217
- const maybeCwd = parsed && typeof parsed === "object" ? parsed.cwd : null;
218
- if (typeof maybeCwd === "string" && maybeCwd.trim()) {
219
- return maybeCwd.trim();
220
- }
221
- }
222
- catch {
223
- return null;
224
- }
225
- return null;
226
- }
227
- if (!sessionPath.endsWith(".jsonl")) {
228
- return null;
229
- }
230
- const rl = readline.createInterface({
231
- input: fs.createReadStream(sessionPath),
232
- crlfDelay: Infinity,
233
- });
234
- for await (const line of rl) {
235
- const trimmed = line.trim();
236
- if (!trimmed) {
237
- continue;
238
- }
239
- let entry;
240
- try {
241
- entry = JSON.parse(trimmed);
242
- }
243
- catch {
244
- continue;
245
- }
246
- const maybeCwd = entry?.data?.context?.cwd || entry?.data?.cwd;
247
- if (typeof maybeCwd === "string" && maybeCwd.trim()) {
248
- return maybeCwd.trim();
249
- }
250
- }
251
- return null;
252
- }
253
- async function extractResumeCwdFromSession(provider, sessionPath, sessionId) {
254
- if (provider === "codex") {
255
- return extractCodexResumeCwd(sessionPath);
256
- }
257
- if (provider === "claude") {
258
- return extractClaudeResumeCwd(sessionPath, sessionId);
259
- }
260
- if (provider === "copilot") {
261
- return extractCopilotResumeCwd(sessionPath);
262
- }
263
- return null;
264
- }
265
- async function findCodexSessionFile(rootDir, sessionId) {
266
- const queue = [rootDir];
267
- while (queue.length) {
268
- const current = queue.pop();
269
- let entries = [];
270
- try {
271
- entries = await fsp.readdir(current, { withFileTypes: true });
272
- }
273
- catch {
274
- continue;
275
- }
276
- for (const entry of entries) {
277
- const fullPath = path.join(current, entry.name);
278
- if (entry.isDirectory()) {
279
- queue.push(fullPath);
280
- }
281
- else if (entry.isFile() &&
282
- entry.name.includes(sessionId) &&
283
- entry.name.endsWith(".jsonl")) {
284
- return fullPath;
285
- }
286
- }
287
- }
288
- return null;
289
- }
290
- async function findClaudeSessionEntries(projectsDir, sessionId) {
291
- const entries = [];
292
- let projectDirs = [];
293
- try {
294
- projectDirs = await fsp.readdir(projectsDir, { withFileTypes: true });
295
- }
296
- catch {
297
- return entries;
298
- }
299
- for (const projectDir of projectDirs) {
300
- if (!projectDir.isDirectory()) {
301
- continue;
302
- }
303
- const projectPath = path.join(projectsDir, projectDir.name);
304
- let files = [];
305
- try {
306
- files = await fsp.readdir(projectPath, { withFileTypes: true });
307
- }
308
- catch {
309
- continue;
310
- }
311
- for (const file of files) {
312
- if (!file.isFile()) {
313
- continue;
314
- }
315
- if (!file.name.endsWith(".jsonl") || file.name.startsWith("agent-")) {
316
- continue;
317
- }
318
- const filePath = path.join(projectPath, file.name);
319
- const rl = readline.createInterface({
320
- input: fs.createReadStream(filePath),
321
- crlfDelay: Infinity,
322
- });
323
- for await (const line of rl) {
324
- const trimmed = line.trim();
325
- if (!trimmed) {
326
- continue;
327
- }
328
- let entry;
329
- try {
330
- entry = JSON.parse(trimmed);
331
- }
332
- catch {
333
- continue;
334
- }
335
- if (entry.sessionId === sessionId) {
336
- entries.push({ ...entry, source: filePath });
337
- }
338
- }
339
- }
340
- }
341
- return entries;
342
- }
343
- async function findPathByName(rootDir, sessionId) {
344
- const queue = [rootDir];
345
- while (queue.length) {
346
- const current = queue.pop();
347
- let entries = [];
348
- try {
349
- entries = await fsp.readdir(current, { withFileTypes: true });
350
- }
351
- catch {
352
- continue;
353
- }
354
- for (const entry of entries) {
355
- const fullPath = path.join(current, entry.name);
356
- if (entry.name.includes(sessionId)) {
357
- return fullPath;
358
- }
359
- if (entry.isDirectory()) {
360
- queue.push(fullPath);
361
- }
362
- }
363
- }
364
- return null;
365
- }
366
- async function pathExists(targetPath, expectedType) {
367
- try {
368
- const stats = await fsp.stat(targetPath);
369
- if (expectedType === "file") {
370
- return stats.isFile();
371
- }
372
- if (expectedType === "directory") {
373
- return stats.isDirectory();
374
- }
375
- return true;
376
- }
377
- catch {
378
- return false;
379
- }
380
- }
@@ -1,153 +0,0 @@
1
- export function profileNameForBackend(backend: any): any;
2
- export function parseCommandParts(commandLine: any): {
3
- command: string;
4
- args: string[];
5
- };
6
- export function buildResumeArgsForBackend(backend: any, sessionId: any): string[];
7
- export function createAiSession(backend: any, options?: {}): TuiAiSession;
8
- export class TuiAiSession extends EventEmitter<[never]> {
9
- constructor(backend: any, options?: {});
10
- backend: any;
11
- options: {};
12
- logger: any;
13
- cwd: any;
14
- sessionId: any;
15
- history: any[];
16
- pendingHistorySeed: boolean;
17
- sessionInfo: {
18
- backend: any;
19
- sessionId: any;
20
- sessionFilePath: any;
21
- } | null;
22
- command: string;
23
- args: string[];
24
- tuiDebug: boolean;
25
- tuiTrace: boolean;
26
- tuiTraceLines: number;
27
- lastSignalSignature: string;
28
- lastPollSignature: string;
29
- lastSnapshotHash: string;
30
- closeRequested: boolean;
31
- closed: boolean;
32
- closeWaiters: Set<any>;
33
- sessionMessageHandler: any;
34
- sessionMonitorPromise: Promise<void> | null;
35
- sessionMonitorStopRequested: boolean;
36
- sessionMonitorCursor: number;
37
- sessionMonitorSessionId: string;
38
- sessionMonitorSessionFilePath: string;
39
- sessionMonitorActiveReplyTo: string;
40
- sessionMonitorHasActiveReplyTarget: boolean;
41
- sessionMonitorLastReplyTo: string;
42
- sessionMonitorAwaitingFirstReply: boolean;
43
- workingStatusHandler: any;
44
- workingStatusMonitorPromise: Promise<void> | null;
45
- workingStatusMonitorStopRequested: boolean;
46
- lastReportedWorkingStatusLine: string;
47
- turnDeadlineMs: any;
48
- useSessionFileReplyStream: boolean;
49
- sessionMonitorFastPollMs: any;
50
- sessionMonitorSlowPollMs: any;
51
- workingStatusPollMs: any;
52
- driver: TuiDriver;
53
- writeLog(message: any): void;
54
- get threadId(): any;
55
- get threadOptions(): {
56
- model: any;
57
- };
58
- getSnapshot(): {
59
- backend: any;
60
- command: string;
61
- args: string[];
62
- cwd: any;
63
- sessionId: any;
64
- sessionInfo: {
65
- backend: any;
66
- sessionId: any;
67
- sessionFilePath: any;
68
- } | null;
69
- useSessionFileReplyStream: boolean;
70
- };
71
- applySessionInfo(session: any): void;
72
- getSessionInfo(): {
73
- backend: any;
74
- sessionId: any;
75
- sessionFilePath: any;
76
- } | null;
77
- ensureSessionInfo(): Promise<{
78
- backend: any;
79
- sessionId: any;
80
- sessionFilePath: any;
81
- } | null>;
82
- getSessionUsageSummary(): Promise<import("@love-moon/tui-driver").TuiSessionUsageSummary | null>;
83
- usesSessionFileReplyStream(): boolean;
84
- setSessionMessageHandler(handler: any): void;
85
- setWorkingStatusHandler(handler: any): void;
86
- setSessionReplyTarget(replyTo: any): void;
87
- ensureSessionFileMonitor(): Promise<void>;
88
- ensureWorkingStatusMonitor(): Promise<void>;
89
- runSessionFileMonitor(): Promise<void>;
90
- runWorkingStatusMonitor(): Promise<void>;
91
- resolveSessionMonitorPollMs(): any;
92
- normalizeCodexWorkingStatusLine(statusLine: any): string;
93
- normalizeCopilotWorkingStatusLine(statusLine: any): string;
94
- normalizeWorkingStatusLine(statusLine: any): string;
95
- getCurrentReplyTarget(): string | undefined;
96
- pollWorkingStatus(): Promise<void>;
97
- pollSessionFileMessages(): Promise<void>;
98
- createSessionClosedError(): Error;
99
- createTurnTimeoutError(timeoutMs: any): Error;
100
- createCloseGuard(): {
101
- promise: Promise<any>;
102
- cleanup: () => void;
103
- };
104
- createTurnTimeoutGuard(): {
105
- promise: Promise<any>;
106
- cleanup: () => void;
107
- };
108
- flushCloseWaiters(): void;
109
- close(): Promise<void>;
110
- getHealthStatus(): import("@love-moon/tui-driver").HealthStatus | {
111
- healthy: boolean;
112
- reason: string;
113
- message: string;
114
- };
115
- buildPrompt(promptText: any, { useInitialImages }?: {
116
- useInitialImages?: boolean | undefined;
117
- }): string;
118
- emitProgress(onProgress: any, payload: any): void;
119
- trace(message: any): void;
120
- formatSignalSummary(signals?: {}): {
121
- prompt: string | undefined;
122
- replyInProgress: boolean;
123
- status: string | undefined;
124
- done: string | undefined;
125
- replyPreview: string | undefined;
126
- blocks: any;
127
- };
128
- logSignals(state: any, signals: any, snapshot: any): void;
129
- logSnapshot(state: any, snapshot: any): void;
130
- runTurn(promptText: any, { useInitialImages, onProgress }?: {
131
- useInitialImages?: boolean | undefined;
132
- }): Promise<{
133
- text: string;
134
- usage: null;
135
- items: never[];
136
- events: never[];
137
- provider?: undefined;
138
- metadata?: undefined;
139
- } | {
140
- text: string;
141
- usage: null;
142
- items: never[];
143
- events: never[];
144
- provider: any;
145
- metadata: {
146
- source: string;
147
- elapsed_ms: any;
148
- signals: any;
149
- };
150
- }>;
151
- }
152
- import { EventEmitter } from "node:events";
153
- import { TuiDriver } from "@love-moon/tui-driver";