viagen 0.0.47 → 0.0.49

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 (2) hide show
  1. package/dist/index.js +97 -41
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -110,7 +110,7 @@ function registerHealthRoutes(server, env, errorRef) {
110
110
  );
111
111
  }
112
112
  });
113
- const currentVersion = true ? "0.0.47" : "0.0.0";
113
+ const currentVersion = true ? "0.0.49" : "0.0.0";
114
114
  debug("health", `version resolved: ${currentVersion}`);
115
115
  let versionCache = null;
116
116
  server.middlewares.use("/via/version", (_req, res) => {
@@ -746,9 +746,38 @@ function registerChatRoutes(server, session, opts) {
746
746
  done = true;
747
747
  debug("chat", "SSE stream done, closing response");
748
748
  if (!res.writableEnded) {
749
- res.write("event: done\ndata: {}\n\n");
749
+ const doneData = {
750
+ ...event.costUsd != null && { costUsd: event.costUsd },
751
+ ...event.inputTokens != null && { inputTokens: event.inputTokens },
752
+ ...event.outputTokens != null && { outputTokens: event.outputTokens },
753
+ ...event.durationMs != null && { durationMs: event.durationMs }
754
+ };
755
+ res.write(`event: done
756
+ data: ${JSON.stringify(doneData)}
757
+
758
+ `);
750
759
  res.end();
751
760
  }
761
+ if (opts.env["VIAGEN_CALLBACK_URL"] && opts.env["VIAGEN_AUTH_TOKEN"]) {
762
+ const taskId = opts.env["VIAGEN_TASK_ID"];
763
+ if (taskId && (event.inputTokens || event.outputTokens || event.costUsd)) {
764
+ fetch(opts.env["VIAGEN_CALLBACK_URL"], {
765
+ method: "POST",
766
+ headers: {
767
+ "Content-Type": "application/json",
768
+ Authorization: `Bearer ${opts.env["VIAGEN_AUTH_TOKEN"]}`
769
+ },
770
+ body: JSON.stringify({
771
+ taskId,
772
+ ...event.inputTokens != null && { inputTokens: event.inputTokens },
773
+ ...event.outputTokens != null && { outputTokens: event.outputTokens },
774
+ ...event.costUsd != null && { costUsd: event.costUsd }
775
+ })
776
+ }).catch((err) => {
777
+ debug("chat", `usage callback failed: ${err}`);
778
+ });
779
+ }
780
+ }
752
781
  return;
753
782
  }
754
783
  if (event.type === "error") {
@@ -18409,23 +18438,18 @@ import {
18409
18438
  createSdkMcpServer,
18410
18439
  tool
18411
18440
  } from "@anthropic-ai/claude-agent-sdk";
18412
- import { updateTask } from "viagen-sdk/sandbox";
18413
- import { createViagen } from "viagen-sdk";
18441
+ import {
18442
+ listTasks,
18443
+ getTask,
18444
+ createTask
18445
+ } from "viagen-sdk/sandbox";
18414
18446
  function createViagenTools(config2) {
18415
- let client;
18416
- let projectId;
18417
- if (config2) {
18418
- client = createViagen({
18419
- baseUrl: config2.platformUrl,
18420
- token: config2.authToken
18421
- });
18422
- projectId = config2.projectId;
18423
- }
18424
18447
  const tools = [
18425
18448
  tool(
18426
18449
  "viagen_update_task",
18427
- "Report task status back to the viagen platform. Use status 'review' after creating a PR (ready for human review) or 'completed' when the task is fully done.",
18450
+ "Update a task's status on the viagen platform. Use status 'review' after creating a PR (ready for human review) or 'completed' when the task is fully done. If no taskId is provided, updates the current task (requires VIAGEN_TASK_ID env var).",
18428
18451
  {
18452
+ taskId: external_exports.string().optional().describe("Task ID to update. Defaults to the current task from VIAGEN_TASK_ID env var."),
18429
18453
  status: external_exports.enum(["review", "completed"]).describe(
18430
18454
  "'review' = PR created, ready for review. 'completed' = task fully done."
18431
18455
  ),
@@ -18433,31 +18457,49 @@ function createViagenTools(config2) {
18433
18457
  result: external_exports.string().describe("Brief one-line summary of what was done."),
18434
18458
  inputTokens: external_exports.number().optional().describe("Total input tokens used."),
18435
18459
  outputTokens: external_exports.number().optional().describe("Total output tokens used."),
18436
- costUsd: external_exports.number().optional().describe("Total cost in USD.")
18460
+ costUsd: external_exports.number().optional().describe("Total cost in USD."),
18461
+ prReviewStatus: external_exports.enum(["approved", "changes_requested", "commented"]).optional().describe("PR review outcome, if applicable.")
18437
18462
  },
18438
18463
  async (args) => {
18439
- await updateTask({
18440
- status: args.status,
18441
- prUrl: args.prUrl,
18442
- result: args.result,
18443
- inputTokens: args.inputTokens,
18444
- outputTokens: args.outputTokens,
18445
- costUsd: args.costUsd
18464
+ const taskId = args.taskId || process.env["VIAGEN_TASK_ID"];
18465
+ if (!taskId) {
18466
+ return {
18467
+ content: [{ type: "text", text: "Error: No taskId provided and VIAGEN_TASK_ID is not set." }]
18468
+ };
18469
+ }
18470
+ const callbackUrl = process.env["VIAGEN_CALLBACK_URL"];
18471
+ const authToken = process.env["VIAGEN_AUTH_TOKEN"];
18472
+ const internalStatus = args.status === "review" ? "validating" : "completed";
18473
+ const res = await fetch(callbackUrl, {
18474
+ method: "POST",
18475
+ headers: {
18476
+ "Content-Type": "application/json",
18477
+ Authorization: `Bearer ${authToken}`
18478
+ },
18479
+ body: JSON.stringify({
18480
+ taskId,
18481
+ status: internalStatus,
18482
+ ...args.prUrl && { prUrl: args.prUrl },
18483
+ result: args.result,
18484
+ ...args.inputTokens != null && { inputTokens: args.inputTokens },
18485
+ ...args.outputTokens != null && { outputTokens: args.outputTokens },
18486
+ ...args.costUsd != null && { costUsd: args.costUsd },
18487
+ ...args.prReviewStatus && { prReviewStatus: args.prReviewStatus }
18488
+ })
18446
18489
  });
18490
+ if (!res.ok) {
18491
+ const text = await res.text().catch(() => "");
18492
+ return {
18493
+ content: [{ type: "text", text: `Error updating task (${res.status}): ${text}` }]
18494
+ };
18495
+ }
18447
18496
  return {
18448
- content: [
18449
- {
18450
- type: "text",
18451
- text: `Task status updated to '${args.status}'.`
18452
- }
18453
- ]
18497
+ content: [{ type: "text", text: `Task ${taskId} status updated to '${args.status}'.` }]
18454
18498
  };
18455
18499
  }
18456
18500
  )
18457
18501
  ];
18458
- if (client && projectId) {
18459
- const c = client;
18460
- const pid = projectId;
18502
+ if (config2?.projectId) {
18461
18503
  tools.push(
18462
18504
  tool(
18463
18505
  "viagen_list_tasks",
@@ -18466,7 +18508,7 @@ function createViagenTools(config2) {
18466
18508
  status: external_exports.enum(["ready", "running", "validating", "completed", "timed_out"]).optional().describe("Filter tasks by status.")
18467
18509
  },
18468
18510
  async (args) => {
18469
- const tasks = await c.tasks.list(pid, args.status);
18511
+ const tasks = await listTasks({ status: args.status });
18470
18512
  return {
18471
18513
  content: [
18472
18514
  {
@@ -18486,7 +18528,7 @@ function createViagenTools(config2) {
18486
18528
  taskId: external_exports.string().describe("The task ID to retrieve.")
18487
18529
  },
18488
18530
  async (args) => {
18489
- const task = await c.tasks.get(pid, args.taskId);
18531
+ const task = await getTask(args.taskId);
18490
18532
  return {
18491
18533
  content: [
18492
18534
  {
@@ -18508,7 +18550,7 @@ function createViagenTools(config2) {
18508
18550
  type: external_exports.enum(["task", "plan"]).optional().describe("Task type: 'task' for code changes, 'plan' for implementation plans.")
18509
18551
  },
18510
18552
  async (args) => {
18511
- const task = await c.tasks.create(pid, {
18553
+ const task = await createTask({
18512
18554
  prompt: args.prompt,
18513
18555
  branch: args.branch,
18514
18556
  type: args.type
@@ -18559,7 +18601,7 @@ You have access to viagen platform tools for task management:
18559
18601
  - viagen_list_tasks: List tasks in this project (optionally filter by status)
18560
18602
  - viagen_get_task: Get full details of a specific task
18561
18603
  - viagen_create_task: Create follow-up tasks for work you identify
18562
- - viagen_update_task: Report your current task status ('review' or 'completed')
18604
+ - viagen_update_task: Update a task's status ('review' or 'completed'). Accepts an optional taskId \u2014 defaults to the current task if one is set.
18563
18605
 
18564
18606
  Use these to understand project context and create follow-up work when appropriate.
18565
18607
  `;
@@ -18956,15 +18998,11 @@ ${payload.err.frame || ""}`
18956
18998
  const resolvedModel = env["VIAGEN_MODEL"] || opts.model;
18957
18999
  debug("server", `creating ChatSession (model: ${resolvedModel})`);
18958
19000
  let mcpServers;
18959
- const hasSandboxContext = !!(env["VIAGEN_CALLBACK_URL"] && env["VIAGEN_AUTH_TOKEN"] && env["VIAGEN_TASK_ID"]);
19001
+ const hasSandboxContext = !!(env["VIAGEN_CALLBACK_URL"] && env["VIAGEN_AUTH_TOKEN"]);
18960
19002
  if (hasSandboxContext) {
18961
19003
  debug("server", "creating viagen MCP tools (sandbox mode)");
18962
19004
  const viagenMcp = createViagenTools(
18963
- env["VIAGEN_PROJECT_ID"] ? {
18964
- authToken: env["VIAGEN_AUTH_TOKEN"],
18965
- platformUrl: env["VIAGEN_PLATFORM_URL"] || "https://app.viagen.dev",
18966
- projectId: env["VIAGEN_PROJECT_ID"]
18967
- } : void 0
19005
+ env["VIAGEN_PROJECT_ID"] ? { projectId: env["VIAGEN_PROJECT_ID"] } : void 0
18968
19006
  );
18969
19007
  mcpServers = { [viagenMcp.name]: viagenMcp };
18970
19008
  }
@@ -19007,6 +19045,24 @@ ${payload.err.frame || ""}`
19007
19045
  if (event.type === "done") {
19008
19046
  debug("server", "auto-prompt completed");
19009
19047
  logBuffer.push("info", `[viagen] Prompt completed`);
19048
+ const taskId = env["VIAGEN_TASK_ID"];
19049
+ if (hasSandboxContext && taskId && (event.inputTokens || event.outputTokens || event.costUsd)) {
19050
+ fetch(env["VIAGEN_CALLBACK_URL"], {
19051
+ method: "POST",
19052
+ headers: {
19053
+ "Content-Type": "application/json",
19054
+ Authorization: `Bearer ${env["VIAGEN_AUTH_TOKEN"]}`
19055
+ },
19056
+ body: JSON.stringify({
19057
+ taskId,
19058
+ ...event.inputTokens != null && { inputTokens: event.inputTokens },
19059
+ ...event.outputTokens != null && { outputTokens: event.outputTokens },
19060
+ ...event.costUsd != null && { costUsd: event.costUsd }
19061
+ })
19062
+ }).catch((err) => {
19063
+ debug("server", `usage callback failed: ${err}`);
19064
+ });
19065
+ }
19010
19066
  }
19011
19067
  });
19012
19068
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "viagen",
3
- "version": "0.0.47",
3
+ "version": "0.0.49",
4
4
  "description": "Vite dev server plugin that exposes endpoints for chatting with Claude Code SDK",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -44,7 +44,7 @@
44
44
  "@vercel/sandbox": "^1",
45
45
  "lucide-react": "^0.564.0",
46
46
  "simple-git": "^3.31.1",
47
- "viagen-sdk": "^0.0.9"
47
+ "viagen-sdk": "^0.0.11"
48
48
  },
49
49
  "license": "MIT",
50
50
  "repository": {