hyperclaw 5.4.1 → 5.4.2
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/a2ui-protocol-CUqdJGh7.js +75 -0
- package/dist/agents-routing-B0D0vcp5.js +424 -0
- package/dist/agents-routing-BC6GndVe.js +7 -0
- package/dist/agents-routing-CyFBHvyk.js +424 -0
- package/dist/agents-routing-DdpszaMx.js +7 -0
- package/dist/api-key-validation-DrMrLEa0.js +66 -0
- package/dist/api-keys-guide-DmKF7tB-.js +149 -0
- package/dist/audit-Q-Uy5nem.js +445 -0
- package/dist/backup-CtHJEqGr.js +86 -0
- package/dist/banner-DYzQ8cCb.js +143 -0
- package/dist/banner-jW84OrYg.js +7 -0
- package/dist/bounty-tools-CCwY61YO.js +211 -0
- package/dist/chat-CJa0ph8c.js +528 -0
- package/dist/chat-CKnfxa1-.js +528 -0
- package/dist/chat-CQKCIrIY.js +528 -0
- package/dist/chat-npW_ZOmo.js +528 -0
- package/dist/claw-tasks-Dq38PrL5.js +80 -0
- package/dist/config-BzK_Xl4Y.js +261 -0
- package/dist/config-ClsdlpXc.js +261 -0
- package/dist/config-Dm394B6X.js +7 -0
- package/dist/config-SiLqEezw.js +7 -0
- package/dist/connector-BYPxgmsD.js +312 -0
- package/dist/cost-tracker-x9E8VKtk.js +103 -0
- package/dist/credentials-store-Ddhgmbpz.js +7 -0
- package/dist/credentials-store-onL1tYct.js +89 -0
- package/dist/cron-tasks-CF4MJoIU.js +89 -0
- package/dist/daemon-ApB1nMs2.js +421 -0
- package/dist/daemon-B2ghXB-I.js +7 -0
- package/dist/daemon-BldYSrDj.js +421 -0
- package/dist/daemon-BqTcxMZe.js +7 -0
- package/dist/daemon-CivMFYkD.js +7 -0
- package/dist/daemon-DBXFUMue.js +421 -0
- package/dist/delivery-BURWi8wu.js +4 -0
- package/dist/delivery-kZ2mVkU5.js +95 -0
- package/dist/destructive-gate-C1ny9ek2.js +116 -0
- package/dist/engine-B-JvIt_Y.js +7 -0
- package/dist/engine-BGZnBZ4m.js +7 -0
- package/dist/engine-BTSXJNba.js +346 -0
- package/dist/engine-C7LyH310.js +353 -0
- package/dist/engine-C_nC_Ioe.js +351 -0
- package/dist/engine-DCtJSbKU.js +7 -0
- package/dist/env-resolve-C0R8R7pb.js +167 -0
- package/dist/env-resolve-Dr-KfTtw.js +11 -0
- package/dist/gmail-watch-setup-BzbG0ICM.js +42 -0
- package/dist/heartbeat-engine-B9bhAHNi.js +89 -0
- package/dist/hyperclawbot-BEm8_87h.js +516 -0
- package/dist/hyperclawbot-DR6BgI_d.js +516 -0
- package/dist/hyperclawbot-hZv4pde0.js +516 -0
- package/dist/inference-C874-2MI.js +8 -0
- package/dist/inference-DCSz6Sb1.js +2880 -0
- package/dist/knowledge-graph-BiIvoxPt.js +134 -0
- package/dist/loader-DMMb9emn.js +410 -0
- package/dist/loader-JktrmJOG.js +6 -0
- package/dist/logger-Oty9sC13.js +86 -0
- package/dist/manager-BIc6zzZV.js +250 -0
- package/dist/manager-BwobWy0l.js +120 -0
- package/dist/mcp-CI2F3m8G.js +142 -0
- package/dist/mcp-loader-C-21ynRH.js +93 -0
- package/dist/mcp-loader-Di7n__ta.js +93 -0
- package/dist/memory-auto-BVCJeTwd.js +306 -0
- package/dist/memory-auto-DXKe2ayf.js +5 -0
- package/dist/memory-integration-D2RvZ-MB.js +91 -0
- package/dist/moltbook-DvV6GFFL.js +81 -0
- package/dist/node-DFKhz7Zn.js +251 -0
- package/dist/node-pending-queue-CIMXPU6K.js +32 -0
- package/dist/nodes-registry-BeiEjd9U.js +52 -0
- package/dist/oauth-flow-CZOsvU1v.js +148 -0
- package/dist/oauth-provider-Dk-6BmGL.js +111 -0
- package/dist/observability-B3dDQSdI.js +89 -0
- package/dist/onboard-BnyHie0K.js +14 -0
- package/dist/onboard-D-5gWzH0.js +3854 -0
- package/dist/onboard-D9pjgaVR.js +3854 -0
- package/dist/onboard-UhWVcTap.js +14 -0
- package/dist/onboard-W5DsxVf2.js +3854 -0
- package/dist/onboard-YszvVNgS.js +14 -0
- package/dist/onboard-pLDBUBpO.js +14 -0
- package/dist/onboard-zISipu-l.js +3854 -0
- package/dist/orchestrator-C0t11xj7.js +189 -0
- package/dist/orchestrator-CA4eKeGn.js +189 -0
- package/dist/orchestrator-CNxTIlOK.js +189 -0
- package/dist/orchestrator-Cg1vgEHb.js +6 -0
- package/dist/orchestrator-DV5t6wQ0.js +6 -0
- package/dist/orchestrator-eT0ZL4yl.js +6 -0
- package/dist/osint-47yIek6w.js +283 -0
- package/dist/osint-c-xDjLb-.js +283 -0
- package/dist/osint-chat-BJgnkFDm.js +789 -0
- package/dist/osint-chat-C09BvbGy.js +789 -0
- package/dist/osint-chat-zdeaaw7a.js +789 -0
- package/dist/osint-e6oBrtlj.js +283 -0
- package/dist/pending-approval-CEu_-DGQ.js +22 -0
- package/dist/providers-BfW-fgpw.js +5 -0
- package/dist/providers-Cs1h_TJA.js +1137 -0
- package/dist/renderer-B_ew6jRs.js +228 -0
- package/dist/rules-BAYXiKiJ.js +106 -0
- package/dist/run-main.js +112 -77
- package/dist/runner-B5uo6C5q.js +1310 -0
- package/dist/search-tools-DXVuVXW_.js +107 -0
- package/dist/server-BJkDIs8Z.js +1467 -0
- package/dist/server-CtFoXM88.js +4 -0
- package/dist/server-DVxVLu_G.js +1467 -0
- package/dist/server-DZj6Nobr.js +1467 -0
- package/dist/server-Diu80smx.js +4 -0
- package/dist/server-DszV63tu.js +4 -0
- package/dist/skill-runtime-BLkXA1mO.js +104 -0
- package/dist/skill-runtime-BMk-h6Dl.js +5 -0
- package/dist/skill-runtime-BaTX-RGy.js +5 -0
- package/dist/skill-runtime-CB9tnc-P.js +104 -0
- package/dist/skill-runtime-D6-rGzX1.js +104 -0
- package/dist/skill-runtime-Dej1Yr5V.js +5 -0
- package/dist/src-6dmkVQGq.js +63 -0
- package/dist/src-7yBXPAs6.js +315 -0
- package/dist/src-BOnuFlI4.js +23 -0
- package/dist/src-BkEtHLLy.js +462 -0
- package/dist/src-CDeWGebw.js +315 -0
- package/dist/src-CNAVUFC6.js +462 -0
- package/dist/src-DB6dPsbY.js +63 -0
- package/dist/src-DE4mH0BB.js +63 -0
- package/dist/src-krHV0uVj.js +315 -0
- package/dist/src-tF0sBtr3.js +462 -0
- package/dist/sub-agent-tools-BwOxHu6f.js +39 -0
- package/dist/sub-agent-tools-CJVEIF1F.js +39 -0
- package/dist/sub-agent-tools-f4X1M-li.js +39 -0
- package/dist/tool-policy-CfWEnRxy.js +190 -0
- package/dist/tts-elevenlabs-CCeOqqrh.js +64 -0
- package/dist/vision-BMRKyu3c.js +167 -0
- package/dist/vision-tools-DVYx9-Jw.js +5 -0
- package/dist/vision-tools-kYb3effk.js +51 -0
- package/dist/voice-transcription-B1D1rpca.js +170 -0
- package/package.json +1 -1
- package/static/chat.html +18 -4
- package/static/web/assets/index-D2ekZ-uM.js +75 -0
- package/static/web/assets/index-D_9lvvup.css +1 -0
- package/static/web/index.html +2 -2
- package/static/web/assets/index-8bDizzaq.js +0 -75
- package/static/web/assets/index-B5N1LHGR.css +0 -1
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
const require_chunk = require('./chunk-jS-bbMI5.js');
|
|
2
|
+
|
|
3
|
+
//#region src/infra/tool-policy.ts
|
|
4
|
+
function expandToToolNames(entries) {
|
|
5
|
+
const out = /* @__PURE__ */ new Set();
|
|
6
|
+
for (const e of entries) {
|
|
7
|
+
const key = e.toLowerCase().trim();
|
|
8
|
+
if (key === "*" || key === "") continue;
|
|
9
|
+
if (key.startsWith("group:")) {
|
|
10
|
+
const group = TOOL_GROUPS[key];
|
|
11
|
+
if (group) group.forEach((t) => out.add(t));
|
|
12
|
+
} else out.add(key);
|
|
13
|
+
}
|
|
14
|
+
return out;
|
|
15
|
+
}
|
|
16
|
+
function matchesPattern(toolName, pattern) {
|
|
17
|
+
const p = pattern.toLowerCase();
|
|
18
|
+
const t = toolName.toLowerCase();
|
|
19
|
+
if (p === "*" || p === t) return true;
|
|
20
|
+
if (p.endsWith("*")) {
|
|
21
|
+
const prefix = p.slice(0, -1);
|
|
22
|
+
return t.startsWith(prefix);
|
|
23
|
+
}
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
function isAllowed(toolName, allowSet, denySet, profileAllowSet) {
|
|
27
|
+
if (denySet.size > 0) {
|
|
28
|
+
for (const d of denySet) if (matchesPattern(toolName, d)) return false;
|
|
29
|
+
}
|
|
30
|
+
if (profileAllowSet && profileAllowSet.size > 0) {
|
|
31
|
+
let inProfile = false;
|
|
32
|
+
for (const a of profileAllowSet) if (matchesPattern(toolName, a)) {
|
|
33
|
+
inProfile = true;
|
|
34
|
+
break;
|
|
35
|
+
}
|
|
36
|
+
if (!inProfile) return false;
|
|
37
|
+
}
|
|
38
|
+
if (allowSet.size > 0) {
|
|
39
|
+
for (const a of allowSet) if (matchesPattern(toolName, a)) return true;
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
return true;
|
|
43
|
+
}
|
|
44
|
+
function applyToolPolicy(tools, config, context) {
|
|
45
|
+
if (!config) return tools;
|
|
46
|
+
let profile = config.profile ?? "full";
|
|
47
|
+
let allow = config.allow ?? [];
|
|
48
|
+
let deny = config.deny ?? [];
|
|
49
|
+
if (context?.provider && config.byProvider) {
|
|
50
|
+
const providerKey = context.provider + (context.model ? "/" + context.model : "");
|
|
51
|
+
const exact = config.byProvider[providerKey] ?? config.byProvider[context.provider];
|
|
52
|
+
if (exact) {
|
|
53
|
+
if (exact.profile) profile = exact.profile;
|
|
54
|
+
if (exact.allow?.length) allow = [...allow, ...exact.allow];
|
|
55
|
+
if (exact.deny?.length) deny = [...deny, ...exact.deny];
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
const denySet = expandToToolNames(deny);
|
|
59
|
+
const allowSet = expandToToolNames(allow);
|
|
60
|
+
const profileTools = profile === "full" ? null : new Set(PROFILE_TOOLS[profile]);
|
|
61
|
+
return tools.filter((t) => isAllowed(t.name, allowSet, denySet, profileTools));
|
|
62
|
+
}
|
|
63
|
+
/** For sandbox explain: return effective policy description. */
|
|
64
|
+
function describeToolPolicy(config, context) {
|
|
65
|
+
if (!config) return {
|
|
66
|
+
profile: "full",
|
|
67
|
+
allow: [],
|
|
68
|
+
deny: [],
|
|
69
|
+
source: "default"
|
|
70
|
+
};
|
|
71
|
+
let profile = config.profile ?? "full";
|
|
72
|
+
let allow = config.allow ?? [];
|
|
73
|
+
let deny = config.deny ?? [];
|
|
74
|
+
let source = "tools";
|
|
75
|
+
if (context?.provider && config.byProvider) {
|
|
76
|
+
const providerKey = context.provider + (context.model ? "/" + context.model : "");
|
|
77
|
+
const exact = config.byProvider[providerKey] ?? config.byProvider[context.provider];
|
|
78
|
+
if (exact) {
|
|
79
|
+
if (exact.profile) {
|
|
80
|
+
profile = exact.profile;
|
|
81
|
+
source = `tools.byProvider[${context.provider}]`;
|
|
82
|
+
}
|
|
83
|
+
if (exact.allow?.length) allow = [...allow, ...exact.allow];
|
|
84
|
+
if (exact.deny?.length) deny = [...deny, ...exact.deny];
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return {
|
|
88
|
+
profile,
|
|
89
|
+
allow,
|
|
90
|
+
deny,
|
|
91
|
+
source
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
var TOOL_GROUPS, PROFILE_TOOLS;
|
|
95
|
+
var init_tool_policy = require_chunk.__esm({ "src/infra/tool-policy.ts"() {
|
|
96
|
+
TOOL_GROUPS = {
|
|
97
|
+
"group:fs": [
|
|
98
|
+
"read_file",
|
|
99
|
+
"write_file",
|
|
100
|
+
"edit_file",
|
|
101
|
+
"delete_file",
|
|
102
|
+
"list_directory"
|
|
103
|
+
],
|
|
104
|
+
"group:runtime": ["run_shell", "kill_process"],
|
|
105
|
+
"group:sessions": [
|
|
106
|
+
"sessions_list",
|
|
107
|
+
"sessions_send",
|
|
108
|
+
"sessions_history",
|
|
109
|
+
"sessions_spawn"
|
|
110
|
+
],
|
|
111
|
+
"group:memory": [
|
|
112
|
+
"read_memory",
|
|
113
|
+
"write_memory",
|
|
114
|
+
"memory_graph_add",
|
|
115
|
+
"memory_graph_query"
|
|
116
|
+
],
|
|
117
|
+
"group:ui": [
|
|
118
|
+
"canvas_add",
|
|
119
|
+
"browser_snapshot",
|
|
120
|
+
"browser_action"
|
|
121
|
+
],
|
|
122
|
+
"group:messaging": [
|
|
123
|
+
"sessions_send",
|
|
124
|
+
"sessions_list",
|
|
125
|
+
"sessions_history"
|
|
126
|
+
],
|
|
127
|
+
"group:automation": [
|
|
128
|
+
"add_reminder",
|
|
129
|
+
"list_reminders",
|
|
130
|
+
"complete_reminder",
|
|
131
|
+
"watch_website_add",
|
|
132
|
+
"watch_website_check",
|
|
133
|
+
"watch_website_list"
|
|
134
|
+
],
|
|
135
|
+
"group:pc": [
|
|
136
|
+
"run_shell",
|
|
137
|
+
"read_file",
|
|
138
|
+
"write_file",
|
|
139
|
+
"edit_file",
|
|
140
|
+
"list_directory",
|
|
141
|
+
"delete_file",
|
|
142
|
+
"kill_process",
|
|
143
|
+
"system_info",
|
|
144
|
+
"open",
|
|
145
|
+
"clipboard",
|
|
146
|
+
"search_files",
|
|
147
|
+
"screenshot",
|
|
148
|
+
"camera_capture",
|
|
149
|
+
"screen_record",
|
|
150
|
+
"contacts_list",
|
|
151
|
+
"calendar_events",
|
|
152
|
+
"photos_recent",
|
|
153
|
+
"app_updates",
|
|
154
|
+
"notify"
|
|
155
|
+
],
|
|
156
|
+
"group:extraction": ["extract_pdf", "extract_spreadsheet"],
|
|
157
|
+
"group:vision": ["analyze_image"]
|
|
158
|
+
};
|
|
159
|
+
PROFILE_TOOLS = {
|
|
160
|
+
full: [],
|
|
161
|
+
messaging: [
|
|
162
|
+
"get_current_time",
|
|
163
|
+
"sessions_list",
|
|
164
|
+
"sessions_history",
|
|
165
|
+
"sessions_send",
|
|
166
|
+
"read_memory",
|
|
167
|
+
"write_memory"
|
|
168
|
+
],
|
|
169
|
+
coding: [
|
|
170
|
+
...TOOL_GROUPS["group:fs"],
|
|
171
|
+
...TOOL_GROUPS["group:runtime"],
|
|
172
|
+
...TOOL_GROUPS["group:sessions"],
|
|
173
|
+
...TOOL_GROUPS["group:memory"],
|
|
174
|
+
"http_get",
|
|
175
|
+
"canvas_add",
|
|
176
|
+
"create_skill",
|
|
177
|
+
"get_current_time"
|
|
178
|
+
],
|
|
179
|
+
minimal: [
|
|
180
|
+
"get_current_time",
|
|
181
|
+
"sessions_list",
|
|
182
|
+
"read_memory"
|
|
183
|
+
]
|
|
184
|
+
};
|
|
185
|
+
} });
|
|
186
|
+
|
|
187
|
+
//#endregion
|
|
188
|
+
init_tool_policy();
|
|
189
|
+
exports.applyToolPolicy = applyToolPolicy;
|
|
190
|
+
exports.describeToolPolicy = describeToolPolicy;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
const require_chunk = require('./chunk-jS-bbMI5.js');
|
|
2
|
+
const https = require_chunk.__toESM(require("https"));
|
|
3
|
+
|
|
4
|
+
//#region src/services/tts-elevenlabs.ts
|
|
5
|
+
const DEFAULT_VOICE = "21m00Tcm4TlvDq8ikWAM";
|
|
6
|
+
const DEFAULT_MODEL = "eleven_multilingual_v2";
|
|
7
|
+
function sanitizeForLog(value) {
|
|
8
|
+
return String(value ?? "").replace(/[\r\n\t]+/g, " ").replace(/[^\x20-\x7e]+/g, "?").slice(0, 200);
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
|
|
12
|
+
* Convert text to speech via ElevenLabs API.
|
|
13
|
+
|
|
14
|
+
* Returns base64-encoded MP3 or null on error.
|
|
15
|
+
|
|
16
|
+
*/
|
|
17
|
+
async function textToSpeech(text, opts) {
|
|
18
|
+
const voiceId = opts.voiceId || DEFAULT_VOICE;
|
|
19
|
+
const modelId = opts.modelId || DEFAULT_MODEL;
|
|
20
|
+
const format = opts.outputFormat || "mp3_22050_32";
|
|
21
|
+
const body = JSON.stringify({
|
|
22
|
+
text,
|
|
23
|
+
model_id: modelId
|
|
24
|
+
});
|
|
25
|
+
const path = `/v1/text-to-speech/${voiceId}?output_format=${format}`;
|
|
26
|
+
return new Promise((resolve) => {
|
|
27
|
+
const req = https.default.request({
|
|
28
|
+
hostname: "api.elevenlabs.io",
|
|
29
|
+
port: 443,
|
|
30
|
+
path,
|
|
31
|
+
method: "POST",
|
|
32
|
+
headers: {
|
|
33
|
+
"Content-Type": "application/json",
|
|
34
|
+
"xi-api-key": opts.apiKey,
|
|
35
|
+
"Content-Length": Buffer.byteLength(body)
|
|
36
|
+
}
|
|
37
|
+
}, (res) => {
|
|
38
|
+
const chunks = [];
|
|
39
|
+
res.on("data", (c) => chunks.push(c));
|
|
40
|
+
res.on("end", () => {
|
|
41
|
+
const buf = Buffer.concat(chunks);
|
|
42
|
+
if (res.statusCode !== 200) {
|
|
43
|
+
console.warn(`[tts] ElevenLabs error ${res.statusCode}: ${sanitizeForLog(buf.toString("utf8", 0, 200))}`);
|
|
44
|
+
resolve(null);
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
resolve(buf.toString("base64"));
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
req.on("error", (e) => {
|
|
51
|
+
console.warn("[tts] ElevenLabs request error:", sanitizeForLog(e.message));
|
|
52
|
+
resolve(null);
|
|
53
|
+
});
|
|
54
|
+
req.setTimeout(3e4, () => {
|
|
55
|
+
req.destroy();
|
|
56
|
+
resolve(null);
|
|
57
|
+
});
|
|
58
|
+
req.write(body);
|
|
59
|
+
req.end();
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
//#endregion
|
|
64
|
+
exports.textToSpeech = textToSpeech;
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
const require_chunk = require('./chunk-jS-bbMI5.js');
|
|
2
|
+
const fs_extra = require_chunk.__toESM(require("fs-extra"));
|
|
3
|
+
const path = require_chunk.__toESM(require("path"));
|
|
4
|
+
const os = require_chunk.__toESM(require("os"));
|
|
5
|
+
const http = require_chunk.__toESM(require("http"));
|
|
6
|
+
const https = require_chunk.__toESM(require("https"));
|
|
7
|
+
|
|
8
|
+
//#region src/services/vision.ts
|
|
9
|
+
function inferImageMediaType(ext) {
|
|
10
|
+
return {
|
|
11
|
+
".png": "image/png",
|
|
12
|
+
".jpg": "image/jpeg",
|
|
13
|
+
".jpeg": "image/jpeg",
|
|
14
|
+
".gif": "image/gif",
|
|
15
|
+
".webp": "image/webp"
|
|
16
|
+
}[ext] ?? "image/jpeg";
|
|
17
|
+
}
|
|
18
|
+
async function readValidatedImageFile(filePath) {
|
|
19
|
+
const resolvedPath = path.default.resolve(filePath.replace(/^~/, os.default.homedir()));
|
|
20
|
+
const ext = path.default.extname(resolvedPath).toLowerCase();
|
|
21
|
+
if (!ALLOWED_IMAGE_EXTENSIONS.has(ext)) throw new Error(`Unsupported image file type: ${ext || "unknown"}`);
|
|
22
|
+
const buf = await fs_extra.default.readFile(resolvedPath);
|
|
23
|
+
if (buf.length === 0) throw new Error("Image input is empty");
|
|
24
|
+
if (buf.length > MAX_IMAGE_BYTES) throw new Error(`Image input exceeds ${MAX_IMAGE_BYTES} bytes`);
|
|
25
|
+
return {
|
|
26
|
+
data: buf.toString("base64"),
|
|
27
|
+
mediaType: inferImageMediaType(ext)
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
async function fetchValidatedRemoteImage(urlString) {
|
|
31
|
+
const url = new URL(urlString);
|
|
32
|
+
if (!["http:", "https:"].includes(url.protocol)) throw new Error(`Unsupported image URL protocol: ${url.protocol}`);
|
|
33
|
+
const mod = url.protocol === "https:" ? https.default : http.default;
|
|
34
|
+
const buf = await new Promise((resolve, reject) => {
|
|
35
|
+
const req = mod.get(url, (res) => {
|
|
36
|
+
if ((res.statusCode ?? 0) >= 400) {
|
|
37
|
+
reject(new Error(`Image download failed with status ${res.statusCode}`));
|
|
38
|
+
res.resume();
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
const contentLength = Number(res.headers["content-length"] ?? 0);
|
|
42
|
+
if (contentLength > MAX_IMAGE_BYTES) {
|
|
43
|
+
reject(new Error(`Image download exceeds ${MAX_IMAGE_BYTES} bytes`));
|
|
44
|
+
res.destroy();
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
const chunks = [];
|
|
48
|
+
let total = 0;
|
|
49
|
+
res.on("data", (c) => {
|
|
50
|
+
total += c.length;
|
|
51
|
+
if (total > MAX_IMAGE_BYTES) {
|
|
52
|
+
req.destroy(new Error(`Image download exceeds ${MAX_IMAGE_BYTES} bytes`));
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
chunks.push(c);
|
|
56
|
+
});
|
|
57
|
+
res.on("end", () => resolve(Buffer.concat(chunks)));
|
|
58
|
+
res.on("error", reject);
|
|
59
|
+
});
|
|
60
|
+
req.on("error", reject);
|
|
61
|
+
});
|
|
62
|
+
const pathnameExt = path.default.extname(url.pathname).toLowerCase();
|
|
63
|
+
return {
|
|
64
|
+
data: buf.toString("base64"),
|
|
65
|
+
mediaType: inferImageMediaType(ALLOWED_IMAGE_EXTENSIONS.has(pathnameExt) ? pathnameExt : ".jpg")
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
async function imageToBase64(input) {
|
|
69
|
+
const trimmed = input.trim();
|
|
70
|
+
if (trimmed.startsWith("data:")) {
|
|
71
|
+
const match = trimmed.match(/^data:(image\/[^;]+);base64,(.+)$/);
|
|
72
|
+
if (match) {
|
|
73
|
+
const buffer = Buffer.from(match[2], "base64");
|
|
74
|
+
if (buffer.length === 0) throw new Error("Image input is empty");
|
|
75
|
+
if (buffer.length > MAX_IMAGE_BYTES) throw new Error(`Image input exceeds ${MAX_IMAGE_BYTES} bytes`);
|
|
76
|
+
return {
|
|
77
|
+
data: match[2],
|
|
78
|
+
mediaType: match[1]
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
if (trimmed.startsWith("http")) return fetchValidatedRemoteImage(trimmed);
|
|
83
|
+
return readValidatedImageFile(trimmed);
|
|
84
|
+
}
|
|
85
|
+
async function analyzeImage(imageInput, prompt, apiKey, provider = "anthropic") {
|
|
86
|
+
const { data, mediaType } = await imageToBase64(imageInput);
|
|
87
|
+
const isAnthropic = provider === "anthropic";
|
|
88
|
+
const hostname = isAnthropic ? "api.anthropic.com" : "openrouter.ai";
|
|
89
|
+
const model = isAnthropic ? "claude-sonnet-4-20250514" : "openai/gpt-4o";
|
|
90
|
+
const body = {
|
|
91
|
+
model,
|
|
92
|
+
max_tokens: 1024,
|
|
93
|
+
messages: isAnthropic ? [{
|
|
94
|
+
role: "user",
|
|
95
|
+
content: [{
|
|
96
|
+
type: "image",
|
|
97
|
+
source: {
|
|
98
|
+
type: "base64",
|
|
99
|
+
media_type: mediaType,
|
|
100
|
+
data
|
|
101
|
+
}
|
|
102
|
+
}, {
|
|
103
|
+
type: "text",
|
|
104
|
+
text: prompt || "Describe this image."
|
|
105
|
+
}]
|
|
106
|
+
}] : [{
|
|
107
|
+
role: "user",
|
|
108
|
+
content: [{
|
|
109
|
+
type: "text",
|
|
110
|
+
text: "[Image attached] " + (prompt || "Describe this image.")
|
|
111
|
+
}, {
|
|
112
|
+
type: "image_url",
|
|
113
|
+
image_url: { url: `data:${mediaType};base64,${data}` }
|
|
114
|
+
}]
|
|
115
|
+
}]
|
|
116
|
+
};
|
|
117
|
+
if (isAnthropic) body.anthropic_version = "2023-06-01";
|
|
118
|
+
return new Promise((resolve, reject) => {
|
|
119
|
+
const payload = JSON.stringify(body);
|
|
120
|
+
const req = https.default.request({
|
|
121
|
+
hostname,
|
|
122
|
+
port: 443,
|
|
123
|
+
path: isAnthropic ? "/v1/messages" : "/api/v1/chat/completions",
|
|
124
|
+
method: "POST",
|
|
125
|
+
headers: {
|
|
126
|
+
"Authorization": `Bearer ${apiKey}`,
|
|
127
|
+
"Content-Type": "application/json",
|
|
128
|
+
...isAnthropic ? { "anthropic-version": "2023-06-01" } : { "HTTP-Referer": "https://hyperclaw.ai" }
|
|
129
|
+
}
|
|
130
|
+
}, (res) => {
|
|
131
|
+
let raw = "";
|
|
132
|
+
res.on("data", (c) => raw += c);
|
|
133
|
+
res.on("end", () => {
|
|
134
|
+
try {
|
|
135
|
+
const j = JSON.parse(raw);
|
|
136
|
+
if (isAnthropic) {
|
|
137
|
+
const text = j.content?.[0]?.text;
|
|
138
|
+
resolve(text || j.error?.message || "(no description)");
|
|
139
|
+
} else {
|
|
140
|
+
const text = j.choices?.[0]?.message?.content;
|
|
141
|
+
resolve(text || j.error?.message || "(no description)");
|
|
142
|
+
}
|
|
143
|
+
} catch {
|
|
144
|
+
resolve(raw || "(parse error)");
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
});
|
|
148
|
+
req.on("error", reject);
|
|
149
|
+
req.write(payload);
|
|
150
|
+
req.end();
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
var MAX_IMAGE_BYTES, ALLOWED_IMAGE_EXTENSIONS;
|
|
154
|
+
var init_vision = require_chunk.__esm({ "src/services/vision.ts"() {
|
|
155
|
+
MAX_IMAGE_BYTES = 15 * 1024 * 1024;
|
|
156
|
+
ALLOWED_IMAGE_EXTENSIONS = new Set([
|
|
157
|
+
".png",
|
|
158
|
+
".jpg",
|
|
159
|
+
".jpeg",
|
|
160
|
+
".gif",
|
|
161
|
+
".webp"
|
|
162
|
+
]);
|
|
163
|
+
} });
|
|
164
|
+
|
|
165
|
+
//#endregion
|
|
166
|
+
init_vision();
|
|
167
|
+
exports.analyzeImage = analyzeImage;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
const require_chunk = require('./chunk-jS-bbMI5.js');
|
|
2
|
+
|
|
3
|
+
//#region packages/core/src/agent/vision-tools.ts
|
|
4
|
+
function getVisionTools(opts = {}) {
|
|
5
|
+
const { apiKey = "", provider = "anthropic" } = opts;
|
|
6
|
+
return [{
|
|
7
|
+
name: "analyze_image",
|
|
8
|
+
description: "Analyze an image using a vision model. Describe scenes, receipts, documents, photos. Supports file path, URL, or data URI.",
|
|
9
|
+
input_schema: {
|
|
10
|
+
type: "object",
|
|
11
|
+
properties: {
|
|
12
|
+
image: {
|
|
13
|
+
type: "string",
|
|
14
|
+
description: "Image path (~/path), URL (https://...), or data:image/...;base64,..."
|
|
15
|
+
},
|
|
16
|
+
prompt: {
|
|
17
|
+
type: "string",
|
|
18
|
+
description: "What to describe or extract (e.g. \"Describe this scene\", \"List items on this receipt\")"
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
required: ["image"]
|
|
22
|
+
},
|
|
23
|
+
handler: async (input) => {
|
|
24
|
+
if (!apiKey) return "Error: No API key configured for vision. Set provider.apiKey or run hyperclaw auth add.";
|
|
25
|
+
const image = input.image?.trim();
|
|
26
|
+
const prompt = input.prompt?.trim() || "Describe this image concisely.";
|
|
27
|
+
if (!image) return "Error: image is required";
|
|
28
|
+
try {
|
|
29
|
+
const { analyzeImage } = await Promise.resolve().then(() => require("./vision-BMRKyu3c.js"));
|
|
30
|
+
return await analyzeImage(image, prompt, apiKey, provider);
|
|
31
|
+
} catch (e) {
|
|
32
|
+
return `Error: ${e.message}`;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}];
|
|
36
|
+
}
|
|
37
|
+
var init_vision_tools = require_chunk.__esm({ "packages/core/src/agent/vision-tools.ts"() {} });
|
|
38
|
+
|
|
39
|
+
//#endregion
|
|
40
|
+
Object.defineProperty(exports, 'getVisionTools', {
|
|
41
|
+
enumerable: true,
|
|
42
|
+
get: function () {
|
|
43
|
+
return getVisionTools;
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
Object.defineProperty(exports, 'init_vision_tools', {
|
|
47
|
+
enumerable: true,
|
|
48
|
+
get: function () {
|
|
49
|
+
return init_vision_tools;
|
|
50
|
+
}
|
|
51
|
+
});
|
|
@@ -0,0 +1,170 @@
|
|
|
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 https = require_chunk.__toESM(require("https"));
|
|
7
|
+
|
|
8
|
+
//#region src/services/voice-transcription.ts
|
|
9
|
+
require_paths$1.init_paths();
|
|
10
|
+
const MAX_AUDIO_BYTES = 25 * 1024 * 1024;
|
|
11
|
+
const ALLOWED_AUDIO_EXTENSIONS = new Set([
|
|
12
|
+
".ogg",
|
|
13
|
+
".oga",
|
|
14
|
+
".mp3",
|
|
15
|
+
".wav",
|
|
16
|
+
".m4a",
|
|
17
|
+
".mp4",
|
|
18
|
+
".mpeg",
|
|
19
|
+
".webm"
|
|
20
|
+
]);
|
|
21
|
+
function sanitizeForError(value) {
|
|
22
|
+
return String(value ?? "").replace(/[\r\n\t]+/g, " ").slice(0, 160);
|
|
23
|
+
}
|
|
24
|
+
async function loadAudioInput(audioPathOrBuffer) {
|
|
25
|
+
if (Buffer.isBuffer(audioPathOrBuffer)) {
|
|
26
|
+
if (audioPathOrBuffer.length === 0) throw new Error("Audio input is empty");
|
|
27
|
+
if (audioPathOrBuffer.length > MAX_AUDIO_BYTES) throw new Error(`Audio input exceeds ${MAX_AUDIO_BYTES} bytes`);
|
|
28
|
+
return audioPathOrBuffer;
|
|
29
|
+
}
|
|
30
|
+
const resolvedPath = path.default.resolve(audioPathOrBuffer);
|
|
31
|
+
const ext = path.default.extname(resolvedPath).toLowerCase();
|
|
32
|
+
if (!ALLOWED_AUDIO_EXTENSIONS.has(ext)) throw new Error(`Unsupported audio file type: ${ext || "unknown"}`);
|
|
33
|
+
const buf = await fs_extra.default.readFile(resolvedPath);
|
|
34
|
+
if (buf.length === 0) throw new Error("Audio input is empty");
|
|
35
|
+
if (buf.length > MAX_AUDIO_BYTES) throw new Error(`Audio input exceeds ${MAX_AUDIO_BYTES} bytes`);
|
|
36
|
+
return buf;
|
|
37
|
+
}
|
|
38
|
+
async function getConfig() {
|
|
39
|
+
try {
|
|
40
|
+
const cfg = await fs_extra.default.readJson(require_paths.getConfigPath());
|
|
41
|
+
const providerId = cfg?.provider?.providerId;
|
|
42
|
+
const apiKey = cfg?.provider?.apiKey;
|
|
43
|
+
return {
|
|
44
|
+
providerId,
|
|
45
|
+
apiKey
|
|
46
|
+
};
|
|
47
|
+
} catch {
|
|
48
|
+
return {};
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
async function transcribeWithWhisper(buffer, apiKey) {
|
|
52
|
+
return new Promise((resolve, reject) => {
|
|
53
|
+
const boundary = "----HyperClaw" + Date.now();
|
|
54
|
+
const header = [
|
|
55
|
+
`--${boundary}`,
|
|
56
|
+
"Content-Disposition: form-data; name=\"file\"; filename=\"audio.ogg\"",
|
|
57
|
+
"Content-Type: application/octet-stream",
|
|
58
|
+
"",
|
|
59
|
+
""
|
|
60
|
+
].join("\r\n");
|
|
61
|
+
const footer = `\r\n--${boundary}\r\nContent-Disposition: form-data; name="model"\r\n\r\nwhisper-1\r\n--${boundary}--\r\n`;
|
|
62
|
+
const body = Buffer.concat([
|
|
63
|
+
Buffer.from(header, "utf8"),
|
|
64
|
+
buffer,
|
|
65
|
+
Buffer.from(footer, "utf8")
|
|
66
|
+
]);
|
|
67
|
+
const req = https.default.request({
|
|
68
|
+
hostname: "api.openai.com",
|
|
69
|
+
port: 443,
|
|
70
|
+
path: "/v1/audio/transcriptions",
|
|
71
|
+
method: "POST",
|
|
72
|
+
headers: {
|
|
73
|
+
"Authorization": `Bearer ${apiKey}`,
|
|
74
|
+
"Content-Type": `multipart/form-data; boundary=${boundary}`,
|
|
75
|
+
"Content-Length": body.length
|
|
76
|
+
}
|
|
77
|
+
}, (res) => {
|
|
78
|
+
let data = "";
|
|
79
|
+
res.on("data", (c) => data += c);
|
|
80
|
+
res.on("end", () => {
|
|
81
|
+
try {
|
|
82
|
+
const j = JSON.parse(data);
|
|
83
|
+
resolve(j.text?.trim() || "[No transcription]");
|
|
84
|
+
} catch {
|
|
85
|
+
resolve(`[Transcription error: ${data.slice(0, 100)}]`);
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
req.on("error", reject);
|
|
90
|
+
req.write(body);
|
|
91
|
+
req.end();
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
async function transcribeWithGemini(buffer, apiKey) {
|
|
95
|
+
const base64 = buffer.toString("base64");
|
|
96
|
+
const payload = JSON.stringify({
|
|
97
|
+
contents: [{ parts: [{ text: "Transcribe this audio to text. Output only the transcription, no other text." }, { inlineData: {
|
|
98
|
+
mimeType: "audio/ogg",
|
|
99
|
+
data: base64
|
|
100
|
+
} }] }],
|
|
101
|
+
generationConfig: { maxOutputTokens: 1024 }
|
|
102
|
+
});
|
|
103
|
+
return new Promise((resolve, reject) => {
|
|
104
|
+
const req = https.default.request({
|
|
105
|
+
hostname: "generativelanguage.googleapis.com",
|
|
106
|
+
port: 443,
|
|
107
|
+
path: "/v1beta/models/gemini-2.0-flash:generateContent?key=" + encodeURIComponent(apiKey),
|
|
108
|
+
method: "POST",
|
|
109
|
+
headers: {
|
|
110
|
+
"Content-Type": "application/json",
|
|
111
|
+
"Content-Length": Buffer.byteLength(payload)
|
|
112
|
+
}
|
|
113
|
+
}, (res) => {
|
|
114
|
+
let data = "";
|
|
115
|
+
res.on("data", (c) => data += c);
|
|
116
|
+
res.on("end", () => {
|
|
117
|
+
try {
|
|
118
|
+
const j = JSON.parse(data);
|
|
119
|
+
const text = j.candidates?.[0]?.content?.parts?.[0]?.text?.trim();
|
|
120
|
+
resolve(text || "[No transcription]");
|
|
121
|
+
} catch {
|
|
122
|
+
resolve(`[Transcription error: ${data.slice(0, 100)}]`);
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
});
|
|
126
|
+
req.on("error", reject);
|
|
127
|
+
req.write(payload);
|
|
128
|
+
req.end();
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
|
|
133
|
+
* Transcribe audio using configured provider or fallbacks.
|
|
134
|
+
|
|
135
|
+
* Providers: OpenAI (Whisper), Google (Gemini), OpenRouter.
|
|
136
|
+
|
|
137
|
+
* Env: OPENAI_API_KEY, WHISPER_API_KEY, GOOGLE_AI_API_KEY.
|
|
138
|
+
|
|
139
|
+
*/
|
|
140
|
+
async function transcribeVoiceNote(audioPathOrBuffer, apiKey) {
|
|
141
|
+
let buffer;
|
|
142
|
+
try {
|
|
143
|
+
buffer = await loadAudioInput(audioPathOrBuffer);
|
|
144
|
+
} catch (e) {
|
|
145
|
+
return `[Transcription failed: ${sanitizeForError(e?.message)}]`;
|
|
146
|
+
}
|
|
147
|
+
const cfg = await getConfig();
|
|
148
|
+
const openaiKey = apiKey || process.env.OPENAI_API_KEY || process.env.WHISPER_API_KEY || (cfg.providerId === "openai" || cfg.providerId === "openrouter" ? cfg.apiKey : "");
|
|
149
|
+
const googleKey = process.env.GOOGLE_AI_API_KEY || (cfg.providerId === "google" ? cfg.apiKey : "");
|
|
150
|
+
if (cfg.providerId === "google" && googleKey) try {
|
|
151
|
+
return await transcribeWithGemini(buffer, googleKey);
|
|
152
|
+
} catch {}
|
|
153
|
+
if ((cfg.providerId === "openrouter" || cfg.providerId === "openai") && openaiKey) try {
|
|
154
|
+
return await transcribeWithWhisper(buffer, openaiKey);
|
|
155
|
+
} catch {}
|
|
156
|
+
if (openaiKey) try {
|
|
157
|
+
return await transcribeWithWhisper(buffer, openaiKey);
|
|
158
|
+
} catch (e) {
|
|
159
|
+
return `[Transcription failed: ${sanitizeForError(e?.message)}]`;
|
|
160
|
+
}
|
|
161
|
+
if (googleKey) try {
|
|
162
|
+
return await transcribeWithGemini(buffer, googleKey);
|
|
163
|
+
} catch (e) {
|
|
164
|
+
return `[Transcription failed: ${sanitizeForError(e?.message)}]`;
|
|
165
|
+
}
|
|
166
|
+
return "[Voice note — add OPENAI_API_KEY or GOOGLE_AI_API_KEY (or select OpenAI/Google provider in the wizard) for transcription]";
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
//#endregion
|
|
170
|
+
exports.transcribeVoiceNote = transcribeVoiceNote;
|