create-agentmark 0.5.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.
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
var createAdapterConfig = (provider) => {
|
|
3
3
|
return {
|
|
4
4
|
"ai-sdk": {
|
|
5
|
-
package: "@agentmark/ai-sdk-v5-adapter",
|
|
5
|
+
package: "@agentmark-ai/ai-sdk-v5-adapter",
|
|
6
6
|
dependencies: ["ai@^5", `@ai-sdk/${provider}@^2`],
|
|
7
7
|
classes: {
|
|
8
8
|
modelRegistry: "VercelAIModelRegistry",
|
|
@@ -11,7 +11,7 @@ var createAdapterConfig = (provider) => {
|
|
|
11
11
|
}
|
|
12
12
|
},
|
|
13
13
|
mastra: {
|
|
14
|
-
package: "@agentmark/mastra-v0-adapter",
|
|
14
|
+
package: "@agentmark-ai/mastra-v0-adapter",
|
|
15
15
|
dependencies: [
|
|
16
16
|
"@mastra/core@<0.20.0",
|
|
17
17
|
"@mastra/mcp@<0.13.4",
|
|
@@ -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 === "
|
|
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";
|
|
@@ -47,11 +110,10 @@ import { client } from "./agentmark.client";
|
|
|
47
110
|
const telemetry = {
|
|
48
111
|
isEnabled: true,
|
|
49
112
|
metadata: {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
sessionName: "my-first-session",
|
|
113
|
+
trace_name: "customer-support",
|
|
114
|
+
user_id: "user-123",
|
|
115
|
+
session_id: "session-123",
|
|
116
|
+
session_name: "my-first-session",
|
|
55
117
|
},
|
|
56
118
|
};
|
|
57
119
|
|
|
@@ -95,11 +157,10 @@ import { client } from "./agentmark.client";
|
|
|
95
157
|
const telemetry = {
|
|
96
158
|
isEnabled: true,
|
|
97
159
|
metadata: {
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
sessionName: "my-first-session",
|
|
160
|
+
trace_name: "customer-support",
|
|
161
|
+
user_id: "user-123",
|
|
162
|
+
session_id: "session-123",
|
|
163
|
+
session_name: "my-first-session",
|
|
103
164
|
},
|
|
104
165
|
};
|
|
105
166
|
|
|
@@ -133,70 +194,211 @@ main();
|
|
|
133
194
|
};
|
|
134
195
|
|
|
135
196
|
// src/utils/examples/templates/env.ts
|
|
136
|
-
var getEnvFileContent = (_modelProvider, apiKey = "") => {
|
|
197
|
+
var getEnvFileContent = (_modelProvider, apiKey = "", adapter = "ai-sdk") => {
|
|
137
198
|
const apiKeyValue = apiKey || "your_api_key_here";
|
|
199
|
+
const apiKeyName = adapter === "claude-agent-sdk" ? "ANTHROPIC_API_KEY" : "OPENAI_API_KEY";
|
|
138
200
|
return `# Cloud deployment: Set these environment variables
|
|
139
201
|
# AGENTMARK_BASE_URL=https://api.agentmark.co
|
|
140
202
|
# AGENTMARK_API_KEY=your_agentmark_api_key
|
|
141
203
|
# AGENTMARK_APP_ID=your_agentmark_app_id
|
|
142
204
|
# Learn more: https://docs.agentmark.co/platform/getting_started/quickstart
|
|
143
205
|
|
|
144
|
-
|
|
206
|
+
${apiKeyName}=${apiKeyValue}
|
|
145
207
|
`;
|
|
146
208
|
};
|
|
147
209
|
|
|
148
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
|
|
149
215
|
import fs from "fs-extra";
|
|
150
|
-
import
|
|
151
|
-
|
|
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) => {
|
|
152
328
|
const packageJsonPath = `${targetPath}/package.json`;
|
|
153
|
-
|
|
329
|
+
const isExistingProject = projectInfo?.isExistingProject ?? false;
|
|
330
|
+
if (!fs2.existsSync(packageJsonPath)) {
|
|
154
331
|
console.log("Creating package.json...");
|
|
155
332
|
execSync("npm init -y", { cwd: targetPath });
|
|
156
333
|
}
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
"
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
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 });
|
|
170
375
|
}
|
|
171
|
-
pkgJson.scripts = scripts;
|
|
172
|
-
pkgJson.overrides = {
|
|
173
|
-
...pkgJson.overrides,
|
|
174
|
-
"axios": "^1.7.9"
|
|
175
|
-
};
|
|
176
|
-
fs.writeJsonSync(packageJsonPath, pkgJson, { spaces: 2 });
|
|
177
376
|
};
|
|
178
|
-
var installDependencies = (modelProvider, targetPath = ".", adapter = "ai-sdk", deploymentMode = "cloud") => {
|
|
377
|
+
var installDependencies = (modelProvider, targetPath = ".", adapter = "ai-sdk", deploymentMode = "cloud", packageManager = null) => {
|
|
179
378
|
console.log("Installing required packages...");
|
|
180
379
|
console.log("This might take a moment...");
|
|
181
380
|
const adapterConfig = getAdapterConfig(adapter, modelProvider);
|
|
381
|
+
const pm = packageManager || DEFAULT_PACKAGE_MANAGER;
|
|
382
|
+
const npmSuffix = pm.name === "npm" ? " --legacy-peer-deps" : "";
|
|
182
383
|
try {
|
|
183
|
-
const
|
|
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...`);
|
|
184
387
|
execSync(devDepsCmd, {
|
|
185
388
|
stdio: "inherit",
|
|
186
389
|
cwd: targetPath
|
|
187
390
|
});
|
|
188
|
-
const loaderPackages = deploymentMode === "static" ? ["@agentmark/loader-api", "@agentmark/loader-file"] : ["@agentmark/loader-api"];
|
|
189
|
-
const
|
|
190
|
-
"install",
|
|
391
|
+
const loaderPackages = deploymentMode === "static" ? ["@agentmark-ai/loader-api", "@agentmark-ai/loader-file"] : ["@agentmark-ai/loader-api"];
|
|
392
|
+
const deps = [
|
|
191
393
|
"dotenv",
|
|
192
|
-
"@agentmark/prompt-core",
|
|
193
|
-
"@agentmark/sdk",
|
|
394
|
+
"@agentmark-ai/prompt-core",
|
|
395
|
+
"@agentmark-ai/sdk",
|
|
194
396
|
adapterConfig.package,
|
|
195
397
|
...loaderPackages,
|
|
196
|
-
...adapterConfig.dependencies
|
|
197
|
-
"--legacy-peer-deps"
|
|
398
|
+
...adapterConfig.dependencies
|
|
198
399
|
];
|
|
199
|
-
|
|
400
|
+
const depsCmd = `${pm.addCmd} ${deps.join(" ")}${npmSuffix}`;
|
|
401
|
+
execSync(depsCmd, { stdio: "inherit", cwd: targetPath });
|
|
200
402
|
console.log("Packages installed successfully!");
|
|
201
403
|
} catch (error) {
|
|
202
404
|
console.error("Error installing packages:", error);
|
|
@@ -370,28 +572,32 @@ var getStoryDataset = () => {
|
|
|
370
572
|
};
|
|
371
573
|
|
|
372
574
|
// src/utils/examples/templates/example-prompts.ts
|
|
373
|
-
import
|
|
575
|
+
import fs3 from "fs-extra";
|
|
374
576
|
var createExamplePrompts = (model, targetPath = ".", adapter = "ai-sdk") => {
|
|
375
|
-
|
|
376
|
-
|
|
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) {
|
|
377
583
|
const animalDrawingPrompt = getAnimalDrawingPrompt();
|
|
378
|
-
|
|
584
|
+
fs3.writeFileSync(`${targetPath}/agentmark/animal-drawing.prompt.mdx`, animalDrawingPrompt);
|
|
379
585
|
const animalDataset = getAnimalDataset();
|
|
380
|
-
|
|
586
|
+
fs3.writeFileSync(`${targetPath}/agentmark/animal.jsonl`, animalDataset);
|
|
381
587
|
}
|
|
382
588
|
const customerSupportPrompt = getCustomerSupportPrompt(model);
|
|
383
|
-
|
|
589
|
+
fs3.writeFileSync(`${targetPath}/agentmark/customer-support-agent.prompt.mdx`, customerSupportPrompt);
|
|
384
590
|
const customerQueryDataset = getCustomerQueryDataset();
|
|
385
|
-
|
|
591
|
+
fs3.writeFileSync(`${targetPath}/agentmark/customer-query.jsonl`, customerQueryDataset);
|
|
386
592
|
const partyPlannerPrompt = getPartyPlannerPrompt(model);
|
|
387
|
-
|
|
593
|
+
fs3.writeFileSync(`${targetPath}/agentmark/party-planner.prompt.mdx`, partyPlannerPrompt);
|
|
388
594
|
const partyDataset = getPartyDataset();
|
|
389
|
-
|
|
390
|
-
if (
|
|
595
|
+
fs3.writeFileSync(`${targetPath}/agentmark/party.jsonl`, partyDataset);
|
|
596
|
+
if (!skipSpeechPrompts) {
|
|
391
597
|
const storyTellerPrompt = getStoryTellerPrompt();
|
|
392
|
-
|
|
598
|
+
fs3.writeFileSync(`${targetPath}/agentmark/story-teller.prompt.mdx`, storyTellerPrompt);
|
|
393
599
|
const storyDataset = getStoryDataset();
|
|
394
|
-
|
|
600
|
+
fs3.writeFileSync(`${targetPath}/agentmark/story.jsonl`, storyDataset);
|
|
395
601
|
}
|
|
396
602
|
};
|
|
397
603
|
|
|
@@ -400,11 +606,12 @@ var getClientConfigContent = (options) => {
|
|
|
400
606
|
const { provider, languageModels, adapter, deploymentMode = "cloud" } = options;
|
|
401
607
|
const adapterConfig = getAdapterConfig(adapter, provider);
|
|
402
608
|
const { modelRegistry, toolRegistry } = adapterConfig.classes;
|
|
403
|
-
const
|
|
404
|
-
const
|
|
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))
|
|
405
612
|
.registerModels(["tts-1-hd"], (name: string) => ${provider}.speech(name))` : "";
|
|
406
|
-
const loaderImport = deploymentMode === "cloud" ? `import { ApiLoader } from "@agentmark/loader-api";` : `import { ApiLoader } from "@agentmark/loader-api";
|
|
407
|
-
import { FileLoader } from "@agentmark/loader-file";`;
|
|
613
|
+
const loaderImport = deploymentMode === "cloud" ? `import { ApiLoader } from "@agentmark-ai/loader-api";` : `import { ApiLoader } from "@agentmark-ai/loader-api";
|
|
614
|
+
import { FileLoader } from "@agentmark-ai/loader-file";`;
|
|
408
615
|
const loaderSetup = deploymentMode === "cloud" ? ` // ApiLoader works for both development and production
|
|
409
616
|
// - Development: 'agentmark dev' sets AGENTMARK_BASE_URL to localhost
|
|
410
617
|
// - Production: Set AGENTMARK_API_KEY and AGENTMARK_APP_ID for cloud
|
|
@@ -416,6 +623,51 @@ import { FileLoader } from "@agentmark/loader-file";`;
|
|
|
416
623
|
});` : ` const loader = process.env.NODE_ENV === 'development'
|
|
417
624
|
? ApiLoader.local({ baseUrl: process.env.AGENTMARK_BASE_URL || 'http://localhost:9418' })
|
|
418
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 });`;
|
|
419
671
|
return `// agentmark.client.ts
|
|
420
672
|
import path from 'node:path';
|
|
421
673
|
import dotenv from 'dotenv';
|
|
@@ -424,13 +676,9 @@ import { createAgentMarkClient, ${modelRegistry}, ${toolRegistry}, EvalRegistry
|
|
|
424
676
|
${loaderImport}
|
|
425
677
|
import AgentMarkTypes, { Tools } from './agentmark.types';
|
|
426
678
|
${providerImport}
|
|
679
|
+
${adapterOptionsImport}
|
|
427
680
|
|
|
428
|
-
|
|
429
|
-
const modelRegistry = new ${modelRegistry}()
|
|
430
|
-
.registerModels(${JSON.stringify(languageModels)}, (name: string) => ${provider}(name))
|
|
431
|
-
${extraModelRegs};
|
|
432
|
-
return modelRegistry;
|
|
433
|
-
}
|
|
681
|
+
${modelRegistrySetup}
|
|
434
682
|
|
|
435
683
|
function createToolRegistry() {
|
|
436
684
|
const toolRegistry = new ${toolRegistry}<Tools>()
|
|
@@ -477,7 +725,7 @@ ${loaderSetup}
|
|
|
477
725
|
const modelRegistry = createModelRegistry();
|
|
478
726
|
const toolRegistry = createToolRegistry();
|
|
479
727
|
const evalRegistry = createEvalRegistry();
|
|
480
|
-
|
|
728
|
+
${createClientCall}
|
|
481
729
|
}
|
|
482
730
|
|
|
483
731
|
export const client = createClient();
|