veryfront 0.1.261 → 0.1.263
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/esm/cli/commands/knowledge/command.d.ts.map +1 -1
- package/esm/cli/commands/knowledge/command.js +19 -26
- package/esm/cli/templates/manifest.d.ts +470 -470
- package/esm/cli/templates/manifest.js +519 -519
- package/esm/deno.js +1 -1
- package/esm/src/agent/ag-ui-detached-start.d.ts +1 -4
- package/esm/src/agent/ag-ui-detached-start.d.ts.map +1 -1
- package/esm/src/agent/ag-ui-detached-start.js +4 -67
- package/esm/src/agent/ag-ui-handler.d.ts +1 -4
- package/esm/src/agent/ag-ui-handler.d.ts.map +1 -1
- package/esm/src/agent/ag-ui-handler.js +3 -61
- package/esm/src/agent/ag-ui-host-support.d.ts.map +1 -1
- package/esm/src/agent/ag-ui-host-support.js +2 -21
- package/esm/src/agent/ag-ui-request-shared.d.ts +4 -0
- package/esm/src/agent/ag-ui-request-shared.d.ts.map +1 -0
- package/esm/src/agent/ag-ui-request-shared.js +47 -0
- package/esm/src/agent/ag-ui-run-control.d.ts.map +1 -1
- package/esm/src/agent/ag-ui-run-control.js +1 -23
- package/esm/src/agent/ag-ui-runtime-handler.d.ts +1 -5
- package/esm/src/agent/ag-ui-runtime-handler.d.ts.map +1 -1
- package/esm/src/agent/ag-ui-runtime-handler.js +3 -67
- package/esm/src/agent/ag-ui-tool-shared.d.ts +15 -0
- package/esm/src/agent/ag-ui-tool-shared.d.ts.map +1 -0
- package/esm/src/agent/ag-ui-tool-shared.js +47 -0
- package/esm/src/agent/conversation-run-event-preparation.d.ts +3 -1
- package/esm/src/agent/conversation-run-event-preparation.d.ts.map +1 -1
- package/esm/src/agent/conversation-run-event-preparation.js +40 -0
- package/esm/src/agent/index.d.ts +3 -1
- package/esm/src/agent/index.d.ts.map +1 -1
- package/esm/src/agent/index.js +2 -1
- package/esm/src/agent/runtime-ag-ui-contract.d.ts.map +1 -1
- package/esm/src/agent/runtime-ag-ui-contract.js +2 -21
- package/esm/src/chat/chat-ui-message-helpers.d.ts +20 -0
- package/esm/src/chat/chat-ui-message-helpers.d.ts.map +1 -0
- package/esm/src/chat/chat-ui-message-helpers.js +167 -0
- package/esm/src/chat/index.d.ts +2 -0
- package/esm/src/chat/index.d.ts.map +1 -1
- package/esm/src/chat/index.js +1 -0
- package/esm/src/chat/protocol.d.ts +109 -0
- package/esm/src/chat/protocol.d.ts.map +1 -1
- package/esm/src/provider/runtime-loader/provider-http.d.ts +47 -0
- package/esm/src/provider/runtime-loader/provider-http.d.ts.map +1 -0
- package/esm/src/provider/runtime-loader/provider-http.js +171 -0
- package/esm/src/provider/runtime-loader/provider-records.d.ts +2 -0
- package/esm/src/provider/runtime-loader/provider-records.d.ts.map +1 -0
- package/esm/src/provider/runtime-loader/provider-records.js +6 -0
- package/esm/src/provider/runtime-loader.d.ts +2 -32
- package/esm/src/provider/runtime-loader.d.ts.map +1 -1
- package/esm/src/provider/runtime-loader.js +3 -176
- package/esm/src/routing/api/module-loader/external-import-rewriter.d.ts +27 -0
- package/esm/src/routing/api/module-loader/external-import-rewriter.d.ts.map +1 -0
- package/esm/src/routing/api/module-loader/external-import-rewriter.js +339 -0
- package/esm/src/routing/api/module-loader/loader.d.ts +1 -22
- package/esm/src/routing/api/module-loader/loader.d.ts.map +1 -1
- package/esm/src/routing/api/module-loader/loader.js +4 -336
- package/esm/src/server/dev-ui/manifest.d.ts +17 -17
- package/esm/src/server/dev-ui/manifest.js +17 -17
- package/esm/src/utils/version-constant.d.ts +1 -1
- package/esm/src/utils/version-constant.js +1 -1
- package/package.json +1 -1
- package/src/cli/commands/knowledge/command.ts +27 -32
- package/src/cli/templates/manifest.js +519 -519
- package/src/deno.js +1 -1
- package/src/src/agent/ag-ui-detached-start.ts +4 -92
- package/src/src/agent/ag-ui-handler.ts +3 -81
- package/src/src/agent/ag-ui-host-support.ts +5 -28
- package/src/src/agent/ag-ui-request-shared.ts +62 -0
- package/src/src/agent/ag-ui-run-control.ts +1 -27
- package/src/src/agent/ag-ui-runtime-handler.ts +3 -86
- package/src/src/agent/ag-ui-tool-shared.ts +77 -0
- package/src/src/agent/conversation-run-event-preparation.ts +57 -1
- package/src/src/agent/index.ts +19 -0
- package/src/src/agent/runtime-ag-ui-contract.ts +5 -28
- package/src/src/chat/chat-ui-message-helpers.ts +232 -0
- package/src/src/chat/index.ts +19 -0
- package/src/src/chat/protocol.ts +148 -0
- package/src/src/provider/runtime-loader/provider-http.ts +207 -0
- package/src/src/provider/runtime-loader/provider-records.ts +7 -0
- package/src/src/provider/runtime-loader.ts +10 -214
- package/src/src/routing/api/module-loader/external-import-rewriter.ts +461 -0
- package/src/src/routing/api/module-loader/loader.ts +19 -462
- package/src/src/server/dev-ui/manifest.js +17 -17
- package/src/src/utils/version-constant.ts +1 -1
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import { readRecord } from "./provider-records.js";
|
|
2
|
+
/**
|
|
3
|
+
* Base class for typed provider errors. The `retryable` flag is the
|
|
4
|
+
* primary signal for callers (or a retry wrapper) to decide whether to
|
|
5
|
+
* re-issue the request. `retryAfterMs` is set when the provider gave an
|
|
6
|
+
* explicit delay hint (Retry-After header, Retry-Info trailer).
|
|
7
|
+
*/
|
|
8
|
+
export class ProviderError extends Error {
|
|
9
|
+
provider;
|
|
10
|
+
status;
|
|
11
|
+
retryable;
|
|
12
|
+
retryAfterMs;
|
|
13
|
+
constructor(options) {
|
|
14
|
+
super(options.message);
|
|
15
|
+
this.name = globalThis[Symbol.for("import-meta-ponyfill-esmodule")](import.meta).name;
|
|
16
|
+
this.provider = options.provider;
|
|
17
|
+
this.status = options.status;
|
|
18
|
+
this.retryable = options.retryable;
|
|
19
|
+
if (options.retryAfterMs !== undefined) {
|
|
20
|
+
this.retryAfterMs = options.retryAfterMs;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
/** Provider reports it is overloaded (Anthropic 529, OpenAI/Google 503). */
|
|
25
|
+
export class ProviderOverloadedError extends ProviderError {
|
|
26
|
+
}
|
|
27
|
+
/** Provider is rate limiting this API key (OpenAI/Google 429 with Retry-After). */
|
|
28
|
+
export class ProviderRateLimitError extends ProviderError {
|
|
29
|
+
}
|
|
30
|
+
/** Provider account quota is exhausted — non-retryable. */
|
|
31
|
+
export class ProviderQuotaError extends ProviderError {
|
|
32
|
+
}
|
|
33
|
+
/** Non-retryable 4xx/5xx that doesn't fit another bucket. */
|
|
34
|
+
export class ProviderRequestError extends ProviderError {
|
|
35
|
+
}
|
|
36
|
+
function parseRetryAfterMs(header) {
|
|
37
|
+
if (!header)
|
|
38
|
+
return undefined;
|
|
39
|
+
const asNumber = Number(header);
|
|
40
|
+
if (Number.isFinite(asNumber) && asNumber >= 0) {
|
|
41
|
+
return Math.round(asNumber * 1000);
|
|
42
|
+
}
|
|
43
|
+
// HTTP-date form (rare in practice for LLM providers).
|
|
44
|
+
const parsed = Date.parse(header);
|
|
45
|
+
if (!Number.isNaN(parsed)) {
|
|
46
|
+
return Math.max(0, parsed - Date.now());
|
|
47
|
+
}
|
|
48
|
+
return undefined;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Inspect a non-2xx response and build the most specific ProviderError
|
|
52
|
+
* subclass we can. Reads the response body as text (it's already dead
|
|
53
|
+
* on the wire by this point). Body classification handles the cases
|
|
54
|
+
* where HTTP status alone is ambiguous — notably OpenAI
|
|
55
|
+
* `insufficient_quota` vs `rate_limit_exceeded` both arriving as 429.
|
|
56
|
+
*/
|
|
57
|
+
async function buildProviderError(provider, response) {
|
|
58
|
+
const rawBody = await response.text();
|
|
59
|
+
const message = rawBody.trim() || `${response.status} ${response.statusText}`.trim();
|
|
60
|
+
const status = response.status;
|
|
61
|
+
const retryAfterMs = parseRetryAfterMs(response.headers.get("retry-after"));
|
|
62
|
+
const parsedBody = (() => {
|
|
63
|
+
try {
|
|
64
|
+
return JSON.parse(rawBody);
|
|
65
|
+
}
|
|
66
|
+
catch {
|
|
67
|
+
return undefined;
|
|
68
|
+
}
|
|
69
|
+
})();
|
|
70
|
+
const errorRecord = readRecord(parsedBody?.error);
|
|
71
|
+
const errorCode = typeof errorRecord?.code === "string"
|
|
72
|
+
? errorRecord.code
|
|
73
|
+
: typeof errorRecord?.type === "string"
|
|
74
|
+
? errorRecord.type
|
|
75
|
+
: typeof errorRecord?.status === "string"
|
|
76
|
+
? errorRecord.status
|
|
77
|
+
: undefined;
|
|
78
|
+
// Anthropic 529 = overloaded. Anthropic surfaces this with
|
|
79
|
+
// { error: { type: "overloaded_error" } } in the body.
|
|
80
|
+
if (provider === "anthropic" && status === 529) {
|
|
81
|
+
return new ProviderOverloadedError({
|
|
82
|
+
provider,
|
|
83
|
+
status,
|
|
84
|
+
message,
|
|
85
|
+
retryable: true,
|
|
86
|
+
...(retryAfterMs !== undefined ? { retryAfterMs } : {}),
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
// OpenAI / Google 503 = overloaded.
|
|
90
|
+
if ((provider === "openai" || provider === "google") && status === 503) {
|
|
91
|
+
return new ProviderOverloadedError({
|
|
92
|
+
provider,
|
|
93
|
+
status,
|
|
94
|
+
message,
|
|
95
|
+
retryable: true,
|
|
96
|
+
...(retryAfterMs !== undefined ? { retryAfterMs } : {}),
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
// OpenAI 429 splits based on the error code in the body:
|
|
100
|
+
// - insufficient_quota → hard quota, non-retryable
|
|
101
|
+
// - rate_limit_exceeded / tokens_per_min_exceeded → retry with Retry-After
|
|
102
|
+
if (provider === "openai" && status === 429) {
|
|
103
|
+
if (errorCode === "insufficient_quota") {
|
|
104
|
+
return new ProviderQuotaError({
|
|
105
|
+
provider,
|
|
106
|
+
status,
|
|
107
|
+
message,
|
|
108
|
+
retryable: false,
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
return new ProviderRateLimitError({
|
|
112
|
+
provider,
|
|
113
|
+
status,
|
|
114
|
+
message,
|
|
115
|
+
retryable: true,
|
|
116
|
+
...(retryAfterMs !== undefined ? { retryAfterMs } : {}),
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
// Google 429 RESOURCE_EXHAUSTED is almost always the daily free-tier
|
|
120
|
+
// quota — surface as a hard quota error so callers don't hot-loop on
|
|
121
|
+
// retries that can't possibly succeed until midnight UTC.
|
|
122
|
+
if (provider === "google" && status === 429) {
|
|
123
|
+
if (errorCode === "RESOURCE_EXHAUSTED") {
|
|
124
|
+
return new ProviderQuotaError({
|
|
125
|
+
provider,
|
|
126
|
+
status,
|
|
127
|
+
message,
|
|
128
|
+
retryable: false,
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
return new ProviderRateLimitError({
|
|
132
|
+
provider,
|
|
133
|
+
status,
|
|
134
|
+
message,
|
|
135
|
+
retryable: true,
|
|
136
|
+
...(retryAfterMs !== undefined ? { retryAfterMs } : {}),
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
return new ProviderRequestError({
|
|
140
|
+
provider,
|
|
141
|
+
status,
|
|
142
|
+
message,
|
|
143
|
+
retryable: false,
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
export async function requestJson(options) {
|
|
147
|
+
const response = await options.fetchImpl(options.url, options.init);
|
|
148
|
+
if (!response.ok) {
|
|
149
|
+
const err = await buildProviderError(options.providerKind, response);
|
|
150
|
+
err.message = `${options.providerLabel} request failed: ${err.message}`;
|
|
151
|
+
throw err;
|
|
152
|
+
}
|
|
153
|
+
return response.json();
|
|
154
|
+
}
|
|
155
|
+
export async function requestStream(options) {
|
|
156
|
+
const response = await options.fetchImpl(options.url, options.init);
|
|
157
|
+
if (!response.ok) {
|
|
158
|
+
const err = await buildProviderError(options.providerKind, response);
|
|
159
|
+
err.message = `${options.providerLabel} request failed: ${err.message}`;
|
|
160
|
+
throw err;
|
|
161
|
+
}
|
|
162
|
+
if (!response.body) {
|
|
163
|
+
throw new ProviderRequestError({
|
|
164
|
+
provider: options.providerKind,
|
|
165
|
+
status: response.status,
|
|
166
|
+
message: `${options.providerLabel} request failed: stream body missing`,
|
|
167
|
+
retryable: false,
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
return response.body;
|
|
171
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider-records.d.ts","sourceRoot":"","sources":["../../../../src/src/provider/runtime-loader/provider-records.ts"],"names":[],"mappings":"AAAA,wBAAgB,UAAU,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,CAM9E"}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import type { EmbeddingRuntime, ModelRuntime } from "./types.js";
|
|
2
|
+
import type { ProviderKind } from "./runtime-loader/provider-http.js";
|
|
2
3
|
import { TOOL_INPUT_PENDING_THRESHOLD_MS, withToolInputStatusTransitions } from "./runtime-loader/tool-input-status.js";
|
|
4
|
+
export { ProviderError, ProviderOverloadedError, ProviderQuotaError, ProviderRateLimitError, ProviderRequestError, } from "./runtime-loader/provider-http.js";
|
|
3
5
|
export { TOOL_INPUT_PENDING_THRESHOLD_MS, withToolInputStatusTransitions };
|
|
4
6
|
export interface OpenAIRuntimeConfig {
|
|
5
7
|
apiKey: string;
|
|
@@ -20,7 +22,6 @@ export interface GoogleRuntimeConfig {
|
|
|
20
22
|
name?: string;
|
|
21
23
|
fetch?: typeof globalThis.fetch;
|
|
22
24
|
}
|
|
23
|
-
type ProviderKind = "anthropic" | "openai" | "google";
|
|
24
25
|
/**
|
|
25
26
|
* Structured warning emitted when a provider runtime drops or rewrites a
|
|
26
27
|
* caller-provided option. Mirrors the AI ecosystem convention (Vercel AI
|
|
@@ -34,37 +35,6 @@ export type ProviderWarning = {
|
|
|
34
35
|
details?: string;
|
|
35
36
|
provider: ProviderKind;
|
|
36
37
|
};
|
|
37
|
-
/**
|
|
38
|
-
* Base class for typed provider errors. The `retryable` flag is the
|
|
39
|
-
* primary signal for callers (or a retry wrapper) to decide whether to
|
|
40
|
-
* re-issue the request. `retryAfterMs` is set when the provider gave an
|
|
41
|
-
* explicit delay hint (Retry-After header, Retry-Info trailer).
|
|
42
|
-
*/
|
|
43
|
-
export declare class ProviderError extends Error {
|
|
44
|
-
readonly provider: ProviderKind;
|
|
45
|
-
readonly status: number;
|
|
46
|
-
readonly retryable: boolean;
|
|
47
|
-
readonly retryAfterMs?: number;
|
|
48
|
-
constructor(options: {
|
|
49
|
-
provider: ProviderKind;
|
|
50
|
-
status: number;
|
|
51
|
-
message: string;
|
|
52
|
-
retryable: boolean;
|
|
53
|
-
retryAfterMs?: number;
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
/** Provider reports it is overloaded (Anthropic 529, OpenAI/Google 503). */
|
|
57
|
-
export declare class ProviderOverloadedError extends ProviderError {
|
|
58
|
-
}
|
|
59
|
-
/** Provider is rate limiting this API key (OpenAI/Google 429 with Retry-After). */
|
|
60
|
-
export declare class ProviderRateLimitError extends ProviderError {
|
|
61
|
-
}
|
|
62
|
-
/** Provider account quota is exhausted — non-retryable. */
|
|
63
|
-
export declare class ProviderQuotaError extends ProviderError {
|
|
64
|
-
}
|
|
65
|
-
/** Non-retryable 4xx/5xx that doesn't fit another bucket. */
|
|
66
|
-
export declare class ProviderRequestError extends ProviderError {
|
|
67
|
-
}
|
|
68
38
|
export declare function createOpenAIModelRuntime(config: OpenAIRuntimeConfig, modelId: string): ModelRuntime;
|
|
69
39
|
export declare function createOpenAIResponsesRuntime(config: OpenAIRuntimeConfig, modelId: string): ModelRuntime;
|
|
70
40
|
export declare function createAnthropicModelRuntime(config: AnthropicRuntimeConfig, modelId: string): ModelRuntime;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runtime-loader.d.ts","sourceRoot":"","sources":["../../../src/src/provider/runtime-loader.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAejE,OAAO,E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C1C,MAAM,EAAE,mBAAmB,EAC3B,OAAO,EAAE,MAAM,GACd,gBAAgB,CA6ClB"}
|
|
@@ -1,16 +1,13 @@
|
|
|
1
1
|
import { getAnthropicMessagesUrl, getGoogleEmbeddingUrl, getGoogleGenerateContentUrl, getGoogleStreamGenerateContentUrl, getOpenAIChatCompletionsUrl, getOpenAIEmbeddingUrl, getOpenAIResponsesUrl, } from "./runtime-loader/provider-endpoints.js";
|
|
2
2
|
import { createAnthropicRequestInit, createGoogleRequestInit, createOpenAIRequestInit, } from "./runtime-loader/provider-request-init.js";
|
|
3
|
+
import { requestJson, requestStream } from "./runtime-loader/provider-http.js";
|
|
4
|
+
import { readRecord } from "./runtime-loader/provider-records.js";
|
|
3
5
|
import { TOOL_INPUT_PENDING_THRESHOLD_MS, withToolInputStatusTransitions, } from "./runtime-loader/tool-input-status.js";
|
|
6
|
+
export { ProviderError, ProviderOverloadedError, ProviderQuotaError, ProviderRateLimitError, ProviderRequestError, } from "./runtime-loader/provider-http.js";
|
|
4
7
|
export { TOOL_INPUT_PENDING_THRESHOLD_MS, withToolInputStatusTransitions };
|
|
5
8
|
function isNumberArray(value) {
|
|
6
9
|
return Array.isArray(value) && value.every((entry) => typeof entry === "number");
|
|
7
10
|
}
|
|
8
|
-
function readRecord(value) {
|
|
9
|
-
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
10
|
-
return undefined;
|
|
11
|
-
}
|
|
12
|
-
return Object.fromEntries(Object.entries(value));
|
|
13
|
-
}
|
|
14
11
|
function extractOpenAIEmbeddings(payload) {
|
|
15
12
|
const record = readRecord(payload);
|
|
16
13
|
const data = record?.data;
|
|
@@ -68,176 +65,6 @@ function createWarningCollector() {
|
|
|
68
65
|
},
|
|
69
66
|
};
|
|
70
67
|
}
|
|
71
|
-
/**
|
|
72
|
-
* Base class for typed provider errors. The `retryable` flag is the
|
|
73
|
-
* primary signal for callers (or a retry wrapper) to decide whether to
|
|
74
|
-
* re-issue the request. `retryAfterMs` is set when the provider gave an
|
|
75
|
-
* explicit delay hint (Retry-After header, Retry-Info trailer).
|
|
76
|
-
*/
|
|
77
|
-
export class ProviderError extends Error {
|
|
78
|
-
provider;
|
|
79
|
-
status;
|
|
80
|
-
retryable;
|
|
81
|
-
retryAfterMs;
|
|
82
|
-
constructor(options) {
|
|
83
|
-
super(options.message);
|
|
84
|
-
this.name = globalThis[Symbol.for("import-meta-ponyfill-esmodule")](import.meta).name;
|
|
85
|
-
this.provider = options.provider;
|
|
86
|
-
this.status = options.status;
|
|
87
|
-
this.retryable = options.retryable;
|
|
88
|
-
if (options.retryAfterMs !== undefined) {
|
|
89
|
-
this.retryAfterMs = options.retryAfterMs;
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
/** Provider reports it is overloaded (Anthropic 529, OpenAI/Google 503). */
|
|
94
|
-
export class ProviderOverloadedError extends ProviderError {
|
|
95
|
-
}
|
|
96
|
-
/** Provider is rate limiting this API key (OpenAI/Google 429 with Retry-After). */
|
|
97
|
-
export class ProviderRateLimitError extends ProviderError {
|
|
98
|
-
}
|
|
99
|
-
/** Provider account quota is exhausted — non-retryable. */
|
|
100
|
-
export class ProviderQuotaError extends ProviderError {
|
|
101
|
-
}
|
|
102
|
-
/** Non-retryable 4xx/5xx that doesn't fit another bucket. */
|
|
103
|
-
export class ProviderRequestError extends ProviderError {
|
|
104
|
-
}
|
|
105
|
-
function parseRetryAfterMs(header) {
|
|
106
|
-
if (!header)
|
|
107
|
-
return undefined;
|
|
108
|
-
const asNumber = Number(header);
|
|
109
|
-
if (Number.isFinite(asNumber) && asNumber >= 0) {
|
|
110
|
-
return Math.round(asNumber * 1000);
|
|
111
|
-
}
|
|
112
|
-
// HTTP-date form (rare in practice for LLM providers).
|
|
113
|
-
const parsed = Date.parse(header);
|
|
114
|
-
if (!Number.isNaN(parsed)) {
|
|
115
|
-
return Math.max(0, parsed - Date.now());
|
|
116
|
-
}
|
|
117
|
-
return undefined;
|
|
118
|
-
}
|
|
119
|
-
/**
|
|
120
|
-
* Inspect a non-2xx response and build the most specific ProviderError
|
|
121
|
-
* subclass we can. Reads the response body as text (it's already dead
|
|
122
|
-
* on the wire by this point). Body classification handles the cases
|
|
123
|
-
* where HTTP status alone is ambiguous — notably OpenAI
|
|
124
|
-
* `insufficient_quota` vs `rate_limit_exceeded` both arriving as 429.
|
|
125
|
-
*/
|
|
126
|
-
async function buildProviderError(provider, response) {
|
|
127
|
-
const rawBody = await response.text();
|
|
128
|
-
const message = rawBody.trim() || `${response.status} ${response.statusText}`.trim();
|
|
129
|
-
const status = response.status;
|
|
130
|
-
const retryAfterMs = parseRetryAfterMs(response.headers.get("retry-after"));
|
|
131
|
-
const parsedBody = (() => {
|
|
132
|
-
try {
|
|
133
|
-
return JSON.parse(rawBody);
|
|
134
|
-
}
|
|
135
|
-
catch {
|
|
136
|
-
return undefined;
|
|
137
|
-
}
|
|
138
|
-
})();
|
|
139
|
-
const errorRecord = readRecord(parsedBody?.error);
|
|
140
|
-
const errorCode = typeof errorRecord?.code === "string"
|
|
141
|
-
? errorRecord.code
|
|
142
|
-
: typeof errorRecord?.type === "string"
|
|
143
|
-
? errorRecord.type
|
|
144
|
-
: typeof errorRecord?.status === "string"
|
|
145
|
-
? errorRecord.status
|
|
146
|
-
: undefined;
|
|
147
|
-
// Anthropic 529 = overloaded. Anthropic surfaces this with
|
|
148
|
-
// { error: { type: "overloaded_error" } } in the body.
|
|
149
|
-
if (provider === "anthropic" && status === 529) {
|
|
150
|
-
return new ProviderOverloadedError({
|
|
151
|
-
provider,
|
|
152
|
-
status,
|
|
153
|
-
message,
|
|
154
|
-
retryable: true,
|
|
155
|
-
...(retryAfterMs !== undefined ? { retryAfterMs } : {}),
|
|
156
|
-
});
|
|
157
|
-
}
|
|
158
|
-
// OpenAI / Google 503 = overloaded.
|
|
159
|
-
if ((provider === "openai" || provider === "google") && status === 503) {
|
|
160
|
-
return new ProviderOverloadedError({
|
|
161
|
-
provider,
|
|
162
|
-
status,
|
|
163
|
-
message,
|
|
164
|
-
retryable: true,
|
|
165
|
-
...(retryAfterMs !== undefined ? { retryAfterMs } : {}),
|
|
166
|
-
});
|
|
167
|
-
}
|
|
168
|
-
// OpenAI 429 splits based on the error code in the body:
|
|
169
|
-
// - insufficient_quota → hard quota, non-retryable
|
|
170
|
-
// - rate_limit_exceeded / tokens_per_min_exceeded → retry with Retry-After
|
|
171
|
-
if (provider === "openai" && status === 429) {
|
|
172
|
-
if (errorCode === "insufficient_quota") {
|
|
173
|
-
return new ProviderQuotaError({
|
|
174
|
-
provider,
|
|
175
|
-
status,
|
|
176
|
-
message,
|
|
177
|
-
retryable: false,
|
|
178
|
-
});
|
|
179
|
-
}
|
|
180
|
-
return new ProviderRateLimitError({
|
|
181
|
-
provider,
|
|
182
|
-
status,
|
|
183
|
-
message,
|
|
184
|
-
retryable: true,
|
|
185
|
-
...(retryAfterMs !== undefined ? { retryAfterMs } : {}),
|
|
186
|
-
});
|
|
187
|
-
}
|
|
188
|
-
// Google 429 RESOURCE_EXHAUSTED is almost always the daily free-tier
|
|
189
|
-
// quota — surface as a hard quota error so callers don't hot-loop on
|
|
190
|
-
// retries that can't possibly succeed until midnight UTC.
|
|
191
|
-
if (provider === "google" && status === 429) {
|
|
192
|
-
if (errorCode === "RESOURCE_EXHAUSTED") {
|
|
193
|
-
return new ProviderQuotaError({
|
|
194
|
-
provider,
|
|
195
|
-
status,
|
|
196
|
-
message,
|
|
197
|
-
retryable: false,
|
|
198
|
-
});
|
|
199
|
-
}
|
|
200
|
-
return new ProviderRateLimitError({
|
|
201
|
-
provider,
|
|
202
|
-
status,
|
|
203
|
-
message,
|
|
204
|
-
retryable: true,
|
|
205
|
-
...(retryAfterMs !== undefined ? { retryAfterMs } : {}),
|
|
206
|
-
});
|
|
207
|
-
}
|
|
208
|
-
return new ProviderRequestError({
|
|
209
|
-
provider,
|
|
210
|
-
status,
|
|
211
|
-
message,
|
|
212
|
-
retryable: false,
|
|
213
|
-
});
|
|
214
|
-
}
|
|
215
|
-
async function requestJson(options) {
|
|
216
|
-
const response = await options.fetchImpl(options.url, options.init);
|
|
217
|
-
if (!response.ok) {
|
|
218
|
-
const err = await buildProviderError(options.providerKind, response);
|
|
219
|
-
err.message = `${options.providerLabel} request failed: ${err.message}`;
|
|
220
|
-
throw err;
|
|
221
|
-
}
|
|
222
|
-
return response.json();
|
|
223
|
-
}
|
|
224
|
-
async function requestStream(options) {
|
|
225
|
-
const response = await options.fetchImpl(options.url, options.init);
|
|
226
|
-
if (!response.ok) {
|
|
227
|
-
const err = await buildProviderError(options.providerKind, response);
|
|
228
|
-
err.message = `${options.providerLabel} request failed: ${err.message}`;
|
|
229
|
-
throw err;
|
|
230
|
-
}
|
|
231
|
-
if (!response.body) {
|
|
232
|
-
throw new ProviderRequestError({
|
|
233
|
-
provider: options.providerKind,
|
|
234
|
-
status: response.status,
|
|
235
|
-
message: `${options.providerLabel} request failed: stream body missing`,
|
|
236
|
-
retryable: false,
|
|
237
|
-
});
|
|
238
|
-
}
|
|
239
|
-
return response.body;
|
|
240
|
-
}
|
|
241
68
|
function stringifyJsonValue(value) {
|
|
242
69
|
if (typeof value === "string") {
|
|
243
70
|
return value;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { FileSystem } from "../../../platform/compat/fs.js";
|
|
2
|
+
/** Node.js built-in module names — shared across the CJS shim, esbuild externals, and Deno rewrites. */
|
|
3
|
+
export declare const NODE_BUILTINS: readonly ["assert", "buffer", "child_process", "cluster", "console", "constants", "crypto", "dgram", "dns", "events", "fs", "http", "http2", "https", "module", "net", "os", "path", "perf_hooks", "process", "querystring", "readline", "stream", "string_decoder", "timers", "tls", "tty", "url", "util", "v8", "vm", "worker_threads", "zlib"];
|
|
4
|
+
export declare function readProjectDependencies(projectDir: string, fs: FileSystem): Promise<Map<string, string>>;
|
|
5
|
+
/**
|
|
6
|
+
* Generates a CJS module loader shim for compiled Deno binaries.
|
|
7
|
+
*
|
|
8
|
+
* In compiled binaries, `createRequire()` can resolve module paths and load
|
|
9
|
+
* built-in modules (fs, path, etc.), but cannot load CJS files from disk
|
|
10
|
+
* (loadMaybeCjs fails with "path not found"). This shim works around that
|
|
11
|
+
* limitation by using `Deno.readTextFileSync` to read CJS files and
|
|
12
|
+
* `new Function` to evaluate them in a proper CJS wrapper with require,
|
|
13
|
+
* exports, module, __filename, and __dirname bindings.
|
|
14
|
+
*/
|
|
15
|
+
export declare function generateCompiledBinaryRequireShim(projectDir: string): string;
|
|
16
|
+
export declare function getNodeExternalPackagesToResolve(userDeps: Map<string, string>): string[];
|
|
17
|
+
export declare function resolveNodePackageToFileUrl(projectDir: string, packageName: string, fs: FileSystem, pathToFileURL: typeof import("node:url").pathToFileURL): Promise<string | null>;
|
|
18
|
+
export declare function loadVeryfrontExportsMap(projectDir: string, fs: FileSystem): Promise<Record<string, {
|
|
19
|
+
import?: string;
|
|
20
|
+
}>>;
|
|
21
|
+
export declare function rewriteNodeExternalImports(code: string, projectDir: string, fs: FileSystem, userDeps: Map<string, string>): Promise<string>;
|
|
22
|
+
export declare function rewriteCompiledBinaryVeryfrontImports(code: string): string;
|
|
23
|
+
export declare function rewriteCompiledBinaryUserDependencyImports(code: string, userDeps: Map<string, string>): string;
|
|
24
|
+
export declare function rewriteDenoNpmDependencyImports(code: string, projectDir: string, fs: FileSystem, userDeps: Map<string, string>): Promise<string>;
|
|
25
|
+
export declare function rewriteDenoNodeBuiltinImports(code: string): string;
|
|
26
|
+
export declare function rewriteExternalImports(code: string, projectDir: string, fs: FileSystem, userDeps?: Map<string, string>): Promise<string>;
|
|
27
|
+
//# sourceMappingURL=external-import-rewriter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"external-import-rewriter.d.ts","sourceRoot":"","sources":["../../../../../src/src/routing/api/module-loader/external-import-rewriter.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gCAAgC,CAAC;AAQjE,wGAAwG;AACxG,eAAO,M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