qlogicagent 0.3.0 → 0.4.0

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 (119) hide show
  1. package/README.md +45 -45
  2. package/package.json +1 -1
  3. package/dist/agent.js +0 -1
  4. package/dist/cli.js +0 -9
  5. package/dist/contracts.js +0 -1
  6. package/dist/index.js +0 -5
  7. package/dist/orchestration.js +0 -118
  8. package/dist/types/agent/agent.d.ts +0 -43
  9. package/dist/types/agent/tool-loop.d.ts +0 -64
  10. package/dist/types/agent/types.d.ts +0 -175
  11. package/dist/types/cli/main.d.ts +0 -11
  12. package/dist/types/cli/stdio-server.d.ts +0 -45
  13. package/dist/types/config/config.d.ts +0 -17
  14. package/dist/types/contracts/hooks.d.ts +0 -120
  15. package/dist/types/contracts/index.d.ts +0 -10
  16. package/dist/types/contracts/planner.d.ts +0 -35
  17. package/dist/types/contracts/skill-candidate.d.ts +0 -63
  18. package/dist/types/contracts/todo.d.ts +0 -14
  19. package/dist/types/index.d.ts +0 -13
  20. package/dist/types/llm/builtin-providers.d.ts +0 -10
  21. package/dist/types/llm/index.d.ts +0 -15
  22. package/dist/types/llm/llm-client.d.ts +0 -43
  23. package/dist/types/llm/model-catalog.d.ts +0 -53
  24. package/dist/types/llm/provider-def.d.ts +0 -59
  25. package/dist/types/llm/provider-registry.d.ts +0 -54
  26. package/dist/types/llm/transport.d.ts +0 -62
  27. package/dist/types/llm/transports/anthropic-messages.d.ts +0 -31
  28. package/dist/types/llm/transports/openai-chat.d.ts +0 -36
  29. package/dist/types/orchestration/agent-registry.d.ts +0 -41
  30. package/dist/types/orchestration/approval-aware-tool-plan.d.ts +0 -32
  31. package/dist/types/orchestration/context-compression.d.ts +0 -220
  32. package/dist/types/orchestration/conversation-repair.d.ts +0 -61
  33. package/dist/types/orchestration/curator-scheduler.d.ts +0 -119
  34. package/dist/types/orchestration/embedded-failover-policy.d.ts +0 -110
  35. package/dist/types/orchestration/error-classification.d.ts +0 -12
  36. package/dist/types/orchestration/failover-classification.d.ts +0 -8
  37. package/dist/types/orchestration/failover-error.d.ts +0 -33
  38. package/dist/types/orchestration/fork-subagent.d.ts +0 -100
  39. package/dist/types/orchestration/index.d.ts +0 -120
  40. package/dist/types/orchestration/memory-flush-policy.d.ts +0 -57
  41. package/dist/types/orchestration/memory-provider.d.ts +0 -14
  42. package/dist/types/orchestration/parallel-tool-calls.d.ts +0 -41
  43. package/dist/types/orchestration/prompt-cache-strategy.d.ts +0 -126
  44. package/dist/types/orchestration/reactive-compact.d.ts +0 -73
  45. package/dist/types/orchestration/retry-loop.d.ts +0 -22
  46. package/dist/types/orchestration/skill-candidate.d.ts +0 -52
  47. package/dist/types/orchestration/skill-consolidation.d.ts +0 -123
  48. package/dist/types/orchestration/skill-improvement.d.ts +0 -59
  49. package/dist/types/orchestration/skill-similarity.d.ts +0 -98
  50. package/dist/types/orchestration/streaming-tool-executor.d.ts +0 -73
  51. package/dist/types/orchestration/team-orchestration.d.ts +0 -195
  52. package/dist/types/orchestration/team-tool-loop-wiring.d.ts +0 -92
  53. package/dist/types/orchestration/tool-choice-policy.d.ts +0 -54
  54. package/dist/types/orchestration/tool-loop-state.d.ts +0 -50
  55. package/dist/types/orchestration/tool-schema.d.ts +0 -39
  56. package/dist/types/orchestration/transcript-repair.d.ts +0 -42
  57. package/dist/types/orchestration/turn-loop-guard.d.ts +0 -86
  58. package/dist/types/orchestration/web-browser-policy.d.ts +0 -17
  59. package/dist/types/runtime/context-compression.d.ts +0 -61
  60. package/dist/types/runtime/hook-registry.d.ts +0 -12
  61. package/dist/types/runtime/memory-hooks.d.ts +0 -23
  62. package/dist/types/runtime/tool-eligibility.d.ts +0 -59
  63. package/dist/types/skills/index.d.ts +0 -108
  64. package/dist/types/skills/memory-extractor.d.ts +0 -64
  65. package/dist/types/skills/memory-query-tool.d.ts +0 -43
  66. package/dist/types/skills/memory-store.d.ts +0 -66
  67. package/dist/types/skills/memory-tool.d.ts +0 -67
  68. package/dist/types/skills/portable-tool.d.ts +0 -71
  69. package/dist/types/skills/qmemory-adapter.d.ts +0 -52
  70. package/dist/types/skills/skill-frontmatter.d.ts +0 -19
  71. package/dist/types/skills/skill-guard.d.ts +0 -23
  72. package/dist/types/skills/skill-loader.d.ts +0 -16
  73. package/dist/types/skills/skill-source.d.ts +0 -119
  74. package/dist/types/skills/skill-types.d.ts +0 -199
  75. package/dist/types/skills/think-tool.d.ts +0 -16
  76. package/dist/types/skills/todo-tool.d.ts +0 -63
  77. package/dist/types/skills/tools/agent-tool.d.ts +0 -91
  78. package/dist/types/skills/tools/apply-patch-tool.d.ts +0 -29
  79. package/dist/types/skills/tools/ask-user-tool.d.ts +0 -80
  80. package/dist/types/skills/tools/brief-tool.d.ts +0 -74
  81. package/dist/types/skills/tools/browser-tool.d.ts +0 -114
  82. package/dist/types/skills/tools/checkpoint-tool.d.ts +0 -66
  83. package/dist/types/skills/tools/config-tool.d.ts +0 -63
  84. package/dist/types/skills/tools/cron-tool.d.ts +0 -116
  85. package/dist/types/skills/tools/edit-tool.d.ts +0 -43
  86. package/dist/types/skills/tools/exec-tool.d.ts +0 -102
  87. package/dist/types/skills/tools/image-generate-tool.d.ts +0 -62
  88. package/dist/types/skills/tools/instructions-tool.d.ts +0 -103
  89. package/dist/types/skills/tools/lsp-tool.d.ts +0 -153
  90. package/dist/types/skills/tools/mcp-client-types.d.ts +0 -269
  91. package/dist/types/skills/tools/mcp-tool.d.ts +0 -249
  92. package/dist/types/skills/tools/memory-tool.d.ts +0 -74
  93. package/dist/types/skills/tools/monitor-tool.d.ts +0 -113
  94. package/dist/types/skills/tools/music-generate-tool.d.ts +0 -55
  95. package/dist/types/skills/tools/notify-tool.d.ts +0 -53
  96. package/dist/types/skills/tools/patch-tool.d.ts +0 -45
  97. package/dist/types/skills/tools/pdf-tool.d.ts +0 -66
  98. package/dist/types/skills/tools/plan-mode-tool.d.ts +0 -59
  99. package/dist/types/skills/tools/read-tool.d.ts +0 -51
  100. package/dist/types/skills/tools/repl-tool.d.ts +0 -70
  101. package/dist/types/skills/tools/search-tool.d.ts +0 -112
  102. package/dist/types/skills/tools/send-message-tool.d.ts +0 -51
  103. package/dist/types/skills/tools/skill-list-tool.d.ts +0 -33
  104. package/dist/types/skills/tools/skill-manage-tool.d.ts +0 -73
  105. package/dist/types/skills/tools/skill-view-tool.d.ts +0 -37
  106. package/dist/types/skills/tools/sleep-tool.d.ts +0 -49
  107. package/dist/types/skills/tools/structured-output-tool.d.ts +0 -116
  108. package/dist/types/skills/tools/task-tool.d.ts +0 -104
  109. package/dist/types/skills/tools/team-tool.d.ts +0 -89
  110. package/dist/types/skills/tools/tool-search-tool.d.ts +0 -51
  111. package/dist/types/skills/tools/tts-tool.d.ts +0 -38
  112. package/dist/types/skills/tools/video-edit-tool.d.ts +0 -69
  113. package/dist/types/skills/tools/video-generate-tool.d.ts +0 -62
  114. package/dist/types/skills/tools/video-merge-tool.d.ts +0 -105
  115. package/dist/types/skills/tools/video-upscale-tool.d.ts +0 -45
  116. package/dist/types/skills/tools/web-fetch-tool.d.ts +0 -78
  117. package/dist/types/skills/tools/web-search-tool.d.ts +0 -57
  118. package/dist/types/skills/tools/worktree-tool.d.ts +0 -69
  119. package/dist/types/skills/tools/write-tool.d.ts +0 -45
@@ -1,45 +0,0 @@
1
- /**
2
- * StdioServer — JSON-RPC 2.0 over stdio protocol handler.
3
- *
4
- * Reads line-delimited JSON from stdin, dispatches to handlers,
5
- * writes JSON-RPC responses/notifications to stdout.
6
- * All log output goes to stderr.
7
- *
8
- * Protocol: each line on stdin/stdout is a single JSON-RPC 2.0 message.
9
- */
10
- export interface StdioServerConfig {
11
- verbose: boolean;
12
- }
13
- export declare class StdioServer {
14
- private running;
15
- private activeTurn;
16
- private pendingToolResults;
17
- private verbose;
18
- private registry;
19
- private agent;
20
- private lastLlmConfigKey;
21
- private currentSessionId;
22
- private currentHooks;
23
- constructor(config: StdioServerConfig);
24
- start(): void;
25
- stop(): void;
26
- private handleMessage;
27
- private handleHello;
28
- private handlePing;
29
- private handleAbort;
30
- private handleToolResult;
31
- private handleTurn;
32
- private resolveAgent;
33
- /**
34
- * Request tool execution from the Gateway host.
35
- * Sends a turn.tool_call notification and waits for tool.result.
36
- */
37
- requestToolExecution(turnId: string, name: string, args: string, signal?: AbortSignal): Promise<{
38
- result: string;
39
- error?: string;
40
- }>;
41
- private sendResponse;
42
- private sendNotification;
43
- private writeStdout;
44
- private log;
45
- }
@@ -1,17 +0,0 @@
1
- /**
2
- * Centralized CLI startup configuration.
3
- *
4
- * Parses and validates all configuration from CLI args and environment.
5
- * Single source of truth for qlogicagent runtime config.
6
- */
7
- export interface AgentConfig {
8
- /** Enable verbose logging to stderr. */
9
- verbose: boolean;
10
- }
11
- /**
12
- * Parse CLI arguments into AgentConfig.
13
- *
14
- * Supports:
15
- * --verbose / -v Enable verbose logging
16
- */
17
- export declare function parseCliArgs(argv: string[]): AgentConfig;
@@ -1,120 +0,0 @@
1
- /**
2
- * Hook system types for the Agent Runtime.
3
- *
4
- * Hooks allow hosts and middleware to intercept, modify, or observe events
5
- * at well-defined lifecycle points during session, turn, and tool execution.
6
- */
7
- /**
8
- * All supported hook points in the Agent Runtime lifecycle.
9
- */
10
- export type HookPoint = "session.created" | "session.ended" | "turn.submitted" | "turn.before_inference" | "turn.after_inference" | "turn.completed" | "turn.failed" | "tool.before_invoke" | "tool.after_invoke" | "tool.invoke_failed" | "approval.requested" | "approval.responded" | "context.before_compact" | "context.after_compact" | "memory.before_recall" | "memory.after_recall";
11
- export interface HookSessionContext {
12
- sessionId: string;
13
- gatewayId?: string;
14
- deviceId?: string;
15
- mode?: string;
16
- }
17
- export interface HookTurnContext extends HookSessionContext {
18
- turnId: string;
19
- executionId?: string;
20
- rootExecutionId?: string;
21
- }
22
- export interface HookToolContext extends HookTurnContext {
23
- callId: string;
24
- toolName: string;
25
- arguments?: Record<string, unknown>;
26
- }
27
- export interface HookApprovalContext extends HookTurnContext {
28
- approvalId: string;
29
- callId?: string;
30
- toolName?: string;
31
- decision?: "approved" | "denied" | "expired" | "cancelled";
32
- }
33
- export interface HookContextMap {
34
- "session.created": HookSessionContext;
35
- "session.ended": HookSessionContext;
36
- "turn.submitted": HookTurnContext & {
37
- prompt?: string;
38
- };
39
- "turn.before_inference": HookTurnContext & {
40
- model?: string;
41
- messages?: unknown[];
42
- };
43
- "turn.after_inference": HookTurnContext & {
44
- model?: string;
45
- response?: unknown;
46
- success?: boolean;
47
- error?: string;
48
- };
49
- "turn.completed": HookTurnContext & {
50
- outcomeId?: string;
51
- };
52
- "turn.failed": HookTurnContext & {
53
- code?: string;
54
- error?: string;
55
- };
56
- "tool.before_invoke": HookToolContext;
57
- "tool.after_invoke": HookToolContext & {
58
- result?: unknown;
59
- ok: boolean;
60
- };
61
- "tool.invoke_failed": HookToolContext & {
62
- error?: string;
63
- };
64
- "approval.requested": HookApprovalContext;
65
- "approval.responded": HookApprovalContext;
66
- "context.before_compact": HookTurnContext & {
67
- tokenCount?: number;
68
- messageCount?: number;
69
- };
70
- "context.after_compact": HookTurnContext & {
71
- tokenCount?: number;
72
- removedCount?: number;
73
- };
74
- "memory.before_recall": HookTurnContext & {
75
- query?: string;
76
- };
77
- "memory.after_recall": HookTurnContext & {
78
- blockCount?: number;
79
- };
80
- }
81
- /**
82
- * Result of a hook handler invocation.
83
- *
84
- * - `continue`: proceed normally (optionally with modified context)
85
- * - `abort`: stop execution (for "before" hooks only)
86
- * - `skip`: skip this step but continue the overall flow
87
- */
88
- export interface HookResult<T = unknown> {
89
- action: "continue" | "abort" | "skip";
90
- /** Modified context to pass downstream (only for "continue") */
91
- context?: T;
92
- /** Reason for abort/skip (for logging) */
93
- reason?: string;
94
- }
95
- /**
96
- * A hook handler function.
97
- *
98
- * @param point - The hook point being invoked
99
- * @param context - Event-specific context data
100
- * @returns A HookResult or void (treated as "continue")
101
- */
102
- export type HookHandler<P extends HookPoint = HookPoint> = (point: P, context: HookContextMap[P]) => HookResult<HookContextMap[P]> | void | Promise<HookResult<HookContextMap[P]> | void>;
103
- /**
104
- * Hook registration entry.
105
- */
106
- export interface HookRegistration<P extends HookPoint = HookPoint> {
107
- point: P;
108
- handler: HookHandler<P>;
109
- /** Priority (lower = earlier). Default: 100 */
110
- priority?: number;
111
- /** Optional label for debugging */
112
- label?: string;
113
- }
114
- /**
115
- * Interface for a hook registry that manages hook handlers.
116
- */
117
- export interface HookRegistry {
118
- register<P extends HookPoint>(registration: HookRegistration<P>): () => void;
119
- invoke<P extends HookPoint>(point: P, context: HookContextMap[P]): Promise<HookResult<HookContextMap[P]>>;
120
- }
@@ -1,10 +0,0 @@
1
- /**
2
- * Internal contracts — types internalized from qlogicagent-runtime-contracts.
3
- *
4
- * These types are only consumed within qlogicagent itself (agent runtime + hub).
5
- * They were removed from the public npm package to slim the cross-repo API surface.
6
- */
7
- export * from "./planner.js";
8
- export * from "./todo.js";
9
- export * from "./hooks.js";
10
- export * from "./skill-candidate.js";
@@ -1,35 +0,0 @@
1
- export declare const TASK_STEP_STATUS_VALUES: readonly ["pending", "in-progress", "completed", "skipped"];
2
- export type TaskStepStatus = (typeof TASK_STEP_STATUS_VALUES)[number];
3
- export declare const TASK_PLAN_STATUS_VALUES: readonly ["active", "completed", "abandoned"];
4
- export type TaskPlanStatus = (typeof TASK_PLAN_STATUS_VALUES)[number];
5
- export interface TaskStep {
6
- index: number;
7
- description: string;
8
- status: TaskStepStatus;
9
- result?: string;
10
- }
11
- export interface TaskPlan {
12
- id: string;
13
- sessionId: string;
14
- userId: string;
15
- goal: string;
16
- steps: TaskStep[];
17
- status: TaskPlanStatus;
18
- createdAt: string;
19
- updatedAt: string;
20
- constraints?: string[];
21
- keyIdentifiers?: string[];
22
- }
23
- export interface TaskPlanContextSnippet {
24
- text: string;
25
- tokens: number;
26
- planId: string;
27
- }
28
- export interface TaskPlanProgressSnapshot {
29
- goal: string;
30
- steps: Array<{
31
- description: string;
32
- status: TaskStepStatus | string;
33
- result?: string;
34
- }>;
35
- }
@@ -1,63 +0,0 @@
1
- export declare const SKILL_CANDIDATE_STATUS_VALUES: readonly ["draft", "in_review", "approved", "rejected", "canary", "published", "stale", "superseded", "rolled_back"];
2
- export declare const SKILL_CANDIDATE_ACTION_VALUES: readonly ["submit-review", "approve", "reject", "start-canary", "record-effectiveness", "promote", "publish", "mark-stale", "mark-superseded", "rollback"];
3
- export declare const SKILL_CANDIDATE_EFFECTIVENESS_PHASE_VALUES: readonly ["canary", "published"];
4
- export type SkillCandidateStatus = (typeof SKILL_CANDIDATE_STATUS_VALUES)[number];
5
- export type SkillCandidateAction = (typeof SKILL_CANDIDATE_ACTION_VALUES)[number];
6
- export type SkillCandidateEffectivenessPhase = (typeof SKILL_CANDIDATE_EFFECTIVENESS_PHASE_VALUES)[number];
7
- export type SkillCandidateArtifactContract = {
8
- uri: string;
9
- sha256?: string;
10
- workspaceDir?: string;
11
- relativePath?: string;
12
- sourceWorkspaceDir?: string;
13
- stagedAt?: string;
14
- };
15
- export type SkillCandidateSourceExecutionContract = {
16
- executionId?: string;
17
- rootExecutionId?: string;
18
- parentExecutionId?: string;
19
- sidechainId?: string;
20
- attemptId?: string;
21
- outcomeId?: string;
22
- sessionId?: string;
23
- turnId?: string;
24
- };
25
- export type SkillCandidateReviewContract = {
26
- action: SkillCandidateAction;
27
- actor?: string | null;
28
- notes?: string | null;
29
- payload?: Record<string, unknown>;
30
- createdAt?: string;
31
- };
32
- export type SkillCandidateEffectivenessContract = {
33
- phase: SkillCandidateEffectivenessPhase;
34
- sampleCount: number;
35
- successCount: number;
36
- failureCount: number;
37
- regressionCount: number;
38
- successRate: number;
39
- regressionRate: number;
40
- avgLatencyMs?: number;
41
- avgCostUsd?: number;
42
- score?: number;
43
- staleReason?: string | null;
44
- notes?: string | null;
45
- summary?: Record<string, unknown>;
46
- lastObservedAt?: string;
47
- updatedAt?: string;
48
- /** ISO-8601 timestamp of last skill invocation/view/patch activity. */
49
- lastActivityAt?: string;
50
- /** Cumulative activity count (use + view + patch). */
51
- activityCount?: number;
52
- };
53
- export declare function coerceSkillCandidateJsonObject(value: unknown): Record<string, unknown>;
54
- export declare function isSkillCandidateStatus(value: unknown): value is SkillCandidateStatus;
55
- export declare function isSkillCandidateAction(value: unknown): value is SkillCandidateAction;
56
- export declare function isSkillCandidateEffectivenessPhase(value: unknown): value is SkillCandidateEffectivenessPhase;
57
- export declare function normalizeSkillCandidateStatus(value: unknown, fallback?: SkillCandidateStatus): SkillCandidateStatus;
58
- export declare function normalizeSkillCandidateAction(value: unknown): SkillCandidateAction | null;
59
- export declare function normalizeSkillCandidateEffectivenessPhase(value: unknown): SkillCandidateEffectivenessPhase | null;
60
- export declare function normalizeSkillCandidateArtifact(value: unknown): SkillCandidateArtifactContract | null;
61
- export declare function normalizeSkillCandidateSourceExecution(value: unknown): SkillCandidateSourceExecutionContract | null;
62
- export declare function normalizeSkillCandidateReview(value: unknown): SkillCandidateReviewContract | null;
63
- export declare function normalizeSkillCandidateEffectiveness(value: unknown): SkillCandidateEffectivenessContract | null;
@@ -1,14 +0,0 @@
1
- export declare const TODO_ITEM_STATUS_VALUES: readonly ["not-started", "in-progress", "completed"];
2
- export type TodoItemStatus = (typeof TODO_ITEM_STATUS_VALUES)[number];
3
- export interface TodoItem {
4
- id: number;
5
- title: string;
6
- status: TodoItemStatus;
7
- }
8
- export interface TodoListSummary {
9
- total: number;
10
- completed: number;
11
- inProgress: number;
12
- notStarted: number;
13
- }
14
- export declare function summarizeTodoList(items: readonly TodoItem[]): TodoListSummary;
@@ -1,13 +0,0 @@
1
- /**
2
- * qlogicagent — Public API surface.
3
- *
4
- * Re-exports core types and constructors for programmatic embedding.
5
- */
6
- export { Agent } from "./agent/agent.js";
7
- export type { AgentLogger, ChatMessage, ToolDefinition, ToolInvoker, TurnConfig, TurnEvent, TurnRequest, HookRegistry, } from "./agent/types.js";
8
- export { parseCliArgs } from "./config/config.js";
9
- export type { AgentConfig } from "./config/config.js";
10
- export { ProviderRegistry, createLLMClient, autoDetectProvider, } from "./llm/index.js";
11
- export type { LLMTransport, LLMRequest, LLMChunk } from "./llm/index.js";
12
- export { createHookRegistry } from "./runtime/hook-registry.js";
13
- export { buildSkillInstruction, shouldCreateSkill, shouldImproveSkill, } from "./orchestration/index.js";
@@ -1,10 +0,0 @@
1
- /**
2
- * Builtin provider definitions — hardcoded fallback list (~30 providers).
3
- *
4
- * This is Layer 1 (lowest priority) of the three-layer merge strategy.
5
- * Used when remote model catalog is unavailable.
6
- *
7
- * Aligned with Hermes hermes_cli/models.py hardcoded fallback.
8
- */
9
- import type { ProviderDef } from "./provider-def.js";
10
- export declare const BUILTIN_PROVIDERS: ProviderDef[];
@@ -1,15 +0,0 @@
1
- /**
2
- * LLM Provider layer — public API surface.
3
- *
4
- * Provides: ProviderDef + LLMTransport + ProviderRegistry + LLMClient factory
5
- */
6
- export type { ProviderDef, ModelInfo, TransportType, AuthType } from "./provider-def.js";
7
- export type { LLMTransport, LLMRequest, LLMChunk, AccumulatedToolCall, } from "./transport.js";
8
- export { accumulateToolCalls } from "./transport.js";
9
- export { ProviderRegistry } from "./provider-registry.js";
10
- export { BUILTIN_PROVIDERS } from "./builtin-providers.js";
11
- export { ModelCatalog } from "./model-catalog.js";
12
- export type { LLMClientConfig, LLMClient } from "./llm-client.js";
13
- export { createLLMClient, autoDetectProvider } from "./llm-client.js";
14
- export { OpenAIChatTransport } from "./transports/openai-chat.js";
15
- export { AnthropicMessagesTransport } from "./transports/anthropic-messages.js";
@@ -1,43 +0,0 @@
1
- /**
2
- * LLM Client factory — resolves ProviderDef → creates LLMTransport instance.
3
- *
4
- * Replaces the old createAdminInferProxyClient() call chain.
5
- * User API key + ProviderDef → direct provider connection.
6
- */
7
- import type { ProviderDef } from "./provider-def.js";
8
- import type { LLMTransport } from "./transport.js";
9
- import { ProviderRegistry } from "./provider-registry.js";
10
- export interface LLMClientConfig {
11
- /** Provider id, e.g. "deepseek" */
12
- provider: string;
13
- /** Model id, e.g. "deepseek-chat" */
14
- model: string;
15
- /** User API key */
16
- apiKey: string;
17
- /** Optional base URL override */
18
- baseUrl?: string;
19
- }
20
- export interface LLMClient {
21
- transport: LLMTransport;
22
- apiKey: string;
23
- resolvedModel: string;
24
- providerDef: ProviderDef;
25
- }
26
- /**
27
- * Create an LLM client from config + registry.
28
- *
29
- * 1. Look up provider in registry
30
- * 2. Apply baseUrl override if provided
31
- * 3. Instantiate the correct transport
32
- */
33
- export declare function createLLMClient(config: LLMClientConfig, registry: ProviderRegistry): LLMClient;
34
- /**
35
- * Auto-detect provider from API key environment variables.
36
- * Scans registry for providers whose env vars are set.
37
- * Returns the first match.
38
- */
39
- export declare function autoDetectProvider(registry: ProviderRegistry): {
40
- providerId: string;
41
- apiKey: string;
42
- defaultModel: string;
43
- } | undefined;
@@ -1,53 +0,0 @@
1
- /**
2
- * ModelCatalog — remote model directory with disk cache + fallback.
3
- *
4
- * Fetches model metadata from models.dev (open community catalog, 4000+ models).
5
- * Aligned with Hermes agent/models_dev.py caching strategy.
6
- *
7
- * Three-layer fallback:
8
- * 1. In-memory cache (process-level, TTL check against disk mtime)
9
- * 2. Disk cache (~/.openclaw/cache/model_catalog.json)
10
- * 3. Remote fetch (https://models.dev/api.json)
11
- * 4. Stale disk cache (if remote fails)
12
- * 5. Empty (caller falls back to builtin-providers.ts hardcoded)
13
- *
14
- * Non-blocking: first startup without cache returns empty immediately,
15
- * triggers background async fetch. Agent uses builtin providers until
16
- * catalog arrives.
17
- */
18
- import type { ModelInfo } from "./provider-def.js";
19
- export declare class ModelCatalog {
20
- private cache;
21
- private cacheDir;
22
- private cacheFile;
23
- private ttlMs;
24
- private fetching;
25
- private lastFetchAttempt;
26
- constructor(opts?: {
27
- cacheDir?: string;
28
- ttlMs?: number;
29
- });
30
- /**
31
- * Get models for a provider. Non-blocking: returns whatever is cached.
32
- * Triggers background refresh if stale.
33
- */
34
- getModels(providerId: string): ModelInfo[];
35
- /**
36
- * Get a single model by provider + model id.
37
- */
38
- getModel(providerId: string, modelId: string): ModelInfo | undefined;
39
- /**
40
- * List all known provider ids from the catalog.
41
- */
42
- listProviderIds(): string[];
43
- /**
44
- * Force refresh from remote. Returns true if successful.
45
- */
46
- refreshCatalog(): Promise<boolean>;
47
- private ensureLoaded;
48
- private isStale;
49
- private loadFromDisk;
50
- private saveToDisk;
51
- private backgroundFetch;
52
- private fetchRemote;
53
- }
@@ -1,59 +0,0 @@
1
- /**
2
- * ProviderDef — defines how to connect to an LLM provider.
3
- *
4
- * Aligned with Hermes `ProviderDef` dataclass pattern:
5
- * id + name + transport type + baseUrl + auth config + model list
6
- *
7
- * Three-layer merge strategy (Layer 3 > Layer 2 > Layer 1):
8
- * Layer 1: builtin-providers.ts hardcoded (fallback)
9
- * Layer 2: model-catalog.ts remote (models.dev)
10
- * Layer 3: user config (from agent.turn.config)
11
- */
12
- export type TransportType = "openai-chat" | "anthropic-messages";
13
- export type AuthType = "bearer" | "x-api-key" | "none";
14
- export interface ProviderDef {
15
- /** Unique provider id, e.g. "deepseek", "openai", "anthropic" */
16
- id: string;
17
- /** Display name, e.g. "DeepSeek" */
18
- name: string;
19
- /** Which transport to use for LLM calls */
20
- transport: TransportType;
21
- /** API base URL, e.g. "https://api.deepseek.com" */
22
- baseUrl: string;
23
- /** Env var names for API key (priority order) */
24
- apiKeyEnvVars: string[];
25
- /** Auth header style */
26
- authType: AuthType;
27
- /** Is an aggregator (OpenRouter, 硅基) — model ids may have prefix */
28
- isAggregator: boolean;
29
- /** Recommended default model */
30
- defaultModel?: string;
31
- /** Known models for this provider */
32
- models?: ModelInfo[];
33
- /** Extra headers to send with every request (e.g. aggregator-specific) */
34
- extraHeaders?: Record<string, string>;
35
- /** Whether this provider supports stream_options (default true for openai-chat) */
36
- supportsStreamOptions?: boolean;
37
- /** Whether to omit temperature when it equals 0 (some providers reject 0) */
38
- omitZeroTemperature?: boolean;
39
- }
40
- export interface ModelInfo {
41
- /** Model id, e.g. "deepseek-chat" */
42
- id: string;
43
- /** Display name, e.g. "DeepSeek Chat V3" */
44
- name: string;
45
- /** Context window in tokens */
46
- contextWindow: number;
47
- /** Max output tokens */
48
- maxOutput: number;
49
- /** Supports function/tool calling */
50
- toolCall: boolean;
51
- /** Has reasoning/thinking mode */
52
- reasoning: boolean;
53
- /** Supports vision (image input) */
54
- vision: boolean;
55
- /** Cost per 1M input tokens (USD) */
56
- costInput?: number;
57
- /** Cost per 1M output tokens (USD) */
58
- costOutput?: number;
59
- }
@@ -1,54 +0,0 @@
1
- /**
2
- * ProviderRegistry — three-layer merge registry for LLM providers.
3
- *
4
- * Layer 1: builtin-providers.ts hardcoded (lowest priority, ~20 providers)
5
- * Layer 2: model-catalog.ts remote (models.dev — enriches model metadata)
6
- * Layer 3: user config override (from agent.turn.config — highest priority)
7
- *
8
- * Merge strategy: Layer 3 > Layer 2 > Layer 1 (later layers override same-id fields)
9
- *
10
- * Aligned with Hermes provider_registry.py.
11
- */
12
- import type { ModelInfo, ProviderDef } from "./provider-def.js";
13
- import { ModelCatalog } from "./model-catalog.js";
14
- export declare class ProviderRegistry {
15
- /** Layer 1: builtin hardcoded providers */
16
- private builtins;
17
- /** Layer 2: remote model catalog (models.dev) */
18
- private catalog;
19
- /** Layer 3: user overrides (from agent.turn.config) */
20
- private overrides;
21
- constructor(opts?: {
22
- catalog?: ModelCatalog;
23
- });
24
- /**
25
- * Apply user config override for a provider.
26
- * Typically called when agent.turn.config has baseUrl/apiKey overrides.
27
- */
28
- applyOverride(providerId: string, override: Partial<ProviderDef>): void;
29
- /**
30
- * Get merged ProviderDef by id (Layer 3 > Layer 1).
31
- * Returns undefined if provider not found.
32
- * Supports common aliases (e.g., "claude" → "anthropic").
33
- */
34
- getProvider(id: string): ProviderDef | undefined;
35
- /**
36
- * List all known provider ids.
37
- */
38
- listProviders(): ProviderDef[];
39
- /**
40
- * List models for a specific provider.
41
- * Merges: Layer 3 override > Layer 1 builtin > Layer 2 catalog enrichment.
42
- */
43
- listModels(providerId: string): ModelInfo[];
44
- /**
45
- * Trigger background refresh of the remote model catalog.
46
- */
47
- refreshCatalog(): Promise<boolean>;
48
- /**
49
- * Resolve API key for a provider:
50
- * 1. Explicit key (from agent.turn.config)
51
- * 2. Environment variables (ProviderDef.apiKeyEnvVars)
52
- */
53
- resolveApiKey(providerId: string, explicitKey?: string): string | undefined;
54
- }
@@ -1,62 +0,0 @@
1
- /**
2
- * LLMTransport — abstract interface for LLM inference calls.
3
- *
4
- * Aligned with Hermes `ProviderTransport` ABC:
5
- * stream(request, apiKey, signal) → AsyncGenerator<LLMChunk>
6
- *
7
- * Two concrete implementations:
8
- * - OpenAI Chat Completions (covers 95% of providers)
9
- * - Anthropic Messages API
10
- */
11
- import type { ChatMessage, ToolDefinition } from "../agent/types.js";
12
- export interface LLMRequest {
13
- model: string;
14
- messages: ChatMessage[];
15
- tools?: ToolDefinition[];
16
- toolChoice?: "auto" | "none" | "required";
17
- temperature?: number;
18
- maxTokens?: number;
19
- reasoning?: {
20
- effort: "low" | "medium" | "high";
21
- };
22
- }
23
- export type LLMChunk = {
24
- type: "delta";
25
- text: string;
26
- } | {
27
- type: "tool_call_delta";
28
- index: number;
29
- id?: string;
30
- name?: string;
31
- arguments: string;
32
- } | {
33
- type: "reasoning_delta";
34
- text: string;
35
- } | {
36
- type: "usage";
37
- promptTokens: number;
38
- completionTokens: number;
39
- reasoningTokens?: number;
40
- } | {
41
- type: "done";
42
- finishReason: string;
43
- };
44
- export interface AccumulatedToolCall {
45
- id: string;
46
- name: string;
47
- arguments: string;
48
- }
49
- export interface LLMTransport {
50
- /**
51
- * Stream an LLM inference request.
52
- * apiKey is passed explicitly (from agent.turn.config, not env).
53
- */
54
- stream(request: LLMRequest, apiKey: string, signal?: AbortSignal): AsyncGenerator<LLMChunk>;
55
- }
56
- /**
57
- * Accumulate tool_call_delta chunks into complete ToolCall objects.
58
- * Modeled after admin-infer-proxy-client's Map<index, toolCall> accumulator.
59
- */
60
- export declare function accumulateToolCalls(accumulator: Map<number, AccumulatedToolCall>, chunk: LLMChunk & {
61
- type: "tool_call_delta";
62
- }): void;
@@ -1,31 +0,0 @@
1
- /**
2
- * Anthropic Messages Transport — SSE streaming for Claude API.
3
- *
4
- * POST {baseUrl}/v1/messages with stream: true
5
- * Auth: x-api-key: {apiKey} + anthropic-version header
6
- *
7
- * SSE event types:
8
- * message_start, content_block_start, content_block_delta,
9
- * content_block_stop, message_delta, message_stop
10
- *
11
- * Tool use is via content blocks with type "tool_use" + "input_json_delta".
12
- *
13
- * Aligned with Hermes anthropic_messages.py transport.
14
- */
15
- import type { LLMChunk, LLMRequest, LLMTransport } from "../transport.js";
16
- export interface AnthropicTransportConfig {
17
- baseUrl: string;
18
- /** anthropic-version header (default "2023-06-01") */
19
- apiVersion?: string;
20
- /** Timeout in ms (default 180_000) */
21
- timeoutMs?: number;
22
- }
23
- export declare class AnthropicMessagesTransport implements LLMTransport {
24
- private baseUrl;
25
- private apiVersion;
26
- private timeoutMs;
27
- constructor(config: AnthropicTransportConfig);
28
- stream(request: LLMRequest, apiKey: string, signal?: AbortSignal): AsyncGenerator<LLMChunk>;
29
- private parseSSEStream;
30
- private mapEvent;
31
- }