fix(code-mode): generalize failures and bound diagnostics
This commit is contained in:
20 files changed
+483
-129
No files matched your search
@@ -8,6 +8,7 @@ import { Context, Service } from 'cordis'
|
||||
import type { CodeRunRequest, CodeRunResult } from './types.ts'
|
||||
|
||||
export type {
|
||||
CodeBindingErrorClass,
|
||||
CodeBindingFunction,
|
||||
CodeBindingNamespace,
|
||||
CodeJsonValue,
|
||||
@@ -25,8 +26,9 @@ declare module 'cordis' {
|
||||
/**
|
||||
* Registers one `ctx.codeRuntime` implementation. Program, budget, abort, and substrate
|
||||
* failures resolve in {@link CodeRunResult}; only seam misuse rejects. Implementations bridge
|
||||
* structured-cloneable bindings while treating programs as hostile peers, isolate runs from
|
||||
* one another, and terminate and await in-flight runs during disposal.
|
||||
* structured-cloneable bindings, materialize each declared namespace rejection
|
||||
* class, treat programs as hostile peers, isolate runs from one another, and
|
||||
* terminate and await in-flight runs during disposal.
|
||||
*/
|
||||
export abstract class CodeRuntime extends Service {
|
||||
/**
|
||||
|
||||
@@ -20,6 +20,20 @@ export type CodeBindingFunction = (args: unknown) => Promise<CodeJsonValue>
|
||||
/** A lossless JSON value transferable across the dependency-light code-runtime seam. */
|
||||
export type CodeJsonValue = null | boolean | number | string | CodeJsonValue[] | { [key: string]: CodeJsonValue }
|
||||
|
||||
/**
|
||||
* Program-visible typed rejection for one binding namespace. The runtime
|
||||
* injects a real error constructor under `name`; rejected member calls become
|
||||
* its instances and expose the exact member name through
|
||||
* `memberNameProperty`. Both strings are runtime data rather than knowledge
|
||||
* of a particular consumer such as Code Mode.
|
||||
*/
|
||||
export interface CodeBindingErrorClass {
|
||||
/** Constructor global and resulting `Error.name` (must be a usable JS identifier). */
|
||||
name: string
|
||||
/** Non-empty own property for the member name; cannot replace `name`, `message`, or `stack`. */
|
||||
memberNameProperty: string
|
||||
}
|
||||
|
||||
/**
|
||||
* A named group of {@link CodeBindingFunction}s the runtime exposes to the
|
||||
* program as one global object (e.g. `tools`). Function names are arbitrary
|
||||
@@ -32,6 +46,8 @@ export interface CodeBindingNamespace {
|
||||
global: string
|
||||
/** The callable members, keyed by the exact name the program calls. */
|
||||
functions: Record<string, CodeBindingFunction>
|
||||
/** Optional program-visible typed rejection contract for this namespace. */
|
||||
errorClass?: CodeBindingErrorClass
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user