hyperclaw 5.2.5 → 5.2.6
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/audit-NPINyRh4.js +445 -0
- package/dist/chat-8E4H6nqx.js +325 -0
- package/dist/connector-1_9a4Mhv.js +276 -0
- package/dist/connector-BeHsEhpz.js +164 -0
- package/dist/connector-DJ63fLj9.js +555 -0
- package/dist/connector-Ic8H84de.js +204 -0
- package/dist/daemon-DRhU750_.js +7 -0
- package/dist/daemon-bJ8IYnkd.js +421 -0
- package/dist/delivery-1vTBQ0a0.js +95 -0
- package/dist/delivery-BbOfKejh.js +4 -0
- package/dist/engine-BjzV25HS.js +7 -0
- package/dist/engine-DJSr69DF.js +327 -0
- package/dist/heartbeat-engine-0swQl6wg.js +89 -0
- package/dist/hub-BuUwiTxh.js +6 -0
- package/dist/hub-DIoASRn6.js +512 -0
- package/dist/hyperclawbot-CIvGq2IG.js +516 -0
- package/dist/inference-BSWFHqzs.js +2854 -0
- package/dist/inference-DQiqWbqu.js +8 -0
- package/dist/loader-Bpju2Xqs.js +6 -0
- package/dist/loader-DRfmh8hU.js +410 -0
- package/dist/logger-CnxILOPV.js +86 -0
- package/dist/mcp-loader-D-uIqYwB.js +93 -0
- package/dist/memory-auto-CK5M1YV8.js +5 -0
- package/dist/memory-auto-Cs6XiIxb.js +306 -0
- package/dist/node-4_wJsNEN.js +226 -0
- package/dist/oauth-flow-CJ7dFXKT.js +148 -0
- package/dist/onboard-C1RArB82.js +3865 -0
- package/dist/onboard-CQkUrkNk.js +13 -0
- package/dist/orchestrator-D9R2u9yL.js +6 -0
- package/dist/orchestrator-DMDgfB8j.js +189 -0
- package/dist/pairing-CNNtZ8JR.js +6 -0
- package/dist/pairing-fGaxBlgG.js +207 -0
- package/dist/pc-access-CaE4x3Vt.js +8 -0
- package/dist/pc-access-OIwXRyAD.js +858 -0
- package/dist/run-main.js +50 -44
- package/dist/runner-CFvEFt23.js +1274 -0
- package/dist/server-BSCeWSlZ.js +1304 -0
- package/dist/server-DIwR4tT3.js +4 -0
- package/dist/skill-runtime-CCwGR7iX.js +5 -0
- package/dist/skill-runtime-vmBIhuVk.js +104 -0
- package/dist/src-3dXyf5GQ.js +458 -0
- package/dist/src-BVeLalMV.js +63 -0
- package/dist/sub-agent-tools-C1dWyUAR.js +39 -0
- package/dist/tts-elevenlabs-F_xjKQ-I.js +64 -0
- package/dist/vision-BR5Gdb2s.js +169 -0
- package/dist/vision-tools-DuB1QtlE.js +51 -0
- package/dist/vision-tools-LvL8RMWR.js +5 -0
- package/dist/voice-transcription-D6dK7b9A.js +171 -0
- package/dist/website-watch-tools-Cqp7RPvn.js +176 -0
- package/dist/website-watch-tools-UPSrnBk2.js +5 -0
- package/package.json +1 -1
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
|
|
2
|
+
//#region src/channels/delivery.ts
|
|
3
|
+
/**
|
|
4
|
+
|
|
5
|
+
* src/channels/delivery.ts
|
|
6
|
+
|
|
7
|
+
* Delivery pipeline: queue retry, per-channel chunking, media handling.
|
|
8
|
+
|
|
9
|
+
*/
|
|
10
|
+
const CHANNEL_MAX_LENGTH = {
|
|
11
|
+
telegram: 4096,
|
|
12
|
+
discord: 2e3,
|
|
13
|
+
whatsapp: 4096,
|
|
14
|
+
"whatsapp-baileys": 4096,
|
|
15
|
+
slack: 4e4,
|
|
16
|
+
googlechat: 4096,
|
|
17
|
+
msteams: 28e3,
|
|
18
|
+
matrix: 32768,
|
|
19
|
+
irc: 512,
|
|
20
|
+
mattermost: 16383,
|
|
21
|
+
signal: 4096,
|
|
22
|
+
line: 2e3,
|
|
23
|
+
twitch: 490,
|
|
24
|
+
viber: 7e3,
|
|
25
|
+
default: 4e3
|
|
26
|
+
};
|
|
27
|
+
function chunkForChannel(text, channelId) {
|
|
28
|
+
const max = CHANNEL_MAX_LENGTH[channelId] ?? CHANNEL_MAX_LENGTH.default;
|
|
29
|
+
if (text.length <= max) return [text];
|
|
30
|
+
const chunks = [];
|
|
31
|
+
let i = 0;
|
|
32
|
+
while (i < text.length) {
|
|
33
|
+
let end = Math.min(i + max, text.length);
|
|
34
|
+
if (end < text.length) {
|
|
35
|
+
const nl = text.lastIndexOf("\n", end);
|
|
36
|
+
if (nl > i) end = nl + 1;
|
|
37
|
+
}
|
|
38
|
+
chunks.push(text.slice(i, end));
|
|
39
|
+
i = end;
|
|
40
|
+
}
|
|
41
|
+
return chunks;
|
|
42
|
+
}
|
|
43
|
+
const DEFAULT_RETRIES = 3;
|
|
44
|
+
const DEFAULT_BACKOFF_MS = 1e3;
|
|
45
|
+
async function withRetry(fn, opts) {
|
|
46
|
+
const retries = opts?.retries ?? DEFAULT_RETRIES;
|
|
47
|
+
const backoff = opts?.backoffMs ?? DEFAULT_BACKOFF_MS;
|
|
48
|
+
let lastErr = null;
|
|
49
|
+
for (let i = 0; i <= retries; i++) try {
|
|
50
|
+
return await fn();
|
|
51
|
+
} catch (e) {
|
|
52
|
+
lastErr = e;
|
|
53
|
+
opts?.onRetry?.(i + 1, lastErr);
|
|
54
|
+
if (i < retries) await new Promise((r) => setTimeout(r, backoff * Math.pow(2, i)));
|
|
55
|
+
}
|
|
56
|
+
throw lastErr;
|
|
57
|
+
}
|
|
58
|
+
/** Enrich message text from voice note (transcribe if audioPath/audioBuffer provided). */
|
|
59
|
+
async function enrichVoiceNote(msg) {
|
|
60
|
+
if (!msg.audioPath && !msg.audioBuffer) return msg.text;
|
|
61
|
+
if (msg.text && msg.text !== "[voice note]") return msg.text;
|
|
62
|
+
try {
|
|
63
|
+
const { transcribeVoiceNote } = await Promise.resolve().then(() => require("./voice-transcription-D6dK7b9A.js"));
|
|
64
|
+
const text = await transcribeVoiceNote(msg.audioBuffer ?? msg.audioPath);
|
|
65
|
+
return text || msg.text;
|
|
66
|
+
} catch (e) {
|
|
67
|
+
return `[Voice note — transcription failed: ${e.message}]`;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
//#endregion
|
|
72
|
+
Object.defineProperty(exports, 'CHANNEL_MAX_LENGTH', {
|
|
73
|
+
enumerable: true,
|
|
74
|
+
get: function () {
|
|
75
|
+
return CHANNEL_MAX_LENGTH;
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
Object.defineProperty(exports, 'chunkForChannel', {
|
|
79
|
+
enumerable: true,
|
|
80
|
+
get: function () {
|
|
81
|
+
return chunkForChannel;
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
Object.defineProperty(exports, 'enrichVoiceNote', {
|
|
85
|
+
enumerable: true,
|
|
86
|
+
get: function () {
|
|
87
|
+
return enrichVoiceNote;
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
Object.defineProperty(exports, 'withRetry', {
|
|
91
|
+
enumerable: true,
|
|
92
|
+
get: function () {
|
|
93
|
+
return withRetry;
|
|
94
|
+
}
|
|
95
|
+
});
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
const require_chunk = require('./chunk-jS-bbMI5.js');
|
|
2
|
+
require('./paths-AIyBxIzm.js');
|
|
3
|
+
require('./src-CbTAVbeI.js');
|
|
4
|
+
const require_engine = require('./engine-DJSr69DF.js');
|
|
5
|
+
|
|
6
|
+
require_engine.init_engine();
|
|
7
|
+
exports.runAgentEngine = require_engine.runAgentEngine;
|
|
@@ -0,0 +1,327 @@
|
|
|
1
|
+
const require_chunk = require('./chunk-jS-bbMI5.js');
|
|
2
|
+
const require_paths = require('./paths-AIyBxIzm.js');
|
|
3
|
+
const require_src = require('./src-CbTAVbeI.js');
|
|
4
|
+
const fs_extra = require_chunk.__toESM(require("fs-extra"));
|
|
5
|
+
const path = require_chunk.__toESM(require("path"));
|
|
6
|
+
|
|
7
|
+
//#region packages/core/src/agent/engine.ts
|
|
8
|
+
/**
|
|
9
|
+
|
|
10
|
+
* Load workspace context: SOUL, AGENTS, MEMORY + custom .md
|
|
11
|
+
|
|
12
|
+
*/
|
|
13
|
+
async function loadWorkspaceContext(hcDir) {
|
|
14
|
+
const dir = hcDir || require_paths.getHyperClawDir();
|
|
15
|
+
let context = "";
|
|
16
|
+
const core = [
|
|
17
|
+
"SOUL.md",
|
|
18
|
+
"AGENTS.md",
|
|
19
|
+
"MEMORY.md"
|
|
20
|
+
];
|
|
21
|
+
for (const f of core) {
|
|
22
|
+
const fp = path.default.join(dir, f);
|
|
23
|
+
try {
|
|
24
|
+
context += `## ${f}\n${fs_extra.default.readFileSync(fp, "utf8")}\n\n`;
|
|
25
|
+
} catch {}
|
|
26
|
+
}
|
|
27
|
+
try {
|
|
28
|
+
const entries = fs_extra.default.readdirSync(dir);
|
|
29
|
+
for (const f of entries) if (f.endsWith(".md") && !core.includes(f)) {
|
|
30
|
+
const fp = path.default.join(dir, f);
|
|
31
|
+
try {
|
|
32
|
+
context += `## ${f}\n${fs_extra.default.readFileSync(fp, "utf8")}\n\n`;
|
|
33
|
+
} catch {}
|
|
34
|
+
}
|
|
35
|
+
} catch {}
|
|
36
|
+
return context;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
|
|
40
|
+
* Load skills context (bundled + workspace)
|
|
41
|
+
|
|
42
|
+
*/
|
|
43
|
+
async function loadSkillsContext() {
|
|
44
|
+
const { loadSkills, buildSkillsContext } = await Promise.resolve().then(() => require("./skill-loader-DwbmjEDa.js"));
|
|
45
|
+
const skills = await loadSkills();
|
|
46
|
+
return skills.length > 0 ? buildSkillsContext(skills) : "";
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
|
|
50
|
+
* Resolve tools with policy, PC access, elevation.
|
|
51
|
+
|
|
52
|
+
*/
|
|
53
|
+
async function resolveTools(opts) {
|
|
54
|
+
const { config, source, elevated, sessionId, daemonMode, activeServer } = opts;
|
|
55
|
+
const cfg = config;
|
|
56
|
+
const sandboxNonMain = cfg?.agents?.defaults?.sandbox?.mode === "non-main" && source && CHANNEL_SOURCES.includes(source);
|
|
57
|
+
const { loadPCAccessConfig, getPCAccessTools } = await Promise.resolve().then(() => require("./pc-access-CaE4x3Vt.js"));
|
|
58
|
+
const pcCfg = await loadPCAccessConfig({ daemonMode });
|
|
59
|
+
const dockerSandbox = cfg?.tools?.dockerSandbox?.enabled === true;
|
|
60
|
+
const pcTools = pcCfg.enabled && (!sandboxNonMain || elevated) ? getPCAccessTools({ dockerSandbox }) : [];
|
|
61
|
+
const { getSessionsTools } = await Promise.resolve().then(() => require("./sessions-tools-B5_ow-s7.js"));
|
|
62
|
+
const sessionsTools = getSessionsTools(() => activeServer ?? null, sessionId);
|
|
63
|
+
const { InferenceEngine, getBuiltinTools } = await Promise.resolve().then(() => require("./inference-DQiqWbqu.js"));
|
|
64
|
+
const { getSubAgentTools } = await Promise.resolve().then(() => require("./sub-agent-tools-C1dWyUAR.js"));
|
|
65
|
+
const { getBrowserTools } = await Promise.resolve().then(() => require("./browser-tools-DF2nQ1hi.js"));
|
|
66
|
+
const { getExtractionTools } = await Promise.resolve().then(() => require("./extraction-tools-B8F3nsLR.js"));
|
|
67
|
+
const { getWebsiteWatchTools } = await Promise.resolve().then(() => require("./website-watch-tools-UPSrnBk2.js"));
|
|
68
|
+
const { getVisionTools } = await Promise.resolve().then(() => require("./vision-tools-LvL8RMWR.js"));
|
|
69
|
+
const { getBountyTools } = await Promise.resolve().then(() => require("./bounty-tools-DWvW3yc-.js"));
|
|
70
|
+
const { loadMCPTools } = await Promise.resolve().then(() => require("./mcp-loader-D-uIqYwB.js"));
|
|
71
|
+
const { applyToolPolicy } = await Promise.resolve().then(() => require("./tool-policy-TmXx_fpp.js"));
|
|
72
|
+
const CUSTOM_BASEURL_PROVIDERS = new Set([
|
|
73
|
+
"groq",
|
|
74
|
+
"mistral",
|
|
75
|
+
"deepseek",
|
|
76
|
+
"perplexity",
|
|
77
|
+
"huggingface",
|
|
78
|
+
"ollama",
|
|
79
|
+
"lmstudio",
|
|
80
|
+
"local",
|
|
81
|
+
"xai",
|
|
82
|
+
"openai",
|
|
83
|
+
"google",
|
|
84
|
+
"minimax",
|
|
85
|
+
"moonshot",
|
|
86
|
+
"qwen",
|
|
87
|
+
"zai",
|
|
88
|
+
"litellm",
|
|
89
|
+
"cloudflare",
|
|
90
|
+
"copilot",
|
|
91
|
+
"vercel-ai",
|
|
92
|
+
"opencode-zen"
|
|
93
|
+
]);
|
|
94
|
+
const isLocal = cfg?.provider?.providerId === "local" || cfg?.provider?.providerId === "ollama" || cfg?.provider?.providerId === "lmstudio";
|
|
95
|
+
const provider = cfg?.provider?.providerId === "anthropic" || cfg?.provider?.providerId === "anthropic-oauth" || cfg?.provider?.providerId === "anthropic-setup-token" ? "anthropic" : cfg?.provider?.providerId === "custom" || isLocal || CUSTOM_BASEURL_PROVIDERS.has(cfg?.provider?.providerId ?? "") ? "custom" : "openrouter";
|
|
96
|
+
const visionProvider = cfg?.provider?.providerId === "custom" || isLocal ? "openrouter" : provider === "anthropic" ? "anthropic" : "openrouter";
|
|
97
|
+
const apiKey = await (await Promise.resolve().then(() => require("./env-resolve-CC_po9t5.js"))).getProviderCredentialAsync(cfg);
|
|
98
|
+
const visionTools = getVisionTools({
|
|
99
|
+
apiKey: apiKey || "",
|
|
100
|
+
provider: visionProvider
|
|
101
|
+
});
|
|
102
|
+
const bountyTools = getBountyTools(cfg);
|
|
103
|
+
let skillInvokeTools = [];
|
|
104
|
+
try {
|
|
105
|
+
const { loadSkills } = await Promise.resolve().then(() => require("./skill-loader-DwbmjEDa.js"));
|
|
106
|
+
const { getSkillInvokeTools } = await Promise.resolve().then(() => require("./skill-runtime-CCwGR7iX.js"));
|
|
107
|
+
const loaded = await loadSkills();
|
|
108
|
+
skillInvokeTools = getSkillInvokeTools(loaded);
|
|
109
|
+
} catch (e) {
|
|
110
|
+
if (typeof process !== "undefined" && process.env?.DEBUG) console.error("[engine] loadSkills failed:", e?.message ?? e);
|
|
111
|
+
}
|
|
112
|
+
let allTools = [
|
|
113
|
+
...getBuiltinTools(),
|
|
114
|
+
...getSubAgentTools(),
|
|
115
|
+
...sessionsTools,
|
|
116
|
+
...pcTools,
|
|
117
|
+
...getBrowserTools(),
|
|
118
|
+
...getExtractionTools(),
|
|
119
|
+
...getWebsiteWatchTools(),
|
|
120
|
+
...visionTools,
|
|
121
|
+
...bountyTools,
|
|
122
|
+
...skillInvokeTools
|
|
123
|
+
];
|
|
124
|
+
try {
|
|
125
|
+
const mcpTools = await loadMCPTools();
|
|
126
|
+
if (mcpTools.length > 0) allTools = [...allTools, ...mcpTools];
|
|
127
|
+
} catch {}
|
|
128
|
+
const policyConfig = cfg?.tools ? {
|
|
129
|
+
profile: cfg.tools.profile,
|
|
130
|
+
allow: cfg.tools.allow ?? cfg.tools.allowlist,
|
|
131
|
+
deny: cfg.tools.deny ?? cfg.tools.blocklist,
|
|
132
|
+
byProvider: cfg.tools.byProvider
|
|
133
|
+
} : void 0;
|
|
134
|
+
let tools = applyToolPolicy(allTools, policyConfig, {
|
|
135
|
+
provider: cfg?.provider?.providerId === "anthropic" ? "anthropic" : "openrouter",
|
|
136
|
+
model: cfg?.provider?.modelId
|
|
137
|
+
});
|
|
138
|
+
const { applyDestructiveGate } = await Promise.resolve().then(() => require("./destructive-gate-DcEpMEqP.js"));
|
|
139
|
+
tools = applyDestructiveGate(tools, {
|
|
140
|
+
elevated: elevated ?? false,
|
|
141
|
+
source,
|
|
142
|
+
sessionId
|
|
143
|
+
});
|
|
144
|
+
return tools;
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
|
|
148
|
+
* Run agent: context + tools + inference.
|
|
149
|
+
|
|
150
|
+
*/
|
|
151
|
+
async function runAgentEngine(message, opts) {
|
|
152
|
+
const cfg = await fs_extra.default.readJson(require_paths.getConfigPath()).catch(() => ({}));
|
|
153
|
+
const CUSTOM_BASEURL_IDS = new Set([
|
|
154
|
+
"groq",
|
|
155
|
+
"mistral",
|
|
156
|
+
"deepseek",
|
|
157
|
+
"perplexity",
|
|
158
|
+
"huggingface",
|
|
159
|
+
"ollama",
|
|
160
|
+
"lmstudio",
|
|
161
|
+
"local",
|
|
162
|
+
"xai",
|
|
163
|
+
"openai",
|
|
164
|
+
"google",
|
|
165
|
+
"minimax",
|
|
166
|
+
"moonshot",
|
|
167
|
+
"qwen",
|
|
168
|
+
"zai",
|
|
169
|
+
"litellm",
|
|
170
|
+
"cloudflare",
|
|
171
|
+
"copilot",
|
|
172
|
+
"vercel-ai",
|
|
173
|
+
"opencode-zen"
|
|
174
|
+
]);
|
|
175
|
+
const isLocalProvider = cfg?.provider?.providerId === "local" || cfg?.provider?.providerId === "ollama" || cfg?.provider?.providerId === "lmstudio";
|
|
176
|
+
const apiKey = await (await Promise.resolve().then(() => require("./env-resolve-CC_po9t5.js"))).getProviderCredentialAsync(cfg);
|
|
177
|
+
if (!apiKey && !isLocalProvider) return {
|
|
178
|
+
text: "No API key configured. Run: hyperclaw config set-key",
|
|
179
|
+
error: "no_api_key"
|
|
180
|
+
};
|
|
181
|
+
const { getProvider } = await Promise.resolve().then(() => require("./providers-CFQC39vg.js"));
|
|
182
|
+
const providerMeta = getProvider(cfg?.provider?.providerId ?? "");
|
|
183
|
+
const registryBaseUrl = providerMeta?.baseUrl;
|
|
184
|
+
const sid = opts.sessionId;
|
|
185
|
+
const sessionKey = opts.sessionKey;
|
|
186
|
+
const effectiveKey = sessionKey || sid;
|
|
187
|
+
if (sessionKey && !opts.getTranscript && !opts.appendTranscript) console.warn("[engine] sessionKey provided but getTranscript/appendTranscript missing — session continuity disabled");
|
|
188
|
+
let messagesForInference = [{
|
|
189
|
+
role: "user",
|
|
190
|
+
content: message
|
|
191
|
+
}];
|
|
192
|
+
if (effectiveKey && opts.getTranscript) try {
|
|
193
|
+
const restored = await opts.getTranscript(effectiveKey);
|
|
194
|
+
if (restored && restored.length > 0) {
|
|
195
|
+
const valid = restored.filter((t) => (t.role === "user" || t.role === "assistant") && typeof t.content === "string");
|
|
196
|
+
messagesForInference = [...valid, {
|
|
197
|
+
role: "user",
|
|
198
|
+
content: message
|
|
199
|
+
}];
|
|
200
|
+
}
|
|
201
|
+
} catch (e) {
|
|
202
|
+
console.warn("[engine] Failed to restore transcript for", effectiveKey, e.message);
|
|
203
|
+
}
|
|
204
|
+
if (effectiveKey && opts.appendTranscript) opts.appendTranscript(effectiveKey, "user", message, opts.source);
|
|
205
|
+
let context = await loadWorkspaceContext(opts.workspace);
|
|
206
|
+
try {
|
|
207
|
+
const { getContextSummary } = await Promise.resolve().then(() => require("./knowledge-graph-BxrAiV2B.js"));
|
|
208
|
+
const kg = await getContextSummary(25);
|
|
209
|
+
if (kg) context += kg + "\n\n";
|
|
210
|
+
} catch {}
|
|
211
|
+
context += await loadSkillsContext();
|
|
212
|
+
const serviceKeys = cfg?.skills?.apiKeys ? Object.keys(cfg.skills.apiKeys) : [];
|
|
213
|
+
if (serviceKeys.length > 0) context += `\n## Service API Keys (configured)\nAvailable for research/skills: ${serviceKeys.join(", ")}. Use hackerone_list_programs, bugcrowd_list_programs, synack_list_targets when applicable, or create_skill for custom integrations.\n\n`;
|
|
214
|
+
const tools = await resolveTools({
|
|
215
|
+
config: cfg,
|
|
216
|
+
source: opts.source,
|
|
217
|
+
elevated: opts.elevated,
|
|
218
|
+
sessionId: sid,
|
|
219
|
+
daemonMode: opts.daemonMode,
|
|
220
|
+
activeServer: opts.activeServer
|
|
221
|
+
});
|
|
222
|
+
const rawModel = opts.modelOverride || cfg?.provider?.modelId || "claude-sonnet-4-5";
|
|
223
|
+
const isLocal2 = cfg?.provider?.providerId === "local" || cfg?.provider?.providerId === "ollama" || cfg?.provider?.providerId === "lmstudio";
|
|
224
|
+
const model = rawModel.startsWith("ollama/") ? rawModel.slice(7) : rawModel;
|
|
225
|
+
const isAnthropicVariant = cfg?.provider?.providerId === "anthropic" || cfg?.provider?.providerId === "anthropic-oauth" || cfg?.provider?.providerId === "anthropic-setup-token";
|
|
226
|
+
const provider = isAnthropicVariant ? "anthropic" : cfg?.provider?.providerId === "custom" || isLocal2 || CUSTOM_BASEURL_IDS.has(cfg?.provider?.providerId ?? "") ? "custom" : "openrouter";
|
|
227
|
+
const resolvedBaseUrl = cfg?.provider?.baseUrl || registryBaseUrl || (isLocal2 ? "http://localhost:11434/v1" : void 0);
|
|
228
|
+
const ollamaBaseUrl = isLocal2 ? cfg?.provider?.baseUrl || "http://localhost:11434/v1" : void 0;
|
|
229
|
+
const thinkingBudget = opts.thinkingBudget ?? 0;
|
|
230
|
+
const maxTokens = thinkingBudget > 0 ? thinkingBudget + 4096 : 4096;
|
|
231
|
+
try {
|
|
232
|
+
const { InferenceEngine } = await Promise.resolve().then(() => require("./inference-DQiqWbqu.js"));
|
|
233
|
+
const engineOpts = {
|
|
234
|
+
model,
|
|
235
|
+
apiKey,
|
|
236
|
+
provider,
|
|
237
|
+
system: context || void 0,
|
|
238
|
+
tools,
|
|
239
|
+
maxTokens,
|
|
240
|
+
onToken: opts.onToken ?? (() => {}),
|
|
241
|
+
onThinking: opts.onThinking,
|
|
242
|
+
onToolCall: opts.onToolCall,
|
|
243
|
+
onToolResult: opts.onToolResult,
|
|
244
|
+
...provider === "custom" ? { baseUrl: ollamaBaseUrl || resolvedBaseUrl || "" } : {},
|
|
245
|
+
...thinkingBudget > 0 && (model.includes("claude") || model.includes("anthropic")) ? { thinking: { budget_tokens: thinkingBudget } } : {}
|
|
246
|
+
};
|
|
247
|
+
const engine = new InferenceEngine(engineOpts);
|
|
248
|
+
const result = await engine.run(messagesForInference);
|
|
249
|
+
const text = result.text || "(empty)";
|
|
250
|
+
if (effectiveKey && opts.appendTranscript) opts.appendTranscript(effectiveKey, "assistant", text, opts.source);
|
|
251
|
+
try {
|
|
252
|
+
const { AutoMemory } = await Promise.resolve().then(() => require("./memory-auto-CK5M1YV8.js"));
|
|
253
|
+
const mem = new AutoMemory({ extractEveryNTurns: 1 });
|
|
254
|
+
mem.addTurn("user", message);
|
|
255
|
+
mem.addTurn("assistant", text);
|
|
256
|
+
await mem.extract();
|
|
257
|
+
} catch {}
|
|
258
|
+
opts.onDone?.(text);
|
|
259
|
+
opts.onRunEnd?.(result.usage);
|
|
260
|
+
return {
|
|
261
|
+
text,
|
|
262
|
+
usage: result.usage
|
|
263
|
+
};
|
|
264
|
+
} catch (e) {
|
|
265
|
+
const errText = `Error: ${e.message}`;
|
|
266
|
+
opts.onDone?.(errText);
|
|
267
|
+
opts.onRunEnd?.(void 0, e.message);
|
|
268
|
+
return {
|
|
269
|
+
text: errText,
|
|
270
|
+
error: e.message
|
|
271
|
+
};
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
var CHANNEL_SOURCES;
|
|
275
|
+
var init_engine = require_chunk.__esm({ "packages/core/src/agent/engine.ts"() {
|
|
276
|
+
require_src.init_src();
|
|
277
|
+
CHANNEL_SOURCES = [
|
|
278
|
+
"telegram",
|
|
279
|
+
"discord",
|
|
280
|
+
"whatsapp",
|
|
281
|
+
"slack",
|
|
282
|
+
"signal",
|
|
283
|
+
"matrix",
|
|
284
|
+
"line",
|
|
285
|
+
"nostr",
|
|
286
|
+
"feishu",
|
|
287
|
+
"msteams",
|
|
288
|
+
"teams",
|
|
289
|
+
"instagram",
|
|
290
|
+
"messenger",
|
|
291
|
+
"twitter",
|
|
292
|
+
"viber",
|
|
293
|
+
"zalo"
|
|
294
|
+
];
|
|
295
|
+
} });
|
|
296
|
+
|
|
297
|
+
//#endregion
|
|
298
|
+
Object.defineProperty(exports, 'init_engine', {
|
|
299
|
+
enumerable: true,
|
|
300
|
+
get: function () {
|
|
301
|
+
return init_engine;
|
|
302
|
+
}
|
|
303
|
+
});
|
|
304
|
+
Object.defineProperty(exports, 'loadSkillsContext', {
|
|
305
|
+
enumerable: true,
|
|
306
|
+
get: function () {
|
|
307
|
+
return loadSkillsContext;
|
|
308
|
+
}
|
|
309
|
+
});
|
|
310
|
+
Object.defineProperty(exports, 'loadWorkspaceContext', {
|
|
311
|
+
enumerable: true,
|
|
312
|
+
get: function () {
|
|
313
|
+
return loadWorkspaceContext;
|
|
314
|
+
}
|
|
315
|
+
});
|
|
316
|
+
Object.defineProperty(exports, 'resolveTools', {
|
|
317
|
+
enumerable: true,
|
|
318
|
+
get: function () {
|
|
319
|
+
return resolveTools;
|
|
320
|
+
}
|
|
321
|
+
});
|
|
322
|
+
Object.defineProperty(exports, 'runAgentEngine', {
|
|
323
|
+
enumerable: true,
|
|
324
|
+
get: function () {
|
|
325
|
+
return runAgentEngine;
|
|
326
|
+
}
|
|
327
|
+
});
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
const require_chunk = require('./chunk-jS-bbMI5.js');
|
|
2
|
+
const require_paths = require('./paths-AIyBxIzm.js');
|
|
3
|
+
const require_paths$1 = require('./paths-DPovhojT.js');
|
|
4
|
+
const fs_extra = require_chunk.__toESM(require("fs-extra"));
|
|
5
|
+
const path = require_chunk.__toESM(require("path"));
|
|
6
|
+
const http = require_chunk.__toESM(require("http"));
|
|
7
|
+
|
|
8
|
+
//#region src/services/heartbeat-engine.ts
|
|
9
|
+
require_paths$1.init_paths();
|
|
10
|
+
const HC_DIR = require_paths.getHyperClawDir();
|
|
11
|
+
async function getGatewayConfig() {
|
|
12
|
+
try {
|
|
13
|
+
const cfg = await fs_extra.default.readJson(require_paths.getConfigPath());
|
|
14
|
+
const authToken = cfg?.gateway?.authToken || process.env.HYPERCLAW_GATEWAY_TOKEN || "";
|
|
15
|
+
return {
|
|
16
|
+
port: cfg?.gateway?.port ?? 18789,
|
|
17
|
+
authToken: authToken || void 0
|
|
18
|
+
};
|
|
19
|
+
} catch {
|
|
20
|
+
return { port: 18789 };
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
function sanitizeBriefing(text) {
|
|
24
|
+
return text.replace(/\r\n/g, "\n").replace(/[^\x09\x0a\x0d\x20-\x7e]+/g, "").trim().slice(0, 12e3);
|
|
25
|
+
}
|
|
26
|
+
/** Generate morning briefing via agent (POST /api/chat). */
|
|
27
|
+
async function runMorningBriefing() {
|
|
28
|
+
const { port, authToken } = await getGatewayConfig();
|
|
29
|
+
const prompt = `Generate a brief morning briefing (3-5 bullets) for the user based on:
|
|
30
|
+
- MEMORY.md and knowledge graph (projects, preferences, recent facts)
|
|
31
|
+
- Today's reminders (list_reminders)
|
|
32
|
+
- Any relevant context
|
|
33
|
+
|
|
34
|
+
Be concise. Format as markdown bullets. No preamble.`;
|
|
35
|
+
return new Promise((resolve, reject) => {
|
|
36
|
+
const payload = JSON.stringify({ message: prompt });
|
|
37
|
+
const headers = {
|
|
38
|
+
"Content-Type": "application/json",
|
|
39
|
+
"Content-Length": String(Buffer.byteLength(payload))
|
|
40
|
+
};
|
|
41
|
+
if (authToken) headers["Authorization"] = `Bearer ${authToken}`;
|
|
42
|
+
const req = http.default.request({
|
|
43
|
+
hostname: "127.0.0.1",
|
|
44
|
+
port,
|
|
45
|
+
path: "/api/chat",
|
|
46
|
+
method: "POST",
|
|
47
|
+
headers
|
|
48
|
+
}, (res) => {
|
|
49
|
+
let data = "";
|
|
50
|
+
res.on("data", (c) => data += c);
|
|
51
|
+
res.on("end", () => {
|
|
52
|
+
try {
|
|
53
|
+
const j = JSON.parse(data);
|
|
54
|
+
resolve(j.response || j.error || "(no response)");
|
|
55
|
+
} catch {
|
|
56
|
+
resolve(data || "(parse error)");
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
req.on("error", reject);
|
|
61
|
+
req.setTimeout(6e4, () => {
|
|
62
|
+
req.destroy();
|
|
63
|
+
reject(new Error("Briefing timeout"));
|
|
64
|
+
});
|
|
65
|
+
req.write(payload);
|
|
66
|
+
req.end();
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
/** Persist briefing to HEARTBEAT.md and daily log. */
|
|
70
|
+
async function persistBriefing(text) {
|
|
71
|
+
const today = (/* @__PURE__ */ new Date()).toISOString().slice(0, 10);
|
|
72
|
+
const ts = (/* @__PURE__ */ new Date()).toISOString();
|
|
73
|
+
const sanitized = sanitizeBriefing(text);
|
|
74
|
+
const heartbeatPath = path.default.join(HC_DIR, "HEARTBEAT.md");
|
|
75
|
+
const content = `## Morning Briefing — ${today}\n\n${sanitized}\n\n---\n*Generated ${ts}*\n`;
|
|
76
|
+
await fs_extra.default.ensureDir(HC_DIR);
|
|
77
|
+
if (await fs_extra.default.pathExists(heartbeatPath)) {
|
|
78
|
+
const existing = await fs_extra.default.readFile(heartbeatPath, "utf8");
|
|
79
|
+
await fs_extra.default.writeFile(heartbeatPath, content + "\n" + existing.slice(0, 8e3), "utf8");
|
|
80
|
+
} else await fs_extra.default.writeFile(heartbeatPath, `# HEARTBEAT.md — Proactive Briefings\n\n${content}`, "utf8");
|
|
81
|
+
const logDir = path.default.join(HC_DIR, "logs");
|
|
82
|
+
const logPath = path.default.join(logDir, `heartbeat-${today}.md`);
|
|
83
|
+
await fs_extra.default.ensureDir(logDir);
|
|
84
|
+
await fs_extra.default.appendFile(logPath, `\n## ${ts}\n\n${sanitized}\n`, "utf8");
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
//#endregion
|
|
88
|
+
exports.persistBriefing = persistBriefing;
|
|
89
|
+
exports.runMorningBriefing = runMorningBriefing;
|