@danypops/papyrus 0.33.0 → 0.33.1
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.
|
@@ -1,45 +1,29 @@
|
|
|
1
|
+
import { createRetryingClient, type RetryingClient } from "@danypops/daemon-kit/pi-client";
|
|
1
2
|
import { connectPapyrusClient, type PapyrusClient } from "../../src/client.ts";
|
|
2
3
|
import type { OperationName } from "../../src/service.ts";
|
|
3
4
|
|
|
4
5
|
type ClientConnector = () => Promise<PapyrusClient>;
|
|
5
6
|
|
|
6
7
|
let connector: ClientConnector = () => connectPapyrusClient();
|
|
7
|
-
|
|
8
|
+
const client: RetryingClient<PapyrusClient> = createRetryingClient<PapyrusClient>(() => connector(), { label: "Papyrus" });
|
|
8
9
|
|
|
9
10
|
export async function papyrusClient(): Promise<PapyrusClient> {
|
|
10
|
-
|
|
11
|
-
cached = await connector();
|
|
12
|
-
return cached;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
function staleConnection(error: unknown): boolean {
|
|
16
|
-
if (error instanceof TypeError) return true;
|
|
17
|
-
if (!(error instanceof Error)) return false;
|
|
18
|
-
if (error.name === "AbortError" || error.name === "TimeoutError") return true;
|
|
19
|
-
return /fetch failed|network|socket|ECONNRESET|ECONNREFUSED|connection refused/i.test(error.message);
|
|
11
|
+
return client.call(async (resolved) => resolved);
|
|
20
12
|
}
|
|
21
13
|
|
|
22
14
|
export async function callService<Input extends Record<string, unknown>, Output>(
|
|
23
15
|
operation: OperationName,
|
|
24
16
|
input: Input,
|
|
25
17
|
): Promise<Output> {
|
|
26
|
-
|
|
27
|
-
try {
|
|
28
|
-
return await (await papyrusClient()).call<Input, Output>(operation, input);
|
|
29
|
-
} catch (error) {
|
|
30
|
-
cached = undefined;
|
|
31
|
-
if (attempt === 1 || !staleConnection(error)) throw error;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
throw new Error("Papyrus daemon client retry exhausted");
|
|
18
|
+
return client.call((resolved) => resolved.call<Input, Output>(operation, input));
|
|
35
19
|
}
|
|
36
20
|
|
|
37
21
|
export function setPapyrusClientConnectorForTests(value: ClientConnector): void {
|
|
38
|
-
cached = undefined;
|
|
39
22
|
connector = value;
|
|
23
|
+
client.reset();
|
|
40
24
|
}
|
|
41
25
|
|
|
42
26
|
export function resetPapyrusClientForTests(): void {
|
|
43
|
-
cached = undefined;
|
|
44
27
|
connector = () => connectPapyrusClient();
|
|
28
|
+
client.reset();
|
|
45
29
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@danypops/papyrus",
|
|
3
|
-
"version": "0.33.
|
|
3
|
+
"version": "0.33.1",
|
|
4
4
|
"description": "Daemon-backed graph artifacts, evidence-bearing tasks, rules, skills, and native TUI workflows for Pi",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"keywords": ["pi-package"],
|
|
@@ -42,6 +42,6 @@
|
|
|
42
42
|
"files": ["src", "extension", "README.md"],
|
|
43
43
|
"dependencies": {
|
|
44
44
|
"beautiful-mermaid": "1.1.3",
|
|
45
|
-
"@danypops/daemon-kit": "^0.
|
|
45
|
+
"@danypops/daemon-kit": "^0.4.0"
|
|
46
46
|
}
|
|
47
47
|
}
|