bruce-models 7.1.85 → 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.
@@ -8453,11 +8453,12 @@
8453
8453
  */
8454
8454
  function Get(params) {
8455
8455
  return __awaiter(this, void 0, void 0, function* () {
8456
- let { id, api, req: reqParams } = params;
8456
+ let { id, expandCount, api, req: reqParams } = params;
8457
8457
  if (!api) {
8458
8458
  api = exports.ENVIRONMENT.Api().GetBruceApi();
8459
8459
  }
8460
- return yield api.GET(`v3/change/${id}`, exports.Api.PrepReqParams(reqParams));
8460
+ const query = expandCount ? "?Expand=Count" : "";
8461
+ return yield api.GET(`v3/change/${id}${query}`, exports.Api.PrepReqParams(reqParams));
8461
8462
  });
8462
8463
  }
8463
8464
  ChangeSet.Get = Get;
@@ -8467,7 +8468,7 @@
8467
8468
  */
8468
8469
  function GetList(params) {
8469
8470
  return __awaiter(this, void 0, void 0, function* () {
8470
- let { api, req: reqParams, pageSize, pageIndex } = params;
8471
+ let { api, req: reqParams, pageSize, pageIndex, expandCount } = params;
8471
8472
  if (!api) {
8472
8473
  api = exports.ENVIRONMENT.Api().GetBruceApi();
8473
8474
  }
@@ -8478,6 +8479,9 @@
8478
8479
  if (pageIndex != null) {
8479
8480
  urlParams.append("PageIndex", String(pageIndex));
8480
8481
  }
8482
+ if (expandCount) {
8483
+ urlParams.append("Expand", "Count");
8484
+ }
8481
8485
  const query = urlParams.toString();
8482
8486
  return api.GET(query ? `v3/changes?${query}` : "v3/changes", exports.Api.PrepReqParams(reqParams));
8483
8487
  });
@@ -16210,27 +16214,19 @@
16210
16214
  }
16211
16215
  Plugin.Upload = Upload;
16212
16216
  /**
16213
- * Returns a run function to call that'll load a plugin within your provided container element.
16214
- * The run function will return a dispose function to call to remove the plugin.
16217
+ * Resolves a plugin record and returns its unwrapped source.
16215
16218
  * @param params
16216
16219
  * @returns
16217
16220
  */
16218
- function GetRunFunction(params) {
16221
+ function LoadPluginSource(params) {
16219
16222
  return __awaiter(this, void 0, void 0, function* () {
16220
- let { containerId, container, pluginParams, pluginId, plugin, api, req } = params;
16223
+ let { api, pluginId, plugin, req } = params;
16221
16224
  if (!api) {
16222
16225
  api = exports.ENVIRONMENT.Api().GetBruceApi({
16223
16226
  loadConfig: true
16224
16227
  });
16225
16228
  }
16226
16229
  yield api.Loading;
16227
- if (!containerId && container) {
16228
- containerId = container.id;
16229
- if (!containerId) {
16230
- containerId = exports.ObjectUtils.UId();
16231
- container.id = containerId;
16232
- }
16233
- }
16234
16230
  if (!plugin && pluginId) {
16235
16231
  plugin = (yield Plugin.Get({
16236
16232
  pluginId,
@@ -16272,6 +16268,39 @@
16272
16268
  const start = fileContent.indexOf("{");
16273
16269
  const end = fileContent.lastIndexOf("}");
16274
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;
16275
16304
  const paramsId = exports.ObjectUtils.UId();
16276
16305
  window[paramsId] = pluginParams ? pluginParams : {};
16277
16306
  window["PLUGIN_" + pluginId] = plugin;
@@ -16346,6 +16375,64 @@
16346
16375
  });
16347
16376
  }
16348
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;
16349
16436
  /**
16350
16437
  * Returns cache identifier for a plugin.
16351
16438
  * Example: {
@@ -16385,6 +16472,133 @@
16385
16472
  Plugin.GetIndexFileCacheKey = GetIndexFileCacheKey;
16386
16473
  })(exports.Plugin || (exports.Plugin = {}));
16387
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
+
16388
16602
  (function (ProgramKey) {
16389
16603
  /**
16390
16604
  * Known program IDs that Nextspace applications will reference.
@@ -20377,7 +20591,7 @@
20377
20591
  })(exports.UrlUtils || (exports.UrlUtils = {}));
20378
20592
 
20379
20593
  // This is updated with the package.json version on build.
20380
- const VERSION = "7.1.85";
20594
+ const VERSION = "7.1.87";
20381
20595
 
20382
20596
  exports.VERSION = VERSION;
20383
20597
  exports.AbstractApi = AbstractApi;