@pixerate/editor 0.140.4 → 0.141.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/dist/agent/canvasPlayback.d.cts +15 -0
- package/dist/agent/canvasPlayback.d.ts +15 -0
- package/dist/agent/index.cjs +144 -23
- package/dist/agent/index.d.cts +1 -0
- package/dist/agent/index.d.ts +1 -0
- package/dist/agent/index.js +125 -4
- package/dist/agent/providers.d.cts +8 -0
- package/dist/agent/providers.d.ts +8 -0
- package/dist/agent/types.d.cts +3 -0
- package/dist/agent/types.d.ts +3 -0
- package/dist/animation/index.cjs +2 -2
- package/dist/animation/index.js +1 -1
- package/dist/animation/presence.d.cts +1 -75
- package/dist/animation/presence.d.ts +1 -75
- package/dist/bridge/cli.cjs +3 -3
- package/dist/bridge/cli.js +2 -2
- package/dist/bridge/index.cjs +3 -3
- package/dist/bridge/index.js +2 -2
- package/dist/canvas/index.cjs +336 -646
- package/dist/canvas/index.d.cts +1 -0
- package/dist/canvas/index.d.ts +1 -0
- package/dist/canvas/index.js +44 -354
- package/dist/canvas/playback.d.cts +14 -0
- package/dist/canvas/playback.d.ts +14 -0
- package/dist/chart/index.cjs +7 -7
- package/dist/chart/index.js +1 -1
- package/dist/chunk-6SFREX6H.cjs +406 -0
- package/dist/chunk-DW4CV5H4.js +591 -0
- package/dist/{chunk-UMS6YFA6.js → chunk-EAQ4BGNS.js} +1 -1
- package/dist/{chunk-AGCD3EHB.cjs → chunk-ENIZYNEF.cjs} +7 -7
- package/dist/chunk-MFFE55CS.js +406 -0
- package/dist/{chunk-BSGPXPTW.js → chunk-PEEP2YR7.js} +1 -1
- package/dist/{chunk-RB62U6MS.js → chunk-RFBFTLVN.js} +27 -5
- package/dist/chunk-UBRYHNRU.cjs +591 -0
- package/dist/{chunk-GEY73RUW.cjs → chunk-UJGAA6AK.cjs} +1 -1
- package/dist/{chunk-HDK3T2QS.cjs → chunk-Y4BWZB6J.cjs} +29 -7
- package/dist/commands/index.cjs +37 -1
- package/dist/commands/index.js +36 -0
- package/dist/commands/registry.d.cts +11 -0
- package/dist/commands/registry.d.ts +11 -0
- package/dist/diagram/index.cjs +7 -7
- package/dist/diagram/index.js +1 -1
- package/dist/image-editor/index.cjs +108 -16
- package/dist/image-editor/index.d.cts +1 -0
- package/dist/image-editor/index.d.ts +1 -0
- package/dist/image-editor/index.js +107 -15
- package/dist/image-editor/playback.d.cts +22 -0
- package/dist/image-editor/playback.d.ts +22 -0
- package/dist/paint-editor/index.cjs +6 -6
- package/dist/paint-editor/index.js +1 -1
- package/dist/tools/index.cjs +33 -3
- package/dist/tools/index.d.cts +2 -0
- package/dist/tools/index.d.ts +2 -0
- package/dist/tools/index.js +32 -2
- package/dist/tools/playback.d.cts +205 -0
- package/dist/tools/playback.d.ts +205 -0
- package/dist/tools/presence.d.cts +82 -0
- package/dist/tools/presence.d.ts +82 -0
- package/dist/tools/registry.d.cts +45 -6
- package/dist/tools/registry.d.ts +45 -6
- package/dist/tools/view.d.cts +2 -4
- package/dist/tools/view.d.ts +2 -4
- package/dist/vector/index.cjs +217 -100
- package/dist/vector/index.d.cts +1 -0
- package/dist/vector/index.d.ts +1 -0
- package/dist/vector/index.js +140 -23
- package/dist/vector/playback.d.cts +13 -0
- package/dist/vector/playback.d.ts +13 -0
- package/package.json +1 -1
- package/skills/pixerate-agent-tools/SKILL.md +13 -0
- package/skills/pixerate-canvas/SKILL.md +3 -0
- package/skills/pixerate-image-editor/SKILL.md +2 -2
- package/skills/pixerate-vector/SKILL.md +5 -0
- package/dist/chunk-BTZS3KZY.js +0 -221
- package/dist/chunk-MRD3NXKR.cjs +0 -221
- /package/dist/{chunk-K73HMKQP.js → chunk-PLKIYNJZ.js} +0 -0
- /package/dist/{chunk-LACYURUW.cjs → chunk-TNCWKC5M.cjs} +0 -0
|
@@ -0,0 +1,406 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } var _class;
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
var _chunkUJGAA6AKcjs = require('./chunk-UJGAA6AK.cjs');
|
|
5
|
+
|
|
6
|
+
// src/tools/playback.ts
|
|
7
|
+
var ARG_KINDS = {
|
|
8
|
+
nodeId: "node",
|
|
9
|
+
edgeId: "edge",
|
|
10
|
+
layerId: "layer",
|
|
11
|
+
clipId: "clip",
|
|
12
|
+
trackId: "track",
|
|
13
|
+
seriesId: "series",
|
|
14
|
+
parameterId: "parameter",
|
|
15
|
+
keyframeId: "keyframe",
|
|
16
|
+
shapeId: "shape"
|
|
17
|
+
};
|
|
18
|
+
function pushRef(out, kind, id) {
|
|
19
|
+
if (typeof id !== "string" || !id) return;
|
|
20
|
+
if (!out.some((r) => r.kind === kind && r.id === id)) out.push({ kind, id });
|
|
21
|
+
}
|
|
22
|
+
function playbackRefsFromArgs(args, defaultKind = "item") {
|
|
23
|
+
const out = [];
|
|
24
|
+
const visit = (value, depth) => {
|
|
25
|
+
if (!value || typeof value !== "object" || Array.isArray(value) || depth > 1) return;
|
|
26
|
+
const record = value;
|
|
27
|
+
pushRef(out, defaultKind, record.id);
|
|
28
|
+
if (Array.isArray(record.ids)) for (const id of record.ids) pushRef(out, defaultKind, id);
|
|
29
|
+
for (const [key, kind] of Object.entries(ARG_KINDS)) {
|
|
30
|
+
pushRef(out, kind, record[key]);
|
|
31
|
+
const many = record[`${key}s`];
|
|
32
|
+
if (Array.isArray(many)) for (const id of many) pushRef(out, kind, id);
|
|
33
|
+
}
|
|
34
|
+
pushRef(out, "cell", record.range);
|
|
35
|
+
pushRef(out, "cell", record.cell);
|
|
36
|
+
visit(record.params, depth + 1);
|
|
37
|
+
};
|
|
38
|
+
visit(args, 0);
|
|
39
|
+
return out;
|
|
40
|
+
}
|
|
41
|
+
function playbackRefsFromResult(value, defaultKind = "item") {
|
|
42
|
+
const out = [];
|
|
43
|
+
const visit = (v, depth) => {
|
|
44
|
+
if (!v || typeof v !== "object" || depth > 2) return;
|
|
45
|
+
if (Array.isArray(v)) {
|
|
46
|
+
for (const item of v) if (item && typeof item === "object") pushRef(out, defaultKind, item.id);
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
const record = v;
|
|
50
|
+
if (Array.isArray(record.content) && record.structuredContent) return visit(record.structuredContent, depth);
|
|
51
|
+
pushRef(out, defaultKind, record.id);
|
|
52
|
+
if (Array.isArray(record.ids)) for (const id of record.ids) pushRef(out, defaultKind, id);
|
|
53
|
+
if (record.node && typeof record.node === "object") pushRef(out, "node", record.node.id);
|
|
54
|
+
pushRef(out, "layer", record.layerId);
|
|
55
|
+
if (record.layer && typeof record.layer === "object") pushRef(out, "layer", record.layer.id);
|
|
56
|
+
const created = record.created;
|
|
57
|
+
if (Array.isArray(created)) visit(created, depth + 1);
|
|
58
|
+
else if (created && typeof created === "object") {
|
|
59
|
+
const c = created;
|
|
60
|
+
for (const n of _nullishCoalesce(c.nodes, () => ( []))) pushRef(out, "node", _optionalChain([n, 'optionalAccess', _ => _.id]));
|
|
61
|
+
for (const e of _nullishCoalesce(c.edges, () => ( []))) pushRef(out, "edge", _optionalChain([e, 'optionalAccess', _2 => _2.id]));
|
|
62
|
+
}
|
|
63
|
+
if (record.result && typeof record.result === "object") visit(record.result, depth + 1);
|
|
64
|
+
};
|
|
65
|
+
visit(value, 0);
|
|
66
|
+
return out;
|
|
67
|
+
}
|
|
68
|
+
function derivePlaybackSteps(args, defaultKind) {
|
|
69
|
+
const refs = playbackRefsFromArgs(args, defaultKind).slice(0, 8);
|
|
70
|
+
if (!refs.length) return [{ type: "commit" }];
|
|
71
|
+
return [...refs.map((ref) => ({ type: "target", ref })), { type: "press" }, { type: "release" }, { type: "commit" }];
|
|
72
|
+
}
|
|
73
|
+
function readingTime(text) {
|
|
74
|
+
return Math.min(2200, Math.max(600, text.length * 65));
|
|
75
|
+
}
|
|
76
|
+
function unionRects(rects) {
|
|
77
|
+
const list = rects.filter((r) => !!r);
|
|
78
|
+
if (!list.length) return null;
|
|
79
|
+
const x = Math.min(...list.map((r) => r.x));
|
|
80
|
+
const y = Math.min(...list.map((r) => r.y));
|
|
81
|
+
return { x, y, width: Math.max(...list.map((r) => r.x + r.width)) - x, height: Math.max(...list.map((r) => r.y + r.height)) - y };
|
|
82
|
+
}
|
|
83
|
+
function normalizePlan(plan) {
|
|
84
|
+
if (!plan) return null;
|
|
85
|
+
if (Array.isArray(plan)) return plan.length ? { steps: plan } : null;
|
|
86
|
+
return _optionalChain([plan, 'access', _3 => _3.steps, 'optionalAccess', _4 => _4.length]) || plan.surface || plan.readOnly !== void 0 ? plan : null;
|
|
87
|
+
}
|
|
88
|
+
var isErrorResult = (value) => !!value && typeof value === "object" && value.isError === true;
|
|
89
|
+
var center = (r) => ({ x: r.x + r.width / 2, y: r.y + r.height / 2 });
|
|
90
|
+
var GLANCE_STEPS = /* @__PURE__ */ new Set(["move", "target", "focus", "say", "wait", "commit"]);
|
|
91
|
+
var AgentPlayback = (_class = class {
|
|
92
|
+
/** 1 = natural pace; `Infinity` plays nothing (calls run instantly). Takes effect on the next step. */
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
__init() {this.surfaces = /* @__PURE__ */ new Map()}
|
|
99
|
+
__init2() {this.actors = /* @__PURE__ */ new Map()}
|
|
100
|
+
__init3() {this.recordings = /* @__PURE__ */ new Set()}
|
|
101
|
+
__init4() {this.installed = /* @__PURE__ */ new WeakSet()}
|
|
102
|
+
__init5() {this.listeners = /* @__PURE__ */ new Set()}
|
|
103
|
+
__init6() {this.generation = 0}
|
|
104
|
+
__init7() {this.running = 0}
|
|
105
|
+
__init8() {this.calls = 0}
|
|
106
|
+
constructor(options = {}) {;_class.prototype.__init.call(this);_class.prototype.__init2.call(this);_class.prototype.__init3.call(this);_class.prototype.__init4.call(this);_class.prototype.__init5.call(this);_class.prototype.__init6.call(this);_class.prototype.__init7.call(this);_class.prototype.__init8.call(this);_class.prototype.__init9.call(this);
|
|
107
|
+
this.clock = _nullishCoalesce(options.clock, () => ( _chunkUJGAA6AKcjs.realPresenceClock));
|
|
108
|
+
this.speed = _nullishCoalesce(options.speed, () => ( 1));
|
|
109
|
+
this.reads = _nullishCoalesce(options.reads, () => ( "glance"));
|
|
110
|
+
this.linger = _nullishCoalesce(options.linger, () => ( 1500));
|
|
111
|
+
this.defaultActor = _nullishCoalesce(options.actor, () => ( { id: "agent", name: "Agent" }));
|
|
112
|
+
}
|
|
113
|
+
/** The registry middleware that plays each call. */
|
|
114
|
+
__init9() {this.middleware = (call, next) => this.perform(call, next)}
|
|
115
|
+
/** Adds the middleware to `registry` once (later calls with the same registry do nothing). */
|
|
116
|
+
install(registry) {
|
|
117
|
+
if (this.installed.has(registry)) return;
|
|
118
|
+
this.installed.add(registry);
|
|
119
|
+
registry.use(this.middleware);
|
|
120
|
+
}
|
|
121
|
+
/** Whether a performance is playing now (e.g. to make the editor read-only meanwhile). */
|
|
122
|
+
get active() {
|
|
123
|
+
return this.running > 0;
|
|
124
|
+
}
|
|
125
|
+
/** Called when `active` changes. Returns an unsubscribe function. */
|
|
126
|
+
subscribe(listener) {
|
|
127
|
+
this.listeners.add(listener);
|
|
128
|
+
return () => {
|
|
129
|
+
this.listeners.delete(listener);
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
/** Attaches a surface under a provider id (or the id providers name as `playbackSurface`). */
|
|
133
|
+
attach(id, surface) {
|
|
134
|
+
this.surfaces.set(id, surface);
|
|
135
|
+
return () => {
|
|
136
|
+
if (this.surfaces.get(id) !== surface) return;
|
|
137
|
+
this.surfaces.delete(id);
|
|
138
|
+
for (const actor of this.actors.values()) if (actor.surface === id) actor.surface = void 0;
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
/** The surface attached under `id`. */
|
|
142
|
+
surface(id) {
|
|
143
|
+
return this.surfaces.get(id);
|
|
144
|
+
}
|
|
145
|
+
/** Shows `text` in the actor's bubble on the surface it last worked on (until its next step). */
|
|
146
|
+
say(text, options = {}) {
|
|
147
|
+
const actor = this.actorState(options.actor);
|
|
148
|
+
const surface = actor.surface ? this.surfaces.get(actor.surface) : void 0;
|
|
149
|
+
if (_optionalChain([surface, 'optionalAccess', _5 => _5.presence, 'access', _6 => _6.get, 'call', _7 => _7(actor.info.id)])) surface.presence.set({ id: actor.info.id, message: text });
|
|
150
|
+
}
|
|
151
|
+
/** Finishes every running performance at once (the calls still run and keep their results). */
|
|
152
|
+
stop() {
|
|
153
|
+
this.generation++;
|
|
154
|
+
}
|
|
155
|
+
/** Collects every step played from now on (for tests). */
|
|
156
|
+
record() {
|
|
157
|
+
const list = [];
|
|
158
|
+
this.recordings.add(list);
|
|
159
|
+
return list;
|
|
160
|
+
}
|
|
161
|
+
actorState(info) {
|
|
162
|
+
const base = _nullishCoalesce(info, () => ( this.defaultActor));
|
|
163
|
+
let actor = this.actors.get(base.id);
|
|
164
|
+
if (!actor) {
|
|
165
|
+
actor = { info: { ...base, color: _nullishCoalesce(base.color, () => ( _chunkUJGAA6AKcjs.PRESENCE_COLORS[this.actors.size % _chunkUJGAA6AKcjs.PRESENCE_COLORS.length])) }, queue: Promise.resolve(), version: 0 };
|
|
166
|
+
this.actors.set(base.id, actor);
|
|
167
|
+
} else if (_optionalChain([info, 'optionalAccess', _8 => _8.name]) && info.name !== actor.info.name) actor.info = { ...actor.info, name: info.name };
|
|
168
|
+
return actor;
|
|
169
|
+
}
|
|
170
|
+
enqueue(actor, run) {
|
|
171
|
+
const result = actor.queue.then(run);
|
|
172
|
+
actor.queue = result.catch(() => void 0);
|
|
173
|
+
return result;
|
|
174
|
+
}
|
|
175
|
+
surfaceFor(provider, hint) {
|
|
176
|
+
for (const id of [hint, provider.playbackSurface, provider.id, provider.namespace]) {
|
|
177
|
+
const surface = id ? this.surfaces.get(id) : void 0;
|
|
178
|
+
if (id && surface) return [id, surface];
|
|
179
|
+
}
|
|
180
|
+
return null;
|
|
181
|
+
}
|
|
182
|
+
async perform(call, next) {
|
|
183
|
+
const tool = call.tool;
|
|
184
|
+
if (tool.playback === false || !Number.isFinite(this.speed)) return next();
|
|
185
|
+
const actor = this.actorState(call.context.actor);
|
|
186
|
+
if (tool.playback === "self") return this.enqueue(actor, next);
|
|
187
|
+
const fallback = this.surfaceFor(call.provider);
|
|
188
|
+
let planned = null;
|
|
189
|
+
if (tool.plan) {
|
|
190
|
+
try {
|
|
191
|
+
const state = {
|
|
192
|
+
surfaceId: _nullishCoalesce(_optionalChain([fallback, 'optionalAccess', _9 => _9[0]]), () => ( null)),
|
|
193
|
+
locate: (ref) => _nullishCoalesce(_optionalChain([fallback, 'optionalAccess', _10 => _10[1], 'access', _11 => _11.locate, 'optionalCall', _12 => _12(ref)]), () => ( null))
|
|
194
|
+
};
|
|
195
|
+
planned = normalizePlan(tool.plan(call.args, state));
|
|
196
|
+
} catch (e2) {
|
|
197
|
+
planned = null;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
const readOnly = _nullishCoalesce(_optionalChain([planned, 'optionalAccess', _13 => _13.readOnly]), () => ( _optionalChain([tool, 'access', _14 => _14.annotations, 'optionalAccess', _15 => _15.readOnlyHint]) === true));
|
|
201
|
+
if (readOnly && this.reads === "skip") return next();
|
|
202
|
+
const found = this.surfaceFor(call.provider, _optionalChain([planned, 'optionalAccess', _16 => _16.surface]));
|
|
203
|
+
if (!found) return next();
|
|
204
|
+
const [surfaceId, surface] = found;
|
|
205
|
+
const steps = _optionalChain([planned, 'optionalAccess', _17 => _17.steps, 'optionalAccess', _18 => _18.length]) ? planned.steps : derivePlaybackSteps(call.args, surface.defaultKind);
|
|
206
|
+
const glance = readOnly && this.reads === "glance";
|
|
207
|
+
const played = glance ? steps.filter((s) => GLANCE_STEPS.has(s.type)) : steps;
|
|
208
|
+
if (!played.some((s) => s.type !== "commit")) return next();
|
|
209
|
+
return this.enqueue(actor, async () => {
|
|
210
|
+
if (surface.visible && !surface.visible()) {
|
|
211
|
+
await _optionalChain([surface, 'access', _19 => _19.reveal, 'optionalCall', _20 => _20()]);
|
|
212
|
+
if (surface.visible && !surface.visible()) return next();
|
|
213
|
+
}
|
|
214
|
+
return this.play({ call, next, actor, surfaceId, surface, steps: played, readOnly, glance });
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
async play(run) {
|
|
218
|
+
const { call, next, actor, surfaceId, surface, readOnly } = run;
|
|
219
|
+
const id = actor.info.id;
|
|
220
|
+
const gen = this.generation;
|
|
221
|
+
const instant = () => gen !== this.generation || !Number.isFinite(this.speed);
|
|
222
|
+
const pace = () => Math.max(0.1, this.speed) * (run.glance ? 1.6 : 1);
|
|
223
|
+
const wait = (ms) => instant() || ms <= 0 ? Promise.resolve() : this.clock.wait(ms / pace());
|
|
224
|
+
const presence = surface.presence;
|
|
225
|
+
const locate = (ref) => _nullishCoalesce(_optionalChain([surface, 'access', _21 => _21.locate, 'optionalCall', _22 => _22(ref.kind === "item" ? { kind: _nullishCoalesce(surface.defaultKind, () => ( "item")), id: ref.id } : ref)]), () => ( null));
|
|
226
|
+
const record = (step) => {
|
|
227
|
+
for (const list of this.recordings) list.push({ actor: id, surface: surfaceId, tool: call.name, step });
|
|
228
|
+
};
|
|
229
|
+
this.running++;
|
|
230
|
+
if (this.running === 1) this.listeners.forEach((l) => l());
|
|
231
|
+
try {
|
|
232
|
+
if (actor.surface && actor.surface !== surfaceId) _optionalChain([this, 'access', _23 => _23.surfaces, 'access', _24 => _24.get, 'call', _25 => _25(actor.surface), 'optionalAccess', _26 => _26.presence, 'access', _27 => _27.remove, 'call', _28 => _28(id)]);
|
|
233
|
+
if (!presence.get(id)) {
|
|
234
|
+
const bounds = _nullishCoalesce(_optionalChain([surface, 'access', _29 => _29.bounds, 'optionalCall', _30 => _30()]), () => ( null));
|
|
235
|
+
let at = actor.viewport && surface.fromViewport ? surface.fromViewport(actor.viewport) : null;
|
|
236
|
+
if (at && bounds) at = { x: Math.min(bounds.x + bounds.width, Math.max(bounds.x, at.x)), y: Math.min(bounds.y + bounds.height, Math.max(bounds.y, at.y)) };
|
|
237
|
+
at ??= bounds ? { x: bounds.x + bounds.width - 48, y: bounds.y + 32 } : null;
|
|
238
|
+
if (!at) {
|
|
239
|
+
const first = run.steps.find((s) => s.type === "move" || s.type === "target" || s.type === "drag");
|
|
240
|
+
const rect = _optionalChain([first, 'optionalAccess', _31 => _31.type]) === "target" ? locate(first.ref) : null;
|
|
241
|
+
at = first && first.type !== "target" ? first.to : rect ? center(rect) : { x: 0, y: 0 };
|
|
242
|
+
}
|
|
243
|
+
presence.set({ id, name: _nullishCoalesce(actor.info.name, () => ( id)), color: actor.info.color, x: at.x, y: at.y, pressed: false });
|
|
244
|
+
} else presence.set({ id, name: _nullishCoalesce(actor.info.name, () => ( id)), color: actor.info.color });
|
|
245
|
+
actor.surface = surfaceId;
|
|
246
|
+
actor.version++;
|
|
247
|
+
const argRefs = playbackRefsFromArgs(call.args, surface.defaultKind);
|
|
248
|
+
if (!readOnly) _optionalChain([surface, 'access', _32 => _32.beginGesture, 'optionalCall', _33 => _33(`agent:${id}:${++this.calls}`)]);
|
|
249
|
+
let result;
|
|
250
|
+
let committed = false;
|
|
251
|
+
try {
|
|
252
|
+
for (const step of run.steps) {
|
|
253
|
+
record(step);
|
|
254
|
+
if (step.type === "commit") {
|
|
255
|
+
if (committed) continue;
|
|
256
|
+
committed = true;
|
|
257
|
+
result = await next();
|
|
258
|
+
continue;
|
|
259
|
+
}
|
|
260
|
+
if (step.type === "open") {
|
|
261
|
+
if (!surface.open) continue;
|
|
262
|
+
const rect = locate(step.ref);
|
|
263
|
+
if (rect) {
|
|
264
|
+
await this.glide(presence, id, { x: rect.x + rect.width / 2, y: rect.y + rect.height / 2 }, step.ms, instant);
|
|
265
|
+
presence.set({ id, pressed: true });
|
|
266
|
+
await wait(90);
|
|
267
|
+
}
|
|
268
|
+
await surface.open(step.ref);
|
|
269
|
+
presence.set({ id, pressed: false });
|
|
270
|
+
await wait(220);
|
|
271
|
+
continue;
|
|
272
|
+
}
|
|
273
|
+
await this.step(presence, locate, id, step, wait, instant);
|
|
274
|
+
}
|
|
275
|
+
if (!committed) {
|
|
276
|
+
record({ type: "commit" });
|
|
277
|
+
result = await next();
|
|
278
|
+
}
|
|
279
|
+
} catch (error) {
|
|
280
|
+
presence.set({ id, pressed: false, message: `\u2717 ${error instanceof Error ? error.message : String(error)}`.slice(0, 140) });
|
|
281
|
+
await wait(900);
|
|
282
|
+
throw error;
|
|
283
|
+
} finally {
|
|
284
|
+
if (!readOnly) _optionalChain([surface, 'access', _34 => _34.endGesture, 'optionalCall', _35 => _35()]);
|
|
285
|
+
presence.set({ id, pressed: false });
|
|
286
|
+
}
|
|
287
|
+
if (isErrorResult(result)) {
|
|
288
|
+
const text = _nullishCoalesce(_optionalChain([result, 'access', _36 => _36.content, 'optionalAccess', _37 => _37.find, 'call', _38 => _38((c) => c.type === "text"), 'optionalAccess', _39 => _39.text]), () => ( "The tool failed."));
|
|
289
|
+
presence.set({ id, message: `\u2717 ${text}`.slice(0, 140) });
|
|
290
|
+
await wait(900);
|
|
291
|
+
} else if (!readOnly) {
|
|
292
|
+
const known = new Set(argRefs.map((r) => `${r.kind}:${r.id}`));
|
|
293
|
+
const fresh = playbackRefsFromResult(result, surface.defaultKind).filter((r) => !known.has(`${r.kind}:${r.id}`));
|
|
294
|
+
const rect = unionRects(fresh.slice(0, 16).map(locate));
|
|
295
|
+
if (rect) {
|
|
296
|
+
const step = { type: "focus", rect };
|
|
297
|
+
record(step);
|
|
298
|
+
presence.set({ id, focus: rect });
|
|
299
|
+
await wait(450);
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
presence.set({ id, message: void 0, focus: void 0 });
|
|
303
|
+
const here = presence.get(id);
|
|
304
|
+
if (here && surface.toViewport) actor.viewport = surface.toViewport({ x: here.x, y: here.y });
|
|
305
|
+
this.scheduleLinger(actor, surface);
|
|
306
|
+
return result;
|
|
307
|
+
} finally {
|
|
308
|
+
this.running--;
|
|
309
|
+
if (this.running === 0) this.listeners.forEach((l) => l());
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
scheduleLinger(actor, surface) {
|
|
313
|
+
if (this.linger <= 0) return;
|
|
314
|
+
const version = actor.version;
|
|
315
|
+
void this.clock.wait(this.linger).then(() => {
|
|
316
|
+
if (actor.version !== version) return;
|
|
317
|
+
surface.presence.remove(actor.info.id);
|
|
318
|
+
for (const [sid, s] of this.surfaces) if (s === surface && actor.surface === sid) actor.surface = void 0;
|
|
319
|
+
});
|
|
320
|
+
}
|
|
321
|
+
async step(presence, locate, id, step, wait, instant) {
|
|
322
|
+
switch (step.type) {
|
|
323
|
+
case "move":
|
|
324
|
+
return this.glide(presence, id, step.to, step.ms, instant);
|
|
325
|
+
case "drag":
|
|
326
|
+
presence.set({ id, pressed: true });
|
|
327
|
+
return this.glide(presence, id, step.to, step.ms, instant);
|
|
328
|
+
case "target": {
|
|
329
|
+
const rect = locate(step.ref);
|
|
330
|
+
if (!rect) return;
|
|
331
|
+
await this.glide(presence, id, center(rect), step.ms, instant);
|
|
332
|
+
presence.set({ id, focus: rect });
|
|
333
|
+
return;
|
|
334
|
+
}
|
|
335
|
+
case "focus":
|
|
336
|
+
presence.set({ id, focus: _nullishCoalesce(step.rect, () => ( void 0)) });
|
|
337
|
+
return;
|
|
338
|
+
case "say":
|
|
339
|
+
presence.set({ id, message: step.text });
|
|
340
|
+
return wait(_nullishCoalesce(step.ms, () => ( readingTime(step.text))));
|
|
341
|
+
case "press":
|
|
342
|
+
presence.set({ id, pressed: true });
|
|
343
|
+
return wait(90);
|
|
344
|
+
case "release":
|
|
345
|
+
presence.set({ id, pressed: false });
|
|
346
|
+
return wait(60);
|
|
347
|
+
case "type": {
|
|
348
|
+
const total = _nullishCoalesce(step.ms, () => ( Math.min(900, 40 * step.text.length + 150)));
|
|
349
|
+
if (instant() || total <= 0) {
|
|
350
|
+
presence.set({ id, message: step.text });
|
|
351
|
+
return;
|
|
352
|
+
}
|
|
353
|
+
const start = this.clock.now();
|
|
354
|
+
for (; ; ) {
|
|
355
|
+
const t = Math.min(1, (this.clock.now() - start) / (total / Math.max(0.1, this.speed)));
|
|
356
|
+
presence.set({ id, message: step.text.slice(0, Math.max(1, Math.round(step.text.length * t))) });
|
|
357
|
+
if (t >= 1 || instant()) break;
|
|
358
|
+
await this.clock.wait(16);
|
|
359
|
+
}
|
|
360
|
+
presence.set({ id, message: step.text });
|
|
361
|
+
return;
|
|
362
|
+
}
|
|
363
|
+
case "wait":
|
|
364
|
+
return wait(step.ms);
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
/** Glides along a slight arc with ease-out, by elapsed time (fewer frames in a throttled tab, never longer). */
|
|
368
|
+
async glide(presence, id, to, ms, instant) {
|
|
369
|
+
const a = presence.get(id);
|
|
370
|
+
const from = a ? { x: a.x, y: a.y } : to;
|
|
371
|
+
const dist = Math.hypot(to.x - from.x, to.y - from.y);
|
|
372
|
+
const duration = (_nullishCoalesce(ms, () => ( Math.min(900, 260 + dist * 0.5)))) / Math.max(0.1, this.speed);
|
|
373
|
+
if (instant() || dist < 1 || duration <= 0) {
|
|
374
|
+
presence.set({ id, x: to.x, y: to.y });
|
|
375
|
+
return;
|
|
376
|
+
}
|
|
377
|
+
const bend = Math.min(60, dist * 0.12);
|
|
378
|
+
const ctrl = { x: (from.x + to.x) / 2 - (to.y - from.y) / dist * bend, y: (from.y + to.y) / 2 + (to.x - from.x) / dist * bend };
|
|
379
|
+
const start = this.clock.now();
|
|
380
|
+
for (; ; ) {
|
|
381
|
+
const t = Math.min(1, (this.clock.now() - start) / duration);
|
|
382
|
+
const e = 1 - Math.pow(1 - t, 3);
|
|
383
|
+
const u = 1 - e;
|
|
384
|
+
presence.set({ id, x: u * u * from.x + 2 * u * e * ctrl.x + e * e * to.x, y: u * u * from.y + 2 * u * e * ctrl.y + e * e * to.y });
|
|
385
|
+
if (t >= 1) break;
|
|
386
|
+
if (instant()) {
|
|
387
|
+
presence.set({ id, x: to.x, y: to.y });
|
|
388
|
+
break;
|
|
389
|
+
}
|
|
390
|
+
await this.clock.wait(16);
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
}, _class);
|
|
394
|
+
function createAgentPlayback(options = {}) {
|
|
395
|
+
return new AgentPlayback(options);
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
|
|
399
|
+
|
|
400
|
+
|
|
401
|
+
|
|
402
|
+
|
|
403
|
+
|
|
404
|
+
|
|
405
|
+
|
|
406
|
+
exports.playbackRefsFromArgs = playbackRefsFromArgs; exports.playbackRefsFromResult = playbackRefsFromResult; exports.derivePlaybackSteps = derivePlaybackSteps; exports.readingTime = readingTime; exports.unionRects = unionRects; exports.AgentPlayback = AgentPlayback; exports.createAgentPlayback = createAgentPlayback;
|