feat: add tool gateway protocol

This commit is contained in:
John
2026-07-02 09:23:55 +08:00
parent e24e6ca4a7
commit 21e03d86b5
8 changed files with 388 additions and 1 deletions
+53
View File
@@ -223,6 +223,59 @@ test('agent run with code tool mode starts and submits with code policy', async
assert.equal(submitted[0].userMessage.metadata.memindRun.toolMode, 'code');
});
test('agent run with enabled tool gateway dispatches code runs outside goose session', async () => {
const pool = createFakePool();
const jobs = [];
const gateway = createAgentRunGateway({
pool,
userAuth: {
async resolveWorkingDir(userId) {
assert.equal(userId, 'user-1');
return '/tmp/memind-user-1';
},
},
tkmindProxy: {
async startSessionForUser() {
assert.fail('goose session should not start for external tool gateway run');
},
async submitSessionReplyForUser() {
assert.fail('goose reply should not be submitted for external tool gateway run');
},
},
toolGateway: {
getStatus() {
return { enabled: true, protocol: 'agent-run-v1' };
},
async executeJob(job) {
jobs.push(job);
return { ok: true, dryRun: true, executor: 'aider' };
},
},
retryDelaysMs: [],
});
const run = await gateway.createRun('user-1', {
requestId: 'req-code-tool-gateway',
userMessage: { role: 'user', content: [{ type: 'text', text: 'run code task' }] },
toolMode: 'code',
taskType: 'small_patch',
});
await waitFor(() => pool.runs.get(run.id)?.status === 'succeeded');
assert.equal(jobs.length, 1);
assert.equal(jobs[0].cwd, '/tmp/memind-user-1');
assert.equal(jobs[0].taskType, 'small_patch');
assert.equal(pool.runs.get(run.id).agent_session_id, null);
assert.equal(
pool.events.some((event) => event.runId === run.id && event.eventType === 'tool_gateway_dispatch'),
true,
);
assert.equal(
pool.events.some((event) => event.runId === run.id && event.eventType === 'tool_gateway_result'),
true,
);
});
test('agent run retries transient failures and then becomes terminal', async () => {
const pool = createFakePool();
const gateway = createAgentRunGateway({