webtau 0.5.0-alpha.1 → 0.5.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.
- package/dist/adapters/electrobun.d.ts +52 -0
- package/dist/adapters/electrobun.d.ts.map +1 -0
- package/dist/adapters/electrobun.js +290 -0
- package/dist/adapters/electrobun.js.map +1 -0
- package/dist/adapters/tauri.d.ts +32 -0
- package/dist/adapters/tauri.d.ts.map +1 -0
- package/dist/adapters/tauri.js +72 -0
- package/dist/adapters/tauri.js.map +1 -0
- package/dist/core.d.ts +2 -0
- package/dist/core.d.ts.map +1 -1
- package/dist/core.js +70 -9
- package/dist/core.js.map +1 -1
- package/dist/diagnostics.d.ts +28 -0
- package/dist/diagnostics.d.ts.map +1 -0
- package/dist/diagnostics.js +22 -0
- package/dist/diagnostics.js.map +1 -0
- package/dist/task.d.ts +89 -0
- package/dist/task.d.ts.map +1 -0
- package/dist/task.js +128 -0
- package/dist/task.js.map +1 -0
- package/package.json +13 -1
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* webtau/adapters/electrobun — Electrobun runtime adapter.
|
|
3
|
+
*
|
|
4
|
+
* Implements WindowAdapter, EventAdapter, FsAdapter, and DialogAdapter
|
|
5
|
+
* by delegating each operation to the Electrobun backend via `invoke()`.
|
|
6
|
+
*
|
|
7
|
+
* Usage:
|
|
8
|
+
* ```ts
|
|
9
|
+
* import { bootstrapElectrobun } from "webtau/adapters/electrobun";
|
|
10
|
+
*
|
|
11
|
+
* bootstrapElectrobun();
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
14
|
+
import type { CoreProvider, DialogAdapter, EventAdapter, FsAdapter, WindowAdapter } from "../provider";
|
|
15
|
+
export declare function createElectrobunWindowAdapter(): WindowAdapter;
|
|
16
|
+
export declare function createElectrobunEventAdapter(): EventAdapter;
|
|
17
|
+
/**
|
|
18
|
+
* Dispatch an event from the Electrobun backend to a registered handler.
|
|
19
|
+
* Called by the IPC bridge when the backend pushes an event.
|
|
20
|
+
*/
|
|
21
|
+
export declare function dispatchElectrobunEvent(listenerId: number, event: string, payload: unknown): void;
|
|
22
|
+
export declare function createElectrobunFsAdapter(): FsAdapter;
|
|
23
|
+
export declare function createElectrobunDialogAdapter(): DialogAdapter;
|
|
24
|
+
/**
|
|
25
|
+
* Core provider for the Electrobun runtime.
|
|
26
|
+
*
|
|
27
|
+
* Provides the `invoke` and `convertFileSrc` implementations that all
|
|
28
|
+
* adapters delegate through.
|
|
29
|
+
*/
|
|
30
|
+
export declare function createElectrobunCoreProvider(): CoreProvider;
|
|
31
|
+
/**
|
|
32
|
+
* Bootstrap all Electrobun adapters at once.
|
|
33
|
+
*
|
|
34
|
+
* Registers the core provider and sets adapters for window, event,
|
|
35
|
+
* filesystem, and dialog modules. After calling this function, all
|
|
36
|
+
* webtau module-level functions will delegate through Electrobun.
|
|
37
|
+
*
|
|
38
|
+
* An optional `coreProvider` can be passed to supply a custom IPC
|
|
39
|
+
* bridge (e.g. one that delegates to `electrobun.ipc.invoke()`).
|
|
40
|
+
*
|
|
41
|
+
* ```ts
|
|
42
|
+
* import { bootstrapElectrobun } from "webtau/adapters/electrobun";
|
|
43
|
+
*
|
|
44
|
+
* bootstrapElectrobun({
|
|
45
|
+
* id: "electrobun",
|
|
46
|
+
* invoke: (cmd, args) => electrobun.ipc.invoke(cmd, args),
|
|
47
|
+
* convertFileSrc: (path) => `electrobun://asset/${path}`,
|
|
48
|
+
* });
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
51
|
+
export declare function bootstrapElectrobun(coreProvider?: CoreProvider): void;
|
|
52
|
+
//# sourceMappingURL=electrobun.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"electrobun.d.ts","sourceRoot":"","sources":["../../src/adapters/electrobun.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAkBH,OAAO,KAAK,EACV,YAAY,EACZ,aAAa,EACb,YAAY,EACZ,SAAS,EACT,aAAa,EACd,MAAM,aAAa,CAAC;AAWrB,wBAAgB,6BAA6B,IAAI,aAAa,CA8F7D;AAWD,wBAAgB,4BAA4B,IAAI,YAAY,CAyB3D;AAQD;;;GAGG;AACH,wBAAgB,uBAAuB,CACrC,UAAU,EAAE,MAAM,EAClB,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,OAAO,GACf,IAAI,CAKN;AAYD,wBAAgB,yBAAyB,IAAI,SAAS,CAkErD;AAUD,wBAAgB,6BAA6B,IAAI,aAAa,CAmC7D;AAID;;;;;GAKG;AACH,wBAAgB,4BAA4B,IAAI,YAAY,CAuB3D;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,mBAAmB,CAAC,YAAY,CAAC,EAAE,YAAY,GAAG,IAAI,CAMrE"}
|
|
@@ -0,0 +1,290 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* webtau/adapters/electrobun — Electrobun runtime adapter.
|
|
3
|
+
*
|
|
4
|
+
* Implements WindowAdapter, EventAdapter, FsAdapter, and DialogAdapter
|
|
5
|
+
* by delegating each operation to the Electrobun backend via `invoke()`.
|
|
6
|
+
*
|
|
7
|
+
* Usage:
|
|
8
|
+
* ```ts
|
|
9
|
+
* import { bootstrapElectrobun } from "webtau/adapters/electrobun";
|
|
10
|
+
*
|
|
11
|
+
* bootstrapElectrobun();
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
14
|
+
import { invoke, registerProvider } from "../core";
|
|
15
|
+
import { setDialogAdapter } from "../dialog";
|
|
16
|
+
import { setEventAdapter } from "../event";
|
|
17
|
+
import { setFsAdapter } from "../fs";
|
|
18
|
+
import { setWindowAdapter } from "../window";
|
|
19
|
+
// ── Window Adapter ──────────────────────────────────────────────────────────
|
|
20
|
+
// Supported: isFullscreen, setFullscreen, innerSize, outerSize, setSize,
|
|
21
|
+
// title, setTitle, close, minimize, unminimize, maximize,
|
|
22
|
+
// isMaximized, show, hide, setDecorations, scaleFactor,
|
|
23
|
+
// currentMonitor
|
|
24
|
+
// Partial: center (depends on backend window manager support)
|
|
25
|
+
// Unsupported: none currently
|
|
26
|
+
export function createElectrobunWindowAdapter() {
|
|
27
|
+
return {
|
|
28
|
+
async isFullscreen() {
|
|
29
|
+
return invoke("plugin:electrobun|window_is_fullscreen");
|
|
30
|
+
},
|
|
31
|
+
async setFullscreen(fullscreen) {
|
|
32
|
+
await invoke("plugin:electrobun|window_set_fullscreen", { fullscreen });
|
|
33
|
+
},
|
|
34
|
+
async innerSize() {
|
|
35
|
+
return invoke("plugin:electrobun|window_inner_size");
|
|
36
|
+
},
|
|
37
|
+
async outerSize() {
|
|
38
|
+
return invoke("plugin:electrobun|window_outer_size");
|
|
39
|
+
},
|
|
40
|
+
async setSize(size) {
|
|
41
|
+
await invoke("plugin:electrobun|window_set_size", {
|
|
42
|
+
width: size.width,
|
|
43
|
+
height: size.height,
|
|
44
|
+
type: size.type,
|
|
45
|
+
});
|
|
46
|
+
},
|
|
47
|
+
async maximize() {
|
|
48
|
+
await invoke("plugin:electrobun|window_maximize");
|
|
49
|
+
},
|
|
50
|
+
async isMaximized() {
|
|
51
|
+
return invoke("plugin:electrobun|window_is_maximized");
|
|
52
|
+
},
|
|
53
|
+
async title() {
|
|
54
|
+
return invoke("plugin:electrobun|window_title");
|
|
55
|
+
},
|
|
56
|
+
async setTitle(title) {
|
|
57
|
+
await invoke("plugin:electrobun|window_set_title", { title });
|
|
58
|
+
},
|
|
59
|
+
async close() {
|
|
60
|
+
await invoke("plugin:electrobun|window_close");
|
|
61
|
+
},
|
|
62
|
+
async minimize() {
|
|
63
|
+
await invoke("plugin:electrobun|window_minimize");
|
|
64
|
+
},
|
|
65
|
+
async unminimize() {
|
|
66
|
+
await invoke("plugin:electrobun|window_unminimize");
|
|
67
|
+
},
|
|
68
|
+
async show() {
|
|
69
|
+
await invoke("plugin:electrobun|window_show");
|
|
70
|
+
},
|
|
71
|
+
async hide() {
|
|
72
|
+
await invoke("plugin:electrobun|window_hide");
|
|
73
|
+
},
|
|
74
|
+
async setDecorations(decorations) {
|
|
75
|
+
await invoke("plugin:electrobun|window_set_decorations", { decorations });
|
|
76
|
+
},
|
|
77
|
+
// Partial: centering depends on the Electrobun backend's window
|
|
78
|
+
// manager integration. May be a no-op on some platforms.
|
|
79
|
+
async center() {
|
|
80
|
+
await invoke("plugin:electrobun|window_center");
|
|
81
|
+
},
|
|
82
|
+
async currentMonitor() {
|
|
83
|
+
return invoke("plugin:electrobun|window_current_monitor");
|
|
84
|
+
},
|
|
85
|
+
async scaleFactor() {
|
|
86
|
+
return invoke("plugin:electrobun|window_scale_factor");
|
|
87
|
+
},
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
// ── Event Adapter ───────────────────────────────────────────────────────────
|
|
91
|
+
// Supported: listen, emit
|
|
92
|
+
// Partial: none
|
|
93
|
+
// Unsupported: none currently
|
|
94
|
+
//
|
|
95
|
+
// Note: The event system relies on the Electrobun backend to manage event
|
|
96
|
+
// subscriptions. The `listen` call returns an unlisten ID that is used to
|
|
97
|
+
// remove the subscription on the backend when `unlisten()` is called.
|
|
98
|
+
export function createElectrobunEventAdapter() {
|
|
99
|
+
return {
|
|
100
|
+
async listen(event, handler) {
|
|
101
|
+
const listenerId = await invoke("plugin:electrobun|event_listen", { event });
|
|
102
|
+
// Register a callback bridge — in a real Electrobun integration this
|
|
103
|
+
// would wire into the IPC message channel. Here we store the handler
|
|
104
|
+
// so the backend can dispatch events to it.
|
|
105
|
+
electrobunEventHandlers.set(listenerId, { event, handler: handler });
|
|
106
|
+
return () => {
|
|
107
|
+
electrobunEventHandlers.delete(listenerId);
|
|
108
|
+
invoke("plugin:electrobun|event_unlisten", { listenerId }).catch(() => {
|
|
109
|
+
// Best-effort cleanup — ignore errors during unlisten.
|
|
110
|
+
});
|
|
111
|
+
};
|
|
112
|
+
},
|
|
113
|
+
async emit(event, payload) {
|
|
114
|
+
await invoke("plugin:electrobun|event_emit", { event, payload });
|
|
115
|
+
},
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
/** Internal registry for event handlers keyed by listener ID. */
|
|
119
|
+
const electrobunEventHandlers = new Map();
|
|
120
|
+
/**
|
|
121
|
+
* Dispatch an event from the Electrobun backend to a registered handler.
|
|
122
|
+
* Called by the IPC bridge when the backend pushes an event.
|
|
123
|
+
*/
|
|
124
|
+
export function dispatchElectrobunEvent(listenerId, event, payload) {
|
|
125
|
+
const entry = electrobunEventHandlers.get(listenerId);
|
|
126
|
+
if (entry) {
|
|
127
|
+
entry.handler({ event, id: listenerId, payload });
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
// ── Filesystem Adapter ──────────────────────────────────────────────────────
|
|
131
|
+
// Supported: writeTextFile, readTextFile, writeFile, readFile, exists,
|
|
132
|
+
// mkdir, readDir, remove, copyFile, rename
|
|
133
|
+
// Partial: none
|
|
134
|
+
// Unsupported: none currently
|
|
135
|
+
//
|
|
136
|
+
// Note: Binary data (Uint8Array/ArrayBuffer) is serialized as a number[]
|
|
137
|
+
// for JSON transport over IPC. The backend is responsible for converting
|
|
138
|
+
// back to native byte buffers.
|
|
139
|
+
export function createElectrobunFsAdapter() {
|
|
140
|
+
return {
|
|
141
|
+
async writeTextFile(path, contents) {
|
|
142
|
+
await invoke("plugin:electrobun|fs_write_text_file", { path, contents });
|
|
143
|
+
},
|
|
144
|
+
async readTextFile(path) {
|
|
145
|
+
return invoke("plugin:electrobun|fs_read_text_file", { path });
|
|
146
|
+
},
|
|
147
|
+
async writeFile(path, contents) {
|
|
148
|
+
// Serialize binary data as number[] for JSON IPC transport.
|
|
149
|
+
let data;
|
|
150
|
+
if (contents instanceof Uint8Array) {
|
|
151
|
+
data = Array.from(contents);
|
|
152
|
+
}
|
|
153
|
+
else if (contents instanceof ArrayBuffer) {
|
|
154
|
+
data = Array.from(new Uint8Array(contents));
|
|
155
|
+
}
|
|
156
|
+
else if (Array.isArray(contents)) {
|
|
157
|
+
data = contents;
|
|
158
|
+
}
|
|
159
|
+
else {
|
|
160
|
+
data = Array.from(new TextEncoder().encode(contents));
|
|
161
|
+
}
|
|
162
|
+
await invoke("plugin:electrobun|fs_write_file", { path, data });
|
|
163
|
+
},
|
|
164
|
+
async readFile(path) {
|
|
165
|
+
const data = await invoke("plugin:electrobun|fs_read_file", { path });
|
|
166
|
+
return new Uint8Array(data);
|
|
167
|
+
},
|
|
168
|
+
async exists(path) {
|
|
169
|
+
return invoke("plugin:electrobun|fs_exists", { path });
|
|
170
|
+
},
|
|
171
|
+
async mkdir(path, options) {
|
|
172
|
+
await invoke("plugin:electrobun|fs_mkdir", {
|
|
173
|
+
path,
|
|
174
|
+
recursive: options?.recursive ?? false,
|
|
175
|
+
});
|
|
176
|
+
},
|
|
177
|
+
async readDir(path, options) {
|
|
178
|
+
return invoke("plugin:electrobun|fs_read_dir", {
|
|
179
|
+
path,
|
|
180
|
+
recursive: options?.recursive ?? false,
|
|
181
|
+
});
|
|
182
|
+
},
|
|
183
|
+
async remove(path, options) {
|
|
184
|
+
await invoke("plugin:electrobun|fs_remove", {
|
|
185
|
+
path,
|
|
186
|
+
recursive: options?.recursive ?? false,
|
|
187
|
+
});
|
|
188
|
+
},
|
|
189
|
+
async copyFile(fromPath, toPath) {
|
|
190
|
+
await invoke("plugin:electrobun|fs_copy_file", { fromPath, toPath });
|
|
191
|
+
},
|
|
192
|
+
async rename(oldPath, newPath) {
|
|
193
|
+
await invoke("plugin:electrobun|fs_rename", { oldPath, newPath });
|
|
194
|
+
},
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
// ── Dialog Adapter ──────────────────────────────────────────────────────────
|
|
198
|
+
// Supported: message, ask, open, save
|
|
199
|
+
// Partial: none
|
|
200
|
+
// Unsupported: none currently
|
|
201
|
+
//
|
|
202
|
+
// Note: Dialog appearance and behavior depend on the Electrobun backend's
|
|
203
|
+
// native dialog implementation. Options are forwarded as-is.
|
|
204
|
+
export function createElectrobunDialogAdapter() {
|
|
205
|
+
return {
|
|
206
|
+
async message(text, options) {
|
|
207
|
+
await invoke("plugin:electrobun|dialog_message", {
|
|
208
|
+
text,
|
|
209
|
+
title: options?.title,
|
|
210
|
+
okLabel: options?.okLabel,
|
|
211
|
+
});
|
|
212
|
+
},
|
|
213
|
+
async ask(text, options) {
|
|
214
|
+
return invoke("plugin:electrobun|dialog_ask", {
|
|
215
|
+
text,
|
|
216
|
+
title: options?.title,
|
|
217
|
+
okLabel: options?.okLabel,
|
|
218
|
+
cancelLabel: options?.cancelLabel,
|
|
219
|
+
});
|
|
220
|
+
},
|
|
221
|
+
async open(options) {
|
|
222
|
+
return invoke("plugin:electrobun|dialog_open", {
|
|
223
|
+
title: options?.title,
|
|
224
|
+
multiple: options?.multiple ?? false,
|
|
225
|
+
directory: options?.directory ?? false,
|
|
226
|
+
filters: options?.filters,
|
|
227
|
+
});
|
|
228
|
+
},
|
|
229
|
+
async save(options) {
|
|
230
|
+
return invoke("plugin:electrobun|dialog_save", {
|
|
231
|
+
title: options?.title,
|
|
232
|
+
defaultPath: options?.defaultPath,
|
|
233
|
+
});
|
|
234
|
+
},
|
|
235
|
+
};
|
|
236
|
+
}
|
|
237
|
+
// ── Bootstrap ───────────────────────────────────────────────────────────────
|
|
238
|
+
/**
|
|
239
|
+
* Core provider for the Electrobun runtime.
|
|
240
|
+
*
|
|
241
|
+
* Provides the `invoke` and `convertFileSrc` implementations that all
|
|
242
|
+
* adapters delegate through.
|
|
243
|
+
*/
|
|
244
|
+
export function createElectrobunCoreProvider() {
|
|
245
|
+
return {
|
|
246
|
+
id: "electrobun",
|
|
247
|
+
invoke: async (command, _args) => {
|
|
248
|
+
// In a real Electrobun integration, this would delegate to
|
|
249
|
+
// electrobun.ipc.invoke(). For now, we throw to indicate
|
|
250
|
+
// that the actual IPC bridge must be provided at integration time.
|
|
251
|
+
//
|
|
252
|
+
// When integrating, replace this with:
|
|
253
|
+
// return electrobun.ipc.invoke(command, args) as Promise<T>;
|
|
254
|
+
throw new Error(`[webtau/electrobun] No IPC bridge configured. ` +
|
|
255
|
+
`Cannot invoke "${command}". Wire electrobun.ipc.invoke() ` +
|
|
256
|
+
`into the core provider before calling bootstrapElectrobun().`);
|
|
257
|
+
},
|
|
258
|
+
convertFileSrc: (filePath, _protocol) => {
|
|
259
|
+
return `electrobun://asset/${filePath.replace(/^\/+/, "")}`;
|
|
260
|
+
},
|
|
261
|
+
};
|
|
262
|
+
}
|
|
263
|
+
/**
|
|
264
|
+
* Bootstrap all Electrobun adapters at once.
|
|
265
|
+
*
|
|
266
|
+
* Registers the core provider and sets adapters for window, event,
|
|
267
|
+
* filesystem, and dialog modules. After calling this function, all
|
|
268
|
+
* webtau module-level functions will delegate through Electrobun.
|
|
269
|
+
*
|
|
270
|
+
* An optional `coreProvider` can be passed to supply a custom IPC
|
|
271
|
+
* bridge (e.g. one that delegates to `electrobun.ipc.invoke()`).
|
|
272
|
+
*
|
|
273
|
+
* ```ts
|
|
274
|
+
* import { bootstrapElectrobun } from "webtau/adapters/electrobun";
|
|
275
|
+
*
|
|
276
|
+
* bootstrapElectrobun({
|
|
277
|
+
* id: "electrobun",
|
|
278
|
+
* invoke: (cmd, args) => electrobun.ipc.invoke(cmd, args),
|
|
279
|
+
* convertFileSrc: (path) => `electrobun://asset/${path}`,
|
|
280
|
+
* });
|
|
281
|
+
* ```
|
|
282
|
+
*/
|
|
283
|
+
export function bootstrapElectrobun(coreProvider) {
|
|
284
|
+
registerProvider(coreProvider ?? createElectrobunCoreProvider());
|
|
285
|
+
setWindowAdapter(createElectrobunWindowAdapter());
|
|
286
|
+
setEventAdapter(createElectrobunEventAdapter());
|
|
287
|
+
setFsAdapter(createElectrobunFsAdapter());
|
|
288
|
+
setDialogAdapter(createElectrobunDialogAdapter());
|
|
289
|
+
}
|
|
290
|
+
//# sourceMappingURL=electrobun.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"electrobun.js","sourceRoot":"","sources":["../../src/adapters/electrobun.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;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CAAC,CAAC;IAChD,YAAY,CAAC,yBAAyB,EAAE,CAAC,CAAC;IAC1C,gBAAgB,CAAC,6BAA6B,EAAE,CAAC,CAAC;AACpD,CAAC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* webtau/adapters/tauri — Tauri runtime adapter.
|
|
3
|
+
*
|
|
4
|
+
* Implements EventAdapter by delegating to @tauri-apps/api/event, giving
|
|
5
|
+
* Tauri the same deterministic listen/unlisten semantics as other runtimes.
|
|
6
|
+
*
|
|
7
|
+
* Usage:
|
|
8
|
+
* ```ts
|
|
9
|
+
* import { bootstrapTauri } from "webtau/adapters/tauri";
|
|
10
|
+
* bootstrapTauri();
|
|
11
|
+
* ```
|
|
12
|
+
*/
|
|
13
|
+
import type { CoreProvider, EventAdapter } from "../provider";
|
|
14
|
+
export declare function createTauriEventAdapter(): EventAdapter;
|
|
15
|
+
export declare function createTauriCoreProvider(): CoreProvider;
|
|
16
|
+
/**
|
|
17
|
+
* Bootstrap all Tauri adapters at once.
|
|
18
|
+
*
|
|
19
|
+
* Registers the event adapter so that webtau's listen/emit route through
|
|
20
|
+
* Tauri's native IPC event system, ensuring backend-origin events are
|
|
21
|
+
* received by frontend listeners.
|
|
22
|
+
*
|
|
23
|
+
* An optional coreProvider can be passed to override the default Tauri
|
|
24
|
+
* core provider (useful for testing).
|
|
25
|
+
*
|
|
26
|
+
* ```ts
|
|
27
|
+
* import { bootstrapTauri } from "webtau/adapters/tauri";
|
|
28
|
+
* bootstrapTauri();
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
export declare function bootstrapTauri(coreProvider?: CoreProvider): void;
|
|
32
|
+
//# sourceMappingURL=tauri.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tauri.d.ts","sourceRoot":"","sources":["../../src/adapters/tauri.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAKH,OAAO,KAAK,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAwB9D,wBAAgB,uBAAuB,IAAI,YAAY,CAmBtD;AAOD,wBAAgB,uBAAuB,IAAI,YAAY,CAYtD;AAID;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,cAAc,CAAC,YAAY,CAAC,EAAE,YAAY,GAAG,IAAI,CAGhE"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* webtau/adapters/tauri — Tauri runtime adapter.
|
|
3
|
+
*
|
|
4
|
+
* Implements EventAdapter by delegating to @tauri-apps/api/event, giving
|
|
5
|
+
* Tauri the same deterministic listen/unlisten semantics as other runtimes.
|
|
6
|
+
*
|
|
7
|
+
* Usage:
|
|
8
|
+
* ```ts
|
|
9
|
+
* import { bootstrapTauri } from "webtau/adapters/tauri";
|
|
10
|
+
* bootstrapTauri();
|
|
11
|
+
* ```
|
|
12
|
+
*/
|
|
13
|
+
import { registerProvider } from "../core";
|
|
14
|
+
import { setEventAdapter } from "../event";
|
|
15
|
+
// ── Event Adapter ───────────────────────────────────────────────────────────
|
|
16
|
+
// Wraps @tauri-apps/api/event listen/emit for use as webtau EventAdapter.
|
|
17
|
+
// The id field on each dispatched event is the numeric listener id assigned
|
|
18
|
+
// by Tauri's own IPC layer (tauriEvent.id).
|
|
19
|
+
export function createTauriEventAdapter() {
|
|
20
|
+
return {
|
|
21
|
+
async listen(event, handler) {
|
|
22
|
+
// Dynamic import so @tauri-apps/api is only loaded at runtime in Tauri.
|
|
23
|
+
const mod = await import("@tauri-apps/api/event");
|
|
24
|
+
const unlisten = await mod.listen(event, (tauriEvent) => {
|
|
25
|
+
handler({ event: tauriEvent.event, id: tauriEvent.id, payload: tauriEvent.payload });
|
|
26
|
+
});
|
|
27
|
+
return unlisten;
|
|
28
|
+
},
|
|
29
|
+
async emit(event, payload) {
|
|
30
|
+
const mod = await import("@tauri-apps/api/event");
|
|
31
|
+
await mod.emit(event, payload);
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
// ── Core Provider ─────────────────────────────────────────────────────────────
|
|
36
|
+
// Wraps @tauri-apps/api/core for explicit provider registration.
|
|
37
|
+
// Prefer auto-detection (isTauri() path in invoke()) over explicit registration
|
|
38
|
+
// unless you need to force Tauri mode or test with a mock provider.
|
|
39
|
+
export function createTauriCoreProvider() {
|
|
40
|
+
return {
|
|
41
|
+
id: "tauri",
|
|
42
|
+
invoke: async (command, args) => {
|
|
43
|
+
const mod = await import("@tauri-apps/api/core");
|
|
44
|
+
return mod.invoke(command, args);
|
|
45
|
+
},
|
|
46
|
+
convertFileSrc: (filePath, protocol) => {
|
|
47
|
+
const proto = protocol ?? "asset";
|
|
48
|
+
return `${proto}://localhost${filePath.startsWith("/") ? filePath : `/${filePath}`}`;
|
|
49
|
+
},
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
// ── Bootstrap ─────────────────────────────────────────────────────────────────
|
|
53
|
+
/**
|
|
54
|
+
* Bootstrap all Tauri adapters at once.
|
|
55
|
+
*
|
|
56
|
+
* Registers the event adapter so that webtau's listen/emit route through
|
|
57
|
+
* Tauri's native IPC event system, ensuring backend-origin events are
|
|
58
|
+
* received by frontend listeners.
|
|
59
|
+
*
|
|
60
|
+
* An optional coreProvider can be passed to override the default Tauri
|
|
61
|
+
* core provider (useful for testing).
|
|
62
|
+
*
|
|
63
|
+
* ```ts
|
|
64
|
+
* import { bootstrapTauri } from "webtau/adapters/tauri";
|
|
65
|
+
* bootstrapTauri();
|
|
66
|
+
* ```
|
|
67
|
+
*/
|
|
68
|
+
export function bootstrapTauri(coreProvider) {
|
|
69
|
+
registerProvider(coreProvider ?? createTauriCoreProvider());
|
|
70
|
+
setEventAdapter(createTauriEventAdapter());
|
|
71
|
+
}
|
|
72
|
+
//# sourceMappingURL=tauri.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tauri.js","sourceRoot":"","sources":["../../src/adapters/tauri.ts"],"names":[],"mappings":"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EAAE;YAC9D,MAAM,KAAK,GAAG,QAAQ,IAAI,OAAO,CAAC;YAClC,OAAO,GAAG,KAAK,eAAe,QAAQ,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,QAAQ,EAAE,EAAE,CAAC;QACvF,CAAC;KACF,CAAC;AACJ,CAAC;AAED,iFAAiF;AAEjF;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,cAAc,CAAC,YAA2B;IACxD,gBAAgB,CAAC,YAAY,IAAI,uBAAuB,EAAE,CAAC,CAAC;IAC5D,eAAe,CAAC,uBAAuB,EAAE,CAAC,CAAC;AAC7C,CAAC"}
|
package/dist/core.d.ts
CHANGED
|
@@ -13,6 +13,8 @@
|
|
|
13
13
|
*/
|
|
14
14
|
import type { CoreProvider } from "./provider";
|
|
15
15
|
export type { CoreProvider };
|
|
16
|
+
export type { DiagnosticCode, DiagnosticEnvelope } from "./diagnostics";
|
|
17
|
+
export { WebtauError } from "./diagnostics";
|
|
16
18
|
type WasmModule = Record<string, (...args: any[]) => any>;
|
|
17
19
|
export interface WebtauConfig {
|
|
18
20
|
/**
|
package/dist/core.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"core.d.ts","sourceRoot":"","sources":["../src/core.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;
|
|
1
|
+
{"version":3,"file":"core.d.ts","sourceRoot":"","sources":["../src/core.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAGH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE/C,YAAY,EAAE,YAAY,EAAE,CAAC;AAC7B,YAAY,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AACxE,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAG5C,KAAK,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,CAAC,CAAC;AAO1D,MAAM,WAAW,YAAY;IAC3B;;;;OAIG;IACH,QAAQ,EAAE,MAAM,OAAO,CAAC,UAAU,CAAC,CAAC;IAEpC;;;OAGG;IACH,WAAW,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,CAAC;CACxC;AAMD;;;;;;;;;;;GAWG;AACH,wBAAgB,SAAS,CAAC,MAAM,EAAE,YAAY,GAAG,IAAI,CAOpD;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,YAAY,GAAG,IAAI,CAE7D;AAED,4DAA4D;AAC5D,wBAAgB,WAAW,IAAI,YAAY,GAAG,IAAI,CAEjD;AAED,2DAA2D;AAC3D,wBAAgB,aAAa,IAAI,IAAI,CAEpC;AAED;;;GAGG;AACH,wBAAgB,OAAO,IAAI,OAAO,CAKjC;AAkDD;;;;;;;;;;;GAWG;AACH,wBAAsB,MAAM,CAAC,CAAC,GAAG,OAAO,EACtC,OAAO,EAAE,MAAM,EACf,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC7B,OAAO,CAAC,CAAC,CAAC,CA8EZ;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,cAAc,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM,CAM1E"}
|
package/dist/core.js
CHANGED
|
@@ -11,6 +11,8 @@
|
|
|
11
11
|
* (e.g. Electrobun). When no provider is registered and `isTauri()`
|
|
12
12
|
* is true, Tauri auto-registers itself on first invoke().
|
|
13
13
|
*/
|
|
14
|
+
import { WebtauError } from "./diagnostics";
|
|
15
|
+
export { WebtauError } from "./diagnostics";
|
|
14
16
|
let registeredProvider = null;
|
|
15
17
|
let wasmModule = null;
|
|
16
18
|
let wasmLoader = null;
|
|
@@ -87,8 +89,13 @@ async function getWasmModule() {
|
|
|
87
89
|
if (wasmLoadPromise)
|
|
88
90
|
return wasmLoadPromise;
|
|
89
91
|
if (!wasmLoader) {
|
|
90
|
-
throw new
|
|
91
|
-
|
|
92
|
+
throw new WebtauError({
|
|
93
|
+
code: "NO_WASM_CONFIGURED",
|
|
94
|
+
runtime: "wasm",
|
|
95
|
+
command: "",
|
|
96
|
+
message: "[webtau] No WASM module configured.",
|
|
97
|
+
hint: 'Call configure({ loadWasm: () => import("./wasm") }) before invoke().',
|
|
98
|
+
});
|
|
92
99
|
}
|
|
93
100
|
wasmLoadPromise = wasmLoader().then((mod) => {
|
|
94
101
|
wasmModule = mod;
|
|
@@ -98,7 +105,13 @@ async function getWasmModule() {
|
|
|
98
105
|
// user fixes the issue (e.g. reconfigures with a valid loader).
|
|
99
106
|
wasmLoadPromise = null;
|
|
100
107
|
onLoadError(err);
|
|
101
|
-
throw
|
|
108
|
+
throw new WebtauError({
|
|
109
|
+
code: "LOAD_FAILED",
|
|
110
|
+
runtime: "wasm",
|
|
111
|
+
command: "",
|
|
112
|
+
message: `[webtau] Failed to load WASM module: ${err instanceof Error ? err.message : String(err)}`,
|
|
113
|
+
hint: "Check that loadWasm returns a valid WASM module and network is available.",
|
|
114
|
+
});
|
|
102
115
|
});
|
|
103
116
|
return wasmLoadPromise;
|
|
104
117
|
}
|
|
@@ -117,7 +130,20 @@ async function getWasmModule() {
|
|
|
117
130
|
export async function invoke(command, args) {
|
|
118
131
|
// 1. Explicit provider — delegate immediately.
|
|
119
132
|
if (registeredProvider) {
|
|
120
|
-
|
|
133
|
+
try {
|
|
134
|
+
return await registeredProvider.invoke(command, args);
|
|
135
|
+
}
|
|
136
|
+
catch (err) {
|
|
137
|
+
if (err instanceof WebtauError)
|
|
138
|
+
throw err;
|
|
139
|
+
throw new WebtauError({
|
|
140
|
+
code: "PROVIDER_ERROR",
|
|
141
|
+
runtime: registeredProvider.id,
|
|
142
|
+
command,
|
|
143
|
+
message: err instanceof Error ? err.message : String(err),
|
|
144
|
+
hint: `Provider "${registeredProvider.id}" threw while invoking "${command}". Check the provider implementation.`,
|
|
145
|
+
});
|
|
146
|
+
}
|
|
121
147
|
}
|
|
122
148
|
// 2. Auto-detect Tauri — lazily register a Tauri provider, then delegate.
|
|
123
149
|
if (isTauri()) {
|
|
@@ -136,12 +162,47 @@ export async function invoke(command, args) {
|
|
|
136
162
|
const wasm = await getWasmModule();
|
|
137
163
|
const fn = wasm[command];
|
|
138
164
|
if (typeof fn !== "function") {
|
|
139
|
-
|
|
140
|
-
|
|
165
|
+
const available = Object.keys(wasm).filter((k) => typeof wasm[k] === "function").join(", ");
|
|
166
|
+
throw new WebtauError({
|
|
167
|
+
code: "UNKNOWN_COMMAND",
|
|
168
|
+
runtime: "wasm",
|
|
169
|
+
command,
|
|
170
|
+
message: `[webtau] WASM module has no export named "${command}". Available: ${available}`,
|
|
171
|
+
hint: `Export "${command}" is not defined. Available exports: ${available}`,
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
try {
|
|
175
|
+
const result = args ? fn(args) : fn();
|
|
176
|
+
// wasm_bindgen can return plain values or promises
|
|
177
|
+
if (result instanceof Promise) {
|
|
178
|
+
try {
|
|
179
|
+
return await result;
|
|
180
|
+
}
|
|
181
|
+
catch (asyncErr) {
|
|
182
|
+
if (asyncErr instanceof WebtauError)
|
|
183
|
+
throw asyncErr;
|
|
184
|
+
throw new WebtauError({
|
|
185
|
+
code: "PROVIDER_ERROR",
|
|
186
|
+
runtime: "wasm",
|
|
187
|
+
command,
|
|
188
|
+
message: asyncErr instanceof Error ? asyncErr.message : String(asyncErr),
|
|
189
|
+
hint: `WASM command "${command}" rejected. Check the Rust implementation for errors.`,
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
return result;
|
|
194
|
+
}
|
|
195
|
+
catch (execErr) {
|
|
196
|
+
if (execErr instanceof WebtauError)
|
|
197
|
+
throw execErr;
|
|
198
|
+
throw new WebtauError({
|
|
199
|
+
code: "PROVIDER_ERROR",
|
|
200
|
+
runtime: "wasm",
|
|
201
|
+
command,
|
|
202
|
+
message: execErr instanceof Error ? execErr.message : String(execErr),
|
|
203
|
+
hint: `WASM command "${command}" threw an error. Check the Rust implementation.`,
|
|
204
|
+
});
|
|
141
205
|
}
|
|
142
|
-
const result = args ? fn(args) : fn();
|
|
143
|
-
// wasm_bindgen can return plain values or promises
|
|
144
|
-
return result instanceof Promise ? result : result;
|
|
145
206
|
}
|
|
146
207
|
/**
|
|
147
208
|
* Converts a file path to a URL that can be used to load assets.
|
package/dist/core.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"core.js","sourceRoot":"","sources":["../src/core.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;
|
|
1
|
+
{"version":3,"file":"core.js","sourceRoot":"","sources":["../src/core.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAK5C,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAK5C,IAAI,kBAAkB,GAAwB,IAAI,CAAC;AACnD,IAAI,UAAU,GAAsB,IAAI,CAAC;AACzC,IAAI,UAAU,GAAuC,IAAI,CAAC;AAC1D,IAAI,eAAe,GAA+B,IAAI,CAAC;AAiBvD,IAAI,WAAW,GAA6B,CAAC,GAAG,EAAE,EAAE;IAClD,OAAO,CAAC,KAAK,CAAC,sCAAsC,EAAE,GAAG,CAAC,CAAC;AAC7D,CAAC,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,SAAS,CAAC,MAAoB;IAC5C,UAAU,GAAG,MAAM,CAAC,QAAQ,CAAC;IAC7B,UAAU,GAAG,IAAI,CAAC;IAClB,eAAe,GAAG,IAAI,CAAC;IACvB,IAAI,MAAM,CAAC,WAAW,EAAE,CAAC;QACvB,WAAW,GAAG,MAAM,CAAC,WAAW,CAAC;IACnC,CAAC;AACH,CAAC;AAED;;;;;;;;;;;;;GAa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B,OAAO,uDAAuD;iBACtF,CAAC,CAAC;YACL,CAAC;QACH,CAAC;QAED,OAAO,MAAW,CAAC;IACrB,CAAC;IAAC,OAAO,OAAO,EAAE,CAAC;QACjB,IAAI,OAAO,YAAY,WAAW;YAAE,MAAM,OAAO,CAAC;QAClD,MAAM,IAAI,WAAW,CAAC;YACpB,IAAI,EAAE,gBAAgB;YACtB,OAAO,EAAE,MAAM;YACf,OAAO;YACP,OAAO,EAAE,OAAO,YAAY,KAAK,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC;YACrE,IAAI,EAAE,iBAAiB,OAAO,kDAAkD;SACjF,CAAC,CAAC;IACL,CAAC;AACH,CAAC;AAED;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,cAAc,CAAC,QAAgB,EAAE,QAAiB;IAChE,IAAI,kBAAkB,EAAE,CAAC;QACvB,OAAO,kBAAkB,CAAC,cAAc,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;IAC/D,CAAC;IACD,qEAAqE;IACrE,OAAO,QAAQ,CAAC;AAClB,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* webtau/diagnostics — Structured error envelope for all webtau failures.
|
|
3
|
+
*
|
|
4
|
+
* Every failure surface from invoke(), configure(), and provider paths
|
|
5
|
+
* throws a WebtauError instead of a plain Error, enabling callers to
|
|
6
|
+
* programmatically inspect and handle failure categories.
|
|
7
|
+
*/
|
|
8
|
+
export type DiagnosticCode = "NO_WASM_CONFIGURED" | "UNKNOWN_COMMAND" | "LOAD_FAILED" | "PROVIDER_ERROR" | "PROVIDER_MISSING";
|
|
9
|
+
export interface DiagnosticEnvelope {
|
|
10
|
+
/** Machine-readable failure category. */
|
|
11
|
+
code: DiagnosticCode;
|
|
12
|
+
/** Which runtime path produced this error: "wasm", "tauri", "provider", or "unknown". */
|
|
13
|
+
runtime: string;
|
|
14
|
+
/** The command name that was invoked when the error occurred, if any. */
|
|
15
|
+
command: string;
|
|
16
|
+
/** Human-readable description of the failure. */
|
|
17
|
+
message: string;
|
|
18
|
+
/** Remediation hint for the developer. */
|
|
19
|
+
hint: string;
|
|
20
|
+
}
|
|
21
|
+
export declare class WebtauError extends Error implements DiagnosticEnvelope {
|
|
22
|
+
readonly code: DiagnosticCode;
|
|
23
|
+
readonly runtime: string;
|
|
24
|
+
readonly command: string;
|
|
25
|
+
readonly hint: string;
|
|
26
|
+
constructor(envelope: DiagnosticEnvelope);
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=diagnostics.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"diagnostics.d.ts","sourceRoot":"","sources":["../src/diagnostics.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,MAAM,MAAM,cAAc,GACtB,oBAAoB,GACpB,iBAAiB,GACjB,aAAa,GACb,gBAAgB,GAChB,kBAAkB,CAAC;AAEvB,MAAM,WAAW,kBAAkB;IACjC,yCAAyC;IACzC,IAAI,EAAE,cAAc,CAAC;IACrB,yFAAyF;IACzF,OAAO,EAAE,MAAM,CAAC;IAChB,yEAAyE;IACzE,OAAO,EAAE,MAAM,CAAC;IAChB,iDAAiD;IACjD,OAAO,EAAE,MAAM,CAAC;IAChB,0CAA0C;IAC1C,IAAI,EAAE,MAAM,CAAC;CACd;AAED,qBAAa,WAAY,SAAQ,KAAM,YAAW,kBAAkB;IAClE,QAAQ,CAAC,IAAI,EAAE,cAAc,CAAC;IAC9B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;gBAEV,QAAQ,EAAE,kBAAkB;CAQzC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* webtau/diagnostics — Structured error envelope for all webtau failures.
|
|
3
|
+
*
|
|
4
|
+
* Every failure surface from invoke(), configure(), and provider paths
|
|
5
|
+
* throws a WebtauError instead of a plain Error, enabling callers to
|
|
6
|
+
* programmatically inspect and handle failure categories.
|
|
7
|
+
*/
|
|
8
|
+
export class WebtauError extends Error {
|
|
9
|
+
code;
|
|
10
|
+
runtime;
|
|
11
|
+
command;
|
|
12
|
+
hint;
|
|
13
|
+
constructor(envelope) {
|
|
14
|
+
super(envelope.message);
|
|
15
|
+
this.name = "WebtauError";
|
|
16
|
+
this.code = envelope.code;
|
|
17
|
+
this.runtime = envelope.runtime;
|
|
18
|
+
this.command = envelope.command;
|
|
19
|
+
this.hint = envelope.hint;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=diagnostics.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"diagnostics.js","sourceRoot":"","sources":["../src/diagnostics.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAsBH,MAAM,OAAO,WAAY,SAAQ,KAAK;IAC3B,IAAI,CAAiB;IACrB,OAAO,CAAS;IAChB,OAAO,CAAS;IAChB,IAAI,CAAS;IAEtB,YAAY,QAA4B;QACtC,KAAK,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;QACxB,IAAI,CAAC,IAAI,GAAG,aAAa,CAAC;QAC1B,IAAI,CAAC,IAAI,GAAG,QAAQ,CAAC,IAAI,CAAC;QAC1B,IAAI,CAAC,OAAO,GAAG,QAAQ,CAAC,OAAO,CAAC;QAChC,IAAI,CAAC,OAAO,GAAG,QAAQ,CAAC,OAAO,CAAC;QAChC,IAAI,CAAC,IAAI,GAAG,QAAQ,CAAC,IAAI,CAAC;IAC5B,CAAC;CACF"}
|
package/dist/task.d.ts
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* webtau/task — Long-running task lifecycle API.
|
|
3
|
+
*
|
|
4
|
+
* Provides startTask/pollTask/cancelTask for non-blocking backend operations.
|
|
5
|
+
* Tasks are tracked internally; progress/completion are driven by invoke()
|
|
6
|
+
* resolution and the structured diagnostic envelope from diagnostics.ts.
|
|
7
|
+
*
|
|
8
|
+
* ```ts
|
|
9
|
+
* import { startTask, pollTask, cancelTask } from "webtau/task";
|
|
10
|
+
*
|
|
11
|
+
* const taskId = await startTask("process_save_data", { slot: 1 });
|
|
12
|
+
* const status = await pollTask(taskId);
|
|
13
|
+
* if (status.state === "completed") console.log(status.result);
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
import { WebtauError } from "./diagnostics";
|
|
17
|
+
export interface TaskProgress {
|
|
18
|
+
/** Completion percentage (0–100). Should be monotonically non-decreasing. */
|
|
19
|
+
percent: number;
|
|
20
|
+
/** Optional human-readable status message. */
|
|
21
|
+
message?: string;
|
|
22
|
+
}
|
|
23
|
+
export type TaskState<T> = {
|
|
24
|
+
state: "running";
|
|
25
|
+
progress?: TaskProgress;
|
|
26
|
+
} | {
|
|
27
|
+
state: "completed";
|
|
28
|
+
result: T;
|
|
29
|
+
} | {
|
|
30
|
+
state: "cancelled";
|
|
31
|
+
} | {
|
|
32
|
+
state: "failed";
|
|
33
|
+
error: WebtauError;
|
|
34
|
+
};
|
|
35
|
+
export interface StartTaskOptions {
|
|
36
|
+
/**
|
|
37
|
+
* Called when cancelTask() is invoked for this task.
|
|
38
|
+
* Use this to propagate cancellation to the backend, e.g. by invoking
|
|
39
|
+
* a cancel command or aborting an in-flight request.
|
|
40
|
+
*
|
|
41
|
+
* ```ts
|
|
42
|
+
* const taskId = await startTask("heavy_op", { slot: 1 }, {
|
|
43
|
+
* onCancel: () => invoke("cancel_heavy_op", { taskId }),
|
|
44
|
+
* });
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
onCancel?: () => void | Promise<void>;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Start a long-running backend task without blocking the caller.
|
|
51
|
+
*
|
|
52
|
+
* Launches `command` via invoke() and returns a taskId immediately.
|
|
53
|
+
* Use pollTask(taskId) to query current state and cancelTask(taskId) to
|
|
54
|
+
* signal cancellation before the task completes.
|
|
55
|
+
*
|
|
56
|
+
* The optional `options.onCancel` callback is invoked when cancelTask()
|
|
57
|
+
* is called, allowing the consumer to propagate cancellation to the
|
|
58
|
+
* backend (e.g. by invoking a cancel command).
|
|
59
|
+
*/
|
|
60
|
+
export declare function startTask<T>(command: string, args?: Record<string, unknown>, options?: StartTaskOptions): Promise<string>;
|
|
61
|
+
/**
|
|
62
|
+
* Poll the current state of a task without blocking.
|
|
63
|
+
*
|
|
64
|
+
* Returns a Promise that resolves immediately with the current TaskState.
|
|
65
|
+
* Terminal states (completed, cancelled, failed) are permanent.
|
|
66
|
+
*/
|
|
67
|
+
export declare function pollTask<T>(taskId: string): Promise<TaskState<T>>;
|
|
68
|
+
/**
|
|
69
|
+
* Signal cancellation for a running task.
|
|
70
|
+
*
|
|
71
|
+
* Idempotent: calling multiple times on the same taskId is safe.
|
|
72
|
+
* If the task has already completed, this is a no-op.
|
|
73
|
+
* If the task has not yet completed, the status transitions to "cancelled"
|
|
74
|
+
* and any future invoke() resolution is ignored.
|
|
75
|
+
*
|
|
76
|
+
* If `onCancel` was provided in startTask options, it is called to
|
|
77
|
+
* propagate cancellation to the backend. This ensures the backend
|
|
78
|
+
* can stop ongoing work rather than continuing to mutate state.
|
|
79
|
+
*/
|
|
80
|
+
export declare function cancelTask(taskId: string): Promise<void>;
|
|
81
|
+
/**
|
|
82
|
+
* Update the progress of a running task.
|
|
83
|
+
* Useful for providers or test helpers that push intermediate progress.
|
|
84
|
+
* No-ops if the task is not in "running" state.
|
|
85
|
+
*/
|
|
86
|
+
export declare function updateTaskProgress(taskId: string, progress: TaskProgress): void;
|
|
87
|
+
/** Clears all tracked tasks. Intended for test isolation. */
|
|
88
|
+
export declare function resetTasks(): void;
|
|
89
|
+
//# sourceMappingURL=task.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"task.d.ts","sourceRoot":"","s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AAC7D,wBAAgB,UAAU,IAAI,IAAI,CAGjC"}
|
package/dist/task.js
ADDED
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* webtau/task — Long-running task lifecycle API.
|
|
3
|
+
*
|
|
4
|
+
* Provides startTask/pollTask/cancelTask for non-blocking backend operations.
|
|
5
|
+
* Tasks are tracked internally; progress/completion are driven by invoke()
|
|
6
|
+
* resolution and the structured diagnostic envelope from diagnostics.ts.
|
|
7
|
+
*
|
|
8
|
+
* ```ts
|
|
9
|
+
* import { startTask, pollTask, cancelTask } from "webtau/task";
|
|
10
|
+
*
|
|
11
|
+
* const taskId = await startTask("process_save_data", { slot: 1 });
|
|
12
|
+
* const status = await pollTask(taskId);
|
|
13
|
+
* if (status.state === "completed") console.log(status.result);
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
import { invoke } from "./core";
|
|
17
|
+
import { WebtauError } from "./diagnostics";
|
|
18
|
+
const taskRegistry = new Map();
|
|
19
|
+
let nextTaskId = 1;
|
|
20
|
+
// ── Public API ──────────────────────────────────────────────────────────────
|
|
21
|
+
/**
|
|
22
|
+
* Start a long-running backend task without blocking the caller.
|
|
23
|
+
*
|
|
24
|
+
* Launches `command` via invoke() and returns a taskId immediately.
|
|
25
|
+
* Use pollTask(taskId) to query current state and cancelTask(taskId) to
|
|
26
|
+
* signal cancellation before the task completes.
|
|
27
|
+
*
|
|
28
|
+
* The optional `options.onCancel` callback is invoked when cancelTask()
|
|
29
|
+
* is called, allowing the consumer to propagate cancellation to the
|
|
30
|
+
* backend (e.g. by invoking a cancel command).
|
|
31
|
+
*/
|
|
32
|
+
export async function startTask(command, args, options) {
|
|
33
|
+
const taskId = `task-${nextTaskId++}`;
|
|
34
|
+
const entry = {
|
|
35
|
+
status: { state: "running" },
|
|
36
|
+
cancelled: false,
|
|
37
|
+
onCancel: options?.onCancel,
|
|
38
|
+
};
|
|
39
|
+
taskRegistry.set(taskId, entry);
|
|
40
|
+
invoke(command, args).then((result) => {
|
|
41
|
+
const current = taskRegistry.get(taskId);
|
|
42
|
+
if (current && !current.cancelled) {
|
|
43
|
+
current.status = { state: "completed", result };
|
|
44
|
+
}
|
|
45
|
+
}, (err) => {
|
|
46
|
+
const current = taskRegistry.get(taskId);
|
|
47
|
+
if (!current)
|
|
48
|
+
return;
|
|
49
|
+
if (current.cancelled) {
|
|
50
|
+
current.status = { state: "cancelled" };
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
const webtauErr = err instanceof WebtauError
|
|
54
|
+
? err
|
|
55
|
+
: new WebtauError({
|
|
56
|
+
code: "PROVIDER_ERROR",
|
|
57
|
+
runtime: "unknown",
|
|
58
|
+
command,
|
|
59
|
+
message: err instanceof Error ? err.message : String(err),
|
|
60
|
+
hint: "Check the command implementation for errors.",
|
|
61
|
+
});
|
|
62
|
+
current.status = { state: "failed", error: webtauErr };
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
return taskId;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Poll the current state of a task without blocking.
|
|
69
|
+
*
|
|
70
|
+
* Returns a Promise that resolves immediately with the current TaskState.
|
|
71
|
+
* Terminal states (completed, cancelled, failed) are permanent.
|
|
72
|
+
*/
|
|
73
|
+
export async function pollTask(taskId) {
|
|
74
|
+
const entry = taskRegistry.get(taskId);
|
|
75
|
+
if (!entry) {
|
|
76
|
+
throw new WebtauError({
|
|
77
|
+
code: "UNKNOWN_COMMAND",
|
|
78
|
+
runtime: "unknown",
|
|
79
|
+
command: taskId,
|
|
80
|
+
message: `[webtau] No task with id "${taskId}".`,
|
|
81
|
+
hint: "Ensure startTask() was called and the taskId is correct.",
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
return entry.status;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Signal cancellation for a running task.
|
|
88
|
+
*
|
|
89
|
+
* Idempotent: calling multiple times on the same taskId is safe.
|
|
90
|
+
* If the task has already completed, this is a no-op.
|
|
91
|
+
* If the task has not yet completed, the status transitions to "cancelled"
|
|
92
|
+
* and any future invoke() resolution is ignored.
|
|
93
|
+
*
|
|
94
|
+
* If `onCancel` was provided in startTask options, it is called to
|
|
95
|
+
* propagate cancellation to the backend. This ensures the backend
|
|
96
|
+
* can stop ongoing work rather than continuing to mutate state.
|
|
97
|
+
*/
|
|
98
|
+
export async function cancelTask(taskId) {
|
|
99
|
+
const entry = taskRegistry.get(taskId);
|
|
100
|
+
if (!entry)
|
|
101
|
+
return;
|
|
102
|
+
if (entry.cancelled)
|
|
103
|
+
return;
|
|
104
|
+
entry.cancelled = true;
|
|
105
|
+
if (entry.status.state === "running") {
|
|
106
|
+
entry.status = { state: "cancelled" };
|
|
107
|
+
}
|
|
108
|
+
if (entry.onCancel) {
|
|
109
|
+
await entry.onCancel();
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Update the progress of a running task.
|
|
114
|
+
* Useful for providers or test helpers that push intermediate progress.
|
|
115
|
+
* No-ops if the task is not in "running" state.
|
|
116
|
+
*/
|
|
117
|
+
export function updateTaskProgress(taskId, progress) {
|
|
118
|
+
const entry = taskRegistry.get(taskId);
|
|
119
|
+
if (!entry || entry.status.state !== "running")
|
|
120
|
+
return;
|
|
121
|
+
entry.status = { state: "running", progress };
|
|
122
|
+
}
|
|
123
|
+
/** Clears all tracked tasks. Intended for test isolation. */
|
|
124
|
+
export function resetTasks() {
|
|
125
|
+
taskRegistry.clear();
|
|
126
|
+
nextTaskId = 1;
|
|
127
|
+
}
|
|
128
|
+
//# sourceMappingURL=task.js.map
|
package/dist/task.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"task.js","sourceRoot":"","sources":["../src/task.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CA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;AAED;;;;GAIG;AACH,MAAM,UAAU,kBAAkB,CAAC,MAAc,EAAE,QAAsB;IACvE,MAAM,KAAK,GAAG,YAAY,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;IACvC,IAAI,CAAC,KAAK,IAAI,KAAK,CAAC,MAAM,CAAC,KAAK,KAAK,SAAS;QAAE,OAAO;IACvD,KAAK,CAAC,MAAM,GAAG,EAAE,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,CAAC;AAChD,CAAC;AAED,6DAA6D;AAC7D,MAAM,UAAU,UAAU;IACxB,YAAY,CAAC,KAAK,EAAE,CAAC;IACrB,UAAU,GAAG,CAAC,CAAC;AACjB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "webtau",
|
|
3
|
-
"version": "0.5.0
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "Deploy Tauri games to web + desktop from one codebase",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -61,6 +61,18 @@
|
|
|
61
61
|
"./provider": {
|
|
62
62
|
"types": "./dist/provider.d.ts",
|
|
63
63
|
"import": "./dist/provider.js"
|
|
64
|
+
},
|
|
65
|
+
"./adapters/electrobun": {
|
|
66
|
+
"types": "./dist/adapters/electrobun.d.ts",
|
|
67
|
+
"import": "./dist/adapters/electrobun.js"
|
|
68
|
+
},
|
|
69
|
+
"./adapters/tauri": {
|
|
70
|
+
"types": "./dist/adapters/tauri.d.ts",
|
|
71
|
+
"import": "./dist/adapters/tauri.js"
|
|
72
|
+
},
|
|
73
|
+
"./task": {
|
|
74
|
+
"types": "./dist/task.d.ts",
|
|
75
|
+
"import": "./dist/task.js"
|
|
64
76
|
}
|
|
65
77
|
},
|
|
66
78
|
"files": [
|