@opencow-ai/opencow-agent-sdk 0.4.4 → 0.4.6
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/cli.mjs +232 -221
- package/dist/client.js +207 -196
- package/dist/lib/schemaSanitizer.d.ts +43 -0
- package/dist/lib/toolInputNullCoercion.d.ts +7 -4
- package/dist/providers/codex/shim.d.ts +1 -1
- package/dist/providers/openai/schema.d.ts +1 -1
- package/dist/providers/openai/wire.d.ts +1 -1
- package/dist/sdk.js +207 -196
- package/package.json +1 -1
|
@@ -40,3 +40,46 @@ export declare function splitTypeArrayToAnyOf(schema: Record<string, unknown>):
|
|
|
40
40
|
* keywords while keeping enum/const cleanup defensive for imperfect MCP schemas.
|
|
41
41
|
*/
|
|
42
42
|
export declare function sanitizeSchemaForOpenAICompat(schema: unknown): Record<string, unknown>;
|
|
43
|
+
/**
|
|
44
|
+
* 「Anthropic 工具 schema → 严格 / Gemini 安全 schema」的统一规整入口。
|
|
45
|
+
*
|
|
46
|
+
* 历史上 chat_completions 路径(openai shim 的 normalizeSchemaForOpenAI)与 Responses
|
|
47
|
+
* 路径(codex shim 的 enforceStrictSchema)各自维护了一份几乎相同的递归实现,Gemini
|
|
48
|
+
* 适配(issue #79/#77、Vertex 400)需要在两处手工同步——典型的「两份会逐渐发散的拷贝」。
|
|
49
|
+
* 这里收敛为单一数据源:递归骨架只此一份,两条路径的差异通过 options 显式表达。
|
|
50
|
+
*
|
|
51
|
+
* 组合的原子能力:
|
|
52
|
+
* - {@link sanitizeSchemaForOpenAICompat}:剥离 provider 不接受的关键字、清洗 enum/const
|
|
53
|
+
* - {@link splitTypeArrayToAnyOf}(仅 gemini):type 数组 → {type, nullable:true}
|
|
54
|
+
* - {@link makeSchemaNullable}:strict 下被强制 required 的「原本可选」字段标可空
|
|
55
|
+
*/
|
|
56
|
+
export interface StrictifyJsonSchemaOptions {
|
|
57
|
+
/**
|
|
58
|
+
* 目标为 Gemini/Vertex。拆 type 数组、可空字段用 nullable:true 而非 type:[T,"null"]
|
|
59
|
+
* (Gemini strict 唯一接受的可空写法)。默认 false(OpenAI/Codex/DeepSeek/Kimi…)。
|
|
60
|
+
*/
|
|
61
|
+
gemini?: boolean;
|
|
62
|
+
/**
|
|
63
|
+
* strict 结构化输出(默认 true):每个属性强制并入 required、对象补
|
|
64
|
+
* additionalProperties:false、顶层「原本可选」字段标可空。设 false(如
|
|
65
|
+
* CLAUDE_CODE_USE_GEMINI 原生路径)则保留原始 required、不强制 additionalProperties、
|
|
66
|
+
* 不加可空。
|
|
67
|
+
*/
|
|
68
|
+
strict?: boolean;
|
|
69
|
+
/**
|
|
70
|
+
* 删除 `format:"uri"`(Codex Responses 拒绝该 format,URL 校验留在工具层)。默认 false。
|
|
71
|
+
*/
|
|
72
|
+
stripUriFormat?: boolean;
|
|
73
|
+
/**
|
|
74
|
+
* 丢弃「规整后退化为空对象」的属性(strict 下 OpenAI/Codex 会静默剥离其 schema、再因
|
|
75
|
+
* 残留 required 报 mismatch;典型如 z.record() / AskUserQuestion.answers)。默认 false。
|
|
76
|
+
*/
|
|
77
|
+
dropEmptyObjectProperties?: boolean;
|
|
78
|
+
/**
|
|
79
|
+
* 对「`type:"object"` 但无 properties 键」的对象也补 additionalProperties:false +
|
|
80
|
+
* required:[](Codex Responses 要求每个对象都严格闭合)。chat 路径保持原样,避免改变
|
|
81
|
+
* 自由对象(freeform object)字段的既有行为。默认 false。
|
|
82
|
+
*/
|
|
83
|
+
normalizeBareObjects?: boolean;
|
|
84
|
+
}
|
|
85
|
+
export declare function strictifyJsonSchema(schema: unknown, options?: StrictifyJsonSchemaOptions): Record<string, unknown>;
|
|
@@ -3,18 +3,21 @@ import type { z } from 'zod/v4';
|
|
|
3
3
|
* 解析工具入参,并对 strict provider 把可选字段强制为 nullable 后模型回传的 `null`
|
|
4
4
|
* 做兜底还原。
|
|
5
5
|
*
|
|
6
|
-
* 背景:OpenAI/Codex strict 模式要求每个属性都出现在 `required`,可选字段会被
|
|
6
|
+
* 背景:OpenAI/Codex/DeepSeek 等 strict 模式要求每个属性都出现在 `required`,可选字段会被
|
|
7
7
|
* `makeSchemaNullable` 标成可空(见 lib/schemaSanitizer.ts),模型遂用 `null` 表达
|
|
8
8
|
* 「未提供」。但工具的 Zod inputSchema 多用 `.optional()`(不接受 `null`),若直接
|
|
9
9
|
* `safeParse` 会得到 InputValidationError —— 这正是「① 让 wire schema 可空」必须搭配的
|
|
10
10
|
* 入参侧兜底(issue #79/#77)。
|
|
11
11
|
*
|
|
12
|
-
* 策略:先按原始 schema 解析;仅当「解析失败 且
|
|
13
|
-
*
|
|
12
|
+
* 策略:先按原始 schema 解析;仅当「解析失败 且 入参任意层级含 null」时,递归去掉这些
|
|
13
|
+
* null 属性再解析一次,且只有重试成功才采用重试结果。由此:
|
|
14
14
|
* - 真正接受 null 的 `.nullable()` 字段:原始即可解析 → 不触发重试 → `null` 保留;
|
|
15
15
|
* - 与 null 无关的真实校验错误:去 null 后仍失败 → 返回原始错误,不掩盖;
|
|
16
16
|
* - 可选非空字段被强制塞入的 `null`:去掉后变缺省,`.optional()` 通过。
|
|
17
17
|
*
|
|
18
|
-
*
|
|
18
|
+
* 递归处理嵌套对象与数组元素——`human_form_input` 这类工具的可选字段藏在
|
|
19
|
+
* `variables[].min_value` 等数组元素内部,模型对不适用的字段(如文本框的数值范围)
|
|
20
|
+
* 习惯性回传 `null`,只剥顶层会漏掉它们、导致整个阻塞工具因校验失败被跳过(handler
|
|
21
|
+
* 不执行、不阻塞,对话直接溜到下一轮)。
|
|
19
22
|
*/
|
|
20
23
|
export declare function safeParseToolInputWithNullCoercion<T extends z.ZodType>(schema: T, input: unknown): ReturnType<T['safeParse']>;
|
|
@@ -115,7 +115,7 @@ export declare function convertToolsToResponsesTools(tools: Array<{
|
|
|
115
115
|
input_schema?: Record<string, unknown>;
|
|
116
116
|
type?: string;
|
|
117
117
|
[k: string]: unknown;
|
|
118
|
-
}
|
|
118
|
+
}>, model?: string): ResponsesTool[];
|
|
119
119
|
export declare function performCodexRequest(options: {
|
|
120
120
|
request: ResolvedProviderRequest;
|
|
121
121
|
credentials: ResolvedCodexCredentials;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { sanitizeSchemaForOpenAICompat, makeSchemaNullable, } from '../../lib/schemaSanitizer.js';
|
|
1
|
+
export { sanitizeSchemaForOpenAICompat, makeSchemaNullable, splitTypeArrayToAnyOf, strictifyJsonSchema, } from '../../lib/schemaSanitizer.js';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { AnthropicStreamEvent } from '../../providers/codex/shim.js';
|
|
2
2
|
import type { NormalizedRequest, NormalizedResponse, StreamEvent } from '../types.js';
|
|
3
3
|
export interface OpenAIWireContext {
|
|
4
4
|
/**
|