maka-agent 0.2.0-dev.41.20260918 → 0.2.0-dev.43.20260919
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 +7 -4
- package/dist/acp/maka-acp-agent.js +17 -6
- package/dist/acp/session-event-mapper.js +6 -0
- package/dist/acp/session-interactions.js +520 -0
- package/dist/acp/session-registry.js +80 -9
- package/dist/acp/tool-event-mapper.js +60 -2
- package/dist/pi-tui-runner.js +57 -6
- package/native/runtime-host-windows-task-launcher/prebuilds/win32-x64/maka-runtime-host-task-launcher.exe +0 -0
- package/node_modules/@maka/core/dist/client-plugin-bridge.js +19 -0
- package/node_modules/@maka/core/dist/connection-usage.js +27 -0
- package/node_modules/@maka/core/dist/events.js +58 -7
- package/node_modules/@maka/core/dist/external-session.js +4 -3
- package/node_modules/@maka/core/dist/interaction.js +38 -4
- package/node_modules/@maka/core/dist/llm-connections.js +4 -0
- package/node_modules/@maka/core/dist/model-metadata.js +89 -0
- package/node_modules/@maka/core/dist/provider-auth.js +9 -1
- package/node_modules/@maka/core/dist/recall.js +198 -15
- package/node_modules/@maka/core/dist/redaction.js +8 -0
- package/node_modules/@maka/core/dist/session-reference.js +149 -0
- package/node_modules/@maka/core/dist/skill-locations.js +29 -0
- package/node_modules/@maka/core/package.json +4 -0
- package/node_modules/@maka/runtime/dist/commandcode-cli-language-model.js +27 -3
- package/node_modules/@maka/runtime/dist/connection-usage.js +232 -0
- package/node_modules/@maka/runtime/dist/model-factory.js +5 -3
- package/node_modules/@maka/runtime/dist/model-history.js +13 -2
- package/node_modules/@maka/runtime/dist/plugin-client-bridge-service.js +308 -0
- package/node_modules/@maka/runtime/dist/plugin-composition-loader.js +4 -3
- package/node_modules/@maka/runtime/dist/plugin-data-services.js +3 -3
- package/node_modules/@maka/runtime/dist/recall-tools.js +70 -2
- package/node_modules/@maka/runtime/dist/skills-discovery.js +17 -23
- package/node_modules/@maka/runtime/package.json +2 -0
- package/node_modules/@maka/runtime-host/dist/protocol/connection-effects.js +132 -1
- package/node_modules/@maka/runtime-host/dist/protocol/index.js +11 -1
- package/node_modules/@maka/runtime-host/dist/protocol/operations.js +6 -0
- package/node_modules/@maka/runtime-host/dist/protocol/plugin-platform.js +269 -0
- package/node_modules/@maka/runtime-host/dist/protocol/workhub-coordination.js +2 -0
- package/node_modules/@maka/runtime-host/dist/server/connection-effect-coordinator.js +57 -1
- package/node_modules/@maka/runtime-host/dist/server/execution-composition.js +50 -9
- package/node_modules/@maka/runtime-host/dist/server/extension-package-manifest.js +19 -1
- package/node_modules/@maka/runtime-host/dist/server/plugin-package-loader.js +88 -14
- package/node_modules/@maka/runtime-host/dist/server/plugin-package-store.js +22 -5
- package/node_modules/@maka/runtime-host/dist/server/plugin-platform-coordinator.js +122 -1
- package/node_modules/@maka/runtime-host/dist/server/plugin-platform.js +120 -1
- package/node_modules/@maka/runtime-host/dist/server/recall-material-fetch.js +92 -0
- package/node_modules/@maka/runtime-host/dist/server/root-turn-coordinator.js +14 -1
- package/node_modules/@maka/runtime-host/dist/server/session-catalog-coordinator.js +17 -1
- package/node_modules/@maka/runtime-host/dist/server/workhub-coordination-action-gate.js +67 -3
- package/node_modules/@maka/runtime-host/dist/server/workhub-coordination-coordinator.js +9 -3
- package/node_modules/@maka/runtime-host/dist/server/workhub-target-execution-authority.js +161 -0
- package/node_modules/@maka/storage/dist/codex-session-adapter.js +26 -28
- package/node_modules/@maka/storage/dist/runtime-policy/coordinator.js +34 -1
- package/node_modules/@maka/storage/dist/runtime-policy-stores.js +2 -0
- package/node_modules/@maka/storage/dist/session-store.js +5 -2
- package/package.json +1 -1
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
* under the License.
|
|
18
18
|
*/
|
|
19
19
|
import { CONNECTION_CATALOG_MAX_MODELS_PER_CONNECTION, decodeConnectionModelId, decodeConnectionModel, decodeConnectionName, decodeConnectionSlug, decodeProviderType, decodeConnectionTestSummary, decodeConnectionVersionBasis, RuntimePolicyDomainDecodeError, } from '@maka/core/runtime-policy';
|
|
20
|
-
import { requireCount, requireEntityId, requireExactRecord, requireRecord, requireShapedRecord, requireString, } from './codec.js';
|
|
20
|
+
import { requireCount, requireEntityId, requireExactRecord, requireRecord, requireShapedRecord, requireString, requireUtf8String, } from './codec.js';
|
|
21
21
|
import { invalidProtocolFrame } from './errors.js';
|
|
22
22
|
import { defineOperation } from './operation-spec.js';
|
|
23
23
|
const EFFECT_ERRORS = [
|
|
@@ -29,6 +29,13 @@ const EFFECT_ERRORS = [
|
|
|
29
29
|
'persistence_failed',
|
|
30
30
|
'commit_outcome_unknown',
|
|
31
31
|
];
|
|
32
|
+
/**
|
|
33
|
+
* Upper bound on the quota windows one usage report may carry. The producer
|
|
34
|
+
* emits three today (5-hour, weekly, monthly); the cap exists because a decoder
|
|
35
|
+
* is the boundary that does not trust its producer, matching how every other
|
|
36
|
+
* array in this package is bounded before mapping.
|
|
37
|
+
*/
|
|
38
|
+
const CONNECTION_USAGE_MAX_WINDOWS = 16;
|
|
32
39
|
export const CONNECTION_EFFECT_CHANGED_DOMAINS = [
|
|
33
40
|
'connection',
|
|
34
41
|
'credential',
|
|
@@ -77,6 +84,13 @@ export const CONNECTION_EFFECT_OPERATION_SPECS = {
|
|
|
77
84
|
decodeInput: decodeConnectionTestRunInput,
|
|
78
85
|
decodeOutput: decodeConnectionTestRunResult,
|
|
79
86
|
}),
|
|
87
|
+
'connection.usage.read': defineOperation({
|
|
88
|
+
mode: 'query',
|
|
89
|
+
availability: 'ready',
|
|
90
|
+
errors: EFFECT_ERRORS,
|
|
91
|
+
decodeInput: decodeConnectionUsageReadInput,
|
|
92
|
+
decodeOutput: decodeConnectionUsageReadResult,
|
|
93
|
+
}),
|
|
80
94
|
};
|
|
81
95
|
export function decodeConnectionOnboardingSaveInput(value) {
|
|
82
96
|
const input = requireExactRecord(value, 'connection onboarding save input', [
|
|
@@ -282,6 +296,123 @@ export function decodeConnectionTestRunResult(value) {
|
|
|
282
296
|
}
|
|
283
297
|
return decodeNonEffectResult(result, 'connection test result');
|
|
284
298
|
}
|
|
299
|
+
export function decodeConnectionUsageReadInput(value) {
|
|
300
|
+
const input = requireExactRecord(value, 'connection usage input', ['connectionId']);
|
|
301
|
+
return { connectionId: requireEntityId(input.connectionId, 'connectionId') };
|
|
302
|
+
}
|
|
303
|
+
export function decodeConnectionUsageReadResult(value) {
|
|
304
|
+
const result = requireRecord(value, 'connection usage result');
|
|
305
|
+
if (result.kind === 'report') {
|
|
306
|
+
const report = requireExactRecord(result, 'connection usage report', ['kind', 'report']);
|
|
307
|
+
return { kind: 'report', report: decodeUsageReport(report.report) };
|
|
308
|
+
}
|
|
309
|
+
if (result.kind === 'unavailable') {
|
|
310
|
+
const unavailable = requireExactRecord(result, 'connection usage unavailable', [
|
|
311
|
+
'kind',
|
|
312
|
+
'reason',
|
|
313
|
+
]);
|
|
314
|
+
if (unavailable.reason !== 'unsupported' &&
|
|
315
|
+
unavailable.reason !== 'network' &&
|
|
316
|
+
unavailable.reason !== 'no-credential' &&
|
|
317
|
+
unavailable.reason !== 'unauthorized') {
|
|
318
|
+
throw invalidProtocolFrame('Invalid connection usage unavailable reason');
|
|
319
|
+
}
|
|
320
|
+
return { kind: 'unavailable', reason: unavailable.reason };
|
|
321
|
+
}
|
|
322
|
+
if (result.kind === 'rejected') {
|
|
323
|
+
const rejected = requireExactRecord(result, 'connection usage result', ['kind', 'reason']);
|
|
324
|
+
return { kind: 'rejected', reason: rejectionReason(rejected.reason) };
|
|
325
|
+
}
|
|
326
|
+
throw invalidProtocolFrame('Invalid connection usage result');
|
|
327
|
+
}
|
|
328
|
+
function decodeUsageReport(value) {
|
|
329
|
+
const report = requireExactRecord(value, 'connection usage report body', [
|
|
330
|
+
'accountLabel',
|
|
331
|
+
'planLabel',
|
|
332
|
+
'stats',
|
|
333
|
+
'windows',
|
|
334
|
+
'periodEnd',
|
|
335
|
+
'partiallyUnauthorized',
|
|
336
|
+
'fetchedAt',
|
|
337
|
+
]);
|
|
338
|
+
if (!Array.isArray(report.windows) || report.windows.length > CONNECTION_USAGE_MAX_WINDOWS) {
|
|
339
|
+
throw invalidProtocolFrame('Invalid connection usage windows');
|
|
340
|
+
}
|
|
341
|
+
return {
|
|
342
|
+
accountLabel: optionalText(report.accountLabel, 'account label'),
|
|
343
|
+
planLabel: optionalText(report.planLabel, 'plan label'),
|
|
344
|
+
stats: report.stats === null ? null : decodeUsageStats(report.stats),
|
|
345
|
+
windows: report.windows.map(decodeUsageWindow),
|
|
346
|
+
periodEnd: optionalMillis(report.periodEnd, 'period end'),
|
|
347
|
+
partiallyUnauthorized: requireBoolean(report.partiallyUnauthorized, 'partially unauthorized'),
|
|
348
|
+
fetchedAt: requireCount(report.fetchedAt, 'usage fetchedAt'),
|
|
349
|
+
};
|
|
350
|
+
}
|
|
351
|
+
function decodeUsageStats(value) {
|
|
352
|
+
const stats = requireExactRecord(value, 'connection usage stats', [
|
|
353
|
+
'requests',
|
|
354
|
+
'failed',
|
|
355
|
+
'successRate',
|
|
356
|
+
'cost',
|
|
357
|
+
'tokensIn',
|
|
358
|
+
'tokensOut',
|
|
359
|
+
]);
|
|
360
|
+
return {
|
|
361
|
+
requests: optionalCount(stats.requests, 'requests'),
|
|
362
|
+
failed: optionalCount(stats.failed, 'failed'),
|
|
363
|
+
successRate: optionalAmount(stats.successRate, 'success rate'),
|
|
364
|
+
cost: optionalAmount(stats.cost, 'cost'),
|
|
365
|
+
tokensIn: optionalCount(stats.tokensIn, 'tokens in'),
|
|
366
|
+
tokensOut: optionalCount(stats.tokensOut, 'tokens out'),
|
|
367
|
+
};
|
|
368
|
+
}
|
|
369
|
+
function decodeUsageWindow(value) {
|
|
370
|
+
const window = requireExactRecord(value, 'connection usage window', [
|
|
371
|
+
'id',
|
|
372
|
+
'label',
|
|
373
|
+
'used',
|
|
374
|
+
'cap',
|
|
375
|
+
'unit',
|
|
376
|
+
'resetsAt',
|
|
377
|
+
'unlimited',
|
|
378
|
+
]);
|
|
379
|
+
const unit = window.unit;
|
|
380
|
+
if (unit !== 'credits' && unit !== 'usd' && unit !== 'tokens') {
|
|
381
|
+
throw invalidProtocolFrame('Invalid connection usage unit');
|
|
382
|
+
}
|
|
383
|
+
return {
|
|
384
|
+
id: requireUtf8String(window.id, 'usage window id', 64),
|
|
385
|
+
label: optionalText(window.label, 'usage window label'),
|
|
386
|
+
used: requireAmount(window.used, 'usage window used'),
|
|
387
|
+
cap: requireAmount(window.cap, 'usage window cap'),
|
|
388
|
+
unit,
|
|
389
|
+
resetsAt: optionalMillis(window.resetsAt, 'usage window reset'),
|
|
390
|
+
unlimited: window.unlimited === null ? null : requireBoolean(window.unlimited, 'unlimited'),
|
|
391
|
+
};
|
|
392
|
+
}
|
|
393
|
+
function optionalText(value, label) {
|
|
394
|
+
return value === null ? null : requireUtf8String(value, label, 256);
|
|
395
|
+
}
|
|
396
|
+
function optionalCount(value, label) {
|
|
397
|
+
return value === null ? null : requireCount(value, label);
|
|
398
|
+
}
|
|
399
|
+
function requireAmount(value, label) {
|
|
400
|
+
if (typeof value !== 'number' || !Number.isFinite(value) || value < 0) {
|
|
401
|
+
throw invalidProtocolFrame(`Invalid ${label}`);
|
|
402
|
+
}
|
|
403
|
+
return value;
|
|
404
|
+
}
|
|
405
|
+
function optionalAmount(value, label) {
|
|
406
|
+
return value === null ? null : requireAmount(value, label);
|
|
407
|
+
}
|
|
408
|
+
function optionalMillis(value, label) {
|
|
409
|
+
return value === null ? null : requireCount(value, label);
|
|
410
|
+
}
|
|
411
|
+
function requireBoolean(value, label) {
|
|
412
|
+
if (typeof value !== 'boolean')
|
|
413
|
+
throw invalidProtocolFrame(`Invalid ${label}`);
|
|
414
|
+
return value;
|
|
415
|
+
}
|
|
285
416
|
function decodeConnectionTestProjection(value) {
|
|
286
417
|
const projection = requireRecord(value, 'connection test projection');
|
|
287
418
|
if (projection.kind === 'verified') {
|
|
@@ -62,7 +62,17 @@ export const RUNTIME_HOST_REGISTRATION_SCHEMA_VERSION = 1;
|
|
|
62
62
|
export const RUNTIME_HOST_PROTOCOL_VERSION = 0;
|
|
63
63
|
// Increment when the same protocol version no longer guarantees safe Client-Host
|
|
64
64
|
// interoperability. Mismatches are rejected before domain commands are admitted.
|
|
65
|
-
export const RUNTIME_HOST_COMPATIBILITY_EPOCH =
|
|
65
|
+
export const RUNTIME_HOST_COMPATIBILITY_EPOCH = 166;
|
|
66
|
+
// 166: Connection usage reads add an operation, an accepted availability reason
|
|
67
|
+
// (`unauthorized`), a report field (`partiallyUnauthorized`), and a bounded
|
|
68
|
+
// window list. Peers older than this epoch take the added operation for an
|
|
69
|
+
// unknown key and reject the new reason and field.
|
|
70
|
+
// 165: WorkHub coordination resolve adds a model_required error code. Older
|
|
71
|
+
// peers reject the new operation outcome rather than misdiagnosing prose.
|
|
72
|
+
// 164: Client Plugin bundles, desktop-ui composition, generation-fenced Host
|
|
73
|
+
// Remote calls, and pull streams are projected through strict Host contracts.
|
|
74
|
+
// 163: Session reference quotes carry strict capture and truncation provenance.
|
|
75
|
+
// Epoch-162 peers reject the added QuoteRef fields.
|
|
66
76
|
// 162: Runtime Resource control and stop replies drop the unused resource
|
|
67
77
|
// snapshot; start replies allow compact state. Older peers require snapshots.
|
|
68
78
|
// 161: Session transcript reads return the whole transcript under a byte budget,
|
|
@@ -131,6 +131,7 @@ export const REMOTE_OWNER_OPERATION_GRANTS = Object.freeze([
|
|
|
131
131
|
'connection.request-headers.query',
|
|
132
132
|
'connection.request-headers.replace',
|
|
133
133
|
'connection.test.run',
|
|
134
|
+
'connection.usage.read',
|
|
134
135
|
'context.compact',
|
|
135
136
|
'context.diagnostics.query',
|
|
136
137
|
'credential.vault.delete',
|
|
@@ -161,6 +162,11 @@ export const REMOTE_OWNER_OPERATION_GRANTS = Object.freeze([
|
|
|
161
162
|
'plan.control',
|
|
162
163
|
'plan.query',
|
|
163
164
|
'plan.turn.start',
|
|
165
|
+
'plugin.client.query',
|
|
166
|
+
'plugin.client.remote.call',
|
|
167
|
+
'plugin.client.remote.stream.close',
|
|
168
|
+
'plugin.client.remote.stream.next',
|
|
169
|
+
'plugin.client.remote.stream.open',
|
|
164
170
|
'pricing.mutate',
|
|
165
171
|
'pricing.query',
|
|
166
172
|
'project.catalog.mutate',
|
|
@@ -35,9 +35,56 @@ const MUTATE_ERRORS = [
|
|
|
35
35
|
'operation_conflict',
|
|
36
36
|
'commit_outcome_unknown',
|
|
37
37
|
];
|
|
38
|
+
const CLIENT_REMOTE_ERRORS = [
|
|
39
|
+
'host_not_ready',
|
|
40
|
+
'host_draining',
|
|
41
|
+
'operation_unavailable',
|
|
42
|
+
'invalid_request',
|
|
43
|
+
'not_found',
|
|
44
|
+
'operation_conflict',
|
|
45
|
+
'internal_failure',
|
|
46
|
+
];
|
|
38
47
|
const MAX_FRAME_BYTES = 512 * 1024;
|
|
39
48
|
export const PLUGIN_PLATFORM_QUERY_RESULT_MAX_BYTES = 480 * 1024;
|
|
49
|
+
export const PLUGIN_CLIENT_BUNDLE_CHUNK_MAX_BYTES = 192 * 1024;
|
|
50
|
+
export const PLUGIN_CLIENT_BUNDLE_MAX_BYTES = 8 * 1024 * 1024;
|
|
51
|
+
export const PLUGIN_CLIENT_REMOTE_VALUE_MAX_BYTES = 256 * 1024;
|
|
40
52
|
export const PLUGIN_PLATFORM_OPERATION_SPECS = {
|
|
53
|
+
'plugin.client.query': defineOperation({
|
|
54
|
+
mode: 'query',
|
|
55
|
+
availability: 'ready',
|
|
56
|
+
errors: [...QUERY_ERRORS, 'not_found'],
|
|
57
|
+
decodeInput: decodePluginClientQueryInput,
|
|
58
|
+
decodeOutput: decodePluginClientQueryResult,
|
|
59
|
+
}),
|
|
60
|
+
'plugin.client.remote.call': defineOperation({
|
|
61
|
+
mode: 'control',
|
|
62
|
+
availability: 'ready',
|
|
63
|
+
errors: CLIENT_REMOTE_ERRORS,
|
|
64
|
+
decodeInput: decodePluginClientRemoteCallInput,
|
|
65
|
+
decodeOutput: decodePluginClientRemoteCallResult,
|
|
66
|
+
}),
|
|
67
|
+
'plugin.client.remote.stream.open': defineOperation({
|
|
68
|
+
mode: 'control',
|
|
69
|
+
availability: 'ready',
|
|
70
|
+
errors: CLIENT_REMOTE_ERRORS,
|
|
71
|
+
decodeInput: decodePluginClientRemoteCallInput,
|
|
72
|
+
decodeOutput: decodePluginClientRemoteStreamOpenResult,
|
|
73
|
+
}),
|
|
74
|
+
'plugin.client.remote.stream.next': defineOperation({
|
|
75
|
+
mode: 'control',
|
|
76
|
+
availability: 'ready',
|
|
77
|
+
errors: CLIENT_REMOTE_ERRORS,
|
|
78
|
+
decodeInput: decodePluginClientRemoteStreamCursorInput,
|
|
79
|
+
decodeOutput: decodePluginClientRemoteStreamNextResult,
|
|
80
|
+
}),
|
|
81
|
+
'plugin.client.remote.stream.close': defineOperation({
|
|
82
|
+
mode: 'control',
|
|
83
|
+
availability: 'ready',
|
|
84
|
+
errors: CLIENT_REMOTE_ERRORS,
|
|
85
|
+
decodeInput: decodePluginClientRemoteStreamCursorInput,
|
|
86
|
+
decodeOutput: decodePluginClientRemoteStreamCloseResult,
|
|
87
|
+
}),
|
|
41
88
|
'plugin.platform.query': defineOperation({
|
|
42
89
|
mode: 'query',
|
|
43
90
|
availability: 'ready',
|
|
@@ -106,6 +153,195 @@ export const PLUGIN_PLATFORM_OPERATION_SPECS = {
|
|
|
106
153
|
decodeOutput: decodePluginMutationReceipt,
|
|
107
154
|
}),
|
|
108
155
|
};
|
|
156
|
+
function decodePluginClientRemoteCallInput(value) {
|
|
157
|
+
const input = requireShapedRecord(value, 'Plugin Client Remote call input', [
|
|
158
|
+
'authorityEpoch',
|
|
159
|
+
'revision',
|
|
160
|
+
'entryId',
|
|
161
|
+
'extensionId',
|
|
162
|
+
'generation',
|
|
163
|
+
'contentDigest',
|
|
164
|
+
'clientDigest',
|
|
165
|
+
'method',
|
|
166
|
+
'input',
|
|
167
|
+
], ['sessionId']);
|
|
168
|
+
const remoteInput = requireJsonValue(input.input, 'Plugin Client Remote input');
|
|
169
|
+
requireEncodedByteLimit(remoteInput, 'Plugin Client Remote input', PLUGIN_CLIENT_REMOTE_VALUE_MAX_BYTES);
|
|
170
|
+
const decoded = {
|
|
171
|
+
authorityEpoch: requireCount(input.authorityEpoch, 'Plugin authority epoch'),
|
|
172
|
+
revision: requireDigest(input.revision, 'Plugin Client composition revision'),
|
|
173
|
+
entryId: requireId(input.entryId, 'Plugin Client Entry identity'),
|
|
174
|
+
extensionId: requireId(input.extensionId, 'Plugin package identity'),
|
|
175
|
+
generation: requireCount(input.generation, 'Plugin Client generation'),
|
|
176
|
+
contentDigest: requireDigest(input.contentDigest, 'Plugin package content digest'),
|
|
177
|
+
clientDigest: requireDigest(input.clientDigest, 'Plugin Client bundle digest'),
|
|
178
|
+
method: requireRemoteMethod(input.method),
|
|
179
|
+
input: remoteInput,
|
|
180
|
+
...(input.sessionId === undefined
|
|
181
|
+
? {}
|
|
182
|
+
: { sessionId: requireId(input.sessionId, 'Plugin Client Remote Session identity') }),
|
|
183
|
+
};
|
|
184
|
+
requireEncodedByteLimit(decoded, 'Plugin Client Remote call input', MAX_FRAME_BYTES);
|
|
185
|
+
return decoded;
|
|
186
|
+
}
|
|
187
|
+
function decodePluginClientRemoteCallResult(value) {
|
|
188
|
+
const result = requireExactRecord(value, 'Plugin Client Remote call result', ['value']);
|
|
189
|
+
const decoded = { value: requireJsonValue(result.value, 'Plugin Client Remote result') };
|
|
190
|
+
requireEncodedByteLimit(decoded, 'Plugin Client Remote call result', PLUGIN_CLIENT_REMOTE_VALUE_MAX_BYTES);
|
|
191
|
+
return decoded;
|
|
192
|
+
}
|
|
193
|
+
function decodePluginClientRemoteStreamOpenResult(value) {
|
|
194
|
+
const result = requireExactRecord(value, 'Plugin Client Remote stream open result', ['streamId']);
|
|
195
|
+
return { streamId: requireId(result.streamId, 'Plugin Client Remote stream identity') };
|
|
196
|
+
}
|
|
197
|
+
function decodePluginClientRemoteStreamCursorInput(value) {
|
|
198
|
+
const input = requireExactRecord(value, 'Plugin Client Remote stream input', ['streamId']);
|
|
199
|
+
return { streamId: requireId(input.streamId, 'Plugin Client Remote stream identity') };
|
|
200
|
+
}
|
|
201
|
+
function decodePluginClientRemoteStreamNextResult(value) {
|
|
202
|
+
const result = requireRecord(value, 'Plugin Client Remote stream next result');
|
|
203
|
+
if (result.done === true) {
|
|
204
|
+
requireExactRecord(result, 'Plugin Client Remote completed stream result', ['done']);
|
|
205
|
+
return { done: true };
|
|
206
|
+
}
|
|
207
|
+
const item = requireExactRecord(result, 'Plugin Client Remote stream item result', [
|
|
208
|
+
'done',
|
|
209
|
+
'value',
|
|
210
|
+
]);
|
|
211
|
+
if (item.done !== false)
|
|
212
|
+
throw invalidProtocolFrame('Invalid Plugin Client Remote stream state');
|
|
213
|
+
const decoded = {
|
|
214
|
+
done: false,
|
|
215
|
+
value: requireJsonValue(item.value, 'Plugin Client Remote stream item'),
|
|
216
|
+
};
|
|
217
|
+
requireEncodedByteLimit(decoded, 'Plugin Client Remote stream item', PLUGIN_CLIENT_REMOTE_VALUE_MAX_BYTES);
|
|
218
|
+
return decoded;
|
|
219
|
+
}
|
|
220
|
+
function decodePluginClientRemoteStreamCloseResult(value) {
|
|
221
|
+
const result = requireExactRecord(value, 'Plugin Client Remote stream close result', [
|
|
222
|
+
'streamId',
|
|
223
|
+
]);
|
|
224
|
+
return { streamId: requireId(result.streamId, 'Plugin Client Remote stream identity') };
|
|
225
|
+
}
|
|
226
|
+
function decodePluginClientQueryInput(value) {
|
|
227
|
+
const input = requireRecord(value, 'Plugin Client query input');
|
|
228
|
+
if (input.kind === 'snapshot') {
|
|
229
|
+
requireExactRecord(input, 'Plugin Client snapshot input', ['kind']);
|
|
230
|
+
return { kind: 'snapshot' };
|
|
231
|
+
}
|
|
232
|
+
if (input.kind === 'bundle') {
|
|
233
|
+
const bundle = requireExactRecord(input, 'Plugin Client bundle input', [
|
|
234
|
+
'kind',
|
|
235
|
+
'extensionId',
|
|
236
|
+
'contentDigest',
|
|
237
|
+
'clientDigest',
|
|
238
|
+
'offset',
|
|
239
|
+
]);
|
|
240
|
+
return {
|
|
241
|
+
kind: 'bundle',
|
|
242
|
+
extensionId: requireId(bundle.extensionId, 'Plugin package identity'),
|
|
243
|
+
contentDigest: requireDigest(bundle.contentDigest, 'Plugin package content digest'),
|
|
244
|
+
clientDigest: requireDigest(bundle.clientDigest, 'Plugin Client bundle digest'),
|
|
245
|
+
offset: requireCount(bundle.offset, 'Plugin Client bundle offset'),
|
|
246
|
+
};
|
|
247
|
+
}
|
|
248
|
+
throw invalidProtocolFrame('Invalid Plugin Client query kind');
|
|
249
|
+
}
|
|
250
|
+
function decodePluginClientQueryResult(value) {
|
|
251
|
+
const result = requireRecord(value, 'Plugin Client query result');
|
|
252
|
+
if (result.kind === 'snapshot') {
|
|
253
|
+
const snapshot = requireExactRecord(result, 'Plugin Client snapshot result', [
|
|
254
|
+
'kind',
|
|
255
|
+
'authorityEpoch',
|
|
256
|
+
'revision',
|
|
257
|
+
'entries',
|
|
258
|
+
'failures',
|
|
259
|
+
]);
|
|
260
|
+
if (!Array.isArray(snapshot.entries) || snapshot.entries.length > 1024) {
|
|
261
|
+
throw invalidProtocolFrame('Invalid Plugin Client composition entries');
|
|
262
|
+
}
|
|
263
|
+
if (!Array.isArray(snapshot.failures) || snapshot.failures.length > 1024) {
|
|
264
|
+
throw invalidProtocolFrame('Invalid Plugin Client failures');
|
|
265
|
+
}
|
|
266
|
+
const decoded = {
|
|
267
|
+
kind: 'snapshot',
|
|
268
|
+
authorityEpoch: requireCount(snapshot.authorityEpoch, 'Plugin authority epoch'),
|
|
269
|
+
revision: requireDigest(snapshot.revision, 'Plugin Client composition revision'),
|
|
270
|
+
entries: snapshot.entries.map(decodePluginClientCompositionEntry),
|
|
271
|
+
failures: snapshot.failures.map(decodePlatformFailure),
|
|
272
|
+
};
|
|
273
|
+
requireEncodedByteLimit(decoded, 'Plugin Client snapshot result', PLUGIN_PLATFORM_QUERY_RESULT_MAX_BYTES);
|
|
274
|
+
return decoded;
|
|
275
|
+
}
|
|
276
|
+
if (result.kind === 'bundle') {
|
|
277
|
+
const bundle = requireExactRecord(result, 'Plugin Client bundle result', [
|
|
278
|
+
'kind',
|
|
279
|
+
'extensionId',
|
|
280
|
+
'contentDigest',
|
|
281
|
+
'clientDigest',
|
|
282
|
+
'offset',
|
|
283
|
+
'totalBytes',
|
|
284
|
+
'content',
|
|
285
|
+
'nextOffset',
|
|
286
|
+
]);
|
|
287
|
+
const offset = requireCount(bundle.offset, 'Plugin Client bundle offset');
|
|
288
|
+
const totalBytes = requireCount(bundle.totalBytes, 'Plugin Client bundle size');
|
|
289
|
+
const content = requireString(bundle.content, 'Plugin Client bundle content', Math.ceil((PLUGIN_CLIENT_BUNDLE_CHUNK_MAX_BYTES * 4) / 3) + 4);
|
|
290
|
+
const decodedBytes = Buffer.from(content, 'base64');
|
|
291
|
+
if (decodedBytes.byteLength === 0 ||
|
|
292
|
+
decodedBytes.byteLength > PLUGIN_CLIENT_BUNDLE_CHUNK_MAX_BYTES ||
|
|
293
|
+
decodedBytes.toString('base64') !== content) {
|
|
294
|
+
throw invalidProtocolFrame('Invalid Plugin Client bundle content');
|
|
295
|
+
}
|
|
296
|
+
const nextOffset = bundle.nextOffset === null
|
|
297
|
+
? null
|
|
298
|
+
: requireCount(bundle.nextOffset, 'Plugin Client next bundle offset');
|
|
299
|
+
if (offset >= totalBytes ||
|
|
300
|
+
offset + decodedBytes.byteLength > totalBytes ||
|
|
301
|
+
(nextOffset === null
|
|
302
|
+
? offset + decodedBytes.byteLength !== totalBytes
|
|
303
|
+
: nextOffset !== offset + decodedBytes.byteLength || nextOffset >= totalBytes)) {
|
|
304
|
+
throw invalidProtocolFrame('Invalid Plugin Client bundle range');
|
|
305
|
+
}
|
|
306
|
+
return {
|
|
307
|
+
kind: 'bundle',
|
|
308
|
+
extensionId: requireId(bundle.extensionId, 'Plugin package identity'),
|
|
309
|
+
contentDigest: requireDigest(bundle.contentDigest, 'Plugin package content digest'),
|
|
310
|
+
clientDigest: requireDigest(bundle.clientDigest, 'Plugin Client bundle digest'),
|
|
311
|
+
offset,
|
|
312
|
+
totalBytes,
|
|
313
|
+
content,
|
|
314
|
+
nextOffset,
|
|
315
|
+
};
|
|
316
|
+
}
|
|
317
|
+
throw invalidProtocolFrame('Invalid Plugin Client query result kind');
|
|
318
|
+
}
|
|
319
|
+
function decodePluginClientCompositionEntry(value) {
|
|
320
|
+
const entry = requireShapedRecord(value, 'Plugin Client composition entry', [
|
|
321
|
+
'entryId',
|
|
322
|
+
'extensionId',
|
|
323
|
+
'generation',
|
|
324
|
+
'contentDigest',
|
|
325
|
+
'clientDigest',
|
|
326
|
+
'totalBytes',
|
|
327
|
+
'dependencies',
|
|
328
|
+
], ['config']);
|
|
329
|
+
if (!Array.isArray(entry.dependencies) || entry.dependencies.length > 64) {
|
|
330
|
+
throw invalidProtocolFrame('Invalid Plugin Client dependencies');
|
|
331
|
+
}
|
|
332
|
+
return {
|
|
333
|
+
entryId: requireId(entry.entryId, 'Plugin Client Entry identity'),
|
|
334
|
+
extensionId: requireId(entry.extensionId, 'Plugin package identity'),
|
|
335
|
+
generation: requireCount(entry.generation, 'Plugin Client generation'),
|
|
336
|
+
contentDigest: requireDigest(entry.contentDigest, 'Plugin package content digest'),
|
|
337
|
+
clientDigest: requireDigest(entry.clientDigest, 'Plugin Client bundle digest'),
|
|
338
|
+
totalBytes: requireCount(entry.totalBytes, 'Plugin Client bundle size'),
|
|
339
|
+
dependencies: entry.dependencies.map((dependency) => requireId(dependency, 'Plugin Client dependency identity')),
|
|
340
|
+
...(entry.config === undefined
|
|
341
|
+
? {}
|
|
342
|
+
: { config: decodeScalarRecord(entry.config, 'Client config') }),
|
|
343
|
+
};
|
|
344
|
+
}
|
|
109
345
|
function decodePluginPlatformQueryInput(value) {
|
|
110
346
|
const input = requireShapedRecord(value, 'Plugin Platform query input', ['view'], ['rootId', 'cursor', 'limit']);
|
|
111
347
|
if (!['status', 'packages', 'entries', 'tools', 'commands', 'executors', 'failures'].includes(input.view)) {
|
|
@@ -583,6 +819,39 @@ function decodeScalarRecord(value, label) {
|
|
|
583
819
|
}
|
|
584
820
|
return Object.fromEntries(output);
|
|
585
821
|
}
|
|
822
|
+
function requireRemoteMethod(value) {
|
|
823
|
+
const method = requireString(value, 'Plugin Client Remote method', 128);
|
|
824
|
+
if (!/^[a-z][a-z0-9]*(?:[._:/-][a-z0-9]+)*$/u.test(method)) {
|
|
825
|
+
throw invalidProtocolFrame('Invalid Plugin Client Remote method');
|
|
826
|
+
}
|
|
827
|
+
return method;
|
|
828
|
+
}
|
|
829
|
+
function requireJsonValue(value, label, depth = 0) {
|
|
830
|
+
if (depth > 32)
|
|
831
|
+
throw invalidProtocolFrame(`${label} is too deeply nested`);
|
|
832
|
+
if (value === null ||
|
|
833
|
+
typeof value === 'string' ||
|
|
834
|
+
typeof value === 'boolean' ||
|
|
835
|
+
(typeof value === 'number' && Number.isFinite(value))) {
|
|
836
|
+
return value;
|
|
837
|
+
}
|
|
838
|
+
if (Array.isArray(value)) {
|
|
839
|
+
if (value.length > 16_384)
|
|
840
|
+
throw invalidProtocolFrame(`${label} has too many items`);
|
|
841
|
+
return value.map((item) => requireJsonValue(item, label, depth + 1));
|
|
842
|
+
}
|
|
843
|
+
if (!value || typeof value !== 'object')
|
|
844
|
+
throw invalidProtocolFrame(`Invalid ${label}`);
|
|
845
|
+
const prototype = Object.getPrototypeOf(value);
|
|
846
|
+
if (prototype !== Object.prototype && prototype !== null) {
|
|
847
|
+
throw invalidProtocolFrame(`Invalid ${label}`);
|
|
848
|
+
}
|
|
849
|
+
const record = value;
|
|
850
|
+
if (Object.keys(record).length > 16_384) {
|
|
851
|
+
throw invalidProtocolFrame(`${label} has too many fields`);
|
|
852
|
+
}
|
|
853
|
+
return Object.fromEntries(Object.entries(record).map(([key, item]) => [key, requireJsonValue(item, label, depth + 1)]));
|
|
854
|
+
}
|
|
586
855
|
function requireBoolean(value) {
|
|
587
856
|
if (typeof value !== 'boolean')
|
|
588
857
|
throw invalidProtocolFrame('Invalid Plugin Entry disabled flag');
|
|
@@ -48,11 +48,13 @@ export const WORKHUB_COORDINATION_TEXT_MAX_BYTES = 48 * 1024;
|
|
|
48
48
|
const COORDINATION_TITLE_MAX_BYTES = 512;
|
|
49
49
|
const CANDIDATE_SET_ID_MAX_BYTES = 96;
|
|
50
50
|
export const WORKHUB_COORDINATION_CANDIDATE_MAX_ITEMS = 32;
|
|
51
|
+
export const WORKHUB_COORDINATION_DEFAULT_MODEL_REQUIRED_MESSAGE = 'WorkHub Coordination Session requires an available default model';
|
|
51
52
|
const RESOLVE_ERRORS = [
|
|
52
53
|
'host_not_ready',
|
|
53
54
|
'host_draining',
|
|
54
55
|
'operation_unavailable',
|
|
55
56
|
'operation_conflict',
|
|
57
|
+
'model_required',
|
|
56
58
|
'persistence_failed',
|
|
57
59
|
'commit_outcome_unknown',
|
|
58
60
|
'internal_failure',
|
|
@@ -17,12 +17,13 @@
|
|
|
17
17
|
* under the License.
|
|
18
18
|
*/
|
|
19
19
|
import { parseRequestHeaders } from '@maka/core/runtime-policy';
|
|
20
|
-
import { PROVIDER_REGISTRY, providerFallbackModelIds } from '@maka/core/llm-connections';
|
|
20
|
+
import { PROVIDER_REGISTRY, effectiveBaseUrl, providerFallbackModelIds, } from '@maka/core/llm-connections';
|
|
21
21
|
import { createConnectionEffectFetchTransport, } from '@maka/runtime/network/scoped-fetch-transport';
|
|
22
22
|
import { createRequestCustomizationFetch } from '@maka/runtime/request-customization-fetch';
|
|
23
23
|
import { isOAuthSubscriptionProvider, parseOAuthSubscriptionTokens, } from '@maka/runtime/subscription-credentials';
|
|
24
24
|
import { runConnectionModelDiscoveryEffect } from '@maka/runtime/model-fetcher';
|
|
25
25
|
import { runConnectionTestEffect } from '@maka/runtime/test-connection';
|
|
26
|
+
import { fetchConnectionUsage } from '@maka/runtime/connection-usage';
|
|
26
27
|
import { authenticateRuntimePolicyStoresWriter, RuntimePolicyStoreError, } from '@maka/storage/runtime-policy-stores';
|
|
27
28
|
import { toRuntimePolicyProxy } from './runtime-policy-proxy.js';
|
|
28
29
|
/** Runs provider I/O outside Storage lanes and conditionally commits canonical results. */
|
|
@@ -32,6 +33,7 @@ export class HostConnectionEffectCoordinator {
|
|
|
32
33
|
'connection.onboarding.verify': (input) => this.#verifyOnboarding(input),
|
|
33
34
|
'connection.models.fetch': (input) => this.#fetchModels(input),
|
|
34
35
|
'connection.test.run': (input) => this.#testConnection(input),
|
|
36
|
+
'connection.usage.read': (input) => this.#readConnectionUsage(input),
|
|
35
37
|
};
|
|
36
38
|
#stores;
|
|
37
39
|
#activation;
|
|
@@ -263,6 +265,32 @@ export class HostConnectionEffectCoordinator {
|
|
|
263
265
|
: projectSuperseded(completion);
|
|
264
266
|
});
|
|
265
267
|
}
|
|
268
|
+
/**
|
|
269
|
+
* Read-only: fetch the account's usage and project it. Nothing is committed,
|
|
270
|
+
* so no superseded branch exists — the ticket is spent and the report
|
|
271
|
+
* returned.
|
|
272
|
+
*/
|
|
273
|
+
#readConnectionUsage(input) {
|
|
274
|
+
return this.#admit(input.connectionId, 'connection.usage.read', async () => {
|
|
275
|
+
const prepared = await this.#stores.operations.beginConnectionUsage(input.connectionId);
|
|
276
|
+
if (prepared.kind !== 'ready')
|
|
277
|
+
return preparationResult(prepared);
|
|
278
|
+
try {
|
|
279
|
+
const result = await this.#withTransport(prepared, (fetch, secret) => fetchConnectionUsage({
|
|
280
|
+
providerType: prepared.connection.providerType,
|
|
281
|
+
apiKey: secret,
|
|
282
|
+
baseUrl: effectiveBaseUrl(prepared.connection),
|
|
283
|
+
fetch,
|
|
284
|
+
}));
|
|
285
|
+
return result.kind === 'report'
|
|
286
|
+
? { kind: 'report', report: projectUsageReport(result.report) }
|
|
287
|
+
: { kind: 'unavailable', reason: result.reason };
|
|
288
|
+
}
|
|
289
|
+
finally {
|
|
290
|
+
await this.#stores.operations.completeConnectionUsage(prepared.ticket);
|
|
291
|
+
}
|
|
292
|
+
});
|
|
293
|
+
}
|
|
266
294
|
#admit(connectionId, operation, run) {
|
|
267
295
|
if (!this.#accepting) {
|
|
268
296
|
return Promise.resolve({
|
|
@@ -351,6 +379,34 @@ function projectSuperseded(completion) {
|
|
|
351
379
|
changed: completion.changed.map((domain) => domain),
|
|
352
380
|
};
|
|
353
381
|
}
|
|
382
|
+
function projectUsageReport(report) {
|
|
383
|
+
return {
|
|
384
|
+
accountLabel: report.accountLabel ?? null,
|
|
385
|
+
planLabel: report.planLabel ?? null,
|
|
386
|
+
stats: report.stats
|
|
387
|
+
? {
|
|
388
|
+
requests: report.stats.requests ?? null,
|
|
389
|
+
failed: report.stats.failed ?? null,
|
|
390
|
+
successRate: report.stats.successRate ?? null,
|
|
391
|
+
cost: report.stats.cost ?? null,
|
|
392
|
+
tokensIn: report.stats.tokensIn ?? null,
|
|
393
|
+
tokensOut: report.stats.tokensOut ?? null,
|
|
394
|
+
}
|
|
395
|
+
: null,
|
|
396
|
+
windows: report.windows.map((window) => ({
|
|
397
|
+
id: window.id,
|
|
398
|
+
label: window.label ?? null,
|
|
399
|
+
used: window.used,
|
|
400
|
+
cap: window.cap,
|
|
401
|
+
unit: window.unit,
|
|
402
|
+
resetsAt: window.resetsAt ?? null,
|
|
403
|
+
unlimited: window.unlimited ?? null,
|
|
404
|
+
})),
|
|
405
|
+
periodEnd: report.periodEnd ?? null,
|
|
406
|
+
partiallyUnauthorized: report.partiallyUnauthorized === true,
|
|
407
|
+
fetchedAt: report.fetchedAt,
|
|
408
|
+
};
|
|
409
|
+
}
|
|
354
410
|
function projectConnectionTest(outcome, checkedAt) {
|
|
355
411
|
const checkedAtIso = new Date(checkedAt).toISOString();
|
|
356
412
|
if (outcome.ok) {
|