qlogicagent 0.2.1 → 0.3.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.
- package/dist/agent.js +1 -0
- package/dist/cli.js +9 -0
- package/dist/contracts.js +1 -0
- package/dist/index.js +5 -15
- package/dist/orchestration.js +118 -0
- package/package.json +56 -42
- package/dist/agent/agent.js +0 -113
- package/dist/agent/tool-loop.js +0 -575
- package/dist/agent/types.js +0 -14
- package/dist/cli/main.js +0 -23
- package/dist/cli/stdio-server.js +0 -463
- package/dist/config/config.js +0 -21
- package/dist/contracts/hooks.js +0 -7
- package/dist/contracts/index.js +0 -10
- package/dist/contracts/planner.js +0 -2
- package/dist/contracts/skill-candidate.js +0 -195
- package/dist/contracts/todo.js +0 -9
- package/dist/llm/builtin-providers.js +0 -531
- package/dist/llm/index.js +0 -14
- package/dist/llm/llm-client.js +0 -67
- package/dist/llm/model-catalog.js +0 -191
- package/dist/llm/provider-def.js +0 -12
- package/dist/llm/provider-registry.js +0 -147
- package/dist/llm/transport.js +0 -27
- package/dist/llm/transports/anthropic-messages.js +0 -293
- package/dist/llm/transports/openai-chat.js +0 -165
- package/dist/orchestration/agent-registry.js +0 -116
- package/dist/orchestration/approval-aware-tool-plan.js +0 -87
- package/dist/orchestration/context-compression.js +0 -583
- package/dist/orchestration/conversation-repair.js +0 -429
- package/dist/orchestration/curator-scheduler.js +0 -135
- package/dist/orchestration/embedded-failover-policy.js +0 -168
- package/dist/orchestration/error-classification.js +0 -77
- package/dist/orchestration/failover-classification.js +0 -381
- package/dist/orchestration/failover-error.js +0 -198
- package/dist/orchestration/fork-subagent.js +0 -98
- package/dist/orchestration/index.js +0 -267
- package/dist/orchestration/memory-flush-policy.js +0 -85
- package/dist/orchestration/memory-provider.js +0 -2
- package/dist/orchestration/parallel-tool-calls.js +0 -59
- package/dist/orchestration/prompt-cache-strategy.js +0 -228
- package/dist/orchestration/reactive-compact.js +0 -78
- package/dist/orchestration/retry-loop.js +0 -24
- package/dist/orchestration/skill-candidate.js +0 -141
- package/dist/orchestration/skill-consolidation.js +0 -220
- package/dist/orchestration/skill-improvement.js +0 -66
- package/dist/orchestration/skill-similarity.js +0 -131
- package/dist/orchestration/streaming-tool-executor.js +0 -96
- package/dist/orchestration/team-orchestration.js +0 -369
- package/dist/orchestration/team-tool-loop-wiring.js +0 -147
- package/dist/orchestration/tool-choice-policy.js +0 -164
- package/dist/orchestration/tool-loop-state.js +0 -133
- package/dist/orchestration/tool-schema.js +0 -297
- package/dist/orchestration/transcript-repair.js +0 -426
- package/dist/orchestration/turn-loop-guard.js +0 -92
- package/dist/orchestration/web-browser-policy.js +0 -39
- package/dist/runtime/context-compression.js +0 -274
- package/dist/runtime/hook-registry.js +0 -53
- package/dist/runtime/memory-hooks.js +0 -65
- package/dist/runtime/tool-eligibility.js +0 -111
- package/dist/skills/index.js +0 -82
- package/dist/skills/memory-extractor.js +0 -173
- package/dist/skills/memory-query-tool.js +0 -127
- package/dist/skills/memory-store.js +0 -228
- package/dist/skills/memory-tool.js +0 -192
- package/dist/skills/portable-tool.js +0 -14
- package/dist/skills/qmemory-adapter.js +0 -165
- package/dist/skills/skill-frontmatter.js +0 -344
- package/dist/skills/skill-guard.js +0 -229
- package/dist/skills/skill-loader.js +0 -303
- package/dist/skills/skill-source.js +0 -126
- package/dist/skills/skill-types.js +0 -6
- package/dist/skills/think-tool.js +0 -59
- package/dist/skills/todo-tool.js +0 -114
- package/dist/skills/tools/agent-tool.js +0 -142
- package/dist/skills/tools/apply-patch-tool.js +0 -184
- package/dist/skills/tools/ask-user-tool.js +0 -121
- package/dist/skills/tools/brief-tool.js +0 -95
- package/dist/skills/tools/browser-tool.js +0 -155
- package/dist/skills/tools/checkpoint-tool.js +0 -102
- package/dist/skills/tools/config-tool.js +0 -143
- package/dist/skills/tools/cron-tool.js +0 -175
- package/dist/skills/tools/edit-tool.js +0 -70
- package/dist/skills/tools/exec-tool.js +0 -133
- package/dist/skills/tools/image-generate-tool.js +0 -67
- package/dist/skills/tools/instructions-tool.js +0 -187
- package/dist/skills/tools/lsp-tool.js +0 -227
- package/dist/skills/tools/mcp-client-types.js +0 -53
- package/dist/skills/tools/mcp-tool.js +0 -503
- package/dist/skills/tools/memory-tool.js +0 -88
- package/dist/skills/tools/monitor-tool.js +0 -131
- package/dist/skills/tools/music-generate-tool.js +0 -62
- package/dist/skills/tools/notify-tool.js +0 -62
- package/dist/skills/tools/patch-tool.js +0 -505
- package/dist/skills/tools/pdf-tool.js +0 -88
- package/dist/skills/tools/plan-mode-tool.js +0 -122
- package/dist/skills/tools/read-tool.js +0 -84
- package/dist/skills/tools/repl-tool.js +0 -69
- package/dist/skills/tools/search-tool.js +0 -225
- package/dist/skills/tools/send-message-tool.js +0 -76
- package/dist/skills/tools/skill-list-tool.js +0 -54
- package/dist/skills/tools/skill-manage-tool.js +0 -153
- package/dist/skills/tools/skill-view-tool.js +0 -72
- package/dist/skills/tools/sleep-tool.js +0 -81
- package/dist/skills/tools/structured-output-tool.js +0 -176
- package/dist/skills/tools/task-tool.js +0 -161
- package/dist/skills/tools/team-tool.js +0 -105
- package/dist/skills/tools/tool-search-tool.js +0 -110
- package/dist/skills/tools/tts-tool.js +0 -45
- package/dist/skills/tools/video-edit-tool.js +0 -74
- package/dist/skills/tools/video-generate-tool.js +0 -66
- package/dist/skills/tools/video-merge-tool.js +0 -92
- package/dist/skills/tools/video-upscale-tool.js +0 -52
- package/dist/skills/tools/web-fetch-tool.js +0 -92
- package/dist/skills/tools/web-search-tool.js +0 -86
- package/dist/skills/tools/worktree-tool.js +0 -147
- package/dist/skills/tools/write-tool.js +0 -81
- /package/dist/{agent → types/agent}/agent.d.ts +0 -0
- /package/dist/{agent → types/agent}/tool-loop.d.ts +0 -0
- /package/dist/{agent → types/agent}/types.d.ts +0 -0
- /package/dist/{cli → types/cli}/main.d.ts +0 -0
- /package/dist/{cli → types/cli}/stdio-server.d.ts +0 -0
- /package/dist/{config → types/config}/config.d.ts +0 -0
- /package/dist/{contracts → types/contracts}/hooks.d.ts +0 -0
- /package/dist/{contracts → types/contracts}/index.d.ts +0 -0
- /package/dist/{contracts → types/contracts}/planner.d.ts +0 -0
- /package/dist/{contracts → types/contracts}/skill-candidate.d.ts +0 -0
- /package/dist/{contracts → types/contracts}/todo.d.ts +0 -0
- /package/dist/{index.d.ts → types/index.d.ts} +0 -0
- /package/dist/{llm → types/llm}/builtin-providers.d.ts +0 -0
- /package/dist/{llm → types/llm}/index.d.ts +0 -0
- /package/dist/{llm → types/llm}/llm-client.d.ts +0 -0
- /package/dist/{llm → types/llm}/model-catalog.d.ts +0 -0
- /package/dist/{llm → types/llm}/provider-def.d.ts +0 -0
- /package/dist/{llm → types/llm}/provider-registry.d.ts +0 -0
- /package/dist/{llm → types/llm}/transport.d.ts +0 -0
- /package/dist/{llm → types/llm}/transports/anthropic-messages.d.ts +0 -0
- /package/dist/{llm → types/llm}/transports/openai-chat.d.ts +0 -0
- /package/dist/{orchestration → types/orchestration}/agent-registry.d.ts +0 -0
- /package/dist/{orchestration → types/orchestration}/approval-aware-tool-plan.d.ts +0 -0
- /package/dist/{orchestration → types/orchestration}/context-compression.d.ts +0 -0
- /package/dist/{orchestration → types/orchestration}/conversation-repair.d.ts +0 -0
- /package/dist/{orchestration → types/orchestration}/curator-scheduler.d.ts +0 -0
- /package/dist/{orchestration → types/orchestration}/embedded-failover-policy.d.ts +0 -0
- /package/dist/{orchestration → types/orchestration}/error-classification.d.ts +0 -0
- /package/dist/{orchestration → types/orchestration}/failover-classification.d.ts +0 -0
- /package/dist/{orchestration → types/orchestration}/failover-error.d.ts +0 -0
- /package/dist/{orchestration → types/orchestration}/fork-subagent.d.ts +0 -0
- /package/dist/{orchestration → types/orchestration}/index.d.ts +0 -0
- /package/dist/{orchestration → types/orchestration}/memory-flush-policy.d.ts +0 -0
- /package/dist/{orchestration → types/orchestration}/memory-provider.d.ts +0 -0
- /package/dist/{orchestration → types/orchestration}/parallel-tool-calls.d.ts +0 -0
- /package/dist/{orchestration → types/orchestration}/prompt-cache-strategy.d.ts +0 -0
- /package/dist/{orchestration → types/orchestration}/reactive-compact.d.ts +0 -0
- /package/dist/{orchestration → types/orchestration}/retry-loop.d.ts +0 -0
- /package/dist/{orchestration → types/orchestration}/skill-candidate.d.ts +0 -0
- /package/dist/{orchestration → types/orchestration}/skill-consolidation.d.ts +0 -0
- /package/dist/{orchestration → types/orchestration}/skill-improvement.d.ts +0 -0
- /package/dist/{orchestration → types/orchestration}/skill-similarity.d.ts +0 -0
- /package/dist/{orchestration → types/orchestration}/streaming-tool-executor.d.ts +0 -0
- /package/dist/{orchestration → types/orchestration}/team-orchestration.d.ts +0 -0
- /package/dist/{orchestration → types/orchestration}/team-tool-loop-wiring.d.ts +0 -0
- /package/dist/{orchestration → types/orchestration}/tool-choice-policy.d.ts +0 -0
- /package/dist/{orchestration → types/orchestration}/tool-loop-state.d.ts +0 -0
- /package/dist/{orchestration → types/orchestration}/tool-schema.d.ts +0 -0
- /package/dist/{orchestration → types/orchestration}/transcript-repair.d.ts +0 -0
- /package/dist/{orchestration → types/orchestration}/turn-loop-guard.d.ts +0 -0
- /package/dist/{orchestration → types/orchestration}/web-browser-policy.d.ts +0 -0
- /package/dist/{runtime → types/runtime}/context-compression.d.ts +0 -0
- /package/dist/{runtime → types/runtime}/hook-registry.d.ts +0 -0
- /package/dist/{runtime → types/runtime}/memory-hooks.d.ts +0 -0
- /package/dist/{runtime → types/runtime}/tool-eligibility.d.ts +0 -0
- /package/dist/{skills → types/skills}/index.d.ts +0 -0
- /package/dist/{skills → types/skills}/memory-extractor.d.ts +0 -0
- /package/dist/{skills → types/skills}/memory-query-tool.d.ts +0 -0
- /package/dist/{skills → types/skills}/memory-store.d.ts +0 -0
- /package/dist/{skills → types/skills}/memory-tool.d.ts +0 -0
- /package/dist/{skills → types/skills}/portable-tool.d.ts +0 -0
- /package/dist/{skills → types/skills}/qmemory-adapter.d.ts +0 -0
- /package/dist/{skills → types/skills}/skill-frontmatter.d.ts +0 -0
- /package/dist/{skills → types/skills}/skill-guard.d.ts +0 -0
- /package/dist/{skills → types/skills}/skill-loader.d.ts +0 -0
- /package/dist/{skills → types/skills}/skill-source.d.ts +0 -0
- /package/dist/{skills → types/skills}/skill-types.d.ts +0 -0
- /package/dist/{skills → types/skills}/think-tool.d.ts +0 -0
- /package/dist/{skills → types/skills}/todo-tool.d.ts +0 -0
- /package/dist/{skills → types/skills}/tools/agent-tool.d.ts +0 -0
- /package/dist/{skills → types/skills}/tools/apply-patch-tool.d.ts +0 -0
- /package/dist/{skills → types/skills}/tools/ask-user-tool.d.ts +0 -0
- /package/dist/{skills → types/skills}/tools/brief-tool.d.ts +0 -0
- /package/dist/{skills → types/skills}/tools/browser-tool.d.ts +0 -0
- /package/dist/{skills → types/skills}/tools/checkpoint-tool.d.ts +0 -0
- /package/dist/{skills → types/skills}/tools/config-tool.d.ts +0 -0
- /package/dist/{skills → types/skills}/tools/cron-tool.d.ts +0 -0
- /package/dist/{skills → types/skills}/tools/edit-tool.d.ts +0 -0
- /package/dist/{skills → types/skills}/tools/exec-tool.d.ts +0 -0
- /package/dist/{skills → types/skills}/tools/image-generate-tool.d.ts +0 -0
- /package/dist/{skills → types/skills}/tools/instructions-tool.d.ts +0 -0
- /package/dist/{skills → types/skills}/tools/lsp-tool.d.ts +0 -0
- /package/dist/{skills → types/skills}/tools/mcp-client-types.d.ts +0 -0
- /package/dist/{skills → types/skills}/tools/mcp-tool.d.ts +0 -0
- /package/dist/{skills → types/skills}/tools/memory-tool.d.ts +0 -0
- /package/dist/{skills → types/skills}/tools/monitor-tool.d.ts +0 -0
- /package/dist/{skills → types/skills}/tools/music-generate-tool.d.ts +0 -0
- /package/dist/{skills → types/skills}/tools/notify-tool.d.ts +0 -0
- /package/dist/{skills → types/skills}/tools/patch-tool.d.ts +0 -0
- /package/dist/{skills → types/skills}/tools/pdf-tool.d.ts +0 -0
- /package/dist/{skills → types/skills}/tools/plan-mode-tool.d.ts +0 -0
- /package/dist/{skills → types/skills}/tools/read-tool.d.ts +0 -0
- /package/dist/{skills → types/skills}/tools/repl-tool.d.ts +0 -0
- /package/dist/{skills → types/skills}/tools/search-tool.d.ts +0 -0
- /package/dist/{skills → types/skills}/tools/send-message-tool.d.ts +0 -0
- /package/dist/{skills → types/skills}/tools/skill-list-tool.d.ts +0 -0
- /package/dist/{skills → types/skills}/tools/skill-manage-tool.d.ts +0 -0
- /package/dist/{skills → types/skills}/tools/skill-view-tool.d.ts +0 -0
- /package/dist/{skills → types/skills}/tools/sleep-tool.d.ts +0 -0
- /package/dist/{skills → types/skills}/tools/structured-output-tool.d.ts +0 -0
- /package/dist/{skills → types/skills}/tools/task-tool.d.ts +0 -0
- /package/dist/{skills → types/skills}/tools/team-tool.d.ts +0 -0
- /package/dist/{skills → types/skills}/tools/tool-search-tool.d.ts +0 -0
- /package/dist/{skills → types/skills}/tools/tts-tool.d.ts +0 -0
- /package/dist/{skills → types/skills}/tools/video-edit-tool.d.ts +0 -0
- /package/dist/{skills → types/skills}/tools/video-generate-tool.d.ts +0 -0
- /package/dist/{skills → types/skills}/tools/video-merge-tool.d.ts +0 -0
- /package/dist/{skills → types/skills}/tools/video-upscale-tool.d.ts +0 -0
- /package/dist/{skills → types/skills}/tools/web-fetch-tool.d.ts +0 -0
- /package/dist/{skills → types/skills}/tools/web-search-tool.d.ts +0 -0
- /package/dist/{skills → types/skills}/tools/worktree-tool.d.ts +0 -0
- /package/dist/{skills → types/skills}/tools/write-tool.d.ts +0 -0
package/dist/cli/stdio-server.js
DELETED
|
@@ -1,463 +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
|
-
import { createInterface } from "node:readline";
|
|
11
|
-
import { randomUUID } from "node:crypto";
|
|
12
|
-
import { Agent } from "../agent/agent.js";
|
|
13
|
-
import { ProviderRegistry, createLLMClient, autoDetectProvider, } from "../llm/index.js";
|
|
14
|
-
import { createHookRegistry } from "../runtime/hook-registry.js";
|
|
15
|
-
import { registerMemoryHooks } from "../runtime/memory-hooks.js";
|
|
16
|
-
import { createQMemoryAdapter } from "../skills/qmemory-adapter.js";
|
|
17
|
-
import { AGENT_RPC_ERROR_CODES, AGENT_RPC_PROTOCOL_VERSION, isAgentRpcRequest, } from "qlogicagent-runtime-contracts";
|
|
18
|
-
export class StdioServer {
|
|
19
|
-
running = false;
|
|
20
|
-
activeTurn = null;
|
|
21
|
-
pendingToolResults = new Map();
|
|
22
|
-
verbose;
|
|
23
|
-
registry;
|
|
24
|
-
agent = null;
|
|
25
|
-
lastLlmConfigKey = "";
|
|
26
|
-
currentSessionId = "";
|
|
27
|
-
currentHooks = null;
|
|
28
|
-
constructor(config) {
|
|
29
|
-
this.verbose = config.verbose;
|
|
30
|
-
this.registry = new ProviderRegistry();
|
|
31
|
-
}
|
|
32
|
-
start() {
|
|
33
|
-
this.running = true;
|
|
34
|
-
this.log("qlogicagent CLI started, waiting for JSON-RPC on stdin...");
|
|
35
|
-
const rl = createInterface({
|
|
36
|
-
input: process.stdin,
|
|
37
|
-
crlfDelay: Number.POSITIVE_INFINITY,
|
|
38
|
-
});
|
|
39
|
-
rl.on("line", (line) => {
|
|
40
|
-
const trimmed = line.trim();
|
|
41
|
-
if (!trimmed)
|
|
42
|
-
return;
|
|
43
|
-
try {
|
|
44
|
-
const parsed = JSON.parse(trimmed);
|
|
45
|
-
if (!isAgentRpcRequest(parsed)) {
|
|
46
|
-
this.log(`[warn] ignoring non-request message: ${trimmed.slice(0, 200)}`);
|
|
47
|
-
return;
|
|
48
|
-
}
|
|
49
|
-
this.handleMessage(parsed);
|
|
50
|
-
}
|
|
51
|
-
catch {
|
|
52
|
-
this.log(`[warn] invalid JSON on stdin: ${trimmed.slice(0, 200)}`);
|
|
53
|
-
}
|
|
54
|
-
});
|
|
55
|
-
rl.on("close", () => {
|
|
56
|
-
this.log("stdin closed, shutting down");
|
|
57
|
-
this.stop();
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
stop() {
|
|
61
|
-
if (!this.running)
|
|
62
|
-
return;
|
|
63
|
-
this.running = false;
|
|
64
|
-
// Fire session.ended for active session
|
|
65
|
-
if (this.currentSessionId && this.currentHooks) {
|
|
66
|
-
this.currentHooks.invoke("session.ended", { sessionId: this.currentSessionId }).catch(() => { });
|
|
67
|
-
}
|
|
68
|
-
// Abort active turn if any
|
|
69
|
-
if (this.activeTurn) {
|
|
70
|
-
this.activeTurn.abort();
|
|
71
|
-
this.activeTurn = null;
|
|
72
|
-
}
|
|
73
|
-
// Reject all pending tool results
|
|
74
|
-
for (const [callId, pending] of this.pendingToolResults) {
|
|
75
|
-
pending.resolve({ result: "", error: "Agent process shutting down" });
|
|
76
|
-
}
|
|
77
|
-
this.pendingToolResults.clear();
|
|
78
|
-
this.log("stopped");
|
|
79
|
-
}
|
|
80
|
-
// ── Message dispatch ──────────────────────────────────────────────────
|
|
81
|
-
handleMessage(msg) {
|
|
82
|
-
switch (msg.method) {
|
|
83
|
-
case "agent.hello":
|
|
84
|
-
this.handleHello(msg);
|
|
85
|
-
break;
|
|
86
|
-
case "agent.ping":
|
|
87
|
-
this.handlePing(msg);
|
|
88
|
-
break;
|
|
89
|
-
case "agent.turn":
|
|
90
|
-
this.handleTurn(msg);
|
|
91
|
-
break;
|
|
92
|
-
case "memory.dream":
|
|
93
|
-
// Dream turns use the same agent.turn pipeline with dream-specific
|
|
94
|
-
// system prompt and messages. The Gateway sends memory.dream but the
|
|
95
|
-
// agent treats it as a regular turn with dream context.
|
|
96
|
-
this.handleTurn(msg);
|
|
97
|
-
break;
|
|
98
|
-
case "agent.abort":
|
|
99
|
-
this.handleAbort(msg);
|
|
100
|
-
break;
|
|
101
|
-
case "tool.result":
|
|
102
|
-
this.handleToolResult(msg);
|
|
103
|
-
break;
|
|
104
|
-
default:
|
|
105
|
-
if (msg.id !== undefined) {
|
|
106
|
-
this.sendResponse(msg.id, undefined, {
|
|
107
|
-
code: AGENT_RPC_ERROR_CODES.METHOD_NOT_FOUND,
|
|
108
|
-
message: `Unknown method: ${msg.method}`,
|
|
109
|
-
});
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
// ── Handlers ──────────────────────────────────────────────────────────
|
|
114
|
-
handleHello(msg) {
|
|
115
|
-
const params = msg.params;
|
|
116
|
-
const hostVersion = params?.protocolVersion ?? "unknown";
|
|
117
|
-
const majorHost = hostVersion.split(".")[0];
|
|
118
|
-
const majorSelf = AGENT_RPC_PROTOCOL_VERSION.split(".")[0];
|
|
119
|
-
if (majorHost !== majorSelf) {
|
|
120
|
-
this.log(`protocol mismatch: host=${hostVersion} agent=${AGENT_RPC_PROTOCOL_VERSION}`);
|
|
121
|
-
if (msg.id !== undefined) {
|
|
122
|
-
this.sendResponse(msg.id, undefined, {
|
|
123
|
-
code: AGENT_RPC_ERROR_CODES.PROTOCOL_MISMATCH,
|
|
124
|
-
message: `Protocol version mismatch: host=${hostVersion}, agent=${AGENT_RPC_PROTOCOL_VERSION}`,
|
|
125
|
-
});
|
|
126
|
-
}
|
|
127
|
-
return;
|
|
128
|
-
}
|
|
129
|
-
this.log(`hello from ${params?.hostName ?? "unknown"} v${params?.hostVersion ?? "?"} (protocol ${hostVersion})`);
|
|
130
|
-
if (msg.id !== undefined) {
|
|
131
|
-
this.sendResponse(msg.id, {
|
|
132
|
-
protocolVersion: AGENT_RPC_PROTOCOL_VERSION,
|
|
133
|
-
agentName: "qlogicagent",
|
|
134
|
-
agentVersion: "0.1.0",
|
|
135
|
-
capabilities: ["turn", "tool-invoke", "streaming"],
|
|
136
|
-
});
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
handlePing(msg) {
|
|
140
|
-
if (msg.id !== undefined) {
|
|
141
|
-
this.sendResponse(msg.id, { status: "ok" });
|
|
142
|
-
}
|
|
143
|
-
this.sendNotification("pong", {});
|
|
144
|
-
}
|
|
145
|
-
handleAbort(msg) {
|
|
146
|
-
const turnId = msg.params?.turnId ?? "";
|
|
147
|
-
this.log(`abort requested for turn ${turnId}`);
|
|
148
|
-
if (this.activeTurn) {
|
|
149
|
-
this.activeTurn.abort();
|
|
150
|
-
this.activeTurn = null;
|
|
151
|
-
}
|
|
152
|
-
if (msg.id !== undefined) {
|
|
153
|
-
this.sendResponse(msg.id, { aborted: true });
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
handleToolResult(msg) {
|
|
157
|
-
const callId = msg.params?.callId;
|
|
158
|
-
const result = msg.params?.result ?? "";
|
|
159
|
-
const error = msg.params?.error;
|
|
160
|
-
if (!callId) {
|
|
161
|
-
this.log("[warn] tool.result missing callId");
|
|
162
|
-
return;
|
|
163
|
-
}
|
|
164
|
-
const pending = this.pendingToolResults.get(callId);
|
|
165
|
-
if (pending) {
|
|
166
|
-
pending.resolve({ result, error });
|
|
167
|
-
this.pendingToolResults.delete(callId);
|
|
168
|
-
}
|
|
169
|
-
else {
|
|
170
|
-
this.log(`[warn] no pending tool call for callId ${callId}`);
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
async handleTurn(msg) {
|
|
174
|
-
const params = msg.params ?? {};
|
|
175
|
-
const turnId = params.turnId ?? randomUUID();
|
|
176
|
-
const sessionId = params.sessionId;
|
|
177
|
-
const messages = params.messages ?? [];
|
|
178
|
-
const tools = params.tools ?? [];
|
|
179
|
-
const config = params.config;
|
|
180
|
-
if (msg.id !== undefined) {
|
|
181
|
-
this.sendResponse(msg.id, { accepted: true, turnId });
|
|
182
|
-
}
|
|
183
|
-
// Session lifecycle: fire session.created when sessionId changes
|
|
184
|
-
if (sessionId && sessionId !== this.currentSessionId) {
|
|
185
|
-
if (this.currentSessionId && this.currentHooks) {
|
|
186
|
-
this.currentHooks.invoke("session.ended", { sessionId: this.currentSessionId }).catch(() => { });
|
|
187
|
-
}
|
|
188
|
-
this.currentSessionId = sessionId;
|
|
189
|
-
// session.created is fired after hooks are available (below in resolveAgent)
|
|
190
|
-
}
|
|
191
|
-
const ac = new AbortController();
|
|
192
|
-
this.activeTurn = ac;
|
|
193
|
-
this.log(`turn ${turnId} starting (session: ${sessionId})`);
|
|
194
|
-
try {
|
|
195
|
-
// ─── Resolve or create Agent with LLM config ──────────────
|
|
196
|
-
const turnConfig = {
|
|
197
|
-
provider: config?.provider,
|
|
198
|
-
model: config?.model,
|
|
199
|
-
apiKey: config?.apiKey,
|
|
200
|
-
baseUrl: config?.baseUrl,
|
|
201
|
-
maxRounds: config?.maxRounds,
|
|
202
|
-
temperature: config?.temperature,
|
|
203
|
-
contextWindowTokens: config?.contextWindowTokens,
|
|
204
|
-
maxOutputTokens: config?.maxOutputTokens,
|
|
205
|
-
modelMaxOutputTokens: config?.modelMaxOutputTokens,
|
|
206
|
-
};
|
|
207
|
-
const agent = this.resolveAgent(turnConfig);
|
|
208
|
-
if (!agent) {
|
|
209
|
-
this.sendNotification("turn.start", { turnId });
|
|
210
|
-
this.sendNotification("turn.error", {
|
|
211
|
-
turnId,
|
|
212
|
-
error: "No LLM provider configured. Provide provider/model/apiKey in agent.turn config, " +
|
|
213
|
-
"or set DEEPSEEK_API_KEY / OPENAI_API_KEY / ANTHROPIC_API_KEY environment variable.",
|
|
214
|
-
code: "NO_PROVIDER",
|
|
215
|
-
});
|
|
216
|
-
return;
|
|
217
|
-
}
|
|
218
|
-
// ─── Stream events from Agent ─────────────────────────────
|
|
219
|
-
const systemPrompt = config?.systemPrompt;
|
|
220
|
-
for await (const event of agent.run({
|
|
221
|
-
turnId,
|
|
222
|
-
sessionId,
|
|
223
|
-
messages,
|
|
224
|
-
tools,
|
|
225
|
-
systemPrompt,
|
|
226
|
-
config: turnConfig,
|
|
227
|
-
}, ac.signal)) {
|
|
228
|
-
// Forward all TurnEvent as JSON-RPC notifications
|
|
229
|
-
switch (event.type) {
|
|
230
|
-
case "start":
|
|
231
|
-
this.sendNotification("turn.start", { turnId: event.turnId });
|
|
232
|
-
break;
|
|
233
|
-
case "delta":
|
|
234
|
-
this.sendNotification("turn.delta", {
|
|
235
|
-
turnId: event.turnId,
|
|
236
|
-
text: event.text,
|
|
237
|
-
});
|
|
238
|
-
break;
|
|
239
|
-
case "end":
|
|
240
|
-
this.sendNotification("turn.end", {
|
|
241
|
-
turnId: event.turnId,
|
|
242
|
-
content: event.content,
|
|
243
|
-
usage: event.usage,
|
|
244
|
-
model: event.model,
|
|
245
|
-
provider: event.provider,
|
|
246
|
-
});
|
|
247
|
-
break;
|
|
248
|
-
case "error":
|
|
249
|
-
this.sendNotification("turn.error", {
|
|
250
|
-
turnId: event.turnId,
|
|
251
|
-
error: event.error,
|
|
252
|
-
code: event.code,
|
|
253
|
-
});
|
|
254
|
-
break;
|
|
255
|
-
case "skill_instruction":
|
|
256
|
-
this.sendNotification("turn.skill_instruction", {
|
|
257
|
-
turnId: event.turnId,
|
|
258
|
-
instruction: event.instruction,
|
|
259
|
-
});
|
|
260
|
-
break;
|
|
261
|
-
case "tool_call":
|
|
262
|
-
// Informational only — actual execution RPC is handled
|
|
263
|
-
// by requestToolExecution() when toolInvoker.invoke() is called.
|
|
264
|
-
break;
|
|
265
|
-
case "tool_result":
|
|
266
|
-
this.sendNotification("turn.tool_result", {
|
|
267
|
-
turnId: event.turnId,
|
|
268
|
-
callId: event.callId,
|
|
269
|
-
name: event.name,
|
|
270
|
-
ok: event.ok,
|
|
271
|
-
...(event.error ? { error: event.error } : {}),
|
|
272
|
-
});
|
|
273
|
-
break;
|
|
274
|
-
case "sidechain_started":
|
|
275
|
-
this.sendNotification("turn.sidechain_started", {
|
|
276
|
-
turnId: event.turnId,
|
|
277
|
-
depth: event.depth,
|
|
278
|
-
role: event.role,
|
|
279
|
-
});
|
|
280
|
-
break;
|
|
281
|
-
case "sidechain_completed":
|
|
282
|
-
this.sendNotification("turn.sidechain_completed", {
|
|
283
|
-
turnId: event.turnId,
|
|
284
|
-
depth: event.depth,
|
|
285
|
-
toolCallCount: event.toolCallCount,
|
|
286
|
-
});
|
|
287
|
-
break;
|
|
288
|
-
case "tool_blocked":
|
|
289
|
-
this.sendNotification("turn.tool_blocked", {
|
|
290
|
-
turnId: event.turnId,
|
|
291
|
-
callId: event.callId,
|
|
292
|
-
name: event.name,
|
|
293
|
-
reason: event.reason,
|
|
294
|
-
});
|
|
295
|
-
break;
|
|
296
|
-
case "recovery":
|
|
297
|
-
this.sendNotification("turn.recovery", {
|
|
298
|
-
turnId: event.turnId,
|
|
299
|
-
action: event.action,
|
|
300
|
-
...(event.detail ? { detail: event.detail } : {}),
|
|
301
|
-
});
|
|
302
|
-
break;
|
|
303
|
-
case "plan_update":
|
|
304
|
-
this.sendNotification("turn.plan_update", {
|
|
305
|
-
turnId: event.turnId,
|
|
306
|
-
slug: event.slug,
|
|
307
|
-
content: event.content,
|
|
308
|
-
});
|
|
309
|
-
break;
|
|
310
|
-
}
|
|
311
|
-
}
|
|
312
|
-
this.log(`turn ${turnId} completed`);
|
|
313
|
-
}
|
|
314
|
-
catch (err) {
|
|
315
|
-
if (ac.signal.aborted) {
|
|
316
|
-
this.sendNotification("turn.error", {
|
|
317
|
-
turnId,
|
|
318
|
-
error: "Turn aborted",
|
|
319
|
-
code: "ABORTED",
|
|
320
|
-
});
|
|
321
|
-
}
|
|
322
|
-
else {
|
|
323
|
-
const message = err instanceof Error ? err.message : String(err);
|
|
324
|
-
this.sendNotification("turn.error", {
|
|
325
|
-
turnId,
|
|
326
|
-
error: message,
|
|
327
|
-
code: "INTERNAL_ERROR",
|
|
328
|
-
});
|
|
329
|
-
}
|
|
330
|
-
}
|
|
331
|
-
finally {
|
|
332
|
-
if (this.activeTurn === ac) {
|
|
333
|
-
this.activeTurn = null;
|
|
334
|
-
}
|
|
335
|
-
}
|
|
336
|
-
}
|
|
337
|
-
// ── Agent resolution (lazy create / re-create on config change) ───────
|
|
338
|
-
resolveAgent(config) {
|
|
339
|
-
// Build a config key to detect provider/model/key changes
|
|
340
|
-
const configKey = `${config.provider ?? ""}:${config.model ?? ""}:${config.apiKey?.slice(0, 8) ?? ""}:${config.baseUrl ?? ""}`;
|
|
341
|
-
if (this.agent && this.lastLlmConfigKey === configKey) {
|
|
342
|
-
return this.agent;
|
|
343
|
-
}
|
|
344
|
-
// Try explicit config first
|
|
345
|
-
let provider = config.provider;
|
|
346
|
-
let model = config.model;
|
|
347
|
-
let apiKey = config.apiKey;
|
|
348
|
-
const baseUrl = config.baseUrl;
|
|
349
|
-
if (!provider || !apiKey) {
|
|
350
|
-
// Fallback: auto-detect from env
|
|
351
|
-
const detected = autoDetectProvider(this.registry);
|
|
352
|
-
if (detected) {
|
|
353
|
-
provider = provider ?? detected.providerId;
|
|
354
|
-
apiKey = apiKey ?? detected.apiKey;
|
|
355
|
-
model = model ?? detected.defaultModel;
|
|
356
|
-
this.log(`auto-detected provider: ${provider}, model: ${model}`);
|
|
357
|
-
}
|
|
358
|
-
}
|
|
359
|
-
if (!provider || !apiKey) {
|
|
360
|
-
return null;
|
|
361
|
-
}
|
|
362
|
-
model = model ?? this.registry.getProvider(provider)?.defaultModel ?? "";
|
|
363
|
-
const client = createLLMClient({ provider, model, apiKey, baseUrl }, this.registry);
|
|
364
|
-
const log = {
|
|
365
|
-
info: (m) => this.log(m),
|
|
366
|
-
warn: (m) => this.log(`[warn] ${m}`),
|
|
367
|
-
error: (m) => this.log(`[error] ${m}`),
|
|
368
|
-
debug: (m) => {
|
|
369
|
-
if (this.verbose)
|
|
370
|
-
this.log(`[debug] ${m}`);
|
|
371
|
-
},
|
|
372
|
-
};
|
|
373
|
-
const toolInvoker = {
|
|
374
|
-
invoke: (turnId, name, args, signal) => this.requestToolExecution(turnId, name, args, signal),
|
|
375
|
-
};
|
|
376
|
-
// ─── HookRegistry ────────────────────────────────────────
|
|
377
|
-
// Skill learning: handled directly in tool-loop (has full metrics context).
|
|
378
|
-
// The tool-loop yields `skill_instruction` events → forwarded above in handleTurn().
|
|
379
|
-
// HookRegistry is available for context-compression and future hooks.
|
|
380
|
-
const hooks = createHookRegistry(log);
|
|
381
|
-
this.currentHooks = hooks;
|
|
382
|
-
// ─── Memory hooks (qmemory REST API) ─────────────────────
|
|
383
|
-
const qmemoryBaseUrl = (process.env.QMEMORY_BASE_URL ??
|
|
384
|
-
process.env.QLOGICAGENT_QMEMORY_BASE_URL ??
|
|
385
|
-
"").trim().replace(/\/+$/, "");
|
|
386
|
-
if (qmemoryBaseUrl) {
|
|
387
|
-
const memoryProvider = createQMemoryAdapter({
|
|
388
|
-
baseUrl: qmemoryBaseUrl,
|
|
389
|
-
apiKey: (process.env.QMEMORY_API_KEY ?? "").trim() || undefined,
|
|
390
|
-
timeoutMs: 5_000,
|
|
391
|
-
});
|
|
392
|
-
registerMemoryHooks(hooks, {
|
|
393
|
-
memoryProvider,
|
|
394
|
-
userId: this.currentSessionId ?? "default",
|
|
395
|
-
log: { debug: (m) => log.debug(m), warn: (m) => log.warn(m) },
|
|
396
|
-
});
|
|
397
|
-
}
|
|
398
|
-
// Fire session.created for the current session
|
|
399
|
-
if (this.currentSessionId) {
|
|
400
|
-
hooks.invoke("session.created", { sessionId: this.currentSessionId }).catch(() => { });
|
|
401
|
-
}
|
|
402
|
-
this.agent = new Agent({
|
|
403
|
-
llmTransport: client.transport,
|
|
404
|
-
apiKey: client.apiKey,
|
|
405
|
-
toolInvoker,
|
|
406
|
-
log,
|
|
407
|
-
hooks,
|
|
408
|
-
maxRounds: config.maxRounds,
|
|
409
|
-
verbose: this.verbose,
|
|
410
|
-
});
|
|
411
|
-
this.lastLlmConfigKey = configKey;
|
|
412
|
-
this.log(`created Agent (provider: ${provider}, model: ${model})`);
|
|
413
|
-
return this.agent;
|
|
414
|
-
}
|
|
415
|
-
// ── Tool call request (used by real Agent in Phase 2+) ────────────────
|
|
416
|
-
/**
|
|
417
|
-
* Request tool execution from the Gateway host.
|
|
418
|
-
* Sends a turn.tool_call notification and waits for tool.result.
|
|
419
|
-
*/
|
|
420
|
-
async requestToolExecution(turnId, name, args, signal) {
|
|
421
|
-
const callId = `tc_${randomUUID().slice(0, 8)}`;
|
|
422
|
-
return new Promise((resolve, reject) => {
|
|
423
|
-
if (signal?.aborted) {
|
|
424
|
-
reject(new Error("Aborted"));
|
|
425
|
-
return;
|
|
426
|
-
}
|
|
427
|
-
this.pendingToolResults.set(callId, { resolve });
|
|
428
|
-
const onAbort = () => {
|
|
429
|
-
this.pendingToolResults.delete(callId);
|
|
430
|
-
reject(new Error("Aborted"));
|
|
431
|
-
};
|
|
432
|
-
signal?.addEventListener("abort", onAbort, { once: true });
|
|
433
|
-
this.sendNotification("turn.tool_call", {
|
|
434
|
-
turnId,
|
|
435
|
-
callId,
|
|
436
|
-
name,
|
|
437
|
-
arguments: args,
|
|
438
|
-
});
|
|
439
|
-
});
|
|
440
|
-
}
|
|
441
|
-
// ── Helpers ───────────────────────────────────────────────────────────
|
|
442
|
-
// ── I/O ───────────────────────────────────────────────────────────────
|
|
443
|
-
sendResponse(id, result, error) {
|
|
444
|
-
const msg = { jsonrpc: "2.0", id };
|
|
445
|
-
if (error)
|
|
446
|
-
msg.error = error;
|
|
447
|
-
else
|
|
448
|
-
msg.result = result;
|
|
449
|
-
this.writeStdout(msg);
|
|
450
|
-
}
|
|
451
|
-
sendNotification(method, params) {
|
|
452
|
-
const msg = { jsonrpc: "2.0", method, params };
|
|
453
|
-
this.writeStdout(msg);
|
|
454
|
-
}
|
|
455
|
-
writeStdout(msg) {
|
|
456
|
-
process.stdout.write(`${JSON.stringify(msg)}\n`);
|
|
457
|
-
}
|
|
458
|
-
log(message) {
|
|
459
|
-
if (this.verbose) {
|
|
460
|
-
process.stderr.write(`[qlogicagent] ${message}\n`);
|
|
461
|
-
}
|
|
462
|
-
}
|
|
463
|
-
}
|
package/dist/config/config.js
DELETED
|
@@ -1,21 +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
|
-
/**
|
|
8
|
-
* Parse CLI arguments into AgentConfig.
|
|
9
|
-
*
|
|
10
|
-
* Supports:
|
|
11
|
-
* --verbose / -v Enable verbose logging
|
|
12
|
-
*/
|
|
13
|
-
export function parseCliArgs(argv) {
|
|
14
|
-
const config = { verbose: false };
|
|
15
|
-
for (const arg of argv.slice(2)) {
|
|
16
|
-
if (arg === "--verbose" || arg === "-v") {
|
|
17
|
-
config.verbose = true;
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
return config;
|
|
21
|
-
}
|
package/dist/contracts/hooks.js
DELETED
package/dist/contracts/index.js
DELETED
|
@@ -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";
|