@prestyj/ai 5.12.0 → 5.13.0
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/README.md +1 -1
- package/dist/index.cjs +10 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +42 -1
- package/dist/index.d.ts +42 -1
- package/dist/index.js +9 -0
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -530,6 +530,47 @@ type ProviderDiagnosticFn = (phase: string, data?: Record<string, unknown>) => v
|
|
|
530
530
|
/** Register a diagnostic callback for provider-level tracing. */
|
|
531
531
|
declare function setProviderDiagnostic(fn: ProviderDiagnosticFn | null): void;
|
|
532
532
|
|
|
533
|
+
/**
|
|
534
|
+
* Converts a Zod schema to a JSON Schema object suitable for provider tool
|
|
535
|
+
* parameter definitions.
|
|
536
|
+
*
|
|
537
|
+
* Anthropic's `input_schema` validator is strict in two ways:
|
|
538
|
+
*
|
|
539
|
+
* 1. The root must be `type: "object"`. Returns 400 with
|
|
540
|
+
* `tools.N.custom.input_schema.type: Field required` otherwise.
|
|
541
|
+
*
|
|
542
|
+
* 2. The root must NOT contain `oneOf`, `anyOf`, or `allOf`. Returns 400 with
|
|
543
|
+
* `input_schema does not support oneOf, allOf, or anyOf at the top level`.
|
|
544
|
+
*
|
|
545
|
+
* Both rules trip whenever a tool's parameters are defined via
|
|
546
|
+
* `z.discriminatedUnion(...)` or `z.union(...)` — Zod 4's
|
|
547
|
+
* `z.toJSONSchema` emits `{oneOf: [...]}` at the root with no `type`.
|
|
548
|
+
*
|
|
549
|
+
* The fix is to collapse the union into a single flat object schema:
|
|
550
|
+
*
|
|
551
|
+
* - properties = union of all branch properties (later branches win on
|
|
552
|
+
* conflict; that's fine because the model only uses these for hints —
|
|
553
|
+
* Zod's actual `tool.parameters.parse(args)` is the real validator)
|
|
554
|
+
* - required = intersection of branch `required` arrays (a field is only
|
|
555
|
+
* required if EVERY branch requires it)
|
|
556
|
+
* - if the union has a discriminator field (every branch has the same
|
|
557
|
+
* property as a `const`), we replace the discriminator's per-branch
|
|
558
|
+
* `const` with an `enum` listing every literal — the model gets a clear
|
|
559
|
+
* hint of the valid action values without needing oneOf
|
|
560
|
+
*
|
|
561
|
+
* The flattening is lossy for *schema-level* constraints (e.g. "if action=X,
|
|
562
|
+
* then field Y is required") — Zod still enforces those at parse time. For
|
|
563
|
+
* the model's purposes this is identical to a single object with optional
|
|
564
|
+
* fields and a discriminator enum, which is exactly how Anthropic-supported
|
|
565
|
+
* tools are typically authored anyway.
|
|
566
|
+
*/
|
|
567
|
+
type JsonSchema = Record<string, unknown>;
|
|
568
|
+
/**
|
|
569
|
+
* Resolve a tool's JSON Schema for provider tool definitions: prefer the
|
|
570
|
+
* tool's pre-built `rawInputSchema`, otherwise convert its Zod `parameters`.
|
|
571
|
+
*/
|
|
572
|
+
declare function resolveToolSchema(tool: Tool): JsonSchema;
|
|
573
|
+
|
|
533
574
|
/**
|
|
534
575
|
* Cap historical images before provider dispatch, removing the oldest first.
|
|
535
576
|
* The persisted/live conversation is never mutated; only modified messages and
|
|
@@ -642,4 +683,4 @@ interface PalsuProviderConfig {
|
|
|
642
683
|
*/
|
|
643
684
|
declare function registerPalsuProvider(config?: PalsuProviderConfig): PalsuProviderHandle;
|
|
644
685
|
|
|
645
|
-
export { type AssistantMessage, type CacheRetention, type ContentPart, type DoneEvent, EZCoderAIError, type ErrorEvent, type ErrorSource, EventStream, type FormattedError, type ImageContent, type Message, type MessageProvenance, type MessageProvenanceKind, type MessageProvenanceSource, type MessageProvenanceVisibility, type PalsuModelConfig, type PalsuModelHandle, type PalsuProviderConfig, type PalsuProviderHandle, type PalsuProviderState, type PalsuResponse, type PalsuResponseFactory, type Provider, type ProviderDiagnosticFn, type ProviderEntry, ProviderError, type ProviderStreamFn, REDACTED as REDACTION_MARKER, type RawContent, type RedactionOptions, 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, type VideoContent, clampProviderContextImages, classifyProviderError, environmentSecrets, formatError, formatErrorForDisplay, hasLoneSurrogate, isHardBillingMessage, isUsageLimitError, localWireModelId, palsuAssistantMessage, palsuText, palsuThinking, palsuToolCall, prewarmAnthropicCache, providerRegistry, redactText, redactValue, registerPalsuProvider, sanitizeMessagesForWire, setProviderDiagnostic, sliceHead, sliceTail, stream, toAnthropicMessages, toOpenAIMessages, toWellFormedText };
|
|
686
|
+
export { type AssistantMessage, type CacheRetention, type ContentPart, type DoneEvent, EZCoderAIError, type ErrorEvent, type ErrorSource, EventStream, type FormattedError, type ImageContent, type Message, type MessageProvenance, type MessageProvenanceKind, type MessageProvenanceSource, type MessageProvenanceVisibility, type PalsuModelConfig, type PalsuModelHandle, type PalsuProviderConfig, type PalsuProviderHandle, type PalsuProviderState, type PalsuResponse, type PalsuResponseFactory, type Provider, type ProviderDiagnosticFn, type ProviderEntry, ProviderError, type ProviderStreamFn, REDACTED as REDACTION_MARKER, type RawContent, type RedactionOptions, 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, type VideoContent, clampProviderContextImages, classifyProviderError, environmentSecrets, formatError, formatErrorForDisplay, hasLoneSurrogate, isHardBillingMessage, isUsageLimitError, localWireModelId, palsuAssistantMessage, palsuText, palsuThinking, palsuToolCall, prewarmAnthropicCache, providerRegistry, redactText, redactValue, registerPalsuProvider, resolveToolSchema, sanitizeMessagesForWire, setProviderDiagnostic, sliceHead, sliceTail, stream, toAnthropicMessages, toOpenAIMessages, toWellFormedText };
|
package/dist/index.d.ts
CHANGED
|
@@ -530,6 +530,47 @@ type ProviderDiagnosticFn = (phase: string, data?: Record<string, unknown>) => v
|
|
|
530
530
|
/** Register a diagnostic callback for provider-level tracing. */
|
|
531
531
|
declare function setProviderDiagnostic(fn: ProviderDiagnosticFn | null): void;
|
|
532
532
|
|
|
533
|
+
/**
|
|
534
|
+
* Converts a Zod schema to a JSON Schema object suitable for provider tool
|
|
535
|
+
* parameter definitions.
|
|
536
|
+
*
|
|
537
|
+
* Anthropic's `input_schema` validator is strict in two ways:
|
|
538
|
+
*
|
|
539
|
+
* 1. The root must be `type: "object"`. Returns 400 with
|
|
540
|
+
* `tools.N.custom.input_schema.type: Field required` otherwise.
|
|
541
|
+
*
|
|
542
|
+
* 2. The root must NOT contain `oneOf`, `anyOf`, or `allOf`. Returns 400 with
|
|
543
|
+
* `input_schema does not support oneOf, allOf, or anyOf at the top level`.
|
|
544
|
+
*
|
|
545
|
+
* Both rules trip whenever a tool's parameters are defined via
|
|
546
|
+
* `z.discriminatedUnion(...)` or `z.union(...)` — Zod 4's
|
|
547
|
+
* `z.toJSONSchema` emits `{oneOf: [...]}` at the root with no `type`.
|
|
548
|
+
*
|
|
549
|
+
* The fix is to collapse the union into a single flat object schema:
|
|
550
|
+
*
|
|
551
|
+
* - properties = union of all branch properties (later branches win on
|
|
552
|
+
* conflict; that's fine because the model only uses these for hints —
|
|
553
|
+
* Zod's actual `tool.parameters.parse(args)` is the real validator)
|
|
554
|
+
* - required = intersection of branch `required` arrays (a field is only
|
|
555
|
+
* required if EVERY branch requires it)
|
|
556
|
+
* - if the union has a discriminator field (every branch has the same
|
|
557
|
+
* property as a `const`), we replace the discriminator's per-branch
|
|
558
|
+
* `const` with an `enum` listing every literal — the model gets a clear
|
|
559
|
+
* hint of the valid action values without needing oneOf
|
|
560
|
+
*
|
|
561
|
+
* The flattening is lossy for *schema-level* constraints (e.g. "if action=X,
|
|
562
|
+
* then field Y is required") — Zod still enforces those at parse time. For
|
|
563
|
+
* the model's purposes this is identical to a single object with optional
|
|
564
|
+
* fields and a discriminator enum, which is exactly how Anthropic-supported
|
|
565
|
+
* tools are typically authored anyway.
|
|
566
|
+
*/
|
|
567
|
+
type JsonSchema = Record<string, unknown>;
|
|
568
|
+
/**
|
|
569
|
+
* Resolve a tool's JSON Schema for provider tool definitions: prefer the
|
|
570
|
+
* tool's pre-built `rawInputSchema`, otherwise convert its Zod `parameters`.
|
|
571
|
+
*/
|
|
572
|
+
declare function resolveToolSchema(tool: Tool): JsonSchema;
|
|
573
|
+
|
|
533
574
|
/**
|
|
534
575
|
* Cap historical images before provider dispatch, removing the oldest first.
|
|
535
576
|
* The persisted/live conversation is never mutated; only modified messages and
|
|
@@ -642,4 +683,4 @@ interface PalsuProviderConfig {
|
|
|
642
683
|
*/
|
|
643
684
|
declare function registerPalsuProvider(config?: PalsuProviderConfig): PalsuProviderHandle;
|
|
644
685
|
|
|
645
|
-
export { type AssistantMessage, type CacheRetention, type ContentPart, type DoneEvent, EZCoderAIError, type ErrorEvent, type ErrorSource, EventStream, type FormattedError, type ImageContent, type Message, type MessageProvenance, type MessageProvenanceKind, type MessageProvenanceSource, type MessageProvenanceVisibility, type PalsuModelConfig, type PalsuModelHandle, type PalsuProviderConfig, type PalsuProviderHandle, type PalsuProviderState, type PalsuResponse, type PalsuResponseFactory, type Provider, type ProviderDiagnosticFn, type ProviderEntry, ProviderError, type ProviderStreamFn, REDACTED as REDACTION_MARKER, type RawContent, type RedactionOptions, 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, type VideoContent, clampProviderContextImages, classifyProviderError, environmentSecrets, formatError, formatErrorForDisplay, hasLoneSurrogate, isHardBillingMessage, isUsageLimitError, localWireModelId, palsuAssistantMessage, palsuText, palsuThinking, palsuToolCall, prewarmAnthropicCache, providerRegistry, redactText, redactValue, registerPalsuProvider, sanitizeMessagesForWire, setProviderDiagnostic, sliceHead, sliceTail, stream, toAnthropicMessages, toOpenAIMessages, toWellFormedText };
|
|
686
|
+
export { type AssistantMessage, type CacheRetention, type ContentPart, type DoneEvent, EZCoderAIError, type ErrorEvent, type ErrorSource, EventStream, type FormattedError, type ImageContent, type Message, type MessageProvenance, type MessageProvenanceKind, type MessageProvenanceSource, type MessageProvenanceVisibility, type PalsuModelConfig, type PalsuModelHandle, type PalsuProviderConfig, type PalsuProviderHandle, type PalsuProviderState, type PalsuResponse, type PalsuResponseFactory, type Provider, type ProviderDiagnosticFn, type ProviderEntry, ProviderError, type ProviderStreamFn, REDACTED as REDACTION_MARKER, type RawContent, type RedactionOptions, 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, type VideoContent, clampProviderContextImages, classifyProviderError, environmentSecrets, formatError, formatErrorForDisplay, hasLoneSurrogate, isHardBillingMessage, isUsageLimitError, localWireModelId, palsuAssistantMessage, palsuText, palsuThinking, palsuToolCall, prewarmAnthropicCache, providerRegistry, redactText, redactValue, registerPalsuProvider, resolveToolSchema, sanitizeMessagesForWire, setProviderDiagnostic, sliceHead, sliceTail, stream, toAnthropicMessages, toOpenAIMessages, toWellFormedText };
|
package/dist/index.js
CHANGED
|
@@ -1105,6 +1105,9 @@ function toLocalReasoningEffort(level) {
|
|
|
1105
1105
|
if (level === "max" || level === "ultra" || level === "xhigh") return "max";
|
|
1106
1106
|
return level;
|
|
1107
1107
|
}
|
|
1108
|
+
function toGlmReasoningEffort(level) {
|
|
1109
|
+
return level === "ultra" ? "max" : level;
|
|
1110
|
+
}
|
|
1108
1111
|
function toOpenAIReasoningEffort(level, model) {
|
|
1109
1112
|
const effort = level === "max" || level === "ultra" ? "xhigh" : level;
|
|
1110
1113
|
if (model.startsWith("fugu") && (effort === "low" || effort === "medium")) {
|
|
@@ -1974,6 +1977,11 @@ async function* runStream2(options) {
|
|
|
1974
1977
|
if (usesThinkingParam) {
|
|
1975
1978
|
if (options.thinking) {
|
|
1976
1979
|
params.thinking = { type: "enabled" };
|
|
1980
|
+
if (options.provider === "glm") {
|
|
1981
|
+
params.reasoning_effort = toGlmReasoningEffort(
|
|
1982
|
+
options.thinking
|
|
1983
|
+
);
|
|
1984
|
+
}
|
|
1977
1985
|
} else {
|
|
1978
1986
|
params.thinking = { type: "disabled" };
|
|
1979
1987
|
}
|
|
@@ -4162,6 +4170,7 @@ export {
|
|
|
4162
4170
|
redactText,
|
|
4163
4171
|
redactValue,
|
|
4164
4172
|
registerPalsuProvider,
|
|
4173
|
+
resolveToolSchema,
|
|
4165
4174
|
sanitizeMessagesForWire,
|
|
4166
4175
|
setProviderDiagnostic,
|
|
4167
4176
|
sliceHead,
|