@go-go-golems/os-scripting 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.
Files changed (119) hide show
  1. package/README.md +147 -0
  2. package/app/createAppStore.d.ts +89 -0
  3. package/app/createAppStore.js +90 -0
  4. package/app/index.d.ts +2 -0
  5. package/app/index.js +2 -0
  6. package/app/runtimeSessionLifecycleMiddleware.d.ts +6 -0
  7. package/app/runtimeSessionLifecycleMiddleware.js +42 -0
  8. package/features/runtimeSessions/capabilityPolicy.d.ts +12 -0
  9. package/features/runtimeSessions/capabilityPolicy.js +36 -0
  10. package/features/runtimeSessions/index.d.ts +3 -0
  11. package/features/runtimeSessions/index.js +3 -0
  12. package/features/runtimeSessions/runtimeSessionsSlice.d.ts +90 -0
  13. package/features/runtimeSessions/runtimeSessionsSlice.js +210 -0
  14. package/features/runtimeSessions/selectors.d.ts +16 -0
  15. package/features/runtimeSessions/selectors.js +40 -0
  16. package/hypercard/artifacts/artifactProjectionMiddleware.d.ts +1 -0
  17. package/hypercard/artifacts/artifactProjectionMiddleware.js +66 -0
  18. package/hypercard/artifacts/artifactRuntime.d.ts +22 -0
  19. package/hypercard/artifacts/artifactRuntime.js +137 -0
  20. package/hypercard/artifacts/artifactsSelectors.d.ts +10 -0
  21. package/hypercard/artifacts/artifactsSelectors.js +2 -0
  22. package/hypercard/artifacts/artifactsSlice.d.ts +38 -0
  23. package/hypercard/artifacts/artifactsSlice.js +94 -0
  24. package/hypercard/debug/RuntimeSurfaceDebugWindow.d.ts +7 -0
  25. package/hypercard/debug/RuntimeSurfaceDebugWindow.js +181 -0
  26. package/hypercard/debug/jsSessionDebugRegistry.d.ts +11 -0
  27. package/hypercard/debug/jsSessionDebugRegistry.js +43 -0
  28. package/hypercard/debug/runtimeDebugApp.d.ts +19 -0
  29. package/hypercard/debug/runtimeDebugApp.js +25 -0
  30. package/hypercard/debug/runtimeDebugRegistry.d.ts +6 -0
  31. package/hypercard/debug/runtimeDebugRegistry.js +49 -0
  32. package/hypercard/editor/CodeEditorWindow.d.ts +7 -0
  33. package/hypercard/editor/CodeEditorWindow.js +128 -0
  34. package/hypercard/editor/editorLaunch.d.ts +16 -0
  35. package/hypercard/editor/editorLaunch.js +58 -0
  36. package/hypercard/editor/runtimeSurfaceRef.d.ts +8 -0
  37. package/hypercard/editor/runtimeSurfaceRef.js +60 -0
  38. package/hypercard/index.d.ts +12 -0
  39. package/hypercard/index.js +12 -0
  40. package/hypercard/task-manager/TaskManagerWindow.d.ts +1 -0
  41. package/hypercard/task-manager/TaskManagerWindow.js +102 -0
  42. package/hypercard/task-manager/index.d.ts +6 -0
  43. package/hypercard/task-manager/index.js +6 -0
  44. package/hypercard/task-manager/jsSessionSource.d.ts +10 -0
  45. package/hypercard/task-manager/jsSessionSource.js +49 -0
  46. package/hypercard/task-manager/runtimeSessionSource.d.ts +26 -0
  47. package/hypercard/task-manager/runtimeSessionSource.js +123 -0
  48. package/hypercard/task-manager/taskManagerApp.d.ts +16 -0
  49. package/hypercard/task-manager/taskManagerApp.js +25 -0
  50. package/hypercard/task-manager/taskManagerRegistry.d.ts +10 -0
  51. package/hypercard/task-manager/taskManagerRegistry.js +75 -0
  52. package/hypercard/task-manager/types.d.ts +25 -0
  53. package/hypercard/task-manager/types.js +1 -0
  54. package/hypercard/timeline/hypercardCard.d.ts +5 -0
  55. package/hypercard/timeline/hypercardCard.js +104 -0
  56. package/index.d.ts +18 -0
  57. package/index.js +18 -0
  58. package/package.json +72 -0
  59. package/plugin-runtime/contracts.d.ts +116 -0
  60. package/plugin-runtime/contracts.js +32 -0
  61. package/plugin-runtime/fixtures/column-stack.vm.js +19 -0
  62. package/plugin-runtime/fixtures/dynamic-card.vm.js +13 -0
  63. package/plugin-runtime/fixtures/inventory-stack.vm.js +29 -0
  64. package/plugin-runtime/fixtures/kanban-card.vm.js +55 -0
  65. package/plugin-runtime/fixtures/loop-stack.vm.js +16 -0
  66. package/plugin-runtime/fixtures/patched-low-stock-handler.vm.js +3 -0
  67. package/plugin-runtime/fixtures/patched-low-stock-render.vm.js +5 -0
  68. package/plugin-runtime/index.d.ts +6 -0
  69. package/plugin-runtime/index.js +6 -0
  70. package/plugin-runtime/intentSchema.d.ts +3 -0
  71. package/plugin-runtime/intentSchema.js +25 -0
  72. package/plugin-runtime/jsEvalSupport.d.ts +6 -0
  73. package/plugin-runtime/jsEvalSupport.js +93 -0
  74. package/plugin-runtime/jsSessionService.d.ts +55 -0
  75. package/plugin-runtime/jsSessionService.js +136 -0
  76. package/plugin-runtime/quickJsSessionCore.d.ts +24 -0
  77. package/plugin-runtime/quickJsSessionCore.js +92 -0
  78. package/plugin-runtime/runtimeService.d.ts +34 -0
  79. package/plugin-runtime/runtimeService.js +248 -0
  80. package/plugin-runtime/runtimeSurfaceRegistry.d.ts +45 -0
  81. package/plugin-runtime/runtimeSurfaceRegistry.js +73 -0
  82. package/plugin-runtime/stack-bootstrap.vm.js +236 -0
  83. package/repl/attachedJsSessionRegistry.d.ts +25 -0
  84. package/repl/attachedJsSessionRegistry.js +81 -0
  85. package/repl/attachedRuntimeSessionRegistry.d.ts +11 -0
  86. package/repl/attachedRuntimeSessionRegistry.js +107 -0
  87. package/repl/hypercardReplDriver.d.ts +54 -0
  88. package/repl/hypercardReplDriver.js +600 -0
  89. package/repl/jsReplDriver.d.ts +8 -0
  90. package/repl/jsReplDriver.js +348 -0
  91. package/repl/jsSessionBroker.d.ts +21 -0
  92. package/repl/jsSessionBroker.js +75 -0
  93. package/repl/runtimeBroker.d.ts +43 -0
  94. package/repl/runtimeBroker.js +117 -0
  95. package/runtime-host/RuntimeSurfaceSessionHost.d.ts +8 -0
  96. package/runtime-host/RuntimeSurfaceSessionHost.js +384 -0
  97. package/runtime-host/fixtures/CardSessionHost.chat.vm.js +61 -0
  98. package/runtime-host/fixtures/CardSessionHost.list.vm.js +29 -0
  99. package/runtime-host/fixtures/CardSessionHost.nav.vm.js +101 -0
  100. package/runtime-host/fixtures/CardSessionHost.report.vm.js +34 -0
  101. package/runtime-host/pluginIntentRouting.d.ts +13 -0
  102. package/runtime-host/pluginIntentRouting.js +83 -0
  103. package/runtime-packages/index.d.ts +1 -0
  104. package/runtime-packages/index.js +1 -0
  105. package/runtime-packages/runtimePackageRegistry.d.ts +14 -0
  106. package/runtime-packages/runtimePackageRegistry.js +42 -0
  107. package/runtime-packages/ui.package.vm.js +84 -0
  108. package/runtime-packs/index.d.ts +1 -0
  109. package/runtime-packs/index.js +1 -0
  110. package/runtime-packs/runtimeSurfaceTypeRegistry.d.ts +20 -0
  111. package/runtime-packs/runtimeSurfaceTypeRegistry.js +37 -0
  112. package/runtime-session-manager/index.d.ts +2 -0
  113. package/runtime-session-manager/index.js +2 -0
  114. package/runtime-session-manager/runtimeOwnership.d.ts +10 -0
  115. package/runtime-session-manager/runtimeOwnership.js +19 -0
  116. package/runtime-session-manager/runtimeSessionManager.d.ts +47 -0
  117. package/runtime-session-manager/runtimeSessionManager.js +214 -0
  118. package/testRuntimeUi.d.ts +4 -0
  119. package/testRuntimeUi.js +39 -0
@@ -0,0 +1,236 @@
1
+ const __runtimePackageState =
2
+ globalThis.__runtimePackageState && typeof globalThis.__runtimePackageState === 'object'
3
+ ? globalThis.__runtimePackageState
4
+ : {
5
+ packageIds: [],
6
+ apis: {},
7
+ };
8
+
9
+ globalThis.__runtimePackageState = __runtimePackageState;
10
+
11
+ let __runtimeBundle = null;
12
+ let __runtimeActions = [];
13
+
14
+ function isPlainObject(value) {
15
+ return value && typeof value === 'object' && !Array.isArray(value);
16
+ }
17
+
18
+ function mergeRuntimeApiValue(existingValue, incomingValue) {
19
+ if (isPlainObject(existingValue) && isPlainObject(incomingValue)) {
20
+ const merged = { ...existingValue };
21
+ for (const [key, value] of Object.entries(incomingValue)) {
22
+ merged[key] = mergeRuntimeApiValue(merged[key], value);
23
+ }
24
+ return merged;
25
+ }
26
+
27
+ return incomingValue;
28
+ }
29
+
30
+ function registerRuntimePackageApi(packageId, apiExports) {
31
+ const normalizedPackageId = String(packageId || '').trim();
32
+ if (!normalizedPackageId) {
33
+ throw new Error('registerRuntimePackageApi requires a package id');
34
+ }
35
+
36
+ if (!__runtimePackageState.packageIds.includes(normalizedPackageId)) {
37
+ __runtimePackageState.packageIds.push(normalizedPackageId);
38
+ }
39
+
40
+ if (!isPlainObject(apiExports)) {
41
+ return;
42
+ }
43
+
44
+ for (const [exportName, exportValue] of Object.entries(apiExports)) {
45
+ const mergedValue = mergeRuntimeApiValue(__runtimePackageState.apis[exportName], exportValue);
46
+ __runtimePackageState.apis[exportName] = mergedValue;
47
+ globalThis[exportName] = mergedValue;
48
+ }
49
+ }
50
+
51
+ function collectRuntimePackageApis() {
52
+ return { ...__runtimePackageState.apis };
53
+ }
54
+
55
+ function defineRuntimeBundleImpl(factory) {
56
+ if (typeof factory !== 'function') {
57
+ throw new Error('defineRuntimeBundle requires a factory function');
58
+ }
59
+
60
+ __runtimeBundle = factory(collectRuntimePackageApis());
61
+ }
62
+
63
+ function assertStackBundleReady() {
64
+ if (!__runtimeBundle || typeof __runtimeBundle !== 'object') {
65
+ throw new Error('Runtime bundle did not register via defineRuntimeBundle');
66
+ }
67
+ }
68
+
69
+ function assertSurfacesMap() {
70
+ assertStackBundleReady();
71
+ if (!__runtimeBundle.surfaces || typeof __runtimeBundle.surfaces !== 'object') {
72
+ __runtimeBundle.surfaces = {};
73
+ }
74
+ return __runtimeBundle.surfaces;
75
+ }
76
+
77
+ function normalizeRuntimeSurfacePackId(surfaceId, packId) {
78
+ const normalizedPackId = typeof packId === 'string' ? packId.trim() : '';
79
+ if (!normalizedPackId) {
80
+ throw new Error('Runtime surface packId is required for surface: ' + String(surfaceId));
81
+ }
82
+ return normalizedPackId;
83
+ }
84
+
85
+ function normalizeRuntimeSurfaceDefinition(surfaceId, definitionOrFactory, packId) {
86
+ const normalizedPackId = normalizeRuntimeSurfacePackId(surfaceId, packId);
87
+ const definition =
88
+ typeof definitionOrFactory === 'function'
89
+ ? definitionOrFactory(collectRuntimePackageApis())
90
+ : definitionOrFactory;
91
+
92
+ if (!definition || typeof definition !== 'object') {
93
+ throw new Error('Runtime surface definition must be an object for surface: ' + String(surfaceId));
94
+ }
95
+
96
+ if (typeof definition.render !== 'function') {
97
+ throw new Error('Runtime surface definition render() is required for surface: ' + String(surfaceId));
98
+ }
99
+
100
+ if (definition.handlers !== undefined) {
101
+ if (!definition.handlers || typeof definition.handlers !== 'object' || Array.isArray(definition.handlers)) {
102
+ throw new Error('Runtime surface definition handlers must be an object for surface: ' + String(surfaceId));
103
+ }
104
+ } else {
105
+ definition.handlers = {};
106
+ }
107
+
108
+ definition.packId = normalizedPackId;
109
+ return definition;
110
+ }
111
+
112
+ function ensureRuntimeSurfaceRecord(surfaceId) {
113
+ const surfaces = assertSurfacesMap();
114
+ const key = String(surfaceId);
115
+ const existing = surfaces[key];
116
+ if (!existing || typeof existing !== 'object') {
117
+ surfaces[key] = {
118
+ handlers: {},
119
+ };
120
+ } else if (!existing.handlers || typeof existing.handlers !== 'object') {
121
+ existing.handlers = {};
122
+ }
123
+ return surfaces[key];
124
+ }
125
+
126
+ function defineRuntimeSurfaceImpl(surfaceId, definitionOrFactory, packId) {
127
+ const surfaces = assertSurfacesMap();
128
+ const key = String(surfaceId);
129
+ surfaces[key] = normalizeRuntimeSurfaceDefinition(key, definitionOrFactory, packId);
130
+ }
131
+
132
+ function defineRuntimeSurfaceRenderImpl(surfaceId, renderFn) {
133
+ if (typeof renderFn !== 'function') {
134
+ throw new Error('defineRuntimeSurfaceRender requires a render function');
135
+ }
136
+
137
+ const surface = ensureRuntimeSurfaceRecord(surfaceId);
138
+ surface.render = renderFn;
139
+ }
140
+
141
+ function defineRuntimeSurfaceHandlerImpl(surfaceId, handlerName, handlerFn) {
142
+ if (typeof handlerFn !== 'function') {
143
+ throw new Error('defineRuntimeSurfaceHandler requires a handler function');
144
+ }
145
+
146
+ const surface = ensureRuntimeSurfaceRecord(surfaceId);
147
+ surface.handlers[String(handlerName)] = handlerFn;
148
+ }
149
+
150
+ globalThis.defineRuntimeBundle = defineRuntimeBundleImpl;
151
+ globalThis.defineRuntimeSurface = defineRuntimeSurfaceImpl;
152
+ globalThis.defineRuntimeSurfaceRender = defineRuntimeSurfaceRenderImpl;
153
+ globalThis.defineRuntimeSurfaceHandler = defineRuntimeSurfaceHandlerImpl;
154
+ globalThis.registerRuntimePackageApi = registerRuntimePackageApi;
155
+
156
+ globalThis.__runtimeBundleHost = {
157
+ getMeta() {
158
+ if (!__runtimeBundle || typeof __runtimeBundle !== 'object') {
159
+ throw new Error('Runtime bundle did not register via defineRuntimeBundle');
160
+ }
161
+
162
+ if (!__runtimeBundle.surfaces || typeof __runtimeBundle.surfaces !== 'object') {
163
+ throw new Error('Runtime bundle surfaces must be an object');
164
+ }
165
+
166
+ return {
167
+ declaredId: typeof __runtimeBundle.id === 'string' ? __runtimeBundle.id : undefined,
168
+ title: String(__runtimeBundle.title ?? 'Untitled Bundle'),
169
+ description: typeof __runtimeBundle.description === 'string' ? __runtimeBundle.description : undefined,
170
+ packageIds: Array.isArray(__runtimeBundle.packageIds)
171
+ ? __runtimeBundle.packageIds.map((packageId) => String(packageId)).filter((packageId) => packageId.length > 0)
172
+ : [],
173
+ initialSessionState: __runtimeBundle.initialSessionState,
174
+ initialSurfaceState: __runtimeBundle.initialSurfaceState,
175
+ surfaces: Object.keys(__runtimeBundle.surfaces),
176
+ surfaceTypes: Object.fromEntries(
177
+ Object.entries(__runtimeBundle.surfaces).map(([key, surface]) => [
178
+ key,
179
+ normalizeRuntimeSurfacePackId(key, surface?.packId),
180
+ ]),
181
+ ),
182
+ };
183
+ },
184
+
185
+ renderRuntimeSurface(surfaceId, state) {
186
+ const surface = __runtimeBundle?.surfaces?.[surfaceId];
187
+ if (!surface || typeof surface.render !== 'function') {
188
+ throw new Error('Runtime surface not found or render() is missing: ' + String(surfaceId));
189
+ }
190
+
191
+ return surface.render({ state });
192
+ },
193
+
194
+ eventRuntimeSurface(surfaceId, handlerName, args, state) {
195
+ const surface = __runtimeBundle?.surfaces?.[surfaceId];
196
+ if (!surface) {
197
+ throw new Error('Runtime surface not found: ' + String(surfaceId));
198
+ }
199
+
200
+ const handler = surface.handlers?.[handlerName];
201
+ if (typeof handler !== 'function') {
202
+ throw new Error('Handler not found: ' + String(handlerName));
203
+ }
204
+
205
+ __runtimeActions = [];
206
+
207
+ const dispatch = (action) => {
208
+ __runtimeActions.push(action);
209
+ };
210
+
211
+ handler(
212
+ {
213
+ state,
214
+ dispatch,
215
+ },
216
+ args
217
+ );
218
+
219
+ return __runtimeActions.slice();
220
+ },
221
+
222
+ defineRuntimeSurface(surfaceId, definitionOrFactory, packId) {
223
+ defineRuntimeSurfaceImpl(surfaceId, definitionOrFactory, packId);
224
+ return this.getMeta();
225
+ },
226
+
227
+ defineRuntimeSurfaceRender(surfaceId, renderFn) {
228
+ defineRuntimeSurfaceRenderImpl(surfaceId, renderFn);
229
+ return this.getMeta();
230
+ },
231
+
232
+ defineRuntimeSurfaceHandler(surfaceId, handlerName, handlerFn) {
233
+ defineRuntimeSurfaceHandlerImpl(surfaceId, handlerName, handlerFn);
234
+ return this.getMeta();
235
+ },
236
+ };
@@ -0,0 +1,25 @@
1
+ import type { JsEvalResult } from '../plugin-runtime/jsSessionService';
2
+ export interface AttachedJsSessionSummary {
3
+ sessionId: string;
4
+ stackId: string;
5
+ title: string;
6
+ origin: 'attached-runtime';
7
+ writable: true;
8
+ }
9
+ export interface AttachedJsSessionHandle {
10
+ sessionId: string;
11
+ stackId: string;
12
+ origin: 'attached-runtime';
13
+ writable: true;
14
+ evaluate(code: string): JsEvalResult;
15
+ inspectGlobals(): string[];
16
+ }
17
+ export interface AttachedJsSessionEntry {
18
+ handle: AttachedJsSessionHandle;
19
+ summary: AttachedJsSessionSummary;
20
+ }
21
+ export declare function clearAttachedJsSessions(): void;
22
+ export declare function listAttachedJsSessions(): AttachedJsSessionEntry[];
23
+ export declare function getAttachedJsSession(sessionId: string): AttachedJsSessionEntry | null;
24
+ export declare function subscribeAttachedJsSessions(listener: () => void): () => void;
25
+ export declare function useAttachedJsSessions(): AttachedJsSessionEntry[];
@@ -0,0 +1,81 @@
1
+ import { useSyncExternalStore } from 'react';
2
+ import { DEFAULT_RUNTIME_SESSION_MANAGER } from '../runtime-session-manager';
3
+ let snapshot = [];
4
+ const listeners = new Set();
5
+ let unsubscribeManager = null;
6
+ function emit() {
7
+ listeners.forEach((listener) => listener());
8
+ }
9
+ function rebuildSnapshot() {
10
+ snapshot = DEFAULT_RUNTIME_SESSION_MANAGER.listSessions()
11
+ .filter((summary) => summary.status === 'ready' && summary.attachedViewIds.length > 0)
12
+ .map((summary) => {
13
+ const handle = DEFAULT_RUNTIME_SESSION_MANAGER.getSession(summary.sessionId);
14
+ if (!handle) {
15
+ return null;
16
+ }
17
+ return {
18
+ handle: {
19
+ sessionId: summary.sessionId,
20
+ stackId: summary.bundleId,
21
+ origin: 'attached-runtime',
22
+ writable: true,
23
+ evaluate(code) {
24
+ return handle.evaluateSessionJs(code);
25
+ },
26
+ inspectGlobals() {
27
+ return handle.getSessionGlobalNames();
28
+ },
29
+ },
30
+ summary: {
31
+ sessionId: summary.sessionId,
32
+ stackId: summary.bundleId,
33
+ title: summary.title,
34
+ origin: 'attached-runtime',
35
+ writable: true,
36
+ },
37
+ };
38
+ })
39
+ .filter((entry) => entry !== null)
40
+ .sort((left, right) => left.summary.sessionId.localeCompare(right.summary.sessionId));
41
+ }
42
+ function ensureSubscribed() {
43
+ if (unsubscribeManager) {
44
+ return;
45
+ }
46
+ rebuildSnapshot();
47
+ unsubscribeManager = DEFAULT_RUNTIME_SESSION_MANAGER.subscribe(() => {
48
+ rebuildSnapshot();
49
+ emit();
50
+ });
51
+ }
52
+ function releaseSubscriptionIfIdle() {
53
+ if (listeners.size > 0 || !unsubscribeManager) {
54
+ return;
55
+ }
56
+ unsubscribeManager();
57
+ unsubscribeManager = null;
58
+ snapshot = [];
59
+ }
60
+ export function clearAttachedJsSessions() {
61
+ rebuildSnapshot();
62
+ }
63
+ export function listAttachedJsSessions() {
64
+ ensureSubscribed();
65
+ return snapshot;
66
+ }
67
+ export function getAttachedJsSession(sessionId) {
68
+ ensureSubscribed();
69
+ return snapshot.find((entry) => entry.summary.sessionId === sessionId) ?? null;
70
+ }
71
+ export function subscribeAttachedJsSessions(listener) {
72
+ ensureSubscribed();
73
+ listeners.add(listener);
74
+ return () => {
75
+ listeners.delete(listener);
76
+ releaseSubscriptionIfIdle();
77
+ };
78
+ }
79
+ export function useAttachedJsSessions() {
80
+ return useSyncExternalStore(subscribeAttachedJsSessions, listAttachedJsSessions, listAttachedJsSessions);
81
+ }
@@ -0,0 +1,11 @@
1
+ import type { SessionId } from '../plugin-runtime/contracts';
2
+ import type { RuntimeSessionHandle, RuntimeSessionSummary } from './runtimeBroker';
3
+ export interface AttachedRuntimeSessionEntry {
4
+ handle: RuntimeSessionHandle;
5
+ summary: RuntimeSessionSummary;
6
+ }
7
+ export declare function clearAttachedRuntimeSessions(): void;
8
+ export declare function listAttachedRuntimeSessions(): AttachedRuntimeSessionEntry[];
9
+ export declare function getAttachedRuntimeSession(sessionId: SessionId): AttachedRuntimeSessionEntry | null;
10
+ export declare function subscribeAttachedRuntimeSessions(listener: () => void): () => void;
11
+ export declare function useAttachedRuntimeSessions(): AttachedRuntimeSessionEntry[];
@@ -0,0 +1,107 @@
1
+ import { useSyncExternalStore } from 'react';
2
+ import { ATTACHED_READ_ONLY_RUNTIME_SESSION, DEFAULT_RUNTIME_SESSION_MANAGER, } from '../runtime-session-manager';
3
+ let snapshot = [];
4
+ const listeners = new Set();
5
+ let unsubscribeManager = null;
6
+ function emit() {
7
+ listeners.forEach((listener) => listener());
8
+ }
9
+ function toSummary(summary) {
10
+ return {
11
+ sessionId: summary.sessionId,
12
+ stackId: summary.bundleId,
13
+ packageIds: [...summary.packageIds],
14
+ surfaces: [...summary.surfaces],
15
+ surfaceTypes: summary.surfaceTypes ? { ...summary.surfaceTypes } : undefined,
16
+ title: summary.title,
17
+ description: summary.description,
18
+ origin: 'attached',
19
+ writable: false,
20
+ ownership: ATTACHED_READ_ONLY_RUNTIME_SESSION,
21
+ };
22
+ }
23
+ function toHandle(handle) {
24
+ return {
25
+ sessionId: handle.sessionId,
26
+ stackId: handle.bundleId,
27
+ origin: 'attached',
28
+ writable: false,
29
+ getBundleMeta() {
30
+ return handle.getBundleMeta();
31
+ },
32
+ renderSurface(surfaceId, state) {
33
+ return handle.renderSurface(surfaceId, state);
34
+ },
35
+ eventSurface(surfaceId, handler, args, state) {
36
+ return handle.eventSurface(surfaceId, handler, args, state);
37
+ },
38
+ defineSurface() {
39
+ throw new Error(`Attached runtime session ${handle.sessionId} is read-only`);
40
+ },
41
+ defineSurfaceRender() {
42
+ throw new Error(`Attached runtime session ${handle.sessionId} is read-only`);
43
+ },
44
+ defineSurfaceHandler() {
45
+ throw new Error(`Attached runtime session ${handle.sessionId} is read-only`);
46
+ },
47
+ dispose() {
48
+ return false;
49
+ },
50
+ };
51
+ }
52
+ function rebuildSnapshot() {
53
+ snapshot = DEFAULT_RUNTIME_SESSION_MANAGER.listSessions()
54
+ .filter((summary) => summary.status === 'ready' && summary.attachedViewIds.length > 0)
55
+ .map((summary) => {
56
+ const handle = DEFAULT_RUNTIME_SESSION_MANAGER.getSession(summary.sessionId);
57
+ if (!handle) {
58
+ return null;
59
+ }
60
+ return {
61
+ handle: toHandle(handle),
62
+ summary: toSummary(summary),
63
+ };
64
+ })
65
+ .filter((entry) => entry !== null)
66
+ .sort((left, right) => left.summary.sessionId.localeCompare(right.summary.sessionId));
67
+ }
68
+ function ensureSubscribed() {
69
+ if (unsubscribeManager) {
70
+ return;
71
+ }
72
+ rebuildSnapshot();
73
+ unsubscribeManager = DEFAULT_RUNTIME_SESSION_MANAGER.subscribe(() => {
74
+ rebuildSnapshot();
75
+ emit();
76
+ });
77
+ }
78
+ function releaseSubscriptionIfIdle() {
79
+ if (listeners.size > 0 || !unsubscribeManager) {
80
+ return;
81
+ }
82
+ unsubscribeManager();
83
+ unsubscribeManager = null;
84
+ snapshot = [];
85
+ }
86
+ export function clearAttachedRuntimeSessions() {
87
+ rebuildSnapshot();
88
+ }
89
+ export function listAttachedRuntimeSessions() {
90
+ ensureSubscribed();
91
+ return snapshot;
92
+ }
93
+ export function getAttachedRuntimeSession(sessionId) {
94
+ ensureSubscribed();
95
+ return snapshot.find((entry) => entry.summary.sessionId === sessionId) ?? null;
96
+ }
97
+ export function subscribeAttachedRuntimeSessions(listener) {
98
+ ensureSubscribed();
99
+ listeners.add(listener);
100
+ return () => {
101
+ listeners.delete(listener);
102
+ releaseSubscriptionIfIdle();
103
+ };
104
+ }
105
+ export function useAttachedRuntimeSessions() {
106
+ return useSyncExternalStore(subscribeAttachedRuntimeSessions, listAttachedRuntimeSessions, listAttachedRuntimeSessions);
107
+ }
@@ -0,0 +1,54 @@
1
+ import type { ReplDriver } from '@go-go-golems/os-repl';
2
+ import { type RuntimeBroker } from './runtimeBroker';
3
+ export interface ReplBundleLibraryEntry {
4
+ key: string;
5
+ title?: string;
6
+ stackId: string;
7
+ packageIds: string[];
8
+ bundleCode: string;
9
+ docsMetadata?: RuntimeBundleDocsMetadata;
10
+ }
11
+ export interface HypercardReplDriverOptions {
12
+ broker?: RuntimeBroker;
13
+ bundleLibrary?: Record<string, ReplBundleLibraryEntry>;
14
+ }
15
+ interface RuntimePackageDocSymbol {
16
+ readonly name: string;
17
+ readonly summary?: string;
18
+ readonly prose?: string;
19
+ }
20
+ interface RuntimePackageDocFile {
21
+ readonly package?: {
22
+ readonly name?: string;
23
+ readonly title?: string;
24
+ readonly description?: string;
25
+ readonly prose?: string;
26
+ };
27
+ readonly symbols?: readonly RuntimePackageDocSymbol[];
28
+ }
29
+ interface RuntimePackageDocsMetadata {
30
+ readonly packId?: string;
31
+ readonly docs?: {
32
+ readonly files?: readonly RuntimePackageDocFile[];
33
+ };
34
+ }
35
+ interface RuntimeBundleDocSymbol {
36
+ readonly name: string;
37
+ readonly summary?: string;
38
+ readonly prose?: string;
39
+ }
40
+ interface RuntimeBundleDocFile {
41
+ readonly file_path?: string;
42
+ readonly symbols?: readonly RuntimeBundleDocSymbol[];
43
+ }
44
+ interface RuntimeBundleDocsMetadata {
45
+ readonly packId?: string;
46
+ readonly docs?: {
47
+ readonly files?: readonly RuntimeBundleDocFile[];
48
+ readonly by_symbol?: Readonly<Record<string, RuntimeBundleDocSymbol>>;
49
+ };
50
+ }
51
+ export declare function createHypercardReplDriver(options?: HypercardReplDriverOptions): ReplDriver;
52
+ export declare function getRuntimePackageDocsMetadata(packageId: string): RuntimePackageDocsMetadata | null;
53
+ export declare function getHypercardReplDriverState(driver: ReplDriver): Record<string, unknown>;
54
+ export {};