@useago/sdk 0.1.6 → 0.2.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/AgoClient-CNT-8sh_.js +905 -0
- package/dist/AgoClient-CNT-8sh_.js.map +1 -0
- package/dist/AgoClient-D0l1GTRs.cjs +976 -0
- package/dist/AgoClient-D0l1GTRs.cjs.map +1 -0
- package/dist/angular/ago.service.d.ts +98 -0
- package/dist/angular/index.d.ts +4 -0
- package/dist/angular/provide.d.ts +27 -0
- package/dist/angular.cjs +143 -0
- package/dist/angular.cjs.map +1 -0
- package/dist/angular.d.ts +2 -0
- package/dist/angular.js +141 -0
- package/dist/angular.js.map +1 -0
- package/dist/auto/createAgo.d.ts +39 -0
- package/dist/auto/index.d.ts +1 -0
- package/dist/client/AgoClient.d.ts +56 -0
- package/dist/client/types.d.ts +9 -7
- package/dist/createMockClient-Ci_N2tH8.cjs +104 -0
- package/dist/createMockClient-Ci_N2tH8.cjs.map +1 -0
- package/dist/createMockClient-U0ae_AYy.js +99 -0
- package/dist/createMockClient-U0ae_AYy.js.map +1 -0
- package/dist/functions--c6lx3ic.cjs +480 -0
- package/dist/functions--c6lx3ic.cjs.map +1 -0
- package/dist/functions-C9F1dnmh.js +398 -0
- package/dist/functions-C9F1dnmh.js.map +1 -0
- package/dist/helpers/factory.d.ts +20 -0
- package/dist/helpers/functions.d.ts +62 -0
- package/dist/helpers/index.d.ts +1 -0
- package/dist/helpers.cjs +15 -0
- package/dist/helpers.d.ts +2 -0
- package/dist/helpers.js +2 -0
- package/dist/index.cjs +312 -17
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +6 -0
- package/dist/index.js +277 -19
- package/dist/index.js.map +1 -1
- package/dist/react/components/ChatWidget.d.ts +2 -0
- package/dist/react/components/Markdown.d.ts +12 -0
- package/dist/react/components/Message.d.ts +2 -0
- package/dist/react/components/index.d.ts +2 -0
- package/dist/react/context/AgoContext.d.ts +30 -4
- package/dist/react/context/index.d.ts +1 -1
- package/dist/react/hooks/index.d.ts +1 -0
- package/dist/react/hooks/useAgoContext.d.ts +40 -0
- package/dist/react/hooks/useAgoFunction.d.ts +14 -2
- package/dist/react/index.d.ts +4 -1
- package/dist/react.cjs +22104 -10273
- package/dist/react.cjs.map +1 -1
- package/dist/react.d.ts +1 -0
- package/dist/react.js +22103 -10289
- package/dist/react.js.map +1 -1
- package/dist/rolldown-runtime-BqCkTl7Q.cjs +50 -0
- package/dist/rolldown-runtime-CNZpIYwj.js +33 -0
- package/dist/state/ClientContextRegistry.d.ts +64 -0
- package/dist/streaming/helpers.d.ts +67 -0
- package/dist/vue/composables/useAgo.d.ts +17 -0
- package/dist/vue/composables/useAgoEvents.d.ts +11 -0
- package/dist/vue/composables/useAgoFunction.d.ts +34 -0
- package/dist/vue/composables/useChat.d.ts +251 -0
- package/dist/vue/composables/useConversation.d.ts +178 -0
- package/dist/vue/composables/useMessages.d.ts +89 -0
- package/dist/vue/index.d.ts +10 -0
- package/dist/vue/plugin.d.ts +16 -0
- package/dist/vue/symbols.d.ts +3 -0
- package/dist/vue.cjs +311 -0
- package/dist/vue.cjs.map +1 -0
- package/dist/vue.d.ts +2 -0
- package/dist/vue.js +301 -0
- package/dist/vue.js.map +1 -0
- package/dist/widget/types.d.ts +1 -0
- package/dist/widget.cjs +0 -2
- package/dist/widget.d.ts +1 -0
- package/dist/widget.js +0 -2
- package/package.json +29 -7
- package/dist/createMockClient-BZKh_1em.cjs +0 -941
- package/dist/createMockClient-BZKh_1em.cjs.map +0 -1
- package/dist/createMockClient-uGlVyjbL.js +0 -942
- package/dist/createMockClient-uGlVyjbL.js.map +0 -1
- package/dist/widget.cjs.map +0 -1
- package/dist/widget.js.map +0 -1
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../src/functions/defineFunction.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"],"names":[],"mappings":";AAsBO,SAAS,eACd,YAC0B;AAC1B,SAAO;AACT;"}
|
|
1
|
+
{"version":3,"file":"index.js","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;A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MAAM,KAAK,SAAS,iBAAiB,4BAA4B,CAAC,CACtE,CAAC,OAAO,QAAQ;AAEjB,OAAK,MAAM,MAAM,SAAS;AACxB,OAAI,CAAC,GAAI;AACT,aAAU,WAAW,GAAG,aAAa,oBAAoB,IAAI,KAAA;AAC7D,cAAW,YAAY,GAAG,aAAa,qBAAqB,IAAI,KAAA;AAChE,WAAQ,SAAS,GAAG,aAAa,iBAAiB,IAAI,GAAG,aAAa,oBAAoB,IAAI,KAAA;AAC9F,gBAAa,cAAc,GAAG,aAAa,sBAAsB,IAAI,KAAA;AACrE,eAAY,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,UAAU,OAAO;;;;;;;;;;;;;;;;;;;;;;ACnG9B,SAAgB,YACd,YACA,SACG;AACH,QAAO;EAAE,GAAG;EAAY;EAAS"}
|
|
@@ -17,6 +17,8 @@ export interface ChatWidgetProps {
|
|
|
17
17
|
height?: string | number;
|
|
18
18
|
/** URL of a logo to display in the header */
|
|
19
19
|
logoUrl?: string;
|
|
20
|
+
/** Show the agent name above assistant messages. Defaults to `true`. */
|
|
21
|
+
showAgentName?: boolean;
|
|
20
22
|
/** Additional CSS class */
|
|
21
23
|
className?: string;
|
|
22
24
|
/** Callback when a message is sent */
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
export interface MarkdownProps {
|
|
3
|
+
/** Raw markdown string to render. */
|
|
4
|
+
content: string;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Renders markdown content with GitHub-flavored markdown support
|
|
8
|
+
* (tables, task lists, strikethrough, autolinks) and inline-styled
|
|
9
|
+
* element renderers. Used by {@link Message} but exported so consumers
|
|
10
|
+
* building a custom chat UI can render assistant content the same way.
|
|
11
|
+
*/
|
|
12
|
+
export declare const Markdown: React.FC<MarkdownProps>;
|
|
@@ -3,5 +3,7 @@ import type { AgoMessage } from "../../client/types";
|
|
|
3
3
|
export interface MessageProps {
|
|
4
4
|
message: AgoMessage;
|
|
5
5
|
className?: string;
|
|
6
|
+
/** Show the agent name above assistant messages. Defaults to `true`. */
|
|
7
|
+
showAgentName?: boolean;
|
|
6
8
|
}
|
|
7
9
|
export declare const Message: React.FC<MessageProps>;
|
|
@@ -2,5 +2,7 @@ export { ChatWidget } from "./ChatWidget";
|
|
|
2
2
|
export type { ChatWidgetProps } from "./ChatWidget";
|
|
3
3
|
export { Message } from "./Message";
|
|
4
4
|
export type { MessageProps } from "./Message";
|
|
5
|
+
export { Markdown } from "./Markdown";
|
|
6
|
+
export type { MarkdownProps } from "./Markdown";
|
|
5
7
|
export { ChatInput } from "./ChatInput";
|
|
6
8
|
export type { ChatInputProps } from "./ChatInput";
|
|
@@ -1,9 +1,22 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import type { AgoClient } from "../../client/AgoClient";
|
|
3
3
|
import type { AgoConfig } from "../../client/types";
|
|
4
|
+
import type { ClientFunctionDefinition, ClientFunctionHandler } from "../../functions/types";
|
|
5
|
+
/**
|
|
6
|
+
* Top-level declarative configuration for the `AgoProvider`.
|
|
7
|
+
*
|
|
8
|
+
* - `tools` — full function definitions to expose to the AI app-wide
|
|
9
|
+
* - `helpers` — map of pre-built helper name → handler override (or `true` for default)
|
|
10
|
+
* - `pageContext` — `"auto"` enables automatic URL/title capture
|
|
11
|
+
*/
|
|
12
|
+
export interface AgoDeclarativeConfig {
|
|
13
|
+
tools?: ClientFunctionDefinition[];
|
|
14
|
+
helpers?: Record<string, ClientFunctionHandler | true>;
|
|
15
|
+
pageContext?: "auto" | "manual";
|
|
16
|
+
}
|
|
4
17
|
export type AgoProviderProps = {
|
|
5
18
|
children: React.ReactNode;
|
|
6
|
-
} & (({
|
|
19
|
+
} & AgoDeclarativeConfig & (({
|
|
7
20
|
client: AgoClient;
|
|
8
21
|
} & Partial<Record<keyof AgoConfig, never>>) | ({
|
|
9
22
|
client?: never;
|
|
@@ -12,12 +25,25 @@ export type AgoProviderProps = {
|
|
|
12
25
|
* Provides an AgoClient to all descendant components via React context.
|
|
13
26
|
*
|
|
14
27
|
* ```tsx
|
|
15
|
-
* //
|
|
16
|
-
* <AgoProvider
|
|
28
|
+
* // Minimal setup
|
|
29
|
+
* <AgoProvider baseUrl="https://YOUR-DOMAIN.useago.com">
|
|
30
|
+
* <App />
|
|
31
|
+
* </AgoProvider>
|
|
32
|
+
*
|
|
33
|
+
* // Declarative config — tools, helpers, page context
|
|
34
|
+
* <AgoProvider
|
|
35
|
+
* baseUrl="https://YOUR-DOMAIN.useago.com"
|
|
36
|
+
* tools={[lookupOrder, cancelOrder]}
|
|
37
|
+
* helpers={{
|
|
38
|
+
* showToast: (args) => toast(args.message as string),
|
|
39
|
+
* copyToClipboard: true, // use default handler
|
|
40
|
+
* }}
|
|
41
|
+
* pageContext="auto"
|
|
42
|
+
* >
|
|
17
43
|
* <App />
|
|
18
44
|
* </AgoProvider>
|
|
19
45
|
*
|
|
20
|
-
* //
|
|
46
|
+
* // With a pre-built client (useful for testing)
|
|
21
47
|
* <AgoProvider client={myClient}>
|
|
22
48
|
* <App />
|
|
23
49
|
* </AgoProvider>
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export { AgoProvider, useAgoClient, useOptionalAgoClient } from "./AgoContext";
|
|
2
|
-
export type { AgoProviderProps } from "./AgoContext";
|
|
2
|
+
export type { AgoProviderProps, AgoDeclarativeConfig } from "./AgoContext";
|
|
@@ -4,3 +4,4 @@ export { useMessages } from "./useMessages";
|
|
|
4
4
|
export type { UseMessagesOptions, UseMessagesResult } from "./useMessages";
|
|
5
5
|
export { useConversation } from "./useConversation";
|
|
6
6
|
export type { UseConversationOptions, UseConversationResult } from "./useConversation";
|
|
7
|
+
export { useAgoContext } from "./useAgoContext";
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { ContextEntry, DynamicContextProvider } from "../../state/ClientContextRegistry";
|
|
2
|
+
/**
|
|
3
|
+
* Declaratively expose a piece of context to the AI agent with every message.
|
|
4
|
+
*
|
|
5
|
+
* Accepts either:
|
|
6
|
+
* - An **object** — sent as-is on every message (re-registered when it changes).
|
|
7
|
+
* Use for data that already lives in React state.
|
|
8
|
+
* - A **function** — called lazily at each message send, so the AI always gets
|
|
9
|
+
* the freshest value. Use for data outside React state (global stores, refs,
|
|
10
|
+
* computed values).
|
|
11
|
+
*
|
|
12
|
+
* A unique key is auto-generated per component instance via `useId()`. Pass an
|
|
13
|
+
* explicit key as second argument to share context across components or
|
|
14
|
+
* reference it from elsewhere.
|
|
15
|
+
*
|
|
16
|
+
* ```tsx
|
|
17
|
+
* // Static object — captured at render time
|
|
18
|
+
* function OrderPage({ order }) {
|
|
19
|
+
* useAgoContext({
|
|
20
|
+
* name: "Order detail",
|
|
21
|
+
* description: "The user is viewing a specific order",
|
|
22
|
+
* data: { orderId: order.id, status: order.status },
|
|
23
|
+
* });
|
|
24
|
+
* }
|
|
25
|
+
*
|
|
26
|
+
* // Dynamic function — evaluated at each sendMessage
|
|
27
|
+
* function App() {
|
|
28
|
+
* const storeRef = useRef(reduxStore);
|
|
29
|
+
* useAgoContext(() => {
|
|
30
|
+
* const state = storeRef.current.getState();
|
|
31
|
+
* return { name: "App shell", data: { userId: state.auth.userId } };
|
|
32
|
+
* });
|
|
33
|
+
* }
|
|
34
|
+
*
|
|
35
|
+
* // With an explicit key
|
|
36
|
+
* useAgoContext({ name: "Sidebar filter", data: { filter } }, "sidebar-filter");
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
export declare function useAgoContext(entry: ContextEntry, key?: string): void;
|
|
40
|
+
export declare function useAgoContext(provider: DynamicContextProvider, key?: string): void;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ClientFunctionHandler } from "../../functions/types";
|
|
1
|
+
import type { ClientFunctionDefinition, ClientFunctionHandler } from "../../functions/types";
|
|
2
2
|
export interface UseAgoFunctionOptions {
|
|
3
3
|
description: string;
|
|
4
4
|
parameters: {
|
|
@@ -17,14 +17,26 @@ export interface UseAgoFunctionOptions {
|
|
|
17
17
|
* Declaratively register a client-side function with the AGO agent.
|
|
18
18
|
* Automatically unregisters on unmount and re-registers when deps change.
|
|
19
19
|
*
|
|
20
|
+
* Accepts either a full definition object (preferred) or classic (name, options) args.
|
|
21
|
+
*
|
|
20
22
|
* ```tsx
|
|
21
|
-
*
|
|
23
|
+
* // Preferred — pass the whole definition
|
|
24
|
+
* useAgoFunction({
|
|
25
|
+
* name: "showToast",
|
|
22
26
|
* description: "Show a notification to the user",
|
|
23
27
|
* parameters: { type: "object", properties: { message: { type: "string" } } },
|
|
24
28
|
* handler: async (args) => { toast(args.message); return { shown: true }; },
|
|
25
29
|
* });
|
|
30
|
+
*
|
|
31
|
+
* // Or reuse a pre-defined function
|
|
32
|
+
* const lookupOrder = defineFunction({ name: "lookupOrder", ... });
|
|
33
|
+
* useAgoFunction(lookupOrder);
|
|
34
|
+
*
|
|
35
|
+
* // Classic form
|
|
36
|
+
* useAgoFunction("showToast", { description: "...", parameters: {...}, handler: async (args) => ... });
|
|
26
37
|
* ```
|
|
27
38
|
*/
|
|
39
|
+
export declare function useAgoFunction(definition: ClientFunctionDefinition): void;
|
|
28
40
|
export declare function useAgoFunction(name: string, options: UseAgoFunctionOptions): void;
|
|
29
41
|
export interface AgoRoute {
|
|
30
42
|
name: string;
|
package/dist/react/index.d.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
export { AgoProvider, useAgoClient, useOptionalAgoClient } from "./context";
|
|
2
|
-
export type { AgoProviderProps } from "./context";
|
|
2
|
+
export type { AgoProviderProps, AgoDeclarativeConfig } from "./context/AgoContext";
|
|
3
3
|
export { ChatWidget } from "./components/ChatWidget";
|
|
4
4
|
export type { ChatWidgetProps } from "./components/ChatWidget";
|
|
5
5
|
export { Message } from "./components/Message";
|
|
6
6
|
export type { MessageProps } from "./components/Message";
|
|
7
|
+
export { Markdown } from "./components/Markdown";
|
|
8
|
+
export type { MarkdownProps } from "./components/Markdown";
|
|
7
9
|
export { ChatInput } from "./components/ChatInput";
|
|
8
10
|
export type { ChatInputProps } from "./components/ChatInput";
|
|
9
11
|
export { useAgo } from "./hooks/useAgo";
|
|
@@ -16,5 +18,6 @@ export { useChat } from "./hooks/useChat";
|
|
|
16
18
|
export type { UseChatOptions, UseChatResult } from "./hooks/useChat";
|
|
17
19
|
export { useAgoFunction, useAgoNavigation } from "./hooks/useAgoFunction";
|
|
18
20
|
export type { UseAgoFunctionOptions, AgoRoute } from "./hooks/useAgoFunction";
|
|
21
|
+
export { useAgoContext } from "./hooks/useAgoContext";
|
|
19
22
|
export { createMockClient } from "./testing";
|
|
20
23
|
export type { AgoConfig, AgoMessage, Conversation, AgoAgent, AgoSource, ToolCallData, } from "../client/types";
|