@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,236 @@
1
+ import type { CommandName, CommandSpec } from "./commands.js";
2
+ import type { JsonValue } from "./json.js";
3
+ import type { Logger, SecretReader } from "./logger.js";
4
+ import type { SchemaInput } from "./schema.js";
5
+ /**
6
+ * A file sent to or from a Chat.
7
+ *
8
+ * Inbound files arrive staged on disk (`kind: "file"`). Outbound files can carry bytes or a staged path. Wheatley
9
+ * rejects files larger than `FrontendContext.maxAttachmentBytes`.
10
+ */
11
+ export type Attachment = {
12
+ readonly kind: "bytes";
13
+ readonly filename: string;
14
+ readonly mimeType: string;
15
+ readonly data: Uint8Array;
16
+ } | {
17
+ readonly kind: "file";
18
+ readonly filename: string;
19
+ readonly mimeType: string;
20
+ readonly path: string;
21
+ readonly sizeBytes: number;
22
+ };
23
+ /** A Sender's decision on an Approval (ADR 0011). */
24
+ export type ApprovalDecision = "allow_once" | "allow_conversation" | "allow_always" | "deny";
25
+ /** How an Approval ended: a decision, the timeout, or `/stop`. */
26
+ export type ApprovalOutcome = ApprovalDecision | "timeout" | "cancelled";
27
+ /** A decision on an Approval, from a Chat or from the Operator. */
28
+ export interface ApprovalResolution {
29
+ readonly decision: ApprovalDecision;
30
+ /** Display name of whoever decided, for attribution only. */
31
+ readonly resolvedBy?: string;
32
+ /** Optional reason for `deny`. Wheatley shows it to the model. */
33
+ readonly reason?: string;
34
+ }
35
+ /** Where an outbound `message` comes from. */
36
+ export type MessageSource = "reply" | "command" | "trigger";
37
+ /** A final Agent message for a Chat. */
38
+ export interface MessageDelivery {
39
+ readonly kind: "message";
40
+ /** The outbox ID. It stays the same across retries, so adapters can drop duplicates. */
41
+ readonly messageId: string;
42
+ readonly chatId: string;
43
+ /** Markdown. The Frontend Binding converts it to the platform format and splits it into chunks. */
44
+ readonly text: string;
45
+ readonly attachments?: readonly Attachment[];
46
+ readonly source: MessageSource;
47
+ /** The Run that produced the reply. Streaming adapters use it to finalize their draft instead of a second message. */
48
+ readonly runId?: string;
49
+ }
50
+ /** A tool call that waits for an Approval in this Chat. */
51
+ export interface ApprovalRequestedDelivery {
52
+ readonly kind: "approval_requested";
53
+ readonly messageId: string;
54
+ readonly chatId: string;
55
+ readonly approvalId: string;
56
+ /** The canonical Tool name, for example `shell`, `notes:add`, or `mcp:github:create_issue`. */
57
+ readonly toolName: string;
58
+ /** Formatted Tool input, at most 500 characters, with secret values redacted. */
59
+ readonly inputPreview: string;
60
+ /** ISO 8601 timestamp, or `null` if the Approval never times out. */
61
+ readonly expiresAt: string | null;
62
+ readonly runId: string;
63
+ }
64
+ /** An Approval ended. Adapters edit or disable the prompt that they showed for `approval_requested`. */
65
+ export interface ApprovalResolvedDelivery {
66
+ readonly kind: "approval_resolved";
67
+ readonly messageId: string;
68
+ readonly chatId: string;
69
+ readonly approvalId: string;
70
+ readonly decision: ApprovalOutcome;
71
+ readonly resolvedBy?: string;
72
+ readonly reason?: string;
73
+ }
74
+ /** Durable outbound work for a Frontend Binding, delivered at least once through the Agent outbox (ADR 0007). */
75
+ export type Delivery = MessageDelivery | ApprovalRequestedDelivery | ApprovalResolvedDelivery;
76
+ /** The kinds of `Delivery`. */
77
+ export type DeliveryKind = Delivery["kind"];
78
+ /**
79
+ * Ephemeral live progress of a Run in a Chat. Wheatley never stores or retries these events.
80
+ *
81
+ * Adapters show a typing indicator between `run_started` and `run_finished` and can stream `text_delta` into a
82
+ * draft that the final `message` delivery with the same `runId` replaces.
83
+ */
84
+ export type RunEvent = {
85
+ readonly kind: "run_started";
86
+ readonly runId: string;
87
+ readonly chatId: string;
88
+ } | {
89
+ readonly kind: "text_delta";
90
+ readonly runId: string;
91
+ readonly chatId: string;
92
+ readonly delta: string;
93
+ } | {
94
+ readonly kind: "tool_started";
95
+ readonly runId: string;
96
+ readonly chatId: string;
97
+ readonly toolCallId: string;
98
+ readonly toolName: string;
99
+ } | {
100
+ readonly kind: "tool_finished";
101
+ readonly runId: string;
102
+ readonly chatId: string;
103
+ readonly toolCallId: string;
104
+ readonly toolName: string;
105
+ readonly isError: boolean;
106
+ } | {
107
+ readonly kind: "run_finished";
108
+ readonly runId: string;
109
+ readonly chatId: string;
110
+ readonly status: "completed" | "failed" | "stopped";
111
+ };
112
+ /** A user message from a Chat. */
113
+ export interface InboundMessage {
114
+ /** The Chat ID, which encodes thread structure, for example `<channel_id>:<thread_ts>` (ADR 0012). */
115
+ readonly chatId: string;
116
+ readonly text: string;
117
+ /** The platform display name, for attribution only (ADR 0002). */
118
+ readonly senderDisplayName?: string;
119
+ readonly attachments?: readonly Attachment[];
120
+ }
121
+ /** A built-in command from a Chat, parsed from text or mapped from a native platform command. */
122
+ export interface InboundCommand {
123
+ readonly chatId: string;
124
+ readonly name: CommandName;
125
+ readonly args?: string;
126
+ readonly senderDisplayName?: string;
127
+ }
128
+ /** A Sender's decision on an Approval, from a Chat. */
129
+ export interface InboundDecision {
130
+ /** The Chat where the Sender decided. */
131
+ readonly chatId: string;
132
+ readonly approvalId: string;
133
+ readonly resolution: ApprovalResolution;
134
+ }
135
+ /** Inbound side of a Frontend Binding, provided by the Agent. */
136
+ export interface FrontendSink {
137
+ /** The built-in command specs, for native command menus. */
138
+ readonly commands: readonly CommandSpec[];
139
+ /**
140
+ * Hands a user message to the Agent. Resolves once the Agent stores it.
141
+ *
142
+ * Call it only for allowed Chats: the adapter enforces `allowedChatIds` before it calls the sink.
143
+ */
144
+ readonly send: (message: InboundMessage) => Promise<void>;
145
+ /** Hands a built-in command to the Agent. Resolves once the Agent accepts it. */
146
+ readonly command: (command: InboundCommand) => Promise<void>;
147
+ /**
148
+ * Submits a decision on an Approval from a Chat of this binding. Resolves `true` if this decision won, or `false` if
149
+ * the Approval already ended, does not exist, or belongs to another Chat (ADR 0002: only a Sender in the originating
150
+ * Chat can decide). The first decision from any surface wins (ADR 0005).
151
+ */
152
+ readonly decide: (decision: InboundDecision) => Promise<boolean>;
153
+ }
154
+ /** An HTTP request that the Webhook Ingress forwards to a Frontend route. */
155
+ export interface WebhookRequest {
156
+ readonly method: "POST";
157
+ /** The part of the path after `/frontends/<agent>/<binding-id>/`. */
158
+ readonly pathSuffix: string;
159
+ /** Header names are lowercase. Repeated headers are joined with `, `. */
160
+ readonly headers: Readonly<Record<string, string>>;
161
+ readonly query: Readonly<Record<string, string>>;
162
+ /** The raw body, at most 256 KiB, for signature checks. */
163
+ readonly body: Uint8Array;
164
+ }
165
+ /** The HTTP response for a `WebhookRequest`. */
166
+ export interface WebhookResponse {
167
+ readonly status: number;
168
+ readonly headers?: Readonly<Record<string, string>>;
169
+ readonly body?: string | Uint8Array;
170
+ }
171
+ /** Handles one Frontend webhook request. The adapter verifies the request itself (ADR 0012). */
172
+ export type WebhookRouteHandler = (request: WebhookRequest) => Promise<WebhookResponse>;
173
+ /** A mounted Frontend webhook route. */
174
+ export interface WebhookRoute {
175
+ /** The mounted path, for example `/frontends/home/telegram-main/updates`. */
176
+ readonly path: string;
177
+ /** Removes the route. Repeated calls do nothing. */
178
+ readonly unregister: () => void;
179
+ }
180
+ /** Services that Wheatley gives a Frontend when it creates a Frontend Binding. */
181
+ export interface FrontendContext {
182
+ readonly agentName: string;
183
+ readonly bindingId: string;
184
+ readonly secrets: SecretReader;
185
+ readonly log: Logger;
186
+ /** A per-Agent directory for staged attachments. Wheatley deletes old files in it. */
187
+ readonly stagingDir: string;
188
+ /**
189
+ * A persistent per-binding directory that survives daemon restarts, for adapter state such as the platform message
190
+ * of each `approval_requested` delivery. Wheatley creates it and never deletes files in it.
191
+ */
192
+ readonly dataDir: string;
193
+ /** The per-file attachment limit. The default is 10 MiB. */
194
+ readonly maxAttachmentBytes: number;
195
+ /**
196
+ * Mounts `POST /frontends/<agent>/<binding-id>/<pathSuffix>` on the Webhook Ingress (ADR 0012).
197
+ *
198
+ * Absent if the Webhook Ingress is disabled. An adapter in webhook mode must then throw from `createBinding`. Throws
199
+ * if `pathSuffix` is empty, contains `..`, or is already mounted for this binding.
200
+ */
201
+ readonly registerWebhookRoute?: (pathSuffix: string, handler: WebhookRouteHandler) => WebhookRoute;
202
+ }
203
+ /**
204
+ * One running Frontend endpoint for one Agent (ADR 0007).
205
+ *
206
+ * Wheatley calls `start` once, then any number of `deliver` and `onEvent` calls, then `stop` once.
207
+ */
208
+ export interface FrontendBinding {
209
+ /** Connects to the platform and starts to forward inbound messages to `sink`. */
210
+ readonly start: (sink: FrontendSink) => Promise<void>;
211
+ /**
212
+ * Delivers durable outbound work. Resolves once the platform confirmed it.
213
+ *
214
+ * Rejects with a `DeliveryError`: `permanent` for a deleted Chat or a removed bot, otherwise `retryable`. The outbox
215
+ * treats any other error as retryable. A retry can deliver the same `messageId` twice.
216
+ */
217
+ readonly deliver: (delivery: Delivery) => Promise<void>;
218
+ /** Receives ephemeral live progress. Must not throw or block. Omit it for minimal adapters. */
219
+ readonly onEvent?: (event: RunEvent) => void;
220
+ /** Disconnects. Wheatley sends no `deliver` or `onEvent` calls after `stop` starts. */
221
+ readonly stop: () => Promise<void>;
222
+ }
223
+ /**
224
+ * A kind of chat surface, such as Telegram, that a Plugin or Wheatley provides.
225
+ *
226
+ * Each `frontends` entry of an Agent in `config.yaml` with this `type` creates one Frontend Binding.
227
+ */
228
+ export interface Frontend<Config = JsonValue> {
229
+ /** The `type` value in `config.yaml`, for example `telegram`. */
230
+ readonly type: string;
231
+ /** Wheatley validates the binding config against it before `createBinding`. */
232
+ readonly configSchema: SchemaInput<Config>;
233
+ /** Creates a binding from validated config. Throw to report invalid setup, for example a missing secret. */
234
+ readonly createBinding: (config: Config, ctx: FrontendContext) => Promise<FrontendBinding> | FrontendBinding;
235
+ }
236
+ //# sourceMappingURL=frontend.d.ts.map
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=frontend.js.map
@@ -0,0 +1,10 @@
1
+ export { chunkMarkdown, MIN_CHUNK_LENGTH } from "./chunk.js";
2
+ export { BUILTIN_COMMANDS, type CommandName, type CommandSpec, type ParsedCommand, parseCommandText, } from "./commands.js";
3
+ export { DeliveryError, type DeliveryErrorOptions, type DeliveryFailureKind, isDeliveryError, } from "./delivery-error.js";
4
+ export type { ApprovalDecision, ApprovalOutcome, ApprovalRequestedDelivery, ApprovalResolution, ApprovalResolvedDelivery, Attachment, Delivery, DeliveryKind, Frontend, FrontendBinding, FrontendContext, FrontendSink, InboundCommand, InboundDecision, InboundMessage, MessageDelivery, MessageSource, RunEvent, WebhookRequest, WebhookResponse, WebhookRoute, WebhookRouteHandler, } from "./frontend.js";
5
+ export type { JsonObject, JsonPrimitive, JsonValue } from "./json.js";
6
+ export type { Logger, SecretReader } from "./logger.js";
7
+ export { API_VERSION, definePlugin, type Plugin, type PluginContributions, type PluginSetupContext, } from "./plugin.js";
8
+ export { isStandardJsonSchema, type JsonSchema, type SchemaInput, type SchemaOutput, type StandardJsonSchemaConverter, type StandardJsonSchemaDocument, type StandardJsonSchemaOptions, type StandardJsonSchemaProps, type StandardJsonSchemaTarget, type StandardJsonSchemaV1, type StandardSchemaIssue, type StandardSchemaResult, } from "./schema.js";
9
+ export { defineTool, type Tool, type ToolContent, type ToolContext, type ToolResult, } from "./tool.js";
10
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,7 @@
1
+ export { chunkMarkdown, MIN_CHUNK_LENGTH } from "./chunk.js";
2
+ export { BUILTIN_COMMANDS, parseCommandText, } from "./commands.js";
3
+ export { DeliveryError, isDeliveryError, } from "./delivery-error.js";
4
+ export { API_VERSION, definePlugin, } from "./plugin.js";
5
+ export { isStandardJsonSchema, } from "./schema.js";
6
+ export { defineTool, } from "./tool.js";
7
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,9 @@
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
+ //# sourceMappingURL=json.d.ts.map
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=json.js.map
@@ -0,0 +1,18 @@
1
+ import type { JsonObject } from "./json.js";
2
+ /** Structured diagnostic logger. Wheatley adds the Agent, Plugin, and Frontend Binding names to every record. */
3
+ export interface Logger {
4
+ readonly debug: (message: string, fields?: JsonObject) => void;
5
+ readonly info: (message: string, fields?: JsonObject) => void;
6
+ readonly warn: (message: string, fields?: JsonObject) => void;
7
+ readonly error: (message: string, fields?: JsonObject) => void;
8
+ }
9
+ /** Read access to the secret values of `secrets.yaml` and their environment variable overrides. */
10
+ export interface SecretReader {
11
+ /**
12
+ * Returns the value of the secret `name`, or `undefined` if no secret has that name.
13
+ *
14
+ * Never log the value. Config refers to secrets by name only.
15
+ */
16
+ readonly get: (name: string) => string | undefined;
17
+ }
18
+ //# sourceMappingURL=logger.d.ts.map
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=logger.js.map
@@ -0,0 +1,48 @@
1
+ import type { Frontend } from "./frontend.js";
2
+ import type { JsonValue } from "./json.js";
3
+ import type { Logger, SecretReader } from "./logger.js";
4
+ import type { SchemaInput } from "./schema.js";
5
+ import type { Tool } from "./tool.js";
6
+ /** The extension API version that this SDK implements. Wheatley skips Plugins with another `apiVersion`. */
7
+ export declare const API_VERSION = 1;
8
+ /** Services that Wheatley gives a Plugin during `setup`. */
9
+ export interface PluginSetupContext<Config = JsonValue> {
10
+ /** The Plugin's `config` block from `config.yaml`, validated against `configSchema`. */
11
+ readonly config: Config;
12
+ readonly agentName: string;
13
+ /** A private data directory for this Plugin in this Agent. */
14
+ readonly dataDir: string;
15
+ readonly secrets: SecretReader;
16
+ readonly log: Logger;
17
+ /** Aborts when the Agent stops during `setup`. */
18
+ readonly signal: AbortSignal;
19
+ }
20
+ /** What a Plugin adds to one Agent. */
21
+ export interface PluginContributions {
22
+ readonly tools?: readonly Tool<any>[];
23
+ readonly frontends?: readonly Frontend<any>[];
24
+ /** Releases resources when the Agent stops or restarts. */
25
+ readonly dispose?: () => Promise<void> | void;
26
+ }
27
+ /**
28
+ * An in-process extension that an Agent loads through `import()` (ADR 0006).
29
+ *
30
+ * A Plugin module default-exports this object. Each Agent that lists the Plugin calls `setup` once for its own instance.
31
+ * Agents share no Plugin state.
32
+ */
33
+ export interface Plugin<Config = JsonValue> {
34
+ readonly apiVersion: typeof API_VERSION;
35
+ /** Matches `^[a-z][a-z0-9_-]*$` and is not `mcp`. It is the namespace of the Plugin's Tools. */
36
+ readonly name: string;
37
+ readonly version: string;
38
+ /** Wheatley validates the `config` block against it before `setup`. */
39
+ readonly configSchema?: SchemaInput<Config>;
40
+ /**
41
+ * Creates the Plugin's Tools and Frontends for one Agent. If `setup` throws or rejects, Wheatley skips the Plugin and
42
+ * reports the error in Agent health. The Agent still starts.
43
+ */
44
+ readonly setup: (ctx: PluginSetupContext<Config>) => Promise<PluginContributions> | PluginContributions;
45
+ }
46
+ /** Returns `plugin` unchanged, typed as a `Plugin` so that config types flow from `configSchema` to `setup`. */
47
+ export declare const definePlugin: <Config = JsonValue>(plugin: Plugin<Config>) => Plugin<Config>;
48
+ //# sourceMappingURL=plugin.d.ts.map
@@ -0,0 +1,5 @@
1
+ /** The extension API version that this SDK implements. Wheatley skips Plugins with another `apiVersion`. */
2
+ export const API_VERSION = 1;
3
+ /** Returns `plugin` unchanged, typed as a `Plugin` so that config types flow from `configSchema` to `setup`. */
4
+ export const definePlugin = (plugin) => plugin;
5
+ //# sourceMappingURL=plugin.js.map
@@ -0,0 +1,69 @@
1
+ import type { JsonObject, JsonValue } from "./json.js";
2
+ /**
3
+ * A plain JSON Schema document (draft 2020-12), for example `{ "type": "object", "properties": {} }`.
4
+ *
5
+ * Wheatley validates input against it and forwards it to the model provider unchanged.
6
+ */
7
+ export type JsonSchema = JsonObject;
8
+ /** The JSON Schema dialects that Wheatley requests from a Standard JSON Schema converter. */
9
+ export type StandardJsonSchemaTarget = "draft-2020-12" | "draft-07" | "openapi-3.0";
10
+ /** Options that Wheatley passes to a Standard JSON Schema converter. */
11
+ export interface StandardJsonSchemaOptions {
12
+ readonly target: StandardJsonSchemaTarget;
13
+ readonly libraryOptions?: JsonObject | undefined;
14
+ }
15
+ /**
16
+ * A JSON Schema document that a Standard JSON Schema converter returns.
17
+ *
18
+ * The Standard JSON Schema V1 specification (https://standardschema.dev) fixes this type. Wheatley keeps it so that
19
+ * schemas from Zod, Valibot, ArkType, and other libraries stay assignable, and decodes the document at its boundary.
20
+ */
21
+ export type StandardJsonSchemaDocument = Record<string, unknown>;
22
+ /** The converter of the Standard JSON Schema V1 specification. */
23
+ export interface StandardJsonSchemaConverter {
24
+ readonly input: (options: StandardJsonSchemaOptions) => StandardJsonSchemaDocument;
25
+ readonly output: (options: StandardJsonSchemaOptions) => StandardJsonSchemaDocument;
26
+ }
27
+ /** One issue that a Standard Schema validator reports. */
28
+ export interface StandardSchemaIssue {
29
+ readonly message: string;
30
+ readonly path?: readonly (PropertyKey | {
31
+ readonly key: PropertyKey;
32
+ })[] | undefined;
33
+ }
34
+ /** The result of a Standard Schema `validate` call. */
35
+ export type StandardSchemaResult<Output> = {
36
+ readonly value: Output;
37
+ readonly issues?: undefined;
38
+ } | {
39
+ readonly issues: readonly StandardSchemaIssue[];
40
+ };
41
+ /** The `~standard` property of a Standard JSON Schema V1 value, with the optional Standard Schema V1 validator. */
42
+ export interface StandardJsonSchemaProps<Input, Output> {
43
+ readonly version: 1;
44
+ readonly vendor: string;
45
+ readonly jsonSchema: StandardJsonSchemaConverter;
46
+ readonly types?: {
47
+ readonly input: Input;
48
+ readonly output: Output;
49
+ } | undefined;
50
+ /**
51
+ * Present when the library also implements Standard Schema V1. Wheatley then validates input with it instead of the
52
+ * converted JSON Schema, so library refinements and transforms apply.
53
+ */
54
+ readonly validate?: (value: JsonValue) => StandardSchemaResult<Output> | Promise<StandardSchemaResult<Output>>;
55
+ }
56
+ /** A schema object that implements Standard JSON Schema V1, for example a Zod 4 schema. */
57
+ export interface StandardJsonSchemaV1<Input = JsonValue, Output = Input> {
58
+ readonly "~standard": StandardJsonSchemaProps<Input, Output>;
59
+ }
60
+ /**
61
+ * A schema that Wheatley accepts for Tool input and Plugin or Frontend configuration: plain JSON Schema or a Standard
62
+ * JSON Schema V1 object (ADR 0006).
63
+ */
64
+ export type SchemaInput<Output = JsonValue> = JsonSchema | StandardJsonSchemaV1<JsonValue, Output>;
65
+ /** The value type that a schema produces after validation. Plain JSON Schema produces `JsonValue`. */
66
+ export type SchemaOutput<Schema> = Schema extends StandardJsonSchemaV1<JsonValue, infer Output> ? Output : JsonValue;
67
+ /** Returns true if `schema` implements Standard JSON Schema V1 rather than plain JSON Schema. */
68
+ export declare const isStandardJsonSchema: <Output>(schema: SchemaInput<Output>) => schema is StandardJsonSchemaV1<JsonValue, Output>;
69
+ //# sourceMappingURL=schema.d.ts.map
@@ -0,0 +1,3 @@
1
+ /** Returns true if `schema` implements Standard JSON Schema V1 rather than plain JSON Schema. */
2
+ export const isStandardJsonSchema = (schema) => "~standard" in schema;
3
+ //# sourceMappingURL=schema.js.map
@@ -0,0 +1,69 @@
1
+ import type { JsonValue } from "./json.js";
2
+ import type { Logger } from "./logger.js";
3
+ import type { SchemaInput } from "./schema.js";
4
+ /**
5
+ * One block of Tool output. `text` and `image` have the shape of the MCP `CallToolResult` blocks of the same type, so
6
+ * they pass through. The MCP provider converts every other MCP block (`audio`, `resource_link`, embedded `resource`)
7
+ * and `structuredContent` to `text` blocks.
8
+ */
9
+ export type ToolContent = {
10
+ readonly type: "text";
11
+ readonly text: string;
12
+ } | {
13
+ readonly type: "image";
14
+ readonly mimeType: string;
15
+ readonly data: string;
16
+ };
17
+ /**
18
+ * The result of one Tool call.
19
+ *
20
+ * Set `isError` to report a failure to the model. The model reads the content and can adapt its plan.
21
+ */
22
+ export interface ToolResult {
23
+ readonly content: readonly ToolContent[];
24
+ readonly isError?: boolean;
25
+ }
26
+ /** Context of one Tool call. */
27
+ export interface ToolContext {
28
+ /** Aborts when the call times out, the Run stops, or the Agent stops. */
29
+ readonly signal: AbortSignal;
30
+ readonly agentName: string;
31
+ readonly conversationId: string;
32
+ readonly runId: string;
33
+ /**
34
+ * The Chat that started the Run, or `null` for a Run without a Chat (Trigger and maintenance Runs). Tools that act
35
+ * on "this Chat", such as `schedule_trigger`, use it as the target.
36
+ */
37
+ readonly chat: {
38
+ readonly bindingId: string;
39
+ readonly chatId: string;
40
+ } | null;
41
+ /** Stable across retries of the same call. Use it as an idempotency key for external side effects. */
42
+ readonly toolCallId: string;
43
+ /** The working directory of the Agent. */
44
+ readonly workspaceDir: string;
45
+ readonly log: Logger;
46
+ }
47
+ /**
48
+ * One callable action for an Agent (ADR 0006).
49
+ *
50
+ * Built-in Tools use bare names. Wheatley exposes Plugin Tools as `<plugin>:<name>`, so `name` must not contain `:`.
51
+ * Every call passes the Permission Policy, input validation against `inputSchema`, a timeout, and a concurrency gate
52
+ * before `execute` runs.
53
+ */
54
+ export interface Tool<Input = JsonValue> {
55
+ /** Matches `^[a-z][a-z0-9_]*$`. */
56
+ readonly name: string;
57
+ readonly description: string;
58
+ readonly inputSchema: SchemaInput<Input>;
59
+ /**
60
+ * Runs the call with validated input.
61
+ *
62
+ * Return `{ isError: true }` for expected failures. Wheatley catches a throw and returns it to the model as an error
63
+ * result. Stop work when `ctx.signal` aborts.
64
+ */
65
+ readonly execute: (input: Input, ctx: ToolContext) => Promise<ToolResult>;
66
+ }
67
+ /** Returns `tool` unchanged, typed so that a Standard JSON Schema output type flows into `execute`. */
68
+ export declare const defineTool: <Input = JsonValue>(tool: Tool<Input>) => Tool<Input>;
69
+ //# sourceMappingURL=tool.d.ts.map
@@ -0,0 +1,3 @@
1
+ /** Returns `tool` unchanged, typed so that a Standard JSON Schema output type flows into `execute`. */
2
+ export const defineTool = (tool) => tool;
3
+ //# sourceMappingURL=tool.js.map
@@ -0,0 +1,11 @@
1
+ {
2
+ "exports": {
3
+ ".": {
4
+ "default": "./dist/index.js",
5
+ "types": "./dist/index.d.ts"
6
+ }
7
+ },
8
+ "name": "@wheatley-ai/sdk",
9
+ "type": "module",
10
+ "version": "0.1.0"
11
+ }