@prestyj/ai 4.3.164 → 4.3.200
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/index.cjs +431 -93
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +80 -3
- package/dist/index.d.ts +80 -3
- package/dist/index.js +428 -93
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
|
|
3
3
|
type Provider = "anthropic" | "xiaomi" | "openai" | "glm" | "moonshot" | "minimax" | "deepseek" | "openrouter" | "palsu";
|
|
4
|
-
type ThinkingLevel = "low" | "medium" | "high" | "
|
|
4
|
+
type ThinkingLevel = "low" | "medium" | "high" | "xhigh";
|
|
5
5
|
type CacheRetention = "none" | "short" | "long";
|
|
6
6
|
interface TextContent {
|
|
7
7
|
type: "text";
|
|
@@ -157,6 +157,10 @@ interface StreamOptions {
|
|
|
157
157
|
signal?: AbortSignal;
|
|
158
158
|
/** Prompt cache retention preference. Providers map this to their supported values. Default: "short". */
|
|
159
159
|
cacheRetention?: CacheRetention;
|
|
160
|
+
/** Stable per-session cache routing key for providers that support it (OpenAI, Moonshot). */
|
|
161
|
+
promptCacheKey?: string;
|
|
162
|
+
/** OpenAI service tier for latency-sensitive requests. Only sent to first-party OpenAI API calls. */
|
|
163
|
+
serviceTier?: "auto" | "default" | "flex" | "priority";
|
|
160
164
|
/** OpenAI ChatGPT account ID (from OAuth JWT) for codex endpoint */
|
|
161
165
|
accountId?: string;
|
|
162
166
|
/** Enable provider-native web search. Each provider uses its own format:
|
|
@@ -185,6 +189,12 @@ interface StreamOptions {
|
|
|
185
189
|
* stalls — broken SSE connections (transient CDN / proxy issues) often
|
|
186
190
|
* recover when the same request is issued over a plain HTTP request/response. */
|
|
187
191
|
streaming?: boolean;
|
|
192
|
+
/** Override the User-Agent sent with OAuth-authenticated Anthropic requests.
|
|
193
|
+
* Anthropic's OAuth edge rejects requests whose claude-cli version lags too
|
|
194
|
+
* far behind the real Claude Code release; callers that track the live
|
|
195
|
+
* version should pass it here. Ignored for non-Anthropic providers and for
|
|
196
|
+
* Anthropic requests using a regular API key. */
|
|
197
|
+
userAgent?: string;
|
|
188
198
|
}
|
|
189
199
|
|
|
190
200
|
/**
|
|
@@ -292,17 +302,84 @@ declare class ProviderRegistryImpl {
|
|
|
292
302
|
/** Global provider registry. Import this to register custom providers. */
|
|
293
303
|
declare const providerRegistry: ProviderRegistryImpl;
|
|
294
304
|
|
|
305
|
+
/**
|
|
306
|
+
* Error model for gg-ai and downstream consumers.
|
|
307
|
+
*
|
|
308
|
+
* Every error users see should answer one question: "is this me or them?"
|
|
309
|
+
* That answer drives whether they retry, switch model, log in, or report a
|
|
310
|
+
* ezcoder bug. The `FormattedError` shape captures it in plain English:
|
|
311
|
+
*
|
|
312
|
+
* ✗ OpenAI returned an error.
|
|
313
|
+
* An error occurred while processing your request...
|
|
314
|
+
* → This is an OpenAI issue, not ezcoder. Retry — if it persists, check status.openai.com.
|
|
315
|
+
*
|
|
316
|
+
* ✗ ezcoder hit an unexpected error.
|
|
317
|
+
* Cannot read property 'foo' of undefined
|
|
318
|
+
* → This is a ezcoder bug — please report it.
|
|
319
|
+
*/
|
|
320
|
+
type ErrorSource = "provider" | "ezcoder" | "network" | "auth";
|
|
321
|
+
interface FormattedError {
|
|
322
|
+
/** Plain-English headline, e.g. "OpenAI returned an error." */
|
|
323
|
+
headline: string;
|
|
324
|
+
/** Machine-readable classification. */
|
|
325
|
+
source: ErrorSource;
|
|
326
|
+
/** Detailed message body from the underlying error (no JSON, no tag prefix). */
|
|
327
|
+
message: string;
|
|
328
|
+
/** Action line — tells the user whether to retry, switch model, log in, or report a bug. */
|
|
329
|
+
guidance: string;
|
|
330
|
+
/** Provider name when source === "provider". */
|
|
331
|
+
provider?: string;
|
|
332
|
+
/** HTTP status code if known. */
|
|
333
|
+
statusCode?: number;
|
|
334
|
+
/** Provider request ID, kept for telemetry / debug — not shown by default. */
|
|
335
|
+
requestId?: string;
|
|
336
|
+
}
|
|
295
337
|
declare class EZCoderAIError extends Error {
|
|
296
|
-
|
|
338
|
+
readonly source: ErrorSource;
|
|
339
|
+
readonly requestId?: string;
|
|
340
|
+
readonly hint?: string;
|
|
341
|
+
constructor(message: string, options?: {
|
|
342
|
+
source?: ErrorSource;
|
|
343
|
+
requestId?: string;
|
|
344
|
+
hint?: string;
|
|
345
|
+
cause?: unknown;
|
|
346
|
+
});
|
|
297
347
|
}
|
|
298
348
|
declare class ProviderError extends EZCoderAIError {
|
|
299
349
|
readonly provider: string;
|
|
300
350
|
readonly statusCode?: number;
|
|
301
351
|
constructor(provider: string, message: string, options?: {
|
|
302
352
|
statusCode?: number;
|
|
353
|
+
requestId?: string;
|
|
354
|
+
hint?: string;
|
|
303
355
|
cause?: unknown;
|
|
304
356
|
});
|
|
305
357
|
}
|
|
358
|
+
/**
|
|
359
|
+
* Normalise any thrown value into a structured display object. Always returns
|
|
360
|
+
* a non-empty `headline` and `guidance` so the UI never has to second-guess
|
|
361
|
+
* what to show the user.
|
|
362
|
+
*/
|
|
363
|
+
declare function formatError(err: unknown): FormattedError;
|
|
364
|
+
/**
|
|
365
|
+
* Render a FormattedError as a multi-line string for terminal display.
|
|
366
|
+
*
|
|
367
|
+
* Format:
|
|
368
|
+
* <headline>
|
|
369
|
+
* <message>
|
|
370
|
+
* → <guidance>
|
|
371
|
+
*/
|
|
372
|
+
declare function formatErrorForDisplay(err: unknown): string;
|
|
373
|
+
|
|
374
|
+
/**
|
|
375
|
+
* Provider-level diagnostic hook. Mirrors the pattern used by gg-agent's
|
|
376
|
+
* setStreamDiagnostic — the host app wires a callback (typically writing to
|
|
377
|
+
* a debug log) and providers call `providerDiag(...)` to record interesting
|
|
378
|
+
* lifecycle events (e.g. raw SSE event types and timings).
|
|
379
|
+
*/
|
|
380
|
+
type ProviderDiagnosticFn = (phase: string, data?: Record<string, unknown>) => void;
|
|
381
|
+
/** Register a diagnostic callback for provider-level tracing. */
|
|
382
|
+
declare function setProviderDiagnostic(fn: ProviderDiagnosticFn | null): void;
|
|
306
383
|
|
|
307
384
|
interface PalsuProviderState {
|
|
308
385
|
callCount: number;
|
|
@@ -373,4 +450,4 @@ interface PalsuProviderConfig {
|
|
|
373
450
|
*/
|
|
374
451
|
declare function registerPalsuProvider(config?: PalsuProviderConfig): PalsuProviderHandle;
|
|
375
452
|
|
|
376
|
-
export { type AssistantMessage, type CacheRetention, type ContentPart, type DoneEvent, EZCoderAIError, type ErrorEvent, EventStream, type ImageContent, type Message, type PalsuModelConfig, type PalsuModelHandle, type PalsuProviderConfig, type PalsuProviderHandle, type PalsuProviderState, type PalsuResponse, type PalsuResponseFactory, type Provider, type ProviderEntry, ProviderError, type ProviderStreamFn, type RawContent, type ServerToolCall, type ServerToolCallEvent, type ServerToolDefinition, type ServerToolResult, type ServerToolResultEvent, type StopReason, type StreamEvent, type StreamOptions, type StreamResponse, StreamResult, type SystemMessage, type TextContent, type TextDeltaEvent, type ThinkingContent, type ThinkingDeltaEvent, type ThinkingLevel, type Tool, type ToolCall, type ToolCallDeltaEvent, type ToolCallDoneEvent, type ToolChoice, type ToolResult, type ToolResultContent, type ToolResultMessage, type Usage, type UserMessage, palsuAssistantMessage, palsuText, palsuThinking, palsuToolCall, providerRegistry, registerPalsuProvider, stream };
|
|
453
|
+
export { type AssistantMessage, type CacheRetention, type ContentPart, type DoneEvent, EZCoderAIError, type ErrorEvent, type ErrorSource, EventStream, type FormattedError, type ImageContent, type Message, type PalsuModelConfig, type PalsuModelHandle, type PalsuProviderConfig, type PalsuProviderHandle, type PalsuProviderState, type PalsuResponse, type PalsuResponseFactory, type Provider, type ProviderDiagnosticFn, type ProviderEntry, ProviderError, type ProviderStreamFn, type RawContent, type ServerToolCall, type ServerToolCallEvent, type ServerToolDefinition, type ServerToolResult, type ServerToolResultEvent, type StopReason, type StreamEvent, type StreamOptions, type StreamResponse, StreamResult, type SystemMessage, type TextContent, type TextDeltaEvent, type ThinkingContent, type ThinkingDeltaEvent, type ThinkingLevel, type Tool, type ToolCall, type ToolCallDeltaEvent, type ToolCallDoneEvent, type ToolChoice, type ToolResult, type ToolResultContent, type ToolResultMessage, type Usage, type UserMessage, formatError, formatErrorForDisplay, palsuAssistantMessage, palsuText, palsuThinking, palsuToolCall, providerRegistry, registerPalsuProvider, setProviderDiagnostic, stream };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
|
|
3
3
|
type Provider = "anthropic" | "xiaomi" | "openai" | "glm" | "moonshot" | "minimax" | "deepseek" | "openrouter" | "palsu";
|
|
4
|
-
type ThinkingLevel = "low" | "medium" | "high" | "
|
|
4
|
+
type ThinkingLevel = "low" | "medium" | "high" | "xhigh";
|
|
5
5
|
type CacheRetention = "none" | "short" | "long";
|
|
6
6
|
interface TextContent {
|
|
7
7
|
type: "text";
|
|
@@ -157,6 +157,10 @@ interface StreamOptions {
|
|
|
157
157
|
signal?: AbortSignal;
|
|
158
158
|
/** Prompt cache retention preference. Providers map this to their supported values. Default: "short". */
|
|
159
159
|
cacheRetention?: CacheRetention;
|
|
160
|
+
/** Stable per-session cache routing key for providers that support it (OpenAI, Moonshot). */
|
|
161
|
+
promptCacheKey?: string;
|
|
162
|
+
/** OpenAI service tier for latency-sensitive requests. Only sent to first-party OpenAI API calls. */
|
|
163
|
+
serviceTier?: "auto" | "default" | "flex" | "priority";
|
|
160
164
|
/** OpenAI ChatGPT account ID (from OAuth JWT) for codex endpoint */
|
|
161
165
|
accountId?: string;
|
|
162
166
|
/** Enable provider-native web search. Each provider uses its own format:
|
|
@@ -185,6 +189,12 @@ interface StreamOptions {
|
|
|
185
189
|
* stalls — broken SSE connections (transient CDN / proxy issues) often
|
|
186
190
|
* recover when the same request is issued over a plain HTTP request/response. */
|
|
187
191
|
streaming?: boolean;
|
|
192
|
+
/** Override the User-Agent sent with OAuth-authenticated Anthropic requests.
|
|
193
|
+
* Anthropic's OAuth edge rejects requests whose claude-cli version lags too
|
|
194
|
+
* far behind the real Claude Code release; callers that track the live
|
|
195
|
+
* version should pass it here. Ignored for non-Anthropic providers and for
|
|
196
|
+
* Anthropic requests using a regular API key. */
|
|
197
|
+
userAgent?: string;
|
|
188
198
|
}
|
|
189
199
|
|
|
190
200
|
/**
|
|
@@ -292,17 +302,84 @@ declare class ProviderRegistryImpl {
|
|
|
292
302
|
/** Global provider registry. Import this to register custom providers. */
|
|
293
303
|
declare const providerRegistry: ProviderRegistryImpl;
|
|
294
304
|
|
|
305
|
+
/**
|
|
306
|
+
* Error model for gg-ai and downstream consumers.
|
|
307
|
+
*
|
|
308
|
+
* Every error users see should answer one question: "is this me or them?"
|
|
309
|
+
* That answer drives whether they retry, switch model, log in, or report a
|
|
310
|
+
* ezcoder bug. The `FormattedError` shape captures it in plain English:
|
|
311
|
+
*
|
|
312
|
+
* ✗ OpenAI returned an error.
|
|
313
|
+
* An error occurred while processing your request...
|
|
314
|
+
* → This is an OpenAI issue, not ezcoder. Retry — if it persists, check status.openai.com.
|
|
315
|
+
*
|
|
316
|
+
* ✗ ezcoder hit an unexpected error.
|
|
317
|
+
* Cannot read property 'foo' of undefined
|
|
318
|
+
* → This is a ezcoder bug — please report it.
|
|
319
|
+
*/
|
|
320
|
+
type ErrorSource = "provider" | "ezcoder" | "network" | "auth";
|
|
321
|
+
interface FormattedError {
|
|
322
|
+
/** Plain-English headline, e.g. "OpenAI returned an error." */
|
|
323
|
+
headline: string;
|
|
324
|
+
/** Machine-readable classification. */
|
|
325
|
+
source: ErrorSource;
|
|
326
|
+
/** Detailed message body from the underlying error (no JSON, no tag prefix). */
|
|
327
|
+
message: string;
|
|
328
|
+
/** Action line — tells the user whether to retry, switch model, log in, or report a bug. */
|
|
329
|
+
guidance: string;
|
|
330
|
+
/** Provider name when source === "provider". */
|
|
331
|
+
provider?: string;
|
|
332
|
+
/** HTTP status code if known. */
|
|
333
|
+
statusCode?: number;
|
|
334
|
+
/** Provider request ID, kept for telemetry / debug — not shown by default. */
|
|
335
|
+
requestId?: string;
|
|
336
|
+
}
|
|
295
337
|
declare class EZCoderAIError extends Error {
|
|
296
|
-
|
|
338
|
+
readonly source: ErrorSource;
|
|
339
|
+
readonly requestId?: string;
|
|
340
|
+
readonly hint?: string;
|
|
341
|
+
constructor(message: string, options?: {
|
|
342
|
+
source?: ErrorSource;
|
|
343
|
+
requestId?: string;
|
|
344
|
+
hint?: string;
|
|
345
|
+
cause?: unknown;
|
|
346
|
+
});
|
|
297
347
|
}
|
|
298
348
|
declare class ProviderError extends EZCoderAIError {
|
|
299
349
|
readonly provider: string;
|
|
300
350
|
readonly statusCode?: number;
|
|
301
351
|
constructor(provider: string, message: string, options?: {
|
|
302
352
|
statusCode?: number;
|
|
353
|
+
requestId?: string;
|
|
354
|
+
hint?: string;
|
|
303
355
|
cause?: unknown;
|
|
304
356
|
});
|
|
305
357
|
}
|
|
358
|
+
/**
|
|
359
|
+
* Normalise any thrown value into a structured display object. Always returns
|
|
360
|
+
* a non-empty `headline` and `guidance` so the UI never has to second-guess
|
|
361
|
+
* what to show the user.
|
|
362
|
+
*/
|
|
363
|
+
declare function formatError(err: unknown): FormattedError;
|
|
364
|
+
/**
|
|
365
|
+
* Render a FormattedError as a multi-line string for terminal display.
|
|
366
|
+
*
|
|
367
|
+
* Format:
|
|
368
|
+
* <headline>
|
|
369
|
+
* <message>
|
|
370
|
+
* → <guidance>
|
|
371
|
+
*/
|
|
372
|
+
declare function formatErrorForDisplay(err: unknown): string;
|
|
373
|
+
|
|
374
|
+
/**
|
|
375
|
+
* Provider-level diagnostic hook. Mirrors the pattern used by gg-agent's
|
|
376
|
+
* setStreamDiagnostic — the host app wires a callback (typically writing to
|
|
377
|
+
* a debug log) and providers call `providerDiag(...)` to record interesting
|
|
378
|
+
* lifecycle events (e.g. raw SSE event types and timings).
|
|
379
|
+
*/
|
|
380
|
+
type ProviderDiagnosticFn = (phase: string, data?: Record<string, unknown>) => void;
|
|
381
|
+
/** Register a diagnostic callback for provider-level tracing. */
|
|
382
|
+
declare function setProviderDiagnostic(fn: ProviderDiagnosticFn | null): void;
|
|
306
383
|
|
|
307
384
|
interface PalsuProviderState {
|
|
308
385
|
callCount: number;
|
|
@@ -373,4 +450,4 @@ interface PalsuProviderConfig {
|
|
|
373
450
|
*/
|
|
374
451
|
declare function registerPalsuProvider(config?: PalsuProviderConfig): PalsuProviderHandle;
|
|
375
452
|
|
|
376
|
-
export { type AssistantMessage, type CacheRetention, type ContentPart, type DoneEvent, EZCoderAIError, type ErrorEvent, EventStream, type ImageContent, type Message, type PalsuModelConfig, type PalsuModelHandle, type PalsuProviderConfig, type PalsuProviderHandle, type PalsuProviderState, type PalsuResponse, type PalsuResponseFactory, type Provider, type ProviderEntry, ProviderError, type ProviderStreamFn, type RawContent, type ServerToolCall, type ServerToolCallEvent, type ServerToolDefinition, type ServerToolResult, type ServerToolResultEvent, type StopReason, type StreamEvent, type StreamOptions, type StreamResponse, StreamResult, type SystemMessage, type TextContent, type TextDeltaEvent, type ThinkingContent, type ThinkingDeltaEvent, type ThinkingLevel, type Tool, type ToolCall, type ToolCallDeltaEvent, type ToolCallDoneEvent, type ToolChoice, type ToolResult, type ToolResultContent, type ToolResultMessage, type Usage, type UserMessage, palsuAssistantMessage, palsuText, palsuThinking, palsuToolCall, providerRegistry, registerPalsuProvider, stream };
|
|
453
|
+
export { type AssistantMessage, type CacheRetention, type ContentPart, type DoneEvent, EZCoderAIError, type ErrorEvent, type ErrorSource, EventStream, type FormattedError, type ImageContent, type Message, type PalsuModelConfig, type PalsuModelHandle, type PalsuProviderConfig, type PalsuProviderHandle, type PalsuProviderState, type PalsuResponse, type PalsuResponseFactory, type Provider, type ProviderDiagnosticFn, type ProviderEntry, ProviderError, type ProviderStreamFn, type RawContent, type ServerToolCall, type ServerToolCallEvent, type ServerToolDefinition, type ServerToolResult, type ServerToolResultEvent, type StopReason, type StreamEvent, type StreamOptions, type StreamResponse, StreamResult, type SystemMessage, type TextContent, type TextDeltaEvent, type ThinkingContent, type ThinkingDeltaEvent, type ThinkingLevel, type Tool, type ToolCall, type ToolCallDeltaEvent, type ToolCallDoneEvent, type ToolChoice, type ToolResult, type ToolResultContent, type ToolResultMessage, type Usage, type UserMessage, formatError, formatErrorForDisplay, palsuAssistantMessage, palsuText, palsuThinking, palsuToolCall, providerRegistry, registerPalsuProvider, setProviderDiagnostic, stream };
|