@aidy-dev/core 0.2.3 → 0.2.4

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 (2) hide show
  1. package/dist/index.js +28 -7
  2. package/package.json +5 -5
package/dist/index.js CHANGED
@@ -1977,7 +1977,6 @@ async function callChain(call) {
1977
1977
  }
1978
1978
  throw new ModelUnavailable("No model of the chain is available.");
1979
1979
  }
1980
- /** Text delta coalescing: deltas are emitted at most every ~50 ms. */
1981
1980
  var TextOut = class {
1982
1981
  emitter;
1983
1982
  messageId = newId("msg");
@@ -2134,27 +2133,41 @@ async function attempt(request, model, vision, out, note) {
2134
2133
  clearTimeout(timer);
2135
2134
  }
2136
2135
  }
2136
+ /**
2137
+ * The step's emitter: a failure to record an event (the thread was deleted meanwhile) ends the
2138
+ * chain call as it is, since it says nothing of the endpoint, which must not rest for it.
2139
+ */
2140
+ function recording(emitter) {
2141
+ const stop = (error) => {
2142
+ throw new ChainStop("The run could not record its events.", { cause: error });
2143
+ };
2144
+ return {
2145
+ emit: (event) => emitter.emit(event).catch(stop),
2146
+ custom: (name, value) => emitter.custom(name, value).catch(stop)
2147
+ };
2148
+ }
2137
2149
  /** Runs one step to a usable answer, or throws ModelUnavailable (or the abort reason). */
2138
2150
  function runStep(request) {
2151
+ const emitter = recording(request.emitter);
2139
2152
  return callChain({
2140
2153
  models: request.models,
2141
2154
  chain: request.chain,
2142
2155
  images: request.images,
2143
2156
  signal: request.signal,
2144
2157
  attempt: async (model, vision, note) => {
2145
- const out = new TextOut(request.emitter);
2158
+ const out = new TextOut(emitter);
2146
2159
  try {
2147
2160
  const result = await attempt(request, model, vision, out, note);
2148
2161
  await out.end();
2149
2162
  return result;
2150
2163
  } catch (error) {
2151
2164
  await out.end();
2152
- if (out.started) await request.emitter.custom("aidy.message.discard", { messageId: out.messageId });
2165
+ if (out.started) await emitter.custom("aidy.message.discard", { messageId: out.messageId });
2153
2166
  throw error;
2154
2167
  }
2155
2168
  },
2156
2169
  retrying: async (retry) => {
2157
- await request.emitter.custom("aidy.model.retry", {
2170
+ await emitter.custom("aidy.model.retry", {
2158
2171
  step: request.step,
2159
2172
  maxAttempts: 4,
2160
2173
  ...retry
@@ -2435,7 +2448,10 @@ var Runner = class {
2435
2448
  if (!await store.acquireLease(thread.id, runId, now + LEASE_MS, now)) throw new RunActive();
2436
2449
  const emitter = new RunEmitter(store, bus, thread.id, runId);
2437
2450
  const controller = new AbortController();
2438
- this.controllers.set(runId, controller);
2451
+ this.controllers.set(runId, {
2452
+ threadId: thread.id,
2453
+ controller
2454
+ });
2439
2455
  try {
2440
2456
  await store.createRun({
2441
2457
  id: runId,
@@ -2481,7 +2497,11 @@ var Runner = class {
2481
2497
  /** Asks a run to stop; workers that do not drive it see the request at their next lease renewal. */
2482
2498
  async cancel(runId) {
2483
2499
  await this.deps.store.updateRun(runId, { cancelRequested: true });
2484
- this.controllers.get(runId)?.abort(new Cancelled());
2500
+ this.controllers.get(runId)?.controller.abort(new Cancelled());
2501
+ }
2502
+ /** Stops the runs this instance drives on a thread, before the thread is deleted. */
2503
+ cancelThread(threadId) {
2504
+ for (const entry of this.controllers.values()) if (entry.threadId === threadId) entry.controller.abort(new Cancelled());
2485
2505
  }
2486
2506
  /** Waits for the runs this instance drives. */
2487
2507
  async close() {
@@ -2899,6 +2919,7 @@ function mountApi(app, deps) {
2899
2919
  const principal = await authenticate(c);
2900
2920
  const record = await thread(c, principal);
2901
2921
  if (!record) return notFound(c);
2922
+ deps.runner.cancelThread(record.id);
2902
2923
  await store.deleteThread(record.id, record.owner);
2903
2924
  return c.body(null, 204);
2904
2925
  });
@@ -3293,7 +3314,7 @@ function mountTasks(app, deps) {
3293
3314
  }
3294
3315
  // src/version.ts
3295
3316
  /** This package's version; scripts/version.mjs keeps it in step with package.json. */
3296
- const VERSION = "0.2.3";
3317
+ const VERSION = "0.2.4";
3297
3318
  // src/mcp.ts
3298
3319
  /**
3299
3320
  * The MCP server: catalog operations as tools over streamable HTTP. Sessions live in memory,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aidy-dev/core",
3
- "version": "0.2.3",
3
+ "version": "0.2.4",
4
4
  "description": "aidy's runtime: the in-app agent, MCP server, search and generated documents over an annotated OpenAPI.",
5
5
  "license": "Apache-2.0",
6
6
  "homepage": "https://aidy.lpythu.workers.dev",
@@ -34,12 +34,12 @@
34
34
  "@modelcontextprotocol/sdk": "^1.32.2",
35
35
  "hono": "^4.13.19",
36
36
  "zod": "^4.6.7",
37
- "@aidy-dev/documents": "0.2.3",
38
- "@aidy-dev/spec": "0.2.3",
39
- "@aidy-dev/sql": "0.2.3"
37
+ "@aidy-dev/documents": "0.2.4",
38
+ "@aidy-dev/spec": "0.2.4",
39
+ "@aidy-dev/sql": "0.2.4"
40
40
  },
41
41
  "devDependencies": {
42
- "@aidy-dev/client": "0.2.3",
42
+ "@aidy-dev/client": "0.2.4",
43
43
  "@aidy-dev/conformance": "0.1.0"
44
44
  },
45
45
  "scripts": {