@chativa/connector-dummy 0.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.
package/dist/index.cjs ADDED
@@ -0,0 +1,2 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=class s{constructor(e={}){this.name="dummy",this.addSentToHistory=!0,this.messageHandler=null,this.disconnectHandler=null,this.typingHandler=null,this.statusHandler=null,this.replyDelay=e.replyDelay??500,this.connectDelay=e.connectDelay??2e3}async connect(){this.connectDelay>0&&await new Promise(e=>setTimeout(e,this.connectDelay))}async disconnect(){this.messageHandler=null,this.disconnectHandler?.("user"),this.disconnectHandler=null}async sendMessage(e){const t=e.data.text??"";if(t.trim()==="/disconnect"){await this.disconnect();return}this.typingHandler?.(!0),setTimeout(()=>{this.typingHandler?.(!1);const a=`dummy-reply-${Date.now()}`;this.messageHandler?.({id:a,type:"text",data:{text:`Echo: ${t}`},timestamp:Date.now()}),this.statusHandler&&setTimeout(()=>{this.statusHandler?.(e.id,"read")},1500)},this.replyDelay)}onMessage(e){this.messageHandler=e}onDisconnect(e){this.disconnectHandler=e}onTyping(e){this.typingHandler=e}onMessageStatus(e){this.statusHandler=e}async sendFeedback(e,t){console.log(`[DummyConnector] Feedback received — messageId: ${e}, feedback: ${t}`)}async sendFile(e,t){console.log(`[DummyConnector] File received — name: ${e.name}, size: ${e.size}`,t),setTimeout(()=>{this.messageHandler?.({id:`dummy-file-reply-${Date.now()}`,type:"file",data:{name:e.name,size:e.size,mimeType:e.type,url:URL.createObjectURL(e),caption:t?.caption??void 0},timestamp:Date.now()})},this.replyDelay)}async loadHistory(e){await new Promise(r=>setTimeout(r,400));const t=e?parseInt(e,10):0,a=s._historyPages[t];if(!a)return{messages:[],hasMore:!1};const n=t+1;return{messages:[...a].reverse(),hasMore:n<s._historyPages.length,cursor:n<s._historyPages.length?String(n):void 0}}injectMessage(e){this.messageHandler?.({id:`demo-${Date.now()}-${Math.random().toString(36).slice(2,7)}`,timestamp:Date.now(),...e})}};s._historyPages=[Array.from({length:5},(e,t)=>({id:`history-p1-${t}`,type:"text",from:t%2===0?"bot":"user",data:{text:t%2===0?`Earlier bot message ${t+1}`:`Earlier user message ${t+1}`},timestamp:Date.now()-(600-t*60)*1e3})),Array.from({length:5},(e,t)=>({id:`history-p2-${t}`,type:"text",from:t%2===0?"bot":"user",data:{text:t%2===0?`Much earlier bot message ${t+1}`:`Much earlier user message ${t+1}`},timestamp:Date.now()-(1200-t*60)*1e3}))];let i=s;exports.DummyConnector=i;
2
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs","sources":["../src/DummyConnector.ts"],"sourcesContent":["import type {\n IConnector,\n MessageHandler,\n DisconnectHandler,\n TypingHandler,\n IncomingMessage,\n MessageStatus,\n HistoryResult,\n} from \"@chativa/core\";\nimport type { FeedbackType, MessageStatusHandler } from \"../../core/src/domain/ports/IConnector\";\nimport type { OutgoingMessage } from \"@chativa/core\";\n\n/**\n * DummyConnector — local mock connector for development and testing.\n * Automatically replies after a configurable delay.\n * `connectDelay` simulates a real connection handshake (default 2000ms).\n * Sending \"/disconnect\" as a message triggers a graceful disconnect.\n */\nexport class DummyConnector implements IConnector {\n readonly name = \"dummy\";\n readonly addSentToHistory = true;\n\n private messageHandler: MessageHandler | null = null;\n private disconnectHandler: DisconnectHandler | null = null;\n private typingHandler: TypingHandler | null = null;\n private statusHandler: MessageStatusHandler | null = null;\n private replyDelay: number;\n private connectDelay: number;\n\n /** Fake history pages — two pages of 5 messages each. */\n private static _historyPages: IncomingMessage[][] = [\n Array.from({ length: 5 }, (_, i) => ({\n id: `history-p1-${i}`,\n type: \"text\",\n from: i % 2 === 0 ? (\"bot\" as const) : (\"user\" as const),\n data: { text: i % 2 === 0 ? `Earlier bot message ${i + 1}` : `Earlier user message ${i + 1}` },\n timestamp: Date.now() - (600 - i * 60) * 1000,\n })),\n Array.from({ length: 5 }, (_, i) => ({\n id: `history-p2-${i}`,\n type: \"text\",\n from: i % 2 === 0 ? (\"bot\" as const) : (\"user\" as const),\n data: { text: i % 2 === 0 ? `Much earlier bot message ${i + 1}` : `Much earlier user message ${i + 1}` },\n timestamp: Date.now() - (1200 - i * 60) * 1000,\n })),\n ];\n\n constructor(options: { replyDelay?: number; connectDelay?: number } = {}) {\n this.replyDelay = options.replyDelay ?? 500;\n this.connectDelay = options.connectDelay ?? 2000;\n }\n\n async connect(): Promise<void> {\n if (this.connectDelay > 0) {\n await new Promise<void>((resolve) => setTimeout(resolve, this.connectDelay));\n }\n }\n\n async disconnect(): Promise<void> {\n this.messageHandler = null;\n this.disconnectHandler?.(\"user\");\n this.disconnectHandler = null;\n }\n\n async sendMessage(message: OutgoingMessage): Promise<void> {\n const text = (message.data as { text?: string }).text ?? \"\";\n\n if (text.trim() === \"/disconnect\") {\n await this.disconnect();\n return;\n }\n\n this.typingHandler?.(true);\n setTimeout(() => {\n this.typingHandler?.(false);\n const replyId = `dummy-reply-${Date.now()}`;\n this.messageHandler?.({\n id: replyId,\n type: \"text\",\n data: { text: `Echo: ${text}` },\n timestamp: Date.now(),\n });\n // Simulate \"read\" status for the sent message after a short delay\n if (this.statusHandler) {\n setTimeout(() => {\n this.statusHandler?.(message.id, \"read\" as MessageStatus);\n }, 1500);\n }\n }, this.replyDelay);\n }\n\n onMessage(callback: MessageHandler): void {\n this.messageHandler = callback;\n }\n\n onDisconnect(callback: DisconnectHandler): void {\n this.disconnectHandler = callback;\n }\n\n onTyping(callback: TypingHandler): void {\n this.typingHandler = callback;\n }\n\n onMessageStatus(callback: MessageStatusHandler): void {\n this.statusHandler = callback;\n }\n\n async sendFeedback(messageId: string, feedback: FeedbackType): Promise<void> {\n console.log(`[DummyConnector] Feedback received — messageId: ${messageId}, feedback: ${feedback}`);\n }\n\n async sendFile(file: File, metadata?: Record<string, unknown>): Promise<void> {\n console.log(`[DummyConnector] File received — name: ${file.name}, size: ${file.size}`, metadata);\n // Echo back a file message so the UI reflects the upload\n setTimeout(() => {\n this.messageHandler?.({\n id: `dummy-file-reply-${Date.now()}`,\n type: \"file\",\n data: {\n name: file.name,\n size: file.size,\n mimeType: file.type,\n url: URL.createObjectURL(file),\n caption: (metadata?.caption as string | undefined) ?? undefined,\n },\n timestamp: Date.now(),\n });\n }, this.replyDelay);\n }\n\n async loadHistory(cursor?: string): Promise<HistoryResult> {\n await new Promise<void>((resolve) => setTimeout(resolve, 400));\n const pageIndex = cursor ? parseInt(cursor, 10) : 0;\n const page = DummyConnector._historyPages[pageIndex];\n if (!page) {\n return { messages: [], hasMore: false };\n }\n const nextPage = pageIndex + 1;\n return {\n messages: [...page].reverse(), // oldest-first within page\n hasMore: nextPage < DummyConnector._historyPages.length,\n cursor: nextPage < DummyConnector._historyPages.length ? String(nextPage) : undefined,\n };\n }\n\n /**\n * Directly inject a bot message — used by the sandbox demo buttons.\n * Does not go through the extension pipeline.\n */\n injectMessage(msg: Omit<IncomingMessage, \"id\" | \"timestamp\">): void {\n this.messageHandler?.({\n id: `demo-${Date.now()}-${Math.random().toString(36).slice(2, 7)}`,\n timestamp: Date.now(),\n ...msg,\n });\n }\n}\n"],"names":["_DummyConnector","options","resolve","message","text","replyId","callback","messageId","feedback","file","metadata","cursor","pageIndex","page","nextPage","msg","_","i","DummyConnector"],"mappings":"gFAkBO,MAAMA,EAAN,MAAMA,CAAqC,CA6BhD,YAAYC,EAA0D,GAAI,CA5B1E,KAAS,KAAO,QAChB,KAAS,iBAAmB,GAE5B,KAAQ,eAAwC,KAChD,KAAQ,kBAA8C,KACtD,KAAQ,cAAsC,KAC9C,KAAQ,cAA6C,KAuBnD,KAAK,WAAaA,EAAQ,YAAc,IACxC,KAAK,aAAeA,EAAQ,cAAgB,GAC9C,CAEA,MAAM,SAAyB,CACzB,KAAK,aAAe,GACtB,MAAM,IAAI,QAAeC,GAAY,WAAWA,EAAS,KAAK,YAAY,CAAC,CAE/E,CAEA,MAAM,YAA4B,CAChC,KAAK,eAAiB,K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AA,EA1BC,IAAMC,EAANlB"}
@@ -0,0 +1,49 @@
1
+ import { DisconnectHandler } from '../../core/src/index.ts';
2
+ import { FeedbackType } from '../../core/src/domain/ports/IConnector';
3
+ import { HistoryResult } from '../../core/src/index.ts';
4
+ import { IConnector } from '../../core/src/index.ts';
5
+ import { IncomingMessage } from '../../core/src/index.ts';
6
+ import { MessageHandler } from '../../core/src/index.ts';
7
+ import { MessageStatusHandler } from '../../core/src/domain/ports/IConnector';
8
+ import { OutgoingMessage } from '../../core/src/index.ts';
9
+ import { TypingHandler } from '../../core/src/index.ts';
10
+
11
+ /**
12
+ * DummyConnector — local mock connector for development and testing.
13
+ * Automatically replies after a configurable delay.
14
+ * `connectDelay` simulates a real connection handshake (default 2000ms).
15
+ * Sending "/disconnect" as a message triggers a graceful disconnect.
16
+ */
17
+ export declare class DummyConnector implements IConnector {
18
+ readonly name = "dummy";
19
+ readonly addSentToHistory = true;
20
+ private messageHandler;
21
+ private disconnectHandler;
22
+ private typingHandler;
23
+ private statusHandler;
24
+ private replyDelay;
25
+ private connectDelay;
26
+ /** Fake history pages — two pages of 5 messages each. */
27
+ private static _historyPages;
28
+ constructor(options?: {
29
+ replyDelay?: number;
30
+ connectDelay?: number;
31
+ });
32
+ connect(): Promise<void>;
33
+ disconnect(): Promise<void>;
34
+ sendMessage(message: OutgoingMessage): Promise<void>;
35
+ onMessage(callback: MessageHandler): void;
36
+ onDisconnect(callback: DisconnectHandler): void;
37
+ onTyping(callback: TypingHandler): void;
38
+ onMessageStatus(callback: MessageStatusHandler): void;
39
+ sendFeedback(messageId: string, feedback: FeedbackType): Promise<void>;
40
+ sendFile(file: File, metadata?: Record<string, unknown>): Promise<void>;
41
+ loadHistory(cursor?: string): Promise<HistoryResult>;
42
+ /**
43
+ * Directly inject a bot message — used by the sandbox demo buttons.
44
+ * Does not go through the extension pipeline.
45
+ */
46
+ injectMessage(msg: Omit<IncomingMessage, "id" | "timestamp">): void;
47
+ }
48
+
49
+ export { }
package/dist/index.js ADDED
@@ -0,0 +1,106 @@
1
+ const s = class s {
2
+ constructor(e = {}) {
3
+ this.name = "dummy", this.addSentToHistory = !0, this.messageHandler = null, this.disconnectHandler = null, this.typingHandler = null, this.statusHandler = null, this.replyDelay = e.replyDelay ?? 500, this.connectDelay = e.connectDelay ?? 2e3;
4
+ }
5
+ async connect() {
6
+ this.connectDelay > 0 && await new Promise((e) => setTimeout(e, this.connectDelay));
7
+ }
8
+ async disconnect() {
9
+ this.messageHandler = null, this.disconnectHandler?.("user"), this.disconnectHandler = null;
10
+ }
11
+ async sendMessage(e) {
12
+ const t = e.data.text ?? "";
13
+ if (t.trim() === "/disconnect") {
14
+ await this.disconnect();
15
+ return;
16
+ }
17
+ this.typingHandler?.(!0), setTimeout(() => {
18
+ this.typingHandler?.(!1);
19
+ const a = `dummy-reply-${Date.now()}`;
20
+ this.messageHandler?.({
21
+ id: a,
22
+ type: "text",
23
+ data: { text: `Echo: ${t}` },
24
+ timestamp: Date.now()
25
+ }), this.statusHandler && setTimeout(() => {
26
+ this.statusHandler?.(e.id, "read");
27
+ }, 1500);
28
+ }, this.replyDelay);
29
+ }
30
+ onMessage(e) {
31
+ this.messageHandler = e;
32
+ }
33
+ onDisconnect(e) {
34
+ this.disconnectHandler = e;
35
+ }
36
+ onTyping(e) {
37
+ this.typingHandler = e;
38
+ }
39
+ onMessageStatus(e) {
40
+ this.statusHandler = e;
41
+ }
42
+ async sendFeedback(e, t) {
43
+ console.log(`[DummyConnector] Feedback received — messageId: ${e}, feedback: ${t}`);
44
+ }
45
+ async sendFile(e, t) {
46
+ console.log(`[DummyConnector] File received — name: ${e.name}, size: ${e.size}`, t), setTimeout(() => {
47
+ this.messageHandler?.({
48
+ id: `dummy-file-reply-${Date.now()}`,
49
+ type: "file",
50
+ data: {
51
+ name: e.name,
52
+ size: e.size,
53
+ mimeType: e.type,
54
+ url: URL.createObjectURL(e),
55
+ caption: t?.caption ?? void 0
56
+ },
57
+ timestamp: Date.now()
58
+ });
59
+ }, this.replyDelay);
60
+ }
61
+ async loadHistory(e) {
62
+ await new Promise((r) => setTimeout(r, 400));
63
+ const t = e ? parseInt(e, 10) : 0, a = s._historyPages[t];
64
+ if (!a)
65
+ return { messages: [], hasMore: !1 };
66
+ const n = t + 1;
67
+ return {
68
+ messages: [...a].reverse(),
69
+ // oldest-first within page
70
+ hasMore: n < s._historyPages.length,
71
+ cursor: n < s._historyPages.length ? String(n) : void 0
72
+ };
73
+ }
74
+ /**
75
+ * Directly inject a bot message — used by the sandbox demo buttons.
76
+ * Does not go through the extension pipeline.
77
+ */
78
+ injectMessage(e) {
79
+ this.messageHandler?.({
80
+ id: `demo-${Date.now()}-${Math.random().toString(36).slice(2, 7)}`,
81
+ timestamp: Date.now(),
82
+ ...e
83
+ });
84
+ }
85
+ };
86
+ s._historyPages = [
87
+ Array.from({ length: 5 }, (e, t) => ({
88
+ id: `history-p1-${t}`,
89
+ type: "text",
90
+ from: t % 2 === 0 ? "bot" : "user",
91
+ data: { text: t % 2 === 0 ? `Earlier bot message ${t + 1}` : `Earlier user message ${t + 1}` },
92
+ timestamp: Date.now() - (600 - t * 60) * 1e3
93
+ })),
94
+ Array.from({ length: 5 }, (e, t) => ({
95
+ id: `history-p2-${t}`,
96
+ type: "text",
97
+ from: t % 2 === 0 ? "bot" : "user",
98
+ data: { text: t % 2 === 0 ? `Much earlier bot message ${t + 1}` : `Much earlier user message ${t + 1}` },
99
+ timestamp: Date.now() - (1200 - t * 60) * 1e3
100
+ }))
101
+ ];
102
+ let i = s;
103
+ export {
104
+ i as DummyConnector
105
+ };
106
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":["../src/DummyConnector.ts"],"sourcesContent":["import type {\n IConnector,\n MessageHandler,\n DisconnectHandler,\n TypingHandler,\n IncomingMessage,\n MessageStatus,\n HistoryResult,\n} from \"@chativa/core\";\nimport type { FeedbackType, MessageStatusHandler } from \"../../core/src/domain/ports/IConnector\";\nimport type { OutgoingMessage } from \"@chativa/core\";\n\n/**\n * DummyConnector — local mock connector for development and testing.\n * Automatically replies after a configurable delay.\n * `connectDelay` simulates a real connection handshake (default 2000ms).\n * Sending \"/disconnect\" as a message triggers a graceful disconnect.\n */\nexport class DummyConnector implements IConnector {\n readonly name = \"dummy\";\n readonly addSentToHistory = true;\n\n private messageHandler: MessageHandler | null = null;\n private disconnectHandler: DisconnectHandler | null = null;\n private typingHandler: TypingHandler | null = null;\n private statusHandler: MessageStatusHandler | null = null;\n private replyDelay: number;\n private connectDelay: number;\n\n /** Fake history pages — two pages of 5 messages each. */\n private static _historyPages: IncomingMessage[][] = [\n Array.from({ length: 5 }, (_, i) => ({\n id: `history-p1-${i}`,\n type: \"text\",\n from: i % 2 === 0 ? (\"bot\" as const) : (\"user\" as const),\n data: { text: i % 2 === 0 ? `Earlier bot message ${i + 1}` : `Earlier user message ${i + 1}` },\n timestamp: Date.now() - (600 - i * 60) * 1000,\n })),\n Array.from({ length: 5 }, (_, i) => ({\n id: `history-p2-${i}`,\n type: \"text\",\n from: i % 2 === 0 ? (\"bot\" as const) : (\"user\" as const),\n data: { text: i % 2 === 0 ? `Much earlier bot message ${i + 1}` : `Much earlier user message ${i + 1}` },\n timestamp: Date.now() - (1200 - i * 60) * 1000,\n })),\n ];\n\n constructor(options: { replyDelay?: number; connectDelay?: number } = {}) {\n this.replyDelay = options.replyDelay ?? 500;\n this.connectDelay = options.connectDelay ?? 2000;\n }\n\n async connect(): Promise<void> {\n if (this.connectDelay > 0) {\n await new Promise<void>((resolve) => setTimeout(resolve, this.connectDelay));\n }\n }\n\n async disconnect(): Promise<void> {\n this.messageHandler = null;\n this.disconnectHandler?.(\"user\");\n this.disconnectHandler = null;\n }\n\n async sendMessage(message: OutgoingMessage): Promise<void> {\n const text = (message.data as { text?: string }).text ?? \"\";\n\n if (text.trim() === \"/disconnect\") {\n await this.disconnect();\n return;\n }\n\n this.typingHandler?.(true);\n setTimeout(() => {\n this.typingHandler?.(false);\n const replyId = `dummy-reply-${Date.now()}`;\n this.messageHandler?.({\n id: replyId,\n type: \"text\",\n data: { text: `Echo: ${text}` },\n timestamp: Date.now(),\n });\n // Simulate \"read\" status for the sent message after a short delay\n if (this.statusHandler) {\n setTimeout(() => {\n this.statusHandler?.(message.id, \"read\" as MessageStatus);\n }, 1500);\n }\n }, this.replyDelay);\n }\n\n onMessage(callback: MessageHandler): void {\n this.messageHandler = callback;\n }\n\n onDisconnect(callback: DisconnectHandler): void {\n this.disconnectHandler = callback;\n }\n\n onTyping(callback: TypingHandler): void {\n this.typingHandler = callback;\n }\n\n onMessageStatus(callback: MessageStatusHandler): void {\n this.statusHandler = callback;\n }\n\n async sendFeedback(messageId: string, feedback: FeedbackType): Promise<void> {\n console.log(`[DummyConnector] Feedback received — messageId: ${messageId}, feedback: ${feedback}`);\n }\n\n async sendFile(file: File, metadata?: Record<string, unknown>): Promise<void> {\n console.log(`[DummyConnector] File received — name: ${file.name}, size: ${file.size}`, metadata);\n // Echo back a file message so the UI reflects the upload\n setTimeout(() => {\n this.messageHandler?.({\n id: `dummy-file-reply-${Date.now()}`,\n type: \"file\",\n data: {\n name: file.name,\n size: file.size,\n mimeType: file.type,\n url: URL.createObjectURL(file),\n caption: (metadata?.caption as string | undefined) ?? undefined,\n },\n timestamp: Date.now(),\n });\n }, this.replyDelay);\n }\n\n async loadHistory(cursor?: string): Promise<HistoryResult> {\n await new Promise<void>((resolve) => setTimeout(resolve, 400));\n const pageIndex = cursor ? parseInt(cursor, 10) : 0;\n const page = DummyConnector._historyPages[pageIndex];\n if (!page) {\n return { messages: [], hasMore: false };\n }\n const nextPage = pageIndex + 1;\n return {\n messages: [...page].reverse(), // oldest-first within page\n hasMore: nextPage < DummyConnector._historyPages.length,\n cursor: nextPage < DummyConnector._historyPages.length ? String(nextPage) : undefined,\n };\n }\n\n /**\n * Directly inject a bot message — used by the sandbox demo buttons.\n * Does not go through the extension pipeline.\n */\n injectMessage(msg: Omit<IncomingMessage, \"id\" | \"timestamp\">): void {\n this.messageHandler?.({\n id: `demo-${Date.now()}-${Math.random().toString(36).slice(2, 7)}`,\n timestamp: Date.now(),\n ...msg,\n });\n }\n}\n"],"names":["_DummyConnector","options","resolve","message","text","replyId","callback","messageId","feedback","file","metadata","cursor","pageIndex","page","nextPage","msg","_","i","DummyConnector"],"mappings":"AAkBO,MAAMA,IAAN,MAAMA,EAAqC;AAAA,EA6BhD,YAAYC,IAA0D,IAAI;AA5B1E,SAAS,OAAO,SAChB,KAAS,mBAAmB,IAE5B,KAAQ,iBAAwC,MAChD,KAAQ,oBAA8C,MACtD,KAAQ,gBAAsC,MAC9C,KAAQ,gBAA6C,MAuBnD,KAAK,aAAaA,EAAQ,cAAc,KACxC,KAAK,eAAeA,EAAQ,gBAAgB;AAAA,EAC9C;AAAA,EAEA,MAAM,UAAyB;AAC7B,IAAI,KAAK,eAAe,KACtB,MAAM,IAAI,QAAc,CAACC,MAAY,WAAWA,GAAS,KAAK,YAAY,CAAC;AAAA,EAE/E;AAAA,EAEA,MAAM,aAA4B;AAChC,SAAK,iBAAiB,MACtB,KAAK,oBAAoB,MAAM,GAC/B,KAAK,oBAAoB;AAAA,EAC3B;AAAA,EAEA,MAAM,YAAYC,GAAyC;AACzD,UAAMC,IAAQD,EAAQ,KAA2B,QAAQ;AAEzD,QAAIC,EAAK,KAAA,MAAW,eAAe;AACjC,YAAM,KAAK,WAAA;AACX;AAAA,IACF;AAEA,SAAK,gBAAgB,EAAI,GACzB,WAAW,MAAM;AACf,WAAK,gBAAgB,EAAK;AAC1B,YAAMC,IAAU,eAAe,KAAK,IAAA,CAAK;AACzC,WAAK,iBAAiB;AAAA,QACpB,IAAIA;AAAA,QACJ,MAAM;AAAA,QACN,MAAM,EAAE,MAAM,SAASD,CAAI,GAAA;AAAA,QAC3B,WAAW,KAAK,IAAA;AAAA,MAAI,CACrB,GAEG,KAAK,iBACP,WAAW,MAAM;AACf,aAAK,gBAAgBD,EAAQ,IAAI,MAAuB;AAAA,MAC1D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B,SAASC,IAAWd,EAAe,cAAc;AAAA,MACjD,QAAQc,IAAWd,EAAe,cAAc,SAAS,OAAOc,CAAQ,IAAI;AAAA,IAAA;AAAA,EAEhF;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,cAAcC,GAAsD;AAClE,SAAK,iBAAiB;AAAA,MACpB,IAAI,QAAQ,KAAK,IAAA,CAAK,IAAI,KAAK,OAAA,EAAS,SAAS,EAAE,EAAE,MAAM,GAAG,CAAC,CAAC;AAAA,MAChE,WAAW,KAAK,IAAA;AAAA,MAChB,GAAGA;AAAA,IAAA,CACJ;AAAA,EACH;AACF;AA9HEf,EAAe,gBAAqC;AAAA,EAClD,MAAM,KAAK,EAAE,QAAQ,KAAK,CAACgB,GAAGC,OAAO;AAAA,IACnC,IAAI,cAAcA,CAAC;AAAA,IACnB,MAAM;AAAA,IACN,MAAMA,IAAI,MAAM,IAAK,QAAmB;AAAA,IACxC,MAAM,EAAE,MAAMA,IAAI,MAAM,IAAI,uBAAuBA,IAAI,CAAC,KAAK,wBAAwBA,IAAI,CAAC,GAAA;AAAA,IAC1F,WAAW,KAAK,IAAA,KAAS,MAAMA,IAAI,MAAM;AAAA,EAAA,EACzC;AAAA,EACF,MAAM,KAAK,EAAE,QAAQ,KAAK,CAACD,GAAGC,OAAO;AAAA,IACnC,IAAI,cAAcA,CAAC;AAAA,IACnB,MAAM;AAAA,IACN,MAAMA,IAAI,MAAM,IAAK,QAAmB;AAAA,IACxC,MAAM,EAAE,MAAMA,IAAI,MAAM,IAAI,4BAA4BA,IAAI,CAAC,KAAK,6BAA6BA,IAAI,CAAC,GAAA;AAAA,IACpG,WAAW,KAAK,IAAA,KAAS,OAAOA,IAAI,MAAM;AAAA,EAAA,EAC1C;AAAA;AA1BC,IAAMC,IAANlB;"}
package/package.json ADDED
@@ -0,0 +1,52 @@
1
+ {
2
+ "name": "@chativa/connector-dummy",
3
+ "version": "0.0.1",
4
+ "description": "Chativa dummy connector — local echo connector for dev and testing.",
5
+ "author": "Hamza Agar",
6
+ "license": "MIT",
7
+ "type": "module",
8
+ "main": "./dist/index.cjs",
9
+ "module": "./dist/index.js",
10
+ "types": "./dist/index.d.ts",
11
+ "exports": {
12
+ ".": {
13
+ "import": "./dist/index.js",
14
+ "require": "./dist/index.cjs",
15
+ "types": "./dist/index.d.ts"
16
+ }
17
+ },
18
+ "files": [
19
+ "dist"
20
+ ],
21
+ "keywords": [
22
+ "chativa",
23
+ "chat",
24
+ "connector",
25
+ "dummy",
26
+ "mock"
27
+ ],
28
+ "homepage": "https://github.com/AimTune/chativa#readme",
29
+ "bugs": {
30
+ "url": "https://github.com/AimTune/chativa/issues"
31
+ },
32
+ "repository": {
33
+ "type": "git",
34
+ "url": "git+https://github.com/AimTune/chativa.git"
35
+ },
36
+ "peerDependencies": {
37
+ "@chativa/core": ">=0.0.1"
38
+ },
39
+ "devDependencies": {
40
+ "jsdom": "^28.1.0",
41
+ "typescript": "~5.8.3",
42
+ "vite": "^7.0.3",
43
+ "vite-plugin-dts": "^4.5.4",
44
+ "vitest": "^4.0.18",
45
+ "@chativa/core": "0.0.1"
46
+ },
47
+ "scripts": {
48
+ "build": "vite build",
49
+ "test": "vitest run",
50
+ "typecheck": "tsc --noEmit"
51
+ }
52
+ }