@kyyinfinite/zapo-message 0.0.0-stage → 1.0.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.
Files changed (191) hide show
  1. package/CHANGELOG.md +159 -0
  2. package/LICENSE +20 -0
  3. package/README.md +532 -2
  4. package/build.config.json +28 -0
  5. package/dist/airich/airich.d.ts +180 -0
  6. package/dist/airich/airich.js +548 -0
  7. package/dist/airich/context.d.ts +24 -0
  8. package/dist/airich/context.js +48 -0
  9. package/dist/airich/encode.d.ts +3 -0
  10. package/dist/airich/encode.js +16 -0
  11. package/dist/airich/index.d.ts +20 -0
  12. package/dist/airich/index.js +11 -0
  13. package/dist/airich/inline.d.ts +45 -0
  14. package/dist/airich/inline.js +152 -0
  15. package/dist/airich/nodes.d.ts +30 -0
  16. package/dist/airich/nodes.js +121 -0
  17. package/dist/airich/primitives.d.ts +144 -0
  18. package/dist/airich/primitives.js +230 -0
  19. package/dist/airich/protocol.d.ts +35 -0
  20. package/dist/airich/protocol.js +65 -0
  21. package/dist/airich/table.d.ts +22 -0
  22. package/dist/airich/table.js +35 -0
  23. package/dist/airich/tokenizer.d.ts +13 -0
  24. package/dist/airich/tokenizer.js +717 -0
  25. package/dist/airich/transport.d.ts +15 -0
  26. package/dist/airich/transport.js +56 -0
  27. package/dist/branding.d.ts +5 -0
  28. package/dist/branding.js +9 -0
  29. package/dist/btn/builders.d.ts +246 -0
  30. package/dist/btn/builders.js +710 -0
  31. package/dist/btn/media-slot.d.ts +28 -0
  32. package/dist/btn/media-slot.js +323 -0
  33. package/dist/btn/media-source.d.ts +38 -0
  34. package/dist/btn/media-source.js +116 -0
  35. package/dist/btn/sharp-loader.d.ts +5 -0
  36. package/dist/btn/sharp-loader.js +18 -0
  37. package/dist/btn/thumbnail.d.ts +21 -0
  38. package/dist/btn/thumbnail.js +124 -0
  39. package/dist/btn/validators.d.ts +40 -0
  40. package/dist/btn/validators.js +135 -0
  41. package/dist/btn.d.ts +1 -0
  42. package/dist/btn.js +1 -0
  43. package/dist/core/async-send.d.ts +20 -0
  44. package/dist/core/async-send.js +1 -0
  45. package/dist/core/base-builder.d.ts +20 -0
  46. package/dist/core/base-builder.js +67 -0
  47. package/dist/core/errors.d.ts +30 -0
  48. package/dist/core/errors.js +61 -0
  49. package/dist/download.d.ts +24 -0
  50. package/dist/download.js +123 -0
  51. package/dist/index.d.ts +38 -0
  52. package/dist/index.js +22 -0
  53. package/dist/integration/augment.d.ts +97 -0
  54. package/dist/integration/augment.js +1 -0
  55. package/dist/integration/auto.d.ts +8 -0
  56. package/dist/integration/auto.js +79 -0
  57. package/dist/integration/index.d.ts +4 -0
  58. package/dist/integration/index.js +2 -0
  59. package/dist/integration/methods.d.ts +25 -0
  60. package/dist/integration/methods.js +24 -0
  61. package/dist/interactive.d.ts +24 -0
  62. package/dist/interactive.js +121 -0
  63. package/dist/media-gate.d.ts +99 -0
  64. package/dist/media-gate.js +322 -0
  65. package/dist/message/album.d.ts +33 -0
  66. package/dist/message/album.js +107 -0
  67. package/dist/message/contact.d.ts +29 -0
  68. package/dist/message/contact.js +123 -0
  69. package/dist/message/forward.d.ts +23 -0
  70. package/dist/message/forward.js +77 -0
  71. package/dist/message/index.d.ts +26 -0
  72. package/dist/message/index.js +13 -0
  73. package/dist/message/link-preview.d.ts +28 -0
  74. package/dist/message/link-preview.js +98 -0
  75. package/dist/message/location.d.ts +24 -0
  76. package/dist/message/location.js +94 -0
  77. package/dist/message/media.d.ts +90 -0
  78. package/dist/message/media.js +123 -0
  79. package/dist/message/poll.d.ts +24 -0
  80. package/dist/message/poll.js +98 -0
  81. package/dist/message/reaction.d.ts +20 -0
  82. package/dist/message/reaction.js +71 -0
  83. package/dist/message/sticker.d.ts +29 -0
  84. package/dist/message/sticker.js +44 -0
  85. package/dist/message/target.d.ts +18 -0
  86. package/dist/message/target.js +24 -0
  87. package/dist/message/text.d.ts +17 -0
  88. package/dist/message/text.js +29 -0
  89. package/dist/message/vcard.d.ts +9 -0
  90. package/dist/message/vcard.js +23 -0
  91. package/dist/message/webp.d.ts +6 -0
  92. package/dist/message/webp.js +57 -0
  93. package/dist/payloads.d.ts +180 -0
  94. package/dist/payloads.js +1 -0
  95. package/dist/serialize.d.ts +41 -0
  96. package/dist/serialize.js +93 -0
  97. package/dist/status.d.ts +3 -0
  98. package/dist/status.js +21 -0
  99. package/dist/zapo-client.d.ts +44 -0
  100. package/dist/zapo-client.js +1 -0
  101. package/examples/airich.ts +59 -0
  102. package/examples/buttons.ts +48 -0
  103. package/examples/client-methods.ts +58 -0
  104. package/examples/hybrid.ts +133 -0
  105. package/examples/serialize.ts +61 -0
  106. package/package.json +271 -4
  107. package/scripts/check-no-comments.mjs +101 -0
  108. package/scripts/compare-golden.mjs +461 -0
  109. package/scripts/lib-config.mjs +9 -0
  110. package/scripts/smoke-auto.mjs +75 -0
  111. package/scripts/test-external-consumer.mjs +316 -0
  112. package/scripts/verify-package.mjs +78 -0
  113. package/src/airich/airich.ts +970 -0
  114. package/src/airich/context.ts +96 -0
  115. package/src/airich/encode.ts +25 -0
  116. package/src/airich/index.ts +98 -0
  117. package/src/airich/inline.ts +272 -0
  118. package/src/airich/nodes.ts +174 -0
  119. package/src/airich/primitives.ts +474 -0
  120. package/src/airich/protocol.ts +133 -0
  121. package/src/airich/table.ts +70 -0
  122. package/src/airich/tokenizer.ts +799 -0
  123. package/src/airich/transport.ts +106 -0
  124. package/src/branding.ts +23 -0
  125. package/src/btn/builders.ts +1073 -0
  126. package/src/btn/media-slot.ts +486 -0
  127. package/src/btn/media-source.ts +189 -0
  128. package/src/btn/sharp-loader.ts +23 -0
  129. package/src/btn/thumbnail.ts +182 -0
  130. package/src/btn/validators.ts +237 -0
  131. package/src/btn.ts +8 -0
  132. package/src/core/async-send.ts +28 -0
  133. package/src/core/base-builder.ts +104 -0
  134. package/src/core/errors.ts +82 -0
  135. package/src/download.ts +212 -0
  136. package/src/index.ts +229 -0
  137. package/src/integration/augment.ts +262 -0
  138. package/src/integration/auto.ts +103 -0
  139. package/src/integration/index.ts +8 -0
  140. package/src/integration/methods.ts +45 -0
  141. package/src/interactive.ts +188 -0
  142. package/src/media-gate.ts +499 -0
  143. package/src/message/album.ts +187 -0
  144. package/src/message/contact.ts +170 -0
  145. package/src/message/forward.ts +123 -0
  146. package/src/message/index.ts +83 -0
  147. package/src/message/link-preview.ts +148 -0
  148. package/src/message/location.ts +150 -0
  149. package/src/message/media.ts +323 -0
  150. package/src/message/poll.ts +158 -0
  151. package/src/message/reaction.ts +133 -0
  152. package/src/message/sticker.ts +100 -0
  153. package/src/message/target.ts +38 -0
  154. package/src/message/text.ts +61 -0
  155. package/src/message/vcard.ts +36 -0
  156. package/src/message/webp.ts +78 -0
  157. package/src/payloads.ts +204 -0
  158. package/src/serialize.ts +180 -0
  159. package/src/status.ts +29 -0
  160. package/src/zapo-client.ts +84 -0
  161. package/test/airich-inline.test.ts +200 -0
  162. package/test/airich-primitives.test.ts +226 -0
  163. package/test/airich-tokenizer.test.ts +145 -0
  164. package/test/airich.golden.test.ts +406 -0
  165. package/test/airich.test.ts +1006 -0
  166. package/test/btn-button.test.ts +416 -0
  167. package/test/btn-header.test.ts +646 -0
  168. package/test/btn-legacy.test.ts +342 -0
  169. package/test/btn-lifecycle.test.ts +295 -0
  170. package/test/btn-list.test.ts +261 -0
  171. package/test/btn-media-source.test.ts +150 -0
  172. package/test/btn-thumbnail.test.ts +160 -0
  173. package/test/builder-compat.test.ts +264 -0
  174. package/test/helpers.ts +27 -0
  175. package/test/hybrid-airich.test.ts +345 -0
  176. package/test/hybrid-client.test.ts +239 -0
  177. package/test/hybrid-errors.test.ts +557 -0
  178. package/test/hybrid-interactive.test.ts +455 -0
  179. package/test/hybrid.golden.test.ts +349 -0
  180. package/test/hybrid.test.ts +479 -0
  181. package/test/integration-auto.test.ts +159 -0
  182. package/test/integration.fakeserver.test.ts +440 -0
  183. package/test/media-gate.test.ts +215 -0
  184. package/test/message-album.test.ts +145 -0
  185. package/test/message-builders.test.ts +401 -0
  186. package/test/message-media.test.ts +303 -0
  187. package/test/message.fakeserver.test.ts +284 -0
  188. package/test/message.golden.test.ts +254 -0
  189. package/test/serializer.test.ts +448 -0
  190. package/tsconfig.json +26 -0
  191. package/tsconfig.test.json +10 -0
@@ -0,0 +1,180 @@
1
+ import type { Proto } from "zapo-js";
2
+ import { BaseBuilder, type SendResolutionArg } from "../core/base-builder.js";
3
+ import { type MessageSendOptions } from "../core/async-send.js";
4
+ import type { MessageSendResult } from "../zapo-client.js";
5
+ import type { SubmessagePayload, WrapBotForwardedResult, PlaceholderBuildResult, EditBuildResult } from "../payloads.js";
6
+ import type { ZapoClient } from "../zapo-client.js";
7
+ import { type ParseInlineOptions } from "./inline.js";
8
+ import { type AllowedContextInfo } from "./context.js";
9
+ import { type UnifiedResponseSection } from "./protocol.js";
10
+ import { type SourceInput, type ImageSectionOptions, type VideoSectionOptions, type FooterActionItem, type WidgetItem, type ProductItem, type PostItem, type ReelsItem, type SectionLayoutOptions, type HtmlSectionOptions } from "./primitives.js";
11
+ export interface AIRichConstructorOptions {
12
+ botJid?: string | undefined;
13
+ }
14
+ export interface RawNodeOptions {
15
+ id?: string | null | undefined;
16
+ }
17
+ export interface InsertNodeOptions extends RawNodeOptions {
18
+ after?: boolean | undefined;
19
+ }
20
+ export interface QuotableMessage {
21
+ key?: {
22
+ id?: string;
23
+ participant?: string;
24
+ remoteJid?: string;
25
+ };
26
+ id?: string;
27
+ message?: Proto.IMessage | Record<string, unknown>;
28
+ }
29
+ export type RichTarget = string | number;
30
+ export declare class AIRich extends BaseBuilder {
31
+ #private;
32
+ constructor(client?: ZapoClient, { botJid }?: AIRichConstructorOptions);
33
+ get lastId(): string | null;
34
+ get size(): number;
35
+ ids(): string[];
36
+ has(id: string): boolean;
37
+ pendingEdit(jid: string): string | null;
38
+ raw(section: UnifiedResponseSection, submessage?: SubmessagePayload, { id }?: RawNodeOptions): this;
39
+ replace(target: RichTarget, section: UnifiedResponseSection, submessage?: SubmessagePayload, { id }?: RawNodeOptions): this;
40
+ insert(target: RichTarget, section: UnifiedResponseSection, submessage?: SubmessagePayload, { id, after }?: InsertNodeOptions): this;
41
+ insertAt(index: number, section: UnifiedResponseSection, submessage?: SubmessagePayload, { id }?: RawNodeOptions): this;
42
+ loadPayload(payload: unknown): this;
43
+ text(text: string, { id, hyperlink, citation, latex, }?: RawNodeOptions & ParseInlineOptions): this;
44
+ code(language: string, code: string, { id }?: RawNodeOptions): this;
45
+ table(rows: string[][], { id, hyperlink, citation, latex, }?: RawNodeOptions & ParseInlineOptions): this;
46
+ metadata(text: string, { id }?: RawNodeOptions): this;
47
+ tip(text: string, { id }?: RawNodeOptions): this;
48
+ suggest(items: string | string[], { id, scroll, layout: layoutName, }?: {
49
+ id?: string | null | undefined;
50
+ scroll?: boolean | undefined;
51
+ layout?: string | undefined;
52
+ }): this;
53
+ source(sources: SourceInput[], { id, layout: layoutName }?: RawNodeOptions & SectionLayoutOptions): this;
54
+ image(url: string, { id, ...options }?: RawNodeOptions & ImageSectionOptions): this;
55
+ video(url: string, { id, ...options }?: RawNodeOptions & VideoSectionOptions): this;
56
+ footerAction(data: FooterActionItem | FooterActionItem[], { id, layout: layoutName }?: RawNodeOptions & SectionLayoutOptions): this;
57
+ widget(data: WidgetItem | WidgetItem[], { id, layout: layoutName }?: RawNodeOptions & SectionLayoutOptions): this;
58
+ product(data: ProductItem | ProductItem[], { id, layout: layoutName }?: RawNodeOptions & SectionLayoutOptions): this;
59
+ post(data: PostItem | PostItem[], { id, layout: layoutName }?: RawNodeOptions & SectionLayoutOptions): this;
60
+ reels(items: ReelsItem | ReelsItem[], { id, layout: layoutName }?: RawNodeOptions & SectionLayoutOptions): this;
61
+ html(html: string, { id, ...options }?: RawNodeOptions & HtmlSectionOptions): this;
62
+ footer(text: string): this;
63
+ context(info: AllowedContextInfo | Record<string, unknown>): this;
64
+ quote(message: QuotableMessage): this;
65
+ remove(target: RichTarget): this;
66
+ clear(): this;
67
+ build({ submessages, }?: {
68
+ submessages?: boolean;
69
+ }): WrapBotForwardedResult;
70
+ buildPlaceholder(): PlaceholderBuildResult;
71
+ buildEdit(jid: string, id: string | null, { submessages }?: {
72
+ submessages?: boolean;
73
+ }): EditBuildResult;
74
+ send(jid?: string, arg?: SendResolutionArg): Promise<unknown>;
75
+ edit(jid: string, id?: string | null, arg?: SendResolutionArg): Promise<unknown>;
76
+ }
77
+ export declare function airich(client?: ZapoClient, options?: AIRichConstructorOptions): AIRich;
78
+ export declare function airich(client: ZapoClient | undefined, jid: string, config: AIRichConfig, options?: AIRichSendOptions): Promise<MessageSendResult>;
79
+ export interface AIRichSendOptions extends MessageSendOptions {
80
+ twoStep?: boolean;
81
+ submessages?: boolean;
82
+ }
83
+ export type AIRichSectionConfig = {
84
+ type: "text";
85
+ text: string;
86
+ hyperlink?: boolean;
87
+ citation?: boolean;
88
+ latex?: boolean;
89
+ id?: string | null;
90
+ } | {
91
+ type: "code";
92
+ language: string;
93
+ code: string;
94
+ id?: string | null;
95
+ } | {
96
+ type: "table";
97
+ rows: string[][];
98
+ hyperlink?: boolean;
99
+ citation?: boolean;
100
+ latex?: boolean;
101
+ id?: string | null;
102
+ } | {
103
+ type: "metadata";
104
+ text: string;
105
+ id?: string | null;
106
+ } | {
107
+ type: "tip";
108
+ text: string;
109
+ id?: string | null;
110
+ } | {
111
+ type: "suggest";
112
+ items: string | readonly string[];
113
+ scroll?: boolean;
114
+ layout?: string;
115
+ id?: string | null;
116
+ } | {
117
+ type: "source";
118
+ sources: readonly SourceInput[];
119
+ layout?: string;
120
+ id?: string | null;
121
+ } | {
122
+ type: "image";
123
+ url: string;
124
+ width?: number;
125
+ height?: number;
126
+ status?: string;
127
+ updateText?: string;
128
+ id?: string | null;
129
+ } | {
130
+ type: "video";
131
+ url: string;
132
+ mimeType?: string;
133
+ fileLength?: number;
134
+ duration?: number;
135
+ status?: string;
136
+ id?: string | null;
137
+ } | {
138
+ type: "footerAction";
139
+ items: FooterActionItem | readonly FooterActionItem[];
140
+ layout?: string;
141
+ id?: string | null;
142
+ } | {
143
+ type: "widget";
144
+ items: WidgetItem | readonly WidgetItem[];
145
+ layout?: string;
146
+ id?: string | null;
147
+ } | {
148
+ type: "product";
149
+ items: ProductItem | readonly ProductItem[];
150
+ layout?: string;
151
+ id?: string | null;
152
+ } | {
153
+ type: "post";
154
+ items: PostItem | readonly PostItem[];
155
+ layout?: string;
156
+ id?: string | null;
157
+ } | {
158
+ type: "reels";
159
+ items: ReelsItem | readonly ReelsItem[];
160
+ layout?: string;
161
+ id?: string | null;
162
+ } | {
163
+ type: "html";
164
+ html: string;
165
+ trustedSources?: readonly unknown[];
166
+ id?: string | null;
167
+ } | {
168
+ type: "raw";
169
+ section: UnifiedResponseSection;
170
+ submessage?: SubmessagePayload;
171
+ id?: string | null;
172
+ };
173
+ export interface AIRichConfig {
174
+ sections: readonly AIRichSectionConfig[];
175
+ footer?: string;
176
+ context?: AllowedContextInfo | Record<string, unknown>;
177
+ quote?: QuotableMessage;
178
+ }
179
+ export declare const applyAIRichConfig: (builder: AIRich, config: AIRichConfig) => void;
180
+ export declare const sendAIRich: (client: ZapoClient | undefined, jid: string | undefined, config: AIRichConfig, options?: AIRichSendOptions) => Promise<MessageSendResult>;