@punica/editor 1.0.6 → 1.0.8
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/dist/index.bundle.esm.js +2 -1
- package/dist/index.bundle.esm.js.map +1 -1
- package/dist/index.bundle.umd.js +2 -1
- package/dist/index.bundle.umd.js.map +1 -1
- package/package.json +28 -3
- package/types/index.d.ts +120 -11
- package/types/punica.module.bootstrap.d.ts +45 -0
- package/types/punica.module.capability.d.ts +359 -0
- package/types/punica.module.extensions.api.d.ts +766 -0
- package/types/punica.module.extensions.settings.d.ts +106 -0
- package/types/punica.module.flow.agent.d.ts +75 -0
- package/types/punica.module.flow.api.d.ts +128 -0
- package/types/punica.module.flow.d.ts +490 -0
- package/types/punica.module.flow.engine.d.ts +228 -0
- package/types/punica.module.flow.mcp.d.ts +26 -0
- package/types/punica.module.flow.notebook.d.ts +210 -0
- package/types/punica.module.flow.primitives.d.ts +700 -0
- package/types/punica.module.flow.shell.d.ts +374 -0
- package/types/punica.module.kernel.ai.d.ts +462 -0
- package/types/punica.module.kernel.commands.d.ts +49 -0
- package/types/punica.module.kernel.events.d.ts +274 -0
- package/types/punica.module.kernel.history.d.ts +20 -0
- package/types/punica.module.kernel.llm.d.ts +343 -0
- package/types/punica.module.kernel.notifications.d.ts +64 -0
- package/types/punica.module.kernel.policy.d.ts +273 -0
- package/types/punica.module.kernel.tasks.d.ts +107 -0
- package/types/punica.module.kernel.timeServer.d.ts +16 -0
- package/types/punica.module.runtime.api.d.ts +214 -0
- package/types/punica.module.runtime.capabilities.d.ts +175 -0
- package/types/punica.module.runtime.compute.d.ts +339 -0
- package/types/punica.module.runtime.datasets.d.ts +234 -0
- package/types/punica.module.runtime.fs.d.ts +385 -0
- package/types/punica.module.runtime.harness.d.ts +246 -0
- package/types/punica.module.runtime.host.d.ts +272 -0
- package/types/punica.module.runtime.inference.d.ts +164 -0
- package/types/punica.module.runtime.lifecycle.d.ts +15 -0
- package/types/punica.module.runtime.llm.d.ts +470 -0
- package/types/punica.module.runtime.mcp.d.ts +139 -0
- package/types/punica.module.runtime.modelRuntimes.d.ts +90 -0
- package/types/punica.module.runtime.models.d.ts +254 -0
- package/types/punica.module.runtime.search.d.ts +59 -0
- package/types/punica.module.runtime.secrets.d.ts +26 -0
- package/types/punica.module.runtime.tasks.d.ts +27 -0
- package/types/punica.module.runtime.vcs.d.ts +67 -0
- package/types/punica.module.runtime.vectors.d.ts +74 -0
- package/types/punica.module.runtime.workspace.d.ts +134 -0
- package/types/punica.module.shell.activityBar.d.ts +42 -0
- package/types/punica.module.shell.components.d.ts +87 -0
- package/types/punica.module.shell.contentTabs.d.ts +33 -0
- package/types/punica.module.shell.dragDrop.d.ts +25 -0
- package/types/punica.module.shell.keyboardShortcuts.d.ts +38 -0
- package/types/punica.module.shell.layout.d.ts +106 -0
- package/types/punica.module.shell.markdown.d.ts +36 -0
- package/types/punica.module.shell.panelTabs.d.ts +71 -0
- package/types/punica.module.shell.profile.d.ts +278 -0
- package/types/punica.module.shell.statusbar.d.ts +26 -0
- package/types/punica.module.shell.view.d.ts +455 -0
- package/types/punica.module.shell.views.d.ts +150 -0
- package/types/punica.module.test.d.ts +562 -0
- package/types/punica.module.activityBar.d.ts +0 -21
- package/types/punica.module.commands.d.ts +0 -21
- package/types/punica.module.dragDrop.d.ts +0 -23
- package/types/punica.module.extensions.d.ts +0 -157
- package/types/punica.module.history.d.ts +0 -18
- package/types/punica.module.keyboardShortcuts.d.ts +0 -29
- package/types/punica.module.layout.d.ts +0 -22
- package/types/punica.module.statusbar.d.ts +0 -21
- package/types/punica.module.timeServer.d.ts +0 -14
- package/types/punica.module.view.d.ts +0 -8
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
/// <reference path="./punica.module.ivy.d.ts" />
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Multi-Runtime Test Harness Type Definitions
|
|
5
|
+
*
|
|
6
|
+
* Defines the contract for testing execution safety guarantees
|
|
7
|
+
* (timeout/retry/concurrency/rate-limit/cancel) across different runtimes.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
declare module 'punica' {
|
|
11
|
+
export namespace runtime {
|
|
12
|
+
export namespace harness {
|
|
13
|
+
/**
|
|
14
|
+
* Runtime adapter interface for test harness.
|
|
15
|
+
* Implemented by JS/TS dev runtime and Python runtime gateway.
|
|
16
|
+
*/
|
|
17
|
+
export interface RuntimeAdapter {
|
|
18
|
+
/**
|
|
19
|
+
* Runtime identifier (e.g., "js-ts-dev", "python-jeg").
|
|
20
|
+
*/
|
|
21
|
+
id: string;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Execute a capability through this runtime.
|
|
25
|
+
*
|
|
26
|
+
* @param capabilityId - Capability identifier
|
|
27
|
+
* @param input - Input payload
|
|
28
|
+
* @param executionDefaults - Capability execution defaults
|
|
29
|
+
* @param executionOverride - Optional workflow node override
|
|
30
|
+
* @param runBudget - Optional run-level budget
|
|
31
|
+
* @returns Promise resolving to output
|
|
32
|
+
*/
|
|
33
|
+
execute(
|
|
34
|
+
capabilityId: string,
|
|
35
|
+
input: unknown,
|
|
36
|
+
executionDefaults?: CapabilityExecutionDefaults,
|
|
37
|
+
executionOverride?: ivy.ExecutionOverride,
|
|
38
|
+
runBudget?: ivy.RunBudget
|
|
39
|
+
): Promise<unknown>;
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Cancel a running execution.
|
|
43
|
+
*
|
|
44
|
+
* @param runId - Run identifier
|
|
45
|
+
* @param mode - Cancellation mode
|
|
46
|
+
*/
|
|
47
|
+
cancel(runId: string, mode: ivy.CancellationMode): Promise<void>;
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Get execution events for a run.
|
|
51
|
+
*
|
|
52
|
+
* @param runId - Run identifier
|
|
53
|
+
* @returns Async iterable of execution events
|
|
54
|
+
*/
|
|
55
|
+
getExecutionEvents(runId: string): AsyncIterable<ivy.ExecutionEvent>;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Golden scenario definition.
|
|
60
|
+
* Represents a test case with deterministic inputs and expected outcomes.
|
|
61
|
+
*/
|
|
62
|
+
export interface GoldenScenario {
|
|
63
|
+
/**
|
|
64
|
+
* Scenario identifier.
|
|
65
|
+
*/
|
|
66
|
+
id: string;
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Human-readable description.
|
|
70
|
+
*/
|
|
71
|
+
description: string;
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Capability identifier to test.
|
|
75
|
+
*/
|
|
76
|
+
capabilityId: string;
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Input payload.
|
|
80
|
+
*/
|
|
81
|
+
input: unknown;
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Execution defaults to apply.
|
|
85
|
+
*/
|
|
86
|
+
executionDefaults?: CapabilityExecutionDefaults;
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Execution override to apply.
|
|
90
|
+
*/
|
|
91
|
+
executionOverride?: ivy.ExecutionOverride;
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Run budget constraints.
|
|
95
|
+
*/
|
|
96
|
+
runBudget?: ivy.RunBudget;
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Expected outcome.
|
|
100
|
+
*/
|
|
101
|
+
expected: {
|
|
102
|
+
/**
|
|
103
|
+
* Whether execution should succeed.
|
|
104
|
+
*/
|
|
105
|
+
ok: boolean;
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Expected output (if ok is true).
|
|
109
|
+
*/
|
|
110
|
+
output?: unknown;
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Expected error message pattern (if ok is false).
|
|
114
|
+
*/
|
|
115
|
+
errorPattern?: string;
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Expected execution events (ordered).
|
|
119
|
+
*/
|
|
120
|
+
events?: Array<{
|
|
121
|
+
type: ivy.ExecutionEvent['type'];
|
|
122
|
+
[key: string]: unknown;
|
|
123
|
+
}>;
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Expected execution duration range (milliseconds).
|
|
127
|
+
*/
|
|
128
|
+
durationMs?: {
|
|
129
|
+
min?: number;
|
|
130
|
+
max?: number;
|
|
131
|
+
};
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Test result for a scenario run.
|
|
137
|
+
*/
|
|
138
|
+
export interface ScenarioResult {
|
|
139
|
+
/**
|
|
140
|
+
* Scenario identifier.
|
|
141
|
+
*/
|
|
142
|
+
scenarioId: string;
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* Runtime adapter identifier.
|
|
146
|
+
*/
|
|
147
|
+
runtimeId: string;
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Whether the scenario passed.
|
|
151
|
+
*/
|
|
152
|
+
ok: boolean;
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Actual output (if execution succeeded).
|
|
156
|
+
*/
|
|
157
|
+
output?: unknown;
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Actual error (if execution failed).
|
|
161
|
+
*/
|
|
162
|
+
error?: {
|
|
163
|
+
message: string;
|
|
164
|
+
code?: string;
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* Actual execution events.
|
|
169
|
+
*/
|
|
170
|
+
events: ivy.ExecutionEvent[];
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* Actual execution duration (milliseconds).
|
|
174
|
+
*/
|
|
175
|
+
durationMs: number;
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* Validation errors (if any).
|
|
179
|
+
*/
|
|
180
|
+
validationErrors?: string[];
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* Harness test runner interface.
|
|
185
|
+
*/
|
|
186
|
+
export interface HarnessRunner {
|
|
187
|
+
/**
|
|
188
|
+
* Run a scenario against a runtime adapter.
|
|
189
|
+
*
|
|
190
|
+
* @param scenario - Scenario to run
|
|
191
|
+
* @param adapter - Runtime adapter to test
|
|
192
|
+
* @returns Test result
|
|
193
|
+
*/
|
|
194
|
+
runScenario(
|
|
195
|
+
scenario: GoldenScenario,
|
|
196
|
+
adapter: RuntimeAdapter
|
|
197
|
+
): Promise<ScenarioResult>;
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* Run multiple scenarios against multiple adapters.
|
|
201
|
+
*
|
|
202
|
+
* @param scenarios - Scenarios to run
|
|
203
|
+
* @param adapters - Runtime adapters to test
|
|
204
|
+
* @returns Test results
|
|
205
|
+
*/
|
|
206
|
+
runScenarios(
|
|
207
|
+
scenarios: GoldenScenario[],
|
|
208
|
+
adapters: RuntimeAdapter[]
|
|
209
|
+
): Promise<ScenarioResult[]>;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* Predefined golden scenario factory functions for common safety guarantee tests.
|
|
214
|
+
*/
|
|
215
|
+
export interface ScenarioFactories {
|
|
216
|
+
/**
|
|
217
|
+
* Timeout scenario: capability should timeout after specified duration.
|
|
218
|
+
*/
|
|
219
|
+
timeout: (timeoutMs: number) => GoldenScenario;
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* Retry scenario: capability should retry on transient errors.
|
|
223
|
+
*/
|
|
224
|
+
retry: (maxAttempts: number, initialDelayMs: number) => GoldenScenario;
|
|
225
|
+
|
|
226
|
+
/**
|
|
227
|
+
* Concurrency scenario: multiple concurrent executions should respect limits.
|
|
228
|
+
*/
|
|
229
|
+
concurrency: (
|
|
230
|
+
maxConcurrent: number,
|
|
231
|
+
numExecutions: number
|
|
232
|
+
) => GoldenScenario;
|
|
233
|
+
|
|
234
|
+
/**
|
|
235
|
+
* Rate limit scenario: executions should be rate-limited.
|
|
236
|
+
*/
|
|
237
|
+
rateLimit: (perSecond: number, numExecutions: number) => GoldenScenario;
|
|
238
|
+
|
|
239
|
+
/**
|
|
240
|
+
* Cancellation scenario: execution should be cancellable.
|
|
241
|
+
*/
|
|
242
|
+
cancellation: (mode: ivy.CancellationMode) => GoldenScenario;
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
}
|
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
declare module 'punica' {
|
|
2
|
+
export namespace runtime {
|
|
3
|
+
export namespace host {
|
|
4
|
+
/**
|
|
5
|
+
* Filesystem surface scoped to the host's data directory (see
|
|
6
|
+
* `HostApi.dataDir`), distinct from the workspace-scoped `runtime.fs`.
|
|
7
|
+
* Paths may be absolute (under the data dir) or relative to it; the host
|
|
8
|
+
* rejects anything that escapes the data-dir root. `list`/`stat` return
|
|
9
|
+
* absolute paths so callers can persist a stable pointer.
|
|
10
|
+
*
|
|
11
|
+
* This exists so heavy artifacts (model weights, dataset files) can live
|
|
12
|
+
* OUTSIDE the workspace while the workspace `.punica` index keeps only an
|
|
13
|
+
* absolute pointer — `runtime.fs` stays strictly workspace-scoped.
|
|
14
|
+
*/
|
|
15
|
+
/** A byte range within a fixed-stride record, for `readStrided`. */
|
|
16
|
+
export interface StridedSlice {
|
|
17
|
+
/** Byte offset of the slice within a single record. */
|
|
18
|
+
offset: number;
|
|
19
|
+
/** Slice length in bytes. */
|
|
20
|
+
length: number;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Instruction for `readStrided`: a mechanical, format-agnostic gather over
|
|
25
|
+
* a fixed-stride binary file. The host reads sequentially from `start`,
|
|
26
|
+
* walks records of `stride` bytes, and for every `keepEvery`-th record
|
|
27
|
+
* (up to `count` records) copies the requested `slices` into the output.
|
|
28
|
+
* It carries no knowledge of what the bytes mean — callers (e.g. a
|
|
29
|
+
* point-cloud viewer) own all format semantics.
|
|
30
|
+
*/
|
|
31
|
+
export interface StridedReadOptions {
|
|
32
|
+
/** Byte offset where the first record begins. */
|
|
33
|
+
start: number;
|
|
34
|
+
/** Size of one record in bytes. */
|
|
35
|
+
stride: number;
|
|
36
|
+
/** Keep every Nth record (1 = keep all). */
|
|
37
|
+
keepEvery: number;
|
|
38
|
+
/** Byte ranges to copy out of each kept record. */
|
|
39
|
+
slices: StridedSlice[];
|
|
40
|
+
/** Total number of records to walk before stopping. */
|
|
41
|
+
count: number;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export interface HostDataFs {
|
|
45
|
+
/** List entries under `path` (relative to the data dir, or absolute). */
|
|
46
|
+
list(path?: string, opts?: ListOptions): Promise<FileEntry[]>;
|
|
47
|
+
/**
|
|
48
|
+
* Read a file's contents. Text files are returned as UTF-8; common image
|
|
49
|
+
* types are returned as a `data:` URL so viewers can render them without
|
|
50
|
+
* a binary surface. Large files are refused (callers should not read
|
|
51
|
+
* multi-GB blobs as text). Enables in-app preview of data-dir files.
|
|
52
|
+
*/
|
|
53
|
+
readFile(path: string): Promise<string>;
|
|
54
|
+
/**
|
|
55
|
+
* Read a raw byte range from a data-dir file. Unlike `readFile` this
|
|
56
|
+
* returns binary and never refuses by size (the range is bounded by
|
|
57
|
+
* `length`). Lets callers read headers / chunks of large binary files.
|
|
58
|
+
* Optional: only hosts with a real filesystem (Electron) provide it.
|
|
59
|
+
*/
|
|
60
|
+
readBytes?(
|
|
61
|
+
path: string,
|
|
62
|
+
offset: number,
|
|
63
|
+
length: number
|
|
64
|
+
): Promise<ArrayBuffer>;
|
|
65
|
+
/**
|
|
66
|
+
* Mechanically gather a decimated subset of a fixed-stride binary file
|
|
67
|
+
* (see `StridedReadOptions`). Format-agnostic — used e.g. by the LIDAR
|
|
68
|
+
* viewer to downsample multi-GB point clouds without moving the whole
|
|
69
|
+
* file across IPC. Optional: Electron-only; a browser host omits it.
|
|
70
|
+
*/
|
|
71
|
+
readStrided?(
|
|
72
|
+
path: string,
|
|
73
|
+
opts: StridedReadOptions
|
|
74
|
+
): Promise<ArrayBuffer>;
|
|
75
|
+
/** Per-path metadata (size, timestamps, kind). */
|
|
76
|
+
stat(path: string): Promise<FileStat>;
|
|
77
|
+
/** Create a directory, recursive by default (`mkdir -p`). */
|
|
78
|
+
mkdir(path: string, opts?: MkdirOptions): Promise<void>;
|
|
79
|
+
/** Delete a single file. */
|
|
80
|
+
deleteFile(path: string): Promise<void>;
|
|
81
|
+
/** Delete a folder (recursive). */
|
|
82
|
+
deleteFolder(path: string): Promise<void>;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/** Options for launching a managed, long-running local server process. */
|
|
86
|
+
export interface HostServerStartOptions {
|
|
87
|
+
/** Executable / command to spawn (e.g. a model server binary). */
|
|
88
|
+
command: string;
|
|
89
|
+
/** Command-line arguments. */
|
|
90
|
+
args?: string[];
|
|
91
|
+
/** Working directory for the spawned process. */
|
|
92
|
+
cwd?: string;
|
|
93
|
+
/** Extra environment variables merged over the host environment. */
|
|
94
|
+
env?: Record<string, string>;
|
|
95
|
+
/**
|
|
96
|
+
* Optional readiness probe. When set, `start` resolves only once an
|
|
97
|
+
* HTTP GET to this URL gets any response, or rejects (and the process
|
|
98
|
+
* is killed) once `readyTimeoutMs` elapses. Lets engine plugins wait for
|
|
99
|
+
* the server's HTTP endpoint without cross-origin fetches from the
|
|
100
|
+
* renderer (the probe runs in the host/main process).
|
|
101
|
+
*/
|
|
102
|
+
readyProbeUrl?: string;
|
|
103
|
+
/** Readiness timeout in ms (default host-defined, e.g. 60000). */
|
|
104
|
+
readyTimeoutMs?: number;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/** Handle to a started managed server process. */
|
|
108
|
+
export interface HostServerHandle {
|
|
109
|
+
/** Host-assigned id; pass to `stop`/`status`. */
|
|
110
|
+
id: string;
|
|
111
|
+
/** OS process id, when known. */
|
|
112
|
+
pid: number | null;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/** Liveness of a managed server process. */
|
|
116
|
+
export interface HostServerStatus {
|
|
117
|
+
id: string;
|
|
118
|
+
running: boolean;
|
|
119
|
+
pid: number | null;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Engine-neutral managed-process surface: start/stop/inspect a
|
|
124
|
+
* long-running local server (e.g. a model inference server). The host does
|
|
125
|
+
* NOT know what engine it runs — it only spawns the command, tracks the
|
|
126
|
+
* child, optionally waits for an HTTP readiness probe, and kills it on
|
|
127
|
+
* `stop`. This is the generic execution primitive `ModelRuntime` adapters
|
|
128
|
+
* use (see docs/model-runtimes.md §2.4, §9): engine specifics stay in the
|
|
129
|
+
* plugin; lifecycle ownership stays in the host. Distinct from
|
|
130
|
+
* `runtime.tasks.run` (which runs a command to completion and returns no
|
|
131
|
+
* handle, so it cannot manage a persistent server).
|
|
132
|
+
*/
|
|
133
|
+
export interface HostServerApi {
|
|
134
|
+
/** Spawn a managed server; optionally wait for `readyProbeUrl`. */
|
|
135
|
+
start(opts: HostServerStartOptions): Promise<HostServerHandle>;
|
|
136
|
+
/** Stop (kill) a managed server by id. No-op if already gone. */
|
|
137
|
+
stop(id: string): Promise<void>;
|
|
138
|
+
/** Report whether the managed server is still running. */
|
|
139
|
+
status(id: string): Promise<HostServerStatus>;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/** A JSON-over-HTTP request executed in the host (main) process. */
|
|
143
|
+
export interface HostHttpJsonRequest {
|
|
144
|
+
/** HTTP method (default 'GET'). */
|
|
145
|
+
method?: 'GET' | 'POST';
|
|
146
|
+
/** Absolute URL (e.g. a local model server endpoint). */
|
|
147
|
+
url: string;
|
|
148
|
+
/** Extra request headers (merged over `Content-Type: application/json`). */
|
|
149
|
+
headers?: Record<string, string>;
|
|
150
|
+
/** Request body; JSON-serialized when present. */
|
|
151
|
+
body?: unknown;
|
|
152
|
+
/** Request timeout in ms (default host-defined). */
|
|
153
|
+
timeoutMs?: number;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/** Response from a `requestJson` call. */
|
|
157
|
+
export interface HostHttpJsonResponse {
|
|
158
|
+
/** HTTP status code. */
|
|
159
|
+
status: number;
|
|
160
|
+
/** Parsed JSON body (or null when the body was empty/non-JSON). */
|
|
161
|
+
json: unknown;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* Engine-neutral JSON-over-HTTP surface executed in the host (main)
|
|
166
|
+
* process. Model-runtime plugins use it to talk to a local inference
|
|
167
|
+
* server's OpenAI-compatible endpoints (e.g. POST `/v1/embeddings`) — the
|
|
168
|
+
* renderer cannot safely fetch the local endpoint directly (same reason
|
|
169
|
+
* the chat path routes through host IPC). The host does NOT know what
|
|
170
|
+
* engine/task it serves; it only performs the HTTP request. Provided by
|
|
171
|
+
* hosts with network access (Electron); a browser host may omit it, in
|
|
172
|
+
* which case the facade throws a clear error on use.
|
|
173
|
+
*/
|
|
174
|
+
export interface HostHttpApi {
|
|
175
|
+
requestJson(req: HostHttpJsonRequest): Promise<HostHttpJsonResponse>;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/** Options for starting the inbound MCP server listener. */
|
|
179
|
+
export interface HostMcpServerStartOptions {
|
|
180
|
+
/** Transport to expose. `stdio` requires the bridge CLI + an http listener. */
|
|
181
|
+
transport: 'http' | 'stdio';
|
|
182
|
+
/** TCP port for the http transport (host picks a default when omitted). */
|
|
183
|
+
port?: number;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/** Liveness/address of the inbound MCP server listener. */
|
|
187
|
+
export interface HostMcpServerStatus {
|
|
188
|
+
running: boolean;
|
|
189
|
+
transport?: 'http' | 'stdio';
|
|
190
|
+
port?: number;
|
|
191
|
+
/** Base URL clients connect to (http transport). */
|
|
192
|
+
url?: string;
|
|
193
|
+
/**
|
|
194
|
+
* Absolute path of the stdio bridge CLI on the host machine. Clients
|
|
195
|
+
* spawn it (`node <bridgePath> --port <port>`) to reach the http
|
|
196
|
+
* listener over a stdio transport. Resolved by the host for both dev
|
|
197
|
+
* and packaged builds; omitted when the host cannot resolve it.
|
|
198
|
+
*/
|
|
199
|
+
bridgePath?: string;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/** An inbound MCP JSON-RPC request forwarded from the transport. */
|
|
203
|
+
export interface HostMcpServerRequest {
|
|
204
|
+
/** Correlation id; echo it back via `reply`. */
|
|
205
|
+
requestId: string;
|
|
206
|
+
/** The parsed JSON-RPC request object. */
|
|
207
|
+
payload: unknown;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
/**
|
|
211
|
+
* Engine-neutral INBOUND MCP server surface (Electron only). Opens a local
|
|
212
|
+
* listener (http on 127.0.0.1, or stdio via a bridge CLI) that accepts MCP
|
|
213
|
+
* JSON-RPC from external clients (Claude Desktop, inspector). Because the
|
|
214
|
+
* capability gateway lives in the renderer, the host forwards each inbound
|
|
215
|
+
* request to the renderer via `onRequest` and writes the renderer's
|
|
216
|
+
* `reply` back to the transport. The host owns only the socket/stdio
|
|
217
|
+
* framing; all protocol + governance logic stays in the renderer/extension
|
|
218
|
+
* (see docs/projection-conformance.md §6/§7 D1). Hosts without Node
|
|
219
|
+
* (browser) omit this; the facade throws a clear error on use.
|
|
220
|
+
*
|
|
221
|
+
* HTTP endpoint contract (matches the substrate MCP client transport):
|
|
222
|
+
* `GET /` info probe · `GET /sse` event stream returning an
|
|
223
|
+
* `mcp-session-id` header · `POST /messages` JSON-RPC answered in the
|
|
224
|
+
* response body (bare `POST /` accepted for the stdio bridge).
|
|
225
|
+
*/
|
|
226
|
+
export interface HostMcpServerApi {
|
|
227
|
+
/** Start the listener for the given transport. */
|
|
228
|
+
start(opts: HostMcpServerStartOptions): Promise<HostMcpServerStatus>;
|
|
229
|
+
/** Stop the listener. No-op if not running. */
|
|
230
|
+
stop(): Promise<void>;
|
|
231
|
+
/** Current listener state. */
|
|
232
|
+
status(): Promise<HostMcpServerStatus>;
|
|
233
|
+
/** Subscribe to inbound MCP requests. Returns an unsubscribe fn. */
|
|
234
|
+
onRequest(handler: (req: HostMcpServerRequest) => void): () => void;
|
|
235
|
+
/** Reply to a forwarded request (`null` response = no reply written). */
|
|
236
|
+
reply(requestId: string, response: unknown): void;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
/**
|
|
240
|
+
* Host-injected surface for the host's persistent data directory — the
|
|
241
|
+
* place for large artifacts that must NOT pollute the workspace. Provided
|
|
242
|
+
* by hosts that have a real filesystem (Electron); a browser host may not
|
|
243
|
+
* inject this, in which case the facade throws a clear error on use.
|
|
244
|
+
*/
|
|
245
|
+
export interface HostApi {
|
|
246
|
+
/**
|
|
247
|
+
* Absolute path to the host data directory root, created on first use.
|
|
248
|
+
* Subtrees (`models/`, `datasets/`, ...) are created lazily by callers
|
|
249
|
+
* via `dataFs.mkdir`.
|
|
250
|
+
*/
|
|
251
|
+
dataDir(): Promise<string>;
|
|
252
|
+
/** Filesystem surface scoped to the data directory. */
|
|
253
|
+
dataFs: HostDataFs;
|
|
254
|
+
/**
|
|
255
|
+
* Optional managed-process surface (Electron). Hosts that cannot spawn
|
|
256
|
+
* processes (browser) omit it; the facade throws a clear error on use.
|
|
257
|
+
*/
|
|
258
|
+
servers?: HostServerApi;
|
|
259
|
+
/**
|
|
260
|
+
* Optional JSON-over-HTTP surface (Electron). Hosts without network
|
|
261
|
+
* access omit it; the facade throws a clear error on use.
|
|
262
|
+
*/
|
|
263
|
+
http?: HostHttpApi;
|
|
264
|
+
/**
|
|
265
|
+
* Optional inbound MCP server surface (Electron). Hosts that cannot open
|
|
266
|
+
* a local listener (browser) omit it; the facade throws on use.
|
|
267
|
+
*/
|
|
268
|
+
mcpServer?: HostMcpServerApi;
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
}
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
/// <reference path="punica.module.runtime.models.d.ts" />
|
|
2
|
+
/// <reference path="punica.module.runtime.modelRuntimes.d.ts" />
|
|
3
|
+
/// <reference path="punica.module.runtime.llm.d.ts" />
|
|
4
|
+
|
|
5
|
+
declare module 'punica' {
|
|
6
|
+
export namespace runtime {
|
|
7
|
+
/**
|
|
8
|
+
* Task-general inference consumption surface (Phase 7b). The local-model
|
|
9
|
+
* substrate runs more than chat: embeddings / vision / ASR / rerank. Chat
|
|
10
|
+
* stays on `runtime.llm.chat({ route: 'local' })`; every OTHER task goes
|
|
11
|
+
* through `runtime.inference.infer(req)`, which dispatches to the engine that
|
|
12
|
+
* owns the started handle (`handle.runtimeId` -> `ModelRuntime.infer`).
|
|
13
|
+
*
|
|
14
|
+
* Requests/responses are a discriminated union on `task` so vision/ASR slot
|
|
15
|
+
* in later (7c) without changing the dispatcher. See docs/model-runtimes.md
|
|
16
|
+
* §9.2.
|
|
17
|
+
*/
|
|
18
|
+
export namespace inference {
|
|
19
|
+
/** Common fields for every inference request. */
|
|
20
|
+
interface InferRequestBase {
|
|
21
|
+
/**
|
|
22
|
+
* Handle of a started runtime (from `runtime.modelRuntimes.start`). The
|
|
23
|
+
* dispatcher routes to its owning engine via `handle.runtimeId`.
|
|
24
|
+
*/
|
|
25
|
+
handle: modelRuntimes.LocalRuntimeHandle;
|
|
26
|
+
/** Optional concrete model id hint (engine-specific). */
|
|
27
|
+
modelId?: string;
|
|
28
|
+
/** Optional correlation id for auditing/tracing. */
|
|
29
|
+
correlationId?: string;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** Embeddings request — one vector per input text. */
|
|
33
|
+
export interface EmbeddingsInferRequest extends InferRequestBase {
|
|
34
|
+
task: 'embeddings';
|
|
35
|
+
/** Texts to embed; vectors are returned in the same order. */
|
|
36
|
+
input: string[];
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** Rerank request — score `documents` by relevance to `query`. */
|
|
40
|
+
export interface RerankInferRequest extends InferRequestBase {
|
|
41
|
+
task: 'rerank';
|
|
42
|
+
/** The search query the documents are scored against. */
|
|
43
|
+
query: string;
|
|
44
|
+
/** Candidate documents to score/rank. */
|
|
45
|
+
documents: string[];
|
|
46
|
+
/** Optional cap on how many ranked results to return. */
|
|
47
|
+
topN?: number;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Speech-to-text (ASR) request. Audio is carried base64-encoded in JSON
|
|
52
|
+
* (transported via `runtime.host.http`), so no binary/multipart host path
|
|
53
|
+
* is needed; targets local servers that accept JSON-base64 audio. See
|
|
54
|
+
* docs/model-runtimes.md §9.5.
|
|
55
|
+
*/
|
|
56
|
+
export interface SpeechToTextInferRequest extends InferRequestBase {
|
|
57
|
+
task: 'speech-to-text';
|
|
58
|
+
/** Base64-encoded audio bytes. */
|
|
59
|
+
audio: string;
|
|
60
|
+
/** Container/codec hint, e.g. 'wav' | 'mp3' | 'flac'. */
|
|
61
|
+
format?: string;
|
|
62
|
+
/** Optional BCP-47 language hint (e.g. 'tr', 'en'). */
|
|
63
|
+
language?: string;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Vision (image understanding) request — caption / visual Q&A on a single
|
|
68
|
+
* image. The image is carried base64-in-JSON; the ONNX runtime builds an
|
|
69
|
+
* OpenAI vision request (a `data:` image URL inside chat-completions
|
|
70
|
+
* content — the OpenAI standard), so no binary host path is needed. See
|
|
71
|
+
* docs/model-runtimes.md §9.5.
|
|
72
|
+
*/
|
|
73
|
+
export interface VisionInferRequest extends InferRequestBase {
|
|
74
|
+
task: 'vision';
|
|
75
|
+
/** Base64-encoded image bytes. */
|
|
76
|
+
image: string;
|
|
77
|
+
/** Image MIME type for the data URL (default 'image/png'). */
|
|
78
|
+
mimeType?: string;
|
|
79
|
+
/** Optional instruction; defaults to a generic "describe this image". */
|
|
80
|
+
prompt?: string;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Discriminated union of inference requests. Embeddings (7b) + rerank +
|
|
85
|
+
* speech-to-text + vision (7c).
|
|
86
|
+
*/
|
|
87
|
+
export type InferRequest =
|
|
88
|
+
| EmbeddingsInferRequest
|
|
89
|
+
| RerankInferRequest
|
|
90
|
+
| SpeechToTextInferRequest
|
|
91
|
+
| VisionInferRequest;
|
|
92
|
+
|
|
93
|
+
/** Embeddings response — one vector per input text, input order. */
|
|
94
|
+
export interface EmbeddingsInferResponse {
|
|
95
|
+
task: 'embeddings';
|
|
96
|
+
vectors: number[][];
|
|
97
|
+
modelId?: string;
|
|
98
|
+
provider?: string;
|
|
99
|
+
usage?: LlmUsage;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/** A single reranked document: its original index + relevance score. */
|
|
103
|
+
export interface RerankResult {
|
|
104
|
+
/** Index into the request's `documents` array. */
|
|
105
|
+
index: number;
|
|
106
|
+
/** Relevance score (higher = more relevant; engine-defined scale). */
|
|
107
|
+
score: number;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Rerank response — `results` ordered most-relevant-first (or as the
|
|
112
|
+
* engine returns them), each pointing back at the original document index.
|
|
113
|
+
*/
|
|
114
|
+
export interface RerankInferResponse {
|
|
115
|
+
task: 'rerank';
|
|
116
|
+
results: RerankResult[];
|
|
117
|
+
modelId?: string;
|
|
118
|
+
provider?: string;
|
|
119
|
+
usage?: LlmUsage;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/** Speech-to-text response — the transcribed text. */
|
|
123
|
+
export interface SpeechToTextInferResponse {
|
|
124
|
+
task: 'speech-to-text';
|
|
125
|
+
text: string;
|
|
126
|
+
/** Detected/used language, when the engine reports it. */
|
|
127
|
+
language?: string;
|
|
128
|
+
modelId?: string;
|
|
129
|
+
provider?: string;
|
|
130
|
+
usage?: LlmUsage;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/** Vision response — the model's text answer about the image. */
|
|
134
|
+
export interface VisionInferResponse {
|
|
135
|
+
task: 'vision';
|
|
136
|
+
text: string;
|
|
137
|
+
modelId?: string;
|
|
138
|
+
provider?: string;
|
|
139
|
+
usage?: LlmUsage;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/** Discriminated union of inference responses. */
|
|
143
|
+
export type InferResponse =
|
|
144
|
+
| EmbeddingsInferResponse
|
|
145
|
+
| RerankInferResponse
|
|
146
|
+
| SpeechToTextInferResponse
|
|
147
|
+
| VisionInferResponse;
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Inference dispatcher facade surfaced as `runtime.inference`. Routes a
|
|
151
|
+
* request to the engine that owns `req.handle`, validating the engine
|
|
152
|
+
* exposes `infer` and supports the requested task.
|
|
153
|
+
*/
|
|
154
|
+
export interface InferenceApi {
|
|
155
|
+
/**
|
|
156
|
+
* Run a non-chat inference task on a started local runtime. Throws if
|
|
157
|
+
* the owning runtime is not registered, does not implement `infer`, or
|
|
158
|
+
* does not support `req.task`.
|
|
159
|
+
*/
|
|
160
|
+
infer(req: InferRequest): Promise<InferResponse>;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
declare module 'punica' {
|
|
2
|
+
export namespace runtime {
|
|
3
|
+
/**
|
|
4
|
+
* High-level lifecycle phases for the Punica workbench / host.
|
|
5
|
+
*/
|
|
6
|
+
export type LifecyclePhase =
|
|
7
|
+
| 'bootstrapping'
|
|
8
|
+
| 'coreReady'
|
|
9
|
+
| 'noWorkspace'
|
|
10
|
+
| 'workspaceLoading'
|
|
11
|
+
| 'workbenchReady'
|
|
12
|
+
| 'background'
|
|
13
|
+
| 'shutdown';
|
|
14
|
+
}
|
|
15
|
+
}
|