@openagents-org/agent-launcher 0.2.151 → 0.2.152

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.
@@ -192,26 +192,29 @@ class WorkspaceClient {
192
192
  }
193
193
 
194
194
  /**
195
- * Fetch the most recent N messages in a channel, returned oldest-to-newest.
196
- * Used by adapters to rebuild context for a fresh Claude Code session
197
- * when --resume of the previous session fails (the channel's chat history
198
- * is the only thing that survives a session-storage rotation).
195
+ * Fetch N messages in a channel, returned oldest-to-newest. `sort` picks
196
+ * which end of the channel the window comes from: 'desc' (default) takes
197
+ * the most recent N, 'asc' takes the channel's opening N. Used by adapters
198
+ * to rebuild context for a fresh Claude Code session when --resume of the
199
+ * previous session fails (the channel's chat history is the only thing
200
+ * that survives a session-storage rotation).
199
201
  */
200
- async getRecentMessages(workspaceId, channelName, token, limit = 30) {
202
+ async getRecentMessages(workspaceId, channelName, token, limit = 30, { sort = 'desc' } = {}) {
201
203
  try {
202
204
  const params = new URLSearchParams({
203
205
  network: workspaceId,
204
206
  channel: channelName,
205
207
  type: 'workspace.message',
206
- sort: 'desc',
208
+ sort,
207
209
  limit: String(limit),
208
210
  });
209
211
  const data = await this._get(`/v1/events?${params}`, this._wsHeaders(token));
210
212
  const result = data.data || data;
211
213
  const events = (result && result.events) || [];
212
- // Server returned newest-first; reverse so the caller can present them
213
- // in chronological order without further fiddling.
214
- return events.slice().reverse().map((e) => this._eventToMessage(e));
214
+ // A desc window arrives newest-first; reverse so the caller always gets
215
+ // chronological order. An asc window is already chronological.
216
+ const ordered = sort === 'asc' ? events.slice() : events.slice().reverse();
217
+ return ordered.map((e) => this._eventToMessage(e));
215
218
  } catch {
216
219
  return [];
217
220
  }
@@ -471,6 +474,31 @@ class WorkspaceClient {
471
474
  return data.data || data;
472
475
  }
473
476
 
477
+ /**
478
+ * Search the web for images via POST /v1/search/images.
479
+ */
480
+ async searchImages(workspaceId, token, query, { count = 10 } = {}) {
481
+ const body = { query, network: workspaceId, count };
482
+ const data = await this._post('/v1/search/images', body, this._wsHeaders(token), 30000);
483
+ return data.data || data;
484
+ }
485
+
486
+ /**
487
+ * Download a URL into workspace storage via POST /v1/files/from_url.
488
+ * With postToChannel, the file is also posted into the chat as an
489
+ * inline attachment.
490
+ */
491
+ async uploadFileFromUrl(workspaceId, token, url, {
492
+ filename, channelName, source = 'human:user', postToChannel = false, caption,
493
+ } = {}) {
494
+ const body = { url, network: workspaceId, source, post_to_channel: postToChannel };
495
+ if (filename) body.filename = filename;
496
+ if (channelName) body.channel_name = channelName;
497
+ if (caption) body.caption = caption;
498
+ const data = await this._post('/v1/files/from_url', body, this._wsHeaders(token), 90000);
499
+ return data.data || data;
500
+ }
501
+
474
502
  /**
475
503
  * List files via GET /v1/files.
476
504
  */
@@ -583,6 +611,19 @@ class WorkspaceClient {
583
611
  return data.data || data;
584
612
  }
585
613
 
614
+ /**
615
+ * Server-side fetch chain via POST /v1/fetch — reads a page WITHOUT
616
+ * holding a shared browser tab. Static HTTP first; JS-heavy pages are
617
+ * rendered in an ephemeral browser session that is closed immediately.
618
+ */
619
+ async fetchUrl(workspaceId, token, url, { mode = 'auto', maxChars, source } = {}) {
620
+ const body = { url, network: workspaceId, mode };
621
+ if (maxChars) body.max_chars = maxChars;
622
+ if (source) body.source = source;
623
+ const data = await this._post('/v1/fetch', body, this._wsHeaders(token), 90000);
624
+ return data.data || data;
625
+ }
626
+
586
627
  /**
587
628
  * List persistent browser contexts via GET /v1/browser/contexts.
588
629
  */
@@ -699,18 +740,18 @@ class WorkspaceClient {
699
740
 
700
741
  // ── Knowledge Base ──
701
742
 
702
- async listKnowledge(workspaceId, token, { limit = 100 } = {}) {
743
+ async listKnowledge(workspaceId, token, { limit = 100, timeout } = {}) {
703
744
  const params = new URLSearchParams({
704
745
  network: workspaceId,
705
746
  limit: String(limit),
706
747
  });
707
- const data = await this._get(`/v1/knowledge?${params}`, this._wsHeaders(token));
748
+ const data = await this._get(`/v1/knowledge?${params}`, this._wsHeaders(token), timeout);
708
749
  return data.data || data;
709
750
  }
710
751
 
711
- async getKnowledge(workspaceId, token, entryId) {
752
+ async getKnowledge(workspaceId, token, entryId, { timeout } = {}) {
712
753
  const params = new URLSearchParams({ network: workspaceId });
713
- const data = await this._get(`/v1/knowledge/${entryId}?${params}`, this._wsHeaders(token));
754
+ const data = await this._get(`/v1/knowledge/${entryId}?${params}`, this._wsHeaders(token), timeout);
714
755
  return data.data || data;
715
756
  }
716
757
 
@@ -878,7 +919,11 @@ class WorkspaceClient {
878
919
  if (typeof msg === 'string' && msg.toLowerCase().includes('session_revoked')) {
879
920
  reject(new SessionRevokedError(msg));
880
921
  } else {
881
- reject(new Error(msg));
922
+ const err = new Error(msg);
923
+ // Preserve structured error details (error_code, hint,
924
+ // quota occupancy, ...) so tool handlers can surface them.
925
+ if (parsed.data && typeof parsed.data === 'object') err.data = parsed.data;
926
+ reject(err);
882
927
  }
883
928
  } else {
884
929
  resolve(parsed);