Skip to content

Commit 9bc5be7

Browse files
committed
feat: add client-side only tools
1 parent 6956096 commit 9bc5be7

2 files changed

Lines changed: 75 additions & 2 deletions

File tree

src/server.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
import { z } from 'zod';
88
import { DAAdminClient } from './da-admin/client.js';
99
import { EDSAdminClient } from './eds-admin/client.js';
10-
import { createDATools, createEDSTools } from './tools/tools.js';
10+
import { createCanvasClientTools, createDATools, createEDSTools } from './tools/tools.js';
1111
import { ensureHtmlExtension } from './tools/utils.js';
1212
import { createCollabClient } from './collab-client.js';
1313

@@ -288,7 +288,8 @@ async function handleChat(request: Request, env: Env): Promise<Response> {
288288
collab: collab ?? undefined,
289289
});
290290
const edsTools = edsClient ? createEDSTools(edsClient) : {};
291-
const tools = { ...daTools, ...edsTools };
291+
const canvasClientTools = createCanvasClientTools();
292+
const tools = { ...canvasClientTools, ...daTools, ...edsTools };
292293

293294
const skills = daClient && pageContext
294295
? await loadSkills(daClient, pageContext.org, pageContext.site)
@@ -335,6 +336,7 @@ Use the available tools to search documentation and provide accurate information
335336
Always provide helpful, accurate responses. You must never refer to the platform as "Dark Alley" or "DA".
336337
337338
CRITICAL INSTRUCTION - TOOL USAGE:
339+
- For bulk preview, publish, or unpublish (live delete) of multiple DA pages in the canvas workspace, use the matching bulk canvas tools (run in the browser). Do not claim the operation finished until the user completes or dismisses the dialog.
338340
- NEVER mention tool names in your response text
339341
- NEVER explain that you are calling a tool or function
340342
- Simply perform the action and describe the RESULT, not the process

src/tools/tools.ts

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,77 @@ export function createDATools(client: DAAdminClient | null, options?: DAToolsOpt
395395
return tools;
396396
}
397397

398+
/**
399+
* Runs only in the canvas browser; no `execute` so the AI SDK defers results to the client.
400+
*/
401+
export const CANVAS_CLIENT_ONLY_TOOLS = [
402+
'da_bulk_preview',
403+
'da_bulk_publish',
404+
'da_bulk_delete',
405+
] as const;
406+
407+
const bulkAemCanvasDialogOutputSchema = z.object({
408+
cancelled: z.boolean().optional(),
409+
okCount: z.number().optional(),
410+
failCount: z.number().optional(),
411+
message: z.string().optional(),
412+
results: z
413+
.array(
414+
z.object({
415+
path: z.string(),
416+
ok: z.boolean(),
417+
status: z.string().optional(),
418+
message: z.string().optional(),
419+
}),
420+
)
421+
.optional(),
422+
});
423+
424+
const bulkAemPagesInputSchema = z.object({
425+
pages: z
426+
.array(z.string().min(1))
427+
.min(1)
428+
.describe(
429+
'HTML page paths under the repo (e.g. "docs/guide.html" or "adobe/my-site/docs/guide.html")',
430+
),
431+
});
432+
433+
/**
434+
* Tools whose effects happen in the DA canvas UI (not on the worker).
435+
* Each must omit `execute` and declare `outputSchema` for typing.
436+
*/
437+
export function createCanvasClientTools() {
438+
return {
439+
da_bulk_preview: tool({
440+
description:
441+
'Open a bulk preview dialog in the user\'s browser for multiple DA pages at once. '
442+
+ 'Use when the user wants to preview several pages in the canvas workspace without opening each one manually. '
443+
+ 'Paths may be relative to the current org/repo (e.g. "folder/page.html") or full "org/repo/path/to/page.html". '
444+
+ 'The user confirms in the dialog; results are returned after they finish or cancel.',
445+
inputSchema: bulkAemPagesInputSchema,
446+
outputSchema: bulkAemCanvasDialogOutputSchema,
447+
}),
448+
da_bulk_publish: tool({
449+
description:
450+
'Open a bulk publish dialog in the user\'s browser to publish multiple DA pages to AEM live (preview then live). '
451+
+ 'Use when the user wants to publish several pages at once from the canvas workspace. '
452+
+ 'Paths may be relative to the current org/repo or full "org/repo/path/to/page.html". '
453+
+ 'The user runs the action in the dialog; results return after they finish or cancel.',
454+
inputSchema: bulkAemPagesInputSchema,
455+
outputSchema: bulkAemCanvasDialogOutputSchema,
456+
}),
457+
da_bulk_delete: tool({
458+
description:
459+
'Open a bulk delete dialog in the user\'s browser to unpublish multiple pages from AEM live (DELETE on live). '
460+
+ 'Use only when the user explicitly wants to remove published pages. '
461+
+ 'Paths may be relative to the current org/repo or full "org/repo/path/to/page.html". '
462+
+ 'The user confirms in the dialog; results return after they finish or cancel.',
463+
inputSchema: bulkAemPagesInputSchema,
464+
outputSchema: bulkAemCanvasDialogOutputSchema,
465+
}),
466+
};
467+
}
468+
398469
export function createEDSTools(client: EDSAdminClient) {
399470
// eslint-disable-next-line @typescript-eslint/no-explicit-any
400471
const tools: Record<string, any> = {};

0 commit comments

Comments
 (0)