@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.
Files changed (176) hide show
  1. package/README.md +160 -0
  2. package/dist/bin.mjs +291 -0
  3. package/dist/index.mjs +107 -0
  4. package/dist/schemas/README.md +57 -0
  5. package/dist/schemas/common/README.md +40 -0
  6. package/dist/schemas/common/action.schema.json +19 -0
  7. package/dist/schemas/common/error.schema.json +23 -0
  8. package/dist/schemas/common/event.schema.json +33 -0
  9. package/dist/schemas/common/game_result.schema.json +31 -0
  10. package/dist/schemas/common/player_identity.schema.json +29 -0
  11. package/dist/schemas/common/player_info.schema.json +27 -0
  12. package/dist/schemas/common/rules.schema.json +34 -0
  13. package/dist/schemas/games/README.md +43 -0
  14. package/dist/schemas/games/coup/README.md +104 -0
  15. package/dist/schemas/games/coup/action.schema.json +198 -0
  16. package/dist/schemas/games/coup/event.schema.json +249 -0
  17. package/dist/schemas/games/coup/rules.schema.json +46 -0
  18. package/dist/schemas/games/coup/state.schema.json +123 -0
  19. package/dist/schemas/games/liars_dice/README.md +59 -0
  20. package/dist/schemas/games/liars_dice/action.schema.json +45 -0
  21. package/dist/schemas/games/liars_dice/event.schema.json +120 -0
  22. package/dist/schemas/games/liars_dice/rules.schema.json +36 -0
  23. package/dist/schemas/games/liars_dice/state.schema.json +72 -0
  24. package/dist/schemas/games/texas_holdem/README.md +58 -0
  25. package/dist/schemas/games/texas_holdem/action.schema.json +88 -0
  26. package/dist/schemas/games/texas_holdem/config.schema.json +30 -0
  27. package/dist/schemas/games/texas_holdem/event.schema.json +135 -0
  28. package/dist/schemas/games/texas_holdem/rules.schema.json +39 -0
  29. package/dist/schemas/games/texas_holdem/state.schema.json +98 -0
  30. package/dist/schemas/messages/README.md +98 -0
  31. package/dist/schemas/messages/client_action.schema.json +20 -0
  32. package/dist/schemas/messages/client_join_queue.schema.json +39 -0
  33. package/dist/schemas/messages/client_leave_queue.schema.json +18 -0
  34. package/dist/schemas/messages/client_match_confirm.schema.json +25 -0
  35. package/dist/schemas/messages/client_runtime_status.schema.json +46 -0
  36. package/dist/schemas/messages/server_action_request.schema.json +71 -0
  37. package/dist/schemas/messages/server_error.schema.json +16 -0
  38. package/dist/schemas/messages/server_event.schema.json +30 -0
  39. package/dist/schemas/messages/server_game_over.schema.json +49 -0
  40. package/dist/schemas/messages/server_game_start.schema.json +99 -0
  41. package/dist/schemas/messages/server_game_state.schema.json +33 -0
  42. package/dist/schemas/messages/server_match_cancelled.schema.json +51 -0
  43. package/dist/schemas/messages/server_match_confirm_request.schema.json +37 -0
  44. package/dist/schemas/messages/server_queue_joined.schema.json +26 -0
  45. package/dist/schemas/messages/server_queue_left.schema.json +24 -0
  46. package/dist/schemas/messages/server_readiness_check.schema.json +42 -0
  47. package/dist/schemas/messages/server_welcome.schema.json +49 -0
  48. package/dist/schemas/rest/README.md +85 -0
  49. package/dist/schemas/rest/agent_status_response.schema.json +34 -0
  50. package/dist/schemas/rest/claim_request.schema.json +20 -0
  51. package/dist/schemas/rest/claim_response.schema.json +24 -0
  52. package/dist/schemas/rest/error_response.schema.json +15 -0
  53. package/dist/schemas/rest/register_request.schema.json +35 -0
  54. package/dist/schemas/rest/register_response.schema.json +54 -0
  55. package/dist/types/account/credentials.d.ts +29 -0
  56. package/dist/types/account/errors.d.ts +61 -0
  57. package/dist/types/account/registration.d.ts +26 -0
  58. package/dist/types/agents/agent.d.ts +82 -0
  59. package/dist/types/agents/state-machine.d.ts +96 -0
  60. package/dist/types/bridge/config.d.ts +35 -0
  61. package/dist/types/bridge/hermes-provider.d.ts +9 -0
  62. package/dist/types/bridge/openclaw-provider.d.ts +9 -0
  63. package/dist/types/bridge/pairing.d.ts +18 -0
  64. package/dist/types/bridge/provider.d.ts +18 -0
  65. package/dist/types/bridge/runner.d.ts +30 -0
  66. package/dist/types/bridge/service.d.ts +55 -0
  67. package/dist/types/bridge/update-check.d.ts +23 -0
  68. package/dist/types/cli/agent-resolver.d.ts +25 -0
  69. package/dist/types/cli/argv.d.ts +13 -0
  70. package/dist/types/cli/commands/agent-list.d.ts +2 -0
  71. package/dist/types/cli/commands/agent-status.d.ts +2 -0
  72. package/dist/types/cli/commands/bridge-accept.d.ts +2 -0
  73. package/dist/types/cli/commands/bridge-challenge.d.ts +2 -0
  74. package/dist/types/cli/commands/bridge-connect.d.ts +2 -0
  75. package/dist/types/cli/commands/bridge-register.d.ts +2 -0
  76. package/dist/types/cli/commands/bridge-run.d.ts +7 -0
  77. package/dist/types/cli/commands/bridge-service.d.ts +3 -0
  78. package/dist/types/cli/commands/bridge-set.d.ts +2 -0
  79. package/dist/types/cli/commands/bridge-start.d.ts +2 -0
  80. package/dist/types/cli/commands/bridge-status.d.ts +2 -0
  81. package/dist/types/cli/commands/bridge-uninstall.d.ts +4 -0
  82. package/dist/types/cli/commands/config-init.d.ts +2 -0
  83. package/dist/types/cli/commands/config-probe.d.ts +2 -0
  84. package/dist/types/cli/commands/config-validate.d.ts +2 -0
  85. package/dist/types/cli/commands/daily-off.d.ts +2 -0
  86. package/dist/types/cli/commands/daily-on.d.ts +2 -0
  87. package/dist/types/cli/commands/daily-set.d.ts +2 -0
  88. package/dist/types/cli/commands/daily-show.d.ts +2 -0
  89. package/dist/types/cli/commands/doctor.d.ts +2 -0
  90. package/dist/types/cli/commands/init.d.ts +2 -0
  91. package/dist/types/cli/commands/join.d.ts +2 -0
  92. package/dist/types/cli/commands/leave.d.ts +2 -0
  93. package/dist/types/cli/commands/mcp.d.ts +2 -0
  94. package/dist/types/cli/commands/runtime-management.d.ts +16 -0
  95. package/dist/types/cli/commands/runtime-setup-state.d.ts +21 -0
  96. package/dist/types/cli/commands/runtime-setup.d.ts +23 -0
  97. package/dist/types/cli/commands/serve.d.ts +2 -0
  98. package/dist/types/cli/commands/service/launchd.d.ts +71 -0
  99. package/dist/types/cli/commands/service/platform.d.ts +69 -0
  100. package/dist/types/cli/commands/service/systemd.d.ts +55 -0
  101. package/dist/types/cli/commands/service/types.d.ts +64 -0
  102. package/dist/types/cli/commands/service-install.d.ts +29 -0
  103. package/dist/types/cli/commands/setup.d.ts +2 -0
  104. package/dist/types/cli/commands/shutdown.d.ts +2 -0
  105. package/dist/types/cli/commands/stubs.d.ts +24 -0
  106. package/dist/types/cli/commands/version.d.ts +2 -0
  107. package/dist/types/cli/control-client.d.ts +59 -0
  108. package/dist/types/cli/format.d.ts +52 -0
  109. package/dist/types/cli/main.d.ts +18 -0
  110. package/dist/types/cli/runtime-files.d.ts +11 -0
  111. package/dist/types/cli/shared.d.ts +74 -0
  112. package/dist/types/controlapi/profile-routes.d.ts +49 -0
  113. package/dist/types/controlapi/server.d.ts +3 -0
  114. package/dist/types/controlapi/types.d.ts +136 -0
  115. package/dist/types/daemon/agent-decision-adapter.d.ts +40 -0
  116. package/dist/types/daemon/lifecycle.d.ts +85 -0
  117. package/dist/types/daemon/router.d.ts +97 -0
  118. package/dist/types/daemon/runtime-files-write.d.ts +76 -0
  119. package/dist/types/decision/direct-model/anthropic.d.ts +12 -0
  120. package/dist/types/decision/direct-model/errors.d.ts +59 -0
  121. package/dist/types/decision/direct-model/openai.d.ts +12 -0
  122. package/dist/types/decision/direct-model/types.d.ts +20 -0
  123. package/dist/types/decision/parser-types.d.ts +31 -0
  124. package/dist/types/decision/prompt-builder.d.ts +10 -0
  125. package/dist/types/decision/provider.d.ts +50 -0
  126. package/dist/types/decision/types.d.ts +87 -0
  127. package/dist/types/games/_shared/player-info.d.ts +14 -0
  128. package/dist/types/games/coup/action-parser.d.ts +3 -0
  129. package/dist/types/games/coup/fallback.d.ts +8 -0
  130. package/dist/types/games/coup/state-formatter.d.ts +14 -0
  131. package/dist/types/games/liars_dice/action-parser.d.ts +3 -0
  132. package/dist/types/games/liars_dice/fallback.d.ts +8 -0
  133. package/dist/types/games/liars_dice/state-formatter.d.ts +14 -0
  134. package/dist/types/games/texas_holdem/action-parser.d.ts +3 -0
  135. package/dist/types/games/texas_holdem/fallback.d.ts +8 -0
  136. package/dist/types/games/texas_holdem/state-formatter.d.ts +14 -0
  137. package/dist/types/identity/identity-manager.d.ts +59 -0
  138. package/dist/types/index.d.ts +30 -0
  139. package/dist/types/llm/adapter-registry.d.ts +27 -0
  140. package/dist/types/llm/adapters/anthropic-messages.d.ts +2 -0
  141. package/dist/types/llm/adapters/deepseek-chat-completions.d.ts +2 -0
  142. package/dist/types/llm/adapters/openai-chat-compat.d.ts +2 -0
  143. package/dist/types/llm/adapters/openai-chat-completions.d.ts +2 -0
  144. package/dist/types/llm/adapters/openai-responses.d.ts +2 -0
  145. package/dist/types/llm/adapters/types.d.ts +128 -0
  146. package/dist/types/llm/capabilities/validate-capabilities.d.ts +68 -0
  147. package/dist/types/mcp/control-client.d.ts +54 -0
  148. package/dist/types/mcp/profile-tools.d.ts +10 -0
  149. package/dist/types/mcp/server.d.ts +10 -0
  150. package/dist/types/mcp/tools.d.ts +31 -0
  151. package/dist/types/mcp/types.d.ts +27 -0
  152. package/dist/types/profile/config-schema.d.ts +199 -0
  153. package/dist/types/profile/identity-schema.d.ts +75 -0
  154. package/dist/types/profile/index.d.ts +7 -0
  155. package/dist/types/profile/migrate.d.ts +16 -0
  156. package/dist/types/profile/profile-loader.d.ts +64 -0
  157. package/dist/types/profile/secret-ref.d.ts +82 -0
  158. package/dist/types/profile/soul.d.ts +46 -0
  159. package/dist/types/profile/strategy-schema.d.ts +70 -0
  160. package/dist/types/protocol/schemas.d.ts +11 -0
  161. package/dist/types/protocol/types.d.ts +1333 -0
  162. package/dist/types/reflection/proposal-store.d.ts +50 -0
  163. package/dist/types/reflection/reflection-engine.d.ts +81 -0
  164. package/dist/types/scheduler/daily.d.ts +47 -0
  165. package/dist/types/scheduler/types.d.ts +42 -0
  166. package/dist/types/session/match-session-manager.d.ts +113 -0
  167. package/dist/types/session/session-context-builder.d.ts +68 -0
  168. package/dist/types/store/errors.d.ts +23 -0
  169. package/dist/types/store/paths.d.ts +3 -0
  170. package/dist/types/store/schema.generated.d.ts +1 -0
  171. package/dist/types/store/sqlite.d.ts +36 -0
  172. package/dist/types/wsclient/client.d.ts +220 -0
  173. package/dist/types/wsclient/errors.d.ts +106 -0
  174. package/dist/types/wsclient/frame-handler.d.ts +20 -0
  175. package/dist/types/wsclient/reconnect.d.ts +84 -0
  176. package/package.json +53 -0
@@ -0,0 +1,59 @@
1
+ import type { AgentIdentity } from "../profile/identity-schema.js";
2
+ export type PlatformEnvironment = "local" | "beta" | "prod";
3
+ export interface RegisterAgentOptions {
4
+ readonly agentSlug: string;
5
+ readonly displayName: string;
6
+ readonly model?: string;
7
+ readonly description?: string;
8
+ readonly environment: PlatformEnvironment;
9
+ readonly platformBaseURL: string;
10
+ readonly hostType?: string;
11
+ }
12
+ export interface RegisterAgentResult {
13
+ readonly agentId: string;
14
+ readonly apiKey: string;
15
+ readonly claimUrl?: string;
16
+ readonly claimToken?: string;
17
+ }
18
+ export interface IdentityStatus {
19
+ readonly agentSlug: string;
20
+ readonly hasIdentity: boolean;
21
+ readonly environment?: string;
22
+ readonly platformAgentId?: string;
23
+ readonly apiKeyAvailable: boolean;
24
+ }
25
+ export declare function getPlatformBaseURL(env: PlatformEnvironment): string;
26
+ /**
27
+ * Register a new agent on the AIFight platform and store identity locally.
28
+ */
29
+ export declare function registerAgent(opts: RegisterAgentOptions): Promise<{
30
+ identity: AgentIdentity;
31
+ result: RegisterAgentResult;
32
+ }>;
33
+ /**
34
+ * Load identity.json for an agent slug.
35
+ */
36
+ export declare function loadIdentity(agentSlug: string): Promise<AgentIdentity | null>;
37
+ /**
38
+ * Resolve the platform API key from identity's SecretRef.
39
+ */
40
+ export declare function resolvePlatformApiKey(identity: AgentIdentity): Promise<string>;
41
+ /**
42
+ * Check identity status without resolving secrets.
43
+ */
44
+ export declare function checkIdentityStatus(agentSlug: string): Promise<IdentityStatus>;
45
+ /**
46
+ * Verify platform identity by calling /api/agents/me/status.
47
+ */
48
+ export declare function verifyPlatformIdentity(identity: AgentIdentity): Promise<{
49
+ verified: boolean;
50
+ agentId?: string;
51
+ isClaimed?: boolean;
52
+ error?: string;
53
+ }>;
54
+ /**
55
+ * Rotate the platform agent API key.
56
+ */
57
+ export declare function rotatePlatformApiKey(agentSlug: string, ownerToken: string): Promise<{
58
+ newApiKey: string;
59
+ }>;
@@ -0,0 +1,30 @@
1
+ export * from "./protocol/types";
2
+ export { findSchemasRoot, loadSchema, loadAllSchemas, loadRestSchema, messageTypes, type MessageType, type RestSchemaName, } from "./protocol/schemas";
3
+ export { registerAgent, type RegisterAgentOptions, type RegisterAgentResult, } from "./account/registration";
4
+ export { RegisterError, RegisterNetworkError, RegisterHttpError, RegisterSchemaError, type RegisterErrorKind, type AjvLikeError, } from "./account/errors";
5
+ export { openDatabase, type OpenDatabaseOptions, type StoreHandle, type AgentRow, type UpsertAgentInput, } from "./store/sqlite";
6
+ export { getRuntimeHome, getDefaultDbPath, ensureRuntimeHome, } from "./store/paths";
7
+ export { StoreError, StoreOpenError, StoreMigrationError, StoreQueryError, type StoreErrorKind, } from "./store/errors";
8
+ export { AIFIGHT_KEYCHAIN_V1_PREFIX, AIFIGHT_CRYPTO_V1_PREFIX, AIFIGHT_RUNTIME_SERVICE, encryptForStorage, decryptFromStorage, deleteFromStorage, isKeychainAvailable, getCredentialsBackend, type CredentialsBackendInfo, } from "./account/credentials";
9
+ export { CredentialsError, CredentialsKeychainUnavailableError, CredentialsCryptoError, CredentialsCorruptError, type CredentialsErrorKind, } from "./account/errors";
10
+ export { createWSClient } from "./wsclient/client";
11
+ export type { WSClient, WSClientMessage, WSClientOptions, WSWelcome, WSCloseInfo, WSMessageHandler, WSErrorHandler, WSCloseHandler, } from "./wsclient/client";
12
+ export type { ServerMessageEnvelope } from "./wsclient/frame-handler";
13
+ export { WSClientError, WSConnectError, WSHandshakeError, WSWelcomeTimeoutError, WSWelcomeInvalidError, WSProtocolVersionError, WSClosedError, WSSchemaError, WSOutboundSchemaError, WSUnknownMessageError, WSAbortedError, } from "./wsclient/errors";
14
+ export type { WSClientErrorKind } from "./wsclient/errors";
15
+ export { createReconnectingWSClient, ReconnectStoppedError, } from "./wsclient/reconnect";
16
+ export type { ReconnectingWSClient, ReconnectingWSClientOptions, ReconnectEvent, ReconnectEventHandler, ReconnectCloseInfo, ReconnectCloseHandler, ReconnectStopReason, JitterStrategy, } from "./wsclient/reconnect";
17
+ export { createDirectModelProvider, DecisionProviderError, } from "./decision/provider";
18
+ export type { DecisionProvider, DirectModelProviderOptions, DirectModelProviderName, DecisionProviderErrorKind, } from "./decision/provider";
19
+ export type { DecisionRequest, DecisionResponse, DecisionResponseProviderMetadata, StrategyProfile, GameSpecificProfile, GameType, GameRules, LegalAction, } from "./decision/types";
20
+ export type { ParseResult, ParseInvalidReason, } from "./decision/parser-types";
21
+ export declare const RUNTIME_VERSION = "0.1.0-alpha.1";
22
+ export declare const PROTOCOL_VERSION = "v1.0.0";
23
+ export interface HelloResult {
24
+ ok: true;
25
+ runtimeVersion: string;
26
+ schemaCount: number;
27
+ messageTypeCount: number;
28
+ schemasRoot: string;
29
+ }
30
+ export declare function hello(): HelloResult;
@@ -0,0 +1,27 @@
1
+ import type { LLMAdapter, LLMProtocol } from "./adapters/types.js";
2
+ /**
3
+ * Register an adapter for a protocol. Overwrites any existing adapter
4
+ * for the same protocol (useful for testing).
5
+ */
6
+ export declare function registerAdapter(adapter: LLMAdapter): void;
7
+ /**
8
+ * Get the adapter for a protocol. Returns undefined if not registered.
9
+ */
10
+ export declare function getAdapter(protocol: LLMProtocol | string): LLMAdapter | undefined;
11
+ /**
12
+ * Get the adapter for a protocol, or throw if not registered.
13
+ */
14
+ export declare function requireAdapter(protocol: LLMProtocol | string): LLMAdapter;
15
+ /**
16
+ * List all registered protocol names.
17
+ */
18
+ export declare function listRegisteredProtocols(): string[];
19
+ /**
20
+ * Clear all registered adapters (for testing).
21
+ */
22
+ export declare function clearAdapters(): void;
23
+ /**
24
+ * Register all built-in P0 adapters. Called at daemon startup.
25
+ * Lazy-imports adapters to keep the registry module lightweight.
26
+ */
27
+ export declare function registerBuiltinAdapters(): Promise<void>;
@@ -0,0 +1,2 @@
1
+ import type { LLMAdapter } from "./types.js";
2
+ export declare function createAnthropicMessagesAdapter(): LLMAdapter;
@@ -0,0 +1,2 @@
1
+ import type { LLMAdapter } from "./types.js";
2
+ export declare function createDeepSeekChatCompletionsAdapter(): LLMAdapter;
@@ -0,0 +1,2 @@
1
+ import type { LLMAdapter } from "./types.js";
2
+ export declare function createOpenAIChatCompatAdapter(): LLMAdapter;
@@ -0,0 +1,2 @@
1
+ import type { LLMAdapter } from "./types.js";
2
+ export declare function createOpenAIChatCompletionsAdapter(): LLMAdapter;
@@ -0,0 +1,2 @@
1
+ import type { LLMAdapter } from "./types.js";
2
+ export declare function createOpenAIResponsesAdapter(): LLMAdapter;
@@ -0,0 +1,128 @@
1
+ export type ReasoningEffort = "off" | "minimal" | "low" | "medium" | "high" | "xhigh" | "max" | "auto";
2
+ export interface CanonicalReasoningConfig {
3
+ readonly enabled?: boolean | "auto";
4
+ readonly mode?: "disabled" | "enabled" | "adaptive" | "auto";
5
+ readonly effort?: ReasoningEffort;
6
+ readonly budgetTokens?: number | null;
7
+ readonly taskBudgetTokens?: number | null;
8
+ readonly thinkingLevel?: "minimal" | "low" | "medium" | "high" | null;
9
+ readonly thinkingBudget?: number | null;
10
+ readonly display?: "omitted" | "summarized" | null;
11
+ readonly summary?: "off" | "auto" | "concise" | "detailed" | null;
12
+ readonly includeEncryptedReasoning?: boolean;
13
+ }
14
+ export declare const SUPPORTED_PROTOCOLS: readonly ["anthropic_messages", "openai_responses", "openai_chat_completions", "openai_chat_compat", "deepseek_chat_completions", "gemini_generate_content", "gemini_openai_compat"];
15
+ export type LLMProtocol = (typeof SUPPORTED_PROTOCOLS)[number];
16
+ export interface DecisionInput {
17
+ /** System prompt assembled from soul + strategy + rules + context */
18
+ readonly systemPrompt: string;
19
+ /** User prompt with current state + legal actions + output contract */
20
+ readonly userPrompt: string;
21
+ /** Max output tokens for this decision */
22
+ readonly maxTokens: number;
23
+ /** Temperature (null = provider default) */
24
+ readonly temperature: number | null;
25
+ /** Canonical reasoning config (adapter translates to provider format) */
26
+ readonly reasoning?: CanonicalReasoningConfig;
27
+ /** Response format hint */
28
+ readonly responseFormat?: "json" | "json_object" | "json_schema" | "text";
29
+ /** Abort signal for timeout */
30
+ readonly signal?: AbortSignal;
31
+ }
32
+ export interface DecisionOutput {
33
+ /** Raw text response from the model */
34
+ readonly text: string;
35
+ /** Input tokens used */
36
+ readonly inputTokens?: number;
37
+ /** Output tokens used (includes reasoning tokens for some providers) */
38
+ readonly outputTokens?: number;
39
+ /** Reasoning/thinking tokens (if separately reported) */
40
+ readonly reasoningTokens?: number;
41
+ /** Cached tokens (if provider reports) */
42
+ readonly cachedTokens?: number;
43
+ /** Response latency in ms */
44
+ readonly latencyMs: number;
45
+ /** Short reasoning summary if provider supports it */
46
+ readonly reasoningSummary?: string;
47
+ /** Raw provider response (for debugging, usually redacted before storage) */
48
+ readonly raw?: unknown;
49
+ /** Provider-specific continuation state to preserve within this match session */
50
+ readonly continuationState?: unknown;
51
+ }
52
+ export interface UsageRecord {
53
+ readonly protocol: string;
54
+ readonly providerLabel: string;
55
+ readonly model: string;
56
+ readonly inputTokens?: number;
57
+ readonly outputTokens?: number;
58
+ readonly reasoningTokens?: number;
59
+ readonly cachedTokens?: number;
60
+ readonly estimatedCostUSD?: number;
61
+ readonly latencyMs: number;
62
+ readonly timestamp: string;
63
+ }
64
+ export interface ProbeResult {
65
+ readonly success: boolean;
66
+ readonly latencyMs: number;
67
+ readonly error?: string;
68
+ readonly model: string;
69
+ readonly protocol: string;
70
+ /** Whether the model returned valid JSON when asked */
71
+ readonly jsonValid?: boolean;
72
+ }
73
+ export interface ValidationResult {
74
+ readonly ok: boolean;
75
+ readonly errors: string[];
76
+ readonly warnings: string[];
77
+ }
78
+ export interface LLMProfile {
79
+ readonly profileId: string;
80
+ readonly displayName: string;
81
+ readonly protocol: LLMProtocol;
82
+ readonly baseURL: string;
83
+ readonly model: string;
84
+ readonly apiKey: string;
85
+ readonly temperature: number | null;
86
+ readonly maxTokens: number;
87
+ readonly responseFormat?: string;
88
+ readonly reasoning?: CanonicalReasoningConfig;
89
+ readonly timeouts: {
90
+ readonly requestMs: number;
91
+ readonly connectMs: number;
92
+ };
93
+ readonly retries: {
94
+ readonly maxAttempts: number;
95
+ readonly backoffMs: number;
96
+ };
97
+ readonly budgets?: {
98
+ readonly maxCostUSDPerMatch?: number;
99
+ readonly maxCostUSDPerDay?: number;
100
+ readonly maxOutputTokensPerDecision?: number;
101
+ };
102
+ }
103
+ export interface LLMAdapter {
104
+ /** Protocol this adapter handles */
105
+ readonly protocol: LLMProtocol;
106
+ /** Validate a profile against this adapter's capabilities */
107
+ validateProfile(profile: LLMProfile): ValidationResult;
108
+ /** Make a probe/test call to verify connectivity and JSON response */
109
+ probe(profile: LLMProfile): Promise<ProbeResult>;
110
+ /** Build and send a decision request, return parsed output */
111
+ generateDecision(input: DecisionInput, profile: LLMProfile, continuationState?: unknown): Promise<DecisionOutput>;
112
+ /** Estimate cost from a completed response */
113
+ estimateUsage(output: DecisionOutput, profile: LLMProfile): UsageRecord;
114
+ /** Redact sensitive data from raw provider response */
115
+ redact(raw: unknown): unknown;
116
+ }
117
+ export type AdapterErrorKind = "auth_failed" | "rate_limited" | "model_not_found" | "invalid_request" | "server_error" | "timeout" | "network" | "aborted" | "invalid_response" | "unsupported" | "budget_exceeded" | "unknown";
118
+ export declare class AdapterError extends Error {
119
+ readonly name = "AdapterError";
120
+ readonly kind: AdapterErrorKind;
121
+ readonly protocol: string;
122
+ readonly retryable: boolean;
123
+ readonly cause: unknown;
124
+ constructor(kind: AdapterErrorKind, protocol: string, message: string, opts?: {
125
+ retryable?: boolean;
126
+ cause?: unknown;
127
+ });
128
+ }
@@ -0,0 +1,68 @@
1
+ export interface ModelCapability {
2
+ /** Regex pattern matched against the model string (e.g. "^claude-opus-4-7"). */
3
+ pattern: string;
4
+ /** Thinking modes the model accepts, e.g. ["adaptive"]. */
5
+ thinkingModes?: string[];
6
+ /** Effort levels accepted by this specific model (subset of protocol effortValues). */
7
+ efforts?: string[];
8
+ /** Per-model default effort override (falls back to protocol defaultEffort). */
9
+ defaultEffort?: string;
10
+ /** True if the model accepts a manual budget_tokens parameter. */
11
+ supportsManualBudget?: boolean;
12
+ /** False if the model ignores temperature even when the protocol supports it. */
13
+ supportsTemperature?: boolean;
14
+ /** True if temperature/top_p are silently ignored in thinking mode. */
15
+ samplingIgnoredWhenThinking?: boolean;
16
+ /** Maximum output tokens the model can produce. */
17
+ maxOutputTokens: number;
18
+ /** Protocol-specific thinking API parameter name, e.g. "thinkingLevel" | "thinkingBudget". */
19
+ thinkingParam?: string;
20
+ /** Free-text notes for operators. Not used in validation logic. */
21
+ notes?: string;
22
+ }
23
+ export interface ProtocolCapability {
24
+ displayName: string;
25
+ defaultBaseURL: string;
26
+ supportsBaseURL: boolean;
27
+ /** true | false | "ignored_when_thinking" */
28
+ supportsTemperature: boolean | string;
29
+ supportsJSONMode: boolean;
30
+ supportsThinking: boolean;
31
+ supportsReasoningSummary: boolean;
32
+ /** Request parameter name for the token limit, e.g. "max_tokens". */
33
+ maxTokensParam: string;
34
+ /** All effort levels the protocol understands. */
35
+ effortValues: string[];
36
+ defaultEffort?: string;
37
+ /** Optional effort remapping for protocols with a restricted effort vocabulary. */
38
+ compatEffortMap?: Record<string, string>;
39
+ models: ModelCapability[];
40
+ notes?: string;
41
+ }
42
+ export interface CapabilityRegistry {
43
+ schemaVersion: number;
44
+ protocols: Record<string, ProtocolCapability>;
45
+ }
46
+ export interface ThinkingConfig {
47
+ /** "adaptive" | "enabled" | "disabled" or protocol-specific value */
48
+ mode?: string;
49
+ /** Explicit budget_tokens (only for protocols/models that support manual budget). */
50
+ budgetTokens?: number;
51
+ /** "low" | "medium" | "high" | "xhigh" | "max" | "none" | "minimal" */
52
+ effort?: string;
53
+ }
54
+ export declare function loadCapabilityRegistry(): CapabilityRegistry;
55
+ export declare function validateProfileAgainstCapabilities(protocol: string, model: string, thinking: ThinkingConfig | undefined, registry: CapabilityRegistry): {
56
+ ok: true;
57
+ } | {
58
+ ok: false;
59
+ errors: string[];
60
+ warnings: string[];
61
+ };
62
+ export declare function getDefaultBaseURL(protocol: string, registry: CapabilityRegistry): string | undefined;
63
+ export declare function mapEffortForProtocol(effort: string, protocol: string, registry: CapabilityRegistry): {
64
+ mapped: string;
65
+ warning?: string;
66
+ } | {
67
+ error: string;
68
+ };
@@ -0,0 +1,54 @@
1
+ export interface ControlClientPaths {
2
+ tokenPath: string;
3
+ portPath: string;
4
+ }
5
+ export interface ControlCredentials {
6
+ token: string;
7
+ port: number;
8
+ }
9
+ export interface RequestOptions {
10
+ method?: "GET" | "POST" | "DELETE" | "PUT" | "PATCH";
11
+ body?: unknown;
12
+ signal?: AbortSignal;
13
+ }
14
+ export type FetchLike = (input: string, init?: RequestInit) => Promise<Response>;
15
+ export interface ControlClientOptions {
16
+ paths?: ControlClientPaths;
17
+ fetch?: FetchLike;
18
+ /**
19
+ * Per-request timeout (covers fetch headers + body read). Default
20
+ * 10000ms — same baseline as the M1 CLI control-client. Tests inject
21
+ * a small value (e.g. 50ms) to assert the timeout path without
22
+ * waiting in real time.
23
+ */
24
+ baseTimeoutMs?: number;
25
+ }
26
+ export interface ControlClient {
27
+ request<T = unknown>(path: string, opts?: RequestOptions): Promise<T>;
28
+ }
29
+ /**
30
+ * Discriminated kind for RuntimeUnavailableError. Used by mcp/tools.ts
31
+ * to emit a whitelist user-facing message that does NOT echo the raw
32
+ * fetch error / URL / port — those would leak via MCP `text` content
33
+ * which the host typically records and uploads to telemetry.
34
+ */
35
+ export type RuntimeUnavailableKind = "unreachable" | "timeout" | "unauthorized" | "files_corrupt" | "other";
36
+ export declare class RuntimeUnavailableError extends Error {
37
+ readonly name = "RuntimeUnavailableError";
38
+ readonly kind: RuntimeUnavailableKind;
39
+ readonly attempts: number;
40
+ constructor(kind: RuntimeUnavailableKind, message: string, attempts: number, options?: ErrorOptions);
41
+ }
42
+ export declare function getDefaultControlClientPaths(homedir?: string): ControlClientPaths;
43
+ /**
44
+ * Non-retryable HTTP error from the controlapi (4xx/5xx other than 401).
45
+ * Tool handlers turn this into a structured `{isError:true}` MCP
46
+ * result so the client sees a tool-level error.
47
+ */
48
+ export declare class ControlHttpError extends Error {
49
+ readonly name = "ControlHttpError";
50
+ readonly status: number;
51
+ readonly bodyText: string;
52
+ constructor(status: number, bodyText: string);
53
+ }
54
+ export declare function createControlClient(opts?: ControlClientOptions): ControlClient;
@@ -0,0 +1,10 @@
1
+ import { type ControlClient } from "./control-client.js";
2
+ import type { McpTool, McpToolResult } from "./tools.js";
3
+ export declare const PROFILE_TOOLS: readonly McpTool[];
4
+ export declare const PROFILE_TOOL_NAMES: string[];
5
+ /**
6
+ * Dispatch a profile tool call by name.
7
+ * Returns a structured McpToolResult — never throws.
8
+ * Call this from mcp/server.ts CallTool handler after checking MCP_TOOL_NAMES.
9
+ */
10
+ export declare function handleProfileTool(client: ControlClient, name: string, args: Record<string, unknown>): Promise<McpToolResult>;
@@ -0,0 +1,10 @@
1
+ import { Server } from "@modelcontextprotocol/sdk/server/index.js";
2
+ import { type McpServerOptions } from "./types.js";
3
+ export declare function createMcpServer(opts?: McpServerOptions): Server;
4
+ /**
5
+ * Spawn the MCP server bound to the process's stdio. Returns the
6
+ * connected server instance — the caller is expected to keep the
7
+ * process alive (the SDK handles JSON-RPC dispatch via its own event
8
+ * loop). Caller may call `server.close()` for graceful shutdown.
9
+ */
10
+ export declare function runMcpServer(opts?: McpServerOptions): Promise<Server>;
@@ -0,0 +1,31 @@
1
+ import { type ControlClient } from "./control-client.js";
2
+ export interface McpToolResult {
3
+ content: Array<{
4
+ type: "text";
5
+ text: string;
6
+ }>;
7
+ isError?: boolean;
8
+ }
9
+ export interface McpTool {
10
+ readonly name: string;
11
+ readonly description: string;
12
+ readonly inputSchema: Record<string, unknown>;
13
+ readonly handler: (client: ControlClient, args: Record<string, unknown>) => Promise<McpToolResult>;
14
+ }
15
+ /**
16
+ * M5-13 B7 — `ping` is intercepted by mcp/server.ts BEFORE registry
17
+ * dispatch, because the response includes daemon-independent uptime_ms
18
+ * which only the server-construction path knows. The metadata is
19
+ * exported separately (not in MCP_TOOLS) so ListTools can still
20
+ * advertise it without keeping a dead handler stub in the registry.
21
+ *
22
+ * Sealed contract: ListTools must return ping FIRST in the tool list;
23
+ * see runtime/tests/mcp-tools.test.ts:87 for the order assertion.
24
+ */
25
+ export declare const PING_METADATA: {
26
+ name: "ping";
27
+ description: string;
28
+ inputSchema: Record<string, unknown>;
29
+ };
30
+ export declare const MCP_TOOLS: readonly McpTool[];
31
+ export declare const MCP_TOOL_NAMES: string[];
@@ -0,0 +1,27 @@
1
+ import type { ControlClient } from "./control-client.js";
2
+ export declare const MCP_SERVER_NAME = "aifight";
3
+ /**
4
+ * Re-export of the canonical tool-name list. Sourced from tools.ts so
5
+ * the MCP_TOOL_NAMES constant stays in lockstep with MCP_TOOLS itself.
6
+ * (M3-01 had this constant local; M3-02 promotes it to tools.ts because
7
+ * the tool definitions are now the source of truth.)
8
+ */
9
+ export { MCP_TOOL_NAMES } from "./tools.js";
10
+ export interface McpServerOptions {
11
+ /** Override the server name (default "aifight"). */
12
+ serverName?: string;
13
+ /** Server version reported on initialize handshake. */
14
+ version?: string;
15
+ /**
16
+ * Used by `ping` to compute uptime_ms. Defaults to `Date.now()`
17
+ * at construction time. Tests inject a fixed value so the uptime
18
+ * assertion is deterministic.
19
+ */
20
+ startedAtMs?: number;
21
+ /**
22
+ * (M3-02) HTTP client to the local controlapi. When omitted,
23
+ * controlapi-bound tools (everything except `ping`) return
24
+ * isError:true with a message telling the user to start the daemon.
25
+ */
26
+ controlClient?: ControlClient;
27
+ }