MCPcopy
hub / github.com/nowork-studio/NotFair / appendTranscriptEvent

Function appendTranscriptEvent

notfair-cmo/src/server/sessions/index.ts:123–153  ·  view source on GitHub ↗
(
  session_id: string,
  kind: TranscriptEvent["kind"],
  payload: unknown,
)

Source from the content-addressed store, hash-verified

121}
122
123export function appendTranscriptEvent(
124 session_id: string,
125 kind: TranscriptEvent["kind"],
126 payload: unknown,
127): void {
128 const db = getDb();
129 const seqRow = db
130 .prepare("SELECT COALESCE(MAX(seq), 0) + 1 AS next FROM transcript_events WHERE session_id = ?")
131 .get(session_id) as { next: number };
132 const id = randomUUID();
133 const seq = seqRow.next;
134 const created_at = new Date().toISOString();
135 const payload_json = JSON.stringify(payload);
136 db.prepare(
137 "INSERT INTO transcript_events (id, session_id, seq, kind, payload_json, created_at) VALUES (?, ?, ?, ?, ?, ?)",
138 ).run(id, session_id, seq, kind, payload_json, created_at);
139 // Push to live subscribers AFTER the INSERT commits. Inline import to
140 // keep this module free of the live-events dependency at module load —
141 // matters for the migration tests that don't want EventEmitter eagerness.
142 // eslint-disable-next-line @typescript-eslint/no-require-imports
143 const { publishSessionEvent } =
144 require("@/server/live-events/emitter") as typeof import("@/server/live-events/emitter");
145 publishSessionEvent(session_id, {
146 id,
147 session_id,
148 seq,
149 kind,
150 payload_json,
151 created_at,
152 });
153}
154
155export function listTranscriptEvents(
156 session_id: string,

Callers 6

POSTFunction · 0.90
startFunction · 0.90
dispatchJobFunction · 0.90
runTaskKickoffServerSideFunction · 0.90

Calls 2

getDbFunction · 0.90
publishSessionEventFunction · 0.85

Tested by

no test coverage detected