@swirls/shuttle 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +10 -0
- package/LICENSE +190 -0
- package/NOTICE +5 -0
- package/README.md +42 -2
- package/dist/api/auth.d.ts +18 -0
- package/dist/api/auth.js +15 -0
- package/dist/api/common.d.ts +8 -0
- package/dist/api/common.js +4 -0
- package/dist/api/connections.d.ts +292 -0
- package/dist/api/connections.js +114 -0
- package/dist/api/github.d.ts +20 -0
- package/dist/api/github.js +13 -0
- package/dist/api/harness.d.ts +97 -0
- package/dist/api/harness.js +47 -0
- package/dist/api/index.d.ts +2059 -0
- package/dist/api/index.js +37 -0
- package/dist/api/runners.d.ts +93 -0
- package/dist/api/runners.js +45 -0
- package/dist/api/sandbox.d.ts +550 -0
- package/dist/api/sandbox.js +210 -0
- package/dist/api/sessions.d.ts +318 -0
- package/dist/api/sessions.js +154 -0
- package/dist/api/tenant.d.ts +54 -0
- package/dist/api/tenant.js +19 -0
- package/dist/api/timings.d.ts +36 -0
- package/dist/api/timings.js +48 -0
- package/dist/api/workspace.d.ts +738 -0
- package/dist/api/workspace.js +246 -0
- package/dist/core/pulls.d.ts +1001 -0
- package/dist/core/pulls.js +170 -0
- package/dist/core/workspace.d.ts +985 -0
- package/dist/core/workspace.js +174 -0
- package/dist/react/components/command-palette.d.ts +22 -0
- package/dist/react/components/command-palette.js +66 -0
- package/dist/react/components/follow-list.d.ts +20 -0
- package/dist/react/components/follow-list.js +98 -0
- package/dist/react/components/json-tree.d.ts +11 -0
- package/dist/react/components/json-tree.js +120 -0
- package/dist/react/components/markdown.d.ts +5 -0
- package/dist/react/components/markdown.js +29 -0
- package/dist/react/components/shuttle-mark.d.ts +7 -0
- package/dist/react/components/shuttle-mark.js +9 -0
- package/dist/react/components/status-dot.d.ts +9 -0
- package/dist/react/components/status-dot.js +27 -0
- package/dist/react/components/status.d.ts +6 -0
- package/dist/react/components/status.js +66 -0
- package/dist/react/components/ui/badge.d.ts +7 -0
- package/dist/react/components/ui/badge.js +19 -0
- package/dist/react/components/ui/button.d.ts +10 -0
- package/dist/react/components/ui/button.js +40 -0
- package/dist/react/components/ui/dialog.d.ts +19 -0
- package/dist/react/components/ui/dialog.js +34 -0
- package/dist/react/components/ui/dropdown-menu.d.ts +14 -0
- package/dist/react/components/ui/dropdown-menu.js +33 -0
- package/dist/react/components/ui/input.d.ts +3 -0
- package/dist/react/components/ui/input.js +6 -0
- package/dist/react/components/ui/panel.d.ts +18 -0
- package/dist/react/components/ui/panel.js +22 -0
- package/dist/react/components/ui/popover.d.ts +7 -0
- package/dist/react/components/ui/popover.js +16 -0
- package/dist/react/components/ui/resizable.d.ts +7 -0
- package/dist/react/components/ui/resizable.js +14 -0
- package/dist/react/components/ui/scroll-area.d.ts +14 -0
- package/dist/react/components/ui/scroll-area.js +12 -0
- package/dist/react/components/ui/select.d.ts +10 -0
- package/dist/react/components/ui/select.js +20 -0
- package/dist/react/components/ui/sheet.d.ts +8 -0
- package/dist/react/components/ui/sheet.js +20 -0
- package/dist/react/components/ui/tabs.d.ts +7 -0
- package/dist/react/components/ui/tabs.js +16 -0
- package/dist/react/components/ui/textarea.d.ts +3 -0
- package/dist/react/components/ui/textarea.js +6 -0
- package/dist/react/components/ui/tooltip.d.ts +8 -0
- package/dist/react/components/ui/tooltip.js +17 -0
- package/dist/react/features/artifacts/artifact-links.d.ts +9 -0
- package/dist/react/features/artifacts/artifact-links.js +38 -0
- package/dist/react/features/artifacts/artifact-pane.d.ts +19 -0
- package/dist/react/features/artifacts/artifact-pane.js +64 -0
- package/dist/react/features/artifacts/artifact-types.d.ts +59 -0
- package/dist/react/features/artifacts/artifact-types.js +69 -0
- package/dist/react/features/artifacts/browser-viewer.d.ts +5 -0
- package/dist/react/features/artifacts/browser-viewer.js +60 -0
- package/dist/react/features/artifacts/diff-style.d.ts +10 -0
- package/dist/react/features/artifacts/diff-style.js +21 -0
- package/dist/react/features/artifacts/file-pane.d.ts +13 -0
- package/dist/react/features/artifacts/file-pane.js +305 -0
- package/dist/react/features/artifacts/file-quick-open.d.ts +15 -0
- package/dist/react/features/artifacts/file-quick-open.js +74 -0
- package/dist/react/features/artifacts/file-search.d.ts +12 -0
- package/dist/react/features/artifacts/file-search.js +90 -0
- package/dist/react/features/artifacts/media-viewer.d.ts +8 -0
- package/dist/react/features/artifacts/media-viewer.js +41 -0
- package/dist/react/features/artifacts/review-diff.d.ts +19 -0
- package/dist/react/features/artifacts/review-diff.js +59 -0
- package/dist/react/features/artifacts/review-viewer.d.ts +4 -0
- package/dist/react/features/artifacts/review-viewer.js +337 -0
- package/dist/react/features/artifacts/sandbox.d.ts +43 -0
- package/dist/react/features/artifacts/sandbox.js +109 -0
- package/dist/react/features/artifacts/tab-strip.d.ts +11 -0
- package/dist/react/features/artifacts/tab-strip.js +55 -0
- package/dist/react/features/artifacts/terminal-theme.d.ts +34 -0
- package/dist/react/features/artifacts/terminal-theme.js +62 -0
- package/dist/react/features/artifacts/terminal-viewer.d.ts +5 -0
- package/dist/react/features/artifacts/terminal-viewer.js +209 -0
- package/dist/react/features/artifacts/unified-diff.d.ts +16 -0
- package/dist/react/features/artifacts/unified-diff.js +55 -0
- package/dist/react/features/artifacts/workspace-viewer.d.ts +16 -0
- package/dist/react/features/artifacts/workspace-viewer.js +275 -0
- package/dist/react/features/connections/agent-sign-in.d.ts +71 -0
- package/dist/react/features/connections/agent-sign-in.js +251 -0
- package/dist/react/features/connections/connections-panel.d.ts +8 -0
- package/dist/react/features/connections/connections-panel.js +42 -0
- package/dist/react/features/connections/login.d.ts +24 -0
- package/dist/react/features/connections/login.js +35 -0
- package/dist/react/features/connections/places.d.ts +20 -0
- package/dist/react/features/connections/places.js +27 -0
- package/dist/react/features/connections/queries.d.ts +28 -0
- package/dist/react/features/connections/queries.js +8 -0
- package/dist/react/features/events/event-cache.d.ts +4 -0
- package/dist/react/features/events/event-cache.js +29 -0
- package/dist/react/features/events/event-catalog.d.ts +17 -0
- package/dist/react/features/events/event-catalog.js +261 -0
- package/dist/react/features/events/event-inspector.d.ts +7 -0
- package/dist/react/features/events/event-inspector.js +29 -0
- package/dist/react/features/events/event-row.d.ts +21 -0
- package/dist/react/features/events/event-row.js +34 -0
- package/dist/react/features/events/event-stream.d.ts +18 -0
- package/dist/react/features/events/event-stream.js +58 -0
- package/dist/react/features/events/global-events.d.ts +122 -0
- package/dist/react/features/events/global-events.js +329 -0
- package/dist/react/features/events/shuttle-events.d.ts +7 -0
- package/dist/react/features/events/shuttle-events.js +1 -0
- package/dist/react/features/playbook/playbook-page.d.ts +2 -0
- package/dist/react/features/playbook/playbook-page.js +36 -0
- package/dist/react/features/playbook/playbook-query.d.ts +111 -0
- package/dist/react/features/playbook/playbook-query.js +17 -0
- package/dist/react/features/pulls/linked-session.d.ts +12 -0
- package/dist/react/features/pulls/linked-session.js +22 -0
- package/dist/react/features/pulls/pull-detail-sheet.d.ts +10 -0
- package/dist/react/features/pulls/pull-detail-sheet.js +41 -0
- package/dist/react/features/pulls/pull-fixtures.d.ts +8 -0
- package/dist/react/features/pulls/pull-fixtures.js +258 -0
- package/dist/react/features/pulls/pull-glyphs.d.ts +24 -0
- package/dist/react/features/pulls/pull-glyphs.js +89 -0
- package/dist/react/features/pulls/pull-inbox-list.d.ts +13 -0
- package/dist/react/features/pulls/pull-inbox-list.js +230 -0
- package/dist/react/features/pulls/pull-inbox-pref.d.ts +2 -0
- package/dist/react/features/pulls/pull-inbox-pref.js +19 -0
- package/dist/react/features/pulls/pull-inbox.d.ts +30 -0
- package/dist/react/features/pulls/pull-inbox.js +110 -0
- package/dist/react/features/pulls/pull-threads.d.ts +39 -0
- package/dist/react/features/pulls/pull-threads.js +145 -0
- package/dist/react/features/pulls/pulls.d.ts +120 -0
- package/dist/react/features/pulls/pulls.js +414 -0
- package/dist/react/features/pulls/session-pull-groups.d.ts +14 -0
- package/dist/react/features/pulls/session-pull-groups.js +29 -0
- package/dist/react/features/pulls/stack-ladder.d.ts +9 -0
- package/dist/react/features/pulls/stack-ladder.js +32 -0
- package/dist/react/features/sessions/agent-tree.d.ts +16 -0
- package/dist/react/features/sessions/agent-tree.js +100 -0
- package/dist/react/features/sessions/agents.d.ts +34 -0
- package/dist/react/features/sessions/agents.js +146 -0
- package/dist/react/features/sessions/attention.d.ts +32 -0
- package/dist/react/features/sessions/attention.js +42 -0
- package/dist/react/features/sessions/composer-attachments.d.ts +33 -0
- package/dist/react/features/sessions/composer-attachments.js +126 -0
- package/dist/react/features/sessions/composer.d.ts +15 -0
- package/dist/react/features/sessions/composer.js +327 -0
- package/dist/react/features/sessions/context-usage-meter.d.ts +5 -0
- package/dist/react/features/sessions/context-usage-meter.js +122 -0
- package/dist/react/features/sessions/context-usage.d.ts +54 -0
- package/dist/react/features/sessions/context-usage.js +206 -0
- package/dist/react/features/sessions/conversation.d.ts +21 -0
- package/dist/react/features/sessions/conversation.js +549 -0
- package/dist/react/features/sessions/harness-switcher.d.ts +26 -0
- package/dist/react/features/sessions/harness-switcher.js +118 -0
- package/dist/react/features/sessions/intake-heuristic.d.ts +5 -0
- package/dist/react/features/sessions/intake-heuristic.js +28 -0
- package/dist/react/features/sessions/interjection-routes.d.ts +13 -0
- package/dist/react/features/sessions/interjection-routes.js +72 -0
- package/dist/react/features/sessions/llm-models.d.ts +128 -0
- package/dist/react/features/sessions/llm-models.js +174 -0
- package/dist/react/features/sessions/media-strip.d.ts +25 -0
- package/dist/react/features/sessions/media-strip.js +56 -0
- package/dist/react/features/sessions/media.d.ts +43 -0
- package/dist/react/features/sessions/media.js +115 -0
- package/dist/react/features/sessions/model-search.d.ts +6 -0
- package/dist/react/features/sessions/model-search.js +16 -0
- package/dist/react/features/sessions/model-switcher.d.ts +16 -0
- package/dist/react/features/sessions/model-switcher.js +262 -0
- package/dist/react/features/sessions/open-pull-request.d.ts +20 -0
- package/dist/react/features/sessions/open-pull-request.js +92 -0
- package/dist/react/features/sessions/pull-publish-card.d.ts +14 -0
- package/dist/react/features/sessions/pull-publish-card.js +88 -0
- package/dist/react/features/sessions/recent-sessions.d.ts +11 -0
- package/dist/react/features/sessions/recent-sessions.js +29 -0
- package/dist/react/features/sessions/seen-sessions.d.ts +16 -0
- package/dist/react/features/sessions/seen-sessions.js +108 -0
- package/dist/react/features/sessions/session-activity.d.ts +95 -0
- package/dist/react/features/sessions/session-activity.js +785 -0
- package/dist/react/features/sessions/session-context.d.ts +8 -0
- package/dist/react/features/sessions/session-context.js +98 -0
- package/dist/react/features/sessions/session-feed.d.ts +243 -0
- package/dist/react/features/sessions/session-feed.js +883 -0
- package/dist/react/features/sessions/session-header.d.ts +24 -0
- package/dist/react/features/sessions/session-header.js +97 -0
- package/dist/react/features/sessions/session-layout.d.ts +7 -0
- package/dist/react/features/sessions/session-layout.js +87 -0
- package/dist/react/features/sessions/session-panes.d.ts +49 -0
- package/dist/react/features/sessions/session-panes.js +142 -0
- package/dist/react/features/sessions/session-parts.d.ts +35 -0
- package/dist/react/features/sessions/session-parts.js +74 -0
- package/dist/react/features/sessions/session-place.d.ts +9 -0
- package/dist/react/features/sessions/session-place.js +109 -0
- package/dist/react/features/sessions/session-pr-pills.d.ts +7 -0
- package/dist/react/features/sessions/session-pr-pills.js +28 -0
- package/dist/react/features/sessions/session-queries.d.ts +172 -0
- package/dist/react/features/sessions/session-queries.js +90 -0
- package/dist/react/features/sessions/session-repos.d.ts +8 -0
- package/dist/react/features/sessions/session-repos.js +15 -0
- package/dist/react/features/sessions/session-share.d.ts +8 -0
- package/dist/react/features/sessions/session-share.js +112 -0
- package/dist/react/features/sessions/session-tabs.d.ts +38 -0
- package/dist/react/features/sessions/session-tabs.js +191 -0
- package/dist/react/features/sessions/session.d.ts +103 -0
- package/dist/react/features/sessions/session.js +216 -0
- package/dist/react/features/sessions/signals.d.ts +13 -0
- package/dist/react/features/sessions/signals.js +34 -0
- package/dist/react/features/sessions/tab-set.d.ts +20 -0
- package/dist/react/features/sessions/tab-set.js +58 -0
- package/dist/react/features/sessions/team.d.ts +16 -0
- package/dist/react/features/sessions/team.js +35 -0
- package/dist/react/features/sessions/timeline.d.ts +53 -0
- package/dist/react/features/sessions/timeline.js +153 -0
- package/dist/react/features/sessions/use-session-tabs.d.ts +18 -0
- package/dist/react/features/sessions/use-session-tabs.js +119 -0
- package/dist/react/features/sessions/vendor-models.d.ts +23 -0
- package/dist/react/features/sessions/vendor-models.js +61 -0
- package/dist/react/features/workspace/activity-dot.d.ts +15 -0
- package/dist/react/features/workspace/activity-dot.js +36 -0
- package/dist/react/features/workspace/app-sidebar.d.ts +16 -0
- package/dist/react/features/workspace/app-sidebar.js +227 -0
- package/dist/react/features/workspace/fixture-toggle.d.ts +2 -0
- package/dist/react/features/workspace/fixture-toggle.js +72 -0
- package/dist/react/features/workspace/folder-group.d.ts +18 -0
- package/dist/react/features/workspace/folder-group.js +83 -0
- package/dist/react/features/workspace/inline-name-input.d.ts +10 -0
- package/dist/react/features/workspace/inline-name-input.js +33 -0
- package/dist/react/features/workspace/link-repo-dialog.d.ts +9 -0
- package/dist/react/features/workspace/link-repo-dialog.js +76 -0
- package/dist/react/features/workspace/repo-chip.d.ts +13 -0
- package/dist/react/features/workspace/repo-chip.js +15 -0
- package/dist/react/features/workspace/session-row.d.ts +20 -0
- package/dist/react/features/workspace/session-row.js +23 -0
- package/dist/react/features/workspace/use-debounced.d.ts +2 -0
- package/dist/react/features/workspace/use-debounced.js +10 -0
- package/dist/react/features/workspace/workspace-context.d.ts +45 -0
- package/dist/react/features/workspace/workspace-context.js +245 -0
- package/dist/react/features/workspace/workspace-fixtures.d.ts +16 -0
- package/dist/react/features/workspace/workspace-fixtures.js +175 -0
- package/dist/react/features/workspace/workspace-tree.d.ts +30 -0
- package/dist/react/features/workspace/workspace-tree.js +69 -0
- package/dist/react/features/workspace/workspace.d.ts +107 -0
- package/dist/react/features/workspace/workspace.js +458 -0
- package/dist/react/index.d.ts +33 -0
- package/dist/react/index.js +35 -0
- package/dist/react/lib/cn.d.ts +6 -0
- package/dist/react/lib/cn.js +20 -0
- package/dist/react/lib/initials.d.ts +6 -0
- package/dist/react/lib/initials.js +32 -0
- package/dist/react/lib/json.d.ts +33 -0
- package/dist/react/lib/json.js +101 -0
- package/dist/react/lib/time.d.ts +8 -0
- package/dist/react/lib/time.js +57 -0
- package/dist/react/lib/use-media-query.d.ts +1 -0
- package/dist/react/lib/use-media-query.js +9 -0
- package/dist/react/lib/use-now.d.ts +2 -0
- package/dist/react/lib/use-now.js +10 -0
- package/dist/react/lib/use-width-bucket.d.ts +6 -0
- package/dist/react/lib/use-width-bucket.js +28 -0
- package/dist/react/parts/index.d.ts +43 -0
- package/dist/react/parts/index.js +43 -0
- package/dist/react/shuttle/device.d.ts +42 -0
- package/dist/react/shuttle/device.js +10 -0
- package/dist/react/shuttle/host.d.ts +1126 -0
- package/dist/react/shuttle/host.js +93 -0
- package/dist/react/shuttle/identity.d.ts +31 -0
- package/dist/react/shuttle/identity.js +20 -0
- package/dist/react/shuttle/index.d.ts +14 -0
- package/dist/react/shuttle/index.js +13 -0
- package/dist/react/shuttle/provider.d.ts +41 -0
- package/dist/react/shuttle/provider.js +59 -0
- package/dist/react/shuttle/router.d.ts +43 -0
- package/dist/react/shuttle/router.js +1 -0
- package/dist/react/theme.css +456 -0
- package/dist/react/ui.d.ts +19 -0
- package/dist/react/ui.js +19 -0
- package/package.json +100 -4
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { createORPCClient, ORPCError } from '@orpc/client';
|
|
2
|
+
import { OpenAPILink } from '@orpc/openapi-client/fetch';
|
|
3
|
+
import { createTanstackQueryUtils } from '@orpc/tanstack-query';
|
|
4
|
+
import { clientContract } from '@swirls/shuttle/api';
|
|
5
|
+
import { preloadRunStore } from '@swirls/looms/react';
|
|
6
|
+
import { eventCacheFor } from '../features/events/event-cache.js';
|
|
7
|
+
function queryUtils(client) {
|
|
8
|
+
return createTanstackQueryUtils(client);
|
|
9
|
+
}
|
|
10
|
+
/** A run refused a signal. `status` is the HTTP status it answered with. */
|
|
11
|
+
export class SignalError extends Error {
|
|
12
|
+
status;
|
|
13
|
+
constructor(message, status) {
|
|
14
|
+
super(message);
|
|
15
|
+
this.status = status;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
/** The HTTP status a failed call came back with, when it reached the backend at all. */
|
|
19
|
+
export function statusOf(cause) {
|
|
20
|
+
return cause instanceof ORPCError ? cause.status : undefined;
|
|
21
|
+
}
|
|
22
|
+
export function isSignedOut(cause) {
|
|
23
|
+
return statusOf(cause) === 401;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* A session stays connected for a while after it is left, so going back to it shows it at once
|
|
27
|
+
* instead of downloading its log again.
|
|
28
|
+
*/
|
|
29
|
+
const SESSION_RETAIN_MS = 5 * 60_000;
|
|
30
|
+
/** How long a page waits on a run's log before going ahead without it. */
|
|
31
|
+
const WAIT_MS = 4000;
|
|
32
|
+
export function createShuttleHost(options = {}) {
|
|
33
|
+
const baseUrl = (options.baseUrl ?? '').replace(/\/+$/, '');
|
|
34
|
+
const device = options.device ?? null;
|
|
35
|
+
const request = options.fetch ?? ((input, init) => fetch(input, init));
|
|
36
|
+
/** The backend's origin: the one it was given, or the page's own. */
|
|
37
|
+
const origin = () => baseUrl || window.location.origin;
|
|
38
|
+
const client = createORPCClient(new OpenAPILink(clientContract, {
|
|
39
|
+
url: origin,
|
|
40
|
+
fetch: (input, init) => request(input, init),
|
|
41
|
+
headers: ({ context }) => (context.deviceId ? { 'x-shuttle-device': context.deviceId } : {}),
|
|
42
|
+
}));
|
|
43
|
+
const runStores = new Map();
|
|
44
|
+
function runStoreOptions(userId) {
|
|
45
|
+
const existing = runStores.get(userId);
|
|
46
|
+
if (existing) {
|
|
47
|
+
return existing;
|
|
48
|
+
}
|
|
49
|
+
const created = {
|
|
50
|
+
endpoint: baseUrl,
|
|
51
|
+
// SSE holds one of the browser's six HTTP/1.1 connections per origin for each run store;
|
|
52
|
+
// across a few tabs that starves route chunks and API calls. WebSockets have their own pool.
|
|
53
|
+
transport: 'websocket',
|
|
54
|
+
retainMs: SESSION_RETAIN_MS,
|
|
55
|
+
cache: eventCacheFor(userId),
|
|
56
|
+
...options.runStore?.(userId),
|
|
57
|
+
};
|
|
58
|
+
runStores.set(userId, created);
|
|
59
|
+
return created;
|
|
60
|
+
}
|
|
61
|
+
return {
|
|
62
|
+
client,
|
|
63
|
+
api: queryUtils(client),
|
|
64
|
+
device,
|
|
65
|
+
fetch: request,
|
|
66
|
+
previewPort: options.previewPort === undefined ? null : String(options.previewPort),
|
|
67
|
+
fixtures: options.fixtures ?? false,
|
|
68
|
+
origin,
|
|
69
|
+
url: (path) => `${baseUrl}${path}`,
|
|
70
|
+
socketUrl: (path) => `${origin().replace(/^http/, 'ws')}${path}`,
|
|
71
|
+
deviceContext: () => ({ deviceId: device?.deviceId ?? null }),
|
|
72
|
+
runStoreOptions,
|
|
73
|
+
async signalRun(runId, name, input) {
|
|
74
|
+
// Looms takes a signal's input wrapped as `{ input }`. `respond=async` has the run answer
|
|
75
|
+
// once the signal is on its log, since the page follows what happens next on the stream.
|
|
76
|
+
const response = await request(`${baseUrl}/runs/${encodeURIComponent(runId)}/signals/${name}?respond=async`, {
|
|
77
|
+
method: 'POST',
|
|
78
|
+
headers: { 'content-type': 'application/json' },
|
|
79
|
+
body: JSON.stringify({ input }),
|
|
80
|
+
});
|
|
81
|
+
if (!response.ok) {
|
|
82
|
+
const detail = (await response.text().catch(() => '')).trim().slice(0, 300);
|
|
83
|
+
throw new SignalError(detail || `The session refused the request (${response.status}).`, response.status);
|
|
84
|
+
}
|
|
85
|
+
},
|
|
86
|
+
async whenRunSynced(runId, userId) {
|
|
87
|
+
await preloadRunStore(runId, {
|
|
88
|
+
...runStoreOptions(userId),
|
|
89
|
+
signal: AbortSignal.timeout(WAIT_MS),
|
|
90
|
+
}).catch(() => { });
|
|
91
|
+
},
|
|
92
|
+
};
|
|
93
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { Tenant } from '@swirls/shuttle/api';
|
|
2
|
+
export interface ShuttlePerson {
|
|
3
|
+
readonly userId: string;
|
|
4
|
+
readonly name: string;
|
|
5
|
+
readonly email: string;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Who is using Shuttle, as the host knows them. Shuttle's components never sign anyone in or
|
|
9
|
+
* ask who they are: the host has already settled that, and says so here.
|
|
10
|
+
*/
|
|
11
|
+
export interface ShuttleIdentity {
|
|
12
|
+
/** The signed-in person, their organization, and the organization's runs. */
|
|
13
|
+
readonly tenant: Tenant;
|
|
14
|
+
/** Everyone in the organization, for names, bylines and sharing. */
|
|
15
|
+
listPeople(): Promise<readonly ShuttlePerson[]>;
|
|
16
|
+
/**
|
|
17
|
+
* Sends the person off to connect their own GitHub account, for what is done in their name
|
|
18
|
+
* (a review comment). A host that connects accounts some other way leaves it out, and the
|
|
19
|
+
* components then only say that the account is not connected.
|
|
20
|
+
*/
|
|
21
|
+
connectGithub?(): void;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Everyone in the organization `orgId`. Membership changes rarely, so one read serves the whole
|
|
25
|
+
* visit. A host that reads it ahead of a page uses this too, so the page finds it there.
|
|
26
|
+
*/
|
|
27
|
+
export declare function peopleQuery(orgId: string, listPeople: ShuttleIdentity['listPeople']): import("@tanstack/react-query").OmitKeyof<import("@tanstack/react-query").UseQueryOptions<readonly ShuttlePerson[], Error, readonly ShuttlePerson[], readonly ["org-members", string]>, "queryFn"> & {
|
|
28
|
+
queryFn?: import("@tanstack/react-query").QueryFunction<readonly ShuttlePerson[], readonly ["org-members", string], never> | undefined;
|
|
29
|
+
} & import("@tanstack/react-query").QueryKeyWithDataTag<readonly ["org-members", string], readonly ShuttlePerson[], Error>;
|
|
30
|
+
/** "your" for the signed-in person, "Alice's" for anyone else, "a teammate's" when unknown. */
|
|
31
|
+
export declare function possessive(userId: string, me: string, people: ReadonlyMap<string, string>): string;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { queryOptions } from '@tanstack/react-query';
|
|
2
|
+
/**
|
|
3
|
+
* Everyone in the organization `orgId`. Membership changes rarely, so one read serves the whole
|
|
4
|
+
* visit. A host that reads it ahead of a page uses this too, so the page finds it there.
|
|
5
|
+
*/
|
|
6
|
+
export function peopleQuery(orgId, listPeople) {
|
|
7
|
+
return queryOptions({
|
|
8
|
+
queryKey: ['org-members', orgId],
|
|
9
|
+
queryFn: () => listPeople(),
|
|
10
|
+
staleTime: 5 * 60_000,
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
/** "your" for the signed-in person, "Alice's" for anyone else, "a teammate's" when unknown. */
|
|
14
|
+
export function possessive(userId, me, people) {
|
|
15
|
+
if (userId === me) {
|
|
16
|
+
return 'your';
|
|
17
|
+
}
|
|
18
|
+
const name = people.get(userId);
|
|
19
|
+
return name ? `${name}'s` : "a teammate's";
|
|
20
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What Shuttle's components are built on, and the only way they reach the world outside them.
|
|
3
|
+
*
|
|
4
|
+
* Nothing under `src/features` (other than `auth`, `desktop` and `github`, which belong to
|
|
5
|
+
* Shuttle's own app) may import the app's router, its API client, its sign-in client or
|
|
6
|
+
* `window.shuttleDesktop`. They ask for those here, and whatever is hosting them answers through
|
|
7
|
+
* `<Shuttle.Provider>` (see `src/parts`). That is what lets the same components be put together differently, in
|
|
8
|
+
* Shuttle's app or in someone else's.
|
|
9
|
+
*/
|
|
10
|
+
export { isolationLabel, type DeviceRunnerStatus, type ShuttleDevice } from './device.js';
|
|
11
|
+
export { createShuttleHost, isSignedOut, SignalError, statusOf, type CallContext, type ShuttleApi, type ShuttleClient, type ShuttleFetch, type ShuttleHost, type ShuttleHostOptions, } from './host.js';
|
|
12
|
+
export { peopleQuery, possessive, type ShuttleIdentity, type ShuttlePerson } from './identity.js';
|
|
13
|
+
export { Link, ShuttleProvider, useApi, useDevice, useLocation, useNavigate, useOrgPeople, useShuttle, useShuttleHost, useTenant, type ShuttleContextValue, type ShuttleProviderProps, } from './provider.js';
|
|
14
|
+
export type { ShuttleDestination, ShuttleLinkProps, ShuttleRouter } from './router.js';
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What Shuttle's components are built on, and the only way they reach the world outside them.
|
|
3
|
+
*
|
|
4
|
+
* Nothing under `src/features` (other than `auth`, `desktop` and `github`, which belong to
|
|
5
|
+
* Shuttle's own app) may import the app's router, its API client, its sign-in client or
|
|
6
|
+
* `window.shuttleDesktop`. They ask for those here, and whatever is hosting them answers through
|
|
7
|
+
* `<Shuttle.Provider>` (see `src/parts`). That is what lets the same components be put together differently, in
|
|
8
|
+
* Shuttle's app or in someone else's.
|
|
9
|
+
*/
|
|
10
|
+
export { isolationLabel } from './device.js';
|
|
11
|
+
export { createShuttleHost, isSignedOut, SignalError, statusOf, } from './host.js';
|
|
12
|
+
export { peopleQuery, possessive } from './identity.js';
|
|
13
|
+
export { Link, ShuttleProvider, useApi, useDevice, useLocation, useNavigate, useOrgPeople, useShuttle, useShuttleHost, useTenant, } from './provider.js';
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { type ReactNode } from 'react';
|
|
2
|
+
import type { Tenant } from '@swirls/shuttle/api';
|
|
3
|
+
import type { ShuttleDevice } from './device.js';
|
|
4
|
+
import type { ShuttleApi, ShuttleHost } from './host.js';
|
|
5
|
+
import { type ShuttleIdentity } from './identity.js';
|
|
6
|
+
import type { ShuttleDestination, ShuttleLinkProps, ShuttleRouter } from './router.js';
|
|
7
|
+
export interface ShuttleContextValue {
|
|
8
|
+
readonly host: ShuttleHost;
|
|
9
|
+
readonly identity: ShuttleIdentity;
|
|
10
|
+
readonly router: Pick<ShuttleRouter, 'Link' | 'navigate'>;
|
|
11
|
+
}
|
|
12
|
+
export interface ShuttleProviderProps {
|
|
13
|
+
/** How to reach the backend, and the machine this is on. See `createShuttleHost`. */
|
|
14
|
+
readonly host: ShuttleHost;
|
|
15
|
+
/** How to move around inside whatever is hosting the components. */
|
|
16
|
+
readonly router: ShuttleRouter;
|
|
17
|
+
/** Who is signed in. */
|
|
18
|
+
readonly identity: ShuttleIdentity;
|
|
19
|
+
readonly children: ReactNode;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Everything Shuttle's components are given by what hosts them. Every other Shuttle component
|
|
23
|
+
* goes somewhere inside one. It expects a TanStack `QueryClientProvider` above it.
|
|
24
|
+
*/
|
|
25
|
+
export declare function ShuttleProvider({ host, router, identity, children }: ShuttleProviderProps): import("react").JSX.Element;
|
|
26
|
+
export declare function useShuttle(): ShuttleContextValue;
|
|
27
|
+
export declare function useShuttleHost(): ShuttleHost;
|
|
28
|
+
/** The backend's API as TanStack Query options. */
|
|
29
|
+
export declare function useApi(): ShuttleApi;
|
|
30
|
+
/** The machine this is running on, or null when it has none. */
|
|
31
|
+
export declare function useDevice(): ShuttleDevice | null;
|
|
32
|
+
/** The signed-in person and their organization. */
|
|
33
|
+
export declare function useTenant(): Tenant;
|
|
34
|
+
/** Names for the people in the signed-in organization, by user id. Empty until they load. */
|
|
35
|
+
export declare function useOrgPeople(): ReadonlyMap<string, string>;
|
|
36
|
+
/** An anchor to one of Shuttle's destinations, drawn by the host's router. */
|
|
37
|
+
export declare function Link(props: ShuttleLinkProps): import("react").JSX.Element;
|
|
38
|
+
/** Returns a function that goes to one of Shuttle's destinations. */
|
|
39
|
+
export declare function useNavigate(): (to: ShuttleDestination) => void;
|
|
40
|
+
/** The destination now on screen, or null when the host is showing something else. */
|
|
41
|
+
export declare function useLocation(): ShuttleDestination | null;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useQuery } from '@tanstack/react-query';
|
|
3
|
+
import { createContext, useContext, useMemo } from 'react';
|
|
4
|
+
import { LoomsProvider } from '@swirls/looms/react';
|
|
5
|
+
import { peopleQuery } from './identity.js';
|
|
6
|
+
const ShuttleContext = createContext(null);
|
|
7
|
+
/** Kept apart from the rest, so moving between pages renders only what shows where it is. */
|
|
8
|
+
const LocationContext = createContext(null);
|
|
9
|
+
/**
|
|
10
|
+
* Everything Shuttle's components are given by what hosts them. Every other Shuttle component
|
|
11
|
+
* goes somewhere inside one. It expects a TanStack `QueryClientProvider` above it.
|
|
12
|
+
*/
|
|
13
|
+
export function ShuttleProvider({ host, router, identity, children }) {
|
|
14
|
+
const { Link: HostLink, navigate, location } = router;
|
|
15
|
+
const value = useMemo(() => ({ host, identity, router: { Link: HostLink, navigate } }), [host, identity, HostLink, navigate]);
|
|
16
|
+
return (_jsx(ShuttleContext, { value: value, children: _jsx(LocationContext, { value: location, children: _jsx(LoomsProvider, { ...host.runStoreOptions(identity.tenant.user.id), children: children }) }) }));
|
|
17
|
+
}
|
|
18
|
+
export function useShuttle() {
|
|
19
|
+
const value = useContext(ShuttleContext);
|
|
20
|
+
if (!value) {
|
|
21
|
+
throw new Error('Shuttle components must be used inside <Shuttle.Provider>');
|
|
22
|
+
}
|
|
23
|
+
return value;
|
|
24
|
+
}
|
|
25
|
+
export function useShuttleHost() {
|
|
26
|
+
return useShuttle().host;
|
|
27
|
+
}
|
|
28
|
+
/** The backend's API as TanStack Query options. */
|
|
29
|
+
export function useApi() {
|
|
30
|
+
return useShuttle().host.api;
|
|
31
|
+
}
|
|
32
|
+
/** The machine this is running on, or null when it has none. */
|
|
33
|
+
export function useDevice() {
|
|
34
|
+
return useShuttle().host.device;
|
|
35
|
+
}
|
|
36
|
+
/** The signed-in person and their organization. */
|
|
37
|
+
export function useTenant() {
|
|
38
|
+
return useShuttle().identity.tenant;
|
|
39
|
+
}
|
|
40
|
+
const nobody = new Map();
|
|
41
|
+
/** Names for the people in the signed-in organization, by user id. Empty until they load. */
|
|
42
|
+
export function useOrgPeople() {
|
|
43
|
+
const { identity } = useShuttle();
|
|
44
|
+
const { data } = useQuery(peopleQuery(identity.tenant.org.id, identity.listPeople));
|
|
45
|
+
return useMemo(() => data ? new Map(data.map((person) => [person.userId, person.name || person.email])) : nobody, [data]);
|
|
46
|
+
}
|
|
47
|
+
/** An anchor to one of Shuttle's destinations, drawn by the host's router. */
|
|
48
|
+
export function Link(props) {
|
|
49
|
+
const { Link: HostLink } = useShuttle().router;
|
|
50
|
+
return _jsx(HostLink, { ...props });
|
|
51
|
+
}
|
|
52
|
+
/** Returns a function that goes to one of Shuttle's destinations. */
|
|
53
|
+
export function useNavigate() {
|
|
54
|
+
return useShuttle().router.navigate;
|
|
55
|
+
}
|
|
56
|
+
/** The destination now on screen, or null when the host is showing something else. */
|
|
57
|
+
export function useLocation() {
|
|
58
|
+
return useContext(LocationContext);
|
|
59
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { AnchorHTMLAttributes, ComponentType, Ref } from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* A place Shuttle's components link to. They name the place and never an address, so each host
|
|
4
|
+
* decides where it lives: Shuttle's own app has a page for each, another product may have a
|
|
5
|
+
* session inside one of its own views and no playbook page at all.
|
|
6
|
+
*/
|
|
7
|
+
export type ShuttleDestination =
|
|
8
|
+
/** Where a new session is started. */
|
|
9
|
+
{
|
|
10
|
+
readonly page: 'home';
|
|
11
|
+
}
|
|
12
|
+
/** One session. `thread` is the agent thread to bring forward when it opens. */
|
|
13
|
+
| {
|
|
14
|
+
readonly page: 'session';
|
|
15
|
+
readonly sessionId: string;
|
|
16
|
+
readonly thread?: string | undefined;
|
|
17
|
+
} | {
|
|
18
|
+
readonly page: 'folder';
|
|
19
|
+
readonly folderId: string;
|
|
20
|
+
} | {
|
|
21
|
+
readonly page: 'playbook';
|
|
22
|
+
} | {
|
|
23
|
+
readonly page: 'events';
|
|
24
|
+
} | {
|
|
25
|
+
readonly page: 'connections';
|
|
26
|
+
};
|
|
27
|
+
export interface ShuttleLinkProps extends Omit<AnchorHTMLAttributes<HTMLAnchorElement>, 'href'> {
|
|
28
|
+
readonly to: ShuttleDestination;
|
|
29
|
+
readonly ref?: Ref<HTMLAnchorElement>;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* How Shuttle's components move around inside whatever is hosting them. The host supplies one,
|
|
33
|
+
* built on its own router. `Link` and `navigate` should stay the same from one render to the
|
|
34
|
+
* next; `location` changes as the host moves, and only what reads it renders again.
|
|
35
|
+
*/
|
|
36
|
+
export interface ShuttleRouter {
|
|
37
|
+
/** An anchor to a destination. It passes every other prop on, so it works under `asChild`. */
|
|
38
|
+
readonly Link: ComponentType<ShuttleLinkProps>;
|
|
39
|
+
/** Goes to a destination. */
|
|
40
|
+
navigate(to: ShuttleDestination): void;
|
|
41
|
+
/** The destination now on screen, or null when it is none of Shuttle's. */
|
|
42
|
+
readonly location: ShuttleDestination | null;
|
|
43
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|