@engenty/wizards-runtime 0.9.7 → 0.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (124) hide show
  1. package/apps/runtime/dist/agents/architect.js +4 -2
  2. package/apps/runtime/dist/agents/company.js +1 -1
  3. package/apps/runtime/dist/agents/studio-assistant.js +1 -1
  4. package/apps/runtime/dist/app.js +18 -1
  5. package/apps/runtime/dist/assistant/primer.js +1 -1
  6. package/apps/runtime/dist/auth/index.js +10 -1
  7. package/apps/runtime/dist/authoring/example.js +2 -2
  8. package/apps/runtime/dist/authoring/guide.js +11 -11
  9. package/apps/runtime/dist/credits/estimate.js +5 -5
  10. package/apps/runtime/dist/db/adopt.js +4 -3
  11. package/apps/runtime/dist/db/client.js +9 -1
  12. package/apps/runtime/dist/db/migrations/control/0011_model_classes.sql +11 -0
  13. package/apps/runtime/dist/db/migrations/control/meta/0011_snapshot.json +600 -0
  14. package/apps/runtime/dist/db/migrations/control/meta/_journal.json +7 -0
  15. package/apps/runtime/dist/db/migrations/tenant/0021_model_classes.sql +41 -0
  16. package/apps/runtime/dist/db/migrations/tenant/0022_sync.sql +247 -0
  17. package/apps/runtime/dist/db/migrations/tenant/meta/0021_snapshot.json +3475 -0
  18. package/apps/runtime/dist/db/migrations/tenant/meta/0022_snapshot.json +3792 -0
  19. package/apps/runtime/dist/db/migrations/tenant/meta/_journal.json +14 -0
  20. package/apps/runtime/dist/db/schema.js +60 -0
  21. package/apps/runtime/dist/docs/dev/plugins/quick-start.md +2 -2
  22. package/apps/runtime/dist/docs/dev/plugins/server.md +2 -2
  23. package/apps/runtime/dist/docs/dev/wizard-format/agent-steps.md +9 -5
  24. package/apps/runtime/dist/docs/dev/wizard-format/film-steps.md +2 -2
  25. package/apps/runtime/dist/docs/dev/wizard-format/index.md +14 -8
  26. package/apps/runtime/dist/docs/user-guide/cloud-sync.md +85 -0
  27. package/apps/runtime/dist/docs/user-guide/data.md +4 -4
  28. package/apps/runtime/dist/docs/user-guide/meta.json +1 -0
  29. package/apps/runtime/dist/docs/user-guide/models.md +22 -13
  30. package/apps/runtime/dist/docs/user-guide/steps.md +6 -6
  31. package/apps/runtime/dist/docs/user-guide/test-and-share.md +4 -14
  32. package/apps/runtime/dist/documents/parse.js +1 -1
  33. package/apps/runtime/dist/engine/requirements.js +11 -11
  34. package/apps/runtime/dist/engine/steps.js +4 -4
  35. package/apps/runtime/dist/env.js +4 -4
  36. package/apps/runtime/dist/files/blobs.js +13 -0
  37. package/apps/runtime/dist/film/step.js +1 -1
  38. package/apps/runtime/dist/harness/antigravity.js +3 -3
  39. package/apps/runtime/dist/harness/apple.js +1 -1
  40. package/apps/runtime/dist/harness/claude.js +2 -2
  41. package/apps/runtime/dist/harness/codex.js +3 -3
  42. package/apps/runtime/dist/harness/cursor.js +1 -1
  43. package/apps/runtime/dist/index.js +7 -1
  44. package/apps/runtime/dist/mcp/tools.js +6 -3
  45. package/apps/runtime/dist/models.js +64 -10
  46. package/apps/runtime/dist/plugins/jobs.js +7 -0
  47. package/apps/runtime/dist/plugins/loader.js +1 -1
  48. package/apps/runtime/dist/routes/api.js +107 -0
  49. package/apps/runtime/dist/routes/studio.js +78 -5
  50. package/apps/runtime/dist/services/assistant-chats.js +1 -1
  51. package/apps/runtime/dist/services/brand.js +1 -1
  52. package/apps/runtime/dist/services/cloud.js +39 -5
  53. package/apps/runtime/dist/services/knowledge-model.js +1 -1
  54. package/apps/runtime/dist/services/marketplace.js +3 -1
  55. package/apps/runtime/dist/services/project-files.js +1 -1
  56. package/apps/runtime/dist/services/projects.js +11 -0
  57. package/apps/runtime/dist/services/translations.js +2 -2
  58. package/apps/runtime/dist/services/wizards.js +2 -2
  59. package/apps/runtime/dist/sharing/agent.js +1 -1
  60. package/apps/runtime/dist/sync/apply.js +39 -0
  61. package/apps/runtime/dist/sync/client.js +828 -0
  62. package/apps/runtime/dist/sync/hub.js +324 -0
  63. package/apps/runtime/dist/sync/log.js +74 -0
  64. package/apps/runtime/dist/sync/records.js +943 -0
  65. package/apps/runtime/dist/sync/state.js +17 -0
  66. package/apps/runtime/dist/texts.js +12 -0
  67. package/apps/web/dist/assets/{AboutDialog-B3tljxg5.js → AboutDialog-D1YHT0jc.js} +1 -1
  68. package/apps/web/dist/assets/{ChangelogDialog-DfWTNzyl.js → ChangelogDialog-Bv02g8av.js} +1 -1
  69. package/apps/web/dist/assets/{EditorPage-XDdz2UM4.js → EditorPage-BThoZwqO.js} +4 -4
  70. package/apps/web/dist/assets/{FlowPreview-CKNVCFbp.js → FlowPreview-dc5C92kK.js} +1 -1
  71. package/apps/web/dist/assets/{Harness-BCec49Cq.js → Harness-D0nFOIVx.js} +1 -1
  72. package/apps/web/dist/assets/{Marketplace-BuYeaxK2.js → Marketplace-Cnd8BF3q.js} +2 -2
  73. package/apps/web/dist/assets/{NewWizardChannels-DRNji-bk.js → NewWizardChannels-i62Y_2DZ.js} +1 -1
  74. package/apps/web/dist/assets/{NewWizardPage-4TpgYOaI.js → NewWizardPage-BcpRA1fx.js} +1 -1
  75. package/apps/web/dist/assets/{OnboardingPage-Cf52NOIt.js → OnboardingPage-BcMDEXNq.js} +1 -1
  76. package/apps/web/dist/assets/PreviewPane-GHcVV2Hu.js +4 -0
  77. package/apps/web/dist/assets/{ProjectPage-D6Tah3QK.js → ProjectPage-TDywzUOd.js} +1 -1
  78. package/apps/web/dist/assets/{PublicRunner-Bftc1c4m.js → PublicRunner-B6JINLpR.js} +1 -1
  79. package/apps/web/dist/assets/{ReadOnly-DVQm9IYx.js → ReadOnly-Mv5M2OV9.js} +1 -1
  80. package/apps/web/dist/assets/SettingsPage-B-F1dLgt.js +2 -0
  81. package/apps/web/dist/assets/SetupPage-CVdsdVBW.js +1 -0
  82. package/apps/web/dist/assets/{SharePage-Cn-bqSyr.js → SharePage-CBSRK0wF.js} +1 -1
  83. package/apps/web/dist/assets/changelog-BR1lxaWv.js +1 -0
  84. package/apps/web/dist/assets/{coins-DgDTBbeg.js → coins-BGZKYmu6.js} +1 -1
  85. package/apps/web/dist/assets/index-D3-kv1WF.js +14 -0
  86. package/apps/web/dist/assets/index-DcUL6teA.css +1 -0
  87. package/apps/web/dist/assets/{phone-D1Drdiio.js → phone-BzHhwehj.js} +1 -1
  88. package/apps/web/dist/assets/{runners-CTd0YAiA.js → runners-C1-zIlry.js} +1 -1
  89. package/apps/web/dist/assets/{session-DX2BcTfz.js → session-B_JeZnJ0.js} +1 -1
  90. package/apps/web/dist/assets/{settings-menu-ay9jNbQu.js → settings-menu-BZRGhsIO.js} +1 -1
  91. package/apps/web/dist/assets/theme-HcCfZDzS.js +11 -0
  92. package/apps/web/dist/assets/{ui-CJCF3Mhe.js → ui-BI1RPFWT.js} +26 -26
  93. package/apps/web/dist/assets/{upload-Dj7KPL--.js → upload-CwT8oMz0.js} +1 -1
  94. package/apps/web/dist/assets/{useMutation-CUSQpD-i.js → useMutation-byk81dDj.js} +1 -1
  95. package/apps/web/dist/assets/{volume-2-CcHZOU2m.js → volume-2-B1Pz6Iwt.js} +1 -1
  96. package/apps/web/dist/assets/{wrench-CfJTFnMJ.js → wrench-CvzXRbWN.js} +1 -1
  97. package/apps/web/dist/index.html +8 -8
  98. package/apps/web/dist/mcp/flow.html +56 -56
  99. package/node_modules/@engenty/wizards/dist/plugin/index.d.ts +2 -2
  100. package/node_modules/@engenty/wizards-shared/dist/definition.d.ts +872 -18
  101. package/node_modules/@engenty/wizards-shared/dist/definition.js +52 -11
  102. package/node_modules/@engenty/wizards-shared/dist/feature-flags.d.ts +6 -0
  103. package/node_modules/@engenty/wizards-shared/dist/feature-flags.js +6 -0
  104. package/node_modules/@engenty/wizards-shared/dist/json-schema.js +3 -3
  105. package/node_modules/@engenty/wizards-shared/dist/providers.d.ts +37 -0
  106. package/node_modules/@engenty/wizards-shared/dist/providers.js +64 -12
  107. package/node_modules/@engenty/wizards-shared/dist/run.d.ts +6 -0
  108. package/node_modules/@engenty/wizards-shared/dist/run.js +12 -0
  109. package/node_modules/@engenty/wizards-shared/dist/sync-merge.d.ts +55 -0
  110. package/node_modules/@engenty/wizards-shared/dist/sync-merge.js +214 -0
  111. package/node_modules/@engenty/wizards-shared/dist/sync.d.ts +166 -0
  112. package/node_modules/@engenty/wizards-shared/dist/sync.js +40 -0
  113. package/node_modules/@engenty/wizards-shared/dist/text-merge.d.ts +14 -0
  114. package/node_modules/@engenty/wizards-shared/dist/text-merge.js +137 -0
  115. package/package.json +1 -1
  116. package/plugin/.claude-plugin/plugin.json +1 -1
  117. package/plugin/plugin.json +1 -1
  118. package/apps/web/dist/assets/PreviewPane-C4yMcZPM.js +0 -4
  119. package/apps/web/dist/assets/SettingsPage-Cd-osLDu.js +0 -2
  120. package/apps/web/dist/assets/SetupPage-Dc8U5k5P.js +0 -1
  121. package/apps/web/dist/assets/changelog-CjSBB-a4.js +0 -1
  122. package/apps/web/dist/assets/index-DS3zUVw_.css +0 -1
  123. package/apps/web/dist/assets/index-Da7hPToW.js +0 -14
  124. package/apps/web/dist/assets/theme-DanjuO1H.js +0 -11
@@ -7,6 +7,7 @@ import { env } from "../env.js";
7
7
  import { getBlob } from "../files/blobs.js";
8
8
  import { managed } from "../manage.js";
9
9
  import { deleteSetting, readSetting, writeSetting } from "../settings.js";
10
+ import { forgetTwoWay, publishInCloud, rotateInCloudSpace, spaceSyncs } from "../sync/client.js";
10
11
  import { currentTenant } from "../tenants/tenant.js";
11
12
  import { mainLogoId } from "./brand.js";
12
13
  import { ServiceError } from "./errors.js";
@@ -218,7 +219,26 @@ export async function syncToCloud(userId, wizardId) {
218
219
  throw new ServiceError("refused", note("publishWizardFirst"));
219
220
  }
220
221
  const before = await cloudState(w.id);
222
+ const twoWay = await spaceSyncs(w.projectId);
221
223
  try {
224
+ if (twoWay) {
225
+ // The space syncs both ways: its draft goes up with the space, then the cloud publishes it.
226
+ const published = await publishInCloud(w.projectId, w.id);
227
+ const state = {
228
+ copy: {
229
+ shareUrl: published.shareUrl,
230
+ code: published.code,
231
+ version: version.version,
232
+ publishedVersion: published.publishedVersion,
233
+ runnable: true,
234
+ problems: [],
235
+ syncedAt: new Date().toISOString(),
236
+ },
237
+ error: null,
238
+ };
239
+ await writeSetting(key(w.id), state);
240
+ return state;
241
+ }
222
242
  const files = await Promise.all(version.files.map(async (f) => ({
223
243
  path: f.path,
224
244
  mime: f.mime,
@@ -286,6 +306,11 @@ export async function pushSharing(userId, wizardId) {
286
306
  if (!(await cloudLinked())) {
287
307
  return;
288
308
  }
309
+ // A space that syncs both ways takes the settings along with the wizard.
310
+ const own = await ownedWizard(userId, wizardId).catch(() => null);
311
+ if (own && (await spaceSyncs(own.projectId))) {
312
+ return;
313
+ }
289
314
  const state = await cloudState(wizardId);
290
315
  if (!state.copy) {
291
316
  return;
@@ -311,13 +336,20 @@ export async function rotateInCloud(userId, wizardId) {
311
336
  return state;
312
337
  }
313
338
  const w = await ownedWizard(userId, wizardId);
314
- const answer = await call("POST", `/spaces/${w.projectId}/wizards/${w.id}/rotate-link`);
315
- if (!answer.ok || !answer.body.shareUrl) {
316
- throw refusal(answer, "The link in the cloud could not be renewed.");
339
+ let link;
340
+ if (await spaceSyncs(w.projectId)) {
341
+ link = await rotateInCloudSpace(w.projectId, w.id);
342
+ }
343
+ else {
344
+ const answer = await call("POST", `/spaces/${w.projectId}/wizards/${w.id}/rotate-link`);
345
+ if (!answer.ok || !answer.body.shareUrl) {
346
+ throw refusal(answer, "The link in the cloud could not be renewed.");
347
+ }
348
+ link = answer.body;
317
349
  }
318
350
  const next = {
319
351
  ...state,
320
- copy: { ...state.copy, shareUrl: answer.body.shareUrl, code: answer.body.code },
352
+ copy: { ...state.copy, shareUrl: link.shareUrl, code: link.code },
321
353
  };
322
354
  await writeSetting(key(w.id), next);
323
355
  return next;
@@ -330,7 +362,8 @@ export async function removeFromCloud(userId, wizardId) {
330
362
  }
331
363
  const w = await ownedWizard(userId, wizardId).catch(() => null);
332
364
  await deleteSetting(key(wizardId));
333
- if (!w || !state.copy || !(await cloudLinked())) {
365
+ // A space that syncs both ways deletes the copy with the next push.
366
+ if (!w || !state.copy || !(await cloudLinked()) || (await spaceSyncs(w.projectId))) {
334
367
  return;
335
368
  }
336
369
  await call("DELETE", `/spaces/${w.projectId}/wizards/${w.id}`).catch((err) => console.error("[cloud] copy not removed:", err.message));
@@ -370,6 +403,7 @@ export async function retryFailedSends(userId) {
370
403
  export async function forgetCloud() {
371
404
  await controlDb.delete(control.setting).where(like(control.setting.key, "cloud:%"));
372
405
  await forgetSentData();
406
+ await forgetTwoWay();
373
407
  }
374
408
  /** The space's data counts as not sent: the next wizard takes it along again. */
375
409
  async function forgetSentData() {
@@ -511,7 +511,7 @@ export async function writeSummary(valueId) {
511
511
  if (!items.length) {
512
512
  throw new ServiceError("invalid", note("nothingFiledUnderValue"));
513
513
  }
514
- const model = await textModel("standard");
514
+ const model = await textModel("low");
515
515
  const result = await generateText({
516
516
  model: model.model,
517
517
  maxOutputTokens: 2000,
@@ -37,6 +37,8 @@ async function call(path, init) {
37
37
  try {
38
38
  const res = await fetch(`${env.marketplace.url}/api/v1${path}`, {
39
39
  ...init,
40
+ // Wizards in this version of the definition; a caller without it gets version 1.
41
+ headers: { ...init?.headers, "x-wizards-definition": String(DEFINITION_VERSION) },
40
42
  signal: AbortSignal.timeout(TIMEOUT_MS),
41
43
  });
42
44
  if (!res.ok) {
@@ -335,9 +337,9 @@ function listPrices() {
335
337
  webSearchCredits: WEB_SEARCH_COST_USD * CREDITS_PER_USD,
336
338
  classes: {
337
339
  classifier: text(m.classifier),
340
+ low: text(m.low),
338
341
  standard: text(m.standard),
339
342
  high: text(m.high),
340
- highest: text(m.highest),
341
343
  image: {
342
344
  model: m.image,
343
345
  kind: "image",
@@ -208,7 +208,7 @@ async function projectLine(projectId) {
208
208
  }
209
209
  /** One sentence about a picture, for whoever picks among the project's files later. */
210
210
  async function describeImage(row, data) {
211
- const seer = await textModel("standard");
211
+ const seer = await textModel("low");
212
212
  const result = await generateText({
213
213
  model: seer.model,
214
214
  maxOutputTokens: 300,
@@ -7,6 +7,7 @@ import { db, schema } from "../db/client.js";
7
7
  import { env } from "../env.js";
8
8
  import { managed, tenantInfo } from "../manage.js";
9
9
  import { spaceChanged } from "../plugins/events.js";
10
+ import { cloudSpaceLimit, twoWayActive } from "../sync/state.js";
10
11
  import { putLink } from "../tenants/control.js";
11
12
  import { currentTenant } from "../tenants/tenant.js";
12
13
  import { serverText } from "../texts.js";
@@ -162,6 +163,16 @@ export async function projectLimit() {
162
163
  return info.limits.projects;
163
164
  }
164
165
  }
166
+ // A local install that syncs both ways has the organization's spaces: its number counts.
167
+ if (twoWayActive()) {
168
+ const limit = cloudSpaceLimit();
169
+ if (limit === null) {
170
+ return Number.POSITIVE_INFINITY;
171
+ }
172
+ if (limit !== undefined) {
173
+ return Math.max(1, limit);
174
+ }
175
+ }
165
176
  return Math.max(1, env.limits.projects);
166
177
  }
167
178
  /** The number for the studio: null where there is no limit (JSON has no infinity). */
@@ -12,7 +12,7 @@ import { currentTenant } from "../tenants/tenant.js";
12
12
  import { ServiceError } from "./errors.js";
13
13
  /**
14
14
  * A wizard in its viewer's language, on request (docs/plans/wizard-translation.md): one call per
15
- * wizard and language on the `standard` class at effort low, kept and shared by every viewer;
15
+ * wizard and language on the `low` class at effort low, kept and shared by every viewer;
16
16
  * the runner's own words once per language for the whole runtime. Booked to the wizard's owner
17
17
  * like any call of the tenant.
18
18
  */
@@ -47,7 +47,7 @@ async function translate(texts, opts) {
47
47
  for (let i = 0; i < keys.length; i += size) {
48
48
  chunks.push(keys.slice(i, i + size));
49
49
  }
50
- const model = await textModel("standard", { effort: "low" });
50
+ const model = await textModel("low", { effort: "low" });
51
51
  // The model sees short keys (t0, t1, …): some providers allow only letters, digits, "_", "."
52
52
  // and "-" in a schema's property names, and a text's own key may hold anything.
53
53
  const call = async (chunk) => {
@@ -1,5 +1,5 @@
1
1
  import { versionChanges } from "@engenty/wizards-shared/changes";
2
- import { pluginToolOf, shapeIssues, validateWizard, wizardSchema, } from "@engenty/wizards-shared/definition";
2
+ import { DEFINITION_VERSION, pluginToolOf, shapeIssues, validateWizard, wizardSchema, } from "@engenty/wizards-shared/definition";
3
3
  import { note } from "@engenty/wizards-shared/run";
4
4
  import { and, desc, eq, sql } from "drizzle-orm";
5
5
  import { nanoid } from "nanoid";
@@ -25,7 +25,7 @@ import { saveTheme } from "./themes.js";
25
25
  /** The wizard a new one starts as, in the language of whoever makes it. */
26
26
  function blankWizard(lang) {
27
27
  return {
28
- version: 1,
28
+ version: DEFINITION_VERSION,
29
29
  title: serverText(lang, "newWizard"),
30
30
  description: "",
31
31
  avatar: "round",
@@ -24,7 +24,7 @@ export async function runShareAgent(ctx, input, job) {
24
24
  throw new ShareError(line("shareNoCredits"));
25
25
  }
26
26
  const step = await ctx.step();
27
- const resolved = await textModel("high", step.call);
27
+ const resolved = await textModel("standard", step.call);
28
28
  const tools = await job.tools(step, new FileKeeper(step, []));
29
29
  attachTools(resolved, tools);
30
30
  const prompt = [
@@ -0,0 +1,39 @@
1
+ import { sql } from "drizzle-orm";
2
+ import { db, inTransaction } from "../db/client.js";
3
+ import { asSync } from "../services/access.js";
4
+ import { quietly } from "./log.js";
5
+ import { KIND_ORDER, KINDS, letDanglingGo } from "./records.js";
6
+ /**
7
+ * Writes a batch of items in one transaction, in an order where what one points to comes
8
+ * first; what still points nowhere at the end is let go. `quiet`: an install writing what it
9
+ * pulled, which the triggers must not note as its own change. What follows a write (links,
10
+ * events, the index) runs after the commit.
11
+ */
12
+ export async function applyItems(items, options) {
13
+ if (!items.length) {
14
+ return;
15
+ }
16
+ const sorted = [...items].sort((a, b) => KIND_ORDER.indexOf(a.kind) - KIND_ORDER.indexOf(b.kind));
17
+ const afters = await asSync(() => inTransaction(async () => {
18
+ const write = async () => {
19
+ // Points between the items of the batch are checked at the commit, not one by one.
20
+ await db.run(sql `PRAGMA defer_foreign_keys = ON`);
21
+ const done = [];
22
+ for (const x of sorted) {
23
+ const def = KINDS[x.kind];
24
+ const after = x.record
25
+ ? await def.write(x.projectId, x.item, x.record)
26
+ : await def.remove(x.projectId, x.item);
27
+ if (after) {
28
+ done.push(after);
29
+ }
30
+ }
31
+ await letDanglingGo();
32
+ return done;
33
+ };
34
+ return options.quiet ? quietly(write) : write();
35
+ }));
36
+ for (const after of afters) {
37
+ await Promise.resolve(after()).catch((err) => console.error("[sync] after a write:", err));
38
+ }
39
+ }