@absolutejs/ai 0.3.2 → 0.3.3
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/CHANGELOG.md +6 -0
- package/README.md +19 -0
- package/changelog.json +20 -0
- package/dist/ai/client/index.js +1 -3
- package/dist/ai/client/index.js.map +2 -2
- package/dist/ai/index.js +7807 -7748
- package/dist/ai/index.js.map +20 -20
- package/dist/ai/models/index.js +1 -71
- package/dist/ai/models/index.js.map +2 -2
- package/dist/ai/providers/anthropic.js +25 -27
- package/dist/ai/providers/anthropic.js.map +2 -2
- package/dist/ai/providers/gemini.js +11 -13
- package/dist/ai/providers/gemini.js.map +2 -2
- package/dist/ai/providers/ollama.js +3 -5
- package/dist/ai/providers/ollama.js.map +2 -2
- package/dist/ai/providers/openai.js +38 -40
- package/dist/ai/providers/openai.js.map +2 -2
- package/dist/ai/providers/openaiCompatible.js +56 -58
- package/dist/ai/providers/openaiCompatible.js.map +2 -2
- package/dist/ai/providers/openaiResponses.js +18 -20
- package/dist/ai/providers/openaiResponses.js.map +2 -2
- package/dist/ai/providers/openrouter.js +122 -124
- package/dist/ai/providers/openrouter.js.map +2 -2
- package/dist/ai/providers/openrouterSDK.js +1 -3
- package/dist/ai/providers/openrouterSDK.js.map +2 -2
- package/dist/ai/research.js +2 -4
- package/dist/ai/research.js.map +2 -2
- package/dist/ai/tools/index.js +55 -58
- package/dist/ai/tools/index.js.map +5 -5
- package/dist/ai/tools/untrusted.js +1 -3
- package/dist/ai/tools/untrusted.js.map +2 -2
- package/dist/ai/ui/index.js +83 -87
- package/dist/ai/ui/index.js.map +4 -4
- package/dist/angular/ai/index.js +9 -7
- package/dist/angular/ai/index.js.map +2 -2
- package/dist/react/ai/index.js +4 -74
- package/dist/react/ai/index.js.map +2 -2
- package/dist/src/ai/ui/catalog.d.ts +3 -0
- package/dist/src/ai/ui/index.d.ts +2 -2
- package/dist/src/ai/ui/uiCards.d.ts +9 -3
- package/dist/svelte/ai/index.js +1 -71
- package/dist/svelte/ai/index.js.map +2 -2
- package/dist/vue/ai/index.js +1 -71
- package/dist/vue/ai/index.js.map +2 -2
- package/package.json +1 -1
package/dist/ai/ui/index.js
CHANGED
|
@@ -1,81 +1,24 @@
|
|
|
1
|
-
var __create = Object.create;
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __name = (target, name) => {
|
|
5
|
-
Object.defineProperty(target, "name", {
|
|
6
|
-
value: name,
|
|
7
|
-
enumerable: false,
|
|
8
|
-
configurable: true
|
|
9
|
-
});
|
|
10
|
-
return target;
|
|
11
|
-
};
|
|
12
|
-
var __knownSymbol = (name, symbol) => (symbol = Symbol[name]) ? symbol : Symbol.for("Symbol." + name);
|
|
13
|
-
var __typeError = (msg) => {
|
|
14
|
-
throw TypeError(msg);
|
|
15
|
-
};
|
|
16
|
-
var __defNormalProp = (obj, key, value) => (key in obj) ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
17
|
-
var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
|
|
18
|
-
var __privateIn = (member, obj) => Object(obj) !== obj ? __typeError('Cannot use the "in" operator on this value') : member.has(obj);
|
|
19
|
-
var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
20
|
-
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
|
|
21
|
-
var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
|
|
22
|
-
var __decoratorStart = (base) => [, , , __create(base?.[__knownSymbol("metadata")] ?? null)];
|
|
23
|
-
var __decoratorStrings = ["class", "method", "getter", "setter", "accessor", "field", "value", "get", "set"];
|
|
24
|
-
var __expectFn = (fn) => fn !== undefined && typeof fn !== "function" ? __typeError("Function expected") : fn;
|
|
25
|
-
var __decoratorContext = (kind, name, done, metadata, fns) => ({
|
|
26
|
-
kind: __decoratorStrings[kind],
|
|
27
|
-
name,
|
|
28
|
-
metadata,
|
|
29
|
-
addInitializer: (fn) => done._ ? __typeError("Already initialized") : fns.push(__expectFn(fn || null))
|
|
30
|
-
});
|
|
31
|
-
var __decoratorMetadata = (array, target) => __defNormalProp(target, __knownSymbol("metadata"), array[3]);
|
|
32
|
-
var __runInitializers = (array, flags, self, value) => {
|
|
33
|
-
for (var i = 0, fns = array[flags >> 1], n = fns && fns.length;i < n; i++)
|
|
34
|
-
flags & 1 ? fns[i].call(self) : value = fns[i].call(self, value);
|
|
35
|
-
return value;
|
|
36
|
-
};
|
|
37
|
-
var __decorateElement = (array, flags, name, decorators, target, extra) => {
|
|
38
|
-
var fn, it, done, ctx, access, k = flags & 7, s = !!(flags & 8), p = !!(flags & 16);
|
|
39
|
-
var j = k > 3 ? array.length + 1 : k ? s ? 1 : 2 : 0, key = __decoratorStrings[k + 5];
|
|
40
|
-
var initializers = k > 3 && (array[j - 1] = []), extraInitializers = array[j] || (array[j] = []);
|
|
41
|
-
var desc = k && (!p && !s && (target = target.prototype), k < 5 && (k > 3 || !p) && __getOwnPropDesc(k < 4 ? target : {
|
|
42
|
-
get [name]() {
|
|
43
|
-
return __privateGet(this, extra);
|
|
44
|
-
},
|
|
45
|
-
set [name](x) {
|
|
46
|
-
__privateSet(this, extra, x);
|
|
47
|
-
}
|
|
48
|
-
}, name));
|
|
49
|
-
k ? p && k < 4 && __name(extra, (k > 2 ? "set " : k > 1 ? "get " : "") + name) : __name(target, name);
|
|
50
|
-
for (var i = decorators.length - 1;i >= 0; i--) {
|
|
51
|
-
ctx = __decoratorContext(k, name, done = {}, array[3], extraInitializers);
|
|
52
|
-
if (k) {
|
|
53
|
-
ctx.static = s, ctx.private = p, access = ctx.access = { has: p ? (x) => __privateIn(target, x) : (x) => (name in x) };
|
|
54
|
-
if (k ^ 3)
|
|
55
|
-
access.get = p ? (x) => (k ^ 1 ? __privateGet : __privateMethod)(x, target, k ^ 4 ? extra : desc.get) : (x) => x[name];
|
|
56
|
-
if (k > 2)
|
|
57
|
-
access.set = p ? (x, y) => __privateSet(x, target, y, k ^ 4 ? extra : desc.set) : (x, y) => x[name] = y;
|
|
58
|
-
}
|
|
59
|
-
it = (0, decorators[i])(k ? k < 4 ? p ? extra : desc[key] : k > 4 ? undefined : { get: desc.get, set: desc.set } : target, ctx);
|
|
60
|
-
done._ = 1;
|
|
61
|
-
if (k ^ 4 || it === undefined)
|
|
62
|
-
__expectFn(it) && (k > 4 ? initializers.unshift(it) : k ? p ? extra = it : desc[key] = it : target = it);
|
|
63
|
-
else if (typeof it !== "object" || it === null)
|
|
64
|
-
__typeError("Object expected");
|
|
65
|
-
else
|
|
66
|
-
__expectFn(fn = it.get) && (desc.get = fn), __expectFn(fn = it.set) && (desc.set = fn), __expectFn(fn = it.init) && initializers.unshift(fn);
|
|
67
|
-
}
|
|
68
|
-
return k || __decoratorMetadata(array, target), desc && __defProp(target, name, desc), p ? k ^ 4 ? extra : desc : target;
|
|
69
|
-
};
|
|
70
|
-
|
|
71
1
|
// src/ai/ui/uiCards.ts
|
|
2
|
+
class UiCardValidationError extends Error {
|
|
3
|
+
card;
|
|
4
|
+
constructor(card) {
|
|
5
|
+
super(`UI card "${card}" was not rendered: input failed validation. Correct the input to match the tool schema and retry.`);
|
|
6
|
+
this.name = "UiCardValidationError";
|
|
7
|
+
this.card = card;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
72
10
|
var createUiCards = (definitions) => {
|
|
73
11
|
const byName = new Map(definitions.map((definition) => [definition.name, definition]));
|
|
74
12
|
const tools = Object.fromEntries(definitions.map((definition) => [
|
|
75
13
|
definition.name,
|
|
76
14
|
{
|
|
77
15
|
description: definition.description,
|
|
78
|
-
handler: () =>
|
|
16
|
+
handler: async (input) => {
|
|
17
|
+
if (definition.parse(input) === null) {
|
|
18
|
+
throw new UiCardValidationError(definition.name);
|
|
19
|
+
}
|
|
20
|
+
return definition.ack;
|
|
21
|
+
},
|
|
79
22
|
input: definition.inputSchema
|
|
80
23
|
}
|
|
81
24
|
]));
|
|
@@ -119,6 +62,9 @@ var UI_ACTIONS_MAX = 3;
|
|
|
119
62
|
var FORM_MAX_FIELDS = 8;
|
|
120
63
|
var FORM_SELECT_MAX_OPTIONS = 12;
|
|
121
64
|
var CHOICE_MAX_OPTIONS = 8;
|
|
65
|
+
var CHOICE_TITLE_MAX_CHARS = 600;
|
|
66
|
+
var CHOICE_LABEL_MAX_CHARS = 600;
|
|
67
|
+
var CHOICE_DESCRIPTION_MAX_CHARS = 2000;
|
|
122
68
|
var CONFIRM_CONSEQUENCE_MAX_CHARS = 500;
|
|
123
69
|
var DIFF_MAX_FILES = 6;
|
|
124
70
|
var DIFF_MAX_LINES = 400;
|
|
@@ -375,18 +321,29 @@ var parseFormSpec = (input) => {
|
|
|
375
321
|
applyCardId(spec, input.cardId);
|
|
376
322
|
return spec;
|
|
377
323
|
};
|
|
324
|
+
var completeString = (value, maxChars) => {
|
|
325
|
+
if (typeof value !== "string")
|
|
326
|
+
return null;
|
|
327
|
+
const text = value.trim();
|
|
328
|
+
return text.length > 0 && text.length <= maxChars ? text : null;
|
|
329
|
+
};
|
|
330
|
+
var optionalCompleteString = (value, maxChars) => value === undefined || typeof value === "string" && value.trim().length <= maxChars;
|
|
378
331
|
var parseChoiceOption = (raw) => {
|
|
379
332
|
if (!isRecord(raw))
|
|
380
333
|
return null;
|
|
381
|
-
const id =
|
|
382
|
-
const label =
|
|
334
|
+
const id = completeString(raw.id, CARD_ID_MAX_CHARS);
|
|
335
|
+
const label = completeString(raw.label, CHOICE_LABEL_MAX_CHARS);
|
|
383
336
|
if (!id || !label)
|
|
384
337
|
return null;
|
|
338
|
+
if (!CARD_ID_PATTERN.test(id))
|
|
339
|
+
return null;
|
|
340
|
+
if (!optionalCompleteString(raw.description, CHOICE_DESCRIPTION_MAX_CHARS) || !optionalCompleteString(raw.badge, BADGE_MAX_CHARS))
|
|
341
|
+
return null;
|
|
385
342
|
const option = { id, label };
|
|
386
|
-
const description =
|
|
343
|
+
const description = completeString(raw.description, CHOICE_DESCRIPTION_MAX_CHARS);
|
|
387
344
|
if (description)
|
|
388
345
|
option.description = description;
|
|
389
|
-
const badge =
|
|
346
|
+
const badge = completeString(raw.badge, BADGE_MAX_CHARS);
|
|
390
347
|
if (badge)
|
|
391
348
|
option.badge = badge;
|
|
392
349
|
return option;
|
|
@@ -394,15 +351,21 @@ var parseChoiceOption = (raw) => {
|
|
|
394
351
|
var parseChoiceSpec = (input) => {
|
|
395
352
|
if (!isRecord(input))
|
|
396
353
|
return null;
|
|
397
|
-
const title =
|
|
354
|
+
const title = completeString(input.title, CHOICE_TITLE_MAX_CHARS);
|
|
355
|
+
if (!optionalCompleteString(input.description, CHOICE_DESCRIPTION_MAX_CHARS))
|
|
356
|
+
return null;
|
|
357
|
+
if (input.cardId !== undefined && (typeof input.cardId !== "string" || !CARD_ID_PATTERN.test(input.cardId.trim())))
|
|
358
|
+
return null;
|
|
359
|
+
if (!isRecord(input.submit) || !completeString(input.submit.label, ACTION_LABEL_MAX_CHARS))
|
|
360
|
+
return null;
|
|
398
361
|
const [submit] = parseUiActions([input.submit]) ?? [];
|
|
399
362
|
if (!title || !submit)
|
|
400
363
|
return null;
|
|
401
|
-
if (!Array.isArray(input.options) || input.options.length === 0)
|
|
364
|
+
if (!Array.isArray(input.options) || input.options.length === 0 || input.options.length > CHOICE_MAX_OPTIONS)
|
|
402
365
|
return null;
|
|
403
366
|
const options = [];
|
|
404
367
|
const seen = new Set;
|
|
405
|
-
for (const raw of input.options
|
|
368
|
+
for (const raw of input.options) {
|
|
406
369
|
const option = parseChoiceOption(raw);
|
|
407
370
|
if (!option || seen.has(option.id))
|
|
408
371
|
return null;
|
|
@@ -410,7 +373,7 @@ var parseChoiceSpec = (input) => {
|
|
|
410
373
|
options.push(option);
|
|
411
374
|
}
|
|
412
375
|
const spec = { options, submit, title };
|
|
413
|
-
const description =
|
|
376
|
+
const description = completeString(input.description, CHOICE_DESCRIPTION_MAX_CHARS);
|
|
414
377
|
if (description)
|
|
415
378
|
spec.description = description;
|
|
416
379
|
if (input.multi === true)
|
|
@@ -724,12 +687,17 @@ var formCard = {
|
|
|
724
687
|
};
|
|
725
688
|
var choiceCard = {
|
|
726
689
|
ack: "(choice card rendered inline — the member picks an option, which runs the bound tool with their selection merged in. Do not re-ask in text; wait for the selection)",
|
|
727
|
-
description: "Render a structured choice card whenever the member must pick between concrete options (which plan, which duplicate record to keep, which time slot) — never ask them to 'reply 1 or 2' in prose. Give every option a stable id; on selection the host merges { choice: id } (or { choices: [ids] } when multi is true) into submit.input and invokes submit.tool exactly like a clicked action button, so put everything you already resolved into submit.input. Max 8 options.",
|
|
690
|
+
description: "Render a structured choice card whenever the member must pick between concrete options (which plan, which duplicate record to keep, which time slot) — never ask them to 'reply 1 or 2' in prose. Give every option a stable id; on selection the host merges { choice: id } (or { choices: [ids] } when multi is true) into submit.input and invokes submit.tool exactly like a clicked action button, so put everything you already resolved into submit.input. Max 8 options. Use complete, concise labels; put supporting detail in descriptions. Titles and labels allow 600 characters, descriptions 2000. Inputs over these limits are rejected, never truncated.",
|
|
728
691
|
inputSchema: {
|
|
729
692
|
properties: {
|
|
730
|
-
cardId:
|
|
693
|
+
cardId: {
|
|
694
|
+
...CARD_ID_SCHEMA,
|
|
695
|
+
maxLength: CARD_ID_MAX_CHARS,
|
|
696
|
+
pattern: CARD_ID_PATTERN.source
|
|
697
|
+
},
|
|
731
698
|
description: {
|
|
732
|
-
description: "Optional
|
|
699
|
+
description: "Optional helper text under the title",
|
|
700
|
+
maxLength: CHOICE_DESCRIPTION_MAX_CHARS,
|
|
733
701
|
type: "string"
|
|
734
702
|
},
|
|
735
703
|
multi: {
|
|
@@ -742,28 +710,52 @@ var choiceCard = {
|
|
|
742
710
|
properties: {
|
|
743
711
|
badge: {
|
|
744
712
|
description: 'Tiny annotation beside the label, e.g. "recommended"',
|
|
713
|
+
maxLength: BADGE_MAX_CHARS,
|
|
745
714
|
type: "string"
|
|
746
715
|
},
|
|
747
716
|
description: {
|
|
748
|
-
description: "
|
|
717
|
+
description: "Supporting explanation of the option",
|
|
718
|
+
maxLength: CHOICE_DESCRIPTION_MAX_CHARS,
|
|
749
719
|
type: "string"
|
|
750
720
|
},
|
|
751
721
|
id: {
|
|
752
722
|
description: "Stable option id merged into submit.input on selection (letters/digits/_/-)",
|
|
723
|
+
maxLength: CARD_ID_MAX_CHARS,
|
|
724
|
+
pattern: CARD_ID_PATTERN.source,
|
|
753
725
|
type: "string"
|
|
754
726
|
},
|
|
755
|
-
label: {
|
|
727
|
+
label: {
|
|
728
|
+
description: "The complete option, without cutting off words",
|
|
729
|
+
maxLength: CHOICE_LABEL_MAX_CHARS,
|
|
730
|
+
minLength: 1,
|
|
731
|
+
type: "string"
|
|
732
|
+
}
|
|
756
733
|
},
|
|
757
734
|
required: ["id", "label"],
|
|
758
735
|
type: "object"
|
|
759
736
|
},
|
|
737
|
+
maxItems: CHOICE_MAX_OPTIONS,
|
|
738
|
+
minItems: 1,
|
|
760
739
|
type: "array"
|
|
761
740
|
},
|
|
762
741
|
submit: {
|
|
763
742
|
...ACTION_BINDING_SCHEMA,
|
|
743
|
+
properties: {
|
|
744
|
+
...ACTION_BINDING_SCHEMA.properties,
|
|
745
|
+
label: {
|
|
746
|
+
...ACTION_BINDING_SCHEMA.properties.label,
|
|
747
|
+
maxLength: ACTION_LABEL_MAX_CHARS,
|
|
748
|
+
minLength: 1
|
|
749
|
+
}
|
|
750
|
+
},
|
|
764
751
|
description: "The submit binding: the tool to run once a choice is made. The selection is merged into input as { choice: id } (or { choices: [ids] })"
|
|
765
752
|
},
|
|
766
|
-
title: {
|
|
753
|
+
title: {
|
|
754
|
+
description: "The complete decision being made",
|
|
755
|
+
maxLength: CHOICE_TITLE_MAX_CHARS,
|
|
756
|
+
minLength: 1,
|
|
757
|
+
type: "string"
|
|
758
|
+
}
|
|
767
759
|
},
|
|
768
760
|
required: ["title", "options", "submit"],
|
|
769
761
|
type: "object"
|
|
@@ -999,7 +991,7 @@ var niceTicks = (min, max) => {
|
|
|
999
991
|
const span = max - min || 1;
|
|
1000
992
|
const rough = span / TICK_TARGET;
|
|
1001
993
|
const power = Math.pow(10, Math.floor(Math.log10(rough)));
|
|
1002
|
-
const candidates = [1, 2, 5, 10].map((
|
|
994
|
+
const candidates = [1, 2, 5, 10].map((step) => step * power);
|
|
1003
995
|
const step = candidates.find((candidate) => candidate >= rough) ?? candidates[candidates.length - 1] ?? rough;
|
|
1004
996
|
const start = Math.floor(min / step) * step;
|
|
1005
997
|
const ticks = [];
|
|
@@ -1168,7 +1160,10 @@ export {
|
|
|
1168
1160
|
CHART_MAX_POINTS,
|
|
1169
1161
|
CHART_MAX_SERIES,
|
|
1170
1162
|
CHART_TYPES,
|
|
1163
|
+
CHOICE_DESCRIPTION_MAX_CHARS,
|
|
1164
|
+
CHOICE_LABEL_MAX_CHARS,
|
|
1171
1165
|
CHOICE_MAX_OPTIONS,
|
|
1166
|
+
CHOICE_TITLE_MAX_CHARS,
|
|
1172
1167
|
CONFIRM_CONSEQUENCE_MAX_CHARS,
|
|
1173
1168
|
CREDENTIAL_MAX_KEYS,
|
|
1174
1169
|
DARK_UI_THEME,
|
|
@@ -1184,6 +1179,7 @@ export {
|
|
|
1184
1179
|
TABLE_MAX_COLUMNS,
|
|
1185
1180
|
TABLE_MAX_ROWS,
|
|
1186
1181
|
UI_ACTIONS_MAX,
|
|
1182
|
+
UiCardValidationError,
|
|
1187
1183
|
chartCard,
|
|
1188
1184
|
choiceCard,
|
|
1189
1185
|
confirmCard,
|
|
@@ -1207,5 +1203,5 @@ export {
|
|
|
1207
1203
|
tableCard
|
|
1208
1204
|
};
|
|
1209
1205
|
|
|
1210
|
-
//# debugId=
|
|
1206
|
+
//# debugId=5FA77A0F06ADA10F64756E2164756E21
|
|
1211
1207
|
//# sourceMappingURL=index.js.map
|