maka-agent 0.2.0-dev.41.20260918 → 0.2.0-dev.42.20260918
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/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/events.js +58 -7
- 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/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/package.json +2 -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/package.json +1 -0
- package/node_modules/@maka/runtime-host/dist/protocol/index.js +7 -1
- package/node_modules/@maka/runtime-host/dist/protocol/operations.js +5 -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/execution-composition.js +46 -6
- 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/package.json +1 -1
|
@@ -23,7 +23,8 @@ import { isDeepStrictEqual } from 'node:util';
|
|
|
23
23
|
import { normalizeMessageContent } from '@maka/core/events';
|
|
24
24
|
import { WORKHUB_COORDINATION_SESSION_ID, WORKHUB_COORDINATION_SESSION_ROLE, WORKHUB_COORDINATION_REPLACEMENT_SCHEMA_VERSION, WORKHUB_COORDINATION_STOP_SCHEMA_VERSION, isWorkHubCoordinationSession, isWorkHubCoordinationSessionId, } from '@maka/core/session';
|
|
25
25
|
import { WORKHUB_COORDINATION_TEXT_MAX_BYTES } from '../protocol/index.js';
|
|
26
|
-
import {
|
|
26
|
+
import { WORKHUB_COORDINATION_DEFAULT_MODEL_REQUIRED_MESSAGE, } from '../protocol/workhub-coordination.js';
|
|
27
|
+
import { SessionOperationFailure, WorkHubDefaultModelRequiredError, projectSessionCatalogRecord, } from './session-catalog-coordinator.js';
|
|
27
28
|
import { RuntimeInteractionAdmissionRejectedError, RuntimeInteractionFailStopError, } from '@maka/runtime/interaction-authority';
|
|
28
29
|
import { WorkHubActionEffectFailure, WorkHubActionGateFailure, WorkHubCoordinationActionGate, } from './workhub-coordination-action-gate.js';
|
|
29
30
|
const CREATE_FINGERPRINT = `sha256:${createHash('sha256')
|
|
@@ -82,6 +83,7 @@ export class HostWorkHubCoordinationCoordinator {
|
|
|
82
83
|
this.#requestDrain = options.requestDrain;
|
|
83
84
|
this.#actionGate = new WorkHubCoordinationActionGate({
|
|
84
85
|
listSessions: () => this.#stores.listHeaders(),
|
|
86
|
+
...(options.targetExecution ? { targetExecution: options.targetExecution } : {}),
|
|
85
87
|
// The global action owner is committed under the same Coordination
|
|
86
88
|
// admission that serializes every durable Coordination fact, so a
|
|
87
89
|
// concurrent action cannot slip between the claim and the fact it owns.
|
|
@@ -109,7 +111,7 @@ export class HostWorkHubCoordinationCoordinator {
|
|
|
109
111
|
resume: async (input, context) => ({
|
|
110
112
|
disposition: 'resume_work',
|
|
111
113
|
targetSessionId: input.source.targetSessionId,
|
|
112
|
-
...(await options.sessionActions.resumeDelegation(input.source, context, input.actionId, input.validateFreshTarget)),
|
|
114
|
+
...(await options.sessionActions.resumeDelegation(input.source, context, input.actionId, input.validateFreshTarget, input.prepareTargetExecution, input.assertTargetExecutionReady)),
|
|
113
115
|
}),
|
|
114
116
|
});
|
|
115
117
|
}
|
|
@@ -516,6 +518,7 @@ export class HostWorkHubCoordinationCoordinator {
|
|
|
516
518
|
result: await this.#actionGate.act({
|
|
517
519
|
...action,
|
|
518
520
|
...(selectedTarget ? { selectedTarget } : {}),
|
|
521
|
+
coordinationRunId: request.runId,
|
|
519
522
|
userText: request.content.text,
|
|
520
523
|
...(carriesAttachments && request.content.attachments
|
|
521
524
|
? { attachments: request.content.attachments }
|
|
@@ -806,10 +809,13 @@ export class HostWorkHubCoordinationCoordinator {
|
|
|
806
809
|
}
|
|
807
810
|
/** Keeps a model-authority gap distinguishable from a failed authority read. */
|
|
808
811
|
function createTargetFailure(error) {
|
|
812
|
+
if (error instanceof WorkHubDefaultModelRequiredError) {
|
|
813
|
+
return failure('model_required', WORKHUB_COORDINATION_DEFAULT_MODEL_REQUIRED_MESSAGE);
|
|
814
|
+
}
|
|
809
815
|
if (error instanceof SessionOperationFailure && error.code === 'persistence_failed') {
|
|
810
816
|
return failure('persistence_failed', error.message);
|
|
811
817
|
}
|
|
812
|
-
return failure('operation_conflict', 'WorkHub Coordination Session
|
|
818
|
+
return failure('operation_conflict', 'WorkHub Coordination Session target is unavailable');
|
|
813
819
|
}
|
|
814
820
|
function validCoordinationIdentityHeader(header) {
|
|
815
821
|
return (isWorkHubCoordinationSessionId(header.id) &&
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Licensed to the Apache Software Foundation (ASF) under one
|
|
3
|
+
* or more contributor license agreements. See the NOTICE file
|
|
4
|
+
* distributed with this work for additional information
|
|
5
|
+
* regarding copyright ownership. The ASF licenses this file
|
|
6
|
+
* to you under the Apache License, Version 2.0 (the
|
|
7
|
+
* "License"); you may not use this file except in compliance
|
|
8
|
+
* with the License. You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing,
|
|
13
|
+
* software distributed under the License is distributed on an
|
|
14
|
+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
15
|
+
* KIND, either express or implied. See the License for the
|
|
16
|
+
* specific language governing permissions and limitations
|
|
17
|
+
* under the License.
|
|
18
|
+
*/
|
|
19
|
+
import { createHash } from 'node:crypto';
|
|
20
|
+
import { authorizeConnectionModel, connectionModelChoiceValue, connectionEnabledModelIds, } from '@maka/core/llm-connections';
|
|
21
|
+
import { isModelExplicitlyUnsupportedForChat } from '@maka/core/model-catalog';
|
|
22
|
+
import { thinkingVariantsForConnection } from '@maka/core/model-thinking';
|
|
23
|
+
import { WORKHUB_COORDINATION_SESSION_ID } from '@maka/core/session';
|
|
24
|
+
import { WorkHubActionEffectFailure } from './workhub-coordination-action-gate.js';
|
|
25
|
+
/** Keeps target-model repair behind one Host-owned interface used by every WorkHub execution path. */
|
|
26
|
+
export class HostWorkHubTargetExecutionAuthority {
|
|
27
|
+
#options;
|
|
28
|
+
constructor(options) {
|
|
29
|
+
this.#options = options;
|
|
30
|
+
}
|
|
31
|
+
async prepare(input, context) {
|
|
32
|
+
const rejectedSelections = [];
|
|
33
|
+
for (let attempt = 0; attempt < 3; attempt++) {
|
|
34
|
+
const readiness = await this.#readiness(input.targetSessionId);
|
|
35
|
+
if (readiness.kind === 'ready')
|
|
36
|
+
return;
|
|
37
|
+
if (readiness.replacements.length === 0) {
|
|
38
|
+
throw new WorkHubActionEffectFailure('operation_unavailable', `Task “${input.targetSessionName}” has no enabled replacement model`);
|
|
39
|
+
}
|
|
40
|
+
const requestId = createHash('sha256')
|
|
41
|
+
.update(JSON.stringify({
|
|
42
|
+
kind: 'workhub_target_model_repair_v1',
|
|
43
|
+
actionId: input.actionId,
|
|
44
|
+
coordinationRunId: input.coordinationRunId,
|
|
45
|
+
targetSessionId: input.targetSessionId,
|
|
46
|
+
revision: readiness.record.revision,
|
|
47
|
+
replacements: readiness.replacements.map(({ value }) => value),
|
|
48
|
+
rejectedSelections,
|
|
49
|
+
}))
|
|
50
|
+
.digest('hex');
|
|
51
|
+
const choice = await this.#options.requestForm({
|
|
52
|
+
sessionId: WORKHUB_COORDINATION_SESSION_ID,
|
|
53
|
+
turnId: input.coordinationTurnId,
|
|
54
|
+
runId: input.coordinationRunId,
|
|
55
|
+
requestId,
|
|
56
|
+
create: async () => ({
|
|
57
|
+
kind: 'form',
|
|
58
|
+
toolUseId: input.actionId,
|
|
59
|
+
message: rejectedSelections.length === 0
|
|
60
|
+
? `Task “${input.targetSessionName}” uses model “${readiness.record.header.model}”, which is no longer available. Choose a replacement to continue.`
|
|
61
|
+
: `The selected model cannot currently run task “${input.targetSessionName}”. Choose another model to continue.`,
|
|
62
|
+
requester: { name: 'WorkHub' },
|
|
63
|
+
fields: [
|
|
64
|
+
{
|
|
65
|
+
kind: 'string',
|
|
66
|
+
name: 'targetModel',
|
|
67
|
+
label: `Model for ${input.targetSessionName}`,
|
|
68
|
+
required: true,
|
|
69
|
+
presentation: 'model_picker',
|
|
70
|
+
minLength: 1,
|
|
71
|
+
},
|
|
72
|
+
],
|
|
73
|
+
}),
|
|
74
|
+
});
|
|
75
|
+
if (choice.answer.action !== 'accept') {
|
|
76
|
+
throw new WorkHubActionEffectFailure('operation_conflict', `Model update for task “${input.targetSessionName}” was cancelled`);
|
|
77
|
+
}
|
|
78
|
+
const value = choice.answer.values.targetModel;
|
|
79
|
+
const replacement = readiness.replacements.find(({ value: offered }) => offered === value);
|
|
80
|
+
if (!replacement) {
|
|
81
|
+
if (typeof value === 'string')
|
|
82
|
+
rejectedSelections.push(value);
|
|
83
|
+
continue;
|
|
84
|
+
}
|
|
85
|
+
const updated = await this.#options.updateModel({
|
|
86
|
+
sessionId: input.targetSessionId,
|
|
87
|
+
expectedRevision: readiness.record.revision,
|
|
88
|
+
modelTarget: replacement.target,
|
|
89
|
+
}, context);
|
|
90
|
+
if (updated === 'committed') {
|
|
91
|
+
if ((await this.#readiness(input.targetSessionId)).kind === 'ready')
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
throw new WorkHubActionEffectFailure('operation_conflict', rejectedSelections.length > 0
|
|
96
|
+
? 'No executable replacement model was selected for this task'
|
|
97
|
+
: 'Task model changed while WorkHub was preparing the delegation; try again');
|
|
98
|
+
}
|
|
99
|
+
async assertReady(targetSessionId) {
|
|
100
|
+
const readiness = await this.#readiness(targetSessionId);
|
|
101
|
+
if (readiness.kind !== 'ready') {
|
|
102
|
+
throw new WorkHubActionEffectFailure('operation_conflict', 'Target task model is no longer enabled; choose a replacement and try again');
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
async #readiness(targetSessionId) {
|
|
106
|
+
const record = await this.#options.readSession(targetSessionId);
|
|
107
|
+
const header = record.header;
|
|
108
|
+
if (header.backend === 'plugin-executor')
|
|
109
|
+
return { kind: 'ready' };
|
|
110
|
+
const resolved = await this.#options.runtimePolicy.resolveExecutionConnection(header.llmConnectionId === undefined
|
|
111
|
+
? { kind: 'catalog_slug', connectionSlug: header.llmConnectionSlug }
|
|
112
|
+
: {
|
|
113
|
+
kind: 'bound',
|
|
114
|
+
connectionId: header.llmConnectionId,
|
|
115
|
+
connectionSlug: header.llmConnectionSlug,
|
|
116
|
+
});
|
|
117
|
+
if (resolved.kind === 'ready') {
|
|
118
|
+
const current = authorizeConnectionModel(resolved.connection, header.model);
|
|
119
|
+
if (current && !isModelExplicitlyUnsupportedForChat(current))
|
|
120
|
+
return { kind: 'ready' };
|
|
121
|
+
}
|
|
122
|
+
const catalog = await this.#options.runtimePolicy.connectionCatalog.getSnapshot();
|
|
123
|
+
const resolvedConnections = await Promise.all(catalog.connections.map((connection) => this.#options.runtimePolicy.resolveExecutionConnection({
|
|
124
|
+
kind: 'bound',
|
|
125
|
+
connectionId: connection.connectionId,
|
|
126
|
+
connectionSlug: connection.slug,
|
|
127
|
+
})));
|
|
128
|
+
const replacements = resolvedConnections
|
|
129
|
+
.flatMap((candidate) => {
|
|
130
|
+
if (candidate.kind !== 'ready')
|
|
131
|
+
return [];
|
|
132
|
+
const connection = candidate.connection;
|
|
133
|
+
return connectionEnabledModelIds(connection).flatMap((modelId) => {
|
|
134
|
+
const model = authorizeConnectionModel(connection, modelId);
|
|
135
|
+
if (!model || isModelExplicitlyUnsupportedForChat(model))
|
|
136
|
+
return [];
|
|
137
|
+
if (header.thinkingLevel !== undefined &&
|
|
138
|
+
!thinkingVariantsForConnection({
|
|
139
|
+
providerType: connection.providerType,
|
|
140
|
+
modelOverrides: connection.modelOverrides,
|
|
141
|
+
}, modelId).includes(header.thinkingLevel)) {
|
|
142
|
+
return [];
|
|
143
|
+
}
|
|
144
|
+
const target = {
|
|
145
|
+
kind: 'explicit',
|
|
146
|
+
connectionId: connection.connectionId,
|
|
147
|
+
connectionSlug: connection.slug,
|
|
148
|
+
model: modelId,
|
|
149
|
+
};
|
|
150
|
+
return [
|
|
151
|
+
{
|
|
152
|
+
value: connectionModelChoiceValue(target.connectionId, target.connectionSlug, target.model),
|
|
153
|
+
target,
|
|
154
|
+
},
|
|
155
|
+
];
|
|
156
|
+
});
|
|
157
|
+
})
|
|
158
|
+
.sort((left, right) => left.value.localeCompare(right.value));
|
|
159
|
+
return { kind: 'model_repair_required', record, replacements };
|
|
160
|
+
}
|
|
161
|
+
}
|