@aifight/aifight 0.1.0-alpha.1
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/README.md +160 -0
- package/dist/bin.mjs +291 -0
- package/dist/index.mjs +107 -0
- package/dist/schemas/README.md +57 -0
- package/dist/schemas/common/README.md +40 -0
- package/dist/schemas/common/action.schema.json +19 -0
- package/dist/schemas/common/error.schema.json +23 -0
- package/dist/schemas/common/event.schema.json +33 -0
- package/dist/schemas/common/game_result.schema.json +31 -0
- package/dist/schemas/common/player_identity.schema.json +29 -0
- package/dist/schemas/common/player_info.schema.json +27 -0
- package/dist/schemas/common/rules.schema.json +34 -0
- package/dist/schemas/games/README.md +43 -0
- package/dist/schemas/games/coup/README.md +104 -0
- package/dist/schemas/games/coup/action.schema.json +198 -0
- package/dist/schemas/games/coup/event.schema.json +249 -0
- package/dist/schemas/games/coup/rules.schema.json +46 -0
- package/dist/schemas/games/coup/state.schema.json +123 -0
- package/dist/schemas/games/liars_dice/README.md +59 -0
- package/dist/schemas/games/liars_dice/action.schema.json +45 -0
- package/dist/schemas/games/liars_dice/event.schema.json +120 -0
- package/dist/schemas/games/liars_dice/rules.schema.json +36 -0
- package/dist/schemas/games/liars_dice/state.schema.json +72 -0
- package/dist/schemas/games/texas_holdem/README.md +58 -0
- package/dist/schemas/games/texas_holdem/action.schema.json +88 -0
- package/dist/schemas/games/texas_holdem/config.schema.json +30 -0
- package/dist/schemas/games/texas_holdem/event.schema.json +135 -0
- package/dist/schemas/games/texas_holdem/rules.schema.json +39 -0
- package/dist/schemas/games/texas_holdem/state.schema.json +98 -0
- package/dist/schemas/messages/README.md +98 -0
- package/dist/schemas/messages/client_action.schema.json +20 -0
- package/dist/schemas/messages/client_join_queue.schema.json +39 -0
- package/dist/schemas/messages/client_leave_queue.schema.json +18 -0
- package/dist/schemas/messages/client_match_confirm.schema.json +25 -0
- package/dist/schemas/messages/client_runtime_status.schema.json +46 -0
- package/dist/schemas/messages/server_action_request.schema.json +71 -0
- package/dist/schemas/messages/server_error.schema.json +16 -0
- package/dist/schemas/messages/server_event.schema.json +30 -0
- package/dist/schemas/messages/server_game_over.schema.json +49 -0
- package/dist/schemas/messages/server_game_start.schema.json +99 -0
- package/dist/schemas/messages/server_game_state.schema.json +33 -0
- package/dist/schemas/messages/server_match_cancelled.schema.json +51 -0
- package/dist/schemas/messages/server_match_confirm_request.schema.json +37 -0
- package/dist/schemas/messages/server_queue_joined.schema.json +26 -0
- package/dist/schemas/messages/server_queue_left.schema.json +24 -0
- package/dist/schemas/messages/server_readiness_check.schema.json +42 -0
- package/dist/schemas/messages/server_welcome.schema.json +49 -0
- package/dist/schemas/rest/README.md +85 -0
- package/dist/schemas/rest/agent_status_response.schema.json +34 -0
- package/dist/schemas/rest/claim_request.schema.json +20 -0
- package/dist/schemas/rest/claim_response.schema.json +24 -0
- package/dist/schemas/rest/error_response.schema.json +15 -0
- package/dist/schemas/rest/register_request.schema.json +35 -0
- package/dist/schemas/rest/register_response.schema.json +54 -0
- package/dist/types/account/credentials.d.ts +29 -0
- package/dist/types/account/errors.d.ts +61 -0
- package/dist/types/account/registration.d.ts +26 -0
- package/dist/types/agents/agent.d.ts +82 -0
- package/dist/types/agents/state-machine.d.ts +96 -0
- package/dist/types/bridge/config.d.ts +35 -0
- package/dist/types/bridge/hermes-provider.d.ts +9 -0
- package/dist/types/bridge/openclaw-provider.d.ts +9 -0
- package/dist/types/bridge/pairing.d.ts +18 -0
- package/dist/types/bridge/provider.d.ts +18 -0
- package/dist/types/bridge/runner.d.ts +30 -0
- package/dist/types/bridge/service.d.ts +55 -0
- package/dist/types/bridge/update-check.d.ts +23 -0
- package/dist/types/cli/agent-resolver.d.ts +25 -0
- package/dist/types/cli/argv.d.ts +13 -0
- package/dist/types/cli/commands/agent-list.d.ts +2 -0
- package/dist/types/cli/commands/agent-status.d.ts +2 -0
- package/dist/types/cli/commands/bridge-accept.d.ts +2 -0
- package/dist/types/cli/commands/bridge-challenge.d.ts +2 -0
- package/dist/types/cli/commands/bridge-connect.d.ts +2 -0
- package/dist/types/cli/commands/bridge-register.d.ts +2 -0
- package/dist/types/cli/commands/bridge-run.d.ts +7 -0
- package/dist/types/cli/commands/bridge-service.d.ts +3 -0
- package/dist/types/cli/commands/bridge-set.d.ts +2 -0
- package/dist/types/cli/commands/bridge-start.d.ts +2 -0
- package/dist/types/cli/commands/bridge-status.d.ts +2 -0
- package/dist/types/cli/commands/bridge-uninstall.d.ts +4 -0
- package/dist/types/cli/commands/config-init.d.ts +2 -0
- package/dist/types/cli/commands/config-probe.d.ts +2 -0
- package/dist/types/cli/commands/config-validate.d.ts +2 -0
- package/dist/types/cli/commands/daily-off.d.ts +2 -0
- package/dist/types/cli/commands/daily-on.d.ts +2 -0
- package/dist/types/cli/commands/daily-set.d.ts +2 -0
- package/dist/types/cli/commands/daily-show.d.ts +2 -0
- package/dist/types/cli/commands/doctor.d.ts +2 -0
- package/dist/types/cli/commands/init.d.ts +2 -0
- package/dist/types/cli/commands/join.d.ts +2 -0
- package/dist/types/cli/commands/leave.d.ts +2 -0
- package/dist/types/cli/commands/mcp.d.ts +2 -0
- package/dist/types/cli/commands/runtime-management.d.ts +16 -0
- package/dist/types/cli/commands/runtime-setup-state.d.ts +21 -0
- package/dist/types/cli/commands/runtime-setup.d.ts +23 -0
- package/dist/types/cli/commands/serve.d.ts +2 -0
- package/dist/types/cli/commands/service/launchd.d.ts +71 -0
- package/dist/types/cli/commands/service/platform.d.ts +69 -0
- package/dist/types/cli/commands/service/systemd.d.ts +55 -0
- package/dist/types/cli/commands/service/types.d.ts +64 -0
- package/dist/types/cli/commands/service-install.d.ts +29 -0
- package/dist/types/cli/commands/setup.d.ts +2 -0
- package/dist/types/cli/commands/shutdown.d.ts +2 -0
- package/dist/types/cli/commands/stubs.d.ts +24 -0
- package/dist/types/cli/commands/version.d.ts +2 -0
- package/dist/types/cli/control-client.d.ts +59 -0
- package/dist/types/cli/format.d.ts +52 -0
- package/dist/types/cli/main.d.ts +18 -0
- package/dist/types/cli/runtime-files.d.ts +11 -0
- package/dist/types/cli/shared.d.ts +74 -0
- package/dist/types/controlapi/profile-routes.d.ts +49 -0
- package/dist/types/controlapi/server.d.ts +3 -0
- package/dist/types/controlapi/types.d.ts +136 -0
- package/dist/types/daemon/agent-decision-adapter.d.ts +40 -0
- package/dist/types/daemon/lifecycle.d.ts +85 -0
- package/dist/types/daemon/router.d.ts +97 -0
- package/dist/types/daemon/runtime-files-write.d.ts +76 -0
- package/dist/types/decision/direct-model/anthropic.d.ts +12 -0
- package/dist/types/decision/direct-model/errors.d.ts +59 -0
- package/dist/types/decision/direct-model/openai.d.ts +12 -0
- package/dist/types/decision/direct-model/types.d.ts +20 -0
- package/dist/types/decision/parser-types.d.ts +31 -0
- package/dist/types/decision/prompt-builder.d.ts +10 -0
- package/dist/types/decision/provider.d.ts +50 -0
- package/dist/types/decision/types.d.ts +87 -0
- package/dist/types/games/_shared/player-info.d.ts +14 -0
- package/dist/types/games/coup/action-parser.d.ts +3 -0
- package/dist/types/games/coup/fallback.d.ts +8 -0
- package/dist/types/games/coup/state-formatter.d.ts +14 -0
- package/dist/types/games/liars_dice/action-parser.d.ts +3 -0
- package/dist/types/games/liars_dice/fallback.d.ts +8 -0
- package/dist/types/games/liars_dice/state-formatter.d.ts +14 -0
- package/dist/types/games/texas_holdem/action-parser.d.ts +3 -0
- package/dist/types/games/texas_holdem/fallback.d.ts +8 -0
- package/dist/types/games/texas_holdem/state-formatter.d.ts +14 -0
- package/dist/types/identity/identity-manager.d.ts +59 -0
- package/dist/types/index.d.ts +30 -0
- package/dist/types/llm/adapter-registry.d.ts +27 -0
- package/dist/types/llm/adapters/anthropic-messages.d.ts +2 -0
- package/dist/types/llm/adapters/deepseek-chat-completions.d.ts +2 -0
- package/dist/types/llm/adapters/openai-chat-compat.d.ts +2 -0
- package/dist/types/llm/adapters/openai-chat-completions.d.ts +2 -0
- package/dist/types/llm/adapters/openai-responses.d.ts +2 -0
- package/dist/types/llm/adapters/types.d.ts +128 -0
- package/dist/types/llm/capabilities/validate-capabilities.d.ts +68 -0
- package/dist/types/mcp/control-client.d.ts +54 -0
- package/dist/types/mcp/profile-tools.d.ts +10 -0
- package/dist/types/mcp/server.d.ts +10 -0
- package/dist/types/mcp/tools.d.ts +31 -0
- package/dist/types/mcp/types.d.ts +27 -0
- package/dist/types/profile/config-schema.d.ts +199 -0
- package/dist/types/profile/identity-schema.d.ts +75 -0
- package/dist/types/profile/index.d.ts +7 -0
- package/dist/types/profile/migrate.d.ts +16 -0
- package/dist/types/profile/profile-loader.d.ts +64 -0
- package/dist/types/profile/secret-ref.d.ts +82 -0
- package/dist/types/profile/soul.d.ts +46 -0
- package/dist/types/profile/strategy-schema.d.ts +70 -0
- package/dist/types/protocol/schemas.d.ts +11 -0
- package/dist/types/protocol/types.d.ts +1333 -0
- package/dist/types/reflection/proposal-store.d.ts +50 -0
- package/dist/types/reflection/reflection-engine.d.ts +81 -0
- package/dist/types/scheduler/daily.d.ts +47 -0
- package/dist/types/scheduler/types.d.ts +42 -0
- package/dist/types/session/match-session-manager.d.ts +113 -0
- package/dist/types/session/session-context-builder.d.ts +68 -0
- package/dist/types/store/errors.d.ts +23 -0
- package/dist/types/store/paths.d.ts +3 -0
- package/dist/types/store/schema.generated.d.ts +1 -0
- package/dist/types/store/sqlite.d.ts +36 -0
- package/dist/types/wsclient/client.d.ts +220 -0
- package/dist/types/wsclient/errors.d.ts +106 -0
- package/dist/types/wsclient/frame-handler.d.ts +20 -0
- package/dist/types/wsclient/reconnect.d.ts +84 -0
- package/package.json +53 -0
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export type BridgeRuntimeType = "openclaw" | "hermes" | "mock";
|
|
2
|
+
export declare class RuntimeLocalUrlError extends Error {
|
|
3
|
+
readonly name = "RuntimeLocalUrlError";
|
|
4
|
+
}
|
|
5
|
+
export interface BridgeConfig {
|
|
6
|
+
readonly version: 1;
|
|
7
|
+
readonly baseUrl: string;
|
|
8
|
+
readonly wsUrl: string;
|
|
9
|
+
readonly agentId: string;
|
|
10
|
+
readonly agentName: string;
|
|
11
|
+
readonly suggestedName?: string;
|
|
12
|
+
readonly apiKey: string;
|
|
13
|
+
readonly claimUrl?: string;
|
|
14
|
+
readonly claimToken?: string;
|
|
15
|
+
readonly runtimeType: BridgeRuntimeType;
|
|
16
|
+
readonly runtimeLocalUrl: string;
|
|
17
|
+
readonly runtimeLocalToken?: string;
|
|
18
|
+
readonly runtimeModel?: string;
|
|
19
|
+
readonly autoDailyLimit?: number;
|
|
20
|
+
readonly autoGames?: readonly string[];
|
|
21
|
+
readonly updatedAt: string;
|
|
22
|
+
}
|
|
23
|
+
export interface RedactedBridgeConfig extends Omit<BridgeConfig, "apiKey" | "runtimeLocalToken" | "claimToken"> {
|
|
24
|
+
readonly apiKey: string;
|
|
25
|
+
readonly runtimeLocalToken?: string;
|
|
26
|
+
readonly claimToken?: string;
|
|
27
|
+
}
|
|
28
|
+
export declare function defaultRuntimeLocalUrl(runtimeType: BridgeRuntimeType): string;
|
|
29
|
+
export declare function normalizeRuntimeLocalUrl(raw: string, runtimeType: BridgeRuntimeType): string;
|
|
30
|
+
export declare function defaultRuntimeModel(runtimeType: BridgeRuntimeType): string;
|
|
31
|
+
export declare function getBridgeConfigPath(): string;
|
|
32
|
+
export declare function removeBridgeConfig(): void;
|
|
33
|
+
export declare function writeBridgeConfig(config: BridgeConfig): void;
|
|
34
|
+
export declare function readBridgeConfig(): BridgeConfig;
|
|
35
|
+
export declare function redactBridgeConfig(config: BridgeConfig): RedactedBridgeConfig;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { BridgeRuntimeProvider } from "./provider";
|
|
2
|
+
export interface HermesRuntimeProviderOptions {
|
|
3
|
+
readonly agentId: string;
|
|
4
|
+
readonly baseUrl?: string;
|
|
5
|
+
readonly token?: string;
|
|
6
|
+
readonly model?: string;
|
|
7
|
+
readonly fetchImpl?: typeof fetch;
|
|
8
|
+
}
|
|
9
|
+
export declare function createHermesRuntimeProvider(opts: HermesRuntimeProviderOptions): BridgeRuntimeProvider;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { BridgeRuntimeProvider } from "./provider";
|
|
2
|
+
export interface OpenClawRuntimeProviderOptions {
|
|
3
|
+
readonly agentId: string;
|
|
4
|
+
readonly baseUrl?: string;
|
|
5
|
+
readonly token?: string;
|
|
6
|
+
readonly model?: string;
|
|
7
|
+
readonly fetchImpl?: typeof fetch;
|
|
8
|
+
}
|
|
9
|
+
export declare function createOpenClawRuntimeProvider(opts: OpenClawRuntimeProviderOptions): BridgeRuntimeProvider;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { type BridgeConfig, type BridgeRuntimeType } from "./config";
|
|
2
|
+
export interface BridgePairExchangeResponse {
|
|
3
|
+
readonly agent: {
|
|
4
|
+
readonly id: string;
|
|
5
|
+
readonly name: string;
|
|
6
|
+
readonly api_key: string;
|
|
7
|
+
readonly runtime_type: BridgeRuntimeType;
|
|
8
|
+
};
|
|
9
|
+
readonly ws_url: string;
|
|
10
|
+
readonly message?: string;
|
|
11
|
+
}
|
|
12
|
+
export interface ExchangePairingCodeOptions {
|
|
13
|
+
readonly pairingCode: string;
|
|
14
|
+
readonly baseUrl?: string;
|
|
15
|
+
readonly fetchImpl?: typeof fetch;
|
|
16
|
+
readonly now?: () => Date;
|
|
17
|
+
}
|
|
18
|
+
export declare function exchangePairingCode(opts: ExchangePairingCodeOptions): Promise<BridgeConfig>;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { AgentDecisionProvider } from "../agents/agent";
|
|
2
|
+
import type { GameType, LegalAction } from "../decision/types";
|
|
3
|
+
export interface BridgeRuntimeDecisionRequest {
|
|
4
|
+
readonly game: GameType;
|
|
5
|
+
readonly matchId: string;
|
|
6
|
+
readonly playerId?: string;
|
|
7
|
+
readonly legalActions: readonly LegalAction[];
|
|
8
|
+
readonly publicState: unknown;
|
|
9
|
+
readonly timeoutMs: number;
|
|
10
|
+
}
|
|
11
|
+
export interface BridgeRuntimeProvider {
|
|
12
|
+
readonly name: string;
|
|
13
|
+
decide(req: BridgeRuntimeDecisionRequest): Promise<string | LegalAction>;
|
|
14
|
+
healthCheck?(): Promise<boolean>;
|
|
15
|
+
}
|
|
16
|
+
export declare function buildBridgeDecisionProvider(runtimeProvider: BridgeRuntimeProvider): AgentDecisionProvider;
|
|
17
|
+
export declare function createMockRuntimeProvider(): BridgeRuntimeProvider;
|
|
18
|
+
export declare function createUnavailableRuntimeProvider(name: string): BridgeRuntimeProvider;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { AgentInstance, type AgentInstanceSnapshot } from "../agents/agent";
|
|
2
|
+
import type { BridgeConfig } from "./config";
|
|
3
|
+
import { type BridgeRuntimeProvider } from "./provider";
|
|
4
|
+
export interface BridgeRunnerOptions {
|
|
5
|
+
readonly config: BridgeConfig;
|
|
6
|
+
readonly runtimeProvider?: BridgeRuntimeProvider;
|
|
7
|
+
readonly autoJoinGame?: "texas_holdem" | "liars_dice" | "coup";
|
|
8
|
+
readonly autoJoinMode?: string;
|
|
9
|
+
readonly autoJoinOneShot?: boolean;
|
|
10
|
+
readonly connect?: ConstructorParameters<typeof AgentInstance>[0]["connect"];
|
|
11
|
+
readonly onLog?: (event: BridgeRunnerLogEvent) => void;
|
|
12
|
+
}
|
|
13
|
+
export interface BridgeRunnerLogEvent {
|
|
14
|
+
readonly level: "info" | "warning" | "error";
|
|
15
|
+
readonly code: string;
|
|
16
|
+
readonly message: string;
|
|
17
|
+
}
|
|
18
|
+
export declare class BridgeRunner {
|
|
19
|
+
#private;
|
|
20
|
+
constructor(opts: BridgeRunnerOptions);
|
|
21
|
+
start(): Promise<AgentInstanceSnapshot>;
|
|
22
|
+
stop(): Promise<void>;
|
|
23
|
+
snapshot(): AgentInstanceSnapshot | null;
|
|
24
|
+
joinQueue(game: "texas_holdem" | "liars_dice" | "coup", mode?: string, opts?: {
|
|
25
|
+
readonly oneShot?: boolean;
|
|
26
|
+
readonly count?: number;
|
|
27
|
+
}): void;
|
|
28
|
+
leaveQueue(): void;
|
|
29
|
+
requestManualMatches(game: "texas_holdem" | "liars_dice" | "coup", mode?: string, count?: number): void;
|
|
30
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
export declare const AIFIGHT_SERVICE_NAME = "aifight.service";
|
|
2
|
+
export type BridgeServicePlatform = "linux-systemd-system" | "linux-systemd-user" | "darwin-launchd-user";
|
|
3
|
+
export interface ServiceExecResult {
|
|
4
|
+
readonly stdout: string;
|
|
5
|
+
readonly stderr: string;
|
|
6
|
+
}
|
|
7
|
+
export interface ServiceExecError extends Error {
|
|
8
|
+
readonly code?: string;
|
|
9
|
+
readonly stdout?: string;
|
|
10
|
+
readonly stderr?: string;
|
|
11
|
+
}
|
|
12
|
+
export type ServiceExecFile = (file: string, args: readonly string[]) => Promise<ServiceExecResult>;
|
|
13
|
+
export interface BridgeServiceDeps {
|
|
14
|
+
readonly execFile?: ServiceExecFile;
|
|
15
|
+
readonly platform?: NodeJS.Platform;
|
|
16
|
+
readonly uid?: number;
|
|
17
|
+
readonly username?: string;
|
|
18
|
+
readonly homeDir?: string;
|
|
19
|
+
readonly aifightExec?: string;
|
|
20
|
+
readonly nodeExec?: string;
|
|
21
|
+
readonly runtimeHome?: string;
|
|
22
|
+
readonly systemdSystemUnitPath?: string;
|
|
23
|
+
readonly systemdUserUnitPath?: string;
|
|
24
|
+
readonly launchdPlistPath?: string;
|
|
25
|
+
readonly launchdLogDir?: string;
|
|
26
|
+
}
|
|
27
|
+
export interface BridgeServiceTarget {
|
|
28
|
+
readonly platform: BridgeServicePlatform;
|
|
29
|
+
readonly unitPath: string;
|
|
30
|
+
readonly nodeExec: string;
|
|
31
|
+
readonly aifightExec: string;
|
|
32
|
+
readonly runtimeHome: string;
|
|
33
|
+
}
|
|
34
|
+
export interface BridgeServiceInstallResult extends BridgeServiceTarget {
|
|
35
|
+
readonly linger: "not_needed" | "enabled" | "failed" | "skipped";
|
|
36
|
+
readonly warning?: string;
|
|
37
|
+
}
|
|
38
|
+
export interface BridgeServiceStatus extends BridgeServiceTarget {
|
|
39
|
+
readonly installed: boolean;
|
|
40
|
+
readonly running: boolean | null;
|
|
41
|
+
readonly detail: string;
|
|
42
|
+
}
|
|
43
|
+
export declare class BridgeServiceError extends Error {
|
|
44
|
+
readonly code: string;
|
|
45
|
+
readonly hint?: string;
|
|
46
|
+
constructor(code: string, message: string, hint?: string);
|
|
47
|
+
}
|
|
48
|
+
export declare const defaultServiceExecFile: ServiceExecFile;
|
|
49
|
+
export declare function installBridgeService(deps?: BridgeServiceDeps): Promise<BridgeServiceInstallResult>;
|
|
50
|
+
export declare function uninstallBridgeService(deps?: BridgeServiceDeps): Promise<BridgeServiceTarget>;
|
|
51
|
+
export declare function startBridgeService(deps?: BridgeServiceDeps): Promise<BridgeServiceTarget>;
|
|
52
|
+
export declare function stopBridgeService(deps?: BridgeServiceDeps): Promise<BridgeServiceTarget>;
|
|
53
|
+
export declare function restartBridgeService(deps?: BridgeServiceDeps): Promise<BridgeServiceTarget>;
|
|
54
|
+
export declare function statusBridgeService(deps?: BridgeServiceDeps): Promise<BridgeServiceStatus>;
|
|
55
|
+
export declare function resolveBridgeServiceTarget(deps?: BridgeServiceDeps): Promise<BridgeServiceTarget>;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export type BridgeUpdateStatus = "current" | "update_recommended" | "unsupported" | "unknown";
|
|
2
|
+
export interface BridgeVersionPolicy {
|
|
3
|
+
readonly minimumSupportedVersion: string;
|
|
4
|
+
readonly recommendedVersion: string;
|
|
5
|
+
readonly latestVersion: string;
|
|
6
|
+
readonly updateCommand: string;
|
|
7
|
+
readonly releaseNotesUrl?: string;
|
|
8
|
+
readonly policy?: string;
|
|
9
|
+
}
|
|
10
|
+
export interface BridgeUpdateCheck {
|
|
11
|
+
readonly status: BridgeUpdateStatus;
|
|
12
|
+
readonly currentVersion: string;
|
|
13
|
+
readonly policy?: BridgeVersionPolicy;
|
|
14
|
+
readonly message: string;
|
|
15
|
+
}
|
|
16
|
+
export interface CheckBridgeUpdateOptions {
|
|
17
|
+
readonly baseUrl: string;
|
|
18
|
+
readonly currentVersion: string;
|
|
19
|
+
readonly fetchImpl?: typeof fetch;
|
|
20
|
+
readonly timeoutMs?: number;
|
|
21
|
+
}
|
|
22
|
+
export declare function checkBridgeUpdate(opts: CheckBridgeUpdateOptions): Promise<BridgeUpdateCheck>;
|
|
23
|
+
export declare function evaluatePolicy(currentVersion: string, policy: BridgeVersionPolicy): BridgeUpdateCheck;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { ControlClient } from "./control-client";
|
|
2
|
+
export type AgentResolverErrorKind = "no_agents" | "ambiguous";
|
|
3
|
+
export declare class AgentResolverError extends Error {
|
|
4
|
+
readonly name = "AgentResolverError";
|
|
5
|
+
readonly kind: AgentResolverErrorKind;
|
|
6
|
+
readonly availableNames?: readonly string[];
|
|
7
|
+
constructor(kind: AgentResolverErrorKind, message: string, availableNames?: readonly string[]);
|
|
8
|
+
}
|
|
9
|
+
export interface AgentResolverOptions {
|
|
10
|
+
/** Only the .get(...) method is used — typed via Pick so tests can
|
|
11
|
+
* inject minimal mocks without implementing post/delete. */
|
|
12
|
+
readonly client: Pick<ControlClient, "get">;
|
|
13
|
+
/** When non-empty, used as-is without contacting the daemon. */
|
|
14
|
+
readonly explicitAgent?: string;
|
|
15
|
+
/** Default true. --json mode passes false so the implicit-choice log
|
|
16
|
+
* doesn't pollute machine-readable output. */
|
|
17
|
+
readonly logImplicitChoice?: boolean;
|
|
18
|
+
/** stderr sink for the implicit-choice log line. Default
|
|
19
|
+
* process.stderr.write. */
|
|
20
|
+
readonly onLog?: (message: string) => void;
|
|
21
|
+
}
|
|
22
|
+
export interface AgentResolver {
|
|
23
|
+
resolve(): Promise<string>;
|
|
24
|
+
}
|
|
25
|
+
export declare function createAgentResolver(opts: AgentResolverOptions): AgentResolver;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export type FlagValue = string | number | boolean;
|
|
2
|
+
export interface FlagSpec {
|
|
3
|
+
readonly name: string;
|
|
4
|
+
readonly type: "string" | "number" | "boolean";
|
|
5
|
+
readonly required?: boolean;
|
|
6
|
+
readonly default?: FlagValue;
|
|
7
|
+
}
|
|
8
|
+
export interface ParsedArgv {
|
|
9
|
+
readonly positional: readonly string[];
|
|
10
|
+
readonly flags: Readonly<Record<string, FlagValue>>;
|
|
11
|
+
readonly errors: readonly string[];
|
|
12
|
+
}
|
|
13
|
+
export declare function parseArgs(argv: readonly string[], spec: readonly FlagSpec[]): ParsedArgv;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { type BridgeConfig } from "../../bridge/config";
|
|
2
|
+
import type { HandlerArgs, HandlerEnv } from "../shared";
|
|
3
|
+
export declare function runBridgeRun(args: HandlerArgs, env: HandlerEnv): Promise<number>;
|
|
4
|
+
export declare function runBridgeWithConfig(opts: {
|
|
5
|
+
readonly config: BridgeConfig;
|
|
6
|
+
readonly env: HandlerEnv;
|
|
7
|
+
}): Promise<number>;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { HandlerArgs, HandlerEnv } from "../shared";
|
|
2
|
+
import { type EnvKeyPrevious } from "./runtime-setup-state";
|
|
3
|
+
export declare function runBridgeUninstall(args: HandlerArgs, env: HandlerEnv): Promise<number>;
|
|
4
|
+
export declare function restoreEnvText(existing: string, previous: Record<string, EnvKeyPrevious>): string;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { HandlerEnv } from "../shared";
|
|
2
|
+
export interface ExecResult {
|
|
3
|
+
readonly code: number;
|
|
4
|
+
readonly stdout: string;
|
|
5
|
+
readonly stderr: string;
|
|
6
|
+
}
|
|
7
|
+
type RuntimeName = "openclaw" | "hermes";
|
|
8
|
+
export declare function findExecutable(name: string): string | undefined;
|
|
9
|
+
export declare function execCommand(command: string, args: readonly string[]): Promise<ExecResult>;
|
|
10
|
+
export declare function writeExecResult(env: HandlerEnv, label: string, result: ExecResult): void;
|
|
11
|
+
export declare function promptYesNo(env: HandlerEnv, question: string): Promise<boolean>;
|
|
12
|
+
export declare function promptYesNoDefaultNo(env: HandlerEnv, question: string): Promise<boolean>;
|
|
13
|
+
export declare function offerGatewayRestart(env: HandlerEnv, runtime: RuntimeName, reason: string): Promise<boolean>;
|
|
14
|
+
export declare function systemdUnitIsActive(result: ExecResult): boolean;
|
|
15
|
+
export declare function hermesRestartUnavailable(result: ExecResult): boolean;
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export interface EnvKeyPrevious {
|
|
2
|
+
readonly wasActive: boolean;
|
|
3
|
+
readonly value?: string;
|
|
4
|
+
}
|
|
5
|
+
export interface RuntimeSetupState {
|
|
6
|
+
readonly version: 1;
|
|
7
|
+
readonly updatedAt: string;
|
|
8
|
+
readonly openclaw?: {
|
|
9
|
+
readonly responsesEnabledByAIFight: boolean;
|
|
10
|
+
readonly updatedAt: string;
|
|
11
|
+
};
|
|
12
|
+
readonly hermes?: {
|
|
13
|
+
readonly envPath: string;
|
|
14
|
+
readonly previous: Record<string, EnvKeyPrevious>;
|
|
15
|
+
readonly updatedAt: string;
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
export declare function getRuntimeSetupStatePath(): string;
|
|
19
|
+
export declare function readRuntimeSetupState(): RuntimeSetupState | undefined;
|
|
20
|
+
export declare function mergeRuntimeSetupState(patch: Omit<Partial<RuntimeSetupState>, "version" | "updatedAt">): void;
|
|
21
|
+
export declare function removeRuntimeSetupState(): void;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { BridgeRuntimeType } from "../../bridge/config";
|
|
2
|
+
import type { HandlerEnv } from "../shared";
|
|
3
|
+
export interface RuntimeSetupResult {
|
|
4
|
+
readonly runtimeLocalToken?: string;
|
|
5
|
+
}
|
|
6
|
+
interface RuntimeSetupOptions {
|
|
7
|
+
readonly env: HandlerEnv;
|
|
8
|
+
readonly runtimeType: BridgeRuntimeType;
|
|
9
|
+
readonly runtimeLocalUrl: string;
|
|
10
|
+
readonly runtimeLocalToken?: string;
|
|
11
|
+
readonly runtimeModel?: string;
|
|
12
|
+
readonly jsonMode: boolean;
|
|
13
|
+
}
|
|
14
|
+
type ProbeStatus = "ready" | "endpoint_reachable" | "disabled" | "auth_failed" | "unreachable";
|
|
15
|
+
interface ProbeResult {
|
|
16
|
+
readonly status: ProbeStatus;
|
|
17
|
+
readonly detail: string;
|
|
18
|
+
}
|
|
19
|
+
export declare function offerRuntimeSetup(opts: RuntimeSetupOptions): Promise<RuntimeSetupResult>;
|
|
20
|
+
export declare function probeOpenClaw(env: HandlerEnv, baseUrl: string, token?: string, model?: string): Promise<ProbeResult>;
|
|
21
|
+
export declare function probeHermes(env: HandlerEnv, baseUrl: string, token?: string, model?: string): Promise<ProbeResult>;
|
|
22
|
+
export declare function upsertEnvText(existing: string, values: Record<string, string>): string;
|
|
23
|
+
export {};
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import type { ServiceTarget } from "./types";
|
|
2
|
+
import { type ServiceExecFile } from "./platform";
|
|
3
|
+
export declare class LaunchdAlreadyInstalledDiffError extends Error {
|
|
4
|
+
readonly code: "client_already_installed_diff";
|
|
5
|
+
readonly hint?: string;
|
|
6
|
+
constructor(message: string, hint?: string);
|
|
7
|
+
}
|
|
8
|
+
export declare class LaunchdNotInstalledError extends Error {
|
|
9
|
+
readonly code: "client_not_installed";
|
|
10
|
+
readonly hint?: string;
|
|
11
|
+
constructor(message: string, hint?: string);
|
|
12
|
+
}
|
|
13
|
+
export declare class LaunchdInstallFailedError extends Error {
|
|
14
|
+
readonly code: "client_install_failed";
|
|
15
|
+
readonly hint?: string;
|
|
16
|
+
/** Stage taxonomy distinct from systemd's (which is daemon-reload /
|
|
17
|
+
* enable / start). Launchd combines register+start into bootstrap, so
|
|
18
|
+
* the natural stages are the prerequisites (log dir + plist write),
|
|
19
|
+
* the bootstrap call itself, and the post-bootstrap verify. */
|
|
20
|
+
readonly stage: "log-dir" | "write-plist" | "bootstrap" | "verify";
|
|
21
|
+
constructor(stage: LaunchdInstallFailedError["stage"], message: string, hint?: string);
|
|
22
|
+
}
|
|
23
|
+
export declare class LaunchdUninstallFailedError extends Error {
|
|
24
|
+
readonly code: "client_uninstall_failed";
|
|
25
|
+
readonly hint?: string;
|
|
26
|
+
constructor(message: string, hint?: string);
|
|
27
|
+
}
|
|
28
|
+
export declare class LaunchdStartFailedError extends Error {
|
|
29
|
+
readonly code: "client_start_failed";
|
|
30
|
+
readonly hint?: string;
|
|
31
|
+
constructor(message: string, hint?: string);
|
|
32
|
+
}
|
|
33
|
+
export declare class LaunchdStopFailedError extends Error {
|
|
34
|
+
readonly code: "client_stop_failed";
|
|
35
|
+
readonly hint?: string;
|
|
36
|
+
constructor(message: string, hint?: string);
|
|
37
|
+
}
|
|
38
|
+
export declare function escapeXmlText(s: string): string;
|
|
39
|
+
export declare const LAUNCHD_LABEL = "ai.aifight.runtime";
|
|
40
|
+
export interface LaunchdTargetOptions {
|
|
41
|
+
/** Absolute path of the resolved `aifight` binary. Step 4
|
|
42
|
+
* `resolveAifightExec()` produces this; tests inject any string. */
|
|
43
|
+
readonly aifightExec: string;
|
|
44
|
+
/** Absolute path of the plist — typically
|
|
45
|
+
* `~/Library/LaunchAgents/ai.aifight.runtime.plist`. Tests inject a
|
|
46
|
+
* tmp dir. */
|
|
47
|
+
readonly plistPath: string;
|
|
48
|
+
/** Absolute log directory — typically `~/Library/Logs/aifight`.
|
|
49
|
+
* Install creates this if missing; uninstall preserves it unless
|
|
50
|
+
* `--purge`. */
|
|
51
|
+
readonly logDir: string;
|
|
52
|
+
/** AIFIGHT_RUNTIME_HOME baked into the plist EnvironmentVariables. */
|
|
53
|
+
readonly runtimeHome: string;
|
|
54
|
+
/** Effective user id for `gui/$UID` selector. Production uses
|
|
55
|
+
* `process.getuid?.() ?? 0`; tests inject any integer. */
|
|
56
|
+
readonly uid: number;
|
|
57
|
+
/** Factory-time `RunAtLoad` setting (rev3 B4 — see module header for
|
|
58
|
+
* the systemd vs launchd asymmetry rationale).
|
|
59
|
+
* - true: plist writes `RunAtLoad=true`; install bootstraps and
|
|
60
|
+
* then verifies via `launchctl print` (daemon should be running).
|
|
61
|
+
* - false: plist writes `RunAtLoad=false`; install still bootstraps
|
|
62
|
+
* (registers LaunchAgent) but does NOT verify (the daemon is
|
|
63
|
+
* intentionally idle until `aifight service start` kickstarts
|
|
64
|
+
* it). */
|
|
65
|
+
readonly autoStart: boolean;
|
|
66
|
+
/** Defaults to `defaultExecFile` (production). Tests pass a mock that
|
|
67
|
+
* records calls + returns canned stdout/stderr without spawning a
|
|
68
|
+
* real subprocess. */
|
|
69
|
+
readonly execFile?: ServiceExecFile;
|
|
70
|
+
}
|
|
71
|
+
export declare function createLaunchdTarget(opts: LaunchdTargetOptions): ServiceTarget;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import type { ServicePlatform } from "./types";
|
|
2
|
+
/** OS-level platform — intermediate value before service-manager probe.
|
|
3
|
+
* - "linux" / "darwin": candidate for service install; needs probe.
|
|
4
|
+
* - "unsupported": Windows / FreeBSD / other; short-circuits without probe. */
|
|
5
|
+
export type OsPlatform = "linux" | "darwin" | "unsupported";
|
|
6
|
+
/** Sync, pure, `process.platform`-only OS detection (rev4 B2 + F4 fold).
|
|
7
|
+
* No I/O, no subprocess. Tests stub `process.platform` via Object.defineProperty. */
|
|
8
|
+
export declare function detectOsPlatform(): OsPlatform;
|
|
9
|
+
/** Result of an injected execFile call. Promise resolves on exit 0;
|
|
10
|
+
* rejects with `ServiceExecFileError` on ENOENT, non-zero exit, or
|
|
11
|
+
* any other subprocess error. Mirrors `util.promisify(child_process.execFile)`
|
|
12
|
+
* semantics so the production default below is a thin adapter. */
|
|
13
|
+
export interface ServiceExecFileResult {
|
|
14
|
+
readonly stdout: string;
|
|
15
|
+
readonly stderr: string;
|
|
16
|
+
}
|
|
17
|
+
export interface ServiceExecFileError extends Error {
|
|
18
|
+
/** Node ErrnoException code, e.g. "ENOENT" when the binary is not in PATH. */
|
|
19
|
+
readonly code?: string;
|
|
20
|
+
/** Captured before failure (when the subprocess emitted output then exited
|
|
21
|
+
* non-zero). Empty string when no output was captured. */
|
|
22
|
+
readonly stdout?: string;
|
|
23
|
+
readonly stderr?: string;
|
|
24
|
+
}
|
|
25
|
+
export type ServiceExecFile = (file: string, args: readonly string[]) => Promise<ServiceExecFileResult>;
|
|
26
|
+
/** Production default — wraps Node `child_process.execFile` with a 2 s
|
|
27
|
+
* timeout suitable for cheap version probes. Tests pass an explicit mock
|
|
28
|
+
* so this is never invoked in CI. Exposed so callers (service-install.ts
|
|
29
|
+
* in Step 4) can reuse it instead of recreating the adapter. */
|
|
30
|
+
export declare const defaultExecFile: ServiceExecFile;
|
|
31
|
+
export interface ProbeServicePlatformOptions {
|
|
32
|
+
readonly execFile: ServiceExecFile;
|
|
33
|
+
/** Defaults to `detectOsPlatform()`; tests pass explicit value to avoid
|
|
34
|
+
* Object.defineProperty(process, "platform") gymnastics. */
|
|
35
|
+
readonly osPlatform?: OsPlatform;
|
|
36
|
+
}
|
|
37
|
+
/** Async, injectable, only-read probe.
|
|
38
|
+
* - osPlatform == "unsupported" → short-circuit `unsupported` (NEVER
|
|
39
|
+
* invokes execFile). Tests assert this with a spy that throws if called.
|
|
40
|
+
* - osPlatform == "linux" → `execFile("systemctl", ["--user", "--version"])`.
|
|
41
|
+
* - osPlatform == "darwin" → `execFile("launchctl", ["version"])`.
|
|
42
|
+
* - any rejection (ENOENT / non-zero exit / timeout / unexpected throw),
|
|
43
|
+
* or stdout/stderr containing a known failure marker (e.g.
|
|
44
|
+
* "Failed to connect to bus" — systemd `--user` not running) → `unsupported`.
|
|
45
|
+
* - resolution + clean stdout/stderr → corresponding `linux-systemd-user`
|
|
46
|
+
* or `darwin-launchd-user`. */
|
|
47
|
+
export declare function probeServicePlatform(opts: ProbeServicePlatformOptions): Promise<ServicePlatform>;
|
|
48
|
+
/** rev4 contract — service-specific error class. NOT a `UsageError`,
|
|
49
|
+
* because plain `UsageError` funnels through `main.ts emitUsageError` and
|
|
50
|
+
* produces only `client_usage_error`. Service handlers catch
|
|
51
|
+
* `ServicePlatformError` and call `emitServiceError(env, jsonMode, 2,
|
|
52
|
+
* e.code, e.message, e.hint)`. */
|
|
53
|
+
export declare class ServicePlatformError extends Error {
|
|
54
|
+
readonly code: "client_platform_unsupported" | "client_service_manager_missing";
|
|
55
|
+
readonly hint?: string;
|
|
56
|
+
constructor(code: ServicePlatformError["code"], message: string, hint?: string);
|
|
57
|
+
}
|
|
58
|
+
export interface EnsureSupportedPlatformOptions extends Partial<ProbeServicePlatformOptions> {
|
|
59
|
+
}
|
|
60
|
+
/** Composes `detectOsPlatform()` + `probeServicePlatform()`.
|
|
61
|
+
* - Returns the resolved supported platform on success.
|
|
62
|
+
* - Throws `ServicePlatformError` on unsupported with:
|
|
63
|
+
* Windows / non-linux + non-darwin → `client_platform_unsupported`
|
|
64
|
+
* + hint mentioning Windows or "platform <p>".
|
|
65
|
+
* linux / darwin but service manager unreachable →
|
|
66
|
+
* `client_service_manager_missing` + hint mentioning systemd `--user`
|
|
67
|
+
* or launchctl.
|
|
68
|
+
* Caller handler maps the error via `emitServiceError(... e.code, e.message, e.hint)`. */
|
|
69
|
+
export declare function ensureSupportedPlatform(opts?: EnsureSupportedPlatformOptions): Promise<"linux-systemd-user" | "darwin-launchd-user">;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import type { ServiceTarget } from "./types";
|
|
2
|
+
import { type ServiceExecFile } from "./platform";
|
|
3
|
+
export declare class AlreadyInstalledDiffError extends Error {
|
|
4
|
+
readonly code: "client_already_installed_diff";
|
|
5
|
+
readonly hint?: string;
|
|
6
|
+
constructor(message: string, hint?: string);
|
|
7
|
+
}
|
|
8
|
+
export declare class NotInstalledError extends Error {
|
|
9
|
+
readonly code: "client_not_installed";
|
|
10
|
+
readonly hint?: string;
|
|
11
|
+
constructor(message: string, hint?: string);
|
|
12
|
+
}
|
|
13
|
+
export declare class InstallFailedError extends Error {
|
|
14
|
+
readonly code: "client_install_failed";
|
|
15
|
+
readonly hint?: string;
|
|
16
|
+
/** Stage the failure happened at — useful for human-mode messages. */
|
|
17
|
+
readonly stage: "daemon-reload" | "enable" | "start";
|
|
18
|
+
constructor(stage: InstallFailedError["stage"], message: string, hint?: string);
|
|
19
|
+
}
|
|
20
|
+
export declare class UninstallFailedError extends Error {
|
|
21
|
+
readonly code: "client_uninstall_failed";
|
|
22
|
+
readonly hint?: string;
|
|
23
|
+
constructor(message: string, hint?: string);
|
|
24
|
+
}
|
|
25
|
+
export declare class StartFailedError extends Error {
|
|
26
|
+
readonly code: "client_start_failed";
|
|
27
|
+
readonly hint?: string;
|
|
28
|
+
constructor(message: string, hint?: string);
|
|
29
|
+
}
|
|
30
|
+
export declare class StopFailedError extends Error {
|
|
31
|
+
readonly code: "client_stop_failed";
|
|
32
|
+
readonly hint?: string;
|
|
33
|
+
constructor(message: string, hint?: string);
|
|
34
|
+
}
|
|
35
|
+
export declare function quoteSystemdExecPath(p: string): string;
|
|
36
|
+
export declare const SYSTEMD_UNIT_NAME = "aifight.service";
|
|
37
|
+
export interface SystemdTargetOptions {
|
|
38
|
+
/** Absolute path of the resolved `aifight` binary. Step 4
|
|
39
|
+
* `resolveAifightExec()` produces this; tests inject any string. */
|
|
40
|
+
readonly aifightExec: string;
|
|
41
|
+
/** Absolute path of the unit file — typically
|
|
42
|
+
* `~/.config/systemd/user/aifight.service`. Tests inject a tmp dir. */
|
|
43
|
+
readonly unitPath: string;
|
|
44
|
+
/** AIFIGHT_RUNTIME_HOME baked into the unit. Tests inject any string. */
|
|
45
|
+
readonly runtimeHome: string;
|
|
46
|
+
/** Optional `--env-file` absolute path (rev3 B3 — systemd-only).
|
|
47
|
+
* Handler validates existence + chmod before passing here; target
|
|
48
|
+
* trusts the value. */
|
|
49
|
+
readonly envFile?: string;
|
|
50
|
+
/** Defaults to `defaultExecFile` (production). Tests pass a mock that
|
|
51
|
+
* records calls + returns canned stdout/stderr without spawning a
|
|
52
|
+
* real subprocess. */
|
|
53
|
+
readonly execFile?: ServiceExecFile;
|
|
54
|
+
}
|
|
55
|
+
export declare function createSystemdTarget(opts: SystemdTargetOptions): ServiceTarget;
|