@aikaara/chat-sdk 0.1.4 → 0.3.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/dist/headless.mjs CHANGED
@@ -1,11 +1,144 @@
1
- import { A as n, a as t, b as s, C as i, c as o, d as r, E as C, M as l } from "./headless-BhsiNVQj.mjs";
1
+ import { E as y } from "./AikaaraChatClient-Cqbcd1jb.mjs";
2
+ import { A as v, a as F, b as I, C as _, c as E, d as b, M as w, T as U, e as C, i as k, f as j, p as A } from "./AikaaraChatClient-Cqbcd1jb.mjs";
3
+ class m extends y {
4
+ registration = null;
5
+ pendingEdits = [];
6
+ constructor(t) {
7
+ super(), this.setupListeners(t);
8
+ }
9
+ /**
10
+ * Register a form to receive AI-driven edits.
11
+ * Only one form can be registered at a time (the active page).
12
+ */
13
+ registerForm(t) {
14
+ this.registration = t;
15
+ const e = this.pendingEdits.filter(
16
+ (i) => i.entity_type === t.entityType && String(i.entity_id) === String(t.entityId)
17
+ );
18
+ if (e.length > 0) {
19
+ for (const i of e)
20
+ t.onFieldUpdate(i.fields), this.emit("edit:applied", {
21
+ entityType: i.entity_type,
22
+ entityId: i.entity_id,
23
+ fields: i.fields
24
+ });
25
+ this.pendingEdits = this.pendingEdits.filter(
26
+ (i) => !(i.entity_type === t.entityType && String(i.entity_id) === String(t.entityId))
27
+ );
28
+ }
29
+ }
30
+ /**
31
+ * Unregister the form (call on unmount).
32
+ */
33
+ unregisterForm(t, e) {
34
+ this.registration?.entityType === t && String(this.registration?.entityId) === String(e) && (this.registration = null);
35
+ }
36
+ /**
37
+ * Get the current form registration (if any).
38
+ */
39
+ get currentForm() {
40
+ return this.registration;
41
+ }
42
+ /**
43
+ * Manually push field updates (for custom tool handling).
44
+ */
45
+ pushFieldUpdates(t, e, i) {
46
+ this.registration && this.registration.entityType === t && String(this.registration.entityId) === String(e) ? (this.registration.onFieldUpdate(i), this.emit("edit:applied", { entityType: t, entityId: e, fields: i })) : (this.pendingEdits.push({
47
+ action: "edit_entity",
48
+ entity_type: t,
49
+ entity_id: e,
50
+ fields: i
51
+ }), this.emit("edit:pending", { entityType: t, entityId: e, fields: i }));
52
+ }
53
+ /**
54
+ * Request the current form to save.
55
+ */
56
+ async requestSave() {
57
+ if (!this.registration)
58
+ return { success: !1, error: "No form registered" };
59
+ try {
60
+ return await this.registration.onSave(), this.emit("save:success", {
61
+ entityType: this.registration.entityType,
62
+ entityId: this.registration.entityId
63
+ }), { success: !0 };
64
+ } catch (t) {
65
+ const e = t instanceof Error ? t.message : "Save failed";
66
+ return this.emit("save:error", {
67
+ entityType: this.registration.entityType,
68
+ entityId: this.registration.entityId,
69
+ error: e
70
+ }), { success: !1, error: e };
71
+ }
72
+ }
73
+ /**
74
+ * Request the current form to run a test.
75
+ */
76
+ async requestTest(t) {
77
+ if (!this.registration?.onTest)
78
+ return { success: !1, error: "Current form does not support testing" };
79
+ try {
80
+ return await this.registration.onTest(t), { success: !0 };
81
+ } catch (e) {
82
+ return { success: !1, error: e instanceof Error ? e.message : "Test failed" };
83
+ }
84
+ }
85
+ setupListeners(t) {
86
+ t.on("action:edit_entity", (e) => {
87
+ this.pushFieldUpdates(e.entity_type, e.entity_id, e.fields);
88
+ }), t.on("action:save_entity", (e) => {
89
+ this.requestSave();
90
+ }), t.on("action:test_tool", (e) => {
91
+ this.emit("test:triggered", { toolId: e.tool_id, parameters: e.parameters }), this.requestTest(e.parameters);
92
+ });
93
+ }
94
+ }
95
+ function g(r) {
96
+ return {
97
+ async upload(t, e) {
98
+ const i = new FormData(), p = r.fieldName ?? "file";
99
+ i.append(p, t, t.name);
100
+ const a = typeof r.extraFields == "function" ? r.extraFields(e) : r.extraFields;
101
+ if (a)
102
+ for (const [c, u] of Object.entries(a)) i.append(c, u);
103
+ i.append("conversationId", e.conversationId), i.append("userId", e.userId), e.projectId && i.append("projectId", e.projectId);
104
+ const l = typeof r.headers == "function" ? await r.headers() : r.headers ?? {}, n = await fetch(r.endpoint, {
105
+ method: r.method ?? "POST",
106
+ body: i,
107
+ headers: l,
108
+ credentials: r.credentials
109
+ });
110
+ if (!n.ok)
111
+ throw new Error(`Upload failed: ${n.status} ${n.statusText}`);
112
+ const o = await n.json().catch(() => ({}));
113
+ if (r.parseResponse) return r.parseResponse(o, e);
114
+ const s = o, d = s.url ?? s.fileUrl ?? s.publicUrl, h = s.fileName ?? s.name ?? t.name;
115
+ if (!d) throw new Error('Upload response missing "url" / "fileUrl" / "publicUrl"');
116
+ return {
117
+ url: d,
118
+ fileName: h,
119
+ cloudFileId: typeof s.cloudFileId == "string" ? s.cloudFileId : void 0,
120
+ relativePath: typeof s.path == "string" ? s.path : void 0,
121
+ contentType: typeof s.contentType == "string" ? s.contentType : void 0,
122
+ byteSize: typeof s.byteSize == "number" ? s.byteSize : void 0,
123
+ meta: s
124
+ };
125
+ }
126
+ };
127
+ }
2
128
  export {
3
- n as ActionCableClient,
4
- t as AikaaraChatClient,
5
- s as ApiClient,
6
- i as ChannelSubscription,
7
- o as ConnectionManager,
8
- r as ConversationManager,
9
- C as EventEmitter,
10
- l as MessageStore
129
+ v as ActionCableClient,
130
+ F as AikaaraChatClient,
131
+ I as ApiClient,
132
+ _ as ChannelSubscription,
133
+ E as ConnectionManager,
134
+ b as ConversationManager,
135
+ y as EventEmitter,
136
+ m as FormBridge,
137
+ w as MessageStore,
138
+ U as TiledeskTransport,
139
+ g as createFetchUploadAdapter,
140
+ C as extractTiledeskFileEnvelope,
141
+ k as inferTiledeskRole,
142
+ j as isTiledeskSelfEcho,
143
+ A as parseTiledeskTemplate
11
144
  };
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./headless-CrgIWcf7.cjs"),a=require("./ui.cjs");function l(t){a.registerComponents();const r=document.createElement("aikaara-chat-widget"),n={baseUrl:"base-url",userToken:"user-token",apiKey:"api-key",title:"title",subtitle:"subtitle",theme:"theme",primaryColor:"primary-color",position:"position",width:"width",height:"height",placeholder:"placeholder",welcomeMessage:"welcome-message",avatarUrl:"avatar-url"};for(const[o,s]of Object.entries(n)){const i=t[o];i!=null&&r.setAttribute(s,String(i))}return r.configure(t),document.body.appendChild(r),r}function u(){const t=document.querySelector("aikaara-chat-widget");t&&t.remove()}exports.ActionCableClient=e.ActionCableClient;exports.AikaaraChatClient=e.AikaaraChatClient;exports.ApiClient=e.ApiClient;exports.ChannelSubscription=e.ChannelSubscription;exports.ConnectionManager=e.ConnectionManager;exports.ConversationManager=e.ConversationManager;exports.EventEmitter=e.EventEmitter;exports.MessageStore=e.MessageStore;exports.AikaaraChatBubble=a.AikaaraChatBubble;exports.AikaaraChatHeader=a.AikaaraChatHeader;exports.AikaaraChatInput=a.AikaaraChatInput;exports.AikaaraChatWidget=a.AikaaraChatWidget;exports.AikaaraErrorBanner=a.AikaaraErrorBanner;exports.AikaaraMessageBubble=a.AikaaraMessageBubble;exports.AikaaraMessageList=a.AikaaraMessageList;exports.AikaaraStreamingMessage=a.AikaaraStreamingMessage;exports.AikaaraTypingIndicator=a.AikaaraTypingIndicator;exports.registerComponents=a.registerComponents;exports.mount=l;exports.unmount=u;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./AikaaraChatClient-kAu65hX-.cjs"),n=require("./headless.cjs"),a=require("./ui.cjs");function c(t){a.registerComponents();const r=document.createElement("aikaara-chat-widget"),o={baseUrl:"base-url",userToken:"user-token",apiKey:"api-key",title:"title",subtitle:"subtitle",theme:"theme",primaryColor:"primary-color",position:"position",width:"width",height:"height",placeholder:"placeholder",welcomeMessage:"welcome-message",avatarUrl:"avatar-url"};for(const[s,l]of Object.entries(o)){const i=t[s];i!=null&&r.setAttribute(l,String(i))}return r.configure(t),document.body.appendChild(r),r}function d(){const t=document.querySelector("aikaara-chat-widget");t&&t.remove()}exports.ActionCableClient=e.ActionCableClient;exports.AikaaraChatClient=e.AikaaraChatClient;exports.ApiClient=e.ApiClient;exports.ChannelSubscription=e.ChannelSubscription;exports.ConnectionManager=e.ConnectionManager;exports.ConversationManager=e.ConversationManager;exports.EventEmitter=e.EventEmitter;exports.MessageStore=e.MessageStore;exports.TiledeskTransport=e.TiledeskTransport;exports.extractTiledeskFileEnvelope=e.extractTiledeskFileEnvelope;exports.inferTiledeskRole=e.inferTiledeskRole;exports.isTiledeskSelfEcho=e.isTiledeskSelfEcho;exports.parseTiledeskTemplate=e.parseTiledeskTemplate;exports.FormBridge=n.FormBridge;exports.createFetchUploadAdapter=n.createFetchUploadAdapter;exports.AikaaraChatBubble=a.AikaaraChatBubble;exports.AikaaraChatHeader=a.AikaaraChatHeader;exports.AikaaraChatInput=a.AikaaraChatInput;exports.AikaaraChatWidget=a.AikaaraChatWidget;exports.AikaaraErrorBanner=a.AikaaraErrorBanner;exports.AikaaraMessageBubble=a.AikaaraMessageBubble;exports.AikaaraMessageList=a.AikaaraMessageList;exports.AikaaraStreamingMessage=a.AikaaraStreamingMessage;exports.AikaaraTypingIndicator=a.AikaaraTypingIndicator;exports.registerComponents=a.registerComponents;exports.mount=c;exports.unmount=d;