@ai-matrx/desktop-protocol 0.21.45 → 0.21.46
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/CHANGELOG.md +17 -2
- package/README.md +1 -1
- package/dist/client.cjs +30 -7
- package/dist/client.cjs.map +1 -1
- package/dist/client.d.cts +5 -5
- package/dist/client.d.ts +5 -5
- package/dist/client.js +30 -7
- package/dist/client.js.map +1 -1
- package/dist/index.cjs +41 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1710 -1488
- package/dist/index.d.ts +1710 -1488
- package/dist/index.js +41 -7
- package/dist/index.js.map +1 -1
- package/dist/{models-BFAtNMgx.d.cts → models-DIsQe_Ef.d.cts} +242 -107
- package/dist/{models-BFAtNMgx.d.ts → models-DIsQe_Ef.d.ts} +242 -107
- package/dist/react.cjs +9 -0
- package/dist/react.cjs.map +1 -1
- package/dist/react.d.cts +48 -5
- package/dist/react.d.ts +48 -5
- package/dist/react.js +9 -0
- package/dist/react.js.map +1 -1
- package/generated/desktop-protocol.schema.json +139 -1
- package/package.json +5 -5
|
@@ -711,7 +711,7 @@ type OpSpec = {
|
|
|
711
711
|
readonly params: z.ZodType;
|
|
712
712
|
readonly result: z.ZodType;
|
|
713
713
|
readonly kind: "unary" | "stream" | "resource";
|
|
714
|
-
readonly since: "1.0" | "1.2" | "1.3" | "1.4" | "1.5" | "1.6" | "1.8" | "1.9" | "1.10" | "1.11" | "1.16" | "1.17" | "1.19" | "1.20" | "1.21" | "1.22" | "1.23" | "1.24" | "1.26" | "1.28" | "1.29" | "1.30" | "1.31" | "1.37" | "1.38" | "1.39" | "1.40" | "1.43" | "1.44" | "1.45" | "1.47";
|
|
714
|
+
readonly since: "1.0" | "1.2" | "1.3" | "1.4" | "1.5" | "1.6" | "1.8" | "1.9" | "1.10" | "1.11" | "1.16" | "1.17" | "1.19" | "1.20" | "1.21" | "1.22" | "1.23" | "1.24" | "1.26" | "1.28" | "1.29" | "1.30" | "1.31" | "1.37" | "1.38" | "1.39" | "1.40" | "1.43" | "1.44" | "1.45" | "1.47" | "1.50";
|
|
715
715
|
readonly errors: readonly z.infer<typeof ErrorCode>[];
|
|
716
716
|
};
|
|
717
717
|
declare const OPS: {
|
|
@@ -2336,6 +2336,18 @@ declare const OPS: {
|
|
|
2336
2336
|
created: z.ZodBoolean;
|
|
2337
2337
|
running: z.ZodBoolean;
|
|
2338
2338
|
open_chats: z.ZodInt;
|
|
2339
|
+
remote_control: z.ZodOptional<z.ZodObject<{
|
|
2340
|
+
setting: z.ZodEnum<{
|
|
2341
|
+
default: "default";
|
|
2342
|
+
on: "on";
|
|
2343
|
+
off: "off";
|
|
2344
|
+
}>;
|
|
2345
|
+
serving: z.ZodNullable<z.ZodBoolean>;
|
|
2346
|
+
pending: z.ZodNullable<z.ZodEnum<{
|
|
2347
|
+
on: "on";
|
|
2348
|
+
off: "off";
|
|
2349
|
+
}>>;
|
|
2350
|
+
}, z.core.$strict>>;
|
|
2339
2351
|
}, z.core.$strict>>;
|
|
2340
2352
|
}, z.core.$strict>;
|
|
2341
2353
|
readonly kind: "unary";
|
|
@@ -2379,6 +2391,35 @@ declare const OPS: {
|
|
|
2379
2391
|
readonly since: "1.10";
|
|
2380
2392
|
readonly errors: readonly ["NOT_FOUND", "CONFLICT", "TIMEOUT", "PLATFORM_UNSUPPORTED", "INTERNAL"];
|
|
2381
2393
|
};
|
|
2394
|
+
readonly "apps.windows.set_remote_control": {
|
|
2395
|
+
readonly params: z.ZodObject<{
|
|
2396
|
+
app_key: z.ZodString;
|
|
2397
|
+
window: z.ZodString;
|
|
2398
|
+
enabled: z.ZodBoolean;
|
|
2399
|
+
}, z.core.$strict>;
|
|
2400
|
+
readonly result: z.ZodObject<{
|
|
2401
|
+
message: z.ZodString;
|
|
2402
|
+
when: z.ZodEnum<{
|
|
2403
|
+
now: "now";
|
|
2404
|
+
next_close: "next_close";
|
|
2405
|
+
}>;
|
|
2406
|
+
remote_control: z.ZodObject<{
|
|
2407
|
+
setting: z.ZodEnum<{
|
|
2408
|
+
default: "default";
|
|
2409
|
+
on: "on";
|
|
2410
|
+
off: "off";
|
|
2411
|
+
}>;
|
|
2412
|
+
serving: z.ZodNullable<z.ZodBoolean>;
|
|
2413
|
+
pending: z.ZodNullable<z.ZodEnum<{
|
|
2414
|
+
on: "on";
|
|
2415
|
+
off: "off";
|
|
2416
|
+
}>>;
|
|
2417
|
+
}, z.core.$strict>;
|
|
2418
|
+
}, z.core.$strict>;
|
|
2419
|
+
readonly kind: "unary";
|
|
2420
|
+
readonly since: "1.50";
|
|
2421
|
+
readonly errors: readonly ["NOT_FOUND", "CONFLICT", "PLATFORM_UNSUPPORTED", "INTERNAL"];
|
|
2422
|
+
};
|
|
2382
2423
|
readonly "apps.windows.refresh_usage": {
|
|
2383
2424
|
readonly params: z.ZodObject<{
|
|
2384
2425
|
app_key: z.ZodString;
|
|
@@ -2449,6 +2490,7 @@ declare const OPS: {
|
|
|
2449
2490
|
readonly "apps.instances.list": {
|
|
2450
2491
|
readonly params: z.ZodObject<{
|
|
2451
2492
|
app_key: z.ZodString;
|
|
2493
|
+
fresh: z.ZodOptional<z.ZodBoolean>;
|
|
2452
2494
|
}, z.core.$strict>;
|
|
2453
2495
|
readonly result: z.ZodObject<{
|
|
2454
2496
|
app_key: z.ZodString;
|
|
@@ -2482,6 +2524,8 @@ declare const OPS: {
|
|
|
2482
2524
|
first_launch_ms: z.ZodNullable<z.ZodInt>;
|
|
2483
2525
|
}, z.core.$strict>>;
|
|
2484
2526
|
problem: z.ZodOptional<z.ZodString>;
|
|
2527
|
+
as_of_ms: z.ZodOptional<z.ZodInt>;
|
|
2528
|
+
refreshing: z.ZodOptional<z.ZodBoolean>;
|
|
2485
2529
|
}, z.core.$strict>;
|
|
2486
2530
|
readonly kind: "unary";
|
|
2487
2531
|
readonly since: "1.47";
|
|
@@ -2490,6 +2534,7 @@ declare const OPS: {
|
|
|
2490
2534
|
readonly "apps.accounts.list": {
|
|
2491
2535
|
readonly params: z.ZodObject<{
|
|
2492
2536
|
app_key: z.ZodString;
|
|
2537
|
+
fresh: z.ZodOptional<z.ZodBoolean>;
|
|
2493
2538
|
}, z.core.$strict>;
|
|
2494
2539
|
readonly result: z.ZodObject<{
|
|
2495
2540
|
app_key: z.ZodString;
|
|
@@ -2524,6 +2569,8 @@ declare const OPS: {
|
|
|
2524
2569
|
}>>;
|
|
2525
2570
|
}, z.core.$strict>>;
|
|
2526
2571
|
problem: z.ZodOptional<z.ZodString>;
|
|
2572
|
+
as_of_ms: z.ZodOptional<z.ZodInt>;
|
|
2573
|
+
refreshing: z.ZodOptional<z.ZodBoolean>;
|
|
2527
2574
|
}, z.core.$strict>;
|
|
2528
2575
|
readonly kind: "unary";
|
|
2529
2576
|
readonly since: "1.47";
|
|
@@ -8681,6 +8728,7 @@ declare const NAMED_SCHEMAS: {
|
|
|
8681
8728
|
}, z.core.$strict>;
|
|
8682
8729
|
readonly AppsInstancesListParams: z.ZodObject<{
|
|
8683
8730
|
app_key: z.ZodString;
|
|
8731
|
+
fresh: z.ZodOptional<z.ZodBoolean>;
|
|
8684
8732
|
}, z.core.$strict>;
|
|
8685
8733
|
readonly AppsInstancesListResult: z.ZodObject<{
|
|
8686
8734
|
app_key: z.ZodString;
|
|
@@ -8714,9 +8762,12 @@ declare const NAMED_SCHEMAS: {
|
|
|
8714
8762
|
first_launch_ms: z.ZodNullable<z.ZodInt>;
|
|
8715
8763
|
}, z.core.$strict>>;
|
|
8716
8764
|
problem: z.ZodOptional<z.ZodString>;
|
|
8765
|
+
as_of_ms: z.ZodOptional<z.ZodInt>;
|
|
8766
|
+
refreshing: z.ZodOptional<z.ZodBoolean>;
|
|
8717
8767
|
}, z.core.$strict>;
|
|
8718
8768
|
readonly AppsAccountsListParams: z.ZodObject<{
|
|
8719
8769
|
app_key: z.ZodString;
|
|
8770
|
+
fresh: z.ZodOptional<z.ZodBoolean>;
|
|
8720
8771
|
}, z.core.$strict>;
|
|
8721
8772
|
readonly AppsAccountsListResult: z.ZodObject<{
|
|
8722
8773
|
app_key: z.ZodString;
|
|
@@ -8751,6 +8802,8 @@ declare const NAMED_SCHEMAS: {
|
|
|
8751
8802
|
}>>;
|
|
8752
8803
|
}, z.core.$strict>>;
|
|
8753
8804
|
problem: z.ZodOptional<z.ZodString>;
|
|
8805
|
+
as_of_ms: z.ZodOptional<z.ZodInt>;
|
|
8806
|
+
refreshing: z.ZodOptional<z.ZodBoolean>;
|
|
8754
8807
|
}, z.core.$strict>;
|
|
8755
8808
|
readonly ProtocolVersion: z.ZodString;
|
|
8756
8809
|
readonly RequestId: z.ZodString;
|
|
@@ -14875,6 +14928,54 @@ declare const NAMED_SCHEMAS: {
|
|
|
14875
14928
|
created: z.ZodBoolean;
|
|
14876
14929
|
running: z.ZodBoolean;
|
|
14877
14930
|
open_chats: z.ZodInt;
|
|
14931
|
+
remote_control: z.ZodOptional<z.ZodObject<{
|
|
14932
|
+
setting: z.ZodEnum<{
|
|
14933
|
+
default: "default";
|
|
14934
|
+
on: "on";
|
|
14935
|
+
off: "off";
|
|
14936
|
+
}>;
|
|
14937
|
+
serving: z.ZodNullable<z.ZodBoolean>;
|
|
14938
|
+
pending: z.ZodNullable<z.ZodEnum<{
|
|
14939
|
+
on: "on";
|
|
14940
|
+
off: "off";
|
|
14941
|
+
}>>;
|
|
14942
|
+
}, z.core.$strict>>;
|
|
14943
|
+
}, z.core.$strict>;
|
|
14944
|
+
readonly WindowRemoteControl: z.ZodObject<{
|
|
14945
|
+
setting: z.ZodEnum<{
|
|
14946
|
+
default: "default";
|
|
14947
|
+
on: "on";
|
|
14948
|
+
off: "off";
|
|
14949
|
+
}>;
|
|
14950
|
+
serving: z.ZodNullable<z.ZodBoolean>;
|
|
14951
|
+
pending: z.ZodNullable<z.ZodEnum<{
|
|
14952
|
+
on: "on";
|
|
14953
|
+
off: "off";
|
|
14954
|
+
}>>;
|
|
14955
|
+
}, z.core.$strict>;
|
|
14956
|
+
readonly AppsWindowsSetRemoteControlParams: z.ZodObject<{
|
|
14957
|
+
app_key: z.ZodString;
|
|
14958
|
+
window: z.ZodString;
|
|
14959
|
+
enabled: z.ZodBoolean;
|
|
14960
|
+
}, z.core.$strict>;
|
|
14961
|
+
readonly AppsWindowsSetRemoteControlResult: z.ZodObject<{
|
|
14962
|
+
message: z.ZodString;
|
|
14963
|
+
when: z.ZodEnum<{
|
|
14964
|
+
now: "now";
|
|
14965
|
+
next_close: "next_close";
|
|
14966
|
+
}>;
|
|
14967
|
+
remote_control: z.ZodObject<{
|
|
14968
|
+
setting: z.ZodEnum<{
|
|
14969
|
+
default: "default";
|
|
14970
|
+
on: "on";
|
|
14971
|
+
off: "off";
|
|
14972
|
+
}>;
|
|
14973
|
+
serving: z.ZodNullable<z.ZodBoolean>;
|
|
14974
|
+
pending: z.ZodNullable<z.ZodEnum<{
|
|
14975
|
+
on: "on";
|
|
14976
|
+
off: "off";
|
|
14977
|
+
}>>;
|
|
14978
|
+
}, z.core.$strict>;
|
|
14878
14979
|
}, z.core.$strict>;
|
|
14879
14980
|
readonly AccountUsage: z.ZodObject<{
|
|
14880
14981
|
account: z.ZodString;
|
|
@@ -14922,6 +15023,18 @@ declare const NAMED_SCHEMAS: {
|
|
|
14922
15023
|
created: z.ZodBoolean;
|
|
14923
15024
|
running: z.ZodBoolean;
|
|
14924
15025
|
open_chats: z.ZodInt;
|
|
15026
|
+
remote_control: z.ZodOptional<z.ZodObject<{
|
|
15027
|
+
setting: z.ZodEnum<{
|
|
15028
|
+
default: "default";
|
|
15029
|
+
on: "on";
|
|
15030
|
+
off: "off";
|
|
15031
|
+
}>;
|
|
15032
|
+
serving: z.ZodNullable<z.ZodBoolean>;
|
|
15033
|
+
pending: z.ZodNullable<z.ZodEnum<{
|
|
15034
|
+
on: "on";
|
|
15035
|
+
off: "off";
|
|
15036
|
+
}>>;
|
|
15037
|
+
}, z.core.$strict>>;
|
|
14925
15038
|
}, z.core.$strict>>;
|
|
14926
15039
|
}, z.core.$strict>;
|
|
14927
15040
|
readonly AppsAccountsUsageParams: z.ZodObject<{
|
|
@@ -17089,8 +17202,8 @@ declare const NAMED_SCHEMAS: {
|
|
|
17089
17202
|
ws_path: z.ZodLiteral<"/v1/connect">;
|
|
17090
17203
|
device_id: z.ZodString;
|
|
17091
17204
|
browser_connection: z.ZodEnum<{
|
|
17092
|
-
off: "off";
|
|
17093
17205
|
on: "on";
|
|
17206
|
+
off: "off";
|
|
17094
17207
|
}>;
|
|
17095
17208
|
}, z.core.$strict>;
|
|
17096
17209
|
readonly BrowserPairRequest: z.ZodObject<{
|
|
@@ -18264,111 +18377,6 @@ type NamedSchemaId = keyof typeof NAMED_SCHEMAS;
|
|
|
18264
18377
|
* schema on both hops, so the two can never disagree.
|
|
18265
18378
|
*/
|
|
18266
18379
|
|
|
18267
|
-
/** The heavy runtime (inference packages) is installed on first use, never shipped in the app. */
|
|
18268
|
-
declare const MlRuntimeState: z.ZodEnum<{
|
|
18269
|
-
not_installed: "not_installed";
|
|
18270
|
-
installing: "installing";
|
|
18271
|
-
installed: "installed";
|
|
18272
|
-
failed: "failed";
|
|
18273
|
-
}>;
|
|
18274
|
-
/** `packages`: the locked inference wheels; `model`: one model's weights; `verifying`: hashes and a load test. */
|
|
18275
|
-
declare const MlInstallPhase: z.ZodEnum<{
|
|
18276
|
-
model: "model";
|
|
18277
|
-
packages: "packages";
|
|
18278
|
-
verifying: "verifying";
|
|
18279
|
-
}>;
|
|
18280
|
-
declare const MlInstallProgress: z.ZodObject<{
|
|
18281
|
-
phase: z.ZodEnum<{
|
|
18282
|
-
model: "model";
|
|
18283
|
-
packages: "packages";
|
|
18284
|
-
verifying: "verifying";
|
|
18285
|
-
}>;
|
|
18286
|
-
item: z.ZodString;
|
|
18287
|
-
bytes_done: z.ZodInt;
|
|
18288
|
-
bytes_total: z.ZodNullable<z.ZodInt>;
|
|
18289
|
-
}, z.core.$strict>;
|
|
18290
|
-
declare const TranscriptionModelInfo: z.ZodObject<{
|
|
18291
|
-
id: z.ZodString;
|
|
18292
|
-
size_bytes: z.ZodInt;
|
|
18293
|
-
multilingual: z.ZodBoolean;
|
|
18294
|
-
installed: z.ZodBoolean;
|
|
18295
|
-
}, z.core.$strict>;
|
|
18296
|
-
/** What the `ml` service itself reports (the core adds the supervisor's view in ModelsStatusResult). */
|
|
18297
|
-
declare const MlStatusParams: z.ZodObject<{}, z.core.$strict>;
|
|
18298
|
-
declare const TextModelInfo: z.ZodObject<{
|
|
18299
|
-
id: z.ZodString;
|
|
18300
|
-
size_bytes: z.ZodInt;
|
|
18301
|
-
installed: z.ZodBoolean;
|
|
18302
|
-
}, z.core.$strict>;
|
|
18303
|
-
/** The model server's process: one model loaded at a time. */
|
|
18304
|
-
declare const LlmServerState: z.ZodEnum<{
|
|
18305
|
-
running: "running";
|
|
18306
|
-
failed: "failed";
|
|
18307
|
-
stopped: "stopped";
|
|
18308
|
-
starting: "starting";
|
|
18309
|
-
}>;
|
|
18310
|
-
declare const ModelsLlmStatusParams: z.ZodObject<{}, z.core.$strict>;
|
|
18311
|
-
/** Download the model server program (if missing) and one model's weights. Progress: models.progress. */
|
|
18312
|
-
declare const ModelsLlmInstallParams: z.ZodObject<{
|
|
18313
|
-
model: z.ZodString;
|
|
18314
|
-
}, z.core.$strict>;
|
|
18315
|
-
declare const ModelsLlmInstallResult: z.ZodObject<{
|
|
18316
|
-
model: z.ZodString;
|
|
18317
|
-
elapsed_ms: z.ZodInt;
|
|
18318
|
-
}, z.core.$strict>;
|
|
18319
|
-
/** Load one downloaded model (stopping any other). Resolves once the server answers its health check. */
|
|
18320
|
-
declare const ModelsLlmStartParams: z.ZodObject<{
|
|
18321
|
-
model: z.ZodString;
|
|
18322
|
-
context_length: z.ZodOptional<z.ZodInt>;
|
|
18323
|
-
gpu_layers: z.ZodOptional<z.ZodInt>;
|
|
18324
|
-
threads: z.ZodOptional<z.ZodInt>;
|
|
18325
|
-
load_timeout_s: z.ZodOptional<z.ZodInt>;
|
|
18326
|
-
}, z.core.$strict>;
|
|
18327
|
-
declare const ModelsLlmStopParams: z.ZodObject<{}, z.core.$strict>;
|
|
18328
|
-
declare const ModelsLlmStopResult: z.ZodObject<{
|
|
18329
|
-
stopped: z.ZodBoolean;
|
|
18330
|
-
}, z.core.$strict>;
|
|
18331
|
-
declare const Sha256Hex: z.ZodString;
|
|
18332
|
-
declare const MlCatalogSetResult: z.ZodObject<{
|
|
18333
|
-
text: z.ZodInt;
|
|
18334
|
-
transcription: z.ZodInt;
|
|
18335
|
-
}, z.core.$strict>;
|
|
18336
|
-
/** What a download fetches: a speech model, a language model, or a runtime (speech runtime, model server program). */
|
|
18337
|
-
declare const DownloadKind: z.ZodEnum<{
|
|
18338
|
-
runtime: "runtime";
|
|
18339
|
-
speech_model: "speech_model";
|
|
18340
|
-
text_model: "text_model";
|
|
18341
|
-
}>;
|
|
18342
|
-
declare const ModelsDownloadsListParams: z.ZodObject<{}, z.core.$strict>;
|
|
18343
|
-
/** Cancel one running download (every caller waiting on it gets CANCELLED); its half-done file stays for Resume. */
|
|
18344
|
-
declare const ModelsDownloadsCancelParams: z.ZodObject<{
|
|
18345
|
-
key: z.ZodString;
|
|
18346
|
-
}, z.core.$strict>;
|
|
18347
|
-
declare const ModelsDownloadsCancelResult: z.ZodObject<{
|
|
18348
|
-
cancelled: z.ZodBoolean;
|
|
18349
|
-
}, z.core.$strict>;
|
|
18350
|
-
/** The supervisor's view of the `ml` service process. */
|
|
18351
|
-
declare const MlServiceState: z.ZodEnum<{
|
|
18352
|
-
failed: "failed";
|
|
18353
|
-
stopped: "stopped";
|
|
18354
|
-
starting: "starting";
|
|
18355
|
-
ready: "ready";
|
|
18356
|
-
restarting: "restarting";
|
|
18357
|
-
}>;
|
|
18358
|
-
declare const MlServiceStatus: z.ZodObject<{
|
|
18359
|
-
state: z.ZodEnum<{
|
|
18360
|
-
failed: "failed";
|
|
18361
|
-
stopped: "stopped";
|
|
18362
|
-
starting: "starting";
|
|
18363
|
-
ready: "ready";
|
|
18364
|
-
restarting: "restarting";
|
|
18365
|
-
}>;
|
|
18366
|
-
pid: z.ZodNullable<z.ZodInt>;
|
|
18367
|
-
restarts: z.ZodInt;
|
|
18368
|
-
python: z.ZodNullable<z.ZodString>;
|
|
18369
|
-
error: z.ZodNullable<z.ZodString>;
|
|
18370
|
-
}, z.core.$strict>;
|
|
18371
|
-
declare const ModelsStatusParams: z.ZodObject<{}, z.core.$strict>;
|
|
18372
18380
|
/** A Whisper model's catalog key (1.49: a string key; 1.48 sizes tiny/base/small/large-v3-turbo stay valid). */
|
|
18373
18381
|
declare const TranscriptionModelId: z.ZodString;
|
|
18374
18382
|
type TranscriptionModelId = z.output<typeof TranscriptionModelId>;
|
|
@@ -18724,5 +18732,132 @@ declare const TranscriptSegment: z.ZodObject<{
|
|
|
18724
18732
|
text: z.ZodString;
|
|
18725
18733
|
}, z.core.$strict>;
|
|
18726
18734
|
type TranscriptSegment = z.output<typeof TranscriptSegment>;
|
|
18735
|
+
/** The heavy runtime (inference packages) is installed on first use, never shipped in the app. */
|
|
18736
|
+
declare const MlRuntimeState: z.ZodEnum<{
|
|
18737
|
+
not_installed: "not_installed";
|
|
18738
|
+
installing: "installing";
|
|
18739
|
+
installed: "installed";
|
|
18740
|
+
failed: "failed";
|
|
18741
|
+
}>;
|
|
18742
|
+
type MlRuntimeState = z.output<typeof MlRuntimeState>;
|
|
18743
|
+
/** `packages`: the locked inference wheels; `model`: one model's weights; `verifying`: hashes and a load test. */
|
|
18744
|
+
declare const MlInstallPhase: z.ZodEnum<{
|
|
18745
|
+
model: "model";
|
|
18746
|
+
packages: "packages";
|
|
18747
|
+
verifying: "verifying";
|
|
18748
|
+
}>;
|
|
18749
|
+
type MlInstallPhase = z.output<typeof MlInstallPhase>;
|
|
18750
|
+
declare const MlInstallProgress: z.ZodObject<{
|
|
18751
|
+
phase: z.ZodEnum<{
|
|
18752
|
+
model: "model";
|
|
18753
|
+
packages: "packages";
|
|
18754
|
+
verifying: "verifying";
|
|
18755
|
+
}>;
|
|
18756
|
+
item: z.ZodString;
|
|
18757
|
+
bytes_done: z.ZodInt;
|
|
18758
|
+
bytes_total: z.ZodNullable<z.ZodInt>;
|
|
18759
|
+
}, z.core.$strict>;
|
|
18760
|
+
type MlInstallProgress = z.output<typeof MlInstallProgress>;
|
|
18761
|
+
declare const TranscriptionModelInfo: z.ZodObject<{
|
|
18762
|
+
id: z.ZodString;
|
|
18763
|
+
size_bytes: z.ZodInt;
|
|
18764
|
+
multilingual: z.ZodBoolean;
|
|
18765
|
+
installed: z.ZodBoolean;
|
|
18766
|
+
}, z.core.$strict>;
|
|
18767
|
+
type TranscriptionModelInfo = z.output<typeof TranscriptionModelInfo>;
|
|
18768
|
+
/** What the `ml` service itself reports (the core adds the supervisor's view in ModelsStatusResult). */
|
|
18769
|
+
declare const MlStatusParams: z.ZodObject<{}, z.core.$strict>;
|
|
18770
|
+
type MlStatusParams = z.output<typeof MlStatusParams>;
|
|
18771
|
+
declare const TextModelInfo: z.ZodObject<{
|
|
18772
|
+
id: z.ZodString;
|
|
18773
|
+
size_bytes: z.ZodInt;
|
|
18774
|
+
installed: z.ZodBoolean;
|
|
18775
|
+
}, z.core.$strict>;
|
|
18776
|
+
type TextModelInfo = z.output<typeof TextModelInfo>;
|
|
18777
|
+
/** The model server's process: one model loaded at a time. */
|
|
18778
|
+
declare const LlmServerState: z.ZodEnum<{
|
|
18779
|
+
running: "running";
|
|
18780
|
+
failed: "failed";
|
|
18781
|
+
stopped: "stopped";
|
|
18782
|
+
starting: "starting";
|
|
18783
|
+
}>;
|
|
18784
|
+
type LlmServerState = z.output<typeof LlmServerState>;
|
|
18785
|
+
declare const ModelsLlmStatusParams: z.ZodObject<{}, z.core.$strict>;
|
|
18786
|
+
type ModelsLlmStatusParams = z.output<typeof ModelsLlmStatusParams>;
|
|
18787
|
+
/** Download the model server program (if missing) and one model's weights. Progress: models.progress. */
|
|
18788
|
+
declare const ModelsLlmInstallParams: z.ZodObject<{
|
|
18789
|
+
model: z.ZodString;
|
|
18790
|
+
}, z.core.$strict>;
|
|
18791
|
+
type ModelsLlmInstallParams = z.output<typeof ModelsLlmInstallParams>;
|
|
18792
|
+
declare const ModelsLlmInstallResult: z.ZodObject<{
|
|
18793
|
+
model: z.ZodString;
|
|
18794
|
+
elapsed_ms: z.ZodInt;
|
|
18795
|
+
}, z.core.$strict>;
|
|
18796
|
+
type ModelsLlmInstallResult = z.output<typeof ModelsLlmInstallResult>;
|
|
18797
|
+
/** Load one downloaded model (stopping any other). Resolves once the server answers its health check. */
|
|
18798
|
+
declare const ModelsLlmStartParams: z.ZodObject<{
|
|
18799
|
+
model: z.ZodString;
|
|
18800
|
+
context_length: z.ZodOptional<z.ZodInt>;
|
|
18801
|
+
gpu_layers: z.ZodOptional<z.ZodInt>;
|
|
18802
|
+
threads: z.ZodOptional<z.ZodInt>;
|
|
18803
|
+
load_timeout_s: z.ZodOptional<z.ZodInt>;
|
|
18804
|
+
}, z.core.$strict>;
|
|
18805
|
+
type ModelsLlmStartParams = z.output<typeof ModelsLlmStartParams>;
|
|
18806
|
+
declare const ModelsLlmStopParams: z.ZodObject<{}, z.core.$strict>;
|
|
18807
|
+
type ModelsLlmStopParams = z.output<typeof ModelsLlmStopParams>;
|
|
18808
|
+
declare const ModelsLlmStopResult: z.ZodObject<{
|
|
18809
|
+
stopped: z.ZodBoolean;
|
|
18810
|
+
}, z.core.$strict>;
|
|
18811
|
+
type ModelsLlmStopResult = z.output<typeof ModelsLlmStopResult>;
|
|
18812
|
+
declare const Sha256Hex: z.ZodString;
|
|
18813
|
+
type Sha256Hex = z.output<typeof Sha256Hex>;
|
|
18814
|
+
declare const MlCatalogSetResult: z.ZodObject<{
|
|
18815
|
+
text: z.ZodInt;
|
|
18816
|
+
transcription: z.ZodInt;
|
|
18817
|
+
}, z.core.$strict>;
|
|
18818
|
+
type MlCatalogSetResult = z.output<typeof MlCatalogSetResult>;
|
|
18819
|
+
/** What a download fetches: a speech model, a language model, or a runtime (speech runtime, model server program). */
|
|
18820
|
+
declare const DownloadKind: z.ZodEnum<{
|
|
18821
|
+
runtime: "runtime";
|
|
18822
|
+
speech_model: "speech_model";
|
|
18823
|
+
text_model: "text_model";
|
|
18824
|
+
}>;
|
|
18825
|
+
type DownloadKind = z.output<typeof DownloadKind>;
|
|
18826
|
+
declare const ModelsDownloadsListParams: z.ZodObject<{}, z.core.$strict>;
|
|
18827
|
+
type ModelsDownloadsListParams = z.output<typeof ModelsDownloadsListParams>;
|
|
18828
|
+
/** Cancel one running download (every caller waiting on it gets CANCELLED); its half-done file stays for Resume. */
|
|
18829
|
+
declare const ModelsDownloadsCancelParams: z.ZodObject<{
|
|
18830
|
+
key: z.ZodString;
|
|
18831
|
+
}, z.core.$strict>;
|
|
18832
|
+
type ModelsDownloadsCancelParams = z.output<typeof ModelsDownloadsCancelParams>;
|
|
18833
|
+
declare const ModelsDownloadsCancelResult: z.ZodObject<{
|
|
18834
|
+
cancelled: z.ZodBoolean;
|
|
18835
|
+
}, z.core.$strict>;
|
|
18836
|
+
type ModelsDownloadsCancelResult = z.output<typeof ModelsDownloadsCancelResult>;
|
|
18837
|
+
/** The supervisor's view of the `ml` service process. */
|
|
18838
|
+
declare const MlServiceState: z.ZodEnum<{
|
|
18839
|
+
failed: "failed";
|
|
18840
|
+
stopped: "stopped";
|
|
18841
|
+
starting: "starting";
|
|
18842
|
+
ready: "ready";
|
|
18843
|
+
restarting: "restarting";
|
|
18844
|
+
}>;
|
|
18845
|
+
type MlServiceState = z.output<typeof MlServiceState>;
|
|
18846
|
+
declare const MlServiceStatus: z.ZodObject<{
|
|
18847
|
+
state: z.ZodEnum<{
|
|
18848
|
+
failed: "failed";
|
|
18849
|
+
stopped: "stopped";
|
|
18850
|
+
starting: "starting";
|
|
18851
|
+
ready: "ready";
|
|
18852
|
+
restarting: "restarting";
|
|
18853
|
+
}>;
|
|
18854
|
+
pid: z.ZodNullable<z.ZodInt>;
|
|
18855
|
+
restarts: z.ZodInt;
|
|
18856
|
+
python: z.ZodNullable<z.ZodString>;
|
|
18857
|
+
error: z.ZodNullable<z.ZodString>;
|
|
18858
|
+
}, z.core.$strict>;
|
|
18859
|
+
type MlServiceStatus = z.output<typeof MlServiceStatus>;
|
|
18860
|
+
declare const ModelsStatusParams: z.ZodObject<{}, z.core.$strict>;
|
|
18861
|
+
type ModelsStatusParams = z.output<typeof ModelsStatusParams>;
|
|
18727
18862
|
|
|
18728
18863
|
export { ModelKey as $, type ErrorReasonName as A, BEARER_PREFIX as B, type CloseOutcome as C, DesktopProtocolError as D, EndReason as E, EventMsg as F, type EventName as G, FsPatchEditFailure as H, HelloMsg as I, LlamaServerBuild as J, LlmRunning as K, Limits as L, ModelsTranscribeResult as M, LlmServerState as N, type OpName as O, MlCatalogSetParams as P, MlCatalogSetResult as Q, MlInstallPhase as R, StreamMeta as S, TranscriptionModelId as T, MlInstallProgress as U, MlRuntimeState as V, Welcome as W, MlServiceState as X, MlServiceStatus as Y, MlStatusParams as Z, MlStatusResult as _, type OpParams as a, ModelsDownloadsCancelParams as a0, ModelsDownloadsCancelResult as a1, ModelsDownloadsListParams as a2, ModelsDownloadsListResult as a3, ModelsInstallParams as a4, ModelsInstallResult as a5, ModelsLlmInstallParams as a6, ModelsLlmInstallResult as a7, ModelsLlmStartParams as a8, ModelsLlmStartResult as a9, TextModelId as aA, TextModelInfo as aB, TranscriptSegment as aC, TranscriptionModelInfo as aD, closeRule as aE, isTerminalClose as aF, ModelsLlmStatusParams as aa, ModelsLlmStatusResult as ab, ModelsLlmStopParams as ac, ModelsLlmStopResult as ad, ModelsProgressEvent as ae, ModelsStatusParams as af, ModelsStatusResult as ag, ModelsTranscribeParams as ah, NAMED_SCHEMAS as ai, type NamedSchemaId as aj, OpDescriptor as ak, type OpSpec as al, PING_TEXT as am, PONG_TEXT as an, ProtocolErrorBody as ao, RelayMsg as ap, RequestMsg as aq, ResponseMsg as ar, SERVICES as as, SUBPROTOCOL as at, type ServiceId as au, type ServiceOpName as av, type ServiceOpSpec as aw, type ServiceSpec as ax, Sha256Hex as ay, StreamMsg as az, type OpResult as b, OPS as c, EVENTS as d, ClientType as e, MlProgress as f, CLOSE_RULES as g, CancelMsg as h, isDesktopProtocolError as i, CatalogFile as j, CatalogModelEntry as k, ClientToCoreMsg as l, type CloseAction as m, CloseCode as n, CloseCodeValue as o, type CloseRule as p, CoreToClientMsg as q, CreditMsg as r, DownloadKind as s, DownloadRow as t, EndMsg as u, ErrorCode as v, type ErrorCodeName as w, type ErrorData as x, ErrorMsg as y, ErrorReason as z };
|
package/dist/react.cjs
CHANGED
|
@@ -111,6 +111,7 @@ function useDesktopConnection(client) {
|
|
|
111
111
|
}, [c]);
|
|
112
112
|
return state;
|
|
113
113
|
}
|
|
114
|
+
var FOCUS_CATCH_UP_MS = 5e3;
|
|
114
115
|
function useDesktopRequest(op, params, options = {}) {
|
|
115
116
|
const c = useDesktopClient(options.client);
|
|
116
117
|
const enabled = options.enabled ?? true;
|
|
@@ -171,11 +172,19 @@ function useDesktopRequest(op, params, options = {}) {
|
|
|
171
172
|
start();
|
|
172
173
|
} else stop();
|
|
173
174
|
};
|
|
175
|
+
let lastFocus = 0;
|
|
176
|
+
const onFocus = () => {
|
|
177
|
+
if (Date.now() - lastFocus < FOCUS_CATCH_UP_MS) return;
|
|
178
|
+
lastFocus = Date.now();
|
|
179
|
+
void run();
|
|
180
|
+
};
|
|
174
181
|
if (document.visibilityState === "visible") start();
|
|
175
182
|
document.addEventListener("visibilitychange", onVisibility);
|
|
183
|
+
window.addEventListener("focus", onFocus);
|
|
176
184
|
return () => {
|
|
177
185
|
stop();
|
|
178
186
|
document.removeEventListener("visibilitychange", onVisibility);
|
|
187
|
+
window.removeEventListener("focus", onFocus);
|
|
179
188
|
};
|
|
180
189
|
}, [enabled, refreshMs, run]);
|
|
181
190
|
const status = (0, import_react.useSyncExternalStore)(c.subscribe, () => c.getState().status, () => c.getState().status);
|
package/dist/react.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/react.ts","../src/client/wake.ts","../src/error.ts"],"sourcesContent":["/**\n * `@ai-matrx/desktop-protocol/react` — hooks over the client: provider, connection state, typed\n * one-shot requests, events. The client owns every hard part (reconnect, reattach, credits); these\n * hooks only bind it to React's lifecycle.\n */\nimport { createContext, createElement, useCallback, useContext, useEffect, useRef, useState, useSyncExternalStore } from \"react\";\nimport type { Context, ReactNode } from \"react\";\nimport type { DesktopClient, DesktopClientState, EventHandler, EventName, RequestOptions } from \"./client/types\";\nimport { bindDesktopWake } from \"./client/wake\";\nimport { DesktopProtocolError } from \"./error\";\nimport type { OpName, OpParams, OpResult } from \"./schema/registry\";\n\n// The context lives on globalThis: an ESM and a CJS copy of this entry in one app (Next.js\n// does this) would otherwise create two contexts and a provider the hooks cannot see.\nconst CONTEXT_SLOT = Symbol.for(\"ai-matrx.desktop-protocol.client-context\");\nfunction clientContext(): Context<DesktopClient | null> {\n const slot = globalThis as { [CONTEXT_SLOT]?: Context<DesktopClient | null> };\n return (slot[CONTEXT_SLOT] ??= createContext<DesktopClient | null>(null));\n}\n\nexport function DesktopClientProvider(props: { client: DesktopClient; children?: ReactNode }): ReactNode {\n return createElement(clientContext().Provider, { value: props.client }, props.children);\n}\n\n/** The client from the nearest provider (or the one passed in). Throws when there is neither. */\nexport function useDesktopClient(client?: DesktopClient): DesktopClient {\n const fromContext = useContext(clientContext());\n const resolved = client ?? fromContext;\n if (!resolved) throw new Error(\"useDesktopClient: wrap the tree in <DesktopClientProvider client={…}> or pass a client\");\n return resolved;\n}\n\n/** Live connection state (status, welcome, attempts, retryInMs, lastError). Connects on mount when idle. */\nexport function useDesktopConnection(client?: DesktopClient): DesktopClientState {\n const c = useDesktopClient(client);\n const state = useSyncExternalStore(c.subscribe, c.getState, c.getState);\n useEffect(() => {\n if (c.getState().status === \"idle\") c.connect();\n }, [c]);\n return state;\n}\n\nexport interface DesktopRequestState<N extends OpName> {\n data: OpResult<N> | undefined;\n error: DesktopProtocolError | undefined;\n loading: boolean;\n /** Re-run now; resolves with the fresh result. */\n refetch: () => Promise<OpResult<N> | undefined>;\n}\n\nexport interface UseDesktopRequestOptions extends Omit<RequestOptions, \"signal\"> {\n /** Default true. False = do not run until refetch() or enabled flips true. */\n enabled?: boolean;\n /** Re-run every `refreshMs` while the page is visible, and at once when it becomes visible\n * again. A hidden window never polls. Default: no refresh. */\n refreshMs?: number;\n client?: DesktopClient;\n}\n\n/**\n * Run a unary op and keep its latest result. Re-runs when `op` or the params' JSON changes, and\n * after a reconnect if the last attempt failed with a retryable error. Aborts on unmount.\n */\nexport function useDesktopRequest<N extends OpName>(op: N, params: OpParams<N>, options: UseDesktopRequestOptions = {}): DesktopRequestState<N> {\n const c = useDesktopClient(options.client);\n const enabled = options.enabled ?? true;\n const key = JSON.stringify(params);\n const [data, setData] = useState<OpResult<N> | undefined>(undefined);\n const [error, setError] = useState<DesktopProtocolError | undefined>(undefined);\n const [loading, setLoading] = useState<boolean>(enabled);\n const paramsRef = useRef(params);\n paramsRef.current = params;\n const runRef = useRef(0);\n const abortRef = useRef<AbortController | null>(null);\n const timeoutMs = options.timeoutMs;\n\n const run = useCallback(async (): Promise<OpResult<N> | undefined> => {\n const runId = ++runRef.current;\n abortRef.current?.abort();\n const abort = new AbortController();\n abortRef.current = abort;\n setLoading(true);\n try {\n const result = await c.request(op, paramsRef.current, timeoutMs === undefined ? { signal: abort.signal } : { signal: abort.signal, timeoutMs });\n if (runId === runRef.current) {\n setData(result);\n setError(undefined);\n }\n return result;\n } catch (caught) {\n const err = DesktopProtocolError.from(caught);\n if (runId === runRef.current && err.code !== \"CANCELLED\") setError(err);\n return undefined;\n } finally {\n if (runId === runRef.current) setLoading(false);\n }\n // `key` stands for the params' content: a new object with equal JSON is not a new request.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [c, op, key, timeoutMs]);\n\n useEffect(() => {\n if (!enabled) {\n setLoading(false);\n return;\n }\n void run();\n return () => {\n abortRef.current?.abort();\n };\n }, [enabled, run]);\n\n // Live data: poll while visible, catch up the moment the window is visible again.\n const refreshMs = options.refreshMs;\n useEffect(() => {\n if (!enabled || !refreshMs || typeof document === \"undefined\") return;\n let timer: ReturnType<typeof setInterval> | null = null;\n const start = () => {\n if (timer === null) timer = setInterval(() => void run(), refreshMs);\n };\n const stop = () => {\n if (timer !== null) clearInterval(timer);\n timer = null;\n };\n const onVisibility = () => {\n if (document.visibilityState === \"visible\") {\n void run();\n start();\n } else stop();\n };\n if (document.visibilityState === \"visible\") start();\n document.addEventListener(\"visibilitychange\", onVisibility);\n return () => {\n stop();\n document.removeEventListener(\"visibilitychange\", onVisibility);\n };\n }, [enabled, refreshMs, run]);\n\n // A retryable failure (device offline, connection lost) re-runs once the client is open again.\n const status = useSyncExternalStore(c.subscribe, () => c.getState().status, () => c.getState().status);\n useEffect(() => {\n if (enabled && status === \"open\" && error?.retryable) void run();\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [status]);\n\n return { data, error, loading, refetch: run };\n}\n\nexport interface DesktopActionState {\n /** Run one or more ops as one action; resolves true when it finished without an error. */\n run: (work: (client: DesktopClient) => Promise<unknown>) => Promise<boolean>;\n /** An action is in flight (disable its controls). */\n busy: boolean;\n /** The last action's error, until the next action or `clearError()`. */\n error: DesktopProtocolError | undefined;\n clearError: () => void;\n}\n\n/**\n * Actions (create, save, remove, open): one busy flag and one error for a screen's writes, with the\n * same error type as reads. `onDone` runs after every successful action (refetch what it changed).\n */\nexport function useDesktopAction(options: { client?: DesktopClient; onDone?: () => unknown } = {}): DesktopActionState {\n const c = useDesktopClient(options.client);\n const [busy, setBusy] = useState(false);\n const [error, setError] = useState<DesktopProtocolError | undefined>(undefined);\n const onDoneRef = useRef(options.onDone);\n onDoneRef.current = options.onDone;\n const run = useCallback(\n async (work: (client: DesktopClient) => Promise<unknown>): Promise<boolean> => {\n setBusy(true);\n setError(undefined);\n try {\n await work(c);\n await onDoneRef.current?.();\n return true;\n } catch (caught) {\n const err = DesktopProtocolError.from(caught);\n // A cancelled action (the person pressed Stop) is not a failure to show.\n if (err.code !== \"CANCELLED\") setError(err);\n return false;\n } finally {\n setBusy(false);\n }\n },\n [c],\n );\n const clearError = useCallback(() => setError(undefined), []);\n return { run, busy, error, clearError };\n}\n\n/** Subscribe to one protocol event (fs.changed, exec.exited, relay.device_status, …) for the component's life. */\nexport function useDesktopEvent<E extends EventName>(name: E, handler: EventHandler<E>, options: { client?: DesktopClient } = {}): void {\n const c = useDesktopClient(options.client);\n const handlerRef = useRef(handler);\n handlerRef.current = handler;\n useEffect(() => c.on(name, ((payload, resourceId) => handlerRef.current(payload, resourceId)) as EventHandler<E>), [c, name]);\n}\n\n/**\n * Reconnect the moment the person is back: page visible again, a bfcache restore, the network\n * returning, window focus. Each calls `client.wake()` — dial now if reconnecting, probe if open.\n */\nexport function useDesktopWake(client?: DesktopClient, options: { probeMs?: number } = {}): void {\n const c = useDesktopClient(client);\n const probeMs = options.probeMs;\n useEffect(() => bindDesktopWake(c, probeMs === undefined ? {} : { probeMs }), [c, probeMs]);\n}\n","/**\n * Wire a client's wake() to the browser events that mean \"the person is back\": the page becomes\n * visible again (iOS Safari suspends a background tab's sockets), a back/forward-cache restore\n * (`pageshow` with persisted), and the network returning (`online`). Framework-free; the React\n * binding is `useDesktopWake` in `./react`.\n */\nimport type { DesktopClient, WakeOptions } from \"./types\";\n\n/** The subset of window/document the binding listens on — injectable for tests and non-DOM hosts. */\nexport interface WakeTargets {\n window: Pick<Window, \"addEventListener\" | \"removeEventListener\">;\n document: Pick<Document, \"addEventListener\" | \"removeEventListener\" | \"visibilityState\">;\n}\n\nexport function bindDesktopWake(client: Pick<DesktopClient, \"wake\">, options: WakeOptions & { targets?: WakeTargets } = {}): () => void {\n const targets: WakeTargets | null =\n options.targets ?? (typeof window !== \"undefined\" && typeof document !== \"undefined\" ? { window, document } : null);\n if (!targets) return () => undefined;\n const wakeOptions: WakeOptions = options.probeMs === undefined ? {} : { probeMs: options.probeMs };\n const onVisibility = () => {\n if (targets.document.visibilityState === \"visible\") client.wake(wakeOptions);\n };\n const onWake = () => client.wake(wakeOptions);\n targets.document.addEventListener(\"visibilitychange\", onVisibility);\n targets.window.addEventListener(\"pageshow\", onWake);\n targets.window.addEventListener(\"online\", onWake);\n targets.window.addEventListener(\"focus\", onWake);\n return () => {\n targets.document.removeEventListener(\"visibilitychange\", onVisibility);\n targets.window.removeEventListener(\"pageshow\", onWake);\n targets.window.removeEventListener(\"online\", onWake);\n targets.window.removeEventListener(\"focus\", onWake);\n };\n}\n","/**\n * The one error type every package entry throws. It carries the wire ErrorCode (SPEC §5), so a\n * caller branches on `code`/`retryable`/`data.reason` and never parses a message. Zod-free on\n * purpose: `./frame` (the relay hot path) throws it without pulling the schema graph.\n */\nimport type { ErrorCodeName, ErrorData } from \"./types\";\n\nexport class DesktopProtocolError extends Error {\n readonly code: ErrorCodeName;\n readonly retryable: boolean;\n readonly data: ErrorData | undefined;\n\n constructor(code: ErrorCodeName, message: string, options: { retryable?: boolean; data?: ErrorData; cause?: unknown } = {}) {\n super(message, options.cause === undefined ? undefined : { cause: options.cause });\n this.name = \"DesktopProtocolError\";\n this.code = code;\n this.retryable = options.retryable ?? false;\n this.data = options.data;\n }\n\n /**\n * Any thrown value as a DesktopProtocolError, keeping its code, message and data. Each built entry\n * (`.`, `./client`, `./react`) carries its own copy of this class, so `instanceof` alone misses an\n * error thrown by a sibling entry and reports a real NOT_FOUND as INTERNAL; this checks the shape.\n */\n static from(caught: unknown): DesktopProtocolError {\n if (caught instanceof DesktopProtocolError) return caught;\n const e = caught as { name?: unknown; code?: unknown; message?: unknown; retryable?: unknown; data?: unknown } | null;\n if (e && typeof e === \"object\" && e.name === \"DesktopProtocolError\" && typeof e.code === \"string\") {\n return new DesktopProtocolError(e.code as ErrorCodeName, typeof e.message === \"string\" ? e.message : String(e.code), {\n retryable: e.retryable === true,\n ...(e.data && typeof e.data === \"object\" ? { data: e.data as ErrorData } : {}),\n cause: caught,\n });\n }\n return new DesktopProtocolError(\"INTERNAL\", caught instanceof Error ? caught.message : String(caught), { cause: caught });\n }\n\n /** The wire body (ProtocolErrorBody) — what a core or relay sends for this error. */\n toBody(): { code: ErrorCodeName; message: string; retryable: boolean; data?: ErrorData } {\n return this.data === undefined\n ? { code: this.code, message: this.message, retryable: this.retryable }\n : { code: this.code, message: this.message, retryable: this.retryable, data: this.data };\n }\n}\n\nexport function isDesktopProtocolError(value: unknown): value is DesktopProtocolError {\n return value instanceof DesktopProtocolError || (value instanceof Error && value.name === \"DesktopProtocolError\" && \"code\" in value);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAKA,mBAAyH;;;ACSlH,SAAS,gBAAgB,QAAqC,UAAmD,CAAC,GAAe;AACtI,QAAM,UACJ,QAAQ,YAAY,OAAO,WAAW,eAAe,OAAO,aAAa,cAAc,EAAE,QAAQ,SAAS,IAAI;AAChH,MAAI,CAAC,QAAS,QAAO,MAAM;AAC3B,QAAM,cAA2B,QAAQ,YAAY,SAAY,CAAC,IAAI,EAAE,SAAS,QAAQ,QAAQ;AACjG,QAAM,eAAe,MAAM;AACzB,QAAI,QAAQ,SAAS,oBAAoB,UAAW,QAAO,KAAK,WAAW;AAAA,EAC7E;AACA,QAAM,SAAS,MAAM,OAAO,KAAK,WAAW;AAC5C,UAAQ,SAAS,iBAAiB,oBAAoB,YAAY;AAClE,UAAQ,OAAO,iBAAiB,YAAY,MAAM;AAClD,UAAQ,OAAO,iBAAiB,UAAU,MAAM;AAChD,UAAQ,OAAO,iBAAiB,SAAS,MAAM;AAC/C,SAAO,MAAM;AACX,YAAQ,SAAS,oBAAoB,oBAAoB,YAAY;AACrE,YAAQ,OAAO,oBAAoB,YAAY,MAAM;AACrD,YAAQ,OAAO,oBAAoB,UAAU,MAAM;AACnD,YAAQ,OAAO,oBAAoB,SAAS,MAAM;AAAA,EACpD;AACF;;;AC1BO,IAAM,uBAAN,MAAM,8BAA6B,MA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Ae,QAAwB,UAAgC,CAAC,GAAS;AAC/F,QAAM,IAAI,iBAAiB,MAAM;AACjC,QAAM,UAAU,QAAQ;AACxB,8BAAU,MAAM,gBAAgB,GAAG,YAAY,SAAY,CAAC,IAAI,EAAE,QAAQ,CAAC,GAAG,CAAC,GAAG,OAAO,CAAC;AAC5F;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/react.ts","../src/client/wake.ts","../src/error.ts"],"sourcesContent":["/**\n * `@ai-matrx/desktop-protocol/react` — hooks over the client: provider, connection state, typed\n * one-shot requests, events. The client owns every hard part (reconnect, reattach, credits); these\n * hooks only bind it to React's lifecycle.\n */\nimport { createContext, createElement, useCallback, useContext, useEffect, useRef, useState, useSyncExternalStore } from \"react\";\nimport type { Context, ReactNode } from \"react\";\nimport type { DesktopClient, DesktopClientState, EventHandler, EventName, RequestOptions } from \"./client/types\";\nimport { bindDesktopWake } from \"./client/wake\";\nimport { DesktopProtocolError } from \"./error\";\nimport type { OpName, OpParams, OpResult } from \"./schema/registry\";\n\n// The context lives on globalThis: an ESM and a CJS copy of this entry in one app (Next.js\n// does this) would otherwise create two contexts and a provider the hooks cannot see.\nconst CONTEXT_SLOT = Symbol.for(\"ai-matrx.desktop-protocol.client-context\");\nfunction clientContext(): Context<DesktopClient | null> {\n const slot = globalThis as { [CONTEXT_SLOT]?: Context<DesktopClient | null> };\n return (slot[CONTEXT_SLOT] ??= createContext<DesktopClient | null>(null));\n}\n\nexport function DesktopClientProvider(props: { client: DesktopClient; children?: ReactNode }): ReactNode {\n return createElement(clientContext().Provider, { value: props.client }, props.children);\n}\n\n/** The client from the nearest provider (or the one passed in). Throws when there is neither. */\nexport function useDesktopClient(client?: DesktopClient): DesktopClient {\n const fromContext = useContext(clientContext());\n const resolved = client ?? fromContext;\n if (!resolved) throw new Error(\"useDesktopClient: wrap the tree in <DesktopClientProvider client={…}> or pass a client\");\n return resolved;\n}\n\n/** Live connection state (status, welcome, attempts, retryInMs, lastError). Connects on mount when idle. */\nexport function useDesktopConnection(client?: DesktopClient): DesktopClientState {\n const c = useDesktopClient(client);\n const state = useSyncExternalStore(c.subscribe, c.getState, c.getState);\n useEffect(() => {\n if (c.getState().status === \"idle\") c.connect();\n }, [c]);\n return state;\n}\n\nexport interface DesktopRequestState<N extends OpName> {\n data: OpResult<N> | undefined;\n error: DesktopProtocolError | undefined;\n loading: boolean;\n /** Re-run now; resolves with the fresh result. */\n refetch: () => Promise<OpResult<N> | undefined>;\n}\n\nexport interface UseDesktopRequestOptions extends Omit<RequestOptions, \"signal\"> {\n /** Default true. False = do not run until refetch() or enabled flips true. */\n enabled?: boolean;\n /** Re-run every `refreshMs` while the page is visible, and at once when it becomes visible\n * again or its window comes to the front. A hidden window never polls. Default: no refresh. */\n refreshMs?: number;\n client?: DesktopClient;\n}\n\n/**\n * Run a unary op and keep its latest result. Re-runs when `op` or the params' JSON changes, and\n * after a reconnect if the last attempt failed with a retryable error. Aborts on unmount.\n */\n/** A window focused again within this long of the last catch-up is not read again. */\nconst FOCUS_CATCH_UP_MS = 5_000;\n\nexport function useDesktopRequest<N extends OpName>(op: N, params: OpParams<N>, options: UseDesktopRequestOptions = {}): DesktopRequestState<N> {\n const c = useDesktopClient(options.client);\n const enabled = options.enabled ?? true;\n const key = JSON.stringify(params);\n const [data, setData] = useState<OpResult<N> | undefined>(undefined);\n const [error, setError] = useState<DesktopProtocolError | undefined>(undefined);\n const [loading, setLoading] = useState<boolean>(enabled);\n const paramsRef = useRef(params);\n paramsRef.current = params;\n const runRef = useRef(0);\n const abortRef = useRef<AbortController | null>(null);\n const timeoutMs = options.timeoutMs;\n\n const run = useCallback(async (): Promise<OpResult<N> | undefined> => {\n const runId = ++runRef.current;\n abortRef.current?.abort();\n const abort = new AbortController();\n abortRef.current = abort;\n setLoading(true);\n try {\n const result = await c.request(op, paramsRef.current, timeoutMs === undefined ? { signal: abort.signal } : { signal: abort.signal, timeoutMs });\n if (runId === runRef.current) {\n setData(result);\n setError(undefined);\n }\n return result;\n } catch (caught) {\n const err = DesktopProtocolError.from(caught);\n if (runId === runRef.current && err.code !== \"CANCELLED\") setError(err);\n return undefined;\n } finally {\n if (runId === runRef.current) setLoading(false);\n }\n // `key` stands for the params' content: a new object with equal JSON is not a new request.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [c, op, key, timeoutMs]);\n\n useEffect(() => {\n if (!enabled) {\n setLoading(false);\n return;\n }\n void run();\n return () => {\n abortRef.current?.abort();\n };\n }, [enabled, run]);\n\n // Live data: poll while visible, catch up the moment the window is visible again.\n const refreshMs = options.refreshMs;\n useEffect(() => {\n if (!enabled || !refreshMs || typeof document === \"undefined\") return;\n let timer: ReturnType<typeof setInterval> | null = null;\n const start = () => {\n if (timer === null) timer = setInterval(() => void run(), refreshMs);\n };\n const stop = () => {\n if (timer !== null) clearInterval(timer);\n timer = null;\n };\n const onVisibility = () => {\n if (document.visibilityState === \"visible\") {\n void run();\n start();\n } else stop();\n };\n // The window coming to the front again (a desktop app switched back to): catch up at once,\n // at most once every few seconds (a quick switch away and back is not two reads).\n let lastFocus = 0;\n const onFocus = () => {\n if (Date.now() - lastFocus < FOCUS_CATCH_UP_MS) return;\n lastFocus = Date.now();\n void run();\n };\n if (document.visibilityState === \"visible\") start();\n document.addEventListener(\"visibilitychange\", onVisibility);\n window.addEventListener(\"focus\", onFocus);\n return () => {\n stop();\n document.removeEventListener(\"visibilitychange\", onVisibility);\n window.removeEventListener(\"focus\", onFocus);\n };\n }, [enabled, refreshMs, run]);\n\n // A retryable failure (device offline, connection lost) re-runs once the client is open again.\n const status = useSyncExternalStore(c.subscribe, () => c.getState().status, () => c.getState().status);\n useEffect(() => {\n if (enabled && status === \"open\" && error?.retryable) void run();\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [status]);\n\n return { data, error, loading, refetch: run };\n}\n\nexport interface DesktopActionState {\n /** Run one or more ops as one action; resolves true when it finished without an error. */\n run: (work: (client: DesktopClient) => Promise<unknown>) => Promise<boolean>;\n /** An action is in flight (disable its controls). */\n busy: boolean;\n /** The last action's error, until the next action or `clearError()`. */\n error: DesktopProtocolError | undefined;\n clearError: () => void;\n}\n\n/**\n * Actions (create, save, remove, open): one busy flag and one error for a screen's writes, with the\n * same error type as reads. `onDone` runs after every successful action (refetch what it changed).\n */\nexport function useDesktopAction(options: { client?: DesktopClient; onDone?: () => unknown } = {}): DesktopActionState {\n const c = useDesktopClient(options.client);\n const [busy, setBusy] = useState(false);\n const [error, setError] = useState<DesktopProtocolError | undefined>(undefined);\n const onDoneRef = useRef(options.onDone);\n onDoneRef.current = options.onDone;\n const run = useCallback(\n async (work: (client: DesktopClient) => Promise<unknown>): Promise<boolean> => {\n setBusy(true);\n setError(undefined);\n try {\n await work(c);\n await onDoneRef.current?.();\n return true;\n } catch (caught) {\n const err = DesktopProtocolError.from(caught);\n // A cancelled action (the person pressed Stop) is not a failure to show.\n if (err.code !== \"CANCELLED\") setError(err);\n return false;\n } finally {\n setBusy(false);\n }\n },\n [c],\n );\n const clearError = useCallback(() => setError(undefined), []);\n return { run, busy, error, clearError };\n}\n\n/** Subscribe to one protocol event (fs.changed, exec.exited, relay.device_status, …) for the component's life. */\nexport function useDesktopEvent<E extends EventName>(name: E, handler: EventHandler<E>, options: { client?: DesktopClient } = {}): void {\n const c = useDesktopClient(options.client);\n const handlerRef = useRef(handler);\n handlerRef.current = handler;\n useEffect(() => c.on(name, ((payload, resourceId) => handlerRef.current(payload, resourceId)) as EventHandler<E>), [c, name]);\n}\n\n/**\n * Reconnect the moment the person is back: page visible again, a bfcache restore, the network\n * returning, window focus. Each calls `client.wake()` — dial now if reconnecting, probe if open.\n */\nexport function useDesktopWake(client?: DesktopClient, options: { probeMs?: number } = {}): void {\n const c = useDesktopClient(client);\n const probeMs = options.probeMs;\n useEffect(() => bindDesktopWake(c, probeMs === undefined ? {} : { probeMs }), [c, probeMs]);\n}\n","/**\n * Wire a client's wake() to the browser events that mean \"the person is back\": the page becomes\n * visible again (iOS Safari suspends a background tab's sockets), a back/forward-cache restore\n * (`pageshow` with persisted), and the network returning (`online`). Framework-free; the React\n * binding is `useDesktopWake` in `./react`.\n */\nimport type { DesktopClient, WakeOptions } from \"./types\";\n\n/** The subset of window/document the binding listens on — injectable for tests and non-DOM hosts. */\nexport interface WakeTargets {\n window: Pick<Window, \"addEventListener\" | \"removeEventListener\">;\n document: Pick<Document, \"addEventListener\" | \"removeEventListener\" | \"visibilityState\">;\n}\n\nexport function bindDesktopWake(client: Pick<DesktopClient, \"wake\">, options: WakeOptions & { targets?: WakeTargets } = {}): () => void {\n const targets: WakeTargets | null =\n options.targets ?? (typeof window !== \"undefined\" && typeof document !== \"undefined\" ? { window, document } : null);\n if (!targets) return () => undefined;\n const wakeOptions: WakeOptions = options.probeMs === undefined ? {} : { probeMs: options.probeMs };\n const onVisibility = () => {\n if (targets.document.visibilityState === \"visible\") client.wake(wakeOptions);\n };\n const onWake = () => client.wake(wakeOptions);\n targets.document.addEventListener(\"visibilitychange\", onVisibility);\n targets.window.addEventListener(\"pageshow\", onWake);\n targets.window.addEventListener(\"online\", onWake);\n targets.window.addEventListener(\"focus\", onWake);\n return () => {\n targets.document.removeEventListener(\"visibilitychange\", onVisibility);\n targets.window.removeEventListener(\"pageshow\", onWake);\n targets.window.removeEventListener(\"online\", onWake);\n targets.window.removeEventListener(\"focus\", onWake);\n };\n}\n","/**\n * The one error type every package entry throws. It carries the wire ErrorCode (SPEC §5), so a\n * caller branches on `code`/`retryable`/`data.reason` and never parses a message. Zod-free on\n * purpose: `./frame` (the relay hot path) throws it without pulling the schema graph.\n */\nimport type { ErrorCodeName, ErrorData } from \"./types\";\n\nexport class DesktopProtocolError extends Error {\n readonly code: ErrorCodeName;\n readonly retryable: boolean;\n readonly data: ErrorData | undefined;\n\n constructor(code: ErrorCodeName, message: string, options: { retryable?: boolean; data?: ErrorData; cause?: unknown } = {}) {\n super(message, options.cause === undefined ? undefined : { cause: options.cause });\n this.name = \"DesktopProtocolError\";\n this.code = code;\n this.retryable = options.retryable ?? false;\n this.data = options.data;\n }\n\n /**\n * Any thrown value as a DesktopProtocolError, keeping its code, message and data. Each built entry\n * (`.`, `./client`, `./react`) carries its own copy of this class, so `instanceof` alone misses an\n * error thrown by a sibling entry and reports a real NOT_FOUND as INTERNAL; this checks the shape.\n */\n static from(caught: unknown): DesktopProtocolError {\n if (caught instanceof DesktopProtocolError) return caught;\n const e = caught as { name?: unknown; code?: unknown; message?: unknown; retryable?: unknown; data?: unknown } | null;\n if (e && typeof e === \"object\" && e.name === \"DesktopProtocolError\" && typeof e.code === \"string\") {\n return new DesktopProtocolError(e.code as ErrorCodeName, typeof e.message === \"string\" ? e.message : String(e.code), {\n retryable: e.retryable === true,\n ...(e.data && typeof e.data === \"object\" ? { data: e.data as ErrorData } : {}),\n cause: caught,\n });\n }\n return new DesktopProtocolError(\"INTERNAL\", caught instanceof Error ? caught.message : String(caught), { cause: caught });\n }\n\n /** The wire body (ProtocolErrorBody) — what a core or relay sends for this error. */\n toBody(): { code: ErrorCodeName; message: string; retryable: boolean; data?: ErrorData } {\n return this.data === undefined\n ? { code: this.code, message: this.message, retryable: this.retryable }\n : { code: this.code, message: this.message, retryable: this.retryable, data: this.data };\n }\n}\n\nexport function isDesktopProtocolError(value: unknown): value is DesktopProtocolError {\n return value instanceof DesktopProtocolError || (value instanceof Error && value.name === \"DesktopProtocolError\" && \"code\" in value);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAKA,mBAAyH;;;ACSlH,SAAS,gBAAgB,QAAqC,UAAmD,CAAC,GAAe;AACtI,QAAM,UACJ,QAAQ,YAAY,OAAO,WAAW,eAAe,OAAO,aAAa,cAAc,EAAE,QAAQ,SAAS,IAAI;AAChH,MAAI,CAAC,QAAS,QAAO,MAAM;AAC3B,QAAM,cAA2B,QAAQ,YAAY,SAAY,CAAC,IAAI,EAAE,SAAS,QAAQ,QAAQ;AACjG,QAAM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