@umituz/web-ai 1.0.0 → 1.0.2
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.
- package/dist/{ABTesting-DDqNhHtP.d.ts → AIErrors-B2ogd1PB.d.ts} +14 -1
- package/dist/{ABTesting-DWBtKTMQ.d.cts → AIErrors-C5EasV_c.d.cts} +14 -1
- package/dist/{ProviderConfig-a55tLhWT.d.cts → ProviderConfig-DIFa9nmG.d.cts} +10 -1
- package/dist/{ProviderConfig-a55tLhWT.d.ts → ProviderConfig-DIFa9nmG.d.ts} +10 -1
- package/dist/chat/index.cjs +114 -23
- package/dist/chat/index.cjs.map +1 -1
- package/dist/chat/index.d.cts +4 -4
- package/dist/chat/index.d.ts +4 -4
- package/dist/chat/index.js +114 -23
- package/dist/chat/index.js.map +1 -1
- package/dist/{chat.service-DBKq9I2c.d.cts → chat.service-CL1qtYxe.d.cts} +7 -7
- package/dist/{chat.service-RQn8UTXD.d.ts → chat.service-q05GnhEm.d.ts} +7 -7
- package/dist/content/index.cjs +506 -193
- package/dist/content/index.cjs.map +1 -1
- package/dist/content/index.d.cts +7 -8
- package/dist/content/index.d.ts +7 -8
- package/dist/content/index.js +506 -193
- package/dist/content/index.js.map +1 -1
- package/dist/core/index.cjs +122 -15
- package/dist/core/index.cjs.map +1 -1
- package/dist/core/index.d.cts +13 -31
- package/dist/core/index.d.ts +13 -31
- package/dist/core/index.js +119 -16
- package/dist/core/index.js.map +1 -1
- package/dist/{create-ai-BhNaz86i.d.ts → create-ai-9PW752z8.d.ts} +14 -21
- package/dist/{create-ai-DGZFBOA1.d.cts → create-ai-CXYKPK6G.d.cts} +14 -21
- package/dist/hooks/index.cjs +631 -179
- package/dist/hooks/index.cjs.map +1 -1
- package/dist/hooks/index.d.cts +33 -7
- package/dist/hooks/index.d.ts +33 -7
- package/dist/hooks/index.js +631 -180
- package/dist/hooks/index.js.map +1 -1
- package/dist/index-DIHz8_OJ.d.ts +48 -0
- package/dist/index-DKHNcMbl.d.cts +48 -0
- package/dist/index.cjs +666 -104
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +8 -7
- package/dist/index.d.ts +8 -7
- package/dist/index.js +645 -105
- package/dist/index.js.map +1 -1
- package/dist/{provider.factory-COsnprLH.d.cts → provider.factory-BxsfK4WW.d.cts} +1 -1
- package/dist/{provider.factory-CpWFyjbw.d.ts → provider.factory-DfDfk0dK.d.ts} +1 -1
- package/dist/providers/index.cjs +973 -130
- package/dist/providers/index.cjs.map +1 -1
- package/dist/providers/index.d.cts +84 -18
- package/dist/providers/index.d.ts +84 -18
- package/dist/providers/index.js +956 -131
- package/dist/providers/index.js.map +1 -1
- package/dist/text-generation.service-BQO3Tvz2.d.cts +66 -0
- package/dist/text-generation.service-CcYQM6Ch.d.ts +66 -0
- package/dist/wizard/index.d.cts +1 -1
- package/dist/wizard/index.d.ts +1 -1
- package/package.json +9 -1
- package/dist/index-DjX9ZKuM.d.cts +0 -14
- package/dist/index-DxLvE588.d.ts +0 -14
package/dist/core/index.d.cts
CHANGED
|
@@ -1,38 +1,18 @@
|
|
|
1
1
|
export { C as ChatMessage, F as FinishReason, G as GenerationResult, P as ProviderHealth, S as StreamCallbacks, a as StructuredGeneration, b as StructuredTextRequest, T as TextRequest, c as TextTier, d as TokenUsage } from '../index-fXjxTR5W.cjs';
|
|
2
|
-
|
|
2
|
+
import { A as AIError, b as AIErrorType, a as AIErrorMetadata } from '../index-DKHNcMbl.cjs';
|
|
3
|
+
export { T as TEXT_TIERS, c as TierModelMap, U as USER_FRIENDLY_ERROR_MESSAGES, i as isTextTier, m as mergeTierOverrides, r as resolveModel } from '../index-DKHNcMbl.cjs';
|
|
3
4
|
import { b as RetryManager, c as RetryOptions, a as RequestQueue, R as RequestDeduplicator } from '../request-deduplicator.util-NDo0_n1y.cjs';
|
|
4
5
|
export { Q as QueueOptions, r as requestDeduplicator, d as requestQueue, e as retryManager, w as withRetry } from '../request-deduplicator.util-NDo0_n1y.cjs';
|
|
5
6
|
export { C as CacheManager, a as CacheOptions, b as CacheStats, c as cacheManager } from '../cache-manager-Df9LLYGA.cjs';
|
|
6
7
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
UNKNOWN_ERROR = "UNKNOWN_ERROR"
|
|
16
|
-
}
|
|
17
|
-
declare const USER_FRIENDLY_ERROR_MESSAGES: Readonly<Record<AIErrorType, string>>;
|
|
18
|
-
|
|
19
|
-
interface AIErrorMetadata {
|
|
20
|
-
readonly status?: number;
|
|
21
|
-
readonly url?: string;
|
|
22
|
-
readonly [key: string]: unknown;
|
|
23
|
-
}
|
|
24
|
-
declare class AIError extends Error {
|
|
25
|
-
readonly type: AIErrorType;
|
|
26
|
-
readonly cause?: Error;
|
|
27
|
-
readonly metadata: AIErrorMetadata;
|
|
28
|
-
constructor(type: AIErrorType, message: string, cause?: Error, metadata?: AIErrorMetadata);
|
|
29
|
-
toString(): string;
|
|
30
|
-
toJSON(): {
|
|
31
|
-
name: string;
|
|
32
|
-
type: AIErrorType;
|
|
33
|
-
message: string;
|
|
34
|
-
metadata: AIErrorMetadata;
|
|
35
|
-
};
|
|
8
|
+
type GroqErrorMetadata = AIErrorMetadata;
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Drop-in backwards-compatible GroqError extending core AIError.
|
|
12
|
+
* Ensures `err instanceof GroqError` and `err instanceof AIError` both evaluate to true.
|
|
13
|
+
*/
|
|
14
|
+
declare class GroqError extends AIError {
|
|
15
|
+
constructor(type: AIErrorType, message: string, cause?: Error, metadata?: GroqErrorMetadata);
|
|
36
16
|
}
|
|
37
17
|
|
|
38
18
|
interface ErrorClassificationRule {
|
|
@@ -193,6 +173,8 @@ declare class JsonResponseParser {
|
|
|
193
173
|
|
|
194
174
|
declare function extractJsonFromCodeFence(content: string): string | null;
|
|
195
175
|
declare function extractJsonObject(content: string): string | null;
|
|
176
|
+
declare function extractJsonArray(content: string): string | null;
|
|
177
|
+
declare function repairCommonJsonDefects(text: string): string;
|
|
196
178
|
declare function extractJsonCandidate(content: string): string;
|
|
197
179
|
|
|
198
180
|
declare class StructuredPromptBuilder {
|
|
@@ -229,4 +211,4 @@ declare const DEFAULT_RETRY_MAX_DELAY_MS = 10000;
|
|
|
229
211
|
declare const DEFAULT_RETRY_BACKOFF_MULTIPLIER = 2;
|
|
230
212
|
declare const DEFAULT_RETRY_JITTER_FACTOR = 0.1;
|
|
231
213
|
|
|
232
|
-
export { AIError, type AIErrorBody,
|
|
214
|
+
export { AIError, type AIErrorBody, AIErrorMetadata, AIErrorType, type ApiKeyValidationRule, CompositeExecutor, DEFAULT_API_KEY_RULE, DEFAULT_ERROR_CLASSIFICATION_RULE, DEFAULT_HTTP_STATUS_RULE, DEFAULT_RETRY_BACKOFF_MULTIPLIER, DEFAULT_RETRY_INITIAL_DELAY_MS, DEFAULT_RETRY_JITTER_FACTOR, DEFAULT_RETRY_MAX_ATTEMPTS, DEFAULT_RETRY_MAX_DELAY_MS, DebounceManager, type DebounceOptions, DedupeExecutor, type DedupeExecutorOptions, type ErrorClassificationRule, GroqError, type GroqErrorMetadata, AIErrorType as GroqErrorType, type HttpStatusClassificationRule, type IRequestExecutor, JSON_CODE_BLOCK_PATTERN, JSON_OBJECT_PATTERN, JsonResponseParser, type LoggedError, type NormalizedSseChunk, QueueExecutor, RequestDeduplicator, RequestQueue, RetryExecutor, RetryManager, RetryOptions, SSE_BRIDGE_EVENTS, SSE_DONE_MARKER, SSE_PREFIX, type SseDeltaExtractor, type SseResponseOptions, type StreamingParserCallbacks, StreamingResponseParser, StructuredPromptBuilder, ThrottleManager, type ThrottleOptions, asObjectArray, asRecord, asStringArray, asTrimmedOptionalString, buildCacheKey, buildHttpStatusFallback, clampScore, classifyHttpStatus, createSseResponse, debounce, debounceManager, describeAIErrorType, extractErrorMessageFromJsonBody, extractErrorMessageFromResponse, extractJsonArray, extractJsonCandidate, extractJsonFromCodeFence, extractJsonObject, extractSseDataPayload, formatErrorForLogging, isAuthErrorType, isRetryableErrorType, isSseDataLine, isSseDoneMarker, isValidApiKey, normalizeSseChunk, oneOfCatalog, repairCommonJsonDefects, resolveUserFriendlyErrorMessage, resolveUserFriendlyMessage, splitSseLines, throttle, throttleManager, validateApiKey };
|
package/dist/core/index.d.ts
CHANGED
|
@@ -1,38 +1,18 @@
|
|
|
1
1
|
export { C as ChatMessage, F as FinishReason, G as GenerationResult, P as ProviderHealth, S as StreamCallbacks, a as StructuredGeneration, b as StructuredTextRequest, T as TextRequest, c as TextTier, d as TokenUsage } from '../index-fXjxTR5W.js';
|
|
2
|
-
|
|
2
|
+
import { A as AIError, b as AIErrorType, a as AIErrorMetadata } from '../index-DIHz8_OJ.js';
|
|
3
|
+
export { T as TEXT_TIERS, c as TierModelMap, U as USER_FRIENDLY_ERROR_MESSAGES, i as isTextTier, m as mergeTierOverrides, r as resolveModel } from '../index-DIHz8_OJ.js';
|
|
3
4
|
import { b as RetryManager, c as RetryOptions, a as RequestQueue, R as RequestDeduplicator } from '../request-deduplicator.util-NDo0_n1y.js';
|
|
4
5
|
export { Q as QueueOptions, r as requestDeduplicator, d as requestQueue, e as retryManager, w as withRetry } from '../request-deduplicator.util-NDo0_n1y.js';
|
|
5
6
|
export { C as CacheManager, a as CacheOptions, b as CacheStats, c as cacheManager } from '../cache-manager-Df9LLYGA.js';
|
|
6
7
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
UNKNOWN_ERROR = "UNKNOWN_ERROR"
|
|
16
|
-
}
|
|
17
|
-
declare const USER_FRIENDLY_ERROR_MESSAGES: Readonly<Record<AIErrorType, string>>;
|
|
18
|
-
|
|
19
|
-
interface AIErrorMetadata {
|
|
20
|
-
readonly status?: number;
|
|
21
|
-
readonly url?: string;
|
|
22
|
-
readonly [key: string]: unknown;
|
|
23
|
-
}
|
|
24
|
-
declare class AIError extends Error {
|
|
25
|
-
readonly type: AIErrorType;
|
|
26
|
-
readonly cause?: Error;
|
|
27
|
-
readonly metadata: AIErrorMetadata;
|
|
28
|
-
constructor(type: AIErrorType, message: string, cause?: Error, metadata?: AIErrorMetadata);
|
|
29
|
-
toString(): string;
|
|
30
|
-
toJSON(): {
|
|
31
|
-
name: string;
|
|
32
|
-
type: AIErrorType;
|
|
33
|
-
message: string;
|
|
34
|
-
metadata: AIErrorMetadata;
|
|
35
|
-
};
|
|
8
|
+
type GroqErrorMetadata = AIErrorMetadata;
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Drop-in backwards-compatible GroqError extending core AIError.
|
|
12
|
+
* Ensures `err instanceof GroqError` and `err instanceof AIError` both evaluate to true.
|
|
13
|
+
*/
|
|
14
|
+
declare class GroqError extends AIError {
|
|
15
|
+
constructor(type: AIErrorType, message: string, cause?: Error, metadata?: GroqErrorMetadata);
|
|
36
16
|
}
|
|
37
17
|
|
|
38
18
|
interface ErrorClassificationRule {
|
|
@@ -193,6 +173,8 @@ declare class JsonResponseParser {
|
|
|
193
173
|
|
|
194
174
|
declare function extractJsonFromCodeFence(content: string): string | null;
|
|
195
175
|
declare function extractJsonObject(content: string): string | null;
|
|
176
|
+
declare function extractJsonArray(content: string): string | null;
|
|
177
|
+
declare function repairCommonJsonDefects(text: string): string;
|
|
196
178
|
declare function extractJsonCandidate(content: string): string;
|
|
197
179
|
|
|
198
180
|
declare class StructuredPromptBuilder {
|
|
@@ -229,4 +211,4 @@ declare const DEFAULT_RETRY_MAX_DELAY_MS = 10000;
|
|
|
229
211
|
declare const DEFAULT_RETRY_BACKOFF_MULTIPLIER = 2;
|
|
230
212
|
declare const DEFAULT_RETRY_JITTER_FACTOR = 0.1;
|
|
231
213
|
|
|
232
|
-
export { AIError, type AIErrorBody,
|
|
214
|
+
export { AIError, type AIErrorBody, AIErrorMetadata, AIErrorType, type ApiKeyValidationRule, CompositeExecutor, DEFAULT_API_KEY_RULE, DEFAULT_ERROR_CLASSIFICATION_RULE, DEFAULT_HTTP_STATUS_RULE, DEFAULT_RETRY_BACKOFF_MULTIPLIER, DEFAULT_RETRY_INITIAL_DELAY_MS, DEFAULT_RETRY_JITTER_FACTOR, DEFAULT_RETRY_MAX_ATTEMPTS, DEFAULT_RETRY_MAX_DELAY_MS, DebounceManager, type DebounceOptions, DedupeExecutor, type DedupeExecutorOptions, type ErrorClassificationRule, GroqError, type GroqErrorMetadata, AIErrorType as GroqErrorType, type HttpStatusClassificationRule, type IRequestExecutor, JSON_CODE_BLOCK_PATTERN, JSON_OBJECT_PATTERN, JsonResponseParser, type LoggedError, type NormalizedSseChunk, QueueExecutor, RequestDeduplicator, RequestQueue, RetryExecutor, RetryManager, RetryOptions, SSE_BRIDGE_EVENTS, SSE_DONE_MARKER, SSE_PREFIX, type SseDeltaExtractor, type SseResponseOptions, type StreamingParserCallbacks, StreamingResponseParser, StructuredPromptBuilder, ThrottleManager, type ThrottleOptions, asObjectArray, asRecord, asStringArray, asTrimmedOptionalString, buildCacheKey, buildHttpStatusFallback, clampScore, classifyHttpStatus, createSseResponse, debounce, debounceManager, describeAIErrorType, extractErrorMessageFromJsonBody, extractErrorMessageFromResponse, extractJsonArray, extractJsonCandidate, extractJsonFromCodeFence, extractJsonObject, extractSseDataPayload, formatErrorForLogging, isAuthErrorType, isRetryableErrorType, isSseDataLine, isSseDoneMarker, isValidApiKey, normalizeSseChunk, oneOfCatalog, repairCommonJsonDefects, resolveUserFriendlyErrorMessage, resolveUserFriendlyMessage, splitSseLines, throttle, throttleManager, validateApiKey };
|
package/dist/core/index.js
CHANGED
|
@@ -41,17 +41,80 @@ var USER_FRIENDLY_ERROR_MESSAGES = {
|
|
|
41
41
|
};
|
|
42
42
|
|
|
43
43
|
// src/core/errors/ai-error.ts
|
|
44
|
-
var
|
|
44
|
+
var KNOWN_ERROR_TYPES = new Set(Object.values(AIErrorType));
|
|
45
|
+
function mapCodeToType(code) {
|
|
46
|
+
switch (code) {
|
|
47
|
+
case "VALIDATION_ERROR":
|
|
48
|
+
case "CLIENT_ERROR":
|
|
49
|
+
return "CLIENT_ERROR" /* CLIENT_ERROR */;
|
|
50
|
+
case "INVALID_API_KEY":
|
|
51
|
+
return "INVALID_API_KEY" /* INVALID_API_KEY */;
|
|
52
|
+
case "MISSING_CONFIG":
|
|
53
|
+
case "PROVIDER_UNAVAILABLE":
|
|
54
|
+
return "MISSING_CONFIG" /* MISSING_CONFIG */;
|
|
55
|
+
case "PROVIDER_QUOTA_EXHAUSTED":
|
|
56
|
+
case "RATE_LIMIT_ERROR":
|
|
57
|
+
return "RATE_LIMIT_ERROR" /* RATE_LIMIT_ERROR */;
|
|
58
|
+
case "NETWORK_ERROR":
|
|
59
|
+
case "TIMEOUT":
|
|
60
|
+
return "NETWORK_ERROR" /* NETWORK_ERROR */;
|
|
61
|
+
case "ABORT_ERROR":
|
|
62
|
+
case "ABORTED":
|
|
63
|
+
return "ABORT_ERROR" /* ABORT_ERROR */;
|
|
64
|
+
case "SERVER_ERROR":
|
|
65
|
+
case "PROVIDER_ERROR":
|
|
66
|
+
case "NO_RESULT":
|
|
67
|
+
return "SERVER_ERROR" /* SERVER_ERROR */;
|
|
68
|
+
default:
|
|
69
|
+
return "UNKNOWN_ERROR" /* UNKNOWN_ERROR */;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
function mapMessageToCode(message, fallback = "UNKNOWN") {
|
|
73
|
+
const lower = message.toLowerCase();
|
|
74
|
+
if (lower.includes("validation")) return "VALIDATION_ERROR";
|
|
75
|
+
if (lower.includes("quota")) return "PROVIDER_QUOTA_EXHAUSTED";
|
|
76
|
+
if (lower.includes("unavailable")) return "PROVIDER_UNAVAILABLE";
|
|
77
|
+
if (lower.includes("timeout") || lower.includes("aborted")) {
|
|
78
|
+
return lower.includes("aborted") ? "ABORTED" : "TIMEOUT";
|
|
79
|
+
}
|
|
80
|
+
if (lower.includes("parse") || lower.includes("json")) return "PARSE_ERROR";
|
|
81
|
+
if (lower.includes("no result")) return "NO_RESULT";
|
|
82
|
+
if (lower.includes("network") || lower.includes("fetch")) return "NETWORK_ERROR";
|
|
83
|
+
return fallback;
|
|
84
|
+
}
|
|
85
|
+
var AIError = class _AIError extends Error {
|
|
45
86
|
type;
|
|
87
|
+
code;
|
|
46
88
|
cause;
|
|
47
89
|
metadata;
|
|
48
|
-
constructor(
|
|
49
|
-
|
|
90
|
+
constructor(typeOrMessage, messageOrCode, cause, metadata = {}) {
|
|
91
|
+
let effectiveType;
|
|
92
|
+
let effectiveMessage;
|
|
93
|
+
let effectiveCode;
|
|
94
|
+
if (KNOWN_ERROR_TYPES.has(typeOrMessage)) {
|
|
95
|
+
effectiveType = typeOrMessage;
|
|
96
|
+
effectiveMessage = messageOrCode ?? "";
|
|
97
|
+
effectiveCode = effectiveType;
|
|
98
|
+
} else {
|
|
99
|
+
effectiveMessage = typeOrMessage;
|
|
100
|
+
effectiveCode = messageOrCode ?? "UNKNOWN";
|
|
101
|
+
effectiveType = mapCodeToType(effectiveCode);
|
|
102
|
+
}
|
|
103
|
+
super(effectiveMessage);
|
|
50
104
|
this.name = "AIError";
|
|
51
|
-
this.type =
|
|
105
|
+
this.type = effectiveType;
|
|
106
|
+
this.code = effectiveCode;
|
|
52
107
|
this.cause = cause;
|
|
53
108
|
this.metadata = metadata;
|
|
54
109
|
}
|
|
110
|
+
static from(error, fallbackCode = "UNKNOWN") {
|
|
111
|
+
if (error instanceof _AIError) return error;
|
|
112
|
+
if (error instanceof Error) {
|
|
113
|
+
const code = mapMessageToCode(error.message, fallbackCode);
|
|
114
|
+
return new _AIError(error.message, code, error);
|
|
115
|
+
}
|
|
116
|
+
return new _AIError(String(error), fallbackCode, error);
|
|
117
|
+
}
|
|
55
118
|
toString() {
|
|
56
119
|
const statusPart = typeof this.metadata.status === "number" ? ` (HTTP ${this.metadata.status})` : "";
|
|
57
120
|
return `${this.name} [${this.type}]: ${this.message}${statusPart}`;
|
|
@@ -60,12 +123,21 @@ var AIError = class extends Error {
|
|
|
60
123
|
return {
|
|
61
124
|
name: this.name,
|
|
62
125
|
type: this.type,
|
|
126
|
+
code: this.code,
|
|
63
127
|
message: this.message,
|
|
64
128
|
metadata: this.metadata
|
|
65
129
|
};
|
|
66
130
|
}
|
|
67
131
|
};
|
|
68
132
|
|
|
133
|
+
// src/core/errors/groq-error.ts
|
|
134
|
+
var GroqError = class extends AIError {
|
|
135
|
+
constructor(type, message, cause, metadata = {}) {
|
|
136
|
+
super(type, message, cause, metadata);
|
|
137
|
+
this.name = "GroqError";
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
|
|
69
141
|
// src/core/errors/error-classifier.ts
|
|
70
142
|
var DEFAULT_RETRYABLE_TYPES = /* @__PURE__ */ new Set([
|
|
71
143
|
"NETWORK_ERROR" /* NETWORK_ERROR */,
|
|
@@ -743,15 +815,22 @@ function oneOfCatalog(catalog, value) {
|
|
|
743
815
|
// src/core/constants/protocol.constants.ts
|
|
744
816
|
var SSE_PREFIX = "data: ";
|
|
745
817
|
var SSE_DONE_MARKER = "[DONE]";
|
|
746
|
-
var JSON_CODE_BLOCK_PATTERN = /```json
|
|
818
|
+
var JSON_CODE_BLOCK_PATTERN = /```(?:json)?\s*\n?([\s\S]*?)\n?```/;
|
|
747
819
|
var JSON_OBJECT_PATTERN = /\{[\s\S]*\}/;
|
|
820
|
+
var JSON_ARRAY_PATTERN = /\[[\s\S]*\]/;
|
|
748
821
|
|
|
749
822
|
// src/core/parsers/sse-lines.ts
|
|
750
823
|
function isSseDataLine(line) {
|
|
751
|
-
return line.startsWith(SSE_PREFIX);
|
|
824
|
+
return line.startsWith(SSE_PREFIX) || line.startsWith("data:");
|
|
752
825
|
}
|
|
753
826
|
function extractSseDataPayload(line) {
|
|
754
|
-
|
|
827
|
+
if (line.startsWith(SSE_PREFIX)) {
|
|
828
|
+
return line.slice(SSE_PREFIX.length);
|
|
829
|
+
}
|
|
830
|
+
if (line.startsWith("data:")) {
|
|
831
|
+
return line.slice(5);
|
|
832
|
+
}
|
|
833
|
+
return line;
|
|
755
834
|
}
|
|
756
835
|
function isSseDoneMarker(payload) {
|
|
757
836
|
return payload === SSE_DONE_MARKER;
|
|
@@ -823,7 +902,7 @@ var StreamingResponseParser = class {
|
|
|
823
902
|
// src/core/parsers/json-content-extractor.ts
|
|
824
903
|
function extractJsonFromCodeFence(content) {
|
|
825
904
|
const match = content.match(JSON_CODE_BLOCK_PATTERN);
|
|
826
|
-
if (match && match[1]) return match[1];
|
|
905
|
+
if (match && match[1]) return match[1].trim();
|
|
827
906
|
return null;
|
|
828
907
|
}
|
|
829
908
|
function extractJsonObject(content) {
|
|
@@ -831,8 +910,27 @@ function extractJsonObject(content) {
|
|
|
831
910
|
if (match && match[0]) return match[0];
|
|
832
911
|
return null;
|
|
833
912
|
}
|
|
913
|
+
function extractJsonArray(content) {
|
|
914
|
+
const match = content.match(JSON_ARRAY_PATTERN);
|
|
915
|
+
if (match && match[0]) return match[0];
|
|
916
|
+
return null;
|
|
917
|
+
}
|
|
918
|
+
function repairCommonJsonDefects(text) {
|
|
919
|
+
return text.replace(/(:\s*-?\d+(?:\.\d+)?)\s*"/g, "$1").replace(/(:\s*"[^"]*")"/g, "$1");
|
|
920
|
+
}
|
|
834
921
|
function extractJsonCandidate(content) {
|
|
835
|
-
|
|
922
|
+
const fromFence = extractJsonFromCodeFence(content);
|
|
923
|
+
if (fromFence) return fromFence;
|
|
924
|
+
const objectIndex = content.indexOf("{");
|
|
925
|
+
const arrayIndex = content.indexOf("[");
|
|
926
|
+
if (objectIndex !== -1 && (arrayIndex === -1 || objectIndex < arrayIndex)) {
|
|
927
|
+
const obj = extractJsonObject(content);
|
|
928
|
+
if (obj) return obj;
|
|
929
|
+
} else if (arrayIndex !== -1) {
|
|
930
|
+
const arr = extractJsonArray(content);
|
|
931
|
+
if (arr) return arr;
|
|
932
|
+
}
|
|
933
|
+
return content.trim();
|
|
836
934
|
}
|
|
837
935
|
|
|
838
936
|
// src/core/parsers/json-response.parser.ts
|
|
@@ -841,12 +939,17 @@ var JsonResponseParser = class {
|
|
|
841
939
|
const candidate = extractJsonCandidate(rawContent);
|
|
842
940
|
try {
|
|
843
941
|
return JSON.parse(candidate);
|
|
844
|
-
} catch
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
942
|
+
} catch {
|
|
943
|
+
try {
|
|
944
|
+
return JSON.parse(repairCommonJsonDefects(candidate));
|
|
945
|
+
} catch (error) {
|
|
946
|
+
throw new AIError(
|
|
947
|
+
"UNKNOWN_ERROR" /* UNKNOWN_ERROR */,
|
|
948
|
+
"Failed to parse structured response as JSON",
|
|
949
|
+
error instanceof Error ? error : void 0,
|
|
950
|
+
{ rawContent }
|
|
951
|
+
);
|
|
952
|
+
}
|
|
850
953
|
}
|
|
851
954
|
}
|
|
852
955
|
};
|
|
@@ -964,6 +1067,6 @@ data: ${JSON.stringify(data)}
|
|
|
964
1067
|
});
|
|
965
1068
|
}
|
|
966
1069
|
|
|
967
|
-
export { AIError, AIErrorType, CacheManager, CompositeExecutor, DEFAULT_API_KEY_RULE, DEFAULT_ERROR_CLASSIFICATION_RULE, DEFAULT_HTTP_STATUS_RULE, DEFAULT_RETRY_BACKOFF_MULTIPLIER, DEFAULT_RETRY_INITIAL_DELAY_MS, DEFAULT_RETRY_JITTER_FACTOR, DEFAULT_RETRY_MAX_ATTEMPTS, DEFAULT_RETRY_MAX_DELAY_MS, DebounceManager, DedupeExecutor, JSON_CODE_BLOCK_PATTERN, JSON_OBJECT_PATTERN, JsonResponseParser, QueueExecutor, RequestDeduplicator, RequestQueue, RetryExecutor, RetryManager, SSE_BRIDGE_EVENTS, SSE_DONE_MARKER, SSE_PREFIX, StreamingResponseParser, StructuredPromptBuilder, TEXT_TIERS, ThrottleManager, USER_FRIENDLY_ERROR_MESSAGES, asObjectArray, asRecord, asStringArray, asTrimmedOptionalString, buildCacheKey, buildHttpStatusFallback, cacheManager, clampScore, classifyHttpStatus, createSseResponse, debounce, debounceManager, describeAIErrorType, extractErrorMessageFromJsonBody, extractErrorMessageFromResponse, extractJsonCandidate, extractJsonFromCodeFence, extractJsonObject, extractSseDataPayload, formatErrorForLogging, isAuthErrorType, isRetryableErrorType, isSseDataLine, isSseDoneMarker, isTextTier, isValidApiKey, mergeTierOverrides, normalizeSseChunk, oneOfCatalog, requestDeduplicator, requestQueue, resolveModel, resolveUserFriendlyErrorMessage, resolveUserFriendlyMessage, retryManager, splitSseLines, throttle, throttleManager, validateApiKey, withRetry };
|
|
1070
|
+
export { AIError, AIErrorType, CacheManager, CompositeExecutor, DEFAULT_API_KEY_RULE, DEFAULT_ERROR_CLASSIFICATION_RULE, DEFAULT_HTTP_STATUS_RULE, DEFAULT_RETRY_BACKOFF_MULTIPLIER, DEFAULT_RETRY_INITIAL_DELAY_MS, DEFAULT_RETRY_JITTER_FACTOR, DEFAULT_RETRY_MAX_ATTEMPTS, DEFAULT_RETRY_MAX_DELAY_MS, DebounceManager, DedupeExecutor, GroqError, AIErrorType as GroqErrorType, JSON_CODE_BLOCK_PATTERN, JSON_OBJECT_PATTERN, JsonResponseParser, QueueExecutor, RequestDeduplicator, RequestQueue, RetryExecutor, RetryManager, SSE_BRIDGE_EVENTS, SSE_DONE_MARKER, SSE_PREFIX, StreamingResponseParser, StructuredPromptBuilder, TEXT_TIERS, ThrottleManager, USER_FRIENDLY_ERROR_MESSAGES, asObjectArray, asRecord, asStringArray, asTrimmedOptionalString, buildCacheKey, buildHttpStatusFallback, cacheManager, clampScore, classifyHttpStatus, createSseResponse, debounce, debounceManager, describeAIErrorType, extractErrorMessageFromJsonBody, extractErrorMessageFromResponse, extractJsonArray, extractJsonCandidate, extractJsonFromCodeFence, extractJsonObject, extractSseDataPayload, formatErrorForLogging, isAuthErrorType, isRetryableErrorType, isSseDataLine, isSseDoneMarker, isTextTier, isValidApiKey, mergeTierOverrides, normalizeSseChunk, oneOfCatalog, repairCommonJsonDefects, requestDeduplicator, requestQueue, resolveModel, resolveUserFriendlyErrorMessage, resolveUserFriendlyMessage, retryManager, splitSseLines, throttle, throttleManager, validateApiKey, withRetry };
|
|
968
1071
|
//# sourceMappingURL=index.js.map
|
|
969
1072
|
//# sourceMappingURL=index.js.map
|