@engenty/wizards-runtime 0.9.6 → 0.9.7
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/architect.js +2 -2
- package/apps/runtime/dist/agents/chat-clients.js +299 -0
- package/apps/runtime/dist/agents/company.js +111 -0
- package/apps/runtime/dist/agents/studio-assistant.js +8 -4
- package/apps/runtime/dist/agents/subscription.js +163 -134
- package/apps/runtime/dist/agents/website.js +571 -53
- package/apps/runtime/dist/app.js +6 -3
- package/apps/runtime/dist/assistant/knows.js +5 -5
- package/apps/runtime/dist/assistant/primer.js +3 -3
- package/apps/runtime/dist/auth/account.js +12 -12
- package/apps/runtime/dist/auth/keys.js +18 -8
- package/apps/runtime/dist/cli/account.js +20 -18
- package/apps/runtime/dist/cli/features.js +3 -3
- package/apps/runtime/dist/cli/ui.js +6 -0
- package/apps/runtime/dist/db/schema.js +1 -1
- package/apps/runtime/dist/docs/dev/plugins/index.md +1 -1
- package/apps/runtime/dist/docs/dev/plugins/server.md +2 -2
- package/apps/runtime/dist/docs/dev/plugins/studio.md +1 -1
- package/apps/runtime/dist/docs/user-guide/ai-apps.md +1 -1
- package/apps/runtime/dist/docs/user-guide/command-line.md +1 -1
- package/apps/runtime/dist/docs/user-guide/create-account.md +6 -6
- package/apps/runtime/dist/docs/user-guide/first-start.md +1 -1
- package/apps/runtime/dist/docs/user-guide/index.md +5 -5
- package/apps/runtime/dist/docs/user-guide/models.md +14 -8
- package/apps/runtime/dist/docs/user-guide/space.md +1 -1
- package/apps/runtime/dist/features.js +4 -4
- package/apps/runtime/dist/harness/cursor.js +4 -0
- package/apps/runtime/dist/manage.js +4 -4
- package/apps/runtime/dist/mcp/auth.js +1 -1
- package/apps/runtime/dist/models.js +75 -5
- package/apps/runtime/dist/routes/lang.js +13 -4
- package/apps/runtime/dist/routes/runs.js +1 -1
- package/apps/runtime/dist/routes/studio.js +66 -37
- package/apps/runtime/dist/services/access.js +3 -3
- package/apps/runtime/dist/services/architect.js +4 -2
- package/apps/runtime/dist/services/assistant-chats.js +10 -1
- package/apps/runtime/dist/services/onboarding.js +268 -48
- package/apps/runtime/dist/services/pages.js +17 -15
- package/apps/runtime/dist/services/wizards.js +2 -2
- package/apps/runtime/dist/texts.js +42 -8
- package/apps/web/dist/assets/{AboutDialog-CZr1JFvY.js → AboutDialog-B3tljxg5.js} +1 -1
- package/apps/web/dist/assets/{ChangelogDialog-0pKHVdhu.js → ChangelogDialog-DfWTNzyl.js} +1 -1
- package/apps/web/dist/assets/EditorPage-XDdz2UM4.js +4 -0
- package/apps/web/dist/assets/{FlowPreview-BZZvY5U9.js → FlowPreview-CKNVCFbp.js} +1 -1
- package/apps/web/dist/assets/{Harness-DPRw6BmX.js → Harness-BCec49Cq.js} +2 -2
- package/apps/web/dist/assets/Marketplace-BuYeaxK2.js +2 -0
- package/apps/web/dist/assets/{NewWizardChannels-K5vfNzaC.js → NewWizardChannels-DRNji-bk.js} +1 -1
- package/apps/web/dist/assets/NewWizardPage-4TpgYOaI.js +7 -0
- package/apps/web/dist/assets/OnboardingPage-Cf52NOIt.js +1 -0
- package/apps/web/dist/assets/PreviewPane-C4yMcZPM.js +4 -0
- package/apps/web/dist/assets/ProjectPage-D6Tah3QK.js +1 -0
- package/apps/web/dist/assets/{PublicRunner-_N7DyvWj.js → PublicRunner-Bftc1c4m.js} +1 -1
- package/apps/web/dist/assets/{ReadOnly-CQ8lWsnZ.js → ReadOnly-DVQm9IYx.js} +1 -1
- package/apps/web/dist/assets/SettingsPage-Cd-osLDu.js +2 -0
- package/apps/web/dist/assets/SetupPage-Dc8U5k5P.js +1 -0
- package/apps/web/dist/assets/{SharePage-BXkykFJC.js → SharePage-Cn-bqSyr.js} +1 -1
- package/apps/web/dist/assets/changelog-CjSBB-a4.js +1 -0
- package/apps/web/dist/assets/{coins-Bo9_D-7S.js → coins-DgDTBbeg.js} +1 -1
- package/apps/web/dist/assets/index-DS3zUVw_.css +1 -0
- package/apps/web/dist/assets/index-Da7hPToW.js +14 -0
- package/apps/web/dist/assets/{phone-BPybLMSm.js → phone-D1Drdiio.js} +1 -1
- package/apps/web/dist/assets/{runners-53tvGeez.js → runners-CTd0YAiA.js} +1 -1
- package/apps/web/dist/assets/{session-DvW7auj-.js → session-DX2BcTfz.js} +1 -1
- package/apps/web/dist/assets/{settings-menu-tSPDYTfT.js → settings-menu-ay9jNbQu.js} +1 -1
- package/apps/web/dist/assets/theme-DanjuO1H.js +11 -0
- package/apps/web/dist/assets/ui-CJCF3Mhe.js +137 -0
- package/apps/web/dist/assets/{upload-Ct_-rz05.js → upload-Dj7KPL--.js} +1 -1
- package/apps/web/dist/assets/{useMutation-DM9Anfo-.js → useMutation-CUSQpD-i.js} +1 -1
- package/apps/web/dist/assets/{volume-2-CHuzf68z.js → volume-2-CcHZOU2m.js} +1 -1
- package/apps/web/dist/assets/{wrench-BAgonupx.js → wrench-CfJTFnMJ.js} +1 -1
- package/apps/web/dist/index.html +8 -8
- package/apps/web/dist/mcp/flow.html +56 -56
- package/node_modules/@engenty/wizards/dist/plugin/studio.d.ts +1 -1
- package/node_modules/@engenty/wizards-shared/dist/assistant.d.ts +6 -0
- package/node_modules/@engenty/wizards-shared/dist/assistant.js +2 -0
- package/node_modules/@engenty/wizards-shared/dist/definition.d.ts +4 -0
- package/node_modules/@engenty/wizards-shared/dist/definition.js +9 -0
- package/node_modules/@engenty/wizards-shared/dist/feature-flags.d.ts +5 -5
- package/node_modules/@engenty/wizards-shared/dist/feature-flags.js +5 -5
- package/node_modules/@engenty/wizards-shared/dist/features.d.ts +1 -1
- package/node_modules/@engenty/wizards-shared/dist/features.js +1 -1
- package/node_modules/@engenty/wizards-shared/dist/projects.d.ts +1 -1
- package/node_modules/@engenty/wizards-shared/dist/projects.js +2 -2
- package/node_modules/@engenty/wizards-shared/dist/providers.d.ts +1 -1
- package/node_modules/@engenty/wizards-shared/dist/providers.js +1 -1
- package/node_modules/@engenty/wizards-shared/dist/run.d.ts +2 -2
- package/node_modules/@engenty/wizards-shared/dist/run.js +4 -4
- package/package.json +1 -1
- package/plugin/.claude-plugin/plugin.json +1 -1
- package/plugin/plugin.json +1 -1
- package/apps/web/dist/assets/EditorPage-_qnWDno2.js +0 -4
- package/apps/web/dist/assets/Marketplace-BwbLRU2n.js +0 -2
- package/apps/web/dist/assets/NewWizardPage-zYwDoQTe.js +0 -7
- package/apps/web/dist/assets/OnboardingPage-jFgWaWJV.js +0 -1
- package/apps/web/dist/assets/PreviewPane-D5Kn9Ila.js +0 -4
- package/apps/web/dist/assets/ProjectPage-CyeEBVGi.js +0 -1
- package/apps/web/dist/assets/SettingsPage-haivwaZK.js +0 -2
- package/apps/web/dist/assets/SetupPage-Dy8KeG7z.js +0 -1
- package/apps/web/dist/assets/changelog-XRs8voQT.js +0 -1
- package/apps/web/dist/assets/index-CXA_do-X.js +0 -14
- package/apps/web/dist/assets/index-DG0i3S-z.css +0 -1
- package/apps/web/dist/assets/theme-CWGl7LyL.js +0 -11
- package/apps/web/dist/assets/ui-Bk08zclS.js +0 -137
|
@@ -145,7 +145,7 @@ export async function tenantInfo(id, fresh = false) {
|
|
|
145
145
|
export function forgetTenant(id) {
|
|
146
146
|
tenants.delete(id);
|
|
147
147
|
}
|
|
148
|
-
/** Renames the
|
|
148
|
+
/** Renames the organization at the Manage-App; what it answers is the tenant as it stands now. */
|
|
149
149
|
export async function renameTenant(id, name) {
|
|
150
150
|
const value = await call("PATCH", `/v1/tenants/${encodeURIComponent(id)}`, {
|
|
151
151
|
name,
|
|
@@ -153,14 +153,14 @@ export async function renameTenant(id, name) {
|
|
|
153
153
|
tenants.set(id, { at: Date.now(), value });
|
|
154
154
|
return value;
|
|
155
155
|
}
|
|
156
|
-
export function
|
|
156
|
+
export function saveOrganizationProfile(tenantId, userId, lang, profile) {
|
|
157
157
|
return call("PUT", `/v1/tenants/${encodeURIComponent(tenantId)}/profile`, {
|
|
158
158
|
...profile,
|
|
159
159
|
userId,
|
|
160
160
|
lang,
|
|
161
161
|
});
|
|
162
162
|
}
|
|
163
|
-
/** The Manage-App mails the install command and the first steps to one of the
|
|
163
|
+
/** The Manage-App mails the install command and the first steps to one of the organization's people. */
|
|
164
164
|
export function installMail(email, lang) {
|
|
165
165
|
return call("POST", "/v1/install-mail", { email, lang });
|
|
166
166
|
}
|
|
@@ -230,7 +230,7 @@ export function bookChannelUsage(id, input) {
|
|
|
230
230
|
return call("POST", `/v1/tenants/${encodeURIComponent(id)}/channels/usage`, input);
|
|
231
231
|
}
|
|
232
232
|
/**
|
|
233
|
-
* The
|
|
233
|
+
* The organization's public page data, whole (services/pages.ts): Manage keeps it and serves the page at
|
|
234
234
|
* `<slug>.<PAGES_DOMAIN>`. What it answers names the page's address.
|
|
235
235
|
*/
|
|
236
236
|
export function putPages(tenantId, data) {
|
|
@@ -78,7 +78,7 @@ const grantCache = new Map();
|
|
|
78
78
|
const GRANT_TTL = 30_000;
|
|
79
79
|
/**
|
|
80
80
|
* A signed token lives its hour whatever happens; whether the person still allows the app —
|
|
81
|
-
* and is still in the
|
|
81
|
+
* and is still in the organization — the Manage-App knows. Asked at most every 30 seconds per grant;
|
|
82
82
|
* when it cannot be asked, the token is refused.
|
|
83
83
|
*/
|
|
84
84
|
async function grantStands(userId, clientId, tenantId) {
|
|
@@ -70,8 +70,8 @@ export async function loadLocalModels() {
|
|
|
70
70
|
}
|
|
71
71
|
const tenantConfigs = new Map();
|
|
72
72
|
const tenantSetting = (tenant) => `models:${tenant}`;
|
|
73
|
-
/**
|
|
74
|
-
function
|
|
73
|
+
/** An organization thinks on its credits unless it brought a key: `own`, with the credits behind it. */
|
|
74
|
+
function organizationSettings(bindings) {
|
|
75
75
|
return { source: "own", bindings, creditFallback: true };
|
|
76
76
|
}
|
|
77
77
|
async function tenantConfig(tenant) {
|
|
@@ -81,7 +81,7 @@ async function tenantConfig(tenant) {
|
|
|
81
81
|
}
|
|
82
82
|
const stored = await readSetting(tenantSetting(tenant));
|
|
83
83
|
const value = {
|
|
84
|
-
settings:
|
|
84
|
+
settings: organizationSettings(stored?.bindings ?? {}),
|
|
85
85
|
keys: (stored?.keys ? unseal(stored.keys) : null) ?? {},
|
|
86
86
|
};
|
|
87
87
|
tenantConfigs.set(tenant, value);
|
|
@@ -92,7 +92,7 @@ async function config() {
|
|
|
92
92
|
return local;
|
|
93
93
|
}
|
|
94
94
|
const tenant = currentTenantOrNull();
|
|
95
|
-
return tenant ? tenantConfig(tenant) : { settings:
|
|
95
|
+
return tenant ? tenantConfig(tenant) : { settings: organizationSettings({}), keys: {} };
|
|
96
96
|
}
|
|
97
97
|
function mergeBindings(current, changes = {}) {
|
|
98
98
|
const bindings = { ...current };
|
|
@@ -132,7 +132,7 @@ export async function saveLocalModels(input) {
|
|
|
132
132
|
}
|
|
133
133
|
await loadLocalModels();
|
|
134
134
|
}
|
|
135
|
-
/**
|
|
135
|
+
/** An organization's keys and bindings on a runtime of a Manage-App. No client and no local model there. */
|
|
136
136
|
async function saveTenantModels(tenant, input) {
|
|
137
137
|
const current = await tenantConfig(tenant);
|
|
138
138
|
const keys = { ...current.keys };
|
|
@@ -434,6 +434,76 @@ async function ownTextModel(cls, meta) {
|
|
|
434
434
|
const { model, gateway } = await ownLanguageModel(route.cfg, route.ref, meta);
|
|
435
435
|
return { model, ref: route.ref, vendor: vendorOf(route.ref), gateway, metered: false };
|
|
436
436
|
}
|
|
437
|
+
/**
|
|
438
|
+
* What answers the studio's chats, Goose and the editor's chat: the text classes as they are set
|
|
439
|
+
* (`models`), an installed client on its subscription, one provider's own key, or the credits.
|
|
440
|
+
*/
|
|
441
|
+
export const CHAT_WAYS = [
|
|
442
|
+
"models",
|
|
443
|
+
"claude",
|
|
444
|
+
"codex",
|
|
445
|
+
"cursor",
|
|
446
|
+
"openai",
|
|
447
|
+
"anthropic",
|
|
448
|
+
"google",
|
|
449
|
+
"gateway",
|
|
450
|
+
"account",
|
|
451
|
+
];
|
|
452
|
+
/** Whether a way can answer now: the client signed in, the key there, the account linked. */
|
|
453
|
+
export async function chatWayReady(way, textModelReady) {
|
|
454
|
+
if (way === "models") {
|
|
455
|
+
return textModelReady;
|
|
456
|
+
}
|
|
457
|
+
if (managed) {
|
|
458
|
+
return false;
|
|
459
|
+
}
|
|
460
|
+
const client = harness(way);
|
|
461
|
+
if (client) {
|
|
462
|
+
const status = await detectHarness(client.id);
|
|
463
|
+
return Boolean(status?.version) && status?.auth !== "none";
|
|
464
|
+
}
|
|
465
|
+
if (way === "account") {
|
|
466
|
+
return Boolean(await linkedAccount());
|
|
467
|
+
}
|
|
468
|
+
return Boolean((await config()).keys[way]);
|
|
469
|
+
}
|
|
470
|
+
/**
|
|
471
|
+
* The model a studio chat runs on. `cls` is the text class it takes where the chat follows the
|
|
472
|
+
* classes; a client or a provider runs its own model of that class.
|
|
473
|
+
*/
|
|
474
|
+
export async function chatModel(way, cls) {
|
|
475
|
+
if (way === "models") {
|
|
476
|
+
return textModel(cls);
|
|
477
|
+
}
|
|
478
|
+
const cfg = await config();
|
|
479
|
+
const client = harness(way);
|
|
480
|
+
if (client) {
|
|
481
|
+
if (!(await detectHarness(client.id))?.version) {
|
|
482
|
+
throw new ModelUnavailableError(notInstalled(client));
|
|
483
|
+
}
|
|
484
|
+
const alias = client.classes[cls];
|
|
485
|
+
return {
|
|
486
|
+
model: client.model(alias),
|
|
487
|
+
ref: `${client.id}/${alias}`,
|
|
488
|
+
vendor: client.id,
|
|
489
|
+
gateway: false,
|
|
490
|
+
metered: false,
|
|
491
|
+
};
|
|
492
|
+
}
|
|
493
|
+
if (way === "account") {
|
|
494
|
+
const access = await creditAccess(cfg, true);
|
|
495
|
+
if (!access) {
|
|
496
|
+
throw new ModelUnavailableError(note("creditsNotSignedIn"));
|
|
497
|
+
}
|
|
498
|
+
return viaCredits({ kind: "credits", access, model: null }, cls, {}, (gateway, id) => gateway(id));
|
|
499
|
+
}
|
|
500
|
+
const ref = providerInfo(way)?.text?.[cls];
|
|
501
|
+
if (!ref) {
|
|
502
|
+
throw new ModelUnavailableError(note("noModelFor", { makes: note("makesText") }));
|
|
503
|
+
}
|
|
504
|
+
const { model, gateway } = await ownLanguageModel(cfg, ref, {});
|
|
505
|
+
return { model, ref, vendor: vendorOf(ref), gateway, metered: false };
|
|
506
|
+
}
|
|
437
507
|
/**
|
|
438
508
|
* Hands the tools an agent will call to a model that runs them itself (an installed AI client).
|
|
439
509
|
* `ignorable`: the step declared no tools and has no uploads — the run's device may answer
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { localLang } from "@engenty/wizards-shared/definition";
|
|
1
|
+
import { britishEnglish, britishSpelling, localLang, } from "@engenty/wizards-shared/definition";
|
|
2
2
|
import { serverText } from "../texts.js";
|
|
3
3
|
/**
|
|
4
4
|
* The language a visitor's request asks for, as the studio starts in it (`localLang`): the
|
|
@@ -6,15 +6,24 @@ import { serverText } from "../texts.js";
|
|
|
6
6
|
* browser's `Accept-Language` names them in its order; the server has no time zone to go by.
|
|
7
7
|
*/
|
|
8
8
|
export function requestLang(c) {
|
|
9
|
-
|
|
9
|
+
return localLang(askedLanguages(c)) ?? "en";
|
|
10
|
+
}
|
|
11
|
+
/** The languages a request's `Accept-Language` names, in its order. */
|
|
12
|
+
function askedLanguages(c) {
|
|
13
|
+
return (c.req.header("accept-language") ?? "")
|
|
10
14
|
.split(",")
|
|
11
15
|
.map((part) => part.split(";")[0]?.trim() ?? "")
|
|
12
16
|
.filter(Boolean);
|
|
13
|
-
return localLang(asked) ?? "en";
|
|
14
17
|
}
|
|
15
18
|
/** A line of the server's table the person reads, in the language their request asks for. */
|
|
16
19
|
export function say(c, key, params) {
|
|
17
|
-
return serverText(requestLang(c), key, params);
|
|
20
|
+
return spelledFor(c, serverText(requestLang(c), key, params));
|
|
21
|
+
}
|
|
22
|
+
/** English text as the request's reader spells it: British where their English is en-GB. */
|
|
23
|
+
export function spelledFor(c, text) {
|
|
24
|
+
return requestLang(c) === "en" && britishEnglish(askedLanguages(c))
|
|
25
|
+
? britishSpelling(text)
|
|
26
|
+
: text;
|
|
18
27
|
}
|
|
19
28
|
/** A 404 the person may read: a sentence in their language, the machine code beside it. */
|
|
20
29
|
export function notFoundAnswer(c) {
|
|
@@ -678,7 +678,7 @@ export const runRoutes = new Hono()
|
|
|
678
678
|
.where(eq(schema.run.id, run.id));
|
|
679
679
|
return c.json({ ok: true });
|
|
680
680
|
})
|
|
681
|
-
// A json step's data, edited in the studio by someone of the
|
|
681
|
+
// A json step's data, edited in the studio by someone of the organization the run belongs to.
|
|
682
682
|
.put("/:id/outputs/:stepId", async (c) => {
|
|
683
683
|
const run = await accessibleRun(c, c.req.param("id"));
|
|
684
684
|
const user = await principalOf(c);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { mkdirSync } from "node:fs";
|
|
2
2
|
import { join } from "node:path";
|
|
3
|
-
import { ASSISTANT_LAYOUTS, ASSISTANT_PAGE_BYTES, assistantSignalSchema, assistantTurnSchema, } from "@engenty/wizards-shared/assistant";
|
|
3
|
+
import { ASSISTANT_LAYOUTS, ASSISTANT_PAGE_BYTES, ASSISTANT_WIDTH, assistantSignalSchema, assistantTurnSchema, } from "@engenty/wizards-shared/assistant";
|
|
4
4
|
import { LANGS, MODEL_CLASSES, TEXT_CLASSES, wizardLang, } from "@engenty/wizards-shared/definition";
|
|
5
5
|
import { CATEGORY_TYPES, whereSchema } from "@engenty/wizards-shared/knowledge";
|
|
6
6
|
import { PROJECT_FILE_KINDS } from "@engenty/wizards-shared/projects";
|
|
@@ -14,7 +14,7 @@ import { streamSSE } from "hono/streaming";
|
|
|
14
14
|
import { nanoid } from "nanoid";
|
|
15
15
|
import { z } from "zod";
|
|
16
16
|
import { runStudioAssistant, signalText } from "../agents/studio-assistant.js";
|
|
17
|
-
import { chatEngine, setChatEngine, subscriptionClients } from "../agents/subscription.js";
|
|
17
|
+
import { chatEngine, chatWays, setChatEngine, subscriptionClients, } from "../agents/subscription.js";
|
|
18
18
|
import { scanColors, scanFonts, scanImages, scanLogos } from "../agents/website.js";
|
|
19
19
|
import { answerBrowser, awaitBrowser } from "../assistant/browser.js";
|
|
20
20
|
import { endRun, signalRun, startRun, takeSignals } from "../assistant/runs.js";
|
|
@@ -32,17 +32,17 @@ import { appleStatus } from "../harness/apple.js";
|
|
|
32
32
|
import { freshAuth, loginEnv } from "../harness/env.js";
|
|
33
33
|
import { detectHarness, detectHarnesses, HARNESS_IDS, harness, installSpec, } from "../harness/index.js";
|
|
34
34
|
import { closeTerminal, openTerminal, resizeTerminal, subscribeTerminal, writeTerminal, } from "../harness/terminal.js";
|
|
35
|
-
import { installMail, managed, renameTenant,
|
|
35
|
+
import { installMail, managed, renameTenant, saveOrganizationProfile, tenantInfo, tenantMembers, userInfo, } from "../manage.js";
|
|
36
36
|
import { seenApps } from "../mcp/seen.js";
|
|
37
37
|
import { generateImageMedia, generateSpeechMedia, generateVideoMedia } from "../media/generate.js";
|
|
38
38
|
import { transcribeAudio } from "../media/transcribe.js";
|
|
39
39
|
import { errorText, saidOf } from "../model-errors.js";
|
|
40
|
-
import { checkKey, classProblem, classWays, embeddingModel, hasTextModel, LOCAL_KEYS, localModelSettings, ModelUnavailableError, modelSettings, saveLocalModels, saveModels, setUpKey, setUpOllama, storedKey, textModel, } from "../models.js";
|
|
40
|
+
import { CHAT_WAYS, checkKey, classProblem, classWays, embeddingModel, hasTextModel, LOCAL_KEYS, localModelSettings, ModelUnavailableError, modelSettings, saveLocalModels, saveModels, setUpKey, setUpOllama, storedKey, textModel, } from "../models.js";
|
|
41
41
|
import { refreshPro } from "../plugins/pro.js";
|
|
42
42
|
import { HTML_RESPONSE_CSP } from "../render/guard.js";
|
|
43
43
|
import { isAdminRole, mayBuild, mayCreate, projectWritable, requireAdmin, requireWritable, } from "../services/access.js";
|
|
44
44
|
import { architectTurn } from "../services/architect.js";
|
|
45
|
-
import { addMessage, assistantLayout, currentChat, earlierChats, foldChat, newChat, openChat, readChat, turnHistory, } from "../services/assistant-chats.js";
|
|
45
|
+
import { addMessage, assistantLayout, assistantWidth, currentChat, earlierChats, foldChat, newChat, openChat, readChat, turnHistory, } from "../services/assistant-chats.js";
|
|
46
46
|
import { describeGradient, themeLooks } from "../services/brand.js";
|
|
47
47
|
import { checkForCloud, cloudLinked, cloudSpaces, cloudState, forgetCloud, publishAndSync, pushSharing, removeFromCloud, replaceCloudSpaces, rotateInCloud, syncToCloud, } from "../services/cloud.js";
|
|
48
48
|
import { notFound, ServiceError } from "../services/errors.js";
|
|
@@ -64,7 +64,7 @@ import { deleteTheme, listThemes, saveTheme } from "../services/themes.js";
|
|
|
64
64
|
import { deleteTranslation, editTranslation, isLangCode, publishedDefinition, translationsOf, } from "../services/translations.js";
|
|
65
65
|
import { draftWidgetPreview } from "../services/widgets.js";
|
|
66
66
|
import { createWizard, deleteWizard, draftChanges, duplicateWizard, listWizards, ownedWizard, rotateShareLink, updateWizardSettings, wizardMessages, wizardState, writableWizard, writeDraft, } from "../services/wizards.js";
|
|
67
|
-
import { readSetting, writeSetting } from "../settings.js";
|
|
67
|
+
import { deleteSetting, readSetting, writeSetting } from "../settings.js";
|
|
68
68
|
import { projectShareTargets, sharePreview } from "../sharing/index.js";
|
|
69
69
|
import { codeOf } from "../tenants/control.js";
|
|
70
70
|
import { currentTenant } from "../tenants/tenant.js";
|
|
@@ -107,7 +107,7 @@ const modelsInput = z.object({
|
|
|
107
107
|
creditFallback: z.boolean().optional(),
|
|
108
108
|
keys: z.partialRecord(z.enum(LOCAL_KEYS), z.string().max(400)).optional(),
|
|
109
109
|
});
|
|
110
|
-
/** Alone the person changes everything; in
|
|
110
|
+
/** Alone the person changes everything; in an organization its owner and admins. */
|
|
111
111
|
function mayChangeModels(user) {
|
|
112
112
|
return !managed || user.role === "owner" || user.role === "admin";
|
|
113
113
|
}
|
|
@@ -235,14 +235,14 @@ export const studio = new Hono()
|
|
|
235
235
|
tenant: {
|
|
236
236
|
id: user.tenantId,
|
|
237
237
|
role: user.role,
|
|
238
|
-
/** The plan the
|
|
238
|
+
/** The plan the organization is on; null alone, or where the Manage-App names none. */
|
|
239
239
|
plan: info?.plan ?? null,
|
|
240
|
-
/** The
|
|
240
|
+
/** The organization's address for its public page (`acme.wizards.page`); null alone, or behind its switch. */
|
|
241
241
|
pagesHost: feature("pages", { ...info?.features, ...person?.features })
|
|
242
242
|
? (info?.pagesHost ?? null)
|
|
243
243
|
: null,
|
|
244
244
|
},
|
|
245
|
-
/** The feature switches: the code's defaults, what the Manage-App says of the
|
|
245
|
+
/** The feature switches: the code's defaults, what the Manage-App says of the organization and the person, this install's file. */
|
|
246
246
|
features: features(managed ? { ...info?.features, ...person?.features } : overview?.tenant.features),
|
|
247
247
|
/** The studio assistant's developer mode may be switched on: ASSISTANT_DEV here, the platform's admins when managed. */
|
|
248
248
|
assistantDev: await assistantDevFor(user),
|
|
@@ -255,8 +255,8 @@ export const studio = new Hono()
|
|
|
255
255
|
? {
|
|
256
256
|
name: linked.name,
|
|
257
257
|
email: linked.email,
|
|
258
|
-
/** The
|
|
259
|
-
|
|
258
|
+
/** The organization the account's space belongs to, as the Manage-App names it. */
|
|
259
|
+
organization: overview?.tenant.name ?? null,
|
|
260
260
|
credits: overview?.tenant.balanceCredits ?? null,
|
|
261
261
|
/** What of the credits ends on a date, the nearest first. */
|
|
262
262
|
expiring: overview?.tenant.expiring ?? [],
|
|
@@ -274,10 +274,12 @@ export const studio = new Hono()
|
|
|
274
274
|
subscriptions: managed ? [] : await subscriptionClients(),
|
|
275
275
|
/** A runtime that runs alone keeps its setup in front until a test call has worked on the chosen source and the way is still open. */
|
|
276
276
|
setupDone: managed ? true : await setupDone(),
|
|
277
|
-
/** The cloud studio's first visit: the short wizard that names the
|
|
277
|
+
/** The cloud studio's first visit: the short wizard that names the organization and fills the space (services/onboarding.ts). */
|
|
278
278
|
onboarding: await needsOnboarding(user),
|
|
279
|
-
/** What answers the studio chat: a
|
|
279
|
+
/** What answers the studio's chats (Goose, the editor's chat): the text classes, a subscription, a key or the credits. */
|
|
280
280
|
chatEngine: managed ? "models" : await chatEngine(await hasTextModel()),
|
|
281
|
+
/** The ways that can answer the studio's chats now. */
|
|
282
|
+
chatWays: managed ? ["models"] : await chatWays(await hasTextModel()),
|
|
281
283
|
aiReady: (await hasTextModel()) || (!managed && (await subscriptionClients()).length > 0),
|
|
282
284
|
mcpUrl: `${env.appUrl}/api/mcp`,
|
|
283
285
|
/**
|
|
@@ -294,8 +296,8 @@ export const studio = new Hono()
|
|
|
294
296
|
},
|
|
295
297
|
});
|
|
296
298
|
})
|
|
297
|
-
// The
|
|
298
|
-
.get("/
|
|
299
|
+
// The organization as the Manage-App keeps it: its people, who is invited, the places the plan gives.
|
|
300
|
+
.get("/organization", async (c) => {
|
|
299
301
|
if (!managed) {
|
|
300
302
|
return c.json({
|
|
301
303
|
error: say(c, "onlyAvailableCloud"),
|
|
@@ -303,16 +305,16 @@ export const studio = new Hono()
|
|
|
303
305
|
}, 404);
|
|
304
306
|
}
|
|
305
307
|
const user = c.get("user");
|
|
306
|
-
const [info,
|
|
308
|
+
const [info, organization] = await Promise.all([
|
|
307
309
|
tenantInfo(user.tenantId).catch(() => null),
|
|
308
310
|
tenantMembers(currentTenant()),
|
|
309
311
|
]);
|
|
310
312
|
return c.json({
|
|
311
|
-
...
|
|
313
|
+
...organization,
|
|
312
314
|
plan: info?.plan ?? null,
|
|
313
315
|
/** Where members are invited and roles changed: the account pages of the Manage-App. */
|
|
314
316
|
manageUrl: env.manage.url,
|
|
315
|
-
/** Whether this person manages the
|
|
317
|
+
/** Whether this person manages the organization there. */
|
|
316
318
|
canManage: isAdminRole(user.role),
|
|
317
319
|
});
|
|
318
320
|
})
|
|
@@ -347,11 +349,36 @@ export const studio = new Hono()
|
|
|
347
349
|
.post("/assistant/chat/new", async (c) => c.json(await newChat(c.get("user"))))
|
|
348
350
|
.get("/assistant/chats", async (c) => c.json({ chats: await earlierChats(c.get("user")) }))
|
|
349
351
|
.get("/assistant/chats/:id", async (c) => c.json(await readChat(c.get("user"), c.req.param("id"))))
|
|
350
|
-
|
|
352
|
+
// Where the assistant stands, and the sidebar's width (null: the default); a PUT sends either.
|
|
353
|
+
.get("/assistant/layout", async (c) => c.json({
|
|
354
|
+
layout: await assistantLayout(c.get("user")),
|
|
355
|
+
width: await assistantWidth(c.get("user")),
|
|
356
|
+
}))
|
|
351
357
|
.put("/assistant/layout", async (c) => {
|
|
352
|
-
const
|
|
353
|
-
|
|
354
|
-
|
|
358
|
+
const user = c.get("user");
|
|
359
|
+
const body = z
|
|
360
|
+
.object({
|
|
361
|
+
layout: z.enum(ASSISTANT_LAYOUTS).optional(),
|
|
362
|
+
width: z
|
|
363
|
+
.number()
|
|
364
|
+
.int()
|
|
365
|
+
.min(ASSISTANT_WIDTH.min)
|
|
366
|
+
.max(ASSISTANT_WIDTH.max)
|
|
367
|
+
.nullable()
|
|
368
|
+
.optional(),
|
|
369
|
+
})
|
|
370
|
+
.refine((b) => b.layout !== undefined || b.width !== undefined)
|
|
371
|
+
.parse(await c.req.json());
|
|
372
|
+
if (body.layout) {
|
|
373
|
+
await writeSetting(`assistant-layout:${user.tenantId}:${user.id}`, body.layout);
|
|
374
|
+
}
|
|
375
|
+
if (body.width === null) {
|
|
376
|
+
await deleteSetting(`assistant-width:${user.tenantId}:${user.id}`);
|
|
377
|
+
}
|
|
378
|
+
else if (body.width !== undefined) {
|
|
379
|
+
await writeSetting(`assistant-width:${user.tenantId}:${user.id}`, body.width);
|
|
380
|
+
}
|
|
381
|
+
return c.json({ layout: await assistantLayout(user), width: await assistantWidth(user) });
|
|
355
382
|
})
|
|
356
383
|
// Live chat reads answers aloud with the speech model where one is set up; else the browser's voices.
|
|
357
384
|
.get("/assistant/voice", async (c) => c.json({ way: (await classWays()).speech.kind }))
|
|
@@ -532,7 +559,7 @@ export const studio = new Hono()
|
|
|
532
559
|
await updateProject(c.get("user").id, c.req.param("id"), patch);
|
|
533
560
|
return c.json({ ok: true });
|
|
534
561
|
})
|
|
535
|
-
// The
|
|
562
|
+
// The organization's public page as Manage will draw it, for the preview beside the page's fields.
|
|
536
563
|
.get("/projects/:id/page", async (c) => {
|
|
537
564
|
await ownedProject(c.get("user").id, c.req.param("id"));
|
|
538
565
|
return c.json(await pagePreview());
|
|
@@ -1328,12 +1355,12 @@ export const studio = new Hono()
|
|
|
1328
1355
|
return c.json(localModelSettings());
|
|
1329
1356
|
})
|
|
1330
1357
|
// --- models: where each class runs, own API keys, the credits behind them -----------------
|
|
1331
|
-
// Alone for this machine; on a Manage-App's runtime for the
|
|
1358
|
+
// Alone for this machine; on a Manage-App's runtime for the organization, whose admins change it.
|
|
1332
1359
|
.get("/models", async (c) => c.json(await modelSettings(requestLang(c))))
|
|
1333
1360
|
.put("/models", async (c) => {
|
|
1334
1361
|
if (!mayChangeModels(c.get("user"))) {
|
|
1335
1362
|
return c.json({
|
|
1336
|
-
error: say(c, "
|
|
1363
|
+
error: say(c, "onlyOrganizationAdminsChange"),
|
|
1337
1364
|
code: "forbidden",
|
|
1338
1365
|
}, 403);
|
|
1339
1366
|
}
|
|
@@ -1348,7 +1375,7 @@ export const studio = new Hono()
|
|
|
1348
1375
|
code: "not_local",
|
|
1349
1376
|
}, 400);
|
|
1350
1377
|
}
|
|
1351
|
-
// Own keys and bindings to a provider's model are a feature of the
|
|
1378
|
+
// Own keys and bindings to a provider's model are a feature of the organization's plan.
|
|
1352
1379
|
// When the Manage-App can't say what the plan holds, own keys wait: nothing is taken unchecked.
|
|
1353
1380
|
const own = Object.values(input.keys ?? {}).some((key) => key?.trim()) ||
|
|
1354
1381
|
Object.values(input.bindings ?? {}).some((ref) => ref && !isCreditsRef(ref));
|
|
@@ -1367,7 +1394,7 @@ export const studio = new Hono()
|
|
|
1367
1394
|
return c.json({
|
|
1368
1395
|
error: info.plan?.name
|
|
1369
1396
|
? say(c, "ownKeysNotInPlan", { plan: info.plan.name })
|
|
1370
|
-
: say(c, "
|
|
1397
|
+
: say(c, "ownKeysNotInOrganizationPlan"),
|
|
1371
1398
|
code: "plan",
|
|
1372
1399
|
}, 403);
|
|
1373
1400
|
}
|
|
@@ -1395,7 +1422,7 @@ export const studio = new Hono()
|
|
|
1395
1422
|
.post("/models/test", async (c) => {
|
|
1396
1423
|
if (!mayChangeModels(c.get("user"))) {
|
|
1397
1424
|
return c.json({
|
|
1398
|
-
error: say(c, "
|
|
1425
|
+
error: say(c, "onlyOrganizationAdminsTest"),
|
|
1399
1426
|
code: "forbidden",
|
|
1400
1427
|
}, 403);
|
|
1401
1428
|
}
|
|
@@ -1568,14 +1595,14 @@ export const studio = new Hono()
|
|
|
1568
1595
|
if (managed) {
|
|
1569
1596
|
return c.notFound();
|
|
1570
1597
|
}
|
|
1571
|
-
const { engine } = z.object({ engine: z.enum(
|
|
1598
|
+
const { engine } = z.object({ engine: z.enum(CHAT_WAYS) }).parse(await c.req.json());
|
|
1572
1599
|
await setChatEngine(engine);
|
|
1573
1600
|
return c.json({ ok: true });
|
|
1574
1601
|
})
|
|
1575
1602
|
// The address the system browser opens: the account's sign-in, or — for someone without an
|
|
1576
1603
|
// account — its sign-up page with the invitation code, which then goes on to the sign-in.
|
|
1577
|
-
// --- the first visit of a cloud studio: who the
|
|
1578
|
-
.put("/
|
|
1604
|
+
// --- the first visit of a cloud studio: who the organization is, its website, first documents -----
|
|
1605
|
+
.put("/organization", async (c) => {
|
|
1579
1606
|
if (!managed) {
|
|
1580
1607
|
return c.json({
|
|
1581
1608
|
error: say(c, "onlyAvailableCloud"),
|
|
@@ -1587,8 +1614,8 @@ export const studio = new Hono()
|
|
|
1587
1614
|
const info = await renameTenant(c.get("user").tenantId, name);
|
|
1588
1615
|
return c.json({ name: info.name });
|
|
1589
1616
|
})
|
|
1590
|
-
// What the
|
|
1591
|
-
.put("/
|
|
1617
|
+
// What the organization uses engenty for, and the questions that fit: kept at the Manage-App.
|
|
1618
|
+
.put("/organization/profile", async (c) => {
|
|
1592
1619
|
if (!managed) {
|
|
1593
1620
|
return c.json({
|
|
1594
1621
|
error: say(c, "onlyAvailableCloud"),
|
|
@@ -1610,7 +1637,7 @@ export const studio = new Hono()
|
|
|
1610
1637
|
})
|
|
1611
1638
|
.parse(await c.req.json());
|
|
1612
1639
|
const user = c.get("user");
|
|
1613
|
-
await
|
|
1640
|
+
await saveOrganizationProfile(user.tenantId, user.id, requestLang(c) === "de" ? "de" : "en", profile);
|
|
1614
1641
|
return c.json({ ok: true });
|
|
1615
1642
|
})
|
|
1616
1643
|
.post("/onboarding/done", async (c) => {
|
|
@@ -1626,8 +1653,10 @@ export const studio = new Hono()
|
|
|
1626
1653
|
.post("/projects/:id/website", async (c) => {
|
|
1627
1654
|
const user = c.get("user");
|
|
1628
1655
|
const project = await ownedProject(user.id, c.req.param("id"));
|
|
1629
|
-
const { url } = z
|
|
1630
|
-
|
|
1656
|
+
const { url, lang } = z
|
|
1657
|
+
.object({ url: z.string().trim().min(3).max(400), lang: z.enum(LANGS).optional() })
|
|
1658
|
+
.parse(await c.req.json());
|
|
1659
|
+
return c.json(await applyWebsite(user.id, project.id, url, lang ?? requestLang(c)));
|
|
1631
1660
|
})
|
|
1632
1661
|
// The install command and the first steps, mailed to the signed-in person by the Manage-App.
|
|
1633
1662
|
.post("/install-mail", async (c) => {
|
|
@@ -19,7 +19,7 @@ export function asSync(fn) {
|
|
|
19
19
|
}
|
|
20
20
|
const syncing = () => sync.getStore() === true;
|
|
21
21
|
// --- roles -----------------------------------------------------------------------------
|
|
22
|
-
// In
|
|
22
|
+
// In an organization, an owner or admin makes and deletes (wizards, spaces, connectors); a member edits
|
|
23
23
|
// the wizards there are. A runtime that runs alone has one person, who does everything.
|
|
24
24
|
const actor = new AsyncLocalStorage();
|
|
25
25
|
/** Runs a request as the person's role in the tenant; set once per entry, like the tenant. */
|
|
@@ -31,8 +31,8 @@ export function currentRole() {
|
|
|
31
31
|
return actor.getStore() ?? "owner";
|
|
32
32
|
}
|
|
33
33
|
export const isAdminRole = (role) => role === "owner" || role === "admin";
|
|
34
|
-
export const MEMBERS_EDIT_ONLY = note("
|
|
35
|
-
/** Refuses a member: making and deleting is for the owner and the admins of the
|
|
34
|
+
export const MEMBERS_EDIT_ONLY = note("onlyOrganizationAdmins");
|
|
35
|
+
/** Refuses a member: making and deleting is for the owner and the admins of the organization. */
|
|
36
36
|
export async function requireAdmin() {
|
|
37
37
|
if (syncing() || !managed || isAdminRole(currentRole())) {
|
|
38
38
|
return;
|
|
@@ -41,11 +41,12 @@ lang, io) {
|
|
|
41
41
|
const images = await attachedImages(userId, w.id, message);
|
|
42
42
|
const userMessageId = await addMessage(w.id, { role: "user", content: message });
|
|
43
43
|
try {
|
|
44
|
-
// A runtime that runs alone can answer the chat on the admin's own
|
|
44
|
+
// A runtime that runs alone can answer the chat on the admin's own subscription or key.
|
|
45
45
|
const engine = managed ? "models" : await chatEngine(await hasTextModel());
|
|
46
|
-
const result = engine === "claude"
|
|
46
|
+
const result = engine === "claude" || engine === "codex" || engine === "cursor"
|
|
47
47
|
? {
|
|
48
48
|
...(await subscriptionTurn({
|
|
49
|
+
client: engine,
|
|
49
50
|
wizardId: w.id,
|
|
50
51
|
message,
|
|
51
52
|
signal: io.signal,
|
|
@@ -59,6 +60,7 @@ lang, io) {
|
|
|
59
60
|
unfinished: false,
|
|
60
61
|
}
|
|
61
62
|
: await runArchitect({
|
|
63
|
+
way: engine,
|
|
62
64
|
userId,
|
|
63
65
|
wizardId: w.id,
|
|
64
66
|
message,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ASSISTANT_LAYOUTS } from "@engenty/wizards-shared/assistant";
|
|
1
|
+
import { ASSISTANT_LAYOUTS, ASSISTANT_WIDTH, } from "@engenty/wizards-shared/assistant";
|
|
2
2
|
import { note } from "@engenty/wizards-shared/run";
|
|
3
3
|
import { generateText } from "ai";
|
|
4
4
|
import { and, asc, desc, eq, isNotNull, isNull, sql } from "drizzle-orm";
|
|
@@ -309,3 +309,12 @@ export async function assistantLayout(user) {
|
|
|
309
309
|
? stored
|
|
310
310
|
: "bottom";
|
|
311
311
|
}
|
|
312
|
+
/** The sidebar's width the person set with its handle; null: the default. */
|
|
313
|
+
export async function assistantWidth(user) {
|
|
314
|
+
const stored = await readSetting(`assistant-width:${user.tenantId}:${user.id}`);
|
|
315
|
+
return typeof stored === "number" &&
|
|
316
|
+
stored >= ASSISTANT_WIDTH.min &&
|
|
317
|
+
stored <= ASSISTANT_WIDTH.max
|
|
318
|
+
? stored
|
|
319
|
+
: null;
|
|
320
|
+
}
|