@zhin.js/core 1.1.40 → 1.1.42

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.
Files changed (54) hide show
  1. package/lib/built/ai-trigger.js +2 -2
  2. package/lib/built/html-segment-fallback.d.ts +4 -2
  3. package/lib/built/html-segment-fallback.js +1 -1
  4. package/lib/built/interactive-segments/action.js +1 -1
  5. package/lib/built/interactive-segments/resolve.js +1 -1
  6. package/lib/built/interactive-segments/types.d.ts +2 -2
  7. package/lib/built/interactive-segments/types.js +22 -2
  8. package/lib/built/outbound-content-arrays.d.ts +4 -0
  9. package/lib/built/outbound-content-arrays.js +32 -0
  10. package/lib/built/outbound-media-utils.d.ts +5 -3
  11. package/lib/built/outbound-media-utils.js +5 -3
  12. package/lib/built/segment-contract/assert.js +6 -1
  13. package/lib/built/segment-contract/json-schema.d.ts +1 -1
  14. package/lib/built/segment-contract/json-schema.js +30 -2
  15. package/lib/feature/component.d.ts +1 -0
  16. package/lib/feature/component.js +1 -0
  17. package/lib/index.d.ts +3 -2
  18. package/lib/index.js +2 -1
  19. package/lib/jsx/intrinsic-elements.d.ts +83 -0
  20. package/lib/jsx/intrinsic-elements.js +1 -0
  21. package/lib/jsx/message-renderer.d.ts +13 -0
  22. package/lib/jsx/message-renderer.js +128 -0
  23. package/lib/jsx/message-tags.d.ts +126 -0
  24. package/lib/jsx/message-tags.js +47 -0
  25. package/lib/jsx-dev-runtime.d.ts +2 -2
  26. package/lib/jsx-dev-runtime.js +1 -2
  27. package/lib/jsx-runtime.d.ts +2 -12
  28. package/lib/jsx-runtime.js +1 -10
  29. package/lib/jsx.d.ts +6 -30
  30. package/lib/jsx.js +3 -93
  31. package/lib/message.d.ts +0 -11
  32. package/lib/plugin-runtime/im/contracts.d.ts +14 -6
  33. package/lib/plugin-runtime/im/contracts.js +28 -6
  34. package/lib/plugin-runtime/im/im-runtime.js +1 -0
  35. package/lib/plugin-runtime/im/inbound-runtime.js +33 -9
  36. package/lib/plugin-runtime/im/interaction-runtime.d.ts +6 -3
  37. package/lib/plugin-runtime/im/interaction-runtime.js +14 -3
  38. package/lib/plugin-runtime/im/interactive-router.d.ts +1 -1
  39. package/lib/plugin-runtime/im/interactive-router.js +19 -16
  40. package/lib/plugin-runtime/im/jsx-button-registry.d.ts +17 -0
  41. package/lib/plugin-runtime/im/jsx-button-registry.js +93 -0
  42. package/lib/plugin-runtime/im/message-dispatcher.js +0 -1
  43. package/lib/plugin-runtime/im/outbound-delivery-runtime.d.ts +3 -1
  44. package/lib/plugin-runtime/im/outbound-delivery-runtime.js +50 -18
  45. package/lib/plugin-runtime/im/outbound-renderer.d.ts +9 -2
  46. package/lib/plugin-runtime/im/outbound-renderer.js +52 -6
  47. package/lib/plugin-runtime/im/outbound-segments.d.ts +6 -1
  48. package/lib/plugin-runtime/im/outbound-segments.js +28 -8
  49. package/lib/types.d.ts +5 -7
  50. package/lib/utils.d.ts +4 -4
  51. package/lib/utils.js +9 -17
  52. package/package.json +15 -13
  53. package/lib/component.d.ts +0 -26
  54. package/lib/component.js +0 -583
package/lib/utils.js CHANGED
@@ -125,12 +125,11 @@ export function segment(type, data) {
125
125
  }
126
126
  segment.keyboard = keyboard;
127
127
  function from(content) {
128
- if (!Array.isArray(content))
129
- content = [content];
128
+ const items = Array.isArray(content) ? content : [content];
130
129
  const toString = (template) => {
131
130
  if (typeof template !== "string")
132
131
  return [template];
133
- /** ReDoS 防护:仅约束 segment.from 的字符串模板解析,不是附件大小上限;MessageElement[] 出站应走 renderComponents 快路径避免往返 */
132
+ /** ReDoS 防护:仅约束 segment.from 的字符串模板解析,不是附件大小上限;结构化段出站直接走统一渲染链路,避免文本往返 */
134
133
  const MAX_TEMPLATE_LENGTH = 400000;
135
134
  if (template.length > MAX_TEMPLATE_LENGTH) {
136
135
  throw new Error(`Template too large: ${template.length} > ${MAX_TEMPLATE_LENGTH}`);
@@ -214,39 +213,32 @@ export function segment(type, data) {
214
213
  }
215
214
  return result;
216
215
  };
217
- return content.reduce((result, item) => {
216
+ return items.reduce((result, item) => {
218
217
  result.push(...toString(item));
219
218
  return result;
220
219
  }, []);
221
220
  }
222
221
  segment.from = from;
223
222
  function raw(content) {
224
- if (!Array.isArray(content))
225
- content = [content];
226
- return content
223
+ const items = Array.isArray(content) ? content : [content];
224
+ return items
227
225
  .map((item) => {
228
226
  if (typeof item === "string")
229
227
  return item;
230
228
  const { type, data } = item;
231
- if (typeof type === "function") {
232
- return `{${type.name || "Component"}}`;
233
- }
234
229
  return formatSegmentPreview({ type, data: data ?? {} });
235
230
  })
236
231
  .join("");
237
232
  }
238
233
  segment.raw = raw;
239
234
  function toString(content) {
240
- if (!Array.isArray(content))
241
- content = [content];
242
- return content
235
+ const items = Array.isArray(content) ? content : [content];
236
+ return items
243
237
  .map((item) => {
244
238
  if (typeof item === "string")
245
239
  return item;
246
- let { type } = item;
247
- const { data } = item;
248
- if (typeof type === "function")
249
- type = type.name;
240
+ const { type } = item;
241
+ const data = item.data;
250
242
  if (type === "text")
251
243
  return data.text;
252
244
  const keys = Object.keys(data).filter((key) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zhin.js/core",
3
- "version": "1.1.40",
3
+ "version": "1.1.42",
4
4
  "description": "Zhin机器人核心框架",
5
5
  "type": "module",
6
6
  "main": "./lib/index.js",
@@ -68,27 +68,29 @@
68
68
  "dependencies": {
69
69
  "qrcode": "^1.5.4",
70
70
  "segment-matcher": "^1.0.5",
71
- "@zhin.js/adapter": "1.1.16",
72
- "@zhin.js/command": "1.1.4",
73
- "@zhin.js/component": "1.1.3",
74
- "@zhin.js/database": "1.1.2",
75
- "@zhin.js/handler": "1.1.2",
71
+ "@zhin.js/adapter": "1.1.17",
72
+ "@zhin.js/command": "1.1.5",
73
+ "@zhin.js/component": "1.1.4",
74
+ "@zhin.js/database": "1.1.3",
75
+ "@zhin.js/handler": "1.1.3",
76
76
  "@zhin.js/im-contract": "1.1.3",
77
77
  "@zhin.js/interaction": "1.1.0",
78
78
  "@zhin.js/kernel": "1.1.2",
79
79
  "@zhin.js/logger": "1.1.1",
80
- "@zhin.js/middleware": "1.1.3",
81
- "@zhin.js/permission": "1.1.3",
82
- "@zhin.js/plugin-runtime": "1.1.11",
83
- "@zhin.js/schedule-feature": "1.1.2",
84
- "@zhin.js/schema": "1.1.1"
80
+ "@zhin.js/middleware": "1.1.4",
81
+ "@zhin.js/permission": "1.1.4",
82
+ "@zhin.js/plugin-runtime": "1.1.12",
83
+ "@zhin.js/schedule-feature": "1.1.3",
84
+ "@zhin.js/schema": "1.1.1",
85
+ "@zhin.js/jsx": "1.1.2",
86
+ "@zhin.js/feature-kit": "1.1.3"
85
87
  },
86
88
  "devDependencies": {
87
89
  "@types/node": "^26.1.2",
88
90
  "@types/qrcode": "^1.5.6",
89
91
  "ajv": "8.18.0",
90
92
  "typescript": "^6.0.3",
91
- "@zhin.js/ai": "1.1.36"
93
+ "@zhin.js/ai": "1.1.37"
92
94
  },
93
95
  "repository": {
94
96
  "type": "git",
@@ -143,7 +145,7 @@
143
145
  "plugins": []
144
146
  },
145
147
  "scripts": {
146
- "build": "tsc",
148
+ "build": "rimraf lib && tsc",
147
149
  "clean": "rimraf lib"
148
150
  }
149
151
  }
@@ -1,26 +0,0 @@
1
- import { Dict, SendContent, SendOptions } from './types.js';
2
- export declare const CapWithChild: unique symbol;
3
- export declare const CapWithClose: unique symbol;
4
- export type Component<P = any> = {
5
- (props: P, context: ComponentContext): SendContent | Promise<SendContent>;
6
- name: string;
7
- };
8
- export interface ComponentContext {
9
- render: (template: string, context?: Partial<ComponentContext>) => Promise<SendContent>;
10
- props: Readonly<Dict>;
11
- parent?: Readonly<ComponentContext>;
12
- root: string;
13
- children?: string;
14
- getValue: (template: string) => any;
15
- compile: (template: string) => string;
16
- }
17
- export declare function defineComponent<P = any>(component: Component<P>, name?: string): Component<P>;
18
- export declare function matchComponent<P = any>(comp: Component<P>, template: string): string;
19
- export declare function getProps<P = any>(comp: Component<P>, template: string, context?: ComponentContext): P;
20
- export declare function createComponentContext(props?: Dict, parent?: ComponentContext, root?: string): ComponentContext;
21
- export declare function renderComponent<P = any>(component: Component<P>, template: string, context: ComponentContext): Promise<SendContent>;
22
- export declare function renderComponents(componentMap: Map<string, Component>, options: SendOptions, customContext?: ComponentContext): Promise<SendOptions>;
23
- export declare const Fragment: Component<{
24
- children?: SendContent;
25
- }>;
26
- export declare const Fetch: Component<any>;