@yaks/browse 0.0.0-stage → 0.2.36
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/README.md +324 -2
- package/_dist/app.d.ts +8 -0
- package/_dist/app.d.ts.map +1 -0
- package/_dist/cli.d.ts +16 -0
- package/_dist/cli.d.ts.map +1 -0
- package/_dist/hosting.d.ts +24 -0
- package/_dist/hosting.d.ts.map +1 -0
- package/_dist/mod.d.ts +7 -0
- package/_dist/mod.d.ts.map +1 -0
- package/_dist/types.d.ts +5 -0
- package/_dist/types.d.ts.map +1 -0
- package/_dist/url.d.ts +2 -0
- package/_dist/url.d.ts.map +1 -0
- package/app.js +10 -0
- package/app.js.map +1 -0
- package/app.ts +10 -0
- package/browser-links.js +22 -0
- package/browser-links.js.map +1 -0
- package/browser-links.ts +28 -0
- package/cli.js +172 -0
- package/cli.js.map +1 -0
- package/cli.ts +168 -0
- package/client.js +748 -0
- package/client.js.map +1 -0
- package/client.ts +734 -0
- package/clipboard.js +18 -0
- package/clipboard.js.map +1 -0
- package/clipboard.ts +17 -0
- package/commands.js +1157 -0
- package/commands.js.map +1 -0
- package/commands.ts +1108 -0
- package/components/Ansi.tsx +160 -0
- package/components/App.tsx +446 -0
- package/components/Canvas.tsx +625 -0
- package/components/Card.tsx +276 -0
- package/components/Chat.tsx +205 -0
- package/components/Configuration.tsx +218 -0
- package/components/Decision.tsx +49 -0
- package/components/Dot.tsx +52 -0
- package/components/Entity.tsx +609 -0
- package/components/Fault.tsx +43 -0
- package/components/Filter.tsx +103 -0
- package/components/Keybindings.tsx +100 -0
- package/components/Keys.tsx +67 -0
- package/components/Markdown.tsx +90 -0
- package/components/Navigation.tsx +161 -0
- package/components/New.tsx +490 -0
- package/components/Peek.tsx +168 -0
- package/components/Prio.tsx +20 -0
- package/components/Run.tsx +263 -0
- package/components/Search.tsx +280 -0
- package/components/Stamp.tsx +44 -0
- package/components/Status.tsx +514 -0
- package/components/Sync.tsx +173 -0
- package/components/Tile.tsx +50 -0
- package/components/answered.js +23 -0
- package/components/answered.js.map +1 -0
- package/components/answered.ts +25 -0
- package/components/comp.js +11 -0
- package/components/comp.js.map +1 -0
- package/components/comp.ts +10 -0
- package/components/drag.js +173 -0
- package/components/drag.js.map +1 -0
- package/components/drag.ts +198 -0
- package/components/fields.tsx +90 -0
- package/components/fixtures/README.md +10 -0
- package/components/fixtures/archetypes.json +3646 -0
- package/components/hits.js +63 -0
- package/components/hits.js.map +1 -0
- package/components/hits.ts +84 -0
- package/components/icons.tsx +177 -0
- package/components/inspect.tsx +331 -0
- package/components/mount.ts +79 -0
- package/components/nav.tsx +479 -0
- package/components/offers.js +26 -0
- package/components/offers.js.map +1 -0
- package/components/offers.ts +54 -0
- package/components/page.js +21 -0
- package/components/page.js.map +1 -0
- package/components/page.ts +18 -0
- package/components/read.js +5 -0
- package/components/read.js.map +1 -0
- package/components/read.ts +7 -0
- package/components/registry.js +285 -0
- package/components/registry.js.map +1 -0
- package/components/registry.ts +317 -0
- package/components/session_status.tsx +115 -0
- package/components/subscriptions.js +149 -0
- package/components/subscriptions.js.map +1 -0
- package/components/subscriptions.ts +161 -0
- package/components/title.tsx +21 -0
- package/components/useQuery.js +166 -0
- package/components/useQuery.js.map +1 -0
- package/components/useQuery.ts +211 -0
- package/components/views/Board.tsx +450 -0
- package/components/views/BoardTile.tsx +65 -0
- package/components/views/Dashboard.tsx +148 -0
- package/components/views/Debug.tsx +445 -0
- package/components/views/Dependency.tsx +51 -0
- package/components/views/Entry.tsx +500 -0
- package/components/views/Gist.tsx +28 -0
- package/components/views/Inline.tsx +54 -0
- package/components/views/Json.tsx +19 -0
- package/components/views/Layout.tsx +211 -0
- package/components/views/List.tsx +238 -0
- package/components/views/Md.tsx +43 -0
- package/components/views/Media.tsx +48 -0
- package/components/views/Memory.tsx +32 -0
- package/components/views/Relate.tsx +205 -0
- package/components/views/Search.tsx +42 -0
- package/components/views/Session.tsx +850 -0
- package/components/views/SessionManage.tsx +127 -0
- package/components/views/Show.tsx +758 -0
- package/components/views/Shown.tsx +72 -0
- package/components/views/Split.tsx +58 -0
- package/components/views/TaskTile.tsx +37 -0
- package/components/views/Title.tsx +105 -0
- package/components/views/Wake.tsx +77 -0
- package/components/views/Web.tsx +49 -0
- package/components/wells.js +30 -0
- package/components/wells.js.map +1 -0
- package/components/wells.ts +33 -0
- package/configuration.js +38 -0
- package/configuration.js.map +1 -0
- package/configuration.ts +41 -0
- package/decision_sync.js +88 -0
- package/decision_sync.js.map +1 -0
- package/decision_sync.ts +93 -0
- package/deno.json +1 -0
- package/domain-host.tsx +108 -0
- package/edge.js +193 -0
- package/edge.js.map +1 -0
- package/edge.ts +196 -0
- package/entry_log.js +241 -0
- package/entry_log.js.map +1 -0
- package/entry_log.ts +214 -0
- package/failure.js +22 -0
- package/failure.js.map +1 -0
- package/failure.ts +34 -0
- package/front.json +61 -0
- package/highlight.js +143 -0
- package/highlight.js.map +1 -0
- package/highlight.ts +149 -0
- package/history.js +68 -0
- package/history.js.map +1 -0
- package/history.ts +72 -0
- package/host_commands.js +107 -0
- package/host_commands.js.map +1 -0
- package/host_commands.ts +38 -0
- package/hosting.js +53 -0
- package/hosting.js.map +1 -0
- package/hosting.ts +72 -0
- package/idb.js +14 -0
- package/idb.js.map +1 -0
- package/idb.ts +15 -0
- package/index.js +232 -0
- package/index.js.map +1 -0
- package/index.ts +252 -0
- package/keybindings.js +136 -0
- package/keybindings.js.map +1 -0
- package/keybindings.ts +37 -0
- package/kit.js +103 -0
- package/kit.js.map +1 -0
- package/kit.ts +119 -0
- package/layout.js +254 -0
- package/layout.js.map +1 -0
- package/layout.ts +210 -0
- package/legacy_outbox.js +53 -0
- package/legacy_outbox.js.map +1 -0
- package/legacy_outbox.ts +63 -0
- package/live.js +2883 -0
- package/live.js.map +1 -0
- package/live.ts +3334 -0
- package/live_archetypes.js +92 -0
- package/live_archetypes.js.map +1 -0
- package/live_archetypes.ts +113 -0
- package/live_client.js +145 -0
- package/live_client.js.map +1 -0
- package/live_client.ts +120 -0
- package/main.tsx +5 -0
- package/mod.js +7 -0
- package/mod.js.map +1 -0
- package/mod.ts +7 -0
- package/mount.tsx +50 -0
- package/navigation.js +120 -0
- package/navigation.js.map +1 -0
- package/navigation.ts +152 -0
- package/near.js +83 -0
- package/near.js.map +1 -0
- package/near.ts +83 -0
- package/new.js +295 -0
- package/new.js.map +1 -0
- package/new.ts +361 -0
- package/outbox.js +112 -0
- package/outbox.js.map +1 -0
- package/outbox.ts +129 -0
- package/owner.js +39 -0
- package/owner.js.map +1 -0
- package/owner.ts +37 -0
- package/package.json +81 -4
- package/paste.js +157 -0
- package/paste.js.map +1 -0
- package/paste.ts +122 -0
- package/props.js +303 -0
- package/props.js.map +1 -0
- package/props.ts +358 -0
- package/providers.js +136 -0
- package/providers.js.map +1 -0
- package/providers.ts +194 -0
- package/query.js +987 -0
- package/query.js.map +1 -0
- package/query.ts +1113 -0
- package/remote.js +37 -0
- package/remote.js.map +1 -0
- package/remote.ts +46 -0
- package/resolver.js +149 -0
- package/resolver.js.map +1 -0
- package/resolver.ts +213 -0
- package/rfc2047.js +37 -0
- package/rfc2047.js.map +1 -0
- package/rfc2047.ts +40 -0
- package/row_holds.js +107 -0
- package/row_holds.js.map +1 -0
- package/row_holds.ts +93 -0
- package/served.ts +42 -0
- package/session_worktree.js +7 -0
- package/session_worktree.js.map +1 -0
- package/session_worktree.ts +16 -0
- package/sessions.js +57 -0
- package/sessions.js.map +1 -0
- package/sessions.ts +53 -0
- package/sha.js +161 -0
- package/sha.js.map +1 -0
- package/sha.ts +164 -0
- package/styles.css +2823 -0
- package/subs.js +36 -0
- package/subs.js.map +1 -0
- package/subs.ts +40 -0
- package/terminal-route.js +13 -0
- package/terminal-route.js.map +1 -0
- package/terminal-route.ts +17 -0
- package/terminal.js +251 -0
- package/terminal.js.map +1 -0
- package/terminal.ts +186 -0
- package/time.js +142 -0
- package/time.js.map +1 -0
- package/time.ts +133 -0
- package/title.js +25 -0
- package/title.js.map +1 -0
- package/title.ts +50 -0
- package/tui/doc.ts +6 -0
- package/tui/testing.ts +19 -0
- package/twin.js +11 -0
- package/twin.js.map +1 -0
- package/twin.ts +13 -0
- package/types.js +456 -0
- package/types.js.map +1 -0
- package/types.ts +1370 -0
- package/url.js +77 -0
- package/url.js.map +1 -0
- package/url.ts +85 -0
- package/verb.js +82 -0
- package/verb.js.map +1 -0
- package/verb.ts +137 -0
- package/warmth.js +41 -0
- package/warmth.js.map +1 -0
- package/warmth.ts +54 -0
- package/wire.js +86 -0
- package/wire.js.map +1 -0
- package/wire.ts +63 -0
|
@@ -0,0 +1,276 @@
|
|
|
1
|
+
/** @jsxRuntime automatic *//** @jsxImportSourceTypes npm:react@19.3.0 *//** @jsxImportSource npm:react@19.3.0 */
|
|
2
|
+
import { useDerived } from './read.ts'
|
|
3
|
+
/* @ts-types="npm:@types/react@19.3.0" */ import { useEffect, useRef, useState } from 'npm:react@19.3.0'
|
|
4
|
+
import { camera, ent, mutate, pinZ, toFront } from '../live.ts'
|
|
5
|
+
import { type Pinned } from '../types.ts'
|
|
6
|
+
import * as ui from 'jsr:@yaks/ui@0.2.36'
|
|
7
|
+
import { Ux } from 'jsr:@yaks/ux@0.2.36'
|
|
8
|
+
import { applicable } from './registry.ts'
|
|
9
|
+
import {
|
|
10
|
+
dragData,
|
|
11
|
+
moved,
|
|
12
|
+
moveEl,
|
|
13
|
+
resetSize,
|
|
14
|
+
resizeDirs,
|
|
15
|
+
resizeEl,
|
|
16
|
+
} from './drag.ts'
|
|
17
|
+
import { Entity } from './Entity.tsx'
|
|
18
|
+
import { filterable, FilterInput } from './Filter.tsx'
|
|
19
|
+
import { Icon } from './icons.tsx'
|
|
20
|
+
import { cardMenuAt } from './nav.tsx'
|
|
21
|
+
import { useEntity } from './subscriptions.ts'
|
|
22
|
+
import { tabOffers } from './offers.ts'
|
|
23
|
+
import { Waiting } from './inspect.tsx'
|
|
24
|
+
|
|
25
|
+
// Each tab view wears an icon; the name moves into an anchored tooltip.
|
|
26
|
+
// Exported: the fullscreen Screen bar (App.tsx) draws the same tabs.
|
|
27
|
+
export let icons: Record<string, string> = {
|
|
28
|
+
Wake: 'alarm-clock',
|
|
29
|
+
Canvas: 'map',
|
|
30
|
+
List: 'list',
|
|
31
|
+
Full: 'file-text',
|
|
32
|
+
Board: 'kanban',
|
|
33
|
+
Split: 'columns-2',
|
|
34
|
+
Layout: 'columns-3',
|
|
35
|
+
Dashboard: 'layout-dashboard',
|
|
36
|
+
Web: 'globe',
|
|
37
|
+
Media: 'image',
|
|
38
|
+
Session: 'bot',
|
|
39
|
+
Markdown: 'hash',
|
|
40
|
+
JSON: 'braces',
|
|
41
|
+
'Inspect.Page': 'table',
|
|
42
|
+
'Inspect.History': 'history',
|
|
43
|
+
Debug: 'bug',
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
let { Tab, Badge } = ui.Tabs
|
|
47
|
+
|
|
48
|
+
// A tab's face: its icon, plus what is waiting behind it when the package
|
|
49
|
+
// offering the tab says (./offers.ts): the difference between a tab you check
|
|
50
|
+
// and one you remember to check. Shared by the card's tab row and the page's
|
|
51
|
+
// bar, so a badge can never appear on one and not the other.
|
|
52
|
+
export let TabFace = ({ view, eid }: { view: string; eid: string }) => {
|
|
53
|
+
let offer = tabOffers().find((t) => t.view == view)
|
|
54
|
+
return (
|
|
55
|
+
<>
|
|
56
|
+
<Icon name={offer?.icon ?? icons[view]} />
|
|
57
|
+
{offer?.waiting && (
|
|
58
|
+
<Waiting offer={offer} eid={eid}>
|
|
59
|
+
{(n) => <Badge>{n > 99 ? '99+' : n}</Badge>}
|
|
60
|
+
</Waiting>
|
|
61
|
+
)}
|
|
62
|
+
</>
|
|
63
|
+
)
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
let Pin = ui.el('div', 'Pin')
|
|
67
|
+
let Handle = ui.el('div', 'Handle')
|
|
68
|
+
|
|
69
|
+
let Frame = ui.block(ui.Card.Frame, 'Window', {
|
|
70
|
+
Tabs: 'header',
|
|
71
|
+
Min: 'button',
|
|
72
|
+
X: 'button',
|
|
73
|
+
Scroll: 'div',
|
|
74
|
+
})
|
|
75
|
+
let { Tabs, Min, X, Scroll } = Frame
|
|
76
|
+
|
|
77
|
+
export let pinStyle = (p: Pinned) => ({
|
|
78
|
+
left: `${p.x}px`,
|
|
79
|
+
top: `${p.y}px`,
|
|
80
|
+
zIndex: pinZ(p.eid, p.z).value,
|
|
81
|
+
width: p.w ? `${p.w}px` : undefined,
|
|
82
|
+
height: p.h ? `${p.h}px` : undefined,
|
|
83
|
+
})
|
|
84
|
+
|
|
85
|
+
// A card: one entity through one chosen view, framed by a tab per view that
|
|
86
|
+
// applies. Everything renders from the cache, so a tab click is just a card
|
|
87
|
+
// patch and a titlebar drag is pin patches — local first (instant), wire on
|
|
88
|
+
// drop. Tabs are native draggables: dropped on the canvas they spawn a new
|
|
89
|
+
// card with that view (Canvas owns the drop); dragged to the desktop they
|
|
90
|
+
// become a file when the view's renderer has a file form (the raw formats
|
|
91
|
+
// nested under Debug use the same drag contract).
|
|
92
|
+
// The scroller (not the card) owns the padding, so the scrollbar rides the
|
|
93
|
+
// card border and the padding scrolls away with the content.
|
|
94
|
+
export let Card = (
|
|
95
|
+
{ p, docked = false, onMinimize }: {
|
|
96
|
+
p: Pinned
|
|
97
|
+
docked?: boolean
|
|
98
|
+
onMinimize?: () => void
|
|
99
|
+
},
|
|
100
|
+
) => {
|
|
101
|
+
// The card's TARGET is subscribed for the card's life (T-22371). It used to
|
|
102
|
+
// arrive in the working-set boot, which walked one hop from every card and
|
|
103
|
+
// preseeded whatever it pointed at — a whole-graph read on every join, for
|
|
104
|
+
// rows a client might not even be showing. A route sub is the scoped form:
|
|
105
|
+
// the entity streams in with the card, stays live, carries its edges (the
|
|
106
|
+
// `.edges` rider), and is evicted when the last card on it closes.
|
|
107
|
+
// Collection faces render the board header, not its incident history.
|
|
108
|
+
// Switching to Full/Debug acquires the ordinary route (and its edges).
|
|
109
|
+
let collection = p.view == 'Board' ||
|
|
110
|
+
(p.view == 'List' && !!ent(p.target).board)
|
|
111
|
+
useEntity(
|
|
112
|
+
p.target,
|
|
113
|
+
collection ? 'doc.title,board.query,project.color' : undefined,
|
|
114
|
+
)
|
|
115
|
+
// A canvas can hold many boards outside the viewport. Keep their frames
|
|
116
|
+
// and titles in place, but acquire member pages only as a tile approaches.
|
|
117
|
+
let frame = useRef<HTMLElement>(null)
|
|
118
|
+
let [near, setNear] = useState(!globalThis.IntersectionObserver)
|
|
119
|
+
useEffect(() => {
|
|
120
|
+
if (!frame.current || !globalThis.IntersectionObserver) return
|
|
121
|
+
let observer = new IntersectionObserver(
|
|
122
|
+
([entry]) => setNear(entry.isIntersecting),
|
|
123
|
+
{ rootMargin: '160px' },
|
|
124
|
+
)
|
|
125
|
+
observer.observe(frame.current)
|
|
126
|
+
return () => observer.disconnect()
|
|
127
|
+
}, [])
|
|
128
|
+
let style = useDerived(() => docked ? undefined : pinStyle(p), [docked, p])
|
|
129
|
+
let down = (e: PointerEvent & { currentTarget: HTMLDivElement }) => {
|
|
130
|
+
if (!(e.target instanceof Element)) return
|
|
131
|
+
if (docked) return
|
|
132
|
+
toFront(p.eid) // ANY touch raises the card — the drag gate is below
|
|
133
|
+
if (e.button != 0) return // right/middle click is a menu, never a drag
|
|
134
|
+
if (
|
|
135
|
+
e.target.closest('button, a, input, [contenteditable="plaintext-only"]')
|
|
136
|
+
) {
|
|
137
|
+
return // an editing title owns its clicks — place the cursor, no drag
|
|
138
|
+
}
|
|
139
|
+
if (!e.target.closest('.Window_Tabs')) return
|
|
140
|
+
let el = e.currentTarget
|
|
141
|
+
let from = { x: p.x, y: p.y }
|
|
142
|
+
moveEl(
|
|
143
|
+
e,
|
|
144
|
+
el,
|
|
145
|
+
() => camera.value.zoom,
|
|
146
|
+
() => {},
|
|
147
|
+
(dx, dy) => {
|
|
148
|
+
mutate({
|
|
149
|
+
eid: p.eid,
|
|
150
|
+
name: 'pin',
|
|
151
|
+
comp: moved(from.x, from.y, dx, dy),
|
|
152
|
+
})
|
|
153
|
+
},
|
|
154
|
+
)
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
// Drag a side or corner to size the card; west/north edges move the pin
|
|
158
|
+
// so the opposite edge stays put. 0 means auto, so an auto dimension
|
|
159
|
+
// starts from the rendered size the moment a resize grabs it.
|
|
160
|
+
let resize = (
|
|
161
|
+
e: PointerEvent & { currentTarget: HTMLDivElement },
|
|
162
|
+
d: string,
|
|
163
|
+
) => {
|
|
164
|
+
e.stopPropagation() // the grip's down never reaches the Pin's handler,
|
|
165
|
+
toFront(p.eid) // so the grab raises the card here — same as any touch
|
|
166
|
+
if (e.button != 0) return
|
|
167
|
+
let grip = e.currentTarget
|
|
168
|
+
let card = grip.parentElement!.querySelector('.Window') as HTMLElement
|
|
169
|
+
let base = {
|
|
170
|
+
x: p.x,
|
|
171
|
+
y: p.y,
|
|
172
|
+
w: p.w || card.offsetWidth,
|
|
173
|
+
h: p.h || card.offsetHeight,
|
|
174
|
+
}
|
|
175
|
+
let pin = grip.parentElement as HTMLElement
|
|
176
|
+
let wasSized = pin.classList.contains('Pin-sized')
|
|
177
|
+
pin.classList.add('Pin-sized')
|
|
178
|
+
resizeEl(
|
|
179
|
+
e,
|
|
180
|
+
grip,
|
|
181
|
+
pin,
|
|
182
|
+
base,
|
|
183
|
+
d,
|
|
184
|
+
() => camera.value.zoom,
|
|
185
|
+
(comp) => {
|
|
186
|
+
if (comp.h != null) {
|
|
187
|
+
pin.style.height = `${comp.h}px`
|
|
188
|
+
}
|
|
189
|
+
mutate({ eid: p.eid, name: 'pin', comp })
|
|
190
|
+
},
|
|
191
|
+
() => {
|
|
192
|
+
if (!wasSized) pin.classList.remove('Pin-sized')
|
|
193
|
+
},
|
|
194
|
+
)
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
// Double-click a side to revert that dimension to auto; a corner, both.
|
|
198
|
+
let reset = (d: string) => {
|
|
199
|
+
mutate({ eid: p.eid, name: 'pin', comp: resetSize(d) })
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
return (
|
|
203
|
+
<Pin
|
|
204
|
+
mod={[p.h ? 'sized' : false, !p.w && 'auto', docked && 'docked']}
|
|
205
|
+
data-eid={p.eid}
|
|
206
|
+
style={style}
|
|
207
|
+
onPointerDown={down}
|
|
208
|
+
// The CARD is the right-click target — "open here" (make this the
|
|
209
|
+
// root card) and "open in new tab" for its target. Links, inputs,
|
|
210
|
+
// and selectable text keep the browser's own menu.
|
|
211
|
+
onContextMenu={cardMenuAt(ent(p.target))}
|
|
212
|
+
>
|
|
213
|
+
{
|
|
214
|
+
/* What is changed on this card is this card's: the same value on
|
|
215
|
+
another card, or twice on one page, keeps a state of its own. */
|
|
216
|
+
}
|
|
217
|
+
<Ux at={p.eid}>
|
|
218
|
+
<Frame elRef={frame}>
|
|
219
|
+
<Tabs>
|
|
220
|
+
<Entity eid={p.target} view='Card.Title' />
|
|
221
|
+
{filterable.has(p.view) && <FilterInput eid={p.target} />}
|
|
222
|
+
<ui.Tabs>
|
|
223
|
+
{applicable(ent(p.target)).map((v) => (
|
|
224
|
+
<Tab
|
|
225
|
+
type='button'
|
|
226
|
+
mod={v == p.view && 'on'}
|
|
227
|
+
draggable
|
|
228
|
+
onDragStart={(e: DragEvent) => dragData(e, p.target, v, p.w)}
|
|
229
|
+
onClick={() =>
|
|
230
|
+
v != p.view &&
|
|
231
|
+
mutate({ eid: p.eid, name: 'card', comp: { view: v } })}
|
|
232
|
+
key={v}
|
|
233
|
+
aria-label={v}
|
|
234
|
+
data-tip={v}
|
|
235
|
+
>
|
|
236
|
+
<TabFace view={v} eid={p.target} />
|
|
237
|
+
</Tab>
|
|
238
|
+
))}
|
|
239
|
+
</ui.Tabs>
|
|
240
|
+
{onMinimize && (
|
|
241
|
+
<Min type='button' aria-label='minimize' onClick={onMinimize}>
|
|
242
|
+
−
|
|
243
|
+
</Min>
|
|
244
|
+
)}
|
|
245
|
+
<X
|
|
246
|
+
type='button'
|
|
247
|
+
onClick={() => mutate({ eid: p.eid, name: 'entity', comp: null })}
|
|
248
|
+
>
|
|
249
|
+
×
|
|
250
|
+
</X>
|
|
251
|
+
</Tabs>
|
|
252
|
+
<Scroll>
|
|
253
|
+
{
|
|
254
|
+
/* The frame's ask wears the Card qualifier: a view with a card
|
|
255
|
+
face (Card.Full) serves it, anything else walks to the plain
|
|
256
|
+
role — the titlebar above already shows the head. */
|
|
257
|
+
}
|
|
258
|
+
{!collection || near
|
|
259
|
+
? <Entity eid={p.target} view={`Card.${p.view}`} />
|
|
260
|
+
: <div className={p.view} />}
|
|
261
|
+
</Scroll>
|
|
262
|
+
</Frame>
|
|
263
|
+
</Ux>
|
|
264
|
+
{!docked && resizeDirs.map((d) => (
|
|
265
|
+
<Handle
|
|
266
|
+
key={d}
|
|
267
|
+
mod={d}
|
|
268
|
+
onPointerDown={(
|
|
269
|
+
e: PointerEvent & { currentTarget: HTMLDivElement },
|
|
270
|
+
) => resize(e, d)}
|
|
271
|
+
onDoubleClick={() => reset(d)}
|
|
272
|
+
/>
|
|
273
|
+
))}
|
|
274
|
+
</Pin>
|
|
275
|
+
)
|
|
276
|
+
}
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
/** @jsxRuntime automatic *//** @jsxImportSourceTypes npm:react@19.3.0 *//** @jsxImportSource npm:react@19.3.0 */
|
|
2
|
+
// The document-side conversation: one actor's selected Session. The binding is graph data on the session, so a
|
|
3
|
+
// reload or another browser finds the same transcript. On a persona the
|
|
4
|
+
// conversation is with it: a message to it begins a native session wearing it
|
|
5
|
+
// on the host's default model (D-130780), as `yak session new --persona`
|
|
6
|
+
// does. On a topic it is with the oracle, the session opened on the topic
|
|
7
|
+
// (D-131941), as `yak session new --topic` does. On any other document the
|
|
8
|
+
// chat plan picks a provider. The conversation alone is `Conversation`, the
|
|
9
|
+
// part a topic's page asks its host for.
|
|
10
|
+
/* @ts-types="npm:@types/react@19.3.0" */ import { useRef, useState } from 'npm:react@19.3.0'
|
|
11
|
+
import { ORACLE } from 'jsr:@yaks/topic@0.2.36'
|
|
12
|
+
import { sessionFrames } from '../client.ts'
|
|
13
|
+
import { mutate, myActor, uuid } from '../live.ts'
|
|
14
|
+
import { catalog, type Provider, usingOf } from '../providers.ts'
|
|
15
|
+
import type { Change, Ent } from '../types.ts'
|
|
16
|
+
import { block, Composer } from 'jsr:@yaks/ui@0.2.36'
|
|
17
|
+
import { sends } from 'jsr:@yaks/ux@0.2.36/composer'
|
|
18
|
+
import { Entity } from './Entity.tsx'
|
|
19
|
+
import { liveBlocked, load, nativeUsing, providers } from './Run.tsx'
|
|
20
|
+
import { useChatFor } from './useQuery.ts'
|
|
21
|
+
|
|
22
|
+
let Frame = block('aside', 'Chat', {
|
|
23
|
+
Label: 'h2',
|
|
24
|
+
Head: 'div',
|
|
25
|
+
New: 'button',
|
|
26
|
+
Start: 'div',
|
|
27
|
+
State: 'p',
|
|
28
|
+
Box: 'div',
|
|
29
|
+
})
|
|
30
|
+
let { Label, Head, New, Start, State, Box } = Frame
|
|
31
|
+
|
|
32
|
+
export let chatPlan = (
|
|
33
|
+
ps: Provider[],
|
|
34
|
+
blocked: (name: string) => boolean,
|
|
35
|
+
) => {
|
|
36
|
+
let ready = (name: string) =>
|
|
37
|
+
['codex', 'ollama'].includes(name) && !blocked(name)
|
|
38
|
+
let pick = catalog(ps).find((p) => p.transports.some(ready))
|
|
39
|
+
let provider = pick?.transports.find(ready)
|
|
40
|
+
if (!pick || !provider) {
|
|
41
|
+
throw new Error('No graph-native chat model is available')
|
|
42
|
+
}
|
|
43
|
+
let effort = pick.efforts.length
|
|
44
|
+
? (pick.efforts.includes('medium') ? 'medium' : pick.efforts[0])
|
|
45
|
+
: undefined
|
|
46
|
+
return {
|
|
47
|
+
provider,
|
|
48
|
+
model: pick.model,
|
|
49
|
+
effort,
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** Who a chat talks to, and what about: the persona its session wears, and
|
|
54
|
+
* the topic it is opened on. */
|
|
55
|
+
export type Voice = { persona: string; topic?: string }
|
|
56
|
+
|
|
57
|
+
// Who a chat on `e` talks to: `e` itself when it is a persona, so a chat
|
|
58
|
+
// there is a message to it (D-130780); the oracle when it is a topic, about
|
|
59
|
+
// that topic (D-131941); no one in particular otherwise.
|
|
60
|
+
export let voiceOf = (e: Ent): Voice | undefined =>
|
|
61
|
+
e.persona
|
|
62
|
+
? { persona: e.eid }
|
|
63
|
+
: e.topic
|
|
64
|
+
? { persona: ORACLE, topic: e.eid }
|
|
65
|
+
: undefined
|
|
66
|
+
|
|
67
|
+
// A chat is opened by the person typing its first ask, bound to this actor
|
|
68
|
+
// and document; one sent to a persona or a topic is native and wears the
|
|
69
|
+
// persona, opened on the topic. A new one unbinds the old.
|
|
70
|
+
export let chatChanges = (
|
|
71
|
+
old: string | undefined,
|
|
72
|
+
session: string,
|
|
73
|
+
actor: string,
|
|
74
|
+
target: string,
|
|
75
|
+
using: { provider: string; model?: string; effort?: string },
|
|
76
|
+
body: string,
|
|
77
|
+
voice?: Voice,
|
|
78
|
+
): Change[] => [
|
|
79
|
+
...(old ? [{ eid: old, name: 'chat', comp: null } as Change] : []),
|
|
80
|
+
...sessionFrames(session, body, using, {
|
|
81
|
+
operator: true,
|
|
82
|
+
...voice,
|
|
83
|
+
native: !!voice,
|
|
84
|
+
}),
|
|
85
|
+
{ eid: session, name: 'chat', comp: { actor, target } },
|
|
86
|
+
]
|
|
87
|
+
|
|
88
|
+
// What the first line says it starts.
|
|
89
|
+
let invite = (e: Ent): string => {
|
|
90
|
+
let voice = voiceOf(e)
|
|
91
|
+
return voice?.topic
|
|
92
|
+
? `ask about ${e.doc?.title || 'this topic'}…`
|
|
93
|
+
: voice
|
|
94
|
+
? `message ${e.doc?.title || 'this persona'}…`
|
|
95
|
+
: 'start a chat…'
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// The provider and model a document's chat runs on, by the chat plan.
|
|
99
|
+
let planned = async () => {
|
|
100
|
+
if (!providers.value.length) await load()
|
|
101
|
+
return usingOf(
|
|
102
|
+
providers.value,
|
|
103
|
+
chatPlan(providers.value, await liveBlocked()),
|
|
104
|
+
)
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export let Starter = (
|
|
108
|
+
{ e, actor, old, done }: {
|
|
109
|
+
e: Ent
|
|
110
|
+
actor: string
|
|
111
|
+
old?: string
|
|
112
|
+
done: () => void
|
|
113
|
+
},
|
|
114
|
+
) => {
|
|
115
|
+
let box = useRef<HTMLTextAreaElement>(null)
|
|
116
|
+
let [state, setState] = useState('')
|
|
117
|
+
let start = async () => {
|
|
118
|
+
let body = box.current?.value.trim() ?? ''
|
|
119
|
+
if (!body || state) return
|
|
120
|
+
setState('Starting chat…')
|
|
121
|
+
try {
|
|
122
|
+
let voice = voiceOf(e)
|
|
123
|
+
let using = voice ? await nativeUsing() : await planned()
|
|
124
|
+
mutate(...chatChanges(old, uuid(), actor, e.eid, using, body, voice))
|
|
125
|
+
done()
|
|
126
|
+
} catch (error) {
|
|
127
|
+
setState(error instanceof Error ? error.message : String(error))
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
return (
|
|
131
|
+
<Start>
|
|
132
|
+
<Composer
|
|
133
|
+
as='form'
|
|
134
|
+
onSubmit={(event: Event) => {
|
|
135
|
+
event.preventDefault()
|
|
136
|
+
start()
|
|
137
|
+
}}
|
|
138
|
+
>
|
|
139
|
+
<Composer.Field
|
|
140
|
+
lines
|
|
141
|
+
elRef={box}
|
|
142
|
+
placeholder={invite(e)}
|
|
143
|
+
onKeyDown={(event: KeyboardEvent) => {
|
|
144
|
+
if (!sends(event)) return
|
|
145
|
+
event.preventDefault()
|
|
146
|
+
start()
|
|
147
|
+
}}
|
|
148
|
+
/>
|
|
149
|
+
<Composer.Send type='submit' disabled={!!state}>Start</Composer.Send>
|
|
150
|
+
</Composer>
|
|
151
|
+
{state && <State>{state}</State>}
|
|
152
|
+
</Start>
|
|
153
|
+
)
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
// This actor's conversation on `e`: the session it last bound here, or a
|
|
157
|
+
// line to start one. Nothing for a reader with no actor. A page that draws it
|
|
158
|
+
// among its parts lets the session scroll with it; the chat beside a page
|
|
159
|
+
// that stays put gives it a box of its own to scroll in (`boxed`).
|
|
160
|
+
export let Conversation = (
|
|
161
|
+
{ e, boxed = false }: { e: Ent; boxed?: boolean },
|
|
162
|
+
) => {
|
|
163
|
+
let actor = myActor()
|
|
164
|
+
let selected = useChatFor(actor, e.eid)
|
|
165
|
+
let [fresh, setFresh] = useState(false)
|
|
166
|
+
return actor
|
|
167
|
+
? (
|
|
168
|
+
<section className='Chat_Conversation'>
|
|
169
|
+
<Head>
|
|
170
|
+
<Label>chat</Label>
|
|
171
|
+
{selected && (
|
|
172
|
+
<New
|
|
173
|
+
type='button'
|
|
174
|
+
onClick={() => setFresh((value) => !value)}
|
|
175
|
+
>
|
|
176
|
+
{fresh ? 'current chat' : 'new chat'}
|
|
177
|
+
</New>
|
|
178
|
+
)}
|
|
179
|
+
</Head>
|
|
180
|
+
{selected && !fresh
|
|
181
|
+
? (boxed
|
|
182
|
+
? (
|
|
183
|
+
<Box>
|
|
184
|
+
<Entity eid={selected.eid} view='Session' />
|
|
185
|
+
</Box>
|
|
186
|
+
)
|
|
187
|
+
: <Entity eid={selected.eid} view='Session' />)
|
|
188
|
+
: (
|
|
189
|
+
<Starter
|
|
190
|
+
e={e}
|
|
191
|
+
actor={actor}
|
|
192
|
+
old={selected?.eid}
|
|
193
|
+
done={() => setFresh(false)}
|
|
194
|
+
/>
|
|
195
|
+
)}
|
|
196
|
+
</section>
|
|
197
|
+
)
|
|
198
|
+
: null
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
export let Chat = ({ e }: { e: Ent }) => (
|
|
202
|
+
<Frame>
|
|
203
|
+
<Conversation e={e} boxed />
|
|
204
|
+
</Frame>
|
|
205
|
+
)
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
/** @jsxRuntime automatic *//** @jsxImportSourceTypes npm:react@19.3.0 *//** @jsxImportSource npm:react@19.3.0 */
|
|
2
|
+
import { useObserved } from 'jsr:@yaks/ux@0.2.36'
|
|
3
|
+
// Configuration restores the host's secrets and sign-ins using their existing
|
|
4
|
+
// graph and authorization doors. Credential input stays private and is never
|
|
5
|
+
// prefilled; each entity's public face is drawn by the shared renderer.
|
|
6
|
+
import { signal } from 'npm:@preact/signals-core@1.14.5'
|
|
7
|
+
/* @ts-types="npm:@types/react@19.3.0" */ import { useEffect, useMemo } from 'npm:react@19.3.0'
|
|
8
|
+
import { Button, Field, Rows, Section } from 'jsr:@yaks/ui@0.2.36'
|
|
9
|
+
import { saveSecret, signIn } from '../configuration.ts'
|
|
10
|
+
import { type Ent, vocab } from '../types.ts'
|
|
11
|
+
import { Entity } from './Entity.tsx'
|
|
12
|
+
import { usePage } from './page.ts'
|
|
13
|
+
import { useQuery } from './useQuery.ts'
|
|
14
|
+
|
|
15
|
+
let useProgress = (place: string) => {
|
|
16
|
+
let page = usePage<{ busy: boolean; message: string }>(
|
|
17
|
+
'Configuration',
|
|
18
|
+
place,
|
|
19
|
+
)
|
|
20
|
+
return {
|
|
21
|
+
busy: !!page.value?.busy,
|
|
22
|
+
message: page.value?.message,
|
|
23
|
+
run: async (work: () => Promise<string>) => {
|
|
24
|
+
page.set({ busy: true, message: '' })
|
|
25
|
+
try {
|
|
26
|
+
page.set({ message: await work() })
|
|
27
|
+
} catch (error) {
|
|
28
|
+
page.set({
|
|
29
|
+
message: error instanceof Error ? error.message : 'Failed',
|
|
30
|
+
})
|
|
31
|
+
} finally {
|
|
32
|
+
page.set({ busy: false })
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
let Secret = ({ e }: { e?: Ent }) => {
|
|
39
|
+
let input = useMemo(() => signal({ name: '', value: '' }), [])
|
|
40
|
+
let progress = useProgress(e?.eid ?? 'new-secret')
|
|
41
|
+
let secret = e?.secret as { name?: string } | undefined
|
|
42
|
+
let entered = useObserved(input)
|
|
43
|
+
let name = secret?.name ?? entered.name
|
|
44
|
+
let save = () => {
|
|
45
|
+
let value = input.value.value
|
|
46
|
+
void progress.run(async () => {
|
|
47
|
+
await saveSecret(name.trim(), value, e?.eid)
|
|
48
|
+
input.value = { ...input.value, value: '' }
|
|
49
|
+
return 'Saved.'
|
|
50
|
+
})
|
|
51
|
+
}
|
|
52
|
+
return (
|
|
53
|
+
<Rows.Item>
|
|
54
|
+
{e ? <Entity eid={e.eid} view='Tile' /> : (
|
|
55
|
+
<Field
|
|
56
|
+
aria-label='New secret name'
|
|
57
|
+
placeholder='Secret name'
|
|
58
|
+
value={entered.name}
|
|
59
|
+
onInput={(ev: InputEvent) => {
|
|
60
|
+
input.value = {
|
|
61
|
+
...input.value,
|
|
62
|
+
name: (ev.currentTarget as HTMLInputElement).value,
|
|
63
|
+
}
|
|
64
|
+
}}
|
|
65
|
+
/>
|
|
66
|
+
)}
|
|
67
|
+
<Field
|
|
68
|
+
type='password'
|
|
69
|
+
aria-label={`${name || 'New secret'} value`}
|
|
70
|
+
autocomplete='new-password'
|
|
71
|
+
placeholder='New secret value'
|
|
72
|
+
value={entered.value}
|
|
73
|
+
disabled={progress.busy}
|
|
74
|
+
onInput={(ev: InputEvent) => {
|
|
75
|
+
input.value = {
|
|
76
|
+
...input.value,
|
|
77
|
+
value: (ev.currentTarget as HTMLInputElement).value,
|
|
78
|
+
}
|
|
79
|
+
}}
|
|
80
|
+
/>
|
|
81
|
+
<Button
|
|
82
|
+
type='button'
|
|
83
|
+
disabled={progress.busy || !name.trim() || !entered.value}
|
|
84
|
+
onClick={save}
|
|
85
|
+
>
|
|
86
|
+
{e ? 'Update secret' : 'Add secret'}
|
|
87
|
+
</Button>
|
|
88
|
+
{progress.message && (
|
|
89
|
+
<Section.Note role='status'>{progress.message}</Section.Note>
|
|
90
|
+
)}
|
|
91
|
+
</Rows.Item>
|
|
92
|
+
)
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
let Authorization = () => {
|
|
96
|
+
let privateState = useMemo(() =>
|
|
97
|
+
signal({
|
|
98
|
+
names: [] as string[],
|
|
99
|
+
name: '',
|
|
100
|
+
url: '',
|
|
101
|
+
callback: '',
|
|
102
|
+
}), [])
|
|
103
|
+
let progress = useProgress('authorization')
|
|
104
|
+
let run = (action: 'list' | 'begin' | 'complete') => {
|
|
105
|
+
let { name, callback } = privateState.value
|
|
106
|
+
void progress.run(async () => {
|
|
107
|
+
let reply = await signIn(action, name, callback)
|
|
108
|
+
privateState.value = {
|
|
109
|
+
...privateState.value,
|
|
110
|
+
callback: '',
|
|
111
|
+
...reply.servers ? { names: reply.servers } : {},
|
|
112
|
+
url: reply.url ?? '',
|
|
113
|
+
}
|
|
114
|
+
return reply.message ?? ''
|
|
115
|
+
})
|
|
116
|
+
}
|
|
117
|
+
useEffect(() => {
|
|
118
|
+
run('list')
|
|
119
|
+
return () => {
|
|
120
|
+
let { name, url } = privateState.value
|
|
121
|
+
if (url) void signIn('cancel', name).catch(() => {})
|
|
122
|
+
privateState.value = { names: [], name: '', url: '', callback: '' }
|
|
123
|
+
}
|
|
124
|
+
}, [])
|
|
125
|
+
let state = useObserved(privateState)
|
|
126
|
+
return (
|
|
127
|
+
<Section>
|
|
128
|
+
<Section.Title>Sign-ins</Section.Title>
|
|
129
|
+
<Section.Sub>Connect a provider using its sign-in link.</Section.Sub>
|
|
130
|
+
<Rows>
|
|
131
|
+
{state.names.map((name) => (
|
|
132
|
+
<Rows.Item key={name}>
|
|
133
|
+
<Button
|
|
134
|
+
disabled={progress.busy}
|
|
135
|
+
onClick={() => {
|
|
136
|
+
privateState.value = { ...state, name }
|
|
137
|
+
run('begin')
|
|
138
|
+
}}
|
|
139
|
+
>
|
|
140
|
+
Sign in to {name}
|
|
141
|
+
</Button>
|
|
142
|
+
</Rows.Item>
|
|
143
|
+
))}
|
|
144
|
+
</Rows>
|
|
145
|
+
{state.url && (
|
|
146
|
+
<>
|
|
147
|
+
<p>
|
|
148
|
+
<a href={state.url} target='_blank' rel='noreferrer'>
|
|
149
|
+
Open sign-in page
|
|
150
|
+
</a>
|
|
151
|
+
</p>
|
|
152
|
+
<Section.Sub>
|
|
153
|
+
After signing in, paste the complete return URL below.
|
|
154
|
+
</Section.Sub>
|
|
155
|
+
<Field
|
|
156
|
+
type='password'
|
|
157
|
+
aria-label='Sign-in return URL'
|
|
158
|
+
placeholder='Paste the URL from your browser'
|
|
159
|
+
autocomplete='off'
|
|
160
|
+
value={state.callback}
|
|
161
|
+
onInput={(ev: InputEvent) => {
|
|
162
|
+
privateState.value = {
|
|
163
|
+
...privateState.value,
|
|
164
|
+
callback: (ev.currentTarget as HTMLInputElement).value,
|
|
165
|
+
}
|
|
166
|
+
}}
|
|
167
|
+
/>
|
|
168
|
+
<Button
|
|
169
|
+
disabled={progress.busy || !state.callback}
|
|
170
|
+
onClick={() => run('complete')}
|
|
171
|
+
>
|
|
172
|
+
Complete sign-in
|
|
173
|
+
</Button>
|
|
174
|
+
</>
|
|
175
|
+
)}
|
|
176
|
+
{progress.message && (
|
|
177
|
+
<Section.Note role='status'>{progress.message}</Section.Note>
|
|
178
|
+
)}
|
|
179
|
+
</Section>
|
|
180
|
+
)
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
export let Configuration = () => {
|
|
184
|
+
let secrets = useQuery(
|
|
185
|
+
vocab.comp('secret')
|
|
186
|
+
? `.secret ${vocab.comp('connection') ? '!connection ' : ''}*`
|
|
187
|
+
: '',
|
|
188
|
+
)
|
|
189
|
+
let connections = useQuery(vocab.comp('connection') ? '.connection *' : '')
|
|
190
|
+
return (
|
|
191
|
+
<>
|
|
192
|
+
<Section>
|
|
193
|
+
<Section.Title>Secrets</Section.Title>
|
|
194
|
+
<Section.Sub>
|
|
195
|
+
Values stay in the vault. Enter a replacement value or a 1Password
|
|
196
|
+
reference; saved values are never displayed.
|
|
197
|
+
</Section.Sub>
|
|
198
|
+
<Rows>
|
|
199
|
+
{secrets.map((e) => <Secret key={e.eid} e={e} />)}
|
|
200
|
+
<Secret />
|
|
201
|
+
</Rows>
|
|
202
|
+
</Section>
|
|
203
|
+
{vocab.comp('connection') && (
|
|
204
|
+
<>
|
|
205
|
+
<Authorization />
|
|
206
|
+
<Section>
|
|
207
|
+
<Section.Title>Connections</Section.Title>
|
|
208
|
+
<Rows>
|
|
209
|
+
{connections.map((e) => (
|
|
210
|
+
<Entity key={e.eid} eid={e.eid} view='Tile' />
|
|
211
|
+
))}
|
|
212
|
+
</Rows>
|
|
213
|
+
</Section>
|
|
214
|
+
</>
|
|
215
|
+
)}
|
|
216
|
+
</>
|
|
217
|
+
)
|
|
218
|
+
}
|