@symerian/symi 3.0.20 → 3.0.21

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 (52) hide show
  1. package/dist/{audio-preflight-BaCdNfrk.js → audio-preflight-D7BVT-ls.js} +4 -4
  2. package/dist/build-info.json +3 -3
  3. package/dist/canvas-host/a2ui/.bundle.hash +1 -1
  4. package/dist/{chrome-UfmVM0xR.js → chrome-B5CO2vB5.js} +7 -7
  5. package/dist/{deliver-BqXdac6W.js → deliver-CrwjsDwv.js} +1 -1
  6. package/dist/extensionAPI.js +7 -7
  7. package/dist/{image-DIWsXYcW.js → image-Csu7WcLW.js} +1 -1
  8. package/dist/{manager-DW3SxcPr.js → manager-BkkVjTO8.js} +1 -1
  9. package/dist/{pi-embedded-BNch0U5F.js → pi-embedded-Dhp64z5l.js} +16 -16
  10. package/dist/{pi-embedded-helpers-IkHl02JF.js → pi-embedded-helpers-840E4hop.js} +4 -4
  11. package/dist/{pw-ai-nMkA-oDJ.js → pw-ai-CBgJf_RR.js} +1 -1
  12. package/dist/{runner-DNEC58JI.js → runner-BbFKo1ne.js} +1 -1
  13. package/dist/{synthesis-BWAr0sZ9.js → synthesis-DoEM0E8_.js} +7 -7
  14. package/dist/{web-7a-m_UxL.js → web-BYXJn-Ps.js} +7 -7
  15. package/package.json +1 -1
  16. package/extensions/imessage/index.ts +0 -17
  17. package/extensions/imessage/node_modules/.bin/symi +0 -21
  18. package/extensions/imessage/package.json +0 -15
  19. package/extensions/imessage/src/channel.outbound.test.ts +0 -66
  20. package/extensions/imessage/src/channel.ts +0 -298
  21. package/extensions/imessage/src/runtime.ts +0 -14
  22. package/extensions/imessage/symi.plugin.json +0 -9
  23. package/extensions/line/index.ts +0 -19
  24. package/extensions/line/node_modules/.bin/symi +0 -21
  25. package/extensions/line/package.json +0 -30
  26. package/extensions/line/src/card-command.ts +0 -344
  27. package/extensions/line/src/channel.logout.test.ts +0 -133
  28. package/extensions/line/src/channel.sendPayload.test.ts +0 -312
  29. package/extensions/line/src/channel.startup.test.ts +0 -133
  30. package/extensions/line/src/channel.ts +0 -801
  31. package/extensions/line/src/runtime.ts +0 -14
  32. package/extensions/line/symi.plugin.json +0 -9
  33. package/extensions/signal/index.ts +0 -17
  34. package/extensions/signal/node_modules/.bin/symi +0 -21
  35. package/extensions/signal/package.json +0 -15
  36. package/extensions/signal/src/channel.ts +0 -302
  37. package/extensions/signal/src/runtime.ts +0 -14
  38. package/extensions/signal/symi.plugin.json +0 -9
  39. package/extensions/telegram/index.ts +0 -17
  40. package/extensions/telegram/node_modules/.bin/symi +0 -21
  41. package/extensions/telegram/package.json +0 -15
  42. package/extensions/telegram/src/channel.test.ts +0 -125
  43. package/extensions/telegram/src/channel.ts +0 -560
  44. package/extensions/telegram/src/runtime.ts +0 -14
  45. package/extensions/telegram/symi.plugin.json +0 -9
  46. package/extensions/whatsapp/index.ts +0 -17
  47. package/extensions/whatsapp/node_modules/.bin/symi +0 -21
  48. package/extensions/whatsapp/package.json +0 -15
  49. package/extensions/whatsapp/src/channel.ts +0 -465
  50. package/extensions/whatsapp/src/resolve-target.test.ts +0 -170
  51. package/extensions/whatsapp/src/runtime.ts +0 -14
  52. package/extensions/whatsapp/symi.plugin.json +0 -9
@@ -1,344 +0,0 @@
1
- import type { LineChannelData, SymiPluginApi, ReplyPayload } from "symi/plugin-sdk";
2
- import {
3
- createActionCard,
4
- createImageCard,
5
- createInfoCard,
6
- createListCard,
7
- createReceiptCard,
8
- type CardAction,
9
- type ListItem,
10
- } from "symi/plugin-sdk";
11
-
12
- const CARD_USAGE = `Usage: /card <type> "title" "body" [options]
13
-
14
- Types:
15
- info "Title" "Body" ["Footer"]
16
- image "Title" "Caption" --url <image-url>
17
- action "Title" "Body" --actions "Btn1|url1,Btn2|text2"
18
- list "Title" "Item1|Desc1,Item2|Desc2"
19
- receipt "Title" "Item1:$10,Item2:$20" --total "$30"
20
- confirm "Question?" --yes "Yes|data" --no "No|data"
21
- buttons "Title" "Text" --actions "Btn1|url1,Btn2|data2"
22
-
23
- Examples:
24
- /card info "Welcome" "Thanks for joining!"
25
- /card image "Product" "Check it out" --url https://example.com/img.jpg
26
- /card action "Menu" "Choose an option" --actions "Order|/order,Help|/help"`;
27
-
28
- function buildLineReply(lineData: LineChannelData): ReplyPayload {
29
- return {
30
- channelData: {
31
- line: lineData,
32
- },
33
- };
34
- }
35
-
36
- /**
37
- * Parse action string format: "Label|data,Label2|data2"
38
- * Data can be a URL (uri action) or plain text (message action) or key=value (postback)
39
- */
40
- function parseActions(actionsStr: string | undefined): CardAction[] {
41
- if (!actionsStr) {
42
- return [];
43
- }
44
-
45
- const results: CardAction[] = [];
46
-
47
- for (const part of actionsStr.split(",")) {
48
- const [label, data] = part
49
- .trim()
50
- .split("|")
51
- .map((s) => s.trim());
52
- if (!label) {
53
- continue;
54
- }
55
-
56
- const actionData = data || label;
57
-
58
- if (actionData.startsWith("http://") || actionData.startsWith("https://")) {
59
- results.push({
60
- label,
61
- action: { type: "uri", label: label.slice(0, 20), uri: actionData },
62
- });
63
- } else if (actionData.includes("=")) {
64
- results.push({
65
- label,
66
- action: {
67
- type: "postback",
68
- label: label.slice(0, 20),
69
- data: actionData.slice(0, 300),
70
- displayText: label,
71
- },
72
- });
73
- } else {
74
- results.push({
75
- label,
76
- action: { type: "message", label: label.slice(0, 20), text: actionData },
77
- });
78
- }
79
- }
80
-
81
- return results;
82
- }
83
-
84
- /**
85
- * Parse list items format: "Item1|Subtitle1,Item2|Subtitle2"
86
- */
87
- function parseListItems(itemsStr: string): ListItem[] {
88
- return itemsStr
89
- .split(",")
90
- .map((part) => {
91
- const [title, subtitle] = part
92
- .trim()
93
- .split("|")
94
- .map((s) => s.trim());
95
- return { title: title || "", subtitle };
96
- })
97
- .filter((item) => item.title);
98
- }
99
-
100
- /**
101
- * Parse receipt items format: "Item1:$10,Item2:$20"
102
- */
103
- function parseReceiptItems(itemsStr: string): Array<{ name: string; value: string }> {
104
- return itemsStr
105
- .split(",")
106
- .map((part) => {
107
- const colonIndex = part.lastIndexOf(":");
108
- if (colonIndex === -1) {
109
- return { name: part.trim(), value: "" };
110
- }
111
- return {
112
- name: part.slice(0, colonIndex).trim(),
113
- value: part.slice(colonIndex + 1).trim(),
114
- };
115
- })
116
- .filter((item) => item.name);
117
- }
118
-
119
- /**
120
- * Parse quoted arguments from command string
121
- * Supports: /card type "arg1" "arg2" "arg3" --flag value
122
- */
123
- function parseCardArgs(argsStr: string): {
124
- type: string;
125
- args: string[];
126
- flags: Record<string, string>;
127
- } {
128
- const result: { type: string; args: string[]; flags: Record<string, string> } = {
129
- type: "",
130
- args: [],
131
- flags: {},
132
- };
133
-
134
- // Extract type (first word)
135
- const typeMatch = argsStr.match(/^(\w+)/);
136
- if (typeMatch) {
137
- result.type = typeMatch[1].toLowerCase();
138
- argsStr = argsStr.slice(typeMatch[0].length).trim();
139
- }
140
-
141
- // Extract quoted arguments
142
- const quotedRegex = /"([^"]*?)"/g;
143
- let match;
144
- while ((match = quotedRegex.exec(argsStr)) !== null) {
145
- result.args.push(match[1]);
146
- }
147
-
148
- // Extract flags (--key value or --key "value")
149
- const flagRegex = /--(\w+)\s+(?:"([^"]*?)"|(\S+))/g;
150
- while ((match = flagRegex.exec(argsStr)) !== null) {
151
- result.flags[match[1]] = match[2] ?? match[3];
152
- }
153
-
154
- return result;
155
- }
156
-
157
- export function registerLineCardCommand(api: SymiPluginApi): void {
158
- api.registerCommand({
159
- name: "card",
160
- description: "Send a rich card message (LINE).",
161
- acceptsArgs: true,
162
- requireAuth: false,
163
- handler: async (ctx) => {
164
- const argsStr = ctx.args?.trim() ?? "";
165
- if (!argsStr) {
166
- return { text: CARD_USAGE };
167
- }
168
-
169
- const parsed = parseCardArgs(argsStr);
170
- const { type, args, flags } = parsed;
171
-
172
- if (!type) {
173
- return { text: CARD_USAGE };
174
- }
175
-
176
- // Only LINE supports rich cards; fallback to text elsewhere.
177
- if (ctx.channel !== "line") {
178
- const fallbackText = args.join(" - ");
179
- return { text: `[${type} card] ${fallbackText}`.trim() };
180
- }
181
-
182
- try {
183
- switch (type) {
184
- case "info": {
185
- const [title = "Info", body = "", footer] = args;
186
- const bubble = createInfoCard(title, body, footer);
187
- return buildLineReply({
188
- flexMessage: {
189
- altText: `${title}: ${body}`.slice(0, 400),
190
- contents: bubble,
191
- },
192
- });
193
- }
194
-
195
- case "image": {
196
- const [title = "Image", caption = ""] = args;
197
- const imageUrl = flags.url || flags.image;
198
- if (!imageUrl) {
199
- return { text: "Error: Image card requires --url <image-url>" };
200
- }
201
- const bubble = createImageCard(imageUrl, title, caption);
202
- return buildLineReply({
203
- flexMessage: {
204
- altText: `${title}: ${caption}`.slice(0, 400),
205
- contents: bubble,
206
- },
207
- });
208
- }
209
-
210
- case "action": {
211
- const [title = "Actions", body = ""] = args;
212
- const actions = parseActions(flags.actions);
213
- if (actions.length === 0) {
214
- return { text: 'Error: Action card requires --actions "Label1|data1,Label2|data2"' };
215
- }
216
- const bubble = createActionCard(title, body, actions, {
217
- imageUrl: flags.url || flags.image,
218
- });
219
- return buildLineReply({
220
- flexMessage: {
221
- altText: `${title}: ${body}`.slice(0, 400),
222
- contents: bubble,
223
- },
224
- });
225
- }
226
-
227
- case "list": {
228
- const [title = "List", itemsStr = ""] = args;
229
- const items = parseListItems(itemsStr || flags.items || "");
230
- if (items.length === 0) {
231
- return {
232
- text: 'Error: List card requires items. Usage: /card list "Title" "Item1|Desc1,Item2|Desc2"',
233
- };
234
- }
235
- const bubble = createListCard(title, items);
236
- return buildLineReply({
237
- flexMessage: {
238
- altText: `${title}: ${items.map((i) => i.title).join(", ")}`.slice(0, 400),
239
- contents: bubble,
240
- },
241
- });
242
- }
243
-
244
- case "receipt": {
245
- const [title = "Receipt", itemsStr = ""] = args;
246
- const items = parseReceiptItems(itemsStr || flags.items || "");
247
- const total = flags.total ? { label: "Total", value: flags.total } : undefined;
248
- const footer = flags.footer;
249
-
250
- if (items.length === 0) {
251
- return {
252
- text: 'Error: Receipt card requires items. Usage: /card receipt "Title" "Item1:$10,Item2:$20" --total "$30"',
253
- };
254
- }
255
-
256
- const bubble = createReceiptCard({ title, items, total, footer });
257
- return buildLineReply({
258
- flexMessage: {
259
- altText: `${title}: ${items.map((i) => `${i.name} ${i.value}`).join(", ")}`.slice(
260
- 0,
261
- 400,
262
- ),
263
- contents: bubble,
264
- },
265
- });
266
- }
267
-
268
- case "confirm": {
269
- const [question = "Confirm?"] = args;
270
- const yesStr = flags.yes || "Yes|yes";
271
- const noStr = flags.no || "No|no";
272
-
273
- const [yesLabel, yesData] = yesStr.split("|").map((s) => s.trim());
274
- const [noLabel, noData] = noStr.split("|").map((s) => s.trim());
275
-
276
- return buildLineReply({
277
- templateMessage: {
278
- type: "confirm",
279
- text: question,
280
- confirmLabel: yesLabel || "Yes",
281
- confirmData: yesData || "yes",
282
- cancelLabel: noLabel || "No",
283
- cancelData: noData || "no",
284
- altText: question,
285
- },
286
- });
287
- }
288
-
289
- case "buttons": {
290
- const [title = "Menu", text = "Choose an option"] = args;
291
- const actionsStr = flags.actions || "";
292
- const actionParts = parseActions(actionsStr);
293
-
294
- if (actionParts.length === 0) {
295
- return { text: 'Error: Buttons card requires --actions "Label1|data1,Label2|data2"' };
296
- }
297
-
298
- const templateActions: Array<{
299
- type: "message" | "uri" | "postback";
300
- label: string;
301
- data?: string;
302
- uri?: string;
303
- }> = actionParts.map((a) => {
304
- const action = a.action;
305
- const label = action.label ?? a.label;
306
- if (action.type === "uri") {
307
- return { type: "uri" as const, label, uri: (action as { uri: string }).uri };
308
- }
309
- if (action.type === "postback") {
310
- return {
311
- type: "postback" as const,
312
- label,
313
- data: (action as { data: string }).data,
314
- };
315
- }
316
- return {
317
- type: "message" as const,
318
- label,
319
- data: (action as { text: string }).text,
320
- };
321
- });
322
-
323
- return buildLineReply({
324
- templateMessage: {
325
- type: "buttons",
326
- title,
327
- text,
328
- thumbnailImageUrl: flags.url || flags.image,
329
- actions: templateActions,
330
- },
331
- });
332
- }
333
-
334
- default:
335
- return {
336
- text: `Unknown card type: "${type}". Available types: info, image, action, list, receipt, confirm, buttons`,
337
- };
338
- }
339
- } catch (err) {
340
- return { text: `Error creating card: ${String(err)}` };
341
- }
342
- },
343
- });
344
- }
@@ -1,133 +0,0 @@
1
- import type { SymiConfig, PluginRuntime, ResolvedLineAccount, RuntimeEnv } from "symi/plugin-sdk";
2
- import { beforeEach, describe, expect, it, vi } from "vitest";
3
- import { linePlugin } from "./channel.js";
4
- import { setLineRuntime } from "./runtime.js";
5
-
6
- const DEFAULT_ACCOUNT_ID = "default";
7
-
8
- type LineRuntimeMocks = {
9
- writeConfigFile: ReturnType<typeof vi.fn>;
10
- resolveLineAccount: ReturnType<typeof vi.fn>;
11
- };
12
-
13
- function createRuntime(): { runtime: PluginRuntime; mocks: LineRuntimeMocks } {
14
- const writeConfigFile = vi.fn(async () => {});
15
- const resolveLineAccount = vi.fn(
16
- ({ cfg, accountId }: { cfg: SymiConfig; accountId?: string }) => {
17
- const lineConfig = (cfg.channels?.line ?? {}) as {
18
- tokenFile?: string;
19
- secretFile?: string;
20
- channelAccessToken?: string;
21
- channelSecret?: string;
22
- accounts?: Record<string, Record<string, unknown>>;
23
- };
24
- const entry =
25
- accountId && accountId !== DEFAULT_ACCOUNT_ID
26
- ? (lineConfig.accounts?.[accountId] ?? {})
27
- : lineConfig;
28
- const hasToken =
29
- // oxlint-disable-next-line typescript/no-explicit-any
30
- Boolean((entry as any).channelAccessToken) || Boolean((entry as any).tokenFile);
31
- // oxlint-disable-next-line typescript/no-explicit-any
32
- const hasSecret = Boolean((entry as any).channelSecret) || Boolean((entry as any).secretFile);
33
- return { tokenSource: hasToken && hasSecret ? "config" : "none" };
34
- },
35
- );
36
-
37
- const runtime = {
38
- config: { writeConfigFile },
39
- channel: { line: { resolveLineAccount } },
40
- } as unknown as PluginRuntime;
41
-
42
- return { runtime, mocks: { writeConfigFile, resolveLineAccount } };
43
- }
44
-
45
- describe("linePlugin gateway.logoutAccount", () => {
46
- beforeEach(() => {
47
- setLineRuntime(createRuntime().runtime);
48
- });
49
-
50
- it("clears tokenFile/secretFile on default account logout", async () => {
51
- const { runtime, mocks } = createRuntime();
52
- setLineRuntime(runtime);
53
-
54
- const cfg: SymiConfig = {
55
- channels: {
56
- line: {
57
- tokenFile: "/tmp/token",
58
- secretFile: "/tmp/secret",
59
- },
60
- },
61
- };
62
- const runtimeEnv: RuntimeEnv = {
63
- log: vi.fn(),
64
- error: vi.fn(),
65
- exit: vi.fn((code: number): never => {
66
- throw new Error(`exit ${code}`);
67
- }),
68
- };
69
- const resolveAccount = mocks.resolveLineAccount as unknown as (params: {
70
- cfg: SymiConfig;
71
- accountId?: string;
72
- }) => ResolvedLineAccount;
73
- const account = resolveAccount({
74
- cfg,
75
- accountId: DEFAULT_ACCOUNT_ID,
76
- });
77
-
78
- const result = await linePlugin.gateway!.logoutAccount!({
79
- accountId: DEFAULT_ACCOUNT_ID,
80
- cfg,
81
- account,
82
- runtime: runtimeEnv,
83
- });
84
-
85
- expect(result.cleared).toBe(true);
86
- expect(result.loggedOut).toBe(true);
87
- expect(mocks.writeConfigFile).toHaveBeenCalledWith({});
88
- });
89
-
90
- it("clears tokenFile/secretFile on account logout", async () => {
91
- const { runtime, mocks } = createRuntime();
92
- setLineRuntime(runtime);
93
-
94
- const cfg: SymiConfig = {
95
- channels: {
96
- line: {
97
- accounts: {
98
- primary: {
99
- tokenFile: "/tmp/token",
100
- secretFile: "/tmp/secret",
101
- },
102
- },
103
- },
104
- },
105
- };
106
- const runtimeEnv: RuntimeEnv = {
107
- log: vi.fn(),
108
- error: vi.fn(),
109
- exit: vi.fn((code: number): never => {
110
- throw new Error(`exit ${code}`);
111
- }),
112
- };
113
- const resolveAccount = mocks.resolveLineAccount as unknown as (params: {
114
- cfg: SymiConfig;
115
- accountId?: string;
116
- }) => ResolvedLineAccount;
117
- const account = resolveAccount({
118
- cfg,
119
- accountId: "primary",
120
- });
121
-
122
- const result = await linePlugin.gateway!.logoutAccount!({
123
- accountId: "primary",
124
- cfg,
125
- account,
126
- runtime: runtimeEnv,
127
- });
128
-
129
- expect(result.cleared).toBe(true);
130
- expect(result.loggedOut).toBe(true);
131
- expect(mocks.writeConfigFile).toHaveBeenCalledWith({});
132
- });
133
- });