qlogicagent 0.5.2 → 0.5.3
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 +402 -402
- package/dist/agent.js +18 -0
- package/dist/cli.js +360 -0
- package/dist/contracts.js +1 -0
- package/dist/index.js +22 -0
- package/dist/orchestration.js +125 -0
- package/dist/types/agent/agent.d.ts +43 -0
- package/dist/types/agent/constants.d.ts +47 -0
- package/dist/types/agent/tool-loop.d.ts +96 -0
- package/dist/types/agent/types.d.ts +250 -0
- package/dist/types/cli/main.d.ts +11 -0
- package/dist/types/cli/stdio-server.d.ts +56 -0
- package/dist/types/cli/tool-bootstrap.d.ts +21 -0
- package/dist/types/config/config.d.ts +17 -0
- package/dist/types/contracts/hooks.d.ts +175 -0
- package/dist/types/contracts/index.d.ts +10 -0
- package/dist/types/contracts/planner.d.ts +35 -0
- package/dist/types/contracts/skill-candidate.d.ts +63 -0
- package/dist/types/contracts/todo.d.ts +14 -0
- package/dist/types/index.d.ts +13 -0
- package/dist/types/llm/builtin-providers.d.ts +10 -0
- package/dist/types/llm/debug-transport.d.ts +12 -0
- package/dist/types/llm/index.d.ts +16 -0
- package/dist/types/llm/llm-client.d.ts +43 -0
- package/dist/types/llm/model-catalog.d.ts +53 -0
- package/dist/types/llm/provider-def.d.ts +59 -0
- package/dist/types/llm/provider-registry.d.ts +54 -0
- package/dist/types/llm/transport.d.ts +62 -0
- package/dist/types/llm/transports/anthropic-messages.d.ts +31 -0
- package/dist/types/llm/transports/openai-chat.d.ts +36 -0
- package/dist/types/orchestration/agent-registry.d.ts +46 -0
- package/dist/types/orchestration/context-collapse.d.ts +58 -0
- package/dist/types/orchestration/context-compression.d.ts +301 -0
- package/dist/types/orchestration/conversation-repair.d.ts +61 -0
- package/dist/types/orchestration/curator-scheduler.d.ts +119 -0
- package/dist/types/orchestration/error-classification.d.ts +12 -0
- package/dist/types/orchestration/failover-classification.d.ts +8 -0
- package/dist/types/orchestration/failover-error.d.ts +33 -0
- package/dist/types/orchestration/fork-subagent.d.ts +100 -0
- package/dist/types/orchestration/index.d.ts +113 -0
- package/dist/types/orchestration/memory-provider.d.ts +14 -0
- package/dist/types/orchestration/reactive-compact.d.ts +73 -0
- package/dist/types/orchestration/retry-loop.d.ts +69 -0
- package/dist/types/orchestration/skill-candidate.d.ts +52 -0
- package/dist/types/orchestration/skill-consolidation.d.ts +123 -0
- package/dist/types/orchestration/skill-improvement.d.ts +59 -0
- package/dist/types/orchestration/skill-similarity.d.ts +98 -0
- package/dist/types/orchestration/task-types.d.ts +142 -0
- package/dist/types/orchestration/team-orchestration.d.ts +195 -0
- package/dist/types/orchestration/team-tool-loop-wiring.d.ts +92 -0
- package/dist/types/orchestration/tool-choice-policy.d.ts +54 -0
- package/dist/types/orchestration/tool-loop-state.d.ts +50 -0
- package/dist/types/orchestration/tool-schema.d.ts +39 -0
- package/dist/types/orchestration/turn-loop-guard.d.ts +86 -0
- package/dist/types/runtime/execution/dream-agent.d.ts +199 -0
- package/dist/types/runtime/execution/forked-agent.d.ts +111 -0
- package/dist/types/runtime/execution/index.d.ts +6 -0
- package/dist/types/runtime/execution/progress-tracker.d.ts +78 -0
- package/dist/types/runtime/execution/remote-agent.d.ts +63 -0
- package/dist/types/runtime/execution/streaming-tool-executor.d.ts +100 -0
- package/dist/types/runtime/execution/tool-eligibility.d.ts +59 -0
- package/dist/types/runtime/execution/tool-result-storage.d.ts +87 -0
- package/dist/types/runtime/hooks/context-compression.d.ts +61 -0
- package/dist/types/runtime/hooks/hook-registry.d.ts +12 -0
- package/dist/types/runtime/hooks/index.d.ts +3 -0
- package/dist/types/runtime/hooks/memory-hooks.d.ts +49 -0
- package/dist/types/runtime/index.d.ts +5 -0
- package/dist/types/runtime/infra/cleanup-registry.d.ts +23 -0
- package/dist/types/runtime/infra/file-watcher.d.ts +72 -0
- package/dist/types/runtime/infra/index.d.ts +6 -0
- package/dist/types/runtime/infra/secure-storage.d.ts +81 -0
- package/dist/types/runtime/infra/task-runtime.d.ts +108 -0
- package/dist/types/runtime/infra/token-budget.d.ts +92 -0
- package/dist/types/runtime/infra/worktree-backend.d.ts +85 -0
- package/dist/types/runtime/prompt/environment-context.d.ts +23 -0
- package/dist/types/runtime/prompt/index.d.ts +3 -0
- package/dist/types/runtime/prompt/instruction-loader.d.ts +64 -0
- package/dist/types/runtime/prompt/system-prompt-sections.d.ts +63 -0
- package/dist/types/runtime/session/index.d.ts +2 -0
- package/dist/types/runtime/session/session-memory.d.ts +91 -0
- package/dist/types/runtime/session/session-persistence.d.ts +94 -0
- package/dist/types/runtime/session/session-state.d.ts +117 -0
- package/dist/types/skills/index.d.ts +125 -0
- package/dist/types/skills/mcp/index.d.ts +3 -0
- package/dist/types/skills/mcp/mcp-http-client.d.ts +66 -0
- package/dist/types/skills/mcp/mcp-manager.d.ts +84 -0
- package/dist/types/skills/mcp/mcp-stdio-client.d.ts +84 -0
- package/dist/types/skills/memory-extractor.d.ts +64 -0
- package/dist/types/skills/memory-query-tool.d.ts +43 -0
- package/dist/types/skills/memory-store.d.ts +66 -0
- package/dist/types/skills/memory-tool.d.ts +67 -0
- package/dist/types/skills/permissions/bash-classifier.d.ts +30 -0
- package/dist/types/skills/permissions/classifier-cache.d.ts +51 -0
- package/dist/types/skills/permissions/denial-tracking.d.ts +42 -0
- package/dist/types/skills/permissions/hook-runner.d.ts +85 -0
- package/dist/types/skills/permissions/index.d.ts +12 -0
- package/dist/types/skills/permissions/permission-classifier.d.ts +41 -0
- package/dist/types/skills/permissions/rule-engine.d.ts +41 -0
- package/dist/types/skills/permissions/settings-watcher.d.ts +46 -0
- package/dist/types/skills/permissions/types.d.ts +113 -0
- package/dist/types/skills/plugins/index.d.ts +2 -0
- package/dist/types/skills/plugins/plugin-api.d.ts +38 -0
- package/dist/types/skills/plugins/plugin-loader.d.ts +45 -0
- package/dist/types/skills/plugins/plugin-marketplace.d.ts +61 -0
- package/dist/types/skills/portable-tool.d.ts +71 -0
- package/dist/types/skills/qmemory-adapter.d.ts +42 -0
- package/dist/types/skills/skill-frontmatter.d.ts +19 -0
- package/dist/types/skills/skill-guard.d.ts +23 -0
- package/dist/types/skills/skill-loader.d.ts +16 -0
- package/dist/types/skills/skill-source.d.ts +119 -0
- package/dist/types/skills/skill-types.d.ts +199 -0
- package/dist/types/skills/think-tool.d.ts +16 -0
- package/dist/types/skills/todo-tool.d.ts +63 -0
- package/dist/types/skills/tool-registry.d.ts +29 -0
- package/dist/types/skills/tools/agent-tool.d.ts +91 -0
- package/dist/types/skills/tools/apply-patch-tool.d.ts +29 -0
- package/dist/types/skills/tools/ask-user-tool.d.ts +80 -0
- package/dist/types/skills/tools/brief-tool.d.ts +74 -0
- package/dist/types/skills/tools/browser-tool.d.ts +114 -0
- package/dist/types/skills/tools/checkpoint-tool.d.ts +66 -0
- package/dist/types/skills/tools/config-tool.d.ts +63 -0
- package/dist/types/skills/tools/cron-tool.d.ts +116 -0
- package/dist/types/skills/tools/edit-tool.d.ts +43 -0
- package/dist/types/skills/tools/exec-tool.d.ts +97 -0
- package/dist/types/skills/tools/image-generate-tool.d.ts +62 -0
- package/dist/types/skills/tools/instructions-tool.d.ts +103 -0
- package/dist/types/skills/tools/lsp-tool.d.ts +153 -0
- package/dist/types/skills/tools/mcp-client-types.d.ts +269 -0
- package/dist/types/skills/tools/mcp-resource-tools.d.ts +14 -0
- package/dist/types/skills/tools/mcp-tool.d.ts +249 -0
- package/dist/types/skills/tools/memory-tool.d.ts +74 -0
- package/dist/types/skills/tools/monitor-tool.d.ts +113 -0
- package/dist/types/skills/tools/music-generate-tool.d.ts +55 -0
- package/dist/types/skills/tools/notebook-edit-tool.d.ts +15 -0
- package/dist/types/skills/tools/notify-tool.d.ts +53 -0
- package/dist/types/skills/tools/patch-tool.d.ts +45 -0
- package/dist/types/skills/tools/pdf-tool.d.ts +66 -0
- package/dist/types/skills/tools/plan-mode-tool.d.ts +98 -0
- package/dist/types/skills/tools/read-tool.d.ts +51 -0
- package/dist/types/skills/tools/repl-tool.d.ts +70 -0
- package/dist/types/skills/tools/search-tool.d.ts +112 -0
- package/dist/types/skills/tools/send-message-tool.d.ts +51 -0
- package/dist/types/skills/tools/shell/bash-provider.d.ts +26 -0
- package/dist/types/skills/tools/shell/command-classification.d.ts +44 -0
- package/dist/types/skills/tools/shell/command-semantics.d.ts +14 -0
- package/dist/types/skills/tools/shell/destructive-command-warning.d.ts +10 -0
- package/dist/types/skills/tools/shell/exec-permissions.d.ts +52 -0
- package/dist/types/skills/tools/shell/index.d.ts +17 -0
- package/dist/types/skills/tools/shell/powershell-provider.d.ts +15 -0
- package/dist/types/skills/tools/shell/shell-command.d.ts +54 -0
- package/dist/types/skills/tools/shell/shell-exec.d.ts +33 -0
- package/dist/types/skills/tools/shell/shell-provider.d.ts +85 -0
- package/dist/types/skills/tools/shell/task-output.d.ts +45 -0
- package/dist/types/skills/tools/skill-invoke-tool.d.ts +46 -0
- package/dist/types/skills/tools/skill-list-tool.d.ts +33 -0
- package/dist/types/skills/tools/skill-manage-tool.d.ts +73 -0
- package/dist/types/skills/tools/skill-view-tool.d.ts +37 -0
- package/dist/types/skills/tools/sleep-tool.d.ts +49 -0
- package/dist/types/skills/tools/structured-output-tool.d.ts +116 -0
- package/dist/types/skills/tools/task-tool.d.ts +104 -0
- package/dist/types/skills/tools/team-tool.d.ts +89 -0
- package/dist/types/skills/tools/tool-search-tool.d.ts +51 -0
- package/dist/types/skills/tools/tts-tool.d.ts +38 -0
- package/dist/types/skills/tools/video-edit-tool.d.ts +69 -0
- package/dist/types/skills/tools/video-generate-tool.d.ts +62 -0
- package/dist/types/skills/tools/video-merge-tool.d.ts +105 -0
- package/dist/types/skills/tools/video-upscale-tool.d.ts +45 -0
- package/dist/types/skills/tools/web-fetch-tool.d.ts +78 -0
- package/dist/types/skills/tools/web-search-tool.d.ts +57 -0
- package/dist/types/skills/tools/workflow-tool.d.ts +44 -0
- package/dist/types/skills/tools/worktree-tool.d.ts +69 -0
- package/dist/types/skills/tools/write-tool.d.ts +45 -0
- package/package.json +3 -2
|
@@ -0,0 +1,63 @@
|
|
|
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;
|
|
@@ -0,0 +1,14 @@
|
|
|
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;
|
|
@@ -0,0 +1,13 @@
|
|
|
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/hooks/hook-registry.js";
|
|
13
|
+
export { buildSkillInstruction, } from "./orchestration/index.js";
|
|
@@ -0,0 +1,10 @@
|
|
|
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[];
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { LLMTransport } from "./transport.js";
|
|
2
|
+
/**
|
|
3
|
+
* Check whether debug transport should be enabled.
|
|
4
|
+
*/
|
|
5
|
+
export declare function isDebugTransportEnabled(): boolean;
|
|
6
|
+
/**
|
|
7
|
+
* Create a DebugTransport decorator that wraps a base LLMTransport,
|
|
8
|
+
* logging request metadata + timing + usage to JSONL.
|
|
9
|
+
*
|
|
10
|
+
* CC parity: createDumpPromptsFetch — but vendor-agnostic via transport abstraction.
|
|
11
|
+
*/
|
|
12
|
+
export declare function createDebugTransport(base: LLMTransport, sessionId: string): LLMTransport;
|
|
@@ -0,0 +1,16 @@
|
|
|
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";
|
|
16
|
+
export { isDebugTransportEnabled, createDebugTransport } from "./debug-transport.js";
|
|
@@ -0,0 +1,43 @@
|
|
|
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;
|
|
@@ -0,0 +1,53 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
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;
|
|
@@ -0,0 +1,31 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OpenAI Chat Completions Transport — SSE streaming implementation.
|
|
3
|
+
*
|
|
4
|
+
* Covers all OpenAI-compatible providers:
|
|
5
|
+
* DeepSeek, Qwen, 硅基, Minimax, Moonshot, Groq, Together, OpenRouter, etc.
|
|
6
|
+
*
|
|
7
|
+
* POST {baseUrl}/v1/chat/completions with stream: true
|
|
8
|
+
* Auth: Authorization: Bearer {apiKey}
|
|
9
|
+
*
|
|
10
|
+
* SSE format: lines prefixed with "data: ", JSON parsing per event.
|
|
11
|
+
*
|
|
12
|
+
* Adapted from admin-infer-proxy-client.ts SSE logic + Hermes openai_chat.py transport.
|
|
13
|
+
*/
|
|
14
|
+
import type { LLMChunk, LLMRequest, LLMTransport } from "../transport.js";
|
|
15
|
+
export interface OpenAIChatTransportConfig {
|
|
16
|
+
baseUrl: string;
|
|
17
|
+
/** Additional headers (e.g. for specific providers) */
|
|
18
|
+
extraHeaders?: Record<string, string>;
|
|
19
|
+
/** Timeout in ms (default 180_000) */
|
|
20
|
+
timeoutMs?: number;
|
|
21
|
+
/** Whether to include stream_options (default true). Set false for providers that reject it. */
|
|
22
|
+
supportsStreamOptions?: boolean;
|
|
23
|
+
/** Whether to omit temperature when it equals 0 (e.g. Moonshot rejects 0) */
|
|
24
|
+
omitZeroTemperature?: boolean;
|
|
25
|
+
}
|
|
26
|
+
export declare class OpenAIChatTransport implements LLMTransport {
|
|
27
|
+
private baseUrl;
|
|
28
|
+
private extraHeaders;
|
|
29
|
+
private timeoutMs;
|
|
30
|
+
private supportsStreamOptions;
|
|
31
|
+
private omitZeroTemperature;
|
|
32
|
+
constructor(config: OpenAIChatTransportConfig);
|
|
33
|
+
stream(request: LLMRequest, apiKey: string, signal?: AbortSignal): AsyncGenerator<LLMChunk>;
|
|
34
|
+
private parseSSEStream;
|
|
35
|
+
private mapChunk;
|
|
36
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Built-in Agent Registry — CC-aligned agent definitions for fork/subagent.
|
|
3
|
+
*
|
|
4
|
+
* Each built-in agent defines a role with constrained tools, system prompt,
|
|
5
|
+
* and execution budget. The LLM can invoke these via the AgentTool.
|
|
6
|
+
*/
|
|
7
|
+
import type { PermissionRole, IsolationMode } from "./task-types.js";
|
|
8
|
+
export interface AgentDefinition {
|
|
9
|
+
/** Unique identifier for the agent (kebab-case). */
|
|
10
|
+
name: string;
|
|
11
|
+
/** Human-readable label. */
|
|
12
|
+
label: string;
|
|
13
|
+
/** Short description (appears in tool_search / LLM prompt). */
|
|
14
|
+
description: string;
|
|
15
|
+
/** Maximum turns this agent can execute before forced stop. */
|
|
16
|
+
maxTurns: number;
|
|
17
|
+
/** Tool access mode. */
|
|
18
|
+
toolAccessMode: "full" | "read-only" | "none";
|
|
19
|
+
/** Explicit allowed tool names (if empty, uses toolAccessMode filter). */
|
|
20
|
+
allowedTools?: string[];
|
|
21
|
+
/** Whether this agent can fork sub-agents itself. */
|
|
22
|
+
canFork: boolean;
|
|
23
|
+
/** System prompt override for this agent. */
|
|
24
|
+
systemPromptSuffix?: string;
|
|
25
|
+
/** Permission role context (CC: interactive/coordinator/worker). Default: "worker". */
|
|
26
|
+
permissionRole?: PermissionRole;
|
|
27
|
+
/** Isolation mode (CC: shared/worktree/container). Default: "shared". */
|
|
28
|
+
isolation?: IsolationMode;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Get the full list of built-in agent definitions.
|
|
32
|
+
*/
|
|
33
|
+
export declare function getBuiltInAgents(): AgentDefinition[];
|
|
34
|
+
/**
|
|
35
|
+
* Look up a built-in agent by name.
|
|
36
|
+
*/
|
|
37
|
+
export declare function getBuiltInAgent(name: string): AgentDefinition | undefined;
|
|
38
|
+
/**
|
|
39
|
+
* Check if a given agent name is a built-in agent.
|
|
40
|
+
*/
|
|
41
|
+
export declare function isBuiltInAgent(name: string): boolean;
|
|
42
|
+
/**
|
|
43
|
+
* Resolve tool access for an agent definition.
|
|
44
|
+
* Returns the set of tool names the agent is allowed to use.
|
|
45
|
+
*/
|
|
46
|
+
export declare function resolveAgentToolSet(agent: AgentDefinition, availableTools: string[]): string[];
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Context Collapse — staged lightweight context reduction that runs
|
|
3
|
+
* BEFORE autocompact and can drain on 413 BEFORE reactive compact.
|
|
4
|
+
*
|
|
5
|
+
* CC parity: services/contextCollapse/index.ts
|
|
6
|
+
*
|
|
7
|
+
* Architecture:
|
|
8
|
+
* 1. applyCollapsesIfNeeded() — runs every iteration, projects the
|
|
9
|
+
* collapsed view and maybe commits more collapses (by summarizing
|
|
10
|
+
* old tool-result groups into compact summaries).
|
|
11
|
+
* 2. recoverFromOverflow() — drain all staged collapses on a real
|
|
12
|
+
* API 413. If it can free enough context, the retry may succeed
|
|
13
|
+
* without reactive compact (which is heavier and destroys more
|
|
14
|
+
* context).
|
|
15
|
+
*
|
|
16
|
+
* Collapses are ordered "stages" — oldest first. Each stage replaces
|
|
17
|
+
* a contiguous run of old messages with a single summary line.
|
|
18
|
+
*/
|
|
19
|
+
export interface CollapseStage {
|
|
20
|
+
/** UUID of the stage (for dedup and ordering). */
|
|
21
|
+
id: string;
|
|
22
|
+
/** Index range [start, end) in the original message array. */
|
|
23
|
+
range: [number, number];
|
|
24
|
+
/** Summary text that replaces the range. */
|
|
25
|
+
summary: string;
|
|
26
|
+
/** Whether this stage has been committed (applied to messages). */
|
|
27
|
+
committed: boolean;
|
|
28
|
+
}
|
|
29
|
+
export interface CollapseStore {
|
|
30
|
+
stages: CollapseStage[];
|
|
31
|
+
}
|
|
32
|
+
export declare function createCollapseStore(): CollapseStore;
|
|
33
|
+
/**
|
|
34
|
+
* Evaluate whether new collapses should be staged.
|
|
35
|
+
*
|
|
36
|
+
* Heuristic: if the conversation has > thresholdMessages non-system messages,
|
|
37
|
+
* group old tool-result runs into collapse stages.
|
|
38
|
+
*/
|
|
39
|
+
export declare function applyCollapsesIfNeeded<T extends {
|
|
40
|
+
role: string;
|
|
41
|
+
content?: string | unknown;
|
|
42
|
+
}>(messages: T[], store: CollapseStore, opts?: {
|
|
43
|
+
thresholdMessages?: number;
|
|
44
|
+
}): {
|
|
45
|
+
messages: T[];
|
|
46
|
+
stagedCount: number;
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* Drain all staged (uncommitted) collapses — called on 413 recovery.
|
|
50
|
+
* Commits every pending stage and returns the collapsed messages.
|
|
51
|
+
*/
|
|
52
|
+
export declare function recoverFromOverflow<T extends {
|
|
53
|
+
role: string;
|
|
54
|
+
content?: string | unknown;
|
|
55
|
+
}>(messages: T[], store: CollapseStore): {
|
|
56
|
+
messages: T[];
|
|
57
|
+
committed: number;
|
|
58
|
+
};
|