narrarium-engine 0.1.7 → 0.1.9
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/README.md +360 -26
- package/dist/ai/body.d.ts +20 -0
- package/dist/ai/body.d.ts.map +1 -0
- package/dist/ai/body.js +112 -0
- package/dist/ai/body.js.map +1 -0
- package/dist/ai/catalog-fetch.d.ts +51 -0
- package/dist/ai/catalog-fetch.d.ts.map +1 -0
- package/dist/ai/catalog-fetch.js +261 -0
- package/dist/ai/catalog-fetch.js.map +1 -0
- package/dist/ai/catalog-support.d.ts +13 -0
- package/dist/ai/catalog-support.d.ts.map +1 -0
- package/dist/ai/catalog-support.js +28 -0
- package/dist/ai/catalog-support.js.map +1 -0
- package/dist/ai/catalog.d.ts +148 -0
- package/dist/ai/catalog.d.ts.map +1 -0
- package/dist/ai/catalog.js +367 -0
- package/dist/ai/catalog.js.map +1 -0
- package/dist/ai/config.d.ts +83 -7
- package/dist/ai/config.d.ts.map +1 -1
- package/dist/ai/config.js +83 -11
- package/dist/ai/config.js.map +1 -1
- package/dist/ai/fetch-client.d.ts +20 -0
- package/dist/ai/fetch-client.d.ts.map +1 -1
- package/dist/ai/fetch-client.js +49 -24
- package/dist/ai/fetch-client.js.map +1 -1
- package/dist/ai/probe.d.ts +40 -0
- package/dist/ai/probe.d.ts.map +1 -0
- package/dist/ai/probe.js +110 -0
- package/dist/ai/probe.js.map +1 -0
- package/dist/ai/request.d.ts +58 -5
- package/dist/ai/request.d.ts.map +1 -1
- package/dist/ai/request.js +96 -7
- package/dist/ai/request.js.map +1 -1
- package/dist/ai/router.d.ts +12 -1
- package/dist/ai/router.d.ts.map +1 -1
- package/dist/ai/router.js +10 -2
- package/dist/ai/router.js.map +1 -1
- package/dist/ai/routing.d.ts +15 -4
- package/dist/ai/routing.d.ts.map +1 -1
- package/dist/ai/routing.js +25 -6
- package/dist/ai/routing.js.map +1 -1
- package/dist/ai/token-limit.d.ts +4 -4
- package/dist/ai/token-limit.d.ts.map +1 -1
- package/dist/ai/token-limit.js +5 -4
- package/dist/ai/token-limit.js.map +1 -1
- package/dist/ai/types.d.ts +12 -1
- package/dist/ai/types.d.ts.map +1 -1
- package/dist/ai/types.js +12 -0
- package/dist/ai/types.js.map +1 -1
- package/dist/autopilot/errors.d.ts +4 -3
- package/dist/autopilot/errors.d.ts.map +1 -1
- package/dist/autopilot/errors.js +21 -5
- package/dist/autopilot/errors.js.map +1 -1
- package/dist/autopilot/frozen.d.ts +169 -0
- package/dist/autopilot/frozen.d.ts.map +1 -0
- package/dist/autopilot/frozen.js +495 -0
- package/dist/autopilot/frozen.js.map +1 -0
- package/dist/autopilot/outline-check.d.ts +39 -0
- package/dist/autopilot/outline-check.d.ts.map +1 -0
- package/dist/autopilot/outline-check.js +81 -0
- package/dist/autopilot/outline-check.js.map +1 -0
- package/dist/autopilot/planner.d.ts +29 -1
- package/dist/autopilot/planner.d.ts.map +1 -1
- package/dist/autopilot/planner.js +78 -8
- package/dist/autopilot/planner.js.map +1 -1
- package/dist/autopilot/profile-check.d.ts +7 -4
- package/dist/autopilot/profile-check.d.ts.map +1 -1
- package/dist/autopilot/profile-check.js +9 -6
- package/dist/autopilot/profile-check.js.map +1 -1
- package/dist/autopilot/runner.d.ts +17 -3
- package/dist/autopilot/runner.d.ts.map +1 -1
- package/dist/autopilot/runner.js +127 -20
- package/dist/autopilot/runner.js.map +1 -1
- package/dist/autopilot/session.d.ts +34 -1
- package/dist/autopilot/session.d.ts.map +1 -1
- package/dist/autopilot/session.js +202 -2
- package/dist/autopilot/session.js.map +1 -1
- package/dist/autopilot/state.d.ts +12 -3
- package/dist/autopilot/state.d.ts.map +1 -1
- package/dist/autopilot/state.js +203 -12
- package/dist/autopilot/state.js.map +1 -1
- package/dist/autopilot/tasks.d.ts +14 -2
- package/dist/autopilot/tasks.d.ts.map +1 -1
- package/dist/autopilot/tasks.js +480 -36
- package/dist/autopilot/tasks.js.map +1 -1
- package/dist/autopilot/types.d.ts +193 -12
- package/dist/autopilot/types.d.ts.map +1 -1
- package/dist/autopilot/types.js +9 -2
- package/dist/autopilot/types.js.map +1 -1
- package/dist/book/context.d.ts +3 -0
- package/dist/book/context.d.ts.map +1 -1
- package/dist/book/context.js +7 -1
- package/dist/book/context.js.map +1 -1
- package/dist/book/freeze.d.ts +115 -0
- package/dist/book/freeze.d.ts.map +1 -0
- package/dist/book/freeze.js +286 -0
- package/dist/book/freeze.js.map +1 -0
- package/dist/book/outline.d.ts +245 -0
- package/dist/book/outline.d.ts.map +1 -0
- package/dist/book/outline.js +488 -0
- package/dist/book/outline.js.map +1 -0
- package/dist/book/paths.d.ts +18 -0
- package/dist/book/paths.d.ts.map +1 -1
- package/dist/book/paths.js +25 -0
- package/dist/book/paths.js.map +1 -1
- package/dist/book/snapshot.d.ts +25 -1
- package/dist/book/snapshot.d.ts.map +1 -1
- package/dist/book/snapshot.js +24 -4
- package/dist/book/snapshot.js.map +1 -1
- package/dist/director/opinion.d.ts +6 -0
- package/dist/director/opinion.d.ts.map +1 -1
- package/dist/director/opinion.js +4 -1
- package/dist/director/opinion.js.map +1 -1
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -1
- package/dist/profiles/evaluation-style.d.ts +44 -0
- package/dist/profiles/evaluation-style.d.ts.map +1 -0
- package/dist/profiles/evaluation-style.js +152 -0
- package/dist/profiles/evaluation-style.js.map +1 -0
- package/dist/server/client.d.ts +46 -2
- package/dist/server/client.d.ts.map +1 -1
- package/dist/server/client.js +57 -0
- package/dist/server/client.js.map +1 -1
- package/dist/server/protocol.d.ts +120 -2
- package/dist/server/protocol.d.ts.map +1 -1
- package/dist/server/protocol.js +36 -0
- package/dist/server/protocol.js.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { DeadlineClock } from "./deadlines.js";
|
|
2
|
+
/** Stops reading without waiting for the other side: whatever it does with the cancel, the call must not hang on it. */
|
|
3
|
+
export declare function release(reader: ReadableStreamDefaultReader<Uint8Array>): void;
|
|
4
|
+
/** Lets a body go that nobody is going to read (an error, a reply that arrived too late, or one that the call gave up). */
|
|
5
|
+
export declare function discardBody(response: Response): void;
|
|
6
|
+
/** Why a body could not be read as JSON: it is not (`invalid`), it is bigger than it may be (`too-large`), or the connection broke while it was read (`lost`). */
|
|
7
|
+
export type BodyFault = "invalid" | "too-large" | "lost";
|
|
8
|
+
/** A body that cannot be used. It says only why, never what the body held. */
|
|
9
|
+
export declare class BodyError extends Error {
|
|
10
|
+
readonly fault: BodyFault;
|
|
11
|
+
constructor(fault: BodyFault);
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Reads a body that has to be one small JSON value, from an endpoint nobody vouches for. A type that says it is not JSON, a length that is not a number
|
|
15
|
+
* or is over `maxBytes` is refused before a byte is read (the body is let go); a body that grows past `maxBytes` whatever its length said is cut where
|
|
16
|
+
* it passes the limit; every piece restarts the silence the clock watches, and the reader is let go however the read ends but by the end of the body.
|
|
17
|
+
* A deadline or the author's cancel is the clock's (it rejects at once, whatever the read does); anything else that goes wrong is a `BodyError`.
|
|
18
|
+
*/
|
|
19
|
+
export declare function readBoundedJson(response: Response, clock: DeadlineClock, maxBytes: number): Promise<unknown>;
|
|
20
|
+
//# sourceMappingURL=body.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"body.d.ts","sourceRoot":"","sources":["../../src/ai/body.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAIpD,wHAAwH;AACxH,wBAAgB,OAAO,CAAC,MAAM,EAAE,2BAA2B,CAAC,UAAU,CAAC,GAAG,IAAI,CAM7E;AAED,2HAA2H;AAC3H,wBAAgB,WAAW,CAAC,QAAQ,EAAE,QAAQ,GAAG,IAAI,CAMpD;AAED,kKAAkK;AAClK,MAAM,MAAM,SAAS,GAAG,SAAS,GAAG,WAAW,GAAG,MAAM,CAAC;AAEzD,8EAA8E;AAC9E,qBAAa,SAAU,SAAQ,KAAK;IACtB,QAAQ,CAAC,KAAK,EAAE,SAAS;gBAAhB,KAAK,EAAE,SAAS;CAItC;AAID;;;;;GAKG;AACH,wBAAsB,eAAe,CAAC,QAAQ,EAAE,QAAQ,EAAE,KAAK,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAkElH"}
|
package/dist/ai/body.js
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
// What reading a body from an endpoint needs, whoever reads it: the chat client, the model catalog and the probe. Internal: not exported by the package.
|
|
2
|
+
/** Stops reading without waiting for the other side: whatever it does with the cancel, the call must not hang on it. */
|
|
3
|
+
export function release(reader) {
|
|
4
|
+
try {
|
|
5
|
+
void reader.cancel().catch(() => undefined);
|
|
6
|
+
}
|
|
7
|
+
catch {
|
|
8
|
+
// A reader that cannot be cancelled is of no use any more.
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
/** Lets a body go that nobody is going to read (an error, a reply that arrived too late, or one that the call gave up). */
|
|
12
|
+
export function discardBody(response) {
|
|
13
|
+
try {
|
|
14
|
+
void response.body?.cancel().catch(() => undefined);
|
|
15
|
+
}
|
|
16
|
+
catch {
|
|
17
|
+
// A body that is locked or already read has nothing left to discard.
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
/** A body that cannot be used. It says only why, never what the body held. */
|
|
21
|
+
export class BodyError extends Error {
|
|
22
|
+
fault;
|
|
23
|
+
constructor(fault) {
|
|
24
|
+
super(`The body could not be read (${fault}).`);
|
|
25
|
+
this.fault = fault;
|
|
26
|
+
this.name = "BodyError";
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
const JSON_TYPE = /\/json(?:\s*;|$)|\+json(?:\s*;|$)/i;
|
|
30
|
+
/**
|
|
31
|
+
* Reads a body that has to be one small JSON value, from an endpoint nobody vouches for. A type that says it is not JSON, a length that is not a number
|
|
32
|
+
* or is over `maxBytes` is refused before a byte is read (the body is let go); a body that grows past `maxBytes` whatever its length said is cut where
|
|
33
|
+
* it passes the limit; every piece restarts the silence the clock watches, and the reader is let go however the read ends but by the end of the body.
|
|
34
|
+
* A deadline or the author's cancel is the clock's (it rejects at once, whatever the read does); anything else that goes wrong is a `BodyError`.
|
|
35
|
+
*/
|
|
36
|
+
export async function readBoundedJson(response, clock, maxBytes) {
|
|
37
|
+
const type = response.headers?.get?.("content-type") ?? "";
|
|
38
|
+
if (type && !JSON_TYPE.test(type)) {
|
|
39
|
+
discardBody(response);
|
|
40
|
+
throw new BodyError("invalid");
|
|
41
|
+
}
|
|
42
|
+
const length = response.headers?.get?.("content-length") ?? null;
|
|
43
|
+
if (length !== null) {
|
|
44
|
+
if (!/^\d+$/.test(length.trim())) {
|
|
45
|
+
discardBody(response);
|
|
46
|
+
throw new BodyError("invalid");
|
|
47
|
+
}
|
|
48
|
+
if (Number(length) > maxBytes) {
|
|
49
|
+
discardBody(response);
|
|
50
|
+
throw new BodyError("too-large");
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
let reader;
|
|
54
|
+
try {
|
|
55
|
+
reader = response.body?.getReader();
|
|
56
|
+
}
|
|
57
|
+
catch {
|
|
58
|
+
discardBody(response);
|
|
59
|
+
throw new BodyError("invalid");
|
|
60
|
+
}
|
|
61
|
+
if (!reader)
|
|
62
|
+
throw new BodyError("invalid");
|
|
63
|
+
let exhausted = false;
|
|
64
|
+
try {
|
|
65
|
+
const chunks = [];
|
|
66
|
+
let size = 0;
|
|
67
|
+
for (;;) {
|
|
68
|
+
let piece;
|
|
69
|
+
try {
|
|
70
|
+
piece = await clock.guard(reader.read());
|
|
71
|
+
}
|
|
72
|
+
catch (error) {
|
|
73
|
+
// A deadline or the author's cancel is told by the clock; anything else here is the connection.
|
|
74
|
+
if (clock.interrupted())
|
|
75
|
+
throw error;
|
|
76
|
+
throw new BodyError("lost");
|
|
77
|
+
}
|
|
78
|
+
if (piece.done) {
|
|
79
|
+
exhausted = true;
|
|
80
|
+
break;
|
|
81
|
+
}
|
|
82
|
+
clock.activity();
|
|
83
|
+
size += piece.value.byteLength;
|
|
84
|
+
if (size > maxBytes)
|
|
85
|
+
throw new BodyError("too-large");
|
|
86
|
+
chunks.push(piece.value);
|
|
87
|
+
}
|
|
88
|
+
const bytes = new Uint8Array(size);
|
|
89
|
+
let offset = 0;
|
|
90
|
+
for (const chunk of chunks) {
|
|
91
|
+
bytes.set(chunk, offset);
|
|
92
|
+
offset += chunk.byteLength;
|
|
93
|
+
}
|
|
94
|
+
try {
|
|
95
|
+
return JSON.parse(new TextDecoder("utf-8", { fatal: true }).decode(bytes));
|
|
96
|
+
}
|
|
97
|
+
catch {
|
|
98
|
+
throw new BodyError("invalid");
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
finally {
|
|
102
|
+
if (!exhausted)
|
|
103
|
+
release(reader);
|
|
104
|
+
try {
|
|
105
|
+
reader.releaseLock();
|
|
106
|
+
}
|
|
107
|
+
catch {
|
|
108
|
+
// A read that is still pending cannot be released: the cancel above is what lets it go.
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
//# sourceMappingURL=body.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"body.js","sourceRoot":"","sources":["../../src/ai/body.ts"],"names":[],"mappings":"AAEA,yJAAyJ;AAEzJ,wHAAwH;AACxH,MAAM,UAAU,OAAO,CAAC,MAA+C;IACrE,IAAI,CAAC;QACH,KAAK,MAAM,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC;IAC9C,CAAC;IAAC,MAAM,CAAC;QACP,2DAA2D;IAC7D,CAAC;AACH,CAAC;AAED,2HAA2H;AAC3H,MAAM,UAAU,WAAW,CAAC,QAAkB;IAC5C,IAAI,CAAC;QAC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AC,CAAC;QACf,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;YAC3B,KAAK,CAAC,GAAG,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;YACzB,MAAM,IAAI,KAAK,CAAC,UAAU,CAAC;QAC7B,CAAC;QACD,IAAI,CAAC;YACH,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,WAAW,CAAC,OAAO,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAY,CAAC;QACxF,CAAC;QAAC,MAAM,CAAC;YACP,MAAM,IAAI,SAAS,CAAC,SAAS,CAAC,CAAC;QACjC,CAAC;IACH,CAAC;YAAS,CAAC;QACT,IAAI,CAAC,SAAS;YAAE,OAAO,CAAC,MAAM,CAAC,CAAC;QAChC,IAAI,CAAC;YACH,MAAM,CAAC,WAAW,EAAE,CAAC;QACvB,CAAC;QAAC,MAAM,CAAC;YACP,wFAAwF;QAC1F,CAAC;IACH,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { type AiLmStudioModel, type AiModalityGroup, type AiModelCatalogEntry } from "./catalog.js";
|
|
2
|
+
import type { AiIntegrationConfig } from "./config.js";
|
|
3
|
+
/** The most bytes of an answer that are read. A longer one is refused as it passes the limit, whatever it said it weighed. */
|
|
4
|
+
export declare const CATALOG_MAX_BYTES = 600000;
|
|
5
|
+
/** How long an endpoint may be silent, for each request: before it answers, and between two pieces of its answer. */
|
|
6
|
+
export declare const CATALOG_TIMEOUT_MS = 8000;
|
|
7
|
+
/** The most a request may take in all, however the endpoint goes on sending: a safety, far above what a catalog needs. */
|
|
8
|
+
export declare const CATALOG_TOTAL_CAP_MS = 60000;
|
|
9
|
+
export interface FetchModelCatalogOptions {
|
|
10
|
+
/** The `fetch` to use (default the global one). Never given a cookie, and told not to follow a redirect. */
|
|
11
|
+
fetch?: typeof fetch;
|
|
12
|
+
/** Cancels the reading: an `AbortError`, never a catalog. */
|
|
13
|
+
signal?: AbortSignal;
|
|
14
|
+
/** How long an endpoint may be silent, per request (default `CATALOG_TIMEOUT_MS`, at most ten minutes). The most a request may take in all is a minute, or this when it is longer. */
|
|
15
|
+
timeoutMs?: number;
|
|
16
|
+
}
|
|
17
|
+
/** What an integration's endpoint says of its models, from its list and from its companions. */
|
|
18
|
+
export interface AiModelCatalog {
|
|
19
|
+
/** Every model the endpoint knows, sorted by id: the ids of `/models`, enriched with what `/models/details` and `/modalities` say, and the ids that only they know. Of every kind, with its `type`. */
|
|
20
|
+
models: AiModelCatalogEntry[];
|
|
21
|
+
/** Which of the answers were read: the list always (without it there is no catalog), the companions when the endpoint has them and they were as they should be. */
|
|
22
|
+
source: {
|
|
23
|
+
models: true;
|
|
24
|
+
details: boolean;
|
|
25
|
+
modalities: boolean;
|
|
26
|
+
};
|
|
27
|
+
/** What the gateway offers by kind of model, with the kinds that run nothing; absent when `/modalities` was not read. */
|
|
28
|
+
modalities?: AiModalityGroup[];
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Reads the models an integration's endpoint offers, as BookWriter does and as LlmProxy exposes them: `GET <base>/models` (the OpenAI list: without
|
|
32
|
+
* it there is no catalog, and a failure is an `AiCatalogError` that says why and what to do), then, together, `GET <base>/models/details` (the window,
|
|
33
|
+
* the largest answer and what each model can do) and `GET <base>/modalities` (what the gateway offers, by kind of model, and what runs for each), which
|
|
34
|
+
* an endpoint may not have and whose every failure is silent: the catalog is then what the list says. The base is the one the chat requests use.
|
|
35
|
+
* The models of every kind are returned, with their `type`, so that a screen can fill the tables of the tools that are not chat. Only OpenAI-compatible
|
|
36
|
+
* integrations have such a list: any other is an `AiCatalogError` of reason `unsupported`, and nothing is sent.
|
|
37
|
+
*
|
|
38
|
+
* What an endpoint sends is untrusted: a request is a plain GET with no cookie and no redirect, with the key in its header only; an endpoint may be
|
|
39
|
+
* silent for 8 s (before it answers, and between two pieces), a minute in all; a body is read in pieces up to 600 KB, and let go the moment it is too
|
|
40
|
+
* much, or not JSON; and nothing it says is quoted in an error. The key is in no message and no result. A cancelled reading is an `AbortError`.
|
|
41
|
+
*/
|
|
42
|
+
export declare function fetchModelCatalog(integration: AiIntegrationConfig, options?: FetchModelCatalogOptions): Promise<AiModelCatalog>;
|
|
43
|
+
/**
|
|
44
|
+
* The native list of an LM Studio on this computer (`GET /api/v1/models` at the root of its server): the thinking levels each language model declares
|
|
45
|
+
* and the context it loaded and supports, for `parseLmStudioModels`. Only a server that runs on this machine is asked (`localhost`, `127.0.0.1`, `::1`,
|
|
46
|
+
* with no credentials in its address), and only an OpenAI-compatible integration is read: for any other, and for any server that is not LM Studio,
|
|
47
|
+
* cannot be reached, or answers what is not its list, the answer is `undefined`, and the caller keeps what it knew. A key that is configured is sent, to this
|
|
48
|
+
* computer only. A cancelled reading is an `AbortError`.
|
|
49
|
+
*/
|
|
50
|
+
export declare function fetchLmStudioModels(integration: AiIntegrationConfig, options?: FetchModelCatalogOptions): Promise<AiLmStudioModel[] | undefined>;
|
|
51
|
+
//# sourceMappingURL=catalog-fetch.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"catalog-fetch.d.ts","sourceRoot":"","sources":["../../src/ai/catalog-fetch.ts"],"names":[],"mappings":"AACA,OAAO,EAQL,KAAK,eAAe,EACpB,KAAK,eAAe,EACpB,KAAK,mBAAmB,EACzB,MAAM,cAAc,CAAC;AAEtB,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAMvD,8HAA8H;AAC9H,eAAO,MAAM,iBAAiB,SAAU,CAAC;AACzC,qHAAqH;AACrH,eAAO,MAAM,kBAAkB,OAAQ,CAAC;AACxC,0HAA0H;AAC1H,eAAO,MAAM,oBAAoB,QAAS,CAAC;AAE3C,MAAM,WAAW,wBAAwB;IACvC,4GAA4G;IAC5G,KAAK,CAAC,EAAE,OAAO,KAAK,CAAC;IACrB,6DAA6D;IAC7D,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,sLAAsL;IACtL,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,gGAAgG;AAChG,MAAM,WAAW,cAAc;IAC7B,uMAAuM;IACvM,MAAM,EAAE,mBAAmB,EAAE,CAAC;IAC9B,mKAAmK;IACnK,MAAM,EAAE;QAAE,MAAM,EAAE,IAAI,CAAC;QAAC,OAAO,EAAE,OAAO,CAAC;QAAC,UAAU,EAAE,OAAO,CAAA;KAAE,CAAC;IAChE,yHAAyH;IACzH,UAAU,CAAC,EAAE,eAAe,EAAE,CAAC;CAChC;AA0KD;;;;;;;;;;;GAWG;AACH,wBAAsB,iBAAiB,CAAC,WAAW,EAAE,mBAAmB,EAAE,OAAO,GAAE,wBAA6B,GAAG,OAAO,CAAC,cAAc,CAAC,CA+BzI;AAED;;;;;;GAMG;AACH,wBAAsB,mBAAmB,CAAC,WAAW,EAAE,mBAAmB,EAAE,OAAO,GAAE,wBAA6B,GAAG,OAAO,CAAC,eAAe,EAAE,GAAG,SAAS,CAAC,CAkB1J"}
|
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
import { BodyError, discardBody, readBoundedJson } from "./body.js";
|
|
2
|
+
import { AiCatalogError, CATALOG_MAX_MODELS, parseLmStudioModels, parseModalities, parseModelDetails, parseModelList, } from "./catalog.js";
|
|
3
|
+
import { abortReason, nameOf, timeoutOf, unsupportedCatalog } from "./catalog-support.js";
|
|
4
|
+
import { formatDuration, startClock } from "./deadlines.js";
|
|
5
|
+
import { redactSecrets } from "./redact.js";
|
|
6
|
+
import { catalogTarget } from "./request.js";
|
|
7
|
+
/** The most bytes of an answer that are read. A longer one is refused as it passes the limit, whatever it said it weighed. */
|
|
8
|
+
export const CATALOG_MAX_BYTES = 600_000;
|
|
9
|
+
/** How long an endpoint may be silent, for each request: before it answers, and between two pieces of its answer. */
|
|
10
|
+
export const CATALOG_TIMEOUT_MS = 8_000;
|
|
11
|
+
/** The most a request may take in all, however the endpoint goes on sending: a safety, far above what a catalog needs. */
|
|
12
|
+
export const CATALOG_TOTAL_CAP_MS = 60_000;
|
|
13
|
+
// ─── How a request fails ────────────────────────────────────────────────────
|
|
14
|
+
/** What went wrong with a request, before it is told in words. Internal: never leaves this module. */
|
|
15
|
+
class Fault extends Error {
|
|
16
|
+
reason;
|
|
17
|
+
about;
|
|
18
|
+
constructor(reason, about = {}) {
|
|
19
|
+
super(reason);
|
|
20
|
+
this.reason = reason;
|
|
21
|
+
this.about = about;
|
|
22
|
+
this.name = "Fault";
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
/** What went wrong, in words: why, and what to do. In English, and without the key, the address, or a word of what the endpoint sent. */
|
|
26
|
+
function describe(fault, how) {
|
|
27
|
+
const { name } = how;
|
|
28
|
+
const { status, phase, ms, bytes } = fault.about;
|
|
29
|
+
const message = (() => {
|
|
30
|
+
switch (fault.reason) {
|
|
31
|
+
case "unreachable":
|
|
32
|
+
return `Could not reach ${name} to read its models. Check that the server is running and that the address is right (a redirect is refused: use the final address). In a browser, a server that does not allow this site (CORS) looks exactly like a server that is off.`;
|
|
33
|
+
case "timeout":
|
|
34
|
+
return phase === "start"
|
|
35
|
+
? `${name} did not answer within ${formatDuration(ms ?? how.timeoutMs)}. The server may be busy or off: try again, or check the address.`
|
|
36
|
+
: phase === "idle"
|
|
37
|
+
? `${name} stopped sending its models for ${formatDuration(ms ?? how.timeoutMs)}. Try again in a moment.`
|
|
38
|
+
: `Reading the models of ${name} took longer than ${formatDuration(ms ?? CATALOG_TOTAL_CAP_MS)} and was stopped. Try again, or enter the model names by hand.`;
|
|
39
|
+
case "unauthorized":
|
|
40
|
+
return status === 403
|
|
41
|
+
? `${name} denied access to its models (HTTP 403). The key may be wrong or not allowed to list models: check the key of the integration, or enter the model names by hand.`
|
|
42
|
+
: `${name} refused the API key (HTTP ${status ?? 401}). Check the key of the integration.`;
|
|
43
|
+
case "not-found":
|
|
44
|
+
return `${name} has no list of models at its address (HTTP 404). Check that the address ends with the version path (for example /v1), or enter the model names by hand.`;
|
|
45
|
+
case "rate-limited":
|
|
46
|
+
return `${name} is limiting requests (HTTP 429). Wait a moment and try again.`;
|
|
47
|
+
case "server-error":
|
|
48
|
+
return `${name} failed while listing its models (HTTP ${status ?? 500}). It may be busy or restarting: try again in a moment.`;
|
|
49
|
+
case "http-error":
|
|
50
|
+
return `${name} answered HTTP ${status ?? 0} to the request for its models. Check the address and the key, or enter the model names by hand.`;
|
|
51
|
+
case "empty":
|
|
52
|
+
return `${name} lists no models. If it is a gateway, start a model there (a model that is stopped is not listed), or enter the model names by hand.`;
|
|
53
|
+
case "too-large":
|
|
54
|
+
return bytes
|
|
55
|
+
? `The answer of ${name} is larger than ${CATALOG_MAX_BYTES / 1000} KB and was not read. Enter the model names by hand.`
|
|
56
|
+
: `The list of models of ${name} is too large to be read: it has more than ${CATALOG_MAX_MODELS} models, or it comes in pages. Enter the model names by hand.`;
|
|
57
|
+
case "unsupported":
|
|
58
|
+
return `${name} has no list of models to read.`;
|
|
59
|
+
default:
|
|
60
|
+
return `${name} answered, but what it sent is not a list of models in the OpenAI format. Check that the address is the API base (for example …/v1), or enter the model names by hand.`;
|
|
61
|
+
}
|
|
62
|
+
})();
|
|
63
|
+
return new AiCatalogError(redactSecrets(message, how.secrets), fault.reason, status);
|
|
64
|
+
}
|
|
65
|
+
function statusFault(status) {
|
|
66
|
+
if (status === 401 || status === 403)
|
|
67
|
+
return new Fault("unauthorized", { status });
|
|
68
|
+
if (status === 404)
|
|
69
|
+
return new Fault("not-found", { status });
|
|
70
|
+
if (status === 429)
|
|
71
|
+
return new Fault("rate-limited", { status });
|
|
72
|
+
return new Fault(status >= 500 ? "server-error" : "http-error", { status });
|
|
73
|
+
}
|
|
74
|
+
/** What a failure of the request is: the author's cancel, a deadline, a status, a body that cannot be used, or no answer at all. */
|
|
75
|
+
function interpret(error, clock, how) {
|
|
76
|
+
if (how.signal?.aborted)
|
|
77
|
+
return abortReason(how.signal);
|
|
78
|
+
const expired = clock.expired();
|
|
79
|
+
if (expired)
|
|
80
|
+
return new Fault("timeout", { phase: expired.phase, ms: expired.ms });
|
|
81
|
+
if (error instanceof Fault)
|
|
82
|
+
return error;
|
|
83
|
+
if (error instanceof BodyError)
|
|
84
|
+
return error.fault === "too-large" ? new Fault("too-large", { bytes: true }) : new Fault(error.fault === "lost" ? "unreachable" : "invalid");
|
|
85
|
+
return new Fault("unreachable");
|
|
86
|
+
}
|
|
87
|
+
/** A parser's refusal of an answer is a fault of the answer; whatever else a parser throws is the same. */
|
|
88
|
+
function parsed(read) {
|
|
89
|
+
try {
|
|
90
|
+
return read();
|
|
91
|
+
}
|
|
92
|
+
catch (error) {
|
|
93
|
+
throw new Fault(error instanceof AiCatalogError ? error.reason : "invalid");
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
// ─── One request ────────────────────────────────────────────────────────────
|
|
97
|
+
/**
|
|
98
|
+
* One GET: no cookie, no redirect, no cache, no referrer, the key in its header and nowhere else, a start deadline and then a silence between two pieces
|
|
99
|
+
* (and a cap on the whole), an answer that is not OK let go unread, and a body that is read as JSON within `CATALOG_MAX_BYTES`. It throws a `Fault`,
|
|
100
|
+
* or the author's cancel as it is.
|
|
101
|
+
*/
|
|
102
|
+
async function readJson(target, how) {
|
|
103
|
+
const clock = startClock(how.signal, { startMs: how.timeoutMs, idleMs: how.timeoutMs, capMs: Math.max(CATALOG_TOTAL_CAP_MS, how.timeoutMs) });
|
|
104
|
+
try {
|
|
105
|
+
const sent = Promise.resolve(how.fetchImpl(target.url, {
|
|
106
|
+
method: "GET",
|
|
107
|
+
headers: { accept: "application/json", ...target.headers },
|
|
108
|
+
credentials: "omit",
|
|
109
|
+
redirect: "error",
|
|
110
|
+
cache: "no-store",
|
|
111
|
+
referrerPolicy: "no-referrer",
|
|
112
|
+
signal: clock.signal,
|
|
113
|
+
}));
|
|
114
|
+
// An answer that comes after the request was given up is dropped, and its body let go.
|
|
115
|
+
sent.then((late) => {
|
|
116
|
+
if (clock.interrupted())
|
|
117
|
+
discardBody(late);
|
|
118
|
+
}, () => undefined);
|
|
119
|
+
const response = await clock.guard(sent);
|
|
120
|
+
if (!response.ok) {
|
|
121
|
+
discardBody(response);
|
|
122
|
+
throw statusFault(response.status);
|
|
123
|
+
}
|
|
124
|
+
// The headers are here: the start deadline is over, and from now on it is the silence between two pieces that is watched.
|
|
125
|
+
clock.streaming();
|
|
126
|
+
return await readBoundedJson(response, clock, CATALOG_MAX_BYTES);
|
|
127
|
+
}
|
|
128
|
+
catch (error) {
|
|
129
|
+
throw interpret(error, clock, how);
|
|
130
|
+
}
|
|
131
|
+
finally {
|
|
132
|
+
clock.dispose();
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
function readingOf(integration, options) {
|
|
136
|
+
return {
|
|
137
|
+
name: nameOf(integration),
|
|
138
|
+
secrets: [integration.apiKey],
|
|
139
|
+
// The global fetch is called on its own, never as a method of this object: a browser refuses `fetch` called with another `this` (Illegal invocation).
|
|
140
|
+
fetchImpl: options.fetch ?? ((input, init) => fetch(input, init)),
|
|
141
|
+
signal: options.signal,
|
|
142
|
+
timeoutMs: timeoutOf(options.timeoutMs, CATALOG_TIMEOUT_MS),
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
// ─── The catalog of an endpoint ─────────────────────────────────────────────
|
|
146
|
+
/** Fills in what the companions say of a model: field by field, what `over` declares wins; what it leaves out stays as `base` has it. */
|
|
147
|
+
function combine(base, over) {
|
|
148
|
+
const contextWindow = over.contextWindow ?? base.contextWindow;
|
|
149
|
+
const maxOutputTokens = over.maxOutputTokens ?? base.maxOutputTokens;
|
|
150
|
+
const inputModalities = over.inputModalities ?? base.inputModalities;
|
|
151
|
+
const outputModalities = over.outputModalities ?? base.outputModalities;
|
|
152
|
+
return {
|
|
153
|
+
id: base.id,
|
|
154
|
+
type: over.type !== "unknown" ? over.type : base.type,
|
|
155
|
+
...(contextWindow !== undefined ? { contextWindow } : {}),
|
|
156
|
+
...(maxOutputTokens !== undefined ? { maxOutputTokens } : {}),
|
|
157
|
+
...(inputModalities ? { inputModalities: [...inputModalities] } : {}),
|
|
158
|
+
...(outputModalities ? { outputModalities: [...outputModalities] } : {}),
|
|
159
|
+
capabilities: { ...base.capabilities, ...over.capabilities },
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
/** The catalog: every id of the list, then what `/modalities` knows of it, then what `/models/details` says (which wins); an id only they know is added, up to the limit. */
|
|
163
|
+
function merge(ids, details, groups) {
|
|
164
|
+
const entries = new Map();
|
|
165
|
+
for (const id of ids)
|
|
166
|
+
entries.set(id, { id, type: "unknown", capabilities: {} });
|
|
167
|
+
const add = (entry) => {
|
|
168
|
+
const have = entries.get(entry.id);
|
|
169
|
+
if (have)
|
|
170
|
+
entries.set(entry.id, combine(have, entry));
|
|
171
|
+
else if (entries.size < CATALOG_MAX_MODELS)
|
|
172
|
+
entries.set(entry.id, combine({ id: entry.id, type: "unknown", capabilities: {} }, entry));
|
|
173
|
+
};
|
|
174
|
+
for (const group of groups ?? [])
|
|
175
|
+
for (const model of group.models)
|
|
176
|
+
add(model);
|
|
177
|
+
for (const model of details ?? [])
|
|
178
|
+
add(model);
|
|
179
|
+
return [...entries.values()].sort((left, right) => (left.id < right.id ? -1 : left.id > right.id ? 1 : 0));
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Reads the models an integration's endpoint offers, as BookWriter does and as LlmProxy exposes them: `GET <base>/models` (the OpenAI list: without
|
|
183
|
+
* it there is no catalog, and a failure is an `AiCatalogError` that says why and what to do), then, together, `GET <base>/models/details` (the window,
|
|
184
|
+
* the largest answer and what each model can do) and `GET <base>/modalities` (what the gateway offers, by kind of model, and what runs for each), which
|
|
185
|
+
* an endpoint may not have and whose every failure is silent: the catalog is then what the list says. The base is the one the chat requests use.
|
|
186
|
+
* The models of every kind are returned, with their `type`, so that a screen can fill the tables of the tools that are not chat. Only OpenAI-compatible
|
|
187
|
+
* integrations have such a list: any other is an `AiCatalogError` of reason `unsupported`, and nothing is sent.
|
|
188
|
+
*
|
|
189
|
+
* What an endpoint sends is untrusted: a request is a plain GET with no cookie and no redirect, with the key in its header only; an endpoint may be
|
|
190
|
+
* silent for 8 s (before it answers, and between two pieces), a minute in all; a body is read in pieces up to 600 KB, and let go the moment it is too
|
|
191
|
+
* much, or not JSON; and nothing it says is quoted in an error. The key is in no message and no result. A cancelled reading is an `AbortError`.
|
|
192
|
+
*/
|
|
193
|
+
export async function fetchModelCatalog(integration, options = {}) {
|
|
194
|
+
const target = catalogTarget(integration, "/models");
|
|
195
|
+
if (!target)
|
|
196
|
+
throw unsupportedCatalog(integration);
|
|
197
|
+
const how = readingOf(integration, options);
|
|
198
|
+
if (how.signal?.aborted)
|
|
199
|
+
throw abortReason(how.signal);
|
|
200
|
+
let ids;
|
|
201
|
+
try {
|
|
202
|
+
const payload = await readJson(target, how);
|
|
203
|
+
ids = parsed(() => parseModelList(payload));
|
|
204
|
+
}
|
|
205
|
+
catch (error) {
|
|
206
|
+
throw error instanceof Fault ? describe(error, how) : error;
|
|
207
|
+
}
|
|
208
|
+
// The companions are optional: an endpoint that does not have them, or whose answer is not what it should be, leaves the catalog as the list says it.
|
|
209
|
+
const optional = async (path, read) => {
|
|
210
|
+
const asked = catalogTarget(integration, path);
|
|
211
|
+
if (!asked)
|
|
212
|
+
return undefined;
|
|
213
|
+
try {
|
|
214
|
+
return read(await readJson(asked, how));
|
|
215
|
+
}
|
|
216
|
+
catch {
|
|
217
|
+
return undefined;
|
|
218
|
+
}
|
|
219
|
+
};
|
|
220
|
+
const [details, groups] = await Promise.all([optional("/models/details", parseModelDetails), optional("/modalities", parseModalities)]);
|
|
221
|
+
if (how.signal?.aborted)
|
|
222
|
+
throw abortReason(how.signal);
|
|
223
|
+
return {
|
|
224
|
+
models: merge(ids, details, groups),
|
|
225
|
+
source: { models: true, details: details !== undefined, modalities: groups !== undefined },
|
|
226
|
+
...(groups !== undefined ? { modalities: groups } : {}),
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
/**
|
|
230
|
+
* The native list of an LM Studio on this computer (`GET /api/v1/models` at the root of its server): the thinking levels each language model declares
|
|
231
|
+
* and the context it loaded and supports, for `parseLmStudioModels`. Only a server that runs on this machine is asked (`localhost`, `127.0.0.1`, `::1`,
|
|
232
|
+
* with no credentials in its address), and only an OpenAI-compatible integration is read: for any other, and for any server that is not LM Studio,
|
|
233
|
+
* cannot be reached, or answers what is not its list, the answer is `undefined`, and the caller keeps what it knew. A key that is configured is sent, to this
|
|
234
|
+
* computer only. A cancelled reading is an `AbortError`.
|
|
235
|
+
*/
|
|
236
|
+
export async function fetchLmStudioModels(integration, options = {}) {
|
|
237
|
+
const headers = catalogTarget(integration, "/models")?.headers;
|
|
238
|
+
if (!headers)
|
|
239
|
+
return undefined;
|
|
240
|
+
let url;
|
|
241
|
+
try {
|
|
242
|
+
url = new URL(integration.endpoint ?? "");
|
|
243
|
+
}
|
|
244
|
+
catch {
|
|
245
|
+
return undefined;
|
|
246
|
+
}
|
|
247
|
+
if ((url.protocol !== "http:" && url.protocol !== "https:") || url.username || url.password || !["localhost", "127.0.0.1", "[::1]"].includes(url.hostname))
|
|
248
|
+
return undefined;
|
|
249
|
+
const how = readingOf(integration, options);
|
|
250
|
+
if (how.signal?.aborted)
|
|
251
|
+
throw abortReason(how.signal);
|
|
252
|
+
try {
|
|
253
|
+
return parseLmStudioModels(await readJson({ url: `${url.origin}/api/v1/models`, headers }, how));
|
|
254
|
+
}
|
|
255
|
+
catch {
|
|
256
|
+
if (how.signal?.aborted)
|
|
257
|
+
throw abortReason(how.signal);
|
|
258
|
+
return undefined;
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
//# sourceMappingURL=catalog-fetch.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"catalog-fetch.js","sourceRoot":"","sources":["../../src/ai/catalog-fetch.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,WAAW,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,EAAE,GAAG,CAAC,CAAC,CAAC;IACnG,CAAC;IAAC,MAAM,CAAC;QACP,IAAI,GAAG,CAAC,MAAM,EAAE,OAAO;YAAE,MAAM,WAAW,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;QACvD,OAAO,SAAS,CAAC;IACnB,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { AiCatalogError } from "./catalog.js";
|
|
2
|
+
import type { AiIntegrationConfig } from "./config.js";
|
|
3
|
+
/** The integration as a message names it, in quotes, with its key (which a careless name may hold) taken out. */
|
|
4
|
+
export declare function nameOf(integration: Pick<AiIntegrationConfig, "name" | "provider" | "apiKey">): string;
|
|
5
|
+
/** What a caller that cancelled is told: its own reason when it gave one, else an `AbortError`. */
|
|
6
|
+
export declare function abortReason(signal: AbortSignal): Error;
|
|
7
|
+
/** The longest a host may ask a request to be silent: ten minutes, far under what a timer can count (past about 24 days it would fire at once). */
|
|
8
|
+
export declare const MAX_REQUEST_TIMEOUT_MS = 600000;
|
|
9
|
+
/** The positive number a host gave as a time, kept within `MAX_REQUEST_TIMEOUT_MS`, or the default. */
|
|
10
|
+
export declare function timeoutOf(value: unknown, fallback: number): number;
|
|
11
|
+
/** An integration that has no list of models to read: it says why, and that its models are entered by hand or picked from the catalog that has them. */
|
|
12
|
+
export declare function unsupportedCatalog(integration: Pick<AiIntegrationConfig, "provider">): AiCatalogError;
|
|
13
|
+
//# sourceMappingURL=catalog-support.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"catalog-support.d.ts","sourceRoot":"","sources":["../../src/ai/catalog-support.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAKvD,iHAAiH;AACjH,wBAAgB,MAAM,CAAC,WAAW,EAAE,IAAI,CAAC,mBAAmB,EAAE,MAAM,GAAG,UAAU,GAAG,QAAQ,CAAC,GAAG,MAAM,CAErG;AAED,mGAAmG;AACnG,wBAAgB,WAAW,CAAC,MAAM,EAAE,WAAW,GAAG,KAAK,CAEtD;AAED,mJAAmJ;AACnJ,eAAO,MAAM,sBAAsB,SAAU,CAAC;AAE9C,uGAAuG;AACvG,wBAAgB,SAAS,CAAC,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAElE;AAED,wJAAwJ;AACxJ,wBAAgB,kBAAkB,CAAC,WAAW,EAAE,IAAI,CAAC,mBAAmB,EAAE,UAAU,CAAC,GAAG,cAAc,CAOrG"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { abortError } from "../util/abort.js";
|
|
2
|
+
import { AiCatalogError } from "./catalog.js";
|
|
3
|
+
import { redactSecrets } from "./redact.js";
|
|
4
|
+
// What reading the models of an endpoint and probing it have in common. Internal: not exported by the package.
|
|
5
|
+
/** The integration as a message names it, in quotes, with its key (which a careless name may hold) taken out. */
|
|
6
|
+
export function nameOf(integration) {
|
|
7
|
+
return redactSecrets(`"${integration.name || integration.provider}"`, [integration.apiKey]);
|
|
8
|
+
}
|
|
9
|
+
/** What a caller that cancelled is told: its own reason when it gave one, else an `AbortError`. */
|
|
10
|
+
export function abortReason(signal) {
|
|
11
|
+
return signal.reason instanceof Error ? signal.reason : abortError();
|
|
12
|
+
}
|
|
13
|
+
/** The longest a host may ask a request to be silent: ten minutes, far under what a timer can count (past about 24 days it would fire at once). */
|
|
14
|
+
export const MAX_REQUEST_TIMEOUT_MS = 600_000;
|
|
15
|
+
/** The positive number a host gave as a time, kept within `MAX_REQUEST_TIMEOUT_MS`, or the default. */
|
|
16
|
+
export function timeoutOf(value, fallback) {
|
|
17
|
+
return typeof value === "number" && Number.isFinite(value) && value > 0 ? Math.min(value, MAX_REQUEST_TIMEOUT_MS) : fallback;
|
|
18
|
+
}
|
|
19
|
+
/** An integration that has no list of models to read: it says why, and that its models are entered by hand or picked from the catalog that has them. */
|
|
20
|
+
export function unsupportedCatalog(integration) {
|
|
21
|
+
const message = integration.provider === "azure_openai"
|
|
22
|
+
? "The models of an Azure OpenAI integration cannot be listed: a deployment is created by hand in Azure, and nobody lists them. Enter the deployment names."
|
|
23
|
+
: integration.provider === "github_models"
|
|
24
|
+
? "GitHub Models does not list its models at this address: its catalog is read from GitHub's own catalog, not from the endpoint. Pick the models from that catalog."
|
|
25
|
+
: "A Microsoft 365 Copilot integration has no catalog of models to read: it runs only inside Microsoft 365.";
|
|
26
|
+
return new AiCatalogError(message, "unsupported");
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=catalog-support.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"catalog-support.js","sourceRoot":"","sources":["../../src/ai/catalog-support.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAE9C,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE5C,+GAA+G;AAE/G,iHAAiH;AACjH,MAAM,UAAU,MAAM,CAAC,WAAsE;IAC3F,OAAO,aAAa,CAAC,IAAI,WAAW,CAAC,IAAI,IAAI,WAAW,CAAC,QAAQ,GAAG,EAAE,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,CAAC;AAC9F,CAAC;AAED,mGAAmG;AACnG,MAAM,UAAU,WAAW,CAAC,MAAmB;IAC7C,OAAO,MAAM,CAAC,MAAM,YAAY,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,UAAU,EAAE,CAAC;AACvE,CAAC;AAED,mJAAmJ;AACnJ,MAAM,CAAC,MAAM,sBAAsB,GAAG,OAAO,CAAC;AAE9C,uGAAuG;AACvG,MAAM,UAAU,SAAS,CAAC,KAAc,EAAE,QAAgB;IACxD,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,MAAM,CAA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