@steipete/summarize 0.19.0 → 0.20.1
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 +25 -0
- package/README.md +5 -3
- package/completions/summarize.fish +1 -1
- 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/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/content/asset.js +11 -1
- package/dist/esm/content/asset.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 +64 -32
- 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/models.js +1 -1
- package/dist/esm/daemon/models.js.map +1 -1
- package/dist/esm/daemon/schtasks.js +7 -2
- package/dist/esm/daemon/schtasks.js.map +1 -1
- package/dist/esm/engine/model-executor.js +76 -17
- package/dist/esm/engine/model-executor.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-shared.js +127 -9
- package/dist/esm/llm/generate-text-shared.js.map +1 -1
- package/dist/esm/llm/generate-text-stream.js +6 -4
- package/dist/esm/llm/generate-text-stream.js.map +1 -1
- package/dist/esm/llm/generate-text.js +83 -42
- 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/anthropic.js +32 -14
- package/dist/esm/llm/providers/anthropic.js.map +1 -1
- package/dist/esm/llm/providers/google.js +52 -8
- package/dist/esm/llm/providers/google.js.map +1 -1
- package/dist/esm/llm/providers/models.js +23 -17
- package/dist/esm/llm/providers/models.js.map +1 -1
- package/dist/esm/llm/providers/openai/chat-completions.js +2 -8
- package/dist/esm/llm/providers/openai/chat-completions.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/responses.js +2 -8
- package/dist/esm/llm/providers/openai/responses.js.map +1 -1
- package/dist/esm/llm/providers/openai/sse.js +28 -44
- package/dist/esm/llm/providers/openai/sse.js.map +1 -1
- package/dist/esm/llm/providers/openai.js +3 -1
- package/dist/esm/llm/providers/openai.js.map +1 -1
- package/dist/esm/llm/providers/shared.js +10 -1
- package/dist/esm/llm/providers/shared.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/help.js +2 -1
- package/dist/esm/run/help.js.map +1 -1
- package/dist/esm/slides/frame-extraction.js +5 -1
- package/dist/esm/slides/frame-extraction.js.map +1 -1
- package/dist/esm/slides/scene-detection.js +19 -3
- package/dist/esm/slides/scene-detection.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/content/asset.d.ts +3 -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/generate-text-shared.d.ts +2 -1
- package/dist/types/llm/github-models.d.ts +2 -0
- package/dist/types/llm/providers/anthropic.d.ts +15 -8
- package/dist/types/llm/providers/models.d.ts +4 -1
- package/dist/types/llm/providers/openai/sse.d.ts +1 -0
- package/dist/types/llm/providers/shared.d.ts +1 -0
- package/dist/types/slides/scene-detection.d.ts +7 -1
- package/dist/types/version.d.ts +1 -1
- package/docs/chrome-extension.md +11 -6
- package/docs/commands/daemon.md +3 -3
- package/docs/commands/summarize.md +1 -1
- package/docs/install.md +1 -1
- package/docs/llm.md +1 -1
- package/package.json +11 -11
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,29 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.20.1 - 2026-06-24
|
|
4
|
+
|
|
5
|
+
### Fixes
|
|
6
|
+
|
|
7
|
+
- Windows daemon: write Scheduled Task XML as BOM-marked UTF-16 so localized systems and non-ASCII user paths register reliably (#316, thanks @Zevan770).
|
|
8
|
+
- File inputs: parse `file:` URLs with Node's platform-aware conversion, including Windows drive and UNC paths (#318, thanks @vincent-peng).
|
|
9
|
+
- LLM summaries: retry transient API and pre-output streaming failures such as HTTP 502 instead of failing immediately.
|
|
10
|
+
- Dependencies: update eligible runtime, test, lint, formatting, and extension tooling releases.
|
|
11
|
+
- Chrome extension: allow Direct and Ollama hover summaries without a daemon token (#317, thanks @vincent-peng).
|
|
12
|
+
- Anthropic custom gateways: request adaptive thinking for synthetic models so Bedrock-compatible proxies accept configured reasoning (#321, thanks @wangwllu).
|
|
13
|
+
|
|
14
|
+
## 0.20.0 - 2026-06-19
|
|
15
|
+
|
|
16
|
+
### Features
|
|
17
|
+
|
|
18
|
+
- 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).
|
|
19
|
+
|
|
20
|
+
### Fixes
|
|
21
|
+
|
|
22
|
+
- Streaming: share EOF-safe, whitespace-preserving SSE parsing across core, CLI providers, and extension clients.
|
|
23
|
+
- Config: preserve standalone `enabled: false` values for cache, media cache, slides, and logging sections.
|
|
24
|
+
- Daemon chat: surface non-streaming provider failures and apply the GitHub Models compatibility fallback to JSON and SSE agent responses.
|
|
25
|
+
- Dependencies: pin patched Vite, tmp, and protobufjs releases to clear known high- and moderate-severity transitive advisories.
|
|
26
|
+
|
|
3
27
|
## 0.19.0 - 2026-06-17
|
|
4
28
|
|
|
5
29
|
### Features
|
|
@@ -46,6 +70,7 @@
|
|
|
46
70
|
- Development CLI: load core workspace TypeScript sources directly for `pnpm summarize` and `pnpm s`, avoiding stale exports and concurrent rebuild races.
|
|
47
71
|
- Network safety: block private IPv4 targets embedded in the IPv4-translatable IPv6 prefix.
|
|
48
72
|
- Slides: ignore invalid zero-index slide markers without hanging while extracting slide references.
|
|
73
|
+
- Slides: support FFmpeg 4 scene detection by falling back to its legacy variable-frame-rate option.
|
|
49
74
|
- Summary length: use `long` as the built-in default across the CLI, daemon, and Chrome extension; explicit and configured lengths remain unchanged.
|
|
50
75
|
- YouTube captions: ignore WebVTT header metadata, cue identifiers, comments, styles, and regions when building transcripts.
|
|
51
76
|
|
package/README.md
CHANGED
|
@@ -41,7 +41,7 @@ YouTube slide screenshots (from the browser):
|
|
|
41
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
42
|
- **npm** (cross-platform): `npm i -g @steipete/summarize`
|
|
43
43
|
- **Homebrew** (Homebrew/core): `brew install summarize`
|
|
44
|
-
- `summarize daemon install --token <TOKEN
|
|
44
|
+
- `summarize daemon install --token <TOKEN> --port 8787`
|
|
45
45
|
|
|
46
46
|
Why a daemon/service?
|
|
47
47
|
|
|
@@ -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:
|
|
@@ -347,7 +348,7 @@ Use `summarize --help` or `summarize help` for the full help text.
|
|
|
347
348
|
- `--model auto`: automatic model selection + fallback (default)
|
|
348
349
|
- `--model <name>`: use a built-in or config-defined preset (see Configuration)
|
|
349
350
|
- `--timeout <duration>`: `30s`, `2m`, `5000ms` (default `2m`)
|
|
350
|
-
- `--retries <count>`: LLM retry attempts
|
|
351
|
+
- `--retries <count>`: LLM retry attempts after timeouts or transient API failures (default `1`)
|
|
351
352
|
- `--length short|medium|long|xl|xxl|s|m|l|<chars>`
|
|
352
353
|
- `--language, --lang <language>`: output language (`auto` = match source)
|
|
353
354
|
- `--max-output-tokens <count>`: hard cap for LLM output tokens
|
|
@@ -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
|
|
@@ -83,7 +83,7 @@ for cmd in summarize summarizer
|
|
|
83
83
|
complete -c $cmd -n '__summarize_no_subcommand' -l max-output-tokens -d 'Hard cap for LLM output tokens' -x
|
|
84
84
|
complete -c $cmd -n '__summarize_no_subcommand' -l force-summary -d 'Force LLM summary even for short content'
|
|
85
85
|
complete -c $cmd -n '__summarize_no_subcommand' -l timeout -d 'Timeout for fetching/LLM' -x
|
|
86
|
-
complete -c $cmd -n '__summarize_no_subcommand' -l retries -d 'LLM
|
|
86
|
+
complete -c $cmd -n '__summarize_no_subcommand' -l retries -d 'LLM retries after timeouts or transient API failures' -x
|
|
87
87
|
|
|
88
88
|
# Model options
|
|
89
89
|
complete -c $cmd -n '__summarize_no_subcommand' -l model -d 'LLM model id' -x
|
|
@@ -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,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IAEF,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,CAAC;AACnC,CAAC"}
|
|
@@ -1,19 +1,12 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { pathToFileURL } 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") {
|