@octane-xplat/devtools 0.0.0-nightly.g1b95ef7 → 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -3
- package/package.json +9 -86
- package/dist/app.d.ts +0 -28
- package/dist/app.js +0 -66
- package/dist/backend.d.ts +0 -31
- package/dist/backend.js +0 -182
- package/dist/client.d.ts +0 -49
- package/dist/client.js +0 -168
- package/dist/host/desktop.d.ts +0 -15
- package/dist/host/desktop.js +0 -133
- package/dist/host/panels.d.ts +0 -14
- package/dist/host/panels.js +0 -156
- package/dist/host/records.d.ts +0 -5
- package/dist/host/records.js +0 -46
- package/dist/host/server.d.ts +0 -8
- package/dist/host/server.js +0 -67
- package/dist/host/web.d.ts +0 -5
- package/dist/host/web.js +0 -74
- package/dist/macos/index.macos.d.ts +0 -3
- package/dist/macos/index.macos.js +0 -5
- package/dist/macos/servers.macos.d.ts +0 -4
- package/dist/macos/servers.macos.js +0 -57
- package/dist/macos/socket.macos.d.ts +0 -2
- package/dist/macos/socket.macos.js +0 -152
- package/dist/macos/ws-frames.d.ts +0 -24
- package/dist/macos/ws-frames.js +0 -205
- package/dist/node.d.ts +0 -12
- package/dist/node.js +0 -51
- package/dist/record.d.ts +0 -9
- package/dist/record.js +0 -38
- package/dist/types.d.ts +0 -128
- package/dist/types.js +0 -25
- package/src/app.ts +0 -105
- package/src/assets.d.ts +0 -2
- package/src/backend.ts +0 -278
- package/src/client.ts +0 -248
- package/src/desktop/Shell.macos.tsrx +0 -158
- package/src/desktop/Shell.ts +0 -16
- package/src/desktop/index.macos.ts +0 -7
- package/src/desktop/main.macos.ts +0 -130
- package/src/desktop/panels.d.ts +0 -10
- package/src/desktop/target.ts +0 -34
- package/src/host/desktop.ts +0 -176
- package/src/host/panels.ts +0 -193
- package/src/host/records.ts +0 -62
- package/src/host/server.ts +0 -92
- package/src/host/web.ts +0 -68
- package/src/macos/index.macos.ts +0 -7
- package/src/macos/servers.macos.ts +0 -83
- package/src/macos/socket.macos.ts +0 -218
- package/src/macos/ws-frames.ts +0 -249
- package/src/node.ts +0 -60
- package/src/panel/App.tsrx +0 -288
- package/src/panel/index.html +0 -12
- package/src/panel/index.ts +0 -24
- package/src/panel/main.tsrx +0 -2
- package/src/panel/main.web.tsrx +0 -89
- package/src/panel/model.ts +0 -216
- package/src/panel/panel.css +0 -189
- package/src/panel/plugin.ts +0 -65
- package/src/panel/styles.ts +0 -5
- package/src/panel/tsconfig.browser.json +0 -9
- package/src/record.ts +0 -66
- package/src/types.ts +0 -129
package/src/panel/App.tsrx
DELETED
|
@@ -1,288 +0,0 @@
|
|
|
1
|
-
/** @jsxImportSource @octane-xplat/jsx */
|
|
2
|
-
// Shared devtools panel shell — Sessions/Actions/Logs tabs driven by a
|
|
3
|
-
// connectDevtools session. The web build wraps this in a server picker; the
|
|
4
|
-
// macOS app mounts one App per discovered record (the window is the picker).
|
|
5
|
-
import './styles'
|
|
6
|
-
import { useEffect, useLazyRef, useRef, useState } from 'octane'
|
|
7
|
-
import { useStore } from '@octane-xplat/ui/data'
|
|
8
|
-
import {
|
|
9
|
-
Button,
|
|
10
|
-
HStack,
|
|
11
|
-
Pressable,
|
|
12
|
-
Popover,
|
|
13
|
-
ScrollableArea,
|
|
14
|
-
Text,
|
|
15
|
-
VStack,
|
|
16
|
-
View,
|
|
17
|
-
type ScrollableAreaHandle,
|
|
18
|
-
} from '@octane-xplat/ui'
|
|
19
|
-
|
|
20
|
-
import type { DevtoolsServerRecord, SessionSnapshot } from '../client.ts'
|
|
21
|
-
import type { DevSocket } from '../types.ts'
|
|
22
|
-
import { PanelModel, type ActionRun, type LogLine } from './model'
|
|
23
|
-
import { resolveDevtoolsPanelPlugins, type DevtoolsPanelPlugin } from './plugin.ts'
|
|
24
|
-
|
|
25
|
-
export interface DevtoolsPanelProps {
|
|
26
|
-
/** The dev-server discovery record this panel connects to. */
|
|
27
|
-
record: DevtoolsServerRecord
|
|
28
|
-
/** Socket factory override — macOS passes nwDevSocket (no host WebSocket). */
|
|
29
|
-
socket?: (url: string) => DevSocket | undefined
|
|
30
|
-
/** Panel plugins appended after the built-in tabs. */
|
|
31
|
-
plugins?: readonly DevtoolsPanelPlugin[]
|
|
32
|
-
/** Tab to show on mount; ignored when it names no known tab. */
|
|
33
|
-
initialTab?: string
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
const TABS = [
|
|
37
|
-
{ id: 'sessions', label: 'Sessions' },
|
|
38
|
-
{ id: 'actions', label: 'Actions' },
|
|
39
|
-
{ id: 'logs', label: 'Logs' },
|
|
40
|
-
] as const
|
|
41
|
-
|
|
42
|
-
const LOG_DISPLAY = 300
|
|
43
|
-
|
|
44
|
-
function SessionRow(props: { session: SessionSnapshot; model: PanelModel }) @{
|
|
45
|
-
const session = props.session
|
|
46
|
-
const anchor = useRef<object | null>(null)
|
|
47
|
-
const [open, setOpen] = useState(false)
|
|
48
|
-
const rates = useStore(props.model.motionRates$)
|
|
49
|
-
const rate = rates.get(session.sessionId)
|
|
50
|
-
const supported =
|
|
51
|
-
session.state === 'ready' &&
|
|
52
|
-
session.channels.some((channel) => channel.id === 'xplat-motion' && channel.version === 1)
|
|
53
|
-
|
|
54
|
-
useEffect(() => {
|
|
55
|
-
if (open && supported) {
|
|
56
|
-
props.model.requestMotionRate(session)
|
|
57
|
-
}
|
|
58
|
-
}, [open, supported, session.sessionId])
|
|
59
|
-
|
|
60
|
-
<HStack className="dt-row">
|
|
61
|
-
<Text className="dt-name">{session.sessionId.slice(0, 8)}</Text>
|
|
62
|
-
<Text className="dt-meta">{session.platform ?? ''}</Text>
|
|
63
|
-
<Text className="dt-meta">{session.state ?? ''}</Text>
|
|
64
|
-
<HStack className="dt-right">
|
|
65
|
-
@for (const channel of session.channels ?? []; key channel.id) {
|
|
66
|
-
<Text className="dt-chip">{`${channel.id}@${channel.version}`}</Text>
|
|
67
|
-
}
|
|
68
|
-
<View ref={anchor}>
|
|
69
|
-
<Button label="⚙" accessibilityLabel="Session settings" onPress={() => setOpen(!open)} />
|
|
70
|
-
</View>
|
|
71
|
-
</HStack>
|
|
72
|
-
<Popover
|
|
73
|
-
anchor={anchor}
|
|
74
|
-
open={open}
|
|
75
|
-
onDismiss={() => setOpen(false)}
|
|
76
|
-
placement="bottom"
|
|
77
|
-
alignment="end"
|
|
78
|
-
>
|
|
79
|
-
<VStack className="dt-session-settings">
|
|
80
|
-
<Text className="dt-name">Motion speed</Text>
|
|
81
|
-
@if (supported) {
|
|
82
|
-
<>
|
|
83
|
-
<Text className="dt-meta">
|
|
84
|
-
{rate === undefined ? 'Reading speed…' : `${rate}×`}
|
|
85
|
-
</Text>
|
|
86
|
-
<HStack className="dt-right">
|
|
87
|
-
<Button
|
|
88
|
-
label="Normal (1×)"
|
|
89
|
-
onPress={() => props.model.requestMotionRate(session, 1)}
|
|
90
|
-
/>
|
|
91
|
-
<Button
|
|
92
|
-
label="Slow (0.25×)"
|
|
93
|
-
onPress={() => props.model.requestMotionRate(session, 0.25)}
|
|
94
|
-
/>
|
|
95
|
-
</HStack>
|
|
96
|
-
<Text className="dt-meta">Also slows delays tied to animations.</Text>
|
|
97
|
-
</>
|
|
98
|
-
} @else {
|
|
99
|
-
<Text className="dt-meta">Unavailable for this session.</Text>
|
|
100
|
-
}
|
|
101
|
-
</VStack>
|
|
102
|
-
</Popover>
|
|
103
|
-
</HStack>
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
function ActionRow(props: {
|
|
107
|
-
action: NonNullable<SessionSnapshot['actions']>[number]
|
|
108
|
-
run: ActionRun | undefined
|
|
109
|
-
onRun: () => void
|
|
110
|
-
}) @{
|
|
111
|
-
const action = props.action
|
|
112
|
-
const run = props.run
|
|
113
|
-
|
|
114
|
-
<>
|
|
115
|
-
<HStack className="dt-row">
|
|
116
|
-
<Text className="dt-name">{action.id}</Text>
|
|
117
|
-
{action.title ? <Text className="dt-meta">{action.title}</Text> : null}
|
|
118
|
-
<HStack className="dt-right">
|
|
119
|
-
@if (action.availability?.ready === false) {
|
|
120
|
-
<Text className="dt-meta">unavailable</Text>
|
|
121
|
-
} @else {
|
|
122
|
-
<Button
|
|
123
|
-
className="dt-run"
|
|
124
|
-
label={run?.status === 'running' ? '…' : 'Run'}
|
|
125
|
-
isDisabled={run?.status === 'running'}
|
|
126
|
-
onPress={props.onRun}
|
|
127
|
-
/>
|
|
128
|
-
}
|
|
129
|
-
</HStack>
|
|
130
|
-
</HStack>
|
|
131
|
-
@if (run && run.status !== 'running') {
|
|
132
|
-
<VStack className={['dt-outcome', `dt-outcome-${run.status}`]}>
|
|
133
|
-
<Text className="dt-outcome-status">{run.status}</Text>
|
|
134
|
-
{run.error ? (
|
|
135
|
-
<Text className="dt-pre">{JSON.stringify(run.error, null, 2)}</Text>
|
|
136
|
-
) : null}
|
|
137
|
-
{run.result !== undefined ? (
|
|
138
|
-
<Text className="dt-pre">{JSON.stringify(run.result, null, 2)}</Text>
|
|
139
|
-
) : null}
|
|
140
|
-
</VStack>
|
|
141
|
-
}
|
|
142
|
-
</>
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
function LogRow(props: { record: LogLine }) @{
|
|
146
|
-
const record = props.record
|
|
147
|
-
|
|
148
|
-
<HStack className={['dt-log-line', `dt-log-${record.level}`]}>
|
|
149
|
-
<Text className="dt-level">{record.level}</Text>
|
|
150
|
-
<Text className="dt-text">{record.line}</Text>
|
|
151
|
-
<Text className="dt-at">{(record.at ?? '').slice(11, 19)}</Text>
|
|
152
|
-
</HStack>
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
export function App(props: DevtoolsPanelProps) @{
|
|
156
|
-
const model = useLazyRef(() => new PanelModel())
|
|
157
|
-
const plugins = useLazyRef(() => resolveDevtoolsPanelPlugins(props.plugins ?? []))
|
|
158
|
-
const tabs = [
|
|
159
|
-
...TABS,
|
|
160
|
-
...plugins.current.map((plugin) => ({ id: plugin.id, label: plugin.title })),
|
|
161
|
-
]
|
|
162
|
-
|
|
163
|
-
const [tab, setTab] = useState<string>(
|
|
164
|
-
tabs.some((item) => item.id === props.initialTab) ? props.initialTab! : 'sessions',
|
|
165
|
-
)
|
|
166
|
-
const [connectionVersion, setConnectionVersion] = useState(0)
|
|
167
|
-
|
|
168
|
-
const scrollRef = useRef<ScrollableAreaHandle | null>(null)
|
|
169
|
-
|
|
170
|
-
useEffect(() => {
|
|
171
|
-
model.current.connect(props.record, props.socket)
|
|
172
|
-
setConnectionVersion((version) => version + 1)
|
|
173
|
-
return () => model.current.dispose()
|
|
174
|
-
}, [props.record.instanceId, props.socket])
|
|
175
|
-
|
|
176
|
-
const connState = useStore(model.current.connState$)
|
|
177
|
-
const panel = useStore(model.current.panel$)
|
|
178
|
-
const sessions = useStore(model.current.sessions$)
|
|
179
|
-
const backends = useStore(model.current.backends$)
|
|
180
|
-
const logs = useStore(model.current.logs$)
|
|
181
|
-
const runs = useStore(model.current.runs$)
|
|
182
|
-
const logTarget = useStore(model.current.logTarget$)
|
|
183
|
-
|
|
184
|
-
// Newest log line stays pinned to the viewport end — the scrollIntoView
|
|
185
|
-
// behavior of the retired DOM panel.
|
|
186
|
-
useEffect(() => {
|
|
187
|
-
if (tab === 'logs' && logs.length) {
|
|
188
|
-
scrollRef.current?.scrollToOffset({ block: Number.MAX_SAFE_INTEGER })
|
|
189
|
-
}
|
|
190
|
-
}, [logs.length, tab])
|
|
191
|
-
|
|
192
|
-
const badge = connState === 'live' ? `live — ${panel ?? ''}` : connState
|
|
193
|
-
const withActions = sessions.filter((session) => session.actions?.length)
|
|
194
|
-
const pluginTab = plugins.current.find((plugin) => plugin.id === tab)
|
|
195
|
-
const connection = model.current.connection
|
|
196
|
-
|
|
197
|
-
<VStack className="dt-root">
|
|
198
|
-
<HStack className="dt-nav">
|
|
199
|
-
<HStack className="dt-tabs">
|
|
200
|
-
@for (const item of tabs; key item.id) {
|
|
201
|
-
<Pressable
|
|
202
|
-
className={['dt-tab', tab === item.id && 'dt-tab-active']}
|
|
203
|
-
onPress={() => setTab(item.id)}
|
|
204
|
-
>
|
|
205
|
-
<Text className="dt-tab-label">{item.label}</Text>
|
|
206
|
-
</Pressable>
|
|
207
|
-
}
|
|
208
|
-
</HStack>
|
|
209
|
-
<Text className={['dt-badge', `dt-badge-${connState}`]}>{badge}</Text>
|
|
210
|
-
</HStack>
|
|
211
|
-
@if (pluginTab) {
|
|
212
|
-
// Plugin tabs own their own scrolling — no dt-main ScrollableArea.
|
|
213
|
-
<VStack className="dt-plugin-host">
|
|
214
|
-
@if (connection) {
|
|
215
|
-
// Plugins bind their subscriptions to the connection they mount with.
|
|
216
|
-
<pluginTab.Panel key={connectionVersion} connection={connection} state={connState} />
|
|
217
|
-
}
|
|
218
|
-
</VStack>
|
|
219
|
-
} @else {
|
|
220
|
-
<ScrollableArea className="dt-main" ref={scrollRef}>
|
|
221
|
-
<VStack className="dt-content">
|
|
222
|
-
@if (tab === 'sessions') {
|
|
223
|
-
<>
|
|
224
|
-
<Text
|
|
225
|
-
className={['dt-heading', 'dt-heading-first']}
|
|
226
|
-
>{`Sessions (${sessions.length})`}</Text>
|
|
227
|
-
@if (!sessions.length) {
|
|
228
|
-
<Text className="dt-empty">No app sessions connected.</Text>
|
|
229
|
-
}
|
|
230
|
-
@for (const session of sessions; key session.sessionId) {
|
|
231
|
-
<SessionRow session={session} model={model.current} />
|
|
232
|
-
}
|
|
233
|
-
<Text className="dt-heading">{`Backends (${backends.length})`}</Text>
|
|
234
|
-
@if (!backends.length) {
|
|
235
|
-
<Text className="dt-empty">No engine backends connected.</Text>
|
|
236
|
-
}
|
|
237
|
-
@for (const backend of backends; key `${backend.channel}:${backend.targetId}`) {
|
|
238
|
-
<HStack className="dt-row">
|
|
239
|
-
<Text className="dt-name">{backend.channel}</Text>
|
|
240
|
-
<Text className="dt-meta">{backend.targetId}</Text>
|
|
241
|
-
</HStack>
|
|
242
|
-
}
|
|
243
|
-
</>
|
|
244
|
-
} @else if (tab === 'actions') {
|
|
245
|
-
<>
|
|
246
|
-
@if (!withActions.length) {
|
|
247
|
-
<Text className="dt-empty">
|
|
248
|
-
No session declares dev actions.
|
|
249
|
-
</Text>
|
|
250
|
-
}
|
|
251
|
-
@for (const session of withActions; key session.sessionId) {
|
|
252
|
-
<>
|
|
253
|
-
<Text className={['dt-heading', 'dt-heading-first']}>
|
|
254
|
-
{`${session.sessionId.slice(0, 8)} — ${session.platform ?? 'app'}`}
|
|
255
|
-
</Text>
|
|
256
|
-
@for (const action of session.actions ?? []; key action.id) {
|
|
257
|
-
<ActionRow
|
|
258
|
-
action={action}
|
|
259
|
-
run={runs.get(action.id)}
|
|
260
|
-
onRun={() => model.current.invoke(session, action.id)}
|
|
261
|
-
/>
|
|
262
|
-
}
|
|
263
|
-
</>
|
|
264
|
-
}
|
|
265
|
-
</>
|
|
266
|
-
} @else {
|
|
267
|
-
<>
|
|
268
|
-
<HStack className="dt-toolbar">
|
|
269
|
-
<Text className="dt-meta">
|
|
270
|
-
{logTarget ? `target ${logTarget}` : 'no xplat-logs backend'}
|
|
271
|
-
</Text>
|
|
272
|
-
<HStack className="dt-right">
|
|
273
|
-
<Button label="Clear" onPress={() => model.current.clearLogs()} />
|
|
274
|
-
</HStack>
|
|
275
|
-
</HStack>
|
|
276
|
-
@if (!logs.length) {
|
|
277
|
-
<Text className="dt-empty">No log records yet.</Text>
|
|
278
|
-
}
|
|
279
|
-
@for (const record of logs.slice(-LOG_DISPLAY); index i; key i) {
|
|
280
|
-
<LogRow record={record} />
|
|
281
|
-
}
|
|
282
|
-
</>
|
|
283
|
-
}
|
|
284
|
-
</VStack>
|
|
285
|
-
</ScrollableArea>
|
|
286
|
-
}
|
|
287
|
-
</VStack>
|
|
288
|
-
}
|
package/src/panel/index.html
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
<!doctype html>
|
|
2
|
-
<html>
|
|
3
|
-
<head>
|
|
4
|
-
<meta charset="utf-8" />
|
|
5
|
-
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
6
|
-
<title>Octane Xplat Devtools</title>
|
|
7
|
-
</head>
|
|
8
|
-
<body>
|
|
9
|
-
<div id="root"></div>
|
|
10
|
-
<script type="module" src="./main.web.tsrx"></script>
|
|
11
|
-
</body>
|
|
12
|
-
</html>
|
package/src/panel/index.ts
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
// Shared devtools panel — `@octane-xplat/devtools/panel`. The web build wraps
|
|
2
|
-
// App in a server picker (main.web.tsrx); the macOS app targets one record
|
|
3
|
-
// through the Shell. `plugin.ts` is the panel-plugin contract — a package
|
|
4
|
-
// default-exports a `defineDevtoolsPanel` result from the subpath named by
|
|
5
|
-
// its `octaneXplat.devtoolsPanel` field, and App renders it as a tab after
|
|
6
|
-
// the built-ins. The generic web panel (/devtools/app/) shows the built-ins;
|
|
7
|
-
// the project browser build and macOS launch include discovered plugins.
|
|
8
|
-
|
|
9
|
-
export { App } from './App.tsrx'
|
|
10
|
-
export type { DevtoolsPanelProps } from './App.tsrx'
|
|
11
|
-
export { PanelModel } from './model'
|
|
12
|
-
export type { DevSocketFactory, LogLine, ActionRun } from './model'
|
|
13
|
-
export { defineDevtoolsPanel, resolveDevtoolsPanelPlugins } from './plugin.ts'
|
|
14
|
-
export type { DevtoolsPanelPlugin, DevtoolsPanelPluginProps } from './plugin.ts'
|
|
15
|
-
export type {
|
|
16
|
-
BackendRef,
|
|
17
|
-
DevtoolsConnection,
|
|
18
|
-
DevtoolsMessage,
|
|
19
|
-
DevtoolsServerRecord,
|
|
20
|
-
SessionSnapshot,
|
|
21
|
-
} from '../client.ts'
|
|
22
|
-
|
|
23
|
-
export type { ListedDevtoolsServer } from '../record.ts'
|
|
24
|
-
export type { DevSocket } from '../types.ts'
|
package/src/panel/main.tsrx
DELETED
package/src/panel/main.web.tsrx
DELETED
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
/** @jsxImportSource @octane-xplat/jsx/dom */
|
|
2
|
-
// Web entry for the devtools panel — a thin picker over the shared App: fetch
|
|
3
|
-
// /devtools/servers from the hosting dev server, keep the selected record,
|
|
4
|
-
// and let App own the connection. Served under /devtools/app/ by `xplat dev`.
|
|
5
|
-
import { createRoot, useEffect, useState } from 'octane'
|
|
6
|
-
import { App } from './App.tsrx'
|
|
7
|
-
import type { ListedDevtoolsServer } from '../record.ts'
|
|
8
|
-
import plugins from 'virtual:octane-devtools-panels'
|
|
9
|
-
|
|
10
|
-
declare const __XPLAT_DEVTOOLS_PROJECT__: string | null
|
|
11
|
-
|
|
12
|
-
async function fetchServers(): Promise<ListedDevtoolsServer[]> {
|
|
13
|
-
try {
|
|
14
|
-
const body = (await (await fetch('/devtools/servers')).json()) as {
|
|
15
|
-
servers?: ListedDevtoolsServer[]
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
const servers = Array.isArray(body.servers) ? body.servers : []
|
|
19
|
-
return __XPLAT_DEVTOOLS_PROJECT__
|
|
20
|
-
? servers.filter((server) => server.appRoot === __XPLAT_DEVTOOLS_PROJECT__)
|
|
21
|
-
: servers
|
|
22
|
-
} catch {
|
|
23
|
-
return []
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
function Picker() {
|
|
28
|
-
const [servers, setServers] = useState<ListedDevtoolsServer[]>([])
|
|
29
|
-
const [record, setRecord] = useState<ListedDevtoolsServer | null>(null)
|
|
30
|
-
|
|
31
|
-
const refresh = async () => {
|
|
32
|
-
const next = await fetchServers()
|
|
33
|
-
|
|
34
|
-
setServers(next)
|
|
35
|
-
setRecord((current) => {
|
|
36
|
-
if (current && next.some((server) => server.key === current.key)) {
|
|
37
|
-
return current
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
return next[0] ?? null
|
|
41
|
-
})
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
useEffect(() => {
|
|
45
|
-
void refresh()
|
|
46
|
-
}, [])
|
|
47
|
-
|
|
48
|
-
return (
|
|
49
|
-
<div className="dt-shell">
|
|
50
|
-
<header className="dt-header">
|
|
51
|
-
<span className="dt-brand">devtools</span>
|
|
52
|
-
<select
|
|
53
|
-
className="dt-select"
|
|
54
|
-
aria-label="Dev server"
|
|
55
|
-
value={record?.key ?? ''}
|
|
56
|
-
onChange={(event) => {
|
|
57
|
-
const key = (event.target as HTMLSelectElement).value
|
|
58
|
-
|
|
59
|
-
setRecord(servers.find((server) => server.key === key) ?? null)
|
|
60
|
-
}}
|
|
61
|
-
>
|
|
62
|
-
{servers.length ? (
|
|
63
|
-
servers.map((server) => (
|
|
64
|
-
<option key={server.key} value={server.key}>
|
|
65
|
-
{server.appRoot}
|
|
66
|
-
</option>
|
|
67
|
-
))
|
|
68
|
-
) : (
|
|
69
|
-
<option value="">No xplat dev servers found</option>
|
|
70
|
-
)}
|
|
71
|
-
</select>
|
|
72
|
-
<button
|
|
73
|
-
className="dt-refresh"
|
|
74
|
-
title="Rescan dev server records"
|
|
75
|
-
onClick={() => void refresh()}
|
|
76
|
-
>
|
|
77
|
-
Refresh
|
|
78
|
-
</button>
|
|
79
|
-
</header>
|
|
80
|
-
{record ? (
|
|
81
|
-
<App key={record.key} record={record} plugins={plugins} />
|
|
82
|
-
) : (
|
|
83
|
-
<div className="dt-empty">Pick a dev server above to connect.</div>
|
|
84
|
-
)}
|
|
85
|
-
</div>
|
|
86
|
-
)
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
createRoot(document.getElementById('root')!).render(<Picker />)
|
package/src/panel/model.ts
DELETED
|
@@ -1,216 +0,0 @@
|
|
|
1
|
-
// Hook-free panel model — owns the connectDevtools lifecycle and exposes each
|
|
2
|
-
// render slice as a store. Actions go through the reserved xplat-actions app
|
|
3
|
-
// channel; logs come from the xplat-logs engine backend. Behavior mirrors the
|
|
4
|
-
// retired vanilla panel (app/panel.js): bare outcomes map back to actions by
|
|
5
|
-
// requestId, logs subscribe on the backend ref's first appearance, and the log
|
|
6
|
-
// view keeps the newest 500 records.
|
|
7
|
-
|
|
8
|
-
import { createStore } from '@octane-xplat/ui/data'
|
|
9
|
-
import {
|
|
10
|
-
connectDevtools,
|
|
11
|
-
type BackendRef,
|
|
12
|
-
type DevtoolsConnection,
|
|
13
|
-
type DevtoolsServerRecord,
|
|
14
|
-
type SessionSnapshot,
|
|
15
|
-
} from '../client.ts'
|
|
16
|
-
|
|
17
|
-
import type { DevSocket } from '../types.ts'
|
|
18
|
-
|
|
19
|
-
export type DevSocketFactory = (url: string) => DevSocket | undefined
|
|
20
|
-
|
|
21
|
-
export interface LogLine {
|
|
22
|
-
level: string
|
|
23
|
-
line: string
|
|
24
|
-
at?: string
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export interface ActionRun {
|
|
28
|
-
status: string
|
|
29
|
-
result?: unknown
|
|
30
|
-
error?: unknown
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
const LOG_KEEP = 500
|
|
34
|
-
|
|
35
|
-
export class PanelModel {
|
|
36
|
-
readonly connState$ = createStore<'connecting' | 'live' | 'closed'>('connecting')
|
|
37
|
-
readonly panel$ = createStore<string | null>(null)
|
|
38
|
-
readonly sessions$ = createStore<readonly SessionSnapshot[]>([])
|
|
39
|
-
readonly backends$ = createStore<readonly BackendRef[]>([])
|
|
40
|
-
readonly logs$ = createStore<readonly LogLine[]>([])
|
|
41
|
-
readonly runs$ = createStore<ReadonlyMap<string, ActionRun>>(new Map())
|
|
42
|
-
readonly motionRates$ = createStore<ReadonlyMap<string, number>>(new Map())
|
|
43
|
-
readonly logTarget$ = createStore<string | null>(null)
|
|
44
|
-
|
|
45
|
-
private conn: DevtoolsConnection | null = null
|
|
46
|
-
private readonly requests = new Map<string, string>()
|
|
47
|
-
private readonly runs = new Map<string, ActionRun>()
|
|
48
|
-
private logs: LogLine[] = []
|
|
49
|
-
private requestCounter = 0
|
|
50
|
-
|
|
51
|
-
connect(record: DevtoolsServerRecord, socket?: DevSocketFactory) {
|
|
52
|
-
this.dispose()
|
|
53
|
-
this.requests.clear()
|
|
54
|
-
this.runs.clear()
|
|
55
|
-
this.logs = []
|
|
56
|
-
this.connState$.set('connecting')
|
|
57
|
-
this.panel$.set(null)
|
|
58
|
-
this.sessions$.set([])
|
|
59
|
-
this.backends$.set([])
|
|
60
|
-
this.logs$.set([])
|
|
61
|
-
this.runs$.set(new Map())
|
|
62
|
-
this.logTarget$.set(null)
|
|
63
|
-
this.motionRates$.set(new Map())
|
|
64
|
-
|
|
65
|
-
const conn = connectDevtools(record, socket ? { socket } : {})
|
|
66
|
-
|
|
67
|
-
this.conn = conn
|
|
68
|
-
|
|
69
|
-
conn.onState((state) => {
|
|
70
|
-
this.connState$.set(state)
|
|
71
|
-
this.panel$.set(conn.panel)
|
|
72
|
-
// The ready frame seeds sessions/backends without firing their
|
|
73
|
-
// listeners — read the snapshots when the connection goes live.
|
|
74
|
-
if (state === 'live') {
|
|
75
|
-
this.sessions$.set(conn.sessions())
|
|
76
|
-
this.backends$.set(conn.backends())
|
|
77
|
-
this.subscribeLogs()
|
|
78
|
-
}
|
|
79
|
-
})
|
|
80
|
-
|
|
81
|
-
conn.onSessions((sessions) => {
|
|
82
|
-
this.sessions$.set(sessions)
|
|
83
|
-
})
|
|
84
|
-
|
|
85
|
-
conn.onBackends((backends) => {
|
|
86
|
-
this.backends$.set(backends)
|
|
87
|
-
this.subscribeLogs()
|
|
88
|
-
})
|
|
89
|
-
|
|
90
|
-
conn.subscribe((message) => {
|
|
91
|
-
if (
|
|
92
|
-
message.channel === 'xplat-motion' &&
|
|
93
|
-
message.from === 'app' &&
|
|
94
|
-
isMotionState(message.data)
|
|
95
|
-
) {
|
|
96
|
-
const rates = new Map(this.motionRates$.getSnapshot())
|
|
97
|
-
|
|
98
|
-
rates.set(message.session, message.data.rate)
|
|
99
|
-
this.motionRates$.set(rates)
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
if (message.channel === 'xplat-actions' && isOutcome(message.data)) {
|
|
103
|
-
const actionId = this.requests.get(message.data.outcome.requestId)
|
|
104
|
-
|
|
105
|
-
if (actionId) {
|
|
106
|
-
this.runs.set(actionId, message.data.outcome)
|
|
107
|
-
this.runs$.set(new Map(this.runs))
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
if (message.channel === 'xplat-logs' && isLogFrame(message.data)) {
|
|
112
|
-
this.logs.push(...message.data.records)
|
|
113
|
-
if (this.logs.length > LOG_KEEP) {
|
|
114
|
-
this.logs.splice(0, this.logs.length - LOG_KEEP)
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
this.logs$.set([...this.logs])
|
|
118
|
-
}
|
|
119
|
-
})
|
|
120
|
-
|
|
121
|
-
this.connState$.set(conn.state)
|
|
122
|
-
this.panel$.set(conn.panel)
|
|
123
|
-
this.subscribeLogs()
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
/** The live panel connection — panel plugins talk to sessions/backends
|
|
127
|
-
* through it instead of opening their own. */
|
|
128
|
-
get connection(): DevtoolsConnection | null {
|
|
129
|
-
return this.conn
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
requestMotionRate(session: SessionSnapshot, rate?: number) {
|
|
133
|
-
return (
|
|
134
|
-
this.conn?.sendToApp('xplat-motion', session.sessionId, {
|
|
135
|
-
type: rate === undefined ? 'get' : 'set',
|
|
136
|
-
requestId: nextRequestId(++this.requestCounter),
|
|
137
|
-
rate,
|
|
138
|
-
}) ?? false
|
|
139
|
-
)
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
invoke(session: SessionSnapshot, actionId: string) {
|
|
143
|
-
const requestId = nextRequestId(++this.requestCounter)
|
|
144
|
-
|
|
145
|
-
this.requests.set(requestId, actionId)
|
|
146
|
-
this.runs.set(actionId, { status: 'running' })
|
|
147
|
-
this.runs$.set(new Map(this.runs))
|
|
148
|
-
this.conn?.sendToApp('xplat-actions', session.sessionId, {
|
|
149
|
-
type: 'invoke',
|
|
150
|
-
requestId,
|
|
151
|
-
actionId,
|
|
152
|
-
input: {},
|
|
153
|
-
})
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
clearLogs() {
|
|
157
|
-
this.logs = []
|
|
158
|
-
this.logs$.set([])
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
dispose() {
|
|
162
|
-
this.conn?.close()
|
|
163
|
-
this.conn = null
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
private subscribeLogs() {
|
|
167
|
-
const backend = this.backends$.getSnapshot().find((ref) => ref.channel === 'xplat-logs')
|
|
168
|
-
|
|
169
|
-
if (!backend || backend.targetId === this.logTarget$.getSnapshot() || !this.conn) {
|
|
170
|
-
return
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
this.logTarget$.set(backend.targetId)
|
|
174
|
-
this.conn.sendToBackend('xplat-logs', backend.targetId, { type: 'subscribe' })
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
function isOutcome(
|
|
179
|
-
data: unknown,
|
|
180
|
-
): data is { type: 'outcome'; outcome: ActionRun & { requestId: string } } {
|
|
181
|
-
return (
|
|
182
|
-
typeof data === 'object' &&
|
|
183
|
-
data !== null &&
|
|
184
|
-
(data as { type?: unknown }).type === 'outcome' &&
|
|
185
|
-
typeof (data as { outcome?: { requestId?: unknown } }).outcome?.requestId === 'string'
|
|
186
|
-
)
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
function isLogFrame(data: unknown): data is { records: LogLine[] } {
|
|
190
|
-
return (
|
|
191
|
-
typeof data === 'object' &&
|
|
192
|
-
data !== null &&
|
|
193
|
-
Array.isArray((data as { records?: unknown }).records)
|
|
194
|
-
)
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
function nextRequestId(counter: number): string {
|
|
198
|
-
const crypto = (globalThis as { crypto?: { randomUUID?: () => string } }).crypto
|
|
199
|
-
|
|
200
|
-
return typeof crypto?.randomUUID === 'function'
|
|
201
|
-
? crypto.randomUUID()
|
|
202
|
-
: `req-${Date.now()}-${counter}`
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
function isMotionState(value: unknown): value is { type: 'state'; rate: number } {
|
|
206
|
-
return (
|
|
207
|
-
!!value &&
|
|
208
|
-
typeof value === 'object' &&
|
|
209
|
-
'type' in value &&
|
|
210
|
-
value.type === 'state' &&
|
|
211
|
-
'rate' in value &&
|
|
212
|
-
typeof value.rate === 'number' &&
|
|
213
|
-
value.rate > 0 &&
|
|
214
|
-
value.rate <= 1
|
|
215
|
-
)
|
|
216
|
-
}
|