@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
package/index.js ADDED
@@ -0,0 +1,18 @@
1
+ export * from './app';
2
+ export * from './plugin-runtime';
3
+ export * from './repl/hypercardReplDriver';
4
+ export * from './repl/attachedJsSessionRegistry';
5
+ export * from './repl/attachedRuntimeSessionRegistry';
6
+ export * from './repl/jsReplDriver';
7
+ export * from './repl/jsSessionBroker';
8
+ export * from './repl/runtimeBroker';
9
+ export * from './runtime-session-manager';
10
+ export * from './features/runtimeSessions';
11
+ export * from './hypercard';
12
+ export * from './hypercard/debug/runtimeDebugApp';
13
+ export * from './hypercard/debug/runtimeDebugRegistry';
14
+ export * from './hypercard/task-manager';
15
+ export * from './runtime-packs';
16
+ export * from './runtime-packages';
17
+ export { RuntimeSurfaceSessionHost } from './runtime-host/RuntimeSurfaceSessionHost';
18
+ export { dispatchRuntimeAction } from './runtime-host/pluginIntentRouting';
package/package.json ADDED
@@ -0,0 +1,72 @@
1
+ {
2
+ "name": "@go-go-golems/os-scripting",
3
+ "version": "0.1.0",
4
+ "type": "module",
5
+ "description": "QuickJS runtime, plugin, and REPL-session support for go-go-os.",
6
+ "keywords": [
7
+ "quickjs",
8
+ "runtime",
9
+ "vm",
10
+ "scripting",
11
+ "react",
12
+ "go-go-os",
13
+ "go-go-golems"
14
+ ],
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "git+https://github.com/go-go-golems/go-go-os-frontend.git",
18
+ "directory": "packages/os-scripting"
19
+ },
20
+ "homepage": "https://github.com/go-go-golems/go-go-os-frontend/tree/main/packages/os-scripting#readme",
21
+ "bugs": {
22
+ "url": "https://github.com/go-go-golems/go-go-os-frontend/issues"
23
+ },
24
+ "license": "MIT",
25
+ "author": "Manuel Odendahl",
26
+ "sideEffects": [
27
+ "**/*.css"
28
+ ],
29
+ "files": [
30
+ "**/*.js",
31
+ "**/*.d.ts",
32
+ "**/*.css",
33
+ "**/*.vm.js",
34
+ "**/*.json",
35
+ "README.md"
36
+ ],
37
+ "exports": {
38
+ ".": "./index.js"
39
+ },
40
+ "main": "./index.js",
41
+ "types": "./index.d.ts",
42
+ "dependencies": {
43
+ "@go-go-golems/os-core": "0.1.1",
44
+ "@go-go-golems/os-chat": "0.1.0",
45
+ "@go-go-golems/os-repl": "0.1.5",
46
+ "@codemirror/commands": "^6.10.2",
47
+ "@codemirror/autocomplete": "^6.18.7",
48
+ "@codemirror/lang-javascript": "^6.2.4",
49
+ "@codemirror/language": "^6.12.1",
50
+ "@codemirror/lint": "^6.8.5",
51
+ "@codemirror/state": "^6.5.4",
52
+ "@codemirror/theme-one-dark": "^6.1.3",
53
+ "@codemirror/view": "^6.39.15",
54
+ "@jitl/quickjs-singlefile-mjs-release-sync": "^0.31.0",
55
+ "@jitl/quickjs-ffi-types": "^0.31.0",
56
+ "@lezer/common": "^1.3.0",
57
+ "@lezer/highlight": "^1.2.3",
58
+ "@lezer/javascript": "^1.5.1",
59
+ "@lezer/lr": "^1.4.2",
60
+ "quickjs-emscripten": "^0.31.0",
61
+ "quickjs-emscripten-core": "^0.31.0"
62
+ },
63
+ "peerDependencies": {
64
+ "@reduxjs/toolkit": "^2.0.0",
65
+ "react": "^18 || ^19",
66
+ "react-dom": "^18 || ^19",
67
+ "react-redux": "^9.0.0"
68
+ },
69
+ "publishConfig": {
70
+ "access": "public"
71
+ }
72
+ }
@@ -0,0 +1,116 @@
1
+ export type StackId = string;
2
+ export type SessionId = string;
3
+ export type RuntimeSurfaceId = string;
4
+ export interface RuntimeErrorPayload {
5
+ code: string;
6
+ message: string;
7
+ details?: unknown;
8
+ }
9
+ export interface RuntimeAction {
10
+ type: string;
11
+ payload?: unknown;
12
+ meta?: Record<string, unknown>;
13
+ }
14
+ export type RuntimeActionKind = 'draft' | 'filters' | 'domain' | 'system' | 'unknown';
15
+ export declare function getRuntimeActionKind(actionType: string): RuntimeActionKind;
16
+ export declare function getRuntimeActionDomain(actionType: string): string | null;
17
+ export declare function getRuntimeActionOperation(actionType: string): string;
18
+ export interface RuntimeBundleMeta {
19
+ stackId: StackId;
20
+ sessionId: SessionId;
21
+ declaredId?: string;
22
+ title: string;
23
+ description?: string;
24
+ packageIds: string[];
25
+ initialSessionState?: unknown;
26
+ initialSurfaceState?: Record<string, unknown>;
27
+ surfaces: string[];
28
+ surfaceTypes?: Record<string, string>;
29
+ }
30
+ export interface LoadRuntimeBundleRequest {
31
+ id: number;
32
+ type: 'loadRuntimeBundle';
33
+ stackId: StackId;
34
+ sessionId: SessionId;
35
+ code: string;
36
+ }
37
+ export interface RenderRuntimeSurfaceRequest {
38
+ id: number;
39
+ type: 'renderRuntimeSurface';
40
+ sessionId: SessionId;
41
+ surfaceId: RuntimeSurfaceId;
42
+ state: unknown;
43
+ }
44
+ export interface EventRuntimeSurfaceRequest {
45
+ id: number;
46
+ type: 'eventRuntimeSurface';
47
+ sessionId: SessionId;
48
+ surfaceId: RuntimeSurfaceId;
49
+ handler: string;
50
+ args?: unknown;
51
+ state: unknown;
52
+ }
53
+ export interface DefineRuntimeSurfaceRequest {
54
+ id: number;
55
+ type: 'defineRuntimeSurface';
56
+ sessionId: SessionId;
57
+ surfaceId: RuntimeSurfaceId;
58
+ code: string;
59
+ packId: string;
60
+ }
61
+ export interface DefineRuntimeSurfaceRenderRequest {
62
+ id: number;
63
+ type: 'defineRuntimeSurfaceRender';
64
+ sessionId: SessionId;
65
+ surfaceId: RuntimeSurfaceId;
66
+ code: string;
67
+ }
68
+ export interface DefineRuntimeSurfaceHandlerRequest {
69
+ id: number;
70
+ type: 'defineRuntimeSurfaceHandler';
71
+ sessionId: SessionId;
72
+ surfaceId: RuntimeSurfaceId;
73
+ handler: string;
74
+ code: string;
75
+ }
76
+ export interface DisposeSessionRequest {
77
+ id: number;
78
+ type: 'disposeSession';
79
+ sessionId: SessionId;
80
+ }
81
+ export interface HealthRequest {
82
+ id: number;
83
+ type: 'health';
84
+ }
85
+ export type WorkerRequest = LoadRuntimeBundleRequest | RenderRuntimeSurfaceRequest | EventRuntimeSurfaceRequest | DefineRuntimeSurfaceRequest | DefineRuntimeSurfaceRenderRequest | DefineRuntimeSurfaceHandlerRequest | DisposeSessionRequest | HealthRequest;
86
+ export interface LoadRuntimeBundleResult {
87
+ bundle: RuntimeBundleMeta;
88
+ }
89
+ export interface RenderRuntimeSurfaceResult {
90
+ tree: unknown;
91
+ }
92
+ export interface EventRuntimeSurfaceResult {
93
+ actions: RuntimeAction[];
94
+ }
95
+ export interface DefineRuntimeSurfaceResult {
96
+ bundle: RuntimeBundleMeta;
97
+ }
98
+ export interface DisposeSessionResult {
99
+ disposed: boolean;
100
+ }
101
+ export interface HealthResult {
102
+ ready: true;
103
+ sessions: string[];
104
+ }
105
+ export type WorkerResult = LoadRuntimeBundleResult | RenderRuntimeSurfaceResult | EventRuntimeSurfaceResult | DefineRuntimeSurfaceResult | DisposeSessionResult | HealthResult;
106
+ export interface WorkerSuccessResponse {
107
+ id: number;
108
+ ok: true;
109
+ result: WorkerResult;
110
+ }
111
+ export interface WorkerErrorResponse {
112
+ id: number;
113
+ ok: false;
114
+ error: RuntimeErrorPayload;
115
+ }
116
+ export type WorkerResponse = WorkerSuccessResponse | WorkerErrorResponse;
@@ -0,0 +1,32 @@
1
+ const SYSTEM_ACTION_TYPES = new Set(['nav.go', 'nav.back', 'notify.show', 'window.close']);
2
+ export function getRuntimeActionKind(actionType) {
3
+ if (actionType.startsWith('draft.')) {
4
+ return 'draft';
5
+ }
6
+ if (actionType.startsWith('filters.')) {
7
+ return 'filters';
8
+ }
9
+ if (SYSTEM_ACTION_TYPES.has(actionType)) {
10
+ return 'system';
11
+ }
12
+ const slashIndex = actionType.indexOf('/');
13
+ if (slashIndex > 0) {
14
+ return 'domain';
15
+ }
16
+ return 'unknown';
17
+ }
18
+ export function getRuntimeActionDomain(actionType) {
19
+ if (getRuntimeActionKind(actionType) !== 'domain') {
20
+ return null;
21
+ }
22
+ return actionType.split('/', 1)[0] ?? null;
23
+ }
24
+ export function getRuntimeActionOperation(actionType) {
25
+ if (actionType.startsWith('draft.')) {
26
+ return actionType.slice('draft.'.length);
27
+ }
28
+ if (actionType.startsWith('filters.')) {
29
+ return actionType.slice('filters.'.length);
30
+ }
31
+ return actionType;
32
+ }
@@ -0,0 +1,19 @@
1
+ defineRuntimeBundle(({ ui }) => {
2
+ return {
3
+ id: 'column-demo',
4
+ title: 'Column Demo',
5
+ packageIds: ["ui"],
6
+ surfaces: {
7
+ main: {
8
+ packId: 'ui.card.v1',
9
+ render() {
10
+ return ui.column([
11
+ ui.text('top'),
12
+ ui.text('bottom'),
13
+ ]);
14
+ },
15
+ handlers: {},
16
+ },
17
+ },
18
+ };
19
+ });
@@ -0,0 +1,13 @@
1
+ ({ ui }) => ({
2
+ render({ state }) {
3
+ return ui.panel([
4
+ ui.text('Dynamic card: ' + String(state?.draft?.name ?? 'n/a')),
5
+ ui.button('Back', { onClick: { handler: 'back' } }),
6
+ ]);
7
+ },
8
+ handlers: {
9
+ back({ dispatch }) {
10
+ dispatch({ type: 'nav.back' });
11
+ },
12
+ },
13
+ })
@@ -0,0 +1,29 @@
1
+ defineRuntimeBundle(({ ui }) => {
2
+ return {
3
+ id: 'inventory',
4
+ title: 'Inventory',
5
+ packageIds: ["ui"],
6
+ initialSessionState: { filter: 'all' },
7
+ initialSurfaceState: { lowStock: { limit: 5 } },
8
+ surfaces: {
9
+ lowStock: {
10
+ packId: 'ui.card.v1',
11
+ render({ state }) {
12
+ return ui.panel([
13
+ ui.text('Filter: ' + String(state?.filters?.filter ?? 'all')),
14
+ ui.text('Limit: ' + String(state?.draft?.limit ?? 0)),
15
+ ui.button('Reserve', { onClick: { handler: 'reserve', args: { sku: 'A-1' } } }),
16
+ ]);
17
+ },
18
+ handlers: {
19
+ reserve({ dispatch }, args) {
20
+ dispatch({ type: 'draft.set', payload: { path: 'lastSku', value: args?.sku } });
21
+ dispatch({ type: 'filters.set', payload: { path: 'filter', value: 'low-stock' } });
22
+ dispatch({ type: 'inventory/reserve-item', payload: { sku: args?.sku } });
23
+ dispatch({ type: 'notify.show', payload: { level: 'info', message: 'reserved' } });
24
+ },
25
+ },
26
+ },
27
+ },
28
+ };
29
+ });
@@ -0,0 +1,55 @@
1
+ ({ widgets }) => ({
2
+ render({ state }) {
3
+ const board = state?.app_kanban ?? {};
4
+
5
+ return widgets.kanban.page(
6
+ widgets.kanban.taxonomy({
7
+ issueTypes: Array.isArray(board.taxonomy?.issueTypes) ? board.taxonomy.issueTypes : [{ id: 'feature', label: 'Feature', icon: '✨' }],
8
+ priorities: Array.isArray(board.taxonomy?.priorities) ? board.taxonomy.priorities : [{ id: 'high', label: 'High', icon: '▲' }],
9
+ labels: Array.isArray(board.taxonomy?.labels) ? board.taxonomy.labels : [{ id: 'frontend', label: 'Frontend', icon: '🖼️' }],
10
+ }),
11
+ widgets.kanban.header({
12
+ title: 'Sprint Board',
13
+ subtitle: 'Fixture board',
14
+ searchQuery: typeof board.searchQuery === 'string' ? board.searchQuery : '',
15
+ }),
16
+ widgets.kanban.highlights({
17
+ items: [
18
+ {
19
+ id: 'total',
20
+ label: 'Total',
21
+ value: Array.isArray(board.tasks) ? board.tasks.length : 0,
22
+ tone: 'accent',
23
+ },
24
+ ],
25
+ }),
26
+ widgets.kanban.filters({
27
+ filterType: board.filterType ?? null,
28
+ filterPriority: board.filterPriority ?? null,
29
+ }),
30
+ widgets.kanban.board({
31
+ columns: Array.isArray(board.columns) ? board.columns : [],
32
+ tasks: Array.isArray(board.tasks) ? board.tasks : [],
33
+ editingTask: board.editingTask ?? null,
34
+ collapsedCols:
35
+ board.collapsedCols && typeof board.collapsedCols === 'object' && !Array.isArray(board.collapsedCols)
36
+ ? board.collapsedCols
37
+ : {},
38
+ onMoveTask: { handler: 'moveTask' },
39
+ }),
40
+ widgets.kanban.status({
41
+ metrics: [
42
+ { label: 'total', value: Array.isArray(board.tasks) ? board.tasks.length : 0 },
43
+ ],
44
+ }),
45
+ );
46
+ },
47
+ handlers: {
48
+ moveTask({ dispatch }, args) {
49
+ dispatch({
50
+ type: 'kanban/move-task',
51
+ payload: args,
52
+ });
53
+ },
54
+ },
55
+ })
@@ -0,0 +1,16 @@
1
+ defineRuntimeBundle(({ ui }) => {
2
+ return {
3
+ id: 'loop',
4
+ title: 'Loop',
5
+ packageIds: ["ui"],
6
+ surfaces: {
7
+ loop: {
8
+ packId: 'ui.card.v1',
9
+ render() {
10
+ while (true) {}
11
+ },
12
+ handlers: {},
13
+ },
14
+ },
15
+ };
16
+ });
@@ -0,0 +1,3 @@
1
+ ({ dispatch }) => {
2
+ dispatch({ type: 'notify.show', payload: { level: 'info', message: 'patched-handler' } });
3
+ }
@@ -0,0 +1,5 @@
1
+ ({ state }) =>
2
+ ui.panel([
3
+ ui.text('Patched limit: ' + String(state?.draft?.limit ?? 0)),
4
+ ui.button('Reserve', { onClick: { handler: 'reserve', args: { sku: 'A-1' } } }),
5
+ ])
@@ -0,0 +1,6 @@
1
+ export * from './contracts';
2
+ export * from './intentSchema';
3
+ export * from './jsSessionService';
4
+ export * from './quickJsSessionCore';
5
+ export * from './runtimeSurfaceRegistry';
6
+ export * from './runtimeService';
@@ -0,0 +1,6 @@
1
+ export * from './contracts';
2
+ export * from './intentSchema';
3
+ export * from './jsSessionService';
4
+ export * from './quickJsSessionCore';
5
+ export * from './runtimeSurfaceRegistry';
6
+ export * from './runtimeService';
@@ -0,0 +1,3 @@
1
+ import type { RuntimeAction } from './contracts';
2
+ export declare function validateRuntimeAction(value: unknown): RuntimeAction;
3
+ export declare function validateRuntimeActions(value: unknown): RuntimeAction[];
@@ -0,0 +1,25 @@
1
+ function isRecord(value) {
2
+ return typeof value === 'object' && value !== null && !Array.isArray(value);
3
+ }
4
+ export function validateRuntimeAction(value) {
5
+ if (!isRecord(value)) {
6
+ throw new Error('Runtime action must be an object');
7
+ }
8
+ if (typeof value.type !== 'string' || value.type.length === 0) {
9
+ throw new Error('Runtime action type must be a non-empty string');
10
+ }
11
+ if (value.meta !== undefined && !isRecord(value.meta)) {
12
+ throw new Error('Runtime action meta must be an object when provided');
13
+ }
14
+ return {
15
+ type: value.type,
16
+ payload: value.payload,
17
+ meta: value.meta,
18
+ };
19
+ }
20
+ export function validateRuntimeActions(value) {
21
+ if (!Array.isArray(value)) {
22
+ throw new Error('Runtime actions result must be an array');
23
+ }
24
+ return value.map((action) => validateRuntimeAction(action));
25
+ }
@@ -0,0 +1,6 @@
1
+ import { type QuickJsSessionVm } from './quickJsSessionCore';
2
+ import type { JsEvalResult } from './jsSessionService';
3
+ export declare function installJsEvalBridge(vm: QuickJsSessionVm, filename: string, timeoutMs: number): void;
4
+ export declare function consumeJsEvalLogs(vm: QuickJsSessionVm, filename: string, timeoutMs: number): string[];
5
+ export declare function evaluateQuickJsSessionJs(vm: QuickJsSessionVm, code: string, filename: string, evalTimeoutMs: number, inspectTimeoutMs: number): JsEvalResult;
6
+ export declare function getQuickJsSessionGlobalNames(vm: QuickJsSessionVm, filename: string, timeoutMs: number): string[];
@@ -0,0 +1,93 @@
1
+ import { evalQuickJsCodeOrThrow, evalQuickJsToNative, } from './quickJsSessionCore';
2
+ const JS_EVAL_BRIDGE_BOOTSTRAP_SOURCE = `
3
+ if (!globalThis.__jsEvalHost) {
4
+ globalThis.__jsEvalHost = {
5
+ logs: [],
6
+ pushLog(text) {
7
+ this.logs.push(String(text));
8
+ },
9
+ consumeLogs() {
10
+ const copy = this.logs.slice();
11
+ this.logs.length = 0;
12
+ return copy;
13
+ }
14
+ };
15
+
16
+ const __existingConsole = globalThis.console && typeof globalThis.console === 'object'
17
+ ? globalThis.console
18
+ : {};
19
+ const __baseLog = typeof __existingConsole.log === 'function'
20
+ ? __existingConsole.log.bind(__existingConsole)
21
+ : null;
22
+
23
+ globalThis.console = {
24
+ ...__existingConsole,
25
+ log(...args) {
26
+ globalThis.__jsEvalHost.pushLog(args.map((arg) => String(arg)).join(' '));
27
+ if (__baseLog) {
28
+ return __baseLog(...args);
29
+ }
30
+ }
31
+ };
32
+ }
33
+ `;
34
+ function valueTypeOf(value) {
35
+ if (value === null) {
36
+ return 'null';
37
+ }
38
+ if (Array.isArray(value)) {
39
+ return 'array';
40
+ }
41
+ return typeof value;
42
+ }
43
+ function asError(error) {
44
+ if (error instanceof Error) {
45
+ const [name, ...rest] = error.message.split(':');
46
+ if (rest.length > 0 && name.trim().length > 0) {
47
+ return {
48
+ name: name.trim(),
49
+ message: rest.join(':').trim(),
50
+ };
51
+ }
52
+ return {
53
+ name: 'Error',
54
+ message: error.message,
55
+ };
56
+ }
57
+ return {
58
+ name: 'Error',
59
+ message: String(error),
60
+ };
61
+ }
62
+ export function installJsEvalBridge(vm, filename, timeoutMs) {
63
+ evalQuickJsCodeOrThrow(vm, JS_EVAL_BRIDGE_BOOTSTRAP_SOURCE, filename, timeoutMs);
64
+ }
65
+ export function consumeJsEvalLogs(vm, filename, timeoutMs) {
66
+ try {
67
+ return evalQuickJsToNative(vm, 'globalThis.__jsEvalHost.consumeLogs()', filename, timeoutMs);
68
+ }
69
+ catch {
70
+ return [];
71
+ }
72
+ }
73
+ export function evaluateQuickJsSessionJs(vm, code, filename, evalTimeoutMs, inspectTimeoutMs) {
74
+ try {
75
+ const value = evalQuickJsToNative(vm, code, filename, evalTimeoutMs);
76
+ return {
77
+ value,
78
+ valueType: valueTypeOf(value),
79
+ logs: consumeJsEvalLogs(vm, `${filename}.consume-logs.js`, inspectTimeoutMs),
80
+ };
81
+ }
82
+ catch (error) {
83
+ return {
84
+ value: undefined,
85
+ valueType: 'error',
86
+ logs: consumeJsEvalLogs(vm, `${filename}.consume-logs.js`, inspectTimeoutMs),
87
+ error: asError(error),
88
+ };
89
+ }
90
+ }
91
+ export function getQuickJsSessionGlobalNames(vm, filename, timeoutMs) {
92
+ return evalQuickJsToNative(vm, 'Object.getOwnPropertyNames(globalThis).sort()', filename, timeoutMs);
93
+ }
@@ -0,0 +1,55 @@
1
+ export interface JsSessionServiceOptions {
2
+ memoryLimitBytes?: number;
3
+ stackLimitBytes?: number;
4
+ loadTimeoutMs?: number;
5
+ evalTimeoutMs?: number;
6
+ inspectTimeoutMs?: number;
7
+ }
8
+ export interface CreateJsSessionRequest {
9
+ sessionId: string;
10
+ title?: string;
11
+ scopeId?: string;
12
+ preludeCode?: string;
13
+ bootstrapSources?: Array<{
14
+ code: string;
15
+ filename: string;
16
+ }>;
17
+ }
18
+ export interface JsSessionSummary {
19
+ sessionId: string;
20
+ title: string;
21
+ createdAt: string;
22
+ globalNames: string[];
23
+ }
24
+ export interface JsEvalError {
25
+ name: string;
26
+ message: string;
27
+ }
28
+ export interface JsEvalResult {
29
+ value: unknown;
30
+ valueType: string;
31
+ logs: string[];
32
+ error?: JsEvalError;
33
+ }
34
+ export declare class JsSessionService {
35
+ private readonly options;
36
+ private readonly sessions;
37
+ constructor(options?: JsSessionServiceOptions);
38
+ private getRecordOrThrow;
39
+ private createRecord;
40
+ createSession(request: CreateJsSessionRequest): Promise<JsSessionSummary>;
41
+ getSummary(sessionId: string): JsSessionSummary;
42
+ listSessions(): JsSessionSummary[];
43
+ evaluate(sessionId: string, code: string): JsEvalResult;
44
+ evaluateToNative<T>(sessionId: string, code: string, filename: string, timeoutMs: number): T;
45
+ runCode(sessionId: string, code: string, filename: string, timeoutMs: number): void;
46
+ getGlobalNames(sessionId: string): string[];
47
+ resetSession(sessionId: string): Promise<JsSessionSummary>;
48
+ disposeSession(sessionId: string): boolean;
49
+ clear(): void;
50
+ health(): {
51
+ ready: true;
52
+ sessions: string[];
53
+ };
54
+ installPrelude(sessionId: string, code: string): void;
55
+ }