@jungjaehoon/mama-os 0.32.2 → 0.33.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/dist/cli/commands/start.d.ts.map +1 -1
- package/dist/cli/commands/start.js +58 -24
- package/dist/cli/commands/start.js.map +1 -1
- package/dist/cli/runtime/api-routes-init.d.ts +2 -0
- package/dist/cli/runtime/api-routes-init.d.ts.map +1 -1
- package/dist/cli/runtime/api-routes-init.js +61 -0
- package/dist/cli/runtime/api-routes-init.js.map +1 -1
- package/dist/gateways/message-router.d.ts +4 -0
- package/dist/gateways/message-router.d.ts.map +1 -1
- package/dist/gateways/message-router.js +62 -13
- package/dist/gateways/message-router.js.map +1 -1
- package/dist/gateways/owner-report-inbox.d.ts +40 -0
- package/dist/gateways/owner-report-inbox.d.ts.map +1 -0
- package/dist/gateways/owner-report-inbox.js +128 -0
- package/dist/gateways/owner-report-inbox.js.map +1 -0
- package/dist/gateways/report-projection-v1.d.ts +41 -0
- package/dist/gateways/report-projection-v1.d.ts.map +1 -0
- package/dist/gateways/report-projection-v1.js +160 -0
- package/dist/gateways/report-projection-v1.js.map +1 -0
- package/dist/gateways/session-store.d.ts +22 -0
- package/dist/gateways/session-store.d.ts.map +1 -1
- package/dist/gateways/session-store.js +76 -3
- package/dist/gateways/session-store.js.map +1 -1
- package/dist/gateways/telegram-message-ledger.d.ts +10 -0
- package/dist/gateways/telegram-message-ledger.d.ts.map +1 -1
- package/dist/gateways/telegram-message-ledger.js +23 -2
- package/dist/gateways/telegram-message-ledger.js.map +1 -1
- package/dist/gateways/telegram-report-context-store.d.ts +193 -0
- package/dist/gateways/telegram-report-context-store.d.ts.map +1 -0
- package/dist/gateways/telegram-report-context-store.js +612 -0
- package/dist/gateways/telegram-report-context-store.js.map +1 -0
- package/dist/gateways/telegram.d.ts +9 -0
- package/dist/gateways/telegram.d.ts.map +1 -1
- package/dist/gateways/telegram.js +100 -0
- package/dist/gateways/telegram.js.map +1 -1
- package/dist/gateways/types.d.ts +12 -0
- package/dist/gateways/types.d.ts.map +1 -1
- package/dist/operator/operator-trigger-loop.d.ts +39 -7
- package/dist/operator/operator-trigger-loop.d.ts.map +1 -1
- package/dist/operator/operator-trigger-loop.js +282 -89
- package/dist/operator/operator-trigger-loop.js.map +1 -1
- package/dist/operator/report-delivery-coordinator.d.ts +82 -0
- package/dist/operator/report-delivery-coordinator.d.ts.map +1 -0
- package/dist/operator/report-delivery-coordinator.js +123 -0
- package/dist/operator/report-delivery-coordinator.js.map +1 -0
- package/dist/operator/situation-report.d.ts +7 -0
- package/dist/operator/situation-report.d.ts.map +1 -1
- package/dist/operator/situation-report.js +12 -0
- package/dist/operator/situation-report.js.map +1 -1
- package/dist/operator/trigger-author.d.ts +10 -2
- package/dist/operator/trigger-author.d.ts.map +1 -1
- package/dist/operator/trigger-author.js +112 -39
- package/dist/operator/trigger-author.js.map +1 -1
- package/dist/operator/trigger-registry.d.ts +21 -0
- package/dist/operator/trigger-registry.d.ts.map +1 -1
- package/dist/operator/trigger-registry.js +161 -1
- package/dist/operator/trigger-registry.js.map +1 -1
- package/dist/operator/trigger-review.d.ts.map +1 -1
- package/dist/operator/trigger-review.js +56 -10
- package/dist/operator/trigger-review.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TG-05/TG-06: Telegram owner-report context inbox store.
|
|
3
|
+
*
|
|
4
|
+
* The messenger SQLite database is the single report-context authority for
|
|
5
|
+
* owner-report delivery events and turn-consumption receipts
|
|
6
|
+
* (docs/development/telegram-outbound-context-inbox-design.md, Decision 4).
|
|
7
|
+
*/
|
|
8
|
+
import type { SQLiteDatabase } from '../sqlite.js';
|
|
9
|
+
export type ReportContextEventState = 'prepared_retryable' | 'prepared_definite_rejection' | 'delivered' | 'cancelled';
|
|
10
|
+
export interface ReportContextTarget {
|
|
11
|
+
source: 'telegram';
|
|
12
|
+
channelId: string;
|
|
13
|
+
}
|
|
14
|
+
export interface ReportContextReservationInput {
|
|
15
|
+
deliveryId: string;
|
|
16
|
+
target: ReportContextTarget;
|
|
17
|
+
mode: 'digest' | 'full';
|
|
18
|
+
occurrence: Record<string, unknown>;
|
|
19
|
+
provenance?: Record<string, unknown>;
|
|
20
|
+
text: string;
|
|
21
|
+
payloadIdentity: string;
|
|
22
|
+
}
|
|
23
|
+
export interface ReportContextEvent {
|
|
24
|
+
seq: number;
|
|
25
|
+
deliveryId: string;
|
|
26
|
+
state: ReportContextEventState;
|
|
27
|
+
}
|
|
28
|
+
export interface ReportContextEventDetail extends ReportContextEvent {
|
|
29
|
+
attemptCount: number;
|
|
30
|
+
nextAttemptAt: string | null;
|
|
31
|
+
leaseUntil: string | null;
|
|
32
|
+
rejectionReason: string | null;
|
|
33
|
+
cancelReason: string | null;
|
|
34
|
+
}
|
|
35
|
+
export interface TelegramReportContextStoreOptions {
|
|
36
|
+
nowIso?: () => string;
|
|
37
|
+
/**
|
|
38
|
+
* TG-05 Slice K (design Decision 8): when set, the constructor solely
|
|
39
|
+
* migrates the legacy V2 carry file (last-full-report.json) into the
|
|
40
|
+
* event/legacy-restoration tables and renames the source `.migrated`.
|
|
41
|
+
* No component reads or writes V2 afterward.
|
|
42
|
+
*/
|
|
43
|
+
legacyCarryPath?: string;
|
|
44
|
+
/** Design Decision 5 live capacity (prepared-or-unconsumed) per target. */
|
|
45
|
+
liveRowCapPerTarget?: number;
|
|
46
|
+
liveByteCapPerTarget?: number;
|
|
47
|
+
/** Retained exact-text capacity per target before consumed rows compact. */
|
|
48
|
+
retainedRowCapPerTarget?: number;
|
|
49
|
+
retainedByteCapPerTarget?: number;
|
|
50
|
+
}
|
|
51
|
+
export declare class TelegramReportContextStore {
|
|
52
|
+
private readonly db;
|
|
53
|
+
private readonly nowIso;
|
|
54
|
+
private readonly liveRowCap;
|
|
55
|
+
private readonly liveByteCap;
|
|
56
|
+
private readonly retainedRowCap;
|
|
57
|
+
private readonly retainedByteCap;
|
|
58
|
+
constructor(db: SQLiteDatabase, options?: TelegramReportContextStoreOptions);
|
|
59
|
+
/**
|
|
60
|
+
* TG-05 Slice K: migrate the legacy V2 carry file. Unconsumed -> a
|
|
61
|
+
* delivered-pending event (even past the old 24h TTL); consumed -> a
|
|
62
|
+
* target-scoped legacy restoration record carrying the EXACT old prefix
|
|
63
|
+
* bytes. Transactionally insert/verify, commit, then atomically rename the
|
|
64
|
+
* source `.migrated`. Invalid files are quarantined and never injected.
|
|
65
|
+
*/
|
|
66
|
+
private migrateLegacyCarry;
|
|
67
|
+
/**
|
|
68
|
+
* Idempotently insert the exact prepared report before any external send.
|
|
69
|
+
* A replay of the same delivery ID must carry the identical payload; any
|
|
70
|
+
* divergence is an identity conflict and never silently overwrites.
|
|
71
|
+
*/
|
|
72
|
+
reserve(input: ReportContextReservationInput): ReportContextEvent;
|
|
73
|
+
/**
|
|
74
|
+
* Atomically transition a confirmed send to `delivered`. Idempotent: an
|
|
75
|
+
* already-delivered row keeps its original delivery time so crash-recovery
|
|
76
|
+
* replays converge instead of rewriting history.
|
|
77
|
+
*/
|
|
78
|
+
markDelivered(deliveryId: string, deliveredAtIso: string): void;
|
|
79
|
+
/**
|
|
80
|
+
* Compare-and-swap attempt lease: exactly one holder may execute a Telegram
|
|
81
|
+
* send at a time. A live lease excludes every new claim - another worker,
|
|
82
|
+
* another tick, or the same owner - and an expired lease is recoverable
|
|
83
|
+
* after restart. Returns null when no claim is possible.
|
|
84
|
+
*/
|
|
85
|
+
claimAttempt(deliveryId: string, owner: string, nowIso: string, leaseUntilIso: string): {
|
|
86
|
+
deliveryId: string;
|
|
87
|
+
owner: string;
|
|
88
|
+
leaseUntilIso: string;
|
|
89
|
+
} | null;
|
|
90
|
+
/**
|
|
91
|
+
* Safe cancellation (design Decision 3): permitted only from
|
|
92
|
+
* prepared_definite_rejection - the one state where the Telegram ledger
|
|
93
|
+
* proves definite non-acceptance and no attempt lease is live. Ambiguous or
|
|
94
|
+
* confirmed acceptance can never be cancelled. Replay on an already
|
|
95
|
+
* cancelled row is a converging no-op that keeps the first audit record.
|
|
96
|
+
*/
|
|
97
|
+
cancel(deliveryId: string, reason: string, operatorTimeIso: string): void;
|
|
98
|
+
/**
|
|
99
|
+
* Explicit operator reactivation of a definite rejection after conditions
|
|
100
|
+
* are corrected (for example the bot was unblocked). Same delivery ID, same
|
|
101
|
+
* immutable target; the row becomes immediately recoverable.
|
|
102
|
+
*/
|
|
103
|
+
reactivate(deliveryId: string): void;
|
|
104
|
+
/**
|
|
105
|
+
* Delivered reports not yet consumed by an owner turn, for one exact
|
|
106
|
+
* target, oldest first. This is the pending-projection source; one chat can
|
|
107
|
+
* never read another target's reports.
|
|
108
|
+
*/
|
|
109
|
+
listDeliveredPending(target: ReportContextTarget): Array<{
|
|
110
|
+
seq: number;
|
|
111
|
+
deliveryId: string;
|
|
112
|
+
mode: 'digest' | 'full';
|
|
113
|
+
deliveredAtIso: string;
|
|
114
|
+
text: string;
|
|
115
|
+
}>;
|
|
116
|
+
/**
|
|
117
|
+
* Committed receipts for the given source-message references, in the input
|
|
118
|
+
* order. Only text-bearing receipts are returned; a compacted receipt no
|
|
119
|
+
* longer restores.
|
|
120
|
+
*/
|
|
121
|
+
listReceiptsByRefs(refs: string[]): Array<{
|
|
122
|
+
sourceMessageRef: string;
|
|
123
|
+
deliveryIds: string[];
|
|
124
|
+
projectionText: string;
|
|
125
|
+
committedAtIso: string;
|
|
126
|
+
}>;
|
|
127
|
+
/**
|
|
128
|
+
* Legacy V2 restorations for one target, eligible for fresh-session history
|
|
129
|
+
* (30 days after consumption, design Decision 8). Restoration text is
|
|
130
|
+
* JSON-decoded back to the exact legacy prefix string.
|
|
131
|
+
*/
|
|
132
|
+
listLegacyRestorations(target: ReportContextTarget, nowIso: string): Array<{
|
|
133
|
+
deliveryId: string;
|
|
134
|
+
consumedAtIso: string;
|
|
135
|
+
deliveredAtIso: string;
|
|
136
|
+
restorationText: string;
|
|
137
|
+
}>;
|
|
138
|
+
private compactRetained;
|
|
139
|
+
private enforceLiveCapacity;
|
|
140
|
+
/**
|
|
141
|
+
* Design Decision 5: explicit two-step operator action (token flow lives at
|
|
142
|
+
* the API layer). Archives ONLY already-delivered pending rows up to and
|
|
143
|
+
* including `throughSeq`, records the audit fields, and removes them from
|
|
144
|
+
* pending projection and live capacity. Never Telegram cancellation.
|
|
145
|
+
*/
|
|
146
|
+
archiveDelivered(target: ReportContextTarget, throughSeq: number, actor: string, reason: string, nowIso: string): string[];
|
|
147
|
+
/** Live usage for the status surface; warn at 80% of either bound. */
|
|
148
|
+
liveUsage(target: ReportContextTarget): {
|
|
149
|
+
rows: number;
|
|
150
|
+
bytes: number;
|
|
151
|
+
rowCap: number;
|
|
152
|
+
byteCap: number;
|
|
153
|
+
warn: boolean;
|
|
154
|
+
};
|
|
155
|
+
/**
|
|
156
|
+
* Tombstone GC (design Decision 4): identity tombstones are retained up to
|
|
157
|
+
* 365 days with a global count cap. No tombstone younger than Telegram's
|
|
158
|
+
* seven-day replay window is ever pruned; beyond that floor the oldest
|
|
159
|
+
* terminal tombstones go first. Returns the number of removed rows.
|
|
160
|
+
*/
|
|
161
|
+
pruneTombstones(nowIso: string, options?: {
|
|
162
|
+
maxTombstones?: number;
|
|
163
|
+
}): number;
|
|
164
|
+
/** Read one event's attempt/terminal detail; null when unknown. */
|
|
165
|
+
getEvent(deliveryId: string): ReportContextEventDetail | null;
|
|
166
|
+
/**
|
|
167
|
+
* Record a retryable send failure: keep the row nonterminal, stamp the next
|
|
168
|
+
* attempt time, and release the lease. Only the current lease holder may
|
|
169
|
+
* reshape backoff - a stale worker's outcome must not race a live one.
|
|
170
|
+
*/
|
|
171
|
+
scheduleRetry(deliveryId: string, owner: string, nextAttemptAtIso: string): void;
|
|
172
|
+
/**
|
|
173
|
+
* Record a definite Telegram non-acceptance. The row stays pinned in the
|
|
174
|
+
* ledger (nonterminal) and is never automatically retried; only an explicit
|
|
175
|
+
* operator action may reactivate it (design Decision 3).
|
|
176
|
+
*/
|
|
177
|
+
markDefiniteRejection(deliveryId: string, owner: string, reason: string): void;
|
|
178
|
+
/**
|
|
179
|
+
* Startup/tick recovery: prepared_retryable rows that are due (no future
|
|
180
|
+
* retry scheduled) and not held by a live attempt lease, oldest first.
|
|
181
|
+
*/
|
|
182
|
+
listRecoverable(nowIso: string): ReportContextEvent[];
|
|
183
|
+
/**
|
|
184
|
+
* Startup ledger reconciliation input: every nonterminal row must hold a
|
|
185
|
+
* Telegram-ledger pin, every terminal row must not (design Decision 2).
|
|
186
|
+
*/
|
|
187
|
+
listPinReconciliation(): {
|
|
188
|
+
nonterminal: string[];
|
|
189
|
+
terminal: string[];
|
|
190
|
+
};
|
|
191
|
+
private runMigration;
|
|
192
|
+
}
|
|
193
|
+
//# sourceMappingURL=telegram-report-context-store.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"telegram-report-context-store.d.ts","sourceRoot":"","sources":["../../src/gateways/telegram-report-context-store.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAIH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AA6BnD,MAAM,MAAM,uBAAuB,GAC/B,oBAAoB,GACpB,6BAA6B,GAC7B,WAAW,GACX,WAAW,CAAC;AAEhB,MAAM,WAAW,mBAAmB;IAClC,MAAM,EAAE,UAAU,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,6BAA6B;IAC5C,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,mBAAmB,CAAC;IAC5B,IAAI,EAAE,QAAQ,GAAG,MAAM,CAAC;IACxB,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACpC,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACrC,IAAI,EAAE,MAAM,CAAC;IACb,eAAe,EAAE,MAAM,CAAC;CACzB;AAED,MAAM,WAAW,kBAAkB;IACjC,GAAG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