@useago/sdk 0.2.0 → 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/README.md +102 -6
- package/dist/AgoClient-B-SONi_K.js +861 -0
- package/dist/AgoClient-B-SONi_K.js.map +1 -0
- package/dist/AgoClient-xTWfMWKh.cjs +860 -0
- package/dist/AgoClient-xTWfMWKh.cjs.map +1 -0
- package/dist/angular.cjs +100 -138
- package/dist/angular.cjs.map +1 -1
- package/dist/angular.d.ts +0 -1
- package/dist/angular.js +103 -139
- package/dist/angular.js.map +1 -1
- package/dist/client/AgoClient.d.ts +0 -56
- package/dist/client/types.d.ts +1 -5
- package/dist/createMockClient-B1DcBiIK.js +94 -0
- package/dist/createMockClient-B1DcBiIK.js.map +1 -0
- package/dist/createMockClient-BqNSJUu4.cjs +93 -0
- package/dist/createMockClient-BqNSJUu4.cjs.map +1 -0
- package/dist/helpers.cjs +305 -14
- package/dist/helpers.cjs.map +1 -0
- package/dist/helpers.d.ts +0 -1
- package/dist/helpers.js +306 -2
- package/dist/helpers.js.map +1 -0
- package/dist/index.cjs +151 -284
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +0 -3
- package/dist/index.js +163 -258
- package/dist/index.js.map +1 -1
- package/dist/react/components/ChatWidget.d.ts +0 -2
- package/dist/react/components/Message.d.ts +0 -2
- package/dist/react/components/index.d.ts +0 -2
- package/dist/react/context/AgoContext.d.ts +3 -29
- package/dist/react/context/index.d.ts +1 -1
- package/dist/react/hooks/index.d.ts +0 -1
- package/dist/react/hooks/useAgoFunction.d.ts +2 -14
- package/dist/react/index.d.ts +1 -4
- package/dist/react.cjs +10274 -22104
- package/dist/react.cjs.map +1 -1
- package/dist/react.d.ts +0 -1
- package/dist/react.js +10289 -22103
- package/dist/react.js.map +1 -1
- package/dist/vue.cjs +208 -287
- package/dist/vue.cjs.map +1 -1
- package/dist/vue.d.ts +0 -1
- package/dist/vue.js +218 -287
- package/dist/vue.js.map +1 -1
- package/dist/widget/types.d.ts +0 -1
- package/dist/widget.cjs +2 -0
- package/dist/widget.cjs.map +1 -0
- package/dist/widget.d.ts +0 -1
- package/dist/widget.js +2 -0
- package/dist/widget.js.map +1 -0
- package/package.json +1 -1
- package/dist/AgoClient-CNT-8sh_.js +0 -905
- package/dist/AgoClient-CNT-8sh_.js.map +0 -1
- package/dist/AgoClient-D0l1GTRs.cjs +0 -976
- package/dist/AgoClient-D0l1GTRs.cjs.map +0 -1
- package/dist/createMockClient-Ci_N2tH8.cjs +0 -104
- package/dist/createMockClient-Ci_N2tH8.cjs.map +0 -1
- package/dist/createMockClient-U0ae_AYy.js +0 -99
- package/dist/createMockClient-U0ae_AYy.js.map +0 -1
- package/dist/functions--c6lx3ic.cjs +0 -480
- package/dist/functions--c6lx3ic.cjs.map +0 -1
- package/dist/functions-C9F1dnmh.js +0 -398
- package/dist/functions-C9F1dnmh.js.map +0 -1
- package/dist/helpers/factory.d.ts +0 -20
- package/dist/react/components/Markdown.d.ts +0 -12
- package/dist/react/hooks/useAgoContext.d.ts +0 -40
- package/dist/rolldown-runtime-BqCkTl7Q.cjs +0 -50
- package/dist/rolldown-runtime-CNZpIYwj.js +0 -33
- package/dist/state/ClientContextRegistry.d.ts +0 -64
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helpers.js","sources":["../src/helpers/functions.ts"],"sourcesContent":["import type { ClientFunctionDefinition } from \"../functions/types\";\n\n/**\n * Show a toast/notification to the user.\n * The handler is a no-op by default — wire it up to your toast library.\n *\n * ```ts\n * import { showToast } from \"@useago/sdk/helpers\";\n * showToast.handler = async (args) => { myToast(args.message); return { shown: true }; };\n * client.registerFunction(showToast);\n * ```\n */\nexport const showToast: ClientFunctionDefinition = {\n name: \"showToast\",\n description:\n \"Show a toast notification to the user. Use this to confirm actions or display brief messages.\",\n parameters: {\n type: \"object\",\n properties: {\n message: { type: \"string\", description: \"The message to display\" },\n type: {\n type: \"string\",\n description: \"Toast type\",\n enum: [\"success\", \"error\", \"warning\", \"info\"],\n },\n duration: {\n type: \"number\",\n description: \"Duration in milliseconds (default 3000)\",\n },\n },\n required: [\"message\"],\n },\n handler: async () => ({ shown: false, error: \"No toast handler configured\" }),\n};\n\n/**\n * Show a browser notification (requires permission).\n */\nexport const showNotification: ClientFunctionDefinition = {\n name: \"showNotification\",\n description:\n \"Show a browser notification to the user. Useful for important alerts even when the tab is not focused.\",\n parameters: {\n type: \"object\",\n properties: {\n title: { type: \"string\", description: \"Notification title\" },\n body: { type: \"string\", description: \"Notification body text\" },\n },\n required: [\"title\"],\n },\n handler: async (args) => {\n if (typeof Notification === \"undefined\") {\n return { shown: false, error: \"Notifications not supported\" };\n }\n if (Notification.permission === \"denied\") {\n return { shown: false, error: \"Notification permission denied\" };\n }\n if (Notification.permission !== \"granted\") {\n await Notification.requestPermission();\n }\n if (Notification.permission === \"granted\") {\n new Notification(args.title as string, { body: args.body as string });\n return { shown: true };\n }\n return { shown: false, error: \"Permission not granted\" };\n },\n};\n\n/**\n * Open a URL in a new tab.\n */\nexport const openUrl: ClientFunctionDefinition = {\n name: \"openUrl\",\n description: \"Open a URL in a new browser tab.\",\n parameters: {\n type: \"object\",\n properties: {\n url: { type: \"string\", description: \"The URL to open\" },\n },\n required: [\"url\"],\n },\n handler: async (args) => {\n window.open(args.url as string, \"_blank\", \"noopener,noreferrer\");\n return { opened: true };\n },\n};\n\n/**\n * Copy text to clipboard.\n */\nexport const copyToClipboard: ClientFunctionDefinition = {\n name: \"copyToClipboard\",\n description: \"Copy text to the user's clipboard.\",\n parameters: {\n type: \"object\",\n properties: {\n text: { type: \"string\", description: \"The text to copy\" },\n },\n required: [\"text\"],\n },\n handler: async (args) => {\n await navigator.clipboard.writeText(args.text as string);\n return { copied: true };\n },\n};\n\n/**\n * Set the application theme (light/dark/system).\n * Default handler toggles a `data-theme` attribute on `<html>`.\n */\nexport const setTheme: ClientFunctionDefinition = {\n name: \"setTheme\",\n description:\n \"Change the application's color theme. Sets a data-theme attribute on the document element.\",\n parameters: {\n type: \"object\",\n properties: {\n theme: {\n type: \"string\",\n description: \"Theme to apply\",\n enum: [\"light\", \"dark\", \"system\"],\n },\n },\n required: [\"theme\"],\n },\n handler: async (args) => {\n const theme = args.theme as string;\n document.documentElement.setAttribute(\"data-theme\", theme);\n if (theme === \"dark\") {\n document.documentElement.classList.add(\"dark\");\n } else {\n document.documentElement.classList.remove(\"dark\");\n }\n return { theme, applied: true };\n },\n};\n\n/**\n * Show a confirm dialog and return the user's choice.\n */\nexport const showConfirmDialog: ClientFunctionDefinition = {\n name: \"showConfirmDialog\",\n description:\n \"Show a confirmation dialog to the user and return their choice (true/false).\",\n parameters: {\n type: \"object\",\n properties: {\n message: {\n type: \"string\",\n description: \"The confirmation message to display\",\n },\n },\n required: [\"message\"],\n },\n handler: async (args) => {\n const confirmed = window.confirm(args.message as string);\n return { confirmed };\n },\n};\n\n/**\n * Get the user's geolocation.\n */\nexport const getUserLocation: ClientFunctionDefinition = {\n name: \"getUserLocation\",\n description:\n \"Get the user's current geographic location (requires permission).\",\n parameters: {\n type: \"object\",\n properties: {},\n },\n handler: async () => {\n if (!navigator.geolocation) {\n return { error: \"Geolocation not supported\" };\n }\n return new Promise((resolve) => {\n navigator.geolocation.getCurrentPosition(\n (pos) =>\n resolve({\n latitude: pos.coords.latitude,\n longitude: pos.coords.longitude,\n accuracy: pos.coords.accuracy,\n }),\n (err) => resolve({ error: err.message })\n );\n });\n },\n};\n\n/**\n * Scroll to an element on the page.\n */\nexport const scrollToElement: ClientFunctionDefinition = {\n name: \"scrollToElement\",\n description: \"Scroll the page to a specific element identified by CSS selector.\",\n parameters: {\n type: \"object\",\n properties: {\n selector: {\n type: \"string\",\n description: \"CSS selector of the element to scroll to (e.g. '#section-pricing')\",\n },\n behavior: {\n type: \"string\",\n description: \"Scroll behavior\",\n enum: [\"smooth\", \"instant\"],\n },\n },\n required: [\"selector\"],\n },\n handler: async (args) => {\n const el = document.querySelector(args.selector as string);\n if (!el) {\n return { scrolled: false, error: `Element not found: ${args.selector}` };\n }\n el.scrollIntoView({ behavior: (args.behavior as ScrollBehavior) || \"smooth\" });\n return { scrolled: true };\n },\n};\n\n/**\n * Set a value in localStorage.\n */\nexport const setLocalStorage: ClientFunctionDefinition = {\n name: \"setLocalStorage\",\n description: \"Store a value in the browser's localStorage.\",\n parameters: {\n type: \"object\",\n properties: {\n key: { type: \"string\", description: \"Storage key\" },\n value: { type: \"string\", description: \"Value to store\" },\n },\n required: [\"key\", \"value\"],\n },\n handler: async (args) => {\n localStorage.setItem(args.key as string, args.value as string);\n return { stored: true };\n },\n};\n\n/**\n * Get a value from localStorage.\n */\nexport const getLocalStorage: ClientFunctionDefinition = {\n name: \"getLocalStorage\",\n description: \"Retrieve a value from the browser's localStorage.\",\n parameters: {\n type: \"object\",\n properties: {\n key: { type: \"string\", description: \"Storage key\" },\n },\n required: [\"key\"],\n },\n handler: async (args) => {\n const value = localStorage.getItem(args.key as string);\n return { key: args.key, value, found: value !== null };\n },\n};\n\n/**\n * Highlight an element on the page (useful for guided tours).\n */\nexport const highlightElement: ClientFunctionDefinition = {\n name: \"highlightElement\",\n description:\n \"Highlight a DOM element to draw the user's attention (e.g. for onboarding).\",\n parameters: {\n type: \"object\",\n properties: {\n selector: {\n type: \"string\",\n description: \"CSS selector of the element to highlight\",\n },\n color: {\n type: \"string\",\n description: \"Highlight border color (default: #3b82f6)\",\n },\n },\n required: [\"selector\"],\n },\n handler: async (args) => {\n const el = document.querySelector(args.selector as string) as HTMLElement | null;\n if (!el) {\n return { highlighted: false, error: `Element not found: ${args.selector}` };\n }\n const prev = el.style.outline;\n const color = (args.color as string) || \"#3b82f6\";\n el.style.outline = `3px solid ${color}`;\n el.style.outlineOffset = \"2px\";\n el.scrollIntoView({ behavior: \"smooth\", block: \"center\" });\n setTimeout(() => {\n el.style.outline = prev;\n el.style.outlineOffset = \"\";\n }, 3000);\n return { highlighted: true };\n },\n};\n\n/**\n * Submit a form on the page programmatically.\n */\nexport const submitForm: ClientFunctionDefinition = {\n name: \"submitForm\",\n description:\n \"Fill and submit an HTML form on the page. Pass field values as key-value pairs.\",\n parameters: {\n type: \"object\",\n properties: {\n selector: {\n type: \"string\",\n description: \"CSS selector of the form element\",\n },\n values: {\n type: \"string\",\n description: \"JSON string of field name → value pairs\",\n },\n },\n required: [\"selector\"],\n },\n handler: async (args) => {\n const form = document.querySelector(args.selector as string) as HTMLFormElement | null;\n if (!form) {\n return { submitted: false, error: `Form not found: ${args.selector}` };\n }\n if (args.values) {\n const values = JSON.parse(args.values as string) as Record<string, string>;\n for (const [name, value] of Object.entries(values)) {\n const input = form.elements.namedItem(name) as HTMLInputElement | null;\n if (input) input.value = value;\n }\n }\n form.requestSubmit();\n return { submitted: true };\n },\n};\n\n/**\n * Track a custom analytics event.\n * Default handler logs to console — replace with your analytics provider.\n */\nexport const trackEvent: ClientFunctionDefinition = {\n name: \"trackEvent\",\n description:\n \"Track a custom analytics event. Override the handler to wire up your analytics provider.\",\n parameters: {\n type: \"object\",\n properties: {\n event: { type: \"string\", description: \"Event name\" },\n properties: {\n type: \"string\",\n description: \"JSON string of event properties\",\n },\n },\n required: [\"event\"],\n },\n handler: async (args) => {\n const props = args.properties ? JSON.parse(args.properties as string) : {};\n console.log(`[AGO Analytics] ${args.event}`, props);\n return { tracked: true, event: args.event };\n },\n};\n"],"names":[],"mappings":"AAYO,MAAM,YAAsC;AAAA,EACjD,MAAM;AAAA,EACN,aACE;AAAA,EACF,YAAY;AAAA,IACV,MAAM;AAAA,IACN,YAAY;AAAA,MACV,SAAS,EAAE,MAAM,UAAU,aAAa,yBAAA;AAAA,MACxC,MAAM;AAAA,QACJ,MAAM;AAAA,QACN,aAAa;AAAA,QACb,MAAM,CAAC,WAAW,SAAS,WAAW,MAAM;AAAA,MAAA;AAAA,MAE9C,UAAU;AAAA,QACR,MAAM;AAAA,QACN,aAAa;AAAA,MAAA;AAAA,IACf;AAAA,IAEF,UAAU,CAAC,SAAS;AAAA,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MAAA;AAAA,EACtC;AACF;"}
|
package/dist/index.cjs
CHANGED
|
@@ -1,315 +1,182 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const
|
|
3
|
-
const
|
|
4
|
-
const
|
|
5
|
-
//#region src/functions/defineFunction.ts
|
|
6
|
-
/**
|
|
7
|
-
* Create a reusable function definition.
|
|
8
|
-
* Returns the same object — this is an identity function for discoverability and type-checking.
|
|
9
|
-
*
|
|
10
|
-
* ```ts
|
|
11
|
-
* // Define once, reuse anywhere
|
|
12
|
-
* export const lookupOrder = defineFunction({
|
|
13
|
-
* name: "lookupOrder",
|
|
14
|
-
* description: "Look up an order by ID",
|
|
15
|
-
* parameters: { type: "object", properties: { id: { type: "string" } }, required: ["id"] },
|
|
16
|
-
* handler: async (args) => fetchOrder(args.id as string),
|
|
17
|
-
* });
|
|
18
|
-
*
|
|
19
|
-
* // Register with client
|
|
20
|
-
* client.registerFunction(lookupOrder);
|
|
21
|
-
*
|
|
22
|
-
* // Or use in React
|
|
23
|
-
* useAgoFunction(lookupOrder.name, lookupOrder);
|
|
24
|
-
* ```
|
|
25
|
-
*/
|
|
3
|
+
const AgoClient = require("./AgoClient-xTWfMWKh.cjs");
|
|
4
|
+
const createMockClient = require("./createMockClient-BqNSJUu4.cjs");
|
|
5
|
+
const helpers = require("./helpers.cjs");
|
|
26
6
|
function defineFunction(definition) {
|
|
27
|
-
|
|
7
|
+
return definition;
|
|
28
8
|
}
|
|
29
|
-
//#endregion
|
|
30
|
-
//#region src/streaming/helpers.ts
|
|
31
|
-
/**
|
|
32
|
-
* Subscribe to complete messages with a simple callback. Returns an unsubscribe function.
|
|
33
|
-
*
|
|
34
|
-
* ```ts
|
|
35
|
-
* const unsub = onMessage(client, (msg) => console.log(msg.content));
|
|
36
|
-
* // later: unsub();
|
|
37
|
-
* ```
|
|
38
|
-
*/
|
|
39
9
|
function onMessage(client, callback) {
|
|
40
|
-
|
|
41
|
-
|
|
10
|
+
client.on("message:complete", callback);
|
|
11
|
+
return () => client.off("message:complete", callback);
|
|
42
12
|
}
|
|
43
|
-
/**
|
|
44
|
-
* Subscribe to streaming text chunks.
|
|
45
|
-
*
|
|
46
|
-
* ```ts
|
|
47
|
-
* onMessageChunk(client, ({ content }) => {
|
|
48
|
-
* outputEl.textContent += content;
|
|
49
|
-
* });
|
|
50
|
-
* ```
|
|
51
|
-
*/
|
|
52
13
|
function onMessageChunk(client, callback) {
|
|
53
|
-
|
|
54
|
-
|
|
14
|
+
client.on("message:chunk", callback);
|
|
15
|
+
return () => client.off("message:chunk", callback);
|
|
55
16
|
}
|
|
56
|
-
/**
|
|
57
|
-
* Subscribe to message start events.
|
|
58
|
-
*/
|
|
59
17
|
function onMessageStart(client, callback) {
|
|
60
|
-
|
|
61
|
-
|
|
18
|
+
client.on("message:start", callback);
|
|
19
|
+
return () => client.off("message:start", callback);
|
|
62
20
|
}
|
|
63
|
-
/**
|
|
64
|
-
* Subscribe to message errors.
|
|
65
|
-
*/
|
|
66
21
|
function onMessageError(client, callback) {
|
|
67
|
-
|
|
68
|
-
|
|
22
|
+
client.on("message:error", callback);
|
|
23
|
+
return () => client.off("message:error", callback);
|
|
69
24
|
}
|
|
70
|
-
/**
|
|
71
|
-
* Subscribe to tool call events.
|
|
72
|
-
*/
|
|
73
25
|
function onToolCall(client, callback) {
|
|
74
|
-
|
|
75
|
-
|
|
26
|
+
client.on("toolCall:received", callback);
|
|
27
|
+
return () => client.off("toolCall:received", callback);
|
|
76
28
|
}
|
|
77
|
-
/**
|
|
78
|
-
* Subscribe to client function invocations.
|
|
79
|
-
*/
|
|
80
29
|
function onFunctionInvoke(client, callback) {
|
|
81
|
-
|
|
82
|
-
|
|
30
|
+
client.on("function:invoke", callback);
|
|
31
|
+
return () => client.off("function:invoke", callback);
|
|
83
32
|
}
|
|
84
|
-
/**
|
|
85
|
-
* Send a message and iterate over chunks as an async generator.
|
|
86
|
-
* Gives you full control over how you process the stream.
|
|
87
|
-
*
|
|
88
|
-
* ```ts
|
|
89
|
-
* for await (const chunk of createMessageStream(client, "Hello!")) {
|
|
90
|
-
* console.log(chunk.type, chunk.data);
|
|
91
|
-
* }
|
|
92
|
-
* ```
|
|
93
|
-
*/
|
|
94
33
|
async function* createMessageStream(client, content, options) {
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
await new Promise((r) => {
|
|
143
|
-
resolve = r;
|
|
144
|
-
});
|
|
145
|
-
resolve = null;
|
|
146
|
-
}
|
|
147
|
-
} finally {
|
|
148
|
-
client.off("message:start", onStart);
|
|
149
|
-
client.off("message:chunk", onChunk);
|
|
150
|
-
client.off("message:complete", onComplete);
|
|
151
|
-
client.off("message:error", onError);
|
|
152
|
-
client.off("toolCall:received", onTool);
|
|
153
|
-
}
|
|
34
|
+
const queue = [];
|
|
35
|
+
let resolve = null;
|
|
36
|
+
let done = false;
|
|
37
|
+
const push = (event) => {
|
|
38
|
+
queue.push(event);
|
|
39
|
+
resolve == null ? void 0 : resolve();
|
|
40
|
+
};
|
|
41
|
+
const onStart = (data) => push({ type: "start", data });
|
|
42
|
+
const onChunk = (data) => push({ type: "chunk", data });
|
|
43
|
+
const onComplete = (data) => {
|
|
44
|
+
push({ type: "complete", data });
|
|
45
|
+
done = true;
|
|
46
|
+
resolve == null ? void 0 : resolve();
|
|
47
|
+
};
|
|
48
|
+
const onError = (data) => {
|
|
49
|
+
push({ type: "error", data });
|
|
50
|
+
done = true;
|
|
51
|
+
resolve == null ? void 0 : resolve();
|
|
52
|
+
};
|
|
53
|
+
const onTool = (data) => push({ type: "toolCall", data });
|
|
54
|
+
client.on("message:start", onStart);
|
|
55
|
+
client.on("message:chunk", onChunk);
|
|
56
|
+
client.on("message:complete", onComplete);
|
|
57
|
+
client.on("message:error", onError);
|
|
58
|
+
client.on("toolCall:received", onTool);
|
|
59
|
+
client.sendMessage(content, options).catch(() => {
|
|
60
|
+
done = true;
|
|
61
|
+
resolve == null ? void 0 : resolve();
|
|
62
|
+
});
|
|
63
|
+
try {
|
|
64
|
+
while (!done || queue.length > 0) {
|
|
65
|
+
if (queue.length > 0) {
|
|
66
|
+
yield queue.shift();
|
|
67
|
+
} else {
|
|
68
|
+
await new Promise((r) => {
|
|
69
|
+
resolve = r;
|
|
70
|
+
});
|
|
71
|
+
resolve = null;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
} finally {
|
|
75
|
+
client.off("message:start", onStart);
|
|
76
|
+
client.off("message:chunk", onChunk);
|
|
77
|
+
client.off("message:complete", onComplete);
|
|
78
|
+
client.off("message:error", onError);
|
|
79
|
+
client.off("toolCall:received", onTool);
|
|
80
|
+
}
|
|
154
81
|
}
|
|
155
|
-
//#endregion
|
|
156
|
-
//#region src/auto/createAgo.ts
|
|
157
|
-
/**
|
|
158
|
-
* Auto-detect AGO configuration from the DOM environment.
|
|
159
|
-
*
|
|
160
|
-
* Checks (in order of priority):
|
|
161
|
-
* 1. `window.AGO` global object (widget config)
|
|
162
|
-
* 2. `<meta>` tags: `<meta name="ago-api-key" content="...">`
|
|
163
|
-
* 3. `data-ago-*` attributes on `<body>` or `<script data-ago-api-key="...">`
|
|
164
|
-
* 4. Explicit overrides passed as argument
|
|
165
|
-
*
|
|
166
|
-
* Returns null if no API key can be found.
|
|
167
|
-
*/
|
|
168
82
|
function autoDetectConfig(overrides) {
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
83
|
+
let baseUrl;
|
|
84
|
+
let widgetId;
|
|
85
|
+
let defaultAgentId;
|
|
86
|
+
let userEmail;
|
|
87
|
+
let userJwt;
|
|
88
|
+
let debug;
|
|
89
|
+
if (typeof window !== "undefined" && window.AGO) {
|
|
90
|
+
const ago = window.AGO;
|
|
91
|
+
baseUrl = ago.basepath;
|
|
92
|
+
widgetId = ago.widgetId;
|
|
93
|
+
defaultAgentId = ago.defaultAgent;
|
|
94
|
+
userEmail = ago.email;
|
|
95
|
+
userJwt = ago.jwt;
|
|
96
|
+
}
|
|
97
|
+
if (typeof document !== "undefined") {
|
|
98
|
+
const getMeta = (name) => {
|
|
99
|
+
var _a;
|
|
100
|
+
return ((_a = document.querySelector(`meta[name="${name}"]`)) == null ? void 0 : _a.getAttribute("content")) || void 0;
|
|
101
|
+
};
|
|
102
|
+
baseUrl = baseUrl || getMeta("ago-base-url");
|
|
103
|
+
widgetId = widgetId || getMeta("ago-widget-id");
|
|
104
|
+
defaultAgentId = defaultAgentId || getMeta("ago-agent-id");
|
|
105
|
+
userEmail = userEmail || getMeta("ago-user-email");
|
|
106
|
+
}
|
|
107
|
+
if (typeof document !== "undefined") {
|
|
108
|
+
const sources = [
|
|
109
|
+
document.body,
|
|
110
|
+
...Array.from(document.querySelectorAll("script[data-ago-base-url]"))
|
|
111
|
+
].filter(Boolean);
|
|
112
|
+
for (const el of sources) {
|
|
113
|
+
if (!el) continue;
|
|
114
|
+
baseUrl = baseUrl || el.getAttribute("data-ago-base-url") || void 0;
|
|
115
|
+
widgetId = widgetId || el.getAttribute("data-ago-widget-id") || void 0;
|
|
116
|
+
defaultAgentId = defaultAgentId || el.getAttribute("data-ago-agent-id") || void 0;
|
|
117
|
+
userEmail = userEmail || el.getAttribute("data-ago-user-email") || void 0;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
baseUrl = (overrides == null ? void 0 : overrides.baseUrl) || baseUrl;
|
|
121
|
+
widgetId = (overrides == null ? void 0 : overrides.widgetId) || widgetId;
|
|
122
|
+
defaultAgentId = (overrides == null ? void 0 : overrides.defaultAgentId) || defaultAgentId;
|
|
123
|
+
userEmail = (overrides == null ? void 0 : overrides.userEmail) || userEmail;
|
|
124
|
+
userJwt = (overrides == null ? void 0 : overrides.userJwt) || userJwt;
|
|
125
|
+
debug = (overrides == null ? void 0 : overrides.debug) ?? debug;
|
|
126
|
+
if (!baseUrl) {
|
|
127
|
+
return null;
|
|
128
|
+
}
|
|
129
|
+
return {
|
|
130
|
+
baseUrl,
|
|
131
|
+
widgetId,
|
|
132
|
+
defaultAgentId,
|
|
133
|
+
userEmail,
|
|
134
|
+
userJwt,
|
|
135
|
+
debug
|
|
136
|
+
};
|
|
220
137
|
}
|
|
221
|
-
/**
|
|
222
|
-
* Create an AgoClient with zero configuration.
|
|
223
|
-
* Auto-detects config from window.AGO, meta tags, and data-ago-* attributes.
|
|
224
|
-
*
|
|
225
|
-
* ```html
|
|
226
|
-
* <!-- In your HTML -->
|
|
227
|
-
* <meta name="ago-base-url" content="https://YOUR-DOMAIN.useago.com">
|
|
228
|
-
*
|
|
229
|
-
* <!-- Or on a script tag -->
|
|
230
|
-
* <script src="app.js" data-ago-base-url="https://YOUR-DOMAIN.useago.com"><\/script>
|
|
231
|
-
* ```
|
|
232
|
-
*
|
|
233
|
-
* ```ts
|
|
234
|
-
* import { createAgo } from "@useago/sdk";
|
|
235
|
-
*
|
|
236
|
-
* // Zero config — picks up from DOM
|
|
237
|
-
* const client = createAgo();
|
|
238
|
-
*
|
|
239
|
-
* // Or with partial overrides
|
|
240
|
-
* const client = createAgo({ debug: true });
|
|
241
|
-
* ```
|
|
242
|
-
*
|
|
243
|
-
* Throws if no base URL can be detected.
|
|
244
|
-
*/
|
|
245
138
|
function createAgo(overrides) {
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
139
|
+
const config = autoDetectConfig(overrides);
|
|
140
|
+
if (!config) {
|
|
141
|
+
throw new Error(
|
|
142
|
+
'createAgo(): could not detect AGO configuration. Set window.AGO, add <meta name="ago-base-url">, or pass { baseUrl } explicitly.'
|
|
143
|
+
);
|
|
144
|
+
}
|
|
145
|
+
return new AgoClient.AgoClient(config);
|
|
249
146
|
}
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
}
|
|
276
|
-
//#endregion
|
|
277
|
-
exports.AgoApiError = require_AgoClient.AgoApiError;
|
|
278
|
-
exports.AgoClient = require_AgoClient.AgoClient;
|
|
279
|
-
exports.AgoError = require_AgoClient.AgoError;
|
|
280
|
-
exports.AgoFunctionError = require_AgoClient.AgoFunctionError;
|
|
281
|
-
exports.AgoNetworkError = require_AgoClient.AgoNetworkError;
|
|
282
|
-
exports.AgoStreamError = require_AgoClient.AgoStreamError;
|
|
283
|
-
exports.ClientContextRegistry = require_AgoClient.ClientContextRegistry;
|
|
284
|
-
exports.EventEmitter = require_AgoClient.EventEmitter;
|
|
285
|
-
exports.FunctionRegistry = require_AgoClient.FunctionRegistry;
|
|
286
|
-
exports.SSEHandler = require_AgoClient.SSEHandler;
|
|
147
|
+
exports.AgoApiError = AgoClient.AgoApiError;
|
|
148
|
+
exports.AgoClient = AgoClient.AgoClient;
|
|
149
|
+
exports.AgoError = AgoClient.AgoError;
|
|
150
|
+
exports.AgoFunctionError = AgoClient.AgoFunctionError;
|
|
151
|
+
exports.AgoNetworkError = AgoClient.AgoNetworkError;
|
|
152
|
+
exports.AgoStreamError = AgoClient.AgoStreamError;
|
|
153
|
+
exports.EventEmitter = AgoClient.EventEmitter;
|
|
154
|
+
exports.FunctionRegistry = AgoClient.FunctionRegistry;
|
|
155
|
+
exports.SSEHandler = AgoClient.SSEHandler;
|
|
156
|
+
exports.isStreamNetworkError = AgoClient.isStreamNetworkError;
|
|
157
|
+
exports.logger = AgoClient.logger;
|
|
158
|
+
exports.createMockClient = createMockClient.createMockClient;
|
|
159
|
+
exports.copyToClipboard = helpers.copyToClipboard;
|
|
160
|
+
exports.getLocalStorage = helpers.getLocalStorage;
|
|
161
|
+
exports.getUserLocation = helpers.getUserLocation;
|
|
162
|
+
exports.highlightElement = helpers.highlightElement;
|
|
163
|
+
exports.openUrl = helpers.openUrl;
|
|
164
|
+
exports.scrollToElement = helpers.scrollToElement;
|
|
165
|
+
exports.setLocalStorage = helpers.setLocalStorage;
|
|
166
|
+
exports.setTheme = helpers.setTheme;
|
|
167
|
+
exports.showConfirmDialog = helpers.showConfirmDialog;
|
|
168
|
+
exports.showNotification = helpers.showNotification;
|
|
169
|
+
exports.showToast = helpers.showToast;
|
|
170
|
+
exports.submitForm = helpers.submitForm;
|
|
171
|
+
exports.trackEvent = helpers.trackEvent;
|
|
287
172
|
exports.autoDetectConfig = autoDetectConfig;
|
|
288
|
-
exports.copyToClipboard = require_functions.copyToClipboard;
|
|
289
173
|
exports.createAgo = createAgo;
|
|
290
174
|
exports.createMessageStream = createMessageStream;
|
|
291
|
-
exports.createMockClient = require_createMockClient.createMockClient;
|
|
292
175
|
exports.defineFunction = defineFunction;
|
|
293
|
-
exports.getLocalStorage = require_functions.getLocalStorage;
|
|
294
|
-
exports.getUserLocation = require_functions.getUserLocation;
|
|
295
|
-
exports.highlightElement = require_functions.highlightElement;
|
|
296
|
-
exports.isStreamNetworkError = require_AgoClient.isStreamNetworkError;
|
|
297
|
-
exports.logger = require_AgoClient.logger;
|
|
298
176
|
exports.onFunctionInvoke = onFunctionInvoke;
|
|
299
177
|
exports.onMessage = onMessage;
|
|
300
178
|
exports.onMessageChunk = onMessageChunk;
|
|
301
179
|
exports.onMessageError = onMessageError;
|
|
302
180
|
exports.onMessageStart = onMessageStart;
|
|
303
181
|
exports.onToolCall = onToolCall;
|
|
304
|
-
|
|
305
|
-
exports.scrollToElement = require_functions.scrollToElement;
|
|
306
|
-
exports.setLocalStorage = require_functions.setLocalStorage;
|
|
307
|
-
exports.setTheme = require_functions.setTheme;
|
|
308
|
-
exports.showConfirmDialog = require_functions.showConfirmDialog;
|
|
309
|
-
exports.showNotification = require_functions.showNotification;
|
|
310
|
-
exports.showToast = require_functions.showToast;
|
|
311
|
-
exports.submitForm = require_functions.submitForm;
|
|
312
|
-
exports.trackEvent = require_functions.trackEvent;
|
|
313
|
-
exports.withHandler = withHandler;
|
|
314
|
-
|
|
315
|
-
//# sourceMappingURL=index.cjs.map
|
|
182
|
+
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":[],"sources":["../src/functions/defineFunction.ts","../src/streaming/helpers.ts","../src/auto/createAgo.ts","../src/helpers/factory.ts"],"sourcesContent":["import type { ClientFunctionDefinition } from \"./types\";\n\n/**\n * Create a reusable function definition.\n * Returns the same object — this is an identity function for discoverability and type-checking.\n *\n * ```ts\n * // Define once, reuse anywhere\n * export const lookupOrder = defineFunction({\n * name: \"lookupOrder\",\n * description: \"Look up an order by ID\",\n * parameters: { type: \"object\", properties: { id: { type: \"string\" } }, required: [\"id\"] },\n * handler: async (args) => fetchOrder(args.id as string),\n * });\n *\n * // Register with client\n * client.registerFunction(lookupOrder);\n *\n * // Or use in React\n * useAgoFunction(lookupOrder.name, lookupOrder);\n * ```\n */\nexport function defineFunction(\n definition: ClientFunctionDefinition\n): ClientFunctionDefinition {\n return definition;\n}\n","import type { AgoClient } from \"../client/AgoClient\";\nimport type {\n AgoMessage,\n AgoClientEvents,\n ToolCallData,\n ClientFunctionInvocation,\n} from \"../client/types\";\n\n/**\n * Subscribe to complete messages with a simple callback. Returns an unsubscribe function.\n *\n * ```ts\n * const unsub = onMessage(client, (msg) => console.log(msg.content));\n * // later: unsub();\n * ```\n */\nexport function onMessage(\n client: AgoClient,\n callback: (message: AgoMessage) => void\n): () => void {\n client.on(\"message:complete\", callback);\n return () => client.off(\"message:complete\", callback);\n}\n\n/**\n * Subscribe to streaming text chunks.\n *\n * ```ts\n * onMessageChunk(client, ({ content }) => {\n * outputEl.textContent += content;\n * });\n * ```\n */\nexport function onMessageChunk(\n client: AgoClient,\n callback: (data: AgoClientEvents[\"message:chunk\"]) => void\n): () => void {\n client.on(\"message:chunk\", callback);\n return () => client.off(\"message:chunk\", callback);\n}\n\n/**\n * Subscribe to message start events.\n */\nexport function onMessageStart(\n client: AgoClient,\n callback: (data: AgoClientEvents[\"message:start\"]) => void\n): () => void {\n client.on(\"message:start\", callback);\n return () => client.off(\"message:start\", callback);\n}\n\n/**\n * Subscribe to message errors.\n */\nexport function onMessageError(\n client: AgoClient,\n callback: (data: AgoClientEvents[\"message:error\"]) => void\n): () => void {\n client.on(\"message:error\", callback);\n return () => client.off(\"message:error\", callback);\n}\n\n/**\n * Subscribe to tool call events.\n */\nexport function onToolCall(\n client: AgoClient,\n callback: (toolCall: ToolCallData) => void\n): () => void {\n client.on(\"toolCall:received\", callback);\n return () => client.off(\"toolCall:received\", callback);\n}\n\n/**\n * Subscribe to client function invocations.\n */\nexport function onFunctionInvoke(\n client: AgoClient,\n callback: (data: ClientFunctionInvocation) => void\n): () => void {\n client.on(\"function:invoke\", callback);\n return () => client.off(\"function:invoke\", callback);\n}\n\n/**\n * Send a message and iterate over chunks as an async generator.\n * Gives you full control over how you process the stream.\n *\n * ```ts\n * for await (const chunk of createMessageStream(client, \"Hello!\")) {\n * console.log(chunk.type, chunk.data);\n * }\n * ```\n */\nexport async function* createMessageStream(\n client: AgoClient,\n content: string,\n options?: { conversationId?: string; agentId?: string; files?: File[] }\n): AsyncGenerator<\n | { type: \"start\"; data: AgoClientEvents[\"message:start\"] }\n | { type: \"chunk\"; data: AgoClientEvents[\"message:chunk\"] }\n | { type: \"complete\"; data: AgoMessage }\n | { type: \"error\"; data: AgoClientEvents[\"message:error\"] }\n | { type: \"toolCall\"; data: ToolCallData }\n> {\n type StreamEvent =\n | { type: \"start\"; data: AgoClientEvents[\"message:start\"] }\n | { type: \"chunk\"; data: AgoClientEvents[\"message:chunk\"] }\n | { type: \"complete\"; data: AgoMessage }\n | { type: \"error\"; data: AgoClientEvents[\"message:error\"] }\n | { type: \"toolCall\"; data: ToolCallData };\n\n const queue: StreamEvent[] = [];\n let resolve: (() => void) | null = null;\n let done = false;\n\n const push = (event: StreamEvent) => {\n queue.push(event);\n resolve?.();\n };\n\n const onStart = (data: AgoClientEvents[\"message:start\"]) => push({ type: \"start\", data });\n const onChunk = (data: AgoClientEvents[\"message:chunk\"]) => push({ type: \"chunk\", data });\n const onComplete = (data: AgoMessage) => {\n push({ type: \"complete\", data });\n done = true;\n resolve?.();\n };\n const onError = (data: AgoClientEvents[\"message:error\"]) => {\n push({ type: \"error\", data });\n done = true;\n resolve?.();\n };\n const onTool = (data: ToolCallData) => push({ type: \"toolCall\", data });\n\n client.on(\"message:start\", onStart);\n client.on(\"message:chunk\", onChunk);\n client.on(\"message:complete\", onComplete);\n client.on(\"message:error\", onError);\n client.on(\"toolCall:received\", onTool);\n\n // Fire the request (don't await — we'll consume events via the generator)\n client.sendMessage(content, options).catch(() => {\n done = true;\n resolve?.();\n });\n\n try {\n while (!done || queue.length > 0) {\n if (queue.length > 0) {\n yield queue.shift()!;\n } else {\n await new Promise<void>((r) => { resolve = r; });\n resolve = null;\n }\n }\n } finally {\n client.off(\"message:start\", onStart);\n client.off(\"message:chunk\", onChunk);\n client.off(\"message:complete\", onComplete);\n client.off(\"message:error\", onError);\n client.off(\"toolCall:received\", onTool);\n }\n}\n","import { AgoClient } from \"../client/AgoClient\";\nimport type { AgoConfig } from \"../client/types\";\n\n/**\n * Auto-detect AGO configuration from the DOM environment.\n *\n * Checks (in order of priority):\n * 1. `window.AGO` global object (widget config)\n * 2. `<meta>` tags: `<meta name=\"ago-api-key\" content=\"...\">`\n * 3. `data-ago-*` attributes on `<body>` or `<script data-ago-api-key=\"...\">`\n * 4. Explicit overrides passed as argument\n *\n * Returns null if no API key can be found.\n */\nexport function autoDetectConfig(\n overrides?: Partial<AgoConfig>\n): AgoConfig | null {\n let baseUrl: string | undefined;\n let widgetId: string | undefined;\n let agent: string | undefined;\n let permission: string | undefined;\n let userEmail: string | undefined;\n let userJwt: string | undefined;\n\n // 1. window.AGO (widget config format)\n if (typeof window !== \"undefined\" && (window as unknown as Record<string, unknown>).AGO) {\n const ago = (window as unknown as Record<string, unknown>).AGO as Record<string, unknown>;\n baseUrl = ago.basepath as string | undefined;\n widgetId = ago.widgetId as string | undefined;\n agent = (ago.agent as string | undefined) || (ago.defaultAgent as string | undefined);\n permission = ago.permission as string | undefined;\n userEmail = ago.email as string | undefined;\n userJwt = ago.jwt as string | undefined;\n }\n\n // 2. Meta tags\n if (typeof document !== \"undefined\") {\n const getMeta = (name: string) =>\n document.querySelector(`meta[name=\"${name}\"]`)?.getAttribute(\"content\") || undefined;\n\n baseUrl = baseUrl || getMeta(\"ago-base-url\");\n widgetId = widgetId || getMeta(\"ago-widget-id\");\n agent = agent || getMeta(\"ago-agent\") || getMeta(\"ago-agent-id\");\n permission = permission || getMeta(\"ago-permission\");\n userEmail = userEmail || getMeta(\"ago-user-email\");\n }\n\n // 3. data-ago-* attributes on body or script tags\n if (typeof document !== \"undefined\") {\n const sources = [\n document.body,\n ...Array.from(document.querySelectorAll(\"script[data-ago-base-url]\")),\n ].filter(Boolean);\n\n for (const el of sources) {\n if (!el) continue;\n baseUrl = baseUrl || el.getAttribute(\"data-ago-base-url\") || undefined;\n widgetId = widgetId || el.getAttribute(\"data-ago-widget-id\") || undefined;\n agent = agent || el.getAttribute(\"data-ago-agent\") || el.getAttribute(\"data-ago-agent-id\") || undefined;\n permission = permission || el.getAttribute(\"data-ago-permission\") || undefined;\n userEmail = userEmail || el.getAttribute(\"data-ago-user-email\") || undefined;\n }\n }\n\n // 4. Apply overrides\n baseUrl = overrides?.baseUrl || baseUrl;\n widgetId = overrides?.widgetId || widgetId;\n agent = overrides?.agent || overrides?.defaultAgentId || agent;\n permission = overrides?.permission || permission;\n userEmail = overrides?.userEmail || userEmail;\n userJwt = overrides?.userJwt || userJwt;\n const debug = overrides?.debug;\n\n if (!baseUrl) {\n return null;\n }\n\n return {\n baseUrl,\n widgetId,\n agent,\n permission,\n userEmail,\n userJwt,\n debug,\n };\n}\n\n/**\n * Create an AgoClient with zero configuration.\n * Auto-detects config from window.AGO, meta tags, and data-ago-* attributes.\n *\n * ```html\n * <!-- In your HTML -->\n * <meta name=\"ago-base-url\" content=\"https://YOUR-DOMAIN.useago.com\">\n *\n * <!-- Or on a script tag -->\n * <script src=\"app.js\" data-ago-base-url=\"https://YOUR-DOMAIN.useago.com\"></script>\n * ```\n *\n * ```ts\n * import { createAgo } from \"@useago/sdk\";\n *\n * // Zero config — picks up from DOM\n * const client = createAgo();\n *\n * // Or with partial overrides\n * const client = createAgo({ debug: true });\n * ```\n *\n * Throws if no base URL can be detected.\n */\nexport function createAgo(overrides?: Partial<AgoConfig>): AgoClient {\n const config = autoDetectConfig(overrides);\n\n if (!config) {\n throw new Error(\n \"createAgo(): could not detect AGO configuration. \" +\n \"Set window.AGO, add <meta name=\\\"ago-base-url\\\">, or pass { baseUrl } explicitly.\"\n );\n }\n\n return new AgoClient(config);\n}\n","import type {\n ClientFunctionDefinition,\n ClientFunctionHandler,\n} from \"../functions/types\";\n\n/**\n * Attach a handler to a pre-built function definition.\n *\n * Pre-built helpers (`showToast`, `trackEvent`, ...) ship with a no-op or\n * console-logging default handler. Use `withHandler` to wire them up to\n * your actual implementation without mutating the original definition.\n *\n * ```ts\n * import { showToast, withHandler } from \"@useago/sdk\";\n *\n * client.register(\n * withHandler(showToast, (args) => {\n * myToast(args.message as string);\n * return { shown: true };\n * })\n * );\n * ```\n */\nexport function withHandler<T extends ClientFunctionDefinition>(\n definition: T,\n handler: ClientFunctionHandler\n): T {\n return { ...definition, handler };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAsBA,SAAgB,eACd,YAC0B;AAC1B,QAAO;;;;;;;;;;;;ACTT,SAAgB,UACd,QACA,UACY;AACZ,QAAO,GAAG,oBAAoB,SAAS;AACvC,cAAa,OAAO,IAAI,oBAAoB,SAAS;;;;;;;;;;;AAYvD,SAAgB,eACd,QACA,UACY;AACZ,QAAO,GAAG,iBAAiB,SAAS;AACpC,cAAa,OAAO,IAAI,iBAAiB,SAAS;;;;;AAMpD,SAAgB,eACd,QACA,UACY;AACZ,QAAO,GAAG,iBAAiB,SAAS;AACpC,cAAa,OAAO,IAAI,iBAAiB,SAAS;;;;;AAMpD,SAAgB,eACd,Q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aAAa,GAAG,aAAa,sBAAsB,IAAI,KAAA;;;AAKvE,WAAU,WAAW,WAAW;AAChC,YAAW,WAAW,YAAY;AAClC,SAAQ,WAAW,SAAS,WAAW,kBAAkB;AACzD,cAAa,WAAW,cAAc;AACtC,aAAY,WAAW,aAAa;AACpC,WAAU,WAAW,WAAW;CAChC,MAAM,QAAQ,WAAW;AAEzB,KAAI,CAAC,QACH,QAAO;AAGT,QAAO;EACL;EACA;EACA;EACA;EACA;EACA;EACA;EACD;;;;;;;;;;;;;;;;;;;;;;;;;;AA2BH,SAAgB,UAAU,WAA2C;CACnE,MAAM,SAAS,iBAAiB,UAAU;AAE1C,KAAI,CAAC,OACH,OAAM,IAAI,MACR,qIAED;AAGH,QAAO,IAAI,kBAAA,UAAU,OAAO;;;;;;;;;;;;;;;;;;;;;;ACnG9B,SAAgB,YACd,YACA,SACG;AACH,QAAO;EAAE,GAAG;EAAY;EAAS"}
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../src/functions/defineFunction.ts","../src/streaming/helpers.ts","../src/auto/createAgo.ts"],"sourcesContent":["import type { ClientFunctionDefinition } from \"./types\";\n\n/**\n * Create a reusable function definition.\n * Returns the same object — this is an identity function for discoverability and type-checking.\n *\n * ```ts\n * // Define once, reuse anywhere\n * export const lookupOrder = defineFunction({\n * name: \"lookupOrder\",\n * description: \"Look up an order by ID\",\n * parameters: { type: \"object\", properties: { id: { type: \"string\" } }, required: [\"id\"] },\n * handler: async (args) => fetchOrder(args.id as string),\n * });\n *\n * // Register with client\n * client.registerFunction(lookupOrder);\n *\n * // Or use in React\n * useAgoFunction(lookupOrder.name, lookupOrder);\n * ```\n */\nexport function defineFunction(\n definition: ClientFunctionDefinition\n): ClientFunctionDefinition {\n return definition;\n}\n","import type { AgoClient } from \"../client/AgoClient\";\nimport type {\n AgoMessage,\n AgoClientEvents,\n ToolCallData,\n ClientFunctionInvocation,\n} from \"../client/types\";\n\n/**\n * Subscribe to complete messages with a simple callback. Returns an unsubscribe function.\n *\n * ```ts\n * const unsub = onMessage(client, (msg) => console.log(msg.content));\n * // later: unsub();\n * ```\n */\nexport function onMessage(\n client: AgoClient,\n callback: (message: AgoMessage) => void\n): () => void {\n client.on(\"message:complete\", callback);\n return () => client.off(\"message:complete\", callback);\n}\n\n/**\n * Subscribe to streaming text chunks.\n *\n * ```ts\n * onMessageChunk(client, ({ content }) => {\n * outputEl.textContent += content;\n * });\n * ```\n */\nexport function onMessageChunk(\n client: AgoClient,\n callback: (data: AgoClientEvents[\"message:chunk\"]) => void\n): () => void {\n client.on(\"message:chunk\", callback);\n return () => client.off(\"message:chunk\", callback);\n}\n\n/**\n * Subscribe to message start events.\n */\nexport function onMessageStart(\n client: AgoClient,\n callback: (data: AgoClientEvents[\"message:start\"]) => void\n): () => void {\n client.on(\"message:start\", callback);\n return () => client.off(\"message:start\", callback);\n}\n\n/**\n * Subscribe to message errors.\n */\nexport function onMessageError(\n client: AgoClient,\n callback: (data: AgoClientEvents[\"message:error\"]) => void\n): () => void {\n client.on(\"message:error\", callback);\n return () => client.off(\"message:error\", callback);\n}\n\n/**\n * Subscribe to tool call events.\n */\nexport function onToolCall(\n client: AgoClient,\n callback: (toolCall: ToolCallData) => void\n): () => void {\n client.on(\"toolCall:received\", callback);\n return () => client.off(\"toolCall:received\", callback);\n}\n\n/**\n * Subscribe to client function invocations.\n */\nexport function onFunctionInvoke(\n client: AgoClient,\n callback: (data: ClientFunctionInvocation) => void\n): () => void {\n client.on(\"function:invoke\", callback);\n return () => client.off(\"function:invoke\", callback);\n}\n\n/**\n * Send a message and iterate over chunks as an async generator.\n * Gives you full control over how you process the stream.\n *\n * ```ts\n * for await (const chunk of createMessageStream(client, \"Hello!\")) {\n * console.log(chunk.type, chunk.data);\n * }\n * ```\n */\nexport async function* createMessageStream(\n client: AgoClient,\n content: string,\n options?: { conversationId?: string; agentId?: string; files?: File[] }\n): AsyncGenerator<\n | { type: \"start\"; data: AgoClientEvents[\"message:start\"] }\n | { type: \"chunk\"; data: AgoClientEvents[\"message:chunk\"] }\n | { type: \"complete\"; data: AgoMessage }\n | { type: \"error\"; data: AgoClientEvents[\"message:error\"] }\n | { type: \"toolCall\"; data: ToolCallData }\n> {\n type StreamEvent =\n | { type: \"start\"; data: AgoClientEvents[\"message:start\"] }\n | { type: \"chunk\"; data: AgoClientEvents[\"message:chunk\"] }\n | { type: \"complete\"; data: AgoMessage }\n | { type: \"error\"; data: AgoClientEvents[\"message:error\"] }\n | { type: \"toolCall\"; data: ToolCallData };\n\n const queue: StreamEvent[] = [];\n let resolve: (() => void) | null = null;\n let done = false;\n\n const push = (event: StreamEvent) => {\n queue.push(event);\n resolve?.();\n };\n\n const onStart = (data: AgoClientEvents[\"message:start\"]) => push({ type: \"start\", data });\n const onChunk = (data: AgoClientEvents[\"message:chunk\"]) => push({ type: \"chunk\", data });\n const onComplete = (data: AgoMessage) => {\n push({ type: \"complete\", data });\n done = true;\n resolve?.();\n };\n const onError = (data: AgoClientEvents[\"message:error\"]) => {\n push({ type: \"error\", data });\n done = true;\n resolve?.();\n };\n const onTool = (data: ToolCallData) => push({ type: \"toolCall\", data });\n\n client.on(\"message:start\", onStart);\n client.on(\"message:chunk\", onChunk);\n client.on(\"message:complete\", onComplete);\n client.on(\"message:error\", onError);\n client.on(\"toolCall:received\", onTool);\n\n // Fire the request (don't await — we'll consume events via the generator)\n client.sendMessage(content, options).catch(() => {\n done = true;\n resolve?.();\n });\n\n try {\n while (!done || queue.length > 0) {\n if (queue.length > 0) {\n yield queue.shift()!;\n } else {\n await new Promise<void>((r) => { resolve = r; });\n resolve = null;\n }\n }\n } finally {\n client.off(\"message:start\", onStart);\n client.off(\"message:chunk\", onChunk);\n client.off(\"message:complete\", onComplete);\n client.off(\"message:error\", onError);\n client.off(\"toolCall:received\", onTool);\n }\n}\n","import { AgoClient } from \"../client/AgoClient\";\nimport type { AgoConfig } from \"../client/types\";\n\n/**\n * Auto-detect AGO configuration from the DOM environment.\n *\n * Checks (in order of priority):\n * 1. `window.AGO` global object (widget config)\n * 2. `<meta>` tags: `<meta name=\"ago-api-key\" content=\"...\">`\n * 3. `data-ago-*` attributes on `<body>` or `<script data-ago-api-key=\"...\">`\n * 4. Explicit overrides passed as argument\n *\n * Returns null if no API key can be found.\n */\nexport function autoDetectConfig(\n overrides?: Partial<AgoConfig>\n): AgoConfig | null {\n let baseUrl: string | undefined;\n let widgetId: string | undefined;\n let defaultAgentId: string | undefined;\n let userEmail: string | undefined;\n let userJwt: string | undefined;\n let debug: boolean | undefined;\n\n // 1. window.AGO (widget config format)\n if (typeof window !== \"undefined\" && (window as unknown as Record<string, unknown>).AGO) {\n const ago = (window as unknown as Record<string, unknown>).AGO as Record<string, unknown>;\n baseUrl = ago.basepath as string | undefined;\n widgetId = ago.widgetId as string | undefined;\n defaultAgentId = ago.defaultAgent as string | undefined;\n userEmail = ago.email as string | undefined;\n userJwt = ago.jwt as string | undefined;\n }\n\n // 2. Meta tags\n if (typeof document !== \"undefined\") {\n const getMeta = (name: string) =>\n document.querySelector(`meta[name=\"${name}\"]`)?.getAttribute(\"content\") || undefined;\n\n baseUrl = baseUrl || getMeta(\"ago-base-url\");\n widgetId = widgetId || getMeta(\"ago-widget-id\");\n defaultAgentId = defaultAgentId || getMeta(\"ago-agent-id\");\n userEmail = userEmail || getMeta(\"ago-user-email\");\n }\n\n // 3. data-ago-* attributes on body or script tags\n if (typeof document !== \"undefined\") {\n const sources = [\n document.body,\n ...Array.from(document.querySelectorAll(\"script[data-ago-base-url]\")),\n ].filter(Boolean);\n\n for (const el of sources) {\n if (!el) continue;\n baseUrl = baseUrl || el.getAttribute(\"data-ago-base-url\") || undefined;\n widgetId = widgetId || el.getAttribute(\"data-ago-widget-id\") || undefined;\n defaultAgentId = defaultAgentId || el.getAttribute(\"data-ago-agent-id\") || undefined;\n userEmail = userEmail || el.getAttribute(\"data-ago-user-email\") || undefined;\n }\n }\n\n // 4. Apply overrides\n baseUrl = overrides?.baseUrl || baseUrl;\n widgetId = overrides?.widgetId || widgetId;\n defaultAgentId = overrides?.defaultAgentId || defaultAgentId;\n userEmail = overrides?.userEmail || userEmail;\n userJwt = overrides?.userJwt || userJwt;\n debug = overrides?.debug ?? debug;\n\n if (!baseUrl) {\n return null;\n }\n\n return {\n baseUrl,\n widgetId,\n defaultAgentId,\n userEmail,\n userJwt,\n debug,\n };\n}\n\n/**\n * Create an AgoClient with zero configuration.\n * Auto-detects config from window.AGO, meta tags, and data-ago-* attributes.\n *\n * ```html\n * <!-- In your HTML -->\n * <meta name=\"ago-base-url\" content=\"https://YOUR-DOMAIN.useago.com\">\n *\n * <!-- Or on a script tag -->\n * <script src=\"app.js\" data-ago-base-url=\"https://YOUR-DOMAIN.useago.com\"></script>\n * ```\n *\n * ```ts\n * import { createAgo } from \"@useago/sdk\";\n *\n * // Zero config — picks up from DOM\n * const client = createAgo();\n *\n * // Or with partial overrides\n * const client = createAgo({ debug: true });\n * ```\n *\n * Throws if no base URL can be detected.\n */\nexport function createAgo(overrides?: Partial<AgoConfig>): AgoClient {\n const config = autoDetectConfig(overrides);\n\n if (!config) {\n throw new Error(\n \"createAgo(): could not detect AGO configuration. \" +\n \"Set window.AGO, add <meta name=\\\"ago-base-url\\\">, or pass { baseUrl } explicitly.\"\n );\n }\n\n return new AgoClient(config);\n}\n"],"names":["AgoClient"],"mappings":";;;;;AAsBO,SAAS,eACd,YAC0B;AAC1B,SAAO;AACT;ACVO,SAAS,UACd,QACA,UACY;AACZ,SAAO,GAAG,oBAAoB,QAAQ;AACtC,SAAO,MAAM,OAAO,IAAI,oBAAoB,QAAQ;AACtD;AAWO,SAAS,eACd,QACA,UACY;AACZ,SAAO,GAAG,iBAAiB,QAAQ;AACnC,SAAO,MAAM,OAAO,IAAI,iBAAiB,QAAQ;AACnD;AAKO,SAAS,eACd,QACA,UACY;AACZ,SAAO,GAAG,iBAAiB,QAAQ;AACnC,SAAO,MAAM,OAAO,IAAI,iBAAiB,QAAQ;AACnD;AAKO,SAAS,eACd,QACA,UACY;AACZ,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B,KAAK;AAAA,IACrE;AAAA,EACF;AAGA,aAAU,uCAAW,YAAW;AAChC,cAAW,uCAAW,aAAY;AAClC,oBAAiB,uCAAW,mBAAkB;AAC9C,eAAY,uCAAW,cAAa;AACpC,aAAU,uCAAW,YAAW;AAChC,WAAQ,uCAAW,UAAS;AAE5B,MAAI,CAAC,SAAS;AACZ,WAAO;AAAA,EACT;AAEA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EAAA;AAEJ;AA0BO,SAAS,UAAU,WAA2C;AACnE,QAAM,SAAS,iBAAiB,SAAS;AAEzC,MAAI,CAAC,QAAQ;AACX,UAAM,IAAI;AAAA,MACR;AAAA,IAAA;AAAA,EAGJ;AAEA,SAAO,IAAIA,UAAAA,UAAU,MAAM;AAC7B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
export { AgoClient } from "./client/AgoClient";
|
|
2
2
|
export type { AgoConfig, SendMessageOptions, AgoMessage, Conversation, AgoAgent, AgoSource, ToolCallData, ToolCallType, FormSchema, FormField, FunctionSchema, ClientFunction, FunctionDefinition, ClientFunctionInvocation, AgoClientEvents, AgoEventName, AgoEventHandler, MessageStatus, SSEChunkData, } from "./client/types";
|
|
3
3
|
export { AgoError, AgoApiError, AgoNetworkError, AgoStreamError, AgoFunctionError, } from "./client/errors";
|
|
4
|
-
export { ClientContextRegistry } from "./state/ClientContextRegistry";
|
|
5
|
-
export type { ContextEntry, ContextSnapshot, DynamicContextProvider, } from "./state/ClientContextRegistry";
|
|
6
4
|
export { FunctionRegistry } from "./functions/FunctionRegistry";
|
|
7
5
|
export { defineFunction } from "./functions/defineFunction";
|
|
8
6
|
export type { ClientFunctionSchema, ClientFunctionHandler, ClientFunctionDefinition, RegisteredFunction, } from "./functions/types";
|
|
@@ -13,6 +11,5 @@ export type { AgoWidgetConfig, AgoWidgetColors } from "./widget/types";
|
|
|
13
11
|
export { onMessage, onMessageChunk, onMessageStart, onMessageError, onToolCall, onFunctionInvoke, createMessageStream, } from "./streaming/helpers";
|
|
14
12
|
export { createAgo, autoDetectConfig } from "./auto/createAgo";
|
|
15
13
|
export { showToast, showNotification, openUrl, copyToClipboard, setTheme, showConfirmDialog, getUserLocation, scrollToElement, setLocalStorage, getLocalStorage, highlightElement, submitForm, trackEvent, } from "./helpers/functions";
|
|
16
|
-
export { withHandler } from "./helpers/factory";
|
|
17
14
|
export { EventEmitter } from "./utils/eventEmitter";
|
|
18
15
|
export { logger } from "./utils/logger";
|