@robota-sdk/agent-sdk 3.0.0-beta.44 → 3.0.0-beta.46
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/README.md +14 -1
- package/dist/node/index.cjs +118 -1
- package/dist/node/index.d.cts +25 -0
- package/dist/node/index.d.ts +25 -0
- package/dist/node/index.js +118 -1
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -84,7 +84,9 @@ const session = new InteractiveSession({
|
|
|
84
84
|
config,
|
|
85
85
|
context,
|
|
86
86
|
projectInfo,
|
|
87
|
-
sessionStore,
|
|
87
|
+
sessionStore, // SessionStore instance for persistence
|
|
88
|
+
resumeSessionId, // Session ID to restore (optional)
|
|
89
|
+
forkSession, // Session ID to fork from (optional)
|
|
88
90
|
permissionMode: 'default',
|
|
89
91
|
maxTurns: 10,
|
|
90
92
|
cwd: process.cwd(),
|
|
@@ -129,6 +131,13 @@ session.abort();
|
|
|
129
131
|
// Cancel queued prompt without aborting current execution
|
|
130
132
|
session.cancelQueue();
|
|
131
133
|
|
|
134
|
+
// Execute system commands
|
|
135
|
+
const result = await session.executeCommand('context', '');
|
|
136
|
+
// result.message, result.success, result.data
|
|
137
|
+
|
|
138
|
+
// List all registered system commands
|
|
139
|
+
session.listCommands(); // Array<{ name, description }>
|
|
140
|
+
|
|
132
141
|
// State queries
|
|
133
142
|
session.isExecuting(); // boolean
|
|
134
143
|
session.getPendingPrompt(); // string | null
|
|
@@ -137,6 +146,10 @@ session.getContextState(); // IContextWindowState
|
|
|
137
146
|
session.getStreamingText(); // string (accumulated so far)
|
|
138
147
|
session.getActiveTools(); // IToolState[]
|
|
139
148
|
|
|
149
|
+
// Session naming
|
|
150
|
+
session.getName(); // string | undefined
|
|
151
|
+
session.setName('my-task'); // sets the session name
|
|
152
|
+
|
|
140
153
|
// Access underlying Session for advanced use
|
|
141
154
|
session.getSession(); // Session
|
|
142
155
|
```
|
package/dist/node/index.cjs
CHANGED
|
@@ -713,6 +713,7 @@ function createSession(options) {
|
|
|
713
713
|
model: options.config.provider.model,
|
|
714
714
|
maxTurns: options.maxTurns,
|
|
715
715
|
sessionStore: options.sessionStore,
|
|
716
|
+
sessionId: options.sessionId,
|
|
716
717
|
permissionHandler: options.permissionHandler,
|
|
717
718
|
onTextDelta: options.onTextDelta,
|
|
718
719
|
onToolExecution: options.onToolExecution,
|
|
@@ -1117,6 +1118,8 @@ function createSystemCommands() {
|
|
|
1117
1118
|
" cost \u2014 Show session info",
|
|
1118
1119
|
" context \u2014 Context window info",
|
|
1119
1120
|
" permissions \u2014 Permission rules",
|
|
1121
|
+
" resume \u2014 Resume a previous session",
|
|
1122
|
+
" rename <name> \u2014 Rename the current session",
|
|
1120
1123
|
" reset \u2014 Delete settings and exit"
|
|
1121
1124
|
].join("\n"),
|
|
1122
1125
|
success: true
|
|
@@ -1255,6 +1258,30 @@ Messages: ${messageCount}`,
|
|
|
1255
1258
|
};
|
|
1256
1259
|
}
|
|
1257
1260
|
},
|
|
1261
|
+
{
|
|
1262
|
+
name: "resume",
|
|
1263
|
+
description: "Resume a previous session",
|
|
1264
|
+
execute: (_session, _args) => ({
|
|
1265
|
+
message: "Opening session picker...",
|
|
1266
|
+
success: true,
|
|
1267
|
+
data: { triggerResumePicker: true }
|
|
1268
|
+
})
|
|
1269
|
+
},
|
|
1270
|
+
{
|
|
1271
|
+
name: "rename",
|
|
1272
|
+
description: "Rename the current session",
|
|
1273
|
+
execute: (_session, args) => {
|
|
1274
|
+
const name = args.trim();
|
|
1275
|
+
if (!name) {
|
|
1276
|
+
return { message: "Usage: rename <name>", success: false };
|
|
1277
|
+
}
|
|
1278
|
+
return {
|
|
1279
|
+
message: `Session renamed to "${name}".`,
|
|
1280
|
+
success: true,
|
|
1281
|
+
data: { name }
|
|
1282
|
+
};
|
|
1283
|
+
}
|
|
1284
|
+
},
|
|
1258
1285
|
{
|
|
1259
1286
|
name: "reset",
|
|
1260
1287
|
description: "Delete settings",
|
|
@@ -2180,6 +2207,14 @@ var InteractiveSession = class {
|
|
|
2180
2207
|
pendingRawInput;
|
|
2181
2208
|
// Full history timeline (chat messages + events)
|
|
2182
2209
|
history = [];
|
|
2210
|
+
// Session persistence
|
|
2211
|
+
sessionStore;
|
|
2212
|
+
sessionName;
|
|
2213
|
+
cwd;
|
|
2214
|
+
// Session restore state
|
|
2215
|
+
pendingRestoreMessages = null;
|
|
2216
|
+
resumeSessionId;
|
|
2217
|
+
forkSession;
|
|
2183
2218
|
constructor(options) {
|
|
2184
2219
|
this.commandExecutor = new SystemCommandExecutor(createSystemCommands());
|
|
2185
2220
|
if ("session" in options && options.session) {
|
|
@@ -2189,6 +2224,30 @@ var InteractiveSession = class {
|
|
|
2189
2224
|
const stdOpts = options;
|
|
2190
2225
|
this.initPromise = this.initializeAsync(stdOpts);
|
|
2191
2226
|
}
|
|
2227
|
+
this.sessionStore = options.sessionStore;
|
|
2228
|
+
this.sessionName = options.sessionName;
|
|
2229
|
+
this.cwd = ("cwd" in options ? options.cwd : void 0) ?? "";
|
|
2230
|
+
this.resumeSessionId = options.resumeSessionId;
|
|
2231
|
+
this.forkSession = options.forkSession ?? false;
|
|
2232
|
+
if (options.resumeSessionId && this.sessionStore) {
|
|
2233
|
+
const record = this.sessionStore.load(options.resumeSessionId);
|
|
2234
|
+
if (record) {
|
|
2235
|
+
this.history = record.history ?? [];
|
|
2236
|
+
this.sessionName = record.name;
|
|
2237
|
+
if (record.messages) {
|
|
2238
|
+
if (this.session) {
|
|
2239
|
+
for (const msg of record.messages) {
|
|
2240
|
+
const m = msg;
|
|
2241
|
+
if (m.role && m.content) {
|
|
2242
|
+
this.session.injectMessage(m.role, m.content);
|
|
2243
|
+
}
|
|
2244
|
+
}
|
|
2245
|
+
} else {
|
|
2246
|
+
this.pendingRestoreMessages = record.messages;
|
|
2247
|
+
}
|
|
2248
|
+
}
|
|
2249
|
+
}
|
|
2250
|
+
}
|
|
2192
2251
|
}
|
|
2193
2252
|
async initializeAsync(options) {
|
|
2194
2253
|
const cwd = options.cwd;
|
|
@@ -2215,6 +2274,7 @@ var InteractiveSession = class {
|
|
|
2215
2274
|
} catch {
|
|
2216
2275
|
}
|
|
2217
2276
|
const paths = projectPaths(cwd);
|
|
2277
|
+
const sessionId = this.resumeSessionId && !this.forkSession ? this.resumeSessionId : void 0;
|
|
2218
2278
|
this.session = createSession({
|
|
2219
2279
|
config: mergedConfig,
|
|
2220
2280
|
context,
|
|
@@ -2226,8 +2286,20 @@ var InteractiveSession = class {
|
|
|
2226
2286
|
permissionHandler: options.permissionHandler,
|
|
2227
2287
|
provider: options.provider,
|
|
2228
2288
|
onTextDelta: (delta) => this.handleTextDelta(delta),
|
|
2229
|
-
onToolExecution: (event) => this.handleToolExecution(event)
|
|
2289
|
+
onToolExecution: (event) => this.handleToolExecution(event),
|
|
2290
|
+
sessionId
|
|
2230
2291
|
});
|
|
2292
|
+
if (this.pendingRestoreMessages) {
|
|
2293
|
+
for (const msg of this.pendingRestoreMessages) {
|
|
2294
|
+
if (msg && typeof msg === "object" && "role" in msg && "content" in msg) {
|
|
2295
|
+
this.session.injectMessage(
|
|
2296
|
+
msg.role,
|
|
2297
|
+
msg.content
|
|
2298
|
+
);
|
|
2299
|
+
}
|
|
2300
|
+
}
|
|
2301
|
+
this.pendingRestoreMessages = null;
|
|
2302
|
+
}
|
|
2231
2303
|
this.initialized = true;
|
|
2232
2304
|
}
|
|
2233
2305
|
async ensureInitialized() {
|
|
@@ -2274,6 +2346,13 @@ var InteractiveSession = class {
|
|
|
2274
2346
|
await this.ensureInitialized();
|
|
2275
2347
|
return this.commandExecutor.execute(name, this, args);
|
|
2276
2348
|
}
|
|
2349
|
+
/** List all registered system commands. */
|
|
2350
|
+
listCommands() {
|
|
2351
|
+
return this.commandExecutor.listCommands().map((cmd) => ({
|
|
2352
|
+
name: cmd.name,
|
|
2353
|
+
description: cmd.description
|
|
2354
|
+
}));
|
|
2355
|
+
}
|
|
2277
2356
|
/** Abort current execution and clear queue. */
|
|
2278
2357
|
abort() {
|
|
2279
2358
|
this.pendingPrompt = null;
|
|
@@ -2310,6 +2389,26 @@ var InteractiveSession = class {
|
|
|
2310
2389
|
getContextState() {
|
|
2311
2390
|
return this.getSessionOrThrow().getContextState();
|
|
2312
2391
|
}
|
|
2392
|
+
/** Get session name. */
|
|
2393
|
+
getName() {
|
|
2394
|
+
return this.sessionName;
|
|
2395
|
+
}
|
|
2396
|
+
/** Set session name and persist if store is available. */
|
|
2397
|
+
setName(name) {
|
|
2398
|
+
this.sessionName = name;
|
|
2399
|
+
if (this.sessionStore && this.session) {
|
|
2400
|
+
try {
|
|
2401
|
+
const id = this.getSessionOrThrow().getSessionId();
|
|
2402
|
+
const existing = this.sessionStore.load(id);
|
|
2403
|
+
if (existing) {
|
|
2404
|
+
existing.name = name;
|
|
2405
|
+
existing.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
2406
|
+
this.sessionStore.save(existing);
|
|
2407
|
+
}
|
|
2408
|
+
} catch {
|
|
2409
|
+
}
|
|
2410
|
+
}
|
|
2411
|
+
}
|
|
2313
2412
|
/** Access underlying Session. For advanced use / testing only. */
|
|
2314
2413
|
getSession() {
|
|
2315
2414
|
return this.getSessionOrThrow();
|
|
@@ -2351,6 +2450,22 @@ var InteractiveSession = class {
|
|
|
2351
2450
|
} finally {
|
|
2352
2451
|
this.executing = false;
|
|
2353
2452
|
this.emit("thinking", false);
|
|
2453
|
+
if (this.sessionStore && this.session) {
|
|
2454
|
+
try {
|
|
2455
|
+
const sessionId = this.getSessionOrThrow().getSessionId();
|
|
2456
|
+
const existing = this.sessionStore.load(sessionId);
|
|
2457
|
+
this.sessionStore.save({
|
|
2458
|
+
id: sessionId,
|
|
2459
|
+
name: this.sessionName ?? existing?.name,
|
|
2460
|
+
cwd: this.cwd ?? "",
|
|
2461
|
+
createdAt: existing?.createdAt ?? (/* @__PURE__ */ new Date()).toISOString(),
|
|
2462
|
+
updatedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
2463
|
+
messages: this.getSessionOrThrow().getHistory(),
|
|
2464
|
+
history: this.history
|
|
2465
|
+
});
|
|
2466
|
+
} catch {
|
|
2467
|
+
}
|
|
2468
|
+
}
|
|
2354
2469
|
if (this.pendingPrompt) {
|
|
2355
2470
|
const queued = this.pendingPrompt;
|
|
2356
2471
|
const queuedDisplay = this.pendingDisplayInput;
|
|
@@ -2638,6 +2753,8 @@ function createBuiltinCommands() {
|
|
|
2638
2753
|
{ name: "cost", description: "Show session info", source: "builtin" },
|
|
2639
2754
|
{ name: "context", description: "Context window info", source: "builtin" },
|
|
2640
2755
|
{ name: "permissions", description: "Permission rules", source: "builtin" },
|
|
2756
|
+
{ name: "resume", description: "Resume a previous session", source: "builtin" },
|
|
2757
|
+
{ name: "rename", description: "Rename the current session", source: "builtin" },
|
|
2641
2758
|
{ name: "plugin", description: "Manage plugins", source: "builtin" },
|
|
2642
2759
|
{ name: "reload-plugins", description: "Reload all plugin resources", source: "builtin" },
|
|
2643
2760
|
{ name: "reset", description: "Delete settings and exit", source: "builtin" },
|
package/dist/node/index.d.cts
CHANGED
|
@@ -210,6 +210,8 @@ interface ICreateSessionOptions {
|
|
|
210
210
|
sessionFactory?: TSessionFactory;
|
|
211
211
|
/** Additional hook type executors beyond the defaults (prompt, agent). */
|
|
212
212
|
additionalHookExecutors?: IHookTypeExecutor[];
|
|
213
|
+
/** Override session ID (used when resuming a session to reuse the original ID) */
|
|
214
|
+
sessionId?: string;
|
|
213
215
|
}
|
|
214
216
|
|
|
215
217
|
/**
|
|
@@ -420,6 +422,10 @@ interface IInteractiveSessionStandardOptions {
|
|
|
420
422
|
permissionMode?: ICreateSessionOptions['permissionMode'];
|
|
421
423
|
maxTurns?: number;
|
|
422
424
|
permissionHandler?: TInteractivePermissionHandler;
|
|
425
|
+
sessionStore?: SessionStore;
|
|
426
|
+
sessionName?: string;
|
|
427
|
+
resumeSessionId?: string;
|
|
428
|
+
forkSession?: boolean;
|
|
423
429
|
}
|
|
424
430
|
/** Test/advanced construction: inject pre-built session directly. */
|
|
425
431
|
interface IInteractiveSessionInjectedOptions {
|
|
@@ -429,6 +435,10 @@ interface IInteractiveSessionInjectedOptions {
|
|
|
429
435
|
permissionMode?: ICreateSessionOptions['permissionMode'];
|
|
430
436
|
maxTurns?: number;
|
|
431
437
|
permissionHandler?: TInteractivePermissionHandler;
|
|
438
|
+
sessionStore?: SessionStore;
|
|
439
|
+
sessionName?: string;
|
|
440
|
+
resumeSessionId?: string;
|
|
441
|
+
forkSession?: boolean;
|
|
432
442
|
}
|
|
433
443
|
type IInteractiveSessionOptions = IInteractiveSessionStandardOptions | IInteractiveSessionInjectedOptions;
|
|
434
444
|
declare class InteractiveSession {
|
|
@@ -445,6 +455,12 @@ declare class InteractiveSession {
|
|
|
445
455
|
private pendingDisplayInput;
|
|
446
456
|
private pendingRawInput;
|
|
447
457
|
private history;
|
|
458
|
+
private sessionStore?;
|
|
459
|
+
private sessionName?;
|
|
460
|
+
private cwd?;
|
|
461
|
+
private pendingRestoreMessages;
|
|
462
|
+
private resumeSessionId?;
|
|
463
|
+
private forkSession;
|
|
448
464
|
constructor(options: IInteractiveSessionOptions);
|
|
449
465
|
private initializeAsync;
|
|
450
466
|
private ensureInitialized;
|
|
@@ -460,6 +476,11 @@ declare class InteractiveSession {
|
|
|
460
476
|
success: boolean;
|
|
461
477
|
data?: Record<string, unknown>;
|
|
462
478
|
} | null>;
|
|
479
|
+
/** List all registered system commands. */
|
|
480
|
+
listCommands(): Array<{
|
|
481
|
+
name: string;
|
|
482
|
+
description: string;
|
|
483
|
+
}>;
|
|
463
484
|
/** Abort current execution and clear queue. */
|
|
464
485
|
abort(): void;
|
|
465
486
|
/** Cancel queued prompt without aborting current execution. */
|
|
@@ -473,6 +494,10 @@ declare class InteractiveSession {
|
|
|
473
494
|
getStreamingText(): string;
|
|
474
495
|
getActiveTools(): IToolState[];
|
|
475
496
|
getContextState(): IContextWindowState;
|
|
497
|
+
/** Get session name. */
|
|
498
|
+
getName(): string | undefined;
|
|
499
|
+
/** Set session name and persist if store is available. */
|
|
500
|
+
setName(name: string): void;
|
|
476
501
|
/** Access underlying Session. For advanced use / testing only. */
|
|
477
502
|
getSession(): Session;
|
|
478
503
|
private executePrompt;
|
package/dist/node/index.d.ts
CHANGED
|
@@ -210,6 +210,8 @@ interface ICreateSessionOptions {
|
|
|
210
210
|
sessionFactory?: TSessionFactory;
|
|
211
211
|
/** Additional hook type executors beyond the defaults (prompt, agent). */
|
|
212
212
|
additionalHookExecutors?: IHookTypeExecutor[];
|
|
213
|
+
/** Override session ID (used when resuming a session to reuse the original ID) */
|
|
214
|
+
sessionId?: string;
|
|
213
215
|
}
|
|
214
216
|
|
|
215
217
|
/**
|
|
@@ -420,6 +422,10 @@ interface IInteractiveSessionStandardOptions {
|
|
|
420
422
|
permissionMode?: ICreateSessionOptions['permissionMode'];
|
|
421
423
|
maxTurns?: number;
|
|
422
424
|
permissionHandler?: TInteractivePermissionHandler;
|
|
425
|
+
sessionStore?: SessionStore;
|
|
426
|
+
sessionName?: string;
|
|
427
|
+
resumeSessionId?: string;
|
|
428
|
+
forkSession?: boolean;
|
|
423
429
|
}
|
|
424
430
|
/** Test/advanced construction: inject pre-built session directly. */
|
|
425
431
|
interface IInteractiveSessionInjectedOptions {
|
|
@@ -429,6 +435,10 @@ interface IInteractiveSessionInjectedOptions {
|
|
|
429
435
|
permissionMode?: ICreateSessionOptions['permissionMode'];
|
|
430
436
|
maxTurns?: number;
|
|
431
437
|
permissionHandler?: TInteractivePermissionHandler;
|
|
438
|
+
sessionStore?: SessionStore;
|
|
439
|
+
sessionName?: string;
|
|
440
|
+
resumeSessionId?: string;
|
|
441
|
+
forkSession?: boolean;
|
|
432
442
|
}
|
|
433
443
|
type IInteractiveSessionOptions = IInteractiveSessionStandardOptions | IInteractiveSessionInjectedOptions;
|
|
434
444
|
declare class InteractiveSession {
|
|
@@ -445,6 +455,12 @@ declare class InteractiveSession {
|
|
|
445
455
|
private pendingDisplayInput;
|
|
446
456
|
private pendingRawInput;
|
|
447
457
|
private history;
|
|
458
|
+
private sessionStore?;
|
|
459
|
+
private sessionName?;
|
|
460
|
+
private cwd?;
|
|
461
|
+
private pendingRestoreMessages;
|
|
462
|
+
private resumeSessionId?;
|
|
463
|
+
private forkSession;
|
|
448
464
|
constructor(options: IInteractiveSessionOptions);
|
|
449
465
|
private initializeAsync;
|
|
450
466
|
private ensureInitialized;
|
|
@@ -460,6 +476,11 @@ declare class InteractiveSession {
|
|
|
460
476
|
success: boolean;
|
|
461
477
|
data?: Record<string, unknown>;
|
|
462
478
|
} | null>;
|
|
479
|
+
/** List all registered system commands. */
|
|
480
|
+
listCommands(): Array<{
|
|
481
|
+
name: string;
|
|
482
|
+
description: string;
|
|
483
|
+
}>;
|
|
463
484
|
/** Abort current execution and clear queue. */
|
|
464
485
|
abort(): void;
|
|
465
486
|
/** Cancel queued prompt without aborting current execution. */
|
|
@@ -473,6 +494,10 @@ declare class InteractiveSession {
|
|
|
473
494
|
getStreamingText(): string;
|
|
474
495
|
getActiveTools(): IToolState[];
|
|
475
496
|
getContextState(): IContextWindowState;
|
|
497
|
+
/** Get session name. */
|
|
498
|
+
getName(): string | undefined;
|
|
499
|
+
/** Set session name and persist if store is available. */
|
|
500
|
+
setName(name: string): void;
|
|
476
501
|
/** Access underlying Session. For advanced use / testing only. */
|
|
477
502
|
getSession(): Session;
|
|
478
503
|
private executePrompt;
|
package/dist/node/index.js
CHANGED
|
@@ -650,6 +650,7 @@ function createSession(options) {
|
|
|
650
650
|
model: options.config.provider.model,
|
|
651
651
|
maxTurns: options.maxTurns,
|
|
652
652
|
sessionStore: options.sessionStore,
|
|
653
|
+
sessionId: options.sessionId,
|
|
653
654
|
permissionHandler: options.permissionHandler,
|
|
654
655
|
onTextDelta: options.onTextDelta,
|
|
655
656
|
onToolExecution: options.onToolExecution,
|
|
@@ -1059,6 +1060,8 @@ function createSystemCommands() {
|
|
|
1059
1060
|
" cost \u2014 Show session info",
|
|
1060
1061
|
" context \u2014 Context window info",
|
|
1061
1062
|
" permissions \u2014 Permission rules",
|
|
1063
|
+
" resume \u2014 Resume a previous session",
|
|
1064
|
+
" rename <name> \u2014 Rename the current session",
|
|
1062
1065
|
" reset \u2014 Delete settings and exit"
|
|
1063
1066
|
].join("\n"),
|
|
1064
1067
|
success: true
|
|
@@ -1197,6 +1200,30 @@ Messages: ${messageCount}`,
|
|
|
1197
1200
|
};
|
|
1198
1201
|
}
|
|
1199
1202
|
},
|
|
1203
|
+
{
|
|
1204
|
+
name: "resume",
|
|
1205
|
+
description: "Resume a previous session",
|
|
1206
|
+
execute: (_session, _args) => ({
|
|
1207
|
+
message: "Opening session picker...",
|
|
1208
|
+
success: true,
|
|
1209
|
+
data: { triggerResumePicker: true }
|
|
1210
|
+
})
|
|
1211
|
+
},
|
|
1212
|
+
{
|
|
1213
|
+
name: "rename",
|
|
1214
|
+
description: "Rename the current session",
|
|
1215
|
+
execute: (_session, args) => {
|
|
1216
|
+
const name = args.trim();
|
|
1217
|
+
if (!name) {
|
|
1218
|
+
return { message: "Usage: rename <name>", success: false };
|
|
1219
|
+
}
|
|
1220
|
+
return {
|
|
1221
|
+
message: `Session renamed to "${name}".`,
|
|
1222
|
+
success: true,
|
|
1223
|
+
data: { name }
|
|
1224
|
+
};
|
|
1225
|
+
}
|
|
1226
|
+
},
|
|
1200
1227
|
{
|
|
1201
1228
|
name: "reset",
|
|
1202
1229
|
description: "Delete settings",
|
|
@@ -2130,6 +2157,14 @@ var InteractiveSession = class {
|
|
|
2130
2157
|
pendingRawInput;
|
|
2131
2158
|
// Full history timeline (chat messages + events)
|
|
2132
2159
|
history = [];
|
|
2160
|
+
// Session persistence
|
|
2161
|
+
sessionStore;
|
|
2162
|
+
sessionName;
|
|
2163
|
+
cwd;
|
|
2164
|
+
// Session restore state
|
|
2165
|
+
pendingRestoreMessages = null;
|
|
2166
|
+
resumeSessionId;
|
|
2167
|
+
forkSession;
|
|
2133
2168
|
constructor(options) {
|
|
2134
2169
|
this.commandExecutor = new SystemCommandExecutor(createSystemCommands());
|
|
2135
2170
|
if ("session" in options && options.session) {
|
|
@@ -2139,6 +2174,30 @@ var InteractiveSession = class {
|
|
|
2139
2174
|
const stdOpts = options;
|
|
2140
2175
|
this.initPromise = this.initializeAsync(stdOpts);
|
|
2141
2176
|
}
|
|
2177
|
+
this.sessionStore = options.sessionStore;
|
|
2178
|
+
this.sessionName = options.sessionName;
|
|
2179
|
+
this.cwd = ("cwd" in options ? options.cwd : void 0) ?? "";
|
|
2180
|
+
this.resumeSessionId = options.resumeSessionId;
|
|
2181
|
+
this.forkSession = options.forkSession ?? false;
|
|
2182
|
+
if (options.resumeSessionId && this.sessionStore) {
|
|
2183
|
+
const record = this.sessionStore.load(options.resumeSessionId);
|
|
2184
|
+
if (record) {
|
|
2185
|
+
this.history = record.history ?? [];
|
|
2186
|
+
this.sessionName = record.name;
|
|
2187
|
+
if (record.messages) {
|
|
2188
|
+
if (this.session) {
|
|
2189
|
+
for (const msg of record.messages) {
|
|
2190
|
+
const m = msg;
|
|
2191
|
+
if (m.role && m.content) {
|
|
2192
|
+
this.session.injectMessage(m.role, m.content);
|
|
2193
|
+
}
|
|
2194
|
+
}
|
|
2195
|
+
} else {
|
|
2196
|
+
this.pendingRestoreMessages = record.messages;
|
|
2197
|
+
}
|
|
2198
|
+
}
|
|
2199
|
+
}
|
|
2200
|
+
}
|
|
2142
2201
|
}
|
|
2143
2202
|
async initializeAsync(options) {
|
|
2144
2203
|
const cwd = options.cwd;
|
|
@@ -2165,6 +2224,7 @@ var InteractiveSession = class {
|
|
|
2165
2224
|
} catch {
|
|
2166
2225
|
}
|
|
2167
2226
|
const paths = projectPaths(cwd);
|
|
2227
|
+
const sessionId = this.resumeSessionId && !this.forkSession ? this.resumeSessionId : void 0;
|
|
2168
2228
|
this.session = createSession({
|
|
2169
2229
|
config: mergedConfig,
|
|
2170
2230
|
context,
|
|
@@ -2176,8 +2236,20 @@ var InteractiveSession = class {
|
|
|
2176
2236
|
permissionHandler: options.permissionHandler,
|
|
2177
2237
|
provider: options.provider,
|
|
2178
2238
|
onTextDelta: (delta) => this.handleTextDelta(delta),
|
|
2179
|
-
onToolExecution: (event) => this.handleToolExecution(event)
|
|
2239
|
+
onToolExecution: (event) => this.handleToolExecution(event),
|
|
2240
|
+
sessionId
|
|
2180
2241
|
});
|
|
2242
|
+
if (this.pendingRestoreMessages) {
|
|
2243
|
+
for (const msg of this.pendingRestoreMessages) {
|
|
2244
|
+
if (msg && typeof msg === "object" && "role" in msg && "content" in msg) {
|
|
2245
|
+
this.session.injectMessage(
|
|
2246
|
+
msg.role,
|
|
2247
|
+
msg.content
|
|
2248
|
+
);
|
|
2249
|
+
}
|
|
2250
|
+
}
|
|
2251
|
+
this.pendingRestoreMessages = null;
|
|
2252
|
+
}
|
|
2181
2253
|
this.initialized = true;
|
|
2182
2254
|
}
|
|
2183
2255
|
async ensureInitialized() {
|
|
@@ -2224,6 +2296,13 @@ var InteractiveSession = class {
|
|
|
2224
2296
|
await this.ensureInitialized();
|
|
2225
2297
|
return this.commandExecutor.execute(name, this, args);
|
|
2226
2298
|
}
|
|
2299
|
+
/** List all registered system commands. */
|
|
2300
|
+
listCommands() {
|
|
2301
|
+
return this.commandExecutor.listCommands().map((cmd) => ({
|
|
2302
|
+
name: cmd.name,
|
|
2303
|
+
description: cmd.description
|
|
2304
|
+
}));
|
|
2305
|
+
}
|
|
2227
2306
|
/** Abort current execution and clear queue. */
|
|
2228
2307
|
abort() {
|
|
2229
2308
|
this.pendingPrompt = null;
|
|
@@ -2260,6 +2339,26 @@ var InteractiveSession = class {
|
|
|
2260
2339
|
getContextState() {
|
|
2261
2340
|
return this.getSessionOrThrow().getContextState();
|
|
2262
2341
|
}
|
|
2342
|
+
/** Get session name. */
|
|
2343
|
+
getName() {
|
|
2344
|
+
return this.sessionName;
|
|
2345
|
+
}
|
|
2346
|
+
/** Set session name and persist if store is available. */
|
|
2347
|
+
setName(name) {
|
|
2348
|
+
this.sessionName = name;
|
|
2349
|
+
if (this.sessionStore && this.session) {
|
|
2350
|
+
try {
|
|
2351
|
+
const id = this.getSessionOrThrow().getSessionId();
|
|
2352
|
+
const existing = this.sessionStore.load(id);
|
|
2353
|
+
if (existing) {
|
|
2354
|
+
existing.name = name;
|
|
2355
|
+
existing.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
2356
|
+
this.sessionStore.save(existing);
|
|
2357
|
+
}
|
|
2358
|
+
} catch {
|
|
2359
|
+
}
|
|
2360
|
+
}
|
|
2361
|
+
}
|
|
2263
2362
|
/** Access underlying Session. For advanced use / testing only. */
|
|
2264
2363
|
getSession() {
|
|
2265
2364
|
return this.getSessionOrThrow();
|
|
@@ -2301,6 +2400,22 @@ var InteractiveSession = class {
|
|
|
2301
2400
|
} finally {
|
|
2302
2401
|
this.executing = false;
|
|
2303
2402
|
this.emit("thinking", false);
|
|
2403
|
+
if (this.sessionStore && this.session) {
|
|
2404
|
+
try {
|
|
2405
|
+
const sessionId = this.getSessionOrThrow().getSessionId();
|
|
2406
|
+
const existing = this.sessionStore.load(sessionId);
|
|
2407
|
+
this.sessionStore.save({
|
|
2408
|
+
id: sessionId,
|
|
2409
|
+
name: this.sessionName ?? existing?.name,
|
|
2410
|
+
cwd: this.cwd ?? "",
|
|
2411
|
+
createdAt: existing?.createdAt ?? (/* @__PURE__ */ new Date()).toISOString(),
|
|
2412
|
+
updatedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
2413
|
+
messages: this.getSessionOrThrow().getHistory(),
|
|
2414
|
+
history: this.history
|
|
2415
|
+
});
|
|
2416
|
+
} catch {
|
|
2417
|
+
}
|
|
2418
|
+
}
|
|
2304
2419
|
if (this.pendingPrompt) {
|
|
2305
2420
|
const queued = this.pendingPrompt;
|
|
2306
2421
|
const queuedDisplay = this.pendingDisplayInput;
|
|
@@ -2588,6 +2703,8 @@ function createBuiltinCommands() {
|
|
|
2588
2703
|
{ name: "cost", description: "Show session info", source: "builtin" },
|
|
2589
2704
|
{ name: "context", description: "Context window info", source: "builtin" },
|
|
2590
2705
|
{ name: "permissions", description: "Permission rules", source: "builtin" },
|
|
2706
|
+
{ name: "resume", description: "Resume a previous session", source: "builtin" },
|
|
2707
|
+
{ name: "rename", description: "Rename the current session", source: "builtin" },
|
|
2591
2708
|
{ name: "plugin", description: "Manage plugins", source: "builtin" },
|
|
2592
2709
|
{ name: "reload-plugins", description: "Reload all plugin resources", source: "builtin" },
|
|
2593
2710
|
{ name: "reset", description: "Delete settings and exit", source: "builtin" },
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@robota-sdk/agent-sdk",
|
|
3
|
-
"version": "3.0.0-beta.
|
|
3
|
+
"version": "3.0.0-beta.46",
|
|
4
4
|
"description": "Programmatic SDK for building AI agents with Robota — provides Session, query(), built-in tools, permissions, hooks, and context loading",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/node/index.js",
|
|
@@ -24,9 +24,9 @@
|
|
|
24
24
|
"dependencies": {
|
|
25
25
|
"chalk": "^5.3.0",
|
|
26
26
|
"zod": "^3.24.0",
|
|
27
|
-
"@robota-sdk/agent-core": "3.0.0-beta.
|
|
28
|
-
"@robota-sdk/agent-sessions": "3.0.0-beta.
|
|
29
|
-
"@robota-sdk/agent-tools": "3.0.0-beta.
|
|
27
|
+
"@robota-sdk/agent-core": "3.0.0-beta.46",
|
|
28
|
+
"@robota-sdk/agent-sessions": "3.0.0-beta.46",
|
|
29
|
+
"@robota-sdk/agent-tools": "3.0.0-beta.46"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
32
|
"rimraf": "^5.0.5",
|