@engenty/wizards-runtime 0.11.5 → 0.11.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 +40 -55
- package/apps/runtime/dist/agents/chat-clients.js +3 -0
- package/apps/runtime/dist/agents/company.js +4 -12
- package/apps/runtime/dist/agents/studio-assistant.js +82 -74
- package/apps/runtime/dist/agents/subscription.js +27 -17
- package/apps/runtime/dist/assistant/knows.js +19 -19
- package/apps/runtime/dist/auth/account.js +51 -12
- package/apps/runtime/dist/auth/index.js +15 -2
- package/apps/runtime/dist/authoring/guide.js +20 -447
- package/apps/runtime/dist/browser/fast/run.js +18 -12
- package/apps/runtime/dist/cli/account.js +127 -10
- package/apps/runtime/dist/cli/main.js +4 -2
- package/apps/runtime/dist/connectors/mail.js +4 -3
- package/apps/runtime/dist/data/chat-models.json +116 -0
- package/apps/runtime/dist/docs/user-guide/models.md +15 -5
- package/apps/runtime/dist/documents/parse.js +5 -14
- package/apps/runtime/dist/engine/decide.js +2 -1
- package/apps/runtime/dist/engine/runner.js +4 -3
- package/apps/runtime/dist/engine/steps.js +82 -91
- package/apps/runtime/dist/engine/template.js +2 -3
- package/apps/runtime/dist/env.js +5 -0
- package/apps/runtime/dist/harness/antigravity.js +2 -2
- package/apps/runtime/dist/harness/apple.js +4 -6
- package/apps/runtime/dist/harness/codex.js +5 -6
- package/apps/runtime/dist/harness/prompt.js +8 -8
- package/apps/runtime/dist/mcp/handler.js +5 -7
- package/apps/runtime/dist/mcp/tools.js +33 -54
- package/apps/runtime/dist/media/conversation.js +18 -23
- package/apps/runtime/dist/media/generate.js +18 -3
- package/apps/runtime/dist/media/transcribe.js +5 -4
- package/apps/runtime/dist/models.js +8 -9
- package/apps/runtime/dist/motion-graphics/project.js +19 -53
- package/apps/runtime/dist/motion-graphics/sounds.js +2 -1
- package/apps/runtime/dist/motion-graphics/step.js +31 -16
- package/apps/runtime/dist/prompts/README.md +48 -0
- package/apps/runtime/dist/prompts/architect.md +89 -0
- package/apps/runtime/dist/prompts/authoring.md +503 -0
- package/apps/runtime/dist/prompts/goose.md +229 -0
- package/apps/runtime/dist/prompts/mcp.md +156 -0
- package/apps/runtime/dist/prompts/safety.md +23 -0
- package/apps/runtime/dist/prompts/services.md +151 -0
- package/apps/runtime/dist/prompts/step.md +334 -0
- package/apps/runtime/dist/prompts/tools.md +330 -0
- package/apps/runtime/dist/prompts/voice.md +53 -0
- package/apps/runtime/dist/prompts.js +50 -0
- package/apps/runtime/dist/routes/studio.js +58 -7
- package/apps/runtime/dist/safety.js +45 -0
- package/apps/runtime/dist/sandbox/index.js +8 -3
- package/apps/runtime/dist/services/architect.js +5 -4
- package/apps/runtime/dist/services/assistant-chats.js +5 -8
- package/apps/runtime/dist/services/brand.js +2 -7
- package/apps/runtime/dist/services/chat-models.js +58 -0
- package/apps/runtime/dist/services/cloud.js +8 -4
- package/apps/runtime/dist/services/knowledge-model.js +17 -8
- package/apps/runtime/dist/services/knowledge.js +5 -9
- package/apps/runtime/dist/services/project-files.js +3 -8
- package/apps/runtime/dist/services/relevance.js +4 -3
- package/apps/runtime/dist/services/runs.js +6 -7
- package/apps/runtime/dist/services/site.js +2 -2
- package/apps/runtime/dist/services/translations.js +17 -10
- package/apps/runtime/dist/services/wizards.js +8 -0
- package/apps/runtime/dist/sync/client.js +116 -1
- package/apps/runtime/dist/tools/browser.js +36 -33
- package/apps/runtime/dist/tools/code.js +20 -6
- package/apps/runtime/dist/tools/connector.js +23 -9
- package/apps/runtime/dist/tools/index.js +14 -11
- package/apps/runtime/dist/tools/mail.js +5 -5
- package/apps/runtime/dist/tools/net-guard.js +4 -4
- package/apps/runtime/dist/tools/pages.js +3 -2
- package/apps/runtime/dist/tools/project.js +7 -8
- package/apps/runtime/dist/tools/store.js +14 -10
- package/apps/web/dist/assets/{AboutDialog-B525L37O.js → AboutDialog-J9rRhJTJ.js} +1 -1
- package/apps/web/dist/assets/{ChangelogDialog-gInSm1Xe.js → ChangelogDialog-D9bBSuLQ.js} +1 -1
- package/apps/web/dist/assets/{CodeEditor-C0TmdCrb.js → CodeEditor-CiRJjYpm.js} +1 -1
- package/apps/web/dist/assets/{EditorPage-7t3vhZi6.js → EditorPage-ChLV09jO.js} +1 -1
- package/apps/web/dist/assets/{FlowPreview-BBN-APkG.js → FlowPreview-QRnLE4JM.js} +1 -1
- package/apps/web/dist/assets/{Harness-fAoC908y.js → Harness-dM1CDgnx.js} +1 -1
- package/apps/web/dist/assets/Marketplace-8rU-MhWj.js +2 -0
- package/apps/web/dist/assets/{NewWizardChannels-X32lBGMf.js → NewWizardChannels--JqgVT-t.js} +1 -1
- package/apps/web/dist/assets/{NewWizardPage-DMoqDhsh.js → NewWizardPage-CNv5UuBn.js} +1 -1
- package/apps/web/dist/assets/{OnboardingPage-BjZy-bhI.js → OnboardingPage-CDuhfBEI.js} +1 -1
- package/apps/web/dist/assets/{PreviewPane-Bt-ForJG.js → PreviewPane-BsMrHW8b.js} +2 -2
- package/apps/web/dist/assets/{ProjectPage-B5a-nod-.js → ProjectPage-CoVMEoB1.js} +1 -1
- package/apps/web/dist/assets/{PublicRunner-Cq_XzX54.js → PublicRunner-Ckte5NnM.js} +1 -1
- package/apps/web/dist/assets/{ReadOnly-DX3beZJz.js → ReadOnly-Ch-ss9Mh.js} +1 -1
- package/apps/web/dist/assets/SettingsPage-CGp6G_fp.js +2 -0
- package/apps/web/dist/assets/{SetupPage-BI9bgEkI.js → SetupPage-DgFT_646.js} +1 -1
- package/apps/web/dist/assets/{SharePage-Ch-1oLBs.js → SharePage-CEcFKE3b.js} +1 -1
- package/apps/web/dist/assets/changelog-DMhLfQmS.js +1 -0
- package/apps/web/dist/assets/i18n-AXoEWXfv.js +55 -0
- package/apps/web/dist/assets/index-BYZBN0xx.css +1 -0
- package/apps/web/dist/assets/index-Dx7qMiM3.js +34 -0
- package/apps/web/dist/assets/{oss-credits-CZT1KRIp.js → oss-credits-Da4KrYmP.js} +1 -1
- package/apps/web/dist/assets/{phone-DxC6eM6O.js → phone-De-HF0g7.js} +1 -1
- package/apps/web/dist/assets/{runners-SQHfvvNQ.js → runners-UIPj9xyX.js} +1 -1
- package/apps/web/dist/assets/{session-4CTNIlai.js → session-DUxZmhqy.js} +1 -1
- package/apps/web/dist/assets/{settings-menu-B0af5EBE.js → settings-menu-Bo1yXMGF.js} +1 -1
- package/apps/web/dist/assets/{theme-mtamawa_.js → theme-CSuPPxre.js} +1 -1
- package/apps/web/dist/assets/ui-CBDsXUoA.js +83 -0
- package/apps/web/dist/assets/{upload-DXJQU2lL.js → upload-CZgdEF60.js} +1 -1
- package/apps/web/dist/assets/{useMutation-DwRYrG3V.js → useMutation-ZHWqRSPd.js} +1 -1
- package/apps/web/dist/assets/{volume-2-CYbbBiXP.js → volume-2-c641MxaU.js} +1 -1
- package/apps/web/dist/assets/{wrench-D8lG2BH7.js → wrench-DCEAyYuR.js} +1 -1
- package/apps/web/dist/index.html +8 -9
- package/apps/web/dist/mcp/flow.html +87 -87
- package/node_modules/@engenty/wizards-shared/dist/assistant.d.ts +1 -0
- package/node_modules/@engenty/wizards-shared/dist/assistant.js +2 -0
- package/node_modules/@engenty/wizards-shared/dist/run.d.ts +6 -0
- package/node_modules/@engenty/wizards-shared/dist/run.js +12 -0
- package/node_modules/@engenty/wizards-shared/dist/surface.d.ts +0 -2
- package/node_modules/@engenty/wizards-shared/dist/surface.js +0 -29
- package/node_modules/@engenty/wizards-shared/dist/sync.d.ts +5 -0
- package/package.json +2 -2
- package/plugin/.claude-plugin/plugin.json +1 -1
- package/plugin/plugin.json +1 -1
- package/apps/runtime/dist/assistant/primer.js +0 -26
- package/apps/web/dist/assets/Marketplace-CotMMcJ-.js +0 -2
- package/apps/web/dist/assets/SettingsPage-DPuwA3QL.js +0 -2
- package/apps/web/dist/assets/changelog-BlJc9UFS.js +0 -1
- package/apps/web/dist/assets/coins-D_yN56kT.js +0 -1
- package/apps/web/dist/assets/i18n-Dy3fTQM3.js +0 -55
- package/apps/web/dist/assets/index-Dt1Ps3ge.js +0 -34
- package/apps/web/dist/assets/index-rX7eCvWh.css +0 -1
- package/apps/web/dist/assets/ui-CL8v8Goa.js +0 -83
|
@@ -8,6 +8,7 @@ import { emitEvent, recentEvents, watchRun } from "../engine/events.js";
|
|
|
8
8
|
import { fieldErrorsIn } from "../engine/input.js";
|
|
9
9
|
import { cancel, createRun, goBack, NoCreditsError, pageContext, RunConflict, RunInputError, retry, reviewStep, runView, submitPage, } from "../engine/runner.js";
|
|
10
10
|
import { ModelUnavailableError, saidOf } from "../model-errors.js";
|
|
11
|
+
import { prompt } from "../prompts.js";
|
|
11
12
|
import { signedUrl } from "../secrets/signing.js";
|
|
12
13
|
import { currentTenant } from "../tenants/tenant.js";
|
|
13
14
|
import { brandView } from "./brand.js";
|
|
@@ -194,9 +195,7 @@ function slotHints(run, field, options) {
|
|
|
194
195
|
return {
|
|
195
196
|
times: (options ?? []).map((o) => ({ value: o, label: slotText(o, lang) })),
|
|
196
197
|
...(typeof value === "string" ? { valueText: slotText(value, lang) } : {}),
|
|
197
|
-
hint: options?.length
|
|
198
|
-
? "One appointment time: show the person the labels, answer with the value of the one they pick, exactly as given."
|
|
199
|
-
: "No times are free right now: tell the person.",
|
|
198
|
+
hint: options?.length ? prompt("mcp", "hint.slot") : prompt("mcp", "hint.slot_none"),
|
|
200
199
|
};
|
|
201
200
|
}
|
|
202
201
|
/** Where the person can go on in a browser: the run page of a live run, the studio for a test. */
|
|
@@ -223,14 +222,14 @@ async function waitingFor(run, current, draft) {
|
|
|
223
222
|
service: ask.service,
|
|
224
223
|
action: ask.action.summary,
|
|
225
224
|
input: clip(ask.input, 1500),
|
|
226
|
-
hint: "
|
|
225
|
+
hint: prompt("mcp", "hint.confirm"),
|
|
227
226
|
}
|
|
228
227
|
: {
|
|
229
228
|
ask: ask.id,
|
|
230
229
|
kind: ask.kind,
|
|
231
230
|
reason: ask.reason,
|
|
232
231
|
site: ask.site.host,
|
|
233
|
-
hint: "
|
|
232
|
+
hint: prompt("mcp", "hint.sign_in"),
|
|
234
233
|
};
|
|
235
234
|
}
|
|
236
235
|
if (run.status !== "waiting_input" || !current) {
|
|
@@ -272,7 +271,7 @@ async function waitingFor(run, current, draft) {
|
|
|
272
271
|
// page holds or not as the person answers. `shown` says so for what is known now.
|
|
273
272
|
...(f.when ? { when: f.when, shown: shown.has(f.id) } : {}),
|
|
274
273
|
})),
|
|
275
|
-
hint: "
|
|
274
|
+
hint: prompt("mcp", "hint.page"),
|
|
276
275
|
};
|
|
277
276
|
}
|
|
278
277
|
if (current.type === "review") {
|
|
@@ -281,7 +280,7 @@ async function waitingFor(run, current, draft) {
|
|
|
281
280
|
title: current.title,
|
|
282
281
|
show: current.show,
|
|
283
282
|
editable: Boolean(current.edit),
|
|
284
|
-
hint: "
|
|
283
|
+
hint: prompt("mcp", "hint.review"),
|
|
285
284
|
};
|
|
286
285
|
}
|
|
287
286
|
return undefined;
|
|
@@ -5,6 +5,7 @@ import { z } from "zod";
|
|
|
5
5
|
import { runStudioAssistant } from "../agents/studio-assistant.js";
|
|
6
6
|
import { canSpend } from "../credits/credits.js";
|
|
7
7
|
import { errorText } from "../model-errors.js";
|
|
8
|
+
import { prompt } from "../prompts.js";
|
|
8
9
|
import { currentTenant } from "../tenants/tenant.js";
|
|
9
10
|
import { serverText } from "../texts.js";
|
|
10
11
|
import { projectWritable, requireWritable } from "./access.js";
|
|
@@ -151,8 +152,7 @@ function assistMessage(input) {
|
|
|
151
152
|
.slice(0, 6)
|
|
152
153
|
.map((p) => `## ${p.title}${p.url ? ` (${p.url})` : ""}${p.role ? ` [${p.role}]` : ""}\n\n${p.markdown.slice(0, 6000)}`);
|
|
153
154
|
return [
|
|
154
|
-
|
|
155
|
-
"The details below come straight from WordPress. Read the website with read_website only when something important is missing. Invent nothing.",
|
|
155
|
+
prompt("goose", "site.wordpress", { url: input.url }),
|
|
156
156
|
`Name: ${input.name || "—"}\nTagline: ${input.tagline || "—"}\nLanguage: ${input.language ?? "—"}`,
|
|
157
157
|
input.facts.length
|
|
158
158
|
? `What the website states:\n${input.facts.map((f) => `- ${f.label}: ${f.value}`).join("\n")}`
|
|
@@ -8,6 +8,7 @@ import { generateText, jsonSchema, Output } from "ai";
|
|
|
8
8
|
import { and, eq } from "drizzle-orm";
|
|
9
9
|
import { control, controlDb, db, schema } from "../db/client.js";
|
|
10
10
|
import { textModel } from "../models.js";
|
|
11
|
+
import { prompt } from "../prompts.js";
|
|
11
12
|
import { currentTenant } from "../tenants/tenant.js";
|
|
12
13
|
import { ServiceError } from "./errors.js";
|
|
13
14
|
/**
|
|
@@ -62,11 +63,14 @@ async function translate(texts, opts) {
|
|
|
62
63
|
model: model.model,
|
|
63
64
|
output: Output.object({ schema }),
|
|
64
65
|
system: [
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
66
|
+
prompt("services", "translate.system", {
|
|
67
|
+
what: opts.what,
|
|
68
|
+
from: langNameEn(opts.from),
|
|
69
|
+
to: langNameEn(opts.to),
|
|
70
|
+
tone: prompt("services", "translate.tone", { language: langNameEn(opts.to) }),
|
|
71
|
+
}),
|
|
72
|
+
opts.extra,
|
|
73
|
+
prompt("services", "translate.return"),
|
|
70
74
|
]
|
|
71
75
|
.filter(Boolean)
|
|
72
76
|
.join("\n"),
|
|
@@ -153,7 +157,7 @@ export function translationFor(wizardId, def, lang, version) {
|
|
|
153
157
|
answer = await translate(keys, {
|
|
154
158
|
from: wizardLang(def),
|
|
155
159
|
to: lang,
|
|
156
|
-
what: "
|
|
160
|
+
what: prompt("services", "translate.wizard"),
|
|
157
161
|
});
|
|
158
162
|
}
|
|
159
163
|
catch (err) {
|
|
@@ -198,8 +202,8 @@ export async function translateResult(text, lang, from) {
|
|
|
198
202
|
const answer = await translate({ result: text }, {
|
|
199
203
|
from,
|
|
200
204
|
to: lang,
|
|
201
|
-
what: "
|
|
202
|
-
extra: "
|
|
205
|
+
what: prompt("services", "translate.result"),
|
|
206
|
+
extra: prompt("services", "translate.result.extra"),
|
|
203
207
|
});
|
|
204
208
|
return answer.result;
|
|
205
209
|
}
|
|
@@ -269,8 +273,11 @@ export function uiTexts(lang) {
|
|
|
269
273
|
answer = await translate(flat, {
|
|
270
274
|
from: "en",
|
|
271
275
|
to: lang,
|
|
272
|
-
what: "
|
|
273
|
-
extra:
|
|
276
|
+
what: prompt("services", "translate.runner"),
|
|
277
|
+
extra: prompt("services", "translate.runner.extra", {
|
|
278
|
+
categories: cats.join(", #"),
|
|
279
|
+
language: langNameEn(lang),
|
|
280
|
+
}),
|
|
274
281
|
});
|
|
275
282
|
}
|
|
276
283
|
catch (err) {
|
|
@@ -96,6 +96,14 @@ export async function listWizards(_userId, projectId) {
|
|
|
96
96
|
});
|
|
97
97
|
return rows.map(wizardSummary);
|
|
98
98
|
}
|
|
99
|
+
/** The organization has made a wizard: the studio offers itself as an app from then on. */
|
|
100
|
+
export async function hasWizards() {
|
|
101
|
+
const row = await db.query.wizard.findFirst({
|
|
102
|
+
columns: { id: true },
|
|
103
|
+
where: eq(schema.wizard.tenantId, currentTenant()),
|
|
104
|
+
});
|
|
105
|
+
return Boolean(row);
|
|
106
|
+
}
|
|
99
107
|
export async function publishedVersion(w) {
|
|
100
108
|
if (w.publishedVersion === null) {
|
|
101
109
|
return null;
|
|
@@ -4,7 +4,7 @@ import { mergeText } from "@engenty/wizards-shared/text-merge";
|
|
|
4
4
|
import { generateText } from "ai";
|
|
5
5
|
import { and, desc, eq, gt, inArray, like } from "drizzle-orm";
|
|
6
6
|
import { nanoid } from "nanoid";
|
|
7
|
-
import { accountToken, linkedAccount } from "../auth/account.js";
|
|
7
|
+
import { accountToken, knownOrganization, linkedAccount } from "../auth/account.js";
|
|
8
8
|
import { control, controlDb, db, schema, tenantSchemaVersion, withTenant as withTenantOf, } from "../db/client.js";
|
|
9
9
|
import { env } from "../env.js";
|
|
10
10
|
import { feature, remoteFeatures } from "../features.js";
|
|
@@ -137,6 +137,54 @@ export function useTransport(next) {
|
|
|
137
137
|
}
|
|
138
138
|
const stateKey = (id) => `sync:space:${id}`;
|
|
139
139
|
const EXCLUDED = "sync:excluded";
|
|
140
|
+
/**
|
|
141
|
+
* The organization each space synced with, by space. Outside `sync:`: a sign-out or a switch
|
|
142
|
+
* forgets the sync but not whose a space is, so it never goes up to another organization.
|
|
143
|
+
*/
|
|
144
|
+
const ORGANIZATIONS = "space-organizations";
|
|
145
|
+
export async function spaceOrganizations() {
|
|
146
|
+
return (await readSetting(ORGANIZATIONS)) ?? {};
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Notes the organization the account is signed in to as the one of these spaces. A space
|
|
150
|
+
* noted for another organization keeps it: it never moves between organizations.
|
|
151
|
+
*/
|
|
152
|
+
async function belongHere(ids) {
|
|
153
|
+
const account = await linkedAccount();
|
|
154
|
+
if (!(account && ids.length)) {
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
const known = await spaceOrganizations();
|
|
158
|
+
const organization = await knownOrganization();
|
|
159
|
+
const name = organization?.tenantId === account.tenantId ? organization.name : null;
|
|
160
|
+
let changed = false;
|
|
161
|
+
for (const id of ids) {
|
|
162
|
+
const before = known[id];
|
|
163
|
+
if (before && before.id !== account.tenantId) {
|
|
164
|
+
continue;
|
|
165
|
+
}
|
|
166
|
+
if (!before || (name && before.name !== name)) {
|
|
167
|
+
known[id] = { id: account.tenantId, name: name ?? before?.name ?? null };
|
|
168
|
+
changed = true;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
if (changed) {
|
|
172
|
+
await writeSetting(ORGANIZATIONS, known);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
/** The organization a space synced with, when it is not the one the account is signed in to now. */
|
|
176
|
+
async function otherOrganization(projectId) {
|
|
177
|
+
const account = await linkedAccount();
|
|
178
|
+
const owner = (await spaceOrganizations())[projectId];
|
|
179
|
+
return owner && account && owner.id !== account.tenantId ? owner : null;
|
|
180
|
+
}
|
|
181
|
+
/** A space of another organization stays here and never goes up to this one. */
|
|
182
|
+
export async function refuseOtherOrganization(projectId) {
|
|
183
|
+
const owner = await otherOrganization(projectId);
|
|
184
|
+
if (owner) {
|
|
185
|
+
throw new ServiceError("refused", note("spaceOfOtherOrganization", { organization: owner.name ?? owner.id }), { reason: "other_organization" });
|
|
186
|
+
}
|
|
187
|
+
}
|
|
140
188
|
const readState = (id) => readSetting(stateKey(id));
|
|
141
189
|
const writeState = (id, s) => writeSetting(stateKey(id), s);
|
|
142
190
|
/** The spaces of this install that sync both ways. */
|
|
@@ -586,7 +634,12 @@ export async function syncAll() {
|
|
|
586
634
|
const local = await db.query.project.findMany({ columns: { id: true } });
|
|
587
635
|
const ov = await overview(true).catch(() => null);
|
|
588
636
|
const ids = [...new Set([...local.map((p) => p.id), ...(ov?.spaces ?? []).map((s) => s.id)])];
|
|
637
|
+
// Spaces that synced before their organization was noted.
|
|
638
|
+
await belongHere([...known]);
|
|
589
639
|
for (const id of ids) {
|
|
640
|
+
if (await otherOrganization(id)) {
|
|
641
|
+
continue;
|
|
642
|
+
}
|
|
590
643
|
if (known.has(id)) {
|
|
591
644
|
await syncSpace(id);
|
|
592
645
|
}
|
|
@@ -601,6 +654,7 @@ export async function startTwoWay() {
|
|
|
601
654
|
}
|
|
602
655
|
/** A space starts to sync both ways: one this install synced one way becomes the cloud's own. */
|
|
603
656
|
export async function startSpace(projectId) {
|
|
657
|
+
await refuseOtherOrganization(projectId);
|
|
604
658
|
const excluded = ((await readSetting(EXCLUDED)) ?? []).filter((x) => x !== projectId);
|
|
605
659
|
await writeSetting(EXCLUDED, excluded);
|
|
606
660
|
if (!(await readState(projectId))) {
|
|
@@ -613,6 +667,7 @@ export async function startSpace(projectId) {
|
|
|
613
667
|
}
|
|
614
668
|
await writeState(projectId, { pushed: 0, pulled: 0, full: false, at: null, error: null });
|
|
615
669
|
}
|
|
670
|
+
await belongHere([projectId]);
|
|
616
671
|
await syncSpace(projectId);
|
|
617
672
|
}
|
|
618
673
|
/** The space syncs no more; what it holds here stays. */
|
|
@@ -704,6 +759,8 @@ export async function syncView() {
|
|
|
704
759
|
}
|
|
705
760
|
const local = await db.query.project.findMany({ columns: { id: true, name: true } });
|
|
706
761
|
const cloud = await overview().catch(() => null);
|
|
762
|
+
const account = await linkedAccount();
|
|
763
|
+
const owners = await spaceOrganizations();
|
|
707
764
|
const ids = [...new Set([...local.map((p) => p.id), ...(cloud?.spaces ?? []).map((s) => s.id)])];
|
|
708
765
|
const conflicts = await db.query.syncConflict.findMany({
|
|
709
766
|
orderBy: [desc(schema.syncConflict.createdAt)],
|
|
@@ -729,6 +786,9 @@ export async function syncView() {
|
|
|
729
786
|
conflicts: conflicts.filter((c) => c.projectId === id).length,
|
|
730
787
|
merges: merges.filter((m) => m.projectId === id).length,
|
|
731
788
|
error: sayError(st?.error ?? null),
|
|
789
|
+
organization: owners[id] && owners[id].id !== account?.tenantId
|
|
790
|
+
? (owners[id].name ?? owners[id].id)
|
|
791
|
+
: null,
|
|
732
792
|
};
|
|
733
793
|
}));
|
|
734
794
|
return {
|
|
@@ -883,6 +943,61 @@ export async function proposeMerge(id) {
|
|
|
883
943
|
issues,
|
|
884
944
|
});
|
|
885
945
|
}
|
|
946
|
+
/**
|
|
947
|
+
* Before the account switches to another organization: every change made here goes up to the
|
|
948
|
+
* organization it belongs to. The spaces that did not get there, with why; empty when all did.
|
|
949
|
+
*/
|
|
950
|
+
export async function sendBeforeSwitch() {
|
|
951
|
+
if (!(await twoWayAvailable().catch(() => false))) {
|
|
952
|
+
return [];
|
|
953
|
+
}
|
|
954
|
+
const ids = await syncedSpaceIds();
|
|
955
|
+
await belongHere(ids);
|
|
956
|
+
const stuck = [];
|
|
957
|
+
for (const id of ids) {
|
|
958
|
+
await syncSpace(id, "push");
|
|
959
|
+
const st = await readState(id);
|
|
960
|
+
const waiting = st ? (await pending(id, st)).filter((x) => x.seq > 0 || !st.full).length : 0;
|
|
961
|
+
if (st?.error || waiting) {
|
|
962
|
+
const here = await db.query.project.findFirst({
|
|
963
|
+
where: eq(schema.project.id, id),
|
|
964
|
+
columns: { name: true },
|
|
965
|
+
});
|
|
966
|
+
stuck.push({
|
|
967
|
+
name: here?.name ?? id,
|
|
968
|
+
message: st?.error?.message ?? noteText(note("syncChangesWaiting"), "en"),
|
|
969
|
+
});
|
|
970
|
+
}
|
|
971
|
+
}
|
|
972
|
+
return stuck;
|
|
973
|
+
}
|
|
974
|
+
/**
|
|
975
|
+
* A switch to another organization, before its sync is forgotten as at a sign-out: the spaces
|
|
976
|
+
* that sync are noted as the organization's own. They stay here and sync again after a switch back.
|
|
977
|
+
*/
|
|
978
|
+
export async function noteSyncedSpaces() {
|
|
979
|
+
// Without the two-way sync, the spaces of wizards published to the cloud one way.
|
|
980
|
+
const sent = await controlDb
|
|
981
|
+
.select({ key: control.setting.key })
|
|
982
|
+
.from(control.setting)
|
|
983
|
+
.where(like(control.setting.key, "cloud:%"));
|
|
984
|
+
const wizards = sent.length
|
|
985
|
+
? await db
|
|
986
|
+
.select({ projectId: schema.wizard.projectId })
|
|
987
|
+
.from(schema.wizard)
|
|
988
|
+
.where(inArray(schema.wizard.id, sent.map((r) => r.key.slice("cloud:".length))))
|
|
989
|
+
: [];
|
|
990
|
+
await belongHere([...new Set([...(await syncedSpaceIds()), ...wizards.map((w) => w.projectId)])]);
|
|
991
|
+
}
|
|
992
|
+
/**
|
|
993
|
+
* After a switch: spaces that never synced with any organization stay on this computer only,
|
|
994
|
+
* until the person turns them on for the new one.
|
|
995
|
+
*/
|
|
996
|
+
export async function keepUnsyncedHere() {
|
|
997
|
+
const owners = await spaceOrganizations();
|
|
998
|
+
const local = await db.query.project.findMany({ columns: { id: true } });
|
|
999
|
+
await writeSetting(EXCLUDED, local.map((p) => p.id).filter((id) => !owners[id]));
|
|
1000
|
+
}
|
|
886
1001
|
/** The account was unlinked: nothing syncs any more, and what was kept of the cloud goes. */
|
|
887
1002
|
export async function forgetTwoWay() {
|
|
888
1003
|
setTwoWayActive(false);
|
|
@@ -8,6 +8,7 @@ import { createFieldText } from "../browser/fast/text-helper.js";
|
|
|
8
8
|
import { nodeScript, PAGE_SCRIPT, settleScript, targetScript, } from "../browser/snapshot.js";
|
|
9
9
|
import { env } from "../env.js";
|
|
10
10
|
import { costOf, textModel } from "../models.js";
|
|
11
|
+
import { prompt } from "../prompts.js";
|
|
11
12
|
import { assertPublicUrl } from "./net-guard.js";
|
|
12
13
|
import { attempt, imageOutput } from "./shared.js";
|
|
13
14
|
import { resolveFile } from "./store.js";
|
|
@@ -58,7 +59,7 @@ function line(item) {
|
|
|
58
59
|
*/
|
|
59
60
|
export function pageForModel(view) {
|
|
60
61
|
const more = view.omitted
|
|
61
|
-
? `\n
|
|
62
|
+
? `\n${prompt("tools", "note.browser_more", { count: view.omitted })}`
|
|
62
63
|
: "";
|
|
63
64
|
return {
|
|
64
65
|
url: view.url,
|
|
@@ -114,13 +115,13 @@ async function signedInGet(page, url) {
|
|
|
114
115
|
function targetError(n, target) {
|
|
115
116
|
switch (target.error) {
|
|
116
117
|
case "covered":
|
|
117
|
-
return
|
|
118
|
+
return prompt("tools", "note.browser_covered", { ref: n, by: String(target.by) });
|
|
118
119
|
case "disabled":
|
|
119
|
-
return
|
|
120
|
+
return prompt("tools", "note.browser_disabled", { ref: n });
|
|
120
121
|
case "gone":
|
|
121
|
-
return
|
|
122
|
+
return prompt("tools", "note.browser_gone", { ref: n });
|
|
122
123
|
default:
|
|
123
|
-
return
|
|
124
|
+
return prompt("tools", "note.browser_hidden", { ref: n });
|
|
124
125
|
}
|
|
125
126
|
}
|
|
126
127
|
/**
|
|
@@ -210,10 +211,6 @@ async function fillCredentials(page, origin, fields, values) {
|
|
|
210
211
|
}
|
|
211
212
|
return { filled };
|
|
212
213
|
}
|
|
213
|
-
const NOBODY = "Nobody is at the keyboard for this run, so a sign-in cannot be asked for. Go on without it and report what the person has to do.";
|
|
214
|
-
const DECLINED = "The person did not sign in. Do not ask again for this site; go on without it and say in your result what is missing and what the person can do.";
|
|
215
|
-
const TOOK_OVER = "The person took the browser over and has handed it back; nothing you asked for was done. The page may have changed — here it is as it stands now. Go on from here.";
|
|
216
|
-
const RUN_FAST_DESCRIPTION = "Hand a small, concrete browser sub-goal to the fast executor: on the CURRENT page it reads the visible controls, picks one element per step with a classifier (no language model), types field values taken from your goal, and repeats until the goal is visibly satisfied or it is unsure. Use it for mechanical sequences — click a cookie banner away, fill and submit a form, pick a date in a calendar, choose an autocomplete suggestion, set filters and dropdowns, open a matching result. Give one page's worth of work per call with every value spelled out (dates, names, filters); it never invents data. Returns status `done`, or `uncertain`/`blocked`/`budget`/`error` with the page and a note naming the step it could not decide. Then do THAT ONE step with the other browser_* tools and call browser_run_fast again with the same goal — do not finish the rest by hand. Open the page with browser_open first; it does not open URLs.";
|
|
217
214
|
/** One line of at most 60 characters, for the run's log. */
|
|
218
215
|
function short(text) {
|
|
219
216
|
const one = text.trim().replace(/\s+/g, " ");
|
|
@@ -262,7 +259,7 @@ export async function browserTools(ctx, assets, files) {
|
|
|
262
259
|
// back, the agent gets the page as they left it instead.
|
|
263
260
|
const acting = (run) => inTurn(async () => {
|
|
264
261
|
if (await ctx.resources.agentTurn(ctx.signal)) {
|
|
265
|
-
return { note:
|
|
262
|
+
return { note: prompt("tools", "note.browser_took_over"), page: await read(await page()) };
|
|
266
263
|
}
|
|
267
264
|
return run();
|
|
268
265
|
});
|
|
@@ -272,7 +269,7 @@ export async function browserTools(ctx, assets, files) {
|
|
|
272
269
|
};
|
|
273
270
|
tools.browser_open = createTool({
|
|
274
271
|
id: "browser_open",
|
|
275
|
-
description: "
|
|
272
|
+
description: prompt("tools", "tool.browser_open"),
|
|
276
273
|
inputSchema: z.object({ url: z.string() }),
|
|
277
274
|
execute: ({ url }) => acting(async () => {
|
|
278
275
|
const safe = await assertPublicUrl(url);
|
|
@@ -286,13 +283,13 @@ export async function browserTools(ctx, assets, files) {
|
|
|
286
283
|
});
|
|
287
284
|
tools.browser_read = createTool({
|
|
288
285
|
id: "browser_read",
|
|
289
|
-
description: "
|
|
286
|
+
description: prompt("tools", "tool.browser_read"),
|
|
290
287
|
inputSchema: z.object({}),
|
|
291
288
|
execute: () => acting(async () => read(await page())),
|
|
292
289
|
});
|
|
293
290
|
tools.browser_click = createTool({
|
|
294
291
|
id: "browser_click",
|
|
295
|
-
description: "
|
|
292
|
+
description: prompt("tools", "tool.browser_click"),
|
|
296
293
|
inputSchema: z.object({ ref: z.number() }),
|
|
297
294
|
execute: ({ ref: n }) => acting(async () => {
|
|
298
295
|
const p = await page();
|
|
@@ -307,7 +304,7 @@ export async function browserTools(ctx, assets, files) {
|
|
|
307
304
|
});
|
|
308
305
|
tools.browser_type = createTool({
|
|
309
306
|
id: "browser_type",
|
|
310
|
-
description: "
|
|
307
|
+
description: prompt("tools", "tool.browser_type"),
|
|
311
308
|
inputSchema: z.object({ ref: z.number(), text: z.string(), submit: z.boolean().optional() }),
|
|
312
309
|
execute: ({ ref: n, text, submit }) => acting(async () => {
|
|
313
310
|
const p = await page();
|
|
@@ -321,7 +318,7 @@ export async function browserTools(ctx, assets, files) {
|
|
|
321
318
|
}
|
|
322
319
|
if ((await el.evaluate((e) => e.type)) === "password") {
|
|
323
320
|
return {
|
|
324
|
-
error:
|
|
321
|
+
error: prompt("tools", "note.browser_password_field", { ref: n }),
|
|
325
322
|
};
|
|
326
323
|
}
|
|
327
324
|
const said = short(text);
|
|
@@ -336,7 +333,7 @@ export async function browserTools(ctx, assets, files) {
|
|
|
336
333
|
});
|
|
337
334
|
tools.browser_select = createTool({
|
|
338
335
|
id: "browser_select",
|
|
339
|
-
description: "
|
|
336
|
+
description: prompt("tools", "tool.browser_select"),
|
|
340
337
|
inputSchema: z.object({ ref: z.number(), option: z.string() }),
|
|
341
338
|
execute: ({ ref: n, option }) => acting(async () => {
|
|
342
339
|
const p = await page();
|
|
@@ -360,7 +357,7 @@ export async function browserTools(ctx, assets, files) {
|
|
|
360
357
|
});
|
|
361
358
|
tools.browser_scroll = createTool({
|
|
362
359
|
id: "browser_scroll",
|
|
363
|
-
description: "
|
|
360
|
+
description: prompt("tools", "tool.browser_scroll"),
|
|
364
361
|
inputSchema: z.object({
|
|
365
362
|
direction: z.enum(["down", "up"]).optional(),
|
|
366
363
|
ref: z.number().optional(),
|
|
@@ -385,7 +382,7 @@ export async function browserTools(ctx, assets, files) {
|
|
|
385
382
|
});
|
|
386
383
|
tools.browser_press = createTool({
|
|
387
384
|
id: "browser_press",
|
|
388
|
-
description: "
|
|
385
|
+
description: prompt("tools", "tool.browser_press"),
|
|
389
386
|
inputSchema: z.object({
|
|
390
387
|
key: z.enum([
|
|
391
388
|
"Enter",
|
|
@@ -411,7 +408,7 @@ export async function browserTools(ctx, assets, files) {
|
|
|
411
408
|
});
|
|
412
409
|
tools.browser_back = createTool({
|
|
413
410
|
id: "browser_back",
|
|
414
|
-
description: "
|
|
411
|
+
description: prompt("tools", "tool.browser_back"),
|
|
415
412
|
inputSchema: z.object({}),
|
|
416
413
|
execute: () => acting(async () => {
|
|
417
414
|
const p = await page();
|
|
@@ -427,7 +424,7 @@ export async function browserTools(ctx, assets, files) {
|
|
|
427
424
|
});
|
|
428
425
|
tools.browser_wait = createTool({
|
|
429
426
|
id: "browser_wait",
|
|
430
|
-
description: "
|
|
427
|
+
description: prompt("tools", "tool.browser_wait"),
|
|
431
428
|
inputSchema: z.object({
|
|
432
429
|
text: z.string().optional().describe("Wait until this text is on the page."),
|
|
433
430
|
seconds: z.number().min(1).max(15).optional().describe("How long at most; default 5."),
|
|
@@ -455,7 +452,7 @@ export async function browserTools(ctx, assets, files) {
|
|
|
455
452
|
});
|
|
456
453
|
tools.browser_screenshot = createTool({
|
|
457
454
|
id: "browser_screenshot",
|
|
458
|
-
description: "
|
|
455
|
+
description: prompt("tools", "tool.browser_screenshot"),
|
|
459
456
|
inputSchema: z.object({ save: z.boolean().optional(), name: z.string().optional() }),
|
|
460
457
|
execute: ({ save, name }) => inTurn(async () => {
|
|
461
458
|
const p = await page();
|
|
@@ -480,13 +477,13 @@ export async function browserTools(ctx, assets, files) {
|
|
|
480
477
|
const p = await page();
|
|
481
478
|
const origin = originOf(p.url());
|
|
482
479
|
if (!origin) {
|
|
483
|
-
return { error: "no_site", note: "
|
|
480
|
+
return { error: "no_site", note: prompt("tools", "note.browser_no_site") };
|
|
484
481
|
}
|
|
485
482
|
for (const field of input.fields) {
|
|
486
483
|
if (!(await handleOf(p, field.ref))) {
|
|
487
484
|
return {
|
|
488
485
|
error: "fields_not_found",
|
|
489
|
-
note:
|
|
486
|
+
note: prompt("tools", "note.browser_fields_gone", { ref: field.ref }),
|
|
490
487
|
};
|
|
491
488
|
}
|
|
492
489
|
}
|
|
@@ -505,20 +502,20 @@ export async function browserTools(ctx, assets, files) {
|
|
|
505
502
|
})),
|
|
506
503
|
});
|
|
507
504
|
if (!answer) {
|
|
508
|
-
return { status: "needs_person", note:
|
|
505
|
+
return { status: "needs_person", note: prompt("tools", "note.browser_nobody") };
|
|
509
506
|
}
|
|
510
507
|
if (answer.type === "skip" || answer.type === "timeout") {
|
|
511
|
-
return { status: "declined", note:
|
|
508
|
+
return { status: "declined", note: prompt("tools", "note.browser_declined") };
|
|
512
509
|
}
|
|
513
510
|
// The person may have gone on in a tab the site opened.
|
|
514
511
|
const current = ctx.resources.openPage() ?? p;
|
|
515
|
-
let note = "
|
|
512
|
+
let note = prompt("tools", "note.browser_signed_in_self");
|
|
516
513
|
if (answer.type === "fill") {
|
|
517
514
|
const result = await fillCredentials(current, origin, input.fields, answer.values);
|
|
518
515
|
if ("error" in result) {
|
|
519
516
|
return {
|
|
520
517
|
error: result.error,
|
|
521
|
-
note: "
|
|
518
|
+
note: prompt("tools", "note.browser_fill_failed"),
|
|
522
519
|
};
|
|
523
520
|
}
|
|
524
521
|
if (result.filled.length && input.submitRef !== undefined) {
|
|
@@ -529,7 +526,13 @@ export async function browserTools(ctx, assets, files) {
|
|
|
529
526
|
}
|
|
530
527
|
await settle(current);
|
|
531
528
|
await current.waitForLoadState("networkidle", { timeout: 5000 }).catch(() => undefined);
|
|
532
|
-
note =
|
|
529
|
+
note = [
|
|
530
|
+
prompt("tools", "note.browser_entered", { fields: result.filled.join(", ") }),
|
|
531
|
+
input.submitRef !== undefined ? prompt("tools", "note.browser_entered_submitted") : "",
|
|
532
|
+
prompt("tools", "note.browser_entered_unseen"),
|
|
533
|
+
]
|
|
534
|
+
.filter(Boolean)
|
|
535
|
+
.join(" ");
|
|
533
536
|
}
|
|
534
537
|
if (answer.remember) {
|
|
535
538
|
await ctx.resources.keepSession().catch(() => undefined);
|
|
@@ -538,7 +541,7 @@ export async function browserTools(ctx, assets, files) {
|
|
|
538
541
|
};
|
|
539
542
|
tools.browser_request_credentials = createTool({
|
|
540
543
|
id: "browser_request_credentials",
|
|
541
|
-
description: "
|
|
544
|
+
description: prompt("tools", "tool.browser_request_credentials"),
|
|
542
545
|
inputSchema: z.object({
|
|
543
546
|
reason: z
|
|
544
547
|
.string()
|
|
@@ -555,7 +558,7 @@ export async function browserTools(ctx, assets, files) {
|
|
|
555
558
|
});
|
|
556
559
|
tools.browser_request_user = createTool({
|
|
557
560
|
id: "browser_request_user",
|
|
558
|
-
description: "
|
|
561
|
+
description: prompt("tools", "tool.browser_request_user"),
|
|
559
562
|
inputSchema: z.object({
|
|
560
563
|
reason: z
|
|
561
564
|
.string()
|
|
@@ -567,7 +570,7 @@ export async function browserTools(ctx, assets, files) {
|
|
|
567
570
|
});
|
|
568
571
|
tools.browser_upload = createTool({
|
|
569
572
|
id: "browser_upload",
|
|
570
|
-
description:
|
|
573
|
+
description: prompt("tools", "tool.browser_upload"),
|
|
571
574
|
inputSchema: z.object({
|
|
572
575
|
ref: z.number().describe("[number] of the file input or the upload button."),
|
|
573
576
|
file: z.string().describe("upload:<id>, result:<step>.<format>, or a kept file's path."),
|
|
@@ -614,7 +617,7 @@ export async function browserTools(ctx, assets, files) {
|
|
|
614
617
|
});
|
|
615
618
|
tools.browser_download = createTool({
|
|
616
619
|
id: "browser_download",
|
|
617
|
-
description: "
|
|
620
|
+
description: prompt("tools", "tool.browser_download"),
|
|
618
621
|
inputSchema: z.object({
|
|
619
622
|
ref: z.number().optional().describe("[number] of the download link or button."),
|
|
620
623
|
url: z.string().optional().describe("Direct URL of the file, instead of ref."),
|
|
@@ -711,7 +714,7 @@ export async function browserTools(ctx, assets, files) {
|
|
|
711
714
|
});
|
|
712
715
|
tools.browser_run_fast = createTool({
|
|
713
716
|
id: "browser_run_fast",
|
|
714
|
-
description:
|
|
717
|
+
description: prompt("tools", "tool.browser_run_fast"),
|
|
715
718
|
inputSchema: z.object({
|
|
716
719
|
goal: z
|
|
717
720
|
.string()
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
2
2
|
import { createCodeMode, createTool, noopObserve } from "@mastra/core/tools";
|
|
3
3
|
import { QuickJsCodeModeTransport } from "@mastra/quickjs";
|
|
4
|
+
import { prompt } from "../prompts.js";
|
|
4
5
|
import { clip } from "./shared.js";
|
|
5
6
|
/**
|
|
6
7
|
* Code Mode: the model writes one TypeScript program that calls the step's tools as
|
|
@@ -94,10 +95,10 @@ function guarded(tools, ctx, limits, step) {
|
|
|
94
95
|
calls++;
|
|
95
96
|
step.calls++;
|
|
96
97
|
if (calls > limits.maxCalls) {
|
|
97
|
-
throw new Error(
|
|
98
|
+
throw new Error(prompt("tools", "note.code_max_calls", { maxCalls: limits.maxCalls }));
|
|
98
99
|
}
|
|
99
100
|
if (step.calls > limits.stepCalls) {
|
|
100
|
-
throw new Error(
|
|
101
|
+
throw new Error(prompt("tools", "note.code_step_calls", { stepCalls: limits.stepCalls }));
|
|
101
102
|
}
|
|
102
103
|
if (ctx.signal.aborted) {
|
|
103
104
|
throw new Error("The run was stopped.");
|
|
@@ -106,7 +107,11 @@ function guarded(tools, ctx, limits, step) {
|
|
|
106
107
|
const answer = await program.run(true, () => tool.execute(input, options));
|
|
107
108
|
const size = JSON.stringify(answer ?? null)?.length ?? 0;
|
|
108
109
|
if (size > limits.answerChars) {
|
|
109
|
-
throw new Error(
|
|
110
|
+
throw new Error(prompt("tools", "note.code_answer_too_long", {
|
|
111
|
+
tool: key,
|
|
112
|
+
size,
|
|
113
|
+
answerChars: limits.answerChars,
|
|
114
|
+
}));
|
|
110
115
|
}
|
|
111
116
|
return answer;
|
|
112
117
|
});
|
|
@@ -129,7 +134,7 @@ export function codeTool(tools, ctx, limits = CODE_LIMITS) {
|
|
|
129
134
|
const { tool: base, instructions } = createCodeMode(config, quickJs());
|
|
130
135
|
const tool = createTool({
|
|
131
136
|
id: CODE_TOOL_ID,
|
|
132
|
-
description: "
|
|
137
|
+
description: prompt("tools", "tool.execute_typescript"),
|
|
133
138
|
inputSchema: base.inputSchema,
|
|
134
139
|
execute: async (input, options) => {
|
|
135
140
|
await ctx.emit("tool", { code: "runsProgram" });
|
|
@@ -148,7 +153,9 @@ export function codeTool(tools, ctx, limits = CODE_LIMITS) {
|
|
|
148
153
|
return {
|
|
149
154
|
success: false,
|
|
150
155
|
error: {
|
|
151
|
-
message:
|
|
156
|
+
message: prompt("tools", "note.code_failed", {
|
|
157
|
+
error: String(err?.message ?? err).slice(0, 120),
|
|
158
|
+
}),
|
|
152
159
|
},
|
|
153
160
|
};
|
|
154
161
|
}
|
|
@@ -168,6 +175,13 @@ export function codeTool(tools, ctx, limits = CODE_LIMITS) {
|
|
|
168
175
|
});
|
|
169
176
|
return {
|
|
170
177
|
tool,
|
|
171
|
-
instructions: `${instructions}\n\
|
|
178
|
+
instructions: `${instructions}\n\n${prompt("tools", "tool.execute_typescript.limits", {
|
|
179
|
+
maxCalls: limits.maxCalls,
|
|
180
|
+
maxParallel: limits.maxParallel,
|
|
181
|
+
seconds: limits.timeoutMs / 1000,
|
|
182
|
+
stepCalls: limits.stepCalls,
|
|
183
|
+
resultChars: limits.resultChars,
|
|
184
|
+
paidTools: [...PAID_TOOLS].join(", "),
|
|
185
|
+
})}`,
|
|
172
186
|
};
|
|
173
187
|
}
|