@kwirthmagnify/kwirth-common-ai 0.5.64 → 0.5.65
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/back.d.ts +49 -3
- package/dist/back.js +153 -5
- package/dist/index.d.ts +23 -0
- package/dist/index.js +16 -1
- package/package.json +79 -79
package/dist/back.d.ts
CHANGED
|
@@ -1,13 +1,58 @@
|
|
|
1
|
-
import { ILlm, ILlmProvider, ECapability, EToolEffect, EToolSensitivity, IAiToolInfo, IAiToolsetInfo, IToolsetConfig } from './index';
|
|
1
|
+
import { ILlm, ILlmProvider, ECapability, EToolEffect, EToolSensitivity, EUsagePeriod, EUsageUnit, IAiToolInfo, IAiToolsetInfo, IToolsetConfig } from './index';
|
|
2
2
|
import type { AppsV1Api, CoreV1Api, CustomObjectsApi, NetworkingV1Api } from '@kubernetes/client-node';
|
|
3
3
|
interface ILogChannel {
|
|
4
4
|
logInfo?: (msg: string) => void;
|
|
5
5
|
logWarning?: (msg: string) => void;
|
|
6
6
|
logError?: (msg: string) => void;
|
|
7
7
|
}
|
|
8
|
-
import { LanguageModel, ToolSet } from 'ai';
|
|
8
|
+
import { LanguageModel, ToolSet, generateText as sdkGenerateText } from 'ai';
|
|
9
9
|
import { z } from 'zod';
|
|
10
10
|
export declare const buildModel: (llm: ILlm, providers: ILlmProvider[]) => LanguageModel | null;
|
|
11
|
+
export declare enum EUsageScope {
|
|
12
|
+
LLM_KEY = "llmkey",
|
|
13
|
+
CHANNEL = "channel"
|
|
14
|
+
}
|
|
15
|
+
export interface IUsageAmounts {
|
|
16
|
+
tokensIn: number;
|
|
17
|
+
tokensOut: number;
|
|
18
|
+
calls: number;
|
|
19
|
+
cost: number;
|
|
20
|
+
}
|
|
21
|
+
export interface IUsageLimitExceeded {
|
|
22
|
+
scope: EUsageScope;
|
|
23
|
+
unit: EUsageUnit;
|
|
24
|
+
period: EUsagePeriod;
|
|
25
|
+
limit: number;
|
|
26
|
+
current: number;
|
|
27
|
+
}
|
|
28
|
+
export interface IUsageService {
|
|
29
|
+
read(scope: EUsageScope, subject: string): Promise<{
|
|
30
|
+
daily: IUsageAmounts;
|
|
31
|
+
monthly: IUsageAmounts;
|
|
32
|
+
}>;
|
|
33
|
+
add(scope: EUsageScope, subject: string, amounts: IUsageAmounts): Promise<void>;
|
|
34
|
+
readonly durable: boolean;
|
|
35
|
+
onCut?(detail: IUsageLimitExceeded): void;
|
|
36
|
+
}
|
|
37
|
+
export declare class UsageLimitError extends Error {
|
|
38
|
+
readonly detail: IUsageLimitExceeded;
|
|
39
|
+
constructor(detail: IUsageLimitExceeded);
|
|
40
|
+
}
|
|
41
|
+
export declare const setUsageService: (service: IUsageService | undefined) => void;
|
|
42
|
+
export declare const getUsageService: () => IUsageService | undefined;
|
|
43
|
+
export declare const runWithUsageGuard: (options: {
|
|
44
|
+
model?: unknown;
|
|
45
|
+
}, call: () => Promise<{
|
|
46
|
+
usage?: {
|
|
47
|
+
inputTokens?: number;
|
|
48
|
+
outputTokens?: number;
|
|
49
|
+
};
|
|
50
|
+
}>) => Promise<{
|
|
51
|
+
usage?: {
|
|
52
|
+
inputTokens?: number;
|
|
53
|
+
outputTokens?: number;
|
|
54
|
+
};
|
|
55
|
+
}>;
|
|
11
56
|
export interface IVisionResult<T> {
|
|
12
57
|
object: T | null;
|
|
13
58
|
text: string;
|
|
@@ -29,7 +74,8 @@ export interface IVisionOptions<T> {
|
|
|
29
74
|
}
|
|
30
75
|
export declare const generateVision: <T>(opts: IVisionOptions<T>) => Promise<IVisionResult<T>>;
|
|
31
76
|
export declare const loadModels: (providers: ILlmProvider[], log: ILogChannel) => Promise<void>;
|
|
32
|
-
export
|
|
77
|
+
export declare const generateText: typeof sdkGenerateText;
|
|
78
|
+
export { Output, stepCountIs, tool } from 'ai';
|
|
33
79
|
export type { LanguageModel, ToolSet } from 'ai';
|
|
34
80
|
export { z } from 'zod';
|
|
35
81
|
export declare const zodFromExample: (example: Record<string, unknown>) => z.ZodObject<Record<string, z.ZodTypeAny>>;
|
package/dist/back.js
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.buildAgentTools = exports.resolveTools = exports.resolveToolRef = exports.invokeToolRef = exports.buildToolHost = exports.listToolsetInfos = exports.listToolsets = exports.getToolset = exports.unregisterToolset = exports.registerToolset = exports.isToolsetGrantedTo = exports.getToolsetGrants = exports.setToolsetGrants = exports.isBuiltInToolsetId = exports.defineTool = exports.runWithToolContext = exports.EToolEffect = exports.zodFromExample = exports.z = exports.tool = exports.stepCountIs = exports.Output = exports.generateText = exports.loadModels = exports.generateVision = exports.buildModel = void 0;
|
|
3
|
+
exports.buildAgentTools = exports.resolveTools = exports.resolveToolRef = exports.invokeToolRef = exports.buildToolHost = exports.listToolsetInfos = exports.listToolsets = exports.getToolset = exports.unregisterToolset = exports.registerToolset = exports.isToolsetGrantedTo = exports.getToolsetGrants = exports.setToolsetGrants = exports.isBuiltInToolsetId = exports.defineTool = exports.runWithToolContext = exports.EToolEffect = exports.zodFromExample = exports.z = exports.tool = exports.stepCountIs = exports.Output = exports.generateText = exports.loadModels = exports.generateVision = exports.runWithUsageGuard = exports.getUsageService = exports.setUsageService = exports.UsageLimitError = exports.EUsageScope = exports.buildModel = void 0;
|
|
4
4
|
const index_1 = require("./index");
|
|
5
|
+
// Aliased on purpose: the generateText this module EXPORTS is the wrapped one, and nothing below should
|
|
6
|
+
// be able to reach the raw SDK call by accident — that is exactly how a call would escape the counters.
|
|
5
7
|
const ai_1 = require("ai");
|
|
6
8
|
const zod_1 = require("zod");
|
|
7
9
|
const async_hooks_1 = require("async_hooks");
|
|
10
|
+
const crypto_1 = require("crypto");
|
|
8
11
|
const openai_1 = require("@ai-sdk/openai");
|
|
9
12
|
const groq_1 = require("@ai-sdk/groq");
|
|
10
13
|
const mistral_1 = require("@ai-sdk/mistral");
|
|
@@ -13,13 +16,19 @@ const deepseek_1 = require("@ai-sdk/deepseek");
|
|
|
13
16
|
const ai_sdk_provider_1 = require("@openrouter/ai-sdk-provider");
|
|
14
17
|
const anthropic_1 = require("@ai-sdk/anthropic");
|
|
15
18
|
const buildModel = (llm, providers) => {
|
|
16
|
-
var _a, _b, _c;
|
|
17
19
|
const prov = providers.find(p => p.name === llm.provider);
|
|
18
20
|
const key = llm.useProviderKey ? prov === null || prov === void 0 ? void 0 : prov.key : llm.key;
|
|
19
21
|
if (!key) {
|
|
20
22
|
console.log('Could not find a key');
|
|
21
23
|
return null;
|
|
22
24
|
}
|
|
25
|
+
// Whatever the switch returns is annotated with what it was built from, so generateText knows which
|
|
26
|
+
// budget to count it against. Wrapping here and not at each 'return' keeps the two in step.
|
|
27
|
+
return rememberOrigin(buildSdkModel(llm, prov, key), llm, prov, key);
|
|
28
|
+
};
|
|
29
|
+
exports.buildModel = buildModel;
|
|
30
|
+
const buildSdkModel = (llm, prov, key) => {
|
|
31
|
+
var _a, _b, _c;
|
|
23
32
|
const type = (_b = (_a = prov === null || prov === void 0 ? void 0 : prov.type) !== null && _a !== void 0 ? _a : prov === null || prov === void 0 ? void 0 : prov.name) !== null && _b !== void 0 ? _b : llm.provider;
|
|
24
33
|
switch (type) {
|
|
25
34
|
case 'openai': return (0, openai_1.createOpenAI)({ apiKey: key })(llm.model);
|
|
@@ -41,7 +50,138 @@ const buildModel = (llm, providers) => {
|
|
|
41
50
|
return null;
|
|
42
51
|
}
|
|
43
52
|
};
|
|
44
|
-
|
|
53
|
+
// ─────────────────────────────────────────────────────────────────────────────────────────────────────
|
|
54
|
+
// Usage control (plan: plans/ai-usage-control/PLAN.md, S1)
|
|
55
|
+
//
|
|
56
|
+
// Every LLM call in Kwirth goes through the generateText below. Not by convention: the plugins map
|
|
57
|
+
// '@kwirthmagnify/kwirth-common-ai' to global.__kwirth_back__ in their build, so what they execute is the
|
|
58
|
+
// CORE's copy of this module. Counting here counts everything, and nothing in a plugin has to change.
|
|
59
|
+
//
|
|
60
|
+
// What this file does NOT do is store anything: the counters need SQL, and dragging that into common-ai
|
|
61
|
+
// would put a database client inside the contract every extension imports. The core implements
|
|
62
|
+
// IUsageService and registers it; without one, nothing is counted and nothing is cut.
|
|
63
|
+
// ─────────────────────────────────────────────────────────────────────────────────────────────────────
|
|
64
|
+
/* Which of the two axes a limit belongs to. */
|
|
65
|
+
var EUsageScope;
|
|
66
|
+
(function (EUsageScope) {
|
|
67
|
+
EUsageScope["LLM_KEY"] = "llmkey";
|
|
68
|
+
EUsageScope["CHANNEL"] = "channel";
|
|
69
|
+
})(EUsageScope || (exports.EUsageScope = EUsageScope = {}));
|
|
70
|
+
/*
|
|
71
|
+
Thrown instead of calling the model. A subclass and not a plain Error because a channel has to be able
|
|
72
|
+
to tell 'you have no quota left' from 'the model answered badly', and a string message cannot be
|
|
73
|
+
inspected without parsing it.
|
|
74
|
+
*/
|
|
75
|
+
class UsageLimitError extends Error {
|
|
76
|
+
constructor(detail) {
|
|
77
|
+
super(`AI usage limit reached: ${detail.unit} ${detail.period} on ${detail.scope} (${detail.current} of ${detail.limit})`);
|
|
78
|
+
this.name = 'UsageLimitError';
|
|
79
|
+
this.detail = detail;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
exports.UsageLimitError = UsageLimitError;
|
|
83
|
+
let usageService;
|
|
84
|
+
/* The core calls this at startup. Without it everything below is a no-op and the LLM is reached as ever. */
|
|
85
|
+
const setUsageService = (service) => { usageService = service; };
|
|
86
|
+
exports.setUsageService = setUsageService;
|
|
87
|
+
const getUsageService = () => usageService;
|
|
88
|
+
exports.getUsageService = getUsageService;
|
|
89
|
+
const modelOrigin = new WeakMap();
|
|
90
|
+
/*
|
|
91
|
+
The subject of the llmkey axis is a HASH of the effective key, never the key. Two LLM entries on the
|
|
92
|
+
same key land on the same subject and share one budget, which is what the provider does when it bills
|
|
93
|
+
it. And the counters table ends up holding no secret.
|
|
94
|
+
*/
|
|
95
|
+
const keyFingerprint = (key) => (0, crypto_1.createHash)('sha256').update(key).digest('hex').slice(0, 32);
|
|
96
|
+
/*
|
|
97
|
+
Records what a model was built from, so generateText can count against it. Called by buildModel; a
|
|
98
|
+
model built any other way simply has no origin and is not counted — never silently miscounted.
|
|
99
|
+
*/
|
|
100
|
+
const rememberOrigin = (model, llm, prov, key) => {
|
|
101
|
+
var _a, _b;
|
|
102
|
+
if (model && typeof model === 'object') {
|
|
103
|
+
modelOrigin.set(model, {
|
|
104
|
+
subject: keyFingerprint(key),
|
|
105
|
+
limits: llm.useProviderKey ? prov === null || prov === void 0 ? void 0 : prov.limits : llm.limits,
|
|
106
|
+
inputCostPerMillion: (_a = llm.inputCostPerMillion) !== null && _a !== void 0 ? _a : 0,
|
|
107
|
+
outputCostPerMillion: (_b = llm.outputCostPerMillion) !== null && _b !== void 0 ? _b : 0
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
return model;
|
|
111
|
+
};
|
|
112
|
+
/* The four units, paired with where each one is read from in a counted total. */
|
|
113
|
+
const UNITS = [
|
|
114
|
+
{ unit: index_1.EUsageUnit.TOKENS_IN, of: a => a.tokensIn },
|
|
115
|
+
{ unit: index_1.EUsageUnit.TOKENS_OUT, of: a => a.tokensOut },
|
|
116
|
+
{ unit: index_1.EUsageUnit.CALLS, of: a => a.calls },
|
|
117
|
+
{ unit: index_1.EUsageUnit.COST, of: a => a.cost }
|
|
118
|
+
];
|
|
119
|
+
const windowsOf = (limits, unit) => limits === null || limits === void 0 ? void 0 : limits[unit];
|
|
120
|
+
/*
|
|
121
|
+
The ONE rule: the call goes out only if NO active ceiling is exceeded. Whichever is passed first —
|
|
122
|
+
whatever axis, whatever unit, whatever window — cuts, and what is returned says which, so the error
|
|
123
|
+
can name it instead of talking about 'a limit'.
|
|
124
|
+
|
|
125
|
+
'Exceeded' is >=, not >: a ceiling of 100 calls means the hundred-and-first does not happen, so the
|
|
126
|
+
check at 100 already has to cut.
|
|
127
|
+
*/
|
|
128
|
+
const findExceeded = (scope, limits, daily, monthly) => {
|
|
129
|
+
if (!limits)
|
|
130
|
+
return undefined;
|
|
131
|
+
for (const { unit, of } of UNITS) {
|
|
132
|
+
const w = windowsOf(limits, unit);
|
|
133
|
+
if (!(w === null || w === void 0 ? void 0 : w.enabled))
|
|
134
|
+
continue;
|
|
135
|
+
if (w.daily !== undefined && of(daily) >= w.daily)
|
|
136
|
+
return { scope, unit, period: index_1.EUsagePeriod.DAY, limit: w.daily, current: of(daily) };
|
|
137
|
+
if (w.monthly !== undefined && of(monthly) >= w.monthly)
|
|
138
|
+
return { scope, unit, period: index_1.EUsagePeriod.MONTH, limit: w.monthly, current: of(monthly) };
|
|
139
|
+
}
|
|
140
|
+
return undefined;
|
|
141
|
+
};
|
|
142
|
+
/* What a response cost, in money, with the price of the LLM that was actually used. */
|
|
143
|
+
const costOf = (origin, tokensIn, tokensOut) => (tokensIn / 1000000) * origin.inputCostPerMillion + (tokensOut / 1000000) * origin.outputCostPerMillion;
|
|
144
|
+
/*
|
|
145
|
+
The LLM call every channel in Kwirth makes, with the counters around it.
|
|
146
|
+
|
|
147
|
+
🔴 The order is not arbitrary. The ceilings are checked BEFORE calling, with what has been spent so
|
|
148
|
+
far; the usage is added AFTER, because the SDK reports it with the answer and not before. So a limit
|
|
149
|
+
on CALLS stops the call that would exceed it, and a limit on TOKENS or COST stops the NEXT one: the
|
|
150
|
+
one that crosses the line has already been paid for. That is the protocol, not a shortcut, and the UI
|
|
151
|
+
says so where the limit is set.
|
|
152
|
+
|
|
153
|
+
A model nobody built with buildModel has no origin, so it is not counted. Not counting is a visible
|
|
154
|
+
gap; counting it against someone else's budget would be a lie.
|
|
155
|
+
|
|
156
|
+
It takes the call as a parameter rather than making it, which is what lets the accounting half be
|
|
157
|
+
exercised without reaching a real provider — a harness that calls api.openai.com is slow, fails
|
|
158
|
+
offline, and sends something outward on every run. The same seam is what a wrapper around another SDK
|
|
159
|
+
entry point (streamText) would use.
|
|
160
|
+
*/
|
|
161
|
+
const runWithUsageGuard = async (options, call) => {
|
|
162
|
+
var _a, _b, _c, _d, _e;
|
|
163
|
+
const service = usageService;
|
|
164
|
+
const origin = options.model && typeof options.model === 'object' ? modelOrigin.get(options.model) : undefined;
|
|
165
|
+
if (!service || !origin)
|
|
166
|
+
return await call();
|
|
167
|
+
const { daily, monthly } = await service.read(EUsageScope.LLM_KEY, origin.subject);
|
|
168
|
+
const exceeded = findExceeded(EUsageScope.LLM_KEY, origin.limits, daily, monthly);
|
|
169
|
+
if (exceeded) {
|
|
170
|
+
(_a = service.onCut) === null || _a === void 0 ? void 0 : _a.call(service, exceeded);
|
|
171
|
+
throw new UsageLimitError(exceeded);
|
|
172
|
+
}
|
|
173
|
+
const result = await call();
|
|
174
|
+
const tokensIn = (_c = (_b = result.usage) === null || _b === void 0 ? void 0 : _b.inputTokens) !== null && _c !== void 0 ? _c : 0;
|
|
175
|
+
const tokensOut = (_e = (_d = result.usage) === null || _d === void 0 ? void 0 : _d.outputTokens) !== null && _e !== void 0 ? _e : 0;
|
|
176
|
+
await service.add(EUsageScope.LLM_KEY, origin.subject, {
|
|
177
|
+
tokensIn,
|
|
178
|
+
tokensOut,
|
|
179
|
+
calls: 1,
|
|
180
|
+
cost: costOf(origin, tokensIn, tokensOut)
|
|
181
|
+
});
|
|
182
|
+
return result;
|
|
183
|
+
};
|
|
184
|
+
exports.runWithUsageGuard = runWithUsageGuard;
|
|
45
185
|
// Generic MULTIMODAL call: sends an image plus a prompt to an LLM and returns STRUCTURED output validated by
|
|
46
186
|
// a Zod schema (the Output.object pattern). Reusable across the whole platform (Iter uses it to extract a map
|
|
47
187
|
// from a diagram). It never throws: errors come back in `error`.
|
|
@@ -57,7 +197,7 @@ const generateVision = async (opts) => {
|
|
|
57
197
|
mediaType: opts.mediaType, imageBytes: ((_l = opts.image) !== null && _l !== void 0 ? _l : '').length,
|
|
58
198
|
systemLen: ((_m = opts.system) !== null && _m !== void 0 ? _m : '').length, providerOptions: opts.providerOptions,
|
|
59
199
|
});
|
|
60
|
-
const { output, text, usage } = await (0,
|
|
200
|
+
const { output, text, usage } = await (0, exports.generateText)(Object.assign({ model: opts.model, temperature: (_o = opts.temperature) !== null && _o !== void 0 ? _o : 0, system: opts.system, messages: [{
|
|
61
201
|
role: 'user',
|
|
62
202
|
content: [{ type: 'text', text: opts.prompt }, imagePart],
|
|
63
203
|
}], output: ai_1.Output.object({ schema: opts.schema }) }, (opts.providerOptions ? { providerOptions: opts.providerOptions } : {})));
|
|
@@ -223,8 +363,16 @@ const inferZod = (value) => {
|
|
|
223
363
|
// Re-export AI SDK symbols so plugins can use them without bundling the SDK
|
|
224
364
|
// The TYPES needed by anyone writing a helper around generateText are re-exported too: without
|
|
225
365
|
// LanguageModel and ToolSet a plugin cannot type its own functions and ends up with 'any'.
|
|
366
|
+
/*
|
|
367
|
+
🔴 generateText is NOT re-exported from the SDK any more: what leaves here is the wrapped one, which
|
|
368
|
+
is what makes every LLM call in Kwirth countable. Re-exporting the raw one again would open the hole
|
|
369
|
+
this whole feature exists to close, and nothing would fail to compile to warn you.
|
|
370
|
+
|
|
371
|
+
The cast is to the SDK's own type because the wrapper has exactly that signature: the alternative is
|
|
372
|
+
restating generateText's generics here and keeping them in step with the SDK by hand.
|
|
373
|
+
*/
|
|
374
|
+
exports.generateText = ((options) => (0, exports.runWithUsageGuard)(options, () => (0, ai_1.generateText)(options)));
|
|
226
375
|
var ai_2 = require("ai");
|
|
227
|
-
Object.defineProperty(exports, "generateText", { enumerable: true, get: function () { return ai_2.generateText; } });
|
|
228
376
|
Object.defineProperty(exports, "Output", { enumerable: true, get: function () { return ai_2.Output; } });
|
|
229
377
|
Object.defineProperty(exports, "stepCountIs", { enumerable: true, get: function () { return ai_2.stepCountIs; } });
|
|
230
378
|
Object.defineProperty(exports, "tool", { enumerable: true, get: function () { return ai_2.tool; } });
|
package/dist/index.d.ts
CHANGED
|
@@ -7,12 +7,34 @@ export interface ILlmModel {
|
|
|
7
7
|
description: string;
|
|
8
8
|
type: 'text' | 'image' | 'video' | 'other';
|
|
9
9
|
}
|
|
10
|
+
export declare enum EUsageUnit {
|
|
11
|
+
TOKENS_IN = "tokensIn",
|
|
12
|
+
TOKENS_OUT = "tokensOut",
|
|
13
|
+
CALLS = "calls",
|
|
14
|
+
COST = "cost"
|
|
15
|
+
}
|
|
16
|
+
export declare enum EUsagePeriod {
|
|
17
|
+
DAY = "day",
|
|
18
|
+
MONTH = "month"
|
|
19
|
+
}
|
|
20
|
+
export interface IUsageWindows {
|
|
21
|
+
enabled: boolean;
|
|
22
|
+
daily?: number;
|
|
23
|
+
monthly?: number;
|
|
24
|
+
}
|
|
25
|
+
export interface IUsageLimits {
|
|
26
|
+
tokensIn?: IUsageWindows;
|
|
27
|
+
tokensOut?: IUsageWindows;
|
|
28
|
+
calls?: IUsageWindows;
|
|
29
|
+
cost?: IUsageWindows;
|
|
30
|
+
}
|
|
10
31
|
export interface ILlmProvider {
|
|
11
32
|
name: string;
|
|
12
33
|
type: string;
|
|
13
34
|
key: string;
|
|
14
35
|
models: ILlmModel[];
|
|
15
36
|
endpoint?: string;
|
|
37
|
+
limits?: IUsageLimits;
|
|
16
38
|
}
|
|
17
39
|
export interface ILlm {
|
|
18
40
|
id: string;
|
|
@@ -23,6 +45,7 @@ export interface ILlm {
|
|
|
23
45
|
key: string;
|
|
24
46
|
inputCostPerMillion?: number;
|
|
25
47
|
outputCostPerMillion?: number;
|
|
48
|
+
limits?: IUsageLimits;
|
|
26
49
|
data?: unknown;
|
|
27
50
|
}
|
|
28
51
|
export declare const STORAGE_KEY_AGENTS = "kwirth-ai-agents";
|
package/dist/index.js
CHANGED
|
@@ -1,9 +1,24 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.parseToolRef = exports.toolRef = exports.TOOL_REF_SEPARATOR = exports.ECapability = exports.EToolSensitivity = exports.EToolEffect = exports.STORAGE_KEY_AGENTS = exports.PROVIDERS_AVAILABLE = exports.STORAGE_KEY_LLMS = exports.STORAGE_KEY_PROVIDERS = void 0;
|
|
3
|
+
exports.parseToolRef = exports.toolRef = exports.TOOL_REF_SEPARATOR = exports.ECapability = exports.EToolSensitivity = exports.EToolEffect = exports.STORAGE_KEY_AGENTS = exports.EUsagePeriod = exports.EUsageUnit = exports.PROVIDERS_AVAILABLE = exports.STORAGE_KEY_LLMS = exports.STORAGE_KEY_PROVIDERS = void 0;
|
|
4
4
|
exports.STORAGE_KEY_PROVIDERS = 'kwirth-ai-providers';
|
|
5
5
|
exports.STORAGE_KEY_LLMS = 'kwirth-ai-llms';
|
|
6
6
|
exports.PROVIDERS_AVAILABLE = ['google', 'openai', 'openrouter', 'mistral', 'groq', 'deepseek', 'anthropic', 'openai-compat'];
|
|
7
|
+
/* What a usage limit is counted in. */
|
|
8
|
+
var EUsageUnit;
|
|
9
|
+
(function (EUsageUnit) {
|
|
10
|
+
EUsageUnit["TOKENS_IN"] = "tokensIn";
|
|
11
|
+
EUsageUnit["TOKENS_OUT"] = "tokensOut";
|
|
12
|
+
EUsageUnit["CALLS"] = "calls";
|
|
13
|
+
/* Money, from the per-million prices the admin already sets on each LLM. */
|
|
14
|
+
EUsageUnit["COST"] = "cost";
|
|
15
|
+
})(EUsageUnit || (exports.EUsageUnit = EUsageUnit = {}));
|
|
16
|
+
/* The window a limit is measured over. Both can be set at once, each with its own ceiling. */
|
|
17
|
+
var EUsagePeriod;
|
|
18
|
+
(function (EUsagePeriod) {
|
|
19
|
+
EUsagePeriod["DAY"] = "day";
|
|
20
|
+
EUsagePeriod["MONTH"] = "month";
|
|
21
|
+
})(EUsagePeriod || (exports.EUsagePeriod = EUsagePeriod = {}));
|
|
7
22
|
exports.STORAGE_KEY_AGENTS = 'kwirth-ai-agents';
|
|
8
23
|
// ─────────────────────────────────────────────────────────────────────────────────────────────────────
|
|
9
24
|
// AI toolset contract (plan: plans/ai-tools/PLAN.md, S1)
|
package/package.json
CHANGED
|
@@ -1,79 +1,79 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@kwirthmagnify/kwirth-common-ai",
|
|
3
|
-
"version": "0.5.
|
|
4
|
-
"description": "Shared AI/LLM types and utilities for Kwirth AI plugins",
|
|
5
|
-
"scripts": {
|
|
6
|
-
"build": "del .\\dist\\* /s /q 2>nul & tsc",
|
|
7
|
-
"test": "node --test tests/*.test.mjs"
|
|
8
|
-
},
|
|
9
|
-
"publishConfig": {
|
|
10
|
-
"access": "public"
|
|
11
|
-
},
|
|
12
|
-
"main": "dist/index.js",
|
|
13
|
-
"module": "dist/index.js",
|
|
14
|
-
"types": "dist/index.d.ts",
|
|
15
|
-
"exports": {
|
|
16
|
-
".": {
|
|
17
|
-
"types": "./dist/index.d.ts",
|
|
18
|
-
"require": "./dist/index.js",
|
|
19
|
-
"default": "./dist/index.js"
|
|
20
|
-
},
|
|
21
|
-
"./back": {
|
|
22
|
-
"types": "./dist/back.d.ts",
|
|
23
|
-
"require": "./dist/back.js",
|
|
24
|
-
"default": "./dist/back.js"
|
|
25
|
-
},
|
|
26
|
-
"./front": {
|
|
27
|
-
"types": "./dist/front.d.ts",
|
|
28
|
-
"require": "./dist/front.js",
|
|
29
|
-
"default": "./dist/front.js"
|
|
30
|
-
}
|
|
31
|
-
},
|
|
32
|
-
"typesVersions": {
|
|
33
|
-
"*": {
|
|
34
|
-
"back": [
|
|
35
|
-
"dist/back.d.ts"
|
|
36
|
-
],
|
|
37
|
-
"front": [
|
|
38
|
-
"dist/front.d.ts"
|
|
39
|
-
]
|
|
40
|
-
}
|
|
41
|
-
},
|
|
42
|
-
"files": [
|
|
43
|
-
"dist"
|
|
44
|
-
],
|
|
45
|
-
"author": "Julio Fernandez",
|
|
46
|
-
"license": "ISC",
|
|
47
|
-
"dependencies": {
|
|
48
|
-
"@ai-sdk/anthropic": "^3.0.116",
|
|
49
|
-
"@ai-sdk/deepseek": "^2.0.29",
|
|
50
|
-
"@ai-sdk/google": "^3.0.64",
|
|
51
|
-
"@ai-sdk/groq": "^3.0.35",
|
|
52
|
-
"@ai-sdk/mistral": "^3.0.30",
|
|
53
|
-
"@ai-sdk/openai": "^3.0.53",
|
|
54
|
-
"@openrouter/ai-sdk-provider": "^2.8.0",
|
|
55
|
-
"ai": "^6.0.174",
|
|
56
|
-
"zod": "^4.3.6"
|
|
57
|
-
},
|
|
58
|
-
"peerDependencies": {
|
|
59
|
-
"react": ">=18.0.0",
|
|
60
|
-
"@kubernetes/client-node": ">=1.0.0"
|
|
61
|
-
},
|
|
62
|
-
"devDependencies": {
|
|
63
|
-
"@kwirthmagnify/kwirth-common": "^0.5.42",
|
|
64
|
-
"@mui/icons-material": "7.1.2",
|
|
65
|
-
"@mui/material": "7.1.2",
|
|
66
|
-
"@types/node": "^25.9.1",
|
|
67
|
-
"@types/react": "^18.3.0",
|
|
68
|
-
"typescript": "^5.4.0",
|
|
69
|
-
"@kubernetes/client-node": "^1.4.0"
|
|
70
|
-
},
|
|
71
|
-
"peerDependenciesMeta": {
|
|
72
|
-
"@kubernetes/client-node": {
|
|
73
|
-
"optional": true
|
|
74
|
-
},
|
|
75
|
-
"react": {
|
|
76
|
-
"optional": true
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@kwirthmagnify/kwirth-common-ai",
|
|
3
|
+
"version": "0.5.65",
|
|
4
|
+
"description": "Shared AI/LLM types and utilities for Kwirth AI plugins",
|
|
5
|
+
"scripts": {
|
|
6
|
+
"build": "del .\\dist\\* /s /q 2>nul & tsc",
|
|
7
|
+
"test": "node --test tests/*.test.mjs"
|
|
8
|
+
},
|
|
9
|
+
"publishConfig": {
|
|
10
|
+
"access": "public"
|
|
11
|
+
},
|
|
12
|
+
"main": "dist/index.js",
|
|
13
|
+
"module": "dist/index.js",
|
|
14
|
+
"types": "dist/index.d.ts",
|
|
15
|
+
"exports": {
|
|
16
|
+
".": {
|
|
17
|
+
"types": "./dist/index.d.ts",
|
|
18
|
+
"require": "./dist/index.js",
|
|
19
|
+
"default": "./dist/index.js"
|
|
20
|
+
},
|
|
21
|
+
"./back": {
|
|
22
|
+
"types": "./dist/back.d.ts",
|
|
23
|
+
"require": "./dist/back.js",
|
|
24
|
+
"default": "./dist/back.js"
|
|
25
|
+
},
|
|
26
|
+
"./front": {
|
|
27
|
+
"types": "./dist/front.d.ts",
|
|
28
|
+
"require": "./dist/front.js",
|
|
29
|
+
"default": "./dist/front.js"
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
"typesVersions": {
|
|
33
|
+
"*": {
|
|
34
|
+
"back": [
|
|
35
|
+
"dist/back.d.ts"
|
|
36
|
+
],
|
|
37
|
+
"front": [
|
|
38
|
+
"dist/front.d.ts"
|
|
39
|
+
]
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
"files": [
|
|
43
|
+
"dist"
|
|
44
|
+
],
|
|
45
|
+
"author": "Julio Fernandez",
|
|
46
|
+
"license": "ISC",
|
|
47
|
+
"dependencies": {
|
|
48
|
+
"@ai-sdk/anthropic": "^3.0.116",
|
|
49
|
+
"@ai-sdk/deepseek": "^2.0.29",
|
|
50
|
+
"@ai-sdk/google": "^3.0.64",
|
|
51
|
+
"@ai-sdk/groq": "^3.0.35",
|
|
52
|
+
"@ai-sdk/mistral": "^3.0.30",
|
|
53
|
+
"@ai-sdk/openai": "^3.0.53",
|
|
54
|
+
"@openrouter/ai-sdk-provider": "^2.8.0",
|
|
55
|
+
"ai": "^6.0.174",
|
|
56
|
+
"zod": "^4.3.6"
|
|
57
|
+
},
|
|
58
|
+
"peerDependencies": {
|
|
59
|
+
"react": ">=18.0.0",
|
|
60
|
+
"@kubernetes/client-node": ">=1.0.0"
|
|
61
|
+
},
|
|
62
|
+
"devDependencies": {
|
|
63
|
+
"@kwirthmagnify/kwirth-common": "^0.5.42",
|
|
64
|
+
"@mui/icons-material": "7.1.2",
|
|
65
|
+
"@mui/material": "7.1.2",
|
|
66
|
+
"@types/node": "^25.9.1",
|
|
67
|
+
"@types/react": "^18.3.0",
|
|
68
|
+
"typescript": "^5.4.0",
|
|
69
|
+
"@kubernetes/client-node": "^1.4.0"
|
|
70
|
+
},
|
|
71
|
+
"peerDependenciesMeta": {
|
|
72
|
+
"@kubernetes/client-node": {
|
|
73
|
+
"optional": true
|
|
74
|
+
},
|
|
75
|
+
"react": {
|
|
76
|
+
"optional": true
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|