@ai-matrx/desktop-protocol 0.17.1 → 0.17.3
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 +23 -0
- package/dist/client.cjs +28 -3
- package/dist/client.cjs.map +1 -1
- package/dist/client.d.cts +2 -2
- package/dist/client.d.ts +2 -2
- package/dist/client.js +28 -3
- package/dist/client.js.map +1 -1
- package/dist/frame.cjs +18 -1
- package/dist/frame.cjs.map +1 -1
- package/dist/frame.js +18 -1
- package/dist/frame.js.map +1 -1
- package/dist/index.cjs +52 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +19 -6
- package/dist/index.d.ts +19 -6
- package/dist/index.js +52 -6
- package/dist/index.js.map +1 -1
- package/dist/{models-Dj_B9wHj.d.cts → models-BiquRLLO.d.cts} +22 -2
- package/dist/{models-Dj_B9wHj.d.ts → models-BiquRLLO.d.ts} +22 -2
- package/dist/react.cjs +21 -3
- package/dist/react.cjs.map +1 -1
- package/dist/react.d.cts +12 -0
- package/dist/react.d.ts +12 -0
- package/dist/react.js +21 -3
- package/dist/react.js.map +1 -1
- package/generated/desktop-protocol.schema.json +14 -1
- package/package.json +1 -1
|
@@ -127,6 +127,12 @@ declare class DesktopProtocolError extends Error {
|
|
|
127
127
|
data?: ErrorData;
|
|
128
128
|
cause?: unknown;
|
|
129
129
|
});
|
|
130
|
+
/**
|
|
131
|
+
* Any thrown value as a DesktopProtocolError, keeping its code, message and data. Each built entry
|
|
132
|
+
* (`.`, `./client`, `./react`) carries its own copy of this class, so `instanceof` alone misses an
|
|
133
|
+
* error thrown by a sibling entry and reports a real NOT_FOUND as INTERNAL; this checks the shape.
|
|
134
|
+
*/
|
|
135
|
+
static from(caught: unknown): DesktopProtocolError;
|
|
130
136
|
/** The wire body (ProtocolErrorBody) — what a core or relay sends for this error. */
|
|
131
137
|
toBody(): {
|
|
132
138
|
code: ErrorCodeName;
|
|
@@ -765,8 +771,8 @@ declare const OPS: {
|
|
|
765
771
|
page_token: z.ZodOptional<z.ZodString>;
|
|
766
772
|
show_hidden: z.ZodDefault<z.ZodBoolean>;
|
|
767
773
|
sort: z.ZodDefault<z.ZodEnum<{
|
|
768
|
-
kind: "kind";
|
|
769
774
|
name: "name";
|
|
775
|
+
kind: "kind";
|
|
770
776
|
size: "size";
|
|
771
777
|
mtime: "mtime";
|
|
772
778
|
}>>;
|
|
@@ -1865,6 +1871,8 @@ declare const OPS: {
|
|
|
1865
1871
|
y: z.ZodInt;
|
|
1866
1872
|
width: z.ZodInt;
|
|
1867
1873
|
height: z.ZodInt;
|
|
1874
|
+
app: z.ZodOptional<z.ZodString>;
|
|
1875
|
+
pid: z.ZodOptional<z.ZodInt>;
|
|
1868
1876
|
}, z.core.$strict>>;
|
|
1869
1877
|
total: z.ZodInt;
|
|
1870
1878
|
truncated: z.ZodBoolean;
|
|
@@ -1885,6 +1893,8 @@ declare const OPS: {
|
|
|
1885
1893
|
y: z.ZodInt;
|
|
1886
1894
|
width: z.ZodInt;
|
|
1887
1895
|
height: z.ZodInt;
|
|
1896
|
+
app: z.ZodOptional<z.ZodString>;
|
|
1897
|
+
pid: z.ZodOptional<z.ZodInt>;
|
|
1888
1898
|
}, z.core.$strict>;
|
|
1889
1899
|
}, z.core.$strict>;
|
|
1890
1900
|
readonly kind: "unary";
|
|
@@ -1907,6 +1917,8 @@ declare const OPS: {
|
|
|
1907
1917
|
y: z.ZodInt;
|
|
1908
1918
|
width: z.ZodInt;
|
|
1909
1919
|
height: z.ZodInt;
|
|
1920
|
+
app: z.ZodOptional<z.ZodString>;
|
|
1921
|
+
pid: z.ZodOptional<z.ZodInt>;
|
|
1910
1922
|
}, z.core.$strict>;
|
|
1911
1923
|
}, z.core.$strict>;
|
|
1912
1924
|
readonly kind: "unary";
|
|
@@ -3206,8 +3218,8 @@ declare const NAMED_SCHEMAS: {
|
|
|
3206
3218
|
page_token: z.ZodOptional<z.ZodString>;
|
|
3207
3219
|
show_hidden: z.ZodDefault<z.ZodBoolean>;
|
|
3208
3220
|
sort: z.ZodDefault<z.ZodEnum<{
|
|
3209
|
-
kind: "kind";
|
|
3210
3221
|
name: "name";
|
|
3222
|
+
kind: "kind";
|
|
3211
3223
|
size: "size";
|
|
3212
3224
|
mtime: "mtime";
|
|
3213
3225
|
}>>;
|
|
@@ -4607,6 +4619,8 @@ declare const NAMED_SCHEMAS: {
|
|
|
4607
4619
|
y: z.ZodInt;
|
|
4608
4620
|
width: z.ZodInt;
|
|
4609
4621
|
height: z.ZodInt;
|
|
4622
|
+
app: z.ZodOptional<z.ZodString>;
|
|
4623
|
+
pid: z.ZodOptional<z.ZodInt>;
|
|
4610
4624
|
}, z.core.$strict>;
|
|
4611
4625
|
readonly WindowListParams: z.ZodObject<{
|
|
4612
4626
|
title: z.ZodOptional<z.ZodString>;
|
|
@@ -4620,6 +4634,8 @@ declare const NAMED_SCHEMAS: {
|
|
|
4620
4634
|
y: z.ZodInt;
|
|
4621
4635
|
width: z.ZodInt;
|
|
4622
4636
|
height: z.ZodInt;
|
|
4637
|
+
app: z.ZodOptional<z.ZodString>;
|
|
4638
|
+
pid: z.ZodOptional<z.ZodInt>;
|
|
4623
4639
|
}, z.core.$strict>>;
|
|
4624
4640
|
total: z.ZodInt;
|
|
4625
4641
|
truncated: z.ZodBoolean;
|
|
@@ -4635,6 +4651,8 @@ declare const NAMED_SCHEMAS: {
|
|
|
4635
4651
|
y: z.ZodInt;
|
|
4636
4652
|
width: z.ZodInt;
|
|
4637
4653
|
height: z.ZodInt;
|
|
4654
|
+
app: z.ZodOptional<z.ZodString>;
|
|
4655
|
+
pid: z.ZodOptional<z.ZodInt>;
|
|
4638
4656
|
}, z.core.$strict>;
|
|
4639
4657
|
}, z.core.$strict>;
|
|
4640
4658
|
readonly WindowMoveParams: z.ZodObject<{
|
|
@@ -4652,6 +4670,8 @@ declare const NAMED_SCHEMAS: {
|
|
|
4652
4670
|
y: z.ZodInt;
|
|
4653
4671
|
width: z.ZodInt;
|
|
4654
4672
|
height: z.ZodInt;
|
|
4673
|
+
app: z.ZodOptional<z.ZodString>;
|
|
4674
|
+
pid: z.ZodOptional<z.ZodInt>;
|
|
4655
4675
|
}, z.core.$strict>;
|
|
4656
4676
|
}, z.core.$strict>;
|
|
4657
4677
|
readonly WindowMinimizeParams: z.ZodObject<{
|
|
@@ -127,6 +127,12 @@ declare class DesktopProtocolError extends Error {
|
|
|
127
127
|
data?: ErrorData;
|
|
128
128
|
cause?: unknown;
|
|
129
129
|
});
|
|
130
|
+
/**
|
|
131
|
+
* Any thrown value as a DesktopProtocolError, keeping its code, message and data. Each built entry
|
|
132
|
+
* (`.`, `./client`, `./react`) carries its own copy of this class, so `instanceof` alone misses an
|
|
133
|
+
* error thrown by a sibling entry and reports a real NOT_FOUND as INTERNAL; this checks the shape.
|
|
134
|
+
*/
|
|
135
|
+
static from(caught: unknown): DesktopProtocolError;
|
|
130
136
|
/** The wire body (ProtocolErrorBody) — what a core or relay sends for this error. */
|
|
131
137
|
toBody(): {
|
|
132
138
|
code: ErrorCodeName;
|
|
@@ -765,8 +771,8 @@ declare const OPS: {
|
|
|
765
771
|
page_token: z.ZodOptional<z.ZodString>;
|
|
766
772
|
show_hidden: z.ZodDefault<z.ZodBoolean>;
|
|
767
773
|
sort: z.ZodDefault<z.ZodEnum<{
|
|
768
|
-
kind: "kind";
|
|
769
774
|
name: "name";
|
|
775
|
+
kind: "kind";
|
|
770
776
|
size: "size";
|
|
771
777
|
mtime: "mtime";
|
|
772
778
|
}>>;
|
|
@@ -1865,6 +1871,8 @@ declare const OPS: {
|
|
|
1865
1871
|
y: z.ZodInt;
|
|
1866
1872
|
width: z.ZodInt;
|
|
1867
1873
|
height: z.ZodInt;
|
|
1874
|
+
app: z.ZodOptional<z.ZodString>;
|
|
1875
|
+
pid: z.ZodOptional<z.ZodInt>;
|
|
1868
1876
|
}, z.core.$strict>>;
|
|
1869
1877
|
total: z.ZodInt;
|
|
1870
1878
|
truncated: z.ZodBoolean;
|
|
@@ -1885,6 +1893,8 @@ declare const OPS: {
|
|
|
1885
1893
|
y: z.ZodInt;
|
|
1886
1894
|
width: z.ZodInt;
|
|
1887
1895
|
height: z.ZodInt;
|
|
1896
|
+
app: z.ZodOptional<z.ZodString>;
|
|
1897
|
+
pid: z.ZodOptional<z.ZodInt>;
|
|
1888
1898
|
}, z.core.$strict>;
|
|
1889
1899
|
}, z.core.$strict>;
|
|
1890
1900
|
readonly kind: "unary";
|
|
@@ -1907,6 +1917,8 @@ declare const OPS: {
|
|
|
1907
1917
|
y: z.ZodInt;
|
|
1908
1918
|
width: z.ZodInt;
|
|
1909
1919
|
height: z.ZodInt;
|
|
1920
|
+
app: z.ZodOptional<z.ZodString>;
|
|
1921
|
+
pid: z.ZodOptional<z.ZodInt>;
|
|
1910
1922
|
}, z.core.$strict>;
|
|
1911
1923
|
}, z.core.$strict>;
|
|
1912
1924
|
readonly kind: "unary";
|
|
@@ -3206,8 +3218,8 @@ declare const NAMED_SCHEMAS: {
|
|
|
3206
3218
|
page_token: z.ZodOptional<z.ZodString>;
|
|
3207
3219
|
show_hidden: z.ZodDefault<z.ZodBoolean>;
|
|
3208
3220
|
sort: z.ZodDefault<z.ZodEnum<{
|
|
3209
|
-
kind: "kind";
|
|
3210
3221
|
name: "name";
|
|
3222
|
+
kind: "kind";
|
|
3211
3223
|
size: "size";
|
|
3212
3224
|
mtime: "mtime";
|
|
3213
3225
|
}>>;
|
|
@@ -4607,6 +4619,8 @@ declare const NAMED_SCHEMAS: {
|
|
|
4607
4619
|
y: z.ZodInt;
|
|
4608
4620
|
width: z.ZodInt;
|
|
4609
4621
|
height: z.ZodInt;
|
|
4622
|
+
app: z.ZodOptional<z.ZodString>;
|
|
4623
|
+
pid: z.ZodOptional<z.ZodInt>;
|
|
4610
4624
|
}, z.core.$strict>;
|
|
4611
4625
|
readonly WindowListParams: z.ZodObject<{
|
|
4612
4626
|
title: z.ZodOptional<z.ZodString>;
|
|
@@ -4620,6 +4634,8 @@ declare const NAMED_SCHEMAS: {
|
|
|
4620
4634
|
y: z.ZodInt;
|
|
4621
4635
|
width: z.ZodInt;
|
|
4622
4636
|
height: z.ZodInt;
|
|
4637
|
+
app: z.ZodOptional<z.ZodString>;
|
|
4638
|
+
pid: z.ZodOptional<z.ZodInt>;
|
|
4623
4639
|
}, z.core.$strict>>;
|
|
4624
4640
|
total: z.ZodInt;
|
|
4625
4641
|
truncated: z.ZodBoolean;
|
|
@@ -4635,6 +4651,8 @@ declare const NAMED_SCHEMAS: {
|
|
|
4635
4651
|
y: z.ZodInt;
|
|
4636
4652
|
width: z.ZodInt;
|
|
4637
4653
|
height: z.ZodInt;
|
|
4654
|
+
app: z.ZodOptional<z.ZodString>;
|
|
4655
|
+
pid: z.ZodOptional<z.ZodInt>;
|
|
4638
4656
|
}, z.core.$strict>;
|
|
4639
4657
|
}, z.core.$strict>;
|
|
4640
4658
|
readonly WindowMoveParams: z.ZodObject<{
|
|
@@ -4652,6 +4670,8 @@ declare const NAMED_SCHEMAS: {
|
|
|
4652
4670
|
y: z.ZodInt;
|
|
4653
4671
|
width: z.ZodInt;
|
|
4654
4672
|
height: z.ZodInt;
|
|
4673
|
+
app: z.ZodOptional<z.ZodString>;
|
|
4674
|
+
pid: z.ZodOptional<z.ZodInt>;
|
|
4655
4675
|
}, z.core.$strict>;
|
|
4656
4676
|
}, z.core.$strict>;
|
|
4657
4677
|
readonly WindowMinimizeParams: z.ZodObject<{
|
package/dist/react.cjs
CHANGED
|
@@ -54,7 +54,7 @@ function bindDesktopWake(client, options = {}) {
|
|
|
54
54
|
}
|
|
55
55
|
|
|
56
56
|
// src/error.ts
|
|
57
|
-
var DesktopProtocolError = class extends Error {
|
|
57
|
+
var DesktopProtocolError = class _DesktopProtocolError extends Error {
|
|
58
58
|
code;
|
|
59
59
|
retryable;
|
|
60
60
|
data;
|
|
@@ -65,6 +65,23 @@ var DesktopProtocolError = class extends Error {
|
|
|
65
65
|
this.retryable = options.retryable ?? false;
|
|
66
66
|
this.data = options.data;
|
|
67
67
|
}
|
|
68
|
+
/**
|
|
69
|
+
* Any thrown value as a DesktopProtocolError, keeping its code, message and data. Each built entry
|
|
70
|
+
* (`.`, `./client`, `./react`) carries its own copy of this class, so `instanceof` alone misses an
|
|
71
|
+
* error thrown by a sibling entry and reports a real NOT_FOUND as INTERNAL; this checks the shape.
|
|
72
|
+
*/
|
|
73
|
+
static from(caught) {
|
|
74
|
+
if (caught instanceof _DesktopProtocolError) return caught;
|
|
75
|
+
const e = caught;
|
|
76
|
+
if (e && typeof e === "object" && e.name === "DesktopProtocolError" && typeof e.code === "string") {
|
|
77
|
+
return new _DesktopProtocolError(e.code, typeof e.message === "string" ? e.message : String(e.code), {
|
|
78
|
+
retryable: e.retryable === true,
|
|
79
|
+
...e.data && typeof e.data === "object" ? { data: e.data } : {},
|
|
80
|
+
cause: caught
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
return new _DesktopProtocolError("INTERNAL", caught instanceof Error ? caught.message : String(caught), { cause: caught });
|
|
84
|
+
}
|
|
68
85
|
/** The wire body (ProtocolErrorBody) — what a core or relay sends for this error. */
|
|
69
86
|
toBody() {
|
|
70
87
|
return this.data === void 0 ? { code: this.code, message: this.message, retryable: this.retryable } : { code: this.code, message: this.message, retryable: this.retryable, data: this.data };
|
|
@@ -120,7 +137,7 @@ function useDesktopRequest(op, params, options = {}) {
|
|
|
120
137
|
}
|
|
121
138
|
return result;
|
|
122
139
|
} catch (caught) {
|
|
123
|
-
const err =
|
|
140
|
+
const err = DesktopProtocolError.from(caught);
|
|
124
141
|
if (runId === runRef.current && err.code !== "CANCELLED") setError(err);
|
|
125
142
|
return void 0;
|
|
126
143
|
} finally {
|
|
@@ -182,7 +199,8 @@ function useDesktopAction(options = {}) {
|
|
|
182
199
|
await onDoneRef.current?.();
|
|
183
200
|
return true;
|
|
184
201
|
} catch (caught) {
|
|
185
|
-
|
|
202
|
+
const err = DesktopProtocolError.from(caught);
|
|
203
|
+
if (err.code !== "CANCELLED") setError(err);
|
|
186
204
|
return false;
|
|
187
205
|
} finally {
|
|
188
206
|
setBusy(false);
|
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 = caught instanceof DesktopProtocolError ? caught : new DesktopProtocolError(\"INTERNAL\", String(caught), { cause: 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 setError(caught instanceof DesktopProtocolError ? caught : new DesktopProtocolError(\"INTERNAL\", caught instanceof Error ? caught.message : String(caught), { cause: caught }));\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 /** 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":";;;;;;;;;;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,CAAC;AAAA,EACJ;AACA,QAAM,iBAAa,0BAAY,MAAM,SAAS,MAAS,GAAG,CAAC,CAAC;AAC5D,SAAO,EAAE,KAAK,MAAM,OAAO,WAAW;AACxC;AAGO,SAAS,gBAAqC,MAAS,SAA0B,UAAsC,CAAC,GAAS;AACtI,QAAM,IAAI,iBAAiB,QAAQ,MAAM;AACzC,QAAM,iBAAa,qBAAO,OAAO;AACjC,aAAW,UAAU;AACrB,8BAAU,MAAM,EAAE,GAAG,OAAO,CAAC,SAAS,eAAe,WAAW,QAAQ,SAAS,UAAU,EAAqB,GAAG,CAAC,GAAG,IAAI,CAAC;AAC9H;AAMO,SAAS,eAAe,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. 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,IAA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AK,CAAC;AACZ,cAAM,UAAU,UAAU;AAC1B,eAAO;AAAA,MACT,SAAS,QAAQ;AACf,cAAM,MAAM,qBAAqB,KAAK,MAAM;AAE5C,YAAI,IAAI,SAAS,YAAa,UAAS,GAAG;AAC1C,eAAO;AAAA,MACT,UAAE;AACA,gBAAQ,KAAK;AAAA,MACf;AAAA,IACF;AAAA,IACA,CAAC,CAAC;AAAA,EACJ;AACA,QAAM,iBAAa,0BAAY,MAAM,SAAS,MAAS,GAAG,CAAC,CAAC;AAC5D,SAAO,EAAE,KAAK,MAAM,OAAO,WAAW;AACxC;AAGO,SAAS,gBAAqC,MAAS,SAA0B,UAAsC,CAAC,GAAS;AACtI,QAAM,IAAI,iBAAiB,QAAQ,MAAM;AACzC,QAAM,iBAAa,qBAAO,OAAO;AACjC,aAAW,UAAU;AACrB,8BAAU,MAAM,EAAE,GAAG,OAAO,CAAC,SAAS,eAAe,WAAW,QAAQ,SAAS,UAAU,EAAqB,GAAG,CAAC,GAAG,IAAI,CAAC;AAC9H;AAMO,SAAS,eAAe,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":[]}
|
package/dist/react.d.cts
CHANGED
|
@@ -55,6 +55,12 @@ declare class DesktopProtocolError extends Error {
|
|
|
55
55
|
data?: ErrorData;
|
|
56
56
|
cause?: unknown;
|
|
57
57
|
});
|
|
58
|
+
/**
|
|
59
|
+
* Any thrown value as a DesktopProtocolError, keeping its code, message and data. Each built entry
|
|
60
|
+
* (`.`, `./client`, `./react`) carries its own copy of this class, so `instanceof` alone misses an
|
|
61
|
+
* error thrown by a sibling entry and reports a real NOT_FOUND as INTERNAL; this checks the shape.
|
|
62
|
+
*/
|
|
63
|
+
static from(caught: unknown): DesktopProtocolError;
|
|
58
64
|
/** The wire body (ProtocolErrorBody) — what a core or relay sends for this error. */
|
|
59
65
|
toBody(): {
|
|
60
66
|
code: ErrorCodeName;
|
|
@@ -1325,6 +1331,8 @@ declare const OPS: {
|
|
|
1325
1331
|
y: z.ZodInt;
|
|
1326
1332
|
width: z.ZodInt;
|
|
1327
1333
|
height: z.ZodInt;
|
|
1334
|
+
app: z.ZodOptional<z.ZodString>;
|
|
1335
|
+
pid: z.ZodOptional<z.ZodInt>;
|
|
1328
1336
|
}, z.core.$strict>>;
|
|
1329
1337
|
total: z.ZodInt;
|
|
1330
1338
|
truncated: z.ZodBoolean;
|
|
@@ -1345,6 +1353,8 @@ declare const OPS: {
|
|
|
1345
1353
|
y: z.ZodInt;
|
|
1346
1354
|
width: z.ZodInt;
|
|
1347
1355
|
height: z.ZodInt;
|
|
1356
|
+
app: z.ZodOptional<z.ZodString>;
|
|
1357
|
+
pid: z.ZodOptional<z.ZodInt>;
|
|
1348
1358
|
}, z.core.$strict>;
|
|
1349
1359
|
}, z.core.$strict>;
|
|
1350
1360
|
readonly kind: "unary";
|
|
@@ -1367,6 +1377,8 @@ declare const OPS: {
|
|
|
1367
1377
|
y: z.ZodInt;
|
|
1368
1378
|
width: z.ZodInt;
|
|
1369
1379
|
height: z.ZodInt;
|
|
1380
|
+
app: z.ZodOptional<z.ZodString>;
|
|
1381
|
+
pid: z.ZodOptional<z.ZodInt>;
|
|
1370
1382
|
}, z.core.$strict>;
|
|
1371
1383
|
}, z.core.$strict>;
|
|
1372
1384
|
readonly kind: "unary";
|
package/dist/react.d.ts
CHANGED
|
@@ -55,6 +55,12 @@ declare class DesktopProtocolError extends Error {
|
|
|
55
55
|
data?: ErrorData;
|
|
56
56
|
cause?: unknown;
|
|
57
57
|
});
|
|
58
|
+
/**
|
|
59
|
+
* Any thrown value as a DesktopProtocolError, keeping its code, message and data. Each built entry
|
|
60
|
+
* (`.`, `./client`, `./react`) carries its own copy of this class, so `instanceof` alone misses an
|
|
61
|
+
* error thrown by a sibling entry and reports a real NOT_FOUND as INTERNAL; this checks the shape.
|
|
62
|
+
*/
|
|
63
|
+
static from(caught: unknown): DesktopProtocolError;
|
|
58
64
|
/** The wire body (ProtocolErrorBody) — what a core or relay sends for this error. */
|
|
59
65
|
toBody(): {
|
|
60
66
|
code: ErrorCodeName;
|
|
@@ -1325,6 +1331,8 @@ declare const OPS: {
|
|
|
1325
1331
|
y: z.ZodInt;
|
|
1326
1332
|
width: z.ZodInt;
|
|
1327
1333
|
height: z.ZodInt;
|
|
1334
|
+
app: z.ZodOptional<z.ZodString>;
|
|
1335
|
+
pid: z.ZodOptional<z.ZodInt>;
|
|
1328
1336
|
}, z.core.$strict>>;
|
|
1329
1337
|
total: z.ZodInt;
|
|
1330
1338
|
truncated: z.ZodBoolean;
|
|
@@ -1345,6 +1353,8 @@ declare const OPS: {
|
|
|
1345
1353
|
y: z.ZodInt;
|
|
1346
1354
|
width: z.ZodInt;
|
|
1347
1355
|
height: z.ZodInt;
|
|
1356
|
+
app: z.ZodOptional<z.ZodString>;
|
|
1357
|
+
pid: z.ZodOptional<z.ZodInt>;
|
|
1348
1358
|
}, z.core.$strict>;
|
|
1349
1359
|
}, z.core.$strict>;
|
|
1350
1360
|
readonly kind: "unary";
|
|
@@ -1367,6 +1377,8 @@ declare const OPS: {
|
|
|
1367
1377
|
y: z.ZodInt;
|
|
1368
1378
|
width: z.ZodInt;
|
|
1369
1379
|
height: z.ZodInt;
|
|
1380
|
+
app: z.ZodOptional<z.ZodString>;
|
|
1381
|
+
pid: z.ZodOptional<z.ZodInt>;
|
|
1370
1382
|
}, z.core.$strict>;
|
|
1371
1383
|
}, z.core.$strict>;
|
|
1372
1384
|
readonly kind: "unary";
|
package/dist/react.js
CHANGED
|
@@ -25,7 +25,7 @@ function bindDesktopWake(client, options = {}) {
|
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
// src/error.ts
|
|
28
|
-
var DesktopProtocolError = class extends Error {
|
|
28
|
+
var DesktopProtocolError = class _DesktopProtocolError extends Error {
|
|
29
29
|
code;
|
|
30
30
|
retryable;
|
|
31
31
|
data;
|
|
@@ -36,6 +36,23 @@ var DesktopProtocolError = class extends Error {
|
|
|
36
36
|
this.retryable = options.retryable ?? false;
|
|
37
37
|
this.data = options.data;
|
|
38
38
|
}
|
|
39
|
+
/**
|
|
40
|
+
* Any thrown value as a DesktopProtocolError, keeping its code, message and data. Each built entry
|
|
41
|
+
* (`.`, `./client`, `./react`) carries its own copy of this class, so `instanceof` alone misses an
|
|
42
|
+
* error thrown by a sibling entry and reports a real NOT_FOUND as INTERNAL; this checks the shape.
|
|
43
|
+
*/
|
|
44
|
+
static from(caught) {
|
|
45
|
+
if (caught instanceof _DesktopProtocolError) return caught;
|
|
46
|
+
const e = caught;
|
|
47
|
+
if (e && typeof e === "object" && e.name === "DesktopProtocolError" && typeof e.code === "string") {
|
|
48
|
+
return new _DesktopProtocolError(e.code, typeof e.message === "string" ? e.message : String(e.code), {
|
|
49
|
+
retryable: e.retryable === true,
|
|
50
|
+
...e.data && typeof e.data === "object" ? { data: e.data } : {},
|
|
51
|
+
cause: caught
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
return new _DesktopProtocolError("INTERNAL", caught instanceof Error ? caught.message : String(caught), { cause: caught });
|
|
55
|
+
}
|
|
39
56
|
/** The wire body (ProtocolErrorBody) — what a core or relay sends for this error. */
|
|
40
57
|
toBody() {
|
|
41
58
|
return this.data === void 0 ? { code: this.code, message: this.message, retryable: this.retryable } : { code: this.code, message: this.message, retryable: this.retryable, data: this.data };
|
|
@@ -91,7 +108,7 @@ function useDesktopRequest(op, params, options = {}) {
|
|
|
91
108
|
}
|
|
92
109
|
return result;
|
|
93
110
|
} catch (caught) {
|
|
94
|
-
const err =
|
|
111
|
+
const err = DesktopProtocolError.from(caught);
|
|
95
112
|
if (runId === runRef.current && err.code !== "CANCELLED") setError(err);
|
|
96
113
|
return void 0;
|
|
97
114
|
} finally {
|
|
@@ -153,7 +170,8 @@ function useDesktopAction(options = {}) {
|
|
|
153
170
|
await onDoneRef.current?.();
|
|
154
171
|
return true;
|
|
155
172
|
} catch (caught) {
|
|
156
|
-
|
|
173
|
+
const err = DesktopProtocolError.from(caught);
|
|
174
|
+
if (err.code !== "CANCELLED") setError(err);
|
|
157
175
|
return false;
|
|
158
176
|
} finally {
|
|
159
177
|
setBusy(false);
|
package/dist/react.js.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 = caught instanceof DesktopProtocolError ? caught : new DesktopProtocolError(\"INTERNAL\", String(caught), { cause: 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 setError(caught instanceof DesktopProtocolError ? caught : new DesktopProtocolError(\"INTERNAL\", caught instanceof Error ? caught.message : String(caught), { cause: caught }));\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 /** 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":";;;AAKA,SAAS,eAAe,eAAe,aAAa,YAAY,WAAW,QAAQ,UAAU,4BAA4B;;;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,cAAmC,MAAM;AAAA,EACrC;AAAA,EACA;AAAA,EACA;AAAA,EAET,YAAY,MAAqB,SAAiB,UAAsE,CAAC,GAAG;AAC1H,UAAM,SAAS,QAAQ,UAAU,SAAY,SAAY,EAAE,OAAO,QAAQ,MAAM,CAAC;AACjF,SAAK,OAAO;AACZ,SAAK,OAAO;AACZ,SAAK,YAAY,QAAQ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,OAAO,CAAC,CAAC;AAC7K,eAAO;AAAA,MACT,UAAE;AACA,gBAAQ,KAAK;AAAA,MACf;AAAA,IACF;AAAA,IACA,CAAC,CAAC;AAAA,EACJ;AACA,QAAM,aAAa,YAAY,MAAM,SAAS,MAAS,GAAG,CAAC,CAAC;AAC5D,SAAO,EAAE,KAAK,MAAM,OAAO,WAAW;AACxC;AAGO,SAAS,gBAAqC,MAAS,SAA0B,UAAsC,CAAC,GAAS;AACtI,QAAM,IAAI,iBAAiB,QAAQ,MAAM;AACzC,QAAM,aAAa,OAAO,OAAO;AACjC,aAAW,UAAU;AACrB,YAAU,MAAM,EAAE,GAAG,OAAO,CAAC,SAAS,eAAe,WAAW,QAAQ,SAAS,UAAU,EAAqB,GAAG,CAAC,GAAG,IAAI,CAAC;AAC9H;AAMO,SAAS,eAAe,QAAwB,UAAgC,CAAC,GAAS;AAC/F,QAAM,IAAI,iBAAiB,MAAM;AACjC,QAAM,UAAU,QAAQ;AACxB,YAAU,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. 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":";;;AAKA,SAAS,eAAe,eAAe,aAAa,YAAY,WAAW,QAAQ,UAAU,4BAA4B;;;ACSlH,SAAS,gBAAgB,QAAqC,UAAmD,CAAC,GAAe;AACtI,QAAM,UACJ,QAAQ,YAAY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AAS,MAAS;AAClB,UAAI;AACF,cAAM,KAAK,CAAC;AACZ,cAAM,UAAU,UAAU;AAC1B,eAAO;AAAA,MACT,SAAS,QAAQ;AACf,cAAM,MAAM,qBAAqB,KAAK,MAAM;AAE5C,YAAI,IAAI,SAAS,YAAa,UAAS,GAAG;AAC1C,eAAO;AAAA,MACT,UAAE;AACA,gBAAQ,KAAK;AAAA,MACf;AAAA,IACF;AAAA,IACA,CAAC,CAAC;AAAA,EACJ;AACA,QAAM,aAAa,YAAY,MAAM,SAAS,MAAS,GAAG,CAAC,CAAC;AAC5D,SAAO,EAAE,KAAK,MAAM,OAAO,WAAW;AACxC;AAGO,SAAS,gBAAqC,MAAS,SAA0B,UAAsC,CAAC,GAAS;AACtI,QAAM,IAAI,iBAAiB,QAAQ,MAAM;AACzC,QAAM,aAAa,OAAO,OAAO;AACjC,aAAW,UAAU;AACrB,YAAU,MAAM,EAAE,GAAG,OAAO,CAAC,SAAS,eAAe,WAAW,QAAQ,SAAS,UAAU,EAAqB,GAAG,CAAC,GAAG,IAAI,CAAC;AAC9H;AAMO,SAAS,eAAe,QAAwB,UAAgC,CAAC,GAAS;AAC/F,QAAM,IAAI,iBAAiB,MAAM;AACjC,QAAM,UAAU,QAAQ;AACxB,YAAU,MAAM,gBAAgB,GAAG,YAAY,SAAY,CAAC,IAAI,EAAE,QAAQ,CAAC,GAAG,CAAC,GAAG,OAAO,CAAC;AAC5F;","names":[]}
|
|
@@ -4474,6 +4474,15 @@
|
|
|
4474
4474
|
"type": "integer",
|
|
4475
4475
|
"minimum": 0,
|
|
4476
4476
|
"maximum": 9007199254740991
|
|
4477
|
+
},
|
|
4478
|
+
"app": {
|
|
4479
|
+
"type": "string",
|
|
4480
|
+
"maxLength": 256
|
|
4481
|
+
},
|
|
4482
|
+
"pid": {
|
|
4483
|
+
"type": "integer",
|
|
4484
|
+
"minimum": 0,
|
|
4485
|
+
"maximum": 9007199254740991
|
|
4477
4486
|
}
|
|
4478
4487
|
},
|
|
4479
4488
|
"required": [
|
|
@@ -6981,6 +6990,10 @@
|
|
|
6981
6990
|
},
|
|
6982
6991
|
"RelayCallResponse|1": {
|
|
6983
6992
|
"protocol_version": "1.1"
|
|
6993
|
+
},
|
|
6994
|
+
"WindowInfo": {
|
|
6995
|
+
"app": "1.7",
|
|
6996
|
+
"pid": "1.7"
|
|
6984
6997
|
}
|
|
6985
6998
|
},
|
|
6986
6999
|
"x-null-since": {
|
|
@@ -6989,5 +7002,5 @@
|
|
|
6989
7002
|
"olderPeersGet": 0
|
|
6990
7003
|
}
|
|
6991
7004
|
},
|
|
6992
|
-
"x-protocol-version": "1.
|
|
7005
|
+
"x-protocol-version": "1.7"
|
|
6993
7006
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ai-matrx/desktop-protocol",
|
|
3
|
-
"version": "0.17.
|
|
3
|
+
"version": "0.17.3",
|
|
4
4
|
"description": "The one wire contract between Matrx 2 (the desktop app) and every client that drives it — phone, web app, extension, server: zod schemas for the envelope and every cap.op, the 16-byte binary frame codec, a reconnecting request/stream/credit/reattach client, React hooks, and a generated JSON Schema + Pydantic twin that CI keeps byte-identical.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|