create-agentmark 0.6.0 → 0.7.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.
@@ -22,6 +22,15 @@ var createAdapterConfig = (provider) => {
22
22
  toolRegistry: "MastraToolRegistry",
23
23
  webhookHandler: "MastraAdapterWebhookHandler"
24
24
  }
25
+ },
26
+ "claude-agent-sdk": {
27
+ package: "@agentmark-ai/claude-agent-sdk-adapter",
28
+ dependencies: ["@anthropic-ai/claude-agent-sdk@^0.1.0"],
29
+ classes: {
30
+ modelRegistry: "ClaudeAgentModelRegistry",
31
+ toolRegistry: "ClaudeAgentToolRegistry",
32
+ webhookHandler: "ClaudeAgentWebhookHandler"
33
+ }
25
34
  }
26
35
  };
27
36
  };
@@ -39,7 +48,61 @@ function getAdapterConfig(adapter, provider) {
39
48
 
40
49
  // src/utils/examples/templates/app-index.ts
41
50
  var getIndexFileContent = (adapter = "ai-sdk") => {
42
- if (adapter === "mastra") {
51
+ if (adapter === "claude-agent-sdk") {
52
+ return `import "dotenv/config";
53
+ import { query } from "@anthropic-ai/claude-agent-sdk";
54
+ import { withTracing } from "@agentmark-ai/claude-agent-sdk-adapter";
55
+ import { client } from "./agentmark.client";
56
+
57
+ const telemetry = {
58
+ isEnabled: true,
59
+ metadata: {
60
+ trace_name: "customer-support",
61
+ user_id: "user-123",
62
+ session_id: "session-123",
63
+ session_name: "my-first-session",
64
+ },
65
+ };
66
+
67
+ const runCustomerSupport = async (customer_message: string) => {
68
+ const prompt = await client.loadTextPrompt("customer-support-agent");
69
+ const adapted = await prompt.format({
70
+ props: {
71
+ customer_question: customer_message,
72
+ },
73
+ telemetry,
74
+ });
75
+
76
+ // Execute with Claude Agent SDK using withTracing for telemetry
77
+ // The adapted object contains { query, telemetry } ready for withTracing()
78
+ const tracedResult = await withTracing(query, adapted);
79
+
80
+ // traceId is available immediately
81
+ console.log("Trace ID:", tracedResult.traceId);
82
+
83
+ let result = "";
84
+ for await (const message of tracedResult) {
85
+ if (message.type === "result" && message.subtype === "success") {
86
+ result = message.result || "";
87
+ }
88
+ }
89
+
90
+ return result;
91
+ };
92
+
93
+ const main = async () => {
94
+ try {
95
+ const user_message = "How long does shipping take?";
96
+ const assistant = await runCustomerSupport(user_message);
97
+ console.log("Customer support response:", assistant);
98
+ } catch (error) {
99
+ console.error(error);
100
+ }
101
+ };
102
+
103
+ main();
104
+ `;
105
+ } else if (adapter === "mastra") {
43
106
  return `import "dotenv/config";
44
107
  import { Agent } from "@mastra/core/agent";
45
108
  import { client } from "./agentmark.client";
@@ -131,70 +194,211 @@ main();
131
194
  };
132
195
 
133
196
  // src/utils/examples/templates/env.ts
134
- var getEnvFileContent = (_modelProvider, apiKey = "") => {
197
+ var getEnvFileContent = (_modelProvider, apiKey = "", adapter = "ai-sdk") => {
135
198
  const apiKeyValue = apiKey || "your_api_key_here";
199
+ const apiKeyName = adapter === "claude-agent-sdk" ? "ANTHROPIC_API_KEY" : "OPENAI_API_KEY";
136
200
  return `# Cloud deployment: Set these environment variables
137
201
  # AGENTMARK_BASE_URL=https://api.agentmark.co
138
202
  # AGENTMARK_API_KEY=your_agentmark_api_key
139
203
  # AGENTMARK_APP_ID=your_agentmark_app_id
140
204
  # Learn more: https://docs.agentmark.co/platform/getting_started/quickstart
141
205
 
142
- OPENAI_API_KEY=${apiKeyValue}
206
+ ${apiKeyName}=${apiKeyValue}
143
207
  `;
144
208
  };
145
209
 
146
210
  // src/utils/examples/templates/package-setup.ts
211
+ import fs2 from "fs-extra";
212
+ import { execSync } from "child_process";
213
+
214
+ // src/utils/file-merge.ts
147
215
  import fs from "fs-extra";
148
- import { execSync, execFileSync } from "child_process";
149
- var setupPackageJson = (targetPath = ".", deploymentMode = "cloud") => {
216
+ import path from "path";
217
+ function mergePackageJson(targetPath, agentmarkDeps, agentmarkDevDeps, agentmarkScripts) {
218
+ const packageJsonPath = path.join(targetPath, "package.json");
219
+ const result = {
220
+ success: false,
221
+ warnings: [],
222
+ added: [],
223
+ skipped: []
224
+ };
225
+ try {
226
+ if (!fs.existsSync(packageJsonPath)) {
227
+ result.warnings.push("No existing package.json found");
228
+ return result;
229
+ }
230
+ const existing = fs.readJsonSync(packageJsonPath);
231
+ if (!existing.dependencies) {
232
+ existing.dependencies = {};
233
+ }
234
+ if (!existing.devDependencies) {
235
+ existing.devDependencies = {};
236
+ }
237
+ if (!existing.scripts) {
238
+ existing.scripts = {};
239
+ }
240
+ const deps = existing.dependencies;
241
+ const devDeps = existing.devDependencies;
242
+ const scripts = existing.scripts;
243
+ for (const [pkg, version] of Object.entries(agentmarkDeps)) {
244
+ if (deps[pkg]) {
245
+ result.skipped.push(`dependency: ${pkg} (already exists)`);
246
+ } else {
247
+ deps[pkg] = version;
248
+ result.added.push(`dependency: ${pkg}@${version}`);
249
+ }
250
+ }
251
+ for (const [pkg, version] of Object.entries(agentmarkDevDeps)) {
252
+ if (devDeps[pkg]) {
253
+ result.skipped.push(`devDependency: ${pkg} (already exists)`);
254
+ } else {
255
+ devDeps[pkg] = version;
256
+ result.added.push(`devDependency: ${pkg}@${version}`);
257
+ }
258
+ }
259
+ for (const [scriptName, scriptCmd] of Object.entries(agentmarkScripts)) {
260
+ if (scripts[scriptName]) {
261
+ const namespacedName = `agentmark:${scriptName}`;
262
+ if (scripts[namespacedName]) {
263
+ result.skipped.push(`script: ${scriptName}`);
264
+ result.warnings.push(
265
+ `Script "${scriptName}" and "${namespacedName}" both already exist. Skipping.`
266
+ );
267
+ } else {
268
+ scripts[namespacedName] = scriptCmd;
269
+ result.added.push(`script: ${namespacedName} (namespaced due to conflict)`);
270
+ result.warnings.push(
271
+ `Script "${scriptName}" already exists. Added as "${namespacedName}" instead.`
272
+ );
273
+ }
274
+ } else {
275
+ scripts[scriptName] = scriptCmd;
276
+ result.added.push(`script: ${scriptName}`);
277
+ }
278
+ }
279
+ fs.writeJsonSync(packageJsonPath, existing, { spaces: 2 });
280
+ result.success = true;
281
+ result.content = JSON.stringify(existing, null, 2);
282
+ return result;
283
+ } catch (error) {
284
+ result.warnings.push(`Error merging package.json: ${error}`);
285
+ return result;
286
+ }
287
+ }
288
+
289
+ // src/utils/types.ts
290
+ var PACKAGE_MANAGERS = {
291
+ "yarn.lock": {
292
+ name: "yarn",
293
+ lockFile: "yarn.lock",
294
+ installCmd: "yarn install",
295
+ addCmd: "yarn add",
296
+ addDevCmd: "yarn add --dev",
297
+ runCmd: "yarn"
298
+ },
299
+ "pnpm-lock.yaml": {
300
+ name: "pnpm",
301
+ lockFile: "pnpm-lock.yaml",
302
+ installCmd: "pnpm install",
303
+ addCmd: "pnpm add",
304
+ addDevCmd: "pnpm add --save-dev",
305
+ runCmd: "pnpm"
306
+ },
307
+ "bun.lockb": {
308
+ name: "bun",
309
+ lockFile: "bun.lockb",
310
+ installCmd: "bun install",
311
+ addCmd: "bun add",
312
+ addDevCmd: "bun add --dev",
313
+ runCmd: "bun run"
314
+ },
315
+ "package-lock.json": {
316
+ name: "npm",
317
+ lockFile: "package-lock.json",
318
+ installCmd: "npm install",
319
+ addCmd: "npm install",
320
+ addDevCmd: "npm install --save-dev",
321
+ runCmd: "npm run"
322
+ }
323
+ };
324
+ var DEFAULT_PACKAGE_MANAGER = PACKAGE_MANAGERS["package-lock.json"];
325
+
326
+ // src/utils/examples/templates/package-setup.ts
327
+ var setupPackageJson = (targetPath = ".", deploymentMode = "cloud", projectInfo = null) => {
150
328
  const packageJsonPath = `${targetPath}/package.json`;
151
- if (!fs.existsSync(packageJsonPath)) {
329
+ const isExistingProject = projectInfo?.isExistingProject ?? false;
330
+ if (!fs2.existsSync(packageJsonPath)) {
152
331
  console.log("Creating package.json...");
153
332
  execSync("npm init -y", { cwd: targetPath });
154
333
  }
155
- const pkgJson = fs.readJsonSync(packageJsonPath);
156
- pkgJson.name = pkgJson.name === "test" || !pkgJson.name ? "agentmark-example-app" : pkgJson.name;
157
- pkgJson.description = pkgJson.description || "A simple Node.js app using the Agentmark SDK";
158
- const devScript = "agentmark dev";
159
- const scripts = {
160
- ...pkgJson.scripts,
161
- "demo": "npx tsx index.ts",
162
- "dev": devScript,
163
- "prompt": "agentmark run-prompt",
164
- "experiment": "agentmark run-experiment"
165
- };
166
- if (deploymentMode === "static") {
167
- scripts["build"] = "agentmark build --out dist/agentmark";
334
+ if (isExistingProject && fs2.existsSync(packageJsonPath)) {
335
+ const scriptsToAdd = {
336
+ "demo": "npx tsx index.ts",
337
+ "dev": "agentmark dev",
338
+ "prompt": "agentmark run-prompt",
339
+ "experiment": "agentmark run-experiment"
340
+ };
341
+ if (deploymentMode === "static") {
342
+ scriptsToAdd["build"] = "agentmark build --out dist/agentmark";
343
+ }
344
+ const result = mergePackageJson(targetPath, {}, {}, scriptsToAdd);
345
+ if (result.added.length > 0) {
346
+ console.log(`\u2705 Added to package.json: ${result.added.join(", ")}`);
347
+ }
348
+ if (result.skipped.length > 0) {
349
+ console.log(`\u23ED\uFE0F Skipped existing in package.json: ${result.skipped.join(", ")}`);
350
+ }
351
+ if (result.warnings.length > 0) {
352
+ result.warnings.forEach((w) => console.log(`\u26A0\uFE0F ${w}`));
353
+ }
354
+ } else {
355
+ const pkgJson = fs2.readJsonSync(packageJsonPath);
356
+ pkgJson.name = pkgJson.name === "test" || !pkgJson.name ? "agentmark-example-app" : pkgJson.name;
357
+ pkgJson.description = pkgJson.description || "A simple Node.js app using the Agentmark SDK";
358
+ const devScript = "agentmark dev";
359
+ const scripts = {
360
+ ...pkgJson.scripts,
361
+ "demo": "npx tsx index.ts",
362
+ "dev": devScript,
363
+ "prompt": "agentmark run-prompt",
364
+ "experiment": "agentmark run-experiment"
365
+ };
366
+ if (deploymentMode === "static") {
367
+ scripts["build"] = "agentmark build --out dist/agentmark";
368
+ }
369
+ pkgJson.scripts = scripts;
370
+ pkgJson.overrides = {
371
+ ...pkgJson.overrides,
372
+ "axios": "^1.7.9"
373
+ };
374
+ fs2.writeJsonSync(packageJsonPath, pkgJson, { spaces: 2 });
168
375
  }
169
- pkgJson.scripts = scripts;
170
- pkgJson.overrides = {
171
- ...pkgJson.overrides,
172
- "axios": "^1.7.9"
173
- };
174
- fs.writeJsonSync(packageJsonPath, pkgJson, { spaces: 2 });
175
376
  };
176
- var installDependencies = (modelProvider, targetPath = ".", adapter = "ai-sdk", deploymentMode = "cloud") => {
377
+ var installDependencies = (modelProvider, targetPath = ".", adapter = "ai-sdk", deploymentMode = "cloud", packageManager = null) => {
177
378
  console.log("Installing required packages...");
178
379
  console.log("This might take a moment...");
179
380
  const adapterConfig = getAdapterConfig(adapter, modelProvider);
381
+ const pm = packageManager || DEFAULT_PACKAGE_MANAGER;
382
+ const npmSuffix = pm.name === "npm" ? " --legacy-peer-deps" : "";
180
383
  try {
181
- const devDepsCmd = "npm install --save-dev typescript ts-node @types/node @agentmark-ai/cli --legacy-peer-deps";
384
+ const devDeps = ["typescript", "ts-node", "@types/node", "@agentmark-ai/cli"];
385
+ const devDepsCmd = `${pm.addDevCmd} ${devDeps.join(" ")}${npmSuffix}`;
386
+ console.log(`Using ${pm.name} to install dependencies...`);
182
387
  execSync(devDepsCmd, {
183
388
  stdio: "inherit",
184
389
  cwd: targetPath
185
390
  });
186
391
  const loaderPackages = deploymentMode === "static" ? ["@agentmark-ai/loader-api", "@agentmark-ai/loader-file"] : ["@agentmark-ai/loader-api"];
187
- const installArgs = [
188
- "install",
392
+ const deps = [
189
393
  "dotenv",
190
394
  "@agentmark-ai/prompt-core",
191
395
  "@agentmark-ai/sdk",
192
396
  adapterConfig.package,
193
397
  ...loaderPackages,
194
- ...adapterConfig.dependencies,
195
- "--legacy-peer-deps"
398
+ ...adapterConfig.dependencies
196
399
  ];
197
- execFileSync("npm", installArgs, { stdio: "inherit", cwd: targetPath });
400
+ const depsCmd = `${pm.addCmd} ${deps.join(" ")}${npmSuffix}`;
401
+ execSync(depsCmd, { stdio: "inherit", cwd: targetPath });
198
402
  console.log("Packages installed successfully!");
199
403
  } catch (error) {
200
404
  console.error("Error installing packages:", error);
@@ -368,28 +572,32 @@ var getStoryDataset = () => {
368
572
  };
369
573
 
370
574
  // src/utils/examples/templates/example-prompts.ts
371
- import fs2 from "fs-extra";
575
+ import fs3 from "fs-extra";
372
576
  var createExamplePrompts = (model, targetPath = ".", adapter = "ai-sdk") => {
373
- fs2.ensureDirSync(`${targetPath}/agentmark`);
374
- if (adapter !== "mastra") {
577
+ fs3.ensureDirSync(`${targetPath}/agentmark`);
578
+ const noImageSupport = ["mastra", "claude-agent-sdk"];
579
+ const noSpeechSupport = ["mastra", "claude-agent-sdk"];
580
+ const skipImagePrompts = noImageSupport.includes(adapter);
581
+ const skipSpeechPrompts = noSpeechSupport.includes(adapter);
582
+ if (!skipImagePrompts) {
375
583
  const animalDrawingPrompt = getAnimalDrawingPrompt();
376
- fs2.writeFileSync(`${targetPath}/agentmark/animal-drawing.prompt.mdx`, animalDrawingPrompt);
584
+ fs3.writeFileSync(`${targetPath}/agentmark/animal-drawing.prompt.mdx`, animalDrawingPrompt);
377
585
  const animalDataset = getAnimalDataset();
378
- fs2.writeFileSync(`${targetPath}/agentmark/animal.jsonl`, animalDataset);
586
+ fs3.writeFileSync(`${targetPath}/agentmark/animal.jsonl`, animalDataset);
379
587
  }
380
588
  const customerSupportPrompt = getCustomerSupportPrompt(model);
381
- fs2.writeFileSync(`${targetPath}/agentmark/customer-support-agent.prompt.mdx`, customerSupportPrompt);
589
+ fs3.writeFileSync(`${targetPath}/agentmark/customer-support-agent.prompt.mdx`, customerSupportPrompt);
382
590
  const customerQueryDataset = getCustomerQueryDataset();
383
- fs2.writeFileSync(`${targetPath}/agentmark/customer-query.jsonl`, customerQueryDataset);
591
+ fs3.writeFileSync(`${targetPath}/agentmark/customer-query.jsonl`, customerQueryDataset);
384
592
  const partyPlannerPrompt = getPartyPlannerPrompt(model);
385
- fs2.writeFileSync(`${targetPath}/agentmark/party-planner.prompt.mdx`, partyPlannerPrompt);
593
+ fs3.writeFileSync(`${targetPath}/agentmark/party-planner.prompt.mdx`, partyPlannerPrompt);
386
594
  const partyDataset = getPartyDataset();
387
- fs2.writeFileSync(`${targetPath}/agentmark/party.jsonl`, partyDataset);
388
- if (adapter !== "mastra") {
595
+ fs3.writeFileSync(`${targetPath}/agentmark/party.jsonl`, partyDataset);
596
+ if (!skipSpeechPrompts) {
389
597
  const storyTellerPrompt = getStoryTellerPrompt();
390
- fs2.writeFileSync(`${targetPath}/agentmark/story-teller.prompt.mdx`, storyTellerPrompt);
598
+ fs3.writeFileSync(`${targetPath}/agentmark/story-teller.prompt.mdx`, storyTellerPrompt);
391
599
  const storyDataset = getStoryDataset();
392
- fs2.writeFileSync(`${targetPath}/agentmark/story.jsonl`, storyDataset);
600
+ fs3.writeFileSync(`${targetPath}/agentmark/story.jsonl`, storyDataset);
393
601
  }
394
602
  };
395
603
 
@@ -398,8 +606,9 @@ var getClientConfigContent = (options) => {
398
606
  const { provider, languageModels, adapter, deploymentMode = "cloud" } = options;
399
607
  const adapterConfig = getAdapterConfig(adapter, provider);
400
608
  const { modelRegistry, toolRegistry } = adapterConfig.classes;
401
- const providerImport = `import { ${provider} } from '@ai-sdk/${provider}';`;
402
- const extraModelRegs = provider === "openai" ? `.registerModels(["dall-e-3"], (name: string) => ${provider}.image(name))
609
+ const isClaudeAgentSdk = adapter === "claude-agent-sdk";
610
+ const providerImport = isClaudeAgentSdk ? "" : `import { ${provider} } from '@ai-sdk/${provider}';`;
611
+ const extraModelRegs = provider === "openai" && !isClaudeAgentSdk ? `.registerModels(["dall-e-3"], (name: string) => ${provider}.image(name))
403
612
  .registerModels(["tts-1-hd"], (name: string) => ${provider}.speech(name))` : "";
404
613
  const loaderImport = deploymentMode === "cloud" ? `import { ApiLoader } from "@agentmark-ai/loader-api";` : `import { ApiLoader } from "@agentmark-ai/loader-api";
405
614
  import { FileLoader } from "@agentmark-ai/loader-file";`;
@@ -414,6 +623,51 @@ import { FileLoader } from "@agentmark-ai/loader-file";`;
414
623
  });` : ` const loader = process.env.NODE_ENV === 'development'
415
624
  ? ApiLoader.local({ baseUrl: process.env.AGENTMARK_BASE_URL || 'http://localhost:9418' })
416
625
  : new FileLoader('./dist/agentmark');`;
626
+ const modelRegistrySetup = isClaudeAgentSdk ? `function createModelRegistry() {
627
+ // Claude Agent SDK accepts model names directly.
628
+ // Use createDefault() for simple pass-through of model names.
629
+ const modelRegistry = ${modelRegistry}.createDefault();
630
+
631
+ // To configure specific models (e.g., extended thinking), use:
632
+ // const modelRegistry = new ${modelRegistry}()
633
+ // .registerModels(/claude-.*-thinking/, (name) => ({
634
+ // model: name,
635
+ // maxThinkingTokens: 10000, // Enable extended thinking
636
+ // }))
637
+ // .registerModels("claude-sonnet-4-20250514", (name) => ({ model: name }));
638
+
639
+ return modelRegistry;
640
+ }` : `function createModelRegistry() {
641
+ const modelRegistry = new ${modelRegistry}()
642
+ .registerModels(${JSON.stringify(languageModels)}, (name: string) => ${provider}(name))
643
+ ${extraModelRegs};
644
+ return modelRegistry;
645
+ }`;
646
+ const adapterOptionsImport = isClaudeAgentSdk ? `
647
+ // Claude Agent SDK adapter options
648
+ // See: https://github.com/anthropics/claude-agent-sdk
649
+ const adapterOptions = {
650
+ // Permission mode controls tool access:
651
+ // - 'default': Requires user approval for each tool use
652
+ // - 'acceptEdits': Auto-approve file edits only
653
+ // - 'bypassPermissions': Auto-approve all tools (use for automated pipelines)
654
+ // - 'plan': Planning mode only, no tool execution
655
+ permissionMode: 'bypassPermissions' as const,
656
+
657
+ // Maximum conversation turns before stopping
658
+ maxTurns: 20,
659
+
660
+ // Optional: Set working directory for file operations
661
+ // cwd: process.cwd(),
662
+
663
+ // Optional: Budget limit in USD
664
+ // maxBudgetUsd: 10.00,
665
+
666
+ // Optional: Restrict which tools the agent can use
667
+ // allowedTools: ['Read', 'Write', 'Glob'],
668
+ // disallowedTools: ['Bash'],
669
+ };` : "";
670
+ const createClientCall = isClaudeAgentSdk ? `return createAgentMarkClient<AgentMarkTypes, typeof toolRegistry>({ loader, modelRegistry, toolRegistry, evalRegistry, adapterOptions });` : `return createAgentMarkClient<AgentMarkTypes, typeof toolRegistry>({ loader, modelRegistry, toolRegistry, evalRegistry });`;
417
671
  return `// agentmark.client.ts
418
672
  import path from 'node:path';
419
673
  import dotenv from 'dotenv';
@@ -422,13 +676,9 @@ import { createAgentMarkClient, ${modelRegistry}, ${toolRegistry}, EvalRegistry
422
676
  ${loaderImport}
423
677
  import AgentMarkTypes, { Tools } from './agentmark.types';
424
678
  ${providerImport}
679
+ ${adapterOptionsImport}
425
680
 
426
- function createModelRegistry() {
427
- const modelRegistry = new ${modelRegistry}()
428
- .registerModels(${JSON.stringify(languageModels)}, (name: string) => ${provider}(name))
429
- ${extraModelRegs};
430
- return modelRegistry;
431
- }
681
+ ${modelRegistrySetup}
432
682
 
433
683
  function createToolRegistry() {
434
684
  const toolRegistry = new ${toolRegistry}<Tools>()
@@ -475,7 +725,7 @@ ${loaderSetup}
475
725
  const modelRegistry = createModelRegistry();
476
726
  const toolRegistry = createToolRegistry();
477
727
  const evalRegistry = createEvalRegistry();
478
- return createAgentMarkClient<AgentMarkTypes, typeof toolRegistry>({ loader, modelRegistry, toolRegistry, evalRegistry });
728
+ ${createClientCall}
479
729
  }
480
730
 
481
731
  export const client = createClient();