@ggui-ai/protocol 0.1.0-rc.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 (222) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +46 -0
  3. package/dist/bridge/invoke-agent.d.ts +65 -0
  4. package/dist/bridge/invoke-agent.d.ts.map +1 -0
  5. package/dist/bridge/invoke-agent.js +113 -0
  6. package/dist/envelope-adapters.d.ts +24 -0
  7. package/dist/envelope-adapters.d.ts.map +1 -0
  8. package/dist/envelope-adapters.js +14 -0
  9. package/dist/envelopes/builders.d.ts +145 -0
  10. package/dist/envelopes/builders.d.ts.map +1 -0
  11. package/dist/envelopes/builders.js +113 -0
  12. package/dist/errors/unknown-permission-name.d.ts +12 -0
  13. package/dist/errors/unknown-permission-name.d.ts.map +1 -0
  14. package/dist/errors/unknown-permission-name.js +29 -0
  15. package/dist/errors/version-mismatch.d.ts +55 -0
  16. package/dist/errors/version-mismatch.d.ts.map +1 -0
  17. package/dist/errors/version-mismatch.js +52 -0
  18. package/dist/gadgets/resolve-contract-gadgets.d.ts +93 -0
  19. package/dist/gadgets/resolve-contract-gadgets.d.ts.map +1 -0
  20. package/dist/gadgets/resolve-contract-gadgets.js +119 -0
  21. package/dist/gadgets/stdlib-gadgets.d.ts +43 -0
  22. package/dist/gadgets/stdlib-gadgets.d.ts.map +1 -0
  23. package/dist/gadgets/stdlib-gadgets.js +161 -0
  24. package/dist/iframe-bridge.d.ts +63 -0
  25. package/dist/iframe-bridge.d.ts.map +1 -0
  26. package/dist/iframe-bridge.js +166 -0
  27. package/dist/index.d.ts +62 -0
  28. package/dist/index.d.ts.map +1 -0
  29. package/dist/index.js +79 -0
  30. package/dist/integrations/mcp-apps.d.ts +1218 -0
  31. package/dist/integrations/mcp-apps.d.ts.map +1 -0
  32. package/dist/integrations/mcp-apps.js +427 -0
  33. package/dist/navigation/index.d.ts +3 -0
  34. package/dist/navigation/index.d.ts.map +1 -0
  35. package/dist/navigation/index.js +1 -0
  36. package/dist/navigation/stack-navigation.d.ts +55 -0
  37. package/dist/navigation/stack-navigation.d.ts.map +1 -0
  38. package/dist/navigation/stack-navigation.js +80 -0
  39. package/dist/recommended-prompts.d.ts +56 -0
  40. package/dist/recommended-prompts.d.ts.map +1 -0
  41. package/dist/recommended-prompts.js +55 -0
  42. package/dist/registry/blueprint-key.d.ts +9 -0
  43. package/dist/registry/blueprint-key.d.ts.map +1 -0
  44. package/dist/registry/blueprint-key.js +28 -0
  45. package/dist/registry/canonicalize-contract.d.ts +35 -0
  46. package/dist/registry/canonicalize-contract.d.ts.map +1 -0
  47. package/dist/registry/canonicalize-contract.js +166 -0
  48. package/dist/registry/summarize-contract.d.ts +46 -0
  49. package/dist/registry/summarize-contract.d.ts.map +1 -0
  50. package/dist/registry/summarize-contract.js +63 -0
  51. package/dist/schema-learning/derive-contract.d.ts +67 -0
  52. package/dist/schema-learning/derive-contract.d.ts.map +1 -0
  53. package/dist/schema-learning/derive-contract.js +117 -0
  54. package/dist/schema-learning/merge.d.ts +32 -0
  55. package/dist/schema-learning/merge.d.ts.map +1 -0
  56. package/dist/schema-learning/merge.js +146 -0
  57. package/dist/schemas/blueprint.d.ts +32 -0
  58. package/dist/schemas/blueprint.d.ts.map +1 -0
  59. package/dist/schemas/blueprint.js +92 -0
  60. package/dist/schemas/data-contract.d.ts +750 -0
  61. package/dist/schemas/data-contract.d.ts.map +1 -0
  62. package/dist/schemas/data-contract.js +663 -0
  63. package/dist/schemas/gadget-name-grammar.d.ts +29 -0
  64. package/dist/schemas/gadget-name-grammar.d.ts.map +1 -0
  65. package/dist/schemas/gadget-name-grammar.js +28 -0
  66. package/dist/schemas/handshake-suggestion.d.ts +46 -0
  67. package/dist/schemas/handshake-suggestion.d.ts.map +1 -0
  68. package/dist/schemas/handshake-suggestion.js +107 -0
  69. package/dist/schemas/invoke.d.ts +337 -0
  70. package/dist/schemas/invoke.d.ts.map +1 -0
  71. package/dist/schemas/invoke.js +169 -0
  72. package/dist/schemas/mcp.d.ts +301 -0
  73. package/dist/schemas/mcp.d.ts.map +1 -0
  74. package/dist/schemas/mcp.js +373 -0
  75. package/dist/schemas/ops-blueprint.d.ts +176 -0
  76. package/dist/schemas/ops-blueprint.d.ts.map +1 -0
  77. package/dist/schemas/ops-blueprint.js +259 -0
  78. package/dist/schemas/sync-check.d.ts +11 -0
  79. package/dist/schemas/sync-check.d.ts.map +1 -0
  80. package/dist/schemas/sync-check.js +60 -0
  81. package/dist/screen-blueprints/define.d.ts +22 -0
  82. package/dist/screen-blueprints/define.d.ts.map +1 -0
  83. package/dist/screen-blueprints/define.js +3 -0
  84. package/dist/screen-blueprints/index.d.ts +4 -0
  85. package/dist/screen-blueprints/index.d.ts.map +1 -0
  86. package/dist/screen-blueprints/index.js +3 -0
  87. package/dist/screen-blueprints/match.d.ts +35 -0
  88. package/dist/screen-blueprints/match.d.ts.map +1 -0
  89. package/dist/screen-blueprints/match.js +51 -0
  90. package/dist/screen-blueprints/types.d.ts +164 -0
  91. package/dist/screen-blueprints/types.d.ts.map +1 -0
  92. package/dist/screen-blueprints/types.js +1 -0
  93. package/dist/stream/stream-parser.d.ts +62 -0
  94. package/dist/stream/stream-parser.d.ts.map +1 -0
  95. package/dist/stream/stream-parser.js +199 -0
  96. package/dist/transport/websocket.d.ts +178 -0
  97. package/dist/transport/websocket.d.ts.map +1 -0
  98. package/dist/transport/websocket.js +1 -0
  99. package/dist/types/app-config.d.ts +61 -0
  100. package/dist/types/app-config.d.ts.map +1 -0
  101. package/dist/types/app-config.js +1 -0
  102. package/dist/types/auth.d.ts +61 -0
  103. package/dist/types/auth.d.ts.map +1 -0
  104. package/dist/types/auth.js +1 -0
  105. package/dist/types/blueprint.d.ts +206 -0
  106. package/dist/types/blueprint.d.ts.map +1 -0
  107. package/dist/types/blueprint.js +1 -0
  108. package/dist/types/canvas-lifecycle.d.ts +105 -0
  109. package/dist/types/canvas-lifecycle.d.ts.map +1 -0
  110. package/dist/types/canvas-lifecycle.js +38 -0
  111. package/dist/types/capabilities.d.ts +40 -0
  112. package/dist/types/capabilities.d.ts.map +1 -0
  113. package/dist/types/capabilities.js +19 -0
  114. package/dist/types/contract-inference.d.ts +401 -0
  115. package/dist/types/contract-inference.d.ts.map +1 -0
  116. package/dist/types/contract-inference.js +44 -0
  117. package/dist/types/credential.d.ts +41 -0
  118. package/dist/types/credential.d.ts.map +1 -0
  119. package/dist/types/credential.js +32 -0
  120. package/dist/types/data-bindings.d.ts +322 -0
  121. package/dist/types/data-bindings.d.ts.map +1 -0
  122. package/dist/types/data-bindings.js +29 -0
  123. package/dist/types/data-contract.d.ts +1296 -0
  124. package/dist/types/data-contract.d.ts.map +1 -0
  125. package/dist/types/data-contract.js +111 -0
  126. package/dist/types/events.d.ts +182 -0
  127. package/dist/types/events.d.ts.map +1 -0
  128. package/dist/types/events.js +8 -0
  129. package/dist/types/feedback.d.ts +24 -0
  130. package/dist/types/feedback.d.ts.map +1 -0
  131. package/dist/types/feedback.js +7 -0
  132. package/dist/types/gadget.d.ts +121 -0
  133. package/dist/types/gadget.d.ts.map +1 -0
  134. package/dist/types/gadget.js +24 -0
  135. package/dist/types/handshake-suggestion.d.ts +264 -0
  136. package/dist/types/handshake-suggestion.d.ts.map +1 -0
  137. package/dist/types/handshake-suggestion.js +70 -0
  138. package/dist/types/host-context.d.ts +163 -0
  139. package/dist/types/host-context.d.ts.map +1 -0
  140. package/dist/types/host-context.js +142 -0
  141. package/dist/types/interface-context.d.ts +105 -0
  142. package/dist/types/interface-context.d.ts.map +1 -0
  143. package/dist/types/interface-context.js +115 -0
  144. package/dist/types/invoke.d.ts +28 -0
  145. package/dist/types/invoke.d.ts.map +1 -0
  146. package/dist/types/invoke.js +7 -0
  147. package/dist/types/live-channel.d.ts +613 -0
  148. package/dist/types/live-channel.d.ts.map +1 -0
  149. package/dist/types/live-channel.js +1 -0
  150. package/dist/types/llm.d.ts +61 -0
  151. package/dist/types/llm.d.ts.map +1 -0
  152. package/dist/types/llm.js +186 -0
  153. package/dist/types/mcp-proxy.d.ts +67 -0
  154. package/dist/types/mcp-proxy.d.ts.map +1 -0
  155. package/dist/types/mcp-proxy.js +46 -0
  156. package/dist/types/mcp.d.ts +637 -0
  157. package/dist/types/mcp.d.ts.map +1 -0
  158. package/dist/types/mcp.js +30 -0
  159. package/dist/types/openrouter-models.d.ts +22 -0
  160. package/dist/types/openrouter-models.d.ts.map +1 -0
  161. package/dist/types/openrouter-models.js +4843 -0
  162. package/dist/types/region.d.ts +26 -0
  163. package/dist/types/region.d.ts.map +1 -0
  164. package/dist/types/region.js +36 -0
  165. package/dist/types/session.d.ts +419 -0
  166. package/dist/types/session.d.ts.map +1 -0
  167. package/dist/types/session.js +1 -0
  168. package/dist/types/thread.d.ts +207 -0
  169. package/dist/types/thread.d.ts.map +1 -0
  170. package/dist/types/thread.js +57 -0
  171. package/dist/types/ui-generator.d.ts +100 -0
  172. package/dist/types/ui-generator.d.ts.map +1 -0
  173. package/dist/types/ui-generator.js +53 -0
  174. package/dist/validation/ajv-runtime.d.ts +140 -0
  175. package/dist/validation/ajv-runtime.d.ts.map +1 -0
  176. package/dist/validation/ajv-runtime.js +452 -0
  177. package/dist/validation/content-hash.d.ts +3 -0
  178. package/dist/validation/content-hash.d.ts.map +1 -0
  179. package/dist/validation/content-hash.js +21 -0
  180. package/dist/validation/contract-validator.d.ts +244 -0
  181. package/dist/validation/contract-validator.d.ts.map +1 -0
  182. package/dist/validation/contract-validator.js +711 -0
  183. package/dist/validation/cross-references.d.ts +105 -0
  184. package/dist/validation/cross-references.d.ts.map +1 -0
  185. package/dist/validation/cross-references.js +164 -0
  186. package/dist/validation/hygiene-rules.d.ts +250 -0
  187. package/dist/validation/hygiene-rules.d.ts.map +1 -0
  188. package/dist/validation/hygiene-rules.js +564 -0
  189. package/dist/validation/lint-contract.d.ts +130 -0
  190. package/dist/validation/lint-contract.d.ts.map +1 -0
  191. package/dist/validation/lint-contract.js +225 -0
  192. package/dist/validation/name-invariants.d.ts +117 -0
  193. package/dist/validation/name-invariants.d.ts.map +1 -0
  194. package/dist/validation/name-invariants.js +172 -0
  195. package/dist/validation/reserved-channels.d.ts +156 -0
  196. package/dist/validation/reserved-channels.d.ts.map +1 -0
  197. package/dist/validation/reserved-channels.js +356 -0
  198. package/dist/validation/resolve-stream-channel.d.ts +78 -0
  199. package/dist/validation/resolve-stream-channel.d.ts.map +1 -0
  200. package/dist/validation/resolve-stream-channel.js +64 -0
  201. package/dist/validation/sanitize-error.d.ts +46 -0
  202. package/dist/validation/sanitize-error.d.ts.map +1 -0
  203. package/dist/validation/sanitize-error.js +88 -0
  204. package/dist/validation/schema-compat-invariants.d.ts +140 -0
  205. package/dist/validation/schema-compat-invariants.d.ts.map +1 -0
  206. package/dist/validation/schema-compat-invariants.js +220 -0
  207. package/dist/validation/schema-meta-validation.d.ts +60 -0
  208. package/dist/validation/schema-meta-validation.d.ts.map +1 -0
  209. package/dist/validation/schema-meta-validation.js +131 -0
  210. package/dist/validation/schema-subset.d.ts +165 -0
  211. package/dist/validation/schema-subset.d.ts.map +1 -0
  212. package/dist/validation/schema-subset.js +295 -0
  213. package/dist/validation/ui-security.d.ts +54 -0
  214. package/dist/validation/ui-security.d.ts.map +1 -0
  215. package/dist/validation/ui-security.js +138 -0
  216. package/dist/validation/zod-to-json-schema.d.ts +63 -0
  217. package/dist/validation/zod-to-json-schema.d.ts.map +1 -0
  218. package/dist/validation/zod-to-json-schema.js +126 -0
  219. package/dist/version.d.ts +1458 -0
  220. package/dist/version.d.ts.map +1 -0
  221. package/dist/version.js +1459 -0
  222. package/package.json +113 -0
@@ -0,0 +1,244 @@
1
+ import type { PropsSpec, StreamSpec, ActionSpec, ContextSpec, JsonSchema, JsonObject, DataContract } from '../types/data-contract';
2
+ import type { ActionEnvelope } from '../types/events';
3
+ import type { CompiledContractValidators } from '../integrations/mcp-apps';
4
+ import type { ValidateFunction } from './ajv-runtime';
5
+ export type { ValidateFunction } from './ajv-runtime';
6
+ import { type ReservedChannelValidator } from './reserved-channels';
7
+ export interface ContractViolation extends JsonObject {
8
+ field: string;
9
+ message: string;
10
+ expected?: string;
11
+ received?: string;
12
+ }
13
+ export interface ValidationResult {
14
+ valid: boolean;
15
+ violations: ContractViolation[];
16
+ }
17
+ /**
18
+ * Synthesize a {@link PropsSpec} into the single object-node JSON
19
+ * Schema the runtime validates `props` against — `{type:'object',
20
+ * properties:{…entry.schema…}, required:[…entry.required…]}`.
21
+ * Closed-shape (`additionalProperties:false` at every depth) is NOT
22
+ * injected here — the Ajv compile step ({@link compileForValidation} /
23
+ * {@link compileValidatorModule}) does that, so this returns the raw
24
+ * pre-injection wrapper.
25
+ *
26
+ * Shared by {@link validatePropsData} (server-side runtime check) and
27
+ * {@link compileContractValidators} (push-time standalone emission) so
28
+ * the precompiled in-iframe validator enforces byte-identical
29
+ * semantics to the runtime validator — one synthesis, no drift.
30
+ */
31
+ export declare function buildPropsWrapperSchema(spec: PropsSpec): JsonSchema;
32
+ /**
33
+ * Validate runtime props data against a PropsSpec contract.
34
+ *
35
+ * Synthesizes the propsSpec into a single JSON Schema object node
36
+ * — `{type:'object', properties: {…spec.properties[name].schema…},
37
+ * required: [...names where entry.required], additionalProperties:
38
+ * false}` — and validates `props` against it via the shared Ajv
39
+ * runtime. The closed-shape injector recurses into every nested
40
+ * object so the bidirectional contract (every declared key
41
+ * validated, every data key declared) holds at any depth.
42
+ *
43
+ * Load-bearing for `ggui_update kind:'merge'` (RFC 7396): a patch
44
+ * adding a key absent from `propsSpec.properties` would silently
45
+ * land on the stack item without this gate. Same rule applies to
46
+ * the `done`-vs-declared-`completed` class of bug inside array
47
+ * items — Ajv rejects with the exact path (`todos[0].done`).
48
+ */
49
+ export declare function validatePropsData(props: Record<string, unknown>, spec: PropsSpec, precompiled?: ValidateFunction): ValidationResult;
50
+ /**
51
+ * Validate a stream delivery's payload against the channel's declared
52
+ * schema on a {@link StreamSpec}.
53
+ *
54
+ * Signature takes the channel name + payload explicitly — matching
55
+ * the {@link StreamEnvelope} wire shape (where channel is a first-
56
+ * class envelope field, not a field nested inside the payload).
57
+ *
58
+ * Checks:
59
+ * - `channelName` is declared in `spec` (a flat `Record<channelName,
60
+ * StreamChannelEntry>` post-2026-04-22 flatten) — undeclared
61
+ * channels reject with `'Unknown stream channel'` in the
62
+ * violation message.
63
+ * - `payload` conforms to `spec[channelName].schema` when
64
+ * that schema declares a `type`.
65
+ *
66
+ * Reserved-channel handling (injection pattern):
67
+ *
68
+ * Known reserved channels (see {@link isKnownReservedChannel}) are
69
+ * server-owned and bypass the streamSpec path entirely — agents
70
+ * never declare them. Their payloads are validated through the
71
+ * TWO-TIER validator lookup:
72
+ *
73
+ * 1. `extraReservedValidators` — optional, caller-provided. Primary
74
+ * consumer: a hosting implementation composing the A2UI
75
+ * validator for `_ggui:preview`. Consulted FIRST so callers can
76
+ * override or extend built-ins.
77
+ * 2. `BUILTIN_RESERVED_VALIDATORS` — protocol-owned, always active.
78
+ * Ships the {@link validateContractErrorPayload} for
79
+ * `_ggui:contract-error`.
80
+ * 3. Fall-through: if no validator is registered for the known
81
+ * reserved channel, return `{valid: true}`. Preserves backward
82
+ * compatibility for any future reserved channel the runtime
83
+ * adds before its validator is authored.
84
+ *
85
+ * Without this structure, a `_ggui:preview` emission into a session
86
+ * whose active stack item carries ANY user streamSpec would
87
+ * synthesize a false "Unknown channel" violation, blocking the
88
+ * provisional preview runtime. Symmetric with the client-side
89
+ * handling in `GguiSession`.
90
+ *
91
+ * Crucially narrow by design — the known-reserved path is a CLOSED
92
+ * SET, not a prefix check. A typo inside the reserved namespace
93
+ * (e.g. `_ggui:preveiw`) is NOT recognized, falls through to the
94
+ * normal unknown-channel rejection, and surfaces the bug at its
95
+ * emission site instead of turning into a silent no-op delivery.
96
+ *
97
+ * Does NOT validate channel semantics (mode / replay / complete) —
98
+ * those are declarations, not shape constraints. See
99
+ * `resolveStreamChannel` for semantics lookup.
100
+ */
101
+ export declare function validateStreamData(channelName: string, payload: unknown, spec: StreamSpec, extraReservedValidators?: ReadonlyMap<string, ReservedChannelValidator>, precompiledChannels?: ReadonlyMap<string, ValidateFunction>): ValidationResult;
102
+ /**
103
+ * Validate a contextSpec slot value against the spec's declared
104
+ * schema. Symmetric with {@link validateStreamData} /
105
+ * {@link validateActionData}: the iframe-runtime observer uses this
106
+ * to gate Provider values BEFORE posting `ui/update-model-context`
107
+ * envelopes (per the contextSpec design-lock — Q4 schema check).
108
+ *
109
+ * Checks:
110
+ * - `slotName` is declared in `spec` — undeclared slots reject with
111
+ * `'Unknown context slot'`.
112
+ * - `value` conforms to `spec[slotName].schema` when that schema
113
+ * declares a `type`.
114
+ *
115
+ * Mirrors `validateActionData`'s posture: the runtime that calls this
116
+ * decides whether to surface the failure (dev-only `console.warn`,
117
+ * drop silently in production) — the validator is a pure shape gate.
118
+ */
119
+ export declare function validateContextData(slotName: string, value: unknown, spec: ContextSpec, precompiledSlots?: ReadonlyMap<string, ValidateFunction>): ValidationResult;
120
+ /**
121
+ * Validate an inbound user-action payload against the session's ActionSpec.
122
+ *
123
+ * Symmetric with {@link validatePropsData} / {@link validateStreamData}, but for
124
+ * live-channel INBOUND user → core traffic. Enforces the action contract at the
125
+ * wire boundary BEFORE the event is buffered or forwarded to an agent.
126
+ *
127
+ * Input shape mirrors `ActionEventValue` from `events.ts`:
128
+ * `{ action: string, data?: JsonValue, tool?: string }`
129
+ *
130
+ * Checks:
131
+ * - `action` is a non-empty string
132
+ * - `action` is declared in `spec` (a flat `Record<actionName,
133
+ * ActionEntry>` post-2026-04-22 flatten)
134
+ * - If the declared action has a `schema`, `data` matches it
135
+ *
136
+ * Actions without a declared schema are void-payload (fire-and-forget) — a
137
+ * present-but-unexpected `data` is tolerated to stay forward-compatible with
138
+ * clients that attach UI metadata the contract doesn't model. Contracts that
139
+ * want strict emptiness should declare `schema: { type: 'null' }`.
140
+ */
141
+ export declare function validateActionData(value: unknown, spec: ActionSpec, precompiledActions?: ReadonlyMap<string, ValidateFunction>): ValidationResult;
142
+ /**
143
+ * Validate an inbound {@link ActionEnvelope} against the target stack
144
+ * item's {@link ActionSpec}. Payload-contract layer of live-channel
145
+ * inbound enforcement — the allowlist gate (`assertEventAllowed` in
146
+ * `@ggui-ai/mcp-server-handlers`) is a separate concern that runs
147
+ * first.
148
+ *
149
+ * Semantics:
150
+ * - `envelope.type !== 'data:submit'` → `{valid: true, violations: []}`.
151
+ * Only action submissions carry payload contract today; other
152
+ * event types (lifecycle, interaction, error) have no schema
153
+ * enforcement on this layer.
154
+ * - `spec === undefined` → `{valid: true, violations: []}`. Stack
155
+ * items without an actionSpec have no contract; legacy pushes keep
156
+ * flowing.
157
+ * - Otherwise `envelope.payload` is validated against `spec` via
158
+ * {@link validateActionData}. Same rules, same output shape.
159
+ *
160
+ * This helper does NOT enforce allowlist, session binding, or stack
161
+ * routing — those are ingress-plumbing concerns. Pure payload-shape
162
+ * check; returns `ValidationResult` rather than throwing so callers
163
+ * can decide whether to surface as a wire error, log, etc.
164
+ */
165
+ export declare function validateActionEnvelope(envelope: ActionEnvelope, spec: ActionSpec | undefined, precompiledActions?: ReadonlyMap<string, ValidateFunction>): ValidationResult;
166
+ /**
167
+ * Compile a contract's runtime-validated sub-schemas into standalone,
168
+ * eval-free ESM validator modules — the producer half of the
169
+ * precompiled-validator channel
170
+ * ({@link CompiledContractValidators} on `GguiBootstrapMeta`).
171
+ *
172
+ * The renderer iframe runs under a strict CSP with no `'unsafe-eval'`,
173
+ * so it cannot call `ajv.compile()` (which builds validators via
174
+ * `new Function`). Compilation therefore happens server-side at push
175
+ * time — where the contract schema is fixed and codegen is legal — and
176
+ * the iframe loads each emitted module via a `blob:` dynamic import.
177
+ *
178
+ * One module per runtime-validated surface, matching the four runtime
179
+ * validators in this file exactly (no second contract model):
180
+ *
181
+ * - `props` — the synthesized object wrapper from
182
+ * {@link buildPropsWrapperSchema}, as {@link validatePropsData}
183
+ * validates `props`.
184
+ * - `actions` — per-action `entry.schema`, as {@link validateActionData}
185
+ * validates `data`. Void actions (no `schema`) contribute no entry.
186
+ * - `streams` — per-channel `entry.schema`, as {@link validateStreamData}
187
+ * validates `payload`.
188
+ * - `context` — per-slot `entry.schema`, as {@link validateContextData}
189
+ * validates `value`.
190
+ *
191
+ * Returns `undefined` when the contract declares no runtime-validated
192
+ * schema at all — the bootstrap projection then omits the field.
193
+ */
194
+ export declare function compileContractValidators(specs: {
195
+ readonly propsSpec?: PropsSpec;
196
+ readonly actionSpec?: ActionSpec;
197
+ readonly streamSpec?: StreamSpec;
198
+ readonly contextSpec?: ContextSpec;
199
+ }): CompiledContractValidators | undefined;
200
+ /**
201
+ * Format violations into a human-readable error message for the target agent.
202
+ */
203
+ export declare function formatViolations(violations: ContractViolation[]): string;
204
+ /**
205
+ * Validate the contract structure itself — catches malformed contract
206
+ * before they're persisted and used to validate runtime data.
207
+ *
208
+ * Checks:
209
+ * - PropsSpec properties have valid schemas (type or oneOf/anyOf defined)
210
+ * - Array schemas have items defined (otherwise element validation is impossible)
211
+ * - Object schemas with required fields reference existing properties
212
+ * - StreamSpec channels have schemas defined (reserved-prefix names rejected)
213
+ * - ActionSpec actions have schemas defined
214
+ * - ContextSpec slots: identifier-shape keys, no reserved keys
215
+ * (`__proto__`/`constructor`/`prototype`), schema present, default
216
+ * satisfies schema, debounceMs is a non-negative integer, no key
217
+ * collision with propsSpec, and `deriveContextDefault` yields a
218
+ * non-undefined initial value (see `validateContextStructure`).
219
+ * - Cross-reference invariants (`actionSpec.nextStep`,
220
+ * `streamSpec.source.tool` resolve to `agentCapabilities.tools[*]`).
221
+ * - Name invariants (no collision across actionSpec / streamSpec /
222
+ * contextSpec; no `_ggui:` reserved-prefix keys).
223
+ * - Schema-compat invariants (`actionSpec[*].schema` ⊆
224
+ * `tool.inputSchema`; `streamSpec[*].schema` ⊇ `tool.outputSchema`).
225
+ */
226
+ export declare function validateContractStructure(contract: DataContract): ValidationResult;
227
+ export declare class ContractViolationError extends Error {
228
+ readonly violations: ContractViolation[];
229
+ readonly tool: 'ggui_push' | 'ggui_update' | 'ggui_emit' | 'ggui_event';
230
+ readonly hint: string;
231
+ constructor(opts: {
232
+ tool: 'ggui_push' | 'ggui_update' | 'ggui_emit' | 'ggui_event';
233
+ violations: ContractViolation[];
234
+ hint?: string;
235
+ });
236
+ /** Structured payload for MCP error response `data` field. */
237
+ toErrorData(): {
238
+ error: 'contract_violation';
239
+ tool: string;
240
+ violations: ContractViolation[];
241
+ hint: string;
242
+ };
243
+ }
244
+ //# sourceMappingURL=contract-validator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"contract-validator.d.ts","sourceRoot":"","sources":["../../src/validation/contract-validator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,UAAU,EAAE,WAAW,EAAE,UAAU,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAEnI,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACtD,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,0BAA0B,CAAC;AAO3E,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAItD,YAAY,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAItD,OAAO,EAKL,KAAK,wBAAwB,EAC9B,MAAM,qBAAqB,CAAC;AAE7B,MAAM,WAAW,iBAAkB,SAAQ,UAAU;IACnD,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,gBAAgB;IAC/B,KAAK,EAAE,OAAO,CAAC;IACf,UAAU,EAAE,iBAAiB,EAAE,CAAC;CACjC;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,SAAS,GAAG,UAAU,CAcnE;AAED;;;;;;;;;;;;;;;;GAgBG;AACH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