@av-pi-studio/protocol 0.0.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.
Files changed (38) hide show
  1. package/dist/.tsbuildinfo +1 -0
  2. package/dist/binary-frames/file-transfer-protocol.d.ts +63 -0
  3. package/dist/binary-frames/file-transfer-protocol.d.ts.map +1 -0
  4. package/dist/binary-frames/file-transfer-protocol.js +108 -0
  5. package/dist/binary-frames/file-transfer-protocol.js.map +1 -0
  6. package/dist/binary-frames/index.d.ts +3 -0
  7. package/dist/binary-frames/index.d.ts.map +1 -0
  8. package/dist/binary-frames/index.js +4 -0
  9. package/dist/binary-frames/index.js.map +1 -0
  10. package/dist/binary-frames/terminal-stream-protocol.d.ts +67 -0
  11. package/dist/binary-frames/terminal-stream-protocol.d.ts.map +1 -0
  12. package/dist/binary-frames/terminal-stream-protocol.js +104 -0
  13. package/dist/binary-frames/terminal-stream-protocol.js.map +1 -0
  14. package/dist/client-capabilities.d.ts +46 -0
  15. package/dist/client-capabilities.d.ts.map +1 -0
  16. package/dist/client-capabilities.js +75 -0
  17. package/dist/client-capabilities.js.map +1 -0
  18. package/dist/endpoint.d.ts +27 -0
  19. package/dist/endpoint.d.ts.map +1 -0
  20. package/dist/endpoint.js +75 -0
  21. package/dist/endpoint.js.map +1 -0
  22. package/dist/index.d.ts +9 -0
  23. package/dist/index.d.ts.map +1 -0
  24. package/dist/index.js +17 -0
  25. package/dist/index.js.map +1 -0
  26. package/dist/messages.d.ts +6119 -0
  27. package/dist/messages.d.ts.map +1 -0
  28. package/dist/messages.js +372 -0
  29. package/dist/messages.js.map +1 -0
  30. package/dist/provider-manifest.d.ts +176 -0
  31. package/dist/provider-manifest.d.ts.map +1 -0
  32. package/dist/provider-manifest.js +43 -0
  33. package/dist/provider-manifest.js.map +1 -0
  34. package/dist/validation.d.ts +77 -0
  35. package/dist/validation.d.ts.map +1 -0
  36. package/dist/validation.js +54 -0
  37. package/dist/validation.js.map +1 -0
  38. package/package.json +23 -0
@@ -0,0 +1,77 @@
1
+ import { z } from "zod";
2
+ /**
3
+ * Shared validation conventions for Pi-Studio.
4
+ *
5
+ * Every wire frame and every on-disk JSON document is parsed through Zod before it is trusted
6
+ * (MAIN-SCOPE.md §9). These helpers are the backbone of "validate at every boundary" and are
7
+ * reused by the protocol message schemas and the file-based persistence stores.
8
+ *
9
+ * ## Append-only compatibility rules (always)
10
+ *
11
+ * Schemas are **append-only**. A 6-month-old client must still parse new-daemon messages and
12
+ * vice-versa. Concretely:
13
+ *
14
+ * - **New fields are optional with a default or transform.** Use {@link optionalWithDefault} so a
15
+ * missing field deserializes to a known value instead of `undefined`.
16
+ * - **Never flip `optional` → `required`.** Once a field is optional it stays optional.
17
+ * - **Never remove a field.** Stop *sending* it if you must, but keep *reading* it.
18
+ * - **Never narrow a type** (e.g. `string` → enum, `nullable` → non-null). New enum values are
19
+ * gated at serialization behind capability flags so old clients only ever receive values they
20
+ * advertised support for.
21
+ *
22
+ * ## COMPAT(name) convention
23
+ *
24
+ * Back-compat shims are tagged so a single grep (`COMPAT(`) lists all pending cleanup work. Each
25
+ * tag records the version the shim was added in and the date it may be removed. Use {@link COMPAT}
26
+ * at the call site of a shim, e.g.:
27
+ *
28
+ * ```ts
29
+ * // COMPAT(legacy-provider-key): added 1.2.0, remove by 2026-12-31
30
+ * const normalized = COMPAT({ name: "legacy-provider-key", addedIn: "1.2.0", removeBy: "2026-12-31" });
31
+ * ```
32
+ */
33
+ /** Metadata describing a back-compat shim. Grep `COMPAT(` to enumerate cleanup work. */
34
+ export interface CompatTag {
35
+ /** Stable identifier for the shim (kebab-case). */
36
+ readonly name: string;
37
+ /** Version the shim was introduced in (semver). */
38
+ readonly addedIn: string;
39
+ /** ISO date (YYYY-MM-DD) after which the shim may be removed. */
40
+ readonly removeBy: string;
41
+ }
42
+ /**
43
+ * Marks a back-compat shim. Returns the tag unchanged so it can be used inline; its real value is
44
+ * the grep-able `COMPAT(` token and the structured metadata it carries.
45
+ */
46
+ export declare function COMPAT(tag: CompatTag): CompatTag;
47
+ /**
48
+ * Append-only field helper: declares a schema field that is optional on the wire/disk but always
49
+ * resolves to a concrete default once parsed. This is the sanctioned way to add new fields without
50
+ * breaking older producers that omit them.
51
+ */
52
+ export declare function optionalWithDefault<S extends z.ZodTypeAny>(schema: S, defaultValue: z.infer<S>): z.ZodDefault<z.ZodOptional<S>>;
53
+ /**
54
+ * Parse `value` with `schema`, returning the parsed value on success or `defaults` on any failure.
55
+ * Used by the file-based stores so corrupt/partial JSON falls back to defaults instead of crashing
56
+ * the daemon (architecture/persistence.md — "Corrupt/partial JSON → fall back to defaults").
57
+ */
58
+ export declare function safeParseOrDefault<S extends z.ZodTypeAny>(schema: S, value: unknown, defaults: z.infer<S>): z.infer<S>;
59
+ /**
60
+ * ISO-8601 timestamp string (UTC `Z` or explicit offset), e.g. `2026-06-11T15:00:00.000Z`.
61
+ * Timeline row timestamps are canonical, daemon-owned strings (MAIN-SCOPE.md §9).
62
+ */
63
+ export declare const isoTimestampSchema: z.ZodString;
64
+ /** RFC-4122 UUID string (the primary key shape for agents, chat rooms, messages, etc.). */
65
+ export declare const uuidSchema: z.ZodString;
66
+ /**
67
+ * base64url character set with no padding (`A–Z a–z 0–9 - _`). The encoding used for stable ids
68
+ * like the daemon `server-id` (`srv_<base64url>`).
69
+ */
70
+ export declare const base64UrlSchema: z.ZodString;
71
+ /** Returns true if `value` is a non-empty base64url string. */
72
+ export declare function isBase64Url(value: string): boolean;
73
+ /**
74
+ * Schema for a prefixed base64url id of the form `${prefix}_<base64url>` (e.g. `srv_AbC-123`).
75
+ */
76
+ export declare function prefixedIdSchema(prefix: string): z.ZodString;
77
+ //# sourceMappingURL=validation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validation.d.ts","sourceRoot":"","sources":["../src/validation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AAEH,wFAAwF;AACxF,MAAM,WAAW,SAAS;IACxB,mDAAmD;IACnD,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,mDAAmD;IACnD,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,iEAAiE;IACjE,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;CAC3B;AAED;;;GAGG;AACH,wBAAgB,MAAM,CAAC,GAAG,EAAE,SAAS,GAAG,SAAS,CAEhD;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,CAAC,SAAS,CAAC,CAAC,UAAU,EACxD,MAAM,EAAE,CAAC,EACT,YAAY,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,GACvB,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAEhC;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,CAAC,SAAS,CAAC,CAAC,UAAU,EACvD,MAAM,EAAE,CAAC,EACT,KAAK,EAAE,OAAO,EACd,QAAQ,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,GACnB,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAGZ;AAMD;;;GAGG;AACH,eAAO,MAAM,kBAAkB,aAAwC,CAAC;AAExE,2FAA2F;AAC3F,eAAO,MAAM,UAAU,aAAoB,CAAC;AAE5C;;;GAGG;AACH,eAAO,MAAM,eAAe,aAA6D,CAAC;AAE1F,+DAA+D;AAC/D,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAElD;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,MAAM,GAAG,CAAC,CAAC,SAAS,CAK5D"}
@@ -0,0 +1,54 @@
1
+ import { z } from "zod";
2
+ /**
3
+ * Marks a back-compat shim. Returns the tag unchanged so it can be used inline; its real value is
4
+ * the grep-able `COMPAT(` token and the structured metadata it carries.
5
+ */
6
+ export function COMPAT(tag) {
7
+ return tag;
8
+ }
9
+ /**
10
+ * Append-only field helper: declares a schema field that is optional on the wire/disk but always
11
+ * resolves to a concrete default once parsed. This is the sanctioned way to add new fields without
12
+ * breaking older producers that omit them.
13
+ */
14
+ export function optionalWithDefault(schema, defaultValue) {
15
+ return schema.optional().default(defaultValue);
16
+ }
17
+ /**
18
+ * Parse `value` with `schema`, returning the parsed value on success or `defaults` on any failure.
19
+ * Used by the file-based stores so corrupt/partial JSON falls back to defaults instead of crashing
20
+ * the daemon (architecture/persistence.md — "Corrupt/partial JSON → fall back to defaults").
21
+ */
22
+ export function safeParseOrDefault(schema, value, defaults) {
23
+ const result = schema.safeParse(value);
24
+ return result.success ? result.data : defaults;
25
+ }
26
+ // ---------------------------------------------------------------------------
27
+ // Shared primitive schemas
28
+ // ---------------------------------------------------------------------------
29
+ /**
30
+ * ISO-8601 timestamp string (UTC `Z` or explicit offset), e.g. `2026-06-11T15:00:00.000Z`.
31
+ * Timeline row timestamps are canonical, daemon-owned strings (MAIN-SCOPE.md §9).
32
+ */
33
+ export const isoTimestampSchema = z.string().datetime({ offset: true });
34
+ /** RFC-4122 UUID string (the primary key shape for agents, chat rooms, messages, etc.). */
35
+ export const uuidSchema = z.string().uuid();
36
+ /**
37
+ * base64url character set with no padding (`A–Z a–z 0–9 - _`). The encoding used for stable ids
38
+ * like the daemon `server-id` (`srv_<base64url>`).
39
+ */
40
+ export const base64UrlSchema = z.string().regex(/^[A-Za-z0-9_-]+$/, "expected base64url");
41
+ /** Returns true if `value` is a non-empty base64url string. */
42
+ export function isBase64Url(value) {
43
+ return base64UrlSchema.safeParse(value).success;
44
+ }
45
+ /**
46
+ * Schema for a prefixed base64url id of the form `${prefix}_<base64url>` (e.g. `srv_AbC-123`).
47
+ */
48
+ export function prefixedIdSchema(prefix) {
49
+ const escaped = prefix.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
50
+ return z
51
+ .string()
52
+ .regex(new RegExp(`^${escaped}_[A-Za-z0-9_-]+$`), `expected ${prefix}_<base64url> id`);
53
+ }
54
+ //# sourceMappingURL=validation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validation.js","sourceRoot":"","sources":["../src/validation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AA4CxB;;;GAGG;AACH,MAAM,UAAU,MAAM,CAAC,GAAc;IACnC,OAAO,GAAG,CAAC;AACb,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,mBAAmB,CACjC,MAAS,EACT,YAAwB;IAExB,OAAO,MAAM,CAAC,QAAQ,EAAE,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC;AACjD,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,kBAAkB,CAChC,MAAS,EACT,KAAc,EACd,QAAoB;IAEpB,MAAM,MAAM,GAAG,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;IACvC,OAAO,MAAM,CAAC,OAAO,CAAC,CAAC,CAAE,MAAM,CAAC,IAAmB,CAAC,CAAC,CAAC,QAAQ,CAAC;AACjE,CAAC;AAED,8EAA8E;AAC9E,2BAA2B;AAC3B,8EAA8E;AAE9E;;;GAGG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC;AAExE,2FAA2F;AAC3F,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE,CAAC;AAE5C;;;GAGG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,kBAAkB,EAAE,oBAAoB,CAAC,CAAC;AAE1F,+DAA+D;AAC/D,MAAM,UAAU,WAAW,CAAC,KAAa;IACvC,OAAO,eAAe,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC;AAClD,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,gBAAgB,CAAC,MAAc;IAC7C,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC,qBAAqB,EAAE,MAAM,CAAC,CAAC;IAC9D,OAAO,CAAC;SACL,MAAM,EAAE;SACR,KAAK,CAAC,IAAI,MAAM,CAAC,IAAI,OAAO,kBAAkB,CAAC,EAAE,YAAY,MAAM,iBAAiB,CAAC,CAAC;AAC3F,CAAC"}
package/package.json ADDED
@@ -0,0 +1,23 @@
1
+ {
2
+ "name": "@av-pi-studio/protocol",
3
+ "version": "0.0.1",
4
+ "type": "module",
5
+ "main": "./dist/index.js",
6
+ "types": "./dist/index.d.ts",
7
+ "files": [
8
+ "dist"
9
+ ],
10
+ "exports": {
11
+ ".": {
12
+ "types": "./dist/index.d.ts",
13
+ "default": "./dist/index.js"
14
+ }
15
+ },
16
+ "scripts": {
17
+ "build": "tsc -b",
18
+ "clean": "rm -rf dist *.tsbuildinfo"
19
+ },
20
+ "dependencies": {
21
+ "zod": "^3.23.0"
22
+ }
23
+ }