@annals/agent-mesh 0.12.1 → 0.13.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 (2) hide show
  1. package/dist/index.js +73 -5
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -410,7 +410,9 @@ var BridgeManager = class {
410
410
  }
411
411
  }
412
412
  wireSession(handle, sessionId, requestRef) {
413
+ let fullResponseBuffer = "";
413
414
  handle.onChunk((delta) => {
415
+ fullResponseBuffer += delta;
414
416
  const chunk = {
415
417
  type: "chunk",
416
418
  session_id: sessionId,
@@ -438,10 +440,12 @@ var BridgeManager = class {
438
440
  type: "done",
439
441
  session_id: sessionId,
440
442
  request_id: requestRef.requestId,
441
- ...attachments && attachments.length > 0 && { attachments }
443
+ ...attachments && attachments.length > 0 && { attachments },
444
+ ...fullResponseBuffer && { result: fullResponseBuffer }
442
445
  };
443
446
  this.trackRequest(sessionId, requestRef.requestId, "done");
444
447
  this.wsClient.send(done);
448
+ fullResponseBuffer = "";
445
449
  this.sessionLastSeenAt.set(sessionId, Date.now());
446
450
  const fileInfo = attachments && attachments.length > 0 ? ` (${attachments.length} files)` : "";
447
451
  log.info(`Request done: session=${sessionId.slice(0, 8)}... request=${requestRef.requestId.slice(0, 8)}...${fileInfo}`);
@@ -2897,7 +2901,68 @@ function parseSseChunk(raw, carry) {
2897
2901
 
2898
2902
  // src/commands/chat.ts
2899
2903
  var DEFAULT_BASE_URL3 = "https://agents.hot";
2904
+ function sleep4(ms) {
2905
+ return new Promise((resolve2) => setTimeout(resolve2, ms));
2906
+ }
2907
+ async function asyncChat(opts) {
2908
+ const res = await fetch(`${opts.baseUrl}/api/agents/${opts.agentId}/chat`, {
2909
+ method: "POST",
2910
+ headers: {
2911
+ Authorization: `Bearer ${opts.token}`,
2912
+ "Content-Type": "application/json"
2913
+ },
2914
+ body: JSON.stringify({ message: opts.message, mode: "async" }),
2915
+ signal: opts.signal
2916
+ });
2917
+ if (!res.ok) {
2918
+ let msg = `HTTP ${res.status}`;
2919
+ try {
2920
+ const body = await res.json();
2921
+ msg = body.message || body.error || msg;
2922
+ } catch {
2923
+ }
2924
+ throw new Error(msg);
2925
+ }
2926
+ const { task_id, status, error_message, error_code } = await res.json();
2927
+ if (status === "failed") {
2928
+ throw new Error(`Task failed: ${error_message || error_code}`);
2929
+ }
2930
+ process.stderr.write(`${GRAY}[async] task=${task_id.slice(0, 8)}... polling${RESET}`);
2931
+ const maxWait = 5 * 60 * 1e3;
2932
+ const pollInterval = 2e3;
2933
+ const startTime = Date.now();
2934
+ while (Date.now() - startTime < maxWait) {
2935
+ if (opts.signal?.aborted) throw new Error("Aborted");
2936
+ await sleep4(pollInterval);
2937
+ const pollRes = await fetch(`${opts.baseUrl}/api/tasks/${task_id}`, {
2938
+ headers: { Authorization: `Bearer ${opts.token}` },
2939
+ signal: opts.signal
2940
+ });
2941
+ if (!pollRes.ok) {
2942
+ throw new Error(`Poll failed: HTTP ${pollRes.status}`);
2943
+ }
2944
+ const task = await pollRes.json();
2945
+ if (task.status === "completed") {
2946
+ process.stderr.write(` done
2947
+ `);
2948
+ process.stdout.write((task.result || "") + "\n");
2949
+ return;
2950
+ }
2951
+ if (task.status === "failed") {
2952
+ process.stderr.write(` failed
2953
+ `);
2954
+ throw new Error(`Task failed: ${task.error_message || task.error_code}`);
2955
+ }
2956
+ process.stderr.write(".");
2957
+ }
2958
+ process.stderr.write(` timeout
2959
+ `);
2960
+ throw new Error("Task timed out waiting for result");
2961
+ }
2900
2962
  async function streamChat(opts) {
2963
+ if ((opts.mode ?? "async") === "async") {
2964
+ return asyncChat(opts);
2965
+ }
2901
2966
  const res = await fetch(`${opts.baseUrl}/api/agents/${opts.agentId}/chat`, {
2902
2967
  method: "POST",
2903
2968
  headers: {
@@ -2998,7 +3063,7 @@ ${"\x1B[31m"}Error: ${event.errorText}${RESET}
2998
3063
  }
2999
3064
  }
3000
3065
  function registerChatCommand(program2) {
3001
- program2.command("chat <agent> [message]").description("Chat with an agent through the platform (for debugging)").option("--no-thinking", "Hide thinking/reasoning output").option("--base-url <url>", "Platform base URL", DEFAULT_BASE_URL3).action(async (agentInput, inlineMessage, opts) => {
3066
+ program2.command("chat <agent> [message]").description("Chat with an agent through the platform (for debugging)").option("--no-thinking", "Hide thinking/reasoning output").option("--stream", "Force SSE streaming mode (default is async)").option("--base-url <url>", "Platform base URL", DEFAULT_BASE_URL3).action(async (agentInput, inlineMessage, opts) => {
3002
3067
  const token = loadToken();
3003
3068
  if (!token) {
3004
3069
  log.error("Not authenticated. Run `agent-mesh login` first.");
@@ -3015,15 +3080,17 @@ function registerChatCommand(program2) {
3015
3080
  log.error(err.message);
3016
3081
  process.exit(1);
3017
3082
  }
3083
+ const mode = opts.stream ? "stream" : "async";
3018
3084
  if (inlineMessage) {
3019
- log.info(`Chatting with ${BOLD}${agentName}${RESET}`);
3085
+ log.info(`Chatting with ${BOLD}${agentName}${RESET} (${mode})`);
3020
3086
  try {
3021
3087
  await streamChat({
3022
3088
  agentId,
3023
3089
  message: inlineMessage,
3024
3090
  token,
3025
3091
  baseUrl: opts.baseUrl,
3026
- showThinking: opts.thinking
3092
+ showThinking: opts.thinking,
3093
+ mode
3027
3094
  });
3028
3095
  } catch (err) {
3029
3096
  log.error(err.message);
@@ -3067,7 +3134,8 @@ function registerChatCommand(program2) {
3067
3134
  message: trimmed,
3068
3135
  token,
3069
3136
  baseUrl: opts.baseUrl,
3070
- showThinking: opts.thinking
3137
+ showThinking: opts.thinking,
3138
+ mode
3071
3139
  });
3072
3140
  } catch (err) {
3073
3141
  if (abortController.signal.aborted) return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@annals/agent-mesh",
3
- "version": "0.12.1",
3
+ "version": "0.13.0",
4
4
  "description": "CLI bridge connecting local AI agents to the Agents.Hot platform",
5
5
  "type": "module",
6
6
  "bin": {