@memberjunction/ai-agents 6.2.0-edge.3 → 6.2.0-edge.5
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 +100 -7
- package/dist/AgentRunner.d.ts +55 -5
- package/dist/AgentRunner.d.ts.map +1 -1
- package/dist/AgentRunner.js +277 -59
- package/dist/AgentRunner.js.map +1 -1
- package/dist/ArtifactToolManager.d.ts +11 -3
- package/dist/ArtifactToolManager.d.ts.map +1 -1
- package/dist/ArtifactToolManager.js +72 -6
- package/dist/ArtifactToolManager.js.map +1 -1
- package/dist/ClientToolRequestManager.d.ts +11 -1
- package/dist/ClientToolRequestManager.d.ts.map +1 -1
- package/dist/ClientToolRequestManager.js +19 -6
- package/dist/ClientToolRequestManager.js.map +1 -1
- package/dist/ConversationCompactionManager.d.ts +2 -0
- package/dist/ConversationCompactionManager.d.ts.map +1 -1
- package/dist/ConversationCompactionManager.js +2 -2
- package/dist/ConversationCompactionManager.js.map +1 -1
- package/dist/ConversationToolManager.d.ts +13 -2
- package/dist/ConversationToolManager.d.ts.map +1 -1
- package/dist/ConversationToolManager.js +19 -3
- package/dist/ConversationToolManager.js.map +1 -1
- package/dist/KnowledgeAgent.d.ts.map +1 -1
- package/dist/KnowledgeAgent.js +6 -1
- package/dist/KnowledgeAgent.js.map +1 -1
- package/dist/MJAIAgentRequestEntityServer.d.ts +6 -0
- package/dist/MJAIAgentRequestEntityServer.d.ts.map +1 -1
- package/dist/MJAIAgentRequestEntityServer.js +26 -1
- package/dist/MJAIAgentRequestEntityServer.js.map +1 -1
- package/dist/PayloadChangeAnalyzer.d.ts.map +1 -1
- package/dist/PayloadChangeAnalyzer.js +53 -30
- package/dist/PayloadChangeAnalyzer.js.map +1 -1
- package/dist/PayloadManager.d.ts +35 -2
- package/dist/PayloadManager.d.ts.map +1 -1
- package/dist/PayloadManager.js +250 -149
- package/dist/PayloadManager.js.map +1 -1
- package/dist/ScratchpadManager.d.ts +18 -0
- package/dist/ScratchpadManager.d.ts.map +1 -1
- package/dist/ScratchpadManager.js +61 -0
- package/dist/ScratchpadManager.js.map +1 -1
- package/dist/agent-audience.d.ts +38 -0
- package/dist/agent-audience.d.ts.map +1 -0
- package/dist/agent-audience.js +99 -0
- package/dist/agent-audience.js.map +1 -0
- package/dist/agent-context-injector.d.ts +17 -2
- package/dist/agent-context-injector.d.ts.map +1 -1
- package/dist/agent-context-injector.js +23 -7
- package/dist/agent-context-injector.js.map +1 -1
- package/dist/agent-memory-context-builder.d.ts +7 -2
- package/dist/agent-memory-context-builder.d.ts.map +1 -1
- package/dist/agent-memory-context-builder.js +12 -3
- package/dist/agent-memory-context-builder.js.map +1 -1
- package/dist/agent-pre-execution-rag.d.ts +101 -9
- package/dist/agent-pre-execution-rag.d.ts.map +1 -1
- package/dist/agent-pre-execution-rag.js +224 -23
- package/dist/agent-pre-execution-rag.js.map +1 -1
- package/dist/agent-run-watchdog.d.ts +65 -5
- package/dist/agent-run-watchdog.d.ts.map +1 -1
- package/dist/agent-run-watchdog.js +143 -28
- package/dist/agent-run-watchdog.js.map +1 -1
- package/dist/agent-types/flow-agent-type.d.ts +8 -0
- package/dist/agent-types/flow-agent-type.d.ts.map +1 -1
- package/dist/agent-types/flow-agent-type.js +48 -6
- package/dist/agent-types/flow-agent-type.js.map +1 -1
- package/dist/agent-types/loop-agent-prompt-params.d.ts +7 -0
- package/dist/agent-types/loop-agent-prompt-params.d.ts.map +1 -1
- package/dist/agent-types/loop-agent-prompt-params.js +1 -0
- package/dist/agent-types/loop-agent-prompt-params.js.map +1 -1
- package/dist/agent-types/loop-agent-response-type.d.ts +8 -2
- package/dist/agent-types/loop-agent-response-type.d.ts.map +1 -1
- package/dist/agent-types/loop-agent-response-type.js.map +1 -1
- package/dist/agent-types/loop-agent-type.d.ts +9 -2
- package/dist/agent-types/loop-agent-type.d.ts.map +1 -1
- package/dist/agent-types/loop-agent-type.js +60 -16
- package/dist/agent-types/loop-agent-type.js.map +1 -1
- package/dist/artifact-tools/SearchResultSetToolLibrary.js +4 -4
- package/dist/artifact-tools/SearchResultSetToolLibrary.js.map +1 -1
- package/dist/base-agent.d.ts +837 -43
- package/dist/base-agent.d.ts.map +1 -1
- package/dist/base-agent.js +3081 -663
- package/dist/base-agent.js.map +1 -1
- package/dist/client-tool-results.d.ts +45 -0
- package/dist/client-tool-results.d.ts.map +1 -0
- package/dist/client-tool-results.js +94 -0
- package/dist/client-tool-results.js.map +1 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -0
- package/dist/index.js.map +1 -1
- package/dist/memory-manager-agent.d.ts.map +1 -1
- package/dist/memory-manager-agent.js +46 -34
- package/dist/memory-manager-agent.js.map +1 -1
- package/dist/native-tools/action-param-schema.d.ts +57 -0
- package/dist/native-tools/action-param-schema.d.ts.map +1 -0
- package/dist/native-tools/action-param-schema.js +238 -0
- package/dist/native-tools/action-param-schema.js.map +1 -0
- package/dist/native-tools/action-tool-builder.d.ts +5 -4
- package/dist/native-tools/action-tool-builder.d.ts.map +1 -1
- package/dist/native-tools/action-tool-builder.js +29 -71
- package/dist/native-tools/action-tool-builder.js.map +1 -1
- package/dist/native-tools/json-argument.d.ts +41 -0
- package/dist/native-tools/json-argument.d.ts.map +1 -0
- package/dist/native-tools/json-argument.js +79 -0
- package/dist/native-tools/json-argument.js.map +1 -0
- package/dist/prior-turn-tool-result-cache.d.ts +31 -12
- package/dist/prior-turn-tool-result-cache.d.ts.map +1 -1
- package/dist/prior-turn-tool-result-cache.js +59 -16
- package/dist/prior-turn-tool-result-cache.js.map +1 -1
- package/dist/query-builder-agent.d.ts +13 -4
- package/dist/query-builder-agent.d.ts.map +1 -1
- package/dist/query-builder-agent.js +102 -27
- package/dist/query-builder-agent.js.map +1 -1
- package/dist/realtime/bridge-realtime-session-factory.d.ts +44 -2
- package/dist/realtime/bridge-realtime-session-factory.d.ts.map +1 -1
- package/dist/realtime/bridge-realtime-session-factory.js +68 -20
- package/dist/realtime/bridge-realtime-session-factory.js.map +1 -1
- package/dist/realtime/bridge-realtime-usage-recorder.d.ts +81 -0
- package/dist/realtime/bridge-realtime-usage-recorder.d.ts.map +1 -0
- package/dist/realtime/bridge-realtime-usage-recorder.js +194 -0
- package/dist/realtime/bridge-realtime-usage-recorder.js.map +1 -0
- package/dist/realtime/client-only-channel-server.d.ts +83 -0
- package/dist/realtime/client-only-channel-server.d.ts.map +1 -0
- package/dist/realtime/client-only-channel-server.js +107 -0
- package/dist/realtime/client-only-channel-server.js.map +1 -0
- package/dist/realtime/identity-verification-channel-server.d.ts +50 -0
- package/dist/realtime/identity-verification-channel-server.d.ts.map +1 -0
- package/dist/realtime/identity-verification-channel-server.js +66 -0
- package/dist/realtime/identity-verification-channel-server.js.map +1 -0
- package/dist/realtime/interactive-component-channel-server.d.ts +39 -0
- package/dist/realtime/interactive-component-channel-server.d.ts.map +1 -0
- package/dist/realtime/interactive-component-channel-server.js +55 -0
- package/dist/realtime/interactive-component-channel-server.js.map +1 -0
- package/dist/realtime/realtime-avatar-resolution.d.ts +194 -0
- package/dist/realtime/realtime-avatar-resolution.d.ts.map +1 -0
- package/dist/realtime/realtime-avatar-resolution.js +208 -0
- package/dist/realtime/realtime-avatar-resolution.js.map +1 -0
- package/dist/realtime/realtime-channel-policy.d.ts +81 -0
- package/dist/realtime/realtime-channel-policy.d.ts.map +1 -0
- package/dist/realtime/realtime-channel-policy.js +91 -0
- package/dist/realtime/realtime-channel-policy.js.map +1 -0
- package/dist/realtime/realtime-channel-server-host.d.ts +14 -0
- package/dist/realtime/realtime-channel-server-host.d.ts.map +1 -1
- package/dist/realtime/realtime-channel-server-host.js +35 -0
- package/dist/realtime/realtime-channel-server-host.js.map +1 -1
- package/dist/realtime/realtime-client-session-service.d.ts +435 -34
- package/dist/realtime/realtime-client-session-service.d.ts.map +1 -1
- package/dist/realtime/realtime-client-session-service.js +806 -139
- package/dist/realtime/realtime-client-session-service.js.map +1 -1
- package/dist/realtime/realtime-coagent-config.d.ts +102 -16
- package/dist/realtime/realtime-coagent-config.d.ts.map +1 -1
- package/dist/realtime/realtime-coagent-config.js +126 -5
- package/dist/realtime/realtime-coagent-config.js.map +1 -1
- package/dist/realtime/realtime-recording-ledger.d.ts +130 -0
- package/dist/realtime/realtime-recording-ledger.d.ts.map +1 -0
- package/dist/realtime/realtime-recording-ledger.js +190 -0
- package/dist/realtime/realtime-recording-ledger.js.map +1 -0
- package/dist/realtime/realtime-recording-opus-assembly.d.ts +211 -0
- package/dist/realtime/realtime-recording-opus-assembly.d.ts.map +1 -0
- package/dist/realtime/realtime-recording-opus-assembly.js +706 -0
- package/dist/realtime/realtime-recording-opus-assembly.js.map +1 -0
- package/dist/realtime/realtime-recording-store.d.ts +174 -17
- package/dist/realtime/realtime-recording-store.d.ts.map +1 -1
- package/dist/realtime/realtime-recording-store.js +552 -58
- package/dist/realtime/realtime-recording-store.js.map +1 -1
- package/dist/realtime/realtime-session-runner.js +4 -4
- package/dist/realtime/realtime-session-runner.js.map +1 -1
- package/dist/realtime/realtime-turn-moderator.d.ts +2 -1
- package/dist/realtime/realtime-turn-moderator.d.ts.map +1 -1
- package/dist/realtime/realtime-turn-moderator.js +7 -1
- package/dist/realtime/realtime-turn-moderator.js.map +1 -1
- package/dist/realtime/realtime-vendor-resolution.d.ts +9 -0
- package/dist/realtime/realtime-vendor-resolution.d.ts.map +1 -1
- package/dist/realtime/realtime-vendor-resolution.js +16 -5
- package/dist/realtime/realtime-vendor-resolution.js.map +1 -1
- package/dist/realtime/realtime-video-output-gate.d.ts +83 -0
- package/dist/realtime/realtime-video-output-gate.d.ts.map +1 -0
- package/dist/realtime/realtime-video-output-gate.js +79 -0
- package/dist/realtime/realtime-video-output-gate.js.map +1 -0
- package/dist/tool-result-format.d.ts +14 -0
- package/dist/tool-result-format.d.ts.map +1 -1
- package/dist/tool-result-format.js.map +1 -1
- package/dist/volatile-child-prompt.js +3 -3
- package/package.json +21 -19
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
import { Base64ToBytes, IsValidUUID } from '@memberjunction/global';
|
|
2
|
+
import { RECORDING_SHARD_MAX_BYTES } from '@memberjunction/ai-core-plus';
|
|
3
|
+
const SHARD_ENTITY = 'MJ: AI Agent Session Recording Shards';
|
|
4
|
+
const SP_RECORD_SHARD = 'spRecordAIAgentSessionRecordingShard';
|
|
5
|
+
const SP_STAMP_TERMINAL = 'spStampAIAgentSessionRecordingTerminal';
|
|
6
|
+
const SP_CLAIM = 'spClaimAIAgentSessionRecordingAssembly';
|
|
7
|
+
const SP_FINISH = 'spFinishAIAgentSessionRecordingAssembly';
|
|
8
|
+
const SP_DELETE = 'spDeleteAIAgentSessionRecordingShards';
|
|
9
|
+
const SP_PURGE = 'spPurgeAIAgentSessionRecordingShards';
|
|
10
|
+
const RECORD_OUTCOMES = ['Inserted', 'Duplicate', 'Conflict'];
|
|
11
|
+
const TERMINAL_OUTCOMES = ['Stamped', 'Ignored'];
|
|
12
|
+
/** StartSample is a BIGINT, which some drivers return as a string. */
|
|
13
|
+
function toMetadata(row) {
|
|
14
|
+
return { Index: row.Index, StartSample: Number(row.StartSample), SampleCount: row.SampleCount };
|
|
15
|
+
}
|
|
16
|
+
const SHA256_HEX = /^[0-9a-f]{64}$/;
|
|
17
|
+
/**
|
|
18
|
+
* {@link IRealtimeRecordingLedger} over a server-side database provider. Proc calls are built with the
|
|
19
|
+
* provider's dialect (`ProcedureCallSyntax` + positional placeholders) and bound as parameters, never
|
|
20
|
+
* interpolated. Every method validates its inputs first and throws on a SQL failure or a malformed
|
|
21
|
+
* result, with the proc and session in the message.
|
|
22
|
+
*/
|
|
23
|
+
export class SqlRealtimeRecordingLedger {
|
|
24
|
+
constructor(provider, contextUser) {
|
|
25
|
+
this.provider = provider;
|
|
26
|
+
this.contextUser = contextUser;
|
|
27
|
+
}
|
|
28
|
+
async RecordShard(input) {
|
|
29
|
+
const { SessionID, Index, StartSample, SampleCount, Data, Sha256 } = input;
|
|
30
|
+
assertSessionID(SessionID);
|
|
31
|
+
assertNonNegativeInteger(Index, 'shard index');
|
|
32
|
+
assertNonNegativeInteger(StartSample, 'start sample');
|
|
33
|
+
assertNonNegativeInteger(SampleCount, 'sample count');
|
|
34
|
+
if (Data.length === 0 || Data.length > RECORDING_SHARD_MAX_BYTES) {
|
|
35
|
+
throw new Error(`recording ledger: shard ${Index} of session ${SessionID} is ${Data.length} bytes; it must be 1..${RECORDING_SHARD_MAX_BYTES}`);
|
|
36
|
+
}
|
|
37
|
+
// The proc compares hashes as strings, so a differently-cased or malformed hash would turn a retry into a Conflict.
|
|
38
|
+
if (!SHA256_HEX.test(Sha256)) {
|
|
39
|
+
throw new Error(`recording ledger: shard ${Index} of session ${SessionID} has an invalid Sha256 (expected 64 lowercase hex characters)`);
|
|
40
|
+
}
|
|
41
|
+
const row = await this.callForOneRow(SP_RECORD_SHARD, SessionID, [SessionID, Index, StartSample, SampleCount, Data.length, Sha256, Data]);
|
|
42
|
+
if (!RECORD_OUTCOMES.includes(row.Outcome)) {
|
|
43
|
+
throw new Error(`${SP_RECORD_SHARD} returned unknown outcome '${row.Outcome}' for session ${SessionID}, shard ${Index}`);
|
|
44
|
+
}
|
|
45
|
+
return {
|
|
46
|
+
Outcome: row.Outcome,
|
|
47
|
+
RecordingStatus: row.RecordingStatus ?? null,
|
|
48
|
+
ExpectedShards: row.RecordingExpectedShards ?? null,
|
|
49
|
+
ClosedAt: toDateOrNull(row.ClosedAt),
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
async StampTerminal(sessionID, expectedShards, capturedSamples) {
|
|
53
|
+
assertSessionID(sessionID);
|
|
54
|
+
assertNonNegativeInteger(expectedShards, 'expected shards');
|
|
55
|
+
assertNonNegativeInteger(capturedSamples, 'captured samples');
|
|
56
|
+
const row = await this.callForOneRow(SP_STAMP_TERMINAL, sessionID, [sessionID, expectedShards, capturedSamples]);
|
|
57
|
+
const outcome = row.Outcome;
|
|
58
|
+
if (!TERMINAL_OUTCOMES.includes(outcome)) {
|
|
59
|
+
throw new Error(`${SP_STAMP_TERMINAL} returned unknown outcome '${row.Outcome}' for session ${sessionID}`);
|
|
60
|
+
}
|
|
61
|
+
return { Outcome: outcome, RecordingStatus: row.RecordingStatus ?? null };
|
|
62
|
+
}
|
|
63
|
+
async ClaimAssembly(sessionID, staleBefore) {
|
|
64
|
+
assertSessionID(sessionID);
|
|
65
|
+
const rows = await this.call(SP_CLAIM, sessionID, [sessionID, staleBefore]);
|
|
66
|
+
if (rows.length === 0) {
|
|
67
|
+
return null;
|
|
68
|
+
}
|
|
69
|
+
const version = rows[0].RecordingAssemblyVersion;
|
|
70
|
+
if (!Number.isInteger(version)) {
|
|
71
|
+
throw new Error(`${SP_CLAIM} returned a non-integer version '${String(version)}' for session ${sessionID}`);
|
|
72
|
+
}
|
|
73
|
+
return version;
|
|
74
|
+
}
|
|
75
|
+
async FinishAssembly(input) {
|
|
76
|
+
const { SessionID, Version, Status, Gaps, FileID } = input;
|
|
77
|
+
assertSessionID(SessionID);
|
|
78
|
+
assertNonNegativeInteger(Version, 'assembly version');
|
|
79
|
+
const gaps = Array.isArray(Gaps) ? JSON.stringify(Gaps) : Gaps;
|
|
80
|
+
const affected = await this.callForAffectedRows(SP_FINISH, SessionID, [SessionID, Version, Status, gaps, FileID]);
|
|
81
|
+
return affected > 0;
|
|
82
|
+
}
|
|
83
|
+
async StampAssemblyGaps(sessionID, version, gaps) {
|
|
84
|
+
assertSessionID(sessionID);
|
|
85
|
+
assertNonNegativeInteger(version, 'assembly version');
|
|
86
|
+
// The finish proc with the claim's own status: it writes the gaps, keeps `Assembling`, leaves the
|
|
87
|
+
// file id alone (null), and is fenced on the version and the Assembling status.
|
|
88
|
+
const affected = await this.callForAffectedRows(SP_FINISH, sessionID, [sessionID, version, 'Assembling', JSON.stringify(gaps), null]);
|
|
89
|
+
return affected > 0;
|
|
90
|
+
}
|
|
91
|
+
async LoadShards(sessionID) {
|
|
92
|
+
// Naming the binary Data field makes the provider include it (as base64).
|
|
93
|
+
const rows = await this.readShardRows(sessionID, ['Index', 'StartSample', 'SampleCount', 'Data'], 'LoadShards');
|
|
94
|
+
return rows.map(row => ({ ...toMetadata(row), Data: Base64ToBytes(row.Data) }));
|
|
95
|
+
}
|
|
96
|
+
async LoadShardMetadata(sessionID) {
|
|
97
|
+
const rows = await this.readShardRows(sessionID, ['Index', 'StartSample', 'SampleCount'], 'LoadShardMetadata');
|
|
98
|
+
return rows.map(toMetadata);
|
|
99
|
+
}
|
|
100
|
+
async readShardRows(sessionID, fields, operation) {
|
|
101
|
+
assertSessionID(sessionID);
|
|
102
|
+
const result = await this.provider.RunView({
|
|
103
|
+
EntityName: SHARD_ENTITY,
|
|
104
|
+
ExtraFilter: `AgentSessionID='${sessionID}'`,
|
|
105
|
+
OrderBy: this.provider.Dialect.QuoteIdentifier('Index'),
|
|
106
|
+
Fields: fields,
|
|
107
|
+
ResultType: 'simple',
|
|
108
|
+
BypassCache: true,
|
|
109
|
+
}, this.contextUser);
|
|
110
|
+
if (!result.Success) {
|
|
111
|
+
throw new Error(`${operation} failed for session ${sessionID}: ${result.ErrorMessage ?? 'unknown error'}`);
|
|
112
|
+
}
|
|
113
|
+
return result.Results;
|
|
114
|
+
}
|
|
115
|
+
async CountShardsBelow(sessionID, indexBelow) {
|
|
116
|
+
assertSessionID(sessionID);
|
|
117
|
+
// Validated as an integer because it is interpolated into the filter.
|
|
118
|
+
assertNonNegativeInteger(indexBelow, 'index bound');
|
|
119
|
+
const quotedIndex = this.provider.Dialect.QuoteIdentifier('Index');
|
|
120
|
+
const result = await this.provider.RunView({
|
|
121
|
+
EntityName: SHARD_ENTITY,
|
|
122
|
+
ExtraFilter: `AgentSessionID='${sessionID}' AND ${quotedIndex} < ${indexBelow}`,
|
|
123
|
+
ResultType: 'count_only',
|
|
124
|
+
BypassCache: true,
|
|
125
|
+
}, this.contextUser);
|
|
126
|
+
if (!result.Success) {
|
|
127
|
+
throw new Error(`CountShardsBelow failed for session ${sessionID}: ${result.ErrorMessage ?? 'unknown error'}`);
|
|
128
|
+
}
|
|
129
|
+
return result.TotalRowCount;
|
|
130
|
+
}
|
|
131
|
+
async DeleteShardsBelow(sessionID, indexBelow) {
|
|
132
|
+
assertSessionID(sessionID);
|
|
133
|
+
assertNonNegativeInteger(indexBelow, 'index bound');
|
|
134
|
+
return this.callForAffectedRows(SP_DELETE, sessionID, [sessionID, indexBelow]);
|
|
135
|
+
}
|
|
136
|
+
async PurgeClosedBefore(closedBefore, maxRows) {
|
|
137
|
+
if (!(closedBefore instanceof Date) || Number.isNaN(closedBefore.getTime())) {
|
|
138
|
+
throw new Error('PurgeClosedBefore: closedBefore must be a valid Date');
|
|
139
|
+
}
|
|
140
|
+
if (!Number.isInteger(maxRows) || maxRows <= 0) {
|
|
141
|
+
throw new Error(`PurgeClosedBefore: maxRows must be a positive integer, got ${maxRows}`);
|
|
142
|
+
}
|
|
143
|
+
return this.callForAffectedRows(SP_PURGE, `(purge before ${closedBefore.toISOString()})`, [closedBefore, maxRows]);
|
|
144
|
+
}
|
|
145
|
+
/** Runs a proc with positional parameters; wraps any failure with the proc and the session it was for. */
|
|
146
|
+
async call(proc, sessionLabel, params) {
|
|
147
|
+
const d = this.provider.Dialect;
|
|
148
|
+
const placeholders = params.map((_, i) => d.ParameterPlaceholder(i));
|
|
149
|
+
const sql = d.ProcedureCallSyntax(this.provider.MJCoreSchemaName, proc, placeholders) + ';';
|
|
150
|
+
try {
|
|
151
|
+
const rows = await this.provider.ExecuteSQL(sql, params, { isMutation: true, description: `${proc} (session ${sessionLabel})` }, this.contextUser);
|
|
152
|
+
return Array.isArray(rows) ? rows : [];
|
|
153
|
+
}
|
|
154
|
+
catch (error) {
|
|
155
|
+
throw new Error(`${proc} failed for session ${sessionLabel}: ${error instanceof Error ? error.message : String(error)}`, { cause: error });
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
async callForOneRow(proc, sessionLabel, params) {
|
|
159
|
+
const rows = await this.call(proc, sessionLabel, params);
|
|
160
|
+
if (rows.length === 0) {
|
|
161
|
+
throw new Error(`${proc} returned no row for session ${sessionLabel}`);
|
|
162
|
+
}
|
|
163
|
+
return rows[0];
|
|
164
|
+
}
|
|
165
|
+
async callForAffectedRows(proc, sessionLabel, params) {
|
|
166
|
+
const rows = await this.call(proc, sessionLabel, params);
|
|
167
|
+
const affected = rows[0]?.AffectedRows;
|
|
168
|
+
if (typeof affected !== 'number') {
|
|
169
|
+
throw new Error(`${proc} returned no AffectedRows for session ${sessionLabel}`);
|
|
170
|
+
}
|
|
171
|
+
return affected;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
function assertSessionID(sessionID) {
|
|
175
|
+
if (!IsValidUUID(sessionID)) {
|
|
176
|
+
throw new Error(`recording ledger: invalid session id '${sessionID}'`);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
function assertNonNegativeInteger(value, field) {
|
|
180
|
+
if (!Number.isSafeInteger(value) || value < 0) {
|
|
181
|
+
throw new Error(`recording ledger: ${field} must be a non-negative integer, got ${value}`);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
function toDateOrNull(value) {
|
|
185
|
+
if (value === null || value === undefined) {
|
|
186
|
+
return null;
|
|
187
|
+
}
|
|
188
|
+
return value instanceof Date ? value : new Date(value);
|
|
189
|
+
}
|
|
190
|
+
//# sourceMappingURL=realtime-recording-ledger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"realtime-recording-ledger.js","sourceRoot":"","sources":["../../src/realtime/realtime-recording-ledger.ts"],"names":[],"mappings":"AAkBA,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACpE,OAAO,EAAE,yBAAyB,EAAE,MAAM,8BAA8B,CAAC;AAyFzE,MAAM,YAAY,GAAG,uCAAuC,CAAC;AAC7D,MAAM,eAAe,GAAG,sCAAsC,CAAC;AAC/D,MAAM,iBAAiB,GAAG,wCAAwC,CAAC;AACnE,MAAM,QAAQ,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EAAE,MAAM,CAAC,CAAC;QACtE,MAAM,QAAQ,GAAG,IAAI,CAAC,CAAC,CAAC,EAAE,YAAY,CAAC;QACvC,IAAI,OAAO,QAAQ,KAAK,QAAQ,EAAE,CAAC;YAC/B,MAAM,IAAI,KAAK,CAAC,GAAG,IAAI,yCAAyC,YAAY,EAAE,CAAC,CAAC;QACpF,CAAC;QACD,OAAO,QAAQ,CAAC;IACpB,CAAC;CACJ;AAED,SAAS,eAAe,CAAC,SAAiB;IACtC,IAAI,CAAC,WAAW,CAAC,SAAS,CAAC,EAAE,CAAC;QAC1B,MAAM,IAAI,KAAK,CAAC,yCAAyC,SAAS,GAAG,CAAC,CAAC;IAC3E,CAAC;AACL,CAAC;AAED,SAAS,wBAAwB,CAAC,KAAa,EAAE,KAAa;IAC1D,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,KAAK,CAAC,IAAI,KAAK,GAAG,CAAC,EAAE,CAAC;QAC5C,MAAM,IAAI,KAAK,CAAC,qBAAqB,KAAK,wCAAwC,KAAK,EAAE,CAAC,CAAC;IAC/F,CAAC;AACL,CAAC;AAED,SAAS,YAAY,CAAC,KAAuC;IACzD,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;QACxC,OAAO,IAAI,CAAC;IAChB,CAAC;IACD,OAAO,KAAK,YAAY,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,KAAK,CAAC,CAAC;AAC3D,CAAC"}
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
import { IMetadataProvider, UserInfo } from '@memberjunction/core';
|
|
2
|
+
import { RecordingShardContents } from '@memberjunction/ai-core-plus';
|
|
3
|
+
import { IRealtimeRecordingLedger } from './realtime-recording-ledger.js';
|
|
4
|
+
/** A silent range of the assembled recording and the shard indexes whose absence caused it. */
|
|
5
|
+
export interface RecordingGap {
|
|
6
|
+
/** First silent sample (48 kHz). */
|
|
7
|
+
startSample: number;
|
|
8
|
+
/** Number of silent samples. */
|
|
9
|
+
sampleCount: number;
|
|
10
|
+
/** Missing shard indexes covered by the gap; empty when shards are present but do not abut. */
|
|
11
|
+
indexes: number[];
|
|
12
|
+
}
|
|
13
|
+
/** Decodes one Opus packet at a time, keeping decoder state across calls (one stream). */
|
|
14
|
+
export interface IOpusPacketDecoder {
|
|
15
|
+
/** Decodes one packet to mono PCM16 samples. The returned array is owned by the caller. */
|
|
16
|
+
Decode(packet: Uint8Array): Int16Array;
|
|
17
|
+
/**
|
|
18
|
+
* Resets the decoder state. Called after a gap, so the previous shard's state (and packet-loss
|
|
19
|
+
* concealment based on it) does not smear into the first frames after the gap.
|
|
20
|
+
*/
|
|
21
|
+
Reset(): void;
|
|
22
|
+
}
|
|
23
|
+
/** A shard whose packets libopus could not decode; its whole range was left silent (and listed as a gap). */
|
|
24
|
+
export interface ShardDecodeFailure {
|
|
25
|
+
ShardIndex: number;
|
|
26
|
+
PacketIndex: number;
|
|
27
|
+
Message: string;
|
|
28
|
+
}
|
|
29
|
+
/** Result of {@link AssembleOpusRecordingPcm}. */
|
|
30
|
+
export interface AssembledOpusRecording {
|
|
31
|
+
/** Mono PCM16 at 48 kHz. On little-endian hosts this is a view over `Wav`'s data section. */
|
|
32
|
+
Pcm: Int16Array;
|
|
33
|
+
/** The recording as a canonical 44-byte-header mono PCM16 WAV holding `Pcm`. */
|
|
34
|
+
Wav: Buffer;
|
|
35
|
+
/** Silent ranges, in timeline order. */
|
|
36
|
+
Gaps: RecordingGap[];
|
|
37
|
+
/** Shards dropped because a packet failed to decode (each is also in `Gaps`). */
|
|
38
|
+
DecodeFailures: ShardDecodeFailure[];
|
|
39
|
+
/** True when the terminal counts are known and the timeline matches them (shard count == expected, length == captured). */
|
|
40
|
+
/**
|
|
41
|
+
* The gaps caused by missing shard indexes, in timeline order (each one of `Gaps`). These are the only
|
|
42
|
+
* ranges {@link FillGapsFromPreviousRecording} may reuse; a shard that failed to decode, or a gap
|
|
43
|
+
* between present shards that do not abut, is never filled from an earlier recording.
|
|
44
|
+
*/
|
|
45
|
+
MissingRuns: RecordingGap[];
|
|
46
|
+
TerminalMatched: boolean;
|
|
47
|
+
/** `TerminalMatched` and no gaps: every expected range holds decoded (or reused, see {@link FillGapsFromPreviousRecording}) audio. */
|
|
48
|
+
Complete: boolean;
|
|
49
|
+
}
|
|
50
|
+
/** A recording assembled earlier for the same session: its samples and the gaps it was finished with. */
|
|
51
|
+
export interface PreviousRecording {
|
|
52
|
+
Pcm: Int16Array;
|
|
53
|
+
Gaps: RecordingGap[];
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* A deterministic assembly failure: re-running against the same data fails the same way (bounds
|
|
57
|
+
* exceeded, overlapping or duplicate shards, no storage account, agent not loadable), so the recording
|
|
58
|
+
* is finished as `Failed`. Any other error is treated as transient (see {@link AssembleRealtimeRecordingFromLedger}).
|
|
59
|
+
*/
|
|
60
|
+
export declare class RecordingAssemblyError extends Error {
|
|
61
|
+
constructor(message: string);
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Outcome of {@link AssembleRealtimeRecordingFromLedger}. `Retry`: a transient failure left the claim in
|
|
65
|
+
* `Assembling` for a stale re-claim to retry.
|
|
66
|
+
*/
|
|
67
|
+
export type AssembleRealtimeRecordingOutcome = 'Complete' | 'Partial' | 'Failed' | 'Superseded' | 'Deferred' | 'Retry';
|
|
68
|
+
/** Input to {@link AssembleRealtimeRecordingFromLedger}. */
|
|
69
|
+
export interface AssembleRealtimeRecordingInput {
|
|
70
|
+
SessionID: string;
|
|
71
|
+
/** The version {@link IRealtimeRecordingLedger.ClaimAssembly} returned for this assembly. */
|
|
72
|
+
Version: number;
|
|
73
|
+
Ledger: IRealtimeRecordingLedger;
|
|
74
|
+
ContextUser: UserInfo;
|
|
75
|
+
Provider: IMetadataProvider;
|
|
76
|
+
/**
|
|
77
|
+
* Assemble what exists even when shards are missing (gaps become silence; the result is `Partial`).
|
|
78
|
+
* Without it, an incomplete ledger hands the claim back (`Deferred`) so a later assembly can finish
|
|
79
|
+
* it once the missing shards arrive or the grace period runs out.
|
|
80
|
+
*/
|
|
81
|
+
ForcePartial?: boolean;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Most shards one assembly accepts. At 5 s per shard this is ~2.8 h, past any real call; a larger
|
|
85
|
+
* count (from the terminal signal or the ledger) is corrupt or hostile, and assembling it would allocate
|
|
86
|
+
* an unbounded PCM buffer, so assembly refuses it.
|
|
87
|
+
*/
|
|
88
|
+
export declare const MAX_ASSEMBLY_SHARDS = 2000;
|
|
89
|
+
/**
|
|
90
|
+
* Most samples one assembly produces: 3 h at 48 kHz. The WAV is 2 bytes per sample (~1 GB at this cap;
|
|
91
|
+
* on big-endian hosts a separate PCM array doubles that), so this is the memory ceiling of one
|
|
92
|
+
* assembly; the captured count comes from the browser, so it must be bounded before anything is allocated.
|
|
93
|
+
*/
|
|
94
|
+
export declare const MAX_ASSEMBLY_SAMPLES: number;
|
|
95
|
+
/**
|
|
96
|
+
* Lays a session's shards out on one 48 kHz timeline and decodes them with one decoder.
|
|
97
|
+
*
|
|
98
|
+
* - A present shard is decoded packet by packet; exactly `SampleCount` samples are kept (decoded audio
|
|
99
|
+
* past it is dropped, a shortfall stays silent). Every packet is still decoded so the decoder state
|
|
100
|
+
* stays continuous into the next shard.
|
|
101
|
+
* - A run of missing indexes becomes one silent gap from the end of the previous shard to the start of
|
|
102
|
+
* the next present one (a trailing run: to the end of the recording), listing the missing indexes.
|
|
103
|
+
* - A present shard that starts after the end of the previous one leaves a silent gap with no indexes.
|
|
104
|
+
* - A shard with a packet libopus cannot decode is silenced whole, listed as a gap with its index and
|
|
105
|
+
* in `DecodeFailures`.
|
|
106
|
+
* - After any gap the decoder is reset.
|
|
107
|
+
*
|
|
108
|
+
* The samples are decoded straight into the returned WAV's data section (see `allocatePcm16Wav`).
|
|
109
|
+
*
|
|
110
|
+
* The shard count is `expectedShards`, or the highest present index + 1 when no terminal signal has
|
|
111
|
+
* arrived. The length is `capturedSamples`, or the end of the last shard when unknown (and never less
|
|
112
|
+
* than the end of the last shard: audio past a stale terminal is kept, not cut).
|
|
113
|
+
*
|
|
114
|
+
* @param shards Parsed shards (any order, unique indexes).
|
|
115
|
+
* @param expectedShards Shard count from the terminal signal, or null when none arrived.
|
|
116
|
+
* @param capturedSamples Captured sample count from the terminal signal, or null.
|
|
117
|
+
* @param decoder The one decoder for this stream.
|
|
118
|
+
* @throws RecordingAssemblyError on a duplicate index, a shard overlapping the audio before it, or a
|
|
119
|
+
* shard/sample count over {@link MAX_ASSEMBLY_SHARDS} / {@link MAX_ASSEMBLY_SAMPLES}.
|
|
120
|
+
*/
|
|
121
|
+
export declare function AssembleOpusRecordingPcm(shards: RecordingShardContents[], expectedShards: number | null, capturedSamples: number | null, decoder: IOpusPacketDecoder): AssembledOpusRecording;
|
|
122
|
+
/**
|
|
123
|
+
* Fills the missing-shard ranges of a re-assembly from the session's previous recording.
|
|
124
|
+
*
|
|
125
|
+
* Why: a Complete assembly deletes its shard rows (everything below its expected count). When a strictly
|
|
126
|
+
* higher terminal later re-opens the session (the tab was hidden, a terminal went out, the call
|
|
127
|
+
* continued), the re-assembly finds those indexes missing. Their audio lives only in the previous
|
|
128
|
+
* `recording.wav`, so it is copied back rather than overwritten with silence.
|
|
129
|
+
*
|
|
130
|
+
* Every missing range the previous file covers is reused, not only the leading one: a re-sent copy of
|
|
131
|
+
* an assembled shard (its ack was lost, so the browser sent it again after the rows were deleted) is
|
|
132
|
+
* stored again, and would otherwise split the deleted range and leave everything after it silent.
|
|
133
|
+
* Reusing is safe because the previous recording's silent ranges are exactly its stored gaps: every
|
|
134
|
+
* assembly stamps its gaps before it overwrites the object (see `StampAssemblyGaps`), so an assembly
|
|
135
|
+
* that wrote silence and then failed to finish still left that silence listed. Those gaps are carried
|
|
136
|
+
* over (clipped to each reused range) and stay gaps. The one remaining way the object can disagree is a
|
|
137
|
+
* superseded assembler whose slow storage write lands after a newer one finished (a known, parked race).
|
|
138
|
+
*
|
|
139
|
+
* The part of a range beyond the previous recording's length stays silent and stays a gap; the range's
|
|
140
|
+
* rows are gone, so per-index boundaries are unknown, and the remainder lists the indexes that can hold
|
|
141
|
+
* samples past the old end: an index `i` ends no later than `(i + 1) * MAX_SHARD_SAMPLES`, so indexes
|
|
142
|
+
* that provably end inside the old recording are dropped.
|
|
143
|
+
*
|
|
144
|
+
* Returns a new result (the samples are written in place) with `Complete` recomputed.
|
|
145
|
+
*/
|
|
146
|
+
export declare function FillGapsFromPreviousRecording(assembled: AssembledOpusRecording, previous: PreviousRecording): AssembledOpusRecording;
|
|
147
|
+
/**
|
|
148
|
+
* The samples of a canonical recording WAV (exactly the 44-byte mono PCM16 48 kHz layout
|
|
149
|
+
* `WriteRecordingWavHeader` writes, data size matching the file), or null for anything else. Only such
|
|
150
|
+
* a file is trusted as a previous assembly's output.
|
|
151
|
+
*/
|
|
152
|
+
export declare function ParseCanonicalRecordingWav(bytes: Uint8Array): Int16Array | null;
|
|
153
|
+
/**
|
|
154
|
+
* Throws when an assembly would exceed {@link MAX_ASSEMBLY_SHARDS} or {@link MAX_ASSEMBLY_SAMPLES}.
|
|
155
|
+
* Checked twice on purpose: by the orchestrator on the session's terminal counts BEFORE loading any
|
|
156
|
+
* shard rows, and by {@link AssembleOpusRecordingPcm} on the counts derived from the shards themselves
|
|
157
|
+
* (the only counts there are when no terminal signal arrived).
|
|
158
|
+
*/
|
|
159
|
+
export declare function AssertRecordingAssemblyBounds(shardCount: number | null, sampleCount: number | null): void;
|
|
160
|
+
/**
|
|
161
|
+
* Waveform peaks of a whole recording: max-abs per bucket, normalized by the global max (0..1). Same
|
|
162
|
+
* semantics as the peaks the browser used to compute at capture time for its whole-call WAV upload,
|
|
163
|
+
* so a viewer renders an assembled recording exactly like one uploaded before #5294.
|
|
164
|
+
*
|
|
165
|
+
* @param pcm Mono PCM16 samples.
|
|
166
|
+
* @param buckets Target bucket count (default 600); a shorter buffer yields one bucket per sample.
|
|
167
|
+
* @returns The peaks, or `[]` for an empty or all-silent buffer.
|
|
168
|
+
*/
|
|
169
|
+
export declare function ComputeRecordingPeaks(pcm: Int16Array, buckets?: number): number[];
|
|
170
|
+
/**
|
|
171
|
+
* Wraps mono PCM16 samples in the canonical 44-byte WAV header (written by the shared
|
|
172
|
+
* `WriteRecordingWavHeader`), samples little-endian regardless of host byte order.
|
|
173
|
+
*/
|
|
174
|
+
export declare function EncodePcm16Wav(pcm: Int16Array, sampleRate: number): Buffer;
|
|
175
|
+
/** A fresh 48 kHz mono libopus decoder. Use one per assembly; feed it packets in stream order. */
|
|
176
|
+
export declare function CreateLibopusDecoder(): IOpusPacketDecoder;
|
|
177
|
+
/**
|
|
178
|
+
* Assembles a claimed session's shard ledger into `recording.wav` + `peaks.json` and finishes the claim.
|
|
179
|
+
*
|
|
180
|
+
* Flow: read the session's terminal counts and the stored rows' positions (both bounded before any
|
|
181
|
+
* shard bytes are loaded) → without `ForcePartial`, hand the claim back (`Deferred`) when the positions
|
|
182
|
+
* alone show the recording cannot be Complete → resolve where the recording is stored → load and parse
|
|
183
|
+
* the shards (a shard that fails to parse, or whose header disagrees with its ledger row, is logged and
|
|
184
|
+
* treated as missing) → decode ({@link AssembleOpusRecordingPcm}; a shard with an undecodable packet is
|
|
185
|
+
* logged and silenced) → when the session already has its own `recording.wav` and shards are missing,
|
|
186
|
+
* read it and fill those ranges from it ({@link FillGapsFromPreviousRecording}: a Complete assembly deleted
|
|
187
|
+
* the rows its audio came from, so a re-opened session must not overwrite that audio with silence; the
|
|
188
|
+
* early position-only Deferred is skipped for such a session for the same reason). Then:
|
|
189
|
+
* - incomplete and not `ForcePartial`: the claim is handed back as `Pending` with no file, keeping the
|
|
190
|
+
* gaps already stored for the session's existing recording → `Deferred`;
|
|
191
|
+
* - otherwise the gaps are stamped (fenced: a lost claim is `Superseded`, nothing written) and the WAV
|
|
192
|
+
* is stored: a first assembly uploads `recording.wav`
|
|
193
|
+
* into the session folder; a re-assembly overwrites the session's existing WAV object in place, keeping
|
|
194
|
+
* its `MJ: Files` id. `peaks.json` is rewritten next to it. The finish is fenced on `Version`; only then
|
|
195
|
+
* is a new file linked to the session and, for `Complete`, the assembled shard rows deleted.
|
|
196
|
+
*
|
|
197
|
+
* The session is never saved through `BaseEntity` (that rewrites every column and would clobber the
|
|
198
|
+
* concurrent proc writes to the recording state); the finish proc stamps `RecordingFileID`.
|
|
199
|
+
*
|
|
200
|
+
* Never throws. Failures split by kind:
|
|
201
|
+
* - a {@link RecordingAssemblyError} (deterministic: bounds exceeded, overlapping or duplicate shards,
|
|
202
|
+
* no storage account, agent not loadable) is logged, the claim is finished as `Failed` (when the fence
|
|
203
|
+
* still holds), and the outcome is `Failed`;
|
|
204
|
+
* - any other error (SQL, storage, decoder load: likely transient) is logged with the session id and
|
|
205
|
+
* version, and the claim is LEFT in `Assembling` with no finish call; the outcome is `Retry`. The
|
|
206
|
+
* janitor's stale-`Assembling` re-claim (with its backoff and give-up cap) retries a closed session,
|
|
207
|
+
* and a later terminal or shard re-opens a live one.
|
|
208
|
+
* A lost fence is `Superseded` and leaves the shards.
|
|
209
|
+
*/
|
|
210
|
+
export declare function AssembleRealtimeRecordingFromLedger(input: AssembleRealtimeRecordingInput): Promise<AssembleRealtimeRecordingOutcome>;
|
|
211
|
+
//# sourceMappingURL=realtime-recording-opus-assembly.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"realtime-recording-opus-assembly.d.ts","sourceRoot":"","sources":["../../src/realtime/realtime-recording-opus-assembly.ts"],"names":[],"mappings":"AAmBA,OAAO,EAAE,iBAAiB,EAAuB,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAGxF,OAAO,EACkB,sBAAsB,EAC9C,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAE,wBAAwB,EAAoC,MAAM,6BAA6B,CAAC;AAMzG,+FAA+F;AAC/F,MAAM,WAAW,YAAY;IACzB,oCAAoC;IACpC,WAAW,EAAE,MAAM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