@aidy-dev/core 0.0.0-stage → 0.2.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.
package/LICENSE ADDED
@@ -0,0 +1,18 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ Copyright 2026 Aidy Contributors
6
+
7
+ Licensed under the Apache License, Version 2.0 (the "License");
8
+ you may not use this file except in compliance with the License.
9
+ You may obtain a copy of the License at
10
+
11
+ http://www.apache.org/licenses/LICENSE-2.0
12
+
13
+ Unless required by applicable law or agreed to in writing, software
14
+ distributed under the License is distributed on an "AS IS" BASIS,
15
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ See the License for the specific language governing permissions and
17
+ limitations under the License.
18
+
package/README.md CHANGED
@@ -1,3 +1,132 @@
1
- # Temporary Holding Version
1
+ # @aidy-dev/core
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ The aidy runtime. It reads a product's annotated OpenAPI (`x-aidy`) and serves, from one
4
+ Web-standard `fetch` handler:
5
+
6
+ - the in-app agent over aidy's HTTP API and its AG-UI 1.0 profile (`/aidy/v0/*`),
7
+ - an MCP server (`/mcp`),
8
+ - federated search (`/aidy/v0/search`),
9
+ - one-shot completions for host jobs (`POST /aidy/v0/generate`, signed by the host),
10
+ - generated agent documents (`/skill.md`, `/llms.txt`) and its public keys
11
+ (`/.well-known/aidy-keys.json`).
12
+
13
+ It uses Web-standard APIs only, so it runs on Node, Bun, Deno and Cloudflare Workers. The
14
+ contract it implements is in [`spec/`](../../spec); every behavior is pinned by the
15
+ [conformance cases](../../conformance).
16
+
17
+ ## Quickstart
18
+
19
+ ```ts
20
+ import { createAidy, SqlStore } from '@aidy-dev/core';
21
+ import { importSigningKey } from '@aidy-dev/spec/delegation';
22
+ import { sqliteDriver } from '@aidy-dev/sql/sqlite';
23
+
24
+ // An Ed25519 private JWK with its kid, from `aidy keys generate`. importSigningKey drops the
25
+ // members some runtimes refuse (Node's `alg`) and keeps the key extractable to publish it.
26
+ const signingKey = await importSigningKey(JSON.parse(process.env.AIDY_PRIVATE_JWK!));
27
+
28
+ const aidy = createAidy({
29
+ url: 'https://console.example.com',
30
+ host: { origin: 'https://console.example.com', openapi: '/openapi.json' },
31
+ signingKey,
32
+ secret: process.env.AIDY_SECRET!, // 32+ bytes; seals model API keys at rest
33
+ store: new SqlStore(sqliteDriver('aidy.db')),
34
+ models: {
35
+ chain: [
36
+ { id: 'main', provider: 'openai', model: 'gpt-5.1', apiKey: process.env.OPENAI_API_KEY },
37
+ { id: 'backup', provider: 'anthropic', model: 'claude-sonnet-4-5', apiKey: process.env.ANTHROPIC_API_KEY },
38
+ ],
39
+ },
40
+ });
41
+
42
+ // Any server that speaks `fetch`: Hono, Bun.serve, Deno.serve, a Worker.
43
+ Bun.serve({ fetch: (request) => aidy.fetch(request) });
44
+ ```
45
+
46
+ The host keeps serving its own API. aidy calls it as the user: every call carries the user's
47
+ `Authorization` and `Cookie` headers and an `Aidy-Assertion` the host verifies with aidy's
48
+ public key ([delegation](../../spec/delegation.md)).
49
+
50
+ ### Embedded in the host
51
+
52
+ Pass the host's own handler as `host.fetch` to call it in process, and mount aidy under a
53
+ prefix with `basePath` (clients then use `createClient({ baseUrl: '/assistant' })`):
54
+
55
+ ```ts
56
+ const app = new Hono();
57
+ // … the product's routes …
58
+ const aidy = createAidy({ ...config, basePath: '/assistant', host: { ...config.host, fetch: app.fetch } });
59
+ app.all('/assistant/*', (c) => aidy.fetch(c.req.raw));
60
+ ```
61
+
62
+ ### Cloudflare Workers
63
+
64
+ `createAidy` does no I/O, so build it per isolate from `env`. Pass the execution context so
65
+ runs that outlive the response are kept alive, and use the D1 driver:
66
+
67
+ ```ts
68
+ import { d1Driver } from '@aidy-dev/sql/d1';
69
+
70
+ export default {
71
+ fetch(request, env, ctx) {
72
+ aidy ??= createAidy({ ...configFrom(env), store: new SqlStore(d1Driver(env.DB)) });
73
+ return aidy.fetch(request, ctx);
74
+ },
75
+ };
76
+ ```
77
+
78
+ Any AI SDK provider model can join the chain, e.g. Workers AI through the `agents` package:
79
+
80
+ ```ts
81
+ import { createAI } from 'agents/models/ai-sdk';
82
+
83
+ const chain = [{ id: 'workers-ai', languageModel: createAI({ binding: env.AI })('@cf/zai-org/glm-4.7-flash') }];
84
+ ```
85
+
86
+ Use `agents/models/ai-sdk` rather than `workers-ai-provider`: inside workerd,
87
+ `workers-ai-provider` 4.0.1 reads streamed tool-call arguments from two fields of each chunk and
88
+ interleaves them, so every tool call fails with `invalid_arguments`.
89
+
90
+ ## Configuration
91
+
92
+ | Key | Meaning |
93
+ | --- | --- |
94
+ | `url` | aidy's public URL: the assertion `iss`, and the base of `/mcp` in generated documents. |
95
+ | `basePath` | Prefix of every route. Default `''`. |
96
+ | `host.origin` | The host's public origin: the assertion `aud` and the base of `htu`. |
97
+ | `host.baseUrl` | Where aidy reaches the host's API, if not the origin (an internal address). |
98
+ | `host.openapi` | Path or URL of the OpenAPI 3.1 document, read with each user's credential. |
99
+ | `host.fetch` | In-process fetch for embedded hosts. |
100
+ | `signingKey` | aidy's Ed25519 key for assertions. |
101
+ | `hostKeys` | Host public keys that may sign `Aidy-Host-Assertion`: deferred-task completions and `POST /aidy/v0/generate`. |
102
+ | `secret` | 32+ bytes; seals settings (model API keys) with AES-GCM. |
103
+ | `store` | `MemoryStore` or `SqlStore(driver)` over any `@aidy-dev/sql` driver. |
104
+ | `models.chain` | Endpoints tried in order. A failure not retried on the endpoint (any 4xx, a quota answer, retries used up) rests it and the next one answers: quota-like answers (402, or a body matching quota/insufficient/exhausted) 6 h, 429 60 s, others 5 min, per endpoint `cooldownSeconds: { quota, rateLimit, error }`. Each endpoint may set `temperature` and `maxOutputTokens`. Turns with images go to `vision` endpoints. Admins replace the chain through `PUT /aidy/v0/settings` and restore it with `DELETE`. |
105
+ | `instructions` | Extra system instructions, or a (possibly async) function of the user's identity. |
106
+ | `sources` | Extra search sources (`SearchSource`, with an optional `timeoutMs`, default 2000, at most 10 000), such as `@aidy-dev/knowledge`. |
107
+ | `skill` | `/skill.md`: `name` (the frontmatter slug), `guide` (Markdown placed first), `cli: { command, package?, install? }`, also named in `/llms.txt` (default `aidy`, `@aidy-dev/cli`; `install` is a free-form line that wins over `package`). |
108
+ | `name` | The assistant's display name (default `Aidy`), served at `GET /aidy/v0/info` for the UI. |
109
+ | `limits` | `maxSteps` (16), `contextTokens` (128 000), `runTimeoutSeconds` (600). |
110
+ | `mcp.authorizationServers` | Serves OAuth protected-resource metadata for MCP clients. |
111
+
112
+ ## The instance
113
+
114
+ ```ts
115
+ interface Aidy {
116
+ fetch(request: Request, ctx?: { waitUntil(promise: Promise<unknown>): void }): Promise<Response>;
117
+ migrate(): Promise<void>; // otherwise run on the first request
118
+ close(): Promise<void>; // waits for runs in progress, ends MCP sessions
119
+ }
120
+ ```
121
+
122
+ `Store` is the persistence contract; `MemoryStore` keeps everything in process (tests,
123
+ demos), and `SqlStore` keeps it in `aidy_*` tables of Postgres, SQLite or D1, with
124
+ compare-and-set approvals and tasks and a lease per thread, so several workers can share one
125
+ database.
126
+
127
+ ## Development
128
+
129
+ ```sh
130
+ pnpm --filter @aidy-dev/core test # unit tests and every conformance case (memory, sqlite)
131
+ AIDY_TEST_POSTGRES_URL=postgres://… pnpm --filter @aidy-dev/core test # and on Postgres
132
+ ```
@@ -0,0 +1,400 @@
1
+ import "hono";
2
+ import { Identity } from "@aidy-dev/spec/catalog";
3
+ import { SigningKey, VerificationKeys } from "@aidy-dev/spec/delegation";
4
+ import { Form } from "@aidy-dev/spec/protocol";
5
+ import { SearchHit } from "@aidy-dev/spec/search";
6
+ import "zod";
7
+ import { LanguageModelV4, SharedV4ProviderOptions } from "@ai-sdk/provider";
8
+ import { SqlDriver } from "@aidy-dev/sql";
9
+ import { Interrupt, Message } from "@ag-ui/core";
10
+ type Owner = {
11
+ subject: string;
12
+ tenant?: string;
13
+ };
14
+ interface ThreadRecord {
15
+ readonly id: string;
16
+ readonly owner: Owner;
17
+ readonly title: string;
18
+ readonly createdAt: string;
19
+ readonly updatedAt: string;
20
+ }
21
+ /** An AG-UI event as aidy stores and streams it; `metadata.aidy.seq` is set on append. */
22
+ type AidyEvent = {
23
+ type: string;
24
+ [key: string]: unknown;
25
+ };
26
+ interface StoredEvent {
27
+ readonly seq: number;
28
+ readonly runId: string;
29
+ readonly event: AidyEvent;
30
+ }
31
+ type RunStatus = 'running' | 'finished' | 'interrupted' | 'failed' | 'cancelled';
32
+ /** What a run remembers across its steps, and across the runs that resume it. */
33
+ interface RunState {
34
+ /** Digest of the catalog the run works with (see CatalogLoader). */
35
+ catalog: string;
36
+ steps: number;
37
+ /** Guard keys of reads that succeeded since the last write. */
38
+ reads: string[];
39
+ /** Guard key → tool message content of writes that succeeded. */
40
+ writes: Record<string, string>;
41
+ /** Operation → error message of approved writes that failed. */
42
+ failedWrites: Record<string, string>;
43
+ /** The next step is offered no tools: the model must answer from what it has. */
44
+ answerOnly: boolean;
45
+ /** Search hits the model may cite as `[n]`, n = index + 1. */
46
+ hits: CitedHit[];
47
+ }
48
+ interface CitedHit {
49
+ readonly type: string;
50
+ readonly id: string;
51
+ readonly title: string;
52
+ readonly url: string;
53
+ readonly excerpt?: string;
54
+ readonly updatedAt?: string;
55
+ }
56
+ interface RunRecord {
57
+ readonly id: string;
58
+ readonly threadId: string;
59
+ readonly status: RunStatus;
60
+ readonly cancelRequested: boolean;
61
+ readonly state: RunState;
62
+ readonly createdAt: string;
63
+ }
64
+ /** A tool call the model made, as it is kept while it waits. */
65
+ interface PendingToolCall {
66
+ readonly id: string;
67
+ readonly name: string;
68
+ readonly arguments: Record<string, unknown>;
69
+ }
70
+ /** What a paused call needs to go on once its interrupt is answered. */
71
+ type PendingCall = {
72
+ readonly kind: 'approval';
73
+ readonly call: PendingToolCall;
74
+ readonly argsHash: string;
75
+ readonly guardKey: string;
76
+ } | {
77
+ readonly kind: 'form';
78
+ readonly call: PendingToolCall;
79
+ readonly form: Form;
80
+ readonly guardKey: string;
81
+ } | {
82
+ readonly kind: 'input';
83
+ readonly call: PendingToolCall;
84
+ readonly form: Form;
85
+ } | {
86
+ readonly kind: 'task';
87
+ readonly call: PendingToolCall;
88
+ readonly taskId: string;
89
+ readonly guardKey: string;
90
+ };
91
+ type InterruptStatus = 'open' | 'resolved' | 'cancelled';
92
+ interface InterruptRecord {
93
+ readonly id: string;
94
+ readonly threadId: string;
95
+ readonly runId: string;
96
+ readonly status: InterruptStatus;
97
+ readonly interrupt: Interrupt;
98
+ readonly pending: PendingCall;
99
+ readonly createdAt: string;
100
+ }
101
+ type TaskStatus = 'pending' | 'succeeded' | 'failed' | 'cancelled';
102
+ interface TaskRecord {
103
+ readonly id: string;
104
+ readonly threadId: string;
105
+ readonly interruptId: string;
106
+ readonly op: string;
107
+ readonly owner: Owner;
108
+ readonly status: TaskStatus;
109
+ readonly result?: unknown;
110
+ }
111
+ /** A user's rating of an assistant message; one per message, the latest wins. */
112
+ interface FeedbackRecord {
113
+ readonly threadId: string;
114
+ readonly messageId: string;
115
+ readonly owner: Owner;
116
+ readonly rating: 'up' | 'down';
117
+ readonly comment?: string;
118
+ /** When the rating was given (or last replaced), RFC 3339 UTC. */
119
+ readonly createdAt: string;
120
+ }
121
+ interface FeedbackQuery {
122
+ /** Only the feedback on threads of this tenant ('' or absent: of no tenant). */
123
+ readonly tenant?: string;
124
+ /** Only feedback given at or after this RFC 3339 UTC time. */
125
+ readonly since?: string;
126
+ /** The `next` of the previous page. */
127
+ readonly cursor?: string;
128
+ readonly limit: number;
129
+ }
130
+ interface Store {
131
+ /** Creates or upgrades the store's tables. */
132
+ migrate(): Promise<void>;
133
+ createThread(thread: ThreadRecord): Promise<void>;
134
+ getThread(id: string, owner: Owner): Promise<ThreadRecord | undefined>;
135
+ /** Newest first. `next` is the cursor of the following page. */
136
+ listThreads(owner: Owner, cursor?: string, limit?: number): Promise<{
137
+ items: ThreadRecord[];
138
+ next?: string;
139
+ }>;
140
+ updateThread(id: string, owner: Owner, patch: {
141
+ title?: string;
142
+ }): Promise<void>;
143
+ /** Deletes the thread with its messages, events, runs, interrupts and tasks. */
144
+ deleteThread(id: string, owner: Owner): Promise<void>;
145
+ listMessages(threadId: string): Promise<Message[]>;
146
+ appendMessages(threadId: string, messages: readonly Message[]): Promise<void>;
147
+ /** Stores the event under the thread's next `seq` and answers it. */
148
+ appendEvent(threadId: string, runId: string, event: AidyEvent): Promise<number>;
149
+ listEvents(threadId: string, after: number, limit?: number): Promise<StoredEvent[]>;
150
+ /** Takes the thread's run lease when it is free, expired, or already this run's. */
151
+ acquireLease(threadId: string, runId: string, until: number, now: number): Promise<boolean>;
152
+ /** Extends the lease; false when the run no longer holds it. */
153
+ renewLease(threadId: string, runId: string, until: number): Promise<boolean>;
154
+ releaseLease(threadId: string, runId: string): Promise<void>;
155
+ createRun(run: RunRecord): Promise<void>;
156
+ getRun(id: string): Promise<RunRecord | undefined>;
157
+ updateRun(id: string, patch: {
158
+ status?: RunStatus;
159
+ state?: RunState;
160
+ cancelRequested?: boolean;
161
+ }): Promise<void>;
162
+ createInterrupt(record: InterruptRecord): Promise<void>;
163
+ listOpenInterrupts(threadId: string): Promise<InterruptRecord[]>;
164
+ /** Closes an open interrupt; false when it was not open (someone else answered it). */
165
+ closeInterrupt(id: string, status: Exclude<InterruptStatus, 'open'>): Promise<boolean>;
166
+ createTask(task: TaskRecord): Promise<void>;
167
+ getTask(id: string): Promise<TaskRecord | undefined>;
168
+ /** Completes a pending task; false when it was not pending. */
169
+ completeTask(id: string, status: Exclude<TaskStatus, 'pending'>, result?: unknown): Promise<boolean>;
170
+ /** Records feedback, replacing the previous rating of the same message. */
171
+ putFeedback(record: FeedbackRecord): Promise<void>;
172
+ /** Feedback oldest first; `next` is the cursor of the following page. */
173
+ listFeedback(query: FeedbackQuery): Promise<{
174
+ items: FeedbackRecord[];
175
+ next?: string;
176
+ }>;
177
+ /** The sealed settings document, if any. */
178
+ getSettings(): Promise<string | undefined>;
179
+ putSettings(sealed: string): Promise<void>;
180
+ deleteSettings(): Promise<void>;
181
+ }
182
+ /**
183
+ * How long an endpoint rests after a failure that moved the chain past it, in seconds:
184
+ * `quota` after 402 or an exhausted quota (default 6 h), `rateLimit` after 429 (60 s), `error`
185
+ * after any other failure (5 min).
186
+ */
187
+ interface CooldownSeconds {
188
+ quota?: number;
189
+ rateLimit?: number;
190
+ error?: number;
191
+ }
192
+ /** Settings every chain endpoint takes. */
193
+ interface EndpointOptions {
194
+ /** Used for turns with images; other endpoints get a note in place of each image. */
195
+ vision?: boolean;
196
+ /** Sampling temperature; the provider's default when unset. */
197
+ temperature?: number;
198
+ /** The most tokens one answer may have; the provider's default when unset. */
199
+ maxOutputTokens?: number;
200
+ cooldownSeconds?: CooldownSeconds;
201
+ }
202
+ /** A model aidy builds from an AI SDK provider package. */
203
+ interface ProviderEndpoint extends EndpointOptions {
204
+ /** Stable id: settings keep an entry's API key by it. */
205
+ id: string;
206
+ provider: 'openai-compatible' | 'openai' | 'anthropic';
207
+ model: string;
208
+ baseURL?: string;
209
+ apiKey?: string;
210
+ /** Passed to the provider, e.g. `{ "openai-compatible": { enable_thinking: false } }`. */
211
+ providerOptions?: SharedV4ProviderOptions;
212
+ }
213
+ /** Any AI SDK provider model, e.g. Workers AI through `workers-ai-provider`. */
214
+ interface CustomEndpoint extends EndpointOptions {
215
+ /** Stable id, shown in settings. */
216
+ id: string;
217
+ languageModel: LanguageModelV4;
218
+ }
219
+ type ModelEndpoint = ProviderEndpoint | CustomEndpoint;
220
+ interface ModelSettings {
221
+ /**
222
+ * Tried in order. An endpoint that fails in a way not retried on it rests (see
223
+ * `cooldownSeconds`) and the next one answers. Turns with images go to `vision` endpoints.
224
+ */
225
+ chain: ModelEndpoint[];
226
+ }
227
+ interface SearchSource {
228
+ /** Matches OPERATION_NAME, e.g. "knowledge". */
229
+ readonly name: string;
230
+ /** How long federated search waits for this source. Default 2000, at most 10000. */
231
+ readonly timeoutMs?: number;
232
+ search(query: string, options: {
233
+ limit: number;
234
+ identity: Identity;
235
+ }): Promise<SearchHit[]>;
236
+ }
237
+ /** Instructions for the model, or a function of the user that answers them. */
238
+ type Instructions = string | ((identity: Identity) => string | Promise<string>);
239
+ interface AidyConfig {
240
+ /** Display name of the assistant. Default "Aidy". */
241
+ name?: string;
242
+ /** Public URL of this aidy instance (the assertion `iss`), e.g. https://console.example.com/aidy */
243
+ url: string;
244
+ /** Prefix of every route when the host mounts aidy below its root, e.g. `/assistant`. */
245
+ basePath?: string;
246
+ host: {
247
+ /** The host origin (the assertion `aud`). */
248
+ origin: string;
249
+ /** Where aidy reaches the host's API. Default: origin. */
250
+ baseUrl?: string;
251
+ /** Path or absolute URL of the host's OpenAPI 3.1 document, fetched with the user's credential. */
252
+ openapi: string;
253
+ /** In-process fetch for embedded hosts (e.g. Hono `app.fetch`). Default: global fetch. */
254
+ fetch?: (request: Request) => Promise<Response>;
255
+ };
256
+ /** aidy's Ed25519 signing key (assertions). Its private key must be extractable, to publish the public key. */
257
+ signingKey: SigningKey;
258
+ /** Host public keys that may sign `Aidy-Host-Assertion` (deferred-task completion). */
259
+ hostKeys?: VerificationKeys;
260
+ /**
261
+ * 32+ byte secret that seals settings (model API keys) at rest. To rotate it, give a list: the
262
+ * first seals, every one unseals, and settings sealed with an older one are sealed again.
263
+ */
264
+ secret: string | readonly string[];
265
+ store: Store;
266
+ /** Defaults; admins override them through /aidy/v0/settings. */
267
+ models: ModelSettings;
268
+ instructions?: Instructions;
269
+ /** Extra search sources, e.g. knowledge. */
270
+ sources?: SearchSource[];
271
+ /** /skill.md: the hand-written guide placed before the generated sections, and the CLI it names. */
272
+ skill?: {
273
+ /** The skill's `name`; default the product's slug, else the host's first hostname label. */
274
+ name?: string;
275
+ guide?: string;
276
+ /**
277
+ * The CLI /skill.md and /llms.txt name, and how to install it: its npm `package`, or a
278
+ * free-form `install` line (which wins). Default `aidy` from `@aidy-dev/cli`.
279
+ */
280
+ cli?: {
281
+ command: string;
282
+ package?: string;
283
+ install?: string;
284
+ };
285
+ };
286
+ limits?: {
287
+ maxSteps?: number;
288
+ contextTokens?: number;
289
+ runTimeoutSeconds?: number;
290
+ };
291
+ /** OAuth protected-resource metadata for MCP clients. */
292
+ mcp?: {
293
+ authorizationServers?: string[];
294
+ };
295
+ }
296
+ /** Workers' execution context: runs that outlive the response are registered with it. */
297
+ interface ExecutionContext {
298
+ waitUntil(promise: Promise<unknown>): void;
299
+ }
300
+ interface Aidy {
301
+ /** Handles /aidy/v0/*, /mcp, /skill.md, /llms.txt, /.well-known/aidy-keys.json. */
302
+ fetch(request: Request, ctx?: ExecutionContext): Promise<Response>;
303
+ /** Creates or upgrades the store's tables; otherwise done on the first request. */
304
+ migrate(): Promise<void>;
305
+ /** Waits for the runs in progress and ends MCP sessions. */
306
+ close(): Promise<void>;
307
+ }
308
+ /** Builds an aidy instance. It does no I/O until the first request (Workers build one per isolate). */
309
+ export declare function createAidy(config: AidyConfig): Aidy;
310
+ export declare class MemoryStore implements Store {
311
+ private readonly threads;
312
+ private readonly runs;
313
+ private readonly interrupts;
314
+ private readonly tasks;
315
+ private readonly feedback;
316
+ private settings;
317
+ migrate(): Promise<void>;
318
+ createThread(thread: ThreadRecord): Promise<void>;
319
+ getThread(id: string, owner: Owner): Promise<ThreadRecord | undefined>;
320
+ listThreads(owner: Owner, cursor?: string, limit?: number): Promise<{
321
+ items: ThreadRecord[];
322
+ next?: string;
323
+ }>;
324
+ updateThread(id: string, owner: Owner, patch: {
325
+ title?: string;
326
+ }): Promise<void>;
327
+ deleteThread(id: string, owner: Owner): Promise<void>;
328
+ listMessages(threadId: string): Promise<Message[]>;
329
+ appendMessages(threadId: string, messages: readonly Message[]): Promise<void>;
330
+ appendEvent(threadId: string, runId: string, event: AidyEvent): Promise<number>;
331
+ listEvents(threadId: string, after: number, limit?: number): Promise<StoredEvent[]>;
332
+ acquireLease(threadId: string, runId: string, until: number, now: number): Promise<boolean>;
333
+ renewLease(threadId: string, runId: string, until: number): Promise<boolean>;
334
+ releaseLease(threadId: string, runId: string): Promise<void>;
335
+ createRun(run: RunRecord): Promise<void>;
336
+ getRun(id: string): Promise<RunRecord | undefined>;
337
+ updateRun(id: string, patch: {
338
+ status?: RunStatus;
339
+ state?: RunState;
340
+ cancelRequested?: boolean;
341
+ }): Promise<void>;
342
+ createInterrupt(record: InterruptRecord): Promise<void>;
343
+ listOpenInterrupts(threadId: string): Promise<InterruptRecord[]>;
344
+ closeInterrupt(id: string, status: Exclude<InterruptStatus, 'open'>): Promise<boolean>;
345
+ createTask(task: TaskRecord): Promise<void>;
346
+ getTask(id: string): Promise<TaskRecord | undefined>;
347
+ completeTask(id: string, status: Exclude<TaskStatus, 'pending'>, result?: unknown): Promise<boolean>;
348
+ getSettings(): Promise<string | undefined>;
349
+ putSettings(sealed: string): Promise<void>;
350
+ deleteSettings(): Promise<void>;
351
+ putFeedback(record: FeedbackRecord): Promise<void>;
352
+ listFeedback(query: FeedbackQuery): Promise<{
353
+ items: FeedbackRecord[];
354
+ next?: string;
355
+ }>;
356
+ }
357
+ export declare class SqlStore implements Store {
358
+ private readonly db;
359
+ constructor(driver: SqlDriver);
360
+ migrate(): Promise<void>;
361
+ createThread(thread: ThreadRecord): Promise<void>;
362
+ getThread(id: string, owner: Owner): Promise<ThreadRecord | undefined>;
363
+ listThreads(owner: Owner, cursor?: string, limit?: number): Promise<{
364
+ items: ThreadRecord[];
365
+ next?: string;
366
+ }>;
367
+ updateThread(id: string, owner: Owner, patch: {
368
+ title?: string;
369
+ }): Promise<void>;
370
+ deleteThread(id: string, owner: Owner): Promise<void>;
371
+ listMessages(threadId: string): Promise<Message[]>;
372
+ appendMessages(threadId: string, messages: readonly Message[]): Promise<void>;
373
+ appendEvent(threadId: string, runId: string, event: AidyEvent): Promise<number>;
374
+ listEvents(threadId: string, after: number, limit?: number): Promise<StoredEvent[]>;
375
+ acquireLease(threadId: string, runId: string, until: number, now: number): Promise<boolean>;
376
+ renewLease(threadId: string, runId: string, until: number): Promise<boolean>;
377
+ releaseLease(threadId: string, runId: string): Promise<void>;
378
+ createRun(run: RunRecord): Promise<void>;
379
+ getRun(id: string): Promise<RunRecord | undefined>;
380
+ updateRun(id: string, patch: {
381
+ status?: RunStatus;
382
+ state?: RunState;
383
+ cancelRequested?: boolean;
384
+ }): Promise<void>;
385
+ createInterrupt(record: InterruptRecord): Promise<void>;
386
+ listOpenInterrupts(threadId: string): Promise<InterruptRecord[]>;
387
+ closeInterrupt(id: string, status: Exclude<InterruptStatus, 'open'>): Promise<boolean>;
388
+ createTask(task: TaskRecord): Promise<void>;
389
+ getTask(id: string): Promise<TaskRecord | undefined>;
390
+ completeTask(id: string, status: Exclude<TaskStatus, 'pending'>, result?: unknown): Promise<boolean>;
391
+ getSettings(): Promise<string | undefined>;
392
+ putSettings(sealed: string): Promise<void>;
393
+ deleteSettings(): Promise<void>;
394
+ putFeedback(record: FeedbackRecord): Promise<void>;
395
+ listFeedback(query: FeedbackQuery): Promise<{
396
+ items: FeedbackRecord[];
397
+ next?: string;
398
+ }>;
399
+ }
400
+ export type { Aidy, AidyConfig, AidyEvent, CitedHit, CooldownSeconds, CustomEndpoint, ExecutionContext, FeedbackQuery, FeedbackRecord, Instructions, InterruptRecord, InterruptStatus, ModelEndpoint, ModelSettings, Owner, PendingCall, PendingToolCall, ProviderEndpoint, RunRecord, RunState, RunStatus, SearchSource, Store, StoredEvent, TaskRecord, TaskStatus, ThreadRecord };