@zhin.js/core 1.1.33 → 1.1.35
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 +140 -61
- package/lib/adapter.d.ts +72 -23
- package/lib/adapter.js +222 -58
- package/lib/built/adapter-process.d.ts +20 -5
- package/lib/built/adapter-process.js +54 -7
- package/lib/built/agent-preset.d.ts +1 -2
- package/lib/built/agent-preset.js +1 -2
- package/lib/built/ai-access.d.ts +36 -0
- package/lib/built/ai-access.js +46 -0
- package/lib/built/ai-outbound/adapter-access.d.ts +3 -0
- package/lib/built/ai-outbound/adapter-access.js +9 -0
- package/lib/built/ai-outbound/extensions/onebot-keyboard.d.ts +2 -0
- package/lib/built/ai-outbound/extensions/onebot-keyboard.js +67 -0
- package/lib/built/ai-outbound/extensions/qq-message.d.ts +3 -0
- package/lib/built/ai-outbound/extensions/qq-message.js +23 -0
- package/lib/built/ai-outbound/index.d.ts +9 -0
- package/lib/built/ai-outbound/index.js +9 -0
- package/lib/built/ai-outbound/parse.d.ts +13 -0
- package/lib/built/ai-outbound/parse.js +104 -0
- package/lib/built/ai-outbound/plain-mention-rewrite.d.ts +6 -0
- package/lib/built/ai-outbound/plain-mention-rewrite.js +37 -0
- package/lib/built/ai-outbound/prompt.d.ts +11 -0
- package/lib/built/ai-outbound/prompt.js +44 -0
- package/lib/built/ai-outbound/resolve.d.ts +4 -0
- package/lib/built/ai-outbound/resolve.js +64 -0
- package/lib/built/ai-outbound/structured-detect.d.ts +3 -0
- package/lib/built/ai-outbound/structured-detect.js +6 -0
- package/lib/built/ai-outbound/types.d.ts +58 -0
- package/lib/built/ai-outbound/types.js +5 -0
- package/lib/built/ai-trigger.d.ts +17 -17
- package/lib/built/ai-trigger.js +65 -70
- package/lib/built/authorization.d.ts +10 -0
- package/lib/built/authorization.js +76 -0
- package/lib/built/command.d.ts +9 -5
- package/lib/built/command.js +20 -7
- package/lib/built/common-adapter-tools.d.ts +35 -29
- package/lib/built/common-adapter-tools.js +83 -67
- package/lib/built/component.d.ts +1 -3
- package/lib/built/component.js +2 -4
- package/lib/built/config.d.ts +4 -5
- package/lib/built/config.js +26 -9
- package/lib/built/connect-endpoint-instance.d.ts +17 -0
- package/lib/built/connect-endpoint-instance.js +42 -0
- package/lib/built/database.d.ts +5 -3
- package/lib/built/database.js +10 -4
- package/lib/built/dispatcher.d.ts +10 -8
- package/lib/built/dispatcher.js +31 -9
- package/lib/built/endpoint-commands.d.ts +3 -0
- package/lib/built/endpoint-commands.js +99 -0
- package/lib/built/endpoint-lifecycle-service.d.ts +28 -0
- package/lib/built/endpoint-lifecycle-service.js +242 -0
- package/lib/built/endpoint-lifecycle.d.ts +27 -0
- package/lib/built/endpoint-lifecycle.js +36 -0
- package/lib/built/endpoint-manager.d.ts +34 -0
- package/lib/built/endpoint-manager.js +1 -0
- package/lib/built/generated-qrcode.d.ts +24 -0
- package/lib/built/generated-qrcode.js +45 -0
- package/lib/built/generic-segment-mapper.d.ts +4 -0
- package/lib/built/generic-segment-mapper.js +190 -0
- package/lib/built/html-renderer-loader.d.ts +13 -0
- package/lib/built/html-renderer-loader.js +33 -0
- package/lib/built/html-segment-fallback.d.ts +9 -0
- package/lib/built/html-segment-fallback.js +49 -0
- package/lib/built/html-to-text.d.ts +4 -1
- package/lib/built/html-to-text.js +47 -16
- package/lib/built/inbound-pipeline.d.ts +37 -0
- package/lib/built/inbound-pipeline.js +63 -0
- package/lib/built/inbound-runner.d.ts +0 -1
- package/lib/built/inbound-runner.js +0 -3
- package/lib/built/interactive-segment-contract.d.ts +6 -0
- package/lib/built/interactive-segment-contract.js +9 -0
- package/lib/built/interactive-segments/action.d.ts +17 -0
- package/lib/built/interactive-segments/action.js +69 -0
- package/lib/built/interactive-segments/button-spec.d.ts +10 -0
- package/lib/built/interactive-segments/button-spec.js +21 -0
- package/lib/built/interactive-segments/fallback-store.d.ts +29 -0
- package/lib/built/interactive-segments/fallback-store.js +63 -0
- package/lib/built/interactive-segments/handlers.d.ts +16 -0
- package/lib/built/interactive-segments/handlers.js +74 -0
- package/lib/built/interactive-segments/index.d.ts +8 -0
- package/lib/built/interactive-segments/index.js +8 -0
- package/lib/built/interactive-segments/keyboard-segment.d.ts +11 -0
- package/lib/built/interactive-segments/keyboard-segment.js +12 -0
- package/lib/built/interactive-segments/onebot-keyboard.d.ts +7 -0
- package/lib/built/interactive-segments/onebot-keyboard.js +51 -0
- package/lib/built/interactive-segments/resolve.d.ts +15 -0
- package/lib/built/interactive-segments/resolve.js +110 -0
- package/lib/built/interactive-segments/types.d.ts +50 -0
- package/lib/built/interactive-segments/types.js +9 -0
- package/lib/built/introspection-format.d.ts +10 -0
- package/lib/built/introspection-format.js +28 -0
- package/lib/built/login-assist.d.ts +43 -9
- package/lib/built/login-assist.js +113 -11
- package/lib/built/management-command-guard.d.ts +15 -0
- package/lib/built/management-command-guard.js +25 -0
- package/lib/built/message-enrich.d.ts +38 -0
- package/lib/built/message-enrich.js +75 -0
- package/lib/built/message-filter.d.ts +4 -5
- package/lib/built/message-filter.js +5 -7
- package/lib/built/optional-peer-import.d.ts +3 -0
- package/lib/built/optional-peer-import.js +33 -0
- package/lib/built/outbound-media-contract.d.ts +22 -0
- package/lib/built/outbound-media-contract.js +10 -0
- package/lib/built/outbound-media-utils.d.ts +9 -0
- package/lib/built/outbound-media-utils.js +62 -0
- package/lib/built/permission.d.ts +3 -7
- package/lib/built/permission.js +39 -52
- package/lib/built/permit-check.d.ts +7 -0
- package/lib/built/permit-check.js +35 -0
- package/lib/built/permit-parse.d.ts +16 -0
- package/lib/built/permit-parse.js +32 -0
- package/lib/built/platform-permit.d.ts +20 -0
- package/lib/built/platform-permit.js +91 -0
- package/lib/built/queue-im-field-contract.d.ts +7 -2
- package/lib/built/queue-im-field-contract.js +13 -4
- package/lib/built/rich-segments/adapter-policies.d.ts +9 -0
- package/lib/built/rich-segments/adapter-policies.js +27 -0
- package/lib/built/rich-segments/base.d.ts +11 -0
- package/lib/built/rich-segments/base.js +24 -0
- package/lib/built/rich-segments/builtins.d.ts +4 -0
- package/lib/built/rich-segments/builtins.js +40 -0
- package/lib/built/rich-segments/capabilities.d.ts +6 -0
- package/lib/built/rich-segments/capabilities.js +38 -0
- package/lib/built/rich-segments/html-segment.d.ts +15 -0
- package/lib/built/rich-segments/html-segment.js +62 -0
- package/lib/built/rich-segments/index.d.ts +13 -0
- package/lib/built/rich-segments/index.js +13 -0
- package/lib/built/rich-segments/markdown-segment.d.ts +14 -0
- package/lib/built/rich-segments/markdown-segment.js +58 -0
- package/lib/built/rich-segments/markdown-to-text.d.ts +3 -0
- package/lib/built/rich-segments/markdown-to-text.js +27 -0
- package/lib/built/rich-segments/qrcode-segment.d.ts +18 -0
- package/lib/built/rich-segments/qrcode-segment.js +73 -0
- package/lib/built/rich-segments/registry.d.ts +16 -0
- package/lib/built/rich-segments/registry.js +52 -0
- package/lib/built/rich-segments/resolve.d.ts +5 -0
- package/lib/built/rich-segments/resolve.js +87 -0
- package/lib/built/rich-segments/tts-segment.d.ts +13 -0
- package/lib/built/rich-segments/tts-segment.js +51 -0
- package/lib/built/rich-segments/types.d.ts +79 -0
- package/lib/built/rich-segments/types.js +17 -0
- package/lib/built/roles.d.ts +4 -5
- package/lib/built/roles.js +4 -5
- package/lib/built/runtime-io.d.ts +0 -1
- package/lib/built/runtime-io.js +0 -1
- package/lib/built/schedule.d.ts +54 -0
- package/lib/built/schedule.js +112 -0
- package/lib/built/schema-endpoint-manager.d.ts +17 -0
- package/lib/built/schema-endpoint-manager.js +73 -0
- package/lib/built/schema-feature.d.ts +0 -1
- package/lib/built/schema-feature.js +1 -3
- package/lib/built/segment-contract/assert.d.ts +7 -0
- package/lib/built/segment-contract/assert.js +39 -0
- package/lib/built/segment-contract/delivery.d.ts +5 -0
- package/lib/built/segment-contract/delivery.js +40 -0
- package/lib/built/segment-contract/image.d.ts +5 -0
- package/lib/built/segment-contract/image.js +10 -0
- package/lib/built/segment-contract/index.d.ts +10 -0
- package/lib/built/segment-contract/index.js +9 -0
- package/lib/built/segment-contract/json-schema.d.ts +28 -0
- package/lib/built/segment-contract/json-schema.js +128 -0
- package/lib/built/segment-contract/media.d.ts +12 -0
- package/lib/built/segment-contract/media.js +22 -0
- package/lib/built/segment-contract/mention.d.ts +10 -0
- package/lib/built/segment-contract/mention.js +26 -0
- package/lib/built/segment-contract/preview.d.ts +3 -0
- package/lib/built/segment-contract/preview.js +159 -0
- package/lib/built/segment-contract/text.d.ts +7 -0
- package/lib/built/segment-contract/text.js +34 -0
- package/lib/built/segment-contract/types.d.ts +58 -0
- package/lib/built/segment-contract/types.js +1 -0
- package/lib/built/segment-contract/validate.d.ts +229 -0
- package/lib/built/segment-contract/validate.js +174 -0
- package/lib/built/skill.d.ts +0 -1
- package/lib/built/skill.js +0 -1
- package/lib/built/speech-loader.d.ts +14 -0
- package/lib/built/speech-loader.js +32 -0
- package/lib/built/tool.d.ts +14 -13
- package/lib/built/tool.js +30 -25
- package/lib/built/user-interaction.d.ts +30 -0
- package/lib/built/user-interaction.js +248 -0
- package/lib/command.d.ts +19 -11
- package/lib/command.js +42 -11
- package/lib/component.d.ts +0 -1
- package/lib/component.js +67 -14
- package/lib/endpoint-capabilities.d.ts +46 -0
- package/lib/endpoint-capabilities.js +55 -0
- package/lib/endpoint.d.ts +19 -0
- package/lib/endpoint.js +3 -0
- package/lib/errors.d.ts +2 -3
- package/lib/errors.js +4 -5
- package/lib/feature/adapter.d.ts +2 -0
- package/lib/feature/adapter.js +2 -0
- package/lib/feature/command.d.ts +2 -0
- package/lib/feature/command.js +2 -0
- package/lib/feature/component.d.ts +2 -0
- package/lib/feature/component.js +2 -0
- package/lib/feature/handler.d.ts +52 -0
- package/lib/feature/handler.js +26 -0
- package/lib/feature/middleware.d.ts +2 -0
- package/lib/feature/middleware.js +2 -0
- package/lib/host-plugin-registry.d.ts +8 -0
- package/lib/host-plugin-registry.js +12 -0
- package/lib/im-scene.d.ts +29 -0
- package/lib/im-scene.js +75 -0
- package/lib/im-session-id.d.ts +39 -0
- package/lib/im-session-id.js +47 -0
- package/lib/index.d.ts +59 -21
- package/lib/index.js +53 -28
- package/lib/jsx-dev-runtime.d.ts +0 -1
- package/lib/jsx-dev-runtime.js +0 -1
- package/lib/jsx-runtime.d.ts +1 -1
- package/lib/jsx-runtime.js +0 -1
- package/lib/jsx.d.ts +19 -22
- package/lib/jsx.js +0 -1
- package/lib/message.d.ts +16 -10
- package/lib/message.js +16 -13
- package/lib/models/system-log.d.ts +0 -1
- package/lib/models/system-log.js +0 -1
- package/lib/models/user.d.ts +0 -1
- package/lib/models/user.js +0 -1
- package/lib/notice.d.ts +16 -59
- package/lib/notice.js +1 -4
- package/lib/plugin-context.d.ts +27 -0
- package/lib/plugin-context.js +64 -0
- package/lib/plugin-runtime/im/contracts.d.ts +191 -0
- package/lib/plugin-runtime/im/contracts.js +169 -0
- package/lib/plugin-runtime/im/im-runtime.d.ts +177 -0
- package/lib/plugin-runtime/im/im-runtime.js +1204 -0
- package/lib/plugin-runtime/im/index.d.ts +9 -0
- package/lib/plugin-runtime/im/index.js +9 -0
- package/lib/plugin-runtime/im/interactive.d.ts +26 -0
- package/lib/plugin-runtime/im/interactive.js +46 -0
- package/lib/plugin-runtime/im/login-assist-host.d.ts +6 -0
- package/lib/plugin-runtime/im/login-assist-host.js +6 -0
- package/lib/plugin-runtime/im/message-bus.d.ts +38 -0
- package/lib/plugin-runtime/im/message-bus.js +40 -0
- package/lib/plugin-runtime/im/message-dispatcher.d.ts +18 -0
- package/lib/plugin-runtime/im/message-dispatcher.js +107 -0
- package/lib/plugin-runtime/im/outbound-renderer.d.ts +7 -0
- package/lib/plugin-runtime/im/outbound-renderer.js +70 -0
- package/lib/plugin-runtime/im/outbound-segments.d.ts +72 -0
- package/lib/plugin-runtime/im/outbound-segments.js +220 -0
- package/lib/plugin-runtime/im/public-api.d.ts +6 -0
- package/lib/plugin-runtime/im/public-api.js +6 -0
- package/lib/plugin-runtime/im/service-tokens.d.ts +18 -0
- package/lib/plugin-runtime/im/service-tokens.js +13 -0
- package/lib/plugin.d.ts +34 -24
- package/lib/plugin.js +119 -224
- package/lib/request.d.ts +17 -61
- package/lib/request.js +0 -4
- package/lib/{prompt.d.ts → schema-interaction.d.ts} +6 -7
- package/lib/{prompt.js → schema-interaction.js} +20 -17
- package/lib/side-event/base.d.ts +52 -0
- package/lib/side-event/base.js +30 -0
- package/lib/side-event/dispatch.d.ts +15 -0
- package/lib/side-event/dispatch.js +140 -0
- package/lib/side-event/index.d.ts +4 -0
- package/lib/side-event/index.js +4 -0
- package/lib/side-event/normalize.d.ts +42 -0
- package/lib/side-event/normalize.js +121 -0
- package/lib/side-event/types.d.ts +23 -0
- package/lib/side-event/types.js +55 -0
- package/lib/system-event.d.ts +15 -0
- package/lib/system-event.js +7 -0
- package/lib/tool-zod.d.ts +18 -3
- package/lib/tool-zod.js +140 -54
- package/lib/types.d.ts +44 -85
- package/lib/types.js +0 -1
- package/lib/utils.d.ts +68 -1
- package/lib/utils.js +73 -11
- package/package.json +98 -10
- package/lib/adapter.d.ts.map +0 -1
- package/lib/adapter.js.map +0 -1
- package/lib/agent-prompt.d.ts +0 -37
- package/lib/agent-prompt.d.ts.map +0 -1
- package/lib/agent-prompt.js +0 -2
- package/lib/agent-prompt.js.map +0 -1
- package/lib/bot.d.ts +0 -38
- package/lib/bot.d.ts.map +0 -1
- package/lib/bot.js +0 -2
- package/lib/bot.js.map +0 -1
- package/lib/built/adapter-process.d.ts.map +0 -1
- package/lib/built/adapter-process.js.map +0 -1
- package/lib/built/agent-preset.d.ts.map +0 -1
- package/lib/built/agent-preset.js.map +0 -1
- package/lib/built/ai-trigger.d.ts.map +0 -1
- package/lib/built/ai-trigger.js.map +0 -1
- package/lib/built/command.d.ts.map +0 -1
- package/lib/built/command.js.map +0 -1
- package/lib/built/common-adapter-tools.d.ts.map +0 -1
- package/lib/built/common-adapter-tools.js.map +0 -1
- package/lib/built/component.d.ts.map +0 -1
- package/lib/built/component.js.map +0 -1
- package/lib/built/config.d.ts.map +0 -1
- package/lib/built/config.js.map +0 -1
- package/lib/built/cron.d.ts +0 -75
- package/lib/built/cron.d.ts.map +0 -1
- package/lib/built/cron.js +0 -122
- package/lib/built/cron.js.map +0 -1
- package/lib/built/database.d.ts.map +0 -1
- package/lib/built/database.js.map +0 -1
- package/lib/built/dispatcher.d.ts.map +0 -1
- package/lib/built/dispatcher.js.map +0 -1
- package/lib/built/html-to-text.d.ts.map +0 -1
- package/lib/built/html-to-text.js.map +0 -1
- package/lib/built/inbound-runner.d.ts.map +0 -1
- package/lib/built/inbound-runner.js.map +0 -1
- package/lib/built/login-assist.d.ts.map +0 -1
- package/lib/built/login-assist.js.map +0 -1
- package/lib/built/message-filter.d.ts.map +0 -1
- package/lib/built/message-filter.js.map +0 -1
- package/lib/built/permission.d.ts.map +0 -1
- package/lib/built/permission.js.map +0 -1
- package/lib/built/prepend-quote-context.d.ts +0 -33
- package/lib/built/prepend-quote-context.d.ts.map +0 -1
- package/lib/built/prepend-quote-context.js +0 -129
- package/lib/built/prepend-quote-context.js.map +0 -1
- package/lib/built/queue-im-field-contract.d.ts.map +0 -1
- package/lib/built/queue-im-field-contract.js.map +0 -1
- package/lib/built/roles.d.ts.map +0 -1
- package/lib/built/roles.js.map +0 -1
- package/lib/built/runtime-io.d.ts.map +0 -1
- package/lib/built/runtime-io.js.map +0 -1
- package/lib/built/schema-feature.d.ts.map +0 -1
- package/lib/built/schema-feature.js.map +0 -1
- package/lib/built/skill.d.ts.map +0 -1
- package/lib/built/skill.js.map +0 -1
- package/lib/built/tool.d.ts.map +0 -1
- package/lib/built/tool.js.map +0 -1
- package/lib/command.d.ts.map +0 -1
- package/lib/command.js.map +0 -1
- package/lib/component.d.ts.map +0 -1
- package/lib/component.js.map +0 -1
- package/lib/errors.d.ts.map +0 -1
- package/lib/errors.js.map +0 -1
- package/lib/index.d.ts.map +0 -1
- package/lib/index.js.map +0 -1
- package/lib/jsx-dev-runtime.d.ts.map +0 -1
- package/lib/jsx-dev-runtime.js.map +0 -1
- package/lib/jsx-runtime.d.ts.map +0 -1
- package/lib/jsx-runtime.js.map +0 -1
- package/lib/jsx.d.ts.map +0 -1
- package/lib/jsx.js.map +0 -1
- package/lib/message-quote.d.ts +0 -11
- package/lib/message-quote.d.ts.map +0 -1
- package/lib/message-quote.js +0 -91
- package/lib/message-quote.js.map +0 -1
- package/lib/message.d.ts.map +0 -1
- package/lib/message.js.map +0 -1
- package/lib/models/system-log.d.ts.map +0 -1
- package/lib/models/system-log.js.map +0 -1
- package/lib/models/user.d.ts.map +0 -1
- package/lib/models/user.js.map +0 -1
- package/lib/notice.d.ts.map +0 -1
- package/lib/notice.js.map +0 -1
- package/lib/plugin.d.ts.map +0 -1
- package/lib/plugin.js.map +0 -1
- package/lib/prompt.d.ts.map +0 -1
- package/lib/prompt.js.map +0 -1
- package/lib/request.d.ts.map +0 -1
- package/lib/request.js.map +0 -1
- package/lib/scheduler/scheduler.d.ts +0 -49
- package/lib/scheduler/scheduler.d.ts.map +0 -1
- package/lib/scheduler/scheduler.js +0 -352
- package/lib/scheduler/scheduler.js.map +0 -1
- package/lib/scheduler/types.d.ts +0 -71
- package/lib/scheduler/types.d.ts.map +0 -1
- package/lib/scheduler/types.js +0 -8
- package/lib/scheduler/types.js.map +0 -1
- package/lib/tool-zod.d.ts.map +0 -1
- package/lib/tool-zod.js.map +0 -1
- package/lib/types-generator.d.ts +0 -6
- package/lib/types-generator.d.ts.map +0 -1
- package/lib/types-generator.js +0 -72
- package/lib/types-generator.js.map +0 -1
- package/lib/types.d.ts.map +0 -1
- package/lib/types.js.map +0 -1
- package/lib/utils.d.ts.map +0 -1
- package/lib/utils.js.map +0 -1
package/lib/tool-zod.d.ts
CHANGED
|
@@ -10,8 +10,24 @@
|
|
|
10
10
|
* const tool = createToolFromZod('my_tool', '描述', z.object({ id: z.string() }), async (args) => { ... });
|
|
11
11
|
* plugin.addTool(tool);
|
|
12
12
|
*/
|
|
13
|
-
import type { Tool,
|
|
13
|
+
import type { Tool, ToolParametersSchema } from './types.js';
|
|
14
|
+
import type { Message } from './message.js';
|
|
14
15
|
type MaybePromise<T> = T | Promise<T>;
|
|
16
|
+
export type ToolSchemaParseResult<T> = {
|
|
17
|
+
ok: true;
|
|
18
|
+
data: T;
|
|
19
|
+
} | {
|
|
20
|
+
ok: false;
|
|
21
|
+
error: string;
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Normalize a JSON Schema or Zod object schema into the canonical Core tool
|
|
25
|
+
* parameter schema. Zod remains an optional peer: this adapter uses only its
|
|
26
|
+
* public instance methods and retains a structural fallback for Zod 3.
|
|
27
|
+
*/
|
|
28
|
+
export declare function toolInputSchemaToParameters(schema: unknown): ToolParametersSchema;
|
|
29
|
+
/** Validate input with a Zod-like schema, or pass it through for JSON Schema. */
|
|
30
|
+
export declare function parseToolInputSchema<T>(schema: unknown, input: unknown): ToolSchemaParseResult<T>;
|
|
15
31
|
export interface CreateToolFromZodOptions {
|
|
16
32
|
tags?: string[];
|
|
17
33
|
keywords?: string[];
|
|
@@ -23,6 +39,5 @@ export interface CreateToolFromZodOptions {
|
|
|
23
39
|
* 从 Zod 模式创建 Tool,便于类型安全与校验。
|
|
24
40
|
* 需要安装 zod:pnpm add zod。传入的 schema 应为 z.object({ ... })。
|
|
25
41
|
*/
|
|
26
|
-
export declare function createToolFromZod<T extends Record<string, any>>(name: string, description: string, schema: any, execute: (args: T,
|
|
42
|
+
export declare function createToolFromZod<T extends Record<string, any>>(name: string, description: string, schema: any, execute: (args: T, message?: Message<any>) => MaybePromise<any>, options?: CreateToolFromZodOptions): Tool;
|
|
27
43
|
export {};
|
|
28
|
-
//# sourceMappingURL=tool-zod.d.ts.map
|
package/lib/tool-zod.js
CHANGED
|
@@ -10,62 +10,151 @@
|
|
|
10
10
|
* const tool = createToolFromZod('my_tool', '描述', z.object({ id: z.string() }), async (args) => { ... });
|
|
11
11
|
* plugin.addTool(tool);
|
|
12
12
|
*/
|
|
13
|
-
function
|
|
14
|
-
|
|
13
|
+
function isRecord(value) {
|
|
14
|
+
return value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
15
|
+
}
|
|
16
|
+
function getShape(schema) {
|
|
17
|
+
const shape = schema?.shape;
|
|
18
|
+
if (typeof shape === 'function') {
|
|
19
|
+
const value = shape();
|
|
20
|
+
return isRecord(value) ? value : undefined;
|
|
21
|
+
}
|
|
22
|
+
return isRecord(shape) ? shape : undefined;
|
|
23
|
+
}
|
|
24
|
+
function acceptsUndefined(schema) {
|
|
25
|
+
const candidate = schema;
|
|
26
|
+
if (typeof candidate?.safeParse === 'function') {
|
|
27
|
+
try {
|
|
28
|
+
return candidate.safeParse(undefined).success;
|
|
29
|
+
}
|
|
30
|
+
catch {
|
|
31
|
+
// Fall through to structural compatibility for non-Zod lookalikes.
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
const def = candidate?._def;
|
|
35
|
+
const kind = def?.typeName ?? def?.type;
|
|
36
|
+
return kind === 'ZodOptional'
|
|
37
|
+
|| kind === 'ZodDefault'
|
|
38
|
+
|| kind === 'optional'
|
|
39
|
+
|| kind === 'default';
|
|
40
|
+
}
|
|
41
|
+
function requiredFromShape(schema, fallback) {
|
|
42
|
+
const shape = getShape(schema);
|
|
43
|
+
if (!shape)
|
|
44
|
+
return fallback?.length ? [...fallback] : undefined;
|
|
45
|
+
const required = Object.entries(shape)
|
|
46
|
+
.filter(([, field]) => !acceptsUndefined(field))
|
|
47
|
+
.map(([key]) => key);
|
|
48
|
+
return required.length ? required : undefined;
|
|
49
|
+
}
|
|
50
|
+
function descriptionOf(schema, def) {
|
|
51
|
+
const description = schema?.description ?? def.description;
|
|
52
|
+
return typeof description === 'string' ? description : undefined;
|
|
53
|
+
}
|
|
54
|
+
function zodFieldToJsonSchema(schema) {
|
|
55
|
+
const candidate = schema;
|
|
56
|
+
const def = candidate?._def;
|
|
57
|
+
if (!isRecord(def))
|
|
15
58
|
return { type: 'string' };
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
const inner = def.innerType ?? def.type;
|
|
20
|
-
return zodFieldToJsonSchema(inner);
|
|
59
|
+
const kind = def.typeName ?? def.type;
|
|
60
|
+
if (kind === 'ZodOptional' || kind === 'ZodDefault' || kind === 'optional' || kind === 'default') {
|
|
61
|
+
return zodFieldToJsonSchema(def.innerType ?? def.type);
|
|
21
62
|
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
63
|
+
const description = descriptionOf(schema, def);
|
|
64
|
+
const withDescription = (type) => description
|
|
65
|
+
? { type, description }
|
|
66
|
+
: { type };
|
|
67
|
+
if (kind === 'ZodString' || kind === 'string')
|
|
68
|
+
return withDescription('string');
|
|
69
|
+
if (kind === 'ZodNumber' || kind === 'number')
|
|
70
|
+
return withDescription('number');
|
|
71
|
+
if (kind === 'ZodBoolean' || kind === 'boolean')
|
|
72
|
+
return withDescription('boolean');
|
|
73
|
+
if (kind === 'ZodEnum' || kind === 'enum') {
|
|
74
|
+
const values = Array.isArray(def.values)
|
|
75
|
+
? def.values
|
|
76
|
+
: isRecord(def.entries)
|
|
77
|
+
? Object.values(def.entries)
|
|
78
|
+
: [];
|
|
79
|
+
return { ...withDescription('string'), enum: values };
|
|
27
80
|
}
|
|
28
|
-
if (
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
81
|
+
if (kind === 'ZodArray' || kind === 'array') {
|
|
82
|
+
return {
|
|
83
|
+
...withDescription('array'),
|
|
84
|
+
items: zodFieldToJsonSchema(def.element ?? def.type),
|
|
85
|
+
};
|
|
33
86
|
}
|
|
34
|
-
if (
|
|
35
|
-
|
|
36
|
-
if (def.description)
|
|
37
|
-
out.description = def.description;
|
|
38
|
-
return out;
|
|
87
|
+
if (kind === 'ZodObject' || kind === 'object') {
|
|
88
|
+
return toolInputSchemaToParameters(schema);
|
|
39
89
|
}
|
|
40
|
-
|
|
41
|
-
|
|
90
|
+
return withDescription('string');
|
|
91
|
+
}
|
|
92
|
+
function isJsonObjectSchema(schema) {
|
|
93
|
+
if (!isRecord(schema) || schema.type !== 'object')
|
|
94
|
+
return false;
|
|
95
|
+
return typeof schema.safeParse !== 'function';
|
|
96
|
+
}
|
|
97
|
+
function fromNativeJsonSchema(schema) {
|
|
98
|
+
const candidate = schema;
|
|
99
|
+
if (typeof candidate?.toJSONSchema !== 'function')
|
|
100
|
+
return undefined;
|
|
101
|
+
try {
|
|
102
|
+
const converted = candidate.toJSONSchema();
|
|
103
|
+
if (!isRecord(converted) || converted.type !== 'object')
|
|
104
|
+
return undefined;
|
|
105
|
+
return {
|
|
106
|
+
...converted,
|
|
107
|
+
type: 'object',
|
|
108
|
+
properties: isRecord(converted.properties)
|
|
109
|
+
? converted.properties
|
|
110
|
+
: {},
|
|
111
|
+
required: requiredFromShape(schema, Array.isArray(converted.required)
|
|
112
|
+
? converted.required.filter((key) => typeof key === 'string')
|
|
113
|
+
: undefined),
|
|
114
|
+
};
|
|
42
115
|
}
|
|
43
|
-
|
|
44
|
-
return
|
|
116
|
+
catch {
|
|
117
|
+
return undefined;
|
|
45
118
|
}
|
|
46
|
-
return { type: 'string' };
|
|
47
119
|
}
|
|
48
|
-
|
|
49
|
-
|
|
120
|
+
/**
|
|
121
|
+
* Normalize a JSON Schema or Zod object schema into the canonical Core tool
|
|
122
|
+
* parameter schema. Zod remains an optional peer: this adapter uses only its
|
|
123
|
+
* public instance methods and retains a structural fallback for Zod 3.
|
|
124
|
+
*/
|
|
125
|
+
export function toolInputSchemaToParameters(schema) {
|
|
126
|
+
if (isJsonObjectSchema(schema))
|
|
127
|
+
return schema;
|
|
128
|
+
const native = fromNativeJsonSchema(schema);
|
|
129
|
+
if (native)
|
|
130
|
+
return native;
|
|
131
|
+
const shape = getShape(schema);
|
|
132
|
+
const properties = {};
|
|
133
|
+
if (shape) {
|
|
134
|
+
for (const [key, value] of Object.entries(shape)) {
|
|
135
|
+
properties[key] = zodFieldToJsonSchema(value);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
return {
|
|
50
139
|
type: 'object',
|
|
51
|
-
properties:
|
|
52
|
-
required:
|
|
140
|
+
properties: properties,
|
|
141
|
+
required: requiredFromShape(schema),
|
|
53
142
|
};
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
const
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
const zodValue = value;
|
|
61
|
-
properties[key] = zodFieldToJsonSchema(zodValue);
|
|
62
|
-
const typeName = zodValue?._def?.typeName;
|
|
63
|
-
if (typeName !== 'ZodOptional' && typeName !== 'ZodDefault') {
|
|
64
|
-
required.push(key);
|
|
65
|
-
}
|
|
143
|
+
}
|
|
144
|
+
/** Validate input with a Zod-like schema, or pass it through for JSON Schema. */
|
|
145
|
+
export function parseToolInputSchema(schema, input) {
|
|
146
|
+
const candidate = schema;
|
|
147
|
+
if (typeof candidate?.safeParse !== 'function') {
|
|
148
|
+
return { ok: true, data: input };
|
|
66
149
|
}
|
|
67
|
-
|
|
68
|
-
|
|
150
|
+
const parsed = candidate.safeParse(input);
|
|
151
|
+
if (parsed.success)
|
|
152
|
+
return { ok: true, data: parsed.data };
|
|
153
|
+
const issues = parsed.error?.issues ?? parsed.error?.errors ?? [];
|
|
154
|
+
const error = issues
|
|
155
|
+
.map((issue) => `${(issue.path ?? []).join('.') || 'root'}: ${issue.message ?? 'invalid'}`)
|
|
156
|
+
.join('; ');
|
|
157
|
+
return { ok: false, error: error || 'Invalid arguments' };
|
|
69
158
|
}
|
|
70
159
|
/**
|
|
71
160
|
* 从 Zod 模式创建 Tool,便于类型安全与校验。
|
|
@@ -75,18 +164,16 @@ export function createToolFromZod(name, description, schema, execute, options) {
|
|
|
75
164
|
if (!schema?.safeParse) {
|
|
76
165
|
throw new Error('createToolFromZod: schema must be a Zod object schema (e.g. z.object({ ... })). Install zod: pnpm add zod');
|
|
77
166
|
}
|
|
78
|
-
const parameters =
|
|
167
|
+
const parameters = toolInputSchemaToParameters(schema);
|
|
79
168
|
return {
|
|
80
169
|
name,
|
|
81
170
|
description,
|
|
82
171
|
parameters,
|
|
83
|
-
execute: async (args,
|
|
84
|
-
const parsed = schema
|
|
85
|
-
if (!parsed.
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
}
|
|
89
|
-
return execute(parsed.data, context);
|
|
172
|
+
execute: async (args, message) => {
|
|
173
|
+
const parsed = parseToolInputSchema(schema, args);
|
|
174
|
+
if (!parsed.ok)
|
|
175
|
+
return `Error: ${parsed.error}`;
|
|
176
|
+
return execute(parsed.data, message);
|
|
90
177
|
},
|
|
91
178
|
tags: options?.tags,
|
|
92
179
|
keywords: options?.keywords,
|
|
@@ -95,4 +182,3 @@ export function createToolFromZod(name, description, schema, execute, options) {
|
|
|
95
182
|
kind: options?.kind,
|
|
96
183
|
};
|
|
97
184
|
}
|
|
98
|
-
//# sourceMappingURL=tool-zod.js.map
|
package/lib/types.d.ts
CHANGED
|
@@ -1,12 +1,10 @@
|
|
|
1
|
-
import { MessageChannel, Message } from
|
|
2
|
-
import { Adapter, Adapters } from
|
|
3
|
-
import {
|
|
4
|
-
import { SystemLog } from
|
|
5
|
-
import { User } from
|
|
6
|
-
import { Databases, Registry } from
|
|
7
|
-
import {
|
|
8
|
-
import { ProcessAdapter } from "./built/adapter-process.js";
|
|
9
|
-
import type { SenderRole } from "./built/roles.js";
|
|
1
|
+
import type { MessageChannel, Message, MessageComponent } from './message.js';
|
|
2
|
+
import { Adapter, Adapters } from './adapter.js';
|
|
3
|
+
import { Endpoint } from './endpoint.js';
|
|
4
|
+
import { SystemLog } from './models/system-log.js';
|
|
5
|
+
import { User } from './models/user.js';
|
|
6
|
+
import { Databases, Registry } from '@zhin.js/database';
|
|
7
|
+
import { ProcessAdapter } from './built/adapter-process.js';
|
|
10
8
|
export type { SenderRole } from "./built/roles.js";
|
|
11
9
|
export type ArrayItem<T> = T extends Array<infer R> ? R : unknown;
|
|
12
10
|
export interface Models extends Record<string, object> {
|
|
@@ -34,19 +32,19 @@ export type RegisteredAdapter = Extract<keyof RegisteredAdapters, string>;
|
|
|
34
32
|
/**
|
|
35
33
|
* 指定适配器的消息类型
|
|
36
34
|
*/
|
|
37
|
-
export type AdapterMessage<T extends keyof RegisteredAdapters = keyof RegisteredAdapters> = RegisteredAdapters[T] extends Adapter<infer R> ?
|
|
35
|
+
export type AdapterMessage<T extends keyof RegisteredAdapters = keyof RegisteredAdapters> = RegisteredAdapters[T] extends Adapter<infer R> ? EndpointMessage<R> : {};
|
|
38
36
|
/**
|
|
39
37
|
* 指定适配器的配置类型
|
|
40
38
|
*/
|
|
41
|
-
export type AdapterConfig<T extends keyof RegisteredAdapters = keyof RegisteredAdapters> = RegisteredAdapters[T] extends Adapter<infer R> ? PlatformConfig<R> :
|
|
39
|
+
export type AdapterConfig<T extends keyof RegisteredAdapters = keyof RegisteredAdapters> = RegisteredAdapters[T] extends Adapter<infer R> ? PlatformConfig<R> : Endpoint.Config;
|
|
42
40
|
/**
|
|
43
41
|
* Bot实例的配置类型
|
|
44
42
|
*/
|
|
45
|
-
export type PlatformConfig<T> = T extends
|
|
43
|
+
export type PlatformConfig<T> = T extends Endpoint<infer L, infer R> ? R : Endpoint.Config;
|
|
46
44
|
/**
|
|
47
45
|
* Bot实例的消息类型
|
|
48
46
|
*/
|
|
49
|
-
export type
|
|
47
|
+
export type EndpointMessage<T extends Endpoint> = T extends Endpoint<infer R> ? R : {};
|
|
50
48
|
/**
|
|
51
49
|
* 消息段结构,支持 text/image/at/face 等类型
|
|
52
50
|
*/
|
|
@@ -63,23 +61,24 @@ export type MaybeArray<T> = T | T[];
|
|
|
63
61
|
* 消息发送内容类型
|
|
64
62
|
*/
|
|
65
63
|
export type SendContent = MaybeArray<string | MessageElement>;
|
|
66
|
-
/**
|
|
67
|
-
export interface
|
|
64
|
+
/** 可选:编辑已发送消息(交互式棋盘更新) */
|
|
65
|
+
export interface EditMessageOptions {
|
|
68
66
|
messageId: string;
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
content:
|
|
74
|
-
raw?: string;
|
|
75
|
-
time?: number;
|
|
67
|
+
context: string;
|
|
68
|
+
endpoint: string;
|
|
69
|
+
id: string;
|
|
70
|
+
type: 'private' | 'group' | 'channel';
|
|
71
|
+
content: SendContent;
|
|
76
72
|
}
|
|
77
|
-
/**
|
|
78
|
-
export
|
|
79
|
-
|
|
73
|
+
/** 出站回复来源(指令 / AI / proactive),仅当经 MessageDispatcher.replyWithPolish 或 runWithOutboundPolish 发出时由框架填入异步上下文 */
|
|
74
|
+
export type OutboundReplySource = 'command' | 'ai' | 'proactive';
|
|
75
|
+
export type OutboundReplyTrigger = 'inbound' | 'proactive';
|
|
76
|
+
export interface OutboundReplyStore {
|
|
77
|
+
message: Message;
|
|
78
|
+
source: OutboundReplySource;
|
|
79
|
+
trigger: OutboundReplyTrigger;
|
|
80
|
+
proactiveSource?: string;
|
|
80
81
|
}
|
|
81
|
-
/** 出站回复来源(指令 / AI),仅当经 MessageDispatcher.replyWithPolish 发出时由框架填入异步上下文 */
|
|
82
|
-
export type OutboundReplySource = 'command' | 'ai';
|
|
83
82
|
/**
|
|
84
83
|
* 出站润色上下文(`dispatcher.addOutboundPolish` 的 handler 签名的同构类型)。
|
|
85
84
|
* 与 {@link Adapter.sendMessage} → `before.sendMessage` 同一管道;需 `message`/`source` 时见 `getOutboundReplyStore`(dispatcher 导出)。
|
|
@@ -98,13 +97,17 @@ export interface MessageSender {
|
|
|
98
97
|
id: string;
|
|
99
98
|
name?: string;
|
|
100
99
|
permissions?: string[];
|
|
101
|
-
/**
|
|
100
|
+
/** 平台群成员身份(owner / admin / member)— 仅供 platform checker */
|
|
102
101
|
role?: string;
|
|
102
|
+
/** enrich 快照:endpoint 实例 master */
|
|
103
|
+
isMaster?: boolean;
|
|
104
|
+
/** enrich 快照:endpoint 实例 trusted */
|
|
105
|
+
isTrusted?: boolean;
|
|
103
106
|
}
|
|
104
107
|
/**
|
|
105
108
|
* 通用字典类型
|
|
106
109
|
*/
|
|
107
|
-
export type Dict
|
|
110
|
+
export type { Dict } from '@zhin.js/kernel';
|
|
108
111
|
/**
|
|
109
112
|
* 用户信息结构
|
|
110
113
|
*/
|
|
@@ -130,8 +133,10 @@ export type MessageMiddleware<P extends RegisteredAdapter = RegisteredAdapter> =
|
|
|
130
133
|
export type DefineConfig<T> = T | ((env: Record<string, string>) => MaybePromise<T>);
|
|
131
134
|
export interface SendOptions extends MessageChannel {
|
|
132
135
|
context: string;
|
|
133
|
-
|
|
136
|
+
endpoint: string;
|
|
134
137
|
content: SendContent;
|
|
138
|
+
quoteId?: string;
|
|
139
|
+
threadId?: string;
|
|
135
140
|
}
|
|
136
141
|
/** `Adapter.sendMessage` 成功发出后由 core 分发的载荷 */
|
|
137
142
|
export interface MessageSendPayload {
|
|
@@ -156,8 +161,8 @@ export type BeforeSendHandler = (options: SendOptions) => MaybePromise<SendOptio
|
|
|
156
161
|
/**
|
|
157
162
|
* JSON Schema 定义,用于描述工具参数
|
|
158
163
|
*/
|
|
159
|
-
/**
|
|
160
|
-
export type ContextInjectableKey = 'platform' | '
|
|
164
|
+
/** Message 通讯上下文上可经 resolveContextKey 自动注入的字段名 */
|
|
165
|
+
export type ContextInjectableKey = 'platform' | 'endpointKey' | 'sceneId' | 'senderId' | 'scope';
|
|
161
166
|
export interface ToolJsonSchema {
|
|
162
167
|
type: string;
|
|
163
168
|
properties?: Record<string, ToolJsonSchema & {
|
|
@@ -170,9 +175,9 @@ export interface ToolJsonSchema {
|
|
|
170
175
|
description?: string;
|
|
171
176
|
default?: any;
|
|
172
177
|
/**
|
|
173
|
-
* 自动从
|
|
178
|
+
* 自动从 Message 通讯上下文注入的字段名(经 resolveContextKey 映射 $ 字段)。
|
|
174
179
|
* 设置后该参数对 AI 隐藏,执行时自动从上下文填充。
|
|
175
|
-
* 例如: contextKey: '
|
|
180
|
+
* 例如: contextKey: 'endpointKey' → 执行时自动填入 message.$endpoint
|
|
176
181
|
*/
|
|
177
182
|
contextKey?: ContextInjectableKey;
|
|
178
183
|
[key: string]: any;
|
|
@@ -190,7 +195,7 @@ export interface PropertySchema<T = any> extends ToolJsonSchema {
|
|
|
190
195
|
default?: T;
|
|
191
196
|
enum?: T extends string | number ? T[] : never;
|
|
192
197
|
paramType?: 'text' | 'number' | 'boolean' | 'rest';
|
|
193
|
-
/** 自动从
|
|
198
|
+
/** 自动从 Message 注入的字段名(继承自 ToolJsonSchema) */
|
|
194
199
|
contextKey?: ContextInjectableKey;
|
|
195
200
|
}
|
|
196
201
|
/**
|
|
@@ -213,38 +218,6 @@ export interface ToolParametersSchema<TArgs extends Record<string, any> = Record
|
|
|
213
218
|
/** 描述 */
|
|
214
219
|
description?: string;
|
|
215
220
|
}
|
|
216
|
-
/**
|
|
217
|
-
* 工具执行上下文
|
|
218
|
-
* 包含消息来源、发送者等 IM 信息。
|
|
219
|
-
* 通用(IM 无关)版本请使用 @zhin.js/ai 的 ToolContext。
|
|
220
|
-
*/
|
|
221
|
-
export interface ToolContext {
|
|
222
|
-
/** 来源平台 */
|
|
223
|
-
platform?: string;
|
|
224
|
-
/** 来源 Bot */
|
|
225
|
-
botId?: string;
|
|
226
|
-
/** 消息 ID */
|
|
227
|
-
messageId?: string;
|
|
228
|
-
/** 场景 ID(群号/频道ID/私聊用户ID) */
|
|
229
|
-
sceneId?: string;
|
|
230
|
-
/** 发送者 ID */
|
|
231
|
-
senderId?: string;
|
|
232
|
-
/** 原始消息对象(如果从消息触发) */
|
|
233
|
-
message?: Message<any>;
|
|
234
|
-
/**
|
|
235
|
-
* 消息场景类型
|
|
236
|
-
* private: 私聊, group: 群聊, channel: 频道
|
|
237
|
-
*/
|
|
238
|
-
scope?: ToolScope;
|
|
239
|
-
/** 发送者角色集合(群角色 + bot master/trusted 可并存) */
|
|
240
|
-
roles?: readonly SenderRole[];
|
|
241
|
-
/**
|
|
242
|
-
* 文件操作角色 — 用于文件工具的权限控制
|
|
243
|
-
*/
|
|
244
|
-
fileRole?: FileRole;
|
|
245
|
-
/** 额外数据 */
|
|
246
|
-
extra?: Record<string, any>;
|
|
247
|
-
}
|
|
248
221
|
/**
|
|
249
222
|
* 统一的 Tool 定义
|
|
250
223
|
* 可同时用于:
|
|
@@ -334,10 +307,10 @@ export interface Tool<TArgs extends Record<string, any> = Record<string, any>> {
|
|
|
334
307
|
/**
|
|
335
308
|
* 工具执行函数
|
|
336
309
|
* @param args 解析后的参数
|
|
337
|
-
* @param
|
|
310
|
+
* @param message 通讯上下文(入站 Message 或合成 Message)
|
|
338
311
|
* @returns 执行结果
|
|
339
312
|
*/
|
|
340
|
-
execute: (args: TArgs,
|
|
313
|
+
execute: (args: TArgs, message?: Message<any>) => MaybePromise<ToolResult>;
|
|
341
314
|
/** 工具来源标识(自动填充:adapter:xxx / plugin:xxx) */
|
|
342
315
|
source?: string;
|
|
343
316
|
/** 工具标签(用于分类和过滤) */
|
|
@@ -349,6 +322,8 @@ export interface Tool<TArgs extends Record<string, any> = Record<string, any>> {
|
|
|
349
322
|
* 执行此工具需要的权限列表
|
|
350
323
|
*/
|
|
351
324
|
permissions?: string[];
|
|
325
|
+
/** Per-tool approval policy; `on-risk` remains fail-closed at Agent boundaries. */
|
|
326
|
+
approval?: 'always' | 'once' | 'never' | 'on-risk';
|
|
352
327
|
/**
|
|
353
328
|
* 支持的平台列表
|
|
354
329
|
* 例如:['qq', 'telegram', 'discord']
|
|
@@ -361,11 +336,6 @@ export interface Tool<TArgs extends Record<string, any> = Record<string, any>> {
|
|
|
361
336
|
* 不填则支持所有场景
|
|
362
337
|
*/
|
|
363
338
|
scopes?: ToolScope[];
|
|
364
|
-
/**
|
|
365
|
-
* 调用者需具备的角色之一(隐含升格见 roles.ts)
|
|
366
|
-
* 省略则仅需 user
|
|
367
|
-
*/
|
|
368
|
-
requiredAnyRole?: readonly SenderRole[];
|
|
369
339
|
/**
|
|
370
340
|
* 是否隐藏
|
|
371
341
|
* 隐藏的工具不会出现在帮助列表中,但仍可被调用
|
|
@@ -386,10 +356,6 @@ export interface Tool<TArgs extends Record<string, any> = Record<string, any>> {
|
|
|
386
356
|
*/
|
|
387
357
|
command?: ToolCommandConfig | false;
|
|
388
358
|
}
|
|
389
|
-
/**
|
|
390
|
-
* @deprecated 使用 `Tool<TArgs>` 替代。Tool 已原生支持泛型。
|
|
391
|
-
*/
|
|
392
|
-
export type ToolDefinition<TArgs extends Record<string, any> = Record<string, any>> = Tool<TArgs>;
|
|
393
359
|
export declare namespace Tool {
|
|
394
360
|
/**
|
|
395
361
|
* 参数信息
|
|
@@ -416,10 +382,3 @@ export interface PluginManifest {
|
|
|
416
382
|
}
|
|
417
383
|
/** @deprecated 使用 Tool 替代 */
|
|
418
384
|
export type AITool = Tool;
|
|
419
|
-
/**
|
|
420
|
-
* IMToolContext — ToolContext 的显式 IM 别名。
|
|
421
|
-
* 当同时使用 @zhin.js/ai (通用 ToolContext) 和 @zhin.js/core (IM ToolContext) 时,
|
|
422
|
-
* 用此类型消除歧义。
|
|
423
|
-
*/
|
|
424
|
-
export type IMToolContext = ToolContext;
|
|
425
|
-
//# sourceMappingURL=types.d.ts.map
|
package/lib/types.js
CHANGED
package/lib/utils.d.ts
CHANGED
|
@@ -7,8 +7,19 @@
|
|
|
7
7
|
export { evaluate, execute, clearEvalCache, getEvalCacheStats, getValueWithRuntime, compiler, remove, isEmpty, Time, supportedPluginExtensions, resolveEntry, sleep, } from '@zhin.js/kernel';
|
|
8
8
|
import { AdapterMessage, MessageMiddleware, RegisteredAdapter, SendContent } from "./types.js";
|
|
9
9
|
import { Message } from "./message.js";
|
|
10
|
+
import { HtmlSegment } from "./built/rich-segments/html-segment.js";
|
|
11
|
+
import { MarkdownSegment } from "./built/rich-segments/markdown-segment.js";
|
|
12
|
+
import { QrcodeSegment } from "./built/rich-segments/qrcode-segment.js";
|
|
13
|
+
import { TtsSegment } from "./built/rich-segments/tts-segment.js";
|
|
14
|
+
import { KeyboardSegment } from "./built/interactive-segments/keyboard-segment.js";
|
|
15
|
+
import { ButtonSpec, type KeyboardRowInput } from "./built/interactive-segments/button-spec.js";
|
|
16
|
+
import type { ButtonData, KeyboardFallback, KeyboardSegmentData } from "./built/interactive-segments/types.js";
|
|
17
|
+
import type { MediaRef } from "./built/segment-contract/types.js";
|
|
10
18
|
/**
|
|
11
19
|
* 组合中间件,洋葱模型
|
|
20
|
+
*
|
|
21
|
+
* 空中间件列表时必须仍调用 `next`——入站管线把 MessageDispatcher
|
|
22
|
+
* 作为 terminal next 传入;吞掉 next 会导致命令/AI 永远不跑。
|
|
12
23
|
*/
|
|
13
24
|
export declare function compose<P extends RegisteredAdapter = RegisteredAdapter>(middlewares: MessageMiddleware<P>[]): (message: Message<AdapterMessage<P>>, next?: () => Promise<void>) => Promise<void>;
|
|
14
25
|
export declare function segment<T extends object>(type: string, data: T): {
|
|
@@ -24,6 +35,26 @@ export declare namespace segment {
|
|
|
24
35
|
text: string;
|
|
25
36
|
};
|
|
26
37
|
};
|
|
38
|
+
function mention(target: string, name?: string): {
|
|
39
|
+
type: string;
|
|
40
|
+
data: {
|
|
41
|
+
target: string;
|
|
42
|
+
name: string;
|
|
43
|
+
} | {
|
|
44
|
+
target: string;
|
|
45
|
+
name?: undefined;
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
function image(media: MediaRef, alt?: string): {
|
|
49
|
+
type: string;
|
|
50
|
+
data: {
|
|
51
|
+
media: MediaRef;
|
|
52
|
+
alt: string;
|
|
53
|
+
} | {
|
|
54
|
+
media: MediaRef;
|
|
55
|
+
alt?: undefined;
|
|
56
|
+
};
|
|
57
|
+
};
|
|
27
58
|
function face(id: string, text?: string): {
|
|
28
59
|
type: string;
|
|
29
60
|
data: {
|
|
@@ -31,8 +62,44 @@ export declare namespace segment {
|
|
|
31
62
|
text: string | undefined;
|
|
32
63
|
};
|
|
33
64
|
};
|
|
65
|
+
/** 出站 HTML 卡片段(Adapter policy 决定 image/text/origin) */
|
|
66
|
+
function htmlCard(options: {
|
|
67
|
+
html: string;
|
|
68
|
+
text?: string;
|
|
69
|
+
width?: number;
|
|
70
|
+
backgroundColor?: string;
|
|
71
|
+
fileName?: string;
|
|
72
|
+
}): HtmlSegment;
|
|
73
|
+
/** Short alias for {@link htmlCard}. */
|
|
74
|
+
const html: typeof htmlCard;
|
|
75
|
+
/** 出站 Markdown 段(Adapter policy 决定 image/text/origin) */
|
|
76
|
+
function markdown(content: string, options?: Omit<MarkdownSegment['data'], 'content'>): MarkdownSegment;
|
|
77
|
+
/** 二维码出站段(Adapter policy 决定 image/text/origin) */
|
|
78
|
+
function qrcode(text: string, options?: {
|
|
79
|
+
width?: number;
|
|
80
|
+
margin?: number;
|
|
81
|
+
errorCorrectionLevel?: 'L' | 'M' | 'Q' | 'H';
|
|
82
|
+
small?: boolean;
|
|
83
|
+
}): QrcodeSegment;
|
|
84
|
+
/** TTS 出站段(Adapter policy 决定 audio/text/origin) */
|
|
85
|
+
function tts(options: {
|
|
86
|
+
text: string;
|
|
87
|
+
voice?: string;
|
|
88
|
+
provider?: string;
|
|
89
|
+
}): TtsSegment;
|
|
90
|
+
/** 键盘按钮单元(与 {@link keyboard} 组合布局) */
|
|
91
|
+
function button(data: ButtonData): ButtonSpec;
|
|
92
|
+
/** 键盘布局出站段(Adapter interactivePolicy 决定 native/text) */
|
|
93
|
+
function keyboard(rows: KeyboardRowInput[], options?: {
|
|
94
|
+
fallback?: KeyboardFallback;
|
|
95
|
+
}): KeyboardSegment;
|
|
96
|
+
/**
|
|
97
|
+
* @deprecated 使用 {@link keyboard} + {@link button};文本请用 `segment.text` 单独发送
|
|
98
|
+
*/
|
|
99
|
+
function interactive(data: KeyboardSegmentData & {
|
|
100
|
+
text?: SendContent;
|
|
101
|
+
}): KeyboardSegment;
|
|
34
102
|
function from(content: SendContent): SendContent;
|
|
35
103
|
function raw(content: SendContent): string;
|
|
36
104
|
function toString(content: SendContent): string;
|
|
37
105
|
}
|
|
38
|
-
//# sourceMappingURL=utils.d.ts.map
|