@flowy-agent-store/protocol 0.1.0-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs ADDED
@@ -0,0 +1,80 @@
1
+ //#region src/protocol.ts
2
+ /**
3
+ * Agent Store App Server Protocol types.
4
+ *
5
+ * The chat surface uses only opaque public conversation/message IDs. Internal
6
+ * execution/session/step/attempt IDs never appear in this module.
7
+ */
8
+ const APP_SERVER_PROTOCOL_VERSION = "2026-08-26";
9
+ //#endregion
10
+ //#region src/errors.ts
11
+ var AppServerError = class extends Error {
12
+ code;
13
+ requestId;
14
+ retryable;
15
+ details;
16
+ constructor(wire) {
17
+ super(wire.message);
18
+ this.name = "AppServerError";
19
+ this.code = wire.code;
20
+ this.requestId = wire.request_id;
21
+ this.retryable = wire.retryable;
22
+ this.details = wire.details ?? {};
23
+ }
24
+ };
25
+ var TransportError = class extends Error {
26
+ phase;
27
+ retryable;
28
+ cause;
29
+ constructor(phase, message, options) {
30
+ super(message);
31
+ this.name = "TransportError";
32
+ this.phase = phase;
33
+ this.retryable = options?.retryable ?? false;
34
+ this.cause = options?.cause;
35
+ }
36
+ };
37
+ var ProtocolError = class extends Error {
38
+ kind;
39
+ constructor(kind, message) {
40
+ super(message);
41
+ this.name = "ProtocolError";
42
+ this.kind = kind;
43
+ }
44
+ };
45
+ var RequestTimeoutError = class extends Error {
46
+ method;
47
+ timeoutMs;
48
+ constructor(method, timeoutMs) {
49
+ super(`app-server request timed out after ${timeoutMs}ms: ${method}`);
50
+ this.name = "RequestTimeoutError";
51
+ this.method = method;
52
+ this.timeoutMs = timeoutMs;
53
+ }
54
+ };
55
+ function isAppServerError(error) {
56
+ return error instanceof AppServerError;
57
+ }
58
+ function isRetryableTransportError(error) {
59
+ return error instanceof TransportError && error.retryable;
60
+ }
61
+ /**
62
+ * Single human-readable rendering of a caught error.
63
+ *
64
+ * Every UI surface shares this one: a bare `Error` contributes only its
65
+ * message, while a protocol error contributes its stable `code` plus the
66
+ * server's retry hint. Components must not grow their own variants — a
67
+ * second spelling means the two drift apart on the retry hint.
68
+ */
69
+ function formatError(error) {
70
+ if (error instanceof AppServerError) return `${error.code}: ${error.message}`;
71
+ if (error instanceof Error) return error.message;
72
+ return String(error);
73
+ }
74
+ /** Whether the caught error is retryable — used by UI surfaces to append a
75
+ * localized "(可重试)" hint without baking wording into this lib. */
76
+ function isRetryableError(error) {
77
+ return (error instanceof AppServerError || error instanceof TransportError) && error.retryable;
78
+ }
79
+ //#endregion
80
+ export { APP_SERVER_PROTOCOL_VERSION, AppServerError, ProtocolError, RequestTimeoutError, TransportError, formatError, isAppServerError, isRetryableError, isRetryableTransportError };
package/package.json ADDED
@@ -0,0 +1,29 @@
1
+ {
2
+ "name": "@flowy-agent-store/protocol",
3
+ "version": "0.1.0-beta.2",
4
+ "description": "Versioned App Server Protocol types and wire errors (no runtime, no DOM/Node deps)",
5
+ "type": "module",
6
+ "license": "Apache-2.0",
7
+ "exports": {
8
+ ".": {
9
+ "types": "./dist/index.d.mts",
10
+ "import": "./dist/index.mjs",
11
+ "require": "./dist/index.cjs"
12
+ },
13
+ "./package.json": "./package.json"
14
+ },
15
+ "files": [
16
+ "dist"
17
+ ],
18
+ "scripts": {
19
+ "build": "tsdown",
20
+ "prepack": "tsdown"
21
+ },
22
+ "publishConfig": {
23
+ "access": "public",
24
+ "registry": "https://registry.npmjs.org/"
25
+ },
26
+ "main": "./dist/index.cjs",
27
+ "module": "./dist/index.mjs",
28
+ "types": "./dist/index.d.mts"
29
+ }