@aidy-dev/core 0.2.0 → 0.2.1
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 +31 -10
- 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",
|
|
@@ -3279,7 +3296,7 @@ function mountTasks(app, deps) {
|
|
|
3279
3296
|
}
|
|
3280
3297
|
// src/version.ts
|
|
3281
3298
|
/** This package's version; scripts/version.mjs keeps it in step with package.json. */
|
|
3282
|
-
const VERSION = "0.2.
|
|
3299
|
+
const VERSION = "0.2.1";
|
|
3283
3300
|
// src/mcp.ts
|
|
3284
3301
|
/**
|
|
3285
3302
|
* The MCP server: catalog operations as tools over streamable HTTP. Sessions live in memory,
|
|
@@ -3619,7 +3636,7 @@ function createAidy(config) {
|
|
|
3619
3636
|
return;
|
|
3620
3637
|
}
|
|
3621
3638
|
};
|
|
3622
|
-
const productOf = (catalog) => catalog?.info.title ?? new URL(config.host.origin).hostname;
|
|
3639
|
+
const productOf = (catalog) => catalog?.info.title ?? config.product?.name ?? new URL(config.host.origin).hostname;
|
|
3623
3640
|
const cli = config.skill?.cli ?? {
|
|
3624
3641
|
command: "aidy",
|
|
3625
3642
|
package: "@aidy-dev/cli"
|
|
@@ -3631,7 +3648,7 @@ function createAidy(config) {
|
|
|
3631
3648
|
product,
|
|
3632
3649
|
name: skillName({
|
|
3633
3650
|
...config.skill?.name ? { name: config.skill.name } : {},
|
|
3634
|
-
product: catalog?.info.title ?? "",
|
|
3651
|
+
product: catalog?.info.title ?? config.product?.name ?? "",
|
|
3635
3652
|
origin: config.host.origin
|
|
3636
3653
|
}),
|
|
3637
3654
|
url,
|
|
@@ -3647,7 +3664,7 @@ function createAidy(config) {
|
|
|
3647
3664
|
const text = renderLlmsTxt({
|
|
3648
3665
|
product,
|
|
3649
3666
|
url,
|
|
3650
|
-
summary: catalog?.info.description ?? `${product}, operable by agents through aidy.`,
|
|
3667
|
+
summary: catalog?.info.description ?? config.product?.summary ?? `${product}, operable by agents through aidy.`,
|
|
3651
3668
|
cli,
|
|
3652
3669
|
...catalog ? { operations: catalog.operations } : {}
|
|
3653
3670
|
});
|
|
@@ -3673,6 +3690,10 @@ function createAidy(config) {
|
|
|
3673
3690
|
if (authorizationServers?.length && c.req.path.endsWith("/mcp")) headers["www-authenticate"] = `Bearer resource_metadata="${url}/.well-known/oauth-protected-resource/mcp"`;
|
|
3674
3691
|
return c.json(errorBody("unauthorized", error.message), 401, headers);
|
|
3675
3692
|
}
|
|
3693
|
+
if (error instanceof HostUnavailable) {
|
|
3694
|
+
console.error("aidy:", error.message);
|
|
3695
|
+
return c.json(errorBody("host_unavailable", error.message), 502);
|
|
3696
|
+
}
|
|
3676
3697
|
console.error("aidy: request failed", error);
|
|
3677
3698
|
return c.json(errorBody("internal", "The request failed."), 500);
|
|
3678
3699
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aidy-dev/core",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.1",
|
|
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.1",
|
|
38
|
+
"@aidy-dev/spec": "0.2.1",
|
|
39
|
+
"@aidy-dev/sql": "0.2.1"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
|
-
"@aidy-dev/client": "0.2.
|
|
42
|
+
"@aidy-dev/client": "0.2.1",
|
|
43
43
|
"@aidy-dev/conformance": "0.1.0"
|
|
44
44
|
},
|
|
45
45
|
"scripts": {
|