@ziggs-ai/api-client 0.40.4 → 0.40.6

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.
@@ -64,34 +64,31 @@ function thrownFields(err) {
64
64
  const message = typeof o.message === 'string' && o.message ? o.message : String(err);
65
65
  return { message, status, code, choices: choicesIn(o.body) };
66
66
  }
67
- /** The `recovery` call of a refusal body, when the server sent one. */
68
- function recoveryIn(body) {
67
+ /** A refusal body's fields, when the server sent a JSON object. */
68
+ function refusalBody(body) {
69
69
  if (typeof body !== 'string' || !body)
70
70
  return null;
71
71
  try {
72
72
  const parsed = JSON.parse(body);
73
- const recovery = parsed?.recovery;
74
- if (!recovery || typeof recovery !== 'object' || Array.isArray(recovery))
75
- return null;
76
- return recovery;
73
+ return parsed && typeof parsed === 'object' && !Array.isArray(parsed)
74
+ ? parsed
75
+ : null;
77
76
  }
78
77
  catch {
79
78
  return null;
80
79
  }
81
80
  }
81
+ /** One object field of a refusal body (`recovery`, `impact`), when the server sent it. */
82
+ function objectIn(body, field) {
83
+ const value = refusalBody(body)?.[field];
84
+ return value && typeof value === 'object' && !Array.isArray(value)
85
+ ? value
86
+ : null;
87
+ }
82
88
  /** The `choices` list of a refusal body, when the server sent one. */
83
89
  function choicesIn(body) {
84
- if (typeof body !== 'string' || !body)
85
- return null;
86
- try {
87
- const parsed = JSON.parse(body);
88
- return Array.isArray(parsed?.choices)
89
- ? parsed.choices
90
- : null;
91
- }
92
- catch {
93
- return null;
94
- }
90
+ const choices = refusalBody(body)?.choices;
91
+ return Array.isArray(choices) ? choices : null;
95
92
  }
96
93
  /**
97
94
  * Classify a thrown client error (or a plain string this layer raised) into a
@@ -101,9 +98,9 @@ export function describeOperationError(input, surface = 'sdk') {
101
98
  input = unwrapApiError(input);
102
99
  const shape = classify(input);
103
100
  const { choices } = thrownFields(input);
104
- const recovery = typeof input === 'object' && input !== null
105
- ? recoveryIn(input.body)
106
- : null;
101
+ const body = typeof input === 'object' && input !== null ? input.body : undefined;
102
+ const recovery = objectIn(body, 'recovery');
103
+ const impact = objectIn(body, 'impact');
107
104
  let recoveryCursor;
108
105
  if (shape.code === 'INBOX_OBSERVATION_LIMIT' && input && typeof input === 'object') {
109
106
  try {
@@ -117,6 +114,7 @@ export function describeOperationError(input, surface = 'sdk') {
117
114
  ...shape,
118
115
  ...(recoveryCursor ? { recoveryCursor } : {}),
119
116
  ...(choices ? { choices } : {}),
117
+ ...(impact ? { impact } : {}),
120
118
  ...(recovery ? { recovery: typeof recovery.tool === 'string'
121
119
  ? { ...presentResourceCall(recovery, surface) }
122
120
  : recovery } : {}),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ziggs-ai/api-client",
3
- "version": "0.40.4",
3
+ "version": "0.40.6",
4
4
  "description": "HTTP and WebSocket client for the Ziggs backend API",
5
5
  "homepage": "https://ziggsai.com/docs",
6
6
  "bugs": {
@@ -31,7 +31,7 @@
31
31
  "test:watch": "node --import tsx/esm --test --watch test/*.test.ts"
32
32
  },
33
33
  "dependencies": {
34
- "@ziggs-ai/contracts": "0.46.0",
34
+ "@ziggs-ai/contracts": "0.48.0",
35
35
  "socket.io-client": "^4.7.0"
36
36
  },
37
37
  "keywords": [