@aidy-dev/core 0.2.0 → 0.2.2
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 +8 -0
- package/dist/index.js +32 -14
- package/package.json +5 -5
package/dist/index.d.ts
CHANGED
|
@@ -241,6 +241,14 @@ interface AidyConfig {
|
|
|
241
241
|
name?: string;
|
|
242
242
|
/** Public URL of this aidy instance (the assertion `iss`), e.g. https://console.example.com/aidy */
|
|
243
243
|
url: string;
|
|
244
|
+
/**
|
|
245
|
+
* The product's name and summary for documents served to signed-out callers when the host's
|
|
246
|
+
* OpenAPI needs a sign-in. The catalog's `info.title` and `description` win when readable.
|
|
247
|
+
*/
|
|
248
|
+
product?: {
|
|
249
|
+
name: string;
|
|
250
|
+
summary?: string;
|
|
251
|
+
};
|
|
244
252
|
/** Prefix of every route when the host mounts aidy below its root, e.g. `/assistant`. */
|
|
245
253
|
basePath?: string;
|
|
246
254
|
host: {
|
package/dist/index.js
CHANGED
|
@@ -343,6 +343,17 @@ var Unauthorized = class extends Error {
|
|
|
343
343
|
this.name = "Unauthorized";
|
|
344
344
|
}
|
|
345
345
|
};
|
|
346
|
+
/** The host answered the catalog or identity request with an error or an invalid answer. */
|
|
347
|
+
var HostUnavailable = class extends Error {
|
|
348
|
+
constructor(message) {
|
|
349
|
+
super(message);
|
|
350
|
+
this.name = "HostUnavailable";
|
|
351
|
+
}
|
|
352
|
+
};
|
|
353
|
+
/** A credential the host refuses: any 4xx, since hosts use 401, 403 and their own codes. */
|
|
354
|
+
function refused(status) {
|
|
355
|
+
return status >= 400 && status < 500;
|
|
356
|
+
}
|
|
346
357
|
/** Expiring entries by key, dropping stale ones as it goes. */
|
|
347
358
|
var TtlCache = class {
|
|
348
359
|
entries = /* @__PURE__ */ new Map();
|
|
@@ -385,8 +396,8 @@ var CatalogLoader = class {
|
|
|
385
396
|
const known = digest && this.catalogs.get(digest);
|
|
386
397
|
if (known) return known;
|
|
387
398
|
const response = await this.host.plain(this.openapi, credential);
|
|
388
|
-
if (response.status
|
|
389
|
-
if (response.status !== 200) throw new
|
|
399
|
+
if (refused(response.status)) throw new Unauthorized();
|
|
400
|
+
if (response.status !== 200) throw new HostUnavailable(`The host's OpenAPI document answered HTTP ${response.status}.`);
|
|
390
401
|
const fresh = await sha256(JSON.stringify(response.body));
|
|
391
402
|
let catalog = this.catalogs.get(fresh);
|
|
392
403
|
if (!catalog) {
|
|
@@ -427,9 +438,9 @@ var Authenticator = class {
|
|
|
427
438
|
catalog
|
|
428
439
|
};
|
|
429
440
|
const response = await this.host.plain(catalog.identity.path, credential);
|
|
430
|
-
if (response.status
|
|
441
|
+
if (refused(response.status)) throw new Unauthorized();
|
|
431
442
|
const parsed = Identity.safeParse(response.body);
|
|
432
|
-
if (response.status !== 200 || !parsed.success) throw new
|
|
443
|
+
if (response.status !== 200 || !parsed.success) throw new HostUnavailable(`The identity operation answered HTTP ${response.status} without an identity.`);
|
|
433
444
|
this.identities.set(key, parsed.data);
|
|
434
445
|
return {
|
|
435
446
|
identity: parsed.data,
|
|
@@ -1358,13 +1369,19 @@ const REQUEST_INPUT_SCHEMA = {
|
|
|
1358
1369
|
required: ["prompt", "questions"],
|
|
1359
1370
|
additionalProperties: false
|
|
1360
1371
|
};
|
|
1372
|
+
const FORM_NOTE = "Call it with only the values the user gave, even none: a form collects the rest from the user.";
|
|
1373
|
+
/** An operation with a host form is called with what the user said; the form asks for the rest. */
|
|
1374
|
+
function withoutRequired(schema) {
|
|
1375
|
+
const { required: _, ...rest } = schema;
|
|
1376
|
+
return rest;
|
|
1377
|
+
}
|
|
1361
1378
|
function modelTools(ops) {
|
|
1362
1379
|
return [
|
|
1363
1380
|
...ops.map((op) => ({
|
|
1364
1381
|
type: "function",
|
|
1365
1382
|
name: op.name,
|
|
1366
|
-
description: op.description,
|
|
1367
|
-
inputSchema: compactSchema(op.input)
|
|
1383
|
+
description: op.form ? `${op.description} ${FORM_NOTE}` : op.description,
|
|
1384
|
+
inputSchema: op.form ? withoutRequired(compactSchema(op.input)) : compactSchema(op.input)
|
|
1368
1385
|
})),
|
|
1369
1386
|
{
|
|
1370
1387
|
type: "function",
|
|
@@ -2926,10 +2943,7 @@ function mountApi(app, deps) {
|
|
|
2926
2943
|
status: "cancelling"
|
|
2927
2944
|
}, 202);
|
|
2928
2945
|
});
|
|
2929
|
-
app.get(`${API_PREFIX}/info`,
|
|
2930
|
-
await authenticate(c);
|
|
2931
|
-
return c.json({ name: deps.name });
|
|
2932
|
-
});
|
|
2946
|
+
app.get(`${API_PREFIX}/info`, (c) => c.json({ name: deps.name }));
|
|
2933
2947
|
app.put(`${API_PREFIX}/threads/:id/messages/:messageId/feedback`, async (c) => {
|
|
2934
2948
|
const principal = await authenticate(c);
|
|
2935
2949
|
const record = await thread(c, principal);
|
|
@@ -3279,7 +3293,7 @@ function mountTasks(app, deps) {
|
|
|
3279
3293
|
}
|
|
3280
3294
|
// src/version.ts
|
|
3281
3295
|
/** This package's version; scripts/version.mjs keeps it in step with package.json. */
|
|
3282
|
-
const VERSION = "0.2.
|
|
3296
|
+
const VERSION = "0.2.2";
|
|
3283
3297
|
// src/mcp.ts
|
|
3284
3298
|
/**
|
|
3285
3299
|
* The MCP server: catalog operations as tools over streamable HTTP. Sessions live in memory,
|
|
@@ -3619,7 +3633,7 @@ function createAidy(config) {
|
|
|
3619
3633
|
return;
|
|
3620
3634
|
}
|
|
3621
3635
|
};
|
|
3622
|
-
const productOf = (catalog) => catalog?.info.title ?? new URL(config.host.origin).hostname;
|
|
3636
|
+
const productOf = (catalog) => catalog?.info.title ?? config.product?.name ?? new URL(config.host.origin).hostname;
|
|
3623
3637
|
const cli = config.skill?.cli ?? {
|
|
3624
3638
|
command: "aidy",
|
|
3625
3639
|
package: "@aidy-dev/cli"
|
|
@@ -3631,7 +3645,7 @@ function createAidy(config) {
|
|
|
3631
3645
|
product,
|
|
3632
3646
|
name: skillName({
|
|
3633
3647
|
...config.skill?.name ? { name: config.skill.name } : {},
|
|
3634
|
-
product: catalog?.info.title ?? "",
|
|
3648
|
+
product: catalog?.info.title ?? config.product?.name ?? "",
|
|
3635
3649
|
origin: config.host.origin
|
|
3636
3650
|
}),
|
|
3637
3651
|
url,
|
|
@@ -3647,7 +3661,7 @@ function createAidy(config) {
|
|
|
3647
3661
|
const text = renderLlmsTxt({
|
|
3648
3662
|
product,
|
|
3649
3663
|
url,
|
|
3650
|
-
summary: catalog?.info.description ?? `${product}, operable by agents through aidy.`,
|
|
3664
|
+
summary: catalog?.info.description ?? config.product?.summary ?? `${product}, operable by agents through aidy.`,
|
|
3651
3665
|
cli,
|
|
3652
3666
|
...catalog ? { operations: catalog.operations } : {}
|
|
3653
3667
|
});
|
|
@@ -3673,6 +3687,10 @@ function createAidy(config) {
|
|
|
3673
3687
|
if (authorizationServers?.length && c.req.path.endsWith("/mcp")) headers["www-authenticate"] = `Bearer resource_metadata="${url}/.well-known/oauth-protected-resource/mcp"`;
|
|
3674
3688
|
return c.json(errorBody("unauthorized", error.message), 401, headers);
|
|
3675
3689
|
}
|
|
3690
|
+
if (error instanceof HostUnavailable) {
|
|
3691
|
+
console.error("aidy:", error.message);
|
|
3692
|
+
return c.json(errorBody("host_unavailable", error.message), 502);
|
|
3693
|
+
}
|
|
3676
3694
|
console.error("aidy: request failed", error);
|
|
3677
3695
|
return c.json(errorBody("internal", "The request failed."), 500);
|
|
3678
3696
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aidy-dev/core",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.2",
|
|
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.2",
|
|
38
|
+
"@aidy-dev/spec": "0.2.2",
|
|
39
|
+
"@aidy-dev/sql": "0.2.2"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
|
-
"@aidy-dev/client": "0.2.
|
|
42
|
+
"@aidy-dev/client": "0.2.2",
|
|
43
43
|
"@aidy-dev/conformance": "0.1.0"
|
|
44
44
|
},
|
|
45
45
|
"scripts": {
|