@quiverai/sdk 0.7.1 → 0.8.1

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 (128) hide show
  1. package/dist/commonjs/funcs/createSVGsGenerateSVG.js +1 -1
  2. package/dist/commonjs/funcs/createSVGsGenerateSVG.js.map +1 -1
  3. package/dist/commonjs/funcs/modelsGetModel.js +1 -1
  4. package/dist/commonjs/funcs/modelsGetModel.js.map +1 -1
  5. package/dist/commonjs/funcs/modelsListModels.js +1 -1
  6. package/dist/commonjs/funcs/modelsListModels.js.map +1 -1
  7. package/dist/commonjs/funcs/vectorizeSVGVectorizeSVG.js +1 -4
  8. package/dist/commonjs/funcs/vectorizeSVGVectorizeSVG.js.map +1 -1
  9. package/dist/commonjs/hooks/types.d.ts +1 -0
  10. package/dist/commonjs/hooks/types.d.ts.map +1 -1
  11. package/dist/commonjs/lib/config.d.ts +3 -3
  12. package/dist/commonjs/lib/config.js +3 -3
  13. package/dist/commonjs/lib/encodings.js +12 -12
  14. package/dist/commonjs/lib/encodings.js.map +1 -1
  15. package/dist/commonjs/lib/event-streams.d.ts.map +1 -1
  16. package/dist/commonjs/lib/event-streams.js +28 -13
  17. package/dist/commonjs/lib/event-streams.js.map +1 -1
  18. package/dist/commonjs/lib/matchers.js +3 -3
  19. package/dist/commonjs/lib/matchers.js.map +1 -1
  20. package/dist/commonjs/lib/primitives.d.ts +1 -0
  21. package/dist/commonjs/lib/primitives.d.ts.map +1 -1
  22. package/dist/commonjs/lib/primitives.js +18 -0
  23. package/dist/commonjs/lib/primitives.js.map +1 -1
  24. package/dist/commonjs/lib/sdks.d.ts.map +1 -1
  25. package/dist/commonjs/lib/sdks.js +50 -16
  26. package/dist/commonjs/lib/sdks.js.map +1 -1
  27. package/dist/commonjs/sdk/models/shared/index.d.ts +1 -0
  28. package/dist/commonjs/sdk/models/shared/index.d.ts.map +1 -1
  29. package/dist/commonjs/sdk/models/shared/index.js +1 -0
  30. package/dist/commonjs/sdk/models/shared/index.js.map +1 -1
  31. package/dist/commonjs/sdk/models/shared/publicerrorenvelope.d.ts +8 -4
  32. package/dist/commonjs/sdk/models/shared/publicerrorenvelope.d.ts.map +1 -1
  33. package/dist/commonjs/sdk/models/shared/publicerrorenvelope.js +8 -4
  34. package/dist/commonjs/sdk/models/shared/publicerrorenvelope.js.map +1 -1
  35. package/dist/commonjs/sdk/models/shared/publicerrorsseeventdata.d.ts +40 -0
  36. package/dist/commonjs/sdk/models/shared/publicerrorsseeventdata.d.ts.map +1 -0
  37. package/dist/commonjs/sdk/models/shared/publicerrorsseeventdata.js +82 -0
  38. package/dist/commonjs/sdk/models/shared/publicerrorsseeventdata.js.map +1 -0
  39. package/dist/commonjs/sdk/models/shared/svgstreamevent.d.ts +25 -6
  40. package/dist/commonjs/sdk/models/shared/svgstreamevent.d.ts.map +1 -1
  41. package/dist/commonjs/sdk/models/shared/svgstreamevent.js +30 -6
  42. package/dist/commonjs/sdk/models/shared/svgstreamevent.js.map +1 -1
  43. package/dist/commonjs/sdk/models/shared/svgstreameventdata.d.ts +4 -1
  44. package/dist/commonjs/sdk/models/shared/svgstreameventdata.d.ts.map +1 -1
  45. package/dist/commonjs/sdk/models/shared/svgstreameventdata.js +2 -0
  46. package/dist/commonjs/sdk/models/shared/svgstreameventdata.js.map +1 -1
  47. package/dist/esm/funcs/createSVGsGenerateSVG.js +1 -1
  48. package/dist/esm/funcs/createSVGsGenerateSVG.js.map +1 -1
  49. package/dist/esm/funcs/modelsGetModel.js +1 -1
  50. package/dist/esm/funcs/modelsGetModel.js.map +1 -1
  51. package/dist/esm/funcs/modelsListModels.js +1 -1
  52. package/dist/esm/funcs/modelsListModels.js.map +1 -1
  53. package/dist/esm/funcs/vectorizeSVGVectorizeSVG.js +1 -4
  54. package/dist/esm/funcs/vectorizeSVGVectorizeSVG.js.map +1 -1
  55. package/dist/esm/hooks/types.d.ts +1 -0
  56. package/dist/esm/hooks/types.d.ts.map +1 -1
  57. package/dist/esm/lib/config.d.ts +3 -3
  58. package/dist/esm/lib/config.js +3 -3
  59. package/dist/esm/lib/encodings.js +1 -1
  60. package/dist/esm/lib/encodings.js.map +1 -1
  61. package/dist/esm/lib/event-streams.d.ts.map +1 -1
  62. package/dist/esm/lib/event-streams.js +28 -13
  63. package/dist/esm/lib/event-streams.js.map +1 -1
  64. package/dist/esm/lib/matchers.js +1 -1
  65. package/dist/esm/lib/matchers.js.map +1 -1
  66. package/dist/esm/lib/primitives.d.ts +1 -0
  67. package/dist/esm/lib/primitives.d.ts.map +1 -1
  68. package/dist/esm/lib/primitives.js +17 -0
  69. package/dist/esm/lib/primitives.js.map +1 -1
  70. package/dist/esm/lib/sdks.d.ts.map +1 -1
  71. package/dist/esm/lib/sdks.js +50 -16
  72. package/dist/esm/lib/sdks.js.map +1 -1
  73. package/dist/esm/sdk/models/shared/index.d.ts +1 -0
  74. package/dist/esm/sdk/models/shared/index.d.ts.map +1 -1
  75. package/dist/esm/sdk/models/shared/index.js +1 -0
  76. package/dist/esm/sdk/models/shared/index.js.map +1 -1
  77. package/dist/esm/sdk/models/shared/publicerrorenvelope.d.ts +8 -4
  78. package/dist/esm/sdk/models/shared/publicerrorenvelope.d.ts.map +1 -1
  79. package/dist/esm/sdk/models/shared/publicerrorenvelope.js +8 -4
  80. package/dist/esm/sdk/models/shared/publicerrorenvelope.js.map +1 -1
  81. package/dist/esm/sdk/models/shared/publicerrorsseeventdata.d.ts +40 -0
  82. package/dist/esm/sdk/models/shared/publicerrorsseeventdata.d.ts.map +1 -0
  83. package/dist/esm/sdk/models/shared/publicerrorsseeventdata.js +45 -0
  84. package/dist/esm/sdk/models/shared/publicerrorsseeventdata.js.map +1 -0
  85. package/dist/esm/sdk/models/shared/svgstreamevent.d.ts +25 -6
  86. package/dist/esm/sdk/models/shared/svgstreamevent.d.ts.map +1 -1
  87. package/dist/esm/sdk/models/shared/svgstreamevent.js +28 -5
  88. package/dist/esm/sdk/models/shared/svgstreamevent.js.map +1 -1
  89. package/dist/esm/sdk/models/shared/svgstreameventdata.d.ts +4 -1
  90. package/dist/esm/sdk/models/shared/svgstreameventdata.d.ts.map +1 -1
  91. package/dist/esm/sdk/models/shared/svgstreameventdata.js +2 -0
  92. package/dist/esm/sdk/models/shared/svgstreameventdata.js.map +1 -1
  93. package/jsr.json +1 -1
  94. package/package.json +1 -1
  95. package/src/funcs/createSVGsGenerateSVG.ts +2 -2
  96. package/src/funcs/modelsGetModel.ts +2 -2
  97. package/src/funcs/modelsListModels.ts +2 -2
  98. package/src/funcs/vectorizeSVGVectorizeSVG.ts +6 -5
  99. package/src/hooks/types.ts +1 -0
  100. package/src/lib/config.ts +3 -3
  101. package/src/lib/encodings.ts +1 -1
  102. package/src/lib/event-streams.ts +31 -13
  103. package/src/lib/matchers.ts +1 -1
  104. package/src/lib/primitives.ts +16 -0
  105. package/src/lib/sdks.ts +54 -17
  106. package/src/sdk/models/shared/index.ts +1 -0
  107. package/src/sdk/models/shared/publicerrorenvelope.ts +8 -4
  108. package/src/sdk/models/shared/publicerrorsseeventdata.ts +80 -0
  109. package/src/sdk/models/shared/svgstreamevent.ts +59 -11
  110. package/src/sdk/models/shared/svgstreameventdata.ts +8 -0
  111. package/dist/commonjs/lib/dlv.d.ts +0 -14
  112. package/dist/commonjs/lib/dlv.d.ts.map +0 -1
  113. package/dist/commonjs/lib/dlv.js +0 -49
  114. package/dist/commonjs/lib/dlv.js.map +0 -1
  115. package/dist/commonjs/lib/is-plain-object.d.ts +0 -2
  116. package/dist/commonjs/lib/is-plain-object.d.ts.map +0 -1
  117. package/dist/commonjs/lib/is-plain-object.js +0 -41
  118. package/dist/commonjs/lib/is-plain-object.js.map +0 -1
  119. package/dist/esm/lib/dlv.d.ts +0 -14
  120. package/dist/esm/lib/dlv.d.ts.map +0 -1
  121. package/dist/esm/lib/dlv.js +0 -46
  122. package/dist/esm/lib/dlv.js.map +0 -1
  123. package/dist/esm/lib/is-plain-object.d.ts +0 -2
  124. package/dist/esm/lib/is-plain-object.d.ts.map +0 -1
  125. package/dist/esm/lib/is-plain-object.js +0 -38
  126. package/dist/esm/lib/is-plain-object.js.map +0 -1
  127. package/src/lib/dlv.ts +0 -53
  128. package/src/lib/is-plain-object.ts +0 -43
@@ -26,22 +26,45 @@ export class EventStream<T extends SseMessage<unknown>>
26
26
  opts?: { dataRequired?: boolean },
27
27
  ) {
28
28
  const upstream = responseBody.getReader();
29
- let buffer: Uint8Array = new Uint8Array();
29
+ let buffer: Uint8Array = new Uint8Array(4096);
30
+ let bufferLen = 0;
31
+ let searchStart = 0;
30
32
  const state = { eventId: undefined as string | undefined };
31
33
  const dataRequired = opts?.dataRequired ?? true;
32
34
  super({
33
35
  async pull(downstream) {
34
36
  try {
35
37
  while (true) {
36
- const match = findBoundary(buffer);
38
+ const match = findBoundary(buffer, bufferLen, searchStart);
37
39
  if (!match) {
40
+ // Bytes before the trailing MAX_BOUNDARY_LEN-1 were already
41
+ // scanned with full lookahead and cannot start a boundary even
42
+ // once more data arrives, so the next scan can skip them.
43
+ searchStart = Math.max(0, bufferLen - MAX_BOUNDARY_LEN + 1);
38
44
  const chunk = await upstream.read();
39
45
  if (chunk.done) return downstream.close();
40
- buffer = concatBuffer(buffer, chunk.value);
46
+ if (bufferLen + chunk.value.length > buffer.length) {
47
+ const grown = new Uint8Array(
48
+ Math.max(buffer.length * 2, bufferLen + chunk.value.length),
49
+ );
50
+ grown.set(buffer.subarray(0, bufferLen));
51
+ buffer = grown;
52
+ }
53
+ buffer.set(chunk.value, bufferLen);
54
+ bufferLen += chunk.value.length;
41
55
  continue;
42
56
  }
43
57
  const message = buffer.slice(0, match.index);
44
- buffer = buffer.slice(match.index + match.length);
58
+ buffer.copyWithin(0, match.index + match.length, bufferLen);
59
+ bufferLen -= match.index + match.length;
60
+ if (buffer.length > 4096 && bufferLen <= buffer.length >> 2) {
61
+ // Release oversized capacity retained after an unusually large
62
+ // event so long-lived streams do not hold peak memory.
63
+ const shrunk = new Uint8Array(Math.max(4096, bufferLen * 2));
64
+ shrunk.set(buffer.subarray(0, bufferLen));
65
+ buffer = shrunk;
66
+ }
67
+ searchStart = 0;
45
68
  const item = parseMessage(message, parse, state, dataRequired);
46
69
  if (item && !item.done) return downstream.enqueue(item.value);
47
70
  if (item?.done) {
@@ -89,13 +112,6 @@ export class EventStream<T extends SseMessage<unknown>>
89
112
  }
90
113
  }
91
114
 
92
- function concatBuffer(a: Uint8Array, b: Uint8Array): Uint8Array {
93
- const c = new Uint8Array(a.length + b.length);
94
- c.set(a, 0);
95
- c.set(b, a.length);
96
- return c;
97
- }
98
-
99
115
  const CR = 13;
100
116
  const LF = 10;
101
117
  const BOUNDARIES = [
@@ -108,12 +124,14 @@ const BOUNDARIES = [
108
124
  [LF, CR], // \n\r
109
125
  [LF, LF], // \n\n
110
126
  ];
127
+ const MAX_BOUNDARY_LEN = BOUNDARIES.reduce((m, b) => Math.max(m, b.length), 0);
111
128
 
112
129
  function findBoundary(
113
130
  buf: Uint8Array,
131
+ len: number,
132
+ from: number,
114
133
  ): { index: number; length: number } | null {
115
- const len = buf.length;
116
- for (let i = 0; i < len; i++) {
134
+ for (let i = from; i < len; i++) {
117
135
  if (buf[i] !== CR && buf[i] !== LF) continue;
118
136
  for (const boundary of BOUNDARIES) {
119
137
  if (i + boundary.length > len) continue;
@@ -6,7 +6,7 @@ import { ResponseValidationError } from "../sdk/models/errors/responsevalidation
6
6
  import { SDKError } from "../sdk/models/errors/sdkerror.js";
7
7
  import { ERR, OK, Result } from "../sdk/types/fp.js";
8
8
  import { matchResponse, matchStatusCode, StatusCodePredicate } from "./http.js";
9
- import { isPlainObject } from "./is-plain-object.js";
9
+ import { isPlainObject } from "./primitives.js";
10
10
 
11
11
  export type Encoding =
12
12
  | "jsonl"
@@ -148,3 +148,19 @@ export function allRequired<V extends Record<string, unknown>>(
148
148
 
149
149
  return v as ReturnType<typeof allRequired<V>>;
150
150
  }
151
+
152
+ export function isPlainObject(
153
+ value: unknown,
154
+ ): value is Record<string, unknown> {
155
+ if (value === null || typeof value !== "object") return false;
156
+ if (Object.prototype.toString.call(value) !== "[object Object]") return false;
157
+ const proto = Object.getPrototypeOf(value);
158
+ if (proto === null || proto === Object.prototype) return true;
159
+ // cross-realm plain objects (vm contexts, iframes) inherit from a
160
+ // different realm's Object.prototype, which itself has a null prototype
161
+ try {
162
+ return Object.getPrototypeOf(proto) === null;
163
+ } catch {
164
+ return false;
165
+ }
166
+ }
package/src/lib/sdks.ts CHANGED
@@ -23,6 +23,7 @@ import {
23
23
  matchContentType,
24
24
  } from "./http.js";
25
25
  import { Logger } from "./logger.js";
26
+ import { combineSignals } from "./primitives.js";
26
27
  import { retry, RetryConfig } from "./retries.js";
27
28
  import { SecurityState } from "./security.js";
28
29
 
@@ -128,27 +129,55 @@ export class ClientSDK {
128
129
  if (path) {
129
130
  baseURL.pathname = baseURL.pathname.replace(/\/+$/, "") + "/";
130
131
  reqURL = new URL(path, baseURL);
132
+ if (!reqURL.search && baseURL.search) {
133
+ reqURL.search = baseURL.search;
134
+ }
131
135
  } else {
132
136
  reqURL = baseURL;
133
137
  }
134
138
  reqURL.hash = "";
135
139
 
136
- let finalQuery = query || "";
137
-
138
- const secQuery: string[] = [];
139
- for (const [k, v] of Object.entries(security?.queryParams || {})) {
140
- const q = encodeForm(k, v, { charEncoding: "percent" });
141
- if (typeof q !== "undefined") {
142
- secQuery.push(q);
140
+ // Appends already-encoded query pairs to a query string, replacing any
141
+ // existing pairs with the same key so later sources take precedence.
142
+ const mergeQuery = (current: string, additions: string): string => {
143
+ if (!additions) {
144
+ return current;
143
145
  }
144
- }
145
- if (secQuery.length) {
146
- finalQuery += `&${secQuery.join("&")}`;
147
- }
146
+ const additionKeys = new Set(
147
+ additions
148
+ .split("&")
149
+ .filter((pair) => pair !== "")
150
+ .map((pair) => pair.split("=")[0] ?? ""),
151
+ );
152
+ const kept = current.split("&").filter((pair) => {
153
+ return pair !== "" && !additionKeys.has(pair.split("=")[0] ?? "");
154
+ });
155
+ return [...kept, additions].join("&");
156
+ };
157
+
158
+ const encodeQueryRecord = (record: Record<string, unknown>): string => {
159
+ return Object.entries(record)
160
+ .map(([k, v]) => {
161
+ if (v == null) {
162
+ return undefined;
163
+ }
164
+ const value = v;
165
+ return encodeForm(k, value, {
166
+ explode: Array.isArray(value),
167
+ charEncoding: "percent",
168
+ });
169
+ })
170
+ .filter((pair): pair is string => typeof pair !== "undefined")
171
+ .join("&");
172
+ };
173
+
174
+ const finalQuery = [
175
+ query || "",
176
+ encodeQueryRecord(security?.queryParams || {}),
177
+ ].reduce(mergeQuery, reqURL.search.slice(1));
148
178
 
149
179
  if (finalQuery) {
150
- const q = finalQuery.startsWith("&") ? finalQuery.slice(1) : finalQuery;
151
- reqURL.search = `?${q}`;
180
+ reqURL.search = `?${finalQuery}`;
152
181
  }
153
182
 
154
183
  const headers = new Headers(opHeaders);
@@ -194,9 +223,8 @@ export class ClientSDK {
194
223
  ...options?.fetchOptions,
195
224
  ...options,
196
225
  };
197
- if (!fetchOptions?.signal && conf.timeoutMs && conf.timeoutMs > 0) {
198
- const timeoutSignal = AbortSignal.timeout(conf.timeoutMs);
199
- fetchOptions.signal = timeoutSignal;
226
+ if (!fetchOptions?.signal && conf.timeoutMs != null && conf.timeoutMs > 0) {
227
+ context.timeoutMs = conf.timeoutMs;
200
228
  }
201
229
 
202
230
  if (conf.body instanceof ReadableStream) {
@@ -243,10 +271,19 @@ export class ClientSDK {
243
271
  >
244
272
  > {
245
273
  const { context, isErrorStatusCode } = options;
274
+ const timeoutMs = context.timeoutMs;
246
275
 
247
276
  return retry(
248
277
  async () => {
249
- const req = await this.#hooks.beforeRequest(context, request.clone());
278
+ const cloned = request.clone();
279
+ let attempt = cloned;
280
+ if (timeoutMs != null && timeoutMs > 0) {
281
+ const timeoutSignal = AbortSignal.timeout(timeoutMs);
282
+ const combined = combineSignals(cloned.signal, timeoutSignal)
283
+ ?? timeoutSignal;
284
+ attempt = new Request(cloned, { signal: combined });
285
+ }
286
+ const req = await this.#hooks.beforeRequest(context, attempt);
250
287
  await logRequest(this.#logger, req).catch((e) =>
251
288
  this.#logger?.log("Failed to log request:", e)
252
289
  );
@@ -10,6 +10,7 @@ export * from "./imageinputreferenceurl.js";
10
10
  export * from "./listmodelsresponse.js";
11
11
  export * from "./model.js";
12
12
  export * from "./publicerrorenvelope.js";
13
+ export * from "./publicerrorsseeventdata.js";
13
14
  export * from "./security.js";
14
15
  export * from "./svgattributes.js";
15
16
  export * from "./svgcontenteventdata.js";
@@ -13,13 +13,17 @@ export const Code = {
13
13
  InvalidRequest: "invalid_request",
14
14
  InvalidApiKey: "invalid_api_key",
15
15
  Unauthorized: "unauthorized",
16
- RateLimitExceeded: "rate_limit_exceeded",
17
- WeeklyLimitExceeded: "weekly_limit_exceeded",
18
16
  InsufficientCredits: "insufficient_credits",
19
17
  AccountFrozen: "account_frozen",
18
+ ContentPolicyViolation: "content_policy_violation",
20
19
  ModelNotFound: "model_not_found",
21
- UpstreamError: "upstream_error",
22
- InternalError: "internal_error",
20
+ PayloadTooLarge: "payload_too_large",
21
+ RequestTimeout: "request_timeout",
22
+ RateLimitExceeded: "rate_limit_exceeded",
23
+ WeeklyLimitExceeded: "weekly_limit_exceeded",
24
+ ServerError: "server_error",
25
+ ModelError: "model_error",
26
+ ModelUnavailable: "model_unavailable",
23
27
  } as const;
24
28
  export type Code = ClosedEnum<typeof Code>;
25
29
 
@@ -0,0 +1,80 @@
1
+ /*
2
+ * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
3
+ */
4
+
5
+ import * as z from "zod/v3";
6
+ import { remap as remap$ } from "../../../lib/primitives.js";
7
+ import { safeParse } from "../../../lib/schemas.js";
8
+ import { ClosedEnum } from "../../types/enums.js";
9
+ import { Result as SafeParseResult } from "../../types/fp.js";
10
+ import { SDKValidationError } from "../errors/sdkvalidationerror.js";
11
+
12
+ export const PublicErrorSseEventDataCode = {
13
+ InvalidRequest: "invalid_request",
14
+ InvalidApiKey: "invalid_api_key",
15
+ Unauthorized: "unauthorized",
16
+ InsufficientCredits: "insufficient_credits",
17
+ AccountFrozen: "account_frozen",
18
+ ContentPolicyViolation: "content_policy_violation",
19
+ ModelNotFound: "model_not_found",
20
+ PayloadTooLarge: "payload_too_large",
21
+ RequestTimeout: "request_timeout",
22
+ RateLimitExceeded: "rate_limit_exceeded",
23
+ WeeklyLimitExceeded: "weekly_limit_exceeded",
24
+ ServerError: "server_error",
25
+ ModelError: "model_error",
26
+ ModelUnavailable: "model_unavailable",
27
+ } as const;
28
+ export type PublicErrorSseEventDataCode = ClosedEnum<
29
+ typeof PublicErrorSseEventDataCode
30
+ >;
31
+
32
+ export const Type = {
33
+ Error: "error",
34
+ } as const;
35
+ export type Type = ClosedEnum<typeof Type>;
36
+
37
+ export type PublicErrorSseEventData = {
38
+ code: PublicErrorSseEventDataCode;
39
+ message: string;
40
+ requestId: string;
41
+ status: number;
42
+ type: Type;
43
+ };
44
+
45
+ /** @internal */
46
+ export const PublicErrorSseEventDataCode$inboundSchema: z.ZodNativeEnum<
47
+ typeof PublicErrorSseEventDataCode
48
+ > = z.nativeEnum(PublicErrorSseEventDataCode);
49
+
50
+ /** @internal */
51
+ export const Type$inboundSchema: z.ZodNativeEnum<typeof Type> = z.nativeEnum(
52
+ Type,
53
+ );
54
+
55
+ /** @internal */
56
+ export const PublicErrorSseEventData$inboundSchema: z.ZodType<
57
+ PublicErrorSseEventData,
58
+ z.ZodTypeDef,
59
+ unknown
60
+ > = z.object({
61
+ code: PublicErrorSseEventDataCode$inboundSchema,
62
+ message: z.string(),
63
+ request_id: z.string(),
64
+ status: z.number().int(),
65
+ type: Type$inboundSchema,
66
+ }).transform((v) => {
67
+ return remap$(v, {
68
+ "request_id": "requestId",
69
+ });
70
+ });
71
+
72
+ export function publicErrorSseEventDataFromJSON(
73
+ jsonString: string,
74
+ ): SafeParseResult<PublicErrorSseEventData, SDKValidationError> {
75
+ return safeParse(
76
+ jsonString,
77
+ (x) => PublicErrorSseEventData$inboundSchema.parse(JSON.parse(x)),
78
+ `Failed to parse 'PublicErrorSseEventData' from JSON`,
79
+ );
80
+ }
@@ -6,12 +6,16 @@ import * as z from "zod/v3";
6
6
  import { safeParse } from "../../../lib/schemas.js";
7
7
  import { Result as SafeParseResult } from "../../types/fp.js";
8
8
  import { SDKValidationError } from "../errors/sdkvalidationerror.js";
9
+ import {
10
+ PublicErrorSseEventData,
11
+ PublicErrorSseEventData$inboundSchema,
12
+ } from "./publicerrorsseeventdata.js";
9
13
  import {
10
14
  SvgStreamEventData,
11
15
  SvgStreamEventData$inboundSchema,
12
16
  } from "./svgstreameventdata.js";
13
17
 
14
- export type Four = {
18
+ export type Five = {
15
19
  /**
16
20
  * The event payload. Shape depends on the `type` phase discriminator.
17
21
  */
@@ -30,7 +34,7 @@ export type Four = {
30
34
  retry?: number | undefined;
31
35
  };
32
36
 
33
- export type Three = {
37
+ export type Four = {
34
38
  /**
35
39
  * The event payload. Shape depends on the `type` phase discriminator.
36
40
  */
@@ -49,7 +53,7 @@ export type Three = {
49
53
  retry?: number | undefined;
50
54
  };
51
55
 
52
- export type Two = {
56
+ export type Three = {
53
57
  /**
54
58
  * The event payload. Shape depends on the `type` phase discriminator.
55
59
  */
@@ -68,7 +72,7 @@ export type Two = {
68
72
  retry?: number | undefined;
69
73
  };
70
74
 
71
- export type One = {
75
+ export type Two = {
72
76
  /**
73
77
  * The event payload. Shape depends on the `type` phase discriminator.
74
78
  */
@@ -87,13 +91,29 @@ export type One = {
87
91
  retry?: number | undefined;
88
92
  };
89
93
 
94
+ export type One = {
95
+ data: PublicErrorSseEventData;
96
+ /**
97
+ * The SSE event name (sent via the `event:` line).
98
+ */
99
+ event: "error";
100
+ /**
101
+ * Optional SSE event id (sent via the `id:` line).
102
+ */
103
+ id?: string | undefined;
104
+ /**
105
+ * Optional SSE retry value in milliseconds (sent via the `retry:` line).
106
+ */
107
+ retry?: number | undefined;
108
+ };
109
+
90
110
  /**
91
- * Server-sent event (SSE) envelope for SVG streaming operations. Each SSE message uses the `event:` line for the phase discriminator and the `data:` line for a JSON payload. For `n > 1`, events are interleaved: use `data.index` for output position and `data.id` as the stable per-output identifier. The stream terminates with `data: [DONE]`.
111
+ * Server-sent event (SSE) envelope for SVG streaming operations. Each SSE message uses the `event:` line for the phase discriminator and the `data:` line for a JSON payload. For `n > 1`, events are interleaved: use `data.index` for output position and `data.id` as the stable per-output identifier. Terminal failures emit `event: error` with public error data. The stream terminates with `data: [DONE]`.
92
112
  */
93
- export type SvgStreamEvent = One | Two | Three | Four;
113
+ export type SvgStreamEvent = One | Two | Three | Four | Five;
94
114
 
95
115
  /** @internal */
96
- export const Four$inboundSchema: z.ZodType<Four, z.ZodTypeDef, unknown> = z
116
+ export const Five$inboundSchema: z.ZodType<Five, z.ZodTypeDef, unknown> = z
97
117
  .object({
98
118
  data: z.unknown().transform((v, ctx) => {
99
119
  if (typeof v !== "string") return v;
@@ -109,6 +129,33 @@ export const Four$inboundSchema: z.ZodType<Four, z.ZodTypeDef, unknown> = z
109
129
  retry: z.number().int().optional(),
110
130
  });
111
131
 
132
+ export function fiveFromJSON(
133
+ jsonString: string,
134
+ ): SafeParseResult<Five, SDKValidationError> {
135
+ return safeParse(
136
+ jsonString,
137
+ (x) => Five$inboundSchema.parse(JSON.parse(x)),
138
+ `Failed to parse 'Five' from JSON`,
139
+ );
140
+ }
141
+
142
+ /** @internal */
143
+ export const Four$inboundSchema: z.ZodType<Four, z.ZodTypeDef, unknown> = z
144
+ .object({
145
+ data: z.unknown().transform((v, ctx) => {
146
+ if (typeof v !== "string") return v;
147
+ try {
148
+ return JSON.parse(v);
149
+ } catch (err) {
150
+ ctx.addIssue({ code: "custom", message: `malformed json: ${err}` });
151
+ return z.NEVER;
152
+ }
153
+ }).pipe(SvgStreamEventData$inboundSchema),
154
+ event: z.literal("draft"),
155
+ id: z.string().optional(),
156
+ retry: z.number().int().optional(),
157
+ });
158
+
112
159
  export function fourFromJSON(
113
160
  jsonString: string,
114
161
  ): SafeParseResult<Four, SDKValidationError> {
@@ -131,7 +178,7 @@ export const Three$inboundSchema: z.ZodType<Three, z.ZodTypeDef, unknown> = z
131
178
  return z.NEVER;
132
179
  }
133
180
  }).pipe(SvgStreamEventData$inboundSchema),
134
- event: z.literal("draft"),
181
+ event: z.literal("reasoning"),
135
182
  id: z.string().optional(),
136
183
  retry: z.number().int().optional(),
137
184
  });
@@ -158,7 +205,7 @@ export const Two$inboundSchema: z.ZodType<Two, z.ZodTypeDef, unknown> = z
158
205
  return z.NEVER;
159
206
  }
160
207
  }).pipe(SvgStreamEventData$inboundSchema),
161
- event: z.literal("reasoning"),
208
+ event: z.literal("generating"),
162
209
  id: z.string().optional(),
163
210
  retry: z.number().int().optional(),
164
211
  });
@@ -184,8 +231,8 @@ export const One$inboundSchema: z.ZodType<One, z.ZodTypeDef, unknown> = z
184
231
  ctx.addIssue({ code: "custom", message: `malformed json: ${err}` });
185
232
  return z.NEVER;
186
233
  }
187
- }).pipe(SvgStreamEventData$inboundSchema),
188
- event: z.literal("generating"),
234
+ }).pipe(PublicErrorSseEventData$inboundSchema),
235
+ event: z.literal("error"),
189
236
  id: z.string().optional(),
190
237
  retry: z.number().int().optional(),
191
238
  });
@@ -210,6 +257,7 @@ export const SvgStreamEvent$inboundSchema: z.ZodType<
210
257
  z.lazy(() => Two$inboundSchema),
211
258
  z.lazy(() => Three$inboundSchema),
212
259
  z.lazy(() => Four$inboundSchema),
260
+ z.lazy(() => Five$inboundSchema),
213
261
  ]);
214
262
 
215
263
  export function svgStreamEventFromJSON(
@@ -6,6 +6,10 @@ import * as z from "zod/v3";
6
6
  import { safeParse } from "../../../lib/schemas.js";
7
7
  import { Result as SafeParseResult } from "../../types/fp.js";
8
8
  import { SDKValidationError } from "../errors/sdkvalidationerror.js";
9
+ import {
10
+ PublicErrorSseEventData,
11
+ PublicErrorSseEventData$inboundSchema,
12
+ } from "./publicerrorsseeventdata.js";
9
13
  import {
10
14
  SvgContentEventData,
11
15
  SvgContentEventData$inboundSchema,
@@ -29,6 +33,7 @@ import {
29
33
  export type SvgStreamEventData =
30
34
  | SvgContentEventData
31
35
  | SvgDraftEventData
36
+ | (PublicErrorSseEventData & { type: "error" })
32
37
  | SvgGeneratingEventData
33
38
  | SvgReasoningEventData;
34
39
 
@@ -40,6 +45,9 @@ export const SvgStreamEventData$inboundSchema: z.ZodType<
40
45
  > = z.union([
41
46
  SvgContentEventData$inboundSchema,
42
47
  SvgDraftEventData$inboundSchema,
48
+ PublicErrorSseEventData$inboundSchema.and(
49
+ z.object({ type: z.literal("error") }),
50
+ ),
43
51
  SvgGeneratingEventData$inboundSchema,
44
52
  SvgReasoningEventData$inboundSchema,
45
53
  ]);
@@ -1,14 +0,0 @@
1
- /**
2
- * @param obj The object to walk
3
- * @param key The key path to walk the object with
4
- * @param def A default value to return if the result is undefined
5
- *
6
- * @example
7
- * dlv(obj, "a.b.c.d")
8
- * @example
9
- * dlv(object, ["a", "b", "c", "d"])
10
- * @example
11
- * dlv(object, "foo.bar.baz", "Hello, default value!")
12
- */
13
- export declare function dlv<T = any>(obj: any, key: string | string[], def?: T, p?: number, undef?: never): T | undefined;
14
- //# sourceMappingURL=dlv.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"dlv.d.ts","sourceRoot":"","sources":["../../../src/lib/dlv.ts"],"names":[],"mappings":"AA2BA;;;;;;;;;;;GAWG;AACH,wBAAgB,GAAG,CAAC,CAAC,GAAG,GAAG,EACzB,GAAG,EAAE,GAAG,EACR,GAAG,EAAE,MAAM,GAAG,MAAM,EAAE,EACtB,GAAG,CAAC,EAAE,CAAC,EACP,CAAC,CAAC,EAAE,MAAM,EACV,KAAK,CAAC,EAAE,KAAK,GACZ,CAAC,GAAG,SAAS,CAOf"}
@@ -1,49 +0,0 @@
1
- "use strict";
2
- /*
3
- * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
4
- */
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.dlv = dlv;
7
- /*
8
- MIT License
9
-
10
- Copyright (c) 2024 Jason Miller <jason@developit.ca> (http://jasonformat.com)
11
-
12
- Permission is hereby granted, free of charge, to any person obtaining a copy of
13
- this software and associated documentation files (the "Software"), to deal in
14
- the Software without restriction, including without limitation the rights to
15
- use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
16
- the Software, and to permit persons to whom the Software is furnished to do so,
17
- subject to the following conditions:
18
-
19
- The above copyright notice and this permission notice shall be included in all
20
- copies or substantial portions of the Software.
21
-
22
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
24
- FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
25
- COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
26
- IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
27
- CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28
- */
29
- /**
30
- * @param obj The object to walk
31
- * @param key The key path to walk the object with
32
- * @param def A default value to return if the result is undefined
33
- *
34
- * @example
35
- * dlv(obj, "a.b.c.d")
36
- * @example
37
- * dlv(object, ["a", "b", "c", "d"])
38
- * @example
39
- * dlv(object, "foo.bar.baz", "Hello, default value!")
40
- */
41
- function dlv(obj, key, def, p, undef) {
42
- key = Array.isArray(key) ? key : key.split(".");
43
- for (p = 0; p < key.length; p++) {
44
- const k = key[p];
45
- obj = k != null && obj ? obj[k] : undef;
46
- }
47
- return obj === undef ? def : obj;
48
- }
49
- //# sourceMappingURL=dlv.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"dlv.js","sourceRoot":"","sources":["../../../src/lib/dlv.ts"],"names":[],"mappings":";AAAA;;GAEG;;AAqCH,kBAaC;AAhDD;;;;;;;;;;;;;;;;;;;;;EAqBE;AAEF;;;;;;;;;;;GAWG;AACH,SAAgB,GAAG,CACjB,GAAQ,EACR,GAAsB,EACtB,GAAO,EACP,CAAU,EACV,KAAa;IAEb,GAAG,GAAG,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAChD,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,GAAG,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QAChC,MAAM,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC;QACjB,GAAG,GAAG,CAAC,IAAI,IAAI,IAAI,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;IAC1C,CAAC;IACD,OAAO,GAAG,KAAK,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC;AACnC,CAAC"}
@@ -1,2 +0,0 @@
1
- export declare function isPlainObject(value: unknown): value is object;
2
- //# sourceMappingURL=is-plain-object.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"is-plain-object.d.ts","sourceRoot":"","sources":["../../../src/lib/is-plain-object.ts"],"names":[],"mappings":"AA6BA,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAa7D"}
@@ -1,41 +0,0 @@
1
- "use strict";
2
- /*
3
- * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
4
- */
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.isPlainObject = isPlainObject;
7
- /*
8
- MIT License
9
-
10
- Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
11
-
12
- Permission is hereby granted, free of charge, to any person obtaining a copy of
13
- this software and associated documentation files (the "Software"), to deal in
14
- the Software without restriction, including without limitation the rights to
15
- use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
16
- the Software, and to permit persons to whom the Software is furnished to do so,
17
- subject to the following conditions:
18
-
19
- The above copyright notice and this permission notice shall be included in all
20
- copies or substantial portions of the Software.
21
-
22
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
24
- FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
25
- COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
26
- IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
27
- CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28
- */
29
- // Taken from https://github.com/sindresorhus/is-plain-obj/blob/97f38e8836f86a642cce98fc6ab3058bc36df181/index.js
30
- function isPlainObject(value) {
31
- if (typeof value !== "object" || value === null) {
32
- return false;
33
- }
34
- const prototype = Object.getPrototypeOf(value);
35
- return ((prototype === null ||
36
- prototype === Object.prototype ||
37
- Object.getPrototypeOf(prototype) === null) &&
38
- !(Symbol.toStringTag in value) &&
39
- !(Symbol.iterator in value));
40
- }
41
- //# sourceMappingURL=is-plain-object.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"is-plain-object.js","sourceRoot":"","sources":["../../../src/lib/is-plain-object.ts"],"names":[],"mappings":";AAAA;;GAEG;;AA2BH,sCAaC;AAtCD;;;;;;;;;;;;;;;;;;;;;EAqBE;AAEF,iHAAiH;AAEjH,SAAgB,aAAa,CAAC,KAAc;IAC1C,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;QAChD,OAAO,KAAK,CAAC;IACf,CAAC;IAED,MAAM,SAAS,GAAG,MAAM,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC;IAC/C,OAAO,CACL,CAAC,SAAS,KAAK,IAAI;QACjB,SAAS,KAAK,MAAM,CAAC,SAAS;QAC9B,MAAM,CAAC,cAAc,CAAC,SAAS,CAAC,KAAK,IAAI,CAAC;QAC5C,CAAC,CAAC,MAAM,CAAC,WAAW,IAAI,KAAK,CAAC;QAC9B,CAAC,CAAC,MAAM,CAAC,QAAQ,IAAI,KAAK,CAAC,CAC5B,CAAC;AACJ,CAAC"}
@@ -1,14 +0,0 @@
1
- /**
2
- * @param obj The object to walk
3
- * @param key The key path to walk the object with
4
- * @param def A default value to return if the result is undefined
5
- *
6
- * @example
7
- * dlv(obj, "a.b.c.d")
8
- * @example
9
- * dlv(object, ["a", "b", "c", "d"])
10
- * @example
11
- * dlv(object, "foo.bar.baz", "Hello, default value!")
12
- */
13
- export declare function dlv<T = any>(obj: any, key: string | string[], def?: T, p?: number, undef?: never): T | undefined;
14
- //# sourceMappingURL=dlv.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"dlv.d.ts","sourceRoot":"","sources":["../../../src/lib/dlv.ts"],"names":[],"mappings":"AA2BA;;;;;;;;;;;GAWG;AACH,wBAAgB,GAAG,CAAC,CAAC,GAAG,GAAG,EACzB,GAAG,EAAE,GAAG,EACR,GAAG,EAAE,MAAM,GAAG,MAAM,EAAE,EACtB,GAAG,CAAC,EAAE,CAAC,EACP,CAAC,CAAC,EAAE,MAAM,EACV,KAAK,CAAC,EAAE,KAAK,GACZ,CAAC,GAAG,SAAS,CAOf"}