@zetaloop/chappie 0.3.0 → 0.3.1
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 +1 -1
- package/src/session.ts +26 -12
package/package.json
CHANGED
package/src/session.ts
CHANGED
|
@@ -58,7 +58,6 @@ export class LocalSession {
|
|
|
58
58
|
readonly #syncs = new Map<number, SyncRequest>();
|
|
59
59
|
readonly #stores = new Map<string, StoreRequest>();
|
|
60
60
|
readonly #queue: RemoteRequest[] = [];
|
|
61
|
-
readonly #seenInputs = new Set<string>();
|
|
62
61
|
readonly #pendingInputs = new Map<string, SessionInput>();
|
|
63
62
|
readonly #deliveries = new Map<string, DeliveryRecord>();
|
|
64
63
|
#context: ExtensionContext | undefined;
|
|
@@ -98,6 +97,12 @@ export class LocalSession {
|
|
|
98
97
|
this.#context = context;
|
|
99
98
|
void this.#sync().catch(() => {});
|
|
100
99
|
});
|
|
100
|
+
this.#pi.on("session_tree", (event, context) => {
|
|
101
|
+
this.#context = context;
|
|
102
|
+
if (context.model?.provider === "chappie") {
|
|
103
|
+
this.#resetInputs(context, event.newLeafId);
|
|
104
|
+
}
|
|
105
|
+
});
|
|
101
106
|
this.#pi.on("context", (event, context) => ({
|
|
102
107
|
messages:
|
|
103
108
|
context.model?.provider === "chappie"
|
|
@@ -171,6 +176,7 @@ export class LocalSession {
|
|
|
171
176
|
this.#connection?.close();
|
|
172
177
|
this.#connection = undefined;
|
|
173
178
|
this.#context = undefined;
|
|
179
|
+
this.#resetInputs();
|
|
174
180
|
this.#rejectSyncs(new Error("Chappie session ended"));
|
|
175
181
|
this.#rejectStores(new Error("Chappie session ended"));
|
|
176
182
|
}
|
|
@@ -184,6 +190,9 @@ export class LocalSession {
|
|
|
184
190
|
this.close();
|
|
185
191
|
return;
|
|
186
192
|
}
|
|
193
|
+
if (this.#sessionId !== context.sessionManager.getSessionId()) {
|
|
194
|
+
this.#resetInputs(context);
|
|
195
|
+
}
|
|
187
196
|
if (!this.#connection) {
|
|
188
197
|
this.#notify("Connecting to Chappie…");
|
|
189
198
|
this.#connection = new IpcClient(this.#agentDir, this.#connect, {
|
|
@@ -448,16 +457,23 @@ export class LocalSession {
|
|
|
448
457
|
void this.#sync().catch(() => {});
|
|
449
458
|
}
|
|
450
459
|
|
|
460
|
+
#resetInputs(
|
|
461
|
+
context?: ExtensionContext,
|
|
462
|
+
cursor = context?.sessionManager.getLeafId() ?? null,
|
|
463
|
+
): void {
|
|
464
|
+
this.#sessionId = context?.sessionManager.getSessionId();
|
|
465
|
+
this.#inputCursor = cursor;
|
|
466
|
+
this.#pendingInputs.clear();
|
|
467
|
+
}
|
|
468
|
+
|
|
451
469
|
#collectInputs(): void {
|
|
452
470
|
const context = this.#context;
|
|
453
471
|
if (!context) return;
|
|
454
472
|
const sessionManager = context.sessionManager;
|
|
455
473
|
const sessionId = sessionManager.getSessionId();
|
|
456
474
|
if (this.#sessionId !== sessionId) {
|
|
457
|
-
this.#
|
|
458
|
-
|
|
459
|
-
this.#seenInputs.clear();
|
|
460
|
-
this.#pendingInputs.clear();
|
|
475
|
+
this.#resetInputs(context);
|
|
476
|
+
return;
|
|
461
477
|
}
|
|
462
478
|
const leafId = sessionManager.getLeafId();
|
|
463
479
|
if (leafId === this.#inputCursor) return;
|
|
@@ -469,18 +485,16 @@ export class LocalSession {
|
|
|
469
485
|
? sessionManager.getEntry(current.parentId)
|
|
470
486
|
: undefined;
|
|
471
487
|
}
|
|
488
|
+
if (this.#inputCursor !== null && !current) {
|
|
489
|
+
this.#resetInputs(context);
|
|
490
|
+
return;
|
|
491
|
+
}
|
|
472
492
|
for (const entry of entries.reverse()) {
|
|
473
|
-
if (
|
|
474
|
-
entry.type !== "message" ||
|
|
475
|
-
entry.message.role !== "user" ||
|
|
476
|
-
this.#seenInputs.has(entry.id)
|
|
477
|
-
)
|
|
478
|
-
continue;
|
|
493
|
+
if (entry.type !== "message" || entry.message.role !== "user") continue;
|
|
479
494
|
const message = entry.message as UserMessage;
|
|
480
495
|
if (typeof message.content !== "string") {
|
|
481
496
|
rememberImages(sessionId, message.content);
|
|
482
497
|
}
|
|
483
|
-
this.#seenInputs.add(entry.id);
|
|
484
498
|
this.#pendingInputs.set(entry.id, { id: entry.id, sessionId, message });
|
|
485
499
|
}
|
|
486
500
|
this.#inputCursor = leafId;
|