Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 2 additions & 13 deletions apps/server/src/app.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

import { existsSync, unlinkSync } from 'node:fs';
import { unlinkSync } from 'node:fs';
import { tmpdir } from 'node:os';
import { join } from 'node:path';

Expand All @@ -25,13 +25,10 @@ import {
externalAgentRuntimeConfigRoutes,
getExternalAgentRuntimeConfig,
getAgentProfileRegistry,
getSupervisedAgentletId,
installAcpProfileCachePort,
mountAgenetes,
resolveDaemonEntry,
} from './modules/agent/acp/index.js';
import { buildLegacyCommandProfiles } from './modules/agent/acp/legacy-profile-migration.js';
import { listProfiles as listLegacyAcpProfiles } from './modules/agent/acp/profile-store.js';
import { initializeAgentDefaults } from './modules/agent/agent-defaults.js';
import agentDefaultsRoutes from './modules/agent/agent-defaults.route.js';
import agentRoutes from './modules/agent/agent.route.js';
Expand Down Expand Up @@ -317,15 +314,7 @@ const agentletGateway = mountAgenetes(app, {
profiles: {
storageDir: join(getDataDir(), 'agent-profiles'),
legacyStorageDir: join(getDataDir(), 'agent-team'),
legacyCommandProfiles: existsSync(
join(getDataDir(), 'agent-profiles', 'registry.json'),
)
? []
: buildLegacyCommandProfiles(
listLegacyAcpProfiles(),
getSupervisedAgentletId(),
process.cwd(),
),
legacyCommandProfiles: [],
},
});
let unregisterHarnessDiscovery: (() => void) | undefined;
Expand Down
16 changes: 10 additions & 6 deletions apps/server/src/modules/agent/acp/agent-cli.route.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ import type { FastifyInstance } from 'fastify';
const mocks = vi.hoisted(() => ({ getProfile: vi.fn(), discover: vi.fn() }));
vi.mock('@agenetes/agentlet-host', () => ({
getAgentProfileRegistry: () => ({ getProfile: mocks.getProfile }),
getSupervisedAgentletId: () => 'supervised',
getAgentletGateway: () => ({ discoverHarnesses: mocks.discover }),
getAgentletGateway: () => ({
getAgentlet: () => ({ status: 'connected' }),
discoverHarnesses: mocks.discover,
}),
}));

let app: FastifyInstance | undefined;
Expand Down Expand Up @@ -52,7 +54,7 @@ describe('ACP agent CLI route', () => {

const response = await app.inject({
method: 'GET',
url: '/api/acp/agent-cli',
url: '/api/acp/agent-cli?agentletId=machine-a',
});

expect(response.statusCode).toBe(200);
Expand All @@ -72,7 +74,7 @@ describe('ACP agent CLI route', () => {

const response = await app.inject({
method: 'GET',
url: '/api/acp/agent-cli',
url: '/api/acp/agent-cli?agentletId=machine-a',
remoteAddress: '192.0.2.10',
});

Expand All @@ -92,7 +94,7 @@ describe('ACP agent CLI route', () => {

const response = await app.inject({
method: 'GET',
url: '/api/acp/agent-cli',
url: '/api/acp/agent-cli?agentletId=machine-a',
remoteAddress: '192.0.2.10',
});

Expand All @@ -108,7 +110,9 @@ describe('ACP agent CLI route', () => {
),
{ prefix: '/api/acp' },
);
const response = await app.inject('/api/acp/agent-cli');
const response = await app.inject(
'/api/acp/agent-cli?agentletId=machine-a',
);
expect(response.statusCode).toBe(503);
expect(response.json().code).toBe('harness_discovery_unavailable');
expect(response.json()).not.toHaveProperty('agents');
Expand Down
29 changes: 17 additions & 12 deletions apps/server/src/modules/agent/acp/agent-cli.route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

import {
getAgentletGateway,
getSupervisedAgentletId,
getAgentProfileRegistry,
} from '@agenetes/agentlet-host';
import {
Expand All @@ -36,19 +35,25 @@ import type {
} from '@huabu/shared';
import type { FastifyPluginAsync } from 'fastify';

async function detectAgentClis(profileId?: string): Promise<AcpAgentCliInfo[]> {
async function detectAgentClis(target: {
profileId?: string;
agentletId?: string;
}): Promise<AcpAgentCliInfo[]> {
const gateway = getAgentletGateway();
if (!gateway) throw new Error('Agentlet Gateway is not ready');
const profile = profileId
? getAgentProfileRegistry()?.getProfile(profileId)
const profile = target.profileId
? getAgentProfileRegistry()?.getProfile(target.profileId)
: undefined;
if (profileId && !profile) throw new Error('Agent Profile is unavailable');
const result = await gateway.discoverHarnesses(
profile?.agentletId ?? getSupervisedAgentletId(),
{
prepareWorkspaces: false,
},
);
if (target.profileId && !profile)
throw new Error('Agent Profile is unavailable');
const agentletId = profile?.agentletId ?? target.agentletId;
if (!agentletId) throw new Error('Agentlet target is required');
const connection = gateway.getAgentlet(agentletId);
if (connection?.status !== 'connected')
throw new Error('Agentlet is not connected');
const result = await gateway.discoverHarnesses(agentletId, {
prepareWorkspaces: false,
});
if (result.harnesses.some((entry) => entry.id === CUSTOM_COMMAND_WRAPPER_ID))
return result.harnesses;
return [
Expand Down Expand Up @@ -96,7 +101,7 @@ export function createAcpAgentCliRoutes(
message: 'Agent Profile is unavailable',
});
}
return { agents: await detect(parsed.data.profileId) };
return { agents: await detect(parsed.data) };
} catch (error) {
request.log.warn(
{ err: error },
Expand Down
2 changes: 1 addition & 1 deletion apps/server/src/modules/agent/acp/daemon-auth.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function makeAgentletHello(): AgentletHelloParams {
agentletId: 'test:agentlet',
agentletProfile: {
bridge: { name: 'agentlet', version: '1.0.0' },
machine: { hostname: 'test', platform: 'linux' },
machine: { hostname: 'test', platform: 'linux', arch: 'x64' },
capabilities: { autoRestart: true, bufferLimit: 1000 },
},
};
Expand Down
1 change: 0 additions & 1 deletion apps/server/src/modules/agent/acp/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
export {
mountAgenetes,
getAgentProfileRegistry,
getSupervisedAgentletId,
ACP_UPGRADE_PATH,
} from '@agenetes/agentlet-host';
export type {
Expand Down
75 changes: 0 additions & 75 deletions apps/server/src/modules/agent/acp/legacy-profile-migration.test.ts

This file was deleted.

34 changes: 0 additions & 34 deletions apps/server/src/modules/agent/acp/legacy-profile-migration.ts

This file was deleted.

74 changes: 0 additions & 74 deletions apps/server/src/modules/agent/acp/profile-store.test.ts

This file was deleted.

Loading
Loading