fnloom 0.1.0 → 0.2.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/README.md +31 -18
- package/package.json +2 -7
- package/packages/build/package.json +1 -1
- package/packages/cli/package.json +1 -1
- package/packages/cli/src/commands/available.ts +63 -22
- package/packages/cli/src/commands/install.ts +86 -28
- package/packages/cli/src/index.ts +3 -2
- package/packages/cli/src/local.ts +6 -0
- package/packages/cli/src/premade.ts +80 -0
- package/packages/core/package.json +1 -1
- package/packages/hub/package.json +1 -1
- package/packages/hub/src/link/process.ts +6 -1
- package/packages/sdk/package.json +1 -1
- package/packages/web/package.json +1 -1
- package/premade/claude.zip +0 -0
- package/premade/database.zip +0 -0
- package/premade/web.zip +0 -0
- package/scripts/dev-env.ts +4 -4
- package/scripts/stack.ts +42 -27
- package/scripts/start.ts +26 -16
- package/systems/api/package.json +1 -1
- package/systems/code/package.json +1 -1
- package/systems/embedder/package.json +1 -1
- package/systems/fs/package.json +1 -1
- package/systems/google-calendar/package.json +1 -1
- package/systems/input/package.json +1 -1
- package/systems/mcp/package.json +1 -1
- package/systems/ollama/package.json +1 -1
- package/systems/schedule/package.json +1 -1
- package/systems/template/package.json +1 -1
- package/systems/widgets/package.json +1 -1
- package/systems/claude/client/FleetPage.vue +0 -132
- package/systems/claude/client/NewSessionForm.vue +0 -62
- package/systems/claude/client/SessionList.vue +0 -64
- package/systems/claude/client/SessionPage.vue +0 -199
- package/systems/claude/client/TaskList.vue +0 -61
- package/systems/claude/client/fakes.ts +0 -186
- package/systems/claude/client/host.ts +0 -23
- package/systems/claude/client/index.ts +0 -15
- package/systems/claude/client/logic.ts +0 -270
- package/systems/claude/client/state.ts +0 -344
- package/systems/claude/package.json +0 -23
- package/systems/claude/server/agent-sdk.ts +0 -379
- package/systems/claude/server/driver.ts +0 -153
- package/systems/claude/server/env.ts +0 -64
- package/systems/claude/server/fake-driver.ts +0 -112
- package/systems/claude/server/fleet.ts +0 -376
- package/systems/claude/server/impl.ts +0 -568
- package/systems/claude/server/index.ts +0 -8
- package/systems/claude/server/main.ts +0 -38
- package/systems/claude/server/preview.ts +0 -76
- package/systems/claude/server/questions.ts +0 -117
- package/systems/claude/server/transcript.ts +0 -83
- package/systems/claude/shared/index.ts +0 -262
- package/systems/claude/shared/session.ts +0 -284
- package/systems/claude/shared/shapes.ts +0 -106
- package/systems/claude/system.json +0 -18
- package/systems/claude/tsconfig.json +0 -6
- package/systems/database/package.json +0 -25
- package/systems/database/server/author.ts +0 -41
- package/systems/database/server/authoring.ts +0 -322
- package/systems/database/server/catalog.ts +0 -117
- package/systems/database/server/compile.ts +0 -332
- package/systems/database/server/dialects.ts +0 -17
- package/systems/database/server/drivers/database.ts +0 -71
- package/systems/database/server/drivers/index.ts +0 -23
- package/systems/database/server/drivers/postgres.ts +0 -157
- package/systems/database/server/drivers/sqlite.ts +0 -151
- package/systems/database/server/drivers/sqlserver.ts +0 -176
- package/systems/database/server/env.ts +0 -35
- package/systems/database/server/fixture.ts +0 -169
- package/systems/database/server/impl.ts +0 -793
- package/systems/database/server/index.ts +0 -7
- package/systems/database/server/instance.ts +0 -398
- package/systems/database/server/main.ts +0 -47
- package/systems/database/server/pick.ts +0 -97
- package/systems/database/server/queries.ts +0 -390
- package/systems/database/server/results.ts +0 -39
- package/systems/database/server/schema.ts +0 -59
- package/systems/database/server/table-fns.ts +0 -237
- package/systems/database/server/types.ts +0 -253
- package/systems/database/shared/index.ts +0 -544
- package/systems/database/shared/shapes.ts +0 -413
- package/systems/database/system.json +0 -14
- package/systems/database/tsconfig.json +0 -6
- package/systems/web/client/ReadView.vue +0 -110
- package/systems/web/client/SearchView.vue +0 -215
- package/systems/web/client/StatusChip.vue +0 -38
- package/systems/web/client/fakes.ts +0 -48
- package/systems/web/client/index.ts +0 -15
- package/systems/web/client/view.ts +0 -131
- package/systems/web/package.json +0 -22
- package/systems/web/server/chrome.ts +0 -121
- package/systems/web/server/crawl.ts +0 -333
- package/systems/web/server/env.ts +0 -63
- package/systems/web/server/guard.ts +0 -60
- package/systems/web/server/http.ts +0 -89
- package/systems/web/server/impl.ts +0 -203
- package/systems/web/server/index.ts +0 -71
- package/systems/web/server/loader.ts +0 -104
- package/systems/web/server/main.ts +0 -70
- package/systems/web/server/mentions.ts +0 -111
- package/systems/web/server/problem.ts +0 -72
- package/systems/web/server/renderer.ts +0 -243
- package/systems/web/server/robots.ts +0 -75
- package/systems/web/server/searches.ts +0 -29
- package/systems/web/server/tavily.ts +0 -144
- package/systems/web/server/testing.ts +0 -165
- package/systems/web/server/uploads.ts +0 -33
- package/systems/web/shared/index.ts +0 -343
- package/systems/web/shared/urls.ts +0 -60
- package/systems/web/system.json +0 -15
- package/systems/web/tsconfig.json +0 -6
|
@@ -1,215 +0,0 @@
|
|
|
1
|
-
<script setup lang="ts">
|
|
2
|
-
/**
|
|
3
|
-
* The web search card: the query and its filters, a live status chip, Tavily's short answer, and the results (title,
|
|
4
|
-
* site, date, snippet), each opening the page in a new tab or starting a `web/read` of it ("Read", whose own card
|
|
5
|
-
* follows in the chat). Placeholder rows shimmer while the search runs; long snippets clamp until expanded.
|
|
6
|
-
*/
|
|
7
|
-
import type { FnViewOf } from '@harness/sdk';
|
|
8
|
-
import StatusChip from './StatusChip.vue';
|
|
9
|
-
import { computed, ref } from 'vue';
|
|
10
|
-
import type { web } from '../shared/index.ts';
|
|
11
|
-
import { resultRows, statusChip, useStarts } from './view.ts';
|
|
12
|
-
|
|
13
|
-
const view = defineProps<FnViewOf<typeof web, 'search'>>();
|
|
14
|
-
|
|
15
|
-
/** Results drawn before "Show all". */
|
|
16
|
-
const FIRST = 5;
|
|
17
|
-
|
|
18
|
-
const chip = computed(() => statusChip(view.status, view.error));
|
|
19
|
-
const running = computed(() => view.status === 'running' || view.status === 'queued');
|
|
20
|
-
const rows = computed(() => resultRows(view.result?.results ?? [], navigator.language));
|
|
21
|
-
const all = ref(false);
|
|
22
|
-
const shown = computed(() => (all.value ? rows.value : rows.value.slice(0, FIRST)));
|
|
23
|
-
const opened = ref(new Set<string>());
|
|
24
|
-
const filters = computed(() => [
|
|
25
|
-
...(view.args.topic === 'news' ? ['News'] : []),
|
|
26
|
-
...(view.args.depth === 'advanced' ? ['Deep'] : []),
|
|
27
|
-
...(view.args.days === undefined ? [] : [`Last ${view.args.days} ${view.args.days === 1 ? 'day' : 'days'}`]),
|
|
28
|
-
...(view.args.include ?? []).map((domain) => `Only ${domain}`),
|
|
29
|
-
...(view.args.exclude ?? []).map((domain) => `Not ${domain}`),
|
|
30
|
-
]);
|
|
31
|
-
const starts = useStarts();
|
|
32
|
-
|
|
33
|
-
function toggle(key: string): void {
|
|
34
|
-
const next = new Set(opened.value);
|
|
35
|
-
if (next.has(key)) { next.delete(key); } else { next.add(key); }
|
|
36
|
-
opened.value = next;
|
|
37
|
-
}
|
|
38
|
-
/** Why the Read of a result couldn't start, if it couldn't. */
|
|
39
|
-
function problemOf(url: string): string | undefined {
|
|
40
|
-
const state = starts.states[url];
|
|
41
|
-
return state?.phase === 'failed' ? state.message : undefined;
|
|
42
|
-
}
|
|
43
|
-
function read(url: string): void {
|
|
44
|
-
starts.start(url, () => view.system.run.read({ url }));
|
|
45
|
-
}
|
|
46
|
-
</script>
|
|
47
|
-
|
|
48
|
-
<template>
|
|
49
|
-
<article class="search" :data-tone="chip.tone" :aria-busy="running">
|
|
50
|
-
<header class="head">
|
|
51
|
-
<svg class="icon" viewBox="0 0 16 16" aria-hidden="true"><circle cx="7" cy="7" r="4.5" /><path d="m10.5 10.5 3.5 3.5" /></svg>
|
|
52
|
-
<h3 class="query" :title="view.args.query">{{ view.args.query }}</h3>
|
|
53
|
-
<StatusChip :chip="chip" />
|
|
54
|
-
</header>
|
|
55
|
-
<ul v-if="filters.length > 0" class="filters" aria-label="Filters">
|
|
56
|
-
<li v-for="filter in filters" :key="filter" class="filter">{{ filter }}</li>
|
|
57
|
-
</ul>
|
|
58
|
-
|
|
59
|
-
<div v-if="running && !view.result" class="placeholder" aria-hidden="true">
|
|
60
|
-
<div v-for="n in 3" :key="n" class="ghost"><span class="line wide" /><span class="line" /></div>
|
|
61
|
-
</div>
|
|
62
|
-
|
|
63
|
-
<p v-if="view.result?.answer" class="answer"><span class="label">Answer</span>{{ view.result.answer }}</p>
|
|
64
|
-
|
|
65
|
-
<ol v-if="shown.length > 0" class="results">
|
|
66
|
-
<li v-for="row in shown" :key="row.key" class="result">
|
|
67
|
-
<div class="site">
|
|
68
|
-
<span class="badge" aria-hidden="true">{{ row.domain.charAt(0).toUpperCase() }}</span>
|
|
69
|
-
<span class="domain" :title="row.shown">{{ row.shown }}</span>
|
|
70
|
-
<span v-if="row.published" class="date">{{ row.published }}</span>
|
|
71
|
-
</div>
|
|
72
|
-
<a v-if="row.href" class="title" :href="row.href" target="_blank" rel="noopener noreferrer">{{ row.title }}</a>
|
|
73
|
-
<span v-else class="title">{{ row.title }}</span>
|
|
74
|
-
<p
|
|
75
|
-
v-if="row.snippet" class="snippet" :class="{ open: opened.has(row.key) }"
|
|
76
|
-
role="button" tabindex="0" :aria-expanded="opened.has(row.key)"
|
|
77
|
-
@click="toggle(row.key)" @keydown.enter.prevent="toggle(row.key)" @keydown.space.prevent="toggle(row.key)"
|
|
78
|
-
>
|
|
79
|
-
{{ row.snippet }}
|
|
80
|
-
</p>
|
|
81
|
-
<div class="actions">
|
|
82
|
-
<button
|
|
83
|
-
type="button" class="action"
|
|
84
|
-
:disabled="!view.system.online || starts.states[row.url]?.phase === 'starting'"
|
|
85
|
-
@click="read(row.url)"
|
|
86
|
-
>
|
|
87
|
-
<svg viewBox="0 0 16 16" aria-hidden="true"><path d="M2.5 3.5h4a2 2 0 0 1 2 2v7a1.5 1.5 0 0 0-1.5-1.5h-4.5zM13.5 3.5h-4a2 2 0 0 0-1 .3M13.5 3.5V11H9" /></svg>
|
|
88
|
-
{{ starts.states[row.url]?.phase === 'starting' ? 'Starting…' : 'Read' }}
|
|
89
|
-
</button>
|
|
90
|
-
<a v-if="row.href" class="action" :href="row.href" target="_blank" rel="noopener noreferrer">
|
|
91
|
-
<svg viewBox="0 0 16 16" aria-hidden="true"><path d="M9 2.5h4.5V7M13.5 2.5 7.5 8.5M11.5 9.5v3a1 1 0 0 1-1 1h-7a1 1 0 0 1-1-1v-7a1 1 0 0 1 1-1h3" /></svg>
|
|
92
|
-
Open
|
|
93
|
-
</a>
|
|
94
|
-
<span v-if="starts.states[row.url]?.phase === 'started'" class="note started" role="status">Reading below</span>
|
|
95
|
-
<span v-else-if="problemOf(row.url)" class="note problem" role="alert">{{ problemOf(row.url) }}</span>
|
|
96
|
-
</div>
|
|
97
|
-
</li>
|
|
98
|
-
</ol>
|
|
99
|
-
<p v-else-if="view.result" class="empty">No results. Try other words, or fewer filters.</p>
|
|
100
|
-
|
|
101
|
-
<button v-if="rows.length > FIRST" type="button" class="more" @click="all = !all">
|
|
102
|
-
{{ all ? 'Show fewer' : `Show all ${rows.length} results` }}
|
|
103
|
-
</button>
|
|
104
|
-
<p v-if="!view.system.online && view.result" class="note">web is offline; Read works once it reconnects</p>
|
|
105
|
-
<p v-if="view.error" class="problem" role="alert">{{ view.error.message }}</p>
|
|
106
|
-
</article>
|
|
107
|
-
</template>
|
|
108
|
-
|
|
109
|
-
<style scoped>
|
|
110
|
-
.search {
|
|
111
|
-
display: grid;
|
|
112
|
-
gap: var(--space-3);
|
|
113
|
-
min-width: 0;
|
|
114
|
-
padding: var(--space-3);
|
|
115
|
-
border: 1px solid var(--border);
|
|
116
|
-
border-radius: var(--radius);
|
|
117
|
-
background: var(--surface);
|
|
118
|
-
transition: border-color var(--slow) var(--ease);
|
|
119
|
-
}
|
|
120
|
-
.search[data-tone='busy'] { border-color: color-mix(in oklab, var(--accent) 45%, var(--border)); }
|
|
121
|
-
.search[data-tone='bad'] { border-color: color-mix(in oklab, var(--danger) 35%, var(--border)); }
|
|
122
|
-
.head { display: flex; align-items: center; gap: var(--space-2); min-width: 0; }
|
|
123
|
-
.icon { flex: none; width: 16px; height: 16px; fill: none; stroke: var(--accent); stroke-width: 1.6; stroke-linecap: round; }
|
|
124
|
-
.query { flex: 1 1 auto; min-width: 0; margin: 0; font-size: var(--text-sm); font-weight: var(--weight-strong); line-height: 1.4; overflow-wrap: anywhere; }
|
|
125
|
-
.filters { display: flex; flex-wrap: wrap; gap: var(--space-1); margin: 0; padding: 0; list-style: none; }
|
|
126
|
-
.filter { padding: 1px var(--space-2); border: 1px solid var(--border); border-radius: var(--radius-full); color: var(--text-dim); font-size: var(--text-xs); }
|
|
127
|
-
.answer {
|
|
128
|
-
display: grid;
|
|
129
|
-
gap: var(--space-1);
|
|
130
|
-
margin: 0;
|
|
131
|
-
padding: var(--space-2) var(--space-3);
|
|
132
|
-
border-left: 3px solid var(--accent);
|
|
133
|
-
border-radius: var(--radius-sm);
|
|
134
|
-
background: var(--accent-soft);
|
|
135
|
-
font-size: var(--text-sm);
|
|
136
|
-
line-height: 1.5;
|
|
137
|
-
}
|
|
138
|
-
.label { color: var(--accent); font-size: var(--text-xs); font-weight: var(--weight-strong); text-transform: uppercase; letter-spacing: 0.04em; }
|
|
139
|
-
.results { display: grid; gap: var(--space-3); margin: 0; padding: 0; list-style: none; }
|
|
140
|
-
.result { display: grid; gap: var(--space-1); min-width: 0; animation: rise var(--slow) var(--ease) both; }
|
|
141
|
-
.site { display: flex; align-items: center; gap: var(--space-2); min-width: 0; color: var(--text-dim); font-size: var(--text-xs); }
|
|
142
|
-
.badge {
|
|
143
|
-
flex: none;
|
|
144
|
-
display: grid;
|
|
145
|
-
place-items: center;
|
|
146
|
-
width: 18px;
|
|
147
|
-
height: 18px;
|
|
148
|
-
border-radius: 50%;
|
|
149
|
-
background: var(--surface-2);
|
|
150
|
-
color: var(--text-dim);
|
|
151
|
-
font-size: 10px;
|
|
152
|
-
font-weight: var(--weight-strong);
|
|
153
|
-
}
|
|
154
|
-
.domain { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
155
|
-
.date { flex: none; }
|
|
156
|
-
.date::before { content: '·'; margin-right: var(--space-2); }
|
|
157
|
-
.title { color: var(--accent); font-size: var(--text-md, var(--text-sm)); font-weight: var(--weight-strong); line-height: 1.35; text-decoration: none; overflow-wrap: anywhere; }
|
|
158
|
-
.title:hover { text-decoration: underline; }
|
|
159
|
-
.title:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 2px; }
|
|
160
|
-
.snippet {
|
|
161
|
-
margin: 0;
|
|
162
|
-
color: var(--text);
|
|
163
|
-
font-size: var(--text-sm);
|
|
164
|
-
line-height: 1.5;
|
|
165
|
-
overflow-wrap: anywhere;
|
|
166
|
-
display: -webkit-box;
|
|
167
|
-
-webkit-line-clamp: 3;
|
|
168
|
-
-webkit-box-orient: vertical;
|
|
169
|
-
overflow: hidden;
|
|
170
|
-
cursor: pointer;
|
|
171
|
-
}
|
|
172
|
-
.snippet.open { display: block; }
|
|
173
|
-
.snippet:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 2px; }
|
|
174
|
-
.actions { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); }
|
|
175
|
-
.action {
|
|
176
|
-
display: inline-flex;
|
|
177
|
-
align-items: center;
|
|
178
|
-
gap: var(--space-1);
|
|
179
|
-
min-height: var(--control-sm);
|
|
180
|
-
padding: 0 var(--space-3);
|
|
181
|
-
border: 1px solid var(--border);
|
|
182
|
-
border-radius: var(--radius-sm);
|
|
183
|
-
background: var(--surface);
|
|
184
|
-
color: var(--text);
|
|
185
|
-
font-size: var(--text-sm);
|
|
186
|
-
text-decoration: none;
|
|
187
|
-
cursor: pointer;
|
|
188
|
-
transition: background var(--fast) var(--ease), transform var(--fast) var(--ease);
|
|
189
|
-
}
|
|
190
|
-
.action:hover:not(:disabled) { background: var(--surface-2); }
|
|
191
|
-
.action:active:not(:disabled) { transform: scale(0.97); }
|
|
192
|
-
.action:disabled { opacity: 0.5; cursor: default; }
|
|
193
|
-
.action svg { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }
|
|
194
|
-
.placeholder { display: grid; gap: var(--space-3); }
|
|
195
|
-
.ghost { display: grid; gap: var(--space-1); }
|
|
196
|
-
.line { display: block; height: 10px; width: 60%; border-radius: 5px; background: linear-gradient(90deg, var(--surface-2), var(--border), var(--surface-2)); background-size: 200% 100%; animation: flow 1.4s linear infinite; }
|
|
197
|
-
.line.wide { width: 85%; }
|
|
198
|
-
.more {
|
|
199
|
-
justify-self: start;
|
|
200
|
-
padding: 0;
|
|
201
|
-
border: 0;
|
|
202
|
-
background: none;
|
|
203
|
-
color: var(--accent);
|
|
204
|
-
font-size: var(--text-sm);
|
|
205
|
-
cursor: pointer;
|
|
206
|
-
}
|
|
207
|
-
.empty, .note { margin: 0; color: var(--text-dim); font-size: var(--text-xs); }
|
|
208
|
-
.note.started { color: var(--ok); animation: rise var(--slow) var(--ease); }
|
|
209
|
-
.problem { margin: 0; color: var(--danger); font-size: var(--text-sm); }
|
|
210
|
-
@keyframes flow { to { background-position: -200% 0; } }
|
|
211
|
-
@keyframes rise { from { opacity: 0; transform: translateY(4px); } }
|
|
212
|
-
@media (prefers-reduced-motion: reduce) {
|
|
213
|
-
.line, .result, .note.started { animation: none; }
|
|
214
|
-
}
|
|
215
|
-
</style>
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
<script setup lang="ts">
|
|
2
|
-
/**
|
|
3
|
-
* A run's status chip on the web cards: a short label with a dot, coloured by its tone, the dot pulsing while the run
|
|
4
|
-
* is busy. The search card and the page card both draw it.
|
|
5
|
-
*/
|
|
6
|
-
import type { Chip } from './view.ts';
|
|
7
|
-
|
|
8
|
-
defineProps<{ chip: Chip }>();
|
|
9
|
-
</script>
|
|
10
|
-
|
|
11
|
-
<template>
|
|
12
|
-
<span class="chip" :class="chip.tone" role="status"><span class="dot" aria-hidden="true" />{{ chip.label }}</span>
|
|
13
|
-
</template>
|
|
14
|
-
|
|
15
|
-
<style scoped>
|
|
16
|
-
.chip {
|
|
17
|
-
flex: none;
|
|
18
|
-
display: inline-flex;
|
|
19
|
-
align-items: center;
|
|
20
|
-
gap: var(--space-1);
|
|
21
|
-
padding: 2px var(--space-2);
|
|
22
|
-
border-radius: var(--radius-full);
|
|
23
|
-
font-size: var(--text-xs);
|
|
24
|
-
line-height: 18px;
|
|
25
|
-
white-space: nowrap;
|
|
26
|
-
background: var(--surface-2);
|
|
27
|
-
color: var(--text-dim);
|
|
28
|
-
}
|
|
29
|
-
.dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
|
|
30
|
-
.chip.busy { color: var(--accent); background: var(--accent-soft); }
|
|
31
|
-
.chip.busy .dot { animation: pulse 1.2s var(--ease) infinite; }
|
|
32
|
-
.chip.ok { color: var(--ok); background: var(--ok-soft); }
|
|
33
|
-
.chip.bad { color: var(--danger); background: var(--danger-soft); }
|
|
34
|
-
@keyframes pulse { 50% { opacity: 0.35; transform: scale(0.8); } }
|
|
35
|
-
@media (prefers-reduced-motion: reduce) {
|
|
36
|
-
.chip.busy .dot { animation: none; }
|
|
37
|
-
}
|
|
38
|
-
</style>
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* A stand-in for the chat's system client, for the renderer tests: `run.<fn>` records what it was asked to start and
|
|
3
|
-
* waits until the test starts or refuses it, so every state of "Read" can be shown and checked. The web system
|
|
4
|
-
* declares no actions, so `send` is empty.
|
|
5
|
-
*/
|
|
6
|
-
import { mintId, type RunId } from '@harness/core';
|
|
7
|
-
import type { SystemClient } from '@harness/sdk';
|
|
8
|
-
import type { WebContract } from '../shared/index.ts';
|
|
9
|
-
|
|
10
|
-
/** A run the fake was asked to start. */
|
|
11
|
-
export interface StartedRun {
|
|
12
|
-
readonly fn: keyof WebContract['defs']['fns'];
|
|
13
|
-
readonly args: unknown;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
/** A fake web system client and the handles to drive it. */
|
|
17
|
-
export interface FakeWebSystem {
|
|
18
|
-
readonly system: SystemClient<WebContract['defs']>;
|
|
19
|
-
readonly started: StartedRun[];
|
|
20
|
-
/** Start the latest run asked for; returns its id. */
|
|
21
|
-
start(): RunId;
|
|
22
|
-
/** Refuse the latest run asked for. */
|
|
23
|
-
refuse(message: string): void;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
/** Make a fake web system client. */
|
|
27
|
-
export function fakeWebSystem(online = true): FakeWebSystem {
|
|
28
|
-
const started: StartedRun[] = [];
|
|
29
|
-
let pending: { resolve: (run: RunId) => void; reject: (error: Error) => void } | undefined;
|
|
30
|
-
const ask = (fn: StartedRun['fn']) => (args: unknown): Promise<RunId> => {
|
|
31
|
-
started.push({ fn, args });
|
|
32
|
-
return new Promise<RunId>((resolve, reject) => { pending = { resolve, reject }; });
|
|
33
|
-
};
|
|
34
|
-
return {
|
|
35
|
-
system: { online, send: {}, run: { search: ask('search'), read: ask('read'), crawl: ask('crawl'), fetch_raw: ask('fetch_raw') } },
|
|
36
|
-
started,
|
|
37
|
-
start: () => {
|
|
38
|
-
const run = mintId('run');
|
|
39
|
-
pending?.resolve(run);
|
|
40
|
-
pending = undefined;
|
|
41
|
-
return run;
|
|
42
|
-
},
|
|
43
|
-
refuse: (message) => {
|
|
44
|
-
pending?.reject(new Error(message));
|
|
45
|
-
pending = undefined;
|
|
46
|
-
},
|
|
47
|
-
};
|
|
48
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The web system's client renderers, typed by the contract: the search results card and the page card. The chat
|
|
3
|
-
* loads this module from the hub and provides the runtime behind each renderer's `system`.
|
|
4
|
-
*/
|
|
5
|
-
// typescript-eslint can't see the types of .vue modules from .ts files (as for packages/web/src/main.ts); vue-tsc
|
|
6
|
-
// checks this file, so the renderers' props are still checked against the contract
|
|
7
|
-
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
|
|
8
|
-
import { client } from '@harness/sdk';
|
|
9
|
-
import { web } from '../shared/index.ts';
|
|
10
|
-
import ReadView from './ReadView.vue';
|
|
11
|
-
import SearchView from './SearchView.vue';
|
|
12
|
-
|
|
13
|
-
export default client(web, {
|
|
14
|
-
fns: { search: SearchView, read: ReadView },
|
|
15
|
-
});
|
|
@@ -1,131 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* What the web cards show, worked out from their views so the components only draw: status chips, result rows, the
|
|
3
|
-
* page card's facts, and "Read" from a search result, which starts a `web/read` run (its own card follows in the
|
|
4
|
-
* chat). Browser-safe; state lives here, not in the components.
|
|
5
|
-
*/
|
|
6
|
-
import { RUN_STATUS_WORDS, type FnError, type RunId, type RunStatus } from '@harness/core';
|
|
7
|
-
import { safeHref } from '@harness/sdk';
|
|
8
|
-
import { reactive } from 'vue';
|
|
9
|
-
import type { ReadResultValue, SearchHitValue } from '../shared/index.ts';
|
|
10
|
-
import { domainOf, labelOf, redactUrl } from '../shared/urls.ts';
|
|
11
|
-
|
|
12
|
-
/** The tone of a status chip. */
|
|
13
|
-
export type Tone = 'busy' | 'ok' | 'bad' | 'quiet';
|
|
14
|
-
|
|
15
|
-
/** A status chip: a short label and its tone. */
|
|
16
|
-
export interface Chip {
|
|
17
|
-
readonly label: string;
|
|
18
|
-
readonly tone: Tone;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
/** The chip for a run: its status in core's words. Every status is handled, so a new one fails to compile until it is. */
|
|
22
|
-
export function statusChip(status: RunStatus, error: FnError | undefined): Chip {
|
|
23
|
-
const label = RUN_STATUS_WORDS[status];
|
|
24
|
-
switch (status) {
|
|
25
|
-
case 'running': return { label, tone: 'busy' };
|
|
26
|
-
case 'awaiting-approval': case 'queued': case 'waiting': case 'paused': case 'invalid-input': case 'cancelled': case 'undone': return { label, tone: 'quiet' };
|
|
27
|
-
case 'failed': return { label: error?.code === 'timeout' ? 'Timed out' : label, tone: 'bad' };
|
|
28
|
-
case 'done': return { label, tone: 'ok' };
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/** One result row, ready to draw. */
|
|
33
|
-
export interface ResultRow {
|
|
34
|
-
readonly key: string;
|
|
35
|
-
readonly title: string;
|
|
36
|
-
readonly url: string;
|
|
37
|
-
/** Where its links go, when the URL is safe to open (`safeHref`); else it shows as plain text. */
|
|
38
|
-
readonly href: string | undefined;
|
|
39
|
-
readonly domain: string;
|
|
40
|
-
/** The address shown under the title, credentials redacted and the scheme dropped. */
|
|
41
|
-
readonly shown: string;
|
|
42
|
-
readonly snippet: string;
|
|
43
|
-
readonly published: string | undefined;
|
|
44
|
-
/** The match score as a whole percentage. */
|
|
45
|
-
readonly score: number;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
/** The address as a reader sees it: no scheme, no trailing slash, credentials redacted. */
|
|
49
|
-
export function shownUrl(url: string): string {
|
|
50
|
-
return redactUrl(url).replace(/^https?:\/\//, '').replace(/\/$/, '');
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
/** A published date as the person's locale writes it, or the source's own words when they aren't a date. */
|
|
54
|
-
export function publishedLabel(published: string | undefined, locale?: string): string | undefined {
|
|
55
|
-
if (published === undefined) { return undefined; }
|
|
56
|
-
const time = Date.parse(published);
|
|
57
|
-
if (Number.isNaN(time)) { return published; }
|
|
58
|
-
// a bare date is a calendar day, not midnight UTC, so it is shown as that day wherever the reader is
|
|
59
|
-
const dayOnly = /^\d{4}-\d{2}-\d{2}$/.test(published.trim());
|
|
60
|
-
return new Intl.DateTimeFormat(locale, { dateStyle: 'medium', ...(dayOnly ? { timeZone: 'UTC' } : {}) }).format(time);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
/** The rows of a search's results, in order. */
|
|
64
|
-
export function resultRows(results: readonly SearchHitValue[], locale?: string): ResultRow[] {
|
|
65
|
-
return results.map((hit, index) => ({
|
|
66
|
-
key: `${index}:${hit.url}`,
|
|
67
|
-
title: hit.title,
|
|
68
|
-
url: hit.url,
|
|
69
|
-
href: safeHref(hit.url),
|
|
70
|
-
domain: domainOf(hit.url),
|
|
71
|
-
shown: shownUrl(hit.url),
|
|
72
|
-
snippet: hit.snippet,
|
|
73
|
-
published: publishedLabel(hit.published, locale),
|
|
74
|
-
score: Math.round(Math.min(1, Math.max(0, hit.score)) * 100),
|
|
75
|
-
}));
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
/** What the page card says about a read page. */
|
|
79
|
-
export interface PageFacts {
|
|
80
|
-
readonly title: string;
|
|
81
|
-
readonly domain: string;
|
|
82
|
-
readonly shown: string;
|
|
83
|
-
/** Where the page link goes, when the address is safe to open (`safeHref`); else it shows as plain text. */
|
|
84
|
-
readonly href: string | undefined;
|
|
85
|
-
/** The page ended up somewhere other than asked. */
|
|
86
|
-
readonly moved: boolean;
|
|
87
|
-
readonly rendered: boolean;
|
|
88
|
-
readonly truncated: boolean;
|
|
89
|
-
readonly chars: number;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
/** The page card's facts for a read (or, before it finishes, for the URL asked for). */
|
|
93
|
-
export function pageFacts(asked: string, result: ReadResultValue | undefined): PageFacts {
|
|
94
|
-
const at = result?.finalUrl ?? asked;
|
|
95
|
-
const parses = URL.canParse(at);
|
|
96
|
-
return {
|
|
97
|
-
title: result?.title ?? (parses ? labelOf(at) : at),
|
|
98
|
-
domain: parses ? domainOf(at) : at,
|
|
99
|
-
shown: parses ? shownUrl(at) : at,
|
|
100
|
-
href: safeHref(at),
|
|
101
|
-
moved: result !== undefined && URL.canParse(asked) && new URL(asked).href !== new URL(result.finalUrl).href,
|
|
102
|
-
rendered: result?.rendered ?? false,
|
|
103
|
-
truncated: result?.truncated ?? false,
|
|
104
|
-
chars: result?.text.length ?? 0,
|
|
105
|
-
};
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
/** A start of a `web/read` from a card: in flight, started, or refused. */
|
|
109
|
-
export type StartState = { readonly phase: 'starting' } | { readonly phase: 'started'; readonly run: RunId } | { readonly phase: 'failed'; readonly message: string };
|
|
110
|
-
|
|
111
|
-
/** Starts per key (a result's URL), one in flight per key. */
|
|
112
|
-
export interface Starts {
|
|
113
|
-
/** Each key's state, reactive. */
|
|
114
|
-
readonly states: Readonly<Record<string, StartState>>;
|
|
115
|
-
start(key: string, run: () => Promise<RunId>): void;
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
/** Make the starts a card uses. */
|
|
119
|
-
export function useStarts(): Starts {
|
|
120
|
-
const states = reactive<Record<string, StartState>>({});
|
|
121
|
-
return {
|
|
122
|
-
states,
|
|
123
|
-
start(key, run) {
|
|
124
|
-
if (states[key]?.phase === 'starting') { return; }
|
|
125
|
-
states[key] = { phase: 'starting' };
|
|
126
|
-
run()
|
|
127
|
-
.then((id) => { states[key] = { phase: 'started', run: id }; })
|
|
128
|
-
.catch((problem: unknown) => { states[key] = { phase: 'failed', message: problem instanceof Error ? problem.message : 'It could not start.' }; });
|
|
129
|
-
},
|
|
130
|
-
};
|
|
131
|
-
}
|
package/systems/web/package.json
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"dependencies": {
|
|
3
|
-
"@aeye/resources": "^0.10.1",
|
|
4
|
-
"@ayepi/env": "^0.6.0",
|
|
5
|
-
"@harness/core": "*",
|
|
6
|
-
"@harness/sdk": "*",
|
|
7
|
-
"puppeteer": "^25.16.0",
|
|
8
|
-
"vue": "^3.5.22",
|
|
9
|
-
"zod": "^4.6.7"
|
|
10
|
-
},
|
|
11
|
-
"name": "@harness/system-web",
|
|
12
|
-
"private": true,
|
|
13
|
-
"version": "0.1.0",
|
|
14
|
-
"license": "Apache-2.0",
|
|
15
|
-
"type": "module",
|
|
16
|
-
"description": "Development only: system.json holds this system's name, version and entries.",
|
|
17
|
-
"exports": {
|
|
18
|
-
".": "./shared/index.ts",
|
|
19
|
-
"./server": "./server/index.ts",
|
|
20
|
-
"./client": "./client/index.ts"
|
|
21
|
-
}
|
|
22
|
-
}
|
|
@@ -1,121 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The real headless browser: puppeteer's Chrome behind `HeadlessBrowser`. Each tab is a page in its own incognito
|
|
3
|
-
* browser context, with request interception on so `TabLoad.allow` decides every request the page makes. What
|
|
4
|
-
* interception doesn't see is held too: the context's every connection goes through the tab's proxy (loopback
|
|
5
|
-
* included), WebSockets are blocked outright, service workers are bypassed, and WebRTC sends nothing outside the proxy.
|
|
6
|
-
*/
|
|
7
|
-
import puppeteer, { type Browser, type BrowserContext, type BrowserContextOptions, type HTTPRequest, type Page } from 'puppeteer';
|
|
8
|
-
import type { BrowserTab, HeadlessBrowser, LaunchBrowser, LoadedTab, TabLoad, TabNetwork } from './renderer.ts';
|
|
9
|
-
|
|
10
|
-
/** Chrome's launch flags: no GPU, extensions or background requests, and WebRTC kept to the proxy (no UDP of its own). */
|
|
11
|
-
export const CHROME_ARGS: readonly string[] = [
|
|
12
|
-
'--disable-gpu', '--no-first-run', '--no-default-browser-check', '--mute-audio', '--disable-extensions',
|
|
13
|
-
'--disable-background-networking', '--force-webrtc-ip-handling-policy=disable_non_proxied_udp',
|
|
14
|
-
];
|
|
15
|
-
|
|
16
|
-
/** What a tab's network is blocked from outright (WebSocket handshakes skip request interception). */
|
|
17
|
-
export const BLOCKED_URL_PATTERNS: readonly string[] = ['ws://*:*/*', 'wss://*:*/*'];
|
|
18
|
-
|
|
19
|
-
/** The same, in the older wildcard form, for a Chrome (`WEB_CHROME`) that doesn't know `urlPatterns` yet. */
|
|
20
|
-
export const BLOCKED_URLS: readonly string[] = ['ws://*', 'wss://*'];
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* A tab's private context: every connection through its proxy. `<-loopback>` takes away Chrome's own exception for
|
|
24
|
-
* localhost, so a page can't reach this machine around the proxy.
|
|
25
|
-
*/
|
|
26
|
-
export function contextOptions(network: TabNetwork): BrowserContextOptions {
|
|
27
|
-
return { proxyServer: network.proxy, proxyBypassList: ['<-loopback>'] };
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
/** How many requests may still be in flight for the network to count as quiet. */
|
|
31
|
-
const IDLE_CONNECTIONS = 2;
|
|
32
|
-
/** How long the network must stay that quiet. */
|
|
33
|
-
const IDLE_TIME = 500;
|
|
34
|
-
|
|
35
|
-
/** True for puppeteer's timeout errors, which a quiet-network wait may end with. */
|
|
36
|
-
function isTimeoutError(error: unknown): boolean {
|
|
37
|
-
return error instanceof Error && error.name === 'TimeoutError';
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/** A tab in its own browser context. */
|
|
41
|
-
class ChromeTab implements BrowserTab {
|
|
42
|
-
readonly #context: BrowserContext;
|
|
43
|
-
readonly #page: Page;
|
|
44
|
-
#closed = false;
|
|
45
|
-
|
|
46
|
-
constructor(context: BrowserContext, page: Page) {
|
|
47
|
-
this.#context = context;
|
|
48
|
-
this.#page = page;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
async load(request: TabLoad): Promise<LoadedTab> {
|
|
52
|
-
const page = this.#page;
|
|
53
|
-
await page.setUserAgent({ userAgent: request.userAgent });
|
|
54
|
-
// what request interception never sees: service workers' own fetches and WebSocket handshakes
|
|
55
|
-
await page.setBypassServiceWorker(true);
|
|
56
|
-
const cdp = await page.createCDPSession();
|
|
57
|
-
await cdp.send('Network.enable');
|
|
58
|
-
await cdp.send('Network.setBlockedURLs', { urlPatterns: BLOCKED_URL_PATTERNS.map((urlPattern) => ({ urlPattern, block: true })) })
|
|
59
|
-
.catch(() => cdp.send('Network.setBlockedURLs', { urls: [...BLOCKED_URLS] }));
|
|
60
|
-
if (Object.keys(request.headers).length > 0) { await page.setExtraHTTPHeaders({ ...request.headers }); }
|
|
61
|
-
await page.setRequestInterception(true);
|
|
62
|
-
page.on('request', (intercepted: HTTPRequest) => {
|
|
63
|
-
void request.allow(intercepted.url(), intercepted.resourceType()).then(
|
|
64
|
-
(allowed) => {
|
|
65
|
-
if (intercepted.isInterceptResolutionHandled()) { return undefined; }
|
|
66
|
-
return allowed ? intercepted.continue() : intercepted.abort('blockedbyclient');
|
|
67
|
-
},
|
|
68
|
-
).catch(() => undefined);
|
|
69
|
-
});
|
|
70
|
-
await page.goto(request.url, { waitUntil: 'domcontentloaded', timeout: request.timeout });
|
|
71
|
-
if (request.idle > 0) {
|
|
72
|
-
try {
|
|
73
|
-
await page.waitForNetworkIdle({ idleTime: IDLE_TIME, concurrency: IDLE_CONNECTIONS, timeout: request.idle });
|
|
74
|
-
} catch (error) {
|
|
75
|
-
// a page that never goes quiet (polling, analytics) is taken as it is when the wait runs out
|
|
76
|
-
if (!isTimeoutError(error)) { throw error; }
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
return { html: await page.content(), url: page.url() };
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
async close(): Promise<void> {
|
|
83
|
-
if (this.#closed) { return; }
|
|
84
|
-
this.#closed = true;
|
|
85
|
-
await this.#context.close().catch(() => undefined);
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
/** Puppeteer's browser as a `HeadlessBrowser`. */
|
|
90
|
-
class ChromeBrowser implements HeadlessBrowser {
|
|
91
|
-
readonly #browser: Browser;
|
|
92
|
-
|
|
93
|
-
constructor(browser: Browser) {
|
|
94
|
-
this.#browser = browser;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
get connected(): boolean { return this.#browser.connected; }
|
|
98
|
-
|
|
99
|
-
async open(network: TabNetwork): Promise<BrowserTab> {
|
|
100
|
-
const context = await this.#browser.createBrowserContext(contextOptions(network));
|
|
101
|
-
try {
|
|
102
|
-
return new ChromeTab(context, await context.newPage());
|
|
103
|
-
} catch (error) {
|
|
104
|
-
await context.close().catch(() => undefined);
|
|
105
|
-
throw error;
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
async close(): Promise<void> {
|
|
110
|
-
await this.#browser.close().catch(() => undefined);
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
/** Launches puppeteer's headless Chrome (or the one at `executablePath`). */
|
|
115
|
-
export function launchChrome(options: { executablePath?: string | undefined } = {}): LaunchBrowser {
|
|
116
|
-
return async () => new ChromeBrowser(await puppeteer.launch({
|
|
117
|
-
headless: true,
|
|
118
|
-
...(options.executablePath === undefined ? {} : { executablePath: options.executablePath }),
|
|
119
|
-
args: [...CHROME_ARGS],
|
|
120
|
-
}));
|
|
121
|
-
}
|