@muse-code/sdk 1.4.13 → 1.4.15
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 +38 -3
- package/dist/src/connection/connection.js +2 -1
- package/dist/src/connection/discovery.d.ts +14 -0
- package/dist/src/connection/discovery.js +39 -0
- package/dist/src/errors.d.ts +37 -0
- package/dist/src/errors.js +52 -0
- package/dist/src/facade/approval.js +6 -0
- package/dist/src/facade/client.d.ts +76 -10
- package/dist/src/facade/client.js +152 -10
- package/dist/src/facade/run.d.ts +50 -0
- package/dist/src/facade/run.js +132 -0
- package/dist/src/facade/session.d.ts +83 -3
- package/dist/src/facade/session.js +290 -2
- package/dist/src/facade/turn-handle.d.ts +65 -6
- package/dist/src/facade/turn-handle.js +19 -3
- package/dist/src/facade/turn-submit.d.ts +27 -16
- package/dist/src/facade/turn-submit.js +68 -28
- package/dist/src/fingerprint.d.ts +4 -18
- package/dist/src/fingerprint.js +30 -20
- package/dist/src/fingerprint.stamped.d.ts +1 -0
- package/dist/src/fingerprint.stamped.js +6 -0
- package/dist/src/fold/session-fold.d.ts +19 -5
- package/dist/src/fold/session-fold.js +73 -1
- package/dist/src/index.d.ts +5 -4
- package/dist/src/index.js +1 -1
- package/dist/src/msp.d.ts +436 -25
- package/package.json +3 -1
|
@@ -14,7 +14,8 @@
|
|
|
14
14
|
*
|
|
15
15
|
* - the TURN LIFECYCLE — `turn/started`, `turn/completed`, `turn/retracted`,
|
|
16
16
|
* `turn/unqueued`, and the non-terminal `turn/retryScheduled`,
|
|
17
|
-
* `turn/modelRetryScheduled`,
|
|
17
|
+
* `turn/modelRetryScheduled`, `turn/modelAttemptStarted`, and
|
|
18
|
+
* `turn/foregroundCompleted`;
|
|
18
19
|
* - the APPROVAL and USER-INPUT view events as fold INPUTS — the pending
|
|
19
20
|
* sets and their first durable terminal. The decision flow (choosing and
|
|
20
21
|
* sending a resolution) is the facade's, not the fold's;
|
|
@@ -75,6 +76,8 @@ export class SessionFold {
|
|
|
75
76
|
#pendingApprovals = new Map();
|
|
76
77
|
#resolvedApprovals = new Map();
|
|
77
78
|
#pendingUserInputs = new Map();
|
|
79
|
+
/** Pending prompt ids by turn, so retiring a turn's prompts costs that turn's count, not every pending prompt. */
|
|
80
|
+
#pendingUserInputIdsByTurn = new Map();
|
|
78
81
|
#settledUserInputs = new Map();
|
|
79
82
|
#activeTurnId;
|
|
80
83
|
#pendingGap;
|
|
@@ -171,6 +174,8 @@ export class SessionFold {
|
|
|
171
174
|
return this.#turnRetryScheduled(typed.params);
|
|
172
175
|
case "turn/modelRetryScheduled":
|
|
173
176
|
return this.#turnModelRetryScheduled(typed.params);
|
|
177
|
+
case "turn/modelAttemptStarted":
|
|
178
|
+
return this.#turnModelAttemptStarted(typed.params);
|
|
174
179
|
case "turn/foregroundCompleted":
|
|
175
180
|
return this.#turnForegroundCompleted(typed.params);
|
|
176
181
|
case "approval/requested":
|
|
@@ -285,10 +290,14 @@ export class SessionFold {
|
|
|
285
290
|
// Same for the provider-backoff hint: a finished turn is not waiting
|
|
286
291
|
// out a backoff (tdd SS4.5.1).
|
|
287
292
|
turn.modelRetryScheduled = undefined;
|
|
293
|
+
// Same for the attempt hint: a finished turn's model is not working
|
|
294
|
+
// (tdd SS4.5.1).
|
|
295
|
+
turn.modelAttemptStarted = undefined;
|
|
288
296
|
// Same for the foreground hint: a finished turn is not background-waiting
|
|
289
297
|
// (tdd SS4.5.12).
|
|
290
298
|
turn.foregroundCompleted = undefined;
|
|
291
299
|
this.#clearActive(params.turnId);
|
|
300
|
+
this.#retirePendingUserInputsFor(params.turnId);
|
|
292
301
|
return { kind: "turn", turnId: params.turnId, state: turn.state };
|
|
293
302
|
}
|
|
294
303
|
#turnRetracted(params) {
|
|
@@ -315,6 +324,7 @@ export class SessionFold {
|
|
|
315
324
|
// `item/updated` with `retracted: true`, which the item half folds.
|
|
316
325
|
turn.state = "retracted";
|
|
317
326
|
this.#clearActive(params.turnId);
|
|
327
|
+
this.#retirePendingUserInputsFor(params.turnId);
|
|
318
328
|
return { kind: "turn", turnId: params.turnId, state: turn.state };
|
|
319
329
|
}
|
|
320
330
|
#turnUnqueued(params) {
|
|
@@ -326,6 +336,7 @@ export class SessionFold {
|
|
|
326
336
|
turn.commandId = params.commandId;
|
|
327
337
|
turn.state = "unqueued";
|
|
328
338
|
this.#clearActive(params.turnId);
|
|
339
|
+
this.#retirePendingUserInputsFor(params.turnId);
|
|
329
340
|
return { kind: "turn", turnId: params.turnId, state: turn.state };
|
|
330
341
|
}
|
|
331
342
|
#turnRetryScheduled(params) {
|
|
@@ -355,6 +366,18 @@ export class SessionFold {
|
|
|
355
366
|
turn.modelRetryScheduled = params;
|
|
356
367
|
return { kind: "turn", turnId: params.turnId, state: turn.state };
|
|
357
368
|
}
|
|
369
|
+
#turnModelAttemptStarted(params) {
|
|
370
|
+
// Non-terminal by contract: it never resolves a turn-wait (tdd SS4.5.1).
|
|
371
|
+
const turn = this.#turnFor(params.turnId);
|
|
372
|
+
// …but it is still a turn frame, so it takes the same redelivery guard
|
|
373
|
+
// as the retry hint: a replayed page must not re-plant the attempt hint
|
|
374
|
+
// on a turn that already left `running`.
|
|
375
|
+
if (turn.state !== "running") {
|
|
376
|
+
return { kind: "ignoredStaleFrame", method: "turn/modelAttemptStarted", id: params.turnId };
|
|
377
|
+
}
|
|
378
|
+
turn.modelAttemptStarted = params;
|
|
379
|
+
return { kind: "turn", turnId: params.turnId, state: turn.state };
|
|
380
|
+
}
|
|
358
381
|
#turnForegroundCompleted(params) {
|
|
359
382
|
// Non-terminal by contract: it never resolves a turn-wait (tdd SS4.5.12).
|
|
360
383
|
const turn = this.#turnFor(params.turnId);
|
|
@@ -379,6 +402,39 @@ export class SessionFold {
|
|
|
379
402
|
if (this.#activeTurnId === turnId)
|
|
380
403
|
this.#activeTurnId = undefined;
|
|
381
404
|
}
|
|
405
|
+
// A prompt listed while its turn ran retires when that turn leaves
|
|
406
|
+
// `running`: no answer can settle it afterwards, so keeping it listed
|
|
407
|
+
// pends it forever (the reported started→requested→completed order).
|
|
408
|
+
// Retiring records no settlement — the prompt was never answered.
|
|
409
|
+
// Cost is the ending turn's own prompt count via the by-turn index,
|
|
410
|
+
// never a scan over every pending prompt.
|
|
411
|
+
#retirePendingUserInputsFor(turnId) {
|
|
412
|
+
const ids = this.#pendingUserInputIdsByTurn.get(turnId);
|
|
413
|
+
if (ids === undefined)
|
|
414
|
+
return;
|
|
415
|
+
for (const userInputId of ids)
|
|
416
|
+
this.#pendingUserInputs.delete(userInputId);
|
|
417
|
+
this.#pendingUserInputIdsByTurn.delete(turnId);
|
|
418
|
+
}
|
|
419
|
+
#indexPendingUserInput(params) {
|
|
420
|
+
let ids = this.#pendingUserInputIdsByTurn.get(params.turnId);
|
|
421
|
+
if (ids === undefined) {
|
|
422
|
+
ids = new Set();
|
|
423
|
+
this.#pendingUserInputIdsByTurn.set(params.turnId, ids);
|
|
424
|
+
}
|
|
425
|
+
ids.add(params.userInputId);
|
|
426
|
+
}
|
|
427
|
+
#unindexPendingUserInput(userInputId) {
|
|
428
|
+
const params = this.#pendingUserInputs.get(userInputId);
|
|
429
|
+
if (params === undefined)
|
|
430
|
+
return;
|
|
431
|
+
const ids = this.#pendingUserInputIdsByTurn.get(params.turnId);
|
|
432
|
+
if (ids === undefined)
|
|
433
|
+
return;
|
|
434
|
+
ids.delete(userInputId);
|
|
435
|
+
if (ids.size === 0)
|
|
436
|
+
this.#pendingUserInputIdsByTurn.delete(params.turnId);
|
|
437
|
+
}
|
|
382
438
|
static #turnSnapshot(turn) {
|
|
383
439
|
return {
|
|
384
440
|
turnId: turn.turnId,
|
|
@@ -390,6 +446,9 @@ export class SessionFold {
|
|
|
390
446
|
...(turn.modelRetryScheduled !== undefined
|
|
391
447
|
? { modelRetryScheduled: turn.modelRetryScheduled }
|
|
392
448
|
: {}),
|
|
449
|
+
...(turn.modelAttemptStarted !== undefined
|
|
450
|
+
? { modelAttemptStarted: turn.modelAttemptStarted }
|
|
451
|
+
: {}),
|
|
393
452
|
...(turn.foregroundCompleted !== undefined
|
|
394
453
|
? { foregroundCompleted: turn.foregroundCompleted }
|
|
395
454
|
: {}),
|
|
@@ -476,10 +535,23 @@ export class SessionFold {
|
|
|
476
535
|
if (this.#settledUserInputs.has(params.userInputId)) {
|
|
477
536
|
return { kind: "ignoredStaleFrame", method: "userInput/requested", id: params.userInputId };
|
|
478
537
|
}
|
|
538
|
+
// A prompt for a turn this fold has already seen leave `running` is an
|
|
539
|
+
// orphan: no answer can settle it, so listing it would pend forever and
|
|
540
|
+
// an answer attempt would only bounce off the host. Guarded to KNOWN
|
|
541
|
+
// dead turns only — a prompt naming a turn the fold has never seen
|
|
542
|
+
// (a fresh resume re-sending a still-open question) still lists, since
|
|
543
|
+
// this fold cannot prove that turn dead.
|
|
544
|
+
const turn = this.#turns.get(params.turnId);
|
|
545
|
+
if (turn !== undefined && turn.state !== "running") {
|
|
546
|
+
return { kind: "ignoredStaleFrame", method: "userInput/requested", id: params.userInputId };
|
|
547
|
+
}
|
|
548
|
+
this.#unindexPendingUserInput(params.userInputId);
|
|
479
549
|
this.#pendingUserInputs.set(params.userInputId, params);
|
|
550
|
+
this.#indexPendingUserInput(params);
|
|
480
551
|
return { kind: "userInputPending", userInputId: params.userInputId };
|
|
481
552
|
}
|
|
482
553
|
#userInputSettled(params) {
|
|
554
|
+
this.#unindexPendingUserInput(params.userInputId);
|
|
483
555
|
this.#pendingUserInputs.delete(params.userInputId);
|
|
484
556
|
const firstSettlement = !this.#settledUserInputs.has(params.userInputId);
|
|
485
557
|
if (firstSettlement)
|
package/dist/src/index.d.ts
CHANGED
|
@@ -50,7 +50,7 @@ export { MuseClient } from "./facade/client.js";
|
|
|
50
50
|
export type { MuseClientOptions, MuseClientSpawnOptions, ResumeSessionOptions, StartSessionOptions, } from "./facade/client.js";
|
|
51
51
|
export type { ExitClassification, MuseServeChildOptions, ProcessExit, SpawnMspConnectionOptions, } from "./connection/spawn.js";
|
|
52
52
|
export { DiscardedSessions } from "./facade/discarded.js";
|
|
53
|
-
export { MuseForeignSessionError, MuseGapFillError, MuseSessionDiscardedError, PermissionProfileNotApplied, } from "./errors.js";
|
|
53
|
+
export { MuseCapabilityNotGrantedError, MuseFacadeOwnedMethodError, MuseForeignSessionError, MuseGapFillError, MuseHostDiscoveryError, MuseSessionDiscardedError, PermissionProfileNotApplied, } from "./errors.js";
|
|
54
54
|
export type { GapFillFailureReason } from "./errors.js";
|
|
55
55
|
export type { GapFillFailureHandler } from "./facade/gap-fill.js";
|
|
56
56
|
export { MuseHostDiedError, readSessionDurability } from "./facade/host-death.js";
|
|
@@ -58,8 +58,9 @@ export { MuseHostStartError } from "./facade/host-start.js";
|
|
|
58
58
|
export type { HostStartFailure } from "./facade/host-start.js";
|
|
59
59
|
export type { AbnormalExit, HostDeathDischarge, HostDeathNotification, SessionDurabilityProfile, TransportEof, } from "./facade/host-death.js";
|
|
60
60
|
export { Session } from "./facade/session.js";
|
|
61
|
-
export type { PendingCommandView, SessionApplyOutcome, SessionApplyRefusal, SessionFoldView, SessionGapBuffered, SessionGapOverlap, SessionOpening, SessionOptions, } from "./facade/session.js";
|
|
61
|
+
export type { PendingCommandView, SessionApplyOutcome, SessionApplyRefusal, SessionFoldView, SessionGapBuffered, SessionGapOverlap, SessionOpening, SessionOptions, SubagentReasonOptions, } from "./facade/session.js";
|
|
62
62
|
export type { ApprovalDecisionInput, ApprovalFailure, ApprovalFailureHandler, ApprovalHandler, } from "./facade/approval.js";
|
|
63
|
-
export type { SendUserTurnOptions } from "./facade/turn-submit.js";
|
|
63
|
+
export type { SendUserTurnOptions, SteerTurnOptions } from "./facade/turn-submit.js";
|
|
64
|
+
export type { RunOptions, RunResult } from "./facade/run.js";
|
|
64
65
|
export { isLaunchFailure } from "./facade/turn-handle.js";
|
|
65
|
-
export type { FoldedItem, Turn, TurnOutcome } from "./facade/turn-handle.js";
|
|
66
|
+
export type { FoldedItem, InterruptTurnOptions, Turn, TurnOutcome, TurnUnqueueOutcome, } from "./facade/turn-handle.js";
|
package/dist/src/index.js
CHANGED
|
@@ -40,7 +40,7 @@ export { MuseClient } from "./facade/client.js";
|
|
|
40
40
|
// none — the cross-client sharing knob was declined (Constitution XI; see the
|
|
41
41
|
// constructor note in `facade/client.ts`).
|
|
42
42
|
export { DiscardedSessions } from "./facade/discarded.js";
|
|
43
|
-
export { MuseForeignSessionError, MuseGapFillError, MuseSessionDiscardedError, PermissionProfileNotApplied, } from "./errors.js";
|
|
43
|
+
export { MuseCapabilityNotGrantedError, MuseFacadeOwnedMethodError, MuseForeignSessionError, MuseGapFillError, MuseHostDiscoveryError, MuseSessionDiscardedError, PermissionProfileNotApplied, } from "./errors.js";
|
|
44
44
|
// Trimmed deliberately (Constitution XI): `isAbnormalHostDeath`,
|
|
45
45
|
// `isItemInProgress`, and `survivesHostDeath` are `Session`'s own internals
|
|
46
46
|
// with no consumer, and a barrel export would freeze them into `@muse-code/sdk`'s
|