@engenty/wizards-runtime 0.12.1 → 0.13.0
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/apps/runtime/dist/agents/studio-assistant.js +42 -5
- package/apps/runtime/dist/app.js +15 -4
- package/apps/runtime/dist/credits/estimate.js +3 -3
- package/apps/runtime/dist/db/live-triggers.js +13 -3
- package/apps/runtime/dist/db/migrations/tenant/0027_space_skill.sql +48 -0
- package/apps/runtime/dist/db/migrations/tenant/meta/0027_snapshot.json +4120 -0
- package/apps/runtime/dist/db/migrations/tenant/meta/_journal.json +7 -0
- package/apps/runtime/dist/db/schema.js +31 -0
- package/apps/runtime/dist/docs/dev/skills.md +116 -0
- package/apps/runtime/dist/docs/dev/wizard-format/agent-steps.md +20 -2
- package/apps/runtime/dist/docs/user-guide/models.md +105 -30
- package/apps/runtime/dist/docs/user-guide/skills.md +85 -0
- package/apps/runtime/dist/docs/user-guide/together.md +15 -2
- package/apps/runtime/dist/engine/decide.js +1 -1
- package/apps/runtime/dist/engine/requirements.js +139 -11
- package/apps/runtime/dist/engine/runner.js +47 -5
- package/apps/runtime/dist/engine/steps.js +23 -6
- package/apps/runtime/dist/engine/template.js +17 -0
- package/apps/runtime/dist/harness/model.js +4 -0
- package/apps/runtime/dist/link-preview.js +9 -0
- package/apps/runtime/dist/live/views.js +2 -0
- package/apps/runtime/dist/manage.js +25 -0
- package/apps/runtime/dist/mcp/handler.js +55 -1
- package/apps/runtime/dist/mcp/seen.js +47 -0
- package/apps/runtime/dist/models.js +206 -11
- package/apps/runtime/dist/motion-graphics/step.js +2 -2
- package/apps/runtime/dist/prompts/goose.md +15 -7
- package/apps/runtime/dist/prompts/safety.md +18 -0
- package/apps/runtime/dist/prompts/step.md +20 -2
- package/apps/runtime/dist/prompts/tools.md +33 -0
- package/apps/runtime/dist/routes/marketplace.js +3 -3
- package/apps/runtime/dist/routes/runs.js +5 -0
- package/apps/runtime/dist/routes/skills.js +84 -0
- package/apps/runtime/dist/routes/studio.js +103 -4
- package/apps/runtime/dist/safety.js +60 -18
- package/apps/runtime/dist/services/manage-reports.js +3 -0
- package/apps/runtime/dist/services/marketplace.js +7 -31
- package/apps/runtime/dist/services/pages.js +6 -2
- package/apps/runtime/dist/services/shares.js +5 -0
- package/apps/runtime/dist/services/skills-registry.js +209 -0
- package/apps/runtime/dist/services/skills.js +478 -0
- package/apps/runtime/dist/services/spaces.js +15 -1
- package/apps/runtime/dist/sync/records.js +81 -1
- package/apps/runtime/dist/texts.js +45 -0
- package/apps/runtime/dist/tools/index.js +7 -4
- package/apps/runtime/dist/tools/net-guard.js +8 -4
- package/apps/runtime/dist/tools/skills.js +197 -0
- package/apps/web/dist/assets/AboutDialog-B-JxkELB.js +1 -0
- package/apps/web/dist/assets/{ChangelogDialog-BWaEdlt3.js → ChangelogDialog-SwyId00t.js} +1 -1
- package/apps/web/dist/assets/CodeEditor-BwZsk5Al.js +2 -0
- package/apps/web/dist/assets/EditorPage-DQ_2FOzI.js +3 -0
- package/apps/web/dist/assets/{FlowPreview-DXpzFBRj.js → FlowPreview-DtSpjVTl.js} +1 -1
- package/apps/web/dist/assets/Marketplace-DoH4YO3D.js +2 -0
- package/apps/web/dist/assets/{NewWizardChannels-B5wuTm7J.js → NewWizardChannels-Tgoexgj4.js} +1 -1
- package/apps/web/dist/assets/NewWizardPage-B24AF482.js +7 -0
- package/apps/web/dist/assets/OnboardingPage-BEvq4slJ.js +1 -0
- package/apps/web/dist/assets/PreviewPane-B_v7Y8R7.js +10 -0
- package/apps/web/dist/assets/ProjectPage-ClRuhFJo.js +10 -0
- package/apps/web/dist/assets/PublicRunner-MicrpVsv.js +1 -0
- package/apps/web/dist/assets/{ReadOnly-Cap_e5ke.js → ReadOnly-BXjv-MSv.js} +1 -1
- package/apps/web/dist/assets/SettingsPage-DY8O1r43.js +2 -0
- package/apps/web/dist/assets/SetupPage-BOVkVpMu.js +1 -0
- package/apps/web/dist/assets/{SharePage-DEeVGatD.js → SharePage-DXGzJSnR.js} +1 -1
- package/apps/web/dist/assets/SkillEditor-BzzTDeaU.js +1 -0
- package/apps/web/dist/assets/changelog-BLdS-0Bj.js +1 -0
- package/apps/web/dist/assets/code-xml-TwKzzMtA.js +1 -0
- package/apps/web/dist/assets/{dist-BwhPmMDu.js → dist-BdDd1FxP.js} +1 -1
- package/apps/web/dist/assets/dist-EBVTpvRr.js +10 -0
- package/apps/web/dist/assets/dist-GlRRx9Xl.js +1 -0
- package/apps/web/dist/assets/dist-H1UN89OA.js +1 -0
- package/apps/web/dist/assets/eye-Brd-xPUJ.js +1 -0
- package/apps/web/dist/assets/i18n-8-Sw11tB.js +55 -0
- package/apps/web/dist/assets/index-OsdQFHmh.js +49 -0
- package/apps/web/dist/assets/index-QPipX5Fi.css +1 -0
- package/apps/web/dist/assets/json-CEsfHdlZ.js +1 -0
- package/apps/web/dist/assets/{lock-D-CjMpqn.js → lock-C0uxcOlq.js} +1 -1
- package/apps/web/dist/assets/markdown-5-I9_izp.js +29 -0
- package/apps/web/dist/assets/{oss-credits-CUpVhKSr.js → oss-credits-DpRWUPjD.js} +1 -1
- package/apps/web/dist/assets/{phone-CXSrxw3H.js → phone-DhkHteoJ.js} +1 -1
- package/apps/web/dist/assets/{runners-D71NjXtA.js → runners-G-XYaDgR.js} +1 -1
- package/apps/web/dist/assets/{session-B2LtqeDq.js → session-BWI-KENJ.js} +1 -1
- package/apps/web/dist/assets/theme-D7krsx0_.js +11 -0
- package/apps/web/dist/assets/ui-DSXG3f49.js +83 -0
- package/apps/web/dist/assets/{upload-hLkuT3Q6.js → upload-BYZTwJTD.js} +1 -1
- package/apps/web/dist/assets/{useMutation-C3XBoSVf.js → useMutation-D0QP_k2-.js} +1 -1
- package/apps/web/dist/assets/{volume-2-DIxdTlaA.js → volume-2-CVHoxdGM.js} +1 -1
- package/apps/web/dist/index.html +9 -8
- package/apps/web/dist/mcp/flow.html +66 -66
- package/node_modules/@engenty/wizards/dist/plugin/studio.d.ts +3 -2
- package/node_modules/@engenty/wizards-shared/dist/assistant.d.ts +1 -0
- package/node_modules/@engenty/wizards-shared/dist/assistant.js +5 -0
- package/node_modules/@engenty/wizards-shared/dist/definition.d.ts +107 -0
- package/node_modules/@engenty/wizards-shared/dist/definition.js +67 -4
- package/node_modules/@engenty/wizards-shared/dist/feature-flags.d.ts +18 -0
- package/node_modules/@engenty/wizards-shared/dist/feature-flags.js +18 -0
- package/node_modules/@engenty/wizards-shared/dist/live.d.ts +1 -1
- package/node_modules/@engenty/wizards-shared/dist/marketplace.d.ts +0 -5
- package/node_modules/@engenty/wizards-shared/dist/run.d.ts +62 -0
- package/node_modules/@engenty/wizards-shared/dist/run.js +52 -0
- package/node_modules/@engenty/wizards-shared/dist/skills.d.ts +165 -0
- package/node_modules/@engenty/wizards-shared/dist/skills.js +346 -0
- package/node_modules/@engenty/wizards-shared/dist/sync.d.ts +4 -2
- package/node_modules/@engenty/wizards-shared/dist/sync.js +2 -1
- package/node_modules/@engenty/wizards-shared/dist/tiers.d.ts +195 -0
- package/node_modules/@engenty/wizards-shared/dist/tiers.js +98 -0
- package/package.json +7 -7
- package/plugin/.claude-plugin/plugin.json +1 -1
- package/plugin/plugin.json +1 -1
- package/apps/web/dist/assets/AboutDialog-uGYGy2R2.js +0 -1
- package/apps/web/dist/assets/CodeEditor-B5hV1IvK.js +0 -2
- package/apps/web/dist/assets/EditorPage-j9BOx5-V.js +0 -3
- package/apps/web/dist/assets/Marketplace-DSo6uZF6.js +0 -2
- package/apps/web/dist/assets/NewWizardPage-Ci1ZsTJk.js +0 -7
- package/apps/web/dist/assets/OnboardingPage-QkdluEZk.js +0 -1
- package/apps/web/dist/assets/PreviewPane-swAH89un.js +0 -10
- package/apps/web/dist/assets/ProjectPage-Djv5EOYU.js +0 -1
- package/apps/web/dist/assets/PublicRunner-Bt8gMxit.js +0 -1
- package/apps/web/dist/assets/SettingsPage-C2rmXm_Q.js +0 -2
- package/apps/web/dist/assets/SetupPage-CbqGgFPZ.js +0 -1
- package/apps/web/dist/assets/changelog-DAY6ZEyy.js +0 -1
- package/apps/web/dist/assets/dist-DVpDdhG9.js +0 -1
- package/apps/web/dist/assets/dist-DzdNG7Sf.js +0 -10
- package/apps/web/dist/assets/i18n-B3J2ypKu.js +0 -55
- package/apps/web/dist/assets/index-Dxwbli0m.css +0 -1
- package/apps/web/dist/assets/index-WY5lJ_-h.js +0 -49
- package/apps/web/dist/assets/json-D2GVvTXK.js +0 -1
- package/apps/web/dist/assets/markdown-DwdMW7q0.js +0 -29
- package/apps/web/dist/assets/theme-Dab079EV.js +0 -11
- package/apps/web/dist/assets/ui-DQX_CQ7c.js +0 -83
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import { conditionMatches, conditionsOf, isDecidedField, isDecisionStep, isOtherwise, MODEL_CLASSES, } from "@engenty/wizards-shared/definition";
|
|
1
|
+
import { classIdOf, conditionMatches, conditionsOf, isDecidedField, isDecisionStep, isOtherwise, MODEL_CLASSES, textClassOf, } from "@engenty/wizards-shared/definition";
|
|
2
2
|
import { closedChoicesFor, openValue, otherwiseIndex, unavoidableFrom, unavoidableSteps, } from "@engenty/wizards-shared/fit";
|
|
3
|
+
import { CLASS_NAMES } from "@engenty/wizards-shared/providers";
|
|
3
4
|
import { note, saidText } from "@engenty/wizards-shared/run";
|
|
4
|
-
import {
|
|
5
|
+
import { MAKER_COMPANIES, MAKER_FAMILIES, splitClassId, } from "@engenty/wizards-shared/tiers";
|
|
6
|
+
import { classProblem, currentTier, motionClient, tierRefusal } from "../models.js";
|
|
5
7
|
// The steps every run passes through, and the choices that lead around a missing model, are
|
|
6
8
|
// pure and shared (packages/shared/src/fit.ts): the standalone check uses the same.
|
|
7
9
|
export { openValue, unavoidableFrom, unavoidableSteps };
|
|
@@ -29,7 +31,7 @@ function ownClasses(step) {
|
|
|
29
31
|
if (isDecisionStep(step)) {
|
|
30
32
|
return ["classifier"];
|
|
31
33
|
}
|
|
32
|
-
const classes = [step.model ?? "standard"];
|
|
34
|
+
const classes = [textClassOf(step.model ?? "standard")];
|
|
33
35
|
if (step.tools.includes("image")) {
|
|
34
36
|
classes.push("image");
|
|
35
37
|
}
|
|
@@ -50,10 +52,10 @@ function ownClasses(step) {
|
|
|
50
52
|
case "voice":
|
|
51
53
|
return ["speech"];
|
|
52
54
|
default:
|
|
53
|
-
return [step.model ?? "standard"];
|
|
55
|
+
return [textClassOf(step.model ?? "standard")];
|
|
54
56
|
}
|
|
55
57
|
case "motion-graphics":
|
|
56
|
-
return [step.model ?? "low"];
|
|
58
|
+
return [textClassOf(step.model ?? "low")];
|
|
57
59
|
case "page":
|
|
58
60
|
// A voice note the page asks for is listened to before the next step reads it.
|
|
59
61
|
return step.fields.some((f) => f.kind === "audio" && f.required) ? ["audio"] : [];
|
|
@@ -216,10 +218,119 @@ export function mostAlongOnePath(def, cost, closed = new Set()) {
|
|
|
216
218
|
};
|
|
217
219
|
return walk(closed) ?? walk(new Set()) ?? def.steps.reduce((sum, s) => sum + cost(s), 0);
|
|
218
220
|
}
|
|
219
|
-
/** The steps that call a class this runtime cannot serve. */
|
|
221
|
+
/** The steps that call a class this runtime cannot serve, or the organization's tier doesn't offer. */
|
|
220
222
|
export async function stepsWithoutModel(def) {
|
|
221
223
|
const missing = await missingClasses();
|
|
222
|
-
|
|
224
|
+
const tier = await currentTier();
|
|
225
|
+
return new Set(def.steps
|
|
226
|
+
.filter((s) => stepClasses(s).some((cls) => missing.has(cls) || (tier && tierProblem(tier, tierClassOf(s, cls)))))
|
|
227
|
+
.map((s) => s.id));
|
|
228
|
+
}
|
|
229
|
+
/**
|
|
230
|
+
* The class a step asks the gateway for, as the tier names it: `anthropic/highest` where the
|
|
231
|
+
* step names a maker for its own text class, else the class.
|
|
232
|
+
*/
|
|
233
|
+
export function tierClassOf(step, cls) {
|
|
234
|
+
if (!("maker" in step) || !step.maker || cls === "classifier") {
|
|
235
|
+
return cls;
|
|
236
|
+
}
|
|
237
|
+
const own = step.model ?? cls;
|
|
238
|
+
return textClassOf(own) === cls ? classIdOf({ model: own, maker: step.maker }, "standard") : cls;
|
|
239
|
+
}
|
|
240
|
+
/** What a tier's class id makes, as a note's gap: "videos", "Claude · High". */
|
|
241
|
+
export function tierClassWhat(id) {
|
|
242
|
+
const { maker, cls } = splitClassId(id);
|
|
243
|
+
const name = cls === "highest" ? "Highest" : CLASS_NAMES[cls];
|
|
244
|
+
if (maker) {
|
|
245
|
+
return `${MAKER_FAMILIES[maker]} · ${name ?? cls}`;
|
|
246
|
+
}
|
|
247
|
+
switch (cls) {
|
|
248
|
+
case "image":
|
|
249
|
+
return note("makesImages");
|
|
250
|
+
case "video":
|
|
251
|
+
return note("makesVideos");
|
|
252
|
+
case "speech":
|
|
253
|
+
return note("makesSpeech");
|
|
254
|
+
case "audio":
|
|
255
|
+
return note("makesVoiceNotes");
|
|
256
|
+
case "classifier":
|
|
257
|
+
return note("makesDecisions");
|
|
258
|
+
case "embedding":
|
|
259
|
+
return note("makesSearch");
|
|
260
|
+
default:
|
|
261
|
+
return name ?? cls;
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* What a step the gateway refused for the organization's tier or policy says: the class and the
|
|
266
|
+
* tier, or that the admins haven't approved it. Null for any other failure.
|
|
267
|
+
*/
|
|
268
|
+
export async function tierRefusalSaid(err) {
|
|
269
|
+
const refused = tierRefusal(err);
|
|
270
|
+
if (!refused) {
|
|
271
|
+
return null;
|
|
272
|
+
}
|
|
273
|
+
const what = refused.cls ? tierClassWhat(refused.cls) : note("thisModel");
|
|
274
|
+
if (refused.type === "not_in_policy") {
|
|
275
|
+
return note("notInPolicy", { what });
|
|
276
|
+
}
|
|
277
|
+
const tier = await currentTier();
|
|
278
|
+
const problem = (tier && refused.cls ? tierProblem(tier, refused.cls) : null) ??
|
|
279
|
+
note("tierOffersNo", { tier: refused.tier ?? tier?.name ?? "", what });
|
|
280
|
+
return note("tierRefused", { problem });
|
|
281
|
+
}
|
|
282
|
+
const MASKED_KINDS = {
|
|
283
|
+
person: "maskedPerson",
|
|
284
|
+
email: "maskedEmail",
|
|
285
|
+
phone: "maskedPhone",
|
|
286
|
+
iban: "maskedIban",
|
|
287
|
+
id: "maskedId",
|
|
288
|
+
address: "maskedAddress",
|
|
289
|
+
contract: "maskedContract",
|
|
290
|
+
term: "maskedTerm",
|
|
291
|
+
};
|
|
292
|
+
/** The Log line of what the gateway masked in a step's calls, from its counts per kind. */
|
|
293
|
+
export function maskedNote(counts) {
|
|
294
|
+
const kinds = [];
|
|
295
|
+
let other = 0;
|
|
296
|
+
for (const [kind, count] of Object.entries(counts)) {
|
|
297
|
+
const code = MASKED_KINDS[kind];
|
|
298
|
+
if (code) {
|
|
299
|
+
kinds.push(note(code, { count }));
|
|
300
|
+
}
|
|
301
|
+
else {
|
|
302
|
+
other += count;
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
if (other) {
|
|
306
|
+
kinds.push(note("maskedOther", { count: other }));
|
|
307
|
+
}
|
|
308
|
+
const count = Object.values(counts).reduce((sum, n) => sum + n, 0);
|
|
309
|
+
return note("masked", { count, kinds });
|
|
310
|
+
}
|
|
311
|
+
/** Why the organization's tier doesn't serve a class; null where it does. */
|
|
312
|
+
export function tierProblem(tier, id) {
|
|
313
|
+
const entry = tier.classes[id];
|
|
314
|
+
const what = tierClassWhat(id);
|
|
315
|
+
if (!entry) {
|
|
316
|
+
return note("tierOffersNo", { tier: tier.name, what });
|
|
317
|
+
}
|
|
318
|
+
if (entry.model !== null) {
|
|
319
|
+
return null;
|
|
320
|
+
}
|
|
321
|
+
const { maker } = splitClassId(id);
|
|
322
|
+
if (entry.reason === "maker" && maker) {
|
|
323
|
+
return note("tierLeavesOutMaker", { tier: tier.name, maker: MAKER_COMPANIES[maker] });
|
|
324
|
+
}
|
|
325
|
+
const model = entry.name ?? note("thisModel");
|
|
326
|
+
const why = entry.reason === "region"
|
|
327
|
+
? note("tierWhyRegion")
|
|
328
|
+
: entry.reason === "retention"
|
|
329
|
+
? note("tierWhyRetention", { model })
|
|
330
|
+
: entry.reason === "training"
|
|
331
|
+
? note("tierWhyTraining", { model })
|
|
332
|
+
: note("tierWhyUnbound");
|
|
333
|
+
return note("tierOffersNoWhy", { tier: tier.name, what, why });
|
|
223
334
|
}
|
|
224
335
|
/** The classes this wizard needs that this runtime cannot serve, in a language; empty = every step can run. */
|
|
225
336
|
export async function missingModels(def, lang = "en") {
|
|
@@ -228,22 +339,39 @@ export async function missingModels(def, lang = "en") {
|
|
|
228
339
|
/** The classes this wizard needs that this runtime cannot serve; empty = every step can run. */
|
|
229
340
|
export async function missingModelsSaid(def) {
|
|
230
341
|
const unavoidable = unavoidableSteps(def);
|
|
342
|
+
const tier = await currentTier();
|
|
231
343
|
const needs = new Map();
|
|
344
|
+
// What the organization's tier doesn't offer is missing whatever this runtime could serve.
|
|
345
|
+
const outside = new Map();
|
|
346
|
+
const use = (step, cls, required) => {
|
|
347
|
+
const id = tier ? tierClassOf(step, cls) : cls;
|
|
348
|
+
const problem = tier ? tierProblem(tier, id) : null;
|
|
349
|
+
if (!problem) {
|
|
350
|
+
needs.set(cls, [...(needs.get(cls) ?? []), { step, required }]);
|
|
351
|
+
return;
|
|
352
|
+
}
|
|
353
|
+
const entry = outside.get(id) ?? { cls, tierClass: id, problem, steps: [], blocking: false };
|
|
354
|
+
if (!entry.steps.some((s) => s.id === step.id)) {
|
|
355
|
+
entry.steps.push({ id: step.id, title: step.title });
|
|
356
|
+
}
|
|
357
|
+
entry.blocking ||= required && unavoidable.has(step.id);
|
|
358
|
+
outside.set(id, entry);
|
|
359
|
+
};
|
|
232
360
|
for (const step of def.steps) {
|
|
233
361
|
for (const cls of new Set(stepClasses(step))) {
|
|
234
|
-
|
|
362
|
+
use(step, cls, true);
|
|
235
363
|
}
|
|
236
364
|
for (const cls of optionalStepClasses(step)) {
|
|
237
|
-
|
|
365
|
+
use(step, cls, false);
|
|
238
366
|
}
|
|
239
367
|
}
|
|
240
|
-
const missing = [];
|
|
368
|
+
const missing = [...outside.values()];
|
|
241
369
|
// A video runs on an installed client only, whatever serves its class otherwise.
|
|
242
370
|
for (const step of def.steps) {
|
|
243
371
|
if (step.type !== "motion-graphics") {
|
|
244
372
|
continue;
|
|
245
373
|
}
|
|
246
|
-
const cls = step.model ?? "low";
|
|
374
|
+
const cls = textClassOf(step.model ?? "low");
|
|
247
375
|
const found = await motionClient(cls);
|
|
248
376
|
if ("problem" in found) {
|
|
249
377
|
missing.push({
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
1
2
|
import { marginOf, } from "@engenty/wizards-shared/decision";
|
|
2
3
|
import { branchValues, cardsFromData, conditionsOf, dataRef, followRules, formatsFor, isDecidedField, LIST_FORMATS, listRef, loopKey, MAX_SHOWN_FIELDS, optionsFromData, otherwiseOf, pageNeeds, textLang, whenHolds, wizardLang, } from "@engenty/wizards-shared/definition";
|
|
3
4
|
import { note, saidText, } from "@engenty/wizards-shared/run";
|
|
@@ -16,9 +17,10 @@ import { saveAsset } from "../files/storage.js";
|
|
|
16
17
|
import { managed, tenantInfo } from "../manage.js";
|
|
17
18
|
import { hasFfmpeg } from "../media/ffmpeg.js";
|
|
18
19
|
import { NotedError, noteOf, saidOf } from "../model-errors.js";
|
|
19
|
-
import { conversationAvailable, freeTierRefusal, freeTierText, ModelUnavailableError, noteFreeTierRefusal, } from "../models.js";
|
|
20
|
+
import { conversationAvailable, freeTierRefusal, freeTierText, ModelUnavailableError, noteFreeTierRefusal, takeMasked, } from "../models.js";
|
|
20
21
|
import { runEnded } from "../plugins/events.js";
|
|
21
22
|
import { prompt } from "../prompts.js";
|
|
23
|
+
import { ContentBlockedError, checkGuestInput, checkGuestText, guestChecksOn, guestRun, } from "../safety.js";
|
|
22
24
|
import { reportRun } from "../services/manage-reports.js";
|
|
23
25
|
import { projectFiles } from "../services/project-files.js";
|
|
24
26
|
import { projectProfile } from "../services/projects.js";
|
|
@@ -34,7 +36,7 @@ import { clearDeviceCalls } from "./device.js";
|
|
|
34
36
|
import { emitEvent, recentEvents, signalChanged } from "./events.js";
|
|
35
37
|
import { readPageInput } from "./input.js";
|
|
36
38
|
import { pushRun } from "./push.js";
|
|
37
|
-
import { blockingMessage, closedChoices, missingModelsSaid, openValue, stepsWithoutModel, } from "./requirements.js";
|
|
39
|
+
import { blockingMessage, closedChoices, maskedNote, missingModelsSaid, openValue, stepsWithoutModel, tierRefusalSaid, } from "./requirements.js";
|
|
38
40
|
import { releaseResources, resourcesFor } from "./resources.js";
|
|
39
41
|
import { outputSchema, runAutomaticStep } from "./steps.js";
|
|
40
42
|
import { answersAsText, resolveRef } from "./template.js";
|
|
@@ -153,10 +155,23 @@ function friendly(err) {
|
|
|
153
155
|
* as that note, so a runner shows it in its language; the run's error is in the wizard's.
|
|
154
156
|
*/
|
|
155
157
|
async function failRun(run, stepId, err) {
|
|
156
|
-
const said = noteOf(err) ?? friendly(err);
|
|
158
|
+
const said = noteOf(err) ?? (await tierRefusalSaid(err)) ?? friendly(err);
|
|
157
159
|
const message = saidText(said, textLang(wizardLang(run.definition)));
|
|
158
160
|
await emitEvent(run.id, stepId, "error", said);
|
|
159
|
-
|
|
161
|
+
// What the content rules stopped is kept on the run: Manage hears of it with the failed turn.
|
|
162
|
+
const blocked = err instanceof ContentBlockedError
|
|
163
|
+
? (await db.query.run.findFirst({
|
|
164
|
+
where: eq(schema.run.id, run.id),
|
|
165
|
+
columns: { state: true },
|
|
166
|
+
}))?.state
|
|
167
|
+
: undefined;
|
|
168
|
+
await updateRun(run.id, {
|
|
169
|
+
status: "failed",
|
|
170
|
+
error: message,
|
|
171
|
+
...(blocked && err instanceof ContentBlockedError
|
|
172
|
+
? { state: { ...blocked, blocked: err.kind } }
|
|
173
|
+
: {}),
|
|
174
|
+
});
|
|
160
175
|
}
|
|
161
176
|
// --- creating & driving ------------------------------------------------------
|
|
162
177
|
export async function createRun(input) {
|
|
@@ -658,16 +673,39 @@ async function drive(runId, signal) {
|
|
|
658
673
|
const project = await loadProject(run);
|
|
659
674
|
const state = structuredClone(run.state);
|
|
660
675
|
try {
|
|
661
|
-
const
|
|
676
|
+
const ctx = await makeContext(run, project, state, signal);
|
|
677
|
+
// A guest's answers are checked once before any model works on them, and what a step
|
|
678
|
+
// wrote for a guest before it is kept (docs/plans/guest-content-guards.md).
|
|
679
|
+
const guest = guestRun(run) && (await guestChecksOn());
|
|
680
|
+
if (guest) {
|
|
681
|
+
const answers = [answersAsText(ctx.scope), ...Object.values(state.notes)].join("\n");
|
|
682
|
+
const hash = createHash("sha256").update(answers).digest("base64url").slice(0, 24);
|
|
683
|
+
if (state.inputChecked !== hash) {
|
|
684
|
+
await checkGuestInput({ text: answers, call: ctx.call, signal });
|
|
685
|
+
state.inputChecked = hash;
|
|
686
|
+
}
|
|
687
|
+
}
|
|
688
|
+
const output = await runAutomaticStep(step, ctx);
|
|
662
689
|
if (signal.aborted) {
|
|
663
690
|
return;
|
|
664
691
|
}
|
|
692
|
+
if (guest) {
|
|
693
|
+
await checkGuestText({
|
|
694
|
+
text: output.text || (output.json ? JSON.stringify(output.json) : ""),
|
|
695
|
+
call: ctx.call,
|
|
696
|
+
signal,
|
|
697
|
+
});
|
|
698
|
+
}
|
|
665
699
|
await syncRunCost(runId);
|
|
666
700
|
state.outputs[step.id] = output;
|
|
667
701
|
delete state.notes[step.id];
|
|
668
702
|
delete state.redo?.[step.id];
|
|
669
703
|
const cursor = await advance(run, step.id, state);
|
|
670
704
|
await updateRun(runId, { state, cursor, status: cursor ? "running" : "done", error: null });
|
|
705
|
+
const masked = takeMasked(runId, step.id);
|
|
706
|
+
if (masked) {
|
|
707
|
+
await emitEvent(runId, step.id, "info", maskedNote(masked));
|
|
708
|
+
}
|
|
671
709
|
await emitEvent(runId, step.id, "step_done", step.title);
|
|
672
710
|
}
|
|
673
711
|
catch (err) {
|
|
@@ -819,6 +857,10 @@ export async function reviewStep(runId, stepId, action) {
|
|
|
819
857
|
else {
|
|
820
858
|
state.outputs[target] = editedJson(run.definition, target, output, edit);
|
|
821
859
|
}
|
|
860
|
+
// A guest's own words in a result are held to the same rules as what a step wrote.
|
|
861
|
+
if (guestRun(run) && (await guestChecksOn())) {
|
|
862
|
+
await checkGuestText({ text: typeof edit === "string" ? edit : JSON.stringify(edit) });
|
|
863
|
+
}
|
|
822
864
|
}
|
|
823
865
|
state.history.push(stepId);
|
|
824
866
|
const cursor = await advance(run, stepId, state);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { pOf } from "@engenty/wizards-shared/decision";
|
|
2
|
-
import { allFields, dataRef, isDecisionStep, langNameEn, localeOf, stepShape, templateRefs, wizardLang, } from "@engenty/wizards-shared/definition";
|
|
2
|
+
import { allFields, classIdOf, dataRef, isDecisionStep, langNameEn, localeOf, stepShape, templateRefs, textClassOf, wizardLang, } from "@engenty/wizards-shared/definition";
|
|
3
3
|
import { mainLogo, ruleLines, runTheme } from "@engenty/wizards-shared/projects";
|
|
4
4
|
import { note as runNote } from "@engenty/wizards-shared/run";
|
|
5
5
|
import { fitData, labelOf, recordsOf, shapeJsonSchema, shapeLines, shapeZod, titleKey, } from "@engenty/wizards-shared/shape";
|
|
@@ -10,19 +10,21 @@ import { extFor, loadAsset, loadAssetText } from "../files/storage.js";
|
|
|
10
10
|
import { snapshotHtmlImages } from "../files/web-images.js";
|
|
11
11
|
import { generateImageMedia, generateSpeechMedia, generateVideoMedia, } from "../media/generate.js";
|
|
12
12
|
import { markMedia } from "../media/marking.js";
|
|
13
|
-
import { agentModel, attachTools, costOf, isHarnessVendor, textModel, totalUsage, } from "../models.js";
|
|
13
|
+
import { agentModel, attachTools, costOf, isHarnessVendor, takesTools, textModel, totalUsage, } from "../models.js";
|
|
14
14
|
import { runMotionGraphicsStep } from "../motion-graphics/step.js";
|
|
15
15
|
import { prompt } from "../prompts.js";
|
|
16
16
|
import { contentPolicy } from "../safety.js";
|
|
17
|
+
import { sandboxCapabilities } from "../sandbox/index.js";
|
|
17
18
|
import { knowledgeBlock } from "../services/knowledge.js";
|
|
18
19
|
import { buildStepTools } from "../tools/index.js";
|
|
19
20
|
import { callPluginTool, spaceContextOf } from "../tools/plugin.js";
|
|
21
|
+
import { skillsBlock, skillsOf } from "../tools/skills.js";
|
|
20
22
|
import { personUploads } from "../tools/store.js";
|
|
21
23
|
import { runWidgetStep } from "../widgets/step.js";
|
|
22
24
|
import { decide } from "./decide.js";
|
|
23
25
|
import { prepareInputs } from "./prepare.js";
|
|
24
26
|
import { runSurfaceStep } from "./surface.js";
|
|
25
|
-
import { answersAsText, assetSectionLine, colorLine, factLines, logoSectionLine, renderTemplate, resolveRef, typeLines, } from "./template.js";
|
|
27
|
+
import { answersAsText, assetSectionLine, colorLine, factLines, logoSectionLine, renderTask, renderTemplate, resolveRef, typeLines, } from "./template.js";
|
|
26
28
|
import { StepError } from "./types.js";
|
|
27
29
|
/** Today's date as the wizard's people write it. */
|
|
28
30
|
function today(ctx) {
|
|
@@ -475,7 +477,11 @@ export async function runAgentStep(step, ctx) {
|
|
|
475
477
|
if (step.each) {
|
|
476
478
|
return runAgentEach(step, ctx);
|
|
477
479
|
}
|
|
478
|
-
const resolved = await textModel(step.model ?? "standard", {
|
|
480
|
+
const resolved = await textModel(textClassOf(step.model ?? "standard"), {
|
|
481
|
+
...ctx.call,
|
|
482
|
+
effort: step.effort,
|
|
483
|
+
makerClass: step.maker ? classIdOf(step, "standard") : undefined,
|
|
484
|
+
});
|
|
479
485
|
const uploads = await personUploads(ctx);
|
|
480
486
|
const { tools, assets, instructions } = await buildStepTools(step, ctx, resolved, uploads);
|
|
481
487
|
// A step without tools of its own and without uploads: the run's device may answer it alone.
|
|
@@ -497,6 +503,11 @@ export async function runAgentStep(step, ctx) {
|
|
|
497
503
|
brandBlock(ctx),
|
|
498
504
|
// Knowledge: what the space holds for its wizards, and how to find and read it.
|
|
499
505
|
await knowledgeBlock(ctx.project.id),
|
|
506
|
+
// Skills: always on whole, on demand by name and description (docs/plans/skills.md).
|
|
507
|
+
skillsBlock(await skillsOf(ctx), {
|
|
508
|
+
tools: takesTools(resolved),
|
|
509
|
+
sandbox: step.tools.includes("sandbox") && sandboxCapabilities() !== null,
|
|
510
|
+
}),
|
|
500
511
|
// What the space's plugins hold for its wizards: a wiki, questions and answers.
|
|
501
512
|
...(await spaceContextOf(ctx)).blocks,
|
|
502
513
|
formatHint,
|
|
@@ -504,7 +515,7 @@ export async function runAgentStep(step, ctx) {
|
|
|
504
515
|
.filter(Boolean)
|
|
505
516
|
.join("\n\n");
|
|
506
517
|
const request = [
|
|
507
|
-
`# TASK\n${
|
|
518
|
+
`# TASK\n${renderTask(step.instructions, ctx.scope)}`,
|
|
508
519
|
answersBlock(ctx),
|
|
509
520
|
photos.length
|
|
510
521
|
? prompt("step", "photos", {
|
|
@@ -750,6 +761,8 @@ async function writeHtml(step, ctx, kind) {
|
|
|
750
761
|
groundRules(ctx),
|
|
751
762
|
`Today is ${today(ctx)}.`,
|
|
752
763
|
brandBlock(ctx),
|
|
764
|
+
// The skills always on hold for what a step writes, a document too.
|
|
765
|
+
skillsBlock(await skillsOf(ctx), { tools: false }),
|
|
753
766
|
guide,
|
|
754
767
|
// What plugins hold for the space's look: a UI library, say.
|
|
755
768
|
...(await spaceContextOf(ctx)).html,
|
|
@@ -765,7 +778,11 @@ async function writeHtml(step, ctx, kind) {
|
|
|
765
778
|
const request = [`# BRIEF\n${brief}`, answersBlock(ctx), await revisionBlock(ctx, step.id)]
|
|
766
779
|
.filter(Boolean)
|
|
767
780
|
.join("\n\n");
|
|
768
|
-
const writer = await textModel(step.model ?? "standard", {
|
|
781
|
+
const writer = await textModel(textClassOf(step.model ?? "standard"), {
|
|
782
|
+
...ctx.call,
|
|
783
|
+
effort: step.effort,
|
|
784
|
+
makerClass: step.maker ? classIdOf(step, "standard") : undefined,
|
|
785
|
+
});
|
|
769
786
|
const result = await generateText({
|
|
770
787
|
model: writer.model,
|
|
771
788
|
system,
|
|
@@ -225,6 +225,23 @@ export function resolveRef(ref, scope) {
|
|
|
225
225
|
export function renderTemplate(template, scope) {
|
|
226
226
|
return template.replace(TEMPLATE_RE, (_m, ref) => stringify(resolveRef(ref.trim(), scope)));
|
|
227
227
|
}
|
|
228
|
+
const REFERENCE_KINDS = new Set(["image", "file", "signature"]);
|
|
229
|
+
/**
|
|
230
|
+
* A step's task with what the person typed marked as data: a field's value in `<data field="…">`,
|
|
231
|
+
* so a model tells the wizard's instructions from a visitor's words (prompts/step.md,
|
|
232
|
+
* ground_rules). Files and images stay names a tool reads; the rest as `renderTemplate`.
|
|
233
|
+
*/
|
|
234
|
+
export function renderTask(template, scope) {
|
|
235
|
+
return template.replace(TEMPLATE_RE, (_m, ref) => {
|
|
236
|
+
const value = stringify(resolveRef(ref.trim(), scope));
|
|
237
|
+
const head = ref.trim().split(".")[0];
|
|
238
|
+
const field = allFields(scope.def).find((f) => f.id === head);
|
|
239
|
+
if (!field || REFERENCE_KINDS.has(field.kind) || value === "") {
|
|
240
|
+
return value;
|
|
241
|
+
}
|
|
242
|
+
return `<data field="${head}">${value.replaceAll("</data>", "")}</data>`;
|
|
243
|
+
});
|
|
244
|
+
}
|
|
228
245
|
/** Everything the person entered so far, readable — handed to agents as data. */
|
|
229
246
|
export function answersAsText(scope) {
|
|
230
247
|
const lines = [];
|
|
@@ -77,6 +77,10 @@ export class HarnessModel {
|
|
|
77
77
|
nativeSchema = false;
|
|
78
78
|
/** Whether the client runs a call's tools (over the bridge); else they are left out, with a warning. */
|
|
79
79
|
usesTools = true;
|
|
80
|
+
/** The same, for whoever builds the call: a step tells such a client no tools exist. */
|
|
81
|
+
get takesTools() {
|
|
82
|
+
return this.usesTools;
|
|
83
|
+
}
|
|
80
84
|
/** Whether the client searches the web with a tool of its own, tools of the call or not. */
|
|
81
85
|
searchesWeb = true;
|
|
82
86
|
effort;
|
|
@@ -2,6 +2,7 @@ import { and, eq } from "drizzle-orm";
|
|
|
2
2
|
import { db, schema } from "./db/client.js";
|
|
3
3
|
import { env } from "./env.js";
|
|
4
4
|
import { escapeHtml } from "./render/convert.js";
|
|
5
|
+
import { guestRun } from "./safety.js";
|
|
5
6
|
import { sharedRun, shareView } from "./services/shares.js";
|
|
6
7
|
function tags(p) {
|
|
7
8
|
const t = [
|
|
@@ -32,6 +33,14 @@ export async function linkPreview(path) {
|
|
|
32
33
|
return null;
|
|
33
34
|
}
|
|
34
35
|
const view = await shareView(run);
|
|
36
|
+
// A guest's result stays private: the card names the wizard, never what it made.
|
|
37
|
+
if (guestRun(run)) {
|
|
38
|
+
return tags({
|
|
39
|
+
title: view.wizard.title,
|
|
40
|
+
description: view.wizard.description,
|
|
41
|
+
url: `${env.publicUrl}/s/${share[1]}`,
|
|
42
|
+
});
|
|
43
|
+
}
|
|
35
44
|
return tags({
|
|
36
45
|
title: view.title === view.wizard.title ? view.title : `${view.title} · ${view.wizard.title}`,
|
|
37
46
|
description: view.message ?? view.wizard.description,
|
|
@@ -116,6 +116,8 @@ const ITEM_VIEWS = {
|
|
|
116
116
|
const row = await db.query.projectFile.findFirst({ where: eq(schema.projectFile.id, x.item) });
|
|
117
117
|
return row ? fileView(row) : null;
|
|
118
118
|
},
|
|
119
|
+
// The studio asks for the space's skills again: a list of names, no view of its own.
|
|
120
|
+
skill: null,
|
|
119
121
|
connector: async (r, x) => {
|
|
120
122
|
if (!x.projectId) {
|
|
121
123
|
return null;
|
|
@@ -217,6 +217,31 @@ export async function tenantInfo(id, fresh = false) {
|
|
|
217
217
|
export function forgetTenant(id) {
|
|
218
218
|
tenants.delete(id);
|
|
219
219
|
}
|
|
220
|
+
/**
|
|
221
|
+
* Saves the organization's model policy for the admin who asks (`actorId`): the Manage-App checks
|
|
222
|
+
* their role and the plan's ways and answers with the policy as it stands now.
|
|
223
|
+
*/
|
|
224
|
+
export async function saveModelPolicy(tenantId, actorId, modelPolicy) {
|
|
225
|
+
const saved = await call("PUT", `${tenantPath(tenantId)}/model-policy`, { actorId, ...modelPolicy });
|
|
226
|
+
forgetTenant(tenantId);
|
|
227
|
+
return saved.modelPolicy;
|
|
228
|
+
}
|
|
229
|
+
/**
|
|
230
|
+
* Puts the organization on another tier its plan offers, for the admin who asks (`actorId`); the
|
|
231
|
+
* Manage-App refuses one a contract set.
|
|
232
|
+
*/
|
|
233
|
+
export async function saveModelTier(tenantId, actorId, tier) {
|
|
234
|
+
await call("PUT", `${tenantPath(tenantId)}/model-tier`, { actorId, tier });
|
|
235
|
+
forgetTenant(tenantId);
|
|
236
|
+
}
|
|
237
|
+
/** What a model would see of `text` with masking on: the labels given, else the saved ones. */
|
|
238
|
+
export async function tryMasking(tenantId, actorId, text, maskLabels) {
|
|
239
|
+
return call("POST", `${tenantPath(tenantId)}/model-policy/try`, {
|
|
240
|
+
actorId,
|
|
241
|
+
text,
|
|
242
|
+
...(maskLabels ? { maskLabels } : {}),
|
|
243
|
+
});
|
|
244
|
+
}
|
|
220
245
|
/** Renames the organization at the Manage-App; what it answers is the tenant as it stands now. */
|
|
221
246
|
export async function renameTenant(id, name) {
|
|
222
247
|
const value = await call("PATCH", `/v1/tenants/${encodeURIComponent(id)}`, {
|
|
@@ -1,14 +1,64 @@
|
|
|
1
1
|
import { createMcpHandler, McpServer, originValidationResponse, } from "@modelcontextprotocol/server";
|
|
2
2
|
import { withTenant } from "../db/client.js";
|
|
3
3
|
import { env } from "../env.js";
|
|
4
|
+
import { feature } from "../features.js";
|
|
4
5
|
import { nudge } from "../live/hub.js";
|
|
6
|
+
import { managed, tenantInfo } from "../manage.js";
|
|
5
7
|
import { prompt } from "../prompts.js";
|
|
6
8
|
import { asRole } from "../services/access.js";
|
|
7
9
|
import { tenantStatus } from "../tenants/control.js";
|
|
10
|
+
import { serverText } from "../texts.js";
|
|
8
11
|
import { authenticate, principalOf } from "./auth.js";
|
|
9
12
|
import { registerFlowApp } from "./flow-app.js";
|
|
10
|
-
import { noteRequest } from "./seen.js";
|
|
13
|
+
import { appKind, clientNameOf, noteChecked, noteRequest } from "./seen.js";
|
|
11
14
|
import { registerPrompts, registerTools } from "./tools.js";
|
|
15
|
+
/**
|
|
16
|
+
* An app the organization's model policy keeps out of its spaces (`modelPolicy.apps`): its tool
|
|
17
|
+
* calls are answered with a tool error the app shows, before any tool reads the space. Calls of
|
|
18
|
+
* other kinds (listing the tools) go on. Behind `modelTiers`. Best effort: an app is told apart
|
|
19
|
+
* by the name it gives itself, and any name not known as a local app's counts as a subscription.
|
|
20
|
+
*/
|
|
21
|
+
async function appRefusal(who, client, body) {
|
|
22
|
+
const calls = (Array.isArray(body) ? body : [body]).filter((m) => Boolean(m) && typeof m === "object" && m.method === "tools/call");
|
|
23
|
+
// A runtime that runs alone has no organization and no policy.
|
|
24
|
+
if (!calls.length || !managed) {
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
const info = await tenantInfo(who.tenantId).catch(() => null);
|
|
28
|
+
// When the Manage-App can't say what the policy allows, the app waits.
|
|
29
|
+
const policy = info && feature("modelTiers", info.features) ? info.modelPolicy : undefined;
|
|
30
|
+
if (info && !policy) {
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
const kind = appKind(client, who.client);
|
|
34
|
+
const allowed = policy
|
|
35
|
+
? kind === "local"
|
|
36
|
+
? policy.apps.local
|
|
37
|
+
: policy.apps.subscriptions
|
|
38
|
+
: false;
|
|
39
|
+
noteChecked(who.tenantId, client, who.name ?? who.email ?? null, allowed, kind);
|
|
40
|
+
if (allowed) {
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
const text = !info
|
|
44
|
+
? serverText("en", "appPolicyUnavailable", { app: client })
|
|
45
|
+
: kind === "local"
|
|
46
|
+
? serverText("en", "appLocalRefused", { organization: info.name, app: client })
|
|
47
|
+
: serverText("en", "appSubscriptionRefused", {
|
|
48
|
+
organization: info.name,
|
|
49
|
+
app: client,
|
|
50
|
+
tier: info.tier?.name ?? serverText("en", "appYourTier"),
|
|
51
|
+
});
|
|
52
|
+
const answers = calls.map((call) => ({
|
|
53
|
+
jsonrpc: "2.0",
|
|
54
|
+
id: call.id ?? null,
|
|
55
|
+
result: { content: [{ type: "text", text }], isError: true },
|
|
56
|
+
}));
|
|
57
|
+
return new Response(JSON.stringify(Array.isArray(body) ? answers : answers[0]), {
|
|
58
|
+
status: 200,
|
|
59
|
+
headers: { "content-type": "application/json" },
|
|
60
|
+
});
|
|
61
|
+
}
|
|
12
62
|
/** A wizard definition is a few KB; this leaves room and refuses anything far beyond it. */
|
|
13
63
|
const MAX_BODY_BYTES = 300_000;
|
|
14
64
|
/**
|
|
@@ -48,6 +98,10 @@ export function mcpHandler() {
|
|
|
48
98
|
.json()
|
|
49
99
|
.catch(() => null);
|
|
50
100
|
noteRequest(who.tenantId, authInfo.clientId, who.client, body);
|
|
101
|
+
const refused = await appRefusal(who, clientNameOf(authInfo.clientId, who.client), body);
|
|
102
|
+
if (refused) {
|
|
103
|
+
return refused;
|
|
104
|
+
}
|
|
51
105
|
}
|
|
52
106
|
const answer = await withTenant(who.tenantId, () => asRole(who.role, () => handler.fetch(request, { authInfo })));
|
|
53
107
|
if (request.method === "POST") {
|
|
@@ -63,3 +63,50 @@ export function seenApps(tenantId) {
|
|
|
63
63
|
}
|
|
64
64
|
return out;
|
|
65
65
|
}
|
|
66
|
+
/** The name a sign-in's client gave on `initialize`, else the one its sign-in carries. */
|
|
67
|
+
export function clientNameOf(signIn, client) {
|
|
68
|
+
return names.get(signIn) ?? client;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Apps whose model runs on the member's computer: what they read of a space stays there. Goose
|
|
72
|
+
* is not one: it mostly thinks on a provider's model.
|
|
73
|
+
*/
|
|
74
|
+
const LOCAL_APPS = new Set(["lm-studio"]);
|
|
75
|
+
/**
|
|
76
|
+
* Whether an app thinks on the member's computer (`local`) or on a provider under the member's
|
|
77
|
+
* own subscription, from every name it goes by (the one it gave on `initialize`, its sign-in's).
|
|
78
|
+
* It counts as local only where a name says so and none names another app; any other counts as
|
|
79
|
+
* one on a subscription.
|
|
80
|
+
*/
|
|
81
|
+
export function appKind(...names) {
|
|
82
|
+
const ids = names.flatMap(appIdsOf);
|
|
83
|
+
return ids.length && ids.every((id) => LOCAL_APPS.has(id)) ? "local" : "subscription";
|
|
84
|
+
}
|
|
85
|
+
const checked = new Map();
|
|
86
|
+
/** Counts one tool call of an app the policy allowed or refused. */
|
|
87
|
+
export function noteChecked(tenantId, app, person, allowed, kind) {
|
|
88
|
+
const key = `${tenantId}\n${app}\n${person ?? ""}`;
|
|
89
|
+
const last = checked.get(key) ?? {
|
|
90
|
+
app,
|
|
91
|
+
kind,
|
|
92
|
+
person,
|
|
93
|
+
allowed: 0,
|
|
94
|
+
refused: 0,
|
|
95
|
+
at: 0,
|
|
96
|
+
};
|
|
97
|
+
last.at = Date.now();
|
|
98
|
+
if (allowed) {
|
|
99
|
+
last.allowed++;
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
last.refused++;
|
|
103
|
+
}
|
|
104
|
+
checked.set(key, last);
|
|
105
|
+
}
|
|
106
|
+
/** The apps the tenant's members used on its spaces since the runtime started, latest first. */
|
|
107
|
+
export function checkedApps(tenantId) {
|
|
108
|
+
return [...checked]
|
|
109
|
+
.filter(([key]) => key.startsWith(`${tenantId}\n`))
|
|
110
|
+
.map(([, value]) => value)
|
|
111
|
+
.sort((a, b) => b.at - a.at);
|
|
112
|
+
}
|