feat(coding): add model tools and device packages

This commit is contained in:
brother7 committed 2026-09-02 18:46:21 +08:00
1 parent 841273b433
commit 664b8823a0
60 files changed
+3847 -2068

No files matched your search

+38
View File
@@ -724,6 +724,44 @@ describe('Pi worker pool', () => {
expect(cancelled).not.toContain('other');
});
it('refreshes idle worker resources immediately and defers an active run until settlement', async () => {
const workers = new Map<string, FakeWorker[]>();
const pool = new PiWorkerPool({
maxIdle: 4,
openWorker: async ({ conversation: input, existingSession }) => {
const worker = new FakeWorker(
`worker-${input.conversationId}-${(workers.get(input.conversationId)?.length ?? 0) + 1}`,
);
workers.set(input.conversationId, [...(workers.get(input.conversationId) ?? []), worker]);
return {
worker,
session: existingSession ?? {
piSessionId: `session-${input.conversationId}`,
sessionKey: `key-${input.conversationId}`,
},
};
},
});
await Promise.all([
pool.prepare(conversation('conversation-running')),
pool.prepare(conversation('conversation-idle')),
]);
pool.startTopLevel({
conversationId: 'conversation-running',
runId: 'run-running',
command: { type: 'prompt', message: 'running' },
});
await expect.poll(() => workers.get('conversation-running')![0]!.requests.length).toBe(1);
await pool.refreshResources();
expect(workers.get('conversation-idle')).toHaveLength(2);
expect(workers.get('conversation-idle')![0]!.stopped).toBe(true);
expect(workers.get('conversation-running')).toHaveLength(1);
workers.get('conversation-running')![0]!.emit({ type: 'agent_settled' });
await expect.poll(() => workers.get('conversation-running')).toHaveLength(2);
});
it('rebuilds stale idle workers before prompt and lets running workers settle first', async () => {
const workers = new Map<string, FakeWorker[]>();
const revisions: Array<{ conversationId: string; provider: number; resources: number }> = [];