@engenty/wizards-runtime 0.11.6 → 0.11.8
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 +37 -53
- package/apps/runtime/dist/agents/company.js +4 -12
- package/apps/runtime/dist/agents/studio-assistant.js +57 -70
- package/apps/runtime/dist/agents/subscription.js +3 -6
- package/apps/runtime/dist/app.js +3 -0
- package/apps/runtime/dist/assistant/knows.js +19 -19
- package/apps/runtime/dist/auth/account.js +51 -12
- 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/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/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/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/open-command.js +31 -0
- 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 +19 -1
- package/apps/runtime/dist/safety.js +45 -0
- package/apps/runtime/dist/sandbox/index.js +8 -3
- package/apps/runtime/dist/services/assistant-chats.js +5 -8
- package/apps/runtime/dist/services/brand.js +2 -7
- 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/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-30Mc1_N_.js → AboutDialog-BWc0zi6S.js} +1 -1
- package/apps/web/dist/assets/{ChangelogDialog-Vjxg6JV8.js → ChangelogDialog-Ctkpgtt8.js} +1 -1
- package/apps/web/dist/assets/{CodeEditor-CmMRfVhS.js → CodeEditor-ydfkafOX.js} +1 -1
- package/apps/web/dist/assets/{EditorPage-Di5KB-Ei.js → EditorPage-C2lCK9wY.js} +1 -1
- package/apps/web/dist/assets/{FlowPreview-BkcO3iCf.js → FlowPreview-CPEK110v.js} +1 -1
- package/apps/web/dist/assets/{Harness-D_Hr80Fo.js → Harness-CeEYZGHB.js} +1 -1
- package/apps/web/dist/assets/Marketplace-_IfcAgYO.js +2 -0
- package/apps/web/dist/assets/{NewWizardChannels-BIzOtfc8.js → NewWizardChannels-Rq4Oc1OM.js} +1 -1
- package/apps/web/dist/assets/{NewWizardPage-BenzMrPD.js → NewWizardPage-CCR_U2vH.js} +1 -1
- package/apps/web/dist/assets/{OnboardingPage-DuckyzQr.js → OnboardingPage-CcaxqyzN.js} +1 -1
- package/apps/web/dist/assets/{PreviewPane-D9hmriSm.js → PreviewPane-By692ez7.js} +2 -2
- package/apps/web/dist/assets/{ProjectPage-A8Z8cS1E.js → ProjectPage-ClMgq06-.js} +1 -1
- package/apps/web/dist/assets/PublicRunner-BtUu5LCy.js +1 -0
- package/apps/web/dist/assets/{ReadOnly-DFn32cvo.js → ReadOnly-B2BSJ7ms.js} +1 -1
- package/apps/web/dist/assets/SettingsPage-DGHco15-.js +2 -0
- package/apps/web/dist/assets/{SetupPage-WNHH74hu.js → SetupPage-CNJY56MI.js} +1 -1
- package/apps/web/dist/assets/{SharePage-Bw4TRWtv.js → SharePage-ZolaYse9.js} +1 -1
- package/apps/web/dist/assets/changelog-CWPHX0Hf.js +1 -0
- package/apps/web/dist/assets/i18n-BX8GnEZT.js +55 -0
- package/apps/web/dist/assets/index-5U3h_chZ.js +34 -0
- package/apps/web/dist/assets/{index-Bha72INy.css → index-BYZBN0xx.css} +1 -1
- package/apps/web/dist/assets/{oss-credits-CZT1KRIp.js → oss-credits-Da4KrYmP.js} +1 -1
- package/apps/web/dist/assets/{phone-DymZ7rLO.js → phone-Dd7IVbpJ.js} +1 -1
- package/apps/web/dist/assets/{runners-UfKeoOe4.js → runners-XifDCQG3.js} +1 -1
- package/apps/web/dist/assets/{session-COf_im0l.js → session-BwtsznZF.js} +1 -1
- package/apps/web/dist/assets/{settings-menu-mtOjI15L.js → settings-menu-CS-fXrFW.js} +1 -1
- package/apps/web/dist/assets/{theme-DWoTWDAG.js → theme-CnRjADMg.js} +2 -2
- package/apps/web/dist/assets/ui-D719V_Yj.js +83 -0
- package/apps/web/dist/assets/{upload-BizIzwxa.js → upload-CYTDCrYd.js} +1 -1
- package/apps/web/dist/assets/{useMutation-BJfRETsQ.js → useMutation-CVVmJvyz.js} +1 -1
- package/apps/web/dist/assets/{volume-2-BGkyA8T9.js → volume-2-Do0dsjv2.js} +1 -1
- package/apps/web/dist/assets/{wrench-Be5zav03.js → wrench-C5syJD9J.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/run.d.ts +5 -0
- package/node_modules/@engenty/wizards-shared/dist/run.js +10 -0
- package/node_modules/@engenty/wizards-shared/dist/runner-texts.d.ts +3 -1
- package/node_modules/@engenty/wizards-shared/dist/runner-texts.js +2 -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-BxFBMUsi.js +0 -2
- package/apps/web/dist/assets/PublicRunner-QPvlEAxx.js +0 -1
- package/apps/web/dist/assets/SettingsPage-ByP15ndy.js +0 -2
- package/apps/web/dist/assets/changelog-Dr9tAFY9.js +0 -1
- package/apps/web/dist/assets/coins-DTH3SKgZ.js +0 -1
- package/apps/web/dist/assets/i18n-CLxuuhp_.js +0 -55
- package/apps/web/dist/assets/index-HhslPV6N.js +0 -34
- package/apps/web/dist/assets/ui-D_0Xdrjh.js +0 -83
|
@@ -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
|
}
|
|
@@ -2,10 +2,10 @@ import { createTool } from "@mastra/core/tools";
|
|
|
2
2
|
import { z } from "zod";
|
|
3
3
|
import { refreshConnector, resolveConnector } from "../connectors/external.js";
|
|
4
4
|
import { connectionContext } from "../connectors/index.js";
|
|
5
|
+
import { prompt } from "../prompts.js";
|
|
5
6
|
import { inProgram } from "./code.js";
|
|
6
7
|
import { attempt, clip } from "./shared.js";
|
|
7
8
|
import { resolveFile } from "./store.js";
|
|
8
|
-
const FILE_NOTE = " File content never passes through you: returned content is kept as a file and you get its path; to send a file, give `file:<path>` of a kept file or `file:result:<step>.<format>` of a result where an input asks for `*_base64`.";
|
|
9
9
|
/** Above this many actions a connector is offered as "find an action, then call it". */
|
|
10
10
|
const DIRECT_TOOLS = 24;
|
|
11
11
|
const TOOL_NAME = /^[a-zA-Z0-9_-]{1,64}$/;
|
|
@@ -59,7 +59,7 @@ async function keepContent(result, action, service, files) {
|
|
|
59
59
|
});
|
|
60
60
|
delete out[key];
|
|
61
61
|
out.saved = kept.path;
|
|
62
|
-
out.note = "
|
|
62
|
+
out.note = prompt("tools", "note.connector_kept");
|
|
63
63
|
}
|
|
64
64
|
return out;
|
|
65
65
|
}
|
|
@@ -77,6 +77,8 @@ async function sendContent(input, ctx) {
|
|
|
77
77
|
}
|
|
78
78
|
return out;
|
|
79
79
|
}
|
|
80
|
+
/** A text that ends as a sentence, so the notes after it read as their own. */
|
|
81
|
+
const sentence = (text) => (/[.!?]$/.test(text.trim()) ? text.trim() : `${text.trim()}.`);
|
|
80
82
|
/**
|
|
81
83
|
* Whether the person is asked before an action runs. The wizard's author can settle it per
|
|
82
84
|
* action (a server may call a plain lookup a change); deleting is never taken off the person.
|
|
@@ -113,14 +115,14 @@ export async function toolsOf(connection, ctx, files) {
|
|
|
113
115
|
const found = await account();
|
|
114
116
|
if (!found) {
|
|
115
117
|
return {
|
|
116
|
-
error:
|
|
118
|
+
error: prompt("tools", "note.connector_not_connected", { service }),
|
|
117
119
|
};
|
|
118
120
|
}
|
|
119
121
|
const key = `${connection.id}:${action.id}`;
|
|
120
122
|
if (asks(connection, action) && !ctx.resources.allowed.has(key)) {
|
|
121
123
|
if (inProgram()) {
|
|
122
124
|
return {
|
|
123
|
-
error: "
|
|
125
|
+
error: prompt("tools", "note.connector_in_program"),
|
|
124
126
|
};
|
|
125
127
|
}
|
|
126
128
|
const answer = await ctx.ask({
|
|
@@ -136,12 +138,12 @@ export async function toolsOf(connection, ctx, files) {
|
|
|
136
138
|
});
|
|
137
139
|
if (!answer) {
|
|
138
140
|
return {
|
|
139
|
-
error: "
|
|
141
|
+
error: prompt("tools", "note.connector_nobody"),
|
|
140
142
|
};
|
|
141
143
|
}
|
|
142
144
|
if (answer.type !== "done") {
|
|
143
145
|
return {
|
|
144
|
-
error: "
|
|
146
|
+
error: prompt("tools", "note.connector_declined"),
|
|
145
147
|
};
|
|
146
148
|
}
|
|
147
149
|
if (answer.remember) {
|
|
@@ -154,13 +156,21 @@ export async function toolsOf(connection, ctx, files) {
|
|
|
154
156
|
return { result: clip(text ?? "", 8000) };
|
|
155
157
|
});
|
|
156
158
|
const prefix = connector.toolPrefix;
|
|
159
|
+
const fileNote = prompt("tools", "connector.file_note");
|
|
157
160
|
const direct = usable.length <= DIRECT_TOOLS && usable.every((a) => TOOL_NAME.test(`${prefix}_${a.id}`));
|
|
158
161
|
if (direct) {
|
|
159
162
|
return Object.fromEntries(usable.map((action) => [
|
|
160
163
|
`${prefix}_${action.id}`,
|
|
161
164
|
createTool({
|
|
162
165
|
id: `${prefix}_${action.id}`,
|
|
163
|
-
description:
|
|
166
|
+
description: [
|
|
167
|
+
sentence(`${service}: ${action.description || action.summary}`),
|
|
168
|
+
asks(connection, action) ? prompt("tools", "connector.asks") : "",
|
|
169
|
+
fileNote,
|
|
170
|
+
]
|
|
171
|
+
.filter(Boolean)
|
|
172
|
+
.join(" ")
|
|
173
|
+
.slice(0, 1100),
|
|
164
174
|
inputSchema: action.inputSchema,
|
|
165
175
|
execute: (input) => call(action, input),
|
|
166
176
|
}),
|
|
@@ -169,7 +179,11 @@ export async function toolsOf(connection, ctx, files) {
|
|
|
169
179
|
return {
|
|
170
180
|
[`${prefix}_actions`]: createTool({
|
|
171
181
|
id: `${prefix}_actions`,
|
|
172
|
-
description:
|
|
182
|
+
description: prompt("tools", "connector.actions", {
|
|
183
|
+
service,
|
|
184
|
+
count: usable.length,
|
|
185
|
+
prefix,
|
|
186
|
+
}),
|
|
173
187
|
inputSchema: z.object({
|
|
174
188
|
query: z.string().describe("Words to look for, e.g. 'search pages' or 'invoice list'."),
|
|
175
189
|
}),
|
|
@@ -195,7 +209,7 @@ export async function toolsOf(connection, ctx, files) {
|
|
|
195
209
|
}),
|
|
196
210
|
[`${prefix}_call`]: createTool({
|
|
197
211
|
id: `${prefix}_call`,
|
|
198
|
-
description:
|
|
212
|
+
description: `${prompt("tools", "connector.call", { service, prefix })} ${fileNote}`,
|
|
199
213
|
inputSchema: z.object({
|
|
200
214
|
action: z.string(),
|
|
201
215
|
input: z.record(z.string(), z.unknown()).optional(),
|