@alisaitteke/photoshop-mcp 1.2.0 → 1.3.3
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/README.md +38 -2
- package/dist/analytics/beta-telemetry.d.ts +11 -0
- package/dist/analytics/beta-telemetry.d.ts.map +1 -0
- package/dist/analytics/beta-telemetry.js +47 -0
- package/dist/analytics/beta-telemetry.js.map +1 -0
- package/dist/analytics/client-ip.d.ts +5 -0
- package/dist/analytics/client-ip.d.ts.map +1 -0
- package/dist/analytics/client-ip.js +39 -0
- package/dist/analytics/client-ip.js.map +1 -0
- package/dist/analytics/config.d.ts +6 -0
- package/dist/analytics/config.d.ts.map +1 -0
- package/dist/analytics/config.js +23 -0
- package/dist/analytics/config.js.map +1 -0
- package/dist/analytics/context.d.ts +2 -0
- package/dist/analytics/context.d.ts.map +1 -0
- package/dist/analytics/context.js +13 -0
- package/dist/analytics/context.js.map +1 -0
- package/dist/analytics/events.d.ts +3 -0
- package/dist/analytics/events.d.ts.map +1 -0
- package/dist/analytics/events.js +85 -0
- package/dist/analytics/events.js.map +1 -0
- package/dist/analytics/identity.d.ts +9 -0
- package/dist/analytics/identity.d.ts.map +1 -0
- package/dist/analytics/identity.js +166 -0
- package/dist/analytics/identity.js.map +1 -0
- package/dist/analytics/index.d.ts +12 -0
- package/dist/analytics/index.d.ts.map +1 -0
- package/dist/analytics/index.js +38 -0
- package/dist/analytics/index.js.map +1 -0
- package/dist/analytics/launch-method.d.ts +4 -0
- package/dist/analytics/launch-method.d.ts.map +1 -0
- package/dist/analytics/launch-method.js +33 -0
- package/dist/analytics/launch-method.js.map +1 -0
- package/dist/analytics/locale.d.ts +4 -0
- package/dist/analytics/locale.d.ts.map +1 -0
- package/dist/analytics/locale.js +14 -0
- package/dist/analytics/locale.js.map +1 -0
- package/dist/analytics/noop.d.ts +6 -0
- package/dist/analytics/noop.d.ts.map +1 -0
- package/dist/analytics/noop.js +9 -0
- package/dist/analytics/noop.js.map +1 -0
- package/dist/analytics/posthog-node.d.ts +11 -0
- package/dist/analytics/posthog-node.d.ts.map +1 -0
- package/dist/analytics/posthog-node.js +55 -0
- package/dist/analytics/posthog-node.js.map +1 -0
- package/dist/analytics/provider.d.ts +5 -0
- package/dist/analytics/provider.d.ts.map +1 -0
- package/dist/analytics/provider.js +27 -0
- package/dist/analytics/provider.js.map +1 -0
- package/dist/analytics/types.d.ts +23 -0
- package/dist/analytics/types.d.ts.map +1 -0
- package/dist/analytics/types.js +2 -0
- package/dist/analytics/types.js.map +1 -0
- package/dist/core/server.d.ts +1 -0
- package/dist/core/server.d.ts.map +1 -1
- package/dist/core/server.js +3 -0
- package/dist/core/server.js.map +1 -1
- package/dist/index.js +32 -0
- package/dist/index.js.map +1 -1
- package/dist/platform/macos-detector.js +4 -4
- package/dist/platform/macos-detector.js.map +1 -1
- package/dist/platform/macos-executor.js +1 -1
- package/dist/platform/macos-executor.js.map +1 -1
- package/dist/platform/windows-detector.js +4 -4
- package/dist/platform/windows-detector.js.map +1 -1
- package/dist/platform/windows-executor.js +2 -2
- package/dist/platform/windows-executor.js.map +1 -1
- package/dist/ui/agent/action-plan.d.ts +19 -0
- package/dist/ui/agent/action-plan.d.ts.map +1 -0
- package/dist/ui/agent/action-plan.js +552 -0
- package/dist/ui/agent/action-plan.js.map +1 -0
- package/dist/ui/agent/api-key.d.ts.map +1 -1
- package/dist/ui/agent/api-key.js +22 -4
- package/dist/ui/agent/api-key.js.map +1 -1
- package/dist/ui/agent/claude-account.d.ts.map +1 -1
- package/dist/ui/agent/claude-account.js +26 -12
- package/dist/ui/agent/claude-account.js.map +1 -1
- package/dist/ui/agent/gemini-account.d.ts.map +1 -1
- package/dist/ui/agent/gemini-account.js +14 -4
- package/dist/ui/agent/gemini-account.js.map +1 -1
- package/dist/ui/agent/shared.d.ts +26 -1
- package/dist/ui/agent/shared.d.ts.map +1 -1
- package/dist/ui/agent/shared.js +61 -0
- package/dist/ui/agent/shared.js.map +1 -1
- package/dist/ui/agent.d.ts +1 -0
- package/dist/ui/agent.d.ts.map +1 -1
- package/dist/ui/agent.js +36 -0
- package/dist/ui/agent.js.map +1 -1
- package/dist/ui/cli.js +11 -1
- package/dist/ui/cli.js.map +1 -1
- package/dist/ui/config.d.ts +6 -1
- package/dist/ui/config.d.ts.map +1 -1
- package/dist/ui/config.js +1 -12
- package/dist/ui/config.js.map +1 -1
- package/dist/ui/server.d.ts.map +1 -1
- package/dist/ui/server.js +103 -6
- package/dist/ui/server.js.map +1 -1
- package/dist/ui/store/chats.d.ts +11 -0
- package/dist/ui/store/chats.d.ts.map +1 -1
- package/dist/ui/store/chats.js.map +1 -1
- package/dist/ui/store/db.js +2 -2
- package/dist/ui/store/db.js.map +1 -1
- package/package.json +4 -2
- package/web/dist/assets/index-BgiXf1Jy.css +1 -0
- package/web/dist/assets/index-n0ymP-Cw.js +249 -0
- package/web/dist/index.html +9 -3
- package/web/dist/assets/index-BN0tu4e6.css +0 -1
- package/web/dist/assets/index-Cf7sH5RM.js +0 -138
|
@@ -0,0 +1,552 @@
|
|
|
1
|
+
import { createMCPClient } from '@ai-sdk/mcp';
|
|
2
|
+
import { Experimental_StdioMCPTransport } from '@ai-sdk/mcp/mcp-stdio';
|
|
3
|
+
import { Output, streamText } from 'ai';
|
|
4
|
+
import { randomUUID } from 'node:crypto';
|
|
5
|
+
import { z } from 'zod';
|
|
6
|
+
import { PHOTOSHOP_EXPORT_CHAT_ID_ENV } from '../../lib/export-paths.js';
|
|
7
|
+
import { buildSpawnArgs, sanitizedEnv } from './mcp-transport.js';
|
|
8
|
+
import { computeCost, isToolOutputOk, parseToolEnvelope, stringifyToolOutput, toolFailureMessage, } from './shared.js';
|
|
9
|
+
const MAX_STEPS = 20;
|
|
10
|
+
const MAX_REPAIRS = 3;
|
|
11
|
+
const MAX_SUGGESTED_FOLLOW_UPS = 5;
|
|
12
|
+
const planStepSchema = z.object({
|
|
13
|
+
id: z.string().describe('Unique short id for this step, e.g. "s1".'),
|
|
14
|
+
tool: z.string().describe('Exact tool name from the catalog.'),
|
|
15
|
+
argsJson: z
|
|
16
|
+
.string()
|
|
17
|
+
.describe('JSON-encoded object of arguments for the tool. Use "{}" if none. ' +
|
|
18
|
+
'A value may reference a prior step result with the placeholder ' +
|
|
19
|
+
'"$steps.<stepId>.<dot.path>" (e.g. "$steps.s1.document.id").'),
|
|
20
|
+
rationale: z.string().optional().describe('One short sentence on why this step.'),
|
|
21
|
+
dependsOn: z.array(z.string()).optional().describe('Step ids this step depends on.'),
|
|
22
|
+
});
|
|
23
|
+
const planSchema = z.object({
|
|
24
|
+
summary: z.string().describe('One short sentence summarizing the overall plan.'),
|
|
25
|
+
steps: z.array(planStepSchema).max(MAX_STEPS),
|
|
26
|
+
});
|
|
27
|
+
class PlaceholderError extends Error {
|
|
28
|
+
}
|
|
29
|
+
export async function* runChatViaActionPlan(opts) {
|
|
30
|
+
let mcp;
|
|
31
|
+
const buffer = { text: '', toolCalls: [] };
|
|
32
|
+
const model = opts.provider.getLanguageModel({ apiKey: opts.apiKey, modelId: opts.modelId });
|
|
33
|
+
const pricing = opts.provider.getModelPricing(opts.modelId);
|
|
34
|
+
// Aggregate planner + repair token usage across all generateObject calls.
|
|
35
|
+
const totalUsage = {
|
|
36
|
+
inputTokens: 0,
|
|
37
|
+
outputTokens: 0,
|
|
38
|
+
totalTokens: 0,
|
|
39
|
+
inputTokenDetails: { noCacheTokens: 0, cacheReadTokens: 0, cacheWriteTokens: 0 },
|
|
40
|
+
outputTokenDetails: { textTokens: 0, reasoningTokens: 0 },
|
|
41
|
+
};
|
|
42
|
+
const addUsage = (u) => {
|
|
43
|
+
if (!u)
|
|
44
|
+
return;
|
|
45
|
+
totalUsage.inputTokens = (totalUsage.inputTokens ?? 0) + (u.inputTokens ?? 0);
|
|
46
|
+
totalUsage.outputTokens = (totalUsage.outputTokens ?? 0) + (u.outputTokens ?? 0);
|
|
47
|
+
totalUsage.totalTokens = (totalUsage.totalTokens ?? 0) + (u.totalTokens ?? 0);
|
|
48
|
+
const id = totalUsage.inputTokenDetails;
|
|
49
|
+
id.noCacheTokens = (id.noCacheTokens ?? 0) + (u.inputTokenDetails?.noCacheTokens ?? 0);
|
|
50
|
+
id.cacheReadTokens = (id.cacheReadTokens ?? 0) + (u.inputTokenDetails?.cacheReadTokens ?? 0);
|
|
51
|
+
id.cacheWriteTokens = (id.cacheWriteTokens ?? 0) + (u.inputTokenDetails?.cacheWriteTokens ?? 0);
|
|
52
|
+
const od = totalUsage.outputTokenDetails;
|
|
53
|
+
od.textTokens = (od.textTokens ?? 0) + (u.outputTokenDetails?.textTokens ?? 0);
|
|
54
|
+
od.reasoningTokens = (od.reasoningTokens ?? 0) + (u.outputTokenDetails?.reasoningTokens ?? 0);
|
|
55
|
+
};
|
|
56
|
+
try {
|
|
57
|
+
mcp = await createMCPClient({
|
|
58
|
+
transport: new Experimental_StdioMCPTransport({
|
|
59
|
+
command: process.execPath,
|
|
60
|
+
args: buildSpawnArgs(),
|
|
61
|
+
env: {
|
|
62
|
+
...sanitizedEnv(),
|
|
63
|
+
LOG_LEVEL: process.env.LOG_LEVEL ?? '2',
|
|
64
|
+
...(opts.chatId ? { [PHOTOSHOP_EXPORT_CHAT_ID_ENV]: opts.chatId } : {}),
|
|
65
|
+
},
|
|
66
|
+
}),
|
|
67
|
+
});
|
|
68
|
+
const tools = (await mcp.tools());
|
|
69
|
+
const catalog = buildToolCatalog(tools);
|
|
70
|
+
// ---- 1. Plan ---------------------------------------------------------
|
|
71
|
+
yield { type: 'activity', payload: { phase: 'planning' } };
|
|
72
|
+
let plan;
|
|
73
|
+
try {
|
|
74
|
+
const streamed = streamText({
|
|
75
|
+
model,
|
|
76
|
+
output: Output.object({ schema: planSchema }),
|
|
77
|
+
system: opts.systemPrompt,
|
|
78
|
+
prompt: buildPlannerPrompt(catalog, opts.history, opts.prompt),
|
|
79
|
+
abortSignal: opts.abortSignal,
|
|
80
|
+
});
|
|
81
|
+
for await (const partial of streamed.partialOutputStream) {
|
|
82
|
+
const partialView = toPartialPlanView(partial);
|
|
83
|
+
buffer.plan = partialView;
|
|
84
|
+
yield { type: 'plan-partial', payload: partialView };
|
|
85
|
+
opts.onAssistantBuffer?.(buffer);
|
|
86
|
+
}
|
|
87
|
+
plan = await streamed.output;
|
|
88
|
+
addUsage(await streamed.usage);
|
|
89
|
+
}
|
|
90
|
+
catch (err) {
|
|
91
|
+
yield {
|
|
92
|
+
type: 'error',
|
|
93
|
+
payload: { message: `Planning failed: ${err.message}` },
|
|
94
|
+
};
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
// Empty plan -> fall back to a single natural-language reply.
|
|
98
|
+
if (!plan.steps.length) {
|
|
99
|
+
buffer.text = plan.summary?.trim() || 'No actionable steps were produced for this request.';
|
|
100
|
+
yield { type: 'text-delta', payload: { text: buffer.text } };
|
|
101
|
+
opts.onAssistantBuffer?.(buffer);
|
|
102
|
+
yield* emitFinish();
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
const planView = {
|
|
106
|
+
summary: plan.summary,
|
|
107
|
+
steps: plan.steps.map((s) => toStepView(s, 'pending')),
|
|
108
|
+
};
|
|
109
|
+
buffer.plan = planView;
|
|
110
|
+
yield { type: 'plan', payload: planView };
|
|
111
|
+
opts.onAssistantBuffer?.(buffer);
|
|
112
|
+
// ---- 2. Execute (with bounded repair) --------------------------------
|
|
113
|
+
const results = {};
|
|
114
|
+
let steps = plan.steps;
|
|
115
|
+
let i = 0;
|
|
116
|
+
let repairs = 0;
|
|
117
|
+
while (i < steps.length) {
|
|
118
|
+
if (opts.abortSignal.aborted)
|
|
119
|
+
break;
|
|
120
|
+
const step = steps[i];
|
|
121
|
+
const toolCallId = randomUUID();
|
|
122
|
+
setStepStatus(planView, step.id, 'running');
|
|
123
|
+
yield { type: 'plan-step', payload: { id: step.id, status: 'running' } };
|
|
124
|
+
opts.onAssistantBuffer?.(buffer);
|
|
125
|
+
const tool = tools[step.tool];
|
|
126
|
+
// Resolve args + validate tool existence before announcing the call.
|
|
127
|
+
let args;
|
|
128
|
+
let prepError;
|
|
129
|
+
if (!tool || typeof tool.execute !== 'function') {
|
|
130
|
+
prepError = `Unknown tool "${step.tool}". It is not in the available tool catalog.`;
|
|
131
|
+
}
|
|
132
|
+
else {
|
|
133
|
+
try {
|
|
134
|
+
args = resolveArgs(step.argsJson, results);
|
|
135
|
+
}
|
|
136
|
+
catch (err) {
|
|
137
|
+
prepError =
|
|
138
|
+
err instanceof PlaceholderError
|
|
139
|
+
? `Unresolved dependency: ${err.message}`
|
|
140
|
+
: `Invalid arguments JSON: ${err.message}`;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
if (prepError) {
|
|
144
|
+
const repaired = yield* tryRepair(prepError, step);
|
|
145
|
+
if (!repaired)
|
|
146
|
+
break;
|
|
147
|
+
continue;
|
|
148
|
+
}
|
|
149
|
+
yield {
|
|
150
|
+
type: 'tool-call',
|
|
151
|
+
payload: { id: toolCallId, name: step.tool, input: args },
|
|
152
|
+
};
|
|
153
|
+
buffer.toolCalls.push({ id: toolCallId, name: step.tool, input: args, status: 'pending' });
|
|
154
|
+
opts.onAssistantBuffer?.(buffer);
|
|
155
|
+
try {
|
|
156
|
+
const output = await tool.execute(args, {
|
|
157
|
+
toolCallId,
|
|
158
|
+
messages: [],
|
|
159
|
+
abortSignal: opts.abortSignal,
|
|
160
|
+
});
|
|
161
|
+
results[step.id] = output;
|
|
162
|
+
const text = stringifyToolOutput(output);
|
|
163
|
+
const ok = isToolOutputOk(output);
|
|
164
|
+
const tc = buffer.toolCalls.find((c) => c.id === toolCallId);
|
|
165
|
+
if (tc) {
|
|
166
|
+
tc.result = { ok, content: text };
|
|
167
|
+
tc.status = ok ? 'success' : 'error';
|
|
168
|
+
}
|
|
169
|
+
yield { type: 'tool-result', payload: { id: toolCallId, ok, content: text } };
|
|
170
|
+
opts.onAssistantBuffer?.(buffer);
|
|
171
|
+
if (ok) {
|
|
172
|
+
setStepStatus(planView, step.id, 'done');
|
|
173
|
+
yield { type: 'plan-step', payload: { id: step.id, status: 'done' } };
|
|
174
|
+
opts.onAssistantBuffer?.(buffer);
|
|
175
|
+
i++;
|
|
176
|
+
}
|
|
177
|
+
else {
|
|
178
|
+
const repaired = yield* tryRepair(toolFailureMessage(output, text), step);
|
|
179
|
+
if (!repaired)
|
|
180
|
+
break;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
catch (err) {
|
|
184
|
+
const text = err?.message ?? String(err);
|
|
185
|
+
const tc = buffer.toolCalls.find((c) => c.id === toolCallId);
|
|
186
|
+
if (tc) {
|
|
187
|
+
tc.result = { ok: false, content: text };
|
|
188
|
+
tc.status = 'error';
|
|
189
|
+
}
|
|
190
|
+
yield { type: 'tool-result', payload: { id: toolCallId, ok: false, content: text } };
|
|
191
|
+
opts.onAssistantBuffer?.(buffer);
|
|
192
|
+
const repaired = yield* tryRepair(text, step);
|
|
193
|
+
if (!repaired)
|
|
194
|
+
break;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
// ---- 3. Execute tool-suggested follow-ups (no extra LLM round-trip) --
|
|
198
|
+
if (i >= steps.length && !opts.abortSignal.aborted && steps.length > 0) {
|
|
199
|
+
const lastStep = steps[steps.length - 1];
|
|
200
|
+
let lastOutput = results[lastStep.id];
|
|
201
|
+
let followUpCount = 0;
|
|
202
|
+
const seenFollowUpTools = new Set();
|
|
203
|
+
while (followUpCount < MAX_SUGGESTED_FOLLOW_UPS &&
|
|
204
|
+
lastOutput &&
|
|
205
|
+
!opts.abortSignal.aborted) {
|
|
206
|
+
const suggestion = extractSuggestedFollowUp(lastOutput);
|
|
207
|
+
if (!suggestion || seenFollowUpTools.has(suggestion.tool))
|
|
208
|
+
break;
|
|
209
|
+
const followTool = tools[suggestion.tool];
|
|
210
|
+
if (!followTool || typeof followTool.execute !== 'function')
|
|
211
|
+
break;
|
|
212
|
+
seenFollowUpTools.add(suggestion.tool);
|
|
213
|
+
followUpCount++;
|
|
214
|
+
const followStepId = `followup-${followUpCount}`;
|
|
215
|
+
const toolCallId = randomUUID();
|
|
216
|
+
planView.steps.push({
|
|
217
|
+
id: followStepId,
|
|
218
|
+
tool: suggestion.tool,
|
|
219
|
+
rationale: 'Suggested by prior tool result',
|
|
220
|
+
status: 'running',
|
|
221
|
+
});
|
|
222
|
+
yield { type: 'plan', payload: planView };
|
|
223
|
+
yield {
|
|
224
|
+
type: 'plan-step',
|
|
225
|
+
payload: { id: followStepId, status: 'running' },
|
|
226
|
+
};
|
|
227
|
+
opts.onAssistantBuffer?.(buffer);
|
|
228
|
+
yield {
|
|
229
|
+
type: 'tool-call',
|
|
230
|
+
payload: { id: toolCallId, name: suggestion.tool, input: suggestion.args },
|
|
231
|
+
};
|
|
232
|
+
buffer.toolCalls.push({
|
|
233
|
+
id: toolCallId,
|
|
234
|
+
name: suggestion.tool,
|
|
235
|
+
input: suggestion.args,
|
|
236
|
+
status: 'pending',
|
|
237
|
+
});
|
|
238
|
+
opts.onAssistantBuffer?.(buffer);
|
|
239
|
+
try {
|
|
240
|
+
const output = await followTool.execute(suggestion.args, {
|
|
241
|
+
toolCallId,
|
|
242
|
+
messages: [],
|
|
243
|
+
abortSignal: opts.abortSignal,
|
|
244
|
+
});
|
|
245
|
+
lastOutput = output;
|
|
246
|
+
results[followStepId] = output;
|
|
247
|
+
const text = stringifyToolOutput(output);
|
|
248
|
+
const ok = isToolOutputOk(output);
|
|
249
|
+
const tc = buffer.toolCalls.find((c) => c.id === toolCallId);
|
|
250
|
+
if (tc) {
|
|
251
|
+
tc.result = { ok, content: text };
|
|
252
|
+
tc.status = ok ? 'success' : 'error';
|
|
253
|
+
}
|
|
254
|
+
yield { type: 'tool-result', payload: { id: toolCallId, ok, content: text } };
|
|
255
|
+
if (ok) {
|
|
256
|
+
setStepStatus(planView, followStepId, 'done');
|
|
257
|
+
yield {
|
|
258
|
+
type: 'plan-step',
|
|
259
|
+
payload: { id: followStepId, status: 'done' },
|
|
260
|
+
};
|
|
261
|
+
opts.onAssistantBuffer?.(buffer);
|
|
262
|
+
}
|
|
263
|
+
else {
|
|
264
|
+
setStepStatus(planView, followStepId, 'error');
|
|
265
|
+
yield {
|
|
266
|
+
type: 'plan-step',
|
|
267
|
+
payload: { id: followStepId, status: 'error' },
|
|
268
|
+
};
|
|
269
|
+
opts.onAssistantBuffer?.(buffer);
|
|
270
|
+
break;
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
catch (err) {
|
|
274
|
+
const text = err?.message ?? String(err);
|
|
275
|
+
const tc = buffer.toolCalls.find((c) => c.id === toolCallId);
|
|
276
|
+
if (tc) {
|
|
277
|
+
tc.result = { ok: false, content: text };
|
|
278
|
+
tc.status = 'error';
|
|
279
|
+
}
|
|
280
|
+
yield { type: 'tool-result', payload: { id: toolCallId, ok: false, content: text } };
|
|
281
|
+
setStepStatus(planView, followStepId, 'error');
|
|
282
|
+
yield {
|
|
283
|
+
type: 'plan-step',
|
|
284
|
+
payload: { id: followStepId, status: 'error' },
|
|
285
|
+
};
|
|
286
|
+
opts.onAssistantBuffer?.(buffer);
|
|
287
|
+
break;
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
yield* emitFinish();
|
|
292
|
+
return;
|
|
293
|
+
// ---- helpers (closures over plan state) ------------------------------
|
|
294
|
+
function* emitFinish() {
|
|
295
|
+
const cost = pricing ? computeCost(totalUsage, pricing) : undefined;
|
|
296
|
+
opts.onFinish?.({ usage: totalUsage, cost });
|
|
297
|
+
yield { type: 'finish', payload: { finishReason: 'stop', usage: totalUsage, cost } };
|
|
298
|
+
}
|
|
299
|
+
/**
|
|
300
|
+
* Re-plan ONLY the remaining steps (from the current failed index) using the
|
|
301
|
+
* accumulated results and the error. Returns false when the repair budget is
|
|
302
|
+
* exhausted (caller should stop), true when execution can continue.
|
|
303
|
+
*/
|
|
304
|
+
async function* tryRepair(errorMessage, failedStep) {
|
|
305
|
+
if (repairs >= MAX_REPAIRS) {
|
|
306
|
+
setStepStatus(planView, failedStep.id, 'error');
|
|
307
|
+
opts.onAssistantBuffer?.(buffer);
|
|
308
|
+
yield {
|
|
309
|
+
type: 'plan-step',
|
|
310
|
+
payload: { id: failedStep.id, status: 'error' },
|
|
311
|
+
};
|
|
312
|
+
yield {
|
|
313
|
+
type: 'error',
|
|
314
|
+
payload: {
|
|
315
|
+
message: `Action plan failed after ${MAX_REPAIRS} repair attempts at step "${failedStep.id}": ${errorMessage}`,
|
|
316
|
+
},
|
|
317
|
+
};
|
|
318
|
+
return false;
|
|
319
|
+
}
|
|
320
|
+
repairs++;
|
|
321
|
+
setStepStatus(planView, failedStep.id, 'error');
|
|
322
|
+
yield { type: 'plan-step', payload: { id: failedStep.id, status: 'error' } };
|
|
323
|
+
yield {
|
|
324
|
+
type: 'plan-repair',
|
|
325
|
+
payload: { stepId: failedStep.id, attempt: repairs, reason: errorMessage },
|
|
326
|
+
};
|
|
327
|
+
opts.onAssistantBuffer?.(buffer);
|
|
328
|
+
const remaining = steps.slice(i);
|
|
329
|
+
let replanned;
|
|
330
|
+
try {
|
|
331
|
+
yield { type: 'activity', payload: { phase: 'planning' } };
|
|
332
|
+
const streamed = streamText({
|
|
333
|
+
model,
|
|
334
|
+
output: Output.object({ schema: planSchema }),
|
|
335
|
+
system: opts.systemPrompt,
|
|
336
|
+
prompt: buildRepairPrompt(catalog, opts.prompt, remaining, results, errorMessage),
|
|
337
|
+
abortSignal: opts.abortSignal,
|
|
338
|
+
});
|
|
339
|
+
for await (const partial of streamed.partialOutputStream) {
|
|
340
|
+
const partialTail = toPartialPlanView(partial);
|
|
341
|
+
const mergedView = {
|
|
342
|
+
summary: partialTail.summary || planView.summary,
|
|
343
|
+
steps: [
|
|
344
|
+
...planView.steps.slice(0, i),
|
|
345
|
+
...partialTail.steps,
|
|
346
|
+
],
|
|
347
|
+
};
|
|
348
|
+
buffer.plan = mergedView;
|
|
349
|
+
yield { type: 'plan-partial', payload: mergedView };
|
|
350
|
+
opts.onAssistantBuffer?.(buffer);
|
|
351
|
+
}
|
|
352
|
+
replanned = await streamed.output;
|
|
353
|
+
addUsage(await streamed.usage);
|
|
354
|
+
}
|
|
355
|
+
catch (err) {
|
|
356
|
+
yield {
|
|
357
|
+
type: 'error',
|
|
358
|
+
payload: { message: `Re-planning failed: ${err.message}` },
|
|
359
|
+
};
|
|
360
|
+
return false;
|
|
361
|
+
}
|
|
362
|
+
// Splice the new steps in place of the remaining ones; keep index.
|
|
363
|
+
steps = [...steps.slice(0, i), ...replanned.steps];
|
|
364
|
+
// Rebuild the plan view tail so the UI reflects the new todo list.
|
|
365
|
+
planView.steps = [
|
|
366
|
+
...planView.steps.slice(0, i),
|
|
367
|
+
...replanned.steps.map((s) => toStepView(s, 'pending')),
|
|
368
|
+
];
|
|
369
|
+
yield { type: 'plan', payload: planView };
|
|
370
|
+
opts.onAssistantBuffer?.(buffer);
|
|
371
|
+
return true;
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
finally {
|
|
375
|
+
if (mcp)
|
|
376
|
+
await mcp.close().catch(() => undefined);
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
// ---- pure helpers ------------------------------------------------------
|
|
380
|
+
function toStepView(step, status) {
|
|
381
|
+
return { id: step.id, tool: step.tool, rationale: step.rationale, status };
|
|
382
|
+
}
|
|
383
|
+
function toPartialPlanView(partial) {
|
|
384
|
+
const rawSteps = partial.steps ?? [];
|
|
385
|
+
const steps = [];
|
|
386
|
+
for (const s of rawSteps) {
|
|
387
|
+
if (!s)
|
|
388
|
+
continue;
|
|
389
|
+
steps.push({
|
|
390
|
+
id: s.id ?? '',
|
|
391
|
+
tool: s.tool ?? '',
|
|
392
|
+
rationale: s.rationale,
|
|
393
|
+
status: 'pending',
|
|
394
|
+
});
|
|
395
|
+
}
|
|
396
|
+
return {
|
|
397
|
+
summary: partial.summary ?? '',
|
|
398
|
+
steps: steps.filter((s) => s.id || s.tool),
|
|
399
|
+
};
|
|
400
|
+
}
|
|
401
|
+
function setStepStatus(plan, id, status) {
|
|
402
|
+
const step = plan.steps.find((s) => s.id === id);
|
|
403
|
+
if (step)
|
|
404
|
+
step.status = status;
|
|
405
|
+
}
|
|
406
|
+
function buildToolCatalog(tools) {
|
|
407
|
+
const lines = [];
|
|
408
|
+
for (const [name, tool] of Object.entries(tools)) {
|
|
409
|
+
const desc = (tool.description ?? '').replace(/\s+/g, ' ').trim();
|
|
410
|
+
let params = '';
|
|
411
|
+
try {
|
|
412
|
+
const schema = tool.inputSchema;
|
|
413
|
+
const json = schema?.jsonSchema ?? schema;
|
|
414
|
+
if (json)
|
|
415
|
+
params = JSON.stringify(json);
|
|
416
|
+
}
|
|
417
|
+
catch {
|
|
418
|
+
params = '';
|
|
419
|
+
}
|
|
420
|
+
lines.push(`- ${name}: ${desc}${params ? `\n params: ${params}` : ''}`);
|
|
421
|
+
}
|
|
422
|
+
return lines.join('\n');
|
|
423
|
+
}
|
|
424
|
+
function buildPlannerPrompt(catalog, history, prompt) {
|
|
425
|
+
return [
|
|
426
|
+
'Produce a COMPLETE ordered execution plan of Photoshop MCP tool calls that fully delivers the user request.',
|
|
427
|
+
'Rules:',
|
|
428
|
+
'- Use ONLY tools from the catalog below; copy tool names exactly.',
|
|
429
|
+
'- Each step\'s argsJson must be a valid JSON object string matching the tool params.',
|
|
430
|
+
'- When a step needs a value produced by an earlier step, reference it with',
|
|
431
|
+
' "$steps.<stepId>.<dot.path>" inside argsJson instead of guessing.',
|
|
432
|
+
'- The plan must accomplish the full request end-to-end. Do not stop at partial progress.',
|
|
433
|
+
'- After meaningful visual edits, include photoshop_get_preview when the user expects to see the result.',
|
|
434
|
+
'- Prefer photoshop_recipe_* tools over composing many atomic calls when the request matches a recipe.',
|
|
435
|
+
'- Read each tool description: if a recipe already performs a sub-task, do not duplicate with atomic tools.',
|
|
436
|
+
'- Include photoshop_get_state when document/layer state is uncertain before dependent tools.',
|
|
437
|
+
'- Include export/save steps when the user asks to export or save a file.',
|
|
438
|
+
'',
|
|
439
|
+
'Tool catalog:',
|
|
440
|
+
catalog,
|
|
441
|
+
'',
|
|
442
|
+
formatHistory(history),
|
|
443
|
+
`User request: ${prompt}`,
|
|
444
|
+
]
|
|
445
|
+
.filter(Boolean)
|
|
446
|
+
.join('\n');
|
|
447
|
+
}
|
|
448
|
+
function buildRepairPrompt(catalog, originalPrompt, remaining, results, errorMessage) {
|
|
449
|
+
return [
|
|
450
|
+
'A step in the execution plan failed. Re-plan ONLY the remaining work.',
|
|
451
|
+
`Original user request: ${originalPrompt}`,
|
|
452
|
+
'',
|
|
453
|
+
'Error from the failed step:',
|
|
454
|
+
errorMessage,
|
|
455
|
+
'',
|
|
456
|
+
'Results already produced by completed steps (JSON):',
|
|
457
|
+
safeJson(results),
|
|
458
|
+
'',
|
|
459
|
+
'Remaining steps that still need to run (the first one failed):',
|
|
460
|
+
safeJson(remaining),
|
|
461
|
+
'',
|
|
462
|
+
'Return a corrected, ordered plan for the remaining work only. Reuse prior results',
|
|
463
|
+
'via "$steps.<stepId>.<dot.path>" placeholders. Use ONLY tools from the catalog.',
|
|
464
|
+
'',
|
|
465
|
+
'Tool catalog:',
|
|
466
|
+
catalog,
|
|
467
|
+
].join('\n');
|
|
468
|
+
}
|
|
469
|
+
function formatHistory(history) {
|
|
470
|
+
if (!history.length)
|
|
471
|
+
return '';
|
|
472
|
+
const lines = history
|
|
473
|
+
.map((m) => {
|
|
474
|
+
const text = typeof m.content === 'string'
|
|
475
|
+
? m.content
|
|
476
|
+
: Array.isArray(m.content)
|
|
477
|
+
? m.content.map((p) => ('text' in p ? p.text : '')).filter(Boolean).join(' ')
|
|
478
|
+
: '';
|
|
479
|
+
const trimmed = text.trim();
|
|
480
|
+
return trimmed ? `${m.role === 'user' ? 'User' : 'Assistant'}: ${trimmed}` : '';
|
|
481
|
+
})
|
|
482
|
+
.filter(Boolean);
|
|
483
|
+
return lines.length ? `Conversation so far:\n${lines.join('\n')}\n` : '';
|
|
484
|
+
}
|
|
485
|
+
function resolveArgs(argsJson, results) {
|
|
486
|
+
const trimmed = (argsJson ?? '').trim();
|
|
487
|
+
if (!trimmed)
|
|
488
|
+
return {};
|
|
489
|
+
const parsed = JSON.parse(trimmed);
|
|
490
|
+
return resolvePlaceholders(parsed, results);
|
|
491
|
+
}
|
|
492
|
+
const PLACEHOLDER_RE = /^\$steps\.([^.]+)(?:\.(.+))?$/;
|
|
493
|
+
function resolvePlaceholders(value, results) {
|
|
494
|
+
if (typeof value === 'string') {
|
|
495
|
+
const match = PLACEHOLDER_RE.exec(value);
|
|
496
|
+
if (!match)
|
|
497
|
+
return value;
|
|
498
|
+
const [, stepId, path] = match;
|
|
499
|
+
if (!(stepId in results)) {
|
|
500
|
+
throw new PlaceholderError(`step "${stepId}" has no result yet for "${value}"`);
|
|
501
|
+
}
|
|
502
|
+
const resolved = path ? getByPath(results[stepId], path) : results[stepId];
|
|
503
|
+
if (resolved === undefined) {
|
|
504
|
+
throw new PlaceholderError(`path "${path}" not found in result of step "${stepId}"`);
|
|
505
|
+
}
|
|
506
|
+
return resolved;
|
|
507
|
+
}
|
|
508
|
+
if (Array.isArray(value)) {
|
|
509
|
+
return value.map((v) => resolvePlaceholders(v, results));
|
|
510
|
+
}
|
|
511
|
+
if (value && typeof value === 'object') {
|
|
512
|
+
const out = {};
|
|
513
|
+
for (const [k, v] of Object.entries(value)) {
|
|
514
|
+
out[k] = resolvePlaceholders(v, results);
|
|
515
|
+
}
|
|
516
|
+
return out;
|
|
517
|
+
}
|
|
518
|
+
return value;
|
|
519
|
+
}
|
|
520
|
+
function getByPath(root, path) {
|
|
521
|
+
let current = root;
|
|
522
|
+
for (const key of path.split('.')) {
|
|
523
|
+
if (current == null || typeof current !== 'object')
|
|
524
|
+
return undefined;
|
|
525
|
+
current = current[key];
|
|
526
|
+
}
|
|
527
|
+
return current;
|
|
528
|
+
}
|
|
529
|
+
function safeJson(value) {
|
|
530
|
+
try {
|
|
531
|
+
return JSON.stringify(value, null, 2);
|
|
532
|
+
}
|
|
533
|
+
catch {
|
|
534
|
+
return String(value);
|
|
535
|
+
}
|
|
536
|
+
}
|
|
537
|
+
/** Parse tool result envelopes for next_suggested_tool / suggested_next_tool hints. */
|
|
538
|
+
function extractSuggestedFollowUp(result) {
|
|
539
|
+
const parsed = parseToolEnvelope(result);
|
|
540
|
+
if (!parsed)
|
|
541
|
+
return null;
|
|
542
|
+
const tool = (typeof parsed.next_suggested_tool === 'string' && parsed.next_suggested_tool) ||
|
|
543
|
+
(typeof parsed.suggested_next_tool === 'string' && parsed.suggested_next_tool) ||
|
|
544
|
+
null;
|
|
545
|
+
if (!tool)
|
|
546
|
+
return null;
|
|
547
|
+
const args = parsed.suggested_args && typeof parsed.suggested_args === 'object' && parsed.suggested_args !== null
|
|
548
|
+
? parsed.suggested_args
|
|
549
|
+
: {};
|
|
550
|
+
return { tool, args };
|
|
551
|
+
}
|
|
552
|
+
//# sourceMappingURL=action-plan.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"action-plan.js","sourceRoot":"","sources":["../../../src/ui/agent/action-plan.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAkB,MAAM,aAAa,CAAC;AAC9D,OAAO,EAAE,8BAA8B,EAAE,MAAM,uBAAuB,CAAC;AACvE,OAAO,EAAE,MAAM,EAAE,UAAU,EAA8C,MAAM,IAAI,CAAC;AACpF,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,4BAA4B,EAAE,MAAM,2BAA2B,CAAC;AAGzE,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClE,OAAO,EACL,WAAW,EACX,cAAc,EACd,iBAAiB,EACjB,mBAAmB,EACnB,kBAAkB,GAMnB,MAAM,aAAa,CAAC;AAgBrB,MAAM,SAAS,GAAG,EAAE,CAAC;AACrB,MAAM,WAAW,GAAG,CAAC,CAAC;AACtB,MAAM,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C;IACP,IAAI,CAAC,IAAI;QAAE,OAAO,IAAI,CAAC;IAEvB,MAAM,IAAI,GACR,MAAM,CAAC,cAAc,IAAI,OAAO,MAAM,CAAC,cAAc,KAAK,QAAQ,IAAI,MAAM,CAAC,cAAc,KAAK,IAAI;QAClG,CAAC,CAAE,MAAM,CAAC,cAA0C;QACpD,CAAC,CAAC,EAAE,CAAC;IAET,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;AACxB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api-key.d.ts","sourceRoot":"","sources":["../../../src/ui/agent/api-key.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAChE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,IAAI,CAAC;AAGvC,OAAO,
|
|
1
|
+
{"version":3,"file":"api-key.d.ts","sourceRoot":"","sources":["../../../src/ui/agent/api-key.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAChE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,IAAI,CAAC;AAGvC,OAAO,EAIL,KAAK,eAAe,EACpB,KAAK,iBAAiB,EACtB,KAAK,kBAAkB,EAExB,MAAM,aAAa,CAAC;AAErB,MAAM,WAAW,uBAAuB;IACtC,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,YAAY,EAAE,CAAC;IACxB,QAAQ,EAAE,eAAe,CAAC;IAC1B,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,UAAU,CAAC,EAAE,UAAU,CAAC;IACxB,YAAY,EAAE,MAAM,CAAC;IACrB,WAAW,EAAE,WAAW,CAAC;IACzB,iBAAiB,CAAC,EAAE,CAAC,GAAG,EAAE,eAAe,KAAK,IAAI,CAAC;IACnD,QAAQ,CAAC,EAAE,CAAC,IAAI,EAAE,iBAAiB,KAAK,IAAI,CAAC;CAC9C;AAED,wBAAuB,gBAAgB,CACrC,IAAI,EAAE,uBAAuB,GAC5B,cAAc,CAAC,kBAAkB,CAAC,CA6HpC"}
|
package/dist/ui/agent/api-key.js
CHANGED
|
@@ -3,7 +3,7 @@ import { Experimental_StdioMCPTransport } from '@ai-sdk/mcp/mcp-stdio';
|
|
|
3
3
|
import { stepCountIs, streamText } from 'ai';
|
|
4
4
|
import { buildSpawnArgs, sanitizedEnv } from './mcp-transport.js';
|
|
5
5
|
import { PHOTOSHOP_EXPORT_CHAT_ID_ENV } from '../../lib/export-paths.js';
|
|
6
|
-
import { computeCost, stringifyToolOutput, } from './shared.js';
|
|
6
|
+
import { computeCost, isToolOutputOk, stringifyToolOutput, } from './shared.js';
|
|
7
7
|
export async function* runChatViaApiKey(opts) {
|
|
8
8
|
let mcp;
|
|
9
9
|
const buffer = { text: '', toolCalls: [] };
|
|
@@ -39,6 +39,17 @@ export async function* runChatViaApiKey(opts) {
|
|
|
39
39
|
opts.onAssistantBuffer?.(buffer);
|
|
40
40
|
break;
|
|
41
41
|
}
|
|
42
|
+
case 'reasoning-delta': {
|
|
43
|
+
buffer.reasoning = (buffer.reasoning ?? '') + part.text;
|
|
44
|
+
yield { type: 'reasoning-delta', payload: { text: part.text } };
|
|
45
|
+
opts.onAssistantBuffer?.(buffer);
|
|
46
|
+
break;
|
|
47
|
+
}
|
|
48
|
+
case 'start-step': {
|
|
49
|
+
const activity = { phase: 'thinking' };
|
|
50
|
+
yield { type: 'activity', payload: activity };
|
|
51
|
+
break;
|
|
52
|
+
}
|
|
42
53
|
case 'tool-call': {
|
|
43
54
|
const tc = {
|
|
44
55
|
id: part.toolCallId,
|
|
@@ -51,20 +62,26 @@ export async function* runChatViaApiKey(opts) {
|
|
|
51
62
|
type: 'tool-call',
|
|
52
63
|
payload: { id: tc.id, name: tc.name, input: tc.input },
|
|
53
64
|
};
|
|
65
|
+
yield {
|
|
66
|
+
type: 'activity',
|
|
67
|
+
payload: { phase: 'tool-running', detail: part.toolName },
|
|
68
|
+
};
|
|
54
69
|
opts.onAssistantBuffer?.(buffer);
|
|
55
70
|
break;
|
|
56
71
|
}
|
|
57
72
|
case 'tool-result': {
|
|
58
73
|
const tc = buffer.toolCalls.find((c) => c.id === part.toolCallId);
|
|
59
74
|
const text = stringifyToolOutput(part.output);
|
|
75
|
+
const ok = isToolOutputOk(part.output);
|
|
60
76
|
if (tc) {
|
|
61
|
-
tc.result = { ok
|
|
62
|
-
tc.status = 'success';
|
|
77
|
+
tc.result = { ok, content: text };
|
|
78
|
+
tc.status = ok ? 'success' : 'error';
|
|
63
79
|
}
|
|
64
80
|
yield {
|
|
65
81
|
type: 'tool-result',
|
|
66
|
-
payload: { id: part.toolCallId, ok
|
|
82
|
+
payload: { id: part.toolCallId, ok, content: text },
|
|
67
83
|
};
|
|
84
|
+
yield { type: 'activity', payload: { phase: 'thinking' } };
|
|
68
85
|
opts.onAssistantBuffer?.(buffer);
|
|
69
86
|
break;
|
|
70
87
|
}
|
|
@@ -79,6 +96,7 @@ export async function* runChatViaApiKey(opts) {
|
|
|
79
96
|
type: 'tool-result',
|
|
80
97
|
payload: { id: part.toolCallId, ok: false, content: text },
|
|
81
98
|
};
|
|
99
|
+
yield { type: 'activity', payload: { phase: 'thinking' } };
|
|
82
100
|
opts.onAssistantBuffer?.(buffer);
|
|
83
101
|
break;
|
|
84
102
|
}
|