@datalayer/agent-runtimes 1.3.101 → 1.3.103

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.
@@ -185,6 +185,13 @@ export type AskA2APeerOptions = {
185
185
  * besides words comes with it, by media type. A task that ends other than
186
186
  * completed is thrown, with what the peer said.
187
187
  */
188
+ /**
189
+ * What a peer that refused said, in its own sentence (STUDIO H-25): the A2A
190
+ * client throws an HTTP refusal as `HTTP error … : 429 . Response:
191
+ * {"detail": "…"}`, which a balloon would draw as it is — the route's
192
+ * sentence (a visitor's limit, a paused deployment) is its `detail`.
193
+ */
194
+ export declare function peerRefusalOf(reason: unknown): string;
188
195
  export declare function askA2APeer(peer: A2APeer, request: string, options?: AskA2APeerOptions): Promise<A2APeerAnswer>;
189
196
  export type A2APeerToolOptions = {
190
197
  peer: A2APeer;
@@ -210,6 +210,28 @@ const ENDED_BADLY = {
210
210
  * besides words comes with it, by media type. A task that ends other than
211
211
  * completed is thrown, with what the peer said.
212
212
  */
213
+ /**
214
+ * What a peer that refused said, in its own sentence (STUDIO H-25): the A2A
215
+ * client throws an HTTP refusal as `HTTP error … : 429 . Response:
216
+ * {"detail": "…"}`, which a balloon would draw as it is — the route's
217
+ * sentence (a visitor's limit, a paused deployment) is its `detail`.
218
+ */
219
+ export function peerRefusalOf(reason) {
220
+ const message = reason instanceof Error ? reason.message : String(reason);
221
+ const body = /Response:\s*(\{[\s\S]*\})\s*$/.exec(message)?.[1];
222
+ if (body) {
223
+ try {
224
+ const detail = JSON.parse(body).detail;
225
+ if (typeof detail === 'string' && detail.trim()) {
226
+ return detail.trim();
227
+ }
228
+ }
229
+ catch {
230
+ // Not JSON: the message as it came.
231
+ }
232
+ }
233
+ return message;
234
+ }
213
235
  export async function askA2APeer(peer, request, options = {}) {
214
236
  const { signal, onEvent, accept, action } = options;
215
237
  onEvent?.({
@@ -221,9 +243,11 @@ export async function askA2APeer(peer, request, options = {}) {
221
243
  return await streamTask(peer, request, signal, onEvent, accept, action);
222
244
  }
223
245
  catch (reason) {
224
- const error = reason instanceof Error ? reason.message : String(reason);
246
+ const error = peerRefusalOf(reason);
225
247
  onEvent?.({ phase: 'failed', error });
226
- throw reason;
248
+ throw reason instanceof Error && error !== reason.message
249
+ ? new Error(error)
250
+ : reason;
227
251
  }
228
252
  }
229
253
  async function streamTask(peer, request, signal, onEvent, accept, action) {
@@ -384,9 +408,7 @@ export function a2aPeerTool(options) {
384
408
  : { answer };
385
409
  }
386
410
  catch (reason) {
387
- return {
388
- error: reason instanceof Error ? reason.message : String(reason),
389
- };
411
+ return { error: peerRefusalOf(reason) };
390
412
  }
391
413
  },
392
414
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@datalayer/agent-runtimes",
3
- "version": "1.3.101",
3
+ "version": "1.3.103",
4
4
  "type": "module",
5
5
  "workspaces": [
6
6
  ".",