paseo-plugin-genui 0.0.0-stage → 0.1.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/LICENSE +202 -0
- package/OVERVIEW.md +21 -0
- package/README.md +77 -2
- package/assets/fonts/Excalifont-OFL.txt +109 -0
- package/assets/fonts/Excalifont-Regular-latin.woff2 +0 -0
- package/assets/icon.png +0 -0
- package/assets/icon.svg +1 -0
- package/assets/screenshot-chat.png +0 -0
- package/assets/screenshot-gallery.png +0 -0
- package/assets/screenshot-playground.png +0 -0
- package/client/components/content.tsx +468 -0
- package/client/components/data.tsx +967 -0
- package/client/components/dev.tsx +998 -0
- package/client/components/diagram.tsx +513 -0
- package/client/components/inputs.tsx +994 -0
- package/client/components/layout.tsx +239 -0
- package/client/components/media.tsx +428 -0
- package/client/components/project.tsx +641 -0
- package/client/components/widgets.tsx +836 -0
- package/client/gallery.tsx +449 -0
- package/client/live-ui.tsx +525 -0
- package/client/loaders.ts +342 -0
- package/client/markdown.tsx +172 -0
- package/client/node-renderer.tsx +149 -0
- package/client/render.tsx +186 -0
- package/client/runtime.ts +103 -0
- package/client/settings.tsx +57 -0
- package/client/web.ts +186 -0
- package/gallery/Acceptance-baseline.ui +1 -0
- package/gallery/Acceptance-checklist.ui +14 -0
- package/gallery/Acceptance-evidence.ui +9 -0
- package/gallery/Acceptance.ui +1 -0
- package/gallery/Badge.ui +3 -0
- package/gallery/Benchmark-context.ui +8 -0
- package/gallery/Benchmark-hyperfine.ui +1 -0
- package/gallery/Benchmark-runs-list.ui +9 -0
- package/gallery/Benchmark-runs.ui +1 -0
- package/gallery/Benchmark-vitest.ui +1 -0
- package/gallery/Benchmark.ui +9 -0
- package/gallery/Board-bb-tasks.ui +1 -0
- package/gallery/Board-gh-issues.ui +1 -0
- package/gallery/Board-gh-prs.ui +1 -0
- package/gallery/Board.ui +12 -0
- package/gallery/Button-destructive.ui +4 -0
- package/gallery/Button.ui +5 -0
- package/gallery/Calendar.ui +15 -0
- package/gallery/CalendarHeatmap-short.ui +11 -0
- package/gallery/CalendarHeatmap.ui +4 -0
- package/gallery/Callout.ui +4 -0
- package/gallery/Card.ui +4 -0
- package/gallery/Carousel.ui +8 -0
- package/gallery/Changes-paths.ui +1 -0
- package/gallery/Changes-uncommitted.ui +1 -0
- package/gallery/Changes.ui +1 -0
- package/gallery/Chart-area.ui +3 -0
- package/gallery/Chart-funnel.ui +3 -0
- package/gallery/Chart-heatmap.ui +11 -0
- package/gallery/Chart-pie.ui +3 -0
- package/gallery/Chart-radar.ui +3 -0
- package/gallery/Chart-scatter.ui +4 -0
- package/gallery/Chart-stacked.ui +5 -0
- package/gallery/Chart.ui +3 -0
- package/gallery/Checklist.ui +6 -0
- package/gallery/Choice.ui +8 -0
- package/gallery/Code.ui +3 -0
- package/gallery/Commits-limit.ui +1 -0
- package/gallery/Commits.ui +1 -0
- package/gallery/Compare-conditions.ui +4 -0
- package/gallery/Compare-three.ui +7 -0
- package/gallery/Compare.ui +4 -0
- package/gallery/Coverage-go.ui +1 -0
- package/gallery/Coverage-lcov.ui +1 -0
- package/gallery/Coverage-python.ui +1 -0
- package/gallery/Coverage.ui +1 -0
- package/gallery/DateInput.ui +5 -0
- package/gallery/Decision-percent.ui +10 -0
- package/gallery/Decision.ui +12 -0
- package/gallery/Dependencies-audit.ui +1 -0
- package/gallery/Dependencies-both.ui +1 -0
- package/gallery/Dependencies-list.ui +7 -0
- package/gallery/Dependencies-pip.ui +1 -0
- package/gallery/Dependencies-pnpm.ui +1 -0
- package/gallery/Dependencies.ui +1 -0
- package/gallery/Details.ui +4 -0
- package/gallery/Diagram-flow.ui +16 -0
- package/gallery/Diagram-sequence.ui +15 -0
- package/gallery/Diagram.ui +16 -0
- package/gallery/Diff.ui +3 -0
- package/gallery/Divider.ui +5 -0
- package/gallery/EditableTable.ui +9 -0
- package/gallery/Entity-list.ui +6 -0
- package/gallery/Entity.ui +8 -0
- package/gallery/Environments.ui +1 -0
- package/gallery/Estimate-points.ui +6 -0
- package/gallery/Estimate.ui +8 -0
- package/gallery/File.ui +4 -0
- package/gallery/Findings-biome.ui +1 -0
- package/gallery/Findings-eslint.ui +1 -0
- package/gallery/Findings-oxlint.ui +1 -0
- package/gallery/Findings-review.ui +1 -0
- package/gallery/Findings-ruff.ui +1 -0
- package/gallery/Findings-sarif.ui +1 -0
- package/gallery/Findings-ship.ui +11 -0
- package/gallery/Findings-tsc.ui +1 -0
- package/gallery/Findings.ui +7 -0
- package/gallery/Flashcards.ui +3 -0
- package/gallery/FollowUps.ui +4 -0
- package/gallery/Form.ui +8 -0
- package/gallery/Gallery-links.ui +8 -0
- package/gallery/Gallery-strip.ui +14 -0
- package/gallery/Gallery.ui +10 -0
- package/gallery/Gauge.ui +7 -0
- package/gallery/Grid.ui +8 -0
- package/gallery/Hotspots-photo.ui +8 -0
- package/gallery/Hotspots.ui +11 -0
- package/gallery/Icon.ui +5 -0
- package/gallery/Image.ui +4 -0
- package/gallery/ImageSearch-aspects.ui +6 -0
- package/gallery/ImageSearch.ui +4 -0
- package/gallery/Input.ui +5 -0
- package/gallery/Json-api.ui +1 -0
- package/gallery/Json.ui +8 -0
- package/gallery/KeyValue.ui +3 -0
- package/gallery/List-dots.ui +8 -0
- package/gallery/List.ui +8 -0
- package/gallery/ListEditor.ui +5 -0
- package/gallery/Logs-jsonl.ui +1 -0
- package/gallery/Logs-lines.ui +11 -0
- package/gallery/Logs-python.ui +1 -0
- package/gallery/Logs.ui +1 -0
- package/gallery/Map-city.ui +8 -0
- package/gallery/Map.ui +8 -0
- package/gallery/Metric.ui +3 -0
- package/gallery/OptionCards-multi.ui +10 -0
- package/gallery/OptionCards.ui +10 -0
- package/gallery/Pipeline-checks.ui +1 -0
- package/gallery/Pipeline-passed.ui +1 -0
- package/gallery/Pipeline-running.ui +1 -0
- package/gallery/Pipeline-stages.ui +13 -0
- package/gallery/Pipeline.ui +1 -0
- package/gallery/Plan.ui +9 -0
- package/gallery/Progress.ui +4 -0
- package/gallery/Provenance-deploy.ui +6 -0
- package/gallery/Provenance-no-receipt.ui +1 -0
- package/gallery/Provenance.ui +1 -0
- package/gallery/PullRequest.ui +1 -0
- package/gallery/Quiz.ui +6 -0
- package/gallery/Radio.ui +5 -0
- package/gallery/Rating.ui +5 -0
- package/gallery/Roadmap-sprint.ui +8 -0
- package/gallery/Roadmap-year.ui +9 -0
- package/gallery/Roadmap.ui +12 -0
- package/gallery/Row.ui +3 -0
- package/gallery/SegmentedBar-status.ui +8 -0
- package/gallery/SegmentedBar.ui +8 -0
- package/gallery/Select.ui +5 -0
- package/gallery/Slider.ui +7 -0
- package/gallery/Snippet.ui +3 -0
- package/gallery/Sources-chips.ui +4 -0
- package/gallery/Sources.ui +8 -0
- package/gallery/Sparkline.ui +6 -0
- package/gallery/Stack.ui +7 -0
- package/gallery/StackTrace-aggregate.ui +1 -0
- package/gallery/StackTrace-browser.ui +1 -0
- package/gallery/StackTrace-go.ui +1 -0
- package/gallery/StackTrace-java.ui +1 -0
- package/gallery/StackTrace-python.ui +1 -0
- package/gallery/StackTrace-rust.ui +1 -0
- package/gallery/StackTrace.ui +1 -0
- package/gallery/Status.ui +9 -0
- package/gallery/Stepper.ui +5 -0
- package/gallery/Steps.ui +8 -0
- package/gallery/Swatches-long-names.ui +4 -0
- package/gallery/Swatches-picker.ui +5 -0
- package/gallery/Swatches.ui +10 -0
- package/gallery/Table.ui +7 -0
- package/gallery/Tabs.ui +8 -0
- package/gallery/Tests-junit.ui +1 -0
- package/gallery/Tests-vitest-junit.ui +1 -0
- package/gallery/Tests-vitest.ui +1 -0
- package/gallery/Tests.ui +9 -0
- package/gallery/Text.ui +4 -0
- package/gallery/TextArea.ui +5 -0
- package/gallery/Threads-ids.ui +1 -0
- package/gallery/Threads.ui +1 -0
- package/gallery/Timeline.ui +8 -0
- package/gallery/Timer.ui +4 -0
- package/gallery/Toggle.ui +5 -0
- package/gallery/Transcript-text.ui +1 -0
- package/gallery/Transcript-untimed.ui +1 -0
- package/gallery/Transcript-whisper.ui +1 -0
- package/gallery/Transcript.ui +1 -0
- package/gallery/Tree.ui +3 -0
- package/gallery/Treemap-du.ui +1 -0
- package/gallery/Treemap-esbuild.ui +1 -0
- package/gallery/Treemap-tree.ui +7 -0
- package/gallery/Treemap.ui +18 -0
- package/gallery/Walkthrough.ui +9 -0
- package/gallery/Waterfall-har.ui +1 -0
- package/gallery/Waterfall-trace.ui +1 -0
- package/gallery/Waterfall.ui +11 -0
- package/gallery/data/acceptance/coil/viewport-lifecycle.json +25 -0
- package/gallery/data/acceptance/coil-gate.json +153 -0
- package/gallery/data/acceptance/orbit-baseline.json +163 -0
- package/gallery/data/acceptance/shots/gate-cell-opened.png +0 -0
- package/gallery/data/acceptance/shots/gate-light.png +0 -0
- package/gallery/data/acceptance/shots/gate-phone-dark.png +0 -0
- package/gallery/data/activity.json +1 -0
- package/gallery/data/bb-tasks-orb.json +420 -0
- package/gallery/data/biome.json +229 -0
- package/gallery/data/compare/status-after.png +0 -0
- package/gallery/data/compare/status-before.png +0 -0
- package/gallery/data/compare/status-dark-2x.png +0 -0
- package/gallery/data/compare/status-rerender.png +0 -0
- package/gallery/data/coverage-py.json +1 -0
- package/gallery/data/coverage-summary.json +1 -0
- package/gallery/data/coverage.out +23 -0
- package/gallery/data/deploys.json +1 -0
- package/gallery/data/device-runs.json +285 -0
- package/gallery/data/du-node-modules.txt +359 -0
- package/gallery/data/esbuild-meta.json +292 -0
- package/gallery/data/eslint.json +266 -0
- package/gallery/data/eslint.sarif +343 -0
- package/gallery/data/findings-review.json +76 -0
- package/gallery/data/gh-issues-nextjs.json +293 -0
- package/gallery/data/gh-pr-checks.json +272 -0
- package/gallery/data/gh-prs-nextjs.json +419 -0
- package/gallery/data/gh-run-failed.json +1 -0
- package/gallery/data/gh-run-passed.json +1 -0
- package/gallery/data/gh-run-running.json +1 -0
- package/gallery/data/github-release.json +57 -0
- package/gallery/data/hyperfine-startup.json +187 -0
- package/gallery/data/lcov.info +234 -0
- package/gallery/data/logs/media-sync.log +127 -0
- package/gallery/data/logs/thumbnailer.jsonl +17 -0
- package/gallery/data/logs/vitest-run.log +89 -0
- package/gallery/data/npm-audit.json +672 -0
- package/gallery/data/npm-outdated.json +179 -0
- package/gallery/data/oxlint.json +156 -0
- package/gallery/data/pip-outdated.json +68 -0
- package/gallery/data/pnpm-outdated.json +58 -0
- package/gallery/data/provenance/devicectl-install.json +35 -0
- package/gallery/data/provenance/install-timeout.log +4 -0
- package/gallery/data/provenance/iphone-install.json +72 -0
- package/gallery/data/provenance/iphone-no-receipt.json +57 -0
- package/gallery/data/provenance/live-home.jpg +0 -0
- package/gallery/data/provenance/live-probe.txt +10 -0
- package/gallery/data/provenance/xcodebuild-2811.log +19 -0
- package/gallery/data/provenance/xcodebuild-4712.log +19 -0
- package/gallery/data/pytest-junit.xml +64 -0
- package/gallery/data/python-org-trace.json +35 -0
- package/gallery/data/python-org.har +31 -0
- package/gallery/data/retry.ts +13 -0
- package/gallery/data/ruff.json +261 -0
- package/gallery/data/src/durations.py +63 -0
- package/gallery/data/src/json-logic.ts +156 -0
- package/gallery/data/src/mapMath.ts +135 -0
- package/gallery/data/src/semver/bump.go +73 -0
- package/gallery/data/traces/browser-error.json +5 -0
- package/gallery/data/traces/go/main.go +27 -0
- package/gallery/data/traces/go-panic.txt +16 -0
- package/gallery/data/traces/java-caused-by.txt +15 -0
- package/gallery/data/traces/node-aggregate.txt +30 -0
- package/gallery/data/traces/node-cause.txt +21 -0
- package/gallery/data/traces/py/deploy.json +5 -0
- package/gallery/data/traces/py/deploy.py +17 -0
- package/gallery/data/traces/py/settings.py +19 -0
- package/gallery/data/traces/python-chain.txt +30 -0
- package/gallery/data/traces/rust/main.rs +11 -0
- package/gallery/data/traces/rust-panic.txt +16 -0
- package/gallery/data/traces/shop/cart.mjs +19 -0
- package/gallery/data/traces/shop/pricing.mjs +12 -0
- package/gallery/data/traces/shop/status.mjs +9 -0
- package/gallery/data/traces/web/app.js +11 -0
- package/gallery/data/traces/web/index.html +1 -0
- package/gallery/data/traces/web/search.js +10 -0
- package/gallery/data/transcript/call-noisy.wav +0 -0
- package/gallery/data/transcript/call.json +362 -0
- package/gallery/data/transcript/call.wav +0 -0
- package/gallery/data/transcript/mlx-whisper-tiny.en-noisy.json +1 -0
- package/gallery/data/transcript/whisper-cpp-base.en-noisy.json +658 -0
- package/gallery/data/transcript/whisper-cpp-base.en.json +658 -0
- package/gallery/data/transcript/whisper-cpp-base.en.srt +16 -0
- package/gallery/data/transcript/whisper-cpp-tiny.en-noisy.json +619 -0
- package/gallery/data/tsc.txt +4 -0
- package/gallery/data/vitest-bench.json +119 -0
- package/gallery/data/vitest-junit.xml +133 -0
- package/gallery/data/vitest-report.json +612 -0
- package/gallery/images/bell.svg +10 -0
- package/gallery/images/bike.svg +47 -0
- package/gallery/images/footer-planet.webp +0 -0
- package/gallery/images/front-light.svg +13 -0
- package/gallery/images/golden-hour.webp +0 -0
- package/gallery/images/option-flowers.webp +0 -0
- package/gallery/images/option-hilltop.webp +0 -0
- package/gallery/images/option-meadow.webp +0 -0
- package/gallery/images/option-sky.webp +0 -0
- package/gallery/images/u-lock.svg +10 -0
- package/index.client.tsx +164 -0
- package/index.server.ts +216 -0
- package/package.json +50 -4
- package/paseo-plugin.json +14 -0
- package/server/data-source.ts +407 -0
- package/server/project.ts +981 -0
- package/server/web/address.ts +57 -0
- package/server/web/cache.ts +85 -0
- package/server/web/commons.ts +126 -0
- package/server/web/geocode.ts +40 -0
- package/server/web/image.ts +35 -0
- package/server/web/lookups.ts +248 -0
- package/server/web/net.ts +210 -0
- package/shared/core/acceptance.ts +744 -0
- package/shared/core/ast.ts +76 -0
- package/shared/core/benchmark.ts +743 -0
- package/shared/core/catalog.ts +733 -0
- package/shared/core/compare.ts +225 -0
- package/shared/core/coverage.ts +456 -0
- package/shared/core/data.ts +334 -0
- package/shared/core/decisions.ts +527 -0
- package/shared/core/dependencies.ts +604 -0
- package/shared/core/diagnostics.ts +24 -0
- package/shared/core/environments.ts +212 -0
- package/shared/core/evaluate.ts +737 -0
- package/shared/core/fields.ts +66 -0
- package/shared/core/findings.ts +1172 -0
- package/shared/core/form.ts +69 -0
- package/shared/core/index.ts +44 -0
- package/shared/core/junit.ts +252 -0
- package/shared/core/lexer.ts +275 -0
- package/shared/core/logs.ts +496 -0
- package/shared/core/markdown.ts +2374 -0
- package/shared/core/parser.ts +355 -0
- package/shared/core/perf-units.ts +228 -0
- package/shared/core/pipeline.ts +679 -0
- package/shared/core/project.ts +472 -0
- package/shared/core/provenance.ts +725 -0
- package/shared/core/stack-trace.ts +718 -0
- package/shared/core/streaming.ts +136 -0
- package/shared/core/test-results.ts +562 -0
- package/shared/core/thread-activity.ts +203 -0
- package/shared/core/tracking.ts +887 -0
- package/shared/core/transcript.ts +1364 -0
- package/shared/core/treemap.ts +446 -0
- package/shared/core/types.ts +70 -0
- package/shared/core/validate.ts +574 -0
- package/shared/core/waterfall.ts +536 -0
- package/shared/diagram/flowchart.ts +205 -0
- package/shared/diagram/layout.ts +440 -0
- package/shared/diagram/markdown.ts +135 -0
- package/shared/diagram/sequence.ts +122 -0
- package/shared/diagram/zoom.ts +114 -0
- package/shared/fallback.ts +120 -0
- package/shared/genui.test.ts +122 -0
- package/shared/instructions.ts +144 -0
- package/shared/logic/calendarMath.ts +130 -0
- package/shared/logic/chartMath.ts +289 -0
- package/shared/logic/choose-logic.ts +196 -0
- package/shared/logic/compare-logic.ts +270 -0
- package/shared/logic/content-model.ts +227 -0
- package/shared/logic/environments-logic.ts +53 -0
- package/shared/logic/explain-logic.ts +315 -0
- package/shared/logic/fieldLogic.ts +138 -0
- package/shared/logic/gallery-search.ts +71 -0
- package/shared/logic/icons.ts +322 -0
- package/shared/logic/json-logic.ts +153 -0
- package/shared/logic/mapMath.ts +133 -0
- package/shared/logic/project-logic.ts +39 -0
- package/shared/logic/references-model.ts +201 -0
- package/shared/logic/sketch.ts +165 -0
- package/shared/logic/supersession.ts +77 -0
- package/shared/logic/values.ts +133 -0
- package/shared/logic/widget-logic.ts +163 -0
- package/shared/rpc.ts +252 -0
- package/shared/segment.ts +81 -0
- package/shared/settings.ts +12 -0
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
// What a Threads row says a thread is doing beyond its status: its latest
|
|
2
|
+
// assistant message, the question or approval it waits on, and the workers
|
|
3
|
+
// (running subthreads) an idle parent waits for. The backend (project/source.ts)
|
|
4
|
+
// maps BB's answers through these; the renderer and the markdown fallback read
|
|
5
|
+
// the results. Pure: nothing here talks to BB.
|
|
6
|
+
import { threadStatusLabel, type ThreadInfo } from "./project";
|
|
7
|
+
|
|
8
|
+
/** Most characters of a latest message the backend keeps (the row expands to them; the thread has the rest). */
|
|
9
|
+
export const MESSAGE_CHARS = 2_000;
|
|
10
|
+
|
|
11
|
+
/** Most characters of a preview, a question, a command or a plan excerpt. */
|
|
12
|
+
const PREVIEW_CHARS = 400;
|
|
13
|
+
|
|
14
|
+
/** Most answer options a pending question lists. */
|
|
15
|
+
const MAX_OPTIONS = 6;
|
|
16
|
+
|
|
17
|
+
/** A thread's latest assistant message, as markdown, cut to MESSAGE_CHARS. */
|
|
18
|
+
export interface LastMessage {
|
|
19
|
+
readonly text: string;
|
|
20
|
+
/** The message went on past `text`. */
|
|
21
|
+
readonly truncated: boolean;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** What a thread waits on the user for. */
|
|
25
|
+
export interface PendingAsk {
|
|
26
|
+
/** question: the agent asks something; approval: a command, edit, permission or tool; plan: a plan to approve; request: a form. */
|
|
27
|
+
readonly kind: "question" | "approval" | "plan" | "request";
|
|
28
|
+
/** What the user is asked to do, in a few words: "Answer a question", "Approve running a command". */
|
|
29
|
+
readonly action: string;
|
|
30
|
+
/** The question, the command, the plan's start, the request's detail; null when BB gives nothing more. */
|
|
31
|
+
readonly text: string | null;
|
|
32
|
+
/** `text` is a command (shown as code). */
|
|
33
|
+
readonly code: boolean;
|
|
34
|
+
/** Labels of a question's answer options, first MAX_OPTIONS. */
|
|
35
|
+
readonly options: readonly string[];
|
|
36
|
+
/** Further questions in the same interaction, or further pending interactions. */
|
|
37
|
+
readonly more: number;
|
|
38
|
+
/** Epoch ms BB recorded the interaction. */
|
|
39
|
+
readonly since: number;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** The latest message as kept: trimmed, cut at a word boundary, an open code fence closed. Null for none. */
|
|
43
|
+
export function lastMessage(output: string | null | undefined): LastMessage | null {
|
|
44
|
+
if (typeof output !== "string") return null;
|
|
45
|
+
const trimmed = output.trim();
|
|
46
|
+
if (trimmed === "") return null;
|
|
47
|
+
if (trimmed.length <= MESSAGE_CHARS) return { text: trimmed, truncated: false };
|
|
48
|
+
const cut = trimmed.slice(0, MESSAGE_CHARS);
|
|
49
|
+
const space = Math.max(cut.lastIndexOf(" "), cut.lastIndexOf("\n"));
|
|
50
|
+
let text = (space > MESSAGE_CHARS * 0.8 ? cut.slice(0, space) : cut).trimEnd();
|
|
51
|
+
if ((text.match(/^\s*(?:```|~~~)/gm) ?? []).length % 2 === 1) text += "\n```";
|
|
52
|
+
return { text, truncated: true };
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* A message's markdown as one line of plain text for a two-line preview:
|
|
57
|
+
* code blocks, link targets, images, emphasis, heading and list markers,
|
|
58
|
+
* table pipes and HTML tags dropped; whitespace collapsed.
|
|
59
|
+
*/
|
|
60
|
+
export function previewText(markdown: string): string {
|
|
61
|
+
const text = markdown
|
|
62
|
+
.replace(/^\s*(```|~~~)[^\n]*\n[\s\S]*?(?:^\s*\1\s*$|(?![\s\S]))/gm, " ")
|
|
63
|
+
.replace(/!\[[^\]]*\]\([^)]*\)/g, " ")
|
|
64
|
+
.replace(/\[([^\]]*)\]\([^)]*\)/g, "$1")
|
|
65
|
+
.replace(/<\/?[a-z][^>]*>/gi, " ")
|
|
66
|
+
.replace(/^\s{0,3}(?:#{1,6}\s+|>\s?|[-*+]\s+\[[ xX]\]\s+|[-*+]\s+|\d+[.)]\s+)/gm, "")
|
|
67
|
+
.replace(/^\s*\|?\s*:?-{3,}:?\s*(?:\|\s*:?-{3,}:?\s*)*\|?\s*$/gm, " ")
|
|
68
|
+
.replace(/^\s*(?:-{3,}|\*{3,}|_{3,})\s*$/gm, " ")
|
|
69
|
+
.replace(/\|/g, " ")
|
|
70
|
+
.replace(/(\*\*|__)(.+?)\1/g, "$2")
|
|
71
|
+
.replace(/(^|[^\w*])[*_]([^*_\n]+)[*_](?![\w*])/g, "$1$2")
|
|
72
|
+
.replace(/~~(.+?)~~/g, "$1")
|
|
73
|
+
.replace(/`+([^`]*)`+/g, "$1")
|
|
74
|
+
.replace(/\s+/g, " ")
|
|
75
|
+
.trim();
|
|
76
|
+
return clip(text, PREVIEW_CHARS);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function clip(text: string, max: number): string {
|
|
80
|
+
return text.length <= max ? text : `${text.slice(0, max - 1).trimEnd()}…`;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function record(value: unknown): Record<string, unknown> | null {
|
|
84
|
+
return typeof value === "object" && value !== null && !Array.isArray(value) ? (value as Record<string, unknown>) : null;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function text(value: unknown): string | null {
|
|
88
|
+
return typeof value === "string" && value.trim() !== "" ? value.trim() : null;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function list(value: unknown): readonly unknown[] {
|
|
92
|
+
return Array.isArray(value) ? value : [];
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/** Paths a permission asks to read or write, and network access, in a few words. */
|
|
96
|
+
function permissionSummary(permissions: Record<string, unknown> | null): string | null {
|
|
97
|
+
const files = record(permissions?.fileSystem);
|
|
98
|
+
const write = list(files?.write).filter((path): path is string => typeof path === "string");
|
|
99
|
+
const read = list(files?.read).filter((path): path is string => typeof path === "string");
|
|
100
|
+
const network = record(permissions?.network)?.enabled === true;
|
|
101
|
+
const parts = [
|
|
102
|
+
write.length > 0 ? `write ${write.join(", ")}` : "",
|
|
103
|
+
read.length > 0 ? `read ${read.join(", ")}` : "",
|
|
104
|
+
network ? "network access" : "",
|
|
105
|
+
].filter((part) => part !== "");
|
|
106
|
+
return parts.length === 0 ? null : clip(parts.join(" · "), PREVIEW_CHARS);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function ask(kind: PendingAsk["kind"], action: string, body: string | null, since: number, extra: Partial<PendingAsk> = {}): PendingAsk {
|
|
110
|
+
return { kind, action, text: body === null ? null : clip(body, PREVIEW_CHARS), code: false, options: [], more: 0, since, ...extra };
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/** One BB interaction (threads.interactions.list entry) as the user's task, or null for a shape it doesn't know. */
|
|
114
|
+
function interactionAsk(interaction: Record<string, unknown>): PendingAsk | null {
|
|
115
|
+
const payload = record(interaction.payload);
|
|
116
|
+
if (payload === null) return null;
|
|
117
|
+
const since = typeof interaction.createdAt === "number" ? interaction.createdAt : 0;
|
|
118
|
+
switch (payload.kind) {
|
|
119
|
+
case "user_question": {
|
|
120
|
+
const questions = list(payload.questions).map(record).filter((question) => question !== null);
|
|
121
|
+
const first = questions[0];
|
|
122
|
+
if (first === undefined) return ask("question", "Answer a question", null, since);
|
|
123
|
+
const options = list(first.options)
|
|
124
|
+
.map((option) => text(record(option)?.label))
|
|
125
|
+
.filter((label): label is string => label !== null);
|
|
126
|
+
return ask("question", questions.length > 1 ? `Answer ${questions.length} questions` : "Answer a question", text(first.prompt) ?? text(first.shortLabel), since, {
|
|
127
|
+
options: options.slice(0, MAX_OPTIONS),
|
|
128
|
+
more: questions.length - 1,
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
case "approval": {
|
|
132
|
+
const subject = record(payload.subject);
|
|
133
|
+
const reason = text(payload.reason);
|
|
134
|
+
switch (subject?.kind) {
|
|
135
|
+
case "command": {
|
|
136
|
+
const command = text(subject.command);
|
|
137
|
+
return ask("approval", "Approve running a command", command, since, { code: command !== null });
|
|
138
|
+
}
|
|
139
|
+
case "file_change": {
|
|
140
|
+
const scope = text(subject.writeScope);
|
|
141
|
+
return ask("approval", "Approve file changes", scope === null ? reason : `In ${scope}`, since);
|
|
142
|
+
}
|
|
143
|
+
case "permission_grant":
|
|
144
|
+
return ask("approval", "Grant a permission", permissionSummary(record(subject.permissions)) ?? reason, since);
|
|
145
|
+
case "plan":
|
|
146
|
+
return ask("plan", "Approve a plan", text(subject.plan) === null ? null : previewText(String(subject.plan)), since);
|
|
147
|
+
case "tool_use": {
|
|
148
|
+
const presentation = record(subject.presentation);
|
|
149
|
+
const tool = text(subject.tool);
|
|
150
|
+
const shown = text(presentation?.title) ?? text(record(presentation?.label)?.pending) ?? text(presentation?.detail) ?? reason;
|
|
151
|
+
return ask("approval", tool === null ? "Approve a tool" : `Approve using ${tool}`, shown, since);
|
|
152
|
+
}
|
|
153
|
+
default:
|
|
154
|
+
return ask("approval", "Approve an action", reason, since);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
default: {
|
|
158
|
+
// A plugin's form (e.g. the secrets plugin: "Add secrets", "Requesting MAIL_API_KEY"), or a provider's own request kind (`vendor/kind`).
|
|
159
|
+
const presentation = record(payload.presentation);
|
|
160
|
+
const pendingLabel = text(record(presentation?.label)?.pending);
|
|
161
|
+
return ask("request", text(payload.title) ?? text(presentation?.title) ?? "Respond to a request", text(presentation?.detail) ?? pendingLabel, since);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* What the thread waits on the user for, from BB's interaction list: the
|
|
168
|
+
* oldest still-pending interaction it can describe (the one blocking the
|
|
169
|
+
* turn), with how many others are pending too. Null when nothing is pending.
|
|
170
|
+
*/
|
|
171
|
+
export function pendingAsk(interactions: unknown): PendingAsk | null {
|
|
172
|
+
const pending = list(interactions)
|
|
173
|
+
.map(record)
|
|
174
|
+
.filter((interaction): interaction is Record<string, unknown> => interaction !== null && interaction.status === "pending")
|
|
175
|
+
.sort((a, b) => (Number(a.createdAt) || 0) - (Number(b.createdAt) || 0));
|
|
176
|
+
for (const interaction of pending) {
|
|
177
|
+
const found = interactionAsk(interaction);
|
|
178
|
+
if (found !== null) return { ...found, more: found.more + pending.length - 1 };
|
|
179
|
+
}
|
|
180
|
+
return null;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/** How many running threads each parent has, from the running threads' parents (null: a root thread). */
|
|
184
|
+
export function workersByParent(parents: readonly (string | null)[]): Map<string, number> {
|
|
185
|
+
const counts = new Map<string, number>();
|
|
186
|
+
for (const parent of parents) if (parent !== null) counts.set(parent, (counts.get(parent) ?? 0) + 1);
|
|
187
|
+
return counts;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/** "1 running worker", "3 running workers". */
|
|
191
|
+
export function workersLabel(count: number): string {
|
|
192
|
+
return `${count} running worker${count === 1 ? "" : "s"}`;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/** An idle thread whose subthreads still run is waiting on them, not done. */
|
|
196
|
+
export function waitsOnWorkers(thread: Pick<ThreadInfo, "status" | "needsInput" | "archived" | "runningWorkers">): boolean {
|
|
197
|
+
return thread.status === "idle" && !thread.needsInput && !thread.archived && thread.runningWorkers > 0;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/** The status a Threads row shows: "Waiting on 2 running workers" for an idle parent of running workers, else BB's status. */
|
|
201
|
+
export function threadActivityLabel(thread: Pick<ThreadInfo, "status" | "needsInput" | "archived" | "runningWorkers">): string {
|
|
202
|
+
return waitsOnWorkers(thread) ? `Waiting on ${workersLabel(thread.runningWorkers)}` : threadStatusLabel(thread);
|
|
203
|
+
}
|