@jungjaehoon/mama-os 0.64.0 → 0.66.0
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/CHANGELOG.md +65 -0
- package/README.md +14 -13
- package/dist/api/help-actions.js +1 -1
- package/dist/api/help-actions.js.map +1 -1
- package/dist/api/owner-message-actions.d.ts +1 -3
- package/dist/api/owner-message-actions.d.ts.map +1 -1
- package/dist/api/owner-message-actions.js +1 -6
- package/dist/api/owner-message-actions.js.map +1 -1
- package/dist/api/owner-policy-actions.d.ts +8 -0
- package/dist/api/owner-policy-actions.d.ts.map +1 -0
- package/dist/api/owner-policy-actions.js +160 -0
- package/dist/api/owner-policy-actions.js.map +1 -0
- package/dist/api/report-source-actions.d.ts.map +1 -1
- package/dist/api/report-source-actions.js +3 -1
- package/dist/api/report-source-actions.js.map +1 -1
- package/dist/api/wiki-actions.js +3 -3
- package/dist/api/wiki-actions.js.map +1 -1
- package/dist/api/work-actions.d.ts.map +1 -1
- package/dist/api/work-actions.js +9 -2
- package/dist/api/work-actions.js.map +1 -1
- package/dist/backfill/format.d.ts +2 -0
- package/dist/backfill/format.d.ts.map +1 -1
- package/dist/backfill/format.js +8 -3
- package/dist/backfill/format.js.map +1 -1
- package/dist/backfill/push.d.ts.map +1 -1
- package/dist/backfill/push.js +1 -0
- package/dist/backfill/push.js.map +1 -1
- package/dist/cli/commands/daemon.d.ts +0 -1
- package/dist/cli/commands/daemon.d.ts.map +1 -1
- package/dist/cli/commands/daemon.js +1 -1
- package/dist/cli/commands/daemon.js.map +1 -1
- package/dist/gateways/discord.d.ts +0 -1
- package/dist/gateways/discord.d.ts.map +1 -1
- package/dist/gateways/discord.js +23 -4
- package/dist/gateways/discord.js.map +1 -1
- package/dist/gateways/slack.d.ts +0 -1
- package/dist/gateways/slack.d.ts.map +1 -1
- package/dist/gateways/slack.js +23 -4
- package/dist/gateways/slack.js.map +1 -1
- package/dist/gateways/telegram-format.d.ts +0 -13
- package/dist/gateways/telegram-format.d.ts.map +1 -1
- package/dist/gateways/telegram-format.js +1 -42
- package/dist/gateways/telegram-format.js.map +1 -1
- package/dist/gateways/telegram-message-ledger.d.ts +3 -2
- package/dist/gateways/telegram-message-ledger.d.ts.map +1 -1
- package/dist/gateways/telegram-message-ledger.js +10 -9
- package/dist/gateways/telegram-message-ledger.js.map +1 -1
- package/dist/gateways/telegram-response-presenter.d.ts +6 -14
- package/dist/gateways/telegram-response-presenter.d.ts.map +1 -1
- package/dist/gateways/telegram-response-presenter.js +13 -98
- package/dist/gateways/telegram-response-presenter.js.map +1 -1
- package/dist/gateways/telegram.d.ts +0 -1
- package/dist/gateways/telegram.d.ts.map +1 -1
- package/dist/gateways/telegram.js +17 -5
- package/dist/gateways/telegram.js.map +1 -1
- package/dist/gateways/turn-contract.d.ts +8 -0
- package/dist/gateways/turn-contract.d.ts.map +1 -1
- package/dist/replay/import-manifest.d.ts +2 -2
- package/dist/replay/import-manifest.d.ts.map +1 -1
- package/dist/replay/import-manifest.js.map +1 -1
- package/dist/replay/replay-source-catalog.d.ts.map +1 -1
- package/dist/replay/replay-source-catalog.js +1 -0
- package/dist/replay/replay-source-catalog.js.map +1 -1
- package/dist/runtime/action-surface.d.ts +2 -1
- package/dist/runtime/action-surface.d.ts.map +1 -1
- package/dist/runtime/action-surface.js +32 -3
- package/dist/runtime/action-surface.js.map +1 -1
- package/dist/runtime/native-session.d.ts +1 -0
- package/dist/runtime/native-session.d.ts.map +1 -1
- package/dist/runtime/native-session.js +3 -0
- package/dist/runtime/native-session.js.map +1 -1
- package/dist/runtime/owner-authority.d.ts +4 -2
- package/dist/runtime/owner-authority.d.ts.map +1 -1
- package/dist/runtime/owner-authority.js +23 -3
- package/dist/runtime/owner-authority.js.map +1 -1
- package/dist/runtime/owner-policy.d.ts +3 -0
- package/dist/runtime/owner-policy.d.ts.map +1 -1
- package/dist/runtime/owner-policy.js +16 -3
- package/dist/runtime/owner-policy.js.map +1 -1
- package/dist/runtime/owner-runtime.d.ts +2 -3
- package/dist/runtime/owner-runtime.d.ts.map +1 -1
- package/dist/runtime/owner-runtime.js +15 -23
- package/dist/runtime/owner-runtime.js.map +1 -1
- package/dist/runtime/owner-system-prompt.d.ts.map +1 -1
- package/dist/runtime/owner-system-prompt.js +6 -5
- package/dist/runtime/owner-system-prompt.js.map +1 -1
- package/dist/runtime/session-start-context.d.ts +3 -22
- package/dist/runtime/session-start-context.d.ts.map +1 -1
- package/dist/runtime/session-start-context.js +1 -58
- package/dist/runtime/session-start-context.js.map +1 -1
- package/dist/runtime/stimulus-delivery.d.ts +4 -1
- package/dist/runtime/stimulus-delivery.d.ts.map +1 -1
- package/dist/runtime/stimulus-delivery.js +18 -10
- package/dist/runtime/stimulus-delivery.js.map +1 -1
- package/dist/runtime/timezone.d.ts +6 -0
- package/dist/runtime/timezone.d.ts.map +1 -1
- package/dist/runtime/timezone.js +11 -0
- package/dist/runtime/timezone.js.map +1 -1
- package/dist/runtime/turn-orders.d.ts +5 -0
- package/dist/runtime/turn-orders.d.ts.map +1 -1
- package/dist/runtime/turn-orders.js +12 -9
- package/dist/runtime/turn-orders.js.map +1 -1
- package/dist/storage/chat-sources.d.ts +21 -0
- package/dist/storage/chat-sources.d.ts.map +1 -0
- package/dist/storage/chat-sources.js +119 -0
- package/dist/storage/chat-sources.js.map +1 -0
- package/dist/wiki-artifacts/normalization.d.ts +1 -1
- package/dist/wiki-artifacts/normalization.d.ts.map +1 -1
- package/dist/wiki-artifacts/normalization.js +1 -4
- package/dist/wiki-artifacts/normalization.js.map +1 -1
- package/package.json +2 -2
- package/dist/gateways/conversation-record.d.ts +0 -52
- package/dist/gateways/conversation-record.d.ts.map +0 -1
- package/dist/gateways/conversation-record.js +0 -220
- package/dist/gateways/conversation-record.js.map +0 -1
- package/dist/gateways/session-store.d.ts +0 -120
- package/dist/gateways/session-store.d.ts.map +0 -1
- package/dist/gateways/session-store.js +0 -581
- package/dist/gateways/session-store.js.map +0 -1
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import type { SessionStore } from './session-store.js';
|
|
2
|
-
import type { NormalizedMessage } from './types.js';
|
|
3
|
-
import type { NativeTurnResultRecord } from '@jungjaehoon/mama-core/runtime/native-input-journal';
|
|
4
|
-
import type { CompletedTurn, SharedReplyTurn } from './turn-contract.js';
|
|
5
|
-
export interface InlineObservationInput {
|
|
6
|
-
source: string;
|
|
7
|
-
sourceId: string;
|
|
8
|
-
body: string;
|
|
9
|
-
author: string | null;
|
|
10
|
-
observedAt: number;
|
|
11
|
-
metadata: Record<string, unknown>;
|
|
12
|
-
scope: Record<string, unknown>;
|
|
13
|
-
}
|
|
14
|
-
export interface ConversationObservationPorts {
|
|
15
|
-
recordInlineObservation?: (input: InlineObservationInput) => string;
|
|
16
|
-
readInlineObservationByIdentity?: (input: {
|
|
17
|
-
source: string;
|
|
18
|
-
sourceId: string;
|
|
19
|
-
producerVersionId: string;
|
|
20
|
-
}) => {
|
|
21
|
-
observationRef: string;
|
|
22
|
-
body: string;
|
|
23
|
-
} | null;
|
|
24
|
-
}
|
|
25
|
-
export type ConversationRecord = {
|
|
26
|
-
resolved: CompletedTurn | SharedReplyTurn;
|
|
27
|
-
} | {
|
|
28
|
-
resolved: null;
|
|
29
|
-
sourceObservationRef?: string;
|
|
30
|
-
appendInput(content: string): void;
|
|
31
|
-
stageResponse(body: string): void;
|
|
32
|
-
abandon(): void;
|
|
33
|
-
commitResult(body: string): void;
|
|
34
|
-
commitShared(replySourceMessageRef: string): void;
|
|
35
|
-
};
|
|
36
|
-
export declare function sourceMessageIdentity(message: NormalizedMessage): {
|
|
37
|
-
sourceTurnId: string;
|
|
38
|
-
sourceMessageRef: string;
|
|
39
|
-
};
|
|
40
|
-
export declare function openConversationRecord(input: {
|
|
41
|
-
sessionStore: SessionStore;
|
|
42
|
-
sessionId: string;
|
|
43
|
-
message: NormalizedMessage;
|
|
44
|
-
sourceTurnId: string;
|
|
45
|
-
sourceMessageRef: string;
|
|
46
|
-
ownerConsole: boolean;
|
|
47
|
-
recoveryOnly: boolean;
|
|
48
|
-
recoveredNativeResult?: NativeTurnResultRecord;
|
|
49
|
-
startedAt: number;
|
|
50
|
-
observations: ConversationObservationPorts;
|
|
51
|
-
}): ConversationRecord;
|
|
52
|
-
//# sourceMappingURL=conversation-record.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"conversation-record.d.ts","sourceRoot":"","sources":["../../src/gateways/conversation-record.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AACvD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAIpD,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,qDAAqD,CAAC;AAClG,OAAO,KAAK,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAEzE,MAAM,WAAW,sBAAsB;IACrC,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAClC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAChC;AAED,MAAM,WAAW,4BAA4B;IAC3C,uBAAuB,CAAC,EAAE,CAAC,KAAK,EAAE,sBAAsB,KAAK,MAAM,CAAC;IACpE,+BAA+B,CAAC,EAAE,CAAC,KAAK,EAAE;QACxC,MAAM,EAAE,MAAM,CAAC;QACf,QAAQ,EAAE,MAAM,CAAC;QACjB,iBAAiB,EAAE,MAAM,CAAC;KAC3B,KAAK;QAAE,cAAc,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI,CAAC;CACvD;AAED,MAAM,MAAM,kBAAkB,GAC1B;IAAE,QAAQ,EAAE,aAAa,GAAG,eAAe,CAAA;CAAE,GAC7C;IACE,QAAQ,EAAE,IAAI,CAAC;IACf,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IACnC,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IAClC,OAAO,IAAI,IAAI,CAAC;IAChB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACjC,YAAY,CAAC,qBAAqB,EAAE,MAAM,GAAG,IAAI,CAAC;CACnD,CAAC;AAEN,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,iBAAiB,GAAG;IACjE,YAAY,EAAE,MAAM,CAAC;IACrB,gBAAgB,EAAE,MAAM,CAAC;CAC1B,CAMA;AAED,wBAAgB,sBAAsB,CAAC,KAAK,EAAE;IAC5C,YAAY,EAAE,YAAY,CAAC;IAC3B,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,iBAAiB,CAAC;IAC3B,YAAY,EAAE,MAAM,CAAC;IACrB,gBAAgB,EAAE,MAAM,CAAC;IACzB,YAAY,EAAE,OAAO,CAAC;IACtB,YAAY,EAAE,OAAO,CAAC;IACtB,qBAAqB,CAAC,EAAE,sBAAsB,CAAC;IAC/C,SAAS,EAAE,MAAM,CAAC;IAClB,YAAY,EAAE,4BAA4B,CAAC;CAC5C,GAAG,kBAAkB,CAqQrB"}
|
|
@@ -1,220 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.sourceMessageIdentity = sourceMessageIdentity;
|
|
4
|
-
exports.openConversationRecord = openConversationRecord;
|
|
5
|
-
/** Durable messenger turn facts and crash recovery; this module never runs a model. */
|
|
6
|
-
const node_crypto_1 = require("node:crypto");
|
|
7
|
-
function agentIdForPrincipalClass(principalClass) {
|
|
8
|
-
return principalClass === 'owner' ? 'mama-owner' : 'unsigned-local';
|
|
9
|
-
}
|
|
10
|
-
function sourceMessageIdentity(message) {
|
|
11
|
-
const sourceTurnId = message.metadata?.messageId ?? `generated:${(0, node_crypto_1.randomUUID)().replace(/-/g, '')}`;
|
|
12
|
-
return {
|
|
13
|
-
sourceTurnId,
|
|
14
|
-
sourceMessageRef: [message.source, message.channelId, sourceTurnId].filter(Boolean).join(':'),
|
|
15
|
-
};
|
|
16
|
-
}
|
|
17
|
-
function openConversationRecord(input) {
|
|
18
|
-
const { sessionStore, sessionId, message, sourceTurnId, sourceMessageRef, ownerConsole, recoveryOnly, recoveredNativeResult, startedAt, observations, } = input;
|
|
19
|
-
const existing = sessionStore.findTurnBySourceMessageRef(sessionId, sourceMessageRef);
|
|
20
|
-
const scope = {
|
|
21
|
-
visibility: 'owner',
|
|
22
|
-
agentId: agentIdForPrincipalClass(message.principal?.class),
|
|
23
|
-
channel: message.channelId,
|
|
24
|
-
principalId: message.principal?.principalId ?? null,
|
|
25
|
-
};
|
|
26
|
-
const inputObservation = () => ({
|
|
27
|
-
source: `owner-message:${message.source}`,
|
|
28
|
-
sourceId: sourceMessageRef,
|
|
29
|
-
body: message.text,
|
|
30
|
-
author: message.userId,
|
|
31
|
-
observedAt: Date.now(),
|
|
32
|
-
metadata: { messageId: sourceTurnId },
|
|
33
|
-
scope,
|
|
34
|
-
});
|
|
35
|
-
const resultObservation = (body) => ({
|
|
36
|
-
source: `owner-result:${message.source}`,
|
|
37
|
-
sourceId: `${sourceMessageRef}:result`,
|
|
38
|
-
body,
|
|
39
|
-
author: 'mama',
|
|
40
|
-
observedAt: Date.now(),
|
|
41
|
-
metadata: { sourceMessageRef },
|
|
42
|
-
scope,
|
|
43
|
-
});
|
|
44
|
-
const recordResult = (body) => ownerConsole ? observations.recordInlineObservation?.(resultObservation(body)) : undefined;
|
|
45
|
-
const validateStoredObservation = (storedRef, observation) => {
|
|
46
|
-
if (!observations.recordInlineObservation) {
|
|
47
|
-
throw new Error('Stored owner observation cannot be revalidated');
|
|
48
|
-
}
|
|
49
|
-
let returnedRef;
|
|
50
|
-
try {
|
|
51
|
-
returnedRef = observations.recordInlineObservation(observation);
|
|
52
|
-
}
|
|
53
|
-
catch (error) {
|
|
54
|
-
const reason = error instanceof Error ? error.message : String(error);
|
|
55
|
-
if (reason.startsWith('Observation replay conflict for ')) {
|
|
56
|
-
throw new Error('Owner message replay conflicts with persisted immutable input', {
|
|
57
|
-
cause: error,
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
throw new Error('Owner observation replay validation failed', { cause: error });
|
|
61
|
-
}
|
|
62
|
-
if (returnedRef !== storedRef) {
|
|
63
|
-
throw new Error('Owner message replay conflicts with persisted immutable input');
|
|
64
|
-
}
|
|
65
|
-
};
|
|
66
|
-
const sharedTarget = recoveredNativeResult &&
|
|
67
|
-
recoveredNativeResult.primaryStimulusId !== sourceMessageRef &&
|
|
68
|
-
(recoveredNativeResult.primaryKind === 'owner_message' ||
|
|
69
|
-
(existing?.state === 'shared' &&
|
|
70
|
-
existing.sharedReplyRef === recoveredNativeResult.primaryStimulusId))
|
|
71
|
-
? recoveredNativeResult.primaryStimulusId
|
|
72
|
-
: null;
|
|
73
|
-
const shared = (replySourceMessageRef) => ({
|
|
74
|
-
outcome: 'shared_reply',
|
|
75
|
-
response: '',
|
|
76
|
-
sessionId,
|
|
77
|
-
duration: Date.now() - startedAt,
|
|
78
|
-
sourceTurnId,
|
|
79
|
-
sourceMessageRef,
|
|
80
|
-
replySourceMessageRef,
|
|
81
|
-
});
|
|
82
|
-
const completed = (response) => {
|
|
83
|
-
if (sharedTarget || (recoveredNativeResult && response !== recoveredNativeResult.response)) {
|
|
84
|
-
throw new Error('Committed owner response conflicts with native turn result');
|
|
85
|
-
}
|
|
86
|
-
return {
|
|
87
|
-
outcome: 'completed',
|
|
88
|
-
response,
|
|
89
|
-
sessionId,
|
|
90
|
-
duration: Date.now() - startedAt,
|
|
91
|
-
provenance: recoveredNativeResult?.modelRunId
|
|
92
|
-
? { status: 'available', modelRunId: recoveredNativeResult.modelRunId }
|
|
93
|
-
: {
|
|
94
|
-
status: 'unavailable',
|
|
95
|
-
reason: recoveredNativeResult?.modelRunProvenance === 'commit_failed'
|
|
96
|
-
? 'commit_failed'
|
|
97
|
-
: 'backend_no_run',
|
|
98
|
-
},
|
|
99
|
-
sourceTurnId,
|
|
100
|
-
sourceMessageRef,
|
|
101
|
-
};
|
|
102
|
-
};
|
|
103
|
-
if (existing?.state === 'shared') {
|
|
104
|
-
if (!existing.sharedReplyRef ||
|
|
105
|
-
(sharedTarget && existing.sharedReplyRef !== sharedTarget) ||
|
|
106
|
-
(recoveredNativeResult && !sharedTarget)) {
|
|
107
|
-
throw new Error('Shared owner response conflicts with native turn result');
|
|
108
|
-
}
|
|
109
|
-
if (existing.sourceObservationRef) {
|
|
110
|
-
validateStoredObservation(existing.sourceObservationRef, inputObservation());
|
|
111
|
-
}
|
|
112
|
-
return { resolved: shared(existing.sharedReplyRef) };
|
|
113
|
-
}
|
|
114
|
-
if (existing?.state === 'final') {
|
|
115
|
-
if (sharedTarget)
|
|
116
|
-
throw new Error('Final owner response conflicts with shared native turn');
|
|
117
|
-
if (existing.sourceObservationRef) {
|
|
118
|
-
validateStoredObservation(existing.sourceObservationRef, inputObservation());
|
|
119
|
-
}
|
|
120
|
-
if (existing.resultObservationRef) {
|
|
121
|
-
validateStoredObservation(existing.resultObservationRef, resultObservation(existing.bot));
|
|
122
|
-
}
|
|
123
|
-
return { resolved: completed(existing.bot) };
|
|
124
|
-
}
|
|
125
|
-
const sourceObservationRef = existing?.sourceObservationRef ??
|
|
126
|
-
(ownerConsole ? observations.recordInlineObservation?.(inputObservation()) : undefined);
|
|
127
|
-
const recoveredResult = !existing?.resultObservationRef && ownerConsole
|
|
128
|
-
? observations.readInlineObservationByIdentity?.({
|
|
129
|
-
source: `owner-result:${message.source}`,
|
|
130
|
-
sourceId: `${sourceMessageRef}:result`,
|
|
131
|
-
producerVersionId: `${sourceMessageRef}:result`,
|
|
132
|
-
})
|
|
133
|
-
: null;
|
|
134
|
-
if (recoveredResult) {
|
|
135
|
-
validateStoredObservation(sourceObservationRef, inputObservation());
|
|
136
|
-
validateStoredObservation(recoveredResult.observationRef, resultObservation(recoveredResult.body));
|
|
137
|
-
if (existing &&
|
|
138
|
-
(!sessionStore.flushStreamingResponse(sessionId, recoveredResult.body, recoveredResult.observationRef, sourceMessageRef) ||
|
|
139
|
-
!sessionStore.finalizeTurn(sessionId, sourceMessageRef, recoveredResult.body, recoveredResult.observationRef))) {
|
|
140
|
-
throw new Error('Unable to recover committed result observation');
|
|
141
|
-
}
|
|
142
|
-
return { resolved: completed(recoveredResult.body) };
|
|
143
|
-
}
|
|
144
|
-
if (existing?.resultObservationRef && existing.bot.trim().length > 0 && ownerConsole) {
|
|
145
|
-
validateStoredObservation(existing.sourceObservationRef, inputObservation());
|
|
146
|
-
validateStoredObservation(existing.resultObservationRef, resultObservation(existing.bot));
|
|
147
|
-
if (!sessionStore.finalizeTurn(sessionId, sourceMessageRef, existing.bot, existing.resultObservationRef)) {
|
|
148
|
-
throw new Error('Unable to recover final assistant response');
|
|
149
|
-
}
|
|
150
|
-
return { resolved: completed(existing.bot) };
|
|
151
|
-
}
|
|
152
|
-
if (recoveryOnly) {
|
|
153
|
-
if (recoveredNativeResult &&
|
|
154
|
-
(recoveredNativeResult.primaryKind === null ||
|
|
155
|
-
recoveredNativeResult.primaryKind === undefined)) {
|
|
156
|
-
throw new Error('Native result primary kind is unknown; reply ownership requires reconciliation');
|
|
157
|
-
}
|
|
158
|
-
if (sharedTarget) {
|
|
159
|
-
if (!ownerConsole || !existing || !sourceObservationRef) {
|
|
160
|
-
throw new Error('Shared native input has no recoverable owner record');
|
|
161
|
-
}
|
|
162
|
-
validateStoredObservation(sourceObservationRef, inputObservation());
|
|
163
|
-
if (!sessionStore.finalizeSharedTurn(sessionId, sourceMessageRef, sharedTarget)) {
|
|
164
|
-
throw new Error('Unable to recover shared native reply');
|
|
165
|
-
}
|
|
166
|
-
return { resolved: shared(sharedTarget) };
|
|
167
|
-
}
|
|
168
|
-
if (recoveredNativeResult) {
|
|
169
|
-
if (!ownerConsole || !existing || !sourceObservationRef) {
|
|
170
|
-
throw new Error('Native result has no recoverable owner input record');
|
|
171
|
-
}
|
|
172
|
-
validateStoredObservation(sourceObservationRef, inputObservation());
|
|
173
|
-
const response = recoveredNativeResult.response;
|
|
174
|
-
const resultObservationRef = recordResult(response);
|
|
175
|
-
if (!resultObservationRef ||
|
|
176
|
-
!sessionStore.flushStreamingResponse(sessionId, response, resultObservationRef, sourceMessageRef) ||
|
|
177
|
-
!sessionStore.finalizeTurn(sessionId, sourceMessageRef, response, resultObservationRef)) {
|
|
178
|
-
throw new Error('Unable to recover accepted native result');
|
|
179
|
-
}
|
|
180
|
-
return { resolved: completed(response) };
|
|
181
|
-
}
|
|
182
|
-
throw new Error('Native input outcome is unresolved; no committed response was found');
|
|
183
|
-
}
|
|
184
|
-
const stageResponse = (body, resultObservationRef) => {
|
|
185
|
-
if (!sessionStore.flushStreamingResponse(sessionId, body, resultObservationRef, sourceMessageRef)) {
|
|
186
|
-
throw new Error('Unable to stage assistant response');
|
|
187
|
-
}
|
|
188
|
-
};
|
|
189
|
-
return {
|
|
190
|
-
resolved: null,
|
|
191
|
-
sourceObservationRef,
|
|
192
|
-
appendInput(content) {
|
|
193
|
-
if (!sessionStore.appendMessage(sessionId, { role: 'user', content, timestamp: Date.now() }, { sourceMessageRef, sourceObservationRef })) {
|
|
194
|
-
throw new Error('Unable to persist user message');
|
|
195
|
-
}
|
|
196
|
-
},
|
|
197
|
-
stageResponse,
|
|
198
|
-
abandon() {
|
|
199
|
-
if (!sessionStore.discardIncompleteTurn(sessionId, sourceMessageRef)) {
|
|
200
|
-
throw new Error('Unable to discard failed source message');
|
|
201
|
-
}
|
|
202
|
-
},
|
|
203
|
-
commitResult(body) {
|
|
204
|
-
const resultObservationRef = recordResult(body);
|
|
205
|
-
stageResponse(body, resultObservationRef);
|
|
206
|
-
if (!sessionStore.finalizeTurn(sessionId, sourceMessageRef, body, resultObservationRef)) {
|
|
207
|
-
throw new Error('Unable to persist final assistant response');
|
|
208
|
-
}
|
|
209
|
-
},
|
|
210
|
-
commitShared(replySourceMessageRef) {
|
|
211
|
-
if (!ownerConsole || !sourceObservationRef) {
|
|
212
|
-
throw new Error('Shared native reply requires an owner observation');
|
|
213
|
-
}
|
|
214
|
-
if (!sessionStore.finalizeSharedTurn(sessionId, sourceMessageRef, replySourceMessageRef)) {
|
|
215
|
-
throw new Error('Unable to persist shared native reply');
|
|
216
|
-
}
|
|
217
|
-
},
|
|
218
|
-
};
|
|
219
|
-
}
|
|
220
|
-
//# sourceMappingURL=conversation-record.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"conversation-record.js","sourceRoot":"","sources":["../../src/gateways/conversation-record.ts"],"names":[],"mappings":";;AAyCA,sDASC;AAED,wDAgRC;AApUD,uFAAuF;AACvF,6CAAyC;AAGzC,SAAS,wBAAwB,CAAC,cAAmC;IACnE,OAAO,cAAc,KAAK,OAAO,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,gBAAgB,CAAC;AACtE,CAAC;AAmCD,SAAgB,qBAAqB,CAAC,OAA0B;IAI9D,MAAM,YAAY,GAAG,OAAO,CAAC,QAAQ,EAAE,SAAS,IAAI,aAAa,IAAA,wBAAU,GAAE,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,EAAE,CAAC;IAClG,OAAO;QACL,YAAY;QACZ,gBAAgB,EAAE,CAAC,OAAO,CAAC,MAAM,EAAE,OAAO,CAAC,SAAS,EAAE,YAAY,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC;KAC9F,CAAC;AACJ,CAAC;AAED,SAAgB,sBAAsB,CAAC,KAWtC;IACC,MAAM,EACJ,YAAY,EACZ,SAAS,EACT,OAAO,EACP,YAAY,EACZ,gBAAgB,EAChB,YAA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,qBAAqB,CAAC,EAAE,CAAC;gBACzF,MAAM,IAAI,KAAK,CAAC,uCAAuC,CAAC,CAAC;YAC3D,CAAC;QACH,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Session store for messenger conversations
|
|
3
|
-
*
|
|
4
|
-
* Manages conversation sessions with rolling context (history)
|
|
5
|
-
* for cross-platform messenger integration.
|
|
6
|
-
*/
|
|
7
|
-
import type { SQLiteDatabase } from '../sqlite.js';
|
|
8
|
-
import type { Session, MessageSource, ConversationTurn } from './types.js';
|
|
9
|
-
/**
|
|
10
|
-
* SQLite-backed session store for messenger conversations
|
|
11
|
-
*/
|
|
12
|
-
export declare class SessionStore {
|
|
13
|
-
private db;
|
|
14
|
-
private maxTurns;
|
|
15
|
-
constructor(db: SQLiteDatabase, options?: {
|
|
16
|
-
maxTurns?: number;
|
|
17
|
-
});
|
|
18
|
-
/**
|
|
19
|
-
* Run database migration
|
|
20
|
-
*/
|
|
21
|
-
private runMigration;
|
|
22
|
-
/**
|
|
23
|
-
* Get existing session or create new one
|
|
24
|
-
*/
|
|
25
|
-
getOrCreate(source: MessageSource, channelId: string, userId?: string, channelName?: string): Session;
|
|
26
|
-
/**
|
|
27
|
-
* Get session by ID
|
|
28
|
-
*/
|
|
29
|
-
getById(sessionId: string): Session | null;
|
|
30
|
-
/**
|
|
31
|
-
* Update session with new conversation turn
|
|
32
|
-
*/
|
|
33
|
-
updateSession(sessionId: string, userMessage: string, botResponse: string): boolean;
|
|
34
|
-
/**
|
|
35
|
-
* Append a single message (user or assistant) to session history.
|
|
36
|
-
* - role='user': creates a new turn with empty bot
|
|
37
|
-
* - role='assistant': fills bot field of last incomplete turn, or creates new turn
|
|
38
|
-
*/
|
|
39
|
-
appendMessage(sessionId: string, msg: {
|
|
40
|
-
role: 'user' | 'assistant';
|
|
41
|
-
content: string;
|
|
42
|
-
timestamp: number;
|
|
43
|
-
}, opts?: {
|
|
44
|
-
sourceMessageRef?: string;
|
|
45
|
-
sourceObservationRef?: string;
|
|
46
|
-
resultObservationRef?: string;
|
|
47
|
-
}): boolean;
|
|
48
|
-
findTurnBySourceMessageRef(sessionId: string, sourceMessageRef: string): ConversationTurn | null;
|
|
49
|
-
finalizeTurn(sessionId: string, sourceMessageRef: string, response: string, resultObservationRef?: string): boolean;
|
|
50
|
-
/** Preserve a later user input while linking it to the one reply owner. */
|
|
51
|
-
finalizeSharedTurn(sessionId: string, sourceMessageRef: string, replySourceMessageRef: string): boolean;
|
|
52
|
-
/**
|
|
53
|
-
* Flush streaming response to the last incomplete turn.
|
|
54
|
-
* Called periodically during streaming to persist partial assistant responses.
|
|
55
|
-
*/
|
|
56
|
-
flushStreamingResponse(sessionId: string, accumulatedText: string, resultObservationRef?: string, sourceMessageRef?: string): boolean;
|
|
57
|
-
/** Remove only the failed turn; legacy callers without a source ref use the last turn. */
|
|
58
|
-
discardIncompleteTurn(sessionId: string, sourceMessageRef?: string): boolean;
|
|
59
|
-
/**
|
|
60
|
-
* Get conversation history for a session by ID
|
|
61
|
-
*/
|
|
62
|
-
getHistory(sessionId: string): ConversationTurn[];
|
|
63
|
-
/**
|
|
64
|
-
* Get conversation history by source and channel
|
|
65
|
-
* Used by messenger and runtime session consumers
|
|
66
|
-
*/
|
|
67
|
-
getHistoryByChannel(source: MessageSource, channelId: string): ConversationTurn[];
|
|
68
|
-
/**
|
|
69
|
-
* Clear session context (start fresh)
|
|
70
|
-
*/
|
|
71
|
-
clearContext(sessionId: string): boolean;
|
|
72
|
-
/**
|
|
73
|
-
* Delete a session
|
|
74
|
-
*/
|
|
75
|
-
deleteSession(sessionId: string): boolean;
|
|
76
|
-
/**
|
|
77
|
-
* List all sessions for a source
|
|
78
|
-
*/
|
|
79
|
-
/**
|
|
80
|
-
* What this store holds, as the dashboard asks it: how many sessions per
|
|
81
|
-
* source, and the ten most recently active channels.
|
|
82
|
-
*
|
|
83
|
-
* The viewer used to open a second connection to this database by path and
|
|
84
|
-
* run these two queries itself. The store that owns the table answers them.
|
|
85
|
-
*/
|
|
86
|
-
stats(): {
|
|
87
|
-
total: number;
|
|
88
|
-
bySource: Record<string, number>;
|
|
89
|
-
channels: Array<{
|
|
90
|
-
source: string;
|
|
91
|
-
channelId: string;
|
|
92
|
-
channelName: string | null;
|
|
93
|
-
lastActive: number;
|
|
94
|
-
messageCount: number;
|
|
95
|
-
}>;
|
|
96
|
-
};
|
|
97
|
-
listSessions(source?: MessageSource): Session[];
|
|
98
|
-
/**
|
|
99
|
-
* Update channel name for a session by source and channel ID
|
|
100
|
-
* Used to backfill channel names when gateway connects
|
|
101
|
-
*/
|
|
102
|
-
updateChannelName(source: MessageSource, channelId: string, channelName: string): boolean;
|
|
103
|
-
/**
|
|
104
|
-
* Delete inactive sessions older than specified age
|
|
105
|
-
*/
|
|
106
|
-
cleanupInactiveSessions(maxAgeMs: number): number;
|
|
107
|
-
/**
|
|
108
|
-
* Get the most recently active session for a specific source
|
|
109
|
-
*/
|
|
110
|
-
getLastActiveSession(source?: MessageSource): Session | null;
|
|
111
|
-
/**
|
|
112
|
-
* Convert database row to Session object
|
|
113
|
-
*/
|
|
114
|
-
private rowToSession;
|
|
115
|
-
/**
|
|
116
|
-
* Close database connection
|
|
117
|
-
*/
|
|
118
|
-
close(): void;
|
|
119
|
-
}
|
|
120
|
-
//# sourceMappingURL=session-store.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"session-store.d.ts","sourceRoot":"","sources":["../../src/gateways/session-store.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAEnD,OAAO,KAAK,EAAE,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AA+B3E;;GAEG;AACH,qBAAa,YAAY;IACvB,OAAO,CAAC,EAAE,CAAiB;IAC3B,OAAO,CAAC,QAAQ,CAAS;gBAEb,E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