maka-agent 0.2.0-dev.49.20260924 → 0.2.0-dev.50.20260925
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/LICENSE +35 -0
- package/dist/acp/maka-acp-agent.js +71 -11
- package/dist/acp/session-event-mapper.js +59 -3
- package/dist/acp/session-interactions.js +33 -3
- package/dist/acp/session-mcp.js +160 -11
- package/dist/acp/session-registry.js +1014 -242
- package/dist/acp/turn-observation.js +260 -0
- package/dist/mcp-capability-publication.js +17 -1
- package/dist/pi-transcript-tools.js +8 -3
- package/dist/runtime-host-session-channel.js +71 -47
- package/native/runtime-host-windows-task-launcher/prebuilds/win32-x64/maka-runtime-host-task-launcher.exe +0 -0
- package/node_modules/@maka/core/dist/relative-time.js +9 -1
- package/node_modules/@maka/core/dist/session.js +0 -15
- package/node_modules/@maka/core/dist/tool-quiet-preview.js +31 -0
- package/node_modules/@maka/core/dist/transcript-search.js +0 -1
- package/node_modules/@maka/runtime/dist/conversation-copy.js +7 -1
- package/node_modules/@maka/runtime/dist/runtime-event-backfill.js +0 -1
- package/node_modules/@maka/runtime-host/dist/client/client-capability-channel.js +3 -1
- package/node_modules/@maka/runtime-host/dist/client/connection.js +2 -2
- package/node_modules/@maka/runtime-host/dist/client/session-subscription.js +0 -3
- package/node_modules/@maka/runtime-host/dist/protocol/client-capability.js +19 -1
- package/node_modules/@maka/runtime-host/dist/protocol/index.js +4 -1
- package/node_modules/@maka/runtime-host/dist/protocol/session-continuity.js +1 -2
- package/node_modules/@maka/runtime-host/dist/server/client-capability-coordinator.js +122 -9
- package/node_modules/@maka/runtime-host/dist/server/execution-composition.js +11 -6
- package/node_modules/@maka/runtime-host/dist/server/root-turn-coordinator.js +5 -0
- package/node_modules/@maka/runtime-host/dist/server/session-continuity-coordinator.js +0 -16
- package/node_modules/@maka/runtime-host/dist/server/session-transcript-reader.js +3 -38
- package/node_modules/@maka/runtime-host/dist/server/shared-session-transcript.js +0 -3
- package/node_modules/@maka/storage/dist/interaction-store.js +0 -13
- package/node_modules/@maka/storage/dist/runtime-partial-values.js +5 -1
- package/node_modules/@maka/storage/dist/sqlite-core-execution-schema.js +1 -3
- package/node_modules/@maka/storage/dist/usage-screen.js +101 -35
- package/package.json +1 -1
|
@@ -23,37 +23,65 @@ import { CACHE_READ_TOKENS } from './model-call-usage-sql.js';
|
|
|
23
23
|
import { TelemetryQueryValidationError } from './telemetry-repo.js';
|
|
24
24
|
const json = (key) => `json_extract(record_json, '$.${key}')`;
|
|
25
25
|
const num = (key) => `COALESCE(${json(key)}, 0)`;
|
|
26
|
-
//
|
|
27
|
-
//
|
|
28
|
-
const
|
|
29
|
-
|
|
26
|
+
// The three sources share accounting/filter expressions, but activity pages and
|
|
27
|
+
// counts select only the rows/columns they need. Aggregates remain range-wide.
|
|
28
|
+
const SOURCES = [
|
|
29
|
+
{
|
|
30
|
+
name: 'canonical',
|
|
31
|
+
table: 'usage_model_call_attempts',
|
|
32
|
+
time: 'completed_at',
|
|
33
|
+
identity: 'attempt_id',
|
|
34
|
+
filters: `provider_id AS provider, model_id AS model, NULL AS toolName,
|
|
35
|
+
CASE status WHEN 'completed' THEN 'success' WHEN 'failed' THEN 'error' ELSE 'aborted' END AS status`,
|
|
36
|
+
columns: `completed_at AS ts, 'canonical' AS source, attempt_id AS identity,
|
|
30
37
|
attempt_id AS id, 'model' AS kind, session_id AS sessionId, turn_id AS turnId,
|
|
31
|
-
provider_id AS provider, model_id AS model, NULL AS toolName,
|
|
32
38
|
COALESCE(connection_slug, provider_id) AS connection,
|
|
33
39
|
COALESCE(input_tokens, 0) AS inputTokens, COALESCE(output_tokens, 0) AS outputTokens,
|
|
34
40
|
COALESCE(cache_miss_input_tokens, 0) AS cacheMiss, ${CACHE_READ_TOKENS} AS cacheRead,
|
|
35
41
|
COALESCE(cache_write_input_tokens, 0) AS cacheCreation, COALESCE(reasoning_tokens, 0) AS reasoning,
|
|
36
42
|
COALESCE(input_tokens, 0) + COALESCE(output_tokens, 0) AS totalTokens,
|
|
37
43
|
cost_usd AS costUsd, latency_ms AS latencyMs,
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
const TOOL_ROWS = `
|
|
49
|
-
SELECT ts, 'tool' AS source, storage_key AS identity, id, 'tool' AS kind,
|
|
44
|
+
cost_basis AS costBasis, usage_basis AS usageBasis`,
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
name: 'legacy',
|
|
48
|
+
table: 'usage_llm_calls',
|
|
49
|
+
time: 'ts',
|
|
50
|
+
identity: 'storage_key',
|
|
51
|
+
filters: `${json('providerId')} AS provider, ${json('modelId')} AS model,
|
|
52
|
+
NULL AS toolName, ${json('status')} AS status`,
|
|
53
|
+
columns: `ts, 'legacy' AS source, storage_key AS identity, id, 'model' AS kind,
|
|
50
54
|
${json('sessionId')} AS sessionId, ${json('turnId')} AS turnId,
|
|
51
|
-
COALESCE(${json('
|
|
52
|
-
${
|
|
55
|
+
COALESCE(${json('connectionSlug')}, ${json('providerId')}) AS connection,
|
|
56
|
+
${num('inputTokens')} AS inputTokens, ${num('outputTokens')} AS outputTokens,
|
|
57
|
+
${num('cacheMissInputTokens')} AS cacheMiss,
|
|
58
|
+
MIN(${num('inputTokens')}, ${num('cacheHitInputTokens')}) AS cacheRead,
|
|
59
|
+
${num('cacheWriteInputTokens')} AS cacheCreation, ${num('reasoningTokens')} AS reasoning,
|
|
60
|
+
${num('totalTokens')} AS totalTokens, ${num('costUsd')} AS costUsd,
|
|
61
|
+
${num('latencyMs')} AS latencyMs, NULL AS costBasis, NULL AS usageBasis`,
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
name: 'tool',
|
|
65
|
+
table: 'usage_tool_invocations',
|
|
66
|
+
time: 'ts',
|
|
67
|
+
identity: 'storage_key',
|
|
68
|
+
filters: `COALESCE(${json('providerId')}, '') AS provider,
|
|
69
|
+
COALESCE(${json('modelId')}, '') AS model, ${json('toolName')} AS toolName,
|
|
70
|
+
${json('status')} AS status`,
|
|
71
|
+
columns: `ts, 'tool' AS source, storage_key AS identity, id, 'tool' AS kind,
|
|
72
|
+
${json('sessionId')} AS sessionId, ${json('turnId')} AS turnId,
|
|
73
|
+
'' AS connection,
|
|
53
74
|
0 AS inputTokens, 0 AS outputTokens, 0 AS cacheMiss, 0 AS cacheRead,
|
|
54
75
|
0 AS cacheCreation, 0 AS reasoning, 0 AS totalTokens, NULL AS costUsd,
|
|
55
|
-
${num('durationMs')} AS latencyMs,
|
|
56
|
-
|
|
76
|
+
${num('durationMs')} AS latencyMs, NULL AS costBasis, NULL AS usageBasis`,
|
|
77
|
+
},
|
|
78
|
+
];
|
|
79
|
+
function rangeRows(source) {
|
|
80
|
+
return `SELECT ${source.columns}, ${source.filters} FROM ${source.table}
|
|
81
|
+
WHERE ${source.time} >= ? AND ${source.time} <= ?${source.name === 'canonical' ? ' AND cost_basis IS NOT NULL' : ''}`;
|
|
82
|
+
}
|
|
83
|
+
const MODEL_ROWS = `${rangeRows(SOURCES[0])} UNION ALL ${rangeRows(SOURCES[1])}`;
|
|
84
|
+
const TOOL_ROWS = rangeRows(SOURCES[2]);
|
|
57
85
|
const n = (value) => Number(value ?? 0);
|
|
58
86
|
const hash = (value) => createHash('sha256').update(JSON.stringify(value)).digest('hex');
|
|
59
87
|
export function createUsageScreenReader(root) {
|
|
@@ -98,15 +126,23 @@ export function createUsageScreenReader(root) {
|
|
|
98
126
|
const statistics = hit?.statistics ?? readRangeStatistics(db, input.query.range);
|
|
99
127
|
if ('kind' in statistics)
|
|
100
128
|
return statistics;
|
|
129
|
+
// Complete range statistics already counted every readable model/tool
|
|
130
|
+
// row. Only activity filters need a separate exact count.
|
|
131
|
+
const activityTotal = !input.query.search && input.query.status === 'all'
|
|
132
|
+
? statistics.summary.totalRequests +
|
|
133
|
+
statistics.byTool.reduce((sum, row) => sum + row.calls, 0)
|
|
134
|
+
: activityCount(db, input.query);
|
|
101
135
|
const screen = {
|
|
102
136
|
revision,
|
|
103
137
|
queryIdentity,
|
|
104
138
|
query: input.query,
|
|
105
|
-
activityTotal
|
|
139
|
+
activityTotal,
|
|
106
140
|
// Host projects identities and freezes replies; returned objects must
|
|
107
141
|
// never share mutable rows or arrays with another cached response.
|
|
108
142
|
...structuredClone(statistics),
|
|
109
|
-
|
|
143
|
+
// Count and page share this read snapshot: zero proves there is no
|
|
144
|
+
// matching activity, so an empty search needs only one range scan.
|
|
145
|
+
...(activityTotal === 0 ? { logs: [], nextCursor: null } : activity(db, input.query)),
|
|
110
146
|
};
|
|
111
147
|
if (!hit) {
|
|
112
148
|
// A nested read can observe writes that later roll back and reuse the
|
|
@@ -241,8 +277,7 @@ function validateQuery(query) {
|
|
|
241
277
|
}
|
|
242
278
|
}
|
|
243
279
|
function activityPredicate(query) {
|
|
244
|
-
const
|
|
245
|
-
const args = [...range, ...range, ...range];
|
|
280
|
+
const args = [];
|
|
246
281
|
const filters = [];
|
|
247
282
|
if (query.status !== 'all') {
|
|
248
283
|
filters.push('status = ?');
|
|
@@ -255,15 +290,42 @@ function activityPredicate(query) {
|
|
|
255
290
|
}
|
|
256
291
|
return { args, filters };
|
|
257
292
|
}
|
|
293
|
+
function activitySourceQuery(source, query, columns, position) {
|
|
294
|
+
const bounds = [`${source.time} >= ?`];
|
|
295
|
+
const args = [query.range.from];
|
|
296
|
+
if (!position) {
|
|
297
|
+
bounds.push(`${source.time} <= ?`);
|
|
298
|
+
args.push(query.range.to);
|
|
299
|
+
}
|
|
300
|
+
else if (source.name === position.source) {
|
|
301
|
+
// The cursor is validated inside the fixed range. Replacing its redundant
|
|
302
|
+
// upper bound lets SQLite seek on both index columns, even on deep pages.
|
|
303
|
+
bounds.push(`(${source.time}, ${source.identity}) < (?, ?)`);
|
|
304
|
+
args.push(position.ts, position.identity);
|
|
305
|
+
}
|
|
306
|
+
else {
|
|
307
|
+
// Source names are ASCII and follow the existing SQLite BINARY ordering.
|
|
308
|
+
bounds.push(`${source.time} ${source.name < position.source ? '<=' : '<'} ?`);
|
|
309
|
+
args.push(position.ts);
|
|
310
|
+
}
|
|
311
|
+
if (source.name === 'canonical')
|
|
312
|
+
bounds.push('cost_basis IS NOT NULL');
|
|
313
|
+
const predicate = activityPredicate(query);
|
|
314
|
+
args.push(...predicate.args);
|
|
315
|
+
return {
|
|
316
|
+
sql: `SELECT * FROM (SELECT ${columns} FROM ${source.table} WHERE ${bounds.join(' AND ')})
|
|
317
|
+
${predicate.filters.length ? `WHERE ${predicate.filters.join(' AND ')}` : ''}`,
|
|
318
|
+
args,
|
|
319
|
+
};
|
|
320
|
+
}
|
|
258
321
|
function activityCount(db, query) {
|
|
259
|
-
const
|
|
322
|
+
const sources = SOURCES.map((source) => activitySourceQuery(source, query, source.filters));
|
|
260
323
|
return n(db
|
|
261
|
-
.prepare(`
|
|
262
|
-
|
|
263
|
-
.get(...args)?.count);
|
|
324
|
+
.prepare(`SELECT ${sources.map(({ sql }) => `(SELECT COUNT(*) FROM (${sql}))`).join(' + ')} AS count`)
|
|
325
|
+
.get(...sources.flatMap(({ args }) => args))?.count);
|
|
264
326
|
}
|
|
265
327
|
function activity(db, query, cursor) {
|
|
266
|
-
|
|
328
|
+
let position;
|
|
267
329
|
if (cursor) {
|
|
268
330
|
let value;
|
|
269
331
|
try {
|
|
@@ -290,14 +352,18 @@ function activity(db, query, cursor) {
|
|
|
290
352
|
if (!db.prepare(`SELECT 1 FROM ${table} WHERE ${key} = ? AND ${time} = ?`).get(value[3], value[1])) {
|
|
291
353
|
throw new TelemetryQueryValidationError('Invalid Usage cursor position');
|
|
292
354
|
}
|
|
293
|
-
|
|
294
|
-
args.push(value[1], value[2], value[3]);
|
|
355
|
+
position = { ts: value[1], source: value[2], identity: value[3] };
|
|
295
356
|
}
|
|
357
|
+
const sources = SOURCES.map((source) => activitySourceQuery(source, query, `${source.columns}, ${source.filters}`, position));
|
|
358
|
+
// A source's 52nd matching row cannot be in the global first 51. Each local
|
|
359
|
+
// ORDER BY matches its index; the final sort sees at most 3 * 51 candidates.
|
|
296
360
|
const rows = db
|
|
297
|
-
.prepare(`WITH
|
|
298
|
-
|
|
361
|
+
.prepare(`WITH candidates AS (${sources
|
|
362
|
+
.map(({ sql }) => `SELECT * FROM (${sql} ORDER BY ts DESC, identity DESC LIMIT 51)`)
|
|
363
|
+
.join(' UNION ALL ')})
|
|
364
|
+
SELECT * FROM candidates
|
|
299
365
|
ORDER BY ts DESC, source DESC, identity DESC LIMIT 51`)
|
|
300
|
-
.all(...args);
|
|
366
|
+
.all(...sources.flatMap(({ args }) => args));
|
|
301
367
|
const selected = rows.slice(0, 50);
|
|
302
368
|
const last = selected.at(-1);
|
|
303
369
|
// Resolve only this bounded page inside the same read transaction as its
|