@applica-software-guru/persona-sdk 0.1.86 → 0.1.89
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/bundle.cjs.js +14 -14
- package/dist/bundle.cjs.js.map +1 -1
- package/dist/bundle.es.js +1325 -1318
- package/dist/bundle.es.js.map +1 -1
- package/dist/bundle.iife.js +14 -14
- package/dist/bundle.iife.js.map +1 -1
- package/dist/bundle.umd.js +15 -15
- package/dist/bundle.umd.js.map +1 -1
- package/dist/messages.d.ts.map +1 -1
- package/dist/runtime/threads.d.ts +1 -2
- package/dist/runtime/threads.d.ts.map +1 -1
- package/dist/runtime.d.ts.map +1 -1
- package/dist/storage/base.d.ts +3 -13
- package/dist/storage/base.d.ts.map +1 -1
- package/dist/storage/persona.d.ts +4 -5
- package/dist/storage/persona.d.ts.map +1 -1
- package/package.json +1 -1
- package/playground/src/chat.tsx +2 -0
- package/playground/src/components/assistant-ui/thread-list.tsx +7 -11
- package/src/messages.ts +5 -0
- package/src/runtime/threads.ts +13 -28
- package/src/runtime.tsx +0 -1
- package/src/storage/base.ts +5 -13
- package/src/storage/persona.ts +20 -14
package/dist/messages.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"messages.d.ts","sourceRoot":"","sources":["../../src/messages.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AACzC,OAAO,EAAmB,iBAAiB,EAAiB,MAAM,qBAAqB,CAAC;AAIxF,wBAAgB,iBAAiB,IAAI,MAAM,CAE1C;AAED,wBAAgB,eAAe,CAAC,OAAO,EAAE,cAAc,GAAG,cAAc,CAiBvE;AAED,iBAAS,mBAAmB,CAAC,QAAQ,EAAE,cAAc,EAAE,GAAG,cAAc,EAAE,CAOzE;AACD,iBAAS,aAAa,CAAC,QAAQ,EAAE,cAAc,EAAE,GAAG,cAAc,EAAE,
|
|
1
|
+
{"version":3,"file":"messages.d.ts","sourceRoot":"","sources":["../../src/messages.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AACzC,OAAO,EAAmB,iBAAiB,EAAiB,MAAM,qBAAqB,CAAC;AAIxF,wBAAgB,iBAAiB,IAAI,MAAM,CAE1C;AAED,wBAAgB,eAAe,CAAC,OAAO,EAAE,cAAc,GAAG,cAAc,CAiBvE;AAED,iBAAS,mBAAmB,CAAC,QAAQ,EAAE,cAAc,EAAE,GAAG,cAAc,EAAE,CAOzE;AACD,iBAAS,aAAa,CAAC,QAAQ,EAAE,cAAc,EAAE,GAAG,cAAc,EAAE,CAqEnE;AAED,iBAAS,cAAc,CAAC,OAAO,EAAE,cAAc,GAAG,iBAAiB,CAsFlE;AAED,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,mBAAmB,EAAE,CAAC"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { ThreadData } from '../types';
|
|
2
|
-
import type { PersonaLogger } from '../logging';
|
|
3
2
|
import type { SessionStorage } from '../storage';
|
|
4
3
|
/**
|
|
5
4
|
* Generates a new session ID
|
|
@@ -8,7 +7,7 @@ export declare function generateSessionId(): string;
|
|
|
8
7
|
/**
|
|
9
8
|
* Creates the thread list adapter for multi-thread support
|
|
10
9
|
*/
|
|
11
|
-
export declare function createThreadListAdapter(currentThreadId: string, threadList: ThreadData[], setCurrentThreadId: (id: string) => void, setThreadList: React.Dispatch<React.SetStateAction<ThreadData[]>>, storage: SessionStorage, onThreadCreate?: (threadId: string) => void, onThreadSwitch?: (threadId: string) => void, onThreadArchive?: (threadId: string) => void, onThreadUnarchive?: (threadId: string) => void, onThreadDelete?: (threadId: string) => void
|
|
10
|
+
export declare function createThreadListAdapter(currentThreadId: string, threadList: ThreadData[], setCurrentThreadId: (id: string) => void, setThreadList: React.Dispatch<React.SetStateAction<ThreadData[]>>, storage: SessionStorage, onThreadCreate?: (threadId: string) => void, onThreadSwitch?: (threadId: string) => void, onThreadArchive?: (threadId: string) => void, onThreadUnarchive?: (threadId: string) => void, onThreadDelete?: (threadId: string) => void): {
|
|
12
11
|
threadId: string;
|
|
13
12
|
threads: {
|
|
14
13
|
id: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"threads.d.ts","sourceRoot":"","sources":["../../../src/runtime/threads.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AACtC,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"threads.d.ts","sourceRoot":"","sources":["../../../src/runtime/threads.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AACtC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAGjD;;GAEG;AACH,wBAAgB,iBAAiB,IAAI,MAAM,CAO1C;AAED;;GAEG;AACH,wBAAgB,uBAAuB,CACrC,eAAe,EAAE,MAAM,EACvB,UAAU,EAAE,UAAU,EAAE,EACxB,kBAAkB,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,IAAI,EACxC,aAAa,EAAE,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,cAAc,CAAC,UAAU,EAAE,CAAC,CAAC,EACjE,OAAO,EAAE,cAAc,EACvB,cAAc,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,IAAI,EAC3C,cAAc,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,IAAI,EAC3C,eAAe,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,IAAI,EAC5C,iBAAiB,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,IAAI,EAC9C,cAAc,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,IAAI;;;;;;;;;;;;;;;iCAkCZ,MAAM;0BAKb,MAAM;4BASJ,MAAM;yBAKH,MAAM;EAepC;AAED;;GAEG;AACH,wBAAgB,uBAAuB,IAAI,MAAM,CAEhD"}
|
package/dist/runtime.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../../src/runtime.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAoC,iBAAiB,EAAmB,MAAM,OAAO,CAAC;AAO7F,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,eAAe,EAA2B,UAAU,EAAE,MAAM,SAAS,CAAC;AAS9G,OAAO,EACL,iBAAiB,EACjB,yBAAyB,EACzB,yBAAyB,EACzB,+BAA+B,EAC/B,yBAAyB,GAC1B,MAAM,mBAAmB,CAAC;AAE3B,YAAY,EAAE,cAAc,EAAE,eAAe,EAAE,UAAU,EAAE,CAAC;
|
|
1
|
+
{"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../../src/runtime.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAoC,iBAAiB,EAAmB,MAAM,OAAO,CAAC;AAO7F,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,eAAe,EAA2B,UAAU,EAAE,MAAM,SAAS,CAAC;AAS9G,OAAO,EACL,iBAAiB,EACjB,yBAAyB,EACzB,yBAAyB,EACzB,+BAA+B,EAC/B,yBAAyB,GAC1B,MAAM,mBAAmB,CAAC;AAE3B,YAAY,EAAE,cAAc,EAAE,eAAe,EAAE,UAAU,EAAE,CAAC;AAmR5D,wBAAgB,sBAAsB,CAAC,EAAE,QAAQ,EAAE,GAAG,MAAM,EAAE,EAAE,iBAAiB,CAAC,aAAa,CAAC,2CAE/F"}
|
package/dist/storage/base.d.ts
CHANGED
|
@@ -1,19 +1,9 @@
|
|
|
1
1
|
import type { PersonaMessage, Session, ThreadData } from '../types';
|
|
2
|
-
/**
|
|
3
|
-
* Storage interface for messages with thread management support.
|
|
4
|
-
*/
|
|
5
2
|
export interface SessionStorage {
|
|
6
|
-
/**
|
|
7
|
-
* Sync messages for a specific session (load existing messages)
|
|
8
|
-
*/
|
|
9
3
|
sync(sessionId: Session): Promise<PersonaMessage[]>;
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
remove(sessionId: Session): Promise<void>;
|
|
14
|
-
/**
|
|
15
|
-
* List all threads for a specific user
|
|
16
|
-
*/
|
|
4
|
+
archive(sessionId: Session): Promise<void>;
|
|
5
|
+
unarchive(sessionId: Session): Promise<void>;
|
|
6
|
+
delete(sessionId: Session): Promise<void>;
|
|
17
7
|
list(agentId: string, userId?: string): Promise<ThreadData[]>;
|
|
18
8
|
}
|
|
19
9
|
//# sourceMappingURL=base.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base.d.ts","sourceRoot":"","sources":["../../../src/storage/base.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAEpE
|
|
1
|
+
{"version":3,"file":"base.d.ts","sourceRoot":"","sources":["../../../src/storage/base.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAEpE,MAAM,WAAW,cAAc;IAC7B,IAAI,CAAC,SAAS,EAAE,OAAO,GAAG,OAAO,CAAC,cAAc,EAAE,CAAC,CAAC;IAEpD,OAAO,CAAC,SAAS,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAE3C,SAAS,CAAC,SAAS,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAE7C,MAAM,CAAC,SAAS,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAE1C,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,EAAE,CAAC,CAAC;CAC/D"}
|
|
@@ -18,12 +18,11 @@ export declare class PersonaSessionStorage implements SessionStorage {
|
|
|
18
18
|
* Fetch messages for a session from the Persona REST API
|
|
19
19
|
*/
|
|
20
20
|
sync(sessionId: Session): Promise<PersonaMessage[]>;
|
|
21
|
-
|
|
21
|
+
archive(sessionId: Session): Promise<void>;
|
|
22
|
+
unarchive(sessionId: Session): Promise<void>;
|
|
23
|
+
delete(sessionId: Session): Promise<void>;
|
|
24
|
+
_visiblility(sessionId: Session, visibility: 'active' | 'deleted' | 'archived'): Promise<void>;
|
|
22
25
|
clearAll(): Promise<void>;
|
|
23
|
-
/**
|
|
24
|
-
* List all threads for a specific user from the Persona REST API
|
|
25
|
-
* GET /sessions?userId={userId}&page=1&size=100
|
|
26
|
-
*/
|
|
27
26
|
list(agentId: string, userId?: string): Promise<ThreadData[]>;
|
|
28
27
|
}
|
|
29
28
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"persona.d.ts","sourceRoot":"","sources":["../../../src/storage/persona.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AACpE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,QAAQ,CAAC;AAC7C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAEhD,KAAK,4BAA4B,GAAG;IAClC,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE,aAAa,CAAC;CACxB,CAAC;AAEF,qBAAa,qBAAsB,YAAW,cAAc;IAC1D,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,MAAM,CAAC,CAAS;IACxB,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,MAAM,CAAC,CAAgB;gBAEnB,IAAI,EAAE,4BAA4B;IAO9C,OAAO,CAAC,YAAY;IAMpB;;OAEG;IACG,IAAI,CAAC,SAAS,EAAE,OAAO,GAAG,OAAO,CAAC,cAAc,EAAE,CAAC;IA8CnD,MAAM,CAAC,SAAS,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;
|
|
1
|
+
{"version":3,"file":"persona.d.ts","sourceRoot":"","sources":["../../../src/storage/persona.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AACpE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,QAAQ,CAAC;AAC7C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAEhD,KAAK,4BAA4B,GAAG;IAClC,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE,aAAa,CAAC;CACxB,CAAC;AAEF,qBAAa,qBAAsB,YAAW,cAAc;IAC1D,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,MAAM,CAAC,CAAS;IACxB,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,MAAM,CAAC,CAAgB;gBAEnB,IAAI,EAAE,4BAA4B;IAO9C,OAAO,CAAC,YAAY;IAMpB;;OAEG;IACG,IAAI,CAAC,SAAS,EAAE,OAAO,GAAG,OAAO,CAAC,cAAc,EAAE,CAAC;IA8CnD,OAAO,CAAC,SAAS,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;IAI1C,SAAS,CAAC,SAAS,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;IAI5C,MAAM,CAAC,SAAS,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;IAIzC,YAAY,CAAC,SAAS,EAAE,OAAO,EAAE,UAAU,EAAE,QAAQ,GAAG,SAAS,GAAG,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC;IAiB9F,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;IAIzB,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,EAAE,CAAC;CAyBpE"}
|
package/package.json
CHANGED
package/playground/src/chat.tsx
CHANGED
|
@@ -1,14 +1,10 @@
|
|
|
1
|
-
import type { FC } from
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
ThreadListPrimitive,
|
|
5
|
-
useAssistantState,
|
|
6
|
-
} from "@assistant-ui/react";
|
|
7
|
-
import { ArchiveIcon, PlusIcon } from "lucide-react";
|
|
1
|
+
import type { FC } from 'react';
|
|
2
|
+
import { ThreadListItemPrimitive, ThreadListPrimitive, useAssistantState } from '@assistant-ui/react';
|
|
3
|
+
import { ArchiveIcon, PlusIcon } from 'lucide-react';
|
|
8
4
|
|
|
9
|
-
import { Button } from
|
|
10
|
-
import { TooltipIconButton } from
|
|
11
|
-
import { Skeleton } from
|
|
5
|
+
import { Button } from '@/components/ui/button';
|
|
6
|
+
import { TooltipIconButton } from '@/components/assistant-ui/tooltip-icon-button';
|
|
7
|
+
import { Skeleton } from '@/components/ui/skeleton';
|
|
12
8
|
|
|
13
9
|
export const ThreadList: FC = () => {
|
|
14
10
|
return (
|
|
@@ -84,7 +80,7 @@ const ThreadListItemArchive: FC = () => {
|
|
|
84
80
|
return (
|
|
85
81
|
<ThreadListItemPrimitive.Archive asChild>
|
|
86
82
|
<TooltipIconButton
|
|
87
|
-
className="aui-thread-list-item-archive mr-3 ml-auto size-4 p-0 text-foreground hover:text-primary"
|
|
83
|
+
className="aui-thread-list-item-archive mr-3 ml-auto size-4 p-0 text-foreground hover:text-primary cursor-pointer"
|
|
88
84
|
variant="ghost"
|
|
89
85
|
tooltip="Archive thread"
|
|
90
86
|
>
|
package/src/messages.ts
CHANGED
|
@@ -80,6 +80,7 @@ function parseMessages(messages: PersonaMessage[]): PersonaMessage[] {
|
|
|
80
80
|
currentMessage.finishReason = message.finishReason || currentMessage.finishReason;
|
|
81
81
|
// Keep the ID of the first chunk
|
|
82
82
|
currentMessage.id = currentMessage.id || message.id;
|
|
83
|
+
currentMessage.sources = currentMessage.sources ? [...(currentMessage.sources || []), ...(message.sources || [])] : message.sources;
|
|
83
84
|
} else {
|
|
84
85
|
// Different message or current is complete - don't merge
|
|
85
86
|
if (currentMessage) {
|
|
@@ -97,6 +98,10 @@ function parseMessages(messages: PersonaMessage[]): PersonaMessage[] {
|
|
|
97
98
|
outputMessages.push(currentMessage);
|
|
98
99
|
}
|
|
99
100
|
const cleanMessages = removeEmptyMessages(outputMessages);
|
|
101
|
+
console.log({
|
|
102
|
+
before: messages,
|
|
103
|
+
after: cleanMessages,
|
|
104
|
+
});
|
|
100
105
|
return cleanMessages;
|
|
101
106
|
}
|
|
102
107
|
|
package/src/runtime/threads.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { ThreadData } from '../types';
|
|
2
|
-
import type { PersonaLogger } from '../logging';
|
|
3
2
|
import type { SessionStorage } from '../storage';
|
|
4
3
|
|
|
4
|
+
const DEFAULT_THREAD_ID = 'DEFAULT_THREAD_ID';
|
|
5
5
|
/**
|
|
6
6
|
* Generates a new session ID
|
|
7
7
|
*/
|
|
8
8
|
export function generateSessionId(): string {
|
|
9
9
|
const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
|
|
10
10
|
let sid = '';
|
|
11
|
-
for (let i = 0; i <
|
|
11
|
+
for (let i = 0; i < 8; i++) {
|
|
12
12
|
sid += chars.charAt(Math.floor(Math.random() * chars.length));
|
|
13
13
|
}
|
|
14
14
|
return sid;
|
|
@@ -28,7 +28,6 @@ export function createThreadListAdapter(
|
|
|
28
28
|
onThreadArchive?: (threadId: string) => void,
|
|
29
29
|
onThreadUnarchive?: (threadId: string) => void,
|
|
30
30
|
onThreadDelete?: (threadId: string) => void,
|
|
31
|
-
logger?: PersonaLogger,
|
|
32
31
|
) {
|
|
33
32
|
return {
|
|
34
33
|
threadId: currentThreadId,
|
|
@@ -37,7 +36,7 @@ export function createThreadListAdapter(
|
|
|
37
36
|
.map((t) => ({
|
|
38
37
|
id: t.threadId,
|
|
39
38
|
threadId: t.threadId,
|
|
40
|
-
title: t.title || `
|
|
39
|
+
title: t.title || `Session ${t.threadId}`,
|
|
41
40
|
status: t.status as 'regular',
|
|
42
41
|
})),
|
|
43
42
|
archivedThreads: threadList
|
|
@@ -51,63 +50,49 @@ export function createThreadListAdapter(
|
|
|
51
50
|
|
|
52
51
|
onSwitchToNewThread: () => {
|
|
53
52
|
const newId = generateSessionId();
|
|
54
|
-
logger?.debug('Creating new thread:', newId);
|
|
55
|
-
|
|
56
53
|
const newThread = {
|
|
57
54
|
threadId: newId,
|
|
58
55
|
status: 'regular' as const,
|
|
59
|
-
title:
|
|
56
|
+
title: `Session ${newId}`,
|
|
60
57
|
};
|
|
61
58
|
|
|
62
59
|
setThreadList((prev) => [newThread, ...prev]);
|
|
63
60
|
setCurrentThreadId(newId);
|
|
64
|
-
|
|
65
61
|
onThreadCreate?.(newId);
|
|
66
62
|
},
|
|
67
63
|
|
|
68
64
|
onSwitchToThread: (threadId: string) => {
|
|
69
|
-
logger?.debug('Switching to thread:', threadId);
|
|
70
65
|
setCurrentThreadId(threadId);
|
|
71
|
-
// Messages will be synced by the useEffect in runtime.tsx
|
|
72
|
-
|
|
73
66
|
onThreadSwitch?.(threadId);
|
|
74
67
|
},
|
|
75
68
|
|
|
76
69
|
onArchive: (threadId: string) => {
|
|
77
|
-
|
|
78
|
-
setThreadList((prev) => prev.map((t) => (t.threadId === threadId ? { ...t, status: 'archived' as const } : t)));
|
|
79
|
-
|
|
70
|
+
setThreadList((p) => p.map((t) => (t.threadId === threadId ? { ...t, status: 'archived' as const } : t)));
|
|
80
71
|
onThreadArchive?.(threadId);
|
|
72
|
+
if (threadId === DEFAULT_THREAD_ID) {
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
storage.archive(threadId);
|
|
81
76
|
},
|
|
82
77
|
|
|
83
78
|
onUnarchive: (threadId: string) => {
|
|
84
|
-
logger?.debug('Unarchiving thread:', threadId);
|
|
85
79
|
setThreadList((prev) => prev.map((t) => (t.threadId === threadId ? { ...t, status: 'regular' as const } : t)));
|
|
86
|
-
|
|
87
80
|
onThreadUnarchive?.(threadId);
|
|
88
81
|
},
|
|
89
82
|
|
|
90
83
|
onDelete: async (threadId: string) => {
|
|
91
|
-
logger?.debug('Deleting thread:', threadId);
|
|
92
|
-
|
|
93
|
-
// Remove from list
|
|
94
84
|
setThreadList((prev) => prev.filter((t) => t.threadId !== threadId));
|
|
95
|
-
|
|
96
|
-
// Switch to another thread if deleting current
|
|
97
85
|
if (currentThreadId === threadId) {
|
|
98
86
|
const remaining = threadList.filter((t) => t.threadId !== threadId && t.status === 'regular');
|
|
99
87
|
if (remaining.length > 0) {
|
|
100
88
|
setCurrentThreadId(remaining[0].threadId);
|
|
101
89
|
}
|
|
102
90
|
}
|
|
103
|
-
|
|
104
|
-
// Delete from backend (threadId = sessionId)
|
|
105
|
-
storage
|
|
106
|
-
.remove(threadId)
|
|
107
|
-
.then(() => logger?.debug('Thread deleted from backend'))
|
|
108
|
-
.catch((error) => logger?.error('Failed to delete thread:', error));
|
|
109
|
-
|
|
110
91
|
onThreadDelete?.(threadId);
|
|
92
|
+
if (threadId === DEFAULT_THREAD_ID) {
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
await storage.delete(threadId);
|
|
111
96
|
},
|
|
112
97
|
};
|
|
113
98
|
}
|
package/src/runtime.tsx
CHANGED
package/src/storage/base.ts
CHANGED
|
@@ -1,21 +1,13 @@
|
|
|
1
1
|
import type { PersonaMessage, Session, ThreadData } from '../types';
|
|
2
2
|
|
|
3
|
-
/**
|
|
4
|
-
* Storage interface for messages with thread management support.
|
|
5
|
-
*/
|
|
6
3
|
export interface SessionStorage {
|
|
7
|
-
/**
|
|
8
|
-
* Sync messages for a specific session (load existing messages)
|
|
9
|
-
*/
|
|
10
4
|
sync(sessionId: Session): Promise<PersonaMessage[]>;
|
|
11
5
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
6
|
+
archive(sessionId: Session): Promise<void>;
|
|
7
|
+
|
|
8
|
+
unarchive(sessionId: Session): Promise<void>;
|
|
9
|
+
|
|
10
|
+
delete(sessionId: Session): Promise<void>;
|
|
16
11
|
|
|
17
|
-
/**
|
|
18
|
-
* List all threads for a specific user
|
|
19
|
-
*/
|
|
20
12
|
list(agentId: string, userId?: string): Promise<ThreadData[]>;
|
|
21
13
|
}
|
package/src/storage/persona.ts
CHANGED
|
@@ -77,19 +77,31 @@ export class PersonaSessionStorage implements SessionStorage {
|
|
|
77
77
|
}
|
|
78
78
|
}
|
|
79
79
|
|
|
80
|
-
async
|
|
80
|
+
async archive(sessionId: Session): Promise<void> {
|
|
81
|
+
return this._visiblility(sessionId, 'archived');
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
async unarchive(sessionId: Session): Promise<void> {
|
|
85
|
+
return this._visiblility(sessionId, 'active');
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
async delete(sessionId: Session): Promise<void> {
|
|
89
|
+
return this._visiblility(sessionId, 'deleted');
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
async _visiblility(sessionId: Session, visibility: 'active' | 'deleted' | 'archived'): Promise<void> {
|
|
81
93
|
if (!sessionId) return;
|
|
82
|
-
const url = `${this.endpoint}/sessions/${encodeURIComponent(String(sessionId))}`;
|
|
94
|
+
const url = `${this.endpoint}/sessions/${encodeURIComponent(String(sessionId))}/visibility`;
|
|
83
95
|
try {
|
|
84
|
-
const
|
|
96
|
+
const body = JSON.stringify({ visibility });
|
|
97
|
+
const res = await fetch(url, { method: 'PUT', headers: this.buildHeaders(), body });
|
|
85
98
|
if (!res.ok) {
|
|
86
99
|
const text = await res.text();
|
|
87
|
-
this.logger?.warn('PersonaSessionStorage: failed to
|
|
88
|
-
throw new Error(`Failed to
|
|
100
|
+
this.logger?.warn('PersonaSessionStorage: failed to set session visibility', res.status, text);
|
|
101
|
+
throw new Error(`Failed to set session visibility: ${res.status}`);
|
|
89
102
|
}
|
|
90
103
|
return;
|
|
91
104
|
} catch (err) {
|
|
92
|
-
this.logger?.warn('PersonaSessionStorage: error deleting session', err);
|
|
93
105
|
throw err;
|
|
94
106
|
}
|
|
95
107
|
}
|
|
@@ -98,12 +110,8 @@ export class PersonaSessionStorage implements SessionStorage {
|
|
|
98
110
|
return Promise.reject(new Error('PersonaAPIMessageStorage: clearAll not supported'));
|
|
99
111
|
}
|
|
100
112
|
|
|
101
|
-
/**
|
|
102
|
-
* List all threads for a specific user from the Persona REST API
|
|
103
|
-
* GET /sessions?userId={userId}&page=1&size=100
|
|
104
|
-
*/
|
|
105
113
|
async list(agentId: string, userId?: string): Promise<ThreadData[]> {
|
|
106
|
-
const params = new URLSearchParams({ page: '1', size: '100' });
|
|
114
|
+
const params = new URLSearchParams({ page: '1', size: '100', visibility: 'active' });
|
|
107
115
|
if (userId) params.set('userId', userId);
|
|
108
116
|
if (agentId) params.set('agentId', agentId);
|
|
109
117
|
|
|
@@ -111,13 +119,12 @@ export class PersonaSessionStorage implements SessionStorage {
|
|
|
111
119
|
try {
|
|
112
120
|
const res = await fetch(url, { method: 'GET', headers: this.buildHeaders() });
|
|
113
121
|
if (!res.ok) {
|
|
114
|
-
this.logger?.warn('PersonaSessionStorage: failed to list sessions', res.status);
|
|
115
122
|
return [];
|
|
116
123
|
}
|
|
117
124
|
|
|
118
125
|
const data = await res.json();
|
|
119
126
|
if (!Array.isArray(data.items)) return [];
|
|
120
|
-
const threads:
|
|
127
|
+
const threads: ThreadData[] = data.items.map((item: any) => ({
|
|
121
128
|
threadId: item.code || item.id,
|
|
122
129
|
title: item.title || `Session ${item.code || item.id}`,
|
|
123
130
|
status: item.status === 'archived' ? 'archived' : 'regular',
|
|
@@ -125,7 +132,6 @@ export class PersonaSessionStorage implements SessionStorage {
|
|
|
125
132
|
|
|
126
133
|
return threads;
|
|
127
134
|
} catch (err) {
|
|
128
|
-
this.logger?.warn('PersonaSessionStorage: error listing sessions', err);
|
|
129
135
|
return [];
|
|
130
136
|
}
|
|
131
137
|
}
|