create-agentmark 0.3.0 → 0.4.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.
Files changed (65) hide show
  1. package/dist/index.d.ts +2 -3
  2. package/dist/index.js +787 -51
  3. package/dist/index.js.map +1 -1
  4. package/dist/utils/examples/templates/index.d.ts +47 -13
  5. package/dist/utils/examples/templates/index.js +504 -12
  6. package/dist/utils/examples/templates/index.js.map +1 -1
  7. package/package.json +3 -2
  8. package/dist/index.d.ts.map +0 -1
  9. package/dist/utils/examples/create-example-app.d.ts +0 -2
  10. package/dist/utils/examples/create-example-app.d.ts.map +0 -1
  11. package/dist/utils/examples/create-example-app.js +0 -243
  12. package/dist/utils/examples/create-example-app.js.map +0 -1
  13. package/dist/utils/examples/templates/adapters.d.ts +0 -15
  14. package/dist/utils/examples/templates/adapters.d.ts.map +0 -1
  15. package/dist/utils/examples/templates/adapters.js +0 -28
  16. package/dist/utils/examples/templates/adapters.js.map +0 -1
  17. package/dist/utils/examples/templates/animal-drawing-prompt.d.ts +0 -2
  18. package/dist/utils/examples/templates/animal-drawing-prompt.d.ts.map +0 -1
  19. package/dist/utils/examples/templates/animal-drawing-prompt.js +0 -19
  20. package/dist/utils/examples/templates/animal-drawing-prompt.js.map +0 -1
  21. package/dist/utils/examples/templates/app-index.d.ts +0 -2
  22. package/dist/utils/examples/templates/app-index.d.ts.map +0 -1
  23. package/dist/utils/examples/templates/app-index.js +0 -95
  24. package/dist/utils/examples/templates/app-index.js.map +0 -1
  25. package/dist/utils/examples/templates/customer-support-prompt.d.ts +0 -2
  26. package/dist/utils/examples/templates/customer-support-prompt.d.ts.map +0 -1
  27. package/dist/utils/examples/templates/customer-support-prompt.js +0 -40
  28. package/dist/utils/examples/templates/customer-support-prompt.js.map +0 -1
  29. package/dist/utils/examples/templates/datasets.d.ts +0 -5
  30. package/dist/utils/examples/templates/datasets.d.ts.map +0 -1
  31. package/dist/utils/examples/templates/datasets.js +0 -21
  32. package/dist/utils/examples/templates/datasets.js.map +0 -1
  33. package/dist/utils/examples/templates/env.d.ts +0 -2
  34. package/dist/utils/examples/templates/env.d.ts.map +0 -1
  35. package/dist/utils/examples/templates/env.js +0 -12
  36. package/dist/utils/examples/templates/env.js.map +0 -1
  37. package/dist/utils/examples/templates/example-prompts.d.ts +0 -2
  38. package/dist/utils/examples/templates/example-prompts.d.ts.map +0 -1
  39. package/dist/utils/examples/templates/example-prompts.js +0 -35
  40. package/dist/utils/examples/templates/example-prompts.js.map +0 -1
  41. package/dist/utils/examples/templates/index.d.ts.map +0 -1
  42. package/dist/utils/examples/templates/package-setup.d.ts +0 -3
  43. package/dist/utils/examples/templates/package-setup.d.ts.map +0 -1
  44. package/dist/utils/examples/templates/package-setup.js +0 -61
  45. package/dist/utils/examples/templates/package-setup.js.map +0 -1
  46. package/dist/utils/examples/templates/party-planner-prompt.d.ts +0 -2
  47. package/dist/utils/examples/templates/party-planner-prompt.d.ts.map +0 -1
  48. package/dist/utils/examples/templates/party-planner-prompt.js +0 -40
  49. package/dist/utils/examples/templates/party-planner-prompt.js.map +0 -1
  50. package/dist/utils/examples/templates/story-teller-prompt.d.ts +0 -2
  51. package/dist/utils/examples/templates/story-teller-prompt.d.ts.map +0 -1
  52. package/dist/utils/examples/templates/story-teller-prompt.js +0 -23
  53. package/dist/utils/examples/templates/story-teller-prompt.js.map +0 -1
  54. package/dist/utils/examples/templates/tsconfig.d.ts +0 -2
  55. package/dist/utils/examples/templates/tsconfig.d.ts.map +0 -1
  56. package/dist/utils/examples/templates/tsconfig.js +0 -14
  57. package/dist/utils/examples/templates/tsconfig.js.map +0 -1
  58. package/dist/utils/examples/templates/user-client-config.d.ts +0 -6
  59. package/dist/utils/examples/templates/user-client-config.d.ts.map +0 -1
  60. package/dist/utils/examples/templates/user-client-config.js +0 -85
  61. package/dist/utils/examples/templates/user-client-config.js.map +0 -1
  62. package/dist/utils/providers.d.ts +0 -9
  63. package/dist/utils/providers.d.ts.map +0 -1
  64. package/dist/utils/providers.js +0 -16
  65. package/dist/utils/providers.js.map +0 -1
package/dist/index.js CHANGED
@@ -1,61 +1,797 @@
1
1
  #!/usr/bin/env node
2
- import fs from "fs-extra";
2
+
3
+ // src/index.ts
4
+ import fs4 from "fs-extra";
3
5
  import prompts from "prompts";
4
- import { createExampleApp } from "./utils/examples/create-example-app";
6
+
7
+ // src/utils/examples/create-example-app.ts
8
+ import fs3 from "fs-extra";
9
+ import * as path from "path";
10
+
11
+ // src/utils/providers.ts
12
+ var Providers = {
13
+ openai: {
14
+ label: "OpenAI",
15
+ languageModels: [
16
+ "gpt-4o",
17
+ "gpt-4o-mini",
18
+ "gpt-4",
19
+ "gpt-5",
20
+ "gpt-4-turbo",
21
+ "gpt-3.5-turbo"
22
+ ],
23
+ imageModels: ["dall-e-3", "dall-e-2"],
24
+ speechModels: ["tts-1", "tts-1-hd"]
25
+ }
26
+ };
27
+
28
+ // src/utils/examples/templates/adapters.ts
29
+ var createAdapterConfig = (provider) => {
30
+ return {
31
+ "ai-sdk": {
32
+ package: "@agentmark/ai-sdk-v5-adapter",
33
+ dependencies: ["ai@^5", `@ai-sdk/${provider}@^2`],
34
+ classes: {
35
+ modelRegistry: "VercelAIModelRegistry",
36
+ toolRegistry: "VercelAIToolRegistry",
37
+ webhookHandler: "VercelAdapterWebhookHandler"
38
+ }
39
+ },
40
+ mastra: {
41
+ package: "@agentmark/mastra-v0-adapter",
42
+ dependencies: [
43
+ "@mastra/core@<0.20.0",
44
+ "@mastra/mcp@<0.13.4",
45
+ `@ai-sdk/${provider}@<2`
46
+ ],
47
+ classes: {
48
+ modelRegistry: "MastraModelRegistry",
49
+ toolRegistry: "MastraToolRegistry",
50
+ webhookHandler: "MastraAdapterWebhookHandler"
51
+ }
52
+ }
53
+ };
54
+ };
55
+ function getAdapterConfig(adapter, provider) {
56
+ const config = createAdapterConfig(provider)[adapter];
57
+ if (!config) {
58
+ throw new Error(
59
+ `Unknown adapter: ${adapter}. Available adapters: ${Object.keys(
60
+ createAdapterConfig(provider)
61
+ ).join(", ")}`
62
+ );
63
+ }
64
+ return config;
65
+ }
66
+
67
+ // src/utils/examples/templates/app-index.ts
68
+ var getIndexFileContent = (adapter = "ai-sdk") => {
69
+ if (adapter === "mastra") {
70
+ return `import "dotenv/config";
71
+ import { Agent } from "@mastra/core/agent";
72
+ import { client } from "./agentmark.client";
73
+
74
+ const telemetry = {
75
+ isEnabled: true,
76
+ metadata: {
77
+ traceId: "trace-123",
78
+ traceName: "customer-support",
79
+ userId: "user-123",
80
+ sessionId: "session-123",
81
+ sessionName: "my-first-session",
82
+ },
83
+ };
84
+
85
+ const runCustomerSupport = async (customer_message: string) => {
86
+ const prompt = await client.loadTextPrompt("customer-support-agent");
87
+ const agentConfig = await prompt.formatAgent({
88
+ options: {
89
+ telemetry,
90
+ },
91
+ });
92
+
93
+ const [messages, generateOptions] = await agentConfig.formatMessages({
94
+ props: {
95
+ customer_question: customer_message,
96
+ },
97
+ });
98
+
99
+ const agent = new Agent(agentConfig);
100
+ const response = await agent.generate(messages, generateOptions);
101
+
102
+ return (response as any).text || (response as any).content || String(response);
103
+ };
104
+
5
105
  const main = async () => {
6
- const config = {
7
- $schema: "https://raw.githubusercontent.com/agentmark-ai/agentmark/refs/heads/main/packages/cli/agentmark.schema.json",
8
- version: "2.0.0",
9
- mdxVersion: "1.0",
10
- agentmarkPath: ".",
11
- };
12
- console.log("Initializing project.");
13
- const { folderName } = await prompts({
14
- name: "folderName",
15
- type: "text",
16
- message: "Where would you like to create your AgentMark app?",
17
- initial: "my-agentmark-app",
18
- });
19
- // Create the target folder
20
- const targetPath = `./${folderName}`;
21
- fs.ensureDirSync(targetPath);
22
- config.builtInModels = ['gpt-4o'];
23
- // Prompt only for the OpenAI API key
24
- let apiKey = "";
25
- const { providedApiKey } = await prompts({
26
- name: "providedApiKey",
27
- type: "password",
28
- message: `Enter your OpenAI API key (or press Enter to skip):`,
29
- initial: "",
106
+ try {
107
+ const user_message = "How long does shipping take?";
108
+ const assistant = await runCustomerSupport(user_message);
109
+ console.log("Customer support response:", assistant);
110
+ } catch (error) {
111
+ console.error(error);
112
+ }
113
+ };
114
+
115
+ main();
116
+ `;
117
+ } else {
118
+ return `import "dotenv/config";
119
+ import { generateText } from "ai";
120
+ import { client } from "./agentmark.client";
121
+
122
+ const telemetry = {
123
+ isEnabled: true,
124
+ metadata: {
125
+ traceId: "trace-123",
126
+ traceName: "customer-support",
127
+ userId: "user-123",
128
+ sessionId: "session-123",
129
+ sessionName: "my-first-session",
130
+ },
131
+ };
132
+
133
+ const runCustomerSupport = async (customer_message: string) => {
134
+ const prompt = await client.loadTextPrompt("customer-support-agent");
135
+ const vercelInput = await prompt.format({
136
+ props: {
137
+ customer_question: customer_message,
138
+ },
139
+ telemetry,
140
+ });
141
+
142
+ const resp = await generateText(vercelInput);
143
+
144
+ return resp.text;
145
+ };
146
+
147
+ const main = async () => {
148
+ try {
149
+ const user_message = "How long does shipping take?";
150
+ const assistant = await runCustomerSupport(user_message);
151
+ console.log("Customer support response:", assistant);
152
+ } catch (error) {
153
+ console.error(error);
154
+ }
155
+ };
156
+
157
+ main();
158
+ `;
159
+ }
160
+ };
161
+
162
+ // src/utils/examples/templates/env.ts
163
+ var getEnvFileContent = (_modelProvider, apiKey = "") => {
164
+ const apiKeyValue = apiKey || "your_api_key_here";
165
+ return `# Cloud deployment: Set these environment variables
166
+ # AGENTMARK_BASE_URL=https://api.agentmark.co
167
+ # AGENTMARK_API_KEY=your_agentmark_api_key
168
+ # AGENTMARK_APP_ID=your_agentmark_app_id
169
+ # Learn more: https://docs.agentmark.co/platform/getting_started/quickstart
170
+
171
+ OPENAI_API_KEY=${apiKeyValue}
172
+ `;
173
+ };
174
+
175
+ // src/utils/examples/templates/package-setup.ts
176
+ import fs from "fs-extra";
177
+ import { execSync, execFileSync } from "child_process";
178
+ var setupPackageJson = (targetPath = ".", deploymentMode = "cloud") => {
179
+ const packageJsonPath = `${targetPath}/package.json`;
180
+ if (!fs.existsSync(packageJsonPath)) {
181
+ console.log("Creating package.json...");
182
+ execSync("npm init -y", { cwd: targetPath });
183
+ }
184
+ const pkgJson = fs.readJsonSync(packageJsonPath);
185
+ pkgJson.name = pkgJson.name === "test" || !pkgJson.name ? "agentmark-example-app" : pkgJson.name;
186
+ pkgJson.description = pkgJson.description || "A simple Node.js app using the Agentmark SDK";
187
+ const devScript = "agentmark dev";
188
+ const scripts = {
189
+ ...pkgJson.scripts,
190
+ "demo": "npx tsx index.ts",
191
+ "dev": devScript,
192
+ "prompt": "agentmark run-prompt",
193
+ "experiment": "agentmark run-experiment"
194
+ };
195
+ if (deploymentMode === "static") {
196
+ scripts["build"] = "agentmark build --out dist/agentmark";
197
+ }
198
+ pkgJson.scripts = scripts;
199
+ pkgJson.overrides = {
200
+ ...pkgJson.overrides,
201
+ "axios": "^1.7.9"
202
+ };
203
+ fs.writeJsonSync(packageJsonPath, pkgJson, { spaces: 2 });
204
+ };
205
+ var installDependencies = (modelProvider, targetPath = ".", adapter = "ai-sdk", deploymentMode = "cloud") => {
206
+ console.log("Installing required packages...");
207
+ console.log("This might take a moment...");
208
+ const adapterConfig = getAdapterConfig(adapter, modelProvider);
209
+ try {
210
+ const devDepsCmd = "npm install --save-dev typescript ts-node @types/node @agentmark/cli --legacy-peer-deps";
211
+ execSync(devDepsCmd, {
212
+ stdio: "inherit",
213
+ cwd: targetPath
30
214
  });
31
- apiKey = providedApiKey || "";
32
- const { adapter } = await prompts({
33
- name: "adapter",
34
- type: "select",
35
- message: "Which adapter would you like to use?",
36
- choices: [
37
- { title: "AI SDK (Vercel)", value: "ai-sdk" },
38
- { title: "Mastra", value: "mastra" },
39
- ],
215
+ const loaderPackages = deploymentMode === "static" ? ["@agentmark/loader-api", "@agentmark/loader-file"] : ["@agentmark/loader-api"];
216
+ const installArgs = [
217
+ "install",
218
+ "dotenv",
219
+ "@agentmark/prompt-core",
220
+ "@agentmark/sdk",
221
+ adapterConfig.package,
222
+ ...loaderPackages,
223
+ ...adapterConfig.dependencies,
224
+ "--legacy-peer-deps"
225
+ ];
226
+ execFileSync("npm", installArgs, { stdio: "inherit", cwd: targetPath });
227
+ console.log("Packages installed successfully!");
228
+ } catch (error) {
229
+ console.error("Error installing packages:", error);
230
+ throw new Error(
231
+ "Failed to install required packages. Please check your network connection and try again."
232
+ );
233
+ }
234
+ };
235
+
236
+ // src/utils/examples/templates/tsconfig.ts
237
+ var getTsConfigContent = () => {
238
+ return {
239
+ "compilerOptions": {
240
+ "target": "ES2020",
241
+ "module": "NodeNext",
242
+ "moduleResolution": "NodeNext",
243
+ "esModuleInterop": true,
244
+ "forceConsistentCasingInFileNames": true,
245
+ "strict": true,
246
+ "skipLibCheck": true
247
+ }
248
+ };
249
+ };
250
+
251
+ // src/utils/examples/templates/animal-drawing-prompt.ts
252
+ var getAnimalDrawingPrompt = () => {
253
+ return `---
254
+ name: animal-drawing
255
+ image_config:
256
+ model_name: dall-e-3
257
+ num_images: 1
258
+ size: 1024x1024
259
+ aspect_ratio: 1:1
260
+ test_settings:
261
+ dataset: animal.jsonl
262
+ props:
263
+ animal: "cat"
264
+ ---
265
+
266
+ <ImagePrompt>
267
+ Draw a hyper-realistic picture of a {props.animal}
268
+ </ImagePrompt>`;
269
+ };
270
+
271
+ // src/utils/examples/templates/customer-support-prompt.ts
272
+ var getCustomerSupportPrompt = (model) => {
273
+ return `---
274
+ name: customer-support-agent
275
+ text_config:
276
+ model_name: ${model}
277
+ max_calls: 2
278
+ tools:
279
+ search_knowledgebase:
280
+ description: Search the company knowledgebase for information about shipping, warranty, and returns policies.
281
+ parameters:
282
+ type: object
283
+ properties:
284
+ query:
285
+ type: string
286
+ description: The search query to find relevant information
287
+ required: [query]
288
+ test_settings:
289
+ dataset: customer-query.jsonl
290
+ props:
291
+ customer_question: "I'm having trouble with my order. How long does shipping take?"
292
+ input_schema:
293
+ type: object
294
+ properties:
295
+ customer_question:
296
+ type: string
297
+ description: "The customer's question"
298
+ required:
299
+ - customer_question
300
+ ---
301
+
302
+ <System>
303
+ 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.
304
+
305
+ You have access to the following tool:
306
+ - search_knowledgebase: Search the company knowledgebase for information about shipping, warranty, and returns. Use this when customers ask about these topics.
307
+ </System>
308
+
309
+ <User>{props.customer_question}</User>`;
310
+ };
311
+
312
+ // src/utils/examples/templates/party-planner-prompt.ts
313
+ var getPartyPlannerPrompt = (model) => {
314
+ return `---
315
+ name: party-planner
316
+ object_config:
317
+ model_name: ${model}
318
+ schema:
319
+ type: object
320
+ properties:
321
+ names:
322
+ type: array
323
+ description: "List of names of people attending the party."
324
+ items:
325
+ type: string
326
+ required:
327
+ - names
328
+ test_settings:
329
+ dataset: party.jsonl
330
+ evals:
331
+ - exact_match_json
332
+ props:
333
+ party_text: "We're having a party with Alice, Bob, and Carol."
334
+ input_schema:
335
+ type: object
336
+ properties:
337
+ party_text:
338
+ type: string
339
+ description: "A block of text describing the upcoming party and attendees."
340
+ required:
341
+ - party_text
342
+ ---
343
+
344
+ <System>
345
+ Extract the names of all people attending the party from the following text. Respond with a list of names only.
346
+ </System>
347
+
348
+ <User>
349
+ Text: {props.party_text}
350
+ </User>`;
351
+ };
352
+
353
+ // src/utils/examples/templates/story-teller-prompt.ts
354
+ var getStoryTellerPrompt = () => {
355
+ return `---
356
+ name: story-teller
357
+ speech_config:
358
+ model_name: tts-1-hd
359
+ voice: "nova"
360
+ speed: 1.0
361
+ output_format: "mp3"
362
+ test_settings:
363
+ dataset: story.jsonl
364
+ props:
365
+ story: "Once upon a time, there was a cat who loved to play with a ball."
366
+ ---
367
+
368
+ <System>
369
+ You are a storyteller for children. Make sure your story is engaging and interesting.
370
+ </System>
371
+
372
+ <SpeechPrompt>
373
+ - {props.story}
374
+ </SpeechPrompt>`;
375
+ };
376
+
377
+ // src/utils/examples/templates/datasets.ts
378
+ var getAnimalDataset = () => {
379
+ return `{"input": {"animal": "cat"}, "expected_output": "A realistic picture of a cat"}
380
+ {"input": {"animal": "dog"}, "expected_output": "A realistic picture of a dog"}
381
+ {"input": {"animal": "bird"}, "expected_output": "A realistic picture of a bird"}`;
382
+ };
383
+ var getCustomerQueryDataset = () => {
384
+ return `{"input": {"customer_question": "My package hasn't arrived yet. Can you help me track it?"}}
385
+ {"input": {"customer_question": "I received the wrong item in my order. What should I do?"}}
386
+ {"input": {"customer_question": "How do I return a product that I purchased last week?"}}`;
387
+ };
388
+ var getPartyDataset = () => {
389
+ return `{"input": {"party_text": "We're having a party with Alice, Bob, and Carol."}, "expected_output": "{\\"names\\": [\\"Alice\\", \\"Bob\\", \\"Carol\\"]}"}
390
+ {"input": {"party_text": "The guest list includes Dave, Emma, and Frank."}, "expected_output": "{\\"names\\": [\\"Dave\\", \\"Emma\\", \\"Frank\\"]}"}
391
+ {"input": {"party_text": "Join us for a celebration with Grace, Henry, and Isla."}, "expected_output": "{\\"names\\": [\\"Grace\\", \\"Henry\\", \\"Isla\\"]}"}`;
392
+ };
393
+ var getStoryDataset = () => {
394
+ 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."}}
395
+ {"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."}}
396
+ {"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."}}`;
397
+ };
398
+
399
+ // src/utils/examples/templates/example-prompts.ts
400
+ import fs2 from "fs-extra";
401
+ var createExamplePrompts = (model, targetPath = ".", adapter = "ai-sdk") => {
402
+ fs2.ensureDirSync(`${targetPath}/agentmark`);
403
+ if (adapter !== "mastra") {
404
+ const animalDrawingPrompt = getAnimalDrawingPrompt();
405
+ fs2.writeFileSync(`${targetPath}/agentmark/animal-drawing.prompt.mdx`, animalDrawingPrompt);
406
+ const animalDataset = getAnimalDataset();
407
+ fs2.writeFileSync(`${targetPath}/agentmark/animal.jsonl`, animalDataset);
408
+ }
409
+ const customerSupportPrompt = getCustomerSupportPrompt(model);
410
+ fs2.writeFileSync(`${targetPath}/agentmark/customer-support-agent.prompt.mdx`, customerSupportPrompt);
411
+ const customerQueryDataset = getCustomerQueryDataset();
412
+ fs2.writeFileSync(`${targetPath}/agentmark/customer-query.jsonl`, customerQueryDataset);
413
+ const partyPlannerPrompt = getPartyPlannerPrompt(model);
414
+ fs2.writeFileSync(`${targetPath}/agentmark/party-planner.prompt.mdx`, partyPlannerPrompt);
415
+ const partyDataset = getPartyDataset();
416
+ fs2.writeFileSync(`${targetPath}/agentmark/party.jsonl`, partyDataset);
417
+ if (adapter !== "mastra") {
418
+ const storyTellerPrompt = getStoryTellerPrompt();
419
+ fs2.writeFileSync(`${targetPath}/agentmark/story-teller.prompt.mdx`, storyTellerPrompt);
420
+ const storyDataset = getStoryDataset();
421
+ fs2.writeFileSync(`${targetPath}/agentmark/story.jsonl`, storyDataset);
422
+ }
423
+ };
424
+
425
+ // src/utils/examples/templates/user-client-config.ts
426
+ var getClientConfigContent = (options) => {
427
+ const { provider, languageModels, adapter, deploymentMode = "cloud" } = options;
428
+ const adapterConfig = getAdapterConfig(adapter, provider);
429
+ const { modelRegistry, toolRegistry } = adapterConfig.classes;
430
+ const providerImport = `import { ${provider} } from '@ai-sdk/${provider}';`;
431
+ const extraModelRegs = provider === "openai" ? `.registerModels(["dall-e-3"], (name: string) => ${provider}.image(name))
432
+ .registerModels(["tts-1-hd"], (name: string) => ${provider}.speech(name))` : "";
433
+ const loaderImport = deploymentMode === "cloud" ? `import { ApiLoader } from "@agentmark/loader-api";` : `import { ApiLoader } from "@agentmark/loader-api";
434
+ import { FileLoader } from "@agentmark/loader-file";`;
435
+ const loaderSetup = deploymentMode === "cloud" ? ` // ApiLoader works for both development and production
436
+ // - Development: 'agentmark dev' sets AGENTMARK_BASE_URL to localhost
437
+ // - Production: Set AGENTMARK_API_KEY and AGENTMARK_APP_ID for cloud
438
+ const loader = process.env.NODE_ENV === 'development'
439
+ ? ApiLoader.local({ baseUrl: process.env.AGENTMARK_BASE_URL || 'http://localhost:9418' })
440
+ : ApiLoader.cloud({
441
+ apiKey: process.env.AGENTMARK_API_KEY!,
442
+ appId: process.env.AGENTMARK_APP_ID!,
443
+ });` : ` const loader = process.env.NODE_ENV === 'development'
444
+ ? ApiLoader.local({ baseUrl: process.env.AGENTMARK_BASE_URL || 'http://localhost:9418' })
445
+ : new FileLoader('./dist/agentmark');`;
446
+ return `// agentmark.client.ts
447
+ import path from 'node:path';
448
+ import dotenv from 'dotenv';
449
+ dotenv.config({ path: path.resolve(__dirname, '.env') });
450
+ import { createAgentMarkClient, ${modelRegistry}, ${toolRegistry}, EvalRegistry } from "${adapterConfig.package}";
451
+ ${loaderImport}
452
+ import AgentMarkTypes, { Tools } from './agentmark.types';
453
+ ${providerImport}
454
+
455
+ function createModelRegistry() {
456
+ const modelRegistry = new ${modelRegistry}()
457
+ .registerModels(${JSON.stringify(languageModels)}, (name: string) => ${provider}(name))
458
+ ${extraModelRegs};
459
+ return modelRegistry;
460
+ }
461
+
462
+ function createToolRegistry() {
463
+ const toolRegistry = new ${toolRegistry}<Tools>()
464
+ .register('search_knowledgebase', async ({ query }) => {
465
+ // Simulate search delay
466
+ await new Promise(resolve => setTimeout(resolve, 500));
467
+
468
+ // Return all three knowledge base articles
469
+ // The LLM will select the relevant one based on the query
470
+ return {
471
+ articles: [
472
+ { topic: 'shipping', content: 'Standard shipping takes 3\u20135 business days.' },
473
+ { topic: 'warranty', content: 'All products include a 1-year limited warranty.' },
474
+ { topic: 'returns', content: 'You can return items within 30 days of delivery.' }
475
+ ]
476
+ };
40
477
  });
41
- const { client } = await prompts({
42
- name: "client",
43
- type: "select",
44
- message: "Make your IDE an AgentMark expert",
45
- choices: [
46
- { title: "Claude Code", value: "claude-code" },
47
- { title: "Cursor", value: "cursor" },
48
- { title: "VS Code", value: "vscode" },
49
- { title: "Zed", value: "zed" },
50
- { title: "Skip", value: "skip" },
51
- ],
478
+ return toolRegistry;
479
+ }
480
+
481
+ function createEvalRegistry() {
482
+ const evalRegistry = new EvalRegistry()
483
+ .register('exact_match_json', ({ output, expectedOutput }) => {
484
+ if (!expectedOutput) {
485
+ return { score: 0, label: 'error', reason: 'No expected output provided', passed: false };
486
+ }
487
+ try {
488
+ const ok = JSON.stringify(output) === JSON.stringify(JSON.parse(expectedOutput));
489
+ return {
490
+ score: ok ? 1 : 0,
491
+ label: ok ? 'correct' : 'incorrect',
492
+ reason: ok ? 'Exact match' : 'Mismatch',
493
+ passed: ok
494
+ };
495
+ } catch (e) {
496
+ return { score: 0, label: 'error', reason: 'Failed to parse expected output as JSON', passed: false };
497
+ }
52
498
  });
53
- await createExampleApp(client, targetPath, apiKey, adapter);
54
- // Always generate agentmark.json so config is consistent
55
- fs.writeJsonSync(`${targetPath}/agentmark.json`, config, { spaces: 2 });
499
+ return evalRegistry;
500
+ }
501
+
502
+ function createClient() {
503
+ ${loaderSetup}
504
+ const modelRegistry = createModelRegistry();
505
+ const toolRegistry = createToolRegistry();
506
+ const evalRegistry = createEvalRegistry();
507
+ return createAgentMarkClient<AgentMarkTypes, typeof toolRegistry>({ loader, modelRegistry, toolRegistry, evalRegistry });
508
+ }
509
+
510
+ export const client = createClient();
511
+ `;
512
+ };
513
+
514
+ // src/utils/examples/create-example-app.ts
515
+ import { fetchPromptsFrontmatter, generateTypeDefinitions } from "@agentmark/shared-utils";
516
+ var setupMCPServer = (client, targetPath) => {
517
+ if (client === "skip") {
518
+ console.log("Skipping MCP server setup.");
519
+ return;
520
+ }
521
+ const folderName = targetPath;
522
+ if (client === "vscode") {
523
+ try {
524
+ console.log(`Setting up MCP server for VS Code in ${folderName}...`);
525
+ const vscodeDir = path.join(targetPath, ".vscode");
526
+ fs3.ensureDirSync(vscodeDir);
527
+ const mcpConfig = {
528
+ servers: {
529
+ "agentmark-docs": {
530
+ url: "https://docs.agentmark.co/mcp"
531
+ }
532
+ }
533
+ };
534
+ fs3.writeJsonSync(path.join(vscodeDir, "mcp.json"), mcpConfig, { spaces: 2 });
535
+ console.log(`\u2705 MCP server configured for VS Code in ${folderName}/.vscode/mcp.json`);
536
+ } catch (error) {
537
+ console.warn(`Warning: Could not set up MCP server for VS Code:`, error);
538
+ console.log("See https://docs.agentmark.co/agentmark/further_reference/agentmark-mcp for setup instructions.");
539
+ }
540
+ return;
541
+ }
542
+ if (client === "zed") {
543
+ try {
544
+ console.log(`Setting up MCP server for Zed in ${folderName}...`);
545
+ const zedDir = path.join(targetPath, ".zed");
546
+ fs3.ensureDirSync(zedDir);
547
+ const zedConfig = {
548
+ context_servers: {
549
+ "agentmark-docs": {
550
+ url: "https://docs.agentmark.co/mcp"
551
+ }
552
+ }
553
+ };
554
+ fs3.writeJsonSync(path.join(zedDir, "settings.json"), zedConfig, { spaces: 2 });
555
+ console.log(`\u2705 MCP server configured for Zed in ${folderName}/.zed/settings.json`);
556
+ } catch (error) {
557
+ console.warn(`Warning: Could not set up MCP server for Zed:`, error);
558
+ console.log("See https://docs.agentmark.co/agentmark/further_reference/agentmark-mcp for setup instructions.");
559
+ }
560
+ return;
561
+ }
562
+ if (client === "cursor") {
563
+ try {
564
+ console.log(`Setting up MCP server for Cursor in ${folderName}...`);
565
+ const cursorDir = path.join(targetPath, ".cursor");
566
+ fs3.ensureDirSync(cursorDir);
567
+ const cursorConfig = {
568
+ mcpServers: {
569
+ "agentmark-docs": {
570
+ url: "https://docs.agentmark.co/mcp"
571
+ }
572
+ }
573
+ };
574
+ fs3.writeJsonSync(path.join(cursorDir, "mcp.json"), cursorConfig, { spaces: 2 });
575
+ console.log(`\u2705 MCP server configured for Cursor in ${folderName}/.cursor/mcp.json`);
576
+ } catch (error) {
577
+ console.warn(`Warning: Could not set up MCP server for Cursor:`, error);
578
+ console.log("See https://docs.agentmark.co/agentmark/further_reference/agentmark-mcp for setup instructions.");
579
+ }
580
+ return;
581
+ }
582
+ if (client === "claude-code") {
583
+ try {
584
+ console.log(`Setting up MCP server for Claude Code in ${folderName}...`);
585
+ const mcpConfig = {
586
+ mcpServers: {
587
+ "agentmark-docs": {
588
+ type: "http",
589
+ url: "https://docs.agentmark.co/mcp"
590
+ }
591
+ }
592
+ };
593
+ fs3.writeJsonSync(path.join(targetPath, ".mcp.json"), mcpConfig, { spaces: 2 });
594
+ console.log(`\u2705 MCP server configured for Claude Code in ${folderName}/.mcp.json`);
595
+ } catch (error) {
596
+ console.warn(`Warning: Could not set up MCP server for Claude Code:`, error);
597
+ console.log("See https://docs.agentmark.co/agentmark/further_reference/agentmark-mcp for setup instructions.");
598
+ }
599
+ return;
600
+ }
601
+ };
602
+ var createExampleApp = async (client, targetPath = ".", apiKey = "", adapter = "ai-sdk", deploymentMode = "cloud") => {
603
+ try {
604
+ const modelProvider = "openai";
605
+ const model = "gpt-4o";
606
+ console.log("Creating Agent Mark example app...");
607
+ const folderName = targetPath;
608
+ fs3.ensureDirSync(`${targetPath}/agentmark`);
609
+ setupMCPServer(client, targetPath);
610
+ createExamplePrompts(model, targetPath, adapter);
611
+ console.log(`\u2705 Example prompts and datasets created in ${folderName}/agentmark/`);
612
+ const langModels = Providers[modelProvider].languageModels.slice(0, 1);
613
+ fs3.writeFileSync(
614
+ `${targetPath}/agentmark.client.ts`,
615
+ getClientConfigContent({ provider: modelProvider, languageModels: langModels, adapter, deploymentMode })
616
+ );
617
+ fs3.writeFileSync(`${targetPath}/.env`, getEnvFileContent(modelProvider, apiKey));
618
+ const gitignore = ["node_modules", ".env", "*.agentmark-outputs/", ".agentmark", "dist"].join("\n");
619
+ fs3.writeFileSync(`${targetPath}/.gitignore`, gitignore);
620
+ fs3.writeFileSync(
621
+ `${targetPath}/index.ts`,
622
+ getIndexFileContent(adapter)
623
+ );
624
+ fs3.writeJsonSync(`${targetPath}/tsconfig.json`, getTsConfigContent(), { spaces: 2 });
625
+ setupPackageJson(targetPath, deploymentMode);
626
+ installDependencies(modelProvider, targetPath, adapter, deploymentMode);
627
+ console.log("Generating types from prompts...");
628
+ try {
629
+ const agentmarkDir = path.join(targetPath, "agentmark");
630
+ const prompts2 = await fetchPromptsFrontmatter({ rootDir: agentmarkDir });
631
+ const typeDefinitions = await generateTypeDefinitions(prompts2);
632
+ fs3.writeFileSync(`${targetPath}/agentmark.types.ts`, typeDefinitions);
633
+ } catch (error) {
634
+ console.warn("Warning: Could not generate types automatically:", error);
635
+ console.log("You can generate types later by running: npx agentmark generate-types --root-dir agentmark");
636
+ fs3.writeFileSync(`${targetPath}/agentmark.types.ts`, `// Auto-generated types from AgentMark
637
+ // Run 'npx agentmark generate-types --root-dir agentmark' to generate types
638
+ export default interface AgentmarkTypes {}
639
+ `);
640
+ }
641
+ console.log("Creating development server entry point...");
642
+ const agentmarkInternalDir = path.join(targetPath, ".agentmark");
643
+ fs3.ensureDirSync(agentmarkInternalDir);
644
+ const adapterConfig = getAdapterConfig(adapter);
645
+ const { webhookHandler } = adapterConfig.classes;
646
+ const devEntryContent = `// Auto-generated webhook server entry point
647
+ // To customize, create a dev-server.ts file in your project root
648
+
649
+ import { createWebhookServer } from '@agentmark/cli/runner-server';
650
+ import { ${webhookHandler} } from '${adapterConfig.package}/runner';
651
+ import { AgentMarkSDK } from '@agentmark/sdk';
652
+ import path from 'path';
653
+
654
+ async function main() {
655
+ const args = process.argv.slice(2);
656
+ const webhookPortArg = args.find(arg => arg.startsWith('--webhook-port='));
657
+ const fileServerPortArg = args.find(arg => arg.startsWith('--file-server-port='));
658
+
659
+ const webhookPort = webhookPortArg ? parseInt(webhookPortArg.split('=')[1]) : 9417;
660
+ const fileServerPort = fileServerPortArg ? parseInt(fileServerPortArg.split('=')[1]) : 9418;
661
+ const fileServerUrl = \`http://localhost:\${fileServerPort}\`;
662
+
663
+ // Set environment for development mode before importing client
664
+ process.env.NODE_ENV = 'development';
665
+ process.env.AGENTMARK_BASE_URL = fileServerUrl;
666
+
667
+ // Now import client - it will pick up the dev environment
668
+ const { client } = await import('../agentmark.client.js');
669
+
670
+ // Initialize OpenTelemetry tracing to export traces to the API server
671
+ const sdk = new AgentMarkSDK({
672
+ apiKey: '',
673
+ appId: '',
674
+ baseUrl: fileServerUrl,
675
+ });
676
+ sdk.initTracing({ disableBatch: true });
677
+
678
+ const handler = new ${webhookHandler}(client as any);
679
+ const templatesDirectory = path.join(process.cwd(), 'agentmark');
680
+
681
+ await createWebhookServer({
682
+ port: webhookPort,
683
+ handler,
684
+ fileServerUrl,
685
+ templatesDirectory
686
+ });
687
+ }
688
+
689
+ main().catch((err) => {
690
+ console.error(err);
691
+ process.exit(1);
692
+ });
693
+ `;
694
+ fs3.writeFileSync(path.join(agentmarkInternalDir, "dev-entry.ts"), devEntryContent);
695
+ console.log("\n\u2705 Agentmark initialization completed successfully!");
696
+ console.log(
697
+ `
698
+ \u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557\u2588\u2588\u2588\u2557 \u2588\u2588\u2557\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557\u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2557 \u2588\u2588\u2557
699
+ \u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2557\u2588\u2588\u2554\u2550\u2550\u2550\u2550\u255D \u2588\u2588\u2554\u2550\u2550\u2550\u2550\u255D\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2551\u255A\u2550\u2550\u2588\u2588\u2554\u2550\u2550\u255D\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2588\u2551\u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2557\u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2557\u2588\u2588\u2551 \u2588\u2588\u2554\u255D
700
+ \u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2551\u2588\u2588\u2551 \u2588\u2588\u2588\u2557\u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2554\u2588\u2588\u2557 \u2588\u2588\u2551 \u2588\u2588\u2551 \u2588\u2588\u2554\u2588\u2588\u2588\u2588\u2554\u2588\u2588\u2551\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2551\u2588\u2588\u2588\u2588\u2588\u2588\u2554\u255D\u2588\u2588\u2588\u2588\u2588\u2554\u255D
701
+ \u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2551\u2588\u2588\u2551 \u2588\u2588\u2551\u2588\u2588\u2554\u2550\u2550\u255D \u2588\u2588\u2551\u255A\u2588\u2588\u2557\u2588\u2588\u2551 \u2588\u2588\u2551 \u2588\u2588\u2551\u255A\u2588\u2588\u2554\u255D\u2588\u2588\u2551\u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2551\u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2557\u2588\u2588\u2554\u2550\u2588\u2588\u2557
702
+ \u2588\u2588\u2551 \u2588\u2588\u2551\u255A\u2588\u2588\u2588\u2588\u2588\u2588\u2554\u255D\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557\u2588\u2588\u2551 \u255A\u2588\u2588\u2588\u2588\u2551 \u2588\u2588\u2551 \u2588\u2588\u2551 \u255A\u2550\u255D \u2588\u2588\u2551\u2588\u2588\u2551 \u2588\u2588\u2551\u2588\u2588\u2551 \u2588\u2588\u2551\u2588\u2588\u2551 \u2588\u2588\u2557
703
+ \u255A\u2550\u255D \u255A\u2550\u255D \u255A\u2550\u2550\u2550\u2550\u2550\u255D \u255A\u2550\u2550\u2550\u2550\u2550\u2550\u255D\u255A\u2550\u255D \u255A\u2550\u2550\u2550\u255D \u255A\u2550\u255D \u255A\u2550\u255D \u255A\u2550\u255D\u255A\u2550\u255D \u255A\u2550\u255D\u255A\u2550\u255D \u255A\u2550\u255D\u255A\u2550\u255D \u255A\u2550\u255D
704
+
705
+ `
706
+ );
707
+ console.log("\n" + "\u2550".repeat(70));
708
+ console.log("Next Steps");
709
+ console.log("\u2550".repeat(70));
710
+ console.log("\n Get Started:");
711
+ if (folderName !== "." && folderName !== "./") {
712
+ console.log(` $ cd ${folderName}`);
713
+ }
714
+ console.log(" $ npm run dev\n");
715
+ console.log("\u2500".repeat(70));
716
+ console.log("Resources");
717
+ console.log("\u2500".repeat(70));
718
+ console.log(" Documentation: https://docs.agentmark.co");
719
+ console.log("\u2550".repeat(70) + "\n");
720
+ } catch (error) {
721
+ console.error("Error creating example app:", error);
722
+ throw error;
723
+ }
724
+ };
725
+
726
+ // src/index.ts
727
+ var main = async () => {
728
+ const config = {
729
+ $schema: "https://raw.githubusercontent.com/agentmark-ai/agentmark/refs/heads/main/packages/cli/agentmark.schema.json",
730
+ version: "2.0.0",
731
+ mdxVersion: "1.0",
732
+ agentmarkPath: "."
733
+ };
734
+ console.log("Initializing project.");
735
+ const { folderName } = await prompts({
736
+ name: "folderName",
737
+ type: "text",
738
+ message: "Where would you like to create your AgentMark app?",
739
+ initial: "my-agentmark-app"
740
+ });
741
+ const targetPath = `./${folderName}`;
742
+ fs4.ensureDirSync(targetPath);
743
+ config.builtInModels = ["gpt-4o"];
744
+ let apiKey = "";
745
+ const { providedApiKey } = await prompts({
746
+ name: "providedApiKey",
747
+ type: "password",
748
+ message: `Enter your OpenAI API key (or press Enter to skip):`,
749
+ initial: ""
750
+ });
751
+ apiKey = providedApiKey || "";
752
+ const { adapter } = await prompts({
753
+ name: "adapter",
754
+ type: "select",
755
+ message: "Which adapter would you like to use?",
756
+ choices: [
757
+ { title: "AI SDK (Vercel)", value: "ai-sdk" },
758
+ { title: "Mastra", value: "mastra" }
759
+ ]
760
+ });
761
+ const { deploymentMode } = await prompts({
762
+ name: "deploymentMode",
763
+ type: "select",
764
+ message: "Use AgentMark Cloud or manage yourself?",
765
+ choices: [
766
+ {
767
+ title: "AgentMark Cloud (recommended)",
768
+ value: "cloud",
769
+ description: "Have AgentMark cloud manage prompts, datasets, traces, experiments, alerts & more"
770
+ },
771
+ {
772
+ title: "Self-hosted",
773
+ value: "static",
774
+ description: "Self-manage your prompts, datasets, traces & experiments"
775
+ }
776
+ ]
777
+ });
778
+ const { client } = await prompts({
779
+ name: "client",
780
+ type: "select",
781
+ message: "Make your IDE an AgentMark expert",
782
+ choices: [
783
+ { title: "Claude Code", value: "claude-code" },
784
+ { title: "Cursor", value: "cursor" },
785
+ { title: "VS Code", value: "vscode" },
786
+ { title: "Zed", value: "zed" },
787
+ { title: "Skip", value: "skip" }
788
+ ]
789
+ });
790
+ await createExampleApp(client, targetPath, apiKey, adapter, deploymentMode);
791
+ fs4.writeJsonSync(`${targetPath}/agentmark.json`, config, { spaces: 2 });
56
792
  };
57
793
  main().catch((error) => {
58
- console.error("Error:", error);
59
- process.exit(1);
794
+ console.error("Error:", error);
795
+ process.exit(1);
60
796
  });
61
797
  //# sourceMappingURL=index.js.map