@builder.io/ai-utils 0.95.0 → 0.97.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": "@builder.io/ai-utils",
3
- "version": "0.95.0",
3
+ "version": "0.97.0",
4
4
  "description": "Builder.io AI utils",
5
5
  "files": [
6
6
  "src"
@@ -12,11 +12,34 @@ export interface InvestigationCompletionJSON {
12
12
  messages?: MessageParam[];
13
13
  }
14
14
  export declare function serializeContentToBlocks(message: string | ContentMessage | undefined): string;
15
+ export declare function serializeMessage(message: MessageParam): string;
15
16
  export declare function messagesToText(messages: MessageParam[]): string;
16
17
  export declare function truncateToolResultsInTranscript(text: string): string;
18
+ export interface InvestigationTimelineEntry {
19
+ id: string;
20
+ timestampMs?: number;
21
+ role?: string;
22
+ message?: string;
23
+ hasError?: boolean;
24
+ }
17
25
  export interface BuildInvestigationSystemPromptInput {
18
26
  event: InvestigationEvent;
19
27
  completionJson: InvestigationCompletionJSON | undefined;
28
+ timeline?: InvestigationTimelineEntry[];
29
+ }
30
+ export declare function buildInvestigationSystemPrompt({ event, completionJson, timeline, }: BuildInvestigationSystemPromptInput): string;
31
+ export interface InvestigationSessionTurn {
32
+ id: string;
33
+ timestampMs?: number;
34
+ hasError?: boolean;
35
+ completionJson?: InvestigationCompletionJSON;
36
+ }
37
+ export interface BuildSessionInvestigationSystemPromptInput {
38
+ focusEvent: InvestigationEvent;
39
+ focusCompletionJson: InvestigationCompletionJSON | undefined;
40
+ turns: InvestigationSessionTurn[];
41
+ timeline?: InvestigationTimelineEntry[];
20
42
  }
21
- export declare function buildInvestigationSystemPrompt({ event, completionJson, }: BuildInvestigationSystemPromptInput): string;
43
+ export declare function buildSessionInvestigationSystemPrompt({ focusEvent, focusCompletionJson, turns, timeline, }: BuildSessionInvestigationSystemPromptInput): string;
22
44
  export declare const SUGGESTED_QUESTIONS: readonly string[];
45
+ export declare const SESSION_SUGGESTED_QUESTIONS: readonly string[];
@@ -48,13 +48,12 @@ export function serializeContentToBlocks(message) {
48
48
  })
49
49
  .join("\n\n");
50
50
  }
51
+ export function serializeMessage(message) {
52
+ const content = serializeContentToBlocks(message.content);
53
+ return `<___llm_message___ role=${JSON.stringify(message.role)}>\n${content}\n</___llm_message___>`;
54
+ }
51
55
  export function messagesToText(messages) {
52
- return messages
53
- .map((message) => {
54
- const content = serializeContentToBlocks(message.content);
55
- return `<___llm_message___ role=${JSON.stringify(message.role)}>\n${content}\n</___llm_message___>`;
56
- })
57
- .join("\n\n");
56
+ return messages.map(serializeMessage).join("\n\n");
58
57
  }
59
58
  export function truncateToolResultsInTranscript(text) {
60
59
  // Truncate any oversized tool_result block content so a single huge tool
@@ -110,33 +109,139 @@ export function truncateToolResultsInTranscript(text) {
110
109
  }
111
110
  return result;
112
111
  }
113
- export function buildInvestigationSystemPrompt({ event, completionJson, }) {
112
+ // Oldest-first; entries without a timestamp keep their relative order at the end.
113
+ function byTimestampAsc(entries) {
114
+ return [...entries].sort((a, b) => { var _a, _b; return ((_a = a.timestampMs) !== null && _a !== void 0 ? _a : Infinity) - ((_b = b.timestampMs) !== null && _b !== void 0 ? _b : Infinity); });
115
+ }
116
+ function buildTimelineBlock(timeline, currentEventId) {
117
+ if (!(timeline === null || timeline === void 0 ? void 0 : timeline.length))
118
+ return "";
119
+ const MESSAGE_PREVIEW_CHARS = 200;
120
+ const lines = byTimestampAsc(timeline).map((entry, index) => {
121
+ var _a;
122
+ const when = entry.timestampMs != null && Number.isFinite(entry.timestampMs)
123
+ ? new Date(entry.timestampMs).toISOString()
124
+ : "(no timestamp)";
125
+ const role = entry.role ? `[${entry.role}]` : "[?]";
126
+ const marker = entry.id === currentEventId ? " ▶" : "";
127
+ const error = entry.hasError ? " (error)" : "";
128
+ const flat = ((_a = entry.message) !== null && _a !== void 0 ? _a : "").replace(/\s+/g, " ").trim();
129
+ const preview = flat.length > MESSAGE_PREVIEW_CHARS
130
+ ? `${flat.slice(0, MESSAGE_PREVIEW_CHARS)}…`
131
+ : flat;
132
+ return `${index + 1}. ${when} ${role}${marker}${error} ${JSON.stringify(preview)}`;
133
+ });
134
+ return `## Session timeline (turn timestamps)\n\nEach line is one turn in this session — the same list shown on the left of the UI — oldest first, timestamps in UTC (ISO 8601). The event under investigation is marked ▶.\n\n${lines.join("\n")}`;
135
+ }
136
+ export function buildInvestigationSystemPrompt({ event, completionJson, timeline, }) {
114
137
  var _a, _b;
115
138
  const role = `You are a senior AI engineer helping debug a single codegen agent call.
116
139
  You have exactly the same context the engineer sees on the LLM tab for this
117
140
  event: the system prompt and the message transcript (with tool_use,
118
- tool_result, and thinking blocks). Be concise, specific, and critical.
141
+ tool_result, and thinking blocks), plus a session timeline giving the
142
+ timestamp of every turn. Be concise, specific, and critical.
119
143
 
120
144
  Ground every answer in the concrete data below: cite specific tool calls
121
- (by name + id), specific messages (by role + index), or system prompt
122
- sections. When you suggest improvements, propose concrete changes (e.g.
123
- "remove tool X", "add this instruction", "split this prompt section"). If
124
- the data does not support a claim, say so.`;
145
+ (by name + id), specific messages (by role + index), timeline entries (by
146
+ timestamp), or system prompt sections. When you suggest improvements, propose
147
+ concrete changes (e.g. "remove tool X", "add this instruction", "split this
148
+ prompt section"). If the data does not support a claim, say so.`;
125
149
  const header = `## Event\n\nid: ${event.id}\nmodel: ${(_a = completionJson === null || completionJson === void 0 ? void 0 : completionJson.model) !== null && _a !== void 0 ? _a : "(unknown)"}${event.hasError ? "\nstatus: ERROR" : ""}`;
150
+ const timelineBlock = buildTimelineBlock(timeline, event.id);
126
151
  // Use XML-style delimiters instead of triple-backtick fences: codegen
127
152
  // transcripts often contain markdown code fences themselves which would
128
153
  // otherwise close the outer block and corrupt the prompt.
129
154
  const systemPromptBlock = `## System prompt (verbatim)\n\n<___event_system_prompt___>\n${truncate((_b = completionJson === null || completionJson === void 0 ? void 0 : completionJson.systemPrompt) !== null && _b !== void 0 ? _b : "(no system prompt)", MAX_SYSTEM_PROMPT_CHARS)}\n</___event_system_prompt___>`;
155
+ // Debugging a long session needs the whole transcript verbatim, so this is
156
+ // sent in full — no per-tool-result or overall transcript truncation.
130
157
  const transcriptText = (completionJson === null || completionJson === void 0 ? void 0 : completionJson.messages)
131
- ? truncateToolResultsInTranscript(messagesToText(completionJson.messages))
158
+ ? messagesToText(completionJson.messages)
132
159
  : "(no messages)";
133
- const transcriptBlock = `## Message transcript (tool_use / tool_result / thinking)\n\n<___event_transcript___>\n${truncate(transcriptText, MAX_TRANSCRIPT_CHARS)}\n</___event_transcript___>`;
160
+ const transcriptBlock = `## Message transcript (tool_use / tool_result / thinking)\n\n<___event_transcript___>\n${transcriptText}\n</___event_transcript___>`;
134
161
  const guidance = `## How to answer
135
162
 
136
163
  - Start with a 1-2 sentence direct answer.
137
164
  - Back it up with specific evidence (tool names, message indices, prompt phrases).
138
165
  - End with concrete improvement suggestions when applicable.`;
139
- return [role, header, systemPromptBlock, transcriptBlock, guidance].join("\n\n");
166
+ return [
167
+ role,
168
+ header,
169
+ timelineBlock,
170
+ systemPromptBlock,
171
+ transcriptBlock,
172
+ guidance,
173
+ ]
174
+ .filter(Boolean)
175
+ .join("\n\n");
176
+ }
177
+ export function buildSessionInvestigationSystemPrompt({ focusEvent, focusCompletionJson, turns, timeline, }) {
178
+ var _a;
179
+ const role = `You are a senior AI engineer helping debug an entire codegen session:
180
+ a sequence of agent calls (turns). You have the same context the engineer sees
181
+ in the UI — a timeline of every turn with timestamps, and the message
182
+ transcript of the session (with tool_use, tool_result, and thinking blocks).
183
+ Because each turn re-sends the whole prior conversation, each turn below shows
184
+ only the messages it added; earlier messages it carried over are counted, not
185
+ repeated. Be concise, specific, and critical.
186
+
187
+ Ground every answer in the concrete data below: cite specific turns (by event
188
+ id or timestamp), tool calls (by name + id), or messages. Reason about how the
189
+ session evolved across turns — what changed, what regressed, and where. If the
190
+ data does not support a claim, say so.`;
191
+ const header = `## Session\n\nturns: ${turns.length}\nfocus turn (currently selected in UI): ${focusEvent.id}`;
192
+ const timelineBlock = buildTimelineBlock(timeline, focusEvent.id);
193
+ // Per-turn system prompts are largely shared within a session; include the
194
+ // focus turn's verbatim and point elsewhere for exact per-turn prompts.
195
+ const systemPromptBlock = `## System prompt (verbatim — from focus turn ${focusEvent.id}; other turns may differ)\n\n<___event_system_prompt___>\n${truncate((_a = focusCompletionJson === null || focusCompletionJson === void 0 ? void 0 : focusCompletionJson.systemPrompt) !== null && _a !== void 0 ? _a : "(no system prompt)", MAX_SYSTEM_PROMPT_CHARS)}\n</___event_system_prompt___>`;
196
+ // Each turn re-sends the whole prior conversation, so a turn's messages are
197
+ // a growing prefix of the next. Emit only the messages a turn adds beyond the
198
+ // previous one, so every message appears once instead of O(turns) times.
199
+ let prevSerialized = [];
200
+ const turnBlocks = byTimestampAsc(turns)
201
+ .map((turn, index) => {
202
+ var _a, _b;
203
+ var _c;
204
+ const when = turn.timestampMs != null && Number.isFinite(turn.timestampMs)
205
+ ? new Date(turn.timestampMs).toISOString()
206
+ : "(no timestamp)";
207
+ const model = (_c = (_a = turn.completionJson) === null || _a === void 0 ? void 0 : _a.model) !== null && _c !== void 0 ? _c : "(unknown)";
208
+ const status = turn.hasError ? ' status="ERROR"' : "";
209
+ const focus = turn.id === focusEvent.id ? ' focus="true"' : "";
210
+ if (!((_b = turn.completionJson) === null || _b === void 0 ? void 0 : _b.messages)) {
211
+ return `<___session_turn___ index="${index + 1}" event_id="${turn.id}" ts="${when}" model="${model}"${status}${focus}>\n(transcript not loaded)\n</___session_turn___>`;
212
+ }
213
+ const serialized = turn.completionJson.messages.map(serializeMessage);
214
+ let common = 0;
215
+ while (common < serialized.length &&
216
+ common < prevSerialized.length &&
217
+ serialized[common] === prevSerialized[common]) {
218
+ common++;
219
+ }
220
+ prevSerialized = serialized;
221
+ const added = serialized.slice(common);
222
+ const body = added.length
223
+ ? added.join("\n\n")
224
+ : "(no new messages beyond the previous turn)";
225
+ const carried = common > 0 ? ` carried_over_messages="${common}"` : "";
226
+ return `<___session_turn___ index="${index + 1}" event_id="${turn.id}" ts="${when}" model="${model}"${status}${focus}${carried}>\n${body}\n</___session_turn___>`;
227
+ })
228
+ .join("\n\n");
229
+ const transcriptBlock = `## Message transcripts (one block per turn, oldest first)\n\nEach turn re-sends the full prior conversation, so only the messages a turn adds are shown; \`carried_over_messages\` counts identical earlier messages omitted from that turn.\n\n${turnBlocks}`;
230
+ const guidance = `## How to answer
231
+
232
+ - Start with a 1-2 sentence direct answer.
233
+ - Back it up with specific evidence (turn ids/timestamps, tool names, message indices).
234
+ - End with concrete improvement suggestions when applicable.`;
235
+ return [
236
+ role,
237
+ header,
238
+ timelineBlock,
239
+ systemPromptBlock,
240
+ transcriptBlock,
241
+ guidance,
242
+ ]
243
+ .filter(Boolean)
244
+ .join("\n\n");
140
245
  }
141
246
  export const SUGGESTED_QUESTIONS = [
142
247
  "Why did this call fail or behave suboptimally?",
@@ -145,3 +250,10 @@ export const SUGGESTED_QUESTIONS = [
145
250
  "How could the system prompt be improved for this case?",
146
251
  "Walk me through the agent's reasoning step by step.",
147
252
  ];
253
+ export const SESSION_SUGGESTED_QUESTIONS = [
254
+ "Summarize what happened across this whole session.",
255
+ "Where did the session go wrong, and at which turn?",
256
+ "What did the user keep asking for that wasn't delivered?",
257
+ "Which turns were redundant or repeated work?",
258
+ "How did the agent's approach change over time?",
259
+ ];
package/src/codegen.d.ts CHANGED
@@ -384,6 +384,18 @@ export declare const GetScreenshotToolInputSchema: z.ZodObject<{
384
384
  height: z.ZodOptional<z.ZodNumber>;
385
385
  }, z.core.$strip>;
386
386
  export type GetScreenshotToolInput = z.infer<typeof GetScreenshotToolInputSchema>;
387
+ export declare const JudgeCommandSafetyInputSchema: z.ZodObject<{
388
+ command: z.ZodString;
389
+ }, z.core.$strip>;
390
+ export type JudgeCommandSafetyInput = z.infer<typeof JudgeCommandSafetyInputSchema>;
391
+ export declare const JudgeCommandSafetyResultSchema: z.ZodObject<{
392
+ verdict: z.ZodEnum<{
393
+ destructive: "destructive";
394
+ safe: "safe";
395
+ }>;
396
+ reason: z.ZodOptional<z.ZodString>;
397
+ }, z.core.$strip>;
398
+ export type JudgeCommandSafetyResult = z.infer<typeof JudgeCommandSafetyResultSchema>;
387
399
  export declare const NavigatePreviewToolInputSchema: z.ZodObject<{
388
400
  href: z.ZodString;
389
401
  }, z.core.$strip>;
@@ -2107,7 +2119,7 @@ export declare const DEFAULT_QUEUE_BEHAVIOR: QueueBehavior;
2107
2119
  /** True for any schedule that aborts the in-flight run on enqueue. */
2108
2120
  export declare function isInterruptSchedule(schedule: QueueSchedule): boolean;
2109
2121
  export declare function normalizeQueueMode(mode: QueueMode | undefined): QueueBehavior;
2110
- export declare const BASE_CODEGEN_POSITIONS: readonly ["fusion", "editor-ai", "repo-indexing", "cli", "create-app-firebase", "create-app-lovable", "builder-code-panel", "setup-project", "code-review-orchestrator", "project-configuration", "org-agent", "org-worker", "browser-testing", "projects-scheduler-memory-extraction", "builder-code", "unknown", "dsi-mcp", "design-system-indexer", "builder-publish-integration"];
2122
+ export declare const BASE_CODEGEN_POSITIONS: readonly ["fusion", "editor-ai", "repo-indexing", "cli", "create-app-firebase", "create-app-lovable", "builder-code-panel", "setup-project", "code-review-orchestrator", "project-configuration", "org-agent", "org-worker", "browser-testing", "projects-scheduler-memory-extraction", "builder-code", "unknown", "dsi-mcp", "design-system-indexer", "builder-publish-integration", "publish-agent"];
2111
2123
  export type BaseCodeGenPosition = (typeof BASE_CODEGEN_POSITIONS)[number];
2112
2124
  export declare const BaseCodeGenPositionSchema: z.ZodEnum<{
2113
2125
  "browser-testing": "browser-testing";
@@ -2126,6 +2138,7 @@ export declare const BaseCodeGenPositionSchema: z.ZodEnum<{
2126
2138
  "org-worker": "org-worker";
2127
2139
  "project-configuration": "project-configuration";
2128
2140
  "projects-scheduler-memory-extraction": "projects-scheduler-memory-extraction";
2141
+ "publish-agent": "publish-agent";
2129
2142
  "repo-indexing": "repo-indexing";
2130
2143
  "setup-project": "setup-project";
2131
2144
  unknown: "unknown";
@@ -2147,11 +2160,97 @@ export declare const CodeGenPositionSchema: z.ZodUnion<readonly [z.ZodEnum<{
2147
2160
  "org-worker": "org-worker";
2148
2161
  "project-configuration": "project-configuration";
2149
2162
  "projects-scheduler-memory-extraction": "projects-scheduler-memory-extraction";
2163
+ "publish-agent": "publish-agent";
2150
2164
  "repo-indexing": "repo-indexing";
2151
2165
  "setup-project": "setup-project";
2152
2166
  unknown: "unknown";
2153
- }>, z.ZodTemplateLiteral<"browser-testing-agent" | "builder-code-agent" | "builder-code-panel-agent" | "builder-publish-integration-agent" | "cli-agent" | "code-review-orchestrator-agent" | "create-app-firebase-agent" | "create-app-lovable-agent" | "design-system-indexer-agent" | "dsi-mcp-agent" | "editor-ai-agent" | "fusion-agent" | "org-agent-agent" | "org-worker-agent" | "project-configuration-agent" | "projects-scheduler-memory-extraction-agent" | "repo-indexing-agent" | "setup-project-agent" | "unknown-agent">]>;
2167
+ }>, z.ZodTemplateLiteral<"browser-testing-agent" | "builder-code-agent" | "builder-code-panel-agent" | "builder-publish-integration-agent" | "cli-agent" | "code-review-orchestrator-agent" | "create-app-firebase-agent" | "create-app-lovable-agent" | "design-system-indexer-agent" | "dsi-mcp-agent" | "editor-ai-agent" | "fusion-agent" | "org-agent-agent" | "org-worker-agent" | "project-configuration-agent" | "projects-scheduler-memory-extraction-agent" | "publish-agent-agent" | "repo-indexing-agent" | "setup-project-agent" | "unknown-agent">]>;
2154
2168
  export type CodeGenPosition = z.infer<typeof CodeGenPositionSchema>;
2169
+ export declare const PublishAgentMessageRequestSchema: z.ZodObject<{
2170
+ message: z.ZodOptional<z.ZodString>;
2171
+ sessionId: z.ZodOptional<z.ZodString>;
2172
+ toolResults: z.ZodOptional<z.ZodArray<z.ZodObject<{
2173
+ type: z.ZodLiteral<"tool_result">;
2174
+ tool_use_id: z.ZodString;
2175
+ tool_name: z.ZodOptional<z.ZodString>;
2176
+ tool_input: z.ZodOptional<z.ZodString>;
2177
+ title: z.ZodOptional<z.ZodString>;
2178
+ content: z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
2179
+ type: z.ZodLiteral<"text">;
2180
+ text: z.ZodString;
2181
+ cache: z.ZodOptional<z.ZodBoolean>;
2182
+ citations: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
2183
+ cited_text: z.ZodString;
2184
+ document_index: z.ZodNumber;
2185
+ document_title: z.ZodNullable<z.ZodString>;
2186
+ end_char_index: z.ZodNumber;
2187
+ start_char_index: z.ZodNumber;
2188
+ type: z.ZodLiteral<"char_location">;
2189
+ }, z.core.$strip>, z.ZodObject<{
2190
+ cited_text: z.ZodString;
2191
+ document_index: z.ZodNumber;
2192
+ document_title: z.ZodNullable<z.ZodString>;
2193
+ end_page_number: z.ZodNumber;
2194
+ start_page_number: z.ZodNumber;
2195
+ type: z.ZodLiteral<"page_location">;
2196
+ }, z.core.$strip>, z.ZodObject<{
2197
+ cited_text: z.ZodString;
2198
+ document_index: z.ZodNumber;
2199
+ document_title: z.ZodNullable<z.ZodString>;
2200
+ end_block_index: z.ZodNumber;
2201
+ start_block_index: z.ZodNumber;
2202
+ type: z.ZodLiteral<"content_block_location">;
2203
+ }, z.core.$strip>, z.ZodObject<{
2204
+ cited_text: z.ZodString;
2205
+ encrypted_index: z.ZodString;
2206
+ title: z.ZodNullable<z.ZodString>;
2207
+ type: z.ZodLiteral<"web_search_result_location">;
2208
+ url: z.ZodString;
2209
+ }, z.core.$strip>], "type">>>>;
2210
+ ephemeral: z.ZodOptional<z.ZodBoolean>;
2211
+ thoughtSignature: z.ZodOptional<z.ZodString>;
2212
+ tag: z.ZodOptional<z.ZodString>;
2213
+ }, z.core.$strip>, z.ZodObject<{
2214
+ type: z.ZodLiteral<"image">;
2215
+ source: z.ZodDiscriminatedUnion<[z.ZodObject<{
2216
+ type: z.ZodLiteral<"base64">;
2217
+ media_type: z.ZodEnum<{
2218
+ "image/gif": "image/gif";
2219
+ "image/jpeg": "image/jpeg";
2220
+ "image/png": "image/png";
2221
+ "image/webp": "image/webp";
2222
+ }>;
2223
+ data: z.ZodString;
2224
+ original_url: z.ZodOptional<z.ZodString>;
2225
+ }, z.core.$strip>, z.ZodObject<{
2226
+ type: z.ZodLiteral<"url">;
2227
+ url: z.ZodString;
2228
+ }, z.core.$strip>], "type">;
2229
+ cache: z.ZodOptional<z.ZodBoolean>;
2230
+ ephemeral: z.ZodOptional<z.ZodBoolean>;
2231
+ }, z.core.$strip>, z.ZodObject<{
2232
+ type: z.ZodLiteral<"resource">;
2233
+ resource: z.ZodObject<{
2234
+ uri: z.ZodString;
2235
+ mimeType: z.ZodOptional<z.ZodString>;
2236
+ text: z.ZodOptional<z.ZodString>;
2237
+ blob: z.ZodOptional<z.ZodString>;
2238
+ }, z.core.$strip>;
2239
+ }, z.core.$strip>], "type">>]>;
2240
+ is_error: z.ZodOptional<z.ZodBoolean>;
2241
+ cache: z.ZodOptional<z.ZodBoolean>;
2242
+ ephemeral: z.ZodOptional<z.ZodBoolean>;
2243
+ structured_result: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
2244
+ }, z.core.$strip>>>;
2245
+ confirmation: z.ZodOptional<z.ZodObject<{
2246
+ actionId: z.ZodString;
2247
+ decision: z.ZodEnum<{
2248
+ approve: "approve";
2249
+ reject: "reject";
2250
+ }>;
2251
+ }, z.core.$strip>>;
2252
+ }, z.core.$strip>;
2253
+ export type PublishAgentMessageRequest = z.infer<typeof PublishAgentMessageRequestSchema>;
2155
2254
  export declare const RepoIndexingConfigSchema: z.ZodObject<{
2156
2255
  designSystems: z.ZodArray<z.ZodString>;
2157
2256
  }, z.core.$strip>;
@@ -2422,10 +2521,11 @@ export declare const CodeGenInputOptionsSchema: z.ZodObject<{
2422
2521
  "org-worker": "org-worker";
2423
2522
  "project-configuration": "project-configuration";
2424
2523
  "projects-scheduler-memory-extraction": "projects-scheduler-memory-extraction";
2524
+ "publish-agent": "publish-agent";
2425
2525
  "repo-indexing": "repo-indexing";
2426
2526
  "setup-project": "setup-project";
2427
2527
  unknown: "unknown";
2428
- }>, z.ZodTemplateLiteral<"browser-testing-agent" | "builder-code-agent" | "builder-code-panel-agent" | "builder-publish-integration-agent" | "cli-agent" | "code-review-orchestrator-agent" | "create-app-firebase-agent" | "create-app-lovable-agent" | "design-system-indexer-agent" | "dsi-mcp-agent" | "editor-ai-agent" | "fusion-agent" | "org-agent-agent" | "org-worker-agent" | "project-configuration-agent" | "projects-scheduler-memory-extraction-agent" | "repo-indexing-agent" | "setup-project-agent" | "unknown-agent">]>;
2528
+ }>, z.ZodTemplateLiteral<"browser-testing-agent" | "builder-code-agent" | "builder-code-panel-agent" | "builder-publish-integration-agent" | "cli-agent" | "code-review-orchestrator-agent" | "create-app-firebase-agent" | "create-app-lovable-agent" | "design-system-indexer-agent" | "dsi-mcp-agent" | "editor-ai-agent" | "fusion-agent" | "org-agent-agent" | "org-worker-agent" | "project-configuration-agent" | "projects-scheduler-memory-extraction-agent" | "publish-agent-agent" | "repo-indexing-agent" | "setup-project-agent" | "unknown-agent">]>;
2429
2529
  eventName: z.ZodOptional<z.ZodString>;
2430
2530
  sessionId: z.ZodString;
2431
2531
  codeGenMode: z.ZodOptional<z.ZodEnum<{
@@ -2606,6 +2706,7 @@ export declare const CodeGenInputOptionsSchema: z.ZodObject<{
2606
2706
  v1: "v1";
2607
2707
  v2: "v2";
2608
2708
  v3: "v3";
2709
+ v4: "v4";
2609
2710
  }>>;
2610
2711
  reasoning: z.ZodOptional<z.ZodEnum<{
2611
2712
  auto: "auto";
@@ -3472,10 +3573,11 @@ export declare const CustomAgentDefinitionSchema: z.ZodObject<{
3472
3573
  "org-worker": "org-worker";
3473
3574
  "project-configuration": "project-configuration";
3474
3575
  "projects-scheduler-memory-extraction": "projects-scheduler-memory-extraction";
3576
+ "publish-agent": "publish-agent";
3475
3577
  "repo-indexing": "repo-indexing";
3476
3578
  "setup-project": "setup-project";
3477
3579
  unknown: "unknown";
3478
- }>, z.ZodTemplateLiteral<"browser-testing-agent" | "builder-code-agent" | "builder-code-panel-agent" | "builder-publish-integration-agent" | "cli-agent" | "code-review-orchestrator-agent" | "create-app-firebase-agent" | "create-app-lovable-agent" | "design-system-indexer-agent" | "dsi-mcp-agent" | "editor-ai-agent" | "fusion-agent" | "org-agent-agent" | "org-worker-agent" | "project-configuration-agent" | "projects-scheduler-memory-extraction-agent" | "repo-indexing-agent" | "setup-project-agent" | "unknown-agent">]>>;
3580
+ }>, z.ZodTemplateLiteral<"browser-testing-agent" | "builder-code-agent" | "builder-code-panel-agent" | "builder-publish-integration-agent" | "cli-agent" | "code-review-orchestrator-agent" | "create-app-firebase-agent" | "create-app-lovable-agent" | "design-system-indexer-agent" | "dsi-mcp-agent" | "editor-ai-agent" | "fusion-agent" | "org-agent-agent" | "org-worker-agent" | "project-configuration-agent" | "projects-scheduler-memory-extraction-agent" | "publish-agent-agent" | "repo-indexing-agent" | "setup-project-agent" | "unknown-agent">]>>;
3479
3581
  needDevServer: z.ZodOptional<z.ZodBoolean>;
3480
3582
  needValidation: z.ZodOptional<z.ZodBoolean>;
3481
3583
  includeMemories: z.ZodOptional<z.ZodBoolean>;
@@ -4348,6 +4450,12 @@ export interface FusionConfig {
4348
4450
  /** PR number for fork PRs - used for fetching refs/pulls/x/head */
4349
4451
  prNumber?: number;
4350
4452
  refreshPreview?: boolean;
4453
+ /**
4454
+ * Keep the session's commits when HEAD has drifted off `aiBranch`: move the
4455
+ * AI branch to HEAD rather than checking out onto it, and repair the same
4456
+ * drift at backup time instead of refusing to back up.
4457
+ */
4458
+ preserveWorkOnBranchDrift?: boolean;
4351
4459
  workingDirectory?: string;
4352
4460
  bashWorkingDirectory?: string;
4353
4461
  workspace?: WorkspaceConfiguration;
@@ -4468,6 +4576,14 @@ export interface FusionConfig {
4468
4576
  * This is a dangerous setting that removes safety guardrails - equivalent to full shell access.
4469
4577
  */
4470
4578
  skipCommandSecurity?: boolean;
4579
+ /**
4580
+ * LaunchDarkly `command-safety-judge-enabled` flag, resolved server-side at
4581
+ * session start and threaded down since the sandbox has no LaunchDarkly
4582
+ * access of its own. When true, `executeShellCommand` routes Tier 2
4583
+ * judgment-requiring commands to the `JudgeCommandSafety` endpoint instead
4584
+ * of hard-blocking them.
4585
+ */
4586
+ commandSafetyJudgeEnabled?: boolean;
4471
4587
  /** @deprecated use devCommand */
4472
4588
  command?: string;
4473
4589
  }
@@ -4824,6 +4940,7 @@ export interface SearchFileTreeResult {
4824
4940
  }
4825
4941
  export interface SetupCommandResult {
4826
4942
  code: number | null;
4943
+ signal?: string;
4827
4944
  output: string;
4828
4945
  capturedEnv?: Record<string, string>;
4829
4946
  }
@@ -4867,6 +4984,8 @@ export interface BuildCommandResultFailure {
4867
4984
  code?: number;
4868
4985
  signal?: string;
4869
4986
  output: string;
4987
+ /** Which step produced `output`. Absent means the build command itself. */
4988
+ phase?: "setup" | "build";
4870
4989
  }
4871
4990
  export interface ConfigureDevOrchestratorUpdates {
4872
4991
  devCommand: boolean;
@@ -5014,6 +5133,8 @@ export interface SessionData {
5014
5133
  repoHash: string | undefined;
5015
5134
  repoBranch: string | undefined;
5016
5135
  description?: string;
5136
+ /** Hidden from the session list, but still readable by id. Creator-set. */
5137
+ archived?: boolean;
5017
5138
  hasPlanToApply?: boolean;
5018
5139
  cost: number;
5019
5140
  /** Cost from tools (e.g. WebSearch LLM calls) and sub-agent roll-ups. Total session cost = cost + extraCost. */
package/src/codegen.js CHANGED
@@ -580,6 +580,26 @@ export const GetScreenshotToolInputSchema = z
580
580
  height: z.number().optional(),
581
581
  })
582
582
  .meta({ title: "GetScreenshotToolInput" });
583
+ export const JudgeCommandSafetyInputSchema = z
584
+ .object({
585
+ // Bounded so a caller can't force multi-megabyte payloads through this
586
+ // directly-callable, AI-credit-exempt endpoint into every completionLLM
587
+ // call — real shell commands are nowhere near this size.
588
+ command: z.string().max(20000).meta({
589
+ description: "The shell command to classify.",
590
+ }),
591
+ })
592
+ .meta({ title: "JudgeCommandSafetyInput" });
593
+ export const JudgeCommandSafetyResultSchema = z
594
+ .object({
595
+ verdict: z.enum(["safe", "destructive"]).meta({
596
+ description: "Whether the command is safe to run in this ephemeral, fully-writable sandbox, or destructive and should be denied.",
597
+ }),
598
+ reason: z.string().optional().meta({
599
+ description: "Required when verdict is destructive: a short, non-scary explanation shown to the user. Omit when safe.",
600
+ }),
601
+ })
602
+ .meta({ title: "JudgeCommandSafetyResult" });
583
603
  export const NavigatePreviewToolInputSchema = z
584
604
  .object({
585
605
  href: z.string().meta({
@@ -1746,6 +1766,7 @@ export const BASE_CODEGEN_POSITIONS = [
1746
1766
  "dsi-mcp",
1747
1767
  "design-system-indexer",
1748
1768
  "builder-publish-integration",
1769
+ "publish-agent",
1749
1770
  ];
1750
1771
  export const BaseCodeGenPositionSchema = z
1751
1772
  .enum(BASE_CODEGEN_POSITIONS)
@@ -1756,6 +1777,27 @@ export const CodeGenPositionSchema = z
1756
1777
  z.templateLiteral([BaseCodeGenPositionSchema, "-agent"]),
1757
1778
  ])
1758
1779
  .meta({ title: "CodeGenPosition" });
1780
+ export const PublishAgentMessageRequestSchema = z
1781
+ .object({
1782
+ message: z.string().max(100000).optional(),
1783
+ sessionId: z.string().min(1).max(256).optional(),
1784
+ toolResults: z.array(ContentMessageItemToolResultSchema).optional(),
1785
+ confirmation: z
1786
+ .object({
1787
+ actionId: z.string().min(1).max(256),
1788
+ decision: z.enum(["approve", "reject"]),
1789
+ })
1790
+ .optional(),
1791
+ })
1792
+ .refine(({ message, toolResults }) => Boolean(message) || Boolean(toolResults === null || toolResults === void 0 ? void 0 : toolResults.length), {
1793
+ path: ["message"],
1794
+ message: "A message or at least one tool result is required.",
1795
+ })
1796
+ .refine(({ message, sessionId }) => Boolean(message) || Boolean(sessionId), {
1797
+ path: ["sessionId"],
1798
+ message: "A session ID is required when continuing with tool results.",
1799
+ })
1800
+ .meta({ title: "PublishAgentMessageRequest" });
1759
1801
  export const RepoIndexingConfigSchema = z
1760
1802
  .object({
1761
1803
  designSystems: z.array(z.string()),
@@ -1940,7 +1982,7 @@ export const CodeGenInputOptionsSchema = z
1940
1982
  modelOverride: z.string().optional(),
1941
1983
  errorIfHadCompaction: z.boolean().optional(),
1942
1984
  softContextWindow: z.number().optional(),
1943
- promptVersion: z.enum(["v1", "v2", "v3"]).optional(),
1985
+ promptVersion: z.enum(["v1", "v2", "v3", "v4"]).optional(),
1944
1986
  reasoning: ReasoningEffortSchema.optional(),
1945
1987
  redactUserMessages: z.boolean().optional(),
1946
1988
  redactLLMMessages: z.boolean().optional(),
@@ -159,7 +159,7 @@ export const listSourceFilesQuerySchema = z.object({
159
159
  ref: z.string().optional(),
160
160
  });
161
161
  export const listPublicSourceFilesQuerySchema = z.object({
162
- /** Full repo URL (e.g. https://github.com/owner/repo). GitHub only. */
162
+ /** Full repo URL (e.g. https://github.com/owner/repo). Supported across all git providers. */
163
163
  repoUrl: z.string().url(),
164
164
  /** Directory to list, repo-relative. Empty/omitted → repo root. */
165
165
  path: z.string().optional(),
@@ -29,6 +29,7 @@ export declare const EditorAiEditRequestSchema: z.ZodObject<{
29
29
  components: z.ZodOptional<z.ZodArray<z.ZodObject<{
30
30
  name: z.ZodString;
31
31
  }, z.core.$loose>>>;
32
+ allowedComponentNames: z.ZodOptional<z.ZodArray<z.ZodString>>;
32
33
  }, z.core.$strip>;
33
34
  export type EditorAiEditRequest = z.infer<typeof EditorAiEditRequestSchema>;
34
35
  export declare const EditorAiEditResponseSchema: z.ZodObject<{
@@ -44,6 +45,7 @@ export declare const EditorAiWriteRequestSchema: z.ZodObject<{
44
45
  components: z.ZodOptional<z.ZodArray<z.ZodObject<{
45
46
  name: z.ZodString;
46
47
  }, z.core.$loose>>>;
48
+ allowedComponentNames: z.ZodOptional<z.ZodArray<z.ZodString>>;
47
49
  }, z.core.$strip>;
48
50
  export type EditorAiWriteRequest = z.infer<typeof EditorAiWriteRequestSchema>;
49
51
  export declare const EditorAiWriteResponseSchema: z.ZodObject<{
@@ -51,7 +53,7 @@ export declare const EditorAiWriteResponseSchema: z.ZodObject<{
51
53
  modifiedBuilderContent: z.ZodRecord<z.ZodString, z.ZodUnknown>;
52
54
  }, z.core.$strip>;
53
55
  export type EditorAiWriteResponse = z.infer<typeof EditorAiWriteResponseSchema>;
54
- export type EditorAiErrorCode = "BAD_REQUEST" | "UNAUTHORIZED" | "FORBIDDEN" | "NOT_FOUND" | "NO_MATCH" | "VALIDATION_FAILED" | "INTERNAL";
56
+ export type EditorAiErrorCode = "BAD_REQUEST" | "UNAUTHORIZED" | "FORBIDDEN" | "NOT_FOUND" | "NO_MATCH" | "VALIDATION_FAILED" | "COMPONENT_NOT_ALLOWED" | "INTERNAL";
55
57
  export declare const EditorAiErrorBodySchema: z.ZodObject<{
56
58
  error: z.ZodObject<{
57
59
  code: z.ZodString;
package/src/editor-ai.js CHANGED
@@ -13,6 +13,9 @@ export const EditorAiComponentSchema = z
13
13
  })
14
14
  .meta({ title: "EditorAiComponent" });
15
15
  const componentsField = z.array(EditorAiComponentSchema).optional();
16
+ // Omitted is unrestricted; empty forbids every component. Only components-only
17
+ // spaces send it.
18
+ const allowedComponentNamesField = z.array(z.string().min(1)).optional();
16
19
  export const EditorAiReadRequestSchema = z
17
20
  .object({
18
21
  contentId: z.string().min(1),
@@ -45,6 +48,7 @@ export const EditorAiEditRequestSchema = z
45
48
  // Locale to operate on; defaults to "Default" when omitted.
46
49
  activeLocale: z.string().min(1).optional(),
47
50
  components: componentsField,
51
+ allowedComponentNames: allowedComponentNamesField,
48
52
  })
49
53
  .meta({ title: "EditorAiEditRequest" });
50
54
  export const EditorAiEditResponseSchema = z
@@ -61,6 +65,7 @@ export const EditorAiWriteRequestSchema = z
61
65
  // Locale to operate on; defaults to "Default" when omitted.
62
66
  activeLocale: z.string().min(1).optional(),
63
67
  components: componentsField,
68
+ allowedComponentNames: allowedComponentNamesField,
64
69
  })
65
70
  .meta({ title: "EditorAiWriteRequest" });
66
71
  export const EditorAiWriteResponseSchema = z
package/src/events.d.ts CHANGED
@@ -4,6 +4,7 @@ import type { AssistantSettings } from "./settings.js";
4
4
  import type { ExitState, UserSource, CodeGenPosition, ReviewSeverity, ReviewVerdict } from "./codegen.js";
5
5
  import type { FileUpload } from "./messages.js";
6
6
  import type { BuilderConfigRealtime } from "./builder-config.js";
7
+ import type { DeployFailureReport } from "./projects.js";
7
8
  export type BuilderAssistantEventHandler = (ev: BuilderAssistantEvent) => void;
8
9
  export type BuilderAssistantEvent = AssistantCompletionResultEvent | AssistantErrorEvent | AssistantStreamErrorEvent | AppCloseEvent | AppMessagesClickEvent | AppMessagesGenerationEvent | AppMessageEditCustomInstructionsEvent | AppPromptAbortEvent | AppPromptFocusEvent | AppPromptSubmitEvent | AppReadyEvent | AppSettingsSetEvent | AppThreadNewEvent | AssistantStatsEvent | AssistantThemeEvent | BuilderEditorAuthEvent | BuilderEditorStateEvent | ContentUpdateEvent | ContentApplySnapshotEvent | ModelUndoEvent | ModelRedoEvent | ResultEvent | ThreadCreatedEvent | ThreadMessageCompletedEvent | ThreadMessageCreatedEvent | ThreadMessageDeltaEvent | ThreadMessageFeedbackEvent | ThreadRunStepCreatedEvent | ThreadRunStepDeltaEvent | AppAcceptChangeEvent | AppAcceptRejectEvent | AssistantTrackEvent | AssistantEditorAuthMessage | AppAttachmentTemplateEvent | AppPasteSmartExportEvent | ThreadMessageRetryEvent | AppFigmaImportEvent | AppWebImportEvent | AppMcpServersEvent | AssistantContentInitialEvent | ThreadMessageSummaryEvent | ThreadMessageSummaryCodegenDeltaEvent | ThreadMessageThinkingDeltaEvent | AssistantHeartbeatEvent | ShowUpgradeDialogEvent | AssistantFusionSuggestionEvent | AppNavigateToFusionEvent | ModelPermissionRequiredEvent | ModelPermissionResponseEvent;
9
10
  export interface AssistantCompletionResultEvent {
@@ -901,6 +902,13 @@ export type ProjectSnapshotRefreshV1 = FusionEventVariant<"project.snapshot.refr
901
902
  projectId: string;
902
903
  requestedBy: string;
903
904
  reason: string;
905
+ /**
906
+ * When set, the resulting VolumeSnapshot is labeled
907
+ * `fusion-golden-source=<id>` (a baked golden starter snapshot) in addition
908
+ * to the usual per-project labels. Only set for the golden-starter-snapshots
909
+ * producer.
910
+ */
911
+ goldenTemplateId?: string;
904
912
  }, {
905
913
  projectId: string;
906
914
  }, 1>;
@@ -982,9 +990,12 @@ export type ProjectSnapshotPodWatchV1 = FusionEventVariant<"project.snapshot.pod
982
990
  namespace: string;
983
991
  podName: string;
984
992
  source: "pr.merged" | "project.snapshot.refresh";
993
+ provider?: GitPrMergedV1["data"]["provider"];
985
994
  gitSha?: string;
986
995
  startedAtMs: number;
987
996
  timeoutMs: number;
997
+ /** Propagated to the golden starter snapshot's `fusion-golden-source` label. */
998
+ goldenTemplateId?: string;
988
999
  }, {
989
1000
  projectId: string;
990
1001
  }, 1>;
@@ -1283,6 +1294,13 @@ export type ClientDevtoolsBuildUploadedV1 = FusionEventVariant<"client.devtools.
1283
1294
  * falls back to reading the repo at the deployed commit.
1284
1295
  */
1285
1296
  realtimeTransport?: BuilderConfigRealtime["transport"];
1297
+ /**
1298
+ * What the pod's build env resolved each `HOSTED_DEPLOY_ENV_DEFAULTS` key to, so
1299
+ * the runtime env can agree with the artifact that was built — a build-scope opt-in
1300
+ * shouldn't emit a scheduled function the runtime then reports as disabled. Older
1301
+ * pods omit it and the service falls back to the defaults.
1302
+ */
1303
+ resolvedHostedEnvDefaults?: Record<string, string>;
1286
1304
  }, {
1287
1305
  projectId: string;
1288
1306
  deployId: string;
@@ -1295,7 +1313,7 @@ export type ClientDevtoolsBuildFailedV1 = FusionEventVariant<"client.devtools.bu
1295
1313
  deployId: string;
1296
1314
  projectId: string;
1297
1315
  error: string;
1298
- }, {
1316
+ } & DeployFailureReport, {
1299
1317
  projectId: string;
1300
1318
  deployId: string;
1301
1319
  }, 1>;
@@ -0,0 +1 @@
1
+ export {};