@engenty/wizards-runtime 0.11.13 → 0.12.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/app.js +2 -0
- package/apps/runtime/dist/cli/account.js +1 -1
- package/apps/runtime/dist/cli/features.js +45 -2
- package/apps/runtime/dist/docs/dev/plugins/reference.md +3 -3
- package/apps/runtime/dist/docs/dev/plugins/studio.md +1 -1
- package/apps/runtime/dist/docs/user-guide/models.md +22 -2
- package/apps/runtime/dist/docs/user-guide/server.md +15 -2
- package/apps/runtime/dist/features.js +9 -0
- package/apps/runtime/dist/index.js +7 -0
- package/apps/runtime/dist/local-models.js +192 -0
- package/apps/runtime/dist/models.js +250 -75
- package/apps/runtime/dist/plugins/install.js +120 -0
- package/apps/runtime/dist/plugins/loader.js +33 -3
- package/apps/runtime/dist/plugins/pro.js +9 -9
- package/apps/runtime/dist/prompts/tools.md +1 -1
- package/apps/runtime/dist/routes/plugins.js +110 -2
- package/apps/runtime/dist/routes/runtime-settings.js +108 -0
- package/apps/runtime/dist/routes/studio.js +64 -2
- package/apps/runtime/dist/services/project-files.js +11 -1
- package/apps/runtime/dist/services/project-index.js +47 -4
- package/apps/runtime/dist/texts.js +4 -0
- package/apps/runtime/dist/update.js +10 -2
- package/apps/web/dist/assets/AboutDialog-BOJjBIYk.js +1 -0
- package/apps/web/dist/assets/{ChangelogDialog-Cxwkcjdy.js → ChangelogDialog-I9DEn_ra.js} +1 -1
- package/apps/web/dist/assets/{CodeEditor-BijLsoJX.js → CodeEditor-BgUofYLQ.js} +1 -1
- package/apps/web/dist/assets/EditorPage-DEOxHFXn.js +3 -0
- package/apps/web/dist/assets/{FlowPreview-Wjt28MdG.js → FlowPreview-C6DeATyk.js} +1 -1
- package/apps/web/dist/assets/{Marketplace-CpjRqTvn.js → Marketplace-Dt7ktvc3.js} +2 -2
- package/apps/web/dist/assets/{NewWizardChannels-CelW1MGq.js → NewWizardChannels-BrVFc6PV.js} +1 -1
- package/apps/web/dist/assets/{NewWizardPage-Coswm2WX.js → NewWizardPage-Dl8sMR2e.js} +1 -1
- package/apps/web/dist/assets/OnboardingPage-BN5IfLGL.js +1 -0
- package/apps/web/dist/assets/{PreviewPane-BUwlltqA.js → PreviewPane-BDzDuTz1.js} +5 -5
- package/apps/web/dist/assets/ProjectPage-BqkkyEpP.js +1 -0
- package/apps/web/dist/assets/PublicRunner-bAakEGwv.js +1 -0
- package/apps/web/dist/assets/{ReadOnly-DZMZPM-W.js → ReadOnly-MBVPGEhw.js} +1 -1
- package/apps/web/dist/assets/SettingsPage-DDe1BC-3.js +2 -0
- package/apps/web/dist/assets/SetupPage-CmTC9K8_.js +1 -0
- package/apps/web/dist/assets/{SharePage-DF8LO8-K.js → SharePage-D9_IxO3M.js} +1 -1
- package/apps/web/dist/assets/changelog-iTu1De5h.js +1 -0
- package/apps/web/dist/assets/i18n-7CvqRUdn.js +55 -0
- package/apps/web/dist/assets/index-CNwXyMzH.js +49 -0
- package/apps/web/dist/assets/index-Dxwbli0m.css +1 -0
- package/apps/web/dist/assets/{wrench-Dr19y-10.js → lock-D1093O6-.js} +1 -1
- package/apps/web/dist/assets/{phone-JGS60FQU.js → phone-YeDiW-kN.js} +1 -1
- package/apps/web/dist/assets/{runners-CwTP03YR.js → runners-DP0vYvTF.js} +1 -1
- package/apps/web/dist/assets/session-Bio3Vaq1.js +2 -0
- package/apps/web/dist/assets/{theme-D6QLPvJL.js → theme-AlaEfdLQ.js} +2 -2
- package/apps/web/dist/assets/{ui-Bhp_a_44.js → ui-CU-cIuyK.js} +2 -2
- package/apps/web/dist/assets/{upload-DPLDQsRT.js → upload-DbWtEr1f.js} +1 -1
- package/apps/web/dist/assets/{useMutation-Cmn8b7tT.js → useMutation-erJIov3t.js} +1 -1
- package/apps/web/dist/assets/{volume-2-DGqbhyPO.js → volume-2-V1P9DYWO.js} +1 -1
- package/apps/web/dist/index.html +8 -8
- package/apps/web/dist/manifest.webmanifest +1 -1
- package/apps/web/dist/mcp/flow.html +25 -25
- package/node_modules/@engenty/wizards/dist/plugin/studio.d.ts +1 -1
- package/node_modules/@engenty/wizards-shared/dist/feature-flags.d.ts +6 -0
- package/node_modules/@engenty/wizards-shared/dist/feature-flags.js +6 -0
- package/package.json +1 -1
- package/plugin/.claude-plugin/plugin.json +1 -1
- package/plugin/plugin.json +1 -1
- package/apps/web/dist/assets/AboutDialog-pMHleH_y.js +0 -1
- package/apps/web/dist/assets/EditorPage-v7cpENx3.js +0 -3
- package/apps/web/dist/assets/Harness-BrP-ENHg.css +0 -1
- package/apps/web/dist/assets/Harness-TUpGhGX5.js +0 -16
- package/apps/web/dist/assets/OnboardingPage-C9XM_VXs.js +0 -1
- package/apps/web/dist/assets/ProjectPage-Cw7hdXO6.js +0 -1
- package/apps/web/dist/assets/PublicRunner-B5RGNs07.js +0 -1
- package/apps/web/dist/assets/SettingsPage-CfL1e3Vs.js +0 -2
- package/apps/web/dist/assets/SetupPage-BRPenYa-.js +0 -1
- package/apps/web/dist/assets/changelog-CO6ysfQg.js +0 -1
- package/apps/web/dist/assets/i18n-BYeH2Dmi.js +0 -55
- package/apps/web/dist/assets/index-BYZBN0xx.css +0 -1
- package/apps/web/dist/assets/index-Bl7qOZv0.js +0 -34
- package/apps/web/dist/assets/session-CngLvd02.js +0 -2
- package/apps/web/dist/assets/settings-menu-C0yo5q3t.js +0 -1
|
@@ -11,7 +11,7 @@ import { blockingNeeds, CAPABILITY_CLASSES, creditsModelOf, isCreditsRef, missin
|
|
|
11
11
|
import { note, saidText } from "@engenty/wizards-shared/run";
|
|
12
12
|
import { generateSpeech, generateText, } from "ai";
|
|
13
13
|
import { accountToken, linkedAccount } from "./auth/account.js";
|
|
14
|
-
import { ollamaDecisionModel, ollamaRoot } from "./decision-model.js";
|
|
14
|
+
import { LOCAL_DECISION_MODEL, ollamaDecisionModel, ollamaRoot } from "./decision-model.js";
|
|
15
15
|
import { DeviceModel, deviceThinks } from "./engine/device.js";
|
|
16
16
|
import { env } from "./env.js";
|
|
17
17
|
import { appleModel, appleStatus, appleTranscriptionModel, appleUnavailableNote, } from "./harness/apple.js";
|
|
@@ -41,6 +41,25 @@ export { isHarnessVendor } from "./harness/index.js";
|
|
|
41
41
|
export { ModelUnavailableError } from "./model-errors.js";
|
|
42
42
|
// --- configuration -----------------------------------------------------------------
|
|
43
43
|
export const LOCAL_KEYS = PROVIDER_IDS;
|
|
44
|
+
/** The ways to an embedding model, in the order `auto` tries them. */
|
|
45
|
+
export const EMBEDDING_WAYS = ["gateway", "openai", "local", "credits"];
|
|
46
|
+
/**
|
|
47
|
+
* Who turns knowledge into vectors: the first embedding model at hand (`auto`), the one of one
|
|
48
|
+
* way, or none (`off`). Without one the search finds words, not meaning.
|
|
49
|
+
*/
|
|
50
|
+
export const EMBEDDING_CHOICES = ["auto", ...EMBEDDING_WAYS, "off"];
|
|
51
|
+
/**
|
|
52
|
+
* Google's EmbeddingGemma 2: open weights, about 1.3 GB in Ollama's library. Text, images and
|
|
53
|
+
* sound share one space; the index uses its text so far.
|
|
54
|
+
*/
|
|
55
|
+
export const LOCAL_EMBEDDING_MODEL = "embeddinggemma-2:740m";
|
|
56
|
+
/** The ways to a decision model, in the order `auto` tries them. */
|
|
57
|
+
export const DECISION_WAYS = ["gateway", "typesafe", "local", "credits"];
|
|
58
|
+
/**
|
|
59
|
+
* Who answers a decision: the first decision model at hand (`auto`), the one of one way, or none
|
|
60
|
+
* (`llm`). Where the chosen way has none, the classifier class's language model answers.
|
|
61
|
+
*/
|
|
62
|
+
export const DECISION_CHOICES = ["auto", ...DECISION_WAYS, "llm"];
|
|
44
63
|
const local = { settings: { source: "own", bindings: {} }, keys: {} };
|
|
45
64
|
function envKey(name) {
|
|
46
65
|
const value = {
|
|
@@ -122,6 +141,10 @@ export async function saveLocalModels(input) {
|
|
|
122
141
|
bindings: mergeBindings(local.settings.bindings, input.bindings),
|
|
123
142
|
ollamaUrl: input.ollamaUrl?.trim() || local.settings.ollamaUrl,
|
|
124
143
|
creditFallback: input.creditFallback ?? local.settings.creditFallback,
|
|
144
|
+
decision: input.decision ?? local.settings.decision,
|
|
145
|
+
decisionLocal: input.decisionLocal?.trim() || local.settings.decisionLocal,
|
|
146
|
+
embedding: input.embedding ?? local.settings.embedding,
|
|
147
|
+
embeddingLocal: input.embeddingLocal?.trim() || local.settings.embeddingLocal,
|
|
125
148
|
});
|
|
126
149
|
for (const [name, value] of Object.entries(input.keys ?? {})) {
|
|
127
150
|
if (value?.trim()) {
|
|
@@ -132,6 +155,7 @@ export async function saveLocalModels(input) {
|
|
|
132
155
|
}
|
|
133
156
|
}
|
|
134
157
|
await loadLocalModels();
|
|
158
|
+
forgetLocalModels();
|
|
135
159
|
}
|
|
136
160
|
/** An organization's keys and bindings on a runtime of a Manage-App. No client and no local model there. */
|
|
137
161
|
async function saveTenantModels(tenant, input) {
|
|
@@ -690,53 +714,152 @@ export async function listenerModel(meta = {}) {
|
|
|
690
714
|
}
|
|
691
715
|
return { kind: "chat", resolved: await textModel("audio", meta) };
|
|
692
716
|
}
|
|
693
|
-
/**
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
}
|
|
717
|
+
/** The embedding model Ollama is asked for: the setting, an `ollama:` MODEL_EMBEDDING, or EmbeddingGemma. */
|
|
718
|
+
function localEmbeddingName(cfg) {
|
|
719
|
+
const { provider, id } = parse(env.models.embedding);
|
|
720
|
+
return (cfg.settings.embeddingLocal ?? (provider === "ollama" ? id : null) ?? LOCAL_EMBEDDING_MODEL);
|
|
721
|
+
}
|
|
722
|
+
/** What the local Ollama held at the last look, by address and model, so a call does not ask it every time. */
|
|
723
|
+
const ollamaHeld = new Map();
|
|
724
|
+
/** Whether Ollama on this computer holds `name`, looked up once a minute. */
|
|
725
|
+
async function ollamaHolds(url, name) {
|
|
726
|
+
const key = `${url} ${name}`;
|
|
727
|
+
const hit = ollamaHeld.get(key);
|
|
728
|
+
if (hit && Date.now() < hit.at) {
|
|
729
|
+
return hit.there;
|
|
730
|
+
}
|
|
731
|
+
const there = await fetch(`${ollamaRoot(url)}/api/tags`, { signal: AbortSignal.timeout(1500) })
|
|
732
|
+
.then((res) => (res.ok ? res.json() : null))
|
|
733
|
+
.then((body) => (body?.models ?? []).some((m) => m.name === name || m.name === `${name}:latest`))
|
|
734
|
+
.catch(() => false);
|
|
735
|
+
ollamaHeld.set(key, { there, at: Date.now() + 60_000 });
|
|
736
|
+
return there;
|
|
737
|
+
}
|
|
738
|
+
/** Forgets what Ollama held: after a model was downloaded or removed (local-models.ts). */
|
|
739
|
+
export function forgetLocalModels() {
|
|
740
|
+
ollamaHeld.clear();
|
|
741
|
+
localDecision = null;
|
|
742
|
+
}
|
|
743
|
+
/** Where Ollama answers for this machine (…/v1), as the settings name it. */
|
|
744
|
+
export async function localOllamaUrl() {
|
|
745
|
+
return (await config()).settings.ollamaUrl ?? env.ollamaUrl;
|
|
746
|
+
}
|
|
747
|
+
/** The embedding model one way reaches; null where that way has none. */
|
|
748
|
+
async function embeddingBy(cfg, way, chosen) {
|
|
707
749
|
const ref = env.models.embedding;
|
|
708
750
|
const { provider, id, vendor } = parse(ref);
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
751
|
+
switch (way) {
|
|
752
|
+
case "gateway":
|
|
753
|
+
if (!cfg.keys.gateway) {
|
|
754
|
+
return null;
|
|
755
|
+
}
|
|
756
|
+
// The gateway names a model as `vendor/model`; an `ollama:` MODEL_EMBEDDING is not one.
|
|
757
|
+
return provider === null || provider === "gateway"
|
|
758
|
+
? { model: createGateway({ apiKey: cfg.keys.gateway }).embeddingModel(id), ref }
|
|
759
|
+
: {
|
|
760
|
+
model: createGateway({ apiKey: cfg.keys.gateway }).embeddingModel(DEFAULT_EMBEDDING),
|
|
761
|
+
ref: DEFAULT_EMBEDDING,
|
|
762
|
+
};
|
|
763
|
+
case "openai": {
|
|
764
|
+
if (!cfg.keys.openai) {
|
|
765
|
+
return null;
|
|
766
|
+
}
|
|
767
|
+
const own = provider === "openai" || vendor === "openai";
|
|
768
|
+
return {
|
|
769
|
+
model: createOpenAI({ apiKey: cfg.keys.openai }).embedding(own ? (provider ? id : aliasOf(id)) : aliasOf(DEFAULT_EMBEDDING)),
|
|
770
|
+
ref: own ? ref : DEFAULT_EMBEDDING,
|
|
771
|
+
};
|
|
772
|
+
}
|
|
773
|
+
case "local": {
|
|
774
|
+
const url = cfg.settings.ollamaUrl ?? env.ollamaUrl;
|
|
775
|
+
const name = localEmbeddingName(cfg);
|
|
776
|
+
if (!(await ollamaHolds(url, name))) {
|
|
777
|
+
return null;
|
|
778
|
+
}
|
|
779
|
+
const ollama = createOpenAI({ baseURL: url, apiKey: "ollama" });
|
|
780
|
+
return { model: ollama.embedding(name), ref: `ollama:${name}` };
|
|
781
|
+
}
|
|
782
|
+
default: {
|
|
783
|
+
const access = await creditAccess(cfg, chosen).catch(() => null);
|
|
784
|
+
const bound = access ? (await classCatalog())?.classes.embedding : null;
|
|
785
|
+
return access && bound
|
|
786
|
+
? {
|
|
787
|
+
model: gatewayClient(access, {}).embeddingModel("wizards/embedding"),
|
|
788
|
+
ref: bound.model,
|
|
789
|
+
}
|
|
790
|
+
: null;
|
|
791
|
+
}
|
|
715
792
|
}
|
|
716
|
-
|
|
717
|
-
|
|
793
|
+
}
|
|
794
|
+
/** OpenAI's small embedding model, as the AI Gateway names it: what a key gets without MODEL_EMBEDDING. */
|
|
795
|
+
const DEFAULT_EMBEDDING = "openai/text-embedding-3-small";
|
|
796
|
+
async function embeddingAccess(cfg) {
|
|
797
|
+
if (managed) {
|
|
798
|
+
const found = await embeddingBy(cfg, "credits", true);
|
|
799
|
+
return found ? { ...found, way: "credits" } : null;
|
|
718
800
|
}
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
ref,
|
|
723
|
-
};
|
|
801
|
+
const choice = cfg.settings.embedding ?? "auto";
|
|
802
|
+
if (choice === "off") {
|
|
803
|
+
return null;
|
|
724
804
|
}
|
|
725
|
-
//
|
|
726
|
-
const
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
805
|
+
// An `ollama:` MODEL_EMBEDDING asks for the model on this computer before any key.
|
|
806
|
+
const auto = parse(env.models.embedding).provider === "ollama"
|
|
807
|
+
? ["local", ...EMBEDDING_WAYS.filter((w) => w !== "local")]
|
|
808
|
+
: EMBEDDING_WAYS;
|
|
809
|
+
for (const way of choice === "auto" ? auto : [choice]) {
|
|
810
|
+
const found = await embeddingBy(cfg, way, choice !== "auto");
|
|
811
|
+
if (found) {
|
|
812
|
+
return { ...found, way };
|
|
813
|
+
}
|
|
814
|
+
}
|
|
815
|
+
return null;
|
|
816
|
+
}
|
|
817
|
+
/**
|
|
818
|
+
* The model that turns passages and questions into vectors for a project's document index: the
|
|
819
|
+
* credits on a Manage-App's runtime; alone, what the settings choose — by default an AI Gateway
|
|
820
|
+
* key, an OpenAI key, EmbeddingGemma in Ollama on this computer, then the linked account's
|
|
821
|
+
* credits. Null where none is set up — an installed AI client has no such model — and the
|
|
822
|
+
* index then works on keywords alone.
|
|
823
|
+
*/
|
|
824
|
+
export async function embeddingModel() {
|
|
825
|
+
const found = await embeddingAccess(await config());
|
|
826
|
+
return found ? { model: found.model, ref: found.ref } : null;
|
|
827
|
+
}
|
|
828
|
+
/**
|
|
829
|
+
* The search, for the settings page: the choice, which ways have an embedding model, and which
|
|
830
|
+
* one embeds now (null: the search finds words only).
|
|
831
|
+
*/
|
|
832
|
+
async function embeddingSettings(cfg) {
|
|
833
|
+
const ready = Object.fromEntries(await Promise.all(EMBEDDING_WAYS.map(async (way) => [
|
|
834
|
+
way,
|
|
835
|
+
managed ? way === "credits" : Boolean(await embeddingBy(cfg, way, false)),
|
|
836
|
+
])));
|
|
837
|
+
const now = await embeddingAccess(cfg);
|
|
838
|
+
return {
|
|
839
|
+
choice: managed ? "credits" : (cfg.settings.embedding ?? "auto"),
|
|
840
|
+
ready,
|
|
841
|
+
way: now?.way ?? null,
|
|
842
|
+
/** The model the vectors come from, as the index records it. */
|
|
843
|
+
ref: now?.ref ?? null,
|
|
844
|
+
/** The model asked for in Ollama on this computer. */
|
|
845
|
+
local: localEmbeddingName(cfg),
|
|
846
|
+
};
|
|
731
847
|
}
|
|
732
848
|
/** What the local Ollama held at the last look, so a decision does not ask it every time. */
|
|
733
849
|
let localDecision = null;
|
|
734
|
-
/**
|
|
735
|
-
|
|
850
|
+
/**
|
|
851
|
+
* The decision model in the local Ollama, looked up once a minute: the one the settings name,
|
|
852
|
+
* else Clef-flash (pulled by the setup) or Clef.
|
|
853
|
+
*/
|
|
854
|
+
async function localDecisionModel(url, named) {
|
|
736
855
|
if (localDecision?.url === url && Date.now() < localDecision.at) {
|
|
737
856
|
return localDecision.model;
|
|
738
857
|
}
|
|
739
|
-
const model =
|
|
858
|
+
const model = named
|
|
859
|
+
? (await ollamaHolds(url, named))
|
|
860
|
+
? named
|
|
861
|
+
: null
|
|
862
|
+
: await ollamaDecisionModel(url);
|
|
740
863
|
localDecision = { url, model, at: Date.now() + 60_000 };
|
|
741
864
|
return model;
|
|
742
865
|
}
|
|
@@ -755,15 +878,8 @@ function localModelRefused(url, status, body) {
|
|
|
755
878
|
console.warn(`[decide] the local decision model cannot run, left out for 10 minutes: ${body}`);
|
|
756
879
|
localDecision = { url, model: null, at: Date.now() + 10 * 60_000 };
|
|
757
880
|
}
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
* no text: the credits on a Manage-App's runtime; alone, TypeSafe's Jev through an AI Gateway
|
|
761
|
-
* key or a TypeSafe key, then Clef-flash in Ollama on this machine, then Jev on the linked
|
|
762
|
-
* account's credits. Null when there is none.
|
|
763
|
-
*/
|
|
764
|
-
export async function systemOneAccess() {
|
|
765
|
-
const cfg = await config();
|
|
766
|
-
const viaCredits = (access) => ({
|
|
881
|
+
function decisionViaCredits(access) {
|
|
882
|
+
return {
|
|
767
883
|
url: `${access.baseUrl}/v4/ai/systemone`,
|
|
768
884
|
headers: {
|
|
769
885
|
authorization: `Bearer ${access.token}`,
|
|
@@ -773,39 +889,94 @@ export async function systemOneAccess() {
|
|
|
773
889
|
...(access.tenant ? { "x-wizards-tenant": access.tenant } : {}),
|
|
774
890
|
},
|
|
775
891
|
model: null,
|
|
776
|
-
}
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
892
|
+
};
|
|
893
|
+
}
|
|
894
|
+
/** The decision model one way reaches; null where that way has none. */
|
|
895
|
+
async function decisionBy(cfg, way, chosen) {
|
|
896
|
+
switch (way) {
|
|
897
|
+
case "gateway":
|
|
898
|
+
return cfg.keys.gateway
|
|
899
|
+
? {
|
|
900
|
+
url: "https://ai-gateway.vercel.sh/typesafe/v1/systemone",
|
|
901
|
+
headers: { authorization: `Bearer ${cfg.keys.gateway}` },
|
|
902
|
+
model: "typesafe-ai/jev",
|
|
903
|
+
}
|
|
904
|
+
: null;
|
|
905
|
+
case "typesafe":
|
|
906
|
+
return env.typesafeKey
|
|
907
|
+
? {
|
|
908
|
+
url: "https://api.typesafe.ai/v1/systemone",
|
|
909
|
+
headers: { authorization: `Bearer ${env.typesafeKey}` },
|
|
910
|
+
model: "jev-latest",
|
|
911
|
+
}
|
|
912
|
+
: null;
|
|
913
|
+
case "local": {
|
|
914
|
+
const ollama = cfg.settings.ollamaUrl ?? env.ollamaUrl;
|
|
915
|
+
const model = await localDecisionModel(ollama, cfg.settings.decisionLocal);
|
|
916
|
+
return model
|
|
917
|
+
? {
|
|
918
|
+
url: `${ollamaRoot(ollama)}/v1/systemone`,
|
|
919
|
+
headers: {},
|
|
920
|
+
model,
|
|
921
|
+
local: true,
|
|
922
|
+
refused: (status, body) => localModelRefused(ollama, status, body),
|
|
923
|
+
}
|
|
924
|
+
: null;
|
|
925
|
+
}
|
|
926
|
+
default: {
|
|
927
|
+
const access = await creditAccess(cfg, chosen).catch(() => null);
|
|
928
|
+
return access ? decisionViaCredits(access) : null;
|
|
929
|
+
}
|
|
780
930
|
}
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
931
|
+
}
|
|
932
|
+
/**
|
|
933
|
+
* The way to a decision model, one that answers typed questions with probabilities and writes
|
|
934
|
+
* no text: the credits on a Manage-App's runtime; alone, what the settings choose — by default
|
|
935
|
+
* TypeSafe's Jev through an AI Gateway key or a TypeSafe key, then Clef-flash in Ollama on this
|
|
936
|
+
* machine (free, and nothing leaves it), then Jev on the linked account's credits. Null when
|
|
937
|
+
* there is none: the classifier class's language model answers then.
|
|
938
|
+
*/
|
|
939
|
+
export async function systemOneAccess() {
|
|
940
|
+
return (await decisionAccess(await config()))?.access ?? null;
|
|
941
|
+
}
|
|
942
|
+
async function decisionAccess(cfg) {
|
|
943
|
+
if (managed) {
|
|
944
|
+
const access = await decisionBy(cfg, "credits", true);
|
|
945
|
+
return access ? { way: "credits", access } : null;
|
|
787
946
|
}
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
headers: { authorization: `Bearer ${env.typesafeKey}` },
|
|
792
|
-
model: "jev-latest",
|
|
793
|
-
};
|
|
947
|
+
const choice = cfg.settings.decision ?? "auto";
|
|
948
|
+
if (choice === "llm") {
|
|
949
|
+
return null;
|
|
794
950
|
}
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
url: `${ollamaRoot(ollama)}/v1/systemone`,
|
|
801
|
-
headers: {},
|
|
802
|
-
model: local,
|
|
803
|
-
local: true,
|
|
804
|
-
refused: (status, body) => localModelRefused(ollama, status, body),
|
|
805
|
-
};
|
|
951
|
+
for (const way of choice === "auto" ? DECISION_WAYS : [choice]) {
|
|
952
|
+
const access = await decisionBy(cfg, way, choice !== "auto");
|
|
953
|
+
if (access) {
|
|
954
|
+
return { way, access };
|
|
955
|
+
}
|
|
806
956
|
}
|
|
807
|
-
|
|
808
|
-
|
|
957
|
+
return null;
|
|
958
|
+
}
|
|
959
|
+
/**
|
|
960
|
+
* Decisions, for the settings page: the choice, which ways have a decision model, and which one
|
|
961
|
+
* answers now (null: the classifier class's language model).
|
|
962
|
+
*/
|
|
963
|
+
async function decisionSettings(cfg) {
|
|
964
|
+
const ready = Object.fromEntries(await Promise.all(DECISION_WAYS.map(async (way) => [
|
|
965
|
+
way,
|
|
966
|
+
managed ? way === "credits" : Boolean(await decisionBy(cfg, way, false)),
|
|
967
|
+
])));
|
|
968
|
+
const now = await decisionAccess(cfg);
|
|
969
|
+
return {
|
|
970
|
+
choice: managed ? "credits" : (cfg.settings.decision ?? "auto"),
|
|
971
|
+
ready,
|
|
972
|
+
way: now?.way ?? null,
|
|
973
|
+
/** The model it names; null: the credits pick it. */
|
|
974
|
+
model: now?.access.model ?? null,
|
|
975
|
+
/** The decision model asked for in Ollama on this computer. */
|
|
976
|
+
local: cfg.settings.decisionLocal ??
|
|
977
|
+
(managed ? null : await ollamaDecisionModel(cfg.settings.ollamaUrl ?? env.ollamaUrl)) ??
|
|
978
|
+
LOCAL_DECISION_MODEL,
|
|
979
|
+
};
|
|
809
980
|
}
|
|
810
981
|
/** Search tools an AI Gateway runs itself; they travel in the request, so any gateway client names them. */
|
|
811
982
|
export const gatewayTools = createGateway({ apiKey: "unused" }).tools;
|
|
@@ -1064,6 +1235,10 @@ export async function modelSettings(lang = "en") {
|
|
|
1064
1235
|
creditFallback: cfg.settings.creditFallback !== false,
|
|
1065
1236
|
keys: Object.fromEntries(LOCAL_KEYS.map((k) => [k, Boolean(cfg.keys[k])])),
|
|
1066
1237
|
ways: waysIn(ways, lang),
|
|
1238
|
+
/** Who answers decisions; where no decision model does, the classifier class's way. */
|
|
1239
|
+
decision: await decisionSettings(cfg),
|
|
1240
|
+
/** Who embeds knowledge for the search; null way: words only. */
|
|
1241
|
+
embedding: await embeddingSettings(cfg),
|
|
1067
1242
|
/** Per text class, what of its minimums its model lacks (`CLASS_NEEDS`); null: not checked. */
|
|
1068
1243
|
fit: classFit(ways),
|
|
1069
1244
|
/** Apple Intelligence on this Mac: shown where the machine can run it, picked once it answers. */
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { randomBytes } from "node:crypto";
|
|
2
|
+
import { existsSync } from "node:fs";
|
|
3
|
+
import { mkdir, readdir, readFile, rename, rm, stat, writeFile } from "node:fs/promises";
|
|
4
|
+
import { homedir } from "node:os";
|
|
5
|
+
import { dirname, join, relative, resolve } from "node:path";
|
|
6
|
+
import { PLUGIN_ID } from "@engenty/wizards-shared/definition";
|
|
7
|
+
import { managed } from "../manage.js";
|
|
8
|
+
import { MANIFEST_FILE } from "./discovery.js";
|
|
9
|
+
import { foundPlugins, installedPluginsDir, pluginOff, pluginProblems, reloadPlugin, setPluginOn, } from "./loader.js";
|
|
10
|
+
import { filesOf, ProModuleError } from "./pro.js";
|
|
11
|
+
/*
|
|
12
|
+
* Plugins someone installs in Settings › Plugins on a runtime that runs alone: a zip or a folder
|
|
13
|
+
* of this computer, copied to `<DATA_DIR>/plugins/<id>/`. Nobody checked them: the studio says so
|
|
14
|
+
* before it installs one. A plugin holds its manifest, `dist/` and `migrations/`, as a Pro
|
|
15
|
+
* plugin's package does; its server half comes built.
|
|
16
|
+
*/
|
|
17
|
+
/** Larger packages are refused before they are read. */
|
|
18
|
+
export const MAX_PLUGIN = 30 * 1024 * 1024;
|
|
19
|
+
/** What a plugin may hold, besides its manifest. */
|
|
20
|
+
const PARTS = ["dist/", "migrations/"];
|
|
21
|
+
/** Installs a plugin from a zip; answers its id. */
|
|
22
|
+
export async function installPluginZip(zip) {
|
|
23
|
+
if (zip.length > MAX_PLUGIN) {
|
|
24
|
+
throw new ProModuleError("The package is too large.", 400);
|
|
25
|
+
}
|
|
26
|
+
return put(filesOf(zip, 400));
|
|
27
|
+
}
|
|
28
|
+
/** Installs a copy of a plugin folder on this computer; answers its id. */
|
|
29
|
+
export async function installPluginFolder(path) {
|
|
30
|
+
const root = resolve(path.replace(/^~(?=$|[/\\])/, homedir()));
|
|
31
|
+
if (!existsSync(join(root, MANIFEST_FILE))) {
|
|
32
|
+
throw new ProModuleError(`There is no ${MANIFEST_FILE} in this folder.`, 400, "no_plugin");
|
|
33
|
+
}
|
|
34
|
+
const files = {};
|
|
35
|
+
let size = 0;
|
|
36
|
+
const walk = async (dir) => {
|
|
37
|
+
for (const entry of await readdir(dir, { withFileTypes: true })) {
|
|
38
|
+
const full = join(dir, entry.name);
|
|
39
|
+
const name = relative(root, full).split("\\").join("/");
|
|
40
|
+
if (entry.isDirectory()) {
|
|
41
|
+
if (PARTS.some((part) => `${name}/`.startsWith(part) || part.startsWith(`${name}/`))) {
|
|
42
|
+
await walk(full);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
else if (entry.isFile() &&
|
|
46
|
+
(name === MANIFEST_FILE || PARTS.some((part) => name.startsWith(part)))) {
|
|
47
|
+
size += (await stat(full)).size;
|
|
48
|
+
if (size > MAX_PLUGIN) {
|
|
49
|
+
throw new ProModuleError("The plugin is too large.", 400);
|
|
50
|
+
}
|
|
51
|
+
files[name] = new Uint8Array(await readFile(full));
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
await walk(root);
|
|
56
|
+
return put(files);
|
|
57
|
+
}
|
|
58
|
+
/** Its files in place of the old ones, then it loads; a plugin that does not load is taken out again. */
|
|
59
|
+
async function put(files) {
|
|
60
|
+
if (managed) {
|
|
61
|
+
throw new ProModuleError("Not available here.", 404, "not_found");
|
|
62
|
+
}
|
|
63
|
+
let id;
|
|
64
|
+
try {
|
|
65
|
+
id = JSON.parse(new TextDecoder().decode(files[MANIFEST_FILE] ?? new Uint8Array()))?.id;
|
|
66
|
+
}
|
|
67
|
+
catch {
|
|
68
|
+
id = null;
|
|
69
|
+
}
|
|
70
|
+
if (typeof id !== "string" || !PLUGIN_ID.test(id)) {
|
|
71
|
+
throw new ProModuleError(`The plugin has no valid ${MANIFEST_FILE}.`, 400, "no_plugin");
|
|
72
|
+
}
|
|
73
|
+
const dir = installedPluginsDir();
|
|
74
|
+
const target = join(dir, id);
|
|
75
|
+
const other = foundPlugins().find((s) => s.id === id && dirname(s.root) !== dir);
|
|
76
|
+
if (other) {
|
|
77
|
+
throw new ProModuleError(`A plugin “${id}” is already there: ${other.root}.`, 409, "taken");
|
|
78
|
+
}
|
|
79
|
+
const fresh = join(dir, `.new-${id}-${randomBytes(4).toString("hex")}`);
|
|
80
|
+
const old = join(dir, `.old-${id}-${randomBytes(4).toString("hex")}`);
|
|
81
|
+
await mkdir(fresh, { recursive: true });
|
|
82
|
+
try {
|
|
83
|
+
for (const [path, data] of Object.entries(files)) {
|
|
84
|
+
await mkdir(dirname(join(fresh, path)), { recursive: true });
|
|
85
|
+
await writeFile(join(fresh, path), data);
|
|
86
|
+
}
|
|
87
|
+
if (existsSync(target)) {
|
|
88
|
+
await rename(target, old);
|
|
89
|
+
}
|
|
90
|
+
await rename(fresh, target);
|
|
91
|
+
}
|
|
92
|
+
finally {
|
|
93
|
+
await rm(fresh, { recursive: true, force: true });
|
|
94
|
+
await rm(old, { recursive: true, force: true });
|
|
95
|
+
}
|
|
96
|
+
// Installing it again switches it on.
|
|
97
|
+
if (pluginOff(id)) {
|
|
98
|
+
await setPluginOn(id, true);
|
|
99
|
+
}
|
|
100
|
+
const loaded = await reloadPlugin(id);
|
|
101
|
+
if (!loaded) {
|
|
102
|
+
const problem = pluginProblems().find((p) => p.path.startsWith(target));
|
|
103
|
+
await rm(target, { recursive: true, force: true });
|
|
104
|
+
await reloadPlugin(id);
|
|
105
|
+
throw new ProModuleError(problem ? problem.message : "The plugin did not load.", 400, "not_loaded");
|
|
106
|
+
}
|
|
107
|
+
return id;
|
|
108
|
+
}
|
|
109
|
+
/** Whether a plugin was installed here, so Settings › Plugins may remove it. */
|
|
110
|
+
export function installedHere(id) {
|
|
111
|
+
return foundPlugins().some((s) => s.id === id && dirname(s.root) === installedPluginsDir());
|
|
112
|
+
}
|
|
113
|
+
/** Removes a plugin installed here; its tables and what is in them stay. */
|
|
114
|
+
export async function removeInstalledPlugin(id) {
|
|
115
|
+
if (!installedHere(id)) {
|
|
116
|
+
throw new ProModuleError("This plugin was not installed here.", 404, "not_found");
|
|
117
|
+
}
|
|
118
|
+
await rm(join(installedPluginsDir(), id), { recursive: true, force: true });
|
|
119
|
+
await reloadPlugin(id);
|
|
120
|
+
}
|
|
@@ -19,6 +19,7 @@ import { conversationAccess, ModelUnavailableError, textModel } from "../models.
|
|
|
19
19
|
import { seal, unseal } from "../secrets/crypto.js";
|
|
20
20
|
import { putIndexEntry, removeIndexEntries } from "../services/project-index.js";
|
|
21
21
|
import { originData } from "../services/space-origin.js";
|
|
22
|
+
import { readSetting, writeSetting } from "../settings.js";
|
|
22
23
|
import { safeFetch } from "../tools/net-guard.js";
|
|
23
24
|
import { channelsApi } from "./channels.js";
|
|
24
25
|
import { claimsApiFor } from "./claims.js";
|
|
@@ -34,9 +35,36 @@ import { runsApiFor } from "./runs.js";
|
|
|
34
35
|
* imports of the runtime's own packages comes from the runtime's copies, wherever the plugin's
|
|
35
36
|
* file lies.
|
|
36
37
|
*/
|
|
37
|
-
/**
|
|
38
|
+
/** Where Settings › Plugins puts the plugins someone installs here (plugins/install.ts). */
|
|
39
|
+
export const installedPluginsDir = () => join(env.dataDir, "plugins");
|
|
40
|
+
/** What ships with this runtime, then the folders of `PLUGINS_DIR`, then what was installed here. */
|
|
38
41
|
export function pluginDirs() {
|
|
39
|
-
return [join(packageRoot, "modules"), ...env.plugins.dirs];
|
|
42
|
+
return [join(packageRoot, "modules"), ...env.plugins.dirs, installedPluginsDir()];
|
|
43
|
+
}
|
|
44
|
+
/** The plugins switched off in Settings › Plugins: found, not loaded. */
|
|
45
|
+
const OFF = "plugins-off";
|
|
46
|
+
let off = new Set();
|
|
47
|
+
/** Everything the last look found, the switched-off ones too. */
|
|
48
|
+
let lastFound = [];
|
|
49
|
+
/** Everything found, switched off or not, as of the last look. */
|
|
50
|
+
export function foundPlugins() {
|
|
51
|
+
return lastFound;
|
|
52
|
+
}
|
|
53
|
+
export function pluginOff(id) {
|
|
54
|
+
return off.has(id);
|
|
55
|
+
}
|
|
56
|
+
/** Switches a plugin on or off: off it unloads and its files and tables stay; on it loads again. */
|
|
57
|
+
export async function setPluginOn(id, on) {
|
|
58
|
+
const next = new Set(off);
|
|
59
|
+
if (on) {
|
|
60
|
+
next.delete(id);
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
next.add(id);
|
|
64
|
+
}
|
|
65
|
+
off = next;
|
|
66
|
+
await writeSetting(OFF, [...next].sort());
|
|
67
|
+
await findNewPlugins();
|
|
40
68
|
}
|
|
41
69
|
const own = (specifier) => fileURLToPath(import.meta.resolve(specifier));
|
|
42
70
|
/**
|
|
@@ -358,7 +386,8 @@ function discover() {
|
|
|
358
386
|
for (const problem of problems) {
|
|
359
387
|
console.error(`[plugins] ${problem.path}: ${problem.message}`);
|
|
360
388
|
}
|
|
361
|
-
|
|
389
|
+
lastFound = [...result.found, ...allowed.load];
|
|
390
|
+
return lastFound.filter((source) => !off.has(source.id));
|
|
362
391
|
}
|
|
363
392
|
/** One load at a time: the watcher and a person may ask for a reload at the same moment. */
|
|
364
393
|
let queue = Promise.resolve();
|
|
@@ -376,6 +405,7 @@ export function loadPlugins() {
|
|
|
376
405
|
// A plugin whose tables cannot be made must not keep the tenant's database from opening.
|
|
377
406
|
onTenantOpen((tenantId, client) => migratePlugins(tenantId, client).catch((err) => console.error(`[plugins] tables for tenant ${tenantId}:`, err.message)));
|
|
378
407
|
}
|
|
408
|
+
off = new Set((await readSetting(OFF)) ?? []);
|
|
379
409
|
const found = discover();
|
|
380
410
|
for (const source of found) {
|
|
381
411
|
await load(source);
|
|
@@ -170,14 +170,14 @@ async function updateInstalled() {
|
|
|
170
170
|
}
|
|
171
171
|
}
|
|
172
172
|
}
|
|
173
|
-
/** The files of a zip, refusing any that would land outside the
|
|
174
|
-
function filesOf(zip) {
|
|
173
|
+
/** The files of a zip, refusing any that would land outside the plugin's folder. */
|
|
174
|
+
export function filesOf(zip, status = 502) {
|
|
175
175
|
let files;
|
|
176
176
|
try {
|
|
177
177
|
files = unzipSync(zip);
|
|
178
178
|
}
|
|
179
179
|
catch {
|
|
180
|
-
throw new ProModuleError("The package is damaged.",
|
|
180
|
+
throw new ProModuleError("The package is damaged.", status);
|
|
181
181
|
}
|
|
182
182
|
const out = {};
|
|
183
183
|
for (const [name, data] of Object.entries(files)) {
|
|
@@ -188,7 +188,7 @@ function filesOf(zip) {
|
|
|
188
188
|
const safe = parts.every((p) => p && p !== "." && p !== ".." && !p.includes("\\"));
|
|
189
189
|
const allowed = name === MANIFEST_FILE || PARTS.some((part) => name.startsWith(part));
|
|
190
190
|
if (!(safe && allowed)) {
|
|
191
|
-
throw new ProModuleError(`The package holds a file it may not: ${name}`,
|
|
191
|
+
throw new ProModuleError(`The package holds a file it may not: ${name}`, status);
|
|
192
192
|
}
|
|
193
193
|
out[name] = data;
|
|
194
194
|
}
|
|
@@ -208,14 +208,14 @@ export async function installPro(id) {
|
|
|
208
208
|
}
|
|
209
209
|
const entry = listing?.modules.find((m) => m.id === id);
|
|
210
210
|
if (!entry) {
|
|
211
|
-
throw new ProModuleError(`There is no build of this
|
|
211
|
+
throw new ProModuleError(`There is no build of this plugin for ${runtimeTag()}.`, 404, "not_found");
|
|
212
212
|
}
|
|
213
213
|
if (!entry.included) {
|
|
214
|
-
throw new ProModuleError("This
|
|
214
|
+
throw new ProModuleError("This plugin is not part of your plan.", 403, "plan");
|
|
215
215
|
}
|
|
216
216
|
const res = await call(`/${encodeURIComponent(id)}/package`, token);
|
|
217
217
|
if (!res.ok) {
|
|
218
|
-
throw new ProModuleError(`The
|
|
218
|
+
throw new ProModuleError(`The plugin could not be fetched (${res.status}).`, 502);
|
|
219
219
|
}
|
|
220
220
|
if (Number(res.headers.get("content-length") ?? 0) > MAX_PACKAGE) {
|
|
221
221
|
throw new ProModuleError("The package is too large.", 502);
|
|
@@ -236,7 +236,7 @@ export async function installPro(id) {
|
|
|
236
236
|
const files = filesOf(zip);
|
|
237
237
|
const manifest = JSON.parse(new TextDecoder().decode(files[MANIFEST_FILE] ?? new Uint8Array()));
|
|
238
238
|
if (manifest?.id !== id) {
|
|
239
|
-
throw new ProModuleError("The package does not belong to this
|
|
239
|
+
throw new ProModuleError("The package does not belong to this plugin.", 502);
|
|
240
240
|
}
|
|
241
241
|
const dir = proModulesDir();
|
|
242
242
|
const target = join(dir, id);
|
|
@@ -270,7 +270,7 @@ export async function installPro(id) {
|
|
|
270
270
|
/** Removes an installed module; its tables and what is in them stay. */
|
|
271
271
|
export async function removePro(id) {
|
|
272
272
|
if (managed || !(await installedIds()).includes(id)) {
|
|
273
|
-
throw new ProModuleError("This
|
|
273
|
+
throw new ProModuleError("This plugin is not installed.", 404, "not_found");
|
|
274
274
|
}
|
|
275
275
|
await rm(join(proModulesDir(), id), { recursive: true, force: true });
|
|
276
276
|
await findNewPlugins();
|
|
@@ -112,7 +112,7 @@ Write a page of this wizard in Markdown, kept for every later run and shown to t
|
|
|
112
112
|
<!-- Knowledge (tools/project.ts) -->
|
|
113
113
|
|
|
114
114
|
<!-- section: tool.project_search -->
|
|
115
|
-
Search the space's Knowledge: its pages, tables and files, and what its plugins keep (wiki pages, questions and answers). Gives items with their path, categories and best section, each checked for relevance. Ask in their language, with the words they would use; filter with `where` when the task names a category's value. Then read the items you need whole with page_read or table_read.
|
|
115
|
+
Search the space's Knowledge: its pages, tables and files, its images, videos and sounds by their description, and what its plugins keep (wiki pages, questions and answers). Gives items with their path, categories and best section, each checked for relevance. Ask in their language, with the words they would use; filter with `where` when the task names a category's value. Then read the items you need whole with page_read or table_read.
|
|
116
116
|
|
|
117
117
|
<!-- The `where` input of project_search and project_list. -->
|
|
118
118
|
<!-- section: tool.project.where -->
|