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.
@@ -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
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-line-bot",
3
- "version": "0.2.2",
3
+ "version": "0.4.0",
4
4
  "description": "把 LINE 官方帳號(Messaging API)接進 DeepSeek Harness 的插件:內建 Cloudflare Tunnel、人設選擇(大肥魚或插件自訂)、主動傳訊與完整設定面板。",
5
5
  "type": "module",
6
6
  "main": "index.js",