@wheatley-ai/cli 0.0.0-stage → 0.1.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 (210) hide show
  1. package/LICENSE +15 -0
  2. package/bin/wheatley.js +2 -0
  3. package/dist/approvals/gate.js +278 -0
  4. package/dist/approvals/module.js +21 -0
  5. package/dist/approvals/policy.js +30 -0
  6. package/dist/approvals/preview.js +17 -0
  7. package/dist/approvals/prompt.js +98 -0
  8. package/dist/approvals/rpc.js +16 -0
  9. package/dist/approvals/store.js +159 -0
  10. package/dist/cli/ask.js +94 -0
  11. package/dist/cli/chat.js +178 -0
  12. package/dist/cli/client.js +104 -0
  13. package/dist/cli/daemon.js +35 -0
  14. package/dist/cli/init.js +72 -0
  15. package/dist/cli/io.js +45 -0
  16. package/dist/cli/main.js +206 -0
  17. package/dist/cli/session.js +86 -0
  18. package/dist/cli/status.js +46 -0
  19. package/dist/contracts/approval-gate.js +1 -0
  20. package/dist/contracts/config-store.js +1 -0
  21. package/dist/contracts/delivery-outbox.js +1 -0
  22. package/dist/contracts/errors.js +28 -0
  23. package/dist/contracts/extension-catalog.js +1 -0
  24. package/dist/contracts/maintenance-runner.js +1 -0
  25. package/dist/contracts/memory-store.js +1 -0
  26. package/dist/contracts/module.js +7 -0
  27. package/dist/contracts/tool-names.js +43 -0
  28. package/dist/contracts/trigger-runtime.js +1 -0
  29. package/dist/contracts/webhook-ingress.js +2 -0
  30. package/dist/core/agent/agent-store.js +300 -0
  31. package/dist/core/agent/agent.js +1033 -0
  32. package/dist/core/agent/gated-models.js +89 -0
  33. package/dist/core/agent/pi-adapter.js +401 -0
  34. package/dist/core/agent/policy-gate.js +44 -0
  35. package/dist/core/builtin-catalog.js +20 -0
  36. package/dist/core/concurrency-gate.js +87 -0
  37. package/dist/core/config/atomic-file.js +72 -0
  38. package/dist/core/config/config-store.js +138 -0
  39. package/dist/core/config/pending-restart.js +53 -0
  40. package/dist/core/config/secret-references.js +69 -0
  41. package/dist/core/config/secret-store.js +147 -0
  42. package/dist/core/config/validate.js +55 -0
  43. package/dist/core/config/yaml-patch.js +57 -0
  44. package/dist/core/daemon-socket.js +96 -0
  45. package/dist/core/daemon.js +97 -0
  46. package/dist/core/deployment.js +379 -0
  47. package/dist/core/error-message.js +4 -0
  48. package/dist/core/events.js +25 -0
  49. package/dist/core/logger.js +81 -0
  50. package/dist/core/models.js +27 -0
  51. package/dist/core/module.js +42 -0
  52. package/dist/core/rpc/agent-handlers.js +82 -0
  53. package/dist/core/rpc/deployment-handlers.js +63 -0
  54. package/dist/core/rpc/router.js +96 -0
  55. package/dist/core/server/connection.js +170 -0
  56. package/dist/core/server/control-server.js +152 -0
  57. package/dist/core/server/static-files.js +79 -0
  58. package/dist/core/supervisor.js +215 -0
  59. package/dist/core/tool-routing.js +41 -0
  60. package/dist/dashboard/assets/index-C9Rul5vE.css +2 -0
  61. package/dist/dashboard/assets/index-DXzGGAxQ.js +11 -0
  62. package/dist/dashboard/assets/sheet-presentation-DMljN0LW.js +1 -0
  63. package/dist/dashboard/index.html +18 -0
  64. package/dist/db/database.js +16 -0
  65. package/dist/db/migrations.js +184 -0
  66. package/dist/frontends/discord/approvals.js +199 -0
  67. package/dist/frontends/discord/attachments.js +115 -0
  68. package/dist/frontends/discord/binding.js +489 -0
  69. package/dist/frontends/discord/config.js +107 -0
  70. package/dist/frontends/discord/discord-runtime.js +52 -0
  71. package/dist/frontends/discord/errors.js +61 -0
  72. package/dist/frontends/discord/live-runs.js +189 -0
  73. package/dist/frontends/discord/module.js +39 -0
  74. package/dist/frontends/discord/recent-ids.js +20 -0
  75. package/dist/frontends/slack/approval-blocks.js +98 -0
  76. package/dist/frontends/slack/attachments.js +102 -0
  77. package/dist/frontends/slack/background-tasks.js +20 -0
  78. package/dist/frontends/slack/binding.js +405 -0
  79. package/dist/frontends/slack/bounded.js +9 -0
  80. package/dist/frontends/slack/chat-id.js +17 -0
  81. package/dist/frontends/slack/config.js +80 -0
  82. package/dist/frontends/slack/delivery-errors.js +81 -0
  83. package/dist/frontends/slack/inbound.js +76 -0
  84. package/dist/frontends/slack/live-progress.js +190 -0
  85. package/dist/frontends/slack/manifest.js +66 -0
  86. package/dist/frontends/slack/outbound.js +160 -0
  87. package/dist/frontends/slack/schemas.js +99 -0
  88. package/dist/frontends/slack/signature.js +30 -0
  89. package/dist/frontends/slack/slack-client.js +60 -0
  90. package/dist/frontends/slack/slack-frontend.js +38 -0
  91. package/dist/frontends/slack/state-store.js +112 -0
  92. package/dist/frontends/telegram/approvals.js +134 -0
  93. package/dist/frontends/telegram/attachments.js +126 -0
  94. package/dist/frontends/telegram/binding.js +144 -0
  95. package/dist/frontends/telegram/chat-key.js +43 -0
  96. package/dist/frontends/telegram/client.js +88 -0
  97. package/dist/frontends/telegram/config.js +93 -0
  98. package/dist/frontends/telegram/delivery.js +215 -0
  99. package/dist/frontends/telegram/frontend.js +42 -0
  100. package/dist/frontends/telegram/grammy-client.js +122 -0
  101. package/dist/frontends/telegram/http-status.js +6 -0
  102. package/dist/frontends/telegram/inbound.js +149 -0
  103. package/dist/frontends/telegram/live.js +182 -0
  104. package/dist/frontends/telegram/markdown.js +103 -0
  105. package/dist/frontends/telegram/recent-set.js +18 -0
  106. package/dist/frontends/telegram/serial-queue.js +23 -0
  107. package/dist/index.js +7 -0
  108. package/dist/mcp/content.js +61 -0
  109. package/dist/mcp/mcp-module.js +35 -0
  110. package/dist/mcp/mcp-tool-provider.js +93 -0
  111. package/dist/mcp/server-connection.js +297 -0
  112. package/dist/memory/consolidation.js +260 -0
  113. package/dist/memory/format.js +5 -0
  114. package/dist/memory/migrations.js +76 -0
  115. package/dist/memory/module.js +69 -0
  116. package/dist/memory/names.js +20 -0
  117. package/dist/memory/rows.js +22 -0
  118. package/dist/memory/rpc.js +49 -0
  119. package/dist/memory/snapshots.js +12 -0
  120. package/dist/memory/store.js +281 -0
  121. package/dist/memory/tools.js +158 -0
  122. package/dist/node_modules/@wheatley-ai/protocol/dist/config.d.ts +262 -0
  123. package/dist/node_modules/@wheatley-ai/protocol/dist/config.js +120 -0
  124. package/dist/node_modules/@wheatley-ai/protocol/dist/domain.d.ts +512 -0
  125. package/dist/node_modules/@wheatley-ai/protocol/dist/domain.js +441 -0
  126. package/dist/node_modules/@wheatley-ai/protocol/dist/duration.d.ts +8 -0
  127. package/dist/node_modules/@wheatley-ai/protocol/dist/duration.js +28 -0
  128. package/dist/node_modules/@wheatley-ai/protocol/dist/events.d.ts +234 -0
  129. package/dist/node_modules/@wheatley-ai/protocol/dist/events.js +124 -0
  130. package/dist/node_modules/@wheatley-ai/protocol/dist/index.d.ts +11 -0
  131. package/dist/node_modules/@wheatley-ai/protocol/dist/index.js +11 -0
  132. package/dist/node_modules/@wheatley-ai/protocol/dist/json-rpc.d.ts +81 -0
  133. package/dist/node_modules/@wheatley-ai/protocol/dist/json-rpc.js +157 -0
  134. package/dist/node_modules/@wheatley-ai/protocol/dist/json.d.ts +14 -0
  135. package/dist/node_modules/@wheatley-ai/protocol/dist/json.js +23 -0
  136. package/dist/node_modules/@wheatley-ai/protocol/dist/limits.d.ts +17 -0
  137. package/dist/node_modules/@wheatley-ai/protocol/dist/limits.js +17 -0
  138. package/dist/node_modules/@wheatley-ai/protocol/dist/methods.d.ts +1107 -0
  139. package/dist/node_modules/@wheatley-ai/protocol/dist/methods.js +201 -0
  140. package/dist/node_modules/@wheatley-ai/protocol/dist/rpc-error.d.ts +45 -0
  141. package/dist/node_modules/@wheatley-ai/protocol/dist/rpc-error.js +44 -0
  142. package/dist/node_modules/@wheatley-ai/protocol/dist/validation.d.ts +20 -0
  143. package/dist/node_modules/@wheatley-ai/protocol/dist/validation.js +11 -0
  144. package/dist/node_modules/@wheatley-ai/protocol/package.json +14 -0
  145. package/dist/node_modules/@wheatley-ai/sdk/dist/chunk.d.ts +11 -0
  146. package/dist/node_modules/@wheatley-ai/sdk/dist/chunk.js +162 -0
  147. package/dist/node_modules/@wheatley-ai/sdk/dist/commands.d.ts +48 -0
  148. package/dist/node_modules/@wheatley-ai/sdk/dist/commands.js +39 -0
  149. package/dist/node_modules/@wheatley-ai/sdk/dist/delivery-error.d.ts +29 -0
  150. package/dist/node_modules/@wheatley-ai/sdk/dist/delivery-error.js +27 -0
  151. package/dist/node_modules/@wheatley-ai/sdk/dist/frontend.d.ts +236 -0
  152. package/dist/node_modules/@wheatley-ai/sdk/dist/frontend.js +2 -0
  153. package/dist/node_modules/@wheatley-ai/sdk/dist/index.d.ts +10 -0
  154. package/dist/node_modules/@wheatley-ai/sdk/dist/index.js +7 -0
  155. package/dist/node_modules/@wheatley-ai/sdk/dist/json.d.ts +9 -0
  156. package/dist/node_modules/@wheatley-ai/sdk/dist/json.js +2 -0
  157. package/dist/node_modules/@wheatley-ai/sdk/dist/logger.d.ts +18 -0
  158. package/dist/node_modules/@wheatley-ai/sdk/dist/logger.js +2 -0
  159. package/dist/node_modules/@wheatley-ai/sdk/dist/plugin.d.ts +48 -0
  160. package/dist/node_modules/@wheatley-ai/sdk/dist/plugin.js +5 -0
  161. package/dist/node_modules/@wheatley-ai/sdk/dist/schema.d.ts +69 -0
  162. package/dist/node_modules/@wheatley-ai/sdk/dist/schema.js +3 -0
  163. package/dist/node_modules/@wheatley-ai/sdk/dist/tool.d.ts +69 -0
  164. package/dist/node_modules/@wheatley-ai/sdk/dist/tool.js +3 -0
  165. package/dist/node_modules/@wheatley-ai/sdk/package.json +11 -0
  166. package/dist/ops/backup.js +185 -0
  167. package/dist/ops/cli.js +194 -0
  168. package/dist/ops/command-runner.js +34 -0
  169. package/dist/ops/dashboard-assets.js +37 -0
  170. package/dist/ops/migrate.js +63 -0
  171. package/dist/ops/module.js +47 -0
  172. package/dist/ops/paths.js +55 -0
  173. package/dist/ops/service.js +376 -0
  174. package/dist/ops/update.js +145 -0
  175. package/dist/plugins/contributions.js +89 -0
  176. package/dist/plugins/guards.js +111 -0
  177. package/dist/plugins/load.js +76 -0
  178. package/dist/plugins/module.js +31 -0
  179. package/dist/plugins/provider.js +349 -0
  180. package/dist/plugins/schema.js +69 -0
  181. package/dist/skills/disclosure.js +142 -0
  182. package/dist/skills/discovery.js +120 -0
  183. package/dist/skills/fs-errors.js +8 -0
  184. package/dist/skills/read-skill-tool.js +3 -0
  185. package/dist/skills/skill-file.js +90 -0
  186. package/dist/skills/skills.js +140 -0
  187. package/dist/tools/builtin-tools.js +61 -0
  188. package/dist/tools/input.js +45 -0
  189. package/dist/tools/paths.js +6 -0
  190. package/dist/tools/read-file.js +65 -0
  191. package/dist/tools/shell.js +156 -0
  192. package/dist/tools/write-file.js +58 -0
  193. package/dist/triggers/delivery-codec.js +99 -0
  194. package/dist/triggers/delivery-outbox.js +313 -0
  195. package/dist/triggers/due-timer.js +14 -0
  196. package/dist/triggers/errors.js +2 -0
  197. package/dist/triggers/migrations.js +91 -0
  198. package/dist/triggers/module.js +106 -0
  199. package/dist/triggers/rpc.js +35 -0
  200. package/dist/triggers/schedule.js +52 -0
  201. package/dist/triggers/sql-row.js +59 -0
  202. package/dist/triggers/trigger-runtime.js +445 -0
  203. package/dist/triggers/trigger-tools.js +210 -0
  204. package/dist/triggers/webhook-ingress.js +212 -0
  205. package/dist/wiring/agent-services.js +151 -0
  206. package/dist/wiring/catalog.js +81 -0
  207. package/dist/wiring/daemon.js +83 -0
  208. package/dist/wiring/frontend-host.js +268 -0
  209. package/package.json +50 -3
  210. package/README.md +0 -3
@@ -0,0 +1,234 @@
1
+ import { Type } from "typebox";
2
+ import type { Static } from "typebox";
3
+ /**
4
+ * Every v1 live event that the daemon sends as a JSON-RPC notification. The notification `method` is the event name
5
+ * and `params` is the payload (ADR 0003, ADR 0005).
6
+ *
7
+ * On one connection, the response to a request always arrives before the events that the request caused.
8
+ */
9
+ export declare const events: {
10
+ readonly "agent.status": Type.TObject<{
11
+ agent: Type.TString;
12
+ error: Type.TOptional<Type.TString>;
13
+ state: Type.TUnion<[Type.TLiteral<"starting">, Type.TLiteral<"running">, Type.TLiteral<"degraded">, Type.TLiteral<"stopped">]>;
14
+ }>;
15
+ /** Every client receives it. The first `approvals.decide` call wins. */
16
+ readonly "approval.requested": Type.TObject<{
17
+ agent: Type.TString;
18
+ approval: Type.TObject<{
19
+ agent: Type.TString;
20
+ approvalId: Type.TString;
21
+ chat: Type.TUnion<[Type.TObject<{
22
+ bindingId: Type.TString;
23
+ chatId: Type.TString;
24
+ }>, Type.TNull]>;
25
+ conversationId: Type.TString;
26
+ createdAt: Type.TString;
27
+ expiresAt: Type.TUnion<[Type.TString, Type.TNull]>;
28
+ inputPreview: Type.TString;
29
+ runId: Type.TString;
30
+ toolName: Type.TString;
31
+ }>;
32
+ }>;
33
+ readonly "approval.resolved": Type.TObject<{
34
+ agent: Type.TString;
35
+ approvalId: Type.TString;
36
+ decision: Type.TUnion<[Type.TUnion<[Type.TLiteral<"allow_once">, Type.TLiteral<"allow_conversation">, Type.TLiteral<"allow_always">, Type.TLiteral<"deny">]>, Type.TLiteral<"timeout">, Type.TLiteral<"cancelled">]>;
37
+ reason: Type.TOptional<Type.TString>;
38
+ resolvedBy: Type.TOptional<Type.TString>;
39
+ }>;
40
+ /** A message in the Agent's CLI Chat, from any client or the Agent. */
41
+ readonly "chat.message": Type.TObject<{
42
+ agent: Type.TString;
43
+ message: Type.TObject<{
44
+ at: Type.TString;
45
+ attachments: Type.TOptional<Type.TArray<Type.TObject<{
46
+ filename: Type.TString;
47
+ mimeType: Type.TString;
48
+ sizeBytes: Type.TInteger;
49
+ }>>>;
50
+ messageId: Type.TString;
51
+ role: Type.TUnion<[Type.TLiteral<"user">, Type.TLiteral<"assistant">]>;
52
+ runId: Type.TOptional<Type.TString>;
53
+ senderDisplayName: Type.TOptional<Type.TString>;
54
+ source: Type.TOptional<Type.TUnion<[Type.TLiteral<"reply">, Type.TLiteral<"command">, Type.TLiteral<"trigger">]>>;
55
+ text: Type.TString;
56
+ }>;
57
+ }>;
58
+ readonly "config.changed": Type.TObject<{
59
+ pendingRestart: Type.TArray<Type.TUnion<[Type.TObject<{
60
+ agent: Type.TString;
61
+ kind: Type.TLiteral<"agent">;
62
+ }>, Type.TObject<{
63
+ agent: Type.TString;
64
+ bindingId: Type.TString;
65
+ kind: Type.TLiteral<"binding">;
66
+ }>, Type.TObject<{
67
+ kind: Type.TLiteral<"daemon">;
68
+ reason: Type.TString;
69
+ }>]>>;
70
+ revision: Type.TString;
71
+ }>;
72
+ /** A failed outbox entry left the Inbox. */
73
+ readonly "delivery.cleared": Type.TObject<{
74
+ agent: Type.TString;
75
+ deliveryId: Type.TString;
76
+ reason: Type.TUnion<[Type.TLiteral<"retried">, Type.TLiteral<"dismissed">, Type.TLiteral<"delivered">]>;
77
+ }>;
78
+ readonly "delivery.failed": Type.TObject<{
79
+ agent: Type.TString;
80
+ delivery: Type.TObject<{
81
+ agent: Type.TString;
82
+ attempts: Type.TInteger;
83
+ bindingId: Type.TString;
84
+ chatId: Type.TString;
85
+ createdAt: Type.TString;
86
+ deliveryId: Type.TString;
87
+ failedAt: Type.TString;
88
+ kind: Type.TUnion<[Type.TLiteral<"message">, Type.TLiteral<"approval_requested">, Type.TLiteral<"approval_resolved">]>;
89
+ lastError: Type.TString;
90
+ permanent: Type.TBoolean;
91
+ preview: Type.TString;
92
+ }>;
93
+ }>;
94
+ readonly "log.record": Type.TObject<{
95
+ record: Type.TObject<{
96
+ agent: Type.TOptional<Type.TString>;
97
+ at: Type.TString;
98
+ fields: Type.TOptional<Type.TRecord<"^.*$", Type.TUnknown>>;
99
+ level: Type.TUnion<[Type.TLiteral<"debug">, Type.TLiteral<"info">, Type.TLiteral<"warn">, Type.TLiteral<"error">]>;
100
+ message: Type.TString;
101
+ module: Type.TString;
102
+ seq: Type.TInteger;
103
+ }>;
104
+ }>;
105
+ readonly "memory.changed": Type.TObject<{
106
+ agent: Type.TString;
107
+ change: Type.TUnion<[Type.TLiteral<"written">, Type.TLiteral<"deleted">, Type.TLiteral<"reindexed">]>;
108
+ name: Type.TOptional<Type.TString>;
109
+ }>;
110
+ /** Streamed assistant text of a running Run. */
111
+ readonly "run.delta": Type.TObject<{
112
+ agent: Type.TString;
113
+ delta: Type.TString;
114
+ runId: Type.TString;
115
+ }>;
116
+ readonly "run.finished": Type.TObject<{
117
+ agent: Type.TString;
118
+ run: Type.TObject<{
119
+ agent: Type.TString;
120
+ conversationId: Type.TString;
121
+ endedAt: Type.TUnion<[Type.TString, Type.TNull]>;
122
+ error: Type.TOptional<Type.TString>;
123
+ model: Type.TOptional<Type.TString>;
124
+ origin: Type.TUnion<[Type.TObject<{
125
+ bindingId: Type.TString;
126
+ chatId: Type.TString;
127
+ kind: Type.TLiteral<"chat">;
128
+ }>, Type.TObject<{
129
+ kind: Type.TLiteral<"trigger">;
130
+ triggerId: Type.TString;
131
+ }>, Type.TObject<{
132
+ job: Type.TString;
133
+ kind: Type.TLiteral<"maintenance">;
134
+ }>]>;
135
+ runId: Type.TString;
136
+ startedAt: Type.TString;
137
+ status: Type.TUnion<[Type.TLiteral<"running">, Type.TLiteral<"waiting_approval">, Type.TLiteral<"completed">, Type.TLiteral<"failed">, Type.TLiteral<"stopped">]>;
138
+ usage: Type.TOptional<Type.TObject<{
139
+ costUsd: Type.TOptional<Type.TNumber>;
140
+ inputTokens: Type.TInteger;
141
+ outputTokens: Type.TInteger;
142
+ }>>;
143
+ }>;
144
+ }>;
145
+ readonly "run.started": Type.TObject<{
146
+ agent: Type.TString;
147
+ run: Type.TObject<{
148
+ agent: Type.TString;
149
+ conversationId: Type.TString;
150
+ endedAt: Type.TUnion<[Type.TString, Type.TNull]>;
151
+ error: Type.TOptional<Type.TString>;
152
+ model: Type.TOptional<Type.TString>;
153
+ origin: Type.TUnion<[Type.TObject<{
154
+ bindingId: Type.TString;
155
+ chatId: Type.TString;
156
+ kind: Type.TLiteral<"chat">;
157
+ }>, Type.TObject<{
158
+ kind: Type.TLiteral<"trigger">;
159
+ triggerId: Type.TString;
160
+ }>, Type.TObject<{
161
+ job: Type.TString;
162
+ kind: Type.TLiteral<"maintenance">;
163
+ }>]>;
164
+ runId: Type.TString;
165
+ startedAt: Type.TString;
166
+ status: Type.TUnion<[Type.TLiteral<"running">, Type.TLiteral<"waiting_approval">, Type.TLiteral<"completed">, Type.TLiteral<"failed">, Type.TLiteral<"stopped">]>;
167
+ usage: Type.TOptional<Type.TObject<{
168
+ costUsd: Type.TOptional<Type.TNumber>;
169
+ inputTokens: Type.TInteger;
170
+ outputTokens: Type.TInteger;
171
+ }>>;
172
+ }>;
173
+ }>;
174
+ readonly "run.toolFinished": Type.TObject<{
175
+ agent: Type.TString;
176
+ isError: Type.TBoolean;
177
+ outputPreview: Type.TString;
178
+ runId: Type.TString;
179
+ toolCallId: Type.TString;
180
+ toolName: Type.TString;
181
+ }>;
182
+ readonly "run.toolStarted": Type.TObject<{
183
+ agent: Type.TString;
184
+ inputPreview: Type.TString;
185
+ runId: Type.TString;
186
+ toolCallId: Type.TString;
187
+ toolName: Type.TString;
188
+ }>;
189
+ readonly "trigger.changed": Type.TObject<{
190
+ agent: Type.TString;
191
+ change: Type.TUnion<[Type.TLiteral<"created">, Type.TLiteral<"updated">, Type.TLiteral<"deleted">, Type.TLiteral<"fired">]>;
192
+ trigger: Type.TOptional<Type.TObject<{
193
+ conversationMode: Type.TUnion<[Type.TLiteral<"per_firing">, Type.TLiteral<"shared">]>;
194
+ createdAt: Type.TString;
195
+ createdBy: Type.TUnion<[Type.TLiteral<"agent">, Type.TLiteral<"operator">]>;
196
+ id: Type.TString;
197
+ lastFiredAt: Type.TUnion<[Type.TString, Type.TNull]>;
198
+ name: Type.TString;
199
+ nextFireAt: Type.TUnion<[Type.TString, Type.TNull]>;
200
+ paused: Type.TBoolean;
201
+ prompt: Type.TString;
202
+ schedule: Type.TUnion<[Type.TObject<{
203
+ kind: Type.TLiteral<"cron">;
204
+ schedule: Type.TString;
205
+ timezone: Type.TString;
206
+ }>, Type.TObject<{
207
+ at: Type.TString;
208
+ kind: Type.TLiteral<"once">;
209
+ }>, Type.TObject<{
210
+ kind: Type.TLiteral<"webhook">;
211
+ tokenSecret: Type.TString;
212
+ }>]>;
213
+ target: Type.TObject<{
214
+ bindingId: Type.TString;
215
+ chatId: Type.TString;
216
+ }>;
217
+ }>>;
218
+ triggerId: Type.TString;
219
+ }>;
220
+ };
221
+ /** The name of a v1 event. */
222
+ export type EventName = keyof typeof events;
223
+ /** The payload of event `E`. */
224
+ export type EventPayload<E extends EventName> = Static<(typeof events)[E]>;
225
+ /** Returns true if `name` is a v1 event. */
226
+ export declare const isEventName: (name: string) => name is EventName;
227
+ /** The names of all v1 events. */
228
+ export declare const EVENT_NAMES: readonly EventName[];
229
+ /** An event topic: the part of an event name before the dot. `events.subscribe` filters by topic. */
230
+ export declare const EventTopicSchema: Type.TUnion<[Type.TLiteral<"agent">, Type.TLiteral<"approval">, Type.TLiteral<"chat">, Type.TLiteral<"config">, Type.TLiteral<"delivery">, Type.TLiteral<"log">, Type.TLiteral<"memory">, Type.TLiteral<"run">, Type.TLiteral<"trigger">]>;
231
+ export type EventTopic = Static<typeof EventTopicSchema>;
232
+ /** Returns the topic of event `name`. */
233
+ export declare const eventTopic: (name: EventName) => EventTopic;
234
+ //# sourceMappingURL=events.d.ts.map
@@ -0,0 +1,124 @@
1
+ import { Type } from "typebox";
2
+ import { Value } from "typebox/value";
3
+ import { AgentNameSchema, AgentStateSchema, ApprovalOutcomeSchema, ChatMessageSchema, FailedDeliverySchema, IdSchema, LogRecordSchema, MemoryNameSchema, PendingApprovalSchema, PendingRestartSchema, RunSummarySchema, TriggerSchema, } from "./domain.js";
4
+ import { TOOL_INPUT_PREVIEW_MAX_LENGTH, TOOL_OUTPUT_PREVIEW_MAX_LENGTH, } from "./limits.js";
5
+ /**
6
+ * Every v1 live event that the daemon sends as a JSON-RPC notification. The notification `method` is the event name
7
+ * and `params` is the payload (ADR 0003, ADR 0005).
8
+ *
9
+ * On one connection, the response to a request always arrives before the events that the request caused.
10
+ */
11
+ export const events = {
12
+ "agent.status": Type.Object({
13
+ agent: AgentNameSchema,
14
+ error: Type.Optional(Type.String()),
15
+ state: AgentStateSchema,
16
+ }),
17
+ /** Every client receives it. The first `approvals.decide` call wins. */
18
+ "approval.requested": Type.Object({
19
+ agent: AgentNameSchema,
20
+ approval: PendingApprovalSchema,
21
+ }),
22
+ "approval.resolved": Type.Object({
23
+ agent: AgentNameSchema,
24
+ approvalId: IdSchema,
25
+ decision: ApprovalOutcomeSchema,
26
+ reason: Type.Optional(Type.String()),
27
+ resolvedBy: Type.Optional(Type.String()),
28
+ }),
29
+ /** A message in the Agent's CLI Chat, from any client or the Agent. */
30
+ "chat.message": Type.Object({
31
+ agent: AgentNameSchema,
32
+ message: ChatMessageSchema,
33
+ }),
34
+ "config.changed": Type.Object({
35
+ pendingRestart: Type.Array(PendingRestartSchema),
36
+ revision: Type.String(),
37
+ }),
38
+ /** A failed outbox entry left the Inbox. */
39
+ "delivery.cleared": Type.Object({
40
+ agent: AgentNameSchema,
41
+ deliveryId: IdSchema,
42
+ reason: Type.Union([
43
+ Type.Literal("retried"),
44
+ Type.Literal("dismissed"),
45
+ Type.Literal("delivered"),
46
+ ]),
47
+ }),
48
+ "delivery.failed": Type.Object({
49
+ agent: AgentNameSchema,
50
+ delivery: FailedDeliverySchema,
51
+ }),
52
+ "log.record": Type.Object({ record: LogRecordSchema }),
53
+ "memory.changed": Type.Object({
54
+ agent: AgentNameSchema,
55
+ change: Type.Union([
56
+ Type.Literal("written"),
57
+ Type.Literal("deleted"),
58
+ Type.Literal("reindexed"),
59
+ ]),
60
+ name: Type.Optional(MemoryNameSchema),
61
+ }),
62
+ /** Streamed assistant text of a running Run. */
63
+ "run.delta": Type.Object({
64
+ agent: AgentNameSchema,
65
+ delta: Type.String(),
66
+ runId: IdSchema,
67
+ }),
68
+ "run.finished": Type.Object({
69
+ agent: AgentNameSchema,
70
+ run: RunSummarySchema,
71
+ }),
72
+ "run.started": Type.Object({ agent: AgentNameSchema, run: RunSummarySchema }),
73
+ "run.toolFinished": Type.Object({
74
+ agent: AgentNameSchema,
75
+ isError: Type.Boolean(),
76
+ outputPreview: Type.String({ maxLength: TOOL_OUTPUT_PREVIEW_MAX_LENGTH }),
77
+ runId: IdSchema,
78
+ toolCallId: IdSchema,
79
+ toolName: Type.String(),
80
+ }),
81
+ "run.toolStarted": Type.Object({
82
+ agent: AgentNameSchema,
83
+ inputPreview: Type.String({ maxLength: TOOL_INPUT_PREVIEW_MAX_LENGTH }),
84
+ runId: IdSchema,
85
+ toolCallId: IdSchema,
86
+ toolName: Type.String(),
87
+ }),
88
+ "trigger.changed": Type.Object({
89
+ agent: AgentNameSchema,
90
+ change: Type.Union([
91
+ Type.Literal("created"),
92
+ Type.Literal("updated"),
93
+ Type.Literal("deleted"),
94
+ Type.Literal("fired"),
95
+ ]),
96
+ trigger: Type.Optional(TriggerSchema),
97
+ triggerId: IdSchema,
98
+ }),
99
+ };
100
+ /** Returns true if `name` is a v1 event. */
101
+ export const isEventName = (name) => Object.hasOwn(events, name);
102
+ /** The names of all v1 events. */
103
+ export const EVENT_NAMES = Object.keys(events).filter(isEventName);
104
+ /** An event topic: the part of an event name before the dot. `events.subscribe` filters by topic. */
105
+ export const EventTopicSchema = Type.Union([
106
+ Type.Literal("agent"),
107
+ Type.Literal("approval"),
108
+ Type.Literal("chat"),
109
+ Type.Literal("config"),
110
+ Type.Literal("delivery"),
111
+ Type.Literal("log"),
112
+ Type.Literal("memory"),
113
+ Type.Literal("run"),
114
+ Type.Literal("trigger"),
115
+ ]);
116
+ /** Returns the topic of event `name`. */
117
+ export const eventTopic = (name) => {
118
+ const topic = name.slice(0, name.indexOf("."));
119
+ if (!Value.Check(EventTopicSchema, topic)) {
120
+ throw new Error(`Event ${name} has no known topic`);
121
+ }
122
+ return topic;
123
+ };
124
+ //# sourceMappingURL=events.js.map
@@ -0,0 +1,11 @@
1
+ export { type AgentConfig, AgentConfigSchema, type DaemonConfig, DaemonConfigSchema, DEFAULT_WEBHOOK_HOST, DEFAULT_WEBHOOK_PORT, type DeploymentConfig, DeploymentConfigSchema, type FrontendBindingConfig, FrontendBindingConfigSchema, type McpServerConfig, McpServerConfigSchema, type MemoryConfig, MemoryConfigSchema, type ModelChoice, ModelChoiceSchema, type PluginConfig, PluginConfigSchema, type ProviderConfig, ProviderConfigSchema, type SecretRef, SecretRefSchema, type StringOrSecret, StringOrSecretSchema, type WebhooksConfig, WebhooksConfigSchema, webhookTriggerPath, } from "./config.js";
2
+ export { type AgentHealth, AgentHealthSchema, type AgentName, AgentNameSchema, type AgentState, AgentStateSchema, type ApprovalDecision, ApprovalDecisionSchema, type ApprovalOutcome, ApprovalOutcomeSchema, type ApprovalResolution, ApprovalResolutionSchema, type AttachmentInfo, AttachmentInfoSchema, type AttachmentUpload, AttachmentUploadSchema, type BindingStatus, BindingStatusSchema, type ChatKey, ChatKeySchema, type ChatMessage, ChatMessageSchema, type CommandName, CommandNameSchema, type ConfigIssue, ConfigIssueSchema, type ConsolidationLogEntry, ConsolidationLogEntrySchema, type ConversationMode, ConversationModeSchema, type DaemonStatus, DaemonStatusSchema, type DeliveryKind, DeliveryKindSchema, type Duration, DurationSchema, type ExtensionState, ExtensionStateSchema, type ExtensionStatus, ExtensionStatusSchema, type FailedDelivery, FailedDeliverySchema, type GatePressure, GatePressureSchema, type Id, IdSchema, type LogLevel, LogLevelSchema, type LogRecord, LogRecordSchema, type MemoryBudget, MemoryBudgetSchema, type MemoryFile, MemoryFileSchema, type MemoryName, MemoryNameSchema, type MemorySearchHit, MemorySearchHitSchema, type MemorySearchScope, MemorySearchScopeSchema, type PendingApproval, PendingApprovalSchema, type PendingRestart, PendingRestartSchema, type PermissionAction, PermissionActionSchema, type PermissionRule, PermissionRuleSchema, type RunOrigin, RunOriginSchema, type RunStatus, RunStatusSchema, type RunSummary, RunSummarySchema, type RunTimelineItem, RunTimelineItemSchema, type RunUsage, RunUsageSchema, type SecretInfo, SecretInfoSchema, type SecretName, SecretNameSchema, type SecretSource, SecretSourceSchema, type SkillInfo, SkillInfoSchema, type Timestamp, TimestampSchema, type ToolInfo, ToolInfoSchema, type ToolSource, ToolSourceSchema, type Trigger, type TriggerInput, TriggerInputSchema, type TriggerPatch, TriggerPatchSchema, type TriggerSchedule, TriggerScheduleSchema, TriggerSchema, } from "./domain.js";
3
+ export { parseDuration } from "./duration.js";
4
+ export { EVENT_NAMES, type EventName, type EventPayload, events, type EventTopic, eventTopic, EventTopicSchema, isEventName, } from "./events.js";
5
+ export { type ClientMessage, decodeClientMessage, decodeServerMessage, encodeError, encodeEvent, encodeRequest, encodeResult, type RpcEvent, type RpcId, RpcIdSchema, type RpcRequest, type RpcResult, type ServerMessage, } from "./json-rpc.js";
6
+ export { isJsonValue, type JsonObject, type JsonPrimitive, type JsonValue, } from "./json.js";
7
+ export { APPROVAL_REASON_MAX_LENGTH, CRON_EXPRESSION_MIN_LENGTH, DELIVERY_PREVIEW_MAX_LENGTH, DISPLAY_NAME_MAX_LENGTH, MAX_TCP_PORT, TOOL_INPUT_PREVIEW_MAX_LENGTH, TOOL_OUTPUT_PREVIEW_MAX_LENGTH, TRIGGER_NAME_MAX_LENGTH, } from "./limits.js";
8
+ export { isMethodName, METHOD_NAMES, type MethodName, type MethodParams, type MethodResult, methods, PROTOCOL_VERSION, } from "./methods.js";
9
+ export { RpcError, RpcErrorCode, type RpcErrorCodeValue, type RpcErrorObject, } from "./rpc-error.js";
10
+ export { decode, type Decoded, type ValidationIssue, validationIssues, } from "./validation.js";
11
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,11 @@
1
+ export { AgentConfigSchema, DaemonConfigSchema, DEFAULT_WEBHOOK_HOST, DEFAULT_WEBHOOK_PORT, DeploymentConfigSchema, FrontendBindingConfigSchema, McpServerConfigSchema, MemoryConfigSchema, ModelChoiceSchema, PluginConfigSchema, ProviderConfigSchema, SecretRefSchema, StringOrSecretSchema, WebhooksConfigSchema, webhookTriggerPath, } from "./config.js";
2
+ export { AgentHealthSchema, AgentNameSchema, AgentStateSchema, ApprovalDecisionSchema, ApprovalOutcomeSchema, ApprovalResolutionSchema, AttachmentInfoSchema, AttachmentUploadSchema, BindingStatusSchema, ChatKeySchema, ChatMessageSchema, CommandNameSchema, ConfigIssueSchema, ConsolidationLogEntrySchema, ConversationModeSchema, DaemonStatusSchema, DeliveryKindSchema, DurationSchema, ExtensionStateSchema, ExtensionStatusSchema, FailedDeliverySchema, GatePressureSchema, IdSchema, LogLevelSchema, LogRecordSchema, MemoryBudgetSchema, MemoryFileSchema, MemoryNameSchema, MemorySearchHitSchema, MemorySearchScopeSchema, PendingApprovalSchema, PendingRestartSchema, PermissionActionSchema, PermissionRuleSchema, RunOriginSchema, RunStatusSchema, RunSummarySchema, RunTimelineItemSchema, RunUsageSchema, SecretInfoSchema, SecretNameSchema, SecretSourceSchema, SkillInfoSchema, TimestampSchema, ToolInfoSchema, ToolSourceSchema, TriggerInputSchema, TriggerPatchSchema, TriggerScheduleSchema, TriggerSchema, } from "./domain.js";
3
+ export { parseDuration } from "./duration.js";
4
+ export { EVENT_NAMES, events, eventTopic, EventTopicSchema, isEventName, } from "./events.js";
5
+ export { decodeClientMessage, decodeServerMessage, encodeError, encodeEvent, encodeRequest, encodeResult, RpcIdSchema, } from "./json-rpc.js";
6
+ export { isJsonValue, } from "./json.js";
7
+ export { APPROVAL_REASON_MAX_LENGTH, CRON_EXPRESSION_MIN_LENGTH, DELIVERY_PREVIEW_MAX_LENGTH, DISPLAY_NAME_MAX_LENGTH, MAX_TCP_PORT, TOOL_INPUT_PREVIEW_MAX_LENGTH, TOOL_OUTPUT_PREVIEW_MAX_LENGTH, TRIGGER_NAME_MAX_LENGTH, } from "./limits.js";
8
+ export { isMethodName, METHOD_NAMES, methods, PROTOCOL_VERSION, } from "./methods.js";
9
+ export { RpcError, RpcErrorCode, } from "./rpc-error.js";
10
+ export { decode, validationIssues, } from "./validation.js";
11
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,81 @@
1
+ import { Type } from "typebox";
2
+ import type { Static } from "typebox";
3
+ import type { EventName, EventPayload } from "./events.js";
4
+ import type { MethodName, MethodParams, MethodResult } from "./methods.js";
5
+ import type { RpcErrorObject } from "./rpc-error.js";
6
+ /** A JSON-RPC request ID. Wheatley clients use strings or integers. */
7
+ export declare const RpcIdSchema: Type.TUnion<[Type.TString, Type.TInteger]>;
8
+ export type RpcId = Static<typeof RpcIdSchema>;
9
+ /** A decoded request for one method, with params that match its schema. */
10
+ export type RpcRequest = {
11
+ [M in MethodName]: {
12
+ readonly id: RpcId;
13
+ readonly method: M;
14
+ readonly params: MethodParams<M>;
15
+ };
16
+ }[MethodName];
17
+ /** A decoded event notification. */
18
+ export type RpcEvent = {
19
+ [E in EventName]: {
20
+ readonly name: E;
21
+ readonly payload: EventPayload<E>;
22
+ };
23
+ }[EventName];
24
+ /** A decoded success response, matched to the method of its request. */
25
+ export type RpcResult = {
26
+ [M in MethodName]: {
27
+ readonly id: RpcId;
28
+ readonly method: M;
29
+ readonly result: MethodResult<M>;
30
+ };
31
+ }[MethodName];
32
+ /** The result of `decodeClientMessage`. On failure, `id` and `error` form the error response to send back. */
33
+ export type ClientMessage = {
34
+ readonly ok: true;
35
+ readonly request: RpcRequest;
36
+ } | {
37
+ readonly ok: false;
38
+ readonly id: RpcId | null;
39
+ readonly error: RpcErrorObject;
40
+ };
41
+ /** The result of `decodeServerMessage`. */
42
+ export type ServerMessage = {
43
+ readonly kind: "result";
44
+ readonly response: RpcResult;
45
+ } | {
46
+ readonly kind: "error";
47
+ readonly id: RpcId | null;
48
+ readonly error: RpcErrorObject;
49
+ } | {
50
+ readonly kind: "event";
51
+ readonly event: RpcEvent;
52
+ } | {
53
+ readonly kind: "invalid";
54
+ readonly reason: string;
55
+ };
56
+ /**
57
+ * Decodes one client-to-daemon WebSocket message into a request with validated params.
58
+ *
59
+ * Wheatley requires an `id` on every request, accepts object params only, and does not support batches. Absent params
60
+ * decode as `{}`.
61
+ */
62
+ export declare const decodeClientMessage: (text: string) => ClientMessage;
63
+ /**
64
+ * Decodes one daemon-to-client WebSocket message.
65
+ *
66
+ * `methodFor` returns the method of a pending request ID, so the result can be validated against that method's result
67
+ * schema. A result for an unknown ID, a result that fails its schema, or an unknown event decodes as `invalid`.
68
+ */
69
+ export declare const decodeServerMessage: (text: string, methodFor: (id: RpcId) => MethodName | undefined) => ServerMessage;
70
+ /** Encodes a request. */
71
+ export declare const encodeRequest: <M extends MethodName>(id: RpcId, method: M, params: MethodParams<M>) => string;
72
+ /**
73
+ * Encodes a success response. Throws if `result` does not match the result schema of `method`, so a handler defect
74
+ * becomes an `InternalError` response instead of a response that clients reject.
75
+ */
76
+ export declare const encodeResult: <M extends MethodName>(id: RpcId, method: M, result: MethodResult<M>) => string;
77
+ /** Encodes an error response. `id` is `null` if the request ID could not be read. */
78
+ export declare const encodeError: (id: RpcId | null, error: RpcErrorObject) => string;
79
+ /** Encodes an event as a JSON-RPC notification whose method is the event name. */
80
+ export declare const encodeEvent: <E extends EventName>(name: E, payload: EventPayload<E>) => string;
81
+ //# sourceMappingURL=json-rpc.d.ts.map
@@ -0,0 +1,157 @@
1
+ import { Type } from "typebox";
2
+ import { Value } from "typebox/value";
3
+ import { events, isEventName } from "./events.js";
4
+ import { isJsonValue } from "./json.js";
5
+ import { isMethodName, methods } from "./methods.js";
6
+ import { RpcErrorCode } from "./rpc-error.js";
7
+ import { validationIssues } from "./validation.js";
8
+ /** A JSON-RPC request ID. Wheatley clients use strings or integers. */
9
+ export const RpcIdSchema = Type.Union([
10
+ Type.String({ minLength: 1 }),
11
+ Type.Integer(),
12
+ ]);
13
+ const RequestEnvelope = Type.Object({
14
+ id: RpcIdSchema,
15
+ jsonrpc: Type.Literal("2.0"),
16
+ method: Type.String(),
17
+ params: Type.Optional(Type.Union([Type.Object({}), Type.Array(Type.Unknown())])),
18
+ });
19
+ const WithId = Type.Object({ id: RpcIdSchema });
20
+ const ResultEnvelope = Type.Object({
21
+ id: RpcIdSchema,
22
+ jsonrpc: Type.Literal("2.0"),
23
+ result: Type.Unknown(),
24
+ });
25
+ const ErrorEnvelope = Type.Object({
26
+ error: Type.Object({
27
+ code: Type.Integer(),
28
+ data: Type.Optional(Type.Unknown()),
29
+ message: Type.String(),
30
+ }),
31
+ id: Type.Union([RpcIdSchema, Type.Null()]),
32
+ jsonrpc: Type.Literal("2.0"),
33
+ });
34
+ const NotificationEnvelope = Type.Object({
35
+ jsonrpc: Type.Literal("2.0"),
36
+ method: Type.String(),
37
+ params: Type.Unknown(),
38
+ });
39
+ const KNOWN_ERROR_CODES = new Set(Object.values(RpcErrorCode));
40
+ const failure = (id, code, message, data) => ({
41
+ error: data === undefined ? { code, message } : { code, data, message },
42
+ id,
43
+ ok: false,
44
+ });
45
+ const parseJson = (text) => {
46
+ try {
47
+ const value = JSON.parse(text);
48
+ return isJsonValue(value) ? { ok: true, value } : { ok: false };
49
+ }
50
+ catch {
51
+ return { ok: false };
52
+ }
53
+ };
54
+ const isRpcErrorCode = (code) => KNOWN_ERROR_CODES.has(code);
55
+ /** Returns true if `candidate.params` match the params schema of `candidate.method`. */
56
+ const isRpcRequest = (candidate) => Value.Check(methods[candidate.method].params, candidate.params);
57
+ /** Returns true if `candidate.result` matches the result schema of `candidate.method`. */
58
+ const isRpcResult = (candidate) => Value.Check(methods[candidate.method].result, candidate.result);
59
+ /** Returns true if `candidate.payload` matches the payload schema of event `candidate.name`. */
60
+ const isRpcEvent = (candidate) => Value.Check(events[candidate.name], candidate.payload);
61
+ /**
62
+ * Decodes one client-to-daemon WebSocket message into a request with validated params.
63
+ *
64
+ * Wheatley requires an `id` on every request, accepts object params only, and does not support batches. Absent params
65
+ * decode as `{}`.
66
+ */
67
+ export const decodeClientMessage = (text) => {
68
+ const parsed = parseJson(text);
69
+ if (!parsed.ok) {
70
+ return failure(null, RpcErrorCode.ParseError, "Parse error");
71
+ }
72
+ const { value } = parsed;
73
+ if (!Value.Check(RequestEnvelope, value)) {
74
+ const id = Value.Check(WithId, value) ? value.id : null;
75
+ return failure(id, RpcErrorCode.InvalidRequest, "Invalid request");
76
+ }
77
+ const { id, method } = value;
78
+ const params = value.params ?? {};
79
+ if (!isMethodName(method)) {
80
+ return failure(id, RpcErrorCode.MethodNotFound, `Method not found: ${method}`);
81
+ }
82
+ const request = { id, method, params };
83
+ if (isRpcRequest(request)) {
84
+ return { ok: true, request };
85
+ }
86
+ const issues = isJsonValue(params)
87
+ ? validationIssues(methods[method].params, params)
88
+ : [];
89
+ return failure(id, RpcErrorCode.InvalidParams, "Invalid params", {
90
+ issues: issues.map(({ message, path }) => ({ message, path })),
91
+ });
92
+ };
93
+ /**
94
+ * Decodes one daemon-to-client WebSocket message.
95
+ *
96
+ * `methodFor` returns the method of a pending request ID, so the result can be validated against that method's result
97
+ * schema. A result for an unknown ID, a result that fails its schema, or an unknown event decodes as `invalid`.
98
+ */
99
+ export const decodeServerMessage = (text, methodFor) => {
100
+ const parsed = parseJson(text);
101
+ if (!parsed.ok) {
102
+ return { kind: "invalid", reason: "Parse error" };
103
+ }
104
+ const { value } = parsed;
105
+ if (Value.Check(ErrorEnvelope, value)) {
106
+ const { code, message } = value.error;
107
+ const data = isJsonValue(value.error.data) ? value.error.data : undefined;
108
+ const errorCode = isRpcErrorCode(code) ? code : RpcErrorCode.InternalError;
109
+ const error = data === undefined
110
+ ? { code: errorCode, message }
111
+ : { code: errorCode, data, message };
112
+ return { error, id: value.id, kind: "error" };
113
+ }
114
+ if (Value.Check(ResultEnvelope, value)) {
115
+ const method = methodFor(value.id);
116
+ if (method === undefined) {
117
+ return {
118
+ kind: "invalid",
119
+ reason: `No pending request with ID ${String(value.id)}`,
120
+ };
121
+ }
122
+ const response = { id: value.id, method, result: value.result };
123
+ return isRpcResult(response)
124
+ ? { kind: "result", response }
125
+ : {
126
+ kind: "invalid",
127
+ reason: `Result of ${method} does not match its schema`,
128
+ };
129
+ }
130
+ if (Value.Check(NotificationEnvelope, value) && isEventName(value.method)) {
131
+ const event = { name: value.method, payload: value.params };
132
+ return isRpcEvent(event)
133
+ ? { event, kind: "event" }
134
+ : {
135
+ kind: "invalid",
136
+ reason: `Payload of ${event.name} does not match its schema`,
137
+ };
138
+ }
139
+ return { kind: "invalid", reason: "Unknown message" };
140
+ };
141
+ /** Encodes a request. */
142
+ export const encodeRequest = (id, method, params) => JSON.stringify({ id, jsonrpc: "2.0", method, params });
143
+ /**
144
+ * Encodes a success response. Throws if `result` does not match the result schema of `method`, so a handler defect
145
+ * becomes an `InternalError` response instead of a response that clients reject.
146
+ */
147
+ export const encodeResult = (id, method, result) => {
148
+ if (!Value.Check(methods[method].result, result)) {
149
+ throw new Error(`Result of ${method} does not match its schema`);
150
+ }
151
+ return JSON.stringify({ id, jsonrpc: "2.0", result });
152
+ };
153
+ /** Encodes an error response. `id` is `null` if the request ID could not be read. */
154
+ export const encodeError = (id, error) => JSON.stringify({ error, id, jsonrpc: "2.0" });
155
+ /** Encodes an event as a JSON-RPC notification whose method is the event name. */
156
+ export const encodeEvent = (name, payload) => JSON.stringify({ jsonrpc: "2.0", method: name, params: payload });
157
+ //# sourceMappingURL=json-rpc.js.map
@@ -0,0 +1,14 @@
1
+ /** A JSON primitive value. */
2
+ export type JsonPrimitive = string | number | boolean | null;
3
+ /** A JSON object. Keys map to JSON values. */
4
+ export interface JsonObject {
5
+ readonly [key: string]: JsonValue;
6
+ }
7
+ /** Any value that `JSON.parse` can return. */
8
+ export type JsonValue = JsonPrimitive | readonly JsonValue[] | JsonObject;
9
+ /**
10
+ * Returns true if `value` contains only JSON values: no `undefined`, functions, symbols, bigints, non-finite numbers,
11
+ * or class instances other than plain objects and arrays. Use it at boundaries such as a YAML parser.
12
+ */
13
+ export declare const isJsonValue: (value: unknown) => value is JsonValue;
14
+ //# sourceMappingURL=json.d.ts.map
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Returns true if `value` contains only JSON values: no `undefined`, functions, symbols, bigints, non-finite numbers,
3
+ * or class instances other than plain objects and arrays. Use it at boundaries such as a YAML parser.
4
+ */
5
+ export const isJsonValue = (value) => {
6
+ if (value === null ||
7
+ typeof value === "string" ||
8
+ typeof value === "boolean") {
9
+ return true;
10
+ }
11
+ if (typeof value === "number") {
12
+ return Number.isFinite(value);
13
+ }
14
+ if (Array.isArray(value)) {
15
+ return value.every(isJsonValue);
16
+ }
17
+ if (typeof value !== "object" ||
18
+ Object.getPrototypeOf(value) !== Object.prototype) {
19
+ return false;
20
+ }
21
+ return Object.values(value).every(isJsonValue);
22
+ };
23
+ //# sourceMappingURL=json.js.map