@anka-ventures/expert-zalo 0.0.0-stage → 0.1.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.
package/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
package/NOTICE ADDED
@@ -0,0 +1,2 @@
1
+ Expert App SDK
2
+ Copyright 2026 Anka Ventures
package/README.md CHANGED
@@ -1,3 +1,51 @@
1
- # Temporary Holding Version
1
+ # `@anka-ventures/expert-zalo`
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Plans and executes bounded Zalo delivery for an already-saved assistant reply.
4
+ It contains no Zalo SDK, bridge client, credential, network call, recipient
5
+ lookup, database, generation, retry, compensation or inbound authentication.
6
+
7
+ ```ts
8
+ import { deliverZaloReply } from "@anka-ventures/expert-zalo";
9
+
10
+ const report = await deliverZaloReply({
11
+ reply: {
12
+ replyId: savedReply.id,
13
+ inputIdentity: savedReply.turnId,
14
+ parts: [
15
+ { kind: "text", text: savedReply.text },
16
+ { kind: "link", label: "Open result", url: savedReply.url },
17
+ ],
18
+ },
19
+ threadId: zaloThreadId,
20
+ reference: { threadType: "user", replyToMessageId },
21
+ transport: part => hostZaloTransport.send(part),
22
+ });
23
+ ```
24
+
25
+ Text is split at Zalo's 2,000-character bound without removing whitespace or
26
+ breaking surrogate pairs. Images and captions retain order. Links remain a
27
+ bounded plain-text label plus HTTPS URL instead of adopting Telegram button or
28
+ parse-mode behavior. Every planned part carries the exact caller-owned thread
29
+ and reply reference.
30
+
31
+ The adapter calls the injected transport once for each attempted part and only
32
+ advances after an accepted receipt. `retryable` and `refused` require explicit
33
+ `confirmedNoSend`; thrown, malformed, receipt-less accepted and ambiguous
34
+ results become `unknown`. Any non-acceptance stops delivery and returns ordered
35
+ receipts plus the untouched suffix in `remaining`. The adapter never retries,
36
+ regenerates, compensates, resolves a recipient or attempts another part after
37
+ uncertainty. Hosts reconcile using the saved `replyId`, `inputIdentity`, stable
38
+ `partId` and accepted transport `receiptId`.
39
+
40
+ Every plan also carries a deterministic `deliveryId` bound to the saved reply
41
+ content, input identity, thread recipient and reply reference. To resume a
42
+ partial delivery, pass an `acceptedPrefix` containing that exact `deliveryId`
43
+ and an exact ordered prefix of planned `partId`s. The adapter skips only that
44
+ prefix, preserves the original indexes and IDs for later parts, and returns the
45
+ complete accepted prefix in `acceptedPartIds`. A changed reply, input identity,
46
+ recipient or reference rejects the proof before transport is called. The host
47
+ must supply the prefix only from durable accepted receipts.
48
+
49
+ Only plain text, HTTPS images and plain HTTPS links are supported. Stickers,
50
+ rich cards, credentials, bridge signing, live APIs and delivery policy remain
51
+ host concerns.
@@ -0,0 +1,6 @@
1
+ import { type DeliverZaloReplyInput, type PlanZaloDeliveryInput, type ZaloDeliveryPlan, type ZaloDeliveryReport } from "./types.js";
2
+ export declare function planZaloDelivery(input: PlanZaloDeliveryInput): ZaloDeliveryPlan;
3
+ export declare function deliverZaloReply(input: DeliverZaloReplyInput): Promise<ZaloDeliveryReport>;
4
+ /** Preserves Unicode while keeping every JavaScript string within the limit. */
5
+ export declare function splitZaloText(text: string): readonly string[];
6
+ //# sourceMappingURL=delivery.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"delivery.d.ts","sourceRoot":"","sources":["../src/delivery.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,qBAAqB,EAC1B,KAAK,qBAAqB,EAC1B,KAAK,gBAAgB,EACrB,KAAK,kBAAkB,EAKxB,MAAM,YAAY,CAAC;AAEpB,wBAAgB,gBAAgB,CAC9B,KAAK,EAAE,qBAAqB,GAC3B,gBAAgB,CAqElB;AAED,wBAAsB,gBAAgB,CACpC,KAAK,EAAE,qBAAqB,GAC3B,OAAO,CAAC,kBAAkB,CAAC,CA0C7B;AAED,gFAAgF;AAChF,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,MAAM,EAAE,CAE7D"}
@@ -0,0 +1,282 @@
1
+ import { ZALO_IMAGE_CAPTION_LIMIT, ZALO_TEXT_LIMIT, } from "./types.js";
2
+ export function planZaloDelivery(input) {
3
+ validateNonEmpty(input.reply.replyId, "replyId");
4
+ validateNonEmpty(input.reply.inputIdentity, "inputIdentity");
5
+ validateNonEmpty(input.threadId, "threadId");
6
+ validateReference(input.reference);
7
+ const payloads = [];
8
+ for (const part of input.reply.parts) {
9
+ switch (part.kind) {
10
+ case "text": {
11
+ validateNonEmpty(part.text, "text");
12
+ for (const text of splitZaloText(part.text)) {
13
+ payloads.push({ kind: "text", text });
14
+ }
15
+ break;
16
+ }
17
+ case "image": {
18
+ validateHttpsUrl(part.url, "image url");
19
+ if (part.caption !== undefined) {
20
+ validateNonEmpty(part.caption, "image caption");
21
+ validateLimit(part.caption, ZALO_IMAGE_CAPTION_LIMIT, "image caption");
22
+ }
23
+ payloads.push(part.caption === undefined
24
+ ? { kind: "image", url: part.url }
25
+ : { kind: "image", url: part.url, caption: part.caption });
26
+ break;
27
+ }
28
+ case "link": {
29
+ validateHttpsUrl(part.url, "link url");
30
+ if (part.label !== undefined)
31
+ validateNonEmpty(part.label, "link label");
32
+ const rendered = part.label === undefined
33
+ ? part.url
34
+ : `${part.label}\n${part.url}`;
35
+ const chunks = splitZaloText(rendered);
36
+ for (const text of chunks.slice(0, -1)) {
37
+ payloads.push({ kind: "text", text });
38
+ }
39
+ const finalText = chunks.at(-1);
40
+ if (finalText === undefined)
41
+ throw new Error("link url is required");
42
+ payloads.push({ kind: "link", text: finalText, url: part.url });
43
+ break;
44
+ }
45
+ }
46
+ }
47
+ if (payloads.length === 0) {
48
+ throw new Error("saved reply must contain at least one deliverable part");
49
+ }
50
+ const deliveryId = zaloDeliveryId(input);
51
+ const parts = payloads.map((payload, partIndex) => ({
52
+ deliveryId,
53
+ partId: `${input.reply.replyId}:zalo:${partIndex}`,
54
+ partIndex,
55
+ replyId: input.reply.replyId,
56
+ inputIdentity: input.reply.inputIdentity,
57
+ threadId: input.threadId,
58
+ reference: { ...input.reference },
59
+ payload,
60
+ }));
61
+ return {
62
+ deliveryId,
63
+ replyId: input.reply.replyId,
64
+ inputIdentity: input.reply.inputIdentity,
65
+ parts,
66
+ };
67
+ }
68
+ export async function deliverZaloReply(input) {
69
+ const plan = planZaloDelivery(input);
70
+ const receipts = [];
71
+ const acceptedPartIds = acceptedPrefixPartIds(plan, input.acceptedPrefix);
72
+ for (const part of plan.parts.slice(acceptedPartIds.length)) {
73
+ let receipt;
74
+ try {
75
+ receipt = receiptFromResult(part, await input.transport(part));
76
+ }
77
+ catch {
78
+ receipt = {
79
+ partId: part.partId,
80
+ partIndex: part.partIndex,
81
+ outcome: "unknown",
82
+ reason: "transport_threw",
83
+ };
84
+ }
85
+ receipts.push(receipt);
86
+ if (receipt.outcome !== "accepted") {
87
+ return {
88
+ deliveryId: plan.deliveryId,
89
+ replyId: plan.replyId,
90
+ inputIdentity: plan.inputIdentity,
91
+ outcome: receipt.outcome,
92
+ receipts,
93
+ acceptedPartIds: Object.freeze([...acceptedPartIds]),
94
+ remaining: plan.parts.slice(part.partIndex + 1),
95
+ };
96
+ }
97
+ acceptedPartIds.push(part.partId);
98
+ }
99
+ return {
100
+ deliveryId: plan.deliveryId,
101
+ replyId: plan.replyId,
102
+ inputIdentity: plan.inputIdentity,
103
+ outcome: "accepted",
104
+ receipts,
105
+ acceptedPartIds: Object.freeze([...acceptedPartIds]),
106
+ remaining: [],
107
+ };
108
+ }
109
+ /** Preserves Unicode while keeping every JavaScript string within the limit. */
110
+ export function splitZaloText(text) {
111
+ return splitText(text, ZALO_TEXT_LIMIT);
112
+ }
113
+ function receiptFromResult(part, result) {
114
+ if (!result || typeof result !== "object" || !("kind" in result)) {
115
+ return unknownReceipt(part);
116
+ }
117
+ if (result.kind === "accepted") {
118
+ const receiptId = acceptedReceiptId(result.receiptId);
119
+ return receiptId !== undefined
120
+ ? {
121
+ partId: part.partId,
122
+ partIndex: part.partIndex,
123
+ outcome: "accepted",
124
+ receiptId,
125
+ }
126
+ : unknownReceipt(part);
127
+ }
128
+ if ((result.kind === "retryable" || result.kind === "refused")
129
+ && result.confirmedNoSend === true
130
+ && typeof result.reason === "string"
131
+ && result.reason.length > 0) {
132
+ return {
133
+ partId: part.partId,
134
+ partIndex: part.partIndex,
135
+ outcome: result.kind,
136
+ reason: result.reason,
137
+ };
138
+ }
139
+ if (result.kind === "unknown") {
140
+ return {
141
+ partId: part.partId,
142
+ partIndex: part.partIndex,
143
+ outcome: "unknown",
144
+ reason: typeof result.reason === "string" && result.reason.length > 0
145
+ ? result.reason
146
+ : "transport_unknown",
147
+ };
148
+ }
149
+ return unknownReceipt(part);
150
+ }
151
+ function acceptedReceiptId(value) {
152
+ if (typeof value === "string")
153
+ return value.length > 0 ? value : undefined;
154
+ return typeof value === "number" && Number.isFinite(value)
155
+ ? String(value)
156
+ : undefined;
157
+ }
158
+ function unknownReceipt(part) {
159
+ return {
160
+ partId: part.partId,
161
+ partIndex: part.partIndex,
162
+ outcome: "unknown",
163
+ reason: "ambiguous_transport_result",
164
+ };
165
+ }
166
+ function acceptedPrefixPartIds(plan, prefix) {
167
+ if (prefix === undefined)
168
+ return [];
169
+ if (!prefix
170
+ || typeof prefix !== "object"
171
+ || prefix.deliveryId !== plan.deliveryId
172
+ || !Array.isArray(prefix.partIds)
173
+ || prefix.partIds.length > plan.parts.length) {
174
+ throw new Error("acceptedPrefix must match the exact current delivery plan");
175
+ }
176
+ for (let index = 0; index < prefix.partIds.length; index += 1) {
177
+ const acceptedPartId = prefix.partIds[index];
178
+ if (typeof acceptedPartId !== "string"
179
+ || acceptedPartId !== plan.parts[index]?.partId) {
180
+ throw new Error("acceptedPrefix partIds must be an exact ordered prefix");
181
+ }
182
+ }
183
+ return [...prefix.partIds];
184
+ }
185
+ function zaloDeliveryId(input) {
186
+ return JSON.stringify([
187
+ "expert.zalo.delivery",
188
+ 1,
189
+ input.reply.replyId,
190
+ input.reply.inputIdentity,
191
+ input.threadId,
192
+ input.reference.threadType,
193
+ input.reference.replyToMessageId ?? null,
194
+ input.reply.parts.map((part) => {
195
+ switch (part.kind) {
196
+ case "text":
197
+ return ["text", part.text];
198
+ case "image":
199
+ return ["image", part.url, part.caption ?? null];
200
+ case "link":
201
+ return ["link", part.url, part.label ?? null];
202
+ }
203
+ }),
204
+ ]);
205
+ }
206
+ function splitText(text, limit) {
207
+ const codePoints = Array.from(text);
208
+ if (text.length <= limit)
209
+ return [text];
210
+ const chunks = [];
211
+ let offset = 0;
212
+ while (offset < codePoints.length) {
213
+ const boundedEnd = findBoundedEnd(codePoints, offset, limit);
214
+ if (boundedEnd === codePoints.length) {
215
+ chunks.push(codePoints.slice(offset).join(""));
216
+ break;
217
+ }
218
+ const splitAt = findPreferredBoundary(codePoints, offset, boundedEnd);
219
+ chunks.push(codePoints.slice(offset, splitAt).join(""));
220
+ offset = splitAt;
221
+ }
222
+ return chunks;
223
+ }
224
+ function findBoundedEnd(codePoints, offset, limit) {
225
+ let units = 0;
226
+ let end = offset;
227
+ while (end < codePoints.length) {
228
+ const next = codePoints[end];
229
+ if (next === undefined || units + next.length > limit)
230
+ break;
231
+ units += next.length;
232
+ end += 1;
233
+ }
234
+ return end;
235
+ }
236
+ function findPreferredBoundary(codePoints, offset, end) {
237
+ for (let index = end - 1; index > offset; index -= 1) {
238
+ if (codePoints[index - 1] === "\n" && codePoints[index] === "\n") {
239
+ return index + 1;
240
+ }
241
+ }
242
+ for (let index = end - 1; index >= offset; index -= 1) {
243
+ if (codePoints[index] === "\n")
244
+ return index + 1;
245
+ }
246
+ for (let index = end - 1; index >= offset; index -= 1) {
247
+ if (codePoints[index] === " ")
248
+ return index + 1;
249
+ }
250
+ return end;
251
+ }
252
+ function validateNonEmpty(value, name) {
253
+ if (typeof value !== "string" || value.length === 0) {
254
+ throw new Error(`${name} must be a non-empty string`);
255
+ }
256
+ }
257
+ function validateLimit(value, limit, name) {
258
+ if (value.length > limit) {
259
+ throw new Error(`${name} exceeds Zalo's ${limit}-character limit`);
260
+ }
261
+ }
262
+ function validateHttpsUrl(value, name) {
263
+ let url;
264
+ try {
265
+ url = new URL(value);
266
+ }
267
+ catch {
268
+ throw new Error(`${name} must be a valid HTTPS URL`);
269
+ }
270
+ if (url.protocol !== "https:") {
271
+ throw new Error(`${name} must be a valid HTTPS URL`);
272
+ }
273
+ }
274
+ function validateReference(reference) {
275
+ if (reference.threadType !== "user" && reference.threadType !== "group") {
276
+ throw new Error("threadType must be user or group");
277
+ }
278
+ if (reference.replyToMessageId !== undefined) {
279
+ validateNonEmpty(reference.replyToMessageId, "replyToMessageId");
280
+ }
281
+ }
282
+ //# sourceMappingURL=delivery.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"delivery.js","sourceRoot":"","sources":["../src/delivery.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,wBAAwB,EACxB,eAAe,GAShB,MAAM,YAAY,CAAC;AAEpB,MAAM,UAAU,gBAAgB,CAC9B,KAA4B;IAE5B,gBAAgB,CAAC,KAAK,CAAC,KAAK,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC;IACjD,gBAAgB,CAAC,KAAK,CAAC,KAAK,CAAC,aAAa,EAAE,eAAe,CAAC,CAAC;IAC7D,gBAAgB,CAAC,KAAK,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAC;IAC7C,iBAAiB,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;IAEnC,MAAM,QAAQ,GAAkB,EAAE,CAAC;IACnC,KAAK,MAAM,IAAI,IAAI,KAAK,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC;QACrC,QAAQ,IAAI,CAAC,IAAI,EAAE,CAAC;YAClB,KAAK,MAAM,CAAC,CAAC,CAAC;gBACZ,gBAAgB,CAAC,IAAI,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;gBACpC,KAAK,MAAM,IAAI,IAAI,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,EAA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;AACH,CAAC;AAED,SAAS,aAAa,CAAC,KAAa,EAAE,KAAa,EAAE,IAAY;IAC/D,IAAI,KAAK,CAAC,MAAM,GAAG,KAAK,EAAE,CAAC;QACzB,MAAM,IAAI,KAAK,CAAC,GAAG,IAAI,mBAAmB,KAAK,kBAAkB,CAAC,CAAC;IACrE,CAAC;AACH,CAAC;AAED,SAAS,gBAAgB,CAAC,KAAa,EAAE,IAAY;IACnD,IAAI,GAAQ,CAAC;IACb,IAAI,CAAC;QACH,GAAG,GAAG,IAAI,GAAG,CAAC,KAAK,CAAC,CAAC;IACvB,CAAC;IAAC,MAAM,CAAC;QACP,MAAM,IAAI,KAAK,CAAC,GAAG,IAAI,4BAA4B,CAAC,CAAC;IACvD,CAAC;IACD,IAAI,GAAG,CAAC,QAAQ,KAAK,QAAQ,EAAE,CAAC;QAC9B,MAAM,IAAI,KAAK,CAAC,GAAG,IAAI,4BAA4B,CAAC,CAAC;IACvD,CAAC;AACH,CAAC;AAED,SAAS,iBAAiB,CAAC,SAA6C;IACtE,IAAI,SAAS,CAAC,UAAU,KAAK,MAAM,IAAI,SAAS,CAAC,UAAU,KAAK,OAAO,EAAE,CAAC;QACxE,MAAM,IAAI,KAAK,CAAC,kCAAkC,CAAC,CAAC;IACtD,CAAC;IACD,IAAI,SAAS,CAAC,gBAAgB,KAAK,SAAS,EAAE,CAAC;QAC7C,gBAAgB,CAAC,SAAS,CAAC,gBAAgB,EAAE,kBAAkB,CAAC,CAAC;IACnE,CAAC;AACH,CAAC"}
@@ -0,0 +1,3 @@
1
+ export { deliverZaloReply, planZaloDelivery, splitZaloText, } from "./delivery.js";
2
+ export { ZALO_IMAGE_CAPTION_LIMIT, ZALO_TEXT_LIMIT, type ZaloAcceptedPrefix, type DeliverZaloReplyInput, type PlanZaloDeliveryInput, type ZaloDeliveryPlan, type ZaloDeliveryReference, type ZaloDeliveryReport, type ZaloPartReceipt, type ZaloPayload, type ZaloPlannedPart, type ZaloSavedAssistantReply, type ZaloSavedReplyPart, type ZaloTransport, type ZaloTransportResult, } from "./types.js";
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAChB,gBAAgB,EAChB,aAAa,GACd,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,wBAAwB,EACxB,eAAe,EACf,KAAK,kBAAkB,EACvB,KAAK,qBAAqB,EAC1B,KAAK,qBAAqB,EAC1B,KAAK,gBAAgB,EACrB,KAAK,qBAAqB,EAC1B,KAAK,kBAAkB,EACvB,KAAK,eAAe,EACpB,KAAK,WAAW,EAChB,KAAK,eAAe,EACpB,KAAK,uBAAuB,EAC5B,KAAK,kBAAkB,EACvB,KAAK,aAAa,EAClB,KAAK,mBAAmB,GACzB,MAAM,YAAY,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,3 @@
1
+ export { deliverZaloReply, planZaloDelivery, splitZaloText, } from "./delivery.js";
2
+ export { ZALO_IMAGE_CAPTION_LIMIT, ZALO_TEXT_LIMIT, } from "./types.js";
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAChB,gBAAgB,EAChB,aAAa,GACd,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,wBAAwB,EACxB,eAAe,GAchB,MAAM,YAAY,CAAC"}
@@ -0,0 +1,110 @@
1
+ export declare const ZALO_TEXT_LIMIT = 2000;
2
+ export declare const ZALO_IMAGE_CAPTION_LIMIT = 2000;
3
+ export interface ZaloDeliveryReference {
4
+ readonly threadType: "user" | "group";
5
+ readonly replyToMessageId?: string;
6
+ }
7
+ export type ZaloSavedReplyPart = {
8
+ readonly kind: "text";
9
+ readonly text: string;
10
+ } | {
11
+ readonly kind: "image";
12
+ readonly url: string;
13
+ readonly caption?: string;
14
+ } | {
15
+ /** Zalo links remain explicit plain text rather than rich Telegram UI. */
16
+ readonly kind: "link";
17
+ readonly url: string;
18
+ readonly label?: string;
19
+ };
20
+ /** A host-persisted assistant reply. Generation is outside this package. */
21
+ export interface ZaloSavedAssistantReply {
22
+ readonly replyId: string;
23
+ readonly inputIdentity: string;
24
+ readonly parts: readonly ZaloSavedReplyPart[];
25
+ }
26
+ export type ZaloPayload = {
27
+ readonly kind: "text";
28
+ readonly text: string;
29
+ } | {
30
+ readonly kind: "image";
31
+ readonly url: string;
32
+ readonly caption?: string;
33
+ } | {
34
+ readonly kind: "link";
35
+ /** Fully rendered plain text, including the URL. */
36
+ readonly text: string;
37
+ readonly url: string;
38
+ };
39
+ export interface ZaloPlannedPart {
40
+ readonly deliveryId: string;
41
+ readonly partId: string;
42
+ readonly partIndex: number;
43
+ readonly replyId: string;
44
+ readonly inputIdentity: string;
45
+ readonly threadId: string;
46
+ readonly reference: ZaloDeliveryReference;
47
+ readonly payload: ZaloPayload;
48
+ }
49
+ export interface ZaloDeliveryPlan {
50
+ /** Stable across exact-input replays and bound to payload, recipient and reference. */
51
+ readonly deliveryId: string;
52
+ readonly replyId: string;
53
+ readonly inputIdentity: string;
54
+ readonly parts: readonly ZaloPlannedPart[];
55
+ }
56
+ export type ZaloTransportResult = {
57
+ readonly kind: "accepted";
58
+ readonly receiptId: string | number;
59
+ } | {
60
+ readonly kind: "retryable";
61
+ readonly confirmedNoSend: true;
62
+ readonly reason: string;
63
+ } | {
64
+ readonly kind: "refused";
65
+ readonly confirmedNoSend: true;
66
+ readonly reason: string;
67
+ } | {
68
+ readonly kind: "unknown";
69
+ readonly reason?: string;
70
+ };
71
+ export type ZaloTransport = (part: ZaloPlannedPart) => ZaloTransportResult | PromiseLike<ZaloTransportResult>;
72
+ interface ZaloReceiptBase {
73
+ readonly partId: string;
74
+ readonly partIndex: number;
75
+ }
76
+ export type ZaloPartReceipt = (ZaloReceiptBase & {
77
+ readonly outcome: "accepted";
78
+ readonly receiptId: string;
79
+ }) | (ZaloReceiptBase & {
80
+ readonly outcome: "retryable" | "refused" | "unknown";
81
+ readonly reason: string;
82
+ });
83
+ export interface ZaloDeliveryReport {
84
+ readonly deliveryId: string;
85
+ readonly replyId: string;
86
+ readonly inputIdentity: string;
87
+ readonly outcome: "accepted" | "retryable" | "refused" | "unknown";
88
+ readonly receipts: readonly ZaloPartReceipt[];
89
+ /** Exact accepted prefix, including parts proven by the caller on resume. */
90
+ readonly acceptedPartIds: readonly string[];
91
+ /** Planned suffix that was not attempted after the first non-acceptance. */
92
+ readonly remaining: readonly ZaloPlannedPart[];
93
+ }
94
+ export interface PlanZaloDeliveryInput {
95
+ readonly reply: ZaloSavedAssistantReply;
96
+ readonly threadId: string;
97
+ readonly reference: ZaloDeliveryReference;
98
+ }
99
+ export interface ZaloAcceptedPrefix {
100
+ /** Must equal the delivery id produced for the exact current plan. */
101
+ readonly deliveryId: string;
102
+ /** Must be an exact, ordered prefix of the current plan's part ids. */
103
+ readonly partIds: readonly string[];
104
+ }
105
+ export interface DeliverZaloReplyInput extends PlanZaloDeliveryInput {
106
+ readonly acceptedPrefix?: ZaloAcceptedPrefix;
107
+ readonly transport: ZaloTransport;
108
+ }
109
+ export {};
110
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,eAAe,OAAO,CAAC;AACpC,eAAO,MAAM,wBAAwB,OAAO,CAAC;AAE7C,MAAM,WAAW,qBAAqB;IACpC,QAAQ,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC;IACtC,QAAQ,CAAC,gBAAgB,CAAC,EAAE,MAAM,CAAC;CACpC;AAED,MAAM,MAAM,kBAAkB,GAC1B;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAChD;IACE,QAAQ,C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ot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,eAAe,GAAG,IAAI,CAAC;AACpC,MAAM,CAAC,MAAM,wBAAwB,GAAG,IAAI,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,47 @@
1
1
  {
2
2
  "name": "@anka-ventures/expert-zalo",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0",
4
+ "description": "Zalo reply formatting, delivery planning and receipt classification",
5
+ "license": "Apache-2.0",
6
+ "publishConfig": {
7
+ "access": "public",
8
+ "provenance": true
9
+ },
10
+ "homepage": "https://github.com/anka-ventures-labs/expert-app-sdk/tree/main/packages/zalo#readme",
11
+ "bugs": {
12
+ "url": "https://github.com/anka-ventures-labs/expert-app-sdk/issues"
13
+ },
14
+ "keywords": [
15
+ "expert-app",
16
+ "typescript",
17
+ "zalo",
18
+ "messaging"
19
+ ],
20
+ "type": "module",
21
+ "sideEffects": false,
22
+ "engines": {
23
+ "node": ">=20.9.0"
24
+ },
25
+ "repository": {
26
+ "type": "git",
27
+ "url": "git+https://github.com/anka-ventures-labs/expert-app-sdk.git",
28
+ "directory": "packages/zalo"
29
+ },
30
+ "exports": {
31
+ ".": {
32
+ "types": "./dist/index.d.ts",
33
+ "import": "./dist/index.js"
34
+ }
35
+ },
36
+ "files": [
37
+ "dist",
38
+ "README.md",
39
+ "LICENSE",
40
+ "NOTICE"
41
+ ],
42
+ "scripts": {
43
+ "build": "tsc -p tsconfig.build.json",
44
+ "test": "vitest run test",
45
+ "typecheck": "tsc -p tsconfig.json --noEmit"
46
+ }
47
+ }