dsh-line-bot 0.2.2 → 0.4.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/CHANGELOG.md +18 -0
- package/README.en.md +23 -0
- package/README.ja.md +23 -0
- package/README.ko.md +23 -0
- package/README.md +23 -0
- package/README.zh-CN.md +23 -0
- package/bin/cli.mjs +53 -14
- package/client.js +231 -15
- package/lib/agent-runner.mjs +14 -3
- package/lib/config.mjs +21 -0
- package/lib/host.mjs +261 -12
- package/lib/memory.mjs +209 -0
- package/lib/tieba-sync.mjs +19 -11
- package/lib/toolkit.mjs +42 -0
- package/package.json +1 -1
package/lib/toolkit.mjs
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
// 把工具定義補成宿主要求的形狀(output schema + render),並把參數映射轉成 JSON Schema。
|
|
2
|
+
// 做法與 dsh-tieba-dive 的 lib/toolkit.mjs 相同:宿主有 dsh-tools 就用它的 defineTool,
|
|
3
|
+
// 沒有就自己補;這樣外掛不必把 dsh-tools 宣告成依賴。
|
|
4
|
+
let base = (spec) => spec
|
|
5
|
+
let usingHost = false
|
|
6
|
+
|
|
7
|
+
try {
|
|
8
|
+
const mod = await import('dsh-tools')
|
|
9
|
+
if (typeof mod.defineTool === 'function') {
|
|
10
|
+
base = mod.defineTool
|
|
11
|
+
usingHost = true
|
|
12
|
+
}
|
|
13
|
+
} catch {
|
|
14
|
+
/* 宿主沒給,用本地兜底 */
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export const textOutput = {
|
|
18
|
+
schema: { type: 'object', properties: {}, additionalProperties: true },
|
|
19
|
+
render: (_args, value) => [{
|
|
20
|
+
type: 'text',
|
|
21
|
+
text: typeof value === 'string' ? value : JSON.stringify(value, null, 2),
|
|
22
|
+
}],
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function toJsonSchema(params) {
|
|
26
|
+
if (!params) return { type: 'object', properties: {}, required: [] }
|
|
27
|
+
if (params.type === 'object') return params
|
|
28
|
+
const properties = {}
|
|
29
|
+
const required = []
|
|
30
|
+
for (const [key, value] of Object.entries(params)) {
|
|
31
|
+
if (!value || typeof value !== 'object') continue
|
|
32
|
+
const { required: isRequired, ...schema } = value
|
|
33
|
+
properties[key] = schema
|
|
34
|
+
if (isRequired === true) required.push(key)
|
|
35
|
+
}
|
|
36
|
+
return { type: 'object', properties, required, additionalProperties: false }
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function defineTool(spec) {
|
|
40
|
+
if (usingHost) return base({ output: textOutput, ...spec })
|
|
41
|
+
return base({ output: textOutput, ...spec, parameters: toJsonSchema(spec.parameters) })
|
|
42
|
+
}
|