@duckmind/dm-windows-x64 0.63.0 → 0.63.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/dm.exe +0 -0
- package/extensions/.dm-extensions.json +200 -4
- package/extensions/dm-context/package.json +1 -1
- package/extensions/dm-context/skills/context-management/SKILL.md +173 -223
- package/extensions/dm-context/skills/context-management/references/development-and-troubleshooting.md +75 -0
- package/extensions/dm-context/skills/context-management/references/interleaved-async-work.md +143 -0
- package/extensions/dm-context/skills/context-management/references/planning-and-execution.md +81 -0
- package/extensions/dm-context/skills/context-management/references/repeated-items-and-batch-work.md +69 -0
- package/extensions/dm-context/skills/context-management/references/retry-branch-and-pivot.md +80 -0
- package/extensions/dm-context/skills/context-management/references/search-research-and-reading.md +103 -0
- package/extensions/dm-context/skills/context-management/references/task-switching-and-cleanup.md +73 -0
- package/extensions/dm-context/src/context.js +3 -2
- package/extensions/dm-context/src/index.js +168 -84
- package/extensions/dm-skills-manager/THIRD_PARTY_NOTICES.md +27 -0
- package/extensions/dm-skills-manager/extensions/skills-manager/components.js +265 -0
- package/extensions/dm-skills-manager/extensions/skills-manager/constants.js +31 -0
- package/extensions/dm-skills-manager/extensions/skills-manager/creation-fallback.js +20 -0
- package/extensions/dm-skills-manager/extensions/skills-manager/creation.js +145 -0
- package/extensions/dm-skills-manager/extensions/skills-manager/dialog.js +738 -0
- package/extensions/dm-skills-manager/extensions/skills-manager/dm-ai-compat.js +15 -0
- package/extensions/dm-skills-manager/extensions/skills-manager/format.js +125 -0
- package/extensions/dm-skills-manager/extensions/skills-manager/glyphs.js +142 -0
- package/extensions/dm-skills-manager/extensions/skills-manager/layout.js +93 -0
- package/extensions/dm-skills-manager/extensions/skills-manager/paths.js +76 -0
- package/extensions/dm-skills-manager/extensions/skills-manager/registry.js +95 -0
- package/extensions/dm-skills-manager/extensions/skills-manager/settings.js +93 -0
- package/extensions/dm-skills-manager/extensions/skills-manager/startup.js +32 -0
- package/extensions/dm-skills-manager/extensions/skills-manager/toggle.js +54 -0
- package/extensions/dm-skills-manager/extensions/skills-manager/types.js +14 -0
- package/extensions/dm-skills-manager/extensions/skills-manager/ui.js +121 -0
- package/extensions/dm-skills-manager/extensions/skills-manager.js +111 -0
- package/extensions/dm-skills-manager/package.json +121 -0
- package/extensions/dm-web-access/SECURITY.md +5 -0
- package/extensions/dm-web-access/activity.js +65 -0
- package/extensions/dm-web-access/anysearch.js +158 -0
- package/extensions/dm-web-access/auth-fetch.js +131 -0
- package/extensions/dm-web-access/bocha.js +214 -0
- package/extensions/dm-web-access/brave.js +196 -0
- package/extensions/dm-web-access/brightdata-unlocker.js +202 -0
- package/extensions/dm-web-access/brightdata.js +334 -0
- package/extensions/dm-web-access/chrome-cookies.js +627 -0
- package/extensions/dm-web-access/content-find.js +114 -0
- package/extensions/dm-web-access/credential-source.js +150 -0
- package/extensions/dm-web-access/curator-page.js +3559 -0
- package/extensions/dm-web-access/curator-server.js +691 -0
- package/extensions/dm-web-access/data-uri-sanitize.js +312 -0
- package/extensions/dm-web-access/datalab-pdf-extract.js +346 -0
- package/extensions/dm-web-access/declared-web-links.js +167 -0
- package/extensions/dm-web-access/dm-web-fetch-demo.mp4 +0 -0
- package/extensions/dm-web-access/duckduckgo.js +118 -0
- package/extensions/dm-web-access/exa.js +401 -0
- package/extensions/dm-web-access/extract.js +1220 -0
- package/extensions/dm-web-access/feature-config.js +24 -0
- package/extensions/dm-web-access/fetch-params.js +81 -0
- package/extensions/dm-web-access/firecrawl.js +378 -0
- package/extensions/dm-web-access/gemini-adc.js +241 -0
- package/extensions/dm-web-access/gemini-api.js +258 -0
- package/extensions/dm-web-access/gemini-pdf-extract.js +74 -0
- package/extensions/dm-web-access/gemini-search.js +889 -0
- package/extensions/dm-web-access/gemini-url-context.js +97 -0
- package/extensions/dm-web-access/gemini-web-config.js +84 -0
- package/extensions/dm-web-access/gemini-web.js +351 -0
- package/extensions/dm-web-access/github-api.js +166 -0
- package/extensions/dm-web-access/github-extract.js +991 -0
- package/extensions/dm-web-access/github-issue-pr.js +750 -0
- package/extensions/dm-web-access/index.js +3117 -0
- package/extensions/dm-web-access/jina-search.js +242 -0
- package/extensions/dm-web-access/kagi.js +255 -0
- package/extensions/dm-web-access/kimi-search.js +214 -0
- package/extensions/dm-web-access/ollama.js +209 -0
- package/extensions/dm-web-access/openai-search.js +510 -0
- package/extensions/dm-web-access/package.json +34 -0
- package/extensions/dm-web-access/page-query.js +124 -0
- package/extensions/dm-web-access/parallel-mcp.js +223 -0
- package/extensions/dm-web-access/parallel.js +345 -0
- package/extensions/dm-web-access/pdf-extract.js +257 -0
- package/extensions/dm-web-access/perplexity.js +151 -0
- package/extensions/dm-web-access/querit.js +327 -0
- package/extensions/dm-web-access/query-rewrite.js +40 -0
- package/extensions/dm-web-access/render-search-error.js +80 -0
- package/extensions/dm-web-access/rsc-extract.js +347 -0
- package/extensions/dm-web-access/search1api.js +245 -0
- package/extensions/dm-web-access/searchinfinity.js +221 -0
- package/extensions/dm-web-access/searxng.js +223 -0
- package/extensions/dm-web-access/serpbase.js +205 -0
- package/extensions/dm-web-access/serpdive.js +238 -0
- package/extensions/dm-web-access/serper.js +200 -0
- package/extensions/dm-web-access/source-check.js +198 -0
- package/extensions/dm-web-access/ssrf-protection.js +436 -0
- package/extensions/dm-web-access/storage.js +451 -0
- package/extensions/dm-web-access/summary-model-scope.js +83 -0
- package/extensions/dm-web-access/summary-review.js +364 -0
- package/extensions/dm-web-access/tavily.js +199 -0
- package/extensions/dm-web-access/tinyfish.js +325 -0
- package/extensions/dm-web-access/utils.js +476 -0
- package/extensions/dm-web-access/valyu.js +189 -0
- package/extensions/dm-web-access/video-extract.js +336 -0
- package/extensions/dm-web-access/xai-search.js +285 -0
- package/extensions/dm-web-access/xcrawl.js +221 -0
- package/extensions/dm-web-access/youtube-extract.js +279 -0
- package/package.json +9 -1
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
2
|
+
import { activityMonitor } from "./activity.js";
|
|
3
|
+
import { hasCredentialSource, redactCredential, resolveCredential } from "./credential-source.js";
|
|
4
|
+
import { getWebSearchConfigPath } from "./utils.js";
|
|
5
|
+
const XCRAWL_API_URL = "https://run.xcrawl.com/v1/serp";
|
|
6
|
+
const CONFIG_PATH = getWebSearchConfigPath();
|
|
7
|
+
const SEARCH_TIMEOUT_MS = 60000;
|
|
8
|
+
let cachedConfig = null;
|
|
9
|
+
function loadConfig() {
|
|
10
|
+
if (cachedConfig)
|
|
11
|
+
return cachedConfig;
|
|
12
|
+
if (!existsSync(CONFIG_PATH)) {
|
|
13
|
+
cachedConfig = {};
|
|
14
|
+
return cachedConfig;
|
|
15
|
+
}
|
|
16
|
+
const raw = readFileSync(CONFIG_PATH, "utf-8");
|
|
17
|
+
let parsed;
|
|
18
|
+
try {
|
|
19
|
+
parsed = JSON.parse(raw);
|
|
20
|
+
} catch (err) {
|
|
21
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
22
|
+
throw new Error(`Failed to parse ${CONFIG_PATH}: ${message}`);
|
|
23
|
+
}
|
|
24
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
25
|
+
throw new Error(`Invalid config in ${CONFIG_PATH}: expected a JSON object`);
|
|
26
|
+
}
|
|
27
|
+
cachedConfig = parsed;
|
|
28
|
+
return cachedConfig;
|
|
29
|
+
}
|
|
30
|
+
async function getApiKey(signal) {
|
|
31
|
+
return resolveCredential({
|
|
32
|
+
provider: "XCrawl",
|
|
33
|
+
configuredValue: loadConfig().xcrawlApiKey,
|
|
34
|
+
environmentValue: process.env.XCRAWL_API_KEY,
|
|
35
|
+
signal
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
export function isXcrawlAvailable() {
|
|
39
|
+
return hasCredentialSource({ provider: "XCrawl", configuredValue: loadConfig().xcrawlApiKey, environmentValue: process.env.XCRAWL_API_KEY });
|
|
40
|
+
}
|
|
41
|
+
function errorMessage(err) {
|
|
42
|
+
return err instanceof Error ? err.message : String(err);
|
|
43
|
+
}
|
|
44
|
+
function invalidResponse(message) {
|
|
45
|
+
return new Error(`XCrawl API returned invalid response: ${message}`);
|
|
46
|
+
}
|
|
47
|
+
function normalizeCount(value) {
|
|
48
|
+
if (typeof value !== "number" || !Number.isFinite(value))
|
|
49
|
+
return 5;
|
|
50
|
+
return Math.max(1, Math.min(Math.floor(value), 20));
|
|
51
|
+
}
|
|
52
|
+
function hostnameOf(url) {
|
|
53
|
+
try {
|
|
54
|
+
return new URL(url).hostname.toLowerCase();
|
|
55
|
+
} catch {
|
|
56
|
+
return "";
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
function absolutizeLink(link) {
|
|
60
|
+
if (/^https?:\/\//i.test(link))
|
|
61
|
+
return link;
|
|
62
|
+
try {
|
|
63
|
+
return new URL(link, XCRAWL_API_URL).href;
|
|
64
|
+
} catch {
|
|
65
|
+
return link;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
function normalizeDomain(value) {
|
|
69
|
+
let input = value.trim().toLowerCase();
|
|
70
|
+
if (!input)
|
|
71
|
+
return null;
|
|
72
|
+
if (input.startsWith("-"))
|
|
73
|
+
input = input.slice(1).trim();
|
|
74
|
+
if (!input)
|
|
75
|
+
return null;
|
|
76
|
+
try {
|
|
77
|
+
const parsed = input.includes("://") ? new URL(input) : new URL(`https://${input}`);
|
|
78
|
+
input = parsed.hostname;
|
|
79
|
+
} catch {
|
|
80
|
+
input = input.split("/")[0]?.split(":")[0] ?? "";
|
|
81
|
+
}
|
|
82
|
+
input = input.replace(/^\.+|\.+$/g, "");
|
|
83
|
+
return /^[a-z0-9][a-z0-9.-]*\.[a-z]{2,}$/i.test(input) ? input : null;
|
|
84
|
+
}
|
|
85
|
+
function applyDomainFilter(results, domainFilter) {
|
|
86
|
+
const includes = [];
|
|
87
|
+
const excludes = [];
|
|
88
|
+
for (const raw of domainFilter) {
|
|
89
|
+
const normalized = normalizeDomain(raw);
|
|
90
|
+
if (!normalized)
|
|
91
|
+
continue;
|
|
92
|
+
if (raw.trim().startsWith("-"))
|
|
93
|
+
excludes.push(normalized);
|
|
94
|
+
else
|
|
95
|
+
includes.push(normalized);
|
|
96
|
+
}
|
|
97
|
+
if (!includes.length && !excludes.length)
|
|
98
|
+
return results;
|
|
99
|
+
return results.filter((result) => {
|
|
100
|
+
const host = hostnameOf(result.url);
|
|
101
|
+
if (!host)
|
|
102
|
+
return false;
|
|
103
|
+
const matches = (domain) => host === domain || host.endsWith(`.${domain}`);
|
|
104
|
+
if (excludes.some(matches))
|
|
105
|
+
return false;
|
|
106
|
+
if (includes.length && !includes.some(matches))
|
|
107
|
+
return false;
|
|
108
|
+
return true;
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
function parseResponse(value) {
|
|
112
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
113
|
+
throw invalidResponse("expected an object envelope");
|
|
114
|
+
}
|
|
115
|
+
const envelope = value;
|
|
116
|
+
const metadata = envelope.search_metadata;
|
|
117
|
+
if (!metadata || typeof metadata !== "object" || Array.isArray(metadata)) {
|
|
118
|
+
throw invalidResponse("expected search_metadata object");
|
|
119
|
+
}
|
|
120
|
+
const status = metadata.status;
|
|
121
|
+
if (status !== undefined && status !== "completed") {
|
|
122
|
+
throw invalidResponse(`expected search_metadata.status "completed", got ${JSON.stringify(status)}`);
|
|
123
|
+
}
|
|
124
|
+
if (!Array.isArray(envelope.organic_results))
|
|
125
|
+
throw invalidResponse("expected organic_results array");
|
|
126
|
+
const results = [];
|
|
127
|
+
for (const [index, value] of envelope.organic_results.entries()) {
|
|
128
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
129
|
+
throw invalidResponse(`expected organic_results[${index}] object`);
|
|
130
|
+
}
|
|
131
|
+
const result = value;
|
|
132
|
+
const { title, link, snippet } = result;
|
|
133
|
+
if (typeof link !== "string" || !link.trim())
|
|
134
|
+
throw invalidResponse(`expected organic_results[${index}].link to be a non-empty string`);
|
|
135
|
+
if (title !== null && title !== undefined && typeof title !== "string") {
|
|
136
|
+
throw invalidResponse(`expected organic_results[${index}].title to be a string or null`);
|
|
137
|
+
}
|
|
138
|
+
if (snippet !== undefined && snippet !== null && typeof snippet !== "string") {
|
|
139
|
+
throw invalidResponse(`expected organic_results[${index}].snippet to be a string or null`);
|
|
140
|
+
}
|
|
141
|
+
const resolved = absolutizeLink(link.trim());
|
|
142
|
+
results.push({
|
|
143
|
+
title: typeof title === "string" && title.trim().length > 0 ? title : resolved,
|
|
144
|
+
url: resolved,
|
|
145
|
+
snippet: typeof snippet === "string" ? snippet : ""
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
return results;
|
|
149
|
+
}
|
|
150
|
+
function buildAnswer(results) {
|
|
151
|
+
return results.map((result) => result.snippet ? `${result.snippet}
|
|
152
|
+
Source: ${result.title} (${result.url})` : `Source: ${result.title} (${result.url})`).join(`
|
|
153
|
+
|
|
154
|
+
`);
|
|
155
|
+
}
|
|
156
|
+
export async function searchWithXCrawl(query, options = {}) {
|
|
157
|
+
const apiKey = await getApiKey(options.signal);
|
|
158
|
+
const numResults = normalizeCount(options.numResults);
|
|
159
|
+
if (!apiKey) {
|
|
160
|
+
throw new Error("XCrawl search requires an API key. Set xcrawlApiKey in " + CONFIG_PATH + " or export XCRAWL_API_KEY. Get one at https://dash.xcrawl.com/");
|
|
161
|
+
}
|
|
162
|
+
const body = { engine: "google_search", q: query };
|
|
163
|
+
const activityId = activityMonitor.logStart({ type: "api", query });
|
|
164
|
+
const timeoutSignal = AbortSignal.timeout(SEARCH_TIMEOUT_MS);
|
|
165
|
+
let response;
|
|
166
|
+
try {
|
|
167
|
+
response = await fetch(XCRAWL_API_URL, {
|
|
168
|
+
method: "POST",
|
|
169
|
+
headers: {
|
|
170
|
+
Authorization: `Bearer ${apiKey}`,
|
|
171
|
+
"Content-Type": "application/json"
|
|
172
|
+
},
|
|
173
|
+
body: JSON.stringify(body),
|
|
174
|
+
signal: options.signal ? AbortSignal.any([timeoutSignal, options.signal]) : timeoutSignal
|
|
175
|
+
});
|
|
176
|
+
} catch (err) {
|
|
177
|
+
const message = errorMessage(err);
|
|
178
|
+
if (options.signal?.aborted) {
|
|
179
|
+
activityMonitor.logComplete(activityId, 0);
|
|
180
|
+
throw new Error("Aborted");
|
|
181
|
+
}
|
|
182
|
+
const providerTimeout = timeoutSignal.aborted || err instanceof Error && err.name === "TimeoutError";
|
|
183
|
+
let outgoing;
|
|
184
|
+
if (providerTimeout) {
|
|
185
|
+
outgoing = new Error(`XCrawl search request timed out after ${Math.round(SEARCH_TIMEOUT_MS / 1000)}s`);
|
|
186
|
+
} else {
|
|
187
|
+
const redactedMessage = redactCredential(message, apiKey);
|
|
188
|
+
outgoing = redactedMessage === message && err instanceof Error ? err : new Error(redactedMessage);
|
|
189
|
+
if (err instanceof Error && outgoing.name === "Error")
|
|
190
|
+
outgoing.name = err.name;
|
|
191
|
+
}
|
|
192
|
+
activityMonitor.logError(activityId, redactCredential(errorMessage(outgoing), apiKey));
|
|
193
|
+
throw outgoing;
|
|
194
|
+
}
|
|
195
|
+
if (!response.ok) {
|
|
196
|
+
activityMonitor.logComplete(activityId, response.status);
|
|
197
|
+
const errorText = redactCredential(await response.text(), apiKey);
|
|
198
|
+
let detail = errorText.slice(0, 300);
|
|
199
|
+
try {
|
|
200
|
+
const parsed = JSON.parse(errorText);
|
|
201
|
+
if (typeof parsed.message === "string")
|
|
202
|
+
detail = parsed.message.slice(0, 300);
|
|
203
|
+
else if (typeof parsed.error === "string")
|
|
204
|
+
detail = parsed.error.slice(0, 300);
|
|
205
|
+
} catch {}
|
|
206
|
+
throw new Error(`XCrawl API error (${response.status}): ${detail}`);
|
|
207
|
+
}
|
|
208
|
+
activityMonitor.logComplete(activityId, response.status);
|
|
209
|
+
let payload;
|
|
210
|
+
try {
|
|
211
|
+
payload = await response.json();
|
|
212
|
+
} catch (err) {
|
|
213
|
+
throw invalidResponse(`response body is not valid JSON: ${errorMessage(err)}`);
|
|
214
|
+
}
|
|
215
|
+
const results = parseResponse(payload);
|
|
216
|
+
const filtered = ((options.domainFilter?.length) ? applyDomainFilter(results, options.domainFilter) : results).slice(0, numResults);
|
|
217
|
+
return {
|
|
218
|
+
answer: buildAnswer(filtered),
|
|
219
|
+
results: filtered
|
|
220
|
+
};
|
|
221
|
+
}
|
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
import { execFileSync } from "node:child_process";
|
|
2
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
3
|
+
import { activityMonitor } from "./activity.js";
|
|
4
|
+
import { canAttachImages } from "./feature-config.js";
|
|
5
|
+
import { isGeminiWebAvailable, queryWithCookies } from "./gemini-web.js";
|
|
6
|
+
import { isGeminiApiAvailableWithVideo, queryGeminiApiWithVideo } from "./gemini-api.js";
|
|
7
|
+
import { isPerplexityAvailable, searchWithPerplexity } from "./perplexity.js";
|
|
8
|
+
import { extractHeadingTitle } from "./extract.js";
|
|
9
|
+
import { formatSeconds, readExecError, isTimeoutError, trimErrorText, mapFfmpegError, getWebSearchConfigPath } from "./utils.js";
|
|
10
|
+
const CONFIG_PATH = getWebSearchConfigPath();
|
|
11
|
+
const YOUTUBE_PROMPT = `Extract the complete content of this YouTube video. Include:
|
|
12
|
+
1. Video title, channel name, and duration
|
|
13
|
+
2. A brief summary (2-3 sentences)
|
|
14
|
+
3. Full transcript with timestamps
|
|
15
|
+
4. Descriptions of any code, terminal commands, diagrams, slides, or UI shown on screen
|
|
16
|
+
|
|
17
|
+
Format as markdown.`;
|
|
18
|
+
const YOUTUBE_REGEX = /(?:(?:www\.|m\.)?youtube\.com\/(?:watch\?.*v=|shorts\/|live\/|embed\/|v\/)|youtu\.be\/)([a-zA-Z0-9_-]{11})/;
|
|
19
|
+
function errorMessage(err) {
|
|
20
|
+
return err instanceof Error ? err.message : String(err);
|
|
21
|
+
}
|
|
22
|
+
function shouldRethrow(err) {
|
|
23
|
+
return errorMessage(err).startsWith("Failed to parse ");
|
|
24
|
+
}
|
|
25
|
+
function addAttemptError(errors, label, err) {
|
|
26
|
+
const message = errorMessage(err).replace(/\s+/g, " ").trim();
|
|
27
|
+
if (message)
|
|
28
|
+
errors.push(`${label}: ${message}`);
|
|
29
|
+
}
|
|
30
|
+
function normalizePreferredModel(value, fallback) {
|
|
31
|
+
if (typeof value !== "string")
|
|
32
|
+
return fallback;
|
|
33
|
+
const normalized = value.trim();
|
|
34
|
+
return normalized.length > 0 ? normalized : fallback;
|
|
35
|
+
}
|
|
36
|
+
function normalizeEnabled(value, fallback) {
|
|
37
|
+
return typeof value === "boolean" ? value : fallback;
|
|
38
|
+
}
|
|
39
|
+
const defaults = { enabled: true, preferredModel: "gemini-3.6-flash" };
|
|
40
|
+
let cachedConfig = null;
|
|
41
|
+
function loadYouTubeConfig() {
|
|
42
|
+
if (cachedConfig)
|
|
43
|
+
return cachedConfig;
|
|
44
|
+
if (!existsSync(CONFIG_PATH)) {
|
|
45
|
+
cachedConfig = { ...defaults };
|
|
46
|
+
return cachedConfig;
|
|
47
|
+
}
|
|
48
|
+
const rawText = readFileSync(CONFIG_PATH, "utf-8");
|
|
49
|
+
let raw;
|
|
50
|
+
try {
|
|
51
|
+
raw = JSON.parse(rawText);
|
|
52
|
+
} catch (err) {
|
|
53
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
54
|
+
throw new Error(`Failed to parse ${CONFIG_PATH}: ${message}`);
|
|
55
|
+
}
|
|
56
|
+
const yt = raw.youtube ?? {};
|
|
57
|
+
cachedConfig = {
|
|
58
|
+
enabled: normalizeEnabled(yt.enabled, defaults.enabled),
|
|
59
|
+
preferredModel: normalizePreferredModel(yt.preferredModel, defaults.preferredModel)
|
|
60
|
+
};
|
|
61
|
+
return cachedConfig;
|
|
62
|
+
}
|
|
63
|
+
export function isYouTubeURL(url) {
|
|
64
|
+
try {
|
|
65
|
+
const parsed = new URL(url);
|
|
66
|
+
if (parsed.pathname === "/playlist") {
|
|
67
|
+
return { isYouTube: false, videoId: null };
|
|
68
|
+
}
|
|
69
|
+
} catch {}
|
|
70
|
+
const match = url.match(YOUTUBE_REGEX);
|
|
71
|
+
if (!match)
|
|
72
|
+
return { isYouTube: false, videoId: null };
|
|
73
|
+
return { isYouTube: true, videoId: match[1] };
|
|
74
|
+
}
|
|
75
|
+
export function isYouTubeEnabled() {
|
|
76
|
+
return loadYouTubeConfig().enabled;
|
|
77
|
+
}
|
|
78
|
+
export async function extractYouTube(url, signal, prompt, model) {
|
|
79
|
+
const config = loadYouTubeConfig();
|
|
80
|
+
const { videoId } = isYouTubeURL(url);
|
|
81
|
+
const canonicalUrl = videoId ? `https://www.youtube.com/watch?v=${videoId}` : url;
|
|
82
|
+
const effectivePrompt = prompt ?? YOUTUBE_PROMPT;
|
|
83
|
+
const effectiveModel = model ?? config.preferredModel;
|
|
84
|
+
const activityId = activityMonitor.logStart({ type: "fetch", url: `youtube.com/${videoId ?? "video"}` });
|
|
85
|
+
const attemptErrors = [];
|
|
86
|
+
const result = await tryGeminiWeb(canonicalUrl, effectivePrompt, effectiveModel, signal, attemptErrors) ?? await tryGeminiApi(canonicalUrl, effectivePrompt, effectiveModel, signal, attemptErrors) ?? await tryPerplexity(url, effectivePrompt, signal, attemptErrors);
|
|
87
|
+
if (result) {
|
|
88
|
+
result.url = url;
|
|
89
|
+
if (!result.error && videoId && canAttachImages()) {
|
|
90
|
+
const thumb = await fetchYouTubeThumbnail(videoId);
|
|
91
|
+
if (thumb)
|
|
92
|
+
result.thumbnail = thumb;
|
|
93
|
+
}
|
|
94
|
+
activityMonitor.logComplete(activityId, result.error ? 0 : 200);
|
|
95
|
+
return result;
|
|
96
|
+
}
|
|
97
|
+
if (signal?.aborted) {
|
|
98
|
+
activityMonitor.logComplete(activityId, 0);
|
|
99
|
+
return null;
|
|
100
|
+
}
|
|
101
|
+
const error = attemptErrors.length > 0 ? ["Could not extract YouTube video content.", "", ...attemptErrors.map((message) => `- ${message}`)].join(`
|
|
102
|
+
`) : "Could not extract YouTube video content. Sign into Google in a supported Chromium browser for automatic access, or set GEMINI_API_KEY.";
|
|
103
|
+
activityMonitor.logError(activityId, error);
|
|
104
|
+
return { url, title: "", content: "", error };
|
|
105
|
+
}
|
|
106
|
+
function mapYtDlpError(err) {
|
|
107
|
+
const { code, stderr, message } = readExecError(err);
|
|
108
|
+
if (code === "ENOENT")
|
|
109
|
+
return "yt-dlp is not installed. Install with: brew install yt-dlp";
|
|
110
|
+
if (isTimeoutError(err))
|
|
111
|
+
return "yt-dlp timed out fetching video info";
|
|
112
|
+
const lower = stderr.toLowerCase();
|
|
113
|
+
if (lower.includes("private"))
|
|
114
|
+
return "Video is private or unavailable";
|
|
115
|
+
if (lower.includes("sign in"))
|
|
116
|
+
return "Video is age-restricted and requires authentication";
|
|
117
|
+
if (lower.includes("not available"))
|
|
118
|
+
return "Video is unavailable in your region or has been removed";
|
|
119
|
+
if (lower.includes("live"))
|
|
120
|
+
return "Cannot extract frames from a live stream";
|
|
121
|
+
const snippet = trimErrorText(stderr || message);
|
|
122
|
+
return snippet ? `yt-dlp failed: ${snippet}` : "yt-dlp failed";
|
|
123
|
+
}
|
|
124
|
+
export async function getYouTubeStreamInfo(videoId) {
|
|
125
|
+
try {
|
|
126
|
+
const output = execFileSync("yt-dlp", [
|
|
127
|
+
"--print",
|
|
128
|
+
"duration",
|
|
129
|
+
"-g",
|
|
130
|
+
`https://www.youtube.com/watch?v=${videoId}`
|
|
131
|
+
], { timeout: 15000, encoding: "utf-8", stdio: ["pipe", "pipe", "pipe"] }).trim();
|
|
132
|
+
const lines = output.split(/\r?\n/);
|
|
133
|
+
const rawDuration = lines[0]?.trim();
|
|
134
|
+
const streamUrl = lines[1]?.trim();
|
|
135
|
+
if (!streamUrl)
|
|
136
|
+
return { error: "yt-dlp failed: missing stream URL" };
|
|
137
|
+
const parsedDuration = rawDuration && rawDuration !== "NA" ? Number.parseFloat(rawDuration) : NaN;
|
|
138
|
+
const duration = Number.isFinite(parsedDuration) ? parsedDuration : null;
|
|
139
|
+
return { streamUrl, duration };
|
|
140
|
+
} catch (err) {
|
|
141
|
+
return { error: mapYtDlpError(err) };
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
async function extractFrameFromStream(streamUrl, seconds) {
|
|
145
|
+
try {
|
|
146
|
+
const buffer = execFileSync("ffmpeg", [
|
|
147
|
+
"-ss",
|
|
148
|
+
String(seconds),
|
|
149
|
+
"-i",
|
|
150
|
+
streamUrl,
|
|
151
|
+
"-frames:v",
|
|
152
|
+
"1",
|
|
153
|
+
"-f",
|
|
154
|
+
"image2pipe",
|
|
155
|
+
"-vcodec",
|
|
156
|
+
"mjpeg",
|
|
157
|
+
"pipe:1"
|
|
158
|
+
], { maxBuffer: 5 * 1024 * 1024, timeout: 30000, stdio: ["pipe", "pipe", "pipe"] });
|
|
159
|
+
if (buffer.length === 0)
|
|
160
|
+
return { error: "ffmpeg failed: empty output" };
|
|
161
|
+
return { data: buffer.toString("base64"), mimeType: "image/jpeg" };
|
|
162
|
+
} catch (err) {
|
|
163
|
+
return { error: mapFfmpegError(err) };
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
export async function extractYouTubeFrame(videoId, seconds, streamInfo) {
|
|
167
|
+
const info = streamInfo ?? await getYouTubeStreamInfo(videoId);
|
|
168
|
+
if ("error" in info)
|
|
169
|
+
return info;
|
|
170
|
+
return extractFrameFromStream(info.streamUrl, seconds);
|
|
171
|
+
}
|
|
172
|
+
export async function extractYouTubeFrames(videoId, timestamps, streamInfo) {
|
|
173
|
+
const info = streamInfo ?? await getYouTubeStreamInfo(videoId);
|
|
174
|
+
if ("error" in info)
|
|
175
|
+
return { frames: [], duration: null, error: info.error };
|
|
176
|
+
const results = await Promise.all(timestamps.map(async (t) => {
|
|
177
|
+
const frame = await extractFrameFromStream(info.streamUrl, t);
|
|
178
|
+
if ("error" in frame)
|
|
179
|
+
return { error: frame.error };
|
|
180
|
+
return { ...frame, timestamp: formatSeconds(t) };
|
|
181
|
+
}));
|
|
182
|
+
const frames = results.filter((f) => ("data" in f));
|
|
183
|
+
const errorResult = results.find((f) => ("error" in f));
|
|
184
|
+
return { frames, duration: info.duration, error: frames.length === 0 && errorResult ? errorResult.error : null };
|
|
185
|
+
}
|
|
186
|
+
export async function fetchYouTubeThumbnail(videoId) {
|
|
187
|
+
try {
|
|
188
|
+
const res = await fetch(`https://img.youtube.com/vi/${videoId}/hqdefault.jpg`, {
|
|
189
|
+
signal: AbortSignal.timeout(5000)
|
|
190
|
+
});
|
|
191
|
+
if (!res.ok)
|
|
192
|
+
return null;
|
|
193
|
+
const buffer = Buffer.from(await res.arrayBuffer());
|
|
194
|
+
if (buffer.length === 0)
|
|
195
|
+
return null;
|
|
196
|
+
return { data: buffer.toString("base64"), mimeType: "image/jpeg" };
|
|
197
|
+
} catch {
|
|
198
|
+
return null;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
async function tryGeminiWeb(url, prompt, model, signal, attemptErrors) {
|
|
202
|
+
try {
|
|
203
|
+
const cookies = await isGeminiWebAvailable();
|
|
204
|
+
if (!cookies)
|
|
205
|
+
return null;
|
|
206
|
+
if (signal?.aborted)
|
|
207
|
+
return null;
|
|
208
|
+
const text = await queryWithCookies(prompt, cookies, {
|
|
209
|
+
youtubeUrl: url,
|
|
210
|
+
...model !== "gemini-3.6-flash" ? { model } : {},
|
|
211
|
+
signal,
|
|
212
|
+
timeoutMs: 120000
|
|
213
|
+
});
|
|
214
|
+
return {
|
|
215
|
+
url,
|
|
216
|
+
title: extractHeadingTitle(text) ?? "YouTube Video",
|
|
217
|
+
content: text,
|
|
218
|
+
error: null
|
|
219
|
+
};
|
|
220
|
+
} catch (err) {
|
|
221
|
+
if (shouldRethrow(err))
|
|
222
|
+
throw err;
|
|
223
|
+
if (!signal?.aborted)
|
|
224
|
+
addAttemptError(attemptErrors, "Gemini Web", err);
|
|
225
|
+
return null;
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
async function tryGeminiApi(url, prompt, model, signal, attemptErrors) {
|
|
229
|
+
try {
|
|
230
|
+
if (!isGeminiApiAvailableWithVideo())
|
|
231
|
+
return null;
|
|
232
|
+
if (signal?.aborted)
|
|
233
|
+
return null;
|
|
234
|
+
const text = await queryGeminiApiWithVideo(prompt, url, {
|
|
235
|
+
model,
|
|
236
|
+
signal,
|
|
237
|
+
timeoutMs: 120000
|
|
238
|
+
});
|
|
239
|
+
return {
|
|
240
|
+
url,
|
|
241
|
+
title: extractHeadingTitle(text) ?? "YouTube Video",
|
|
242
|
+
content: text,
|
|
243
|
+
error: null
|
|
244
|
+
};
|
|
245
|
+
} catch (err) {
|
|
246
|
+
if (shouldRethrow(err))
|
|
247
|
+
throw err;
|
|
248
|
+
if (!signal?.aborted)
|
|
249
|
+
addAttemptError(attemptErrors, "Gemini API", err);
|
|
250
|
+
return null;
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
async function tryPerplexity(url, prompt, signal, attemptErrors) {
|
|
254
|
+
try {
|
|
255
|
+
if (signal?.aborted || !isPerplexityAvailable())
|
|
256
|
+
return null;
|
|
257
|
+
const perplexityQuery = prompt === YOUTUBE_PROMPT ? `Summarize this YouTube video in detail: ${url}` : `${prompt} YouTube video: ${url}`;
|
|
258
|
+
const { answer } = await searchWithPerplexity(perplexityQuery, { signal });
|
|
259
|
+
if (!answer)
|
|
260
|
+
return null;
|
|
261
|
+
const content = `# Video Summary (via Perplexity)
|
|
262
|
+
|
|
263
|
+
${answer}
|
|
264
|
+
|
|
265
|
+
` + `*Full video understanding requires Gemini access. Set GEMINI_API_KEY or sign into Google in a supported Chromium browser.*`;
|
|
266
|
+
return {
|
|
267
|
+
url,
|
|
268
|
+
title: "Video Summary (via Perplexity)",
|
|
269
|
+
content,
|
|
270
|
+
error: null
|
|
271
|
+
};
|
|
272
|
+
} catch (err) {
|
|
273
|
+
if (shouldRethrow(err))
|
|
274
|
+
throw err;
|
|
275
|
+
if (!signal?.aborted)
|
|
276
|
+
addAttemptError(attemptErrors, "Perplexity", err);
|
|
277
|
+
return null;
|
|
278
|
+
}
|
|
279
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@duckmind/dm-windows-x64",
|
|
3
|
-
"version": "0.63.
|
|
3
|
+
"version": "0.63.6",
|
|
4
4
|
"description": "DuckMind (dm) binary payload for windows x64",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"os": [
|
|
@@ -31,6 +31,14 @@
|
|
|
31
31
|
"jiti": "2.7.0",
|
|
32
32
|
"typebox": "^1.1.34",
|
|
33
33
|
"yaml": "2.8.3",
|
|
34
|
+
"@mozilla/readability": "^0.6.0",
|
|
35
|
+
"defuddle": "0.19.3",
|
|
36
|
+
"linkedom": "^0.16.0",
|
|
37
|
+
"p-limit": "^6.1.0",
|
|
38
|
+
"promise.try": "^2.0.1",
|
|
39
|
+
"turndown": "^7.2.0",
|
|
40
|
+
"undici": "^8.9.0",
|
|
41
|
+
"unpdf": "^1.6.2",
|
|
34
42
|
"@sinclair/typebox": "^0.34.48"
|
|
35
43
|
}
|
|
36
44
|
}
|