@borgee/agents-host 0.1.5 → 0.1.7

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/dist/run.d.ts CHANGED
@@ -1,7 +1,27 @@
1
- /**
2
- * Loads config from the environment, starts an `AgentsHost`, and wires up
3
- * graceful shutdown on SIGINT/SIGTERM. Shared by the plain env-var entry
4
- * point (`index.ts`) and the CLI entry point (`cli.ts`), which sets the
5
- * relevant env vars from argv before delegating here.
6
- */
7
- export declare function runMain(): Promise<void>;
1
+ import { parseGenerateConfigSpec, resolveLocalConfigLayout } from './local-config.js';
2
+ import type { LocalConfigGenerateResult, LocalConfigGenerateSpec, LocalConfigSnapshot } from './types.js';
3
+ export interface RunMainOptions {
4
+ configPath?: string;
5
+ }
6
+ export interface ValidateLocalConfigDeps {
7
+ loadSnapshot?: (configPath: string) => Promise<LocalConfigSnapshot>;
8
+ logger?: Pick<Console, 'log'>;
9
+ }
10
+ export interface PrintLocalConfigLayoutDeps {
11
+ resolveLayout?: (rootPath: string) => ReturnType<typeof resolveLocalConfigLayout>;
12
+ writer?: Pick<Console, 'log'>;
13
+ }
14
+ export interface DescribeLocalConfigDeps {
15
+ loadSpec?: (configPath: string) => Promise<LocalConfigGenerateSpec>;
16
+ writer?: Pick<Console, 'log'>;
17
+ }
18
+ export interface GenerateLocalConfigDeps {
19
+ parseSpec?: (value: unknown, sourceLabel: string) => ReturnType<typeof parseGenerateConfigSpec>;
20
+ materialize?: (rootPath: string, spec: ReturnType<typeof parseGenerateConfigSpec>) => Promise<LocalConfigGenerateResult>;
21
+ writer?: Pick<Console, 'log'>;
22
+ }
23
+ export declare function validateLocalConfig(configPath: string, deps?: ValidateLocalConfigDeps): Promise<void>;
24
+ export declare function printLocalConfigLayout(rootPath: string, deps?: PrintLocalConfigLayoutDeps): Promise<void>;
25
+ export declare function describeLocalConfig(configPath: string, deps?: DescribeLocalConfigDeps): Promise<void>;
26
+ export declare function generateLocalConfig(rootPath: string, specJson: string, sourceLabelOrDeps?: string | GenerateLocalConfigDeps, deps?: GenerateLocalConfigDeps): Promise<void>;
27
+ export declare function runMain(options?: RunMainOptions): Promise<void>;
package/dist/run.js CHANGED
@@ -1,14 +1,51 @@
1
- import { loadConfigFromEnv } from './config.js';
2
1
  import { AgentsHost } from './agents-host.js';
3
- /**
4
- * Loads config from the environment, starts an `AgentsHost`, and wires up
5
- * graceful shutdown on SIGINT/SIGTERM. Shared by the plain env-var entry
6
- * point (`index.ts`) and the CLI entry point (`cli.ts`), which sets the
7
- * relevant env vars from argv before delegating here.
8
- */
9
- export async function runMain() {
10
- const config = loadConfigFromEnv();
11
- const host = new AgentsHost(config);
2
+ import { AgentsHostSupervisor } from './agents-host-supervisor.js';
3
+ import { loadConfigFromEnv } from './config.js';
4
+ import { loadLocalConfigGenerateSpec, loadLocalConfigSnapshot, materializeLocalConfig, parseGenerateConfigSpec, resolveLocalConfigLayout, } from './local-config.js';
5
+ export async function validateLocalConfig(configPath, deps = {}) {
6
+ const loadSnapshot = deps.loadSnapshot ?? loadLocalConfigSnapshot;
7
+ const logger = deps.logger ?? console;
8
+ const snapshot = await loadSnapshot(configPath);
9
+ logger.log('[agents-host] local-config validation OK');
10
+ logger.log(`[agents-host] host config: ${snapshot.hostConfigPath}`);
11
+ logger.log(`[agents-host] agents dir: ${snapshot.agentsDir}`);
12
+ logger.log(`[agents-host] managed agents: ${snapshot.agents.length}`);
13
+ for (const agent of snapshot.agents) {
14
+ logger.log(`[agents-host] managed agent key=${agent.key} provider=${agent.config.agent.provider} sourcePath=${agent.sourcePath}`);
15
+ }
16
+ }
17
+ export async function printLocalConfigLayout(rootPath, deps = {}) {
18
+ const resolveLayout = deps.resolveLayout ?? resolveLocalConfigLayout;
19
+ const writer = deps.writer ?? console;
20
+ writer.log(JSON.stringify(resolveLayout(rootPath), null, 2));
21
+ }
22
+ export async function describeLocalConfig(configPath, deps = {}) {
23
+ const loadSpec = deps.loadSpec ?? loadLocalConfigGenerateSpec;
24
+ const writer = deps.writer ?? console;
25
+ writer.log(JSON.stringify(await loadSpec(configPath), null, 2));
26
+ }
27
+ export async function generateLocalConfig(rootPath, specJson, sourceLabelOrDeps = '--spec-json', deps = {}) {
28
+ const sourceLabel = typeof sourceLabelOrDeps === 'string' ? sourceLabelOrDeps : '--spec-json';
29
+ const resolvedDeps = typeof sourceLabelOrDeps === 'string' ? deps : sourceLabelOrDeps;
30
+ const parseSpec = resolvedDeps.parseSpec ?? parseGenerateConfigSpec;
31
+ const materialize = resolvedDeps.materialize ?? materializeLocalConfig;
32
+ const writer = resolvedDeps.writer ?? console;
33
+ let parsedJson;
34
+ try {
35
+ parsedJson = JSON.parse(specJson);
36
+ }
37
+ catch (error) {
38
+ const message = error instanceof Error ? error.message : String(error);
39
+ throw new Error(`Invalid ${sourceLabel}: ${message}`);
40
+ }
41
+ const spec = parseSpec(parsedJson, sourceLabel);
42
+ const result = await materialize(rootPath, spec);
43
+ writer.log(JSON.stringify(result, null, 2));
44
+ }
45
+ export async function runMain(options = {}) {
46
+ const host = options.configPath
47
+ ? new AgentsHostSupervisor(options.configPath)
48
+ : new AgentsHost(loadConfigFromEnv());
12
49
  const shutdown = (signal) => {
13
50
  console.log(`[agents-host] received ${signal}, shutting down`);
14
51
  host
@@ -19,4 +56,5 @@ export async function runMain() {
19
56
  process.on('SIGINT', () => shutdown('SIGINT'));
20
57
  process.on('SIGTERM', () => shutdown('SIGTERM'));
21
58
  await host.start();
59
+ console.log('[agents-host] ready');
22
60
  }
package/dist/types.d.ts CHANGED
@@ -4,15 +4,11 @@ export interface ProviderCommandConfig {
4
4
  claudeArgs: string[];
5
5
  copilotCommand: string;
6
6
  copilotArgs: string[];
7
+ copilotSessionTtlMinutes: number;
7
8
  }
8
9
  export interface ProviderRuntimeConfig extends ProviderCommandConfig {
9
10
  provider: ProviderKind;
10
11
  }
11
- /**
12
- * Single hosted-agent configuration. The minimal agents host supports exactly
13
- * one Borgee agent per process — running multiple agents means running
14
- * multiple processes with different env vars (see README).
15
- */
16
12
  export interface HostedAgentConfig {
17
13
  agentApiKey: string;
18
14
  agentName: string;
@@ -22,6 +18,66 @@ export interface AgentsHostConfig extends ProviderCommandConfig {
22
18
  borgeeBaseUrl: string;
23
19
  agent: HostedAgentConfig;
24
20
  }
21
+ export interface LocalHostConfigFile {
22
+ borgeeBaseUrl: string;
23
+ agentsDir?: string;
24
+ defaults?: Partial<ProviderCommandConfig>;
25
+ }
26
+ export interface LocalHostGenerateConfigFile {
27
+ borgeeBaseUrl: string;
28
+ defaults?: Partial<ProviderCommandConfig>;
29
+ }
30
+ export interface LocalAgentConfigFile extends Partial<ProviderCommandConfig> {
31
+ key: string;
32
+ name: string;
33
+ apiKey: string;
34
+ provider: ProviderKind;
35
+ enabled?: boolean;
36
+ }
37
+ export interface ManagedAgentConfigSnapshot {
38
+ key: string;
39
+ sourcePath: string;
40
+ config: AgentsHostConfig;
41
+ }
42
+ export interface LocalConfigSnapshot {
43
+ /** Stable caller-facing paths, suitable for validation output and publication watches. */
44
+ hostConfigPath: string;
45
+ hostConfigDir: string;
46
+ agentsDir: string;
47
+ /** Managed stable root when the snapshot comes from generate-config publication. */
48
+ managedRootPath?: string;
49
+ /** Resolved paths pinned before config files are read. */
50
+ resolvedHostConfigPath: string;
51
+ resolvedHostConfigDir: string;
52
+ resolvedAgentsDir: string;
53
+ agents: ManagedAgentConfigSnapshot[];
54
+ }
55
+ export interface LocalConfigGenerateSpec {
56
+ host: LocalHostGenerateConfigFile;
57
+ agents: LocalAgentConfigFile[];
58
+ }
59
+ export interface LocalConfigGenerateWarning {
60
+ code: 'PRUNE_SUPERSEDED_GENERATIONS_FAILED';
61
+ message: string;
62
+ }
63
+ export interface LocalConfigGenerateResult {
64
+ root: string;
65
+ hostConfigPath: string;
66
+ agentsDir: string;
67
+ generatedAgents: Array<{
68
+ key: string;
69
+ path: string;
70
+ provider: ProviderKind;
71
+ enabled: boolean;
72
+ }>;
73
+ /**
74
+ * Agent config paths removed from the active authoritative set. Publication
75
+ * switches the whole set atomically rather than deleting these paths first.
76
+ */
77
+ prunedAgentConfigPaths: string[];
78
+ /** Non-fatal maintenance problems encountered after publication. */
79
+ warnings: LocalConfigGenerateWarning[];
80
+ }
25
81
  export interface ChannelMessageEvent {
26
82
  type?: string;
27
83
  channel_id: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@borgee/agents-host",
3
- "version": "0.1.5",
3
+ "version": "0.1.7",
4
4
  "private": false,
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -21,7 +21,9 @@
21
21
  },
22
22
  "license": "MIT",
23
23
  "dependencies": {
24
+ "@agentclientprotocol/sdk": "^1.2.1",
24
25
  "cross-spawn": "^7.0.6",
26
+ "yaml": "^2.8.1",
25
27
  "@borgee/plugin-sdk": "0.1.1"
26
28
  },
27
29
  "devDependencies": {
@@ -42,6 +44,7 @@
42
44
  "build": "tsc",
43
45
  "typecheck": "tsc --noEmit",
44
46
  "pretest": "pnpm --filter @borgee/plugin-sdk build",
45
- "test": "vitest run"
47
+ "test": "vitest run --testTimeout=10000",
48
+ "pretypecheck": "pnpm --filter @borgee/plugin-sdk build"
46
49
  }
47
50
  }