@aidy-dev/core 0.2.2 → 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.
- package/dist/index.d.ts +2 -0
- package/dist/index.js +37 -10
- package/package.json +5 -5
package/dist/index.d.ts
CHANGED
|
@@ -299,6 +299,8 @@ interface AidyConfig {
|
|
|
299
299
|
/** OAuth protected-resource metadata for MCP clients. */
|
|
300
300
|
mcp?: {
|
|
301
301
|
authorizationServers?: string[];
|
|
302
|
+
/** The `instructions` of MCP's `initialize` result. Default: the skill guide. */
|
|
303
|
+
instructions?: string;
|
|
302
304
|
};
|
|
303
305
|
}
|
|
304
306
|
/** Workers' execution context: runs that outlive the response are registered with it. */
|
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(
|
|
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
|
|
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
|
|
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,
|
|
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.
|
|
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,
|
|
@@ -3320,7 +3341,8 @@ const SEARCH = {
|
|
|
3320
3341
|
maximum: 50
|
|
3321
3342
|
}
|
|
3322
3343
|
},
|
|
3323
|
-
required: ["q"]
|
|
3344
|
+
required: ["q"],
|
|
3345
|
+
additionalProperties: false
|
|
3324
3346
|
},
|
|
3325
3347
|
annotations: {
|
|
3326
3348
|
title: "Search",
|
|
@@ -3401,7 +3423,8 @@ var McpSessions = class {
|
|
|
3401
3423
|
version: VERSION
|
|
3402
3424
|
}, {
|
|
3403
3425
|
capabilities: { tools: {} },
|
|
3404
|
-
jsonSchemaValidator: new CfWorkerJsonSchemaValidator()
|
|
3426
|
+
jsonSchemaValidator: new CfWorkerJsonSchemaValidator(),
|
|
3427
|
+
...this.deps.instructions ? { instructions: this.deps.instructions } : {}
|
|
3405
3428
|
});
|
|
3406
3429
|
const session = {
|
|
3407
3430
|
principal,
|
|
@@ -3454,6 +3477,8 @@ var McpSessions = class {
|
|
|
3454
3477
|
const cid = `mcp_${String(extra.requestId)}`;
|
|
3455
3478
|
const input = isObject(request.params.arguments) ? request.params.arguments : {};
|
|
3456
3479
|
if (request.params.name === "search") {
|
|
3480
|
+
const unknown = Object.keys(input).filter((key) => key !== "q" && key !== "limit");
|
|
3481
|
+
if (unknown.length > 0) return failure("invalid_arguments", `unknown arguments: ${unknown.join(", ")}`);
|
|
3457
3482
|
if (typeof input.q !== "string" || !input.q.trim()) return failure("invalid_arguments", "q: a search text is required");
|
|
3458
3483
|
return text(await federatedSearch({
|
|
3459
3484
|
catalog: scope.catalog,
|
|
@@ -3558,9 +3583,11 @@ function createAidy(config) {
|
|
|
3558
3583
|
settings
|
|
3559
3584
|
});
|
|
3560
3585
|
const sources = config.sources ?? [];
|
|
3586
|
+
const mcpInstructions = config.mcp?.instructions ?? config.skill?.guide;
|
|
3561
3587
|
const mcp = new McpSessions({
|
|
3562
3588
|
host,
|
|
3563
|
-
sources
|
|
3589
|
+
sources,
|
|
3590
|
+
...mcpInstructions ? { instructions: mcpInstructions } : {}
|
|
3564
3591
|
});
|
|
3565
3592
|
const url = config.url.replace(/\/+$/, "");
|
|
3566
3593
|
let migrated;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aidy-dev/core",
|
|
3
|
-
"version": "0.2.
|
|
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.
|
|
38
|
-
"@aidy-dev/spec": "0.2.
|
|
39
|
-
"@aidy-dev/sql": "0.2.
|
|
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.
|
|
42
|
+
"@aidy-dev/client": "0.2.4",
|
|
43
43
|
"@aidy-dev/conformance": "0.1.0"
|
|
44
44
|
},
|
|
45
45
|
"scripts": {
|