yggio-ai 0.0.16 → 0.0.17
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/{chunk-7LQFHKMU.cjs → chunk-F5TA7LVR.cjs} +5 -5
- package/dist/{chunk-7LQFHKMU.cjs.map → chunk-F5TA7LVR.cjs.map} +1 -1
- package/dist/{chunk-X4Y3LGIL.js → chunk-LU2IPSYQ.js} +19 -20
- package/dist/chunk-LU2IPSYQ.js.map +1 -0
- package/dist/{chunk-NK5AY37L.cjs → chunk-U65H3IAT.cjs} +19 -19
- package/dist/chunk-U65H3IAT.cjs.map +1 -0
- package/dist/{chunk-ERSMENJU.js → chunk-XR2XLKYJ.js} +3 -3
- package/dist/{chunk-ERSMENJU.js.map → chunk-XR2XLKYJ.js.map} +1 -1
- package/dist/{engine-BFFaWEM6.d.cts → engine-BfLKZyiq.d.cts} +4 -0
- package/dist/{engine-BFFaWEM6.d.ts → engine-BfLKZyiq.d.ts} +4 -0
- package/dist/http.d.cts +1 -1
- package/dist/http.d.ts +1 -1
- package/dist/index.cjs +26 -26
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +2 -2
- package/dist/node.cjs +15 -11
- package/dist/node.cjs.map +1 -1
- package/dist/node.d.cts +3 -1
- package/dist/node.d.ts +3 -1
- package/dist/node.js +5 -1
- package/dist/node.js.map +1 -1
- package/dist/react.cjs +261 -156
- package/dist/react.cjs.map +1 -1
- package/dist/react.d.cts +1 -1
- package/dist/react.d.ts +1 -1
- package/dist/react.js +233 -128
- package/dist/react.js.map +1 -1
- package/package.json +3 -3
- package/src/engine.ts +4 -0
- package/src/format.ts +23 -18
- package/src/node/addon.ts +2 -0
- package/src/node/json.ts +4 -0
- package/src/react/AgentRunView.tsx +71 -54
- package/src/react/ChatPanel.tsx +95 -66
- package/src/react/ErrorLine.tsx +10 -0
- package/src/react/ModelPicker.tsx +17 -12
- package/src/react/ModelStoreBrowser.tsx +75 -41
- package/src/react/ProviderSettings.tsx +28 -9
- package/src/react/TurnBubble.tsx +30 -0
- package/dist/chunk-NK5AY37L.cjs.map +0 -1
- package/dist/chunk-X4Y3LGIL.js.map +0 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunkU65H3IAT_cjs = require('./chunk-U65H3IAT.cjs');
|
|
4
4
|
|
|
5
5
|
// src/presets.ts
|
|
6
6
|
var API_LABELS = {
|
|
@@ -14,7 +14,7 @@ var API_LABELS = {
|
|
|
14
14
|
var HUGGINGFACE_BASE_URL = "https://router.huggingface.co/v1";
|
|
15
15
|
var OLLAMA_BASE_URL = "http://localhost:11434/v1";
|
|
16
16
|
var AI_PRESETS = [
|
|
17
|
-
...
|
|
17
|
+
...chunkU65H3IAT_cjs.AI_APIS.map((api) => ({ id: api, label: API_LABELS[api], api, base_url: null, api_key_env: null })),
|
|
18
18
|
{ id: "huggingface", label: "Hugging Face", api: "openai", base_url: HUGGINGFACE_BASE_URL, api_key_env: "HF_TOKEN" },
|
|
19
19
|
{ id: "ollama", label: "Ollama", api: "openai", base_url: OLLAMA_BASE_URL, api_key_env: null }
|
|
20
20
|
];
|
|
@@ -26,7 +26,7 @@ function applyPreset(settings, preset) {
|
|
|
26
26
|
return { ...settings, api: preset.api, base_url: preset.base_url, api_key_env: preset.api_key_env };
|
|
27
27
|
}
|
|
28
28
|
function fallbackApi(served) {
|
|
29
|
-
return
|
|
29
|
+
return chunkU65H3IAT_cjs.AI_APIS.find((api) => served.apis.includes(api)) ?? null;
|
|
30
30
|
}
|
|
31
31
|
var API_READS = {
|
|
32
32
|
anthropic: ["base_url", "api_key_env"],
|
|
@@ -45,5 +45,5 @@ exports.OLLAMA_BASE_URL = OLLAMA_BASE_URL;
|
|
|
45
45
|
exports.applyPreset = applyPreset;
|
|
46
46
|
exports.fallbackApi = fallbackApi;
|
|
47
47
|
exports.presetOf = presetOf;
|
|
48
|
-
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,QAAA,EAAU,SAAS,CAAA;AAAA,EAC5C,QAAA,EAAU,CAAC,aAAA,EAAe,QAAA,EAAU,SAAS,CAAA;AAAA,EAC7C,KAAA,EAAO,CAAC,OAAA,EAAS,KAAK,CAAA;AAAA,EACtB,QAAA,EAAU,CAAC,UAAA,EAAY,aAAa,CAAA;AAAA,EACpC,MAAA,EAAQ,CAAC,UAAA,EAAY,aAAa;AACpC","file":"chunk-F5TA7LVR.cjs","sourcesContent":["import type { AiApi, AiServed, AiSettings } from './engine.js'\nimport { AI_APIS } from './engine.js'\n\n/** How each API is named to a reader. */\nexport const API_LABELS: Readonly<Record<AiApi, string>> = {\n anthropic: 'Claude (Anthropic)',\n bedrock: 'Claude in Amazon Bedrock',\n converse: 'Amazon Bedrock Converse',\n local: 'Local (this machine)',\n moonshot: 'Kimi (Moonshot)',\n openai: 'OpenAI-compatible',\n}\n\n/** One provider choice: an API and, for an OpenAI-compatible server, where it answers and which variable holds its key. */\nexport interface AiPreset {\n readonly id: string\n readonly label: string\n readonly api: AiApi\n readonly base_url: string | null\n readonly api_key_env: string | null\n}\n\n/** yggio-ai's `HUGGINGFACE_BASE_URL`: the Hugging Face router, keyed by `HF_TOKEN`. */\nexport const HUGGINGFACE_BASE_URL = 'https://router.huggingface.co/v1'\n/** yggio-ai's `OLLAMA_BASE_URL`: a local Ollama server, keyless. */\nexport const OLLAMA_BASE_URL = 'http://localhost:11434/v1'\n\n/** Every API as itself, then the OpenAI-compatible presets the core names: Hugging Face and Ollama. */\nexport const AI_PRESETS: readonly AiPreset[] = [\n ...AI_APIS.map((api) => ({ id: api, label: API_LABELS[api], api, base_url: null, api_key_env: null })),\n { id: 'huggingface', label: 'Hugging Face', api: 'openai', base_url: HUGGINGFACE_BASE_URL, api_key_env: 'HF_TOKEN' },\n { id: 'ollama', label: 'Ollama', api: 'openai', base_url: OLLAMA_BASE_URL, api_key_env: null },\n]\n\n/** The preset the settings are: an OpenAI-compatible API by its root, any other by its API. */\nexport function presetOf(settings: AiSettings): AiPreset {\n const named = AI_PRESETS.find((preset) => preset.api === settings.api && preset.base_url !== null && preset.base_url === settings.base_url)\n return named ?? AI_PRESETS.find((preset) => preset.id === settings.api)!\n}\n\n/** The settings moved to `preset`: its API, root and key variable; the rest kept. */\nexport function applyPreset(settings: AiSettings, preset: AiPreset): AiSettings {\n return { ...settings, api: preset.api, base_url: preset.base_url, api_key_env: preset.api_key_env }\n}\n\n/** The API shown where the settings name one the build does not serve: the first it does, in `Api::ALL`'s order. */\nexport function fallbackApi(served: AiServed): AiApi | null {\n return AI_APIS.find((api) => served.apis.includes(api)) ?? null\n}\n\n/**\n * The settings each API reads, beyond its model: the ones taking a root\n * (`Api::takes_base_url`), a key variable, Bedrock's region and profile, and\n * this machine's store and Hub.\n */\nexport const API_READS: Readonly<Record<AiApi, readonly ('base_url' | 'api_key_env' | 'region' | 'profile' | 'store' | 'hub')[]>> = {\n anthropic: ['base_url', 'api_key_env'],\n bedrock: ['api_key_env', 'region', 'profile'],\n converse: ['api_key_env', 'region', 'profile'],\n local: ['store', 'hub'],\n moonshot: ['base_url', 'api_key_env'],\n openai: ['base_url', 'api_key_env'],\n}\n"]}
|
|
@@ -26,7 +26,7 @@ function priceText(price) {
|
|
|
26
26
|
return price.simulated ? `${text} (estimate)` : text;
|
|
27
27
|
}
|
|
28
28
|
function bytesText(bytes) {
|
|
29
|
-
const units = ["B", "
|
|
29
|
+
const units = ["B", "KiB", "MiB", "GiB", "TiB"];
|
|
30
30
|
let value = bytes;
|
|
31
31
|
let unit = 0;
|
|
32
32
|
while (value >= 1024 && unit < units.length - 1) {
|
|
@@ -46,23 +46,22 @@ function modelsByApi(models, apis = AI_APIS) {
|
|
|
46
46
|
}
|
|
47
47
|
var localModels = (models) => models.filter((model) => model.api_ids.local !== void 0);
|
|
48
48
|
function agentSteps(events) {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
}
|
|
49
|
+
return events.reduce(applyEvent, []);
|
|
50
|
+
}
|
|
51
|
+
function applyEvent(steps, event) {
|
|
52
|
+
const last = steps[steps.length - 1];
|
|
53
|
+
if (event.type === "text") {
|
|
54
|
+
if (last?.kind === "text") return [...steps.slice(0, -1), { kind: "text", text: last.text + event.text }];
|
|
55
|
+
return [...steps, { kind: "text", text: event.text }];
|
|
56
|
+
}
|
|
57
|
+
if (event.type === "tool_call") return [...steps, { kind: "tool", call: event.call, output: null }];
|
|
58
|
+
if (event.type === "tool_result") {
|
|
59
|
+
const index = steps.findIndex((step) => step.kind === "tool" && step.call.id === event.call.id && step.output === null);
|
|
60
|
+
const answered = { kind: "tool", call: event.call, output: event.output };
|
|
61
|
+
if (index < 0) return [...steps, answered];
|
|
62
|
+
return steps.map((step, at) => at === index ? answered : step);
|
|
64
63
|
}
|
|
65
|
-
return steps;
|
|
64
|
+
return [...steps, { kind: "reply", reply: event.reply }];
|
|
66
65
|
}
|
|
67
66
|
var abortError = () => Object.assign(new Error("the call was cancelled"), { name: "AbortError" });
|
|
68
67
|
function isAbort(error, signal) {
|
|
@@ -70,6 +69,6 @@ function isAbort(error, signal) {
|
|
|
70
69
|
}
|
|
71
70
|
var errorText = (error) => error instanceof Error ? error.message : String(error);
|
|
72
71
|
|
|
73
|
-
export { AI_APIS, NO_USAGE, abortError, addUsage, agentSteps, bytesText, countText, dollarText, errorText, isAbort, limitText, localModels, modelsByApi, priceText, progressFraction, replyText };
|
|
74
|
-
//# sourceMappingURL=chunk-
|
|
75
|
-
//# sourceMappingURL=chunk-
|
|
72
|
+
export { AI_APIS, NO_USAGE, abortError, addUsage, agentSteps, applyEvent, bytesText, countText, dollarText, errorText, isAbort, limitText, localModels, modelsByApi, priceText, progressFraction, replyText };
|
|
73
|
+
//# sourceMappingURL=chunk-LU2IPSYQ.js.map
|
|
74
|
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AAM,IAAA,KAAS,YAAA;AACrE;AAGO,IAAM,SAAA,GAAY,CAAC,KAAA,KAA4B,KAAA,YAAiB,QAAQ,KAAA,CAAM,OAAA,GAAU,OAAO,KAAK","file":"chunk-LU2IPSYQ.js","sourcesContent":["/**\n * The AI port: what the components ask of the Node side, as the core's JSON.\n *\n * Every shape mirrors yggio-ai's own: `AiSettings` is `Settings`'s serde JSON\n * field for field (`rust/ai/src/settings.rs`), `AiStored` a store `Manifest`,\n * `AiUsage` and `AiReply` the Messages API's. The browser side holds no\n * credential and calls nothing: the adapter in `yggio-market/node` answers\n * every method from the addon.\n */\n\n/** An API a model is served through, as `Api::as_str` spells it, in `Api::ALL`'s order. */\nexport type AiApi = 'anthropic' | 'bedrock' | 'converse' | 'local' | 'moonshot' | 'openai'\n\n/** Every API, in `Api::ALL`'s order. */\nexport const AI_APIS: readonly AiApi[] = ['anthropic', 'bedrock', 'converse', 'local', 'moonshot', 'openai']\n\n/** The Hugging Face Hub as `Settings` states it (`HubSettings`). */\nexport interface AiHubSettings {\n readonly endpoint: string | null\n readonly cache: string | null\n readonly offline: boolean\n /** The name of the variable holding the Hub token, never the token. */\n readonly token_env: string | null\n}\n\n/** yggio-ai's `Settings`, its serde JSON: what a caller chose once and keeps. */\nexport interface AiSettings {\n readonly api: AiApi\n readonly model: string\n /** Whether the assistant is served: `false`, the default, refuses every request a server gates by `Settings::model_for`. */\n readonly enabled: boolean\n /** The models a request may ask besides `model`, by catalog name; empty allows `model` alone. */\n readonly allowed: readonly string[]\n readonly base_url: string | null\n /** The name of the variable holding the API's key, never the key. */\n readonly api_key_env: string | null\n readonly region: string | null\n readonly profile: string | null\n readonly store: string | null\n readonly hub: AiHubSettings\n}\n\n/**\n * What the build serves (`Settings::available()`), and for each API it does\n * not, the core's refusal naming why - `local` in the published packages.\n */\nexport interface AiServed {\n readonly apis: readonly AiApi[]\n readonly refusals: Readonly<Partial<Record<AiApi, string>>>\n}\n\n/** A model's price, US dollars per million tokens (`Price`). */\nexport interface AiPrice {\n readonly input: number\n readonly output: number\n readonly cache_read: number | null\n readonly cache_write: number | null\n /** An estimate no one bills. */\n readonly simulated: boolean\n}\n\n/** A catalog model (`Model`): its identifier per API, its limits and its price. */\nexport interface AiModel {\n readonly id: string\n readonly aliases: readonly string[]\n readonly api_ids: Readonly<Partial<Record<AiApi, string>>>\n readonly max_input_tokens: number | null\n readonly max_output_tokens: number | null\n readonly price: AiPrice | null\n}\n\n/** The four token counts of a reply (`Usage`). */\nexport interface AiUsage {\n readonly input_tokens: number\n readonly output_tokens: number\n readonly cache_read_input_tokens: number\n readonly cache_creation_input_tokens: number\n}\n\n/** One Messages API content block: `text` carries `text`, `tool_use` its `id`, `name` and `input`. */\nexport interface AiContent {\n readonly type: string\n readonly text?: string\n readonly id?: string\n readonly name?: string\n readonly input?: unknown\n}\n\n/** A model's reply (`Reply`). */\nexport interface AiReply {\n readonly id: string\n readonly model: string\n readonly content: readonly AiContent[]\n /** Why it stopped: `end_turn`, `tool_use`, `max_tokens`, ... */\n readonly stop: string\n readonly usage: AiUsage\n}\n\nexport interface AiMessage {\n readonly role: 'user' | 'assistant'\n readonly content: string | readonly AiContent[]\n}\n\n/** A request (`LlmRequest`): the conversation oldest first. */\nexport interface AiRequest {\n readonly system?: string\n readonly messages: readonly AiMessage[]\n readonly max_tokens?: number\n readonly effort?: string\n}\n\nexport interface AiToolUse {\n readonly id: string\n readonly name: string\n readonly input: unknown\n}\n\nexport interface AiToolResult {\n readonly content: string\n readonly is_error: boolean\n}\n\n/** One step of an agent run, as the addon's `AgentEvent` reports it. */\nexport type AiAgentEvent =\n | { readonly type: 'text'; readonly text: string }\n | { readonly type: 'reply'; readonly reply: AiReply }\n | { readonly type: 'tool_call'; readonly call: AiToolUse }\n | { readonly type: 'tool_result'; readonly call: AiToolUse; readonly output: AiToolResult }\n\nexport interface AiStoredFile {\n readonly name: string\n readonly size: number\n readonly digest: string\n}\n\n/** A model kept in the store (`Manifest`). */\nexport interface AiStored {\n readonly model: string\n readonly source: string\n readonly revision: string\n readonly tokenizer: string | null\n readonly files: readonly AiStoredFile[]\n readonly stored_unix: number\n}\n\n/** A pull's progress: the file being fetched, its bytes so far and its length where known. */\nexport interface AiProgress {\n readonly file: string\n readonly done: number\n readonly total: number | null\n}\n\n/** A meter's totals (`Kpis`); times in seconds, costs in US dollars. */\nexport interface AiKpis {\n readonly requests: number\n readonly failures: number\n readonly input_tokens: number\n readonly output_tokens: number\n readonly cache_read_input_tokens: number\n readonly cache_creation_input_tokens: number\n readonly cost: number\n readonly simulated_cost: number\n readonly unpriced: number\n readonly elapsed: number\n readonly first_text: number\n}\n\n/**\n * The port the AI components ask. Every method answers a Promise; a run\n * takes an `AbortSignal` and rejects once it is aborted. A refusal is the\n * core's, its message shown as it came.\n */\nexport interface AiEngine {\n settings(): Promise<AiSettings>\n /** Write the settings; answers them as the core read them back. */\n saveSettings(settings: AiSettings): Promise<AiSettings>\n available(): Promise<AiServed>\n models(): Promise<readonly AiModel[]>\n chat(request: AiRequest, options: { readonly onText: (text: string) => void; readonly signal?: AbortSignal }): Promise<AiReply>\n runAgent(request: AiRequest, options: { readonly onEvent: (event: AiAgentEvent) => void; readonly signal?: AbortSignal }): Promise<AiReply>\n store(): Promise<readonly AiStored[]>\n pull(model: string, options: { readonly onProgress: (progress: AiProgress) => void; readonly signal?: AbortSignal }): Promise<void>\n remove(model: string): Promise<void>\n}\n","import type { AiAgentEvent, AiApi, AiModel, AiPrice, AiProgress, AiReply, AiToolResult, AiToolUse, AiUsage } from './engine.js'\nimport { AI_APIS } from './engine.js'\n\n/** A reply's text: its text blocks, joined (`Reply::text`). */\nexport function replyText(reply: AiReply): string {\n return reply.content.map((block) => (block.type === 'text' ? (block.text ?? '') : '')).join('')\n}\n\n/** Two usages summed, count by count. */\nexport function addUsage(one: AiUsage, other: AiUsage): AiUsage {\n return {\n input_tokens: one.input_tokens + other.input_tokens,\n output_tokens: one.output_tokens + other.output_tokens,\n cache_read_input_tokens: one.cache_read_input_tokens + other.cache_read_input_tokens,\n cache_creation_input_tokens: one.cache_creation_input_tokens + other.cache_creation_input_tokens,\n }\n}\n\nexport const NO_USAGE: AiUsage = { input_tokens: 0, output_tokens: 0, cache_read_input_tokens: 0, cache_creation_input_tokens: 0 }\n\nconst COUNT = new Intl.NumberFormat('en-US')\nconst COMPACT = new Intl.NumberFormat('en-US', { notation: 'compact', maximumFractionDigits: 1 })\nconst DOLLARS = new Intl.NumberFormat('en-US', { style: 'currency', currency: 'USD', minimumFractionDigits: 2, maximumFractionDigits: 4 })\n\n/** A token count, grouped: `12,345`. */\nexport const countText = (count: number): string => COUNT.format(count)\n\n/** A US dollar amount: `$0.0123`. */\nexport const dollarText = (amount: number): string => DOLLARS.format(amount)\n\n/** A token limit, compact: `200K tokens`; `unknown` where the catalog states none. */\nexport const limitText = (tokens: number | null): string => (tokens === null ? 'unknown' : `${COMPACT.format(tokens)} tokens`)\n\n/** A price per million tokens: `$3.00 in · $15.00 out / MTok`, an estimate said so; `unpriced` where none is stated. */\nexport function priceText(price: AiPrice | null): string {\n if (price === null) return 'unpriced'\n const text = `${dollarText(price.input)} in · ${dollarText(price.output)} out / MTok`\n return price.simulated ? `${text} (estimate)` : text\n}\n\n/** A byte length in binary units, compact: `1.2 GiB`. */\nexport function bytesText(bytes: number): string {\n const units = ['B', 'KiB', 'MiB', 'GiB', 'TiB']\n let value = bytes\n let unit = 0\n while (value >= 1024 && unit < units.length - 1) {\n value /= 1024\n unit += 1\n }\n return `${unit === 0 ? value : value.toFixed(1)} ${units[unit]}`\n}\n\n/** A pull's progress as a fraction in [0, 1]; null where the file's length is unknown. */\nexport function progressFraction(progress: AiProgress): number | null {\n if (progress.total === null || progress.total <= 0) return null\n return Math.min(1, Math.max(0, progress.done / progress.total))\n}\n\n/** The models served by each of `apis`, each model under the first API that serves it, empty groups left out. */\nexport function modelsByApi(models: readonly AiModel[], apis: readonly AiApi[] = AI_APIS): { api: AiApi; models: AiModel[] }[] {\n const groups = apis.map((api) => ({ api, models: [] as AiModel[] }))\n for (const model of models) groups.find((group) => model.api_ids[group.api] !== undefined)?.models.push(model)\n return groups.filter((group) => group.models.length > 0)\n}\n\n/** The models this machine can run: those with a `local` identifier. */\nexport const localModels = (models: readonly AiModel[]): AiModel[] => models.filter((model) => model.api_ids.local !== undefined)\n\n/** One step of an agent run's timeline. */\nexport type AgentStep =\n | { readonly kind: 'text'; readonly text: string }\n | { readonly kind: 'tool'; readonly call: AiToolUse; readonly output: AiToolResult | null }\n | { readonly kind: 'reply'; readonly reply: AiReply }\n\n/**\n * An agent run's events as its timeline: consecutive text pieces one step, a\n * tool call and its answer one step, each turn's reply closing its turn.\n */\nexport function agentSteps(events: readonly AiAgentEvent[]): AgentStep[] {\n return events.reduce<AgentStep[]>(applyEvent, [])\n}\n\n/**\n * One event folded into a timeline: a new array that shares every step the\n * event leaves alone (only the last text step or the answered tool step is\n * replaced), so a view memoized per step re-renders what changed.\n */\nexport function applyEvent(steps: readonly AgentStep[], event: AiAgentEvent): AgentStep[] {\n const last = steps[steps.length - 1]\n if (event.type === 'text') {\n if (last?.kind === 'text') return [...steps.slice(0, -1), { kind: 'text', text: last.text + event.text }]\n return [...steps, { kind: 'text', text: event.text }]\n }\n if (event.type === 'tool_call') return [...steps, { kind: 'tool', call: event.call, output: null }]\n if (event.type === 'tool_result') {\n const index = steps.findIndex((step) => step.kind === 'tool' && step.call.id === event.call.id && step.output === null)\n const answered: AgentStep = { kind: 'tool', call: event.call, output: event.output }\n if (index < 0) return [...steps, answered]\n return steps.map((step, at) => (at === index ? answered : step))\n }\n return [...steps, { kind: 'reply', reply: event.reply }]\n}\n\n/** The rejection of a cancelled call: an `Error` named `AbortError`, as `fetch` rejects an aborted request. */\nexport const abortError = (): Error => Object.assign(new Error('the call was cancelled'), { name: 'AbortError' })\n\n/** Whether a rejection is the run's own cancellation rather than a refusal. */\nexport function isAbort(error: unknown, signal: AbortSignal): boolean {\n return signal.aborted || (error instanceof Error && error.name === 'AbortError')\n}\n\n/** A rejection's text, the core's message as it came. */\nexport const errorText = (error: unknown): string => (error instanceof Error ? error.message : String(error))\n"]}
|
|
@@ -28,7 +28,7 @@ function priceText(price) {
|
|
|
28
28
|
return price.simulated ? `${text} (estimate)` : text;
|
|
29
29
|
}
|
|
30
30
|
function bytesText(bytes) {
|
|
31
|
-
const units = ["B", "
|
|
31
|
+
const units = ["B", "KiB", "MiB", "GiB", "TiB"];
|
|
32
32
|
let value = bytes;
|
|
33
33
|
let unit = 0;
|
|
34
34
|
while (value >= 1024 && unit < units.length - 1) {
|
|
@@ -48,23 +48,22 @@ function modelsByApi(models, apis = AI_APIS) {
|
|
|
48
48
|
}
|
|
49
49
|
var localModels = (models) => models.filter((model) => model.api_ids.local !== void 0);
|
|
50
50
|
function agentSteps(events) {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
}
|
|
51
|
+
return events.reduce(applyEvent, []);
|
|
52
|
+
}
|
|
53
|
+
function applyEvent(steps, event) {
|
|
54
|
+
const last = steps[steps.length - 1];
|
|
55
|
+
if (event.type === "text") {
|
|
56
|
+
if (last?.kind === "text") return [...steps.slice(0, -1), { kind: "text", text: last.text + event.text }];
|
|
57
|
+
return [...steps, { kind: "text", text: event.text }];
|
|
58
|
+
}
|
|
59
|
+
if (event.type === "tool_call") return [...steps, { kind: "tool", call: event.call, output: null }];
|
|
60
|
+
if (event.type === "tool_result") {
|
|
61
|
+
const index = steps.findIndex((step) => step.kind === "tool" && step.call.id === event.call.id && step.output === null);
|
|
62
|
+
const answered = { kind: "tool", call: event.call, output: event.output };
|
|
63
|
+
if (index < 0) return [...steps, answered];
|
|
64
|
+
return steps.map((step, at) => at === index ? answered : step);
|
|
66
65
|
}
|
|
67
|
-
return steps;
|
|
66
|
+
return [...steps, { kind: "reply", reply: event.reply }];
|
|
68
67
|
}
|
|
69
68
|
var abortError = () => Object.assign(new Error("the call was cancelled"), { name: "AbortError" });
|
|
70
69
|
function isAbort(error, signal) {
|
|
@@ -77,6 +76,7 @@ exports.NO_USAGE = NO_USAGE;
|
|
|
77
76
|
exports.abortError = abortError;
|
|
78
77
|
exports.addUsage = addUsage;
|
|
79
78
|
exports.agentSteps = agentSteps;
|
|
79
|
+
exports.applyEvent = applyEvent;
|
|
80
80
|
exports.bytesText = bytesText;
|
|
81
81
|
exports.countText = countText;
|
|
82
82
|
exports.dollarText = dollarText;
|
|
@@ -88,5 +88,5 @@ exports.modelsByApi = modelsByApi;
|
|
|
88
88
|
exports.priceText = priceText;
|
|
89
89
|
exports.progressFraction = progressFraction;
|
|
90
90
|
exports.replyText = replyText;
|
|
91
|
-
//# sourceMappingURL=chunk-
|
|
92
|
-
//# sourceMappingURL=chunk-
|
|
91
|
+
//# sourceMappingURL=chunk-U65H3IAT.cjs.map
|
|
92
|
+
//# sourceMappingURL=chunk-U65H3IAT.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/engine.ts","../src/format.ts"],"names":[],"mappings":";;;AAcO,IAAM,UAA4B,CAAC,WAAA,EAAa,WAAW,UAAA,EAAY,OAAA,EAAS,YAAY,QAAQ;;;ACVpG,SAAS,UAAU,KAAA,EAAwB;AAChD,EAAA,OAAO,KAAA,CAAM,OAAA,CAAQ,GAAA,CAAI,CAAC,UAAW,KAAA,CAAM,IAAA,KAAS,MAAA,GAAU,KAAA,CAAM,IAAA,IAAQ,EAAA,GAAM,EAAG,CAAA,CAAE,KAAK,EAAE,CAAA;AAChG;AAGO,SAAS,QAAA,CAAS,KAAc,KAAA,EAAyB;AAC9D,EAAA,OAAO;AAAA,IACL,YAAA,EAAc,GAAA,CAAI,YAAA,GAAe,KAAA,CAAM,YAAA;AAAA,IACvC,aAAA,EAAe,GAAA,CAAI,aAAA,GAAgB,KAAA,CAAM,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MAAA,EAAQ,MAAM,KAAA,CAAM,IAAA,EAAM,MAAA,EAAQ,KAAA,CAAM,MAAA,EAAO;AACnF,IAAA,IAAI,QAAQ,CAAA,EAAG,OAAO,CAAC,GAAG,OAAO,QAAQ,CAAA;AACzC,IAAA,OAAO,KAAA,CAAM,IAAI,CAAC,IAAA,EAAM,OAAQ,EAAA,KAAO,KAAA,GAAQ,WAAW,IAAK,CAAA;AAAA,EACjE;AACA,EAAA,OAAO,CAAC,GAAG,KAAA,EAAO,EAAE,MAAM,OAAA,EAAS,KAAA,EAAO,KAAA,CAAM,KAAA,EAAO,CAAA;AACzD;AAGO,IAAM,UAAA,GAAa,MAAa,MAAA,CAAO,MAAA,CAAO,IAAI,KAAA,CAAM,wBAAwB,CAAA,EAAG,EAAE,IAAA,EAAM,YAAA,EAAc;AAGzG,SAAS,OAAA,CAAQ,OAAgB,MAAA,EAA8B;AACpE,EAAA,OAAO,MAAA,CAAO,OAAA,IAAY,KAAA,YAAiB,KAAA,IAAS,MAAM,IAAA,KAAS,YAAA;AACrE;AAGO,IAAM,SAAA,GAAY,CAAC,KAAA,KAA4B,KAAA,YAAiB,QAAQ,KAAA,CAAM,OAAA,GAAU,OAAO,KAAK","file":"chunk-U65H3IAT.cjs","sourcesContent":["/**\n * The AI port: what the components ask of the Node side, as the core's JSON.\n *\n * Every shape mirrors yggio-ai's own: `AiSettings` is `Settings`'s serde JSON\n * field for field (`rust/ai/src/settings.rs`), `AiStored` a store `Manifest`,\n * `AiUsage` and `AiReply` the Messages API's. The browser side holds no\n * credential and calls nothing: the adapter in `yggio-market/node` answers\n * every method from the addon.\n */\n\n/** An API a model is served through, as `Api::as_str` spells it, in `Api::ALL`'s order. */\nexport type AiApi = 'anthropic' | 'bedrock' | 'converse' | 'local' | 'moonshot' | 'openai'\n\n/** Every API, in `Api::ALL`'s order. */\nexport const AI_APIS: readonly AiApi[] = ['anthropic', 'bedrock', 'converse', 'local', 'moonshot', 'openai']\n\n/** The Hugging Face Hub as `Settings` states it (`HubSettings`). */\nexport interface AiHubSettings {\n readonly endpoint: string | null\n readonly cache: string | null\n readonly offline: boolean\n /** The name of the variable holding the Hub token, never the token. */\n readonly token_env: string | null\n}\n\n/** yggio-ai's `Settings`, its serde JSON: what a caller chose once and keeps. */\nexport interface AiSettings {\n readonly api: AiApi\n readonly model: string\n /** Whether the assistant is served: `false`, the default, refuses every request a server gates by `Settings::model_for`. */\n readonly enabled: boolean\n /** The models a request may ask besides `model`, by catalog name; empty allows `model` alone. */\n readonly allowed: readonly string[]\n readonly base_url: string | null\n /** The name of the variable holding the API's key, never the key. */\n readonly api_key_env: string | null\n readonly region: string | null\n readonly profile: string | null\n readonly store: string | null\n readonly hub: AiHubSettings\n}\n\n/**\n * What the build serves (`Settings::available()`), and for each API it does\n * not, the core's refusal naming why - `local` in the published packages.\n */\nexport interface AiServed {\n readonly apis: readonly AiApi[]\n readonly refusals: Readonly<Partial<Record<AiApi, string>>>\n}\n\n/** A model's price, US dollars per million tokens (`Price`). */\nexport interface AiPrice {\n readonly input: number\n readonly output: number\n readonly cache_read: number | null\n readonly cache_write: number | null\n /** An estimate no one bills. */\n readonly simulated: boolean\n}\n\n/** A catalog model (`Model`): its identifier per API, its limits and its price. */\nexport interface AiModel {\n readonly id: string\n readonly aliases: readonly string[]\n readonly api_ids: Readonly<Partial<Record<AiApi, string>>>\n readonly max_input_tokens: number | null\n readonly max_output_tokens: number | null\n readonly price: AiPrice | null\n}\n\n/** The four token counts of a reply (`Usage`). */\nexport interface AiUsage {\n readonly input_tokens: number\n readonly output_tokens: number\n readonly cache_read_input_tokens: number\n readonly cache_creation_input_tokens: number\n}\n\n/** One Messages API content block: `text` carries `text`, `tool_use` its `id`, `name` and `input`. */\nexport interface AiContent {\n readonly type: string\n readonly text?: string\n readonly id?: string\n readonly name?: string\n readonly input?: unknown\n}\n\n/** A model's reply (`Reply`). */\nexport interface AiReply {\n readonly id: string\n readonly model: string\n readonly content: readonly AiContent[]\n /** Why it stopped: `end_turn`, `tool_use`, `max_tokens`, ... */\n readonly stop: string\n readonly usage: AiUsage\n}\n\nexport interface AiMessage {\n readonly role: 'user' | 'assistant'\n readonly content: string | readonly AiContent[]\n}\n\n/** A request (`LlmRequest`): the conversation oldest first. */\nexport interface AiRequest {\n readonly system?: string\n readonly messages: readonly AiMessage[]\n readonly max_tokens?: number\n readonly effort?: string\n}\n\nexport interface AiToolUse {\n readonly id: string\n readonly name: string\n readonly input: unknown\n}\n\nexport interface AiToolResult {\n readonly content: string\n readonly is_error: boolean\n}\n\n/** One step of an agent run, as the addon's `AgentEvent` reports it. */\nexport type AiAgentEvent =\n | { readonly type: 'text'; readonly text: string }\n | { readonly type: 'reply'; readonly reply: AiReply }\n | { readonly type: 'tool_call'; readonly call: AiToolUse }\n | { readonly type: 'tool_result'; readonly call: AiToolUse; readonly output: AiToolResult }\n\nexport interface AiStoredFile {\n readonly name: string\n readonly size: number\n readonly digest: string\n}\n\n/** A model kept in the store (`Manifest`). */\nexport interface AiStored {\n readonly model: string\n readonly source: string\n readonly revision: string\n readonly tokenizer: string | null\n readonly files: readonly AiStoredFile[]\n readonly stored_unix: number\n}\n\n/** A pull's progress: the file being fetched, its bytes so far and its length where known. */\nexport interface AiProgress {\n readonly file: string\n readonly done: number\n readonly total: number | null\n}\n\n/** A meter's totals (`Kpis`); times in seconds, costs in US dollars. */\nexport interface AiKpis {\n readonly requests: number\n readonly failures: number\n readonly input_tokens: number\n readonly output_tokens: number\n readonly cache_read_input_tokens: number\n readonly cache_creation_input_tokens: number\n readonly cost: number\n readonly simulated_cost: number\n readonly unpriced: number\n readonly elapsed: number\n readonly first_text: number\n}\n\n/**\n * The port the AI components ask. Every method answers a Promise; a run\n * takes an `AbortSignal` and rejects once it is aborted. A refusal is the\n * core's, its message shown as it came.\n */\nexport interface AiEngine {\n settings(): Promise<AiSettings>\n /** Write the settings; answers them as the core read them back. */\n saveSettings(settings: AiSettings): Promise<AiSettings>\n available(): Promise<AiServed>\n models(): Promise<readonly AiModel[]>\n chat(request: AiRequest, options: { readonly onText: (text: string) => void; readonly signal?: AbortSignal }): Promise<AiReply>\n runAgent(request: AiRequest, options: { readonly onEvent: (event: AiAgentEvent) => void; readonly signal?: AbortSignal }): Promise<AiReply>\n store(): Promise<readonly AiStored[]>\n pull(model: string, options: { readonly onProgress: (progress: AiProgress) => void; readonly signal?: AbortSignal }): Promise<void>\n remove(model: string): Promise<void>\n}\n","import type { AiAgentEvent, AiApi, AiModel, AiPrice, AiProgress, AiReply, AiToolResult, AiToolUse, AiUsage } from './engine.js'\nimport { AI_APIS } from './engine.js'\n\n/** A reply's text: its text blocks, joined (`Reply::text`). */\nexport function replyText(reply: AiReply): string {\n return reply.content.map((block) => (block.type === 'text' ? (block.text ?? '') : '')).join('')\n}\n\n/** Two usages summed, count by count. */\nexport function addUsage(one: AiUsage, other: AiUsage): AiUsage {\n return {\n input_tokens: one.input_tokens + other.input_tokens,\n output_tokens: one.output_tokens + other.output_tokens,\n cache_read_input_tokens: one.cache_read_input_tokens + other.cache_read_input_tokens,\n cache_creation_input_tokens: one.cache_creation_input_tokens + other.cache_creation_input_tokens,\n }\n}\n\nexport const NO_USAGE: AiUsage = { input_tokens: 0, output_tokens: 0, cache_read_input_tokens: 0, cache_creation_input_tokens: 0 }\n\nconst COUNT = new Intl.NumberFormat('en-US')\nconst COMPACT = new Intl.NumberFormat('en-US', { notation: 'compact', maximumFractionDigits: 1 })\nconst DOLLARS = new Intl.NumberFormat('en-US', { style: 'currency', currency: 'USD', minimumFractionDigits: 2, maximumFractionDigits: 4 })\n\n/** A token count, grouped: `12,345`. */\nexport const countText = (count: number): string => COUNT.format(count)\n\n/** A US dollar amount: `$0.0123`. */\nexport const dollarText = (amount: number): string => DOLLARS.format(amount)\n\n/** A token limit, compact: `200K tokens`; `unknown` where the catalog states none. */\nexport const limitText = (tokens: number | null): string => (tokens === null ? 'unknown' : `${COMPACT.format(tokens)} tokens`)\n\n/** A price per million tokens: `$3.00 in · $15.00 out / MTok`, an estimate said so; `unpriced` where none is stated. */\nexport function priceText(price: AiPrice | null): string {\n if (price === null) return 'unpriced'\n const text = `${dollarText(price.input)} in · ${dollarText(price.output)} out / MTok`\n return price.simulated ? `${text} (estimate)` : text\n}\n\n/** A byte length in binary units, compact: `1.2 GiB`. */\nexport function bytesText(bytes: number): string {\n const units = ['B', 'KiB', 'MiB', 'GiB', 'TiB']\n let value = bytes\n let unit = 0\n while (value >= 1024 && unit < units.length - 1) {\n value /= 1024\n unit += 1\n }\n return `${unit === 0 ? value : value.toFixed(1)} ${units[unit]}`\n}\n\n/** A pull's progress as a fraction in [0, 1]; null where the file's length is unknown. */\nexport function progressFraction(progress: AiProgress): number | null {\n if (progress.total === null || progress.total <= 0) return null\n return Math.min(1, Math.max(0, progress.done / progress.total))\n}\n\n/** The models served by each of `apis`, each model under the first API that serves it, empty groups left out. */\nexport function modelsByApi(models: readonly AiModel[], apis: readonly AiApi[] = AI_APIS): { api: AiApi; models: AiModel[] }[] {\n const groups = apis.map((api) => ({ api, models: [] as AiModel[] }))\n for (const model of models) groups.find((group) => model.api_ids[group.api] !== undefined)?.models.push(model)\n return groups.filter((group) => group.models.length > 0)\n}\n\n/** The models this machine can run: those with a `local` identifier. */\nexport const localModels = (models: readonly AiModel[]): AiModel[] => models.filter((model) => model.api_ids.local !== undefined)\n\n/** One step of an agent run's timeline. */\nexport type AgentStep =\n | { readonly kind: 'text'; readonly text: string }\n | { readonly kind: 'tool'; readonly call: AiToolUse; readonly output: AiToolResult | null }\n | { readonly kind: 'reply'; readonly reply: AiReply }\n\n/**\n * An agent run's events as its timeline: consecutive text pieces one step, a\n * tool call and its answer one step, each turn's reply closing its turn.\n */\nexport function agentSteps(events: readonly AiAgentEvent[]): AgentStep[] {\n return events.reduce<AgentStep[]>(applyEvent, [])\n}\n\n/**\n * One event folded into a timeline: a new array that shares every step the\n * event leaves alone (only the last text step or the answered tool step is\n * replaced), so a view memoized per step re-renders what changed.\n */\nexport function applyEvent(steps: readonly AgentStep[], event: AiAgentEvent): AgentStep[] {\n const last = steps[steps.length - 1]\n if (event.type === 'text') {\n if (last?.kind === 'text') return [...steps.slice(0, -1), { kind: 'text', text: last.text + event.text }]\n return [...steps, { kind: 'text', text: event.text }]\n }\n if (event.type === 'tool_call') return [...steps, { kind: 'tool', call: event.call, output: null }]\n if (event.type === 'tool_result') {\n const index = steps.findIndex((step) => step.kind === 'tool' && step.call.id === event.call.id && step.output === null)\n const answered: AgentStep = { kind: 'tool', call: event.call, output: event.output }\n if (index < 0) return [...steps, answered]\n return steps.map((step, at) => (at === index ? answered : step))\n }\n return [...steps, { kind: 'reply', reply: event.reply }]\n}\n\n/** The rejection of a cancelled call: an `Error` named `AbortError`, as `fetch` rejects an aborted request. */\nexport const abortError = (): Error => Object.assign(new Error('the call was cancelled'), { name: 'AbortError' })\n\n/** Whether a rejection is the run's own cancellation rather than a refusal. */\nexport function isAbort(error: unknown, signal: AbortSignal): boolean {\n return signal.aborted || (error instanceof Error && error.name === 'AbortError')\n}\n\n/** A rejection's text, the core's message as it came. */\nexport const errorText = (error: unknown): string => (error instanceof Error ? error.message : String(error))\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AI_APIS } from './chunk-
|
|
1
|
+
import { AI_APIS } from './chunk-LU2IPSYQ.js';
|
|
2
2
|
|
|
3
3
|
// src/presets.ts
|
|
4
4
|
var API_LABELS = {
|
|
@@ -36,5 +36,5 @@ var API_READS = {
|
|
|
36
36
|
};
|
|
37
37
|
|
|
38
38
|
export { AI_PRESETS, API_LABELS, API_READS, HUGGINGFACE_BASE_URL, OLLAMA_BASE_URL, applyPreset, fallbackApi, presetOf };
|
|
39
|
-
//# sourceMappingURL=chunk-
|
|
40
|
-
//# sourceMappingURL=chunk-
|
|
39
|
+
//# sourceMappingURL=chunk-XR2XLKYJ.js.map
|
|
40
|
+
//# sourceMappingURL=chunk-XR2XLKYJ.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/presets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C,UAAA,EAAY,aAAa;AACpC","file":"chunk-XR2XLKYJ.js","sourcesContent":["import type { AiApi, AiServed, AiSettings } from './engine.js'\nimport { AI_APIS } from './engine.js'\n\n/** How each API is named to a reader. */\nexport const API_LABELS: Readonly<Record<AiApi, string>> = {\n anthropic: 'Claude (Anthropic)',\n bedrock: 'Claude in Amazon Bedrock',\n converse: 'Amazon Bedrock Converse',\n local: 'Local (this machine)',\n moonshot: 'Kimi (Moonshot)',\n openai: 'OpenAI-compatible',\n}\n\n/** One provider choice: an API and, for an OpenAI-compatible server, where it answers and which variable holds its key. */\nexport interface AiPreset {\n readonly id: string\n readonly label: string\n readonly api: AiApi\n readonly base_url: string | null\n readonly api_key_env: string | null\n}\n\n/** yggio-ai's `HUGGINGFACE_BASE_URL`: the Hugging Face router, keyed by `HF_TOKEN`. */\nexport const HUGGINGFACE_BASE_URL = 'https://router.huggingface.co/v1'\n/** yggio-ai's `OLLAMA_BASE_URL`: a local Ollama server, keyless. */\nexport const OLLAMA_BASE_URL = 'http://localhost:11434/v1'\n\n/** Every API as itself, then the OpenAI-compatible presets the core names: Hugging Face and Ollama. */\nexport const AI_PRESETS: readonly AiPreset[] = [\n ...AI_APIS.map((api) => ({ id: api, label: API_LABELS[api], api, base_url: null, api_key_env: null })),\n { id: 'huggingface', label: 'Hugging Face', api: 'openai', base_url: HUGGINGFACE_BASE_URL, api_key_env: 'HF_TOKEN' },\n { id: 'ollama', label: 'Ollama', api: 'openai', base_url: OLLAMA_BASE_URL, api_key_env: null },\n]\n\n/** The preset the settings are: an OpenAI-compatible API by its root, any other by its API. */\nexport function presetOf(settings: AiSettings): AiPreset {\n const named = AI_PRESETS.find((preset) => preset.api === settings.api && preset.base_url !== null && preset.base_url === settings.base_url)\n return named ?? AI_PRESETS.find((preset) => preset.id === settings.api)!\n}\n\n/** The settings moved to `preset`: its API, root and key variable; the rest kept. */\nexport function applyPreset(settings: AiSettings, preset: AiPreset): AiSettings {\n return { ...settings, api: preset.api, base_url: preset.base_url, api_key_env: preset.api_key_env }\n}\n\n/** The API shown where the settings name one the build does not serve: the first it does, in `Api::ALL`'s order. */\nexport function fallbackApi(served: AiServed): AiApi | null {\n return AI_APIS.find((api) => served.apis.includes(api)) ?? null\n}\n\n/**\n * The settings each API reads, beyond its model: the ones taking a root\n * (`Api::takes_base_url`), a key variable, Bedrock's region and profile, and\n * this machine's store and Hub.\n */\nexport const API_READS: Readonly<Record<AiApi, readonly ('base_url' | 'api_key_env' | 'region' | 'profile' | 'store' | 'hub')[]>> = {\n anthropic: ['base_url', 'api_key_env'],\n bedrock: ['api_key_env', 'region', 'profile'],\n converse: ['api_key_env', 'region', 'profile'],\n local: ['store', 'hub'],\n moonshot: ['base_url', 'api_key_env'],\n openai: ['base_url', 'api_key_env'],\n}\n"]}
|
|
@@ -23,6 +23,10 @@ interface AiHubSettings {
|
|
|
23
23
|
interface AiSettings {
|
|
24
24
|
readonly api: AiApi;
|
|
25
25
|
readonly model: string;
|
|
26
|
+
/** Whether the assistant is served: `false`, the default, refuses every request a server gates by `Settings::model_for`. */
|
|
27
|
+
readonly enabled: boolean;
|
|
28
|
+
/** The models a request may ask besides `model`, by catalog name; empty allows `model` alone. */
|
|
29
|
+
readonly allowed: readonly string[];
|
|
26
30
|
readonly base_url: string | null;
|
|
27
31
|
/** The name of the variable holding the API's key, never the key. */
|
|
28
32
|
readonly api_key_env: string | null;
|
|
@@ -23,6 +23,10 @@ interface AiHubSettings {
|
|
|
23
23
|
interface AiSettings {
|
|
24
24
|
readonly api: AiApi;
|
|
25
25
|
readonly model: string;
|
|
26
|
+
/** Whether the assistant is served: `false`, the default, refuses every request a server gates by `Settings::model_for`. */
|
|
27
|
+
readonly enabled: boolean;
|
|
28
|
+
/** The models a request may ask besides `model`, by catalog name; empty allows `model` alone. */
|
|
29
|
+
readonly allowed: readonly string[];
|
|
26
30
|
readonly base_url: string | null;
|
|
27
31
|
/** The name of the variable holding the API's key, never the key. */
|
|
28
32
|
readonly api_key_env: string | null;
|
package/dist/http.d.cts
CHANGED
package/dist/http.d.ts
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -1,105 +1,105 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
var
|
|
3
|
+
var chunkF5TA7LVR_cjs = require('./chunk-F5TA7LVR.cjs');
|
|
4
|
+
var chunkU65H3IAT_cjs = require('./chunk-U65H3IAT.cjs');
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
Object.defineProperty(exports, "AI_PRESETS", {
|
|
9
9
|
enumerable: true,
|
|
10
|
-
get: function () { return
|
|
10
|
+
get: function () { return chunkF5TA7LVR_cjs.AI_PRESETS; }
|
|
11
11
|
});
|
|
12
12
|
Object.defineProperty(exports, "API_LABELS", {
|
|
13
13
|
enumerable: true,
|
|
14
|
-
get: function () { return
|
|
14
|
+
get: function () { return chunkF5TA7LVR_cjs.API_LABELS; }
|
|
15
15
|
});
|
|
16
16
|
Object.defineProperty(exports, "API_READS", {
|
|
17
17
|
enumerable: true,
|
|
18
|
-
get: function () { return
|
|
18
|
+
get: function () { return chunkF5TA7LVR_cjs.API_READS; }
|
|
19
19
|
});
|
|
20
20
|
Object.defineProperty(exports, "HUGGINGFACE_BASE_URL", {
|
|
21
21
|
enumerable: true,
|
|
22
|
-
get: function () { return
|
|
22
|
+
get: function () { return chunkF5TA7LVR_cjs.HUGGINGFACE_BASE_URL; }
|
|
23
23
|
});
|
|
24
24
|
Object.defineProperty(exports, "OLLAMA_BASE_URL", {
|
|
25
25
|
enumerable: true,
|
|
26
|
-
get: function () { return
|
|
26
|
+
get: function () { return chunkF5TA7LVR_cjs.OLLAMA_BASE_URL; }
|
|
27
27
|
});
|
|
28
28
|
Object.defineProperty(exports, "applyPreset", {
|
|
29
29
|
enumerable: true,
|
|
30
|
-
get: function () { return
|
|
30
|
+
get: function () { return chunkF5TA7LVR_cjs.applyPreset; }
|
|
31
31
|
});
|
|
32
32
|
Object.defineProperty(exports, "fallbackApi", {
|
|
33
33
|
enumerable: true,
|
|
34
|
-
get: function () { return
|
|
34
|
+
get: function () { return chunkF5TA7LVR_cjs.fallbackApi; }
|
|
35
35
|
});
|
|
36
36
|
Object.defineProperty(exports, "presetOf", {
|
|
37
37
|
enumerable: true,
|
|
38
|
-
get: function () { return
|
|
38
|
+
get: function () { return chunkF5TA7LVR_cjs.presetOf; }
|
|
39
39
|
});
|
|
40
40
|
Object.defineProperty(exports, "AI_APIS", {
|
|
41
41
|
enumerable: true,
|
|
42
|
-
get: function () { return
|
|
42
|
+
get: function () { return chunkU65H3IAT_cjs.AI_APIS; }
|
|
43
43
|
});
|
|
44
44
|
Object.defineProperty(exports, "NO_USAGE", {
|
|
45
45
|
enumerable: true,
|
|
46
|
-
get: function () { return
|
|
46
|
+
get: function () { return chunkU65H3IAT_cjs.NO_USAGE; }
|
|
47
47
|
});
|
|
48
48
|
Object.defineProperty(exports, "abortError", {
|
|
49
49
|
enumerable: true,
|
|
50
|
-
get: function () { return
|
|
50
|
+
get: function () { return chunkU65H3IAT_cjs.abortError; }
|
|
51
51
|
});
|
|
52
52
|
Object.defineProperty(exports, "addUsage", {
|
|
53
53
|
enumerable: true,
|
|
54
|
-
get: function () { return
|
|
54
|
+
get: function () { return chunkU65H3IAT_cjs.addUsage; }
|
|
55
55
|
});
|
|
56
56
|
Object.defineProperty(exports, "agentSteps", {
|
|
57
57
|
enumerable: true,
|
|
58
|
-
get: function () { return
|
|
58
|
+
get: function () { return chunkU65H3IAT_cjs.agentSteps; }
|
|
59
59
|
});
|
|
60
60
|
Object.defineProperty(exports, "bytesText", {
|
|
61
61
|
enumerable: true,
|
|
62
|
-
get: function () { return
|
|
62
|
+
get: function () { return chunkU65H3IAT_cjs.bytesText; }
|
|
63
63
|
});
|
|
64
64
|
Object.defineProperty(exports, "countText", {
|
|
65
65
|
enumerable: true,
|
|
66
|
-
get: function () { return
|
|
66
|
+
get: function () { return chunkU65H3IAT_cjs.countText; }
|
|
67
67
|
});
|
|
68
68
|
Object.defineProperty(exports, "dollarText", {
|
|
69
69
|
enumerable: true,
|
|
70
|
-
get: function () { return
|
|
70
|
+
get: function () { return chunkU65H3IAT_cjs.dollarText; }
|
|
71
71
|
});
|
|
72
72
|
Object.defineProperty(exports, "errorText", {
|
|
73
73
|
enumerable: true,
|
|
74
|
-
get: function () { return
|
|
74
|
+
get: function () { return chunkU65H3IAT_cjs.errorText; }
|
|
75
75
|
});
|
|
76
76
|
Object.defineProperty(exports, "isAbort", {
|
|
77
77
|
enumerable: true,
|
|
78
|
-
get: function () { return
|
|
78
|
+
get: function () { return chunkU65H3IAT_cjs.isAbort; }
|
|
79
79
|
});
|
|
80
80
|
Object.defineProperty(exports, "limitText", {
|
|
81
81
|
enumerable: true,
|
|
82
|
-
get: function () { return
|
|
82
|
+
get: function () { return chunkU65H3IAT_cjs.limitText; }
|
|
83
83
|
});
|
|
84
84
|
Object.defineProperty(exports, "localModels", {
|
|
85
85
|
enumerable: true,
|
|
86
|
-
get: function () { return
|
|
86
|
+
get: function () { return chunkU65H3IAT_cjs.localModels; }
|
|
87
87
|
});
|
|
88
88
|
Object.defineProperty(exports, "modelsByApi", {
|
|
89
89
|
enumerable: true,
|
|
90
|
-
get: function () { return
|
|
90
|
+
get: function () { return chunkU65H3IAT_cjs.modelsByApi; }
|
|
91
91
|
});
|
|
92
92
|
Object.defineProperty(exports, "priceText", {
|
|
93
93
|
enumerable: true,
|
|
94
|
-
get: function () { return
|
|
94
|
+
get: function () { return chunkU65H3IAT_cjs.priceText; }
|
|
95
95
|
});
|
|
96
96
|
Object.defineProperty(exports, "progressFraction", {
|
|
97
97
|
enumerable: true,
|
|
98
|
-
get: function () { return
|
|
98
|
+
get: function () { return chunkU65H3IAT_cjs.progressFraction; }
|
|
99
99
|
});
|
|
100
100
|
Object.defineProperty(exports, "replyText", {
|
|
101
101
|
enumerable: true,
|
|
102
|
-
get: function () { return
|
|
102
|
+
get: function () { return chunkU65H3IAT_cjs.replyText; }
|
|
103
103
|
});
|
|
104
104
|
//# sourceMappingURL=index.cjs.map
|
|
105
105
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { a as AiApi, b as AiSettings, c as AiServed, d as AiToolUse, e as AiToolResult, f as AiReply, g as AiUsage, h as AiAgentEvent, i as AiModel, j as AiPrice, k as AiProgress } from './engine-
|
|
2
|
-
export { l as AI_APIS, m as AiContent, A as AiEngine, n as AiHubSettings, o as AiKpis, p as AiMessage, q as AiRequest, r as AiStored, s as AiStoredFile } from './engine-
|
|
1
|
+
import { a as AiApi, b as AiSettings, c as AiServed, d as AiToolUse, e as AiToolResult, f as AiReply, g as AiUsage, h as AiAgentEvent, i as AiModel, j as AiPrice, k as AiProgress } from './engine-BfLKZyiq.cjs';
|
|
2
|
+
export { l as AI_APIS, m as AiContent, A as AiEngine, n as AiHubSettings, o as AiKpis, p as AiMessage, q as AiRequest, r as AiStored, s as AiStoredFile } from './engine-BfLKZyiq.cjs';
|
|
3
3
|
|
|
4
4
|
/** How each API is named to a reader. */
|
|
5
5
|
declare const API_LABELS: Readonly<Record<AiApi, string>>;
|
|
@@ -43,7 +43,7 @@ declare const dollarText: (amount: number) => string;
|
|
|
43
43
|
declare const limitText: (tokens: number | null) => string;
|
|
44
44
|
/** A price per million tokens: `$3.00 in · $15.00 out / MTok`, an estimate said so; `unpriced` where none is stated. */
|
|
45
45
|
declare function priceText(price: AiPrice | null): string;
|
|
46
|
-
/** A byte length, compact: `1.2
|
|
46
|
+
/** A byte length in binary units, compact: `1.2 GiB`. */
|
|
47
47
|
declare function bytesText(bytes: number): string;
|
|
48
48
|
/** A pull's progress as a fraction in [0, 1]; null where the file's length is unknown. */
|
|
49
49
|
declare function progressFraction(progress: AiProgress): number | null;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { a as AiApi, b as AiSettings, c as AiServed, d as AiToolUse, e as AiToolResult, f as AiReply, g as AiUsage, h as AiAgentEvent, i as AiModel, j as AiPrice, k as AiProgress } from './engine-
|
|
2
|
-
export { l as AI_APIS, m as AiContent, A as AiEngine, n as AiHubSettings, o as AiKpis, p as AiMessage, q as AiRequest, r as AiStored, s as AiStoredFile } from './engine-
|
|
1
|
+
import { a as AiApi, b as AiSettings, c as AiServed, d as AiToolUse, e as AiToolResult, f as AiReply, g as AiUsage, h as AiAgentEvent, i as AiModel, j as AiPrice, k as AiProgress } from './engine-BfLKZyiq.js';
|
|
2
|
+
export { l as AI_APIS, m as AiContent, A as AiEngine, n as AiHubSettings, o as AiKpis, p as AiMessage, q as AiRequest, r as AiStored, s as AiStoredFile } from './engine-BfLKZyiq.js';
|
|
3
3
|
|
|
4
4
|
/** How each API is named to a reader. */
|
|
5
5
|
declare const API_LABELS: Readonly<Record<AiApi, string>>;
|
|
@@ -43,7 +43,7 @@ declare const dollarText: (amount: number) => string;
|
|
|
43
43
|
declare const limitText: (tokens: number | null) => string;
|
|
44
44
|
/** A price per million tokens: `$3.00 in · $15.00 out / MTok`, an estimate said so; `unpriced` where none is stated. */
|
|
45
45
|
declare function priceText(price: AiPrice | null): string;
|
|
46
|
-
/** A byte length, compact: `1.2
|
|
46
|
+
/** A byte length in binary units, compact: `1.2 GiB`. */
|
|
47
47
|
declare function bytesText(bytes: number): string;
|
|
48
48
|
/** A pull's progress as a fraction in [0, 1]; null where the file's length is unknown. */
|
|
49
49
|
declare function progressFraction(progress: AiProgress): number | null;
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { AI_PRESETS, API_LABELS, API_READS, HUGGINGFACE_BASE_URL, OLLAMA_BASE_URL, applyPreset, fallbackApi, presetOf } from './chunk-
|
|
2
|
-
export { AI_APIS, NO_USAGE, abortError, addUsage, agentSteps, bytesText, countText, dollarText, errorText, isAbort, limitText, localModels, modelsByApi, priceText, progressFraction, replyText } from './chunk-
|
|
1
|
+
export { AI_PRESETS, API_LABELS, API_READS, HUGGINGFACE_BASE_URL, OLLAMA_BASE_URL, applyPreset, fallbackApi, presetOf } from './chunk-XR2XLKYJ.js';
|
|
2
|
+
export { AI_APIS, NO_USAGE, abortError, addUsage, agentSteps, bytesText, countText, dollarText, errorText, isAbort, limitText, localModels, modelsByApi, priceText, progressFraction, replyText } from './chunk-LU2IPSYQ.js';
|
|
3
3
|
//# sourceMappingURL=index.js.map
|
|
4
4
|
//# sourceMappingURL=index.js.map
|