create-agentmark 0.10.8 → 1.0.1

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.
@@ -1,809 +0,0 @@
1
- // src/utils/examples/templates/adapters.ts
2
- var createAdapterConfig = (provider) => {
3
- return {
4
- "ai-sdk": {
5
- package: "@agentmark-ai/ai-sdk-v5-adapter",
6
- dependencies: ["ai@^5", `@ai-sdk/${provider}@^2`],
7
- classes: {
8
- modelRegistry: "VercelAIModelRegistry",
9
- webhookHandler: "VercelAdapterWebhookHandler"
10
- }
11
- },
12
- mastra: {
13
- package: "@agentmark-ai/mastra-v0-adapter",
14
- dependencies: [
15
- "@mastra/core@<0.20.0",
16
- "@mastra/mcp@<0.13.4",
17
- `@ai-sdk/${provider}@<2`,
18
- "ai@^4"
19
- ],
20
- classes: {
21
- modelRegistry: "MastraModelRegistry",
22
- webhookHandler: "MastraAdapterWebhookHandler"
23
- }
24
- },
25
- "claude-agent-sdk": {
26
- package: "@agentmark-ai/claude-agent-sdk-v0-adapter",
27
- dependencies: ["@anthropic-ai/claude-agent-sdk@^0.1.0"],
28
- classes: {
29
- modelRegistry: "ClaudeAgentModelRegistry",
30
- webhookHandler: "ClaudeAgentWebhookHandler"
31
- }
32
- }
33
- };
34
- };
35
- function getAdapterConfig(adapter, provider) {
36
- const config = createAdapterConfig(provider)[adapter];
37
- if (!config) {
38
- throw new Error(
39
- `Unknown adapter: ${adapter}. Available adapters: ${Object.keys(
40
- createAdapterConfig(provider)
41
- ).join(", ")}`
42
- );
43
- }
44
- return config;
45
- }
46
-
47
- // src/utils/examples/templates/app-index.ts
48
- var getIndexFileContent = (adapter = "ai-sdk", deploymentMode = "cloud") => {
49
- const isCloud = deploymentMode === "cloud";
50
- const tracingImport = `import { AgentMarkSDK } from "@agentmark-ai/sdk";
51
- `;
52
- const cloudTracingInit = `
53
- // Initialize tracing - traces will be sent to AgentMark Cloud
54
- // To disable tracing, comment out sdk.initTracing() below
55
- const sdk = new AgentMarkSDK({
56
- apiKey: process.env.AGENTMARK_API_KEY ?? "",
57
- appId: process.env.AGENTMARK_APP_ID ?? "",
58
- });
59
- sdk.initTracing({ disableBatch: true });
60
- `;
61
- const staticTracingInit = `
62
- // Initialize tracing - traces will be sent to local dev server
63
- // Make sure to run "npx agentmark dev" in another terminal first
64
- // To disable tracing, comment out sdk.initTracing() below
65
- const sdk = new AgentMarkSDK({
66
- apiKey: "",
67
- appId: "",
68
- baseUrl: "http://localhost:9418",
69
- });
70
- sdk.initTracing({ disableBatch: true });
71
- `;
72
- const tracingInit = isCloud ? cloudTracingInit : staticTracingInit;
73
- if (adapter === "claude-agent-sdk") {
74
- return `import "dotenv/config";
75
- import { query } from "@anthropic-ai/claude-agent-sdk";
76
- import { withTracing } from "@agentmark-ai/claude-agent-sdk-v0-adapter";
77
- ${tracingImport}import { client } from "./agentmark.client";
78
- ${tracingInit}
79
- const telemetry = {
80
- isEnabled: true,
81
- metadata: {
82
- trace_name: "customer-support",
83
- user_id: "user-123",
84
- session_id: "session-123",
85
- session_name: "my-first-session",
86
- },
87
- };
88
-
89
- const runCustomerSupport = async (customer_message: string) => {
90
- const prompt = await client.loadTextPrompt("customer-support-agent");
91
- const adapted = await prompt.format({
92
- props: {
93
- customer_question: customer_message,
94
- },
95
- telemetry,
96
- });
97
-
98
- // Execute with Claude Agent SDK using withTracing for telemetry
99
- // The adapted object contains { query, telemetry } ready for withTracing()
100
- const tracedResult = await withTracing(query, adapted);
101
-
102
- // traceId is available immediately
103
- console.log("Trace ID:", tracedResult.traceId);
104
-
105
- let result = "";
106
- for await (const message of tracedResult) {
107
- if (message.type === "result" && message.subtype === "success") {
108
- result = message.result || "";
109
- }
110
- }
111
-
112
- return result;
113
- };
114
-
115
- const main = async () => {
116
- try {
117
- const user_message = "How long does shipping take?";
118
- const assistant = await runCustomerSupport(user_message);
119
- console.log("Customer support response:", assistant);
120
- } catch (error) {
121
- console.error(error);
122
- }
123
- };
124
-
125
- main();
126
- `;
127
- } else if (adapter === "mastra") {
128
- return `import "dotenv/config";
129
- import { Agent } from "@mastra/core/agent";
130
- ${tracingImport}import { client } from "./agentmark.client";
131
- ${tracingInit}
132
- const telemetry = {
133
- isEnabled: true,
134
- metadata: {
135
- trace_name: "customer-support",
136
- user_id: "user-123",
137
- session_id: "session-123",
138
- session_name: "my-first-session",
139
- },
140
- };
141
-
142
- const runCustomerSupport = async (customer_message: string) => {
143
- const prompt = await client.loadTextPrompt("customer-support-agent");
144
- const agentConfig = await prompt.formatAgent({
145
- options: {
146
- telemetry,
147
- },
148
- });
149
-
150
- const [messages, generateOptions] = await agentConfig.formatMessages({
151
- props: {
152
- customer_question: customer_message,
153
- },
154
- });
155
-
156
- const agent = new Agent(agentConfig);
157
- const response = await agent.generate(messages, generateOptions);
158
-
159
- return (response as any).text || (response as any).content || String(response);
160
- };
161
-
162
- const main = async () => {
163
- try {
164
- const user_message = "How long does shipping take?";
165
- const assistant = await runCustomerSupport(user_message);
166
- console.log("Customer support response:", assistant);
167
- } catch (error) {
168
- console.error(error);
169
- }
170
- };
171
-
172
- main();
173
- `;
174
- } else {
175
- return `import "dotenv/config";
176
- import { generateText } from "ai";
177
- ${tracingImport}import { client } from "./agentmark.client";
178
- ${tracingInit}
179
- const telemetry = {
180
- isEnabled: true,
181
- metadata: {
182
- trace_name: "customer-support",
183
- user_id: "user-123",
184
- session_id: "session-123",
185
- session_name: "my-first-session",
186
- },
187
- };
188
-
189
- const runCustomerSupport = async (customer_message: string) => {
190
- const prompt = await client.loadTextPrompt("customer-support-agent");
191
- const vercelInput = await prompt.format({
192
- props: {
193
- customer_question: customer_message,
194
- },
195
- telemetry,
196
- });
197
-
198
- const resp = await generateText(vercelInput);
199
-
200
- return resp.text;
201
- };
202
-
203
- const main = async () => {
204
- try {
205
- const user_message = "How long does shipping take?";
206
- const assistant = await runCustomerSupport(user_message);
207
- console.log("Customer support response:", assistant);
208
- } catch (error) {
209
- console.error(error);
210
- }
211
- };
212
-
213
- main();
214
- `;
215
- }
216
- };
217
-
218
- // src/utils/examples/templates/env.ts
219
- var getEnvFileContent = (_modelProvider, apiKey = "", adapter = "ai-sdk", deploymentMode = "cloud") => {
220
- const apiKeyValue = apiKey || "your_api_key_here";
221
- const apiKeyName = adapter === "claude-agent-sdk" ? "ANTHROPIC_API_KEY" : "OPENAI_API_KEY";
222
- const cloudEnvVars = deploymentMode === "cloud" ? `
223
- # AgentMark Cloud \u2014 required for managed deployments
224
- AGENTMARK_API_KEY=your_agentmark_api_key
225
- AGENTMARK_APP_ID=your_agentmark_app_id
226
- ` : `
227
- # Cloud deployment: Set these environment variables
228
- # AGENTMARK_BASE_URL=https://api.agentmark.co
229
- # AGENTMARK_API_KEY=your_agentmark_api_key
230
- # AGENTMARK_APP_ID=your_agentmark_app_id
231
- `;
232
- return `${apiKeyName}=${apiKeyValue}
233
- ${cloudEnvVars}
234
- # Learn more: https://docs.agentmark.co/getting-started/quickstart
235
- `;
236
- };
237
-
238
- // src/utils/examples/templates/package-setup.ts
239
- import fs2 from "fs-extra";
240
- import { execSync } from "child_process";
241
-
242
- // src/utils/file-merge.ts
243
- import fs from "fs-extra";
244
- import path from "path";
245
- function mergePackageJson(targetPath, agentmarkDeps, agentmarkDevDeps, agentmarkScripts) {
246
- const packageJsonPath = path.join(targetPath, "package.json");
247
- const result = {
248
- success: false,
249
- warnings: [],
250
- added: [],
251
- skipped: []
252
- };
253
- try {
254
- if (!fs.existsSync(packageJsonPath)) {
255
- result.warnings.push("No existing package.json found");
256
- return result;
257
- }
258
- const existing = fs.readJsonSync(packageJsonPath);
259
- if (!existing.dependencies) {
260
- existing.dependencies = {};
261
- }
262
- if (!existing.devDependencies) {
263
- existing.devDependencies = {};
264
- }
265
- if (!existing.scripts) {
266
- existing.scripts = {};
267
- }
268
- const deps = existing.dependencies;
269
- const devDeps = existing.devDependencies;
270
- const scripts = existing.scripts;
271
- for (const [pkg, version] of Object.entries(agentmarkDeps)) {
272
- if (deps[pkg]) {
273
- result.skipped.push(`dependency: ${pkg} (already exists)`);
274
- } else {
275
- deps[pkg] = version;
276
- result.added.push(`dependency: ${pkg}@${version}`);
277
- }
278
- }
279
- for (const [pkg, version] of Object.entries(agentmarkDevDeps)) {
280
- if (devDeps[pkg]) {
281
- result.skipped.push(`devDependency: ${pkg} (already exists)`);
282
- } else {
283
- devDeps[pkg] = version;
284
- result.added.push(`devDependency: ${pkg}@${version}`);
285
- }
286
- }
287
- for (const [scriptName, scriptCmd] of Object.entries(agentmarkScripts)) {
288
- if (scripts[scriptName]) {
289
- const namespacedName = `agentmark:${scriptName}`;
290
- if (scripts[namespacedName]) {
291
- result.skipped.push(`script: ${scriptName}`);
292
- result.warnings.push(
293
- `Script "${scriptName}" and "${namespacedName}" both already exist. Skipping.`
294
- );
295
- } else {
296
- scripts[namespacedName] = scriptCmd;
297
- result.added.push(`script: ${namespacedName} (namespaced due to conflict)`);
298
- result.warnings.push(
299
- `Script "${scriptName}" already exists. Added as "${namespacedName}" instead.`
300
- );
301
- }
302
- } else {
303
- scripts[scriptName] = scriptCmd;
304
- result.added.push(`script: ${scriptName}`);
305
- }
306
- }
307
- fs.writeJsonSync(packageJsonPath, existing, { spaces: 2 });
308
- result.success = true;
309
- result.content = JSON.stringify(existing, null, 2);
310
- return result;
311
- } catch (error) {
312
- result.warnings.push(`Error merging package.json: ${error}`);
313
- return result;
314
- }
315
- }
316
-
317
- // src/utils/types.ts
318
- var PACKAGE_MANAGERS = {
319
- "yarn.lock": {
320
- name: "yarn",
321
- lockFile: "yarn.lock",
322
- installCmd: "yarn install",
323
- addCmd: "yarn add",
324
- addDevCmd: "yarn add --dev",
325
- runCmd: "yarn"
326
- },
327
- "pnpm-lock.yaml": {
328
- name: "pnpm",
329
- lockFile: "pnpm-lock.yaml",
330
- installCmd: "pnpm install",
331
- addCmd: "pnpm add",
332
- addDevCmd: "pnpm add --save-dev",
333
- runCmd: "pnpm"
334
- },
335
- "bun.lockb": {
336
- name: "bun",
337
- lockFile: "bun.lockb",
338
- installCmd: "bun install",
339
- addCmd: "bun add",
340
- addDevCmd: "bun add --dev",
341
- runCmd: "bun run"
342
- },
343
- "package-lock.json": {
344
- name: "npm",
345
- lockFile: "package-lock.json",
346
- installCmd: "npm install",
347
- addCmd: "npm install",
348
- addDevCmd: "npm install --save-dev",
349
- runCmd: "npm run"
350
- }
351
- };
352
- var DEFAULT_PACKAGE_MANAGER = PACKAGE_MANAGERS["package-lock.json"];
353
-
354
- // src/utils/examples/templates/package-setup.ts
355
- var setupPackageJson = (targetPath = ".", deploymentMode = "cloud", projectInfo = null) => {
356
- const packageJsonPath = `${targetPath}/package.json`;
357
- const isExistingProject = projectInfo?.isExistingProject ?? false;
358
- if (!fs2.existsSync(packageJsonPath)) {
359
- console.log("Creating package.json...");
360
- execSync("npm init -y", { cwd: targetPath });
361
- }
362
- const demoScript = deploymentMode === "static" ? "npx agentmark build --out dist/agentmark && npx tsx index.ts" : "npx tsx index.ts";
363
- if (isExistingProject && fs2.existsSync(packageJsonPath)) {
364
- const scriptsToAdd = {
365
- "demo": demoScript,
366
- "agentmark": "agentmark"
367
- };
368
- if (deploymentMode === "static") {
369
- scriptsToAdd["build"] = "agentmark build --out dist/agentmark";
370
- }
371
- const result = mergePackageJson(targetPath, {}, {}, scriptsToAdd);
372
- if (result.added.length > 0) {
373
- console.log(`\u2705 Added to package.json: ${result.added.join(", ")}`);
374
- }
375
- if (result.skipped.length > 0) {
376
- console.log(`\u23ED\uFE0F Skipped existing in package.json: ${result.skipped.join(", ")}`);
377
- }
378
- if (result.warnings.length > 0) {
379
- result.warnings.forEach((w) => console.log(`\u26A0\uFE0F ${w}`));
380
- }
381
- } else {
382
- const pkgJson = fs2.readJsonSync(packageJsonPath);
383
- pkgJson.name = pkgJson.name === "test" || !pkgJson.name ? "agentmark-example-app" : pkgJson.name;
384
- pkgJson.description = pkgJson.description || "A simple Node.js app using the Agentmark SDK";
385
- if (pkgJson.type === "commonjs") {
386
- delete pkgJson.type;
387
- }
388
- const scripts = {
389
- ...pkgJson.scripts,
390
- "demo": demoScript,
391
- "agentmark": "agentmark"
392
- };
393
- if (deploymentMode === "static") {
394
- scripts["build"] = "agentmark build --out dist/agentmark";
395
- }
396
- pkgJson.scripts = scripts;
397
- fs2.writeJsonSync(packageJsonPath, pkgJson, { spaces: 2 });
398
- }
399
- };
400
- var installDependencies = (modelProvider, targetPath = ".", adapter = "ai-sdk", deploymentMode = "cloud", packageManager = null) => {
401
- console.log("Installing required packages...");
402
- console.log("This might take a moment...");
403
- const adapterConfig = getAdapterConfig(adapter, modelProvider);
404
- const pm = packageManager || DEFAULT_PACKAGE_MANAGER;
405
- const npmSuffix = pm.name === "npm" ? " --legacy-peer-deps" : "";
406
- try {
407
- const devDeps = ["typescript", "ts-node", "@types/node", "@agentmark-ai/cli"];
408
- const devDepsCmd = `${pm.addDevCmd} ${devDeps.join(" ")}${npmSuffix}`;
409
- console.log(`Using ${pm.name} to install dependencies...`);
410
- execSync(devDepsCmd, {
411
- stdio: "inherit",
412
- cwd: targetPath
413
- });
414
- const loaderPackages = deploymentMode === "static" ? ["@agentmark-ai/loader-api", "@agentmark-ai/loader-file"] : ["@agentmark-ai/loader-api"];
415
- const deps = [
416
- "dotenv",
417
- "@agentmark-ai/prompt-core",
418
- "@agentmark-ai/sdk",
419
- adapterConfig.package,
420
- ...loaderPackages,
421
- ...adapterConfig.dependencies
422
- ];
423
- const depsCmd = `${pm.addCmd} ${deps.join(" ")}${npmSuffix}`;
424
- execSync(depsCmd, { stdio: "inherit", cwd: targetPath });
425
- console.log("Packages installed successfully!");
426
- } catch (error) {
427
- console.error("Error installing packages:", error);
428
- throw new Error(
429
- "Failed to install required packages. Please check your network connection and try again."
430
- );
431
- }
432
- };
433
-
434
- // src/utils/examples/templates/tsconfig.ts
435
- var getTsConfigContent = () => {
436
- return {
437
- "compilerOptions": {
438
- "target": "ES2020",
439
- "module": "NodeNext",
440
- "moduleResolution": "NodeNext",
441
- "esModuleInterop": true,
442
- "forceConsistentCasingInFileNames": true,
443
- "strict": true,
444
- "skipLibCheck": true
445
- }
446
- };
447
- };
448
-
449
- // src/utils/examples/templates/animal-drawing-prompt.ts
450
- var getAnimalDrawingPrompt = () => {
451
- return `---
452
- name: animal-drawing
453
- image_config:
454
- model_name: openai/dall-e-3
455
- num_images: 1
456
- size: 1024x1024
457
- aspect_ratio: 1:1
458
- test_settings:
459
- dataset: animal.jsonl
460
- props:
461
- animal: "cat"
462
- ---
463
-
464
- <ImagePrompt>
465
- Draw a hyper-realistic picture of a {props.animal}
466
- </ImagePrompt>`;
467
- };
468
-
469
- // src/utils/examples/templates/customer-support-prompt.ts
470
- var getCustomerSupportPrompt = (model) => {
471
- return `---
472
- name: customer-support-agent
473
- text_config:
474
- model_name: ${model}
475
- max_calls: 2
476
- tools:
477
- - search_knowledgebase
478
- test_settings:
479
- dataset: customer-query.jsonl
480
- props:
481
- customer_question: "I'm having trouble with my order. How long does shipping take?"
482
- input_schema:
483
- type: object
484
- properties:
485
- customer_question:
486
- type: string
487
- description: "The customer's question"
488
- required:
489
- - customer_question
490
- ---
491
-
492
- <System>
493
- You are a customer service agent for a company that sells products online. You are given a customer's question and you need to respond to the customer. You need to be friendly, professional, and helpful.
494
-
495
- You have access to the following tool:
496
- - search_knowledgebase: Search the company knowledgebase for information about shipping, warranty, and returns. Use this when customers ask about these topics.
497
- </System>
498
-
499
- <User>{props.customer_question}</User>`;
500
- };
501
-
502
- // src/utils/examples/templates/party-planner-prompt.ts
503
- var getPartyPlannerPrompt = (model) => {
504
- return `---
505
- name: party-planner
506
- object_config:
507
- model_name: ${model}
508
- schema:
509
- type: object
510
- properties:
511
- names:
512
- type: array
513
- description: "List of names of people attending the party."
514
- items:
515
- type: string
516
- required:
517
- - names
518
- test_settings:
519
- dataset: party.jsonl
520
- evals:
521
- - exact_match_json
522
- props:
523
- party_text: "We're having a party with Alice, Bob, and Carol."
524
- input_schema:
525
- type: object
526
- properties:
527
- party_text:
528
- type: string
529
- description: "A block of text describing the upcoming party and attendees."
530
- required:
531
- - party_text
532
- ---
533
-
534
- <System>
535
- Extract the names of all people attending the party from the following text. Respond with a list of names only.
536
- </System>
537
-
538
- <User>
539
- Text: {props.party_text}
540
- </User>`;
541
- };
542
-
543
- // src/utils/examples/templates/story-teller-prompt.ts
544
- var getStoryTellerPrompt = () => {
545
- return `---
546
- name: story-teller
547
- speech_config:
548
- model_name: openai/tts-1-hd
549
- voice: "nova"
550
- speed: 1.0
551
- output_format: "mp3"
552
- test_settings:
553
- dataset: story.jsonl
554
- props:
555
- story: "Once upon a time, there was a cat who loved to play with a ball."
556
- ---
557
-
558
- <System>
559
- You are a storyteller for children. Make sure your story is engaging and interesting.
560
- </System>
561
-
562
- <SpeechPrompt>
563
- - {props.story}
564
- </SpeechPrompt>`;
565
- };
566
-
567
- // src/utils/examples/templates/datasets.ts
568
- var getAnimalDataset = () => {
569
- return `{"input": {"animal": "cat"}, "expected_output": "A realistic picture of a cat"}
570
- {"input": {"animal": "dog"}, "expected_output": "A realistic picture of a dog"}
571
- {"input": {"animal": "bird"}, "expected_output": "A realistic picture of a bird"}`;
572
- };
573
- var getCustomerQueryDataset = () => {
574
- return `{"input": {"customer_question": "My package hasn't arrived yet. Can you help me track it?"}}
575
- {"input": {"customer_question": "I received the wrong item in my order. What should I do?"}}
576
- {"input": {"customer_question": "How do I return a product that I purchased last week?"}}`;
577
- };
578
- var getPartyDataset = () => {
579
- return `{"input": {"party_text": "We're having a party with Alice, Bob, and Carol."}, "expected_output": "{\\"names\\": [\\"Alice\\", \\"Bob\\", \\"Carol\\"]}"}
580
- {"input": {"party_text": "The guest list includes Dave, Emma, and Frank."}, "expected_output": "{\\"names\\": [\\"Dave\\", \\"Emma\\", \\"Frank\\"]}"}
581
- {"input": {"party_text": "Join us for a celebration with Grace, Henry, and Isla."}, "expected_output": "{\\"names\\": [\\"Grace\\", \\"Henry\\", \\"Isla\\"]}"}`;
582
- };
583
- var getStoryDataset = () => {
584
- return `{"input": {"story": "Once upon a time, the Moon woke up and found her glow missing! She floated around the sky asking stars, clouds, and even comets if they'd seen her light. It wasn't until she peeked into a mountain lake that she saw her glow shining back\u2014hidden in her own reflection! Laughing, she realized she had never lost it\u2014it was with her all along, just hiding beneath a cloudy sky."}}
585
- {"input": {"story": "Benny was no ordinary banana\u2014he dreamed of becoming a superhero. One day, when a monkey slipped in the jungle and cried for help, Benny rolled into action, dodging vines and swinging from branches using his peel like a lasso. The monkey was saved, and from that day on, Benny was known as \\"The Peel of Justice,\\" the bravest fruit in the whole rainforest."}}
586
- {"input": {"story": "In the town of Maplebrook, there was a library that whispered stories when no one was looking. Curious little Nia tiptoed in one rainy day and heard the books giggling softly. She opened one called The Secret Tunnel, and to her surprise, it sucked her in! She found herself riding a dragon through glittering caves. When she returned, the book winked shut\u2014waiting for its next reader to listen."}}`;
587
- };
588
-
589
- // src/utils/examples/templates/example-prompts.ts
590
- import fs3 from "fs-extra";
591
- var createExamplePrompts = (model, targetPath = ".", adapter = "ai-sdk") => {
592
- fs3.ensureDirSync(`${targetPath}/agentmark`);
593
- const noImageSupport = ["mastra", "claude-agent-sdk", "pydantic-ai"];
594
- const noSpeechSupport = ["mastra", "claude-agent-sdk", "pydantic-ai"];
595
- const skipImagePrompts = noImageSupport.includes(adapter);
596
- const skipSpeechPrompts = noSpeechSupport.includes(adapter);
597
- const usedModels = [];
598
- if (!skipImagePrompts) {
599
- const animalDrawingPrompt = getAnimalDrawingPrompt();
600
- fs3.writeFileSync(`${targetPath}/agentmark/animal-drawing.prompt.mdx`, animalDrawingPrompt);
601
- const animalDataset = getAnimalDataset();
602
- fs3.writeFileSync(`${targetPath}/agentmark/animal.jsonl`, animalDataset);
603
- usedModels.push("openai/dall-e-3");
604
- }
605
- const customerSupportPrompt = getCustomerSupportPrompt(model);
606
- fs3.writeFileSync(`${targetPath}/agentmark/customer-support-agent.prompt.mdx`, customerSupportPrompt);
607
- const customerQueryDataset = getCustomerQueryDataset();
608
- fs3.writeFileSync(`${targetPath}/agentmark/customer-query.jsonl`, customerQueryDataset);
609
- usedModels.push(model);
610
- const partyPlannerPrompt = getPartyPlannerPrompt(model);
611
- fs3.writeFileSync(`${targetPath}/agentmark/party-planner.prompt.mdx`, partyPlannerPrompt);
612
- const partyDataset = getPartyDataset();
613
- fs3.writeFileSync(`${targetPath}/agentmark/party.jsonl`, partyDataset);
614
- if (!skipSpeechPrompts) {
615
- const storyTellerPrompt = getStoryTellerPrompt();
616
- fs3.writeFileSync(`${targetPath}/agentmark/story-teller.prompt.mdx`, storyTellerPrompt);
617
- const storyDataset = getStoryDataset();
618
- fs3.writeFileSync(`${targetPath}/agentmark/story.jsonl`, storyDataset);
619
- usedModels.push("openai/tts-1-hd");
620
- }
621
- return [...new Set(usedModels)];
622
- };
623
-
624
- // src/utils/examples/templates/user-client-config.ts
625
- var getClientConfigContent = (options) => {
626
- const { provider, adapter, deploymentMode = "cloud" } = options;
627
- const isMastra = adapter === "mastra";
628
- const adapterConfig = getAdapterConfig(adapter, provider);
629
- const { modelRegistry } = adapterConfig.classes;
630
- const isClaudeAgentSdk = adapter === "claude-agent-sdk";
631
- const providerImport = isClaudeAgentSdk ? "" : `import { ${provider} } from '@ai-sdk/${provider}';`;
632
- const loaderImport = deploymentMode === "cloud" ? `import { ApiLoader } from "@agentmark-ai/loader-api";` : `import { ApiLoader } from "@agentmark-ai/loader-api";
633
- import { FileLoader } from "@agentmark-ai/loader-file";`;
634
- const loaderSetup = deploymentMode === "cloud" ? ` // ApiLoader works for both development and production
635
- // - Development: 'agentmark dev' sets AGENTMARK_BASE_URL to localhost
636
- // - Production: Set AGENTMARK_API_KEY and AGENTMARK_APP_ID for cloud.
637
- // AGENTMARK_BASE_URL overrides the default https://api.agentmark.co
638
- // target \u2014 managed deployments use this to point back at the gateway
639
- // that dispatched the job.
640
- const loader = process.env.NODE_ENV === 'development'
641
- ? ApiLoader.local({ baseUrl: process.env.AGENTMARK_BASE_URL || 'http://localhost:9418' })
642
- : ApiLoader.cloud({
643
- apiKey: process.env.AGENTMARK_API_KEY!,
644
- appId: process.env.AGENTMARK_APP_ID!,
645
- baseUrl: process.env.AGENTMARK_BASE_URL,
646
- });` : ` const loader = process.env.NODE_ENV === 'development'
647
- ? ApiLoader.local({ baseUrl: process.env.AGENTMARK_BASE_URL || 'http://localhost:9418' })
648
- : new FileLoader('./dist/agentmark');`;
649
- const modelRegistrySetup = isClaudeAgentSdk ? `function createModelRegistry() {
650
- // Claude Agent SDK accepts model names directly.
651
- // Use createDefault() for simple pass-through of model names.
652
- const modelRegistry = ${modelRegistry}.createDefault();
653
-
654
- // To configure specific models (e.g., extended thinking), use:
655
- // const modelRegistry = new ${modelRegistry}()
656
- // .registerModels(/claude-.*-thinking/, (name) => ({
657
- // model: name,
658
- // maxThinkingTokens: 10000, // Enable extended thinking
659
- // }))
660
- // .registerModels("claude-sonnet-4-20250514", (name) => ({ model: name }));
661
-
662
- return modelRegistry;
663
- }` : `function createModelRegistry() {
664
- const modelRegistry = new ${modelRegistry}()
665
- .registerProviders({ ${provider} });
666
- return modelRegistry;
667
- }`;
668
- const adapterOptionsImport = isClaudeAgentSdk ? `
669
- // Claude Agent SDK adapter options
670
- // See: https://github.com/anthropics/claude-agent-sdk
671
- const adapterOptions = {
672
- // Permission mode controls tool access:
673
- // - 'default': Requires user approval for each tool use
674
- // - 'acceptEdits': Auto-approve file edits only
675
- // - 'bypassPermissions': Auto-approve all tools (use for automated pipelines)
676
- // - 'plan': Planning mode only, no tool execution
677
- permissionMode: 'bypassPermissions' as const,
678
-
679
- // Maximum conversation turns before stopping
680
- maxTurns: 20,
681
-
682
- // Optional: Set working directory for file operations
683
- // cwd: process.cwd(),
684
-
685
- // Optional: Budget limit in USD
686
- // maxBudgetUsd: 10.00,
687
-
688
- // Optional: Restrict which tools the agent can use
689
- // allowedTools: ['Read', 'Write', 'Glob'],
690
- // disallowedTools: ['Bash'],
691
- };` : "";
692
- const toolImport = isClaudeAgentSdk ? `import { tool, createSdkMcpServer } from "@anthropic-ai/claude-agent-sdk";
693
- import { z } from 'zod';` : isMastra ? `import { tool } from 'ai';
694
- import type { ToolsInput } from '@mastra/core/agent';
695
- import { z } from 'zod';` : `import { tool } from 'ai';
696
- import type { Tool } from 'ai';
697
- import { z } from 'zod';`;
698
- const createClientCall = isClaudeAgentSdk ? `return createAgentMarkClient<AgentMarkTypes>({ loader, modelRegistry, evals, adapterOptions, mcpServers: { 'customer-support': customerSupportTools } });` : `return createAgentMarkClient<AgentMarkTypes>({ loader, modelRegistry, tools, evals });`;
699
- const toolSchemaField = isMastra ? `parameters: z.object({ query: z.string().describe('The search query') })` : `inputSchema: z.object({ query: z.string().describe('The search query') })`;
700
- const toolsReturnType = isMastra ? "ToolsInput" : "Record<string, Tool>";
701
- const toolsSetup = isClaudeAgentSdk ? `
702
- // Custom tools exposed as an MCP server \u2014 the SDK's native tool mechanism.
703
- // The server name is used in mcpServers config; tool names are used in prompt files.
704
- const knowledgeBase = tool(
705
- 'search_knowledgebase',
706
- 'Search the knowledge base for relevant articles',
707
- { query: z.string().describe('The search query') },
708
- async ({ query }) => ({
709
- content: [{ type: 'text' as const, text: JSON.stringify({
710
- articles: [
711
- { topic: 'shipping', content: 'Standard shipping takes 3\u20135 business days.' },
712
- { topic: 'warranty', content: 'All products include a 1-year limited warranty.' },
713
- { topic: 'returns', content: 'You can return items within 30 days of delivery.' },
714
- ],
715
- }) }],
716
- })
717
- );
718
-
719
- const customerSupportTools = createSdkMcpServer({
720
- name: 'customer-support',
721
- tools: [knowledgeBase],
722
- });` : `
723
- function createTools(): ${toolsReturnType} {
724
- return {
725
- search_knowledgebase: tool({
726
- description: 'Search the knowledge base for relevant articles',
727
- ${toolSchemaField},
728
- execute: async ({ query }) => {
729
- // Simulate search delay
730
- await new Promise(resolve => setTimeout(resolve, 500));
731
-
732
- // Return all three knowledge base articles
733
- // The LLM will select the relevant one based on the query
734
- return {
735
- articles: [
736
- { topic: 'shipping', content: 'Standard shipping takes 3\u20135 business days.' },
737
- { topic: 'warranty', content: 'All products include a 1-year limited warranty.' },
738
- { topic: 'returns', content: 'You can return items within 30 days of delivery.' }
739
- ]
740
- };
741
- },
742
- }),
743
- };
744
- }`;
745
- const toolsVariable = isClaudeAgentSdk ? "" : ` const tools = createTools();`;
746
- return `// agentmark.client.ts
747
- import path from 'node:path';
748
- import dotenv from 'dotenv';
749
- dotenv.config({ path: path.resolve(__dirname, '.env') });
750
- import { createAgentMarkClient, ${modelRegistry} } from "${adapterConfig.package}";
751
- import type { EvalRegistry } from "@agentmark-ai/prompt-core";
752
- ${loaderImport}
753
- import AgentMarkTypes from './agentmark.types';
754
- ${providerImport}
755
- ${toolImport}
756
- ${adapterOptionsImport}
757
-
758
- ${modelRegistrySetup}
759
- ${toolsSetup}
760
-
761
- const evals: EvalRegistry = {
762
- exact_match_json: async ({ output, expectedOutput }) => {
763
- if (!expectedOutput) {
764
- return { score: 0, label: 'error', reason: 'No expected output provided', passed: false };
765
- }
766
- try {
767
- const ok = JSON.stringify(output) === JSON.stringify(JSON.parse(expectedOutput));
768
- return {
769
- score: ok ? 1 : 0,
770
- label: ok ? 'correct' : 'incorrect',
771
- reason: ok ? 'Exact match' : 'Mismatch',
772
- passed: ok
773
- };
774
- } catch (e) {
775
- return { score: 0, label: 'error', reason: 'Failed to parse expected output as JSON', passed: false };
776
- }
777
- },
778
- };
779
-
780
- function createClient() {
781
- ${loaderSetup}
782
- const modelRegistry = createModelRegistry();
783
- ${toolsVariable}
784
- ${createClientCall}
785
- }
786
-
787
- export const client = createClient();
788
- `;
789
- };
790
- export {
791
- createAdapterConfig,
792
- createExamplePrompts,
793
- getAdapterConfig,
794
- getAnimalDataset,
795
- getAnimalDrawingPrompt,
796
- getClientConfigContent,
797
- getCustomerQueryDataset,
798
- getCustomerSupportPrompt,
799
- getEnvFileContent,
800
- getIndexFileContent,
801
- getPartyDataset,
802
- getPartyPlannerPrompt,
803
- getStoryDataset,
804
- getStoryTellerPrompt,
805
- getTsConfigContent,
806
- installDependencies,
807
- setupPackageJson
808
- };
809
- //# sourceMappingURL=index.js.map