@steipete/summarize 0.18.1 → 0.20.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/CHANGELOG.md +32 -0
- package/README.md +11 -9
- package/dist/esm/application/asset-execution.js +122 -0
- package/dist/esm/application/asset-execution.js.map +1 -0
- package/dist/esm/application/execute-summarize.js +37 -318
- package/dist/esm/application/execute-summarize.js.map +1 -1
- package/dist/esm/application/execution-input.js +81 -0
- package/dist/esm/application/execution-input.js.map +1 -0
- package/dist/esm/application/url-routing.js +117 -0
- package/dist/esm/application/url-routing.js.map +1 -0
- package/dist/esm/cache.js +2 -2
- package/dist/esm/cache.js.map +1 -1
- package/dist/esm/config/parse-helpers.js +22 -0
- package/dist/esm/config/parse-helpers.js.map +1 -1
- package/dist/esm/config/sections.js +46 -126
- package/dist/esm/config/sections.js.map +1 -1
- package/dist/esm/daemon/agent-model.js +1 -1
- package/dist/esm/daemon/agent-model.js.map +1 -1
- package/dist/esm/daemon/agent.js +63 -31
- package/dist/esm/daemon/agent.js.map +1 -1
- package/dist/esm/daemon/cli-health.js +61 -0
- package/dist/esm/daemon/cli-health.js.map +1 -0
- package/dist/esm/daemon/cli-service.js +135 -0
- package/dist/esm/daemon/cli-service.js.map +1 -0
- package/dist/esm/daemon/cli.js +5 -211
- package/dist/esm/daemon/cli.js.map +1 -1
- package/dist/esm/daemon/config.js +1 -1
- package/dist/esm/daemon/config.js.map +1 -1
- package/dist/esm/daemon/server-admin-routes.js +1 -0
- package/dist/esm/daemon/server-admin-routes.js.map +1 -1
- package/dist/esm/daemon/server-auth.js +1 -0
- package/dist/esm/daemon/server-auth.js.map +1 -1
- package/dist/esm/daemon/server-http.js +1 -0
- package/dist/esm/daemon/server-http.js.map +1 -1
- package/dist/esm/daemon/server-session.js +1 -0
- package/dist/esm/daemon/server-session.js.map +1 -1
- package/dist/esm/daemon/server-sse.js +1 -0
- package/dist/esm/daemon/server-sse.js.map +1 -1
- package/dist/esm/daemon/server.js +1 -1
- package/dist/esm/daemon/server.js.map +1 -1
- package/dist/esm/engine/errors.js +1 -1
- package/dist/esm/engine/errors.js.map +1 -1
- package/dist/esm/llm/cli-provider-output/codex.js +143 -0
- package/dist/esm/llm/cli-provider-output/codex.js.map +1 -0
- package/dist/esm/llm/cli-provider-output/opencode.js +102 -0
- package/dist/esm/llm/cli-provider-output/opencode.js.map +1 -0
- package/dist/esm/llm/cli-provider-output/pi.js +94 -0
- package/dist/esm/llm/cli-provider-output/pi.js.map +1 -0
- package/dist/esm/llm/cli-provider-output/shared.js +11 -0
- package/dist/esm/llm/cli-provider-output/shared.js.map +1 -0
- package/dist/esm/llm/cli-provider-output.js +41 -440
- package/dist/esm/llm/cli-provider-output.js.map +1 -1
- package/dist/esm/llm/cli-runners/codex.js +97 -0
- package/dist/esm/llm/cli-runners/codex.js.map +1 -0
- package/dist/esm/llm/cli-runners/json.js +43 -0
- package/dist/esm/llm/cli-runners/json.js.map +1 -0
- package/dist/esm/llm/cli-runners/openclaw.js +45 -0
- package/dist/esm/llm/cli-runners/openclaw.js.map +1 -0
- package/dist/esm/llm/cli-runners/opencode.js +31 -0
- package/dist/esm/llm/cli-runners/opencode.js.map +1 -0
- package/dist/esm/llm/cli-runners/pi.js +43 -0
- package/dist/esm/llm/cli-runners/pi.js.map +1 -0
- package/dist/esm/llm/cli-runners/plain.js +63 -0
- package/dist/esm/llm/cli-runners/plain.js.map +1 -0
- package/dist/esm/llm/cli-runners/types.js +2 -0
- package/dist/esm/llm/cli-runners/types.js.map +1 -0
- package/dist/esm/llm/cli.js +34 -366
- package/dist/esm/llm/cli.js.map +1 -1
- package/dist/esm/llm/generate-text.js +1 -1
- package/dist/esm/llm/generate-text.js.map +1 -1
- package/dist/esm/llm/github-models.js +23 -0
- package/dist/esm/llm/github-models.js.map +1 -1
- package/dist/esm/llm/providers/openai/github-models.js +1 -13
- package/dist/esm/llm/providers/openai/github-models.js.map +1 -1
- package/dist/esm/llm/providers/openai/sse.js +11 -44
- package/dist/esm/llm/providers/openai/sse.js.map +1 -1
- package/dist/esm/model-auto.js +1 -1
- package/dist/esm/model-auto.js.map +1 -1
- package/dist/esm/run/flows/url/flow.js +1 -0
- package/dist/esm/run/flows/url/flow.js.map +1 -1
- package/dist/esm/run/flows/url/summary.js +2 -1
- package/dist/esm/run/flows/url/summary.js.map +1 -1
- package/dist/esm/run/flows/url/video-only.js +1 -0
- package/dist/esm/run/flows/url/video-only.js.map +1 -1
- package/dist/esm/run/help.js +2 -1
- package/dist/esm/run/help.js.map +1 -1
- package/dist/esm/run/run-settings.js +1 -1
- package/dist/esm/run/run-settings.js.map +1 -1
- package/dist/esm/slides/extract.js +3 -2
- package/dist/esm/slides/extract.js.map +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/types/application/asset-execution.d.ts +21 -0
- package/dist/types/application/execution-input.d.ts +13 -0
- package/dist/types/application/url-routing.d.ts +37 -0
- package/dist/types/config/parse-helpers.d.ts +6 -0
- package/dist/types/daemon/cli-health.d.ts +25 -0
- package/dist/types/daemon/cli-service.d.ts +39 -0
- package/dist/types/llm/cli-provider-output/codex.d.ts +9 -0
- package/dist/types/llm/cli-provider-output/opencode.d.ts +6 -0
- package/dist/types/llm/cli-provider-output/pi.d.ts +6 -0
- package/dist/types/llm/cli-provider-output/shared.d.ts +2 -0
- package/dist/types/llm/cli-provider-output.d.ts +3 -18
- package/dist/types/llm/cli-runners/codex.d.ts +2 -0
- package/dist/types/llm/cli-runners/json.d.ts +3 -0
- package/dist/types/llm/cli-runners/openclaw.d.ts +2 -0
- package/dist/types/llm/cli-runners/opencode.d.ts +2 -0
- package/dist/types/llm/cli-runners/pi.d.ts +2 -0
- package/dist/types/llm/cli-runners/plain.d.ts +3 -0
- package/dist/types/llm/cli-runners/types.d.ts +22 -0
- package/dist/types/llm/cli.d.ts +1 -6
- package/dist/types/llm/github-models.d.ts +2 -0
- package/dist/types/version.d.ts +1 -1
- package/docs/chrome-extension.md +23 -12
- package/docs/commands/daemon.md +4 -4
- package/docs/install.md +1 -1
- package/package.json +4 -6
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,37 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.20.0 - 2026-06-19
|
|
4
|
+
|
|
5
|
+
### Features
|
|
6
|
+
|
|
7
|
+
- Chrome extension: allow the local daemon port to be configured under **Options → Runtime → Daemon**, with consistent routing for daemon calls and authenticated slide images (#312, thanks @enieuwy).
|
|
8
|
+
|
|
9
|
+
### Fixes
|
|
10
|
+
|
|
11
|
+
- Streaming: share EOF-safe, whitespace-preserving SSE parsing across core, CLI providers, and extension clients.
|
|
12
|
+
- Config: preserve standalone `enabled: false` values for cache, media cache, slides, and logging sections.
|
|
13
|
+
- Daemon chat: surface non-streaming provider failures and apply the GitHub Models compatibility fallback to JSON and SSE agent responses.
|
|
14
|
+
- Dependencies: pin patched Vite, tmp, and protobufjs releases to clear known high- and moderate-severity transitive advisories.
|
|
15
|
+
|
|
16
|
+
## 0.19.0 - 2026-06-17
|
|
17
|
+
|
|
18
|
+
### Features
|
|
19
|
+
|
|
20
|
+
- Chrome extension: add Direct and Daemon AI connections with unified model selection; Auto uses configured direct providers or Gemini Nano on-device, while explicit Nano summaries remain local even with daemon capabilities enabled.
|
|
21
|
+
- Chrome extension: add direct provider-backed summaries, chat, automation, hover summaries, and URL extraction without the daemon, with independent AI and media runtimes plus local credentials for OpenAI, OpenRouter, Anthropic, Gemini, xAI, Z.AI, NVIDIA, MiniMax, GitHub Models, Ollama, and custom base URLs.
|
|
22
|
+
|
|
23
|
+
### Fixes
|
|
24
|
+
|
|
25
|
+
- Chrome extension: keep the default Direct/Gemini Nano experience immediately usable and show daemon performance and capability guidance as a compact dismissible hint.
|
|
26
|
+
- Chrome extension: preserve significant whitespace in SSE data fields while parsing daemon streams (#303, thanks @vincent-peng).
|
|
27
|
+
- Chrome extension: invoke Gemini Nano session methods with their native receiver so Browser summaries complete instead of silently falling back.
|
|
28
|
+
- Chrome extension slides: summarize each browser-extracted slide with Gemini Nano and cache CLI-compatible slide markers instead of showing raw transcript windows.
|
|
29
|
+
- Chrome extension slides: batch browser-extracted frames and transcript windows into one constrained multimodal Gemini Nano prompt, splitting only on context pressure and falling back safely when unavailable.
|
|
30
|
+
- Chrome extension slides: sample browser-captured frames across the full video duration so long videos include their final segment.
|
|
31
|
+
- Chrome extension: use Chrome's built-in Gemini Nano Summarizer API for daemonless Browser summaries when available, with first-use download progress and automatic extractive fallback.
|
|
32
|
+
- Remote transcripts: cap RSS and embedded caption response bodies at 5 MiB and cancel oversized streams. Thanks @Hinotoi-agent.
|
|
33
|
+
- Chrome extension: keep Direct mode's Gemini Nano path fully daemonless even with saved tokens, fail clearly when local extraction or transcription is unavailable, and hide chat and automation without a configured direct provider or authenticated daemon.
|
|
34
|
+
|
|
3
35
|
## 0.18.1 - 2026-06-13
|
|
4
36
|
|
|
5
37
|
### Fixes
|
package/README.md
CHANGED
|
@@ -36,17 +36,17 @@ YouTube slide screenshots (from the browser):
|
|
|
36
36
|
|
|
37
37
|
### Beginner quickstart (extension)
|
|
38
38
|
|
|
39
|
-
1. Install the
|
|
40
|
-
|
|
39
|
+
1. Install the extension (Chrome Web Store link above) and open the Side Panel.
|
|
40
|
+
2. Choose **Direct** or **Daemon**. Direct uses Gemini Nano by default when no provider key is configured, or calls your selected provider from Chrome.
|
|
41
|
+
3. Choose Browser media for daemonless transcription/slides. Optional: install the CLI and pair the daemon for native tools, CLI model fallbacks, OCR, and broader media support:
|
|
42
|
+
- **npm** (cross-platform): `npm i -g @steipete/summarize`
|
|
41
43
|
- **Homebrew** (Homebrew/core): `brew install summarize`
|
|
42
|
-
|
|
43
|
-
3. The panel shows a token + install command. Run it in Terminal:
|
|
44
|
-
- `summarize daemon install --token <TOKEN>`
|
|
44
|
+
- `summarize daemon install --token <TOKEN> --port 8787`
|
|
45
45
|
|
|
46
46
|
Why a daemon/service?
|
|
47
47
|
|
|
48
|
-
-
|
|
49
|
-
- The optional daemon on `127.0.0.1`
|
|
48
|
+
- Direct mode works without the daemon. Auto uses a configured OpenAI, OpenRouter, Anthropic, Gemini, xAI, Z.AI, NVIDIA, MiniMax, GitHub Models, or Ollama provider, otherwise Gemini Nano on-device; keys remain in extension-local storage.
|
|
49
|
+
- The optional daemon on `127.0.0.1` adds CLI model fallbacks, shared caches/diagnostics, native ffmpeg, configurable transcription providers, OCR, and broader media support.
|
|
50
50
|
- The service autostarts (launchd/systemd/Scheduled Task) so the Side Panel is always ready.
|
|
51
51
|
|
|
52
52
|
If you only want the **CLI**, you can skip the daemon install entirely.
|
|
@@ -56,8 +56,9 @@ Notes:
|
|
|
56
56
|
- Summarization only runs when the Side Panel is open.
|
|
57
57
|
- Auto mode summarizes on navigation (incl. SPAs); otherwise use the button.
|
|
58
58
|
- Daemon is localhost-only and requires a shared token; rerunning `summarize daemon install --token <TOKEN>` adds another paired browser token instead of invalidating the old one.
|
|
59
|
+
- Non-default port: install with `summarize daemon install --token <TOKEN> --port <PORT>`, then set the same value in **Options → Runtime → Daemon → Port**.
|
|
59
60
|
- Autostart: macOS (launchd), Linux (systemd user), Windows (Scheduled Task).
|
|
60
|
-
- Windows containers: `summarize daemon install` starts the daemon for the current container session but does not register a Scheduled Task. Run it each time the container starts or add that command to your container startup,
|
|
61
|
+
- Windows containers: `summarize daemon install` starts the daemon for the current container session but does not register a Scheduled Task. Run it each time the container starts or add that command to your container startup, publish the configured port (default `8787`), and set the same port in the extension.
|
|
61
62
|
- Tip: configure `free` via `summarize refresh-free` (needs `OPENROUTER_API_KEY`). Add `--set-default` to set model=`free`.
|
|
62
63
|
|
|
63
64
|
More:
|
|
@@ -153,7 +154,7 @@ If native `ffmpeg`/`ffprobe` are unavailable, Summarize uses the bundled WebAsse
|
|
|
153
154
|
### CLI vs extension
|
|
154
155
|
|
|
155
156
|
- **CLI only:** just install via npm/Homebrew and run `summarize ...` (no daemon needed).
|
|
156
|
-
- **Chrome extension:**
|
|
157
|
+
- **Chrome extension:** Direct mode defaults to Gemini Nano without a key and supports provider-backed summaries/chat/automation/hover when configured; Browser media provides daemonless transcription and slides. Install the daemon for CLI fallbacks and native media tools.
|
|
157
158
|
- **Firefox extension:** install the CLI and daemon for media extraction.
|
|
158
159
|
|
|
159
160
|
### Quickstart
|
|
@@ -861,6 +862,7 @@ pnpm check
|
|
|
861
862
|
- Reload the tab once.
|
|
862
863
|
- "Failed to fetch" / daemon unreachable:
|
|
863
864
|
- `summarize daemon status`
|
|
865
|
+
- For a non-default port, confirm **Options → Runtime → Daemon → Port** matches the daemon configuration.
|
|
864
866
|
- Logs: `~/.summarize/logs/daemon.err.log`
|
|
865
867
|
|
|
866
868
|
License: MIT
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { extractAssetContent } from "../run/flows/asset/extract.js";
|
|
2
|
+
import { executeMediaFile } from "../run/flows/asset/media.js";
|
|
3
|
+
import { executeAssetSummary } from "../run/flows/asset/summary.js";
|
|
4
|
+
function toAssetExecutionInput(input) {
|
|
5
|
+
return {
|
|
6
|
+
kind: "asset",
|
|
7
|
+
sourceKind: input.sourceKind,
|
|
8
|
+
source: input.sourceLabel,
|
|
9
|
+
mediaType: input.attachment.mediaType,
|
|
10
|
+
filename: input.attachment.filename,
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
async function executeResolvedMedia(input, options) {
|
|
14
|
+
if (!options.request.extractOnly) {
|
|
15
|
+
options.emit({ type: "summary-started" });
|
|
16
|
+
}
|
|
17
|
+
const mediaResult = await executeMediaFile(options.context, {
|
|
18
|
+
sourceKind: input.sourceKind,
|
|
19
|
+
sourceLabel: input.sourceLabel,
|
|
20
|
+
attachment: input.attachment,
|
|
21
|
+
onModelChosen: (modelId) => options.emit({ type: "model-selected", modelId }),
|
|
22
|
+
});
|
|
23
|
+
if (mediaResult.kind === "summary" && !mediaResult.summary.summaryEmitted) {
|
|
24
|
+
options.emitSummary(mediaResult.summary.summary);
|
|
25
|
+
}
|
|
26
|
+
const report = mediaResult.kind === "summary" ? await options.context.buildReport() : null;
|
|
27
|
+
const result = {
|
|
28
|
+
kind: "asset-media",
|
|
29
|
+
input: toAssetExecutionInput(input),
|
|
30
|
+
usedModel: options.getSelectedModel() ??
|
|
31
|
+
(mediaResult.kind === "summary" ? (mediaResult.summary.llm?.model ?? null) : null),
|
|
32
|
+
summaryFromCache: mediaResult.kind === "summary" ? mediaResult.summary.summaryFromCache : false,
|
|
33
|
+
elapsedMs: options.elapsedMs(),
|
|
34
|
+
report,
|
|
35
|
+
costUsd: mediaResult.kind === "summary" ? await options.context.estimateCostUsd() : null,
|
|
36
|
+
details: mediaResult,
|
|
37
|
+
};
|
|
38
|
+
options.emit({ type: "run-completed", result });
|
|
39
|
+
return result;
|
|
40
|
+
}
|
|
41
|
+
async function executeResolvedAsset(input, options) {
|
|
42
|
+
if (options.request.extractOnly) {
|
|
43
|
+
const maxCharacters = options.request.input.kind === "url" || options.request.input.kind === "input-url"
|
|
44
|
+
? options.request.input.maxCharacters
|
|
45
|
+
: null;
|
|
46
|
+
const extractedAsset = await extractAssetContent({
|
|
47
|
+
ctx: {
|
|
48
|
+
env: options.context.env,
|
|
49
|
+
envForRun: options.context.envForRun,
|
|
50
|
+
execFileImpl: options.context.execFileImpl,
|
|
51
|
+
timeoutMs: options.context.timeoutMs,
|
|
52
|
+
preprocessMode: options.context.preprocessMode,
|
|
53
|
+
},
|
|
54
|
+
attachment: input.attachment,
|
|
55
|
+
...(typeof maxCharacters === "number" ? { maxCharacters } : {}),
|
|
56
|
+
});
|
|
57
|
+
const report = options.context.shouldComputeReport ? await options.context.buildReport() : null;
|
|
58
|
+
const result = {
|
|
59
|
+
kind: "asset-extraction",
|
|
60
|
+
input: toAssetExecutionInput(input),
|
|
61
|
+
extracted: extractedAsset,
|
|
62
|
+
elapsedMs: options.elapsedMs(),
|
|
63
|
+
report,
|
|
64
|
+
costUsd: options.context.metricsEnabled && report ? await options.context.estimateCostUsd() : null,
|
|
65
|
+
};
|
|
66
|
+
options.emit({ type: "run-completed", result });
|
|
67
|
+
return result;
|
|
68
|
+
}
|
|
69
|
+
options.emit({ type: "summary-started" });
|
|
70
|
+
const assetResult = await executeAssetSummary(options.context, {
|
|
71
|
+
sourceKind: input.sourceKind,
|
|
72
|
+
sourceLabel: input.sourceLabel,
|
|
73
|
+
attachment: input.attachment,
|
|
74
|
+
onModelChosen: (modelId) => options.emit({ type: "model-selected", modelId }),
|
|
75
|
+
});
|
|
76
|
+
if (!assetResult.summaryEmitted) {
|
|
77
|
+
options.emitSummary(assetResult.summary);
|
|
78
|
+
}
|
|
79
|
+
const result = {
|
|
80
|
+
kind: "asset-summary",
|
|
81
|
+
input: toAssetExecutionInput(input),
|
|
82
|
+
summary: assetResult.summary,
|
|
83
|
+
usedModel: options.getSelectedModel() ?? assetResult.llm?.model ?? null,
|
|
84
|
+
summaryFromCache: assetResult.summaryFromCache,
|
|
85
|
+
elapsedMs: options.elapsedMs(),
|
|
86
|
+
report: await options.context.buildReport(),
|
|
87
|
+
costUsd: await options.context.estimateCostUsd(),
|
|
88
|
+
details: assetResult,
|
|
89
|
+
};
|
|
90
|
+
options.emit({ type: "run-completed", result });
|
|
91
|
+
return result;
|
|
92
|
+
}
|
|
93
|
+
export function createAcquiredAssetExecutor(options) {
|
|
94
|
+
const execute = async (input) => {
|
|
95
|
+
const context = options.context;
|
|
96
|
+
if (!context) {
|
|
97
|
+
throw new Error(input.kind === "resolved-media"
|
|
98
|
+
? "Resolved media execution requires prepared asset resources"
|
|
99
|
+
: "Resolved asset execution requires prepared asset resources");
|
|
100
|
+
}
|
|
101
|
+
const executionOptions = { ...options, context };
|
|
102
|
+
return input.kind === "resolved-media"
|
|
103
|
+
? await executeResolvedMedia(input, executionOptions)
|
|
104
|
+
: await executeResolvedAsset(input, executionOptions);
|
|
105
|
+
};
|
|
106
|
+
const emitProgress = (input) => {
|
|
107
|
+
options.emit({
|
|
108
|
+
type: "input-progress",
|
|
109
|
+
phase: input.kind === "resolved-media"
|
|
110
|
+
? "transcribing"
|
|
111
|
+
: options.request.extractOnly
|
|
112
|
+
? "extracting"
|
|
113
|
+
: "summarizing",
|
|
114
|
+
source: input.sourceLabel,
|
|
115
|
+
filename: input.attachment.filename,
|
|
116
|
+
mediaType: input.attachment.mediaType,
|
|
117
|
+
sizeBytes: input.sizeBytes,
|
|
118
|
+
});
|
|
119
|
+
};
|
|
120
|
+
return { execute, emitProgress };
|
|
121
|
+
}
|
|
122
|
+
//# sourceMappingURL=asset-execution.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"asset-execution.js","sourceRoot":"","sources":["../../../src/application/asset-execution.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,+BAA+B,CAAC;AACpE,OAAO,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAC/D,OAAO,EAAE,mBAAmB,EAAE,MAAM,+BAA+B,CAAC;AAoCpE,SAAS,qBAAqB,CAAC,KAAyB;IACtD,OAAO;QACL,IAAI,EAAE,OAAO;QACb,UAAU,EAAE,KAAK,CAAC,UAAU;QAC5B,MAAM,EAAE,KAAK,CAAC,WAAW;QACzB,SAAS,EAAE,KAAK,CAAC,UAAU,CAAC,SAAS;QACrC,QAAQ,EAAE,KAAK,CAAC,UAAU,CAAC,QAAQ;KACpC,CAAC;AACJ,CAAC;AAED,KAAK,UAAU,oBAAoB,CACjC,KAA8D,EAC9D,OAAwE;IAExE,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,WAAW,EAAE,CAAC;QACjC,OAAO,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,iBAAiB,EAAE,CAAC,CAAC;IAC5C,CAAC;IACD,MAAM,WAAW,GAAG,MAAM,gBAAgB,CAAC,OAAO,CAAC,OAAO,EAAE;QAC1D,UAAU,EAAE,KAAK,CAAC,UAAU;QAC5B,WAAW,EAAE,KAAK,CAAC,WAAW;QAC9B,UAAU,EAAE,KAAK,CAAC,UAAU;QAC5B,aAAa,EAAE,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URL } from "node:url";
|
|
3
|
-
import { isDirectVideoInput, isYouTubeUrl } from "@steipete/summarize-core/content/url";
|
|
4
|
-
import { hasEngineErrorCode } from "../engine/errors.js";
|
|
1
|
+
import { isYouTubeUrl } from "@steipete/summarize-core/content/url";
|
|
5
2
|
import { buildUrlPrompt } from "../engine/web-prompt.js";
|
|
6
3
|
import { resolveUrlSummaryExecution } from "../engine/web-summary.js";
|
|
7
|
-
import {
|
|
8
|
-
import { extractAssetContent } from "../run/flows/asset/extract.js";
|
|
9
|
-
import { executeMediaFile } from "../run/flows/asset/media.js";
|
|
10
|
-
import { executeAssetSummary } from "../run/flows/asset/summary.js";
|
|
11
|
-
import { executeUrlFlow } from "../run/flows/url/flow.js";
|
|
4
|
+
import { createAcquiredAssetExecutor } from "./asset-execution.js";
|
|
12
5
|
import { readLastSuccessfulCliProvider, writeLastSuccessfulCliProvider, } from "./cli-fallback-state.js";
|
|
6
|
+
import { prepareExecutionInput } from "./execution-input.js";
|
|
13
7
|
import { bindSummarizeExecutionEvents, } from "./execution-resources.js";
|
|
14
|
-
import { acquireLocalAssetInput, acquireRemoteAssetInput, createRemoteMediaInput, getLocalAssetSize, isPdfAssetPath, isTranscribableAssetPath, materializeAcquiredMediaInput, resolveUrlAssetRoute, } from "./input-acquisition.js";
|
|
15
|
-
import { createTempFileFromStdin } from "./stdin-input.js";
|
|
16
8
|
import { toUrlSummaryPresentationResolution, } from "./url-result.js";
|
|
9
|
+
import { executeUrlWithAssetFallback, resolveInitialUrlInput } from "./url-routing.js";
|
|
17
10
|
import { createSummarizeRuntimeResources } from "./url-runtime.js";
|
|
18
11
|
const ignoreEvent = () => { };
|
|
19
12
|
function createVisiblePageContent(input, cacheMode) {
|
|
@@ -114,15 +107,6 @@ function emitNormalizedSummary(summary, emit) {
|
|
|
114
107
|
text: normalized.endsWith("\n") ? normalized : `${normalized}\n`,
|
|
115
108
|
});
|
|
116
109
|
}
|
|
117
|
-
function toAssetExecutionInput(input) {
|
|
118
|
-
return {
|
|
119
|
-
kind: "asset",
|
|
120
|
-
sourceKind: input.sourceKind,
|
|
121
|
-
source: input.sourceLabel,
|
|
122
|
-
mediaType: input.attachment.mediaType,
|
|
123
|
-
filename: input.attachment.filename,
|
|
124
|
-
};
|
|
125
|
-
}
|
|
126
110
|
function toEventInput(input) {
|
|
127
111
|
if (input.kind === "resolved-asset" || input.kind === "resolved-media") {
|
|
128
112
|
return {
|
|
@@ -135,15 +119,6 @@ function toEventInput(input) {
|
|
|
135
119
|
}
|
|
136
120
|
return input;
|
|
137
121
|
}
|
|
138
|
-
function canRetryUrlFlowAfterAssetMiss(ctx) {
|
|
139
|
-
return ctx.flags.firecrawlMode !== "off" && ctx.model.apiStatus.firecrawlConfigured;
|
|
140
|
-
}
|
|
141
|
-
function allowUrlFlowFirecrawlFallback(ctx) {
|
|
142
|
-
return {
|
|
143
|
-
...ctx,
|
|
144
|
-
flags: { ...ctx.flags, throwOnAssetLikeHtmlError: false },
|
|
145
|
-
};
|
|
146
|
-
}
|
|
147
122
|
export async function executeSummarize(request, runtime, events = ignoreEvent, prepared = null) {
|
|
148
123
|
const now = runtime.now ?? Date.now;
|
|
149
124
|
const startedAt = now();
|
|
@@ -183,64 +158,9 @@ export async function executeSummarize(request, runtime, events = ignoreEvent, p
|
|
|
183
158
|
input: toEventInput(request.input),
|
|
184
159
|
});
|
|
185
160
|
try {
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
throw new Error("--extract is not supported for piped stdin input");
|
|
190
|
-
}
|
|
191
|
-
const stdin = runtime.stdin;
|
|
192
|
-
if (!stdin) {
|
|
193
|
-
throw new Error("Stdin execution requires a readable input stream");
|
|
194
|
-
}
|
|
195
|
-
const temp = await createTempFileFromStdin({ stream: stdin });
|
|
196
|
-
cleanupStdin = temp.cleanup;
|
|
197
|
-
executionInput = { kind: "file", filePath: temp.filePath };
|
|
198
|
-
}
|
|
199
|
-
if (executionInput.kind === "file") {
|
|
200
|
-
if (request.extractOnly &&
|
|
201
|
-
!isTranscribableAssetPath(executionInput.filePath) &&
|
|
202
|
-
!isPdfAssetPath(executionInput.filePath)) {
|
|
203
|
-
throw new Error("--extract for local files is only supported for media files (MP3, MP4, WAV, etc.) and PDF files");
|
|
204
|
-
}
|
|
205
|
-
if (request.slides && isDirectVideoInput(executionInput.filePath)) {
|
|
206
|
-
executionInput = {
|
|
207
|
-
kind: "url",
|
|
208
|
-
url: pathToFileURL(executionInput.filePath).href,
|
|
209
|
-
title: null,
|
|
210
|
-
maxCharacters: null,
|
|
211
|
-
};
|
|
212
|
-
}
|
|
213
|
-
else {
|
|
214
|
-
const sizeBytes = await getLocalAssetSize(executionInput.filePath);
|
|
215
|
-
emit({
|
|
216
|
-
type: "input-progress",
|
|
217
|
-
phase: "loading",
|
|
218
|
-
source: executionInput.filePath,
|
|
219
|
-
filename: path.basename(executionInput.filePath),
|
|
220
|
-
mediaType: null,
|
|
221
|
-
sizeBytes,
|
|
222
|
-
});
|
|
223
|
-
const acquired = await acquireLocalAssetInput({
|
|
224
|
-
filePath: executionInput.filePath,
|
|
225
|
-
...(request.extractOnly && isPdfAssetPath(executionInput.filePath)
|
|
226
|
-
? { maxBytes: MAX_PDF_EXTRACT_BYTES }
|
|
227
|
-
: {}),
|
|
228
|
-
});
|
|
229
|
-
emit({
|
|
230
|
-
type: "input-progress",
|
|
231
|
-
phase: acquired.kind === "resolved-media"
|
|
232
|
-
? "transcribing"
|
|
233
|
-
: request.extractOnly
|
|
234
|
-
? "extracting"
|
|
235
|
-
: "summarizing",
|
|
236
|
-
source: acquired.sourceLabel,
|
|
237
|
-
filename: acquired.attachment.filename,
|
|
238
|
-
mediaType: acquired.attachment.mediaType,
|
|
239
|
-
sizeBytes: acquired.sizeBytes,
|
|
240
|
-
});
|
|
241
|
-
executionInput = acquired;
|
|
242
|
-
}
|
|
243
|
-
}
|
|
161
|
+
const preparedInput = await prepareExecutionInput({ request, runtime, emit });
|
|
162
|
+
cleanupStdin = preparedInput.cleanup;
|
|
163
|
+
let executionInput = preparedInput.input;
|
|
244
164
|
const executionRequest = executionInput === request.input ? request : { ...request, input: executionInput };
|
|
245
165
|
const boundPrepared = prepared
|
|
246
166
|
? bindSummarizeExecutionEvents(prepared, emit)
|
|
@@ -250,168 +170,28 @@ export async function executeSummarize(request, runtime, events = ignoreEvent, p
|
|
|
250
170
|
runStartedAtMs: startedAt,
|
|
251
171
|
emit,
|
|
252
172
|
});
|
|
253
|
-
const
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
const result = {
|
|
274
|
-
kind: "asset-media",
|
|
275
|
-
input: toAssetExecutionInput(input),
|
|
276
|
-
usedModel: usedModel ??
|
|
277
|
-
(mediaResult.kind === "summary" ? (mediaResult.summary.llm?.model ?? null) : null),
|
|
278
|
-
summaryFromCache: mediaResult.kind === "summary" ? mediaResult.summary.summaryFromCache : false,
|
|
279
|
-
elapsedMs: now() - startedAt,
|
|
280
|
-
report,
|
|
281
|
-
costUsd: mediaResult.kind === "summary" ? await assetSummaryContext.estimateCostUsd() : null,
|
|
282
|
-
details: mediaResult,
|
|
283
|
-
};
|
|
284
|
-
emit({ type: "run-completed", result });
|
|
285
|
-
return result;
|
|
286
|
-
};
|
|
287
|
-
const executeResolvedAssetInput = async (input) => {
|
|
288
|
-
const assetSummaryContext = boundPrepared.assetSummaryContext;
|
|
289
|
-
if (!assetSummaryContext) {
|
|
290
|
-
throw new Error("Resolved asset execution requires prepared asset resources");
|
|
291
|
-
}
|
|
292
|
-
if (request.extractOnly) {
|
|
293
|
-
const maxCharacters = request.input.kind === "url" || request.input.kind === "input-url"
|
|
294
|
-
? request.input.maxCharacters
|
|
295
|
-
: null;
|
|
296
|
-
const extractedAsset = await extractAssetContent({
|
|
297
|
-
ctx: {
|
|
298
|
-
env: assetSummaryContext.env,
|
|
299
|
-
envForRun: assetSummaryContext.envForRun,
|
|
300
|
-
execFileImpl: assetSummaryContext.execFileImpl,
|
|
301
|
-
timeoutMs: assetSummaryContext.timeoutMs,
|
|
302
|
-
preprocessMode: assetSummaryContext.preprocessMode,
|
|
303
|
-
},
|
|
304
|
-
attachment: input.attachment,
|
|
305
|
-
...(typeof maxCharacters === "number" ? { maxCharacters } : {}),
|
|
306
|
-
});
|
|
307
|
-
const report = assetSummaryContext.shouldComputeReport
|
|
308
|
-
? await assetSummaryContext.buildReport()
|
|
309
|
-
: null;
|
|
310
|
-
const result = {
|
|
311
|
-
kind: "asset-extraction",
|
|
312
|
-
input: toAssetExecutionInput(input),
|
|
313
|
-
extracted: extractedAsset,
|
|
314
|
-
elapsedMs: now() - startedAt,
|
|
315
|
-
report,
|
|
316
|
-
costUsd: assetSummaryContext.metricsEnabled && report
|
|
317
|
-
? await assetSummaryContext.estimateCostUsd()
|
|
318
|
-
: null,
|
|
319
|
-
};
|
|
320
|
-
emit({ type: "run-completed", result });
|
|
321
|
-
return result;
|
|
322
|
-
}
|
|
323
|
-
emit({ type: "summary-started" });
|
|
324
|
-
const assetResult = await executeAssetSummary(assetSummaryContext, {
|
|
325
|
-
sourceKind: input.sourceKind,
|
|
326
|
-
sourceLabel: input.sourceLabel,
|
|
327
|
-
attachment: input.attachment,
|
|
328
|
-
onModelChosen: (modelId) => emit({ type: "model-selected", modelId }),
|
|
329
|
-
});
|
|
330
|
-
if (!assetResult.summaryEmitted) {
|
|
331
|
-
emitNormalizedSummary(assetResult.summary, emit);
|
|
332
|
-
}
|
|
333
|
-
const result = {
|
|
334
|
-
kind: "asset-summary",
|
|
335
|
-
input: toAssetExecutionInput(input),
|
|
336
|
-
summary: assetResult.summary,
|
|
337
|
-
usedModel: usedModel ?? assetResult.llm?.model ?? null,
|
|
338
|
-
summaryFromCache: assetResult.summaryFromCache,
|
|
339
|
-
elapsedMs: now() - startedAt,
|
|
340
|
-
report: await assetSummaryContext.buildReport(),
|
|
341
|
-
costUsd: await assetSummaryContext.estimateCostUsd(),
|
|
342
|
-
details: assetResult,
|
|
343
|
-
};
|
|
344
|
-
emit({ type: "run-completed", result });
|
|
345
|
-
return result;
|
|
346
|
-
};
|
|
347
|
-
const executeAcquiredAssetInput = async (input) => input.kind === "resolved-media"
|
|
348
|
-
? await executeResolvedMediaInput(input)
|
|
349
|
-
: await executeResolvedAssetInput(input);
|
|
350
|
-
const emitAcquiredProgress = (acquired) => {
|
|
351
|
-
emit({
|
|
352
|
-
type: "input-progress",
|
|
353
|
-
phase: acquired.kind === "resolved-media"
|
|
354
|
-
? "transcribing"
|
|
355
|
-
: request.extractOnly
|
|
356
|
-
? "extracting"
|
|
357
|
-
: "summarizing",
|
|
358
|
-
source: acquired.sourceLabel,
|
|
359
|
-
filename: acquired.attachment.filename,
|
|
360
|
-
mediaType: acquired.attachment.mediaType,
|
|
361
|
-
sizeBytes: acquired.sizeBytes,
|
|
362
|
-
});
|
|
363
|
-
};
|
|
364
|
-
const rawUrlInput = executionInput.kind === "input-url" ? executionInput : null;
|
|
365
|
-
if (rawUrlInput) {
|
|
366
|
-
const isYoutubeUrl = prepared?.isYoutubeUrl ?? isYouTubeUrl(rawUrlInput.url);
|
|
367
|
-
const route = await resolveUrlAssetRoute({
|
|
368
|
-
url: rawUrlInput.url,
|
|
369
|
-
isYoutubeUrl,
|
|
370
|
-
fetchImpl: boundPrepared.urlFlowContext.io.fetch,
|
|
371
|
-
timeoutMs: boundPrepared.urlFlowContext.flags.timeoutMs,
|
|
372
|
-
detectUnknownAssetUrls: false,
|
|
373
|
-
});
|
|
374
|
-
if (route === "audio" || route === "video") {
|
|
375
|
-
if (request.slides && route === "video") {
|
|
376
|
-
executionInput = { ...rawUrlInput, kind: "url" };
|
|
377
|
-
}
|
|
378
|
-
else {
|
|
379
|
-
const acquired = createRemoteMediaInput(rawUrlInput.url);
|
|
380
|
-
emitAcquiredProgress(acquired);
|
|
381
|
-
executionInput = acquired;
|
|
382
|
-
}
|
|
383
|
-
}
|
|
384
|
-
else if (route === "asset") {
|
|
385
|
-
emit({
|
|
386
|
-
type: "input-progress",
|
|
387
|
-
phase: "loading",
|
|
388
|
-
source: rawUrlInput.url,
|
|
389
|
-
filename: null,
|
|
390
|
-
mediaType: null,
|
|
391
|
-
sizeBytes: null,
|
|
392
|
-
});
|
|
393
|
-
const acquired = await acquireRemoteAssetInput({
|
|
394
|
-
url: rawUrlInput.url,
|
|
395
|
-
fetchImpl: boundPrepared.urlFlowContext.io.fetch,
|
|
396
|
-
timeoutMs: boundPrepared.urlFlowContext.flags.timeoutMs,
|
|
397
|
-
});
|
|
398
|
-
if (acquired) {
|
|
399
|
-
emitAcquiredProgress(acquired);
|
|
400
|
-
executionInput = acquired;
|
|
401
|
-
}
|
|
402
|
-
else {
|
|
403
|
-
executionInput = { ...rawUrlInput, kind: "url" };
|
|
404
|
-
}
|
|
405
|
-
}
|
|
406
|
-
else {
|
|
407
|
-
executionInput = { ...rawUrlInput, kind: "url" };
|
|
408
|
-
}
|
|
409
|
-
}
|
|
410
|
-
if (executionInput.kind === "input-url") {
|
|
411
|
-
throw new Error("Internal error: raw input was not resolved");
|
|
412
|
-
}
|
|
173
|
+
const assetExecutor = createAcquiredAssetExecutor({
|
|
174
|
+
request,
|
|
175
|
+
context: boundPrepared.assetSummaryContext,
|
|
176
|
+
emit,
|
|
177
|
+
emitSummary: (summary) => emitNormalizedSummary(summary, emit),
|
|
178
|
+
elapsedMs: () => now() - startedAt,
|
|
179
|
+
getSelectedModel: () => usedModel,
|
|
180
|
+
});
|
|
181
|
+
const routedInput = await resolveInitialUrlInput({
|
|
182
|
+
input: executionInput,
|
|
183
|
+
request,
|
|
184
|
+
isYoutubeUrl: executionInput.kind === "input-url"
|
|
185
|
+
? (prepared?.isYoutubeUrl ?? isYouTubeUrl(executionInput.url))
|
|
186
|
+
: false,
|
|
187
|
+
ctx: boundPrepared.urlFlowContext,
|
|
188
|
+
assetExecutor,
|
|
189
|
+
emit,
|
|
190
|
+
});
|
|
191
|
+
executionInput = routedInput.input;
|
|
192
|
+
const rawUrlInput = routedInput.rawUrlInput;
|
|
413
193
|
if (executionInput.kind === "resolved-media" || executionInput.kind === "resolved-asset") {
|
|
414
|
-
return await
|
|
194
|
+
return await assetExecutor.execute(executionInput);
|
|
415
195
|
}
|
|
416
196
|
if (request.extractOnly && executionInput.kind !== "url") {
|
|
417
197
|
throw new Error("Extract-only execution requires a URL input");
|
|
@@ -433,76 +213,15 @@ export async function executeSummarize(request, runtime, events = ignoreEvent, p
|
|
|
433
213
|
else {
|
|
434
214
|
emit({ type: "extraction-started", url: executionInput.url });
|
|
435
215
|
const isYoutubeUrl = prepared?.isYoutubeUrl ?? isYouTubeUrl(executionInput.url);
|
|
436
|
-
const urlResult = await (
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
if (!rawUrlInput || !hasEngineErrorCode(error, "ASSET_LIKE_HTML_FETCH")) {
|
|
446
|
-
throw error;
|
|
447
|
-
}
|
|
448
|
-
emit({
|
|
449
|
-
type: "input-progress",
|
|
450
|
-
phase: "loading",
|
|
451
|
-
source: rawUrlInput.url,
|
|
452
|
-
filename: null,
|
|
453
|
-
mediaType: null,
|
|
454
|
-
sizeBytes: null,
|
|
455
|
-
});
|
|
456
|
-
const fallbackRoute = await resolveUrlAssetRoute({
|
|
457
|
-
url: rawUrlInput.url,
|
|
458
|
-
isYoutubeUrl,
|
|
459
|
-
fetchImpl: ctx.io.fetch,
|
|
460
|
-
timeoutMs: ctx.flags.timeoutMs,
|
|
461
|
-
detectUnknownAssetUrls: true,
|
|
462
|
-
assumeAsset: true,
|
|
463
|
-
});
|
|
464
|
-
if ((fallbackRoute === "audio" || fallbackRoute === "video") &&
|
|
465
|
-
(!request.slides || fallbackRoute === "audio")) {
|
|
466
|
-
const acquired = createRemoteMediaInput(rawUrlInput.url);
|
|
467
|
-
emitAcquiredProgress(acquired);
|
|
468
|
-
return await executeResolvedMediaInput(acquired);
|
|
469
|
-
}
|
|
470
|
-
if (fallbackRoute === "asset" || (fallbackRoute === "video" && request.slides)) {
|
|
471
|
-
const acquired = await acquireRemoteAssetInput({
|
|
472
|
-
url: rawUrlInput.url,
|
|
473
|
-
fetchImpl: ctx.io.fetch,
|
|
474
|
-
timeoutMs: ctx.flags.timeoutMs,
|
|
475
|
-
});
|
|
476
|
-
if (acquired) {
|
|
477
|
-
emitAcquiredProgress(acquired);
|
|
478
|
-
if (acquired.kind === "resolved-media" &&
|
|
479
|
-
request.slides &&
|
|
480
|
-
acquired.attachment.mediaType.toLowerCase().startsWith("video/")) {
|
|
481
|
-
const materialized = await materializeAcquiredMediaInput(acquired);
|
|
482
|
-
try {
|
|
483
|
-
return await executeUrlFlow({
|
|
484
|
-
ctx,
|
|
485
|
-
url: pathToFileURL(materialized.filePath).href,
|
|
486
|
-
isYoutubeUrl: false,
|
|
487
|
-
});
|
|
488
|
-
}
|
|
489
|
-
finally {
|
|
490
|
-
await materialized.cleanup();
|
|
491
|
-
}
|
|
492
|
-
}
|
|
493
|
-
return await executeAcquiredAssetInput(acquired);
|
|
494
|
-
}
|
|
495
|
-
}
|
|
496
|
-
if (canRetryUrlFlowAfterAssetMiss(ctx)) {
|
|
497
|
-
return await executeUrlFlow({
|
|
498
|
-
ctx: allowUrlFlowFirecrawlFallback(ctx),
|
|
499
|
-
url: executionInput.url,
|
|
500
|
-
isYoutubeUrl,
|
|
501
|
-
});
|
|
502
|
-
}
|
|
503
|
-
throw error;
|
|
504
|
-
}
|
|
505
|
-
})();
|
|
216
|
+
const urlResult = await executeUrlWithAssetFallback({
|
|
217
|
+
input: executionInput,
|
|
218
|
+
rawUrlInput,
|
|
219
|
+
request,
|
|
220
|
+
isYoutubeUrl,
|
|
221
|
+
ctx,
|
|
222
|
+
assetExecutor,
|
|
223
|
+
emit,
|
|
224
|
+
});
|
|
506
225
|
if (urlResult.kind === "asset-media" ||
|
|
507
226
|
urlResult.kind === "asset-summary" ||
|
|
508
227
|
urlResult.kind === "asset-extraction") {
|