@theprototype/agent 1.60.0 → 1.61.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@theprototype/agent",
3
- "version": "1.60.0",
3
+ "version": "1.61.0",
4
4
  "description": "Let an AI agent (Claude Code, Claude Desktop, any MCP host) join a theprototype.app session from its link and build the 3D scene with you.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -339,7 +339,8 @@ export class BrowserEngine extends EventEmitter {
339
339
  /**
340
340
  * A PNG of the scene: tpAgent.screenshot (A5: a clean frame from a temporary camera), else
341
341
  * the renderer canvas as the page draws it (`fallback: true`, chrome-free but with helpers).
342
- * @param {any} opts @returns {Promise<{data: string, mimeType: string, fallback?: boolean, note?: string}>}
342
+ * A refused shot answers `{error}` (the reason), with no picture.
343
+ * @param {any} opts @returns {Promise<{data: string, mimeType: string, fallback?: boolean, note?: string} | {error: string}>}
343
344
  */
344
345
  async screenshot(opts = {}) {
345
346
  if (this.state !== 'ready' || !this.page) throw new Error('the agent page is not ready (state ' + this.state + ')');
@@ -347,8 +348,14 @@ export class BrowserEngine extends EventEmitter {
347
348
  .evaluate(async (o) => {
348
349
  const api = /** @type {any} */ (window).tpAgent;
349
350
  if (!api || typeof api.screenshot !== 'function') return null;
351
+ const asked = Date.now();
350
352
  let r = await api.screenshot(o);
351
- if (!r) return null;
353
+ if (!r) {
354
+ // mcp-diorama2 (26): a REFUSED shot (view camera with no uuid, a bad view) says why in lastShot —
355
+ // the reason goes back to the agent instead of a live-canvas picture it did not ask for
356
+ const last = typeof api.lastShot === 'function' ? api.lastShot() : null;
357
+ return last && typeof last.error === 'string' && last.at >= asked ? { refused: last.error } : null;
358
+ }
352
359
  if (typeof Blob !== 'undefined' && r instanceof Blob) {
353
360
  r = await new Promise((res, rej) => {
354
361
  const fr = new FileReader();
@@ -362,6 +369,7 @@ export class BrowserEngine extends EventEmitter {
362
369
  return typeof r === 'string' ? { data: r, mimeType: 'image/png', camera } : null;
363
370
  }, opts)
364
371
  .catch((/** @type {any} */ e) => ({ error: firstLine(e) }));
372
+ if (viaApi && typeof viaApi.refused === 'string') return { error: viaApi.refused };
365
373
  if (viaApi && typeof viaApi.data === 'string') {
366
374
  const m = /^data:([^;,]+)(;base64)?,/.exec(viaApi.data);
367
375
  return m ? { data: viaApi.data.slice(m[0].length), mimeType: m[1], camera: viaApi.camera } : viaApi;
package/src/catalog.js CHANGED
@@ -36,6 +36,8 @@ export const TOOL_ANNOTATIONS = /** @type {Record<string, {title: string, read?:
36
36
  save_scene: { title: 'Save the scene', destructive: false },
37
37
  import_model: { title: 'Import a 3D model', destructive: false },
38
38
  import_file: { title: 'Import a file', destructive: false },
39
+ import_shape: { title: 'Import a model file (glTF / GLB / OBJ)', destructive: false, openWorld: true },
40
+ upload_asset: { title: 'Upload a sound or an HDR sky', destructive: false },
39
41
  update_objects: { title: 'Change objects', destructive: true },
40
42
  update_flow_nodes: { title: 'Change or remove flow nodes', destructive: true },
41
43
  edit_behaviour: { title: 'Edit a code behaviour', destructive: true },
@@ -44,6 +46,8 @@ export const TOOL_ANNOTATIONS = /** @type {Record<string, {title: string, read?:
44
46
  delete_objects: { title: 'Delete objects', destructive: true },
45
47
  clear_scene: { title: 'Clear the scene', destructive: true },
46
48
  create_lathe: { title: 'Make a lathed shape', destructive: false },
49
+ create_text: { title: 'Add 3D text', destructive: false, openWorld: true },
50
+ list_fonts: { title: 'List fonts for 3D text', read: true },
47
51
  create_tube: { title: 'Make a tube along a path', destructive: false },
48
52
  extrude_shape: { title: 'Extrude an outline', destructive: false },
49
53
  create_mesh: { title: 'Make a mesh from data', destructive: false },
@@ -78,6 +82,8 @@ export const TOOL_ANNOTATIONS = /** @type {Record<string, {title: string, read?:
78
82
  hud_panel: { title: 'Add a HUD panel', destructive: false },
79
83
  set_sky: { title: 'Change the sky and fog', destructive: true },
80
84
  set_light: { title: 'Change the scene light', destructive: true },
85
+ // mcp-diorama2: this device's quality preset, asked of the person on their own screen
86
+ set_quality: { title: 'Ask for higher quality on this device', destructive: true },
81
87
  get_environment: { title: 'Read the sky and light', read: true },
82
88
  place_spawn: { title: 'Set where Play starts', destructive: true },
83
89
  set_play_camera: { title: 'Set the play camera and opening view', destructive: true },
@@ -92,6 +98,7 @@ export const TOOL_ANNOTATIONS = /** @type {Record<string, {title: string, read?:
92
98
  place_sound: { title: 'Place a sound', destructive: false, openWorld: true },
93
99
  set_music: { title: 'Set the background music', destructive: true, openWorld: true },
94
100
  update_mesh: { title: 'Change a mesh made from data', destructive: true },
101
+ duplicate: { title: 'Copy or mirror an object', destructive: false },
95
102
  // 85b R1-R4
96
103
  inspect_runtime: { title: 'See what the game is doing', read: true },
97
104
  validate_scene: { title: 'Check the game for problems', read: true },
@@ -254,20 +261,20 @@ export const CONNECTOR_FAMILIES = Object.freeze({
254
261
  create_shape: {
255
262
  title: 'Make a shape',
256
263
  summary:
257
- 'Make shapes the basic objects cannot: a lathe (a vase, a bowl, a lamp from a profile turned around an axis), a tube along a path (a rail, a pipe, a cable), an extruded outline (a sign, a star, a wall with a hole), or a mesh from your own vertices (anything else).',
258
- actions: { lathe: 'create_lathe', tube: 'create_tube', extrude: 'extrude_shape', mesh: 'create_mesh' },
264
+ 'Make shapes the basic objects cannot: a lathe (a vase, a bowl, a lamp from a profile turned around an axis), a tube along a path (a rail, a pipe, a cable), an extruded outline (a sign, a star, a wall with a hole), a mesh from your own vertices (anything else), or text = 3D words (a sign, a title: flat, or solid with depth and a bevel; any bundled or Google Fonts font); import = a glTF / GLB / OBJ model file (base64, chunks or an https url) whose named parts come back as children animate_parts can move.',
265
+ actions: { lathe: 'create_lathe', tube: 'create_tube', extrude: 'extrude_shape', mesh: 'create_mesh', text: 'create_text', import: 'import_shape' },
259
266
  batch: { key: 'shapes', tool: 'create_shapes' }
260
267
  },
261
268
  edit_shape: {
262
269
  title: 'Reshape or model objects',
263
270
  summary:
264
- 'Change the shape of objects that exist: params = new size / segments / type in place, mesh = model faces and vertices (extrude, inset, bevel, subdivide, weld, smooth, dissolve, make a face), update = new vertices / faces for a mesh made from data (replace it, or patch a range), pivot = the point an object turns about, pivot_group = a group at a joint so several parts swing together.',
265
- actions: { params: 'set_geometry', mesh: 'edit_mesh', update: 'update_mesh', pivot: 'set_pivot', pivot_group: 'create_pivot' }
271
+ 'Change the shape of objects that exist: params = new size / segments / type in place (on a 3D text: its words, font, size, depth, bevel, align, wrap width, anchor, colours), mesh = model faces and vertices (extrude, inset, bevel, subdivide, weld, smooth, dissolve, make a face), update = new vertices / faces for a mesh made from data (replace it, or patch a range), duplicate = copies of an object in a row, or its mirror image (a left arm → the right one), pivot = the point an object turns about, pivot_group = a group at a joint so several parts swing together.',
272
+ actions: { params: 'set_geometry', mesh: 'edit_mesh', update: 'update_mesh', duplicate: 'duplicate', pivot: 'set_pivot', pivot_group: 'create_pivot' }
266
273
  },
267
274
  set_look: {
268
275
  title: 'Materials, shaders, sky, light and post effects',
269
276
  summary:
270
- 'How things look: material = colour, roughness, metal, glow, see-through and textures (a library image, a CC0 material by name or an https image); list_materials / get_material read them; shader / edit_shader / assign_shader / shader_nodes = node shaders on objects; sky = the sky image, background, fog and exposure; light = the sun, ambient and environment lights; environment reads both; post / get_post / post_graph = the scene\'s post effects (bloom, colour grade, vignette); sky, light and post change the whole scene, so the host is asked first; unwrap / uv = texture mapping and tiling.',
277
+ 'How things look: material = colour, roughness, metal, glow, see-through and textures (a library image, a CC0 material by name or an https image); list_materials / get_material read them; shader / edit_shader / assign_shader / shader_nodes = node shaders on objects; sky = the sky image, background, fog and exposure; light = the sun, ambient and environment lights; environment reads both; post / get_post / post_graph = the scene\'s post effects (bloom, colour grade, vignette); sky, light and post change the whole scene, so the host is asked first; unwrap / uv = texture mapping and tiling; quality = ask the person to raise THIS device\'s quality (a card on their screen, Allow / Keep) when a phone hides the post effects to stay smooth.',
271
278
  actions: {
272
279
  material: 'set_material',
273
280
  list_materials: 'list_materials',
@@ -283,7 +290,8 @@ export const CONNECTOR_FAMILIES = Object.freeze({
283
290
  uv: 'set_uv',
284
291
  sky: 'set_sky',
285
292
  light: 'set_light',
286
- environment: 'get_environment'
293
+ environment: 'get_environment',
294
+ quality: 'set_quality'
287
295
  }
288
296
  },
289
297
  // 85b R1-R4 (lane 85-runtime): playtest is agent-page only (B4b), so the connector's `run` has no playtest;
@@ -297,8 +305,8 @@ export const CONNECTOR_FAMILIES = Object.freeze({
297
305
  assets: {
298
306
  title: 'Images and assets',
299
307
  summary:
300
- 'Assets to build with: search = find models, prefabs, sounds, images, CC0 materials and HDRIs by words (library, packs, Poly Haven); place = put a found model or prefab into the scene; prefab = keep objects as a reusable prefab, or place copies of one; image = put an image into the library (an https URL, base64 data, or a canvas you describe) and get its hash for textures.',
301
- actions: { search: 'search_assets', place: 'place_asset', prefab: 'prefab', image: 'add_image' }
308
+ 'Assets to build with: search = find models, prefabs, sounds, images, CC0 materials and HDRIs by words (library, packs, Poly Haven); place = put a found model or prefab into the scene; prefab = keep objects as a reusable prefab, or place copies of one; image = put an image into the library (an https URL, base64 data, or a canvas you describe) and get its hash for textures; upload = put a SOUND or an HDR SKY you hold as base64 bytes (your own music, a file you fetched) into the library and get its hash for effects sound / music or set_look sky; fonts = the fonts 3D text can use (bundled, the library\'s, the scene\'s).',
309
+ actions: { search: 'search_assets', place: 'place_asset', prefab: 'prefab', image: 'add_image', upload: 'upload_asset', fonts: 'list_fonts' }
302
310
  },
303
311
  // 85b (1.60, the tool budget's effects row)
304
312
  effects: {
@@ -365,8 +373,29 @@ export function familyNames() {
365
373
 
366
374
  /** a text with every fine family-member name said the connector's way @param {string} text */
367
375
  export function sayFamilyNames(text) {
368
- const names = familyNames();
369
- return names.size ? String(text).replace(new RegExp('\\b(' + [...names.keys()].join('|') + ')\\b', 'g'), (m) => names.get(m) ?? m) : String(text);
376
+ return sayToolNames(String(text), familyNames());
377
+ }
378
+
379
+ /**
380
+ * mcp-diorama2 (item 4) — THE ONE REWRITE RULE for "a fine tool name in a text → the connector's family wording",
381
+ * shared by the catalog (descriptions) and the Worker (tool results; cloud worker-mcp/src/catalog.js keeps a copy and
382
+ * a test pins the two). The 1.60 rewrite replaced every WORD that is also a tool name, so status answered a key named
383
+ * "run {action: 'logs'}" and a tip said "a campfire with run {action: 'logs'}". It touches TOOL REFERENCES only:
384
+ * - a name with an underscore (set_geometry, create_mesh) is an identifier, never English — rewritten in prose;
385
+ * - a one-word name (logs, scatter, terrain, water, prefab) is rewritten only written as code: `logs`;
386
+ * - never a JSON key ("logs": …) and never a JSON string that IS the name ("tool": "create_mesh" is data).
387
+ * @param {string} text @param {Map<string, string>} say fine name → wording
388
+ */
389
+ export function sayToolNames(text, say) {
390
+ if (!say.size) return text;
391
+ const re = new RegExp('\\b(' + [...say.keys()].sort((a, b) => b.length - a.length).join('|') + ')\\b', 'g');
392
+ return text.replace(re, (m, _name, at, whole) => {
393
+ const before = whole[at - 1];
394
+ const after = whole[at + m.length];
395
+ if (before === '"' && after === '"') return m; // a JSON key or a value that is exactly the name: data
396
+ if (!m.includes('_') && !(before === '`' && after === '`')) return m; // an English word
397
+ return say.get(m) ?? m;
398
+ });
370
399
  }
371
400
 
372
401
  /**
@@ -445,6 +474,18 @@ function familyTool(family, f, actions, batch = null) {
445
474
  return { name: family, title: f.title, description, inputSchema: { type: 'object', properties, ...(batch ? {} : { required: ['action'] }) }, annotations };
446
475
  }
447
476
 
477
+ /**
478
+ * mcp-diorama2 (item 17) — the question's fields travel with the action's object: an agent repeats
479
+ * {action: 'sky', sky: {…}, confirmId, wait} as the needsConfirm note says, and keeping only `sky` dropped the
480
+ * confirmId, so every repeat opened a NEW question and the host's Allow never reached the call.
481
+ * @param {any} inner @param {any} args
482
+ */
483
+ export function withAnswerFields(inner, args) {
484
+ const out = { ...inner };
485
+ for (const k of ['confirmId', 'wait']) if (args?.[k] !== undefined && out[k] === undefined) out[k] = args[k];
486
+ return out;
487
+ }
488
+
448
489
  /**
449
490
  * The Worker's half, kept here so core's unit tests cover it with the same tables: a family call → the fine tool
450
491
  * and its arguments. A missing per-action object falls back to the call's other fields (a model that flattened them).
@@ -461,7 +502,7 @@ export function resolveFamilyCall(families, name, args) {
461
502
  const tool = actions[action];
462
503
  if (!tool) return { error: name + ' needs an action: one of ' + Object.keys(actions).join(', ') + '.' };
463
504
  const inner = args[action];
464
- if (inner && typeof inner === 'object' && !Array.isArray(inner)) return { tool, args: inner };
505
+ if (inner && typeof inner === 'object' && !Array.isArray(inner)) return { tool, args: withAnswerFields(inner, args) };
465
506
  const { action: _a, ...rest } = args;
466
507
  for (const a of Object.keys(actions)) delete rest[a];
467
508
  return { tool, args: rest };
package/src/mcpServer.js CHANGED
@@ -223,11 +223,18 @@ export function createBridgeServer(opts) {
223
223
  if (name === 'screenshot' && reserved.includes('screenshot')) {
224
224
  if (!engineReady()) return textResult({ error: 'the agent page is not up yet (' + engine.state + ')' }, true);
225
225
  const { view, uuid, uuids, from, camera, aspect, zoom, margin, size } = a;
226
- const shot = await engine.screenshot({ view, uuid, uuids, from, camera, aspect, zoom, margin, size });
226
+ const postEffects = a.postEffects === true ? true : undefined;
227
+ const extra = { ...(a.hud === true ? { hud: true } : {}), ...(typeof a.avatars === 'boolean' ? { avatars: a.avatars } : {}) };
228
+ const shot = await engine.screenshot({ view, uuid, uuids, from, camera, aspect, zoom, margin, size, ...(postEffects ? { postEffects } : {}), ...extra });
229
+ if ('error' in shot) return textResult({ error: shot.error }, true);
227
230
  /** @type {any[]} */
228
231
  const content = [{ type: 'image', data: shot.data, mimeType: shot.mimeType || 'image/png' }];
229
232
  if (shot.note) content.push({ type: 'text', text: shot.note });
230
- if (shot.camera) content.push({ type: 'text', text: JSON.stringify({ camera: shot.camera }) });
233
+ if (shot.camera) {
234
+ // mcp-diorama2: the post stack's verdict rides beside the camera (lastShot carries both)
235
+ const { postEffects: pe, reason, detail, how, ...cam } = shot.camera;
236
+ content.push({ type: 'text', text: JSON.stringify({ camera: cam, ...(postEffects && pe ? { postEffects: pe, ...(reason ? { reason } : {}), ...(detail ? { detail } : {}), ...(how ? { how } : {}) } : {}) }) });
237
+ }
231
238
  return { content };
232
239
  }
233
240
  if (name === 'wait_for_edit' && reserved.includes('wait_for_edit')) {
package/src/mcpTools.js CHANGED
@@ -77,7 +77,7 @@ export function bridgeTools(engine = 'browser') {
77
77
  {
78
78
  name: 'status',
79
79
  description:
80
- 'Where the agent is: connection state, whether the host has let it in, its role (viewer edits stay local), the app version, and why any tool is missing. sceneBudget says how heavy the scene is: objects, triangles (per frame drawn; the scene\'s own count while the view is idle, then no draw calls), draw calls, textures, lights you placed, frame time p95, tier green / amber / red on the desktop or vr profile, and over = each budget past green (build lighter, or stop adding, while it is not green).',
80
+ 'Where the agent is: connection state, whether the host has let it in, its role (viewer edits stay local), the app version, and why any tool is missing. sceneBudget says how heavy the scene is: objects, triangles (per frame drawn; the scene\'s own count while the view is idle, then no draw calls), draw calls, textures, lights you placed, frame time p95, tier green / amber / red on the desktop or vr profile, and over = each budget past green (build lighter, or stop adding, while it is not green). top = the objects drawing the most triangles / draw calls (lighten those first); vsync says whether frameP95 sits on the display\'s refresh (a steady 16.7 ms on a 60 Hz screen is the display\'s cap, not a slow scene) or frames miss it — a frame on the refresh never turns the tier amber or red. callsBySource splits the draw calls: objects (yours), otherInView (people, grid, sky, helpers), shadows, post (effects), otherViews (camera previews, reflections).',
81
81
  inputSchema: { type: 'object', properties: {} }
82
82
  }
83
83
  ];
@@ -86,12 +86,12 @@ export function bridgeTools(engine = 'browser') {
86
86
  {
87
87
  name: 'screenshot',
88
88
  description:
89
- 'See the scene: a PNG of a clean frame (no gizmos) from a temporary camera, never moving anyone\'s view. view: current | top | front | iso | focus (focus needs uuid or uuids); from = an angle or {yaw, pitch}; camera = a free {position, target}. 4:3 unless aspect says otherwise (current follows the person\'s window). Answers with the camera it used.',
89
+ 'See the scene: a PNG of a clean frame (no gizmos, no people) from a temporary camera, never moving anyone\'s view. view: current | top | front | iso | focus | camera (focus needs uuid or uuids; camera looks through the scene camera uuid, its lens and framing); from = an angle or {yaw, pitch}; camera = a free {position, target}. 4:3 unless aspect says otherwise (current follows the person\'s window). Answers with the camera it used. postEffects: true draws the scene\'s post effects too; hud: true the game HUD on top; avatars: true keeps the people in (current keeps them unless false).',
90
90
  inputSchema: {
91
91
  type: 'object',
92
92
  properties: {
93
- view: { type: 'string', enum: ['current', 'top', 'front', 'iso', 'focus'] },
94
- uuid: { type: 'string', description: 'object to frame' },
93
+ view: { type: 'string', enum: ['current', 'top', 'front', 'iso', 'focus', 'camera'] },
94
+ uuid: { type: 'string', description: 'object to frame, or the camera to look through (view camera)' },
95
95
  uuids: { type: 'array', items: { type: 'string' }, description: 'objects to frame together' },
96
96
  from: {
97
97
  description: 'the angle around the subject, instead of view: front, back, left, right, top, below, iso, or {yaw, pitch} in degrees (yaw 0 = front, 90 = right; pitch 90 = from above)',
@@ -112,13 +112,20 @@ export function bridgeTools(engine = 'browser') {
112
112
  aspect: { description: 'width to height: "4:3" (default), "1:1", "16:9" or a number. view current defaults to the person\'s window', anyOf: [{ type: 'string' }, { type: 'number' }] },
113
113
  zoom: { type: 'number', description: 'above 1 is closer, 0.1 to 10' },
114
114
  margin: { type: 'number', description: 'room around the subject: 1 touches the frame, default 1.15' },
115
- size: { type: 'number', description: 'longest side in pixels' }
115
+ size: { type: 'number', description: 'longest side in pixels' },
116
+ hud: { type: 'boolean', description: 'true = draw the game HUD this screen shows on top (score, timer, menus), laid out as on screen' },
117
+ avatars: { type: 'boolean', description: 'true = keep the people (avatars, an agent\'s camera marker) in the frame; default leaves them out, except view current' },
118
+ postEffects: {
119
+ type: 'boolean',
120
+ description:
121
+ 'true = draw it through the scene\'s post effects (bloom, vignette, colour grade …) as this screen shows them. The answer says postEffects "applied", or "unavailable" with a reason ("quality tier" = this device turned them off to keep its frame rate, usual on a phone — `how` says where the person raises it, or ask the person for higher quality: set_look action "quality" — set_quality for a local agent)'
122
+ }
116
123
  }
117
124
  }
118
125
  },
119
126
  {
120
127
  name: 'wait_for_edit',
121
- description: 'Wait until someone in the session changes the scene (or the timeout passes), so you can react to the humans.',
128
+ description: 'Wait until someone in the session changes the scene or PINGS a spot (or the timeout passes), so you can react to the humans. A ping answers {changed: true, ping: {id, position, normal, on}}: build there with at: {ping: id}.',
122
129
  inputSchema: {
123
130
  type: 'object',
124
131
  properties: { timeout_ms: { type: 'number', description: 'default 30000, at most 120000' } }