@retaw106/mmc-oc 1.2.1 → 1.2.2

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.
@@ -1,126 +0,0 @@
1
- import {
2
- clearEmergencyRecovery,
3
- dropSlot,
4
- renderUserFacingFailure,
5
- userFacingFailureCode,
6
- executeContextRecomp
7
- } from "./index-xyjcjq10.js";
8
- import {
9
- sessionLog
10
- } from "./index-qbkzdkk0.js";
11
-
12
- // src/hooks/magic-context/recomp-orchestrator.ts
13
- function resolveLiveModelKey(liveSessionState, sessionId) {
14
- const model = liveSessionState.liveModelBySession.get(sessionId);
15
- return model ? `${model.providerID}/${model.modelID}` : undefined;
16
- }
17
- function isRecompFailure(message) {
18
- return /—\s*(Failed|Skipped)/.test(message);
19
- }
20
- function isRecompSkip(message) {
21
- return /—\s*Skipped|already mutating compartment state|already running/i.test(message);
22
- }
23
- function extractRecompReason(raw) {
24
- const meaningful = raw.split(`
25
- `).map((l) => l.trim()).filter((l) => l.length > 0 && !l.startsWith("#"));
26
- return meaningful.join(" ").trim() || "Recomp finished";
27
- }
28
- var RECOMP_DONE_GRACE_MS = 30000;
29
- function setRecompStarting2(liveSessionState, sessionId, note, kind = "recomp") {
30
- dropSlot(sessionId, "recomp-start");
31
- liveSessionState.recompProgressBySession.set(sessionId, {
32
- sessionId,
33
- kind,
34
- phase: "recomp",
35
- processedMessages: 0,
36
- totalMessages: 0,
37
- passCount: 0,
38
- compartmentsCreated: 0,
39
- startedAt: Date.now(),
40
- updatedAt: Date.now(),
41
- note
42
- });
43
- }
44
- function setRecompTerminal2(liveSessionState, sessionId, phase, message) {
45
- const existing = liveSessionState.recompProgressBySession.get(sessionId);
46
- liveSessionState.recompProgressBySession.set(sessionId, {
47
- sessionId,
48
- kind: existing?.kind ?? "recomp",
49
- phase,
50
- processedMessages: existing?.processedMessages ?? 0,
51
- totalMessages: existing?.totalMessages ?? 0,
52
- passCount: existing?.passCount ?? 0,
53
- compartmentsCreated: existing?.compartmentsCreated ?? 0,
54
- startedAt: existing?.startedAt ?? Date.now(),
55
- updatedAt: Date.now(),
56
- message
57
- });
58
- if (phase === "done" || phase === "skipped") {
59
- const t = setTimeout(() => {
60
- const cur = liveSessionState.recompProgressBySession.get(sessionId);
61
- if (cur?.phase === phase)
62
- liveSessionState.recompProgressBySession.delete(sessionId);
63
- }, RECOMP_DONE_GRACE_MS);
64
- t.unref?.();
65
- }
66
- }
67
- function buildRecompDeps(ctx, sessionId) {
68
- return {
69
- client: ctx.client,
70
- hiddenCompletionExecutor: ctx.hiddenCompletionExecutor,
71
- db: ctx.db,
72
- sessionId,
73
- historianChunkTokens: ctx.historianChunkTokens,
74
- historianTimeoutMs: ctx.historianTimeoutMs,
75
- directory: ctx.directory,
76
- memoryEnabled: ctx.memoryEnabled,
77
- autoPromote: ctx.autoPromote,
78
- model: ctx.historianModel,
79
- historianContextLimit: ctx.historianContextLimit,
80
- historianMaxOutputTokens: ctx.historianMaxOutputTokens,
81
- fallbackModels: ctx.fallbackModels,
82
- language: ctx.language,
83
- fallbackModelId: ctx.fallbackModelId ?? resolveLiveModelKey(ctx.liveSessionState, sessionId),
84
- historianTwoPass: ctx.historianTwoPass,
85
- historianExpandTools: ctx.historianExpandTools,
86
- ensureProjectRegistered: ctx.ensureProjectRegistered,
87
- getNotificationParams: () => ctx.getNotificationParams(sessionId),
88
- onCompartmentStatePublished: (sid) => {
89
- ctx.liveSessionState.historyRefreshSessions.add(sid);
90
- ctx.liveSessionState.pendingMaterializationSessions.add(sid);
91
- },
92
- onDeferredMarkerPending: (sid) => {
93
- ctx.liveSessionState.deferredHistoryRefreshSessions.add(sid);
94
- },
95
- onRecompProgress: (p) => {
96
- const prevKind = ctx.liveSessionState.recompProgressBySession.get(sessionId)?.kind ?? "recomp";
97
- ctx.liveSessionState.recompProgressBySession.set(sessionId, {
98
- ...p,
99
- kind: p.kind ?? prevKind
100
- });
101
- }
102
- };
103
- }
104
- async function runManagedRecomp2(ctx, sessionId, options) {
105
- setRecompStarting2(ctx.liveSessionState, sessionId, "Starting recomp…", "recomp");
106
- try {
107
- const message = await executeContextRecomp(buildRecompDeps(ctx, sessionId), options);
108
- const terminalPhase = isRecompSkip(message) ? "skipped" : isRecompFailure(message) ? "failed" : "done";
109
- if (terminalPhase === "done") {
110
- try {
111
- clearEmergencyRecovery(ctx.db, sessionId);
112
- } catch {}
113
- }
114
- setRecompTerminal2(ctx.liveSessionState, sessionId, terminalPhase, extractRecompReason(message));
115
- return message;
116
- } catch (error) {
117
- const failure = renderUserFacingFailure("recomp_unavailable");
118
- sessionLog(sessionId, `recomp failed code=${userFacingFailureCode("recomp_unavailable")}`, error);
119
- setRecompTerminal2(ctx.liveSessionState, sessionId, "failed", failure);
120
- return `## Magic Recomp — Failed
121
-
122
- ${failure}`;
123
- }
124
- }
125
-
126
- export { setRecompStarting2, setRecompTerminal2, runManagedRecomp2 };
@@ -1,126 +0,0 @@
1
- import {
2
- clearEmergencyRecovery,
3
- dropSlot,
4
- renderUserFacingFailure,
5
- userFacingFailureCode,
6
- executeContextRecomp
7
- } from "./index-46j0tj1s.js";
8
- import {
9
- sessionLog
10
- } from "./index-qbkzdkk0.js";
11
-
12
- // src/hooks/magic-context/recomp-orchestrator.ts
13
- function resolveLiveModelKey(liveSessionState, sessionId) {
14
- const model = liveSessionState.liveModelBySession.get(sessionId);
15
- return model ? `${model.providerID}/${model.modelID}` : undefined;
16
- }
17
- function isRecompFailure(message) {
18
- return /—\s*(Failed|Skipped)/.test(message);
19
- }
20
- function isRecompSkip(message) {
21
- return /—\s*Skipped|already mutating compartment state|already running/i.test(message);
22
- }
23
- function extractRecompReason(raw) {
24
- const meaningful = raw.split(`
25
- `).map((l) => l.trim()).filter((l) => l.length > 0 && !l.startsWith("#"));
26
- return meaningful.join(" ").trim() || "Recomp finished";
27
- }
28
- var RECOMP_DONE_GRACE_MS = 30000;
29
- function setRecompStarting2(liveSessionState, sessionId, note, kind = "recomp") {
30
- dropSlot(sessionId, "recomp-start");
31
- liveSessionState.recompProgressBySession.set(sessionId, {
32
- sessionId,
33
- kind,
34
- phase: "recomp",
35
- processedMessages: 0,
36
- totalMessages: 0,
37
- passCount: 0,
38
- compartmentsCreated: 0,
39
- startedAt: Date.now(),
40
- updatedAt: Date.now(),
41
- note
42
- });
43
- }
44
- function setRecompTerminal2(liveSessionState, sessionId, phase, message) {
45
- const existing = liveSessionState.recompProgressBySession.get(sessionId);
46
- liveSessionState.recompProgressBySession.set(sessionId, {
47
- sessionId,
48
- kind: existing?.kind ?? "recomp",
49
- phase,
50
- processedMessages: existing?.processedMessages ?? 0,
51
- totalMessages: existing?.totalMessages ?? 0,
52
- passCount: existing?.passCount ?? 0,
53
- compartmentsCreated: existing?.compartmentsCreated ?? 0,
54
- startedAt: existing?.startedAt ?? Date.now(),
55
- updatedAt: Date.now(),
56
- message
57
- });
58
- if (phase === "done" || phase === "skipped") {
59
- const t = setTimeout(() => {
60
- const cur = liveSessionState.recompProgressBySession.get(sessionId);
61
- if (cur?.phase === phase)
62
- liveSessionState.recompProgressBySession.delete(sessionId);
63
- }, RECOMP_DONE_GRACE_MS);
64
- t.unref?.();
65
- }
66
- }
67
- function buildRecompDeps(ctx, sessionId) {
68
- return {
69
- client: ctx.client,
70
- hiddenCompletionExecutor: ctx.hiddenCompletionExecutor,
71
- db: ctx.db,
72
- sessionId,
73
- historianChunkTokens: ctx.historianChunkTokens,
74
- historianTimeoutMs: ctx.historianTimeoutMs,
75
- directory: ctx.directory,
76
- memoryEnabled: ctx.memoryEnabled,
77
- autoPromote: ctx.autoPromote,
78
- model: ctx.historianModel,
79
- historianContextLimit: ctx.historianContextLimit,
80
- historianMaxOutputTokens: ctx.historianMaxOutputTokens,
81
- fallbackModels: ctx.fallbackModels,
82
- language: ctx.language,
83
- fallbackModelId: ctx.fallbackModelId ?? resolveLiveModelKey(ctx.liveSessionState, sessionId),
84
- historianTwoPass: ctx.historianTwoPass,
85
- historianExpandTools: ctx.historianExpandTools,
86
- ensureProjectRegistered: ctx.ensureProjectRegistered,
87
- getNotificationParams: () => ctx.getNotificationParams(sessionId),
88
- onCompartmentStatePublished: (sid) => {
89
- ctx.liveSessionState.historyRefreshSessions.add(sid);
90
- ctx.liveSessionState.pendingMaterializationSessions.add(sid);
91
- },
92
- onDeferredMarkerPending: (sid) => {
93
- ctx.liveSessionState.deferredHistoryRefreshSessions.add(sid);
94
- },
95
- onRecompProgress: (p) => {
96
- const prevKind = ctx.liveSessionState.recompProgressBySession.get(sessionId)?.kind ?? "recomp";
97
- ctx.liveSessionState.recompProgressBySession.set(sessionId, {
98
- ...p,
99
- kind: p.kind ?? prevKind
100
- });
101
- }
102
- };
103
- }
104
- async function runManagedRecomp2(ctx, sessionId, options) {
105
- setRecompStarting2(ctx.liveSessionState, sessionId, "Starting recomp…", "recomp");
106
- try {
107
- const message = await executeContextRecomp(buildRecompDeps(ctx, sessionId), options);
108
- const terminalPhase = isRecompSkip(message) ? "skipped" : isRecompFailure(message) ? "failed" : "done";
109
- if (terminalPhase === "done") {
110
- try {
111
- clearEmergencyRecovery(ctx.db, sessionId);
112
- } catch {}
113
- }
114
- setRecompTerminal2(ctx.liveSessionState, sessionId, terminalPhase, extractRecompReason(message));
115
- return message;
116
- } catch (error) {
117
- const failure = renderUserFacingFailure("recomp_unavailable");
118
- sessionLog(sessionId, `recomp failed code=${userFacingFailureCode("recomp_unavailable")}`, error);
119
- setRecompTerminal2(ctx.liveSessionState, sessionId, "failed", failure);
120
- return `## Magic Recomp — Failed
121
-
122
- ${failure}`;
123
- }
124
- }
125
-
126
- export { setRecompStarting2, setRecompTerminal2, runManagedRecomp2 };