@kenkaiiii/gg-ai 4.3.170 → 4.3.172
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 +57 -16
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +11 -1
- package/dist/index.d.ts +11 -1
- package/dist/index.js +56 -16
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -371,6 +371,16 @@ declare function formatError(err: unknown): FormattedError;
|
|
|
371
371
|
*/
|
|
372
372
|
declare function formatErrorForDisplay(err: unknown): string;
|
|
373
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;
|
|
383
|
+
|
|
374
384
|
interface PalsuProviderState {
|
|
375
385
|
callCount: number;
|
|
376
386
|
}
|
|
@@ -440,4 +450,4 @@ interface PalsuProviderConfig {
|
|
|
440
450
|
*/
|
|
441
451
|
declare function registerPalsuProvider(config?: PalsuProviderConfig): PalsuProviderHandle;
|
|
442
452
|
|
|
443
|
-
export { type AssistantMessage, type CacheRetention, type ContentPart, type DoneEvent, type ErrorEvent, type ErrorSource, EventStream, type FormattedError, GGAIError, 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, formatError, formatErrorForDisplay, palsuAssistantMessage, palsuText, palsuThinking, palsuToolCall, providerRegistry, registerPalsuProvider, stream };
|
|
453
|
+
export { type AssistantMessage, type CacheRetention, type ContentPart, type DoneEvent, type ErrorEvent, type ErrorSource, EventStream, type FormattedError, GGAIError, 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
|
@@ -371,6 +371,16 @@ declare function formatError(err: unknown): FormattedError;
|
|
|
371
371
|
*/
|
|
372
372
|
declare function formatErrorForDisplay(err: unknown): string;
|
|
373
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;
|
|
383
|
+
|
|
374
384
|
interface PalsuProviderState {
|
|
375
385
|
callCount: number;
|
|
376
386
|
}
|
|
@@ -440,4 +450,4 @@ interface PalsuProviderConfig {
|
|
|
440
450
|
*/
|
|
441
451
|
declare function registerPalsuProvider(config?: PalsuProviderConfig): PalsuProviderHandle;
|
|
442
452
|
|
|
443
|
-
export { type AssistantMessage, type CacheRetention, type ContentPart, type DoneEvent, type ErrorEvent, type ErrorSource, EventStream, type FormattedError, GGAIError, 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, formatError, formatErrorForDisplay, palsuAssistantMessage, palsuText, palsuThinking, palsuToolCall, providerRegistry, registerPalsuProvider, stream };
|
|
453
|
+
export { type AssistantMessage, type CacheRetention, type ContentPart, type DoneEvent, type ErrorEvent, type ErrorSource, EventStream, type FormattedError, GGAIError, 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.js
CHANGED
|
@@ -685,11 +685,7 @@ function toOpenAIToolChoice(choice) {
|
|
|
685
685
|
if (choice === "required") return "required";
|
|
686
686
|
return { type: "function", function: { name: choice.name } };
|
|
687
687
|
}
|
|
688
|
-
function
|
|
689
|
-
return /^gpt-5\.\d+-pro$/i.test(model);
|
|
690
|
-
}
|
|
691
|
-
function toOpenAIReasoningEffort(level, model) {
|
|
692
|
-
if (isOpenAIProVariant(model) && level === "low") return "medium";
|
|
688
|
+
function toOpenAIReasoningEffort(level, _model) {
|
|
693
689
|
return level;
|
|
694
690
|
}
|
|
695
691
|
function normalizeAnthropicStopReason(reason) {
|
|
@@ -782,16 +778,28 @@ async function* runStream(options) {
|
|
|
782
778
|
...options.temperature != null && !thinking ? { temperature: options.temperature } : {},
|
|
783
779
|
...options.topP != null ? { top_p: options.topP } : {},
|
|
784
780
|
...options.stop ? { stop_sequences: options.stop } : {},
|
|
785
|
-
...options.tools?.length || options.serverTools?.length || options.webSearch ? {
|
|
786
|
-
|
|
787
|
-
|
|
781
|
+
...options.tools?.length || options.serverTools?.length || options.webSearch ? (() => {
|
|
782
|
+
const reservedServerNames = /* @__PURE__ */ new Set();
|
|
783
|
+
if (options.webSearch) reservedServerNames.add("web_search");
|
|
784
|
+
for (const t of options.serverTools ?? []) {
|
|
785
|
+
const name = t.name;
|
|
786
|
+
if (name) reservedServerNames.add(name);
|
|
787
|
+
}
|
|
788
|
+
const clientTools = options.tools?.length ? toAnthropicTools(
|
|
789
|
+
options.tools.filter((t) => !reservedServerNames.has(t.name)),
|
|
790
|
+
{
|
|
788
791
|
...supportsFirstPartyToolExtras && cacheControl ? { cacheControl } : {},
|
|
789
792
|
...supportsFirstPartyToolExtras ? { enableFineGrainedToolStreaming: true } : {}
|
|
790
|
-
}
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
793
|
+
}
|
|
794
|
+
) : [];
|
|
795
|
+
return {
|
|
796
|
+
tools: [
|
|
797
|
+
...clientTools,
|
|
798
|
+
...options.serverTools ?? [],
|
|
799
|
+
...options.webSearch ? [{ type: "web_search_20250305", name: "web_search" }] : []
|
|
800
|
+
]
|
|
801
|
+
};
|
|
802
|
+
})() : {},
|
|
795
803
|
...options.toolChoice && options.tools?.length ? { tool_choice: toAnthropicToolChoice(options.toolChoice) } : {},
|
|
796
804
|
...(() => {
|
|
797
805
|
const contextEdits = [
|
|
@@ -876,7 +884,11 @@ async function* runStream(options) {
|
|
|
876
884
|
accum.raw = block;
|
|
877
885
|
}
|
|
878
886
|
blocks.set(idx, accum);
|
|
879
|
-
|
|
887
|
+
if (block.type === "thinking") {
|
|
888
|
+
yield { type: "thinking_delta", text: "" };
|
|
889
|
+
} else {
|
|
890
|
+
yield keepalive;
|
|
891
|
+
}
|
|
880
892
|
break;
|
|
881
893
|
}
|
|
882
894
|
case "content_block_delta": {
|
|
@@ -1442,6 +1454,17 @@ function toError2(err, provider = "openai") {
|
|
|
1442
1454
|
|
|
1443
1455
|
// src/providers/openai-codex.ts
|
|
1444
1456
|
import os from "os";
|
|
1457
|
+
|
|
1458
|
+
// src/utils/diag.ts
|
|
1459
|
+
var _diagFn = null;
|
|
1460
|
+
function setProviderDiagnostic(fn) {
|
|
1461
|
+
_diagFn = fn;
|
|
1462
|
+
}
|
|
1463
|
+
function providerDiag(phase, data) {
|
|
1464
|
+
_diagFn?.(phase, data);
|
|
1465
|
+
}
|
|
1466
|
+
|
|
1467
|
+
// src/providers/openai-codex.ts
|
|
1445
1468
|
var DEFAULT_BASE_URL = "https://chatgpt.com/backend-api";
|
|
1446
1469
|
function streamOpenAICodex(options) {
|
|
1447
1470
|
return new StreamResult(runStream3(options));
|
|
@@ -1500,9 +1523,13 @@ async function* runStream3(options) {
|
|
|
1500
1523
|
const requestId = parsed.requestId ?? response.headers.get("x-request-id") ?? response.headers.get("openai-request-id") ?? void 0;
|
|
1501
1524
|
let hint;
|
|
1502
1525
|
if (response.status === 400 && text.includes("not supported")) {
|
|
1503
|
-
|
|
1526
|
+
if (options.model === "gpt-5.5-pro") {
|
|
1527
|
+
hint = "Use gpt-5.5 instead. OpenAI's Codex model catalog does not list gpt-5.5-pro.";
|
|
1528
|
+
} else {
|
|
1529
|
+
hint = "This model is not available through Codex for the authenticated account. Run /model and choose a model listed for OpenAI Codex, or check your Codex model picker/usage limits.";
|
|
1530
|
+
}
|
|
1504
1531
|
} else if (response.status === 404 && text.includes("does not exist")) {
|
|
1505
|
-
hint = "
|
|
1532
|
+
hint = "This model is not in the current OpenAI Codex catalog for this account. Try gpt-5.5, gpt-5.4, gpt-5.4-mini, or gpt-5.3-codex.";
|
|
1506
1533
|
}
|
|
1507
1534
|
throw new ProviderError("openai", message, {
|
|
1508
1535
|
statusCode: response.status,
|
|
@@ -1519,9 +1546,15 @@ async function* runStream3(options) {
|
|
|
1519
1546
|
let inputTokens = 0;
|
|
1520
1547
|
let outputTokens = 0;
|
|
1521
1548
|
let cacheRead = 0;
|
|
1549
|
+
const diagStart = Date.now();
|
|
1550
|
+
const diagSeen = /* @__PURE__ */ new Set();
|
|
1522
1551
|
for await (const event of parseSSE(response.body)) {
|
|
1523
1552
|
const type = event.type;
|
|
1524
1553
|
if (!type) continue;
|
|
1554
|
+
if (!diagSeen.has(type)) {
|
|
1555
|
+
diagSeen.add(type);
|
|
1556
|
+
providerDiag("codex_event_first", { type, sinceStartMs: Date.now() - diagStart });
|
|
1557
|
+
}
|
|
1525
1558
|
if (type === "error") {
|
|
1526
1559
|
const nested = event.error ?? void 0;
|
|
1527
1560
|
const message = nested?.message ?? event.message ?? "Codex stream emitted an error chunk without a message.";
|
|
@@ -1549,6 +1582,12 @@ async function* runStream3(options) {
|
|
|
1549
1582
|
const delta = event.delta;
|
|
1550
1583
|
yield { type: "thinking_delta", text: delta };
|
|
1551
1584
|
}
|
|
1585
|
+
if (type === "response.output_item.added") {
|
|
1586
|
+
const item = event.item;
|
|
1587
|
+
if (item?.type === "reasoning") {
|
|
1588
|
+
yield { type: "thinking_delta", text: "" };
|
|
1589
|
+
}
|
|
1590
|
+
}
|
|
1552
1591
|
if (type === "response.output_item.added") {
|
|
1553
1592
|
const item = event.item;
|
|
1554
1593
|
if (item?.type === "function_call") {
|
|
@@ -2068,6 +2107,7 @@ export {
|
|
|
2068
2107
|
palsuToolCall,
|
|
2069
2108
|
providerRegistry,
|
|
2070
2109
|
registerPalsuProvider,
|
|
2110
|
+
setProviderDiagnostic,
|
|
2071
2111
|
stream
|
|
2072
2112
|
};
|
|
2073
2113
|
//# sourceMappingURL=index.js.map
|