agenthooksprotocol 0.0.0-bootstrap.0

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 (151) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +29 -0
  3. package/dist/src/client/auth.d.ts +147 -0
  4. package/dist/src/client/auth.d.ts.map +1 -0
  5. package/dist/src/client/auth.js +629 -0
  6. package/dist/src/client/auth.js.map +1 -0
  7. package/dist/src/client/composition.d.ts +42 -0
  8. package/dist/src/client/composition.d.ts.map +1 -0
  9. package/dist/src/client/composition.js +523 -0
  10. package/dist/src/client/composition.js.map +1 -0
  11. package/dist/src/client/content.d.ts +73 -0
  12. package/dist/src/client/content.d.ts.map +1 -0
  13. package/dist/src/client/content.js +404 -0
  14. package/dist/src/client/content.js.map +1 -0
  15. package/dist/src/client/hooks.d.ts +62 -0
  16. package/dist/src/client/hooks.d.ts.map +1 -0
  17. package/dist/src/client/hooks.js +997 -0
  18. package/dist/src/client/hooks.js.map +1 -0
  19. package/dist/src/client/index.d.ts +11 -0
  20. package/dist/src/client/index.d.ts.map +1 -0
  21. package/dist/src/client/index.js +9 -0
  22. package/dist/src/client/index.js.map +1 -0
  23. package/dist/src/client/transport.d.ts +12 -0
  24. package/dist/src/client/transport.d.ts.map +1 -0
  25. package/dist/src/client/transport.js +347 -0
  26. package/dist/src/client/transport.js.map +1 -0
  27. package/dist/src/client/types.d.ts +117 -0
  28. package/dist/src/client/types.d.ts.map +1 -0
  29. package/dist/src/client/types.js +10 -0
  30. package/dist/src/client/types.js.map +1 -0
  31. package/dist/src/client/validation.d.ts +3 -0
  32. package/dist/src/client/validation.d.ts.map +1 -0
  33. package/dist/src/client/validation.js +25 -0
  34. package/dist/src/client/validation.js.map +1 -0
  35. package/dist/src/compaction.d.ts +27 -0
  36. package/dist/src/compaction.d.ts.map +1 -0
  37. package/dist/src/compaction.js +155 -0
  38. package/dist/src/compaction.js.map +1 -0
  39. package/dist/src/content-upload.d.ts +60 -0
  40. package/dist/src/content-upload.d.ts.map +1 -0
  41. package/dist/src/content-upload.js +129 -0
  42. package/dist/src/content-upload.js.map +1 -0
  43. package/dist/src/draft/generated.d.ts +3085 -0
  44. package/dist/src/draft/generated.d.ts.map +1 -0
  45. package/dist/src/draft/generated.js +15372 -0
  46. package/dist/src/draft/generated.js.map +1 -0
  47. package/dist/src/draft/index.d.ts +31 -0
  48. package/dist/src/draft/index.d.ts.map +1 -0
  49. package/dist/src/draft/index.js +129 -0
  50. package/dist/src/draft/index.js.map +1 -0
  51. package/dist/src/draft/schemas.d.ts +8848 -0
  52. package/dist/src/draft/schemas.d.ts.map +1 -0
  53. package/dist/src/draft/schemas.js +9219 -0
  54. package/dist/src/draft/schemas.js.map +1 -0
  55. package/dist/src/draft-atomic.d.ts +18 -0
  56. package/dist/src/draft-atomic.d.ts.map +1 -0
  57. package/dist/src/draft-atomic.js +102 -0
  58. package/dist/src/draft-atomic.js.map +1 -0
  59. package/dist/src/draft-runtime.d.ts +89 -0
  60. package/dist/src/draft-runtime.d.ts.map +1 -0
  61. package/dist/src/draft-runtime.js +242 -0
  62. package/dist/src/draft-runtime.js.map +1 -0
  63. package/dist/src/elicitation.d.ts +18 -0
  64. package/dist/src/elicitation.d.ts.map +1 -0
  65. package/dist/src/elicitation.js +191 -0
  66. package/dist/src/elicitation.js.map +1 -0
  67. package/dist/src/errors.d.ts +7 -0
  68. package/dist/src/errors.d.ts.map +1 -0
  69. package/dist/src/errors.js +15 -0
  70. package/dist/src/errors.js.map +1 -0
  71. package/dist/src/framing.d.ts +7 -0
  72. package/dist/src/framing.d.ts.map +1 -0
  73. package/dist/src/framing.js +39 -0
  74. package/dist/src/framing.js.map +1 -0
  75. package/dist/src/generated.d.ts +304 -0
  76. package/dist/src/generated.d.ts.map +1 -0
  77. package/dist/src/generated.js +1885 -0
  78. package/dist/src/generated.js.map +1 -0
  79. package/dist/src/hook-runner.d.ts +11 -0
  80. package/dist/src/hook-runner.d.ts.map +1 -0
  81. package/dist/src/hook-runner.js +223 -0
  82. package/dist/src/hook-runner.js.map +1 -0
  83. package/dist/src/index.d.ts +8 -0
  84. package/dist/src/index.d.ts.map +1 -0
  85. package/dist/src/index.js +8 -0
  86. package/dist/src/index.js.map +1 -0
  87. package/dist/src/observation.d.ts +26 -0
  88. package/dist/src/observation.d.ts.map +1 -0
  89. package/dist/src/observation.js +28 -0
  90. package/dist/src/observation.js.map +1 -0
  91. package/dist/src/server/attachments.d.ts +29 -0
  92. package/dist/src/server/attachments.d.ts.map +1 -0
  93. package/dist/src/server/attachments.js +112 -0
  94. package/dist/src/server/attachments.js.map +1 -0
  95. package/dist/src/server/hooks.d.ts +20 -0
  96. package/dist/src/server/hooks.d.ts.map +1 -0
  97. package/dist/src/server/hooks.js +129 -0
  98. package/dist/src/server/hooks.js.map +1 -0
  99. package/dist/src/server/index.d.ts +7 -0
  100. package/dist/src/server/index.d.ts.map +1 -0
  101. package/dist/src/server/index.js +4 -0
  102. package/dist/src/server/index.js.map +1 -0
  103. package/dist/src/server/stdio.d.ts +15 -0
  104. package/dist/src/server/stdio.d.ts.map +1 -0
  105. package/dist/src/server/stdio.js +69 -0
  106. package/dist/src/server/stdio.js.map +1 -0
  107. package/dist/src/transport.d.ts +7 -0
  108. package/dist/src/transport.d.ts.map +1 -0
  109. package/dist/src/transport.js +195 -0
  110. package/dist/src/transport.js.map +1 -0
  111. package/dist/src/types.d.ts +116 -0
  112. package/dist/src/types.d.ts.map +1 -0
  113. package/dist/src/types.js +14 -0
  114. package/dist/src/types.js.map +1 -0
  115. package/dist/src/validation.d.ts +7 -0
  116. package/dist/src/validation.d.ts.map +1 -0
  117. package/dist/src/validation.js +209 -0
  118. package/dist/src/validation.js.map +1 -0
  119. package/package.json +64 -0
  120. package/src/client/auth.ts +1076 -0
  121. package/src/client/composition.ts +708 -0
  122. package/src/client/content.ts +510 -0
  123. package/src/client/hooks.ts +1368 -0
  124. package/src/client/index.ts +28 -0
  125. package/src/client/transport.ts +408 -0
  126. package/src/client/types.ts +173 -0
  127. package/src/client/validation.ts +24 -0
  128. package/src/compaction.ts +196 -0
  129. package/src/content-upload.ts +205 -0
  130. package/src/draft/README.md +16 -0
  131. package/src/draft/ahp-codegen.lock.json +123 -0
  132. package/src/draft/generated.ts +19143 -0
  133. package/src/draft/index.ts +246 -0
  134. package/src/draft/schemas.ts +9413 -0
  135. package/src/draft-atomic.ts +119 -0
  136. package/src/draft-runtime.ts +365 -0
  137. package/src/elicitation.ts +254 -0
  138. package/src/errors.ts +30 -0
  139. package/src/framing.ts +56 -0
  140. package/src/generated.ts +2408 -0
  141. package/src/hook-runner.ts +310 -0
  142. package/src/index.ts +8 -0
  143. package/src/observation.ts +65 -0
  144. package/src/server/attachments.ts +128 -0
  145. package/src/server/hooks.ts +205 -0
  146. package/src/server/index.ts +18 -0
  147. package/src/server/node-crypto.d.ts +7 -0
  148. package/src/server/stdio.ts +81 -0
  149. package/src/transport.ts +273 -0
  150. package/src/types.ts +124 -0
  151. package/src/validation.ts +372 -0
@@ -0,0 +1,246 @@
1
+ /** Canonical draft validation and synthetic, request-capability-gated runtime slices. */
2
+ import { Ajv2020 } from "ajv/dist/2020.js";
3
+ import type { ValidateFunction } from "ajv";
4
+ import { fullFormats } from "ajv-formats/dist/formats.js";
5
+ import { schemas } from "./schemas.js";
6
+ import {
7
+ parseEffect as decodeEffect,
8
+ parseInterceptRequest as decodeRequest,
9
+ parseInterceptResponse as decodeResponse,
10
+ parseCapabilities as decodeCapabilities,
11
+ parseCapabilitiesRequest as decodeCapabilitiesRequest,
12
+ parseCapabilitiesResponse as decodeCapabilitiesResponse,
13
+ parseObserveNotification as decodeObserveNotification,
14
+ parseRegistration as decodeRegistration,
15
+ } from "./generated.js";
16
+ import type {
17
+ Effect,
18
+ InterceptRequest,
19
+ InterceptResponse,
20
+ Capabilities,
21
+ CapabilitiesRequest,
22
+ CapabilitiesResponse,
23
+ ParseResult,
24
+ ObserveNotification,
25
+ Registration,
26
+ } from "./generated.js";
27
+
28
+ export type {
29
+ InterceptRequest,
30
+ InterceptResponse,
31
+ Effect,
32
+ Capabilities,
33
+ JsonValue,
34
+ } from "./generated.js";
35
+ export * as draftCodecs from "./generated.js";
36
+ export { PROTOCOL_VERSION, SCHEMA_REVISION } from "./generated.js";
37
+ export { stageResponse, decide } from "../draft-atomic.js";
38
+ export type { PendingState } from "../draft-atomic.js";
39
+
40
+ export type DraftValidationResult<T> =
41
+ | { readonly ok: true; readonly value: T }
42
+ | { readonly ok: false; readonly errors: readonly string[] };
43
+
44
+ // Initialize canonical validation only when used; the narrow root runner does not
45
+ // pay catalogue compilation costs while starting a short-lived stdio backend.
46
+ let registry: Ajv2020 | undefined;
47
+ const base = "https://agenthooksprotocol.org/schemas/draft/";
48
+ function validator(name: string): ValidateFunction {
49
+ if (registry === undefined) {
50
+ // No coercion, default insertion, removal of unknown fields, or partial acceptance.
51
+ registry = new Ajv2020({
52
+ allErrors: true,
53
+ strict: false,
54
+ ownProperties: true,
55
+ });
56
+ registry.addFormat("uri", fullFormats.uri);
57
+ registry.addFormat("date-time", fullFormats["date-time"]);
58
+ for (const schema of schemas) registry.addSchema(schema);
59
+ }
60
+ return registry.getSchema(base + name + ".schema.json")!;
61
+ }
62
+
63
+ // JSON Schema operates on JSON, not arbitrary JS objects (NaN, undefined, cycles, etc.).
64
+ function isJson(value: unknown, ancestors = new Set<object>()): boolean {
65
+ if (value === null || typeof value === "string" || typeof value === "boolean")
66
+ return true;
67
+ if (typeof value === "number") return Number.isFinite(value);
68
+ if (typeof value !== "object" || ancestors.has(value)) return false;
69
+ const prototype: unknown = Object.getPrototypeOf(value);
70
+ if (
71
+ !Array.isArray(value) &&
72
+ prototype !== Object.prototype &&
73
+ prototype !== null
74
+ )
75
+ return false;
76
+ ancestors.add(value);
77
+ const valid = Array.isArray(value)
78
+ ? Object.keys(value).length === value.length &&
79
+ Array.from(value).every((item) => isJson(item, ancestors))
80
+ : Reflect.ownKeys(value).every((key) => {
81
+ const property = Object.getOwnPropertyDescriptor(value, key);
82
+ return (
83
+ typeof key === "string" &&
84
+ property?.enumerable === true &&
85
+ "value" in property &&
86
+ isJson(property.value, ancestors)
87
+ );
88
+ });
89
+ ancestors.delete(value);
90
+ return valid;
91
+ }
92
+
93
+ function validate<T>(
94
+ value: unknown,
95
+ canonical: ValidateFunction,
96
+ decode: (value: unknown) => ParseResult<T>,
97
+ ): DraftValidationResult<T> {
98
+ try {
99
+ if (!isJson(value))
100
+ return { ok: false, errors: ["Expected a finite, acyclic JSON value"] };
101
+ if (!canonical(value)) {
102
+ return {
103
+ ok: false,
104
+ errors: (canonical.errors ?? []).map(
105
+ (error) =>
106
+ `${error.instancePath || "/"}: ${error.message ?? error.keyword}`,
107
+ ),
108
+ };
109
+ }
110
+ // Generated decoding is deliberately permissive; canonical validation above is mandatory.
111
+ const decoded = decode(value);
112
+ return decoded.ok
113
+ ? { ok: true, value: decoded.value }
114
+ : {
115
+ ok: false,
116
+ errors: decoded.diagnostics.map(
117
+ (error) => `${error.path}: ${error.message}`,
118
+ ),
119
+ };
120
+ } catch (error) {
121
+ return {
122
+ ok: false,
123
+ errors: [error instanceof Error ? error.message : String(error)],
124
+ };
125
+ }
126
+ }
127
+
128
+ /** Strict canonical validation for transport-neutral notification consumers. */
129
+ export function validateObserveNotification(
130
+ value: unknown,
131
+ ): DraftValidationResult<ObserveNotification> {
132
+ return validate(
133
+ value,
134
+ validator("observe-notification"),
135
+ decodeObserveNotification,
136
+ );
137
+ }
138
+
139
+ /** Schema/codec validation only; Hooks initialization resolves host capabilities. */
140
+ export function validateRegistration(
141
+ value: unknown,
142
+ ): DraftValidationResult<Registration> {
143
+ return validate(value, validator("registration"), decodeRegistration);
144
+ }
145
+
146
+ export function validateEffect(value: unknown): DraftValidationResult<Effect> {
147
+ return validate(value, validator("effect"), decodeEffect);
148
+ }
149
+
150
+ export function validateCapabilities(
151
+ value: unknown,
152
+ ): DraftValidationResult<Capabilities> {
153
+ return validate(value, validator("capabilities"), decodeCapabilities);
154
+ }
155
+ export function validateCapabilitiesRequest(
156
+ value: unknown,
157
+ ): DraftValidationResult<CapabilitiesRequest> {
158
+ return validate(
159
+ value,
160
+ validator("capabilities-request"),
161
+ decodeCapabilitiesRequest,
162
+ );
163
+ }
164
+ export function validateCapabilitiesResponse(
165
+ value: unknown,
166
+ ): DraftValidationResult<CapabilitiesResponse> {
167
+ return validate(
168
+ value,
169
+ validator("capabilities-response"),
170
+ decodeCapabilitiesResponse,
171
+ );
172
+ }
173
+
174
+ export function validateInterceptRequest(
175
+ value: unknown,
176
+ ): DraftValidationResult<InterceptRequest> {
177
+ const result = validate(value, validator("intercept-request"), decodeRequest);
178
+ if (result.ok && result.value.id !== result.value.params.event.id)
179
+ return { ok: false, errors: ["Request id must equal event id"] };
180
+ return result;
181
+ }
182
+
183
+ export function validateInterceptResponse(
184
+ value: unknown,
185
+ ): DraftValidationResult<InterceptResponse> {
186
+ return validate(value, validator("intercept-response"), decodeResponse);
187
+ }
188
+
189
+ function parse<T>(
190
+ text: string,
191
+ validator: (value: unknown) => DraftValidationResult<T>,
192
+ ): DraftValidationResult<T> {
193
+ try {
194
+ return validator(JSON.parse(text) as unknown);
195
+ } catch (error) {
196
+ return {
197
+ ok: false,
198
+ errors: [error instanceof Error ? error.message : String(error)],
199
+ };
200
+ }
201
+ }
202
+
203
+ export function parseInterceptRequest(
204
+ text: string,
205
+ ): DraftValidationResult<InterceptRequest> {
206
+ return parse(text, validateInterceptRequest);
207
+ }
208
+
209
+ export function parseInterceptResponse(
210
+ text: string,
211
+ ): DraftValidationResult<InterceptResponse> {
212
+ return parse(text, validateInterceptResponse);
213
+ }
214
+
215
+ export {
216
+ uploadContent,
217
+ prepareWireContent,
218
+ stageBoundary,
219
+ dispatchBoundary,
220
+ ContentReceiver,
221
+ prepareContent,
222
+ Lineage,
223
+ actualTaskChange,
224
+ } from "../draft-runtime.js";
225
+ export type {
226
+ BoundaryState,
227
+ BoundaryCapabilities,
228
+ BoundaryEffect,
229
+ Delivery,
230
+ ContentItem,
231
+ ContentView,
232
+ } from "../draft-runtime.js";
233
+
234
+ export type {
235
+ UploadConfiguration,
236
+ BodyReference,
237
+ NormalizedContentInput,
238
+ NormalizedContentView,
239
+ } from "../content-upload.js";
240
+
241
+ export { dispatchObservations } from "../observation.js";
242
+ export type {
243
+ ObservationSubscription,
244
+ ObservationEvent,
245
+ ObservationNotification,
246
+ } from "../observation.js";