@go-go-golems/os-scripting 0.1.0 → 0.1.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@go-go-golems/os-scripting",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "type": "module",
5
5
  "description": "QuickJS runtime, plugin, and REPL-session support for go-go-os.",
6
6
  "keywords": [
@@ -1,7 +1,7 @@
1
1
  import { validateRuntimeActions } from './intentSchema';
2
2
  import { getRuntimePackageOrThrow, resolveRuntimePackageInstallOrder } from '../runtime-packages';
3
3
  import { getRuntimeSurfaceTypeOrThrow } from '../runtime-packs';
4
- import stackBootstrapSource from './stack-bootstrap.vm.js?raw';
4
+ import stackBootstrapSource from './stackBootstrapSource.generated';
5
5
  import { toJsLiteral } from './quickJsSessionCore';
6
6
  import { JsSessionService } from './jsSessionService';
7
7
  const DEFAULT_OPTIONS = {
@@ -0,0 +1,2 @@
1
+ declare const source = "const __runtimePackageState =\n globalThis.__runtimePackageState && typeof globalThis.__runtimePackageState === 'object'\n ? globalThis.__runtimePackageState\n : {\n packageIds: [],\n apis: {},\n };\n\nglobalThis.__runtimePackageState = __runtimePackageState;\n\nlet __runtimeBundle = null;\nlet __runtimeActions = [];\n\nfunction isPlainObject(value) {\n return value && typeof value === 'object' && !Array.isArray(value);\n}\n\nfunction mergeRuntimeApiValue(existingValue, incomingValue) {\n if (isPlainObject(existingValue) && isPlainObject(incomingValue)) {\n const merged = { ...existingValue };\n for (const [key, value] of Object.entries(incomingValue)) {\n merged[key] = mergeRuntimeApiValue(merged[key], value);\n }\n return merged;\n }\n\n return incomingValue;\n}\n\nfunction registerRuntimePackageApi(packageId, apiExports) {\n const normalizedPackageId = String(packageId || '').trim();\n if (!normalizedPackageId) {\n throw new Error('registerRuntimePackageApi requires a package id');\n }\n\n if (!__runtimePackageState.packageIds.includes(normalizedPackageId)) {\n __runtimePackageState.packageIds.push(normalizedPackageId);\n }\n\n if (!isPlainObject(apiExports)) {\n return;\n }\n\n for (const [exportName, exportValue] of Object.entries(apiExports)) {\n const mergedValue = mergeRuntimeApiValue(__runtimePackageState.apis[exportName], exportValue);\n __runtimePackageState.apis[exportName] = mergedValue;\n globalThis[exportName] = mergedValue;\n }\n}\n\nfunction collectRuntimePackageApis() {\n return { ...__runtimePackageState.apis };\n}\n\nfunction defineRuntimeBundleImpl(factory) {\n if (typeof factory !== 'function') {\n throw new Error('defineRuntimeBundle requires a factory function');\n }\n\n __runtimeBundle = factory(collectRuntimePackageApis());\n}\n\nfunction assertStackBundleReady() {\n if (!__runtimeBundle || typeof __runtimeBundle !== 'object') {\n throw new Error('Runtime bundle did not register via defineRuntimeBundle');\n }\n}\n\nfunction assertSurfacesMap() {\n assertStackBundleReady();\n if (!__runtimeBundle.surfaces || typeof __runtimeBundle.surfaces !== 'object') {\n __runtimeBundle.surfaces = {};\n }\n return __runtimeBundle.surfaces;\n}\n\nfunction normalizeRuntimeSurfacePackId(surfaceId, packId) {\n const normalizedPackId = typeof packId === 'string' ? packId.trim() : '';\n if (!normalizedPackId) {\n throw new Error('Runtime surface packId is required for surface: ' + String(surfaceId));\n }\n return normalizedPackId;\n}\n\nfunction normalizeRuntimeSurfaceDefinition(surfaceId, definitionOrFactory, packId) {\n const normalizedPackId = normalizeRuntimeSurfacePackId(surfaceId, packId);\n const definition =\n typeof definitionOrFactory === 'function'\n ? definitionOrFactory(collectRuntimePackageApis())\n : definitionOrFactory;\n\n if (!definition || typeof definition !== 'object') {\n throw new Error('Runtime surface definition must be an object for surface: ' + String(surfaceId));\n }\n\n if (typeof definition.render !== 'function') {\n throw new Error('Runtime surface definition render() is required for surface: ' + String(surfaceId));\n }\n\n if (definition.handlers !== undefined) {\n if (!definition.handlers || typeof definition.handlers !== 'object' || Array.isArray(definition.handlers)) {\n throw new Error('Runtime surface definition handlers must be an object for surface: ' + String(surfaceId));\n }\n } else {\n definition.handlers = {};\n }\n\n definition.packId = normalizedPackId;\n return definition;\n}\n\nfunction ensureRuntimeSurfaceRecord(surfaceId) {\n const surfaces = assertSurfacesMap();\n const key = String(surfaceId);\n const existing = surfaces[key];\n if (!existing || typeof existing !== 'object') {\n surfaces[key] = {\n handlers: {},\n };\n } else if (!existing.handlers || typeof existing.handlers !== 'object') {\n existing.handlers = {};\n }\n return surfaces[key];\n}\n\nfunction defineRuntimeSurfaceImpl(surfaceId, definitionOrFactory, packId) {\n const surfaces = assertSurfacesMap();\n const key = String(surfaceId);\n surfaces[key] = normalizeRuntimeSurfaceDefinition(key, definitionOrFactory, packId);\n}\n\nfunction defineRuntimeSurfaceRenderImpl(surfaceId, renderFn) {\n if (typeof renderFn !== 'function') {\n throw new Error('defineRuntimeSurfaceRender requires a render function');\n }\n\n const surface = ensureRuntimeSurfaceRecord(surfaceId);\n surface.render = renderFn;\n}\n\nfunction defineRuntimeSurfaceHandlerImpl(surfaceId, handlerName, handlerFn) {\n if (typeof handlerFn !== 'function') {\n throw new Error('defineRuntimeSurfaceHandler requires a handler function');\n }\n\n const surface = ensureRuntimeSurfaceRecord(surfaceId);\n surface.handlers[String(handlerName)] = handlerFn;\n}\n\nglobalThis.defineRuntimeBundle = defineRuntimeBundleImpl;\nglobalThis.defineRuntimeSurface = defineRuntimeSurfaceImpl;\nglobalThis.defineRuntimeSurfaceRender = defineRuntimeSurfaceRenderImpl;\nglobalThis.defineRuntimeSurfaceHandler = defineRuntimeSurfaceHandlerImpl;\nglobalThis.registerRuntimePackageApi = registerRuntimePackageApi;\n\nglobalThis.__runtimeBundleHost = {\n getMeta() {\n if (!__runtimeBundle || typeof __runtimeBundle !== 'object') {\n throw new Error('Runtime bundle did not register via defineRuntimeBundle');\n }\n\n if (!__runtimeBundle.surfaces || typeof __runtimeBundle.surfaces !== 'object') {\n throw new Error('Runtime bundle surfaces must be an object');\n }\n\n return {\n declaredId: typeof __runtimeBundle.id === 'string' ? __runtimeBundle.id : undefined,\n title: String(__runtimeBundle.title ?? 'Untitled Bundle'),\n description: typeof __runtimeBundle.description === 'string' ? __runtimeBundle.description : undefined,\n packageIds: Array.isArray(__runtimeBundle.packageIds)\n ? __runtimeBundle.packageIds.map((packageId) => String(packageId)).filter((packageId) => packageId.length > 0)\n : [],\n initialSessionState: __runtimeBundle.initialSessionState,\n initialSurfaceState: __runtimeBundle.initialSurfaceState,\n surfaces: Object.keys(__runtimeBundle.surfaces),\n surfaceTypes: Object.fromEntries(\n Object.entries(__runtimeBundle.surfaces).map(([key, surface]) => [\n key,\n normalizeRuntimeSurfacePackId(key, surface?.packId),\n ]),\n ),\n };\n },\n\n renderRuntimeSurface(surfaceId, state) {\n const surface = __runtimeBundle?.surfaces?.[surfaceId];\n if (!surface || typeof surface.render !== 'function') {\n throw new Error('Runtime surface not found or render() is missing: ' + String(surfaceId));\n }\n\n return surface.render({ state });\n },\n\n eventRuntimeSurface(surfaceId, handlerName, args, state) {\n const surface = __runtimeBundle?.surfaces?.[surfaceId];\n if (!surface) {\n throw new Error('Runtime surface not found: ' + String(surfaceId));\n }\n\n const handler = surface.handlers?.[handlerName];\n if (typeof handler !== 'function') {\n throw new Error('Handler not found: ' + String(handlerName));\n }\n\n __runtimeActions = [];\n\n const dispatch = (action) => {\n __runtimeActions.push(action);\n };\n\n handler(\n {\n state,\n dispatch,\n },\n args\n );\n\n return __runtimeActions.slice();\n },\n\n defineRuntimeSurface(surfaceId, definitionOrFactory, packId) {\n defineRuntimeSurfaceImpl(surfaceId, definitionOrFactory, packId);\n return this.getMeta();\n },\n\n defineRuntimeSurfaceRender(surfaceId, renderFn) {\n defineRuntimeSurfaceRenderImpl(surfaceId, renderFn);\n return this.getMeta();\n },\n\n defineRuntimeSurfaceHandler(surfaceId, handlerName, handlerFn) {\n defineRuntimeSurfaceHandlerImpl(surfaceId, handlerName, handlerFn);\n return this.getMeta();\n },\n};\n";
2
+ export default source;
@@ -0,0 +1,5 @@
1
+ // Generated by scripts/packages/generate-vm-source-modules.mjs.
2
+ // Source: stack-bootstrap.vm.js
3
+ // Do not edit by hand.
4
+ const source = "const __runtimePackageState =\n globalThis.__runtimePackageState && typeof globalThis.__runtimePackageState === 'object'\n ? globalThis.__runtimePackageState\n : {\n packageIds: [],\n apis: {},\n };\n\nglobalThis.__runtimePackageState = __runtimePackageState;\n\nlet __runtimeBundle = null;\nlet __runtimeActions = [];\n\nfunction isPlainObject(value) {\n return value && typeof value === 'object' && !Array.isArray(value);\n}\n\nfunction mergeRuntimeApiValue(existingValue, incomingValue) {\n if (isPlainObject(existingValue) && isPlainObject(incomingValue)) {\n const merged = { ...existingValue };\n for (const [key, value] of Object.entries(incomingValue)) {\n merged[key] = mergeRuntimeApiValue(merged[key], value);\n }\n return merged;\n }\n\n return incomingValue;\n}\n\nfunction registerRuntimePackageApi(packageId, apiExports) {\n const normalizedPackageId = String(packageId || '').trim();\n if (!normalizedPackageId) {\n throw new Error('registerRuntimePackageApi requires a package id');\n }\n\n if (!__runtimePackageState.packageIds.includes(normalizedPackageId)) {\n __runtimePackageState.packageIds.push(normalizedPackageId);\n }\n\n if (!isPlainObject(apiExports)) {\n return;\n }\n\n for (const [exportName, exportValue] of Object.entries(apiExports)) {\n const mergedValue = mergeRuntimeApiValue(__runtimePackageState.apis[exportName], exportValue);\n __runtimePackageState.apis[exportName] = mergedValue;\n globalThis[exportName] = mergedValue;\n }\n}\n\nfunction collectRuntimePackageApis() {\n return { ...__runtimePackageState.apis };\n}\n\nfunction defineRuntimeBundleImpl(factory) {\n if (typeof factory !== 'function') {\n throw new Error('defineRuntimeBundle requires a factory function');\n }\n\n __runtimeBundle = factory(collectRuntimePackageApis());\n}\n\nfunction assertStackBundleReady() {\n if (!__runtimeBundle || typeof __runtimeBundle !== 'object') {\n throw new Error('Runtime bundle did not register via defineRuntimeBundle');\n }\n}\n\nfunction assertSurfacesMap() {\n assertStackBundleReady();\n if (!__runtimeBundle.surfaces || typeof __runtimeBundle.surfaces !== 'object') {\n __runtimeBundle.surfaces = {};\n }\n return __runtimeBundle.surfaces;\n}\n\nfunction normalizeRuntimeSurfacePackId(surfaceId, packId) {\n const normalizedPackId = typeof packId === 'string' ? packId.trim() : '';\n if (!normalizedPackId) {\n throw new Error('Runtime surface packId is required for surface: ' + String(surfaceId));\n }\n return normalizedPackId;\n}\n\nfunction normalizeRuntimeSurfaceDefinition(surfaceId, definitionOrFactory, packId) {\n const normalizedPackId = normalizeRuntimeSurfacePackId(surfaceId, packId);\n const definition =\n typeof definitionOrFactory === 'function'\n ? definitionOrFactory(collectRuntimePackageApis())\n : definitionOrFactory;\n\n if (!definition || typeof definition !== 'object') {\n throw new Error('Runtime surface definition must be an object for surface: ' + String(surfaceId));\n }\n\n if (typeof definition.render !== 'function') {\n throw new Error('Runtime surface definition render() is required for surface: ' + String(surfaceId));\n }\n\n if (definition.handlers !== undefined) {\n if (!definition.handlers || typeof definition.handlers !== 'object' || Array.isArray(definition.handlers)) {\n throw new Error('Runtime surface definition handlers must be an object for surface: ' + String(surfaceId));\n }\n } else {\n definition.handlers = {};\n }\n\n definition.packId = normalizedPackId;\n return definition;\n}\n\nfunction ensureRuntimeSurfaceRecord(surfaceId) {\n const surfaces = assertSurfacesMap();\n const key = String(surfaceId);\n const existing = surfaces[key];\n if (!existing || typeof existing !== 'object') {\n surfaces[key] = {\n handlers: {},\n };\n } else if (!existing.handlers || typeof existing.handlers !== 'object') {\n existing.handlers = {};\n }\n return surfaces[key];\n}\n\nfunction defineRuntimeSurfaceImpl(surfaceId, definitionOrFactory, packId) {\n const surfaces = assertSurfacesMap();\n const key = String(surfaceId);\n surfaces[key] = normalizeRuntimeSurfaceDefinition(key, definitionOrFactory, packId);\n}\n\nfunction defineRuntimeSurfaceRenderImpl(surfaceId, renderFn) {\n if (typeof renderFn !== 'function') {\n throw new Error('defineRuntimeSurfaceRender requires a render function');\n }\n\n const surface = ensureRuntimeSurfaceRecord(surfaceId);\n surface.render = renderFn;\n}\n\nfunction defineRuntimeSurfaceHandlerImpl(surfaceId, handlerName, handlerFn) {\n if (typeof handlerFn !== 'function') {\n throw new Error('defineRuntimeSurfaceHandler requires a handler function');\n }\n\n const surface = ensureRuntimeSurfaceRecord(surfaceId);\n surface.handlers[String(handlerName)] = handlerFn;\n}\n\nglobalThis.defineRuntimeBundle = defineRuntimeBundleImpl;\nglobalThis.defineRuntimeSurface = defineRuntimeSurfaceImpl;\nglobalThis.defineRuntimeSurfaceRender = defineRuntimeSurfaceRenderImpl;\nglobalThis.defineRuntimeSurfaceHandler = defineRuntimeSurfaceHandlerImpl;\nglobalThis.registerRuntimePackageApi = registerRuntimePackageApi;\n\nglobalThis.__runtimeBundleHost = {\n getMeta() {\n if (!__runtimeBundle || typeof __runtimeBundle !== 'object') {\n throw new Error('Runtime bundle did not register via defineRuntimeBundle');\n }\n\n if (!__runtimeBundle.surfaces || typeof __runtimeBundle.surfaces !== 'object') {\n throw new Error('Runtime bundle surfaces must be an object');\n }\n\n return {\n declaredId: typeof __runtimeBundle.id === 'string' ? __runtimeBundle.id : undefined,\n title: String(__runtimeBundle.title ?? 'Untitled Bundle'),\n description: typeof __runtimeBundle.description === 'string' ? __runtimeBundle.description : undefined,\n packageIds: Array.isArray(__runtimeBundle.packageIds)\n ? __runtimeBundle.packageIds.map((packageId) => String(packageId)).filter((packageId) => packageId.length > 0)\n : [],\n initialSessionState: __runtimeBundle.initialSessionState,\n initialSurfaceState: __runtimeBundle.initialSurfaceState,\n surfaces: Object.keys(__runtimeBundle.surfaces),\n surfaceTypes: Object.fromEntries(\n Object.entries(__runtimeBundle.surfaces).map(([key, surface]) => [\n key,\n normalizeRuntimeSurfacePackId(key, surface?.packId),\n ]),\n ),\n };\n },\n\n renderRuntimeSurface(surfaceId, state) {\n const surface = __runtimeBundle?.surfaces?.[surfaceId];\n if (!surface || typeof surface.render !== 'function') {\n throw new Error('Runtime surface not found or render() is missing: ' + String(surfaceId));\n }\n\n return surface.render({ state });\n },\n\n eventRuntimeSurface(surfaceId, handlerName, args, state) {\n const surface = __runtimeBundle?.surfaces?.[surfaceId];\n if (!surface) {\n throw new Error('Runtime surface not found: ' + String(surfaceId));\n }\n\n const handler = surface.handlers?.[handlerName];\n if (typeof handler !== 'function') {\n throw new Error('Handler not found: ' + String(handlerName));\n }\n\n __runtimeActions = [];\n\n const dispatch = (action) => {\n __runtimeActions.push(action);\n };\n\n handler(\n {\n state,\n dispatch,\n },\n args\n );\n\n return __runtimeActions.slice();\n },\n\n defineRuntimeSurface(surfaceId, definitionOrFactory, packId) {\n defineRuntimeSurfaceImpl(surfaceId, definitionOrFactory, packId);\n return this.getMeta();\n },\n\n defineRuntimeSurfaceRender(surfaceId, renderFn) {\n defineRuntimeSurfaceRenderImpl(surfaceId, renderFn);\n return this.getMeta();\n },\n\n defineRuntimeSurfaceHandler(surfaceId, handlerName, handlerFn) {\n defineRuntimeSurfaceHandlerImpl(surfaceId, handlerName, handlerFn);\n return this.getMeta();\n },\n};\n";
5
+ export default source;