@athenaintel/react 0.10.3 → 0.10.5
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/auth.cjs +5 -3
- package/dist/auth.cjs.map +1 -1
- package/dist/auth.d.ts +2 -2
- package/dist/auth.js +5 -3
- package/dist/auth.js.map +1 -1
- package/dist/index.cjs +106 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +44 -0
- package/dist/index.js +106 -2
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -486,6 +486,27 @@ export declare interface AthenaTheme {
|
|
|
486
486
|
threadMaxWidth?: string;
|
|
487
487
|
}
|
|
488
488
|
|
|
489
|
+
/**
|
|
490
|
+
* Public hook for managing thread state and navigation.
|
|
491
|
+
*
|
|
492
|
+
* Wraps the underlying runtime to provide a clean, Athena-branded API
|
|
493
|
+
* for reading the active thread, listing threads, and switching between them.
|
|
494
|
+
*
|
|
495
|
+
* Must be used inside `<AthenaProvider enableThreadList>`.
|
|
496
|
+
*/
|
|
497
|
+
export declare interface AthenaThreadManagerState {
|
|
498
|
+
/** The ID of the currently active thread, or null if not yet available. */
|
|
499
|
+
activeThreadId: string | null;
|
|
500
|
+
/** All available (non-archived) thread IDs, sorted by most recent. */
|
|
501
|
+
threadIds: readonly string[];
|
|
502
|
+
/** Whether the thread list is still loading from the backend. */
|
|
503
|
+
isLoading: boolean;
|
|
504
|
+
/** Switch the chat to a different thread by ID. */
|
|
505
|
+
switchToThread: (threadId: string) => Promise<void>;
|
|
506
|
+
/** Create and switch to a new empty thread. */
|
|
507
|
+
switchToNewThread: () => Promise<void>;
|
|
508
|
+
}
|
|
509
|
+
|
|
489
510
|
/**
|
|
490
511
|
* Athena user information — a simplified, PropelAuth-agnostic representation.
|
|
491
512
|
*/
|
|
@@ -1171,6 +1192,29 @@ export declare const useAthenaLinkClickHandler: () => AthenaLinkClickHandler;
|
|
|
1171
1192
|
|
|
1172
1193
|
export declare const useAthenaRuntime: (config: AthenaRuntimeConfig) => AssistantRuntime;
|
|
1173
1194
|
|
|
1195
|
+
/**
|
|
1196
|
+
* Hook for managing thread navigation.
|
|
1197
|
+
*
|
|
1198
|
+
* Returns `null` when called outside `<AthenaProvider enableThreadList>`
|
|
1199
|
+
* or before the runtime has initialized.
|
|
1200
|
+
*
|
|
1201
|
+
* @example
|
|
1202
|
+
* ```tsx
|
|
1203
|
+
* function MyComponent() {
|
|
1204
|
+
* const threads = useAthenaThreadManager();
|
|
1205
|
+
* if (!threads) return null;
|
|
1206
|
+
*
|
|
1207
|
+
* return (
|
|
1208
|
+
* <div>
|
|
1209
|
+
* <p>Active: {threads.activeThreadId}</p>
|
|
1210
|
+
* <button onClick={() => threads.switchToNewThread()}>New Chat</button>
|
|
1211
|
+
* </div>
|
|
1212
|
+
* );
|
|
1213
|
+
* }
|
|
1214
|
+
* ```
|
|
1215
|
+
*/
|
|
1216
|
+
export declare function useAthenaThreadManager(): AthenaThreadManagerState | null;
|
|
1217
|
+
|
|
1174
1218
|
/**
|
|
1175
1219
|
* Hook for programmatic composer file attachment control.
|
|
1176
1220
|
*
|
package/dist/index.js
CHANGED
|
@@ -1360,8 +1360,8 @@ const createStoreImpl = (createState) => {
|
|
|
1360
1360
|
return api;
|
|
1361
1361
|
};
|
|
1362
1362
|
const createStore = ((createState) => createState ? createStoreImpl(createState) : createStoreImpl);
|
|
1363
|
-
const identity = (arg) => arg;
|
|
1364
|
-
function useStore$1(api, selector = identity) {
|
|
1363
|
+
const identity$1 = (arg) => arg;
|
|
1364
|
+
function useStore$1(api, selector = identity$1) {
|
|
1365
1365
|
const slice2 = React__default.useSyncExternalStore(
|
|
1366
1366
|
api.subscribe,
|
|
1367
1367
|
React__default.useCallback(() => selector(api.getState()), [api, selector]),
|
|
@@ -9571,6 +9571,72 @@ const AssistantRuntimeProviderImpl = ({ children, aui, runtime }) => {
|
|
|
9571
9571
|
return jsxs(AssistantProviderBase, { runtime, aui: aui ?? null, children: [jsx(DevToolsRegistration, {}), jsx(ThreadPrimitiveViewportProvider, { children })] });
|
|
9572
9572
|
};
|
|
9573
9573
|
const AssistantRuntimeProvider = memo(AssistantRuntimeProviderImpl);
|
|
9574
|
+
const debugVerifyPrototype = (runtime, prototype) => {
|
|
9575
|
+
const unboundMethods = Object.getOwnPropertyNames(prototype).filter((methodStr) => {
|
|
9576
|
+
const descriptor = Object.getOwnPropertyDescriptor(prototype, methodStr);
|
|
9577
|
+
const isMethod = descriptor && typeof descriptor.value === "function";
|
|
9578
|
+
if (!isMethod)
|
|
9579
|
+
return false;
|
|
9580
|
+
const methodName = methodStr;
|
|
9581
|
+
return isMethod && !methodName.startsWith("_") && methodName !== "constructor" && prototype[methodName] === runtime[methodName];
|
|
9582
|
+
});
|
|
9583
|
+
if (unboundMethods.length > 0) {
|
|
9584
|
+
throw new Error(`The following methods are not bound: ${JSON.stringify(unboundMethods)}`);
|
|
9585
|
+
}
|
|
9586
|
+
const prototypePrototype = Object.getPrototypeOf(prototype);
|
|
9587
|
+
if (prototypePrototype && prototypePrototype !== Object.prototype) {
|
|
9588
|
+
debugVerifyPrototype(runtime, prototypePrototype);
|
|
9589
|
+
}
|
|
9590
|
+
};
|
|
9591
|
+
const ensureBinding = (r2) => {
|
|
9592
|
+
var _a2;
|
|
9593
|
+
const runtime = r2;
|
|
9594
|
+
if (runtime.__isBound)
|
|
9595
|
+
return;
|
|
9596
|
+
(_a2 = runtime.__internal_bindMethods) == null ? void 0 : _a2.call(runtime);
|
|
9597
|
+
runtime.__isBound = true;
|
|
9598
|
+
if (process.env.NODE_ENV !== "production") {
|
|
9599
|
+
debugVerifyPrototype(runtime, Object.getPrototypeOf(runtime));
|
|
9600
|
+
}
|
|
9601
|
+
};
|
|
9602
|
+
function useRuntimeStateInternal(runtime, selector = identity) {
|
|
9603
|
+
ensureBinding(runtime);
|
|
9604
|
+
const slice2 = useSyncExternalStore(runtime.subscribe, () => selector(runtime.getState()), () => selector(runtime.getState()));
|
|
9605
|
+
useDebugValue(slice2);
|
|
9606
|
+
return slice2;
|
|
9607
|
+
}
|
|
9608
|
+
const identity = (arg) => arg;
|
|
9609
|
+
function createStateHookForRuntime(useRuntime) {
|
|
9610
|
+
function useStoreHook(param) {
|
|
9611
|
+
let optional = false;
|
|
9612
|
+
let selector;
|
|
9613
|
+
if (typeof param === "function") {
|
|
9614
|
+
selector = param;
|
|
9615
|
+
} else if (param) {
|
|
9616
|
+
optional = !!param.optional;
|
|
9617
|
+
selector = param.selector;
|
|
9618
|
+
}
|
|
9619
|
+
const store = useRuntime({ optional });
|
|
9620
|
+
if (!store)
|
|
9621
|
+
return null;
|
|
9622
|
+
return useRuntimeStateInternal(store, selector);
|
|
9623
|
+
}
|
|
9624
|
+
return useStoreHook;
|
|
9625
|
+
}
|
|
9626
|
+
function useAssistantRuntime(options) {
|
|
9627
|
+
var _a2, _b;
|
|
9628
|
+
const aui = useAui();
|
|
9629
|
+
const runtime = ((_b = (_a2 = aui.threads()).__internal_getAssistantRuntime) == null ? void 0 : _b.call(_a2)) ?? null;
|
|
9630
|
+
if (!runtime && !(options == null ? void 0 : options.optional)) {
|
|
9631
|
+
throw new Error("AssistantRuntime is not available");
|
|
9632
|
+
}
|
|
9633
|
+
return runtime;
|
|
9634
|
+
}
|
|
9635
|
+
const useThreadListRuntime = (opt) => {
|
|
9636
|
+
var _a2;
|
|
9637
|
+
return ((_a2 = useAssistantRuntime(opt)) == null ? void 0 : _a2.threads) ?? null;
|
|
9638
|
+
};
|
|
9639
|
+
const useThreadList = createStateHookForRuntime(useThreadListRuntime);
|
|
9574
9640
|
function useComposerRuntime(options) {
|
|
9575
9641
|
const aui = useAui();
|
|
9576
9642
|
const runtime = useAuiState(() => {
|
|
@@ -9582,6 +9648,18 @@ function useComposerRuntime(options) {
|
|
|
9582
9648
|
}
|
|
9583
9649
|
return runtime;
|
|
9584
9650
|
}
|
|
9651
|
+
function useThreadRuntime(options) {
|
|
9652
|
+
const aui = useAui();
|
|
9653
|
+
const runtime = useAuiState(() => {
|
|
9654
|
+
var _a2, _b;
|
|
9655
|
+
return aui.thread.source ? ((_b = (_a2 = aui.thread()).__internal_getRuntime) == null ? void 0 : _b.call(_a2)) ?? null : null;
|
|
9656
|
+
});
|
|
9657
|
+
if (!runtime && !(options == null ? void 0 : options.optional)) {
|
|
9658
|
+
throw new Error("ThreadRuntime is not available");
|
|
9659
|
+
}
|
|
9660
|
+
return runtime;
|
|
9661
|
+
}
|
|
9662
|
+
const useThread = createStateHookForRuntime(useThreadRuntime);
|
|
9585
9663
|
function setRef(ref, value) {
|
|
9586
9664
|
if (typeof ref === "function") {
|
|
9587
9665
|
return ref(value);
|
|
@@ -66508,6 +66586,31 @@ function ThreadListItem() {
|
|
|
66508
66586
|
/* @__PURE__ */ jsx("span", { className: "flex-1 truncate text-left", children: /* @__PURE__ */ jsx(ThreadListItemPrimitiveTitle, { fallback: "Untitled" }) })
|
|
66509
66587
|
] }) });
|
|
66510
66588
|
}
|
|
66589
|
+
function useAthenaThreadManager() {
|
|
66590
|
+
const runtime = useAssistantRuntime({ optional: true });
|
|
66591
|
+
const threadId = useThread({ optional: true, selector: (s) => s.threadId });
|
|
66592
|
+
const threadList = useThreadList({ optional: true });
|
|
66593
|
+
const switchToThread = useCallback(
|
|
66594
|
+
(id) => runtime.threads.switchToThread(id),
|
|
66595
|
+
[runtime]
|
|
66596
|
+
);
|
|
66597
|
+
const switchToNewThread = useCallback(
|
|
66598
|
+
() => runtime.threads.switchToNewThread(),
|
|
66599
|
+
[runtime]
|
|
66600
|
+
);
|
|
66601
|
+
return useMemo(() => {
|
|
66602
|
+
if (!runtime || !threadList) {
|
|
66603
|
+
return null;
|
|
66604
|
+
}
|
|
66605
|
+
return {
|
|
66606
|
+
activeThreadId: threadId ?? null,
|
|
66607
|
+
threadIds: threadList.threadIds,
|
|
66608
|
+
isLoading: threadList.isLoading,
|
|
66609
|
+
switchToThread,
|
|
66610
|
+
switchToNewThread
|
|
66611
|
+
};
|
|
66612
|
+
}, [runtime, threadId, threadList, switchToThread, switchToNewThread]);
|
|
66613
|
+
}
|
|
66511
66614
|
function useAppendToComposer() {
|
|
66512
66615
|
const aui = useAui();
|
|
66513
66616
|
return useCallback(
|
|
@@ -66686,6 +66789,7 @@ export {
|
|
|
66686
66789
|
useAthenaConfig,
|
|
66687
66790
|
useAthenaLinkClickHandler,
|
|
66688
66791
|
useAthenaRuntime,
|
|
66792
|
+
useAthenaThreadManager,
|
|
66689
66793
|
useComposerAttachment,
|
|
66690
66794
|
useFileUpload,
|
|
66691
66795
|
useMentionSuggestions,
|