bruce-models 7.1.86 → 7.1.87
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/bruce-models.es5.js +224 -13
- package/dist/bruce-models.es5.js.map +1 -1
- package/dist/bruce-models.umd.js +222 -12
- package/dist/bruce-models.umd.js.map +1 -1
- package/dist/lib/bruce-models.js +2 -1
- package/dist/lib/bruce-models.js.map +1 -1
- package/dist/lib/plugin/ai-tool-validation.js +131 -0
- package/dist/lib/plugin/ai-tool-validation.js.map +1 -0
- package/dist/lib/plugin/plugin.js +94 -11
- package/dist/lib/plugin/plugin.js.map +1 -1
- package/dist/types/bruce-models.d.ts +2 -1
- package/dist/types/plugin/ai-tool-validation.d.ts +19 -0
- package/dist/types/plugin/plugin.d.ts +23 -0
- package/package.json +1 -1
package/dist/bruce-models.umd.js
CHANGED
|
@@ -16214,27 +16214,19 @@
|
|
|
16214
16214
|
}
|
|
16215
16215
|
Plugin.Upload = Upload;
|
|
16216
16216
|
/**
|
|
16217
|
-
*
|
|
16218
|
-
* The run function will return a dispose function to call to remove the plugin.
|
|
16217
|
+
* Resolves a plugin record and returns its unwrapped source.
|
|
16219
16218
|
* @param params
|
|
16220
16219
|
* @returns
|
|
16221
16220
|
*/
|
|
16222
|
-
function
|
|
16221
|
+
function LoadPluginSource(params) {
|
|
16223
16222
|
return __awaiter(this, void 0, void 0, function* () {
|
|
16224
|
-
let {
|
|
16223
|
+
let { api, pluginId, plugin, req } = params;
|
|
16225
16224
|
if (!api) {
|
|
16226
16225
|
api = exports.ENVIRONMENT.Api().GetBruceApi({
|
|
16227
16226
|
loadConfig: true
|
|
16228
16227
|
});
|
|
16229
16228
|
}
|
|
16230
16229
|
yield api.Loading;
|
|
16231
|
-
if (!containerId && container) {
|
|
16232
|
-
containerId = container.id;
|
|
16233
|
-
if (!containerId) {
|
|
16234
|
-
containerId = exports.ObjectUtils.UId();
|
|
16235
|
-
container.id = containerId;
|
|
16236
|
-
}
|
|
16237
|
-
}
|
|
16238
16230
|
if (!plugin && pluginId) {
|
|
16239
16231
|
plugin = (yield Plugin.Get({
|
|
16240
16232
|
pluginId,
|
|
@@ -16276,6 +16268,39 @@
|
|
|
16276
16268
|
const start = fileContent.indexOf("{");
|
|
16277
16269
|
const end = fileContent.lastIndexOf("}");
|
|
16278
16270
|
fileContent = fileContent.substring(start + 1, end);
|
|
16271
|
+
return {
|
|
16272
|
+
api,
|
|
16273
|
+
pluginId,
|
|
16274
|
+
plugin,
|
|
16275
|
+
fileContent
|
|
16276
|
+
};
|
|
16277
|
+
});
|
|
16278
|
+
}
|
|
16279
|
+
/**
|
|
16280
|
+
* Returns a run function to call that'll load a plugin within your provided container element.
|
|
16281
|
+
* The run function will return a dispose function to call to remove the plugin.
|
|
16282
|
+
* @param params
|
|
16283
|
+
* @returns
|
|
16284
|
+
*/
|
|
16285
|
+
function GetRunFunction(params) {
|
|
16286
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
16287
|
+
let { containerId, container, pluginParams, pluginId, plugin, api, req } = params;
|
|
16288
|
+
if (!containerId && container) {
|
|
16289
|
+
containerId = container.id;
|
|
16290
|
+
if (!containerId) {
|
|
16291
|
+
containerId = exports.ObjectUtils.UId();
|
|
16292
|
+
container.id = containerId;
|
|
16293
|
+
}
|
|
16294
|
+
}
|
|
16295
|
+
const loaded = yield LoadPluginSource({
|
|
16296
|
+
api,
|
|
16297
|
+
pluginId,
|
|
16298
|
+
plugin,
|
|
16299
|
+
req
|
|
16300
|
+
});
|
|
16301
|
+
pluginId = loaded.pluginId;
|
|
16302
|
+
plugin = loaded.plugin;
|
|
16303
|
+
const fileContent = loaded.fileContent;
|
|
16279
16304
|
const paramsId = exports.ObjectUtils.UId();
|
|
16280
16305
|
window[paramsId] = pluginParams ? pluginParams : {};
|
|
16281
16306
|
window["PLUGIN_" + pluginId] = plugin;
|
|
@@ -16350,6 +16375,64 @@
|
|
|
16350
16375
|
});
|
|
16351
16376
|
}
|
|
16352
16377
|
Plugin.GetRunFunction = GetRunFunction;
|
|
16378
|
+
/**
|
|
16379
|
+
* Returns an invoke function that calls an AI_TOOL plugin headlessly.
|
|
16380
|
+
* @param params
|
|
16381
|
+
* @returns
|
|
16382
|
+
*/
|
|
16383
|
+
function GetInvokeFunction(params) {
|
|
16384
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
16385
|
+
const { api, pluginId, plugin, req } = params;
|
|
16386
|
+
const loaded = yield LoadPluginSource({
|
|
16387
|
+
api,
|
|
16388
|
+
pluginId,
|
|
16389
|
+
plugin,
|
|
16390
|
+
req
|
|
16391
|
+
});
|
|
16392
|
+
return {
|
|
16393
|
+
invoke: (args, context) => {
|
|
16394
|
+
const callId = exports.ObjectUtils.UId();
|
|
16395
|
+
const argsId = "PLUGIN_ARGS_" + callId;
|
|
16396
|
+
const contextId = "PLUGIN_CONTEXT_" + callId;
|
|
16397
|
+
const resultId = "PLUGIN_RESULT_" + callId;
|
|
16398
|
+
window[argsId] = args ? args : {};
|
|
16399
|
+
window[contextId] = Object.assign({ config: loaded.plugin.Settings ? loaded.plugin.Settings.config : undefined, plugin: loaded.plugin }, (context ? context : {}));
|
|
16400
|
+
const script = `
|
|
16401
|
+
function invoke() {
|
|
16402
|
+
"use strict";
|
|
16403
|
+
var Invoke;
|
|
16404
|
+
|
|
16405
|
+
${loaded.fileContent}
|
|
16406
|
+
|
|
16407
|
+
if (typeof Invoke !== "function") {
|
|
16408
|
+
throw new Error("Plugin " + ${JSON.stringify(loaded.pluginId)}
|
|
16409
|
+
+ " does not declare an Invoke function.");
|
|
16410
|
+
}
|
|
16411
|
+
|
|
16412
|
+
window["${resultId}"] = Invoke(window["${argsId}"], window["${contextId}"]);
|
|
16413
|
+
}
|
|
16414
|
+
invoke();
|
|
16415
|
+
`;
|
|
16416
|
+
try {
|
|
16417
|
+
// 'eval2 = eval' stops the linter from complaining about using eval.
|
|
16418
|
+
const eval2 = eval;
|
|
16419
|
+
eval2(script);
|
|
16420
|
+
// Invoke may hand back a plain value or a promise; normalise both.
|
|
16421
|
+
return Promise.resolve(window[resultId]);
|
|
16422
|
+
}
|
|
16423
|
+
catch (e) {
|
|
16424
|
+
return Promise.reject(e);
|
|
16425
|
+
}
|
|
16426
|
+
finally {
|
|
16427
|
+
delete window[argsId];
|
|
16428
|
+
delete window[contextId];
|
|
16429
|
+
delete window[resultId];
|
|
16430
|
+
}
|
|
16431
|
+
}
|
|
16432
|
+
};
|
|
16433
|
+
});
|
|
16434
|
+
}
|
|
16435
|
+
Plugin.GetInvokeFunction = GetInvokeFunction;
|
|
16353
16436
|
/**
|
|
16354
16437
|
* Returns cache identifier for a plugin.
|
|
16355
16438
|
* Example: {
|
|
@@ -16389,6 +16472,133 @@
|
|
|
16389
16472
|
Plugin.GetIndexFileCacheKey = GetIndexFileCacheKey;
|
|
16390
16473
|
})(exports.Plugin || (exports.Plugin = {}));
|
|
16391
16474
|
|
|
16475
|
+
/**
|
|
16476
|
+
* Validation for AI_TOOL plugins.
|
|
16477
|
+
*/
|
|
16478
|
+
(function (PluginAiTool) {
|
|
16479
|
+
/** Location value that exposes a plugin as an AI Tool. */
|
|
16480
|
+
PluginAiTool.LOCATION = "AI_TOOL";
|
|
16481
|
+
/** Prefix that turns a plugin ID into its tool name. */
|
|
16482
|
+
const TOOL_NAME_PREFIX = "plugin_";
|
|
16483
|
+
/** Provider limit on a tool name, prefix included. */
|
|
16484
|
+
const MAX_TOOL_NAME_LENGTH = 64;
|
|
16485
|
+
/** Longest plugin ID that still fits inside the tool name limit. */
|
|
16486
|
+
PluginAiTool.MAX_PLUGIN_ID_LENGTH = MAX_TOOL_NAME_LENGTH - TOOL_NAME_PREFIX.length;
|
|
16487
|
+
/**
|
|
16488
|
+
* Schema keywords that silently drop a tool out of strict mode instead of
|
|
16489
|
+
* failing. The tool still works, but stops being structurally guaranteed,
|
|
16490
|
+
* and nothing downstream reports that it happened.
|
|
16491
|
+
*/
|
|
16492
|
+
const STRICT_INCOMPATIBLE_KEYWORDS = ["$ref", "$defs", "allOf", "not"];
|
|
16493
|
+
/**
|
|
16494
|
+
* Side effects an AI Tool may declare.
|
|
16495
|
+
*
|
|
16496
|
+
*/
|
|
16497
|
+
const ALLOWED_SIDE_EFFECTS = ["none", "external"];
|
|
16498
|
+
function isPlainObject(value) {
|
|
16499
|
+
return !!value && typeof value === "object" && !Array.isArray(value);
|
|
16500
|
+
}
|
|
16501
|
+
/**
|
|
16502
|
+
* Walks a schema for a keyword that would disable strict mode.
|
|
16503
|
+
* @param node
|
|
16504
|
+
* @param depth bounded so a pathological schema cannot hang the save
|
|
16505
|
+
* @returns the offending keyword, or null
|
|
16506
|
+
*/
|
|
16507
|
+
function findStrictModeViolation(node, depth = 0) {
|
|
16508
|
+
if (!node || typeof node !== "object" || depth > 32) {
|
|
16509
|
+
return null;
|
|
16510
|
+
}
|
|
16511
|
+
if (Array.isArray(node)) {
|
|
16512
|
+
for (const child of node) {
|
|
16513
|
+
const nested = findStrictModeViolation(child, depth + 1);
|
|
16514
|
+
if (nested) {
|
|
16515
|
+
return nested;
|
|
16516
|
+
}
|
|
16517
|
+
}
|
|
16518
|
+
return null;
|
|
16519
|
+
}
|
|
16520
|
+
for (const key of Object.keys(node)) {
|
|
16521
|
+
if (STRICT_INCOMPATIBLE_KEYWORDS.includes(key)) {
|
|
16522
|
+
return key;
|
|
16523
|
+
}
|
|
16524
|
+
const nested = findStrictModeViolation(node[key], depth + 1);
|
|
16525
|
+
if (nested) {
|
|
16526
|
+
return nested;
|
|
16527
|
+
}
|
|
16528
|
+
}
|
|
16529
|
+
return null;
|
|
16530
|
+
}
|
|
16531
|
+
/**
|
|
16532
|
+
* Returns why an AI Tool plugin cannot be saved, or null when it is valid.
|
|
16533
|
+
*
|
|
16534
|
+
* Messages are written for the administrator authoring the plugin, and say
|
|
16535
|
+
* what to change rather than what failed.
|
|
16536
|
+
* @param plugin
|
|
16537
|
+
* @returns
|
|
16538
|
+
*/
|
|
16539
|
+
function Validate(plugin) {
|
|
16540
|
+
var _a, _b, _c, _d;
|
|
16541
|
+
if (!plugin || plugin.Location !== PluginAiTool.LOCATION) {
|
|
16542
|
+
return null;
|
|
16543
|
+
}
|
|
16544
|
+
const id = ((_a = plugin.ID) !== null && _a !== void 0 ? _a : "").trim();
|
|
16545
|
+
if (!id) {
|
|
16546
|
+
return "An AI Tool needs an ID: it becomes the tool name the agent calls.";
|
|
16547
|
+
}
|
|
16548
|
+
if (!/^[a-zA-Z0-9_-]+$/.test(id)) {
|
|
16549
|
+
return `The ID "${id}" contains characters that are not allowed in a tool name. `
|
|
16550
|
+
+ "Use letters, numbers, hyphens and underscores only.";
|
|
16551
|
+
}
|
|
16552
|
+
if (TOOL_NAME_PREFIX.length + id.length > MAX_TOOL_NAME_LENGTH) {
|
|
16553
|
+
return `The ID is ${id.length} characters, which makes the tool name too long. `
|
|
16554
|
+
+ `The maximum is ${PluginAiTool.MAX_PLUGIN_ID_LENGTH} characters.`;
|
|
16555
|
+
}
|
|
16556
|
+
const tool = (_b = plugin.Settings) === null || _b === void 0 ? void 0 : _b.tool;
|
|
16557
|
+
if (!isPlainObject(tool)) {
|
|
16558
|
+
return "An AI Tool must declare Settings.tool with an inputSchema the agent can call it with.";
|
|
16559
|
+
}
|
|
16560
|
+
// The tool name is an opaque ID, so it carries no signal about what the
|
|
16561
|
+
// tool does. The description is the only thing the agent can select on:
|
|
16562
|
+
// without one it is registered but never chosen, and nothing reports that.
|
|
16563
|
+
const description = typeof tool.description === "string" ? tool.description.trim() : "";
|
|
16564
|
+
if (!description && !((_c = plugin.Name) !== null && _c !== void 0 ? _c : "").trim()) {
|
|
16565
|
+
return "An AI Tool needs a description. Set Settings.tool.description, or fill in the plugin's "
|
|
16566
|
+
+ "Name and Description — the agent has nothing else to choose the tool on.";
|
|
16567
|
+
}
|
|
16568
|
+
if (!isPlainObject(tool.inputSchema)) {
|
|
16569
|
+
return "Settings.tool.inputSchema is missing or is not an object.";
|
|
16570
|
+
}
|
|
16571
|
+
if (tool.inputSchema.type && tool.inputSchema.type !== "object") {
|
|
16572
|
+
return `Settings.tool.inputSchema.type is "${tool.inputSchema.type}"; it must be "object".`;
|
|
16573
|
+
}
|
|
16574
|
+
const strictViolation = findStrictModeViolation(tool.inputSchema);
|
|
16575
|
+
if (strictViolation) {
|
|
16576
|
+
return `Settings.tool.inputSchema uses "${strictViolation}", which silently turns off strict mode `
|
|
16577
|
+
+ "for this tool. Inline the schema instead.";
|
|
16578
|
+
}
|
|
16579
|
+
if (tool.annotations !== undefined && !isPlainObject(tool.annotations)) {
|
|
16580
|
+
return "Settings.tool.annotations must be an object.";
|
|
16581
|
+
}
|
|
16582
|
+
const annotations = (_d = tool.annotations) !== null && _d !== void 0 ? _d : {};
|
|
16583
|
+
if (annotations.sideEffect !== undefined) {
|
|
16584
|
+
const sideEffect = String(annotations.sideEffect).trim().toLowerCase();
|
|
16585
|
+
if (!ALLOWED_SIDE_EFFECTS.includes(sideEffect)) {
|
|
16586
|
+
return `sideEffect "${annotations.sideEffect}" is not allowed. AI Tools are read-only in this `
|
|
16587
|
+
+ "release: use \"none\", or \"external\" for a reviewed read-only external request.";
|
|
16588
|
+
}
|
|
16589
|
+
}
|
|
16590
|
+
if (annotations.timeoutMs !== undefined) {
|
|
16591
|
+
if (typeof annotations.timeoutMs !== "number"
|
|
16592
|
+
|| !isFinite(annotations.timeoutMs)
|
|
16593
|
+
|| annotations.timeoutMs <= 0) {
|
|
16594
|
+
return "timeoutMs must be a positive number of milliseconds.";
|
|
16595
|
+
}
|
|
16596
|
+
}
|
|
16597
|
+
return null;
|
|
16598
|
+
}
|
|
16599
|
+
PluginAiTool.Validate = Validate;
|
|
16600
|
+
})(exports.PluginAiTool || (exports.PluginAiTool = {}));
|
|
16601
|
+
|
|
16392
16602
|
(function (ProgramKey) {
|
|
16393
16603
|
/**
|
|
16394
16604
|
* Known program IDs that Nextspace applications will reference.
|
|
@@ -20381,7 +20591,7 @@
|
|
|
20381
20591
|
})(exports.UrlUtils || (exports.UrlUtils = {}));
|
|
20382
20592
|
|
|
20383
20593
|
// This is updated with the package.json version on build.
|
|
20384
|
-
const VERSION = "7.1.
|
|
20594
|
+
const VERSION = "7.1.87";
|
|
20385
20595
|
|
|
20386
20596
|
exports.VERSION = VERSION;
|
|
20387
20597
|
exports.AbstractApi = AbstractApi;
|