@zhin.js/core 1.1.41 → 1.1.43

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 (58) hide show
  1. package/lib/built/interactive-segments/action.js +1 -1
  2. package/lib/built/roles.d.ts +6 -1
  3. package/lib/built/roles.js +11 -20
  4. package/lib/built/segment-contract/assert.js +1 -1
  5. package/lib/built/segment-contract/json-schema.js +1 -1
  6. package/lib/built/segment-contract/validate.d.ts +301 -158
  7. package/lib/built/user-interaction.js +9 -3
  8. package/lib/feature/middleware-public-api.d.ts +5 -0
  9. package/lib/feature/middleware-public-api.js +5 -0
  10. package/lib/feature/middleware.d.ts +20 -2
  11. package/lib/feature/middleware.js +6 -2
  12. package/lib/jsx/intrinsic-elements.d.ts +83 -0
  13. package/lib/jsx/intrinsic-elements.js +1 -0
  14. package/lib/jsx/message-renderer.d.ts +13 -0
  15. package/lib/jsx/message-renderer.js +128 -0
  16. package/lib/jsx/message-tags.d.ts +126 -0
  17. package/lib/jsx/message-tags.js +47 -0
  18. package/lib/jsx-dev-runtime.d.ts +2 -1
  19. package/lib/jsx-dev-runtime.js +1 -1
  20. package/lib/jsx-runtime.d.ts +2 -1
  21. package/lib/jsx-runtime.js +1 -1
  22. package/lib/jsx.d.ts +5 -0
  23. package/lib/jsx.js +2 -0
  24. package/lib/plugin-runtime/im/contracts.d.ts +14 -0
  25. package/lib/plugin-runtime/im/contracts.js +3 -1
  26. package/lib/plugin-runtime/im/conversation-runtime.d.ts +13 -1
  27. package/lib/plugin-runtime/im/conversation-runtime.js +47 -1
  28. package/lib/plugin-runtime/im/endpoint-runtime.d.ts +8 -3
  29. package/lib/plugin-runtime/im/endpoint-runtime.js +46 -3
  30. package/lib/plugin-runtime/im/im-runtime.d.ts +12 -1
  31. package/lib/plugin-runtime/im/im-runtime.js +19 -1
  32. package/lib/plugin-runtime/im/inbound-dedup.d.ts +51 -0
  33. package/lib/plugin-runtime/im/inbound-dedup.js +184 -0
  34. package/lib/plugin-runtime/im/inbound-origin.d.ts +101 -0
  35. package/lib/plugin-runtime/im/inbound-origin.js +76 -0
  36. package/lib/plugin-runtime/im/inbound-runtime.d.ts +16 -2
  37. package/lib/plugin-runtime/im/inbound-runtime.js +238 -14
  38. package/lib/plugin-runtime/im/index.d.ts +3 -1
  39. package/lib/plugin-runtime/im/index.js +1 -0
  40. package/lib/plugin-runtime/im/interaction-runtime.d.ts +17 -3
  41. package/lib/plugin-runtime/im/interaction-runtime.js +31 -3
  42. package/lib/plugin-runtime/im/interactive-router.d.ts +19 -2
  43. package/lib/plugin-runtime/im/interactive-router.js +80 -23
  44. package/lib/plugin-runtime/im/jsx-button-registry.d.ts +17 -0
  45. package/lib/plugin-runtime/im/jsx-button-registry.js +97 -0
  46. package/lib/plugin-runtime/im/message-dispatcher.js +10 -0
  47. package/lib/plugin-runtime/im/message-events.d.ts +7 -0
  48. package/lib/plugin-runtime/im/outbound-delivery-runtime.d.ts +5 -1
  49. package/lib/plugin-runtime/im/outbound-delivery-runtime.js +49 -44
  50. package/lib/plugin-runtime/im/outbound-ledger.d.ts +24 -0
  51. package/lib/plugin-runtime/im/outbound-ledger.js +114 -0
  52. package/lib/plugin-runtime/im/outbound-projection.d.ts +15 -0
  53. package/lib/plugin-runtime/im/outbound-projection.js +55 -0
  54. package/lib/plugin-runtime/im/outbound-renderer.d.ts +6 -1
  55. package/lib/plugin-runtime/im/outbound-renderer.js +51 -12
  56. package/lib/plugin-runtime/im/outbound-segments.d.ts +4 -1
  57. package/lib/plugin-runtime/im/outbound-segments.js +37 -7
  58. package/package.json +16 -16
@@ -191,14 +191,20 @@ function instructionFor(request) {
191
191
  }
192
192
  }
193
193
  function renderOptions(options) {
194
- return options.map((option, index) => `${index + 1}. ${option.label}${option.description ? ` — ${option.description}` : ''}`).join('\n');
194
+ return options.map((option, index) => {
195
+ const aliases = option.aliases?.length ? `(${option.aliases.join(' / ')})` : '';
196
+ const description = option.description ? ` — ${option.description}` : '';
197
+ return `${index + 1}. ${option.label}${aliases}${description}`;
198
+ }).join('\n');
195
199
  }
196
200
  function resolveOption(options, raw) {
197
201
  const index = Number(raw);
198
202
  if (Number.isInteger(index) && index >= 1 && index <= options.length)
199
203
  return options[index - 1];
200
- const normalized = raw.toLocaleLowerCase();
201
- return options.find((option) => option.label.trim().toLocaleLowerCase() === normalized);
204
+ const normalized = raw.trim().toLocaleLowerCase();
205
+ const matches = (candidate) => candidate.trim().toLocaleLowerCase() === normalized;
206
+ return options.find((option) => matches(option.label))
207
+ ?? options.find((option) => option.aliases?.some(matches));
202
208
  }
203
209
  function uniqueOptions(options) {
204
210
  const result = [];
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Incoming Message and outbound envelope middleware authoring contracts.
3
+ * @module zhin.js/middleware
4
+ */
5
+ export { defineMiddleware, type MiddlewareContext, type MiddlewareContinuation, type MiddlewareDefinition, type MiddlewareDefinitionBase, type MiddlewareNext, type MiddlewarePhase, type MiddlewareTarget, type OutboundMiddlewareNext, } from './middleware.js';
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Incoming Message and outbound envelope middleware authoring contracts.
3
+ * @module zhin.js/middleware
4
+ */
5
+ export { defineMiddleware, } from './middleware.js';
@@ -1,2 +1,20 @@
1
- /** Authoring API for Middleware Feature — implementation in `@zhin.js/middleware`. */
2
- export * from '@zhin.js/middleware';
1
+ /**
2
+ * IM authoring defaults; the underlying Feature remains transport independent.
3
+ * @module zhin.js/middleware
4
+ */
5
+ export type { MiddlewareContinuation, MiddlewareDefinitionBase, MiddlewareNext, MiddlewarePhase, MiddlewareTarget, OutboundMiddlewareNext, } from '@zhin.js/middleware';
6
+ import { type MiddlewareAuthoringDefinition, type MiddlewareContext as FeatureMiddlewareContext, type MiddlewareDefinition as FeatureMiddlewareDefinition } from '@zhin.js/middleware';
7
+ import type { Message, OutboundEnvelope } from '../plugin-runtime/im/contracts.js';
8
+ export type MiddlewareContext<TInput = Message, TConfig = unknown, TAdapter extends string | undefined = undefined> = FeatureMiddlewareContext<TInput, TConfig, TAdapter>;
9
+ export type MiddlewareDefinition<TInput = Message, TConfig = unknown, TAdapter extends string | undefined = string | undefined> = FeatureMiddlewareDefinition<TInput, TConfig, TAdapter>;
10
+ /** Incoming IM middleware receives Message; outbound middleware receives its envelope. */
11
+ export declare function defineMiddleware<TInput = OutboundEnvelope, TConfig = unknown>(definition: Extract<MiddlewareAuthoringDefinition<TInput, TConfig>, {
12
+ readonly target: 'outbound';
13
+ }>): Readonly<Extract<FeatureMiddlewareDefinition<TInput, TConfig>, {
14
+ readonly target: 'outbound';
15
+ }>>;
16
+ export declare function defineMiddleware<TInput = Message, TConfig = unknown>(definition: Extract<MiddlewareAuthoringDefinition<TInput, TConfig>, {
17
+ readonly target?: 'inbound';
18
+ }>): Readonly<Extract<FeatureMiddlewareDefinition<TInput, TConfig>, {
19
+ readonly target: 'inbound';
20
+ }>>;
@@ -1,2 +1,6 @@
1
- /** Authoring API for Middleware Feature — implementation in `@zhin.js/middleware`. */
2
- export * from '@zhin.js/middleware';
1
+ import { defineMiddleware as defineFeatureMiddleware, } from '@zhin.js/middleware';
2
+ export function defineMiddleware(definition) {
3
+ // Both overloads deliberately delegate the same validation and feature brand.
4
+ const define = defineFeatureMiddleware;
5
+ return define(definition);
6
+ }
@@ -0,0 +1,83 @@
1
+ import type { JSX as BaseJSX, JSXAttributes, HtmlProps } from '@zhin.js/jsx';
2
+ import type { MediaRef, ForwardSegment, ShareSegment } from '@zhin.js/im-contract';
3
+ import type { ButtonProps, ImageProps, MentionProps, FaceProps, TextProps, MarkdownProps } from './message-tags.js';
4
+ import type { AudioSegment, VideoSegment, FileSegment } from '../built/segment-contract/types.js';
5
+ import type { KeyboardSegmentData, ActionSegmentData } from '../built/interactive-segments/types.js';
6
+ type MediaProps = {
7
+ readonly media: MediaRef;
8
+ readonly duration?: number;
9
+ readonly alt?: string;
10
+ readonly name?: string;
11
+ };
12
+ type HtmlInputProps = Omit<HtmlProps, 'children'> & ({
13
+ readonly html: string;
14
+ readonly children?: never;
15
+ } | {
16
+ readonly children?: HtmlProps['children'];
17
+ readonly html?: never;
18
+ });
19
+ /** Lowercase tags mirror Segment.type and its data fields, with typed creation helpers. */
20
+ export interface MessageTagProps {
21
+ text: TextProps;
22
+ image: ImageProps | {
23
+ readonly media: MediaRef;
24
+ readonly alt?: string;
25
+ };
26
+ mention: MentionProps;
27
+ face: FaceProps;
28
+ audio: AudioSegment['data'];
29
+ video: VideoSegment['data'];
30
+ file: FileSegment['data'];
31
+ record: MediaProps;
32
+ voice: MediaProps;
33
+ reply: {
34
+ readonly message_id: string;
35
+ };
36
+ forward: ForwardSegment['data'];
37
+ share: ShareSegment['data'];
38
+ dice: {
39
+ readonly result?: number;
40
+ };
41
+ rps: {
42
+ readonly result?: number;
43
+ };
44
+ card: Readonly<Record<string, unknown>> & {
45
+ readonly children?: never;
46
+ };
47
+ button: ButtonProps;
48
+ keyboard: KeyboardSegmentData;
49
+ action: ActionSegmentData;
50
+ html: HtmlInputProps;
51
+ markdown: MarkdownProps;
52
+ link: {
53
+ readonly url: string;
54
+ readonly text?: string;
55
+ };
56
+ qrcode: {
57
+ readonly text: string;
58
+ readonly width?: number;
59
+ readonly margin?: number;
60
+ readonly errorCorrectionLevel?: 'L' | 'M' | 'Q' | 'H';
61
+ readonly small?: boolean;
62
+ };
63
+ tts: {
64
+ readonly text: string;
65
+ readonly voice?: string;
66
+ readonly provider?: string;
67
+ };
68
+ }
69
+ /** Compiler namespace shared by both production and development runtime entrypoints. */
70
+ export declare namespace JSX {
71
+ type Element = BaseJSX.Element;
72
+ type ElementType = BaseJSX.ElementType;
73
+ interface ElementChildrenAttribute {
74
+ children: {};
75
+ }
76
+ interface IntrinsicAttributes {
77
+ key?: string | number;
78
+ }
79
+ interface IntrinsicElements extends MessageTagProps {
80
+ [name: string]: JSXAttributes | MessageTagProps[keyof MessageTagProps];
81
+ }
82
+ }
83
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,13 @@
1
+ import { type JSXRenderable, type JSXProps } from '@zhin.js/jsx';
2
+ import type { Segment } from '@zhin.js/im-contract';
3
+ import { type ButtonProps } from './message-tags.js';
4
+ /** Native and namespaced extension tags do not use ComponentIndex. */
5
+ export declare function isNativeMessageTag(type: string): boolean;
6
+ export interface MessageRenderOptions {
7
+ readonly maxDepth?: number;
8
+ readonly signal?: AbortSignal;
9
+ readonly bindButton?: (props: ButtonProps) => Segment;
10
+ readonly renderComponent?: (name: string, props: JSXProps) => Promise<JSXRenderable>;
11
+ }
12
+ /** Default JSX lays out ordered message segments. Only Html changes to HTML semantics. */
13
+ export declare function renderToSegments(node: JSXRenderable, options?: MessageRenderOptions): Promise<readonly Segment[]>;
@@ -0,0 +1,128 @@
1
+ import { Fragment, Html, isJsxElement, renderToHtml } from '@zhin.js/jsx';
2
+ import { segment } from '../utils.js';
3
+ import { isSegmentContent } from '../plugin-runtime/im/contracts.js';
4
+ import { Image } from './message-tags.js';
5
+ import { isKeyboardSegment } from '../built/interactive-segments/types.js';
6
+ const MESSAGE_TAGS = new Set([
7
+ 'text', 'mention', 'image', 'audio', 'video', 'file', 'reply', 'forward', 'face',
8
+ 'dice', 'rps', 'share', 'card', 'action', 'html', 'keyboard', 'link', 'markdown',
9
+ 'qrcode', 'record', 'tts', 'voice',
10
+ ]);
11
+ /** Native and namespaced extension tags do not use ComponentIndex. */
12
+ export function isNativeMessageTag(type) {
13
+ return type === 'button' || MESSAGE_TAGS.has(type) || /^[a-z][a-z0-9-]*(?::[a-z][a-z0-9-]*)+$/.test(type);
14
+ }
15
+ /** Default JSX lays out ordered message segments. Only Html changes to HTML semantics. */
16
+ export async function renderToSegments(node, options = {}) {
17
+ const maxDepth = options.maxDepth ?? 100;
18
+ if (!Number.isSafeInteger(maxDepth) || maxDepth < 1)
19
+ throw new RangeError('JSX maxDepth must be a positive integer');
20
+ const ancestors = new WeakSet();
21
+ const output = [];
22
+ let lastButtonIndex = -1;
23
+ const render = async (value, depth) => {
24
+ options.signal?.throwIfAborted();
25
+ if (depth > maxDepth)
26
+ throw new RangeError(`JSX exceeds maximum render depth ${maxDepth}`);
27
+ if (value == null || typeof value === 'boolean')
28
+ return;
29
+ if (typeof value === 'string' || typeof value === 'number') {
30
+ if (value !== '')
31
+ output.push(segment.text(String(value)));
32
+ return;
33
+ }
34
+ if (typeof value !== 'object')
35
+ throw new TypeError('Unsupported JSX child');
36
+ if (ancestors.has(value))
37
+ throw new TypeError('Circular JSX tree');
38
+ ancestors.add(value);
39
+ try {
40
+ if (Array.isArray(value)) {
41
+ for (const child of value)
42
+ await render(child, depth + 1);
43
+ }
44
+ else if ('then' in value && typeof value.then === 'function') {
45
+ const then = value.then;
46
+ const resolved = await new Promise((resolve, reject) => {
47
+ then.call(value, (child) => resolve({ node: child }), reject);
48
+ });
49
+ await render(resolved.node, depth + 1);
50
+ }
51
+ else if (isJsxElement(value)) {
52
+ const { type, props } = value;
53
+ if (type === Fragment)
54
+ await render(props.children, depth + 1);
55
+ else if (type === Html || type === 'html') {
56
+ if (props.html !== undefined && props.children !== undefined)
57
+ throw new TypeError('Html accepts html or children, not both');
58
+ if (props.html !== undefined && typeof props.html !== 'string')
59
+ throw new TypeError('Html html must be a string');
60
+ const html = typeof props.html === 'string' ? props.html
61
+ : await renderToHtml(props.children, { maxDepth: Math.max(1, maxDepth - depth) });
62
+ const { width, backgroundColor, fileName, text } = props;
63
+ if (html || text)
64
+ output.push(segment.html({ html,
65
+ ...(width === undefined ? {} : { width }),
66
+ ...(backgroundColor === undefined ? {} : { backgroundColor }),
67
+ ...(fileName === undefined ? {} : { fileName }),
68
+ ...(text === undefined ? {} : { text }),
69
+ }));
70
+ }
71
+ else if (typeof type === 'function')
72
+ await render(type(props), depth + 1);
73
+ else if (type === 'image' && 'src' in props)
74
+ await render(Image(props), depth + 1);
75
+ else if (type === 'button') {
76
+ if (!options.bindButton)
77
+ throw new TypeError('Button requires an active IM runtime');
78
+ const button = options.bindButton(props);
79
+ const previous = output[lastButtonIndex];
80
+ if (lastButtonIndex === output.length - 1 && isKeyboardSegment(previous) && isKeyboardSegment(button)) {
81
+ output[lastButtonIndex] = { type: 'keyboard', data: { rows: [[...previous.data.rows.flat(), ...button.data.rows.flat()]] } };
82
+ }
83
+ else {
84
+ output.push(button);
85
+ lastButtonIndex = output.length - 1;
86
+ }
87
+ }
88
+ else if (typeof type === 'string' && isNativeMessageTag(type)) {
89
+ const { children, ...data } = props;
90
+ if ((type === 'text' || type === 'markdown') && children !== undefined) {
91
+ const field = type === 'text' ? 'text' : 'content';
92
+ if (data[field] !== undefined)
93
+ throw new TypeError(`${type} accepts ${field} or children, not both`);
94
+ const start = output.length;
95
+ await render(children, depth + 1);
96
+ const parts = output.splice(start);
97
+ if (!parts.every((part) => part.type === 'text' && 'text' in part.data && typeof part.data.text === 'string')) {
98
+ throw new TypeError(`${type} children must produce text segments`);
99
+ }
100
+ const text = parts.map(part => part.data.text).join('');
101
+ if (text)
102
+ output.push(segment(type, { ...data, [field]: text }));
103
+ }
104
+ else {
105
+ if (children !== undefined)
106
+ throw new TypeError(`Message tag ${type} stores content in its data props, not children`);
107
+ output.push(segment(type, data));
108
+ }
109
+ }
110
+ else if (typeof type === 'string' && options.renderComponent) {
111
+ await render(await options.renderComponent(type, props), depth + 1);
112
+ }
113
+ else
114
+ throw new TypeError(`Unknown message tag ${String(type)}; register a component or wrap HTML in <html>`);
115
+ }
116
+ else if (isSegmentContent(value))
117
+ output.push(value);
118
+ else
119
+ throw new TypeError('Unsupported JSX child: expected a JSX element or Segment');
120
+ }
121
+ finally {
122
+ ancestors.delete(value);
123
+ }
124
+ options.signal?.throwIfAborted();
125
+ };
126
+ await render(node, 0);
127
+ return output;
128
+ }
@@ -0,0 +1,126 @@
1
+ import { type JSXElement, type JSXRenderable } from '@zhin.js/jsx';
2
+ import type { MediaRef, Segment } from '@zhin.js/im-contract';
3
+ import type { Message, SendContent } from '../plugin-runtime/im/contracts.js';
4
+ import type { ButtonData } from '../built/interactive-segments/types.js';
5
+ export type TextProps = {
6
+ readonly text: string;
7
+ readonly children?: never;
8
+ } | {
9
+ readonly children: JSXRenderable;
10
+ readonly text?: never;
11
+ };
12
+ export declare function Text(props: TextProps): JSXElement;
13
+ export interface ImageProps {
14
+ readonly src: string | MediaRef;
15
+ readonly alt?: string;
16
+ }
17
+ /** URLs and local paths are convenient sources; opaque platform IDs use MediaRef. */
18
+ export declare function Image({ src, alt }: ImageProps): JSXElement;
19
+ export interface MentionProps {
20
+ readonly target: string;
21
+ readonly name?: string;
22
+ }
23
+ export declare function Mention(props: MentionProps): JSXElement;
24
+ export interface FaceProps {
25
+ readonly id: string | number;
26
+ readonly name?: string;
27
+ }
28
+ export declare function Face(props: FaceProps): JSXElement;
29
+ export type MarkdownProps = ({
30
+ readonly content: string;
31
+ readonly children?: never;
32
+ } | {
33
+ readonly children: JSXRenderable;
34
+ readonly content?: never;
35
+ }) & {
36
+ readonly width?: number;
37
+ readonly backgroundColor?: string;
38
+ readonly fileName?: string;
39
+ };
40
+ export declare function Markdown(props: MarkdownProps): JSXElement;
41
+ /** Platform-native payload; no HTML serialization or cross-platform card schema. */
42
+ export interface CardProps {
43
+ readonly data: Readonly<Record<string, unknown>>;
44
+ }
45
+ export declare function Card({ data }: CardProps): Segment;
46
+ export type ButtonClickResult = SendContent | number | boolean | null | void;
47
+ export type ButtonClickHandler = (message: Message) => ButtonClickResult | Promise<ButtonClickResult>;
48
+ export type ButtonProps = Omit<ButtonData, 'id' | 'label' | 'payload'> & {
49
+ readonly id?: string;
50
+ } & ({
51
+ readonly label: string;
52
+ readonly children?: never;
53
+ } | {
54
+ readonly children: string;
55
+ readonly label?: never;
56
+ }) & ({
57
+ readonly onClick: ButtonClickHandler;
58
+ readonly payload?: never;
59
+ } | {
60
+ readonly payload: string;
61
+ readonly onClick?: never;
62
+ });
63
+ /** Event handlers are bound by the active IM operation, never serialized onto the wire. */
64
+ export declare function Button(props: ButtonProps): JSXElement;
65
+ export declare const Audio: (props: {
66
+ media: MediaRef;
67
+ duration?: number;
68
+ }) => JSXElement;
69
+ export declare const Video: (props: {
70
+ media: MediaRef;
71
+ duration?: number;
72
+ alt?: string;
73
+ }) => JSXElement;
74
+ export declare const File: (props: {
75
+ media: MediaRef;
76
+ name?: string;
77
+ }) => JSXElement;
78
+ export declare const Reply: (props: {
79
+ readonly message_id: string;
80
+ }) => JSXElement;
81
+ export declare const Forward: (props: Readonly<{
82
+ forward_id: string;
83
+ title?: string;
84
+ entries?: readonly import("@zhin.js/im-contract").ForwardEntry[];
85
+ }>) => JSXElement;
86
+ export declare const Share: (props: Readonly<{
87
+ url: string;
88
+ title: string;
89
+ description?: string;
90
+ image?: string;
91
+ audio?: string;
92
+ content?: string;
93
+ artist?: string;
94
+ duration?: number;
95
+ config?: Readonly<{
96
+ appid: number;
97
+ package?: string;
98
+ sign?: string;
99
+ icon?: string;
100
+ version?: string;
101
+ }>;
102
+ }>) => JSXElement;
103
+ export declare const Dice: (props: {
104
+ readonly result?: number;
105
+ }) => JSXElement;
106
+ export declare const Rps: (props: {
107
+ readonly result?: number;
108
+ }) => JSXElement;
109
+ export declare const Keyboard: (props: import("../index.js").KeyboardSegmentData) => JSXElement;
110
+ export declare const Action: (props: import("../index.js").ActionSegmentData) => JSXElement;
111
+ export declare const Link: (props: {
112
+ readonly url: string;
113
+ readonly text?: string;
114
+ }) => JSXElement;
115
+ export declare const Qrcode: (props: {
116
+ readonly text: string;
117
+ readonly width?: number;
118
+ readonly margin?: number;
119
+ readonly errorCorrectionLevel?: "L" | "M" | "Q" | "H";
120
+ readonly small?: boolean;
121
+ }) => JSXElement;
122
+ export declare const Tts: (props: {
123
+ readonly text: string;
124
+ readonly voice?: string;
125
+ readonly provider?: string;
126
+ }) => JSXElement;
@@ -0,0 +1,47 @@
1
+ import { jsx } from '@zhin.js/jsx';
2
+ export function Text(props) {
3
+ return jsx('text', { ...props });
4
+ }
5
+ /** URLs and local paths are convenient sources; opaque platform IDs use MediaRef. */
6
+ export function Image({ src, alt }) {
7
+ let media;
8
+ if (typeof src !== 'string')
9
+ media = src;
10
+ else if (/^https?:\/\//i.test(src))
11
+ media = { kind: 'url', value: src };
12
+ else if (src.startsWith('base64://'))
13
+ media = { kind: 'base64', value: src.slice(9) };
14
+ else if (src.startsWith('data:')) {
15
+ const match = /^data:([^;,]+)(?:;[^;,]*)*;base64,([\s\S]+)$/i.exec(src);
16
+ if (!match)
17
+ throw new TypeError('Image data URI must contain base64 media');
18
+ media = { kind: 'base64', value: match[2], mime_type: match[1] };
19
+ }
20
+ else
21
+ media = { kind: 'path', value: src };
22
+ return jsx('image', { media, ...(alt === undefined ? {} : { alt }) });
23
+ }
24
+ export function Mention(props) { return jsx('mention', { ...props }); }
25
+ export function Face(props) { return jsx('face', { ...props }); }
26
+ export function Markdown(props) {
27
+ return jsx('markdown', { ...props });
28
+ }
29
+ export function Card({ data }) { return { type: 'card', data }; }
30
+ /** Event handlers are bound by the active IM operation, never serialized onto the wire. */
31
+ export function Button(props) { return jsx('button', { ...props }); }
32
+ function nativeTag(type) {
33
+ return (props) => jsx(type, { ...props });
34
+ }
35
+ export const Audio = nativeTag('audio');
36
+ export const Video = nativeTag('video');
37
+ export const File = nativeTag('file');
38
+ export const Reply = nativeTag('reply');
39
+ export const Forward = nativeTag('forward');
40
+ export const Share = nativeTag('share');
41
+ export const Dice = nativeTag('dice');
42
+ export const Rps = nativeTag('rps');
43
+ export const Keyboard = nativeTag('keyboard');
44
+ export const Action = nativeTag('action');
45
+ export const Link = nativeTag('link');
46
+ export const Qrcode = nativeTag('qrcode');
47
+ export const Tts = nativeTag('tts');
@@ -1 +1,2 @@
1
- export * from '@zhin.js/jsx/jsx-dev-runtime';
1
+ export { Fragment, jsxDEV } from '@zhin.js/jsx/jsx-dev-runtime';
2
+ export type { JSX } from './jsx/intrinsic-elements.js';
@@ -1 +1 @@
1
- export * from '@zhin.js/jsx/jsx-dev-runtime';
1
+ export { Fragment, jsxDEV } from '@zhin.js/jsx/jsx-dev-runtime';
@@ -1 +1,2 @@
1
- export * from '@zhin.js/jsx/jsx-runtime';
1
+ export { Fragment, jsx, jsxs } from '@zhin.js/jsx/jsx-runtime';
2
+ export type { JSX } from './jsx/intrinsic-elements.js';
@@ -1 +1 @@
1
- export * from '@zhin.js/jsx/jsx-runtime';
1
+ export { Fragment, jsx, jsxs } from '@zhin.js/jsx/jsx-runtime';
package/lib/jsx.d.ts CHANGED
@@ -1 +1,6 @@
1
1
  export * from '@zhin.js/jsx';
2
+ export { Image, Mention, Card, Button, Markdown, Face, Text, Audio, Video, File, Reply, Forward, Share, Dice, Rps, Keyboard, Action, Link, Qrcode, Tts } from './jsx/message-tags.js';
3
+ export type { ImageProps, MentionProps, CardProps, ButtonProps, ButtonClickHandler, ButtonClickResult, MarkdownProps, FaceProps, TextProps } from './jsx/message-tags.js';
4
+ export { renderToSegments } from './jsx/message-renderer.js';
5
+ export type { MessageRenderOptions } from './jsx/message-renderer.js';
6
+ export type { JSX, MessageTagProps } from './jsx/intrinsic-elements.js';
package/lib/jsx.js CHANGED
@@ -1 +1,3 @@
1
1
  export * from '@zhin.js/jsx';
2
+ export { Image, Mention, Card, Button, Markdown, Face, Text, Audio, Video, File, Reply, Forward, Share, Dice, Rps, Keyboard, Action, Link, Qrcode, Tts } from './jsx/message-tags.js';
3
+ export { renderToSegments } from './jsx/message-renderer.js';
@@ -2,6 +2,7 @@ import type { JSXElement } from '@zhin.js/jsx';
2
2
  import type { PluginId, RuntimeSnapshot } from '@zhin.js/plugin-runtime';
3
3
  import { operationInputBinding } from '@zhin.js/feature-kit';
4
4
  import type { ConversationRef, DeliveryReceipt, MessageRef } from '@zhin.js/im-contract';
5
+ import type { MessageOrigin } from './inbound-origin.js';
5
6
  import type { MediaRef, Segment } from '../../built/segment-contract/types.js';
6
7
  export type { MediaRef, Segment };
7
8
  declare const componentCallBrand: "zhin.component-call/1";
@@ -101,6 +102,12 @@ export interface OutboundMessageService {
101
102
  }
102
103
  export interface MessageDispatchResult {
103
104
  readonly matched: boolean;
105
+ readonly status?: 'unmatched' | 'invalid' | 'denied' | 'executed';
106
+ readonly issues?: readonly Readonly<{
107
+ field: string;
108
+ message: string;
109
+ }>[];
110
+ readonly help?: string;
104
111
  readonly command?: string;
105
112
  readonly owner?: PluginId;
106
113
  readonly value?: unknown;
@@ -111,6 +118,11 @@ export interface MessageBase extends IncomingMessage {
111
118
  readonly metadata: Readonly<Record<string, unknown>>;
112
119
  readonly id?: string;
113
120
  readonly clientAdapter?: string;
121
+ /**
122
+ * 入站来源(self / member / peer_bot / human),仅由 InboundRuntime 可信判定写入;
123
+ * 合成消息(Console / Sandbox / 定时任务)为 undefined。绝不从 metadata / 正文读取。
124
+ */
125
+ readonly origin?: MessageOrigin;
114
126
  readonly $client: unknown;
115
127
  readonly $reply: (content: SendContent) => Promise<DeliveryReceipt>;
116
128
  readonly $replyFrom: (requester: PluginId, content: SendContent) => Promise<DeliveryReceipt>;
@@ -145,6 +157,7 @@ export declare class RuntimeMessage implements MessageBase {
145
157
  readonly id: string;
146
158
  } | undefined;
147
159
  readonly clientAdapter?: string | undefined;
160
+ readonly origin?: MessageOrigin;
148
161
  /** @internal Constructed only by the generation-owned IM Runtime. */
149
162
  constructor(conversation: ConversationRef, content: string, generation: number, reply: (content: SendContent, requester?: PluginId, targetConversation?: ConversationAddress) => Promise<DeliveryReceipt>, sender?: MessageSenderRef | undefined, metadata?: Readonly<Record<string, unknown>>,
150
163
  /**
@@ -159,6 +172,7 @@ export declare class RuntimeMessage implements MessageBase {
159
172
  requester?: PluginId;
160
173
  snapshot?: RuntimeSnapshot;
161
174
  assertActive?: () => void;
175
+ origin?: MessageOrigin;
162
176
  }>);
163
177
  /** @internal A frozen view whose sends retain the current author's exact operation. */
164
178
  [operationInputBinding](owner: PluginId, snapshot: RuntimeSnapshot): RuntimeMessage;
@@ -51,6 +51,7 @@ export class RuntimeMessage {
51
51
  #author;
52
52
  #snapshot;
53
53
  #assertActive;
54
+ origin;
54
55
  /** @internal Constructed only by the generation-owned IM Runtime. */
55
56
  constructor(conversation, content, generation, reply, sender, metadata = Object.freeze({}),
56
57
  /**
@@ -73,6 +74,7 @@ export class RuntimeMessage {
73
74
  this.mentioned = mentioned;
74
75
  this.replyTo = replyTo;
75
76
  this.clientAdapter = clientAdapter;
77
+ this.origin = binding.origin;
76
78
  this.#resolveClient = client;
77
79
  this.#reply = reply;
78
80
  this.#author = binding.requester;
@@ -124,7 +126,7 @@ export class RuntimeMessage {
124
126
  throw new Error(`Unknown Message author: ${owner}`);
125
127
  if (this.#author === owner && this.#snapshot === snapshot)
126
128
  return this;
127
- return new RuntimeMessage(this.conversation, this.content, this.generation, this.#reply, this.sender, this.metadata, this.segments, this.message, this.endpointId, this.mentioned, this.replyTo, this.#resolveClient, this.clientAdapter, { requester: owner, snapshot, assertActive: this.#assertActive });
129
+ return new RuntimeMessage(this.conversation, this.content, this.generation, this.#reply, this.sender, this.metadata, this.segments, this.message, this.endpointId, this.mentioned, this.replyTo, this.#resolveClient, this.clientAdapter, { requester: owner, snapshot, assertActive: this.#assertActive, origin: this.origin });
128
130
  }
129
131
  /** 平台原生消息 id(`message` 未提供时为 undefined)。 */
130
132
  get id() {
@@ -1,6 +1,11 @@
1
- import { type ConversationContextBlock, type ConversationEventReader, type ConversationEventStore, type ConversationReference, type ConversationResolution, type ConversationRef, type DeliveryReceipt } from '@zhin.js/im-contract';
1
+ import { type ConversationContextBlock, type ConversationEventReader, type ConversationEventStore, type ConversationReference, type ConversationResolution, type ConversationRef, type DeliveryReceipt, type MessageRef } from '@zhin.js/im-contract';
2
2
  import type { Notice } from '../../notice.js';
3
3
  import type { IncomingMessage, MessageSenderRef, SendRequest } from './contracts.js';
4
+ /**
5
+ * Backlog messages older than this are dropped from the next turn's context:
6
+ * a stale command from hours ago is not something the current reply should answer.
7
+ */
8
+ export declare const CONVERSATION_CONTEXT_MAX_AGE_MS: number;
4
9
  /** Owns one ImRuntime's conversation fact store, projections, and consumer cursors. */
5
10
  export declare class ConversationRuntime {
6
11
  #private;
@@ -12,6 +17,13 @@ export declare class ConversationRuntime {
12
17
  blocks: readonly ConversationContextBlock[];
13
18
  cursor: number;
14
19
  }>>;
20
+ /**
21
+ * An answer to an interaction prompt (an approval `y`, a menu choice) was
22
+ * already handled by that prompt; replaying it as background would invite
23
+ * the model to answer it again. Kept in memory and bounded: the context age
24
+ * window makes older answers irrelevant anyway.
25
+ */
26
+ markInteractionAnswer(message: MessageRef): void;
15
27
  commitContext(conversation: ConversationRef, consumer: string, cursor: number): Promise<void>;
16
28
  recordIncoming(input: IncomingMessage, sender: MessageSenderRef | undefined): Promise<number | undefined>;
17
29
  recordOutbound(request: SendRequest, receipt: DeliveryReceipt): Promise<void>;