@x-otto/plugin-weather 0.1.0-alpha.4 → 0.1.0-alpha.5
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/package.json +3 -3
- package/plugin-dist/meta.json +1 -1
- package/plugin-dist/plugin.cjs +42 -13781
- package/src/schema.ts +44 -12
- package/plugin-dist/plugin.js +0 -13935
package/src/schema.ts
CHANGED
|
@@ -1,17 +1,49 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* schema.ts —— `get_weather` 工具参数 schema(`PluginTool.parameters` 只要求 `safeParse`
|
|
3
|
-
*
|
|
3
|
+
* 接口,见 @x-otto/plugin sdk.ts;不依赖 zod——zod 默认入口会把全部 47 个 locale 文件
|
|
4
|
+
* 打进 plugin.cjs(~500K),本 schema 仅一个字段,手写零依赖实现体积可砍 ~97%)。
|
|
5
|
+
* safeParse 返回 zod 兼容形状({ success, data?, error: { issues } }),行为与测试断言对齐。
|
|
6
|
+
* toJSONSchema 是模型侧序列化契约(provider toJsonSchema 无此方法时退化为 {},模型
|
|
7
|
+
* 将看不到参数——2026-08-13 终局复核发现的回归,务必与 safeParse 成对维护)。
|
|
4
8
|
*/
|
|
5
|
-
import { z } from 'zod'
|
|
6
9
|
|
|
7
|
-
export
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
city: z
|
|
11
|
-
.string()
|
|
12
|
-
.min(1)
|
|
13
|
-
.max(200)
|
|
14
|
-
.describe('City name to look up weather for, e.g. "Beijing" or "Tokyo"'),
|
|
15
|
-
})
|
|
10
|
+
export interface WeatherToolParams {
|
|
11
|
+
city: string
|
|
12
|
+
}
|
|
16
13
|
|
|
17
|
-
export
|
|
14
|
+
export const weatherToolParamsSchema = {
|
|
15
|
+
safeParse(input: unknown): { success: true; data: WeatherToolParams } | { success: false; error: { issues: { path: string[]; message: string }[] } } {
|
|
16
|
+
if (typeof input !== 'object' || input === null) {
|
|
17
|
+
return { success: false, error: { issues: [{ path: [], message: 'Expected object, received non-object' }] } }
|
|
18
|
+
}
|
|
19
|
+
const record = input as Record<string, unknown>
|
|
20
|
+
const city = record.city
|
|
21
|
+
if (typeof city !== 'string') {
|
|
22
|
+
return { success: false, error: { issues: [{ path: ['city'], message: `Expected string, received ${typeof city}` }] } }
|
|
23
|
+
}
|
|
24
|
+
if (city.length < 1) {
|
|
25
|
+
return { success: false, error: { issues: [{ path: ['city'], message: 'String must contain at least 1 character(s)' }] } }
|
|
26
|
+
}
|
|
27
|
+
// max(200):真实城市名远短于此(已知最长地名约 85 字符),上限只为防御纵深——
|
|
28
|
+
// 拦截异常/失控模型输出的超长字符串直接拼进 geocoding 请求 URL(独立审核 R3 发现)。
|
|
29
|
+
if (city.length > 200) {
|
|
30
|
+
return { success: false, error: { issues: [{ path: ['city'], message: 'String must contain at most 200 character(s)' }] } }
|
|
31
|
+
}
|
|
32
|
+
return { success: true, data: { city } }
|
|
33
|
+
},
|
|
34
|
+
toJSONSchema(): Record<string, unknown> {
|
|
35
|
+
return {
|
|
36
|
+
type: 'object',
|
|
37
|
+
properties: {
|
|
38
|
+
city: {
|
|
39
|
+
type: 'string',
|
|
40
|
+
minLength: 1,
|
|
41
|
+
maxLength: 200,
|
|
42
|
+
description: 'City name to look up weather for, e.g. "Beijing" or "Tokyo"',
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
required: ['city'],
|
|
46
|
+
additionalProperties: false,
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
}
|