staklink 0.4.21 → 0.4.23

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.
@@ -60927,7 +60927,7 @@ var SSEManager = class {
60927
60927
  var sseManager = new SSEManager();
60928
60928
 
60929
60929
  // src/proxy/version.ts
60930
- var VERSION = "0.4.21";
60930
+ var VERSION = "0.4.23";
60931
60931
 
60932
60932
  // node_modules/uuid/dist/esm/stringify.js
60933
60933
  var byteToHex = [];
@@ -137648,6 +137648,27 @@ function goose_env(apiKey, model = "sonnet") {
137648
137648
  PATH: `${path7.join(os.homedir(), ".local", "bin")}:${process.env.PATH}`
137649
137649
  };
137650
137650
  }
137651
+ async function extractSessionUsage(session) {
137652
+ try {
137653
+ const safeName = session.replaceAll(" ", "_");
137654
+ const res = await executeCommand(
137655
+ `goose session export --name ${safeName} --format json`,
137656
+ process.cwd(),
137657
+ {}
137658
+ );
137659
+ const data = JSON.parse(res.stdout);
137660
+ if (typeof data.input_tokens === "number" && typeof data.output_tokens === "number") {
137661
+ return {
137662
+ inputTokens: data.input_tokens,
137663
+ outputTokens: data.output_tokens,
137664
+ totalTokens: data.total_tokens ?? data.input_tokens + data.output_tokens
137665
+ };
137666
+ }
137667
+ return void 0;
137668
+ } catch {
137669
+ return void 0;
137670
+ }
137671
+ }
137651
137672
  async function runAgent({
137652
137673
  prompt,
137653
137674
  apiKey,
@@ -137662,7 +137683,7 @@ async function runAgent({
137662
137683
  }) {
137663
137684
  createGooseConfig(searchApiKey, mcpServers);
137664
137685
  const env2 = goose_env(apiKey, model);
137665
- console.log("RUN goose with env", env2);
137686
+ log("RUN goose with env", env2);
137666
137687
  const safePrompt = prompt.startsWith("-") ? `
137667
137688
  ${prompt}` : prompt;
137668
137689
  const cleanPrompt = sanitizeShellArg(safePrompt);
@@ -137670,7 +137691,7 @@ ${prompt}` : prompt;
137670
137691
  system += system_prompt ? sanitizeShellArg(system_prompt) + "\n\n" : "";
137671
137692
  system += SYSTEM_SUFFIX;
137672
137693
  system = sanitizeShellArg(system);
137673
- console.log("Using Goose CLI", cleanPrompt, system);
137694
+ log("Using Goose CLI", cleanPrompt, system);
137674
137695
  let cmd = `goose run --with-builtin developer -t "${cleanPrompt}" --system "${system}"`;
137675
137696
  if (session) {
137676
137697
  session = sanitizeShellArg(session);
@@ -137682,24 +137703,38 @@ ${prompt}` : prompt;
137682
137703
  } catch {
137683
137704
  }
137684
137705
  }
137685
- let res = await executeCommand(cmd, cwd, env2, (l) => console.log(l));
137706
+ let res = await executeCommand(cmd, cwd, env2, (l) => log(l));
137686
137707
  if (session && isStreamDecodeError(res.stdout)) {
137687
137708
  const maxRetries = 2;
137688
137709
  for (let attempt = 1; attempt <= maxRetries; attempt++) {
137689
- console.log(`Stream decode error detected, retrying (${attempt}/${maxRetries})...`);
137710
+ log(`Stream decode error detected, retrying (${attempt}/${maxRetries})...`);
137690
137711
  await new Promise((r) => setTimeout(r, 2e3 * attempt));
137691
137712
  const retryCmd = `goose run --with-builtin developer -t "continue" --system "${system}" --name ${session} --resume`;
137692
- res = await executeCommand(retryCmd, cwd, env2, (l) => console.log(l));
137713
+ res = await executeCommand(retryCmd, cwd, env2, (l) => log(l));
137693
137714
  if (!isStreamDecodeError(res.stdout)) break;
137694
137715
  }
137695
137716
  }
137696
137717
  const output = res.stdout;
137718
+ const resolvedModel = getGooseModel(model || "sonnet");
137719
+ const provider = resolvedModel.includes("/") ? resolvedModel.split("/")[0] : "unknown";
137720
+ const usage = session ? await extractSessionUsage(session) : void 0;
137697
137721
  if (summarize && session) {
137698
137722
  const sessionData = exportSession(session, "assistant");
137699
137723
  const summary = await summarizeSession(sessionData, summaryApiKey || apiKey);
137700
- return { output, summary };
137724
+ return {
137725
+ output,
137726
+ summary,
137727
+ model: resolvedModel,
137728
+ provider,
137729
+ ...usage && { usage }
137730
+ };
137701
137731
  }
137702
- return output;
137732
+ return {
137733
+ output,
137734
+ model: resolvedModel,
137735
+ provider,
137736
+ ...usage && { usage }
137737
+ };
137703
137738
  }
137704
137739
  function createGooseConfig(exaApiKey, mcpServers) {
137705
137740
  const configDir = path7.join(os.homedir(), ".config", "goose");
@@ -137753,9 +137788,9 @@ function createGooseConfig(exaApiKey, mcpServers) {
137753
137788
  fs8.mkdirSync(configDir, { recursive: true });
137754
137789
  }
137755
137790
  fs8.writeFileSync(configPath, configContent, "utf-8");
137756
- console.log(`Created goose config at ${configPath}`);
137791
+ log(`Created goose config at ${configPath}`);
137757
137792
  } catch (error88) {
137758
- console.warn("Error creating goose config:", error88);
137793
+ warn("Error creating goose config:", error88);
137759
137794
  }
137760
137795
  }
137761
137796
  async function runGooseWeb(apiKey, cwd, port) {
@@ -137778,7 +137813,7 @@ async function runGooseWeb(apiKey, cwd, port) {
137778
137813
  env: env2
137779
137814
  });
137780
137815
  } catch (error88) {
137781
- console.error("Error occurred while starting Goose:", error88);
137816
+ error("Error occurred while starting Goose:", error88);
137782
137817
  }
137783
137818
  }
137784
137819
 
@@ -137798,7 +137833,7 @@ async function runAgent2({
137798
137833
  if (!prompt) {
137799
137834
  throw new Error("Missing prompt");
137800
137835
  }
137801
- console.log("runAgent called with:", {
137836
+ log("runAgent called with:", {
137802
137837
  prompt,
137803
137838
  apiKey: apiKey ? "***" : "undefined",
137804
137839
  cwd
@@ -137817,9 +137852,20 @@ async function runAgent2({
137817
137852
  cwd,
137818
137853
  executablePath: findClaudePath()
137819
137854
  });
137820
- return res.text;
137855
+ return {
137856
+ output: res.text,
137857
+ model: "claude_code",
137858
+ provider: "anthropic",
137859
+ ...res.usage && {
137860
+ usage: {
137861
+ inputTokens: res.usage.inputTokens,
137862
+ outputTokens: res.usage.outputTokens,
137863
+ totalTokens: res.usage.totalTokens
137864
+ }
137865
+ }
137866
+ };
137821
137867
  } catch (error88) {
137822
- console.log("Model error:", error88);
137868
+ log("Model error:", error88);
137823
137869
  throw error88;
137824
137870
  }
137825
137871
  }
@@ -137829,7 +137875,7 @@ function findClaudePath() {
137829
137875
  if (!claudePath) {
137830
137876
  throw new Error("Claude CLI not found in PATH");
137831
137877
  }
137832
- console.log("Found Claude CLI at:", claudePath);
137878
+ log("Found Claude CLI at:", claudePath);
137833
137879
  return claudePath;
137834
137880
  } catch (error88) {
137835
137881
  throw new Error(`Could not find Claude CLI: ${error88}`);
@@ -139311,7 +139357,7 @@ async function runAgent3({
139311
139357
  let system = SYSTEM_CORE;
139312
139358
  system += system_prompt ? system_prompt + "\n\n" : "";
139313
139359
  system += SYSTEM_SUFFIX;
139314
- console.log("Codex agent using API key:", apiKey ? `${apiKey.substring(0, 8)}...` : "MISSING");
139360
+ log("Codex agent using API key:", apiKey ? `${apiKey.substring(0, 8)}...` : "MISSING");
139315
139361
  if (apiKey) {
139316
139362
  writeCodexAuth(apiKey);
139317
139363
  }
@@ -139324,15 +139370,20 @@ async function runAgent3({
139324
139370
  };
139325
139371
  }
139326
139372
  const model = codexCli(MODEL, settings);
139327
- const { text: text3 } = await generateText({
139373
+ const { text: text3, usage } = await generateText({
139328
139374
  model,
139329
139375
  prompt,
139330
139376
  system
139331
139377
  });
139378
+ const agentUsage = {
139379
+ inputTokens: usage.inputTokens ?? 0,
139380
+ outputTokens: usage.outputTokens ?? 0,
139381
+ totalTokens: usage.totalTokens ?? 0
139382
+ };
139332
139383
  if (summarize) {
139333
- return text3;
139384
+ return { output: text3, model: MODEL, provider: "openai", usage: agentUsage };
139334
139385
  }
139335
- return text3;
139386
+ return { output: text3, model: MODEL, provider: "openai", usage: agentUsage };
139336
139387
  }
139337
139388
 
139338
139389
  // src/agent/repair.ts
@@ -139515,13 +139566,13 @@ var parseValidationResponse = (rawResponse) => {
139515
139566
  async function streamGooseToSSE(sessionId, prompt, apiKey, res, options) {
139516
139567
  let resume = false;
139517
139568
  try {
139518
- console.log("Exporting session", sessionId);
139569
+ log("Exporting session", sessionId);
139519
139570
  exportSession(sessionId, "assistant");
139520
139571
  resume = true;
139521
- console.log("Session exists, resume");
139572
+ log("Session exists, resume");
139522
139573
  } catch (error88) {
139523
- console.log("Error exporting session", error88);
139524
- console.log("Session doesn't exist, don't resume");
139574
+ log("Error exporting session", error88);
139575
+ log("Session doesn't exist, don't resume");
139525
139576
  }
139526
139577
  log("Streaming Goose to SSE", { sessionId, prompt, apiKey, resume, model: options?.model });
139527
139578
  createGooseConfig(options?.searchApiKey);
@@ -139700,7 +139751,7 @@ async function streamCodexToSSE(sessionId, prompt, apiKey, res, options) {
139700
139751
  ensureSessionsDir();
139701
139752
  const sessionPath = getSessionPath(sessionId);
139702
139753
  log("Streaming Codex to SSE", { sessionId, prompt, sessionPath });
139703
- console.log("Codex streaming using API key:", apiKey ? `${apiKey.substring(0, 8)}...` : "MISSING");
139754
+ log("Codex streaming using API key:", apiKey ? `${apiKey.substring(0, 8)}...` : "MISSING");
139704
139755
  if (apiKey) {
139705
139756
  writeCodexAuth(apiKey);
139706
139757
  }
@@ -139998,7 +140049,11 @@ var createAsyncAgentHandler = (getParams, transformResult) => {
139998
140049
  const recordings = await collectRecordings(startTime);
139999
140050
  finishReq(request_id, {
140000
140051
  success: true,
140001
- result: finalResult,
140052
+ result: finalResult.output ?? finalResult,
140053
+ ...finalResult.summary && { summary: finalResult.summary },
140054
+ ...finalResult.usage && { usage: finalResult.usage },
140055
+ ...finalResult.model && { model: finalResult.model },
140056
+ ...finalResult.provider && { provider: finalResult.provider },
140002
140057
  ...screenshots.length > 0 && { screenshots },
140003
140058
  ...recordings.length > 0 && { recordings }
140004
140059
  });
@@ -142704,7 +142759,7 @@ async function startProxyServer() {
142704
142759
  system: repair_exports.SYSTEM
142705
142760
  };
142706
142761
  },
142707
- (result) => repair_exports.parseXML(result)
142762
+ (result) => repair_exports.parseXML(result.output)
142708
142763
  )
142709
142764
  );
142710
142765
  app.post(
@@ -11004,7 +11004,7 @@ var glob = Object.assign(glob_, {
11004
11004
  glob.glob = glob;
11005
11005
 
11006
11006
  // src/proxy/version.ts
11007
- var VERSION = "0.4.21";
11007
+ var VERSION = "0.4.23";
11008
11008
 
11009
11009
  // src/deps.ts
11010
11010
  var import_child_process = require("child_process");
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "staklink",
3
3
  "displayName": "staklink",
4
4
  "description": "staklink process manager",
5
- "version": "0.4.21",
5
+ "version": "0.4.23",
6
6
  "type": "module",
7
7
  "publisher": "stakwork",
8
8
  "engines": {