@kyyinfinite/zapo-message 0.0.0-stage → 1.0.1

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 +1401 -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 +36 -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,406 @@
1
+ import test from "node:test";
2
+ import assert from "node:assert/strict";
3
+
4
+ import {
5
+ AIRich,
6
+ airich,
7
+ decodeUnifiedResponse,
8
+ ZWSP,
9
+ } from "@kyyinfinite/zapo-message";
10
+ import { asClient, L, A } from "./helpers.js";
11
+
12
+ const makeClient = () => {
13
+ const sends: { jid?: unknown; content?: unknown; options?: unknown }[] = [];
14
+ return {
15
+ sends,
16
+ client: asClient({
17
+ message: {
18
+ send: async (jid: unknown, content: unknown, options: unknown) => {
19
+ sends.push({ jid, content, options });
20
+ return { id: `GOLDEN_${sends.length}`, attempts: 1, ack: {} };
21
+ },
22
+ },
23
+ }),
24
+ };
25
+ };
26
+
27
+ const richOf = (payload: unknown): Record<string, unknown> =>
28
+ L(L(L(payload).botForwardedMessage).message).richResponseMessage as Record<
29
+ string,
30
+ unknown
31
+ >;
32
+
33
+ const dataOf = (payload: unknown): Uint8Array =>
34
+ L(L(richOf(payload)).unifiedResponse).data as unknown as Uint8Array;
35
+
36
+ const FIXTURE_PLACEHOLDER = {
37
+ response_id: "dc8a253b-c1ad-47bc-bb14-3670489f418c",
38
+ sections: [
39
+ {
40
+ view_model: {
41
+ primitive: { text: "​", __typename: "GenAIMarkdownTextUXPrimitive" },
42
+ __typename: "GenAISingleLayoutViewModel",
43
+ },
44
+ },
45
+ ],
46
+ };
47
+
48
+ const FIXTURE_PLACEHOLDER_CONTEXT = {
49
+ mentionedJid: [],
50
+ groupMentions: [],
51
+ statusAttributions: [],
52
+ forwardingScore: 1,
53
+ isForwarded: true,
54
+ expiration: 7776000,
55
+ ephemeralSettingTimestamp: 1773527159,
56
+ disappearingMode: { initiator: 1, trigger: 2, initiatedByMe: true },
57
+ forwardedAiBotMessageInfo: { botJid: "123456789012345@bot" },
58
+ forwardOrigin: 4,
59
+ };
60
+
61
+ const FIXTURE_EDIT_SECTIONS = [
62
+ {
63
+ view_model: {
64
+ primitive: {
65
+ text: "ini tabel rekomendasi film 3 kolom x 3 baris:",
66
+ __typename: "GenAIMarkdownTextUXPrimitive",
67
+ },
68
+ __typename: "GenAISingleLayoutViewModel",
69
+ },
70
+ },
71
+ {
72
+ view_model: {
73
+ primitive: {
74
+ rows: [
75
+ {
76
+ is_header: true,
77
+ cells: ["**Judul Film**", "**Genre**", "**Rating**"],
78
+ markdown_cells: [
79
+ { text: "**Judul Film**" },
80
+ { text: "**Genre**" },
81
+ { text: "**Rating**" },
82
+ ],
83
+ },
84
+ {
85
+ is_header: false,
86
+ cells: ["Interstellar", "Sci-Fi", "9.0/10"],
87
+ markdown_cells: [
88
+ { text: "Interstellar" },
89
+ { text: "Sci-Fi" },
90
+ { text: "9.0/10" },
91
+ ],
92
+ },
93
+ {
94
+ is_header: false,
95
+ cells: ["Inception", "Thriller", "8.8/10"],
96
+ markdown_cells: [
97
+ { text: "Inception" },
98
+ { text: "Thriller" },
99
+ { text: "8.8/10" },
100
+ ],
101
+ },
102
+ {
103
+ is_header: false,
104
+ cells: ["The Martian", "Adventure", "8.5/10"],
105
+ markdown_cells: [
106
+ { text: "The Martian" },
107
+ { text: "Adventure" },
108
+ { text: "8.5/10" },
109
+ ],
110
+ },
111
+ ],
112
+ __typename: "GenATableUXPrimitive",
113
+ },
114
+ __typename: "GenAISingleLayoutViewModel",
115
+ },
116
+ },
117
+ {
118
+ view_model: {
119
+ primitive: {
120
+ text: "Tabel ini berisi beberapa film dengan genre dan rating masing-masing.",
121
+ __typename: "GenAIMarkdownTextUXPrimitive",
122
+ },
123
+ __typename: "GenAISingleLayoutViewModel",
124
+ },
125
+ },
126
+ ];
127
+
128
+ const FIXTURE_EDIT_CONTEXT = {
129
+ forwardingScore: 1,
130
+ isForwarded: true,
131
+ forwardOrigin: 4,
132
+ };
133
+
134
+ const UUID_RE =
135
+ /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/;
136
+
137
+ test("golden: placeholder mengikuti payload botf.js msg1 (outer wrapper + nested structure)", () => {
138
+ const { client } = makeClient();
139
+ const builder = new AIRich(client, { botJid: "123456789012345@bot" });
140
+ builder.context({
141
+ mentionedJid: [],
142
+ groupMentions: [],
143
+ statusAttributions: [],
144
+ expiration: 7776000,
145
+ ephemeralSettingTimestamp: 1773527159,
146
+ disappearingMode: {
147
+ initiator: 1,
148
+ trigger: 2,
149
+ initiatedByMe: true,
150
+ } as never,
151
+ });
152
+
153
+ const payload = builder.buildPlaceholder();
154
+
155
+ assert.deepEqual(
156
+ Object.keys(payload).sort(),
157
+ ["botForwardedMessage", "messageContextInfo"],
158
+ "outer wrapper: messageContextInfo + botForwardedMessage",
159
+ );
160
+
161
+ const message = L(L(payload).botForwardedMessage).message as Record<
162
+ string,
163
+ unknown
164
+ >;
165
+ assert.deepEqual(Object.keys(message), ["richResponseMessage"]);
166
+ const rr = L(message).richResponseMessage;
167
+
168
+ assert.deepEqual(Object.keys(L(rr)).sort(), [
169
+ "contextInfo",
170
+ "messageType",
171
+ "submessages",
172
+ "unifiedResponse",
173
+ ]);
174
+ assert.equal(L(rr).messageType, 1);
175
+ assert.deepEqual(L(rr).submessages, [{ messageType: 2, messageText: ZWSP }]);
176
+ assert.deepEqual(L(rr).contextInfo, FIXTURE_PLACEHOLDER_CONTEXT);
177
+
178
+ assert.ok(L(L(rr).unifiedResponse).data instanceof Uint8Array);
179
+ const decoded = decodeUnifiedResponse(dataOf(payload)) as {
180
+ response_id: string;
181
+ sections: unknown[];
182
+ };
183
+ assert.match(decoded.response_id, UUID_RE);
184
+ assert.deepEqual(decoded.sections, FIXTURE_PLACEHOLDER.sections);
185
+
186
+ assert.equal(payload.messageContextInfo.deviceListMetadataVersion, 2);
187
+ assert.ok(payload.messageContextInfo.messageSecret instanceof Uint8Array);
188
+ assert.equal(payload.messageContextInfo.messageSecret.length, 32);
189
+ });
190
+
191
+ test("golden: protocol edit mengikuti payload botf.js (key + type 14 + editedMessage)", () => {
192
+ const { client } = makeClient();
193
+ const builder = airich(client)
194
+ .text("ini tabel rekomendasi film 3 kolom x 3 baris:")
195
+ .table([
196
+ ["**Judul Film**", "**Genre**", "**Rating**"],
197
+ ["Interstellar", "Sci-Fi", "9.0/10"],
198
+ ["Inception", "Thriller", "8.8/10"],
199
+ ["The Martian", "Adventure", "8.5/10"],
200
+ ])
201
+ .text(
202
+ "Tabel ini berisi beberapa film dengan genre dan rating masing-masing.",
203
+ );
204
+
205
+ const payload = builder.buildEdit(
206
+ "62812036341183@g.us",
207
+ "GOLDEN_PLACEHOLDER_ID",
208
+ { submessages: false },
209
+ );
210
+
211
+ const message = L(L(payload).botForwardedMessage).message as Record<
212
+ string,
213
+ unknown
214
+ >;
215
+ assert.deepEqual(Object.keys(message), ["protocolMessage"]);
216
+
217
+ const protoMessage = L(message).protocolMessage;
218
+ assert.deepEqual(L(protoMessage).key, {
219
+ remoteJid: "62812036341183@g.us",
220
+ fromMe: true,
221
+ id: "GOLDEN_PLACEHOLDER_ID",
222
+ });
223
+ assert.equal(L(protoMessage).type, 14);
224
+
225
+ const editedMessage = L(L(protoMessage).editedMessage).botForwardedMessage;
226
+ const editedRich = L(L(editedMessage).message).richResponseMessage;
227
+ assert.deepEqual(Object.keys(L(editedRich)).sort(), [
228
+ "contextInfo",
229
+ "messageType",
230
+ "submessages",
231
+ "unifiedResponse",
232
+ ]);
233
+ assert.equal(L(editedRich).messageType, 1);
234
+ assert.deepEqual(
235
+ L(editedRich).submessages,
236
+ [],
237
+ "eksperimen botf memakai submessages kosong untuk edit",
238
+ );
239
+ assert.deepEqual(L(editedRich).contextInfo, FIXTURE_EDIT_CONTEXT);
240
+
241
+ const decoded = decodeUnifiedResponse(
242
+ L(L(editedRich).unifiedResponse).data as unknown as Uint8Array,
243
+ ) as { response_id: string; sections: unknown[] };
244
+ assert.match(decoded.response_id, UUID_RE);
245
+ assert.deepEqual(decoded.sections, FIXTURE_EDIT_SECTIONS);
246
+ });
247
+
248
+ test("golden: table markdown_cells selalu {text} tanpa inline entity untuk sel polos", () => {
249
+ const { client } = makeClient();
250
+ const payload = airich(client)
251
+ .table([
252
+ ["A", "B"],
253
+ ["c", "d"],
254
+ ])
255
+ .build({ submessages: false });
256
+ const decoded = decodeUnifiedResponse(dataOf(payload)) as {
257
+ sections: { view_model: { primitive: { rows: unknown[] } } }[];
258
+ };
259
+
260
+ const rows = decoded.sections[0]?.view_model.primitive.rows;
261
+ assert.deepEqual(rows, [
262
+ {
263
+ is_header: true,
264
+ cells: ["A", "B"],
265
+ markdown_cells: [{ text: "A" }, { text: "B" }],
266
+ },
267
+ {
268
+ is_header: false,
269
+ cells: ["c", "d"],
270
+ markdown_cells: [{ text: "c" }, { text: "d" }],
271
+ },
272
+ ]);
273
+ });
274
+
275
+ test("golden: representasi Buffer/Uint8Array stabil untuk transport Zapo", () => {
276
+ const { client } = makeClient();
277
+ const payload = airich(client).text("x").buildPlaceholder();
278
+
279
+ const jsonDump = JSON.stringify(L(L(richOf(payload)).unifiedResponse));
280
+ assert.ok(
281
+ jsonDump.includes('"type":"Buffer"'),
282
+ "bytes harus JSON-serializable sebagai Buffer (Uint8Array)",
283
+ );
284
+
285
+ const secret = payload.messageContextInfo.messageSecret;
286
+ assert.ok(secret instanceof Uint8Array);
287
+ assert.equal(secret.length, 32);
288
+ assert.ok(JSON.stringify(secret).includes('"type":"Buffer"'));
289
+ });
290
+
291
+ test("golden: tidak ada certificate, signature, atau metadata verifikasi palsu di seluruh payload", () => {
292
+ const { client } = makeClient();
293
+ const builder = new AIRich(client, { botJid: "123456789012345@bot" });
294
+ builder
295
+ .text("a")
296
+ .code("js", "b")
297
+ .table([["1"], ["2"]]);
298
+
299
+ const dumps = [
300
+ JSON.stringify(builder.build()),
301
+ JSON.stringify(builder.buildPlaceholder()),
302
+ JSON.stringify(builder.buildEdit("jid@s.whatsapp.net", "ID123")),
303
+ ];
304
+
305
+ for (const dump of dumps) {
306
+ assert.equal(dump.includes('"certificateChain"'), false);
307
+ assert.equal(dump.includes('"signature"'), false);
308
+ assert.equal(dump.includes('"verificationMetadata"'), false);
309
+ assert.equal(dump.includes('"botMetadata"'), false);
310
+ assert.equal(dump.includes('"deviceListMetadata"'), false);
311
+ assert.equal(dump.includes("0@bot"), false);
312
+ assert.equal(dump.includes("867051314767696@bot"), false);
313
+ }
314
+ });
315
+
316
+ test("golden: suggestion HScroll dari payload alternatif botf ter-replikasi builder", () => {
317
+ const { client } = makeClient();
318
+ const payload = airich(client)
319
+ .suggest([
320
+ "extendedTextMessage",
321
+ "120363411834515372@g.us",
322
+ "ACCD293BB8DE4DA98AF01BA0E9E7582",
323
+ ])
324
+ .build({ submessages: false });
325
+ const decoded = decodeUnifiedResponse(dataOf(payload)) as {
326
+ sections: {
327
+ __typename?: string;
328
+ view_model: { __typename: string; primitives: Record<string, unknown>[] };
329
+ }[];
330
+ };
331
+
332
+ const section = decoded.sections[0];
333
+ assert.equal(section?.__typename, "GenAIUnifiedResponseSection");
334
+ assert.equal(section?.view_model.__typename, "GenAIHScrollLayoutViewModel");
335
+ assert.equal(Array.isArray(section?.view_model.primitives), true);
336
+ assert.deepEqual(
337
+ (section?.view_model.primitives ?? []).map((p) => ({
338
+ prompt_text: p.prompt_text,
339
+ prompt_type: p.prompt_type,
340
+ __typename: p.__typename,
341
+ })),
342
+ [
343
+ {
344
+ prompt_text: "extendedTextMessage",
345
+ prompt_type: "SUGGESTED_PROMPT",
346
+ __typename: "GenAIFollowUpSuggestionPillPrimitive",
347
+ },
348
+ {
349
+ prompt_text: "120363411834515372@g.us",
350
+ prompt_type: "SUGGESTED_PROMPT",
351
+ __typename: "GenAIFollowUpSuggestionPillPrimitive",
352
+ },
353
+ {
354
+ prompt_text: "ACCD293BB8DE4DA98AF01BA0E9E7582",
355
+ prompt_type: "SUGGESTED_PROMPT",
356
+ __typename: "GenAIFollowUpSuggestionPillPrimitive",
357
+ },
358
+ ],
359
+ );
360
+ });
361
+
362
+ test("golden: code primitive dari payload alternatif botf (language + code_blocks + token types)", () => {
363
+ const { client } = makeClient();
364
+ const snippet =
365
+ '=> conn.\n relayMessage(\n m.chat,\n {\n extendedTextMessage: {\n text: "testtt",\n previewType: 0,\n contextInfo: {\n expiration: 7776000,\n disappearingMode: {\n initiator: 0,\n trigger: 0\n }\n },\n inviteLinkGroupTypeV2: 0\n }\n },\n {}\n)';
366
+
367
+ const payload = airich(client)
368
+ .code("javascript", snippet)
369
+ .build({ submessages: false });
370
+ const decoded = decodeUnifiedResponse(dataOf(payload)) as {
371
+ sections: {
372
+ view_model: {
373
+ primitive: {
374
+ __typename: string;
375
+ language: string;
376
+ code_blocks: { content: string; type: string }[];
377
+ };
378
+ };
379
+ }[];
380
+ };
381
+
382
+ const primitive = decoded.sections[0]?.view_model.primitive;
383
+ assert.equal(primitive?.__typename, "GenAICodeUXPrimitive");
384
+ assert.equal(primitive?.language, "javascript");
385
+
386
+ assert.deepEqual(
387
+ (primitive?.code_blocks ?? []).map((t) => t.type),
388
+ [
389
+ "DEFAULT",
390
+ "METHOD",
391
+ "DEFAULT",
392
+ "STR",
393
+ "DEFAULT",
394
+ "NUMBER",
395
+ "DEFAULT",
396
+ "NUMBER",
397
+ "DEFAULT",
398
+ "NUMBER",
399
+ "DEFAULT",
400
+ "NUMBER",
401
+ "DEFAULT",
402
+ "NUMBER",
403
+ "DEFAULT",
404
+ ],
405
+ );
406
+ });