connectonion 0.0.18 → 0.0.21
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/connect/auth.d.ts +17 -0
- package/dist/connect/auth.d.ts.map +1 -0
- package/dist/connect/auth.js +90 -0
- package/dist/connect/chat-item-mapper.d.ts +12 -0
- package/dist/connect/chat-item-mapper.d.ts.map +1 -0
- package/dist/connect/chat-item-mapper.js +169 -0
- package/dist/connect/endpoint.d.ts +9 -4
- package/dist/connect/endpoint.d.ts.map +1 -1
- package/dist/connect/endpoint.js +9 -25
- package/dist/connect/index.d.ts +7 -0
- package/dist/connect/index.d.ts.map +1 -1
- package/dist/connect/remote-agent.d.ts +55 -73
- package/dist/connect/remote-agent.d.ts.map +1 -1
- package/dist/connect/remote-agent.js +476 -736
- package/dist/connect/types.d.ts +8 -0
- package/dist/connect/types.d.ts.map +1 -1
- package/dist/react/index.d.ts +5 -95
- package/dist/react/index.d.ts.map +1 -1
- package/dist/react/index.js +8 -230
- package/dist/react/store.d.ts +44 -0
- package/dist/react/store.d.ts.map +1 -0
- package/dist/react/store.js +61 -0
- package/dist/react/use-agent-for-human.d.ts +145 -0
- package/dist/react/use-agent-for-human.d.ts.map +1 -0
- package/dist/react/use-agent-for-human.js +203 -0
- package/package.json +1 -1
package/dist/connect/types.d.ts
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @llm-note
|
|
3
|
+
* Dependencies: imports from [src/address (type-only)] | imported by [all connect/ files, src/react/]
|
|
4
|
+
* Data flow: defines interfaces used by RemoteAgent for WebSocket message parsing → ChatItem union rendered by UI consumers → SessionState synced between client/server
|
|
5
|
+
* State/Effects: pure type definitions, no runtime logic or side effects
|
|
6
|
+
* Integration: exports Response, ChatItem (14-variant union), ChatItemType, WebSocketLike, WebSocketCtor, ResolvedEndpoint, AgentInfo, ConnectOptions, SessionState, ApprovalMode, AgentStatus, ConnectionState
|
|
7
|
+
*/
|
|
1
8
|
import type * as address from '../address';
|
|
2
9
|
export type { AddressData } from '../address';
|
|
3
10
|
export interface Response {
|
|
@@ -171,4 +178,5 @@ export interface SessionState {
|
|
|
171
178
|
export type ApprovalMode = 'safe' | 'plan' | 'accept_edits' | 'ulw';
|
|
172
179
|
export type AgentStatus = 'idle' | 'working' | 'waiting';
|
|
173
180
|
export type ConnectionState = 'disconnected' | 'connected' | 'reconnecting';
|
|
181
|
+
export type OutgoingMessage = Record<string, unknown>;
|
|
174
182
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/connect/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,OAAO,MAAM,YAAY,CAAC;AAE3C,YAAY,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/connect/types.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,KAAK,KAAK,OAAO,MAAM,YAAY,CAAC;AAE3C,YAAY,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAE9C,MAAM,WAAW,QAAQ;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,OAAO,CAAC;CACf;AAED,MAAM,MAAM,YAAY,GAAG,MAAM,GAAG,OAAO,GAAG,UAAU,GAAG,WAAW,GAAG,UAAU,GAAG,iBAAiB,GAAG,kBAAkB,GAAG,iBAAiB,GAAG,QAAQ,GAAG,MAAM,GAAG,SAAS,GAAG,cAAc,GAAG,mBAAmB,GAAG,aAAa,CAAC;AAExO,MAAM,MAAM,QAAQ,GAChB;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,EAAE,CAAA;CAAE,GAChE;IAAE,EAAE,EAAE,MAAM,CAAC;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,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC"}
|
package/dist/react/index.d.ts
CHANGED
|
@@ -1,100 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
* React hook for connecting to remote agents with automatic session persistence.
|
|
3
|
-
*
|
|
4
|
-
* @example
|
|
5
|
-
* ```tsx
|
|
6
|
-
* import { useAgent } from 'connectonion/react'
|
|
7
|
-
*
|
|
8
|
-
* function Chat() {
|
|
9
|
-
* const { status, ui, input, reset } = useAgent('0x123abc')
|
|
10
|
-
*
|
|
11
|
-
* return (
|
|
12
|
-
* <div>
|
|
13
|
-
* {ui.map(event => <div key={event.id}>{event.type}</div>)}
|
|
14
|
-
* <button onClick={() => input('Hello')}>Send</button>
|
|
15
|
-
* </div>
|
|
16
|
-
* )
|
|
17
|
-
* }
|
|
18
|
-
* ```
|
|
19
|
-
*/
|
|
20
|
-
import { Response, ChatItem, AgentStatus, ConnectionState, ConnectOptions, ApprovalMode } from '../connect';
|
|
21
|
-
export type { Response, ChatItem, ChatItemType, AgentStatus, ConnectionState, ConnectOptions, AgentInfo, ApprovalMode, } from '../connect';
|
|
1
|
+
export type { Response, ChatItem, ChatItemType, AgentStatus, ConnectionState, AgentInfo, ApprovalMode, OutgoingMessage, } from '../connect';
|
|
22
2
|
export { fetchAgentInfo } from '../connect';
|
|
3
|
+
export { type Message } from './store';
|
|
4
|
+
export { useAgentForHuman, isChatItemType, isEventType } from './use-agent-for-human';
|
|
5
|
+
export type { UseAgentForHumanReturn } from './use-agent-for-human';
|
|
23
6
|
/** @deprecated Use ChatItem instead */
|
|
24
|
-
export type UIEvent
|
|
25
|
-
/**
|
|
26
|
-
* localStorage structure:
|
|
27
|
-
*
|
|
28
|
-
* co:agent:{address}:session:{sessionId}
|
|
29
|
-
* → { messages, ui, session, createdAt, updatedAt }
|
|
30
|
-
* → Each session stored separately by sessionId
|
|
31
|
-
* → session contains full SessionState (messages, trace, turn) synced from server
|
|
32
|
-
*
|
|
33
|
-
* Future: useSessions hook for session management
|
|
34
|
-
*/
|
|
35
|
-
/** Message in conversation */
|
|
36
|
-
export interface Message {
|
|
37
|
-
role: 'user' | 'assistant' | 'system' | 'tool';
|
|
38
|
-
content: string;
|
|
39
|
-
tool_call_id?: string;
|
|
40
|
-
tool_calls?: Array<{
|
|
41
|
-
name: string;
|
|
42
|
-
arguments: unknown;
|
|
43
|
-
id: string;
|
|
44
|
-
}>;
|
|
45
|
-
}
|
|
46
|
-
export interface UseAgentReturn {
|
|
47
|
-
status: AgentStatus;
|
|
48
|
-
connectionState: ConnectionState;
|
|
49
|
-
ui: ChatItem[];
|
|
50
|
-
sessionId: string;
|
|
51
|
-
isProcessing: boolean;
|
|
52
|
-
error: Error | null;
|
|
53
|
-
/** Current approval mode: 'safe' | 'plan' | 'accept_edits' | 'ulw' */
|
|
54
|
-
mode: ApprovalMode;
|
|
55
|
-
/** ULW mode: max turns before pausing */
|
|
56
|
-
ulwTurns: number | null;
|
|
57
|
-
/** ULW mode: turns used so far */
|
|
58
|
-
ulwTurnsUsed: number | null;
|
|
59
|
-
input: (prompt: string, options?: {
|
|
60
|
-
images?: string[];
|
|
61
|
-
timeoutMs?: number;
|
|
62
|
-
}) => Promise<Response>;
|
|
63
|
-
respond: (answer: string | string[]) => void;
|
|
64
|
-
respondToApproval: (approved: boolean, scope?: 'once' | 'session', mode?: 'reject_soft' | 'reject_hard' | 'reject_explain', feedback?: string) => void;
|
|
65
|
-
respondToPlanReview: (message: string) => void;
|
|
66
|
-
respondToUlwTurnsReached: (action: 'continue' | 'switch_mode', options?: {
|
|
67
|
-
turns?: number;
|
|
68
|
-
mode?: ApprovalMode;
|
|
69
|
-
}) => void;
|
|
70
|
-
submitOnboard: (options: {
|
|
71
|
-
inviteCode?: string;
|
|
72
|
-
payment?: number;
|
|
73
|
-
}) => void;
|
|
74
|
-
/** Change approval mode: 'safe' | 'plan' | 'accept_edits' | 'ulw' */
|
|
75
|
-
setMode: (mode: ApprovalMode, options?: {
|
|
76
|
-
turns?: number;
|
|
77
|
-
}) => void;
|
|
78
|
-
/** Send persistent prompt — injected into system message every turn */
|
|
79
|
-
setPrompt: (prompt: string) => void;
|
|
80
|
-
reset: () => void;
|
|
81
|
-
}
|
|
82
|
-
export interface UseAgentOptions extends ConnectOptions {
|
|
83
|
-
sessionId: string;
|
|
84
|
-
}
|
|
85
|
-
/**
|
|
86
|
-
* React hook for connecting to a remote AI agent.
|
|
87
|
-
* Session automatically persists to localStorage by sessionId.
|
|
88
|
-
*
|
|
89
|
-
* @param address - Agent's public address (0x...)
|
|
90
|
-
* @param options - Connection options with required sessionId
|
|
91
|
-
*/
|
|
92
|
-
export declare function useAgent(address: string, options: UseAgentOptions): UseAgentReturn;
|
|
93
|
-
export declare function isChatItemType<T extends ChatItem['type']>(item: ChatItem, type: T): item is Extract<ChatItem, {
|
|
94
|
-
type: T;
|
|
95
|
-
}>;
|
|
96
|
-
/** @deprecated Use isChatItemType instead */
|
|
97
|
-
export declare const isEventType: typeof isChatItemType;
|
|
7
|
+
export type { ChatItem as UIEvent } from '../connect';
|
|
98
8
|
export { useVoiceInput, type UseVoiceInputOptions, type UseVoiceInputReturn, type VoiceInputStatus, } from './useVoiceInput';
|
|
99
9
|
export { generateBrowser, saveBrowser, loadBrowser, signBrowser, createSignedPayloadBrowser, type AddressData, } from '../address-browser';
|
|
100
10
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/react/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/react/index.ts"],"names":[],"mappings":"AACA,YAAY,EACV,QAAQ,EACR,QAAQ,EACR,YAAY,EACZ,WAAW,EACX,eAAe,EACf,SAAS,EACT,YAAY,EACZ,eAAe,GAChB,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAG5C,OAAO,EAAE,KAAK,OAAO,EAAE,MAAM,SAAS,CAAC;AAGvC,OAAO,EAAE,gBAAgB,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACtF,YAAY,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAC;AAEpE,uCAAuC;AACvC,YAAY,EAAE,QAAQ,IAAI,OAAO,EAAE,MAAM,YAAY,CAAC;AAGtD,OAAO,EACL,aAAa,EACb,KAAK,oBAAoB,EACzB,KAAK,mBAAmB,EACxB,KAAK,gBAAgB,GACtB,MAAM,iBAAiB,CAAC;AAGzB,OAAO,EACL,eAAe,EACf,WAAW,EACX,WAAW,EACX,WAAW,EACX,0BAA0B,EAC1B,KAAK,WAAW,GACjB,MAAM,oBAAoB,CAAC"}
|
package/dist/react/index.js
CHANGED
|
@@ -1,235 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* React hook for connecting to remote agents with automatic session persistence.
|
|
4
|
-
*
|
|
5
|
-
* @example
|
|
6
|
-
* ```tsx
|
|
7
|
-
* import { useAgent } from 'connectonion/react'
|
|
8
|
-
*
|
|
9
|
-
* function Chat() {
|
|
10
|
-
* const { status, ui, input, reset } = useAgent('0x123abc')
|
|
11
|
-
*
|
|
12
|
-
* return (
|
|
13
|
-
* <div>
|
|
14
|
-
* {ui.map(event => <div key={event.id}>{event.type}</div>)}
|
|
15
|
-
* <button onClick={() => input('Hello')}>Send</button>
|
|
16
|
-
* </div>
|
|
17
|
-
* )
|
|
18
|
-
* }
|
|
19
|
-
* ```
|
|
20
|
-
*/
|
|
21
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
-
exports.createSignedPayloadBrowser = exports.signBrowser = exports.loadBrowser = exports.saveBrowser = exports.generateBrowser = exports.useVoiceInput = exports.isEventType = exports.fetchAgentInfo = void 0;
|
|
23
|
-
|
|
24
|
-
exports.
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
Object.defineProperty(exports, "fetchAgentInfo", { enumerable: true, get: function () { return connect_2.fetchAgentInfo; } });
|
|
31
|
-
// =============================================================================
|
|
32
|
-
// Utilities
|
|
33
|
-
// =============================================================================
|
|
34
|
-
function createInitialState() {
|
|
35
|
-
const now = Date.now();
|
|
36
|
-
return {
|
|
37
|
-
messages: [],
|
|
38
|
-
ui: [],
|
|
39
|
-
session: null,
|
|
40
|
-
status: 'idle',
|
|
41
|
-
error: null,
|
|
42
|
-
createdAt: now,
|
|
43
|
-
updatedAt: now,
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
// =============================================================================
|
|
47
|
-
// Store Factory
|
|
48
|
-
// =============================================================================
|
|
49
|
-
const storeCache = new Map();
|
|
50
|
-
function createAgentStore(address, sessionId) {
|
|
51
|
-
return (0, zustand_1.create)()((0, middleware_1.persist)((set) => ({
|
|
52
|
-
...createInitialState(),
|
|
53
|
-
setStatus: (status) => set({ status }),
|
|
54
|
-
setUI: (ui) => set({ ui, updatedAt: Date.now() }),
|
|
55
|
-
setSession: (session) => set({ session, updatedAt: Date.now() }),
|
|
56
|
-
setError: (error) => set({ error }),
|
|
57
|
-
updateMessages: (messages) => set({ messages, updatedAt: Date.now() }),
|
|
58
|
-
reset: () => set(createInitialState()),
|
|
59
|
-
}), {
|
|
60
|
-
name: `co:agent:${address}:session:${sessionId}`,
|
|
61
|
-
storage: (0, middleware_1.createJSONStorage)(() => globalThis.localStorage),
|
|
62
|
-
skipHydration: typeof globalThis !== 'undefined' && !globalThis.localStorage,
|
|
63
|
-
partialize: (state) => ({
|
|
64
|
-
messages: state.messages,
|
|
65
|
-
ui: state.ui,
|
|
66
|
-
session: state.session,
|
|
67
|
-
createdAt: state.createdAt,
|
|
68
|
-
updatedAt: state.updatedAt,
|
|
69
|
-
}),
|
|
70
|
-
}));
|
|
71
|
-
}
|
|
72
|
-
function getStore(address, sessionId) {
|
|
73
|
-
const key = `${address}:${sessionId}`;
|
|
74
|
-
let store = storeCache.get(key);
|
|
75
|
-
if (!store) {
|
|
76
|
-
store = createAgentStore(address, sessionId);
|
|
77
|
-
storeCache.set(key, store);
|
|
78
|
-
}
|
|
79
|
-
return store;
|
|
80
|
-
}
|
|
81
|
-
/**
|
|
82
|
-
* React hook for connecting to a remote AI agent.
|
|
83
|
-
* Session automatically persists to localStorage by sessionId.
|
|
84
|
-
*
|
|
85
|
-
* @param address - Agent's public address (0x...)
|
|
86
|
-
* @param options - Connection options with required sessionId
|
|
87
|
-
*/
|
|
88
|
-
function useAgent(address, options) {
|
|
89
|
-
const { sessionId, ...connectOptions } = options;
|
|
90
|
-
const useStore = getStore(address, sessionId);
|
|
91
|
-
// State from store
|
|
92
|
-
const messages = useStore((s) => s.messages);
|
|
93
|
-
const ui = useStore((s) => s.ui);
|
|
94
|
-
const session = useStore((s) => s.session);
|
|
95
|
-
const status = useStore((s) => s.status);
|
|
96
|
-
const error = useStore((s) => s.error);
|
|
97
|
-
// Actions from store
|
|
98
|
-
const setStatus = useStore((s) => s.setStatus);
|
|
99
|
-
const setUI = useStore((s) => s.setUI);
|
|
100
|
-
const setSession = useStore((s) => s.setSession);
|
|
101
|
-
const setError = useStore((s) => s.setError);
|
|
102
|
-
const updateMessages = useStore((s) => s.updateMessages);
|
|
103
|
-
const resetStore = useStore((s) => s.reset);
|
|
104
|
-
// RemoteAgent instance (keyed by address + sessionId)
|
|
105
|
-
const agentRef = (0, react_1.useRef)(null);
|
|
106
|
-
const keyRef = (0, react_1.useRef)(`${address}:${sessionId}`);
|
|
107
|
-
// Reset agent if address or sessionId changes
|
|
108
|
-
if (keyRef.current !== `${address}:${sessionId}`) {
|
|
109
|
-
agentRef.current = null;
|
|
110
|
-
keyRef.current = `${address}:${sessionId}`;
|
|
111
|
-
}
|
|
112
|
-
if (!agentRef.current) {
|
|
113
|
-
agentRef.current = (0, connect_1.connect)(address, connectOptions);
|
|
114
|
-
}
|
|
115
|
-
const agent = agentRef.current;
|
|
116
|
-
// Restore session to agent on mount or when sessionId changes
|
|
117
|
-
(0, react_1.useEffect)(() => {
|
|
118
|
-
if (session) {
|
|
119
|
-
agent._currentSession = { ...session, session_id: sessionId };
|
|
120
|
-
agent._chatItems = [...ui];
|
|
121
|
-
}
|
|
122
|
-
else if (messages.length > 0) {
|
|
123
|
-
agent._currentSession = { session_id: sessionId, messages };
|
|
124
|
-
agent._chatItems = [...ui];
|
|
125
|
-
}
|
|
126
|
-
}, [sessionId]);
|
|
127
|
-
const input = async (prompt, options) => {
|
|
128
|
-
setError(null);
|
|
129
|
-
setStatus('working');
|
|
130
|
-
// Merge session - preserve mode from agent if set, then overlay store session
|
|
131
|
-
const agentSession = agent._currentSession || {};
|
|
132
|
-
agent._currentSession = {
|
|
133
|
-
...agentSession, // Preserve mode set by setMode()
|
|
134
|
-
...(session || {}), // Overlay with store session
|
|
135
|
-
session_id: sessionId, // Ensure correct session ID
|
|
136
|
-
messages: session?.messages || messages,
|
|
137
|
-
};
|
|
138
|
-
// Poll for UI updates and session state
|
|
139
|
-
const pollInterval = setInterval(() => {
|
|
140
|
-
setUI([...agent.ui]);
|
|
141
|
-
setStatus(agent.status);
|
|
142
|
-
// Sync session from agent on every tick (server sends session with each trace event)
|
|
143
|
-
if (agent.currentSession) {
|
|
144
|
-
setSession(agent.currentSession);
|
|
145
|
-
}
|
|
146
|
-
}, 50);
|
|
147
|
-
try {
|
|
148
|
-
const response = await agent.input(prompt, options);
|
|
149
|
-
// Final sync
|
|
150
|
-
if (agent.currentSession) {
|
|
151
|
-
setSession(agent.currentSession);
|
|
152
|
-
if (agent.currentSession.messages) {
|
|
153
|
-
updateMessages(agent.currentSession.messages);
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
setUI([...agent.ui]);
|
|
157
|
-
setStatus(agent.status);
|
|
158
|
-
return response;
|
|
159
|
-
}
|
|
160
|
-
catch (err) {
|
|
161
|
-
const e = err instanceof Error ? err : new Error(String(err));
|
|
162
|
-
setError(e);
|
|
163
|
-
setStatus('idle');
|
|
164
|
-
throw e;
|
|
165
|
-
}
|
|
166
|
-
finally {
|
|
167
|
-
clearInterval(pollInterval);
|
|
168
|
-
}
|
|
169
|
-
};
|
|
170
|
-
const reset = () => {
|
|
171
|
-
agent.reset();
|
|
172
|
-
resetStore();
|
|
173
|
-
};
|
|
174
|
-
const respond = (answer) => {
|
|
175
|
-
agent.respond(answer);
|
|
176
|
-
};
|
|
177
|
-
const respondToApproval = (approved, scope = 'once', mode, feedback) => {
|
|
178
|
-
agent.respondToApproval(approved, scope, mode, feedback);
|
|
179
|
-
};
|
|
180
|
-
const respondToPlanReview = (message) => {
|
|
181
|
-
agent.respondToPlanReview(message);
|
|
182
|
-
};
|
|
183
|
-
const submitOnboard = (options) => {
|
|
184
|
-
agent.submitOnboard(options);
|
|
185
|
-
};
|
|
186
|
-
const respondToUlwTurnsReached = (action, options) => {
|
|
187
|
-
agent.respondToUlwTurnsReached(action, options);
|
|
188
|
-
};
|
|
189
|
-
const setPrompt = (prompt) => {
|
|
190
|
-
agent.setPrompt(prompt);
|
|
191
|
-
};
|
|
192
|
-
const setMode = (newMode, options) => {
|
|
193
|
-
agent.setMode(newMode, options);
|
|
194
|
-
// Update local session state - create session if it doesn't exist
|
|
195
|
-
const updates = { mode: newMode };
|
|
196
|
-
if (newMode === 'ulw') {
|
|
197
|
-
updates.ulw_turns = options?.turns || 100;
|
|
198
|
-
updates.ulw_turns_used = 0;
|
|
199
|
-
}
|
|
200
|
-
setSession(session
|
|
201
|
-
? { ...session, ...updates }
|
|
202
|
-
: { session_id: sessionId, ...updates });
|
|
203
|
-
};
|
|
204
|
-
return {
|
|
205
|
-
status,
|
|
206
|
-
connectionState: agent.connectionState,
|
|
207
|
-
ui,
|
|
208
|
-
sessionId,
|
|
209
|
-
isProcessing: status !== 'idle',
|
|
210
|
-
error,
|
|
211
|
-
mode: session?.mode || 'safe',
|
|
212
|
-
ulwTurns: session?.ulw_turns ?? null,
|
|
213
|
-
ulwTurnsUsed: session?.ulw_turns_used ?? null,
|
|
214
|
-
input,
|
|
215
|
-
respond,
|
|
216
|
-
respondToApproval,
|
|
217
|
-
respondToPlanReview,
|
|
218
|
-
respondToUlwTurnsReached,
|
|
219
|
-
submitOnboard,
|
|
220
|
-
setMode,
|
|
221
|
-
setPrompt,
|
|
222
|
-
reset,
|
|
223
|
-
};
|
|
224
|
-
}
|
|
225
|
-
// =============================================================================
|
|
226
|
-
// Utility
|
|
227
|
-
// =============================================================================
|
|
228
|
-
function isChatItemType(item, type) {
|
|
229
|
-
return item.type === type;
|
|
230
|
-
}
|
|
231
|
-
/** @deprecated Use isChatItemType instead */
|
|
232
|
-
exports.isEventType = isChatItemType;
|
|
3
|
+
exports.createSignedPayloadBrowser = exports.signBrowser = exports.loadBrowser = exports.saveBrowser = exports.generateBrowser = exports.useVoiceInput = exports.isEventType = exports.isChatItemType = exports.useAgentForHuman = exports.fetchAgentInfo = void 0;
|
|
4
|
+
var connect_1 = require("../connect");
|
|
5
|
+
Object.defineProperty(exports, "fetchAgentInfo", { enumerable: true, get: function () { return connect_1.fetchAgentInfo; } });
|
|
6
|
+
// useAgentForHuman hook
|
|
7
|
+
var use_agent_for_human_1 = require("./use-agent-for-human");
|
|
8
|
+
Object.defineProperty(exports, "useAgentForHuman", { enumerable: true, get: function () { return use_agent_for_human_1.useAgentForHuman; } });
|
|
9
|
+
Object.defineProperty(exports, "isChatItemType", { enumerable: true, get: function () { return use_agent_for_human_1.isChatItemType; } });
|
|
10
|
+
Object.defineProperty(exports, "isEventType", { enumerable: true, get: function () { return use_agent_for_human_1.isEventType; } });
|
|
233
11
|
// Voice input
|
|
234
12
|
var useVoiceInput_1 = require("./useVoiceInput");
|
|
235
13
|
Object.defineProperty(exports, "useVoiceInput", { enumerable: true, get: function () { return useVoiceInput_1.useVoiceInput; } });
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @purpose Zustand store factory for per-session agent state, persisted to localStorage
|
|
3
|
+
* @llm-note
|
|
4
|
+
* Dependencies: imports from [zustand, zustand/middleware, src/connect/types (ChatItem, AgentStatus, SessionState)] | imported by [src/react/index.ts]
|
|
5
|
+
* Data flow: getStore(address, sessionId) → creates or retrieves cached zustand store → persisted to localStorage as co:agent:{address}:session:{sessionId}
|
|
6
|
+
* State/Effects: storeCache (module-level Map) prevents duplicate stores | each store persists messages, ui, session, timestamps to localStorage via zustand/persist
|
|
7
|
+
* Integration: exposes getStore(), Message, AgentState, AgentActions, AgentStore types
|
|
8
|
+
* Performance: storeCache is singleton Map — O(1) lookup per address:sessionId pair | partialize() limits persisted state size
|
|
9
|
+
*/
|
|
10
|
+
import { StoreApi, UseBoundStore } from 'zustand';
|
|
11
|
+
import type { ChatItem, AgentStatus, SessionState } from '../connect';
|
|
12
|
+
/** Message in conversation */
|
|
13
|
+
export interface Message {
|
|
14
|
+
role: 'user' | 'assistant' | 'system' | 'tool';
|
|
15
|
+
content: string;
|
|
16
|
+
tool_call_id?: string;
|
|
17
|
+
tool_calls?: Array<{
|
|
18
|
+
name: string;
|
|
19
|
+
arguments: unknown;
|
|
20
|
+
id: string;
|
|
21
|
+
}>;
|
|
22
|
+
}
|
|
23
|
+
/** Store state */
|
|
24
|
+
export interface AgentState {
|
|
25
|
+
messages: Message[];
|
|
26
|
+
ui: ChatItem[];
|
|
27
|
+
session: SessionState | null;
|
|
28
|
+
status: AgentStatus;
|
|
29
|
+
error: Error | null;
|
|
30
|
+
createdAt: number;
|
|
31
|
+
updatedAt: number;
|
|
32
|
+
}
|
|
33
|
+
/** Store actions */
|
|
34
|
+
export interface AgentActions {
|
|
35
|
+
setStatus: (status: AgentStatus) => void;
|
|
36
|
+
setUI: (ui: ChatItem[]) => void;
|
|
37
|
+
setSession: (session: SessionState | null) => void;
|
|
38
|
+
setError: (error: Error | null) => void;
|
|
39
|
+
updateMessages: (messages: Message[]) => void;
|
|
40
|
+
reset: () => void;
|
|
41
|
+
}
|
|
42
|
+
export type AgentStore = AgentState & AgentActions;
|
|
43
|
+
export declare function getStore(address: string, sessionId: string): UseBoundStore<StoreApi<AgentStore>>;
|
|
44
|
+
//# sourceMappingURL=store.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"store.d.ts","sourceRoot":"","sources":["../../src/react/store.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAU,QAAQ,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAE1D,OAAO,KAAK,EAAE,QAAQ,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAMtE,8BAA8B;AAC9B,MAAM,WAAW,OAAO;IACtB,IAAI,EAAE,MAAM,GAAG,WAAW,GAAG,QAAQ,GAAG,MAAM,CAAC;IAC/C,OAAO,EAAE,MAAM,CAAC;IAChB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,UAAU,CAAC,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,OAAO,CAAC;QAAC,EAAE,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CACtE;AAED,kBAAkB;AAClB,MAAM,WAAW,UAAU;IACzB,QAAQ,EAAE,OAAO,EAAE,CAAC;IACpB,EAAE,EAAE,QAAQ,EAAE,CAAC;IACf,OAAO,EAAE,YAAY,GAAG,IAAI,CAAC;IAC7B,MAAM,EAAE,WAAW,CAAC;IACpB,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,oBAAoB;AACpB,MAAM,WAAW,YAAY;IAC3B,SAAS,EAAE,CAAC,MAAM,EAAE,WAAW,KAAK,IAAI,CAAC;IACzC,KAAK,EAAE,CAAC,EAAE,EAAE,QAAQ,EAAE,KAAK,IAAI,CAAC;IAChC,UAAU,EAAE,CAAC,OAAO,EAAE,YAAY,GAAG,IAAI,KAAK,IAAI,CAAC;IACnD,QAAQ,EAAE,CAAC,KAAK,EAAE,KAAK,GAAG,IAAI,KAAK,IAAI,CAAC;IACxC,cAAc,EAAE,CAAC,QAAQ,EAAE,OAAO,EAAE,KAAK,IAAI,CAAC;IAC9C,KAAK,EAAE,MAAM,IAAI,CAAC;CACnB;AAED,MAAM,MAAM,UAAU,GAAG,UAAU,GAAG,YAAY,CAAC;AAuDnD,wBAAgB,QAAQ,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,uCAQ1D"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @purpose Zustand store factory for per-session agent state, persisted to localStorage
|
|
4
|
+
* @llm-note
|
|
5
|
+
* Dependencies: imports from [zustand, zustand/middleware, src/connect/types (ChatItem, AgentStatus, SessionState)] | imported by [src/react/index.ts]
|
|
6
|
+
* Data flow: getStore(address, sessionId) → creates or retrieves cached zustand store → persisted to localStorage as co:agent:{address}:session:{sessionId}
|
|
7
|
+
* State/Effects: storeCache (module-level Map) prevents duplicate stores | each store persists messages, ui, session, timestamps to localStorage via zustand/persist
|
|
8
|
+
* Integration: exposes getStore(), Message, AgentState, AgentActions, AgentStore types
|
|
9
|
+
* Performance: storeCache is singleton Map — O(1) lookup per address:sessionId pair | partialize() limits persisted state size
|
|
10
|
+
*/
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.getStore = getStore;
|
|
13
|
+
const zustand_1 = require("zustand");
|
|
14
|
+
const middleware_1 = require("zustand/middleware");
|
|
15
|
+
// =============================================================================
|
|
16
|
+
// Store Factory
|
|
17
|
+
// =============================================================================
|
|
18
|
+
function createInitialState() {
|
|
19
|
+
const now = Date.now();
|
|
20
|
+
return {
|
|
21
|
+
messages: [],
|
|
22
|
+
ui: [],
|
|
23
|
+
session: null,
|
|
24
|
+
status: 'idle',
|
|
25
|
+
error: null,
|
|
26
|
+
createdAt: now,
|
|
27
|
+
updatedAt: now,
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
const storeCache = new Map();
|
|
31
|
+
function createAgentStore(address, sessionId) {
|
|
32
|
+
return (0, zustand_1.create)()((0, middleware_1.persist)((set) => ({
|
|
33
|
+
...createInitialState(),
|
|
34
|
+
setStatus: (status) => set({ status }),
|
|
35
|
+
setUI: (ui) => set({ ui, updatedAt: Date.now() }),
|
|
36
|
+
setSession: (session) => set({ session, updatedAt: Date.now() }),
|
|
37
|
+
setError: (error) => set({ error }),
|
|
38
|
+
updateMessages: (messages) => set({ messages, updatedAt: Date.now() }),
|
|
39
|
+
reset: () => set(createInitialState()),
|
|
40
|
+
}), {
|
|
41
|
+
name: `co:agent:${address}:session:${sessionId}`,
|
|
42
|
+
storage: (0, middleware_1.createJSONStorage)(() => globalThis.localStorage),
|
|
43
|
+
skipHydration: typeof globalThis !== 'undefined' && !globalThis.localStorage,
|
|
44
|
+
partialize: (state) => ({
|
|
45
|
+
messages: state.messages,
|
|
46
|
+
ui: state.ui,
|
|
47
|
+
session: state.session,
|
|
48
|
+
createdAt: state.createdAt,
|
|
49
|
+
updatedAt: state.updatedAt,
|
|
50
|
+
}),
|
|
51
|
+
}));
|
|
52
|
+
}
|
|
53
|
+
function getStore(address, sessionId) {
|
|
54
|
+
const key = `${address}:${sessionId}`;
|
|
55
|
+
let store = storeCache.get(key);
|
|
56
|
+
if (!store) {
|
|
57
|
+
store = createAgentStore(address, sessionId);
|
|
58
|
+
storeCache.set(key, store);
|
|
59
|
+
}
|
|
60
|
+
return store;
|
|
61
|
+
}
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import { ChatItem, AgentStatus, ConnectionState, ApprovalMode, OutgoingMessage } from '../connect';
|
|
2
|
+
/**
|
|
3
|
+
* Return value of `useAgentForHuman`. Exposes all reactive state and every method
|
|
4
|
+
* needed to drive a full chat UI — from sending a first prompt to handling
|
|
5
|
+
* ULW (Unlimited Work) pauses and approval gates.
|
|
6
|
+
*
|
|
7
|
+
* This hook is designed for human users interacting with agents through a UI.
|
|
8
|
+
* For agent-to-agent communication, use `connect()` directly.
|
|
9
|
+
*
|
|
10
|
+
* All fields are stable references across re-renders unless their underlying
|
|
11
|
+
* value actually changes.
|
|
12
|
+
*/
|
|
13
|
+
export interface UseAgentForHumanReturn {
|
|
14
|
+
/** Current agent lifecycle state: 'idle' | 'working' | 'waiting' */
|
|
15
|
+
status: AgentStatus;
|
|
16
|
+
/**
|
|
17
|
+
* WebSocket relay connection state: 'disconnected' | 'connected' | 'reconnecting'.
|
|
18
|
+
* Updated synchronously whenever the agent's `onMessage` callback fires.
|
|
19
|
+
*/
|
|
20
|
+
connectionState: ConnectionState;
|
|
21
|
+
/**
|
|
22
|
+
* Ordered list of chat items streamed from the agent. Each item is a
|
|
23
|
+
* discriminated union keyed by `type` — use `isChatItemType` to narrow
|
|
24
|
+
* before reading type-specific fields.
|
|
25
|
+
*/
|
|
26
|
+
ui: ChatItem[];
|
|
27
|
+
/** Session UUID passed to the hook. Echoed here so consumers don't need a separate ref. */
|
|
28
|
+
sessionId: string;
|
|
29
|
+
/** True whenever status !== 'idle'. Useful for disabling input controls. */
|
|
30
|
+
isProcessing: boolean;
|
|
31
|
+
/** Last error captured and stored in the Zustand store. Cleared on the next `input()` call. */
|
|
32
|
+
error: Error | null;
|
|
33
|
+
/**
|
|
34
|
+
* Check whether a specific session is alive on the relay server.
|
|
35
|
+
* The caller decides when and how often to invoke this — no built-in interval.
|
|
36
|
+
*
|
|
37
|
+
* @param sessionId - Session UUID to probe
|
|
38
|
+
* @returns 'executing' | 'suspended' | 'connected' | 'not_found'
|
|
39
|
+
*/
|
|
40
|
+
checkSessionStatus: (sessionId: string) => Promise<'executing' | 'suspended' | 'connected' | 'not_found'>;
|
|
41
|
+
/** Current approval mode. Defaults to 'safe' when no session exists yet. */
|
|
42
|
+
mode: ApprovalMode;
|
|
43
|
+
/** Maximum turns before ULW mode pauses. null when mode is not 'ulw'. */
|
|
44
|
+
ulwTurns: number | null;
|
|
45
|
+
/** Turns consumed so far in the current ULW window. null when mode is not 'ulw'. */
|
|
46
|
+
ulwTurnsUsed: number | null;
|
|
47
|
+
/**
|
|
48
|
+
* Fire-and-forget: sends a user prompt to the agent. Updates flow back through
|
|
49
|
+
* the `onMessage` callback registered during mount, keeping `ui`, `status`,
|
|
50
|
+
* `connectionState`, and `session` in sync as the agent streams its response.
|
|
51
|
+
*
|
|
52
|
+
* @param prompt - Natural-language instruction for the agent
|
|
53
|
+
* @param options.images - Base64-encoded images to attach to the message
|
|
54
|
+
*/
|
|
55
|
+
input: (prompt: string, options?: {
|
|
56
|
+
images?: string[];
|
|
57
|
+
}) => void;
|
|
58
|
+
/**
|
|
59
|
+
* Send a typed message to the agent over the WebSocket.
|
|
60
|
+
* Use this for all response messages: ASK_USER_RESPONSE, APPROVAL_RESPONSE,
|
|
61
|
+
* PLAN_REVIEW_RESPONSE, ULW_RESPONSE, etc.
|
|
62
|
+
*/
|
|
63
|
+
sendMessage: (message: OutgoingMessage) => void;
|
|
64
|
+
/** Sign an onboard payload (requires private keys). Pass result to sendMessage(). */
|
|
65
|
+
signOnboard: (options: {
|
|
66
|
+
inviteCode?: string;
|
|
67
|
+
payment?: number;
|
|
68
|
+
}) => OutgoingMessage;
|
|
69
|
+
/**
|
|
70
|
+
* Switch the agent's approval mode and sync the change to localStorage immediately
|
|
71
|
+
* so it survives a page refresh before the next server-synced session snapshot arrives.
|
|
72
|
+
* Also initialises ULW turn counters locally when switching to 'ulw'.
|
|
73
|
+
*
|
|
74
|
+
* @param mode - Target approval mode
|
|
75
|
+
* @param options.turns - Initial turn budget when switching to 'ulw' (default 100)
|
|
76
|
+
*/
|
|
77
|
+
setMode: (mode: ApprovalMode, options?: {
|
|
78
|
+
turns?: number;
|
|
79
|
+
}) => void;
|
|
80
|
+
/** Reconnect to existing session to receive pending output */
|
|
81
|
+
reconnect: () => void;
|
|
82
|
+
/** Clear all agent and store state, effectively starting a new conversation. */
|
|
83
|
+
reset: () => void;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* React hook for a human user to interact with a remote AI agent.
|
|
87
|
+
*
|
|
88
|
+
* This is the primary hook for building chat UIs where a human drives the
|
|
89
|
+
* conversation. It handles approval gates, ULW pauses, onboarding flows,
|
|
90
|
+
* and session persistence — all concerns specific to human interaction.
|
|
91
|
+
* For agent-to-agent communication, use `connect()` directly instead.
|
|
92
|
+
*
|
|
93
|
+
* Wraps a `RemoteAgent` instance with Zustand-backed localStorage persistence
|
|
94
|
+
* so chat history and session state survive page refreshes. One store is created
|
|
95
|
+
* per `(address, sessionId)` pair and cached for the lifetime of the module.
|
|
96
|
+
*
|
|
97
|
+
* **Lifecycle**
|
|
98
|
+
* 1. On mount (or when `sessionId` changes), any persisted session is restored
|
|
99
|
+
* into the `RemoteAgent` so the server can resume from the correct context.
|
|
100
|
+
* 2. `agent.onMessage` is registered in an effect to receive every streaming
|
|
101
|
+
* event from the agent — UI items, status, connection state, and session
|
|
102
|
+
* snapshots are all synced here without a polling interval.
|
|
103
|
+
* 3. `input()` is fire-and-forget: it merges the session and dispatches the
|
|
104
|
+
* prompt; all reactive updates come back through `onMessage`.
|
|
105
|
+
*
|
|
106
|
+
* **Session ID ownership**
|
|
107
|
+
* The caller is responsible for generating and managing the session UUID.
|
|
108
|
+
* A stable ID (e.g. persisted in a URL parameter or parent component state)
|
|
109
|
+
* lets users resume interrupted sessions across browser refreshes.
|
|
110
|
+
*
|
|
111
|
+
* @param address - Agent's 0x-prefixed public address on the relay network
|
|
112
|
+
* @param sessionId - UUID identifying this conversation session
|
|
113
|
+
* @returns Reactive state and methods for driving a chat UI
|
|
114
|
+
*
|
|
115
|
+
* @example
|
|
116
|
+
* ```tsx
|
|
117
|
+
* const { status, ui, input, isProcessing } = useAgentForHuman(agentAddress, sessionId);
|
|
118
|
+
*
|
|
119
|
+
* return (
|
|
120
|
+
* <button disabled={isProcessing} onClick={() => input('Hello')}>
|
|
121
|
+
* Send
|
|
122
|
+
* </button>
|
|
123
|
+
* );
|
|
124
|
+
* ```
|
|
125
|
+
*/
|
|
126
|
+
export declare function useAgentForHuman(address: string, sessionId: string): UseAgentForHumanReturn;
|
|
127
|
+
/**
|
|
128
|
+
* Type guard that narrows a `ChatItem` to the specific variant identified by `type`.
|
|
129
|
+
*
|
|
130
|
+
* Prefer this over a raw `item.type === 'tool_call'` comparison in render code
|
|
131
|
+
* because TypeScript will fully narrow the variant's unique fields inside the branch.
|
|
132
|
+
*
|
|
133
|
+
* @example
|
|
134
|
+
* ```ts
|
|
135
|
+
* if (isChatItemType(item, 'tool_call')) {
|
|
136
|
+
* console.log(item.name, item.timing_ms); // fully typed
|
|
137
|
+
* }
|
|
138
|
+
* ```
|
|
139
|
+
*/
|
|
140
|
+
export declare function isChatItemType<T extends ChatItem['type']>(item: ChatItem, type: T): item is Extract<ChatItem, {
|
|
141
|
+
type: T;
|
|
142
|
+
}>;
|
|
143
|
+
/** @deprecated Use isChatItemType instead */
|
|
144
|
+
export declare const isEventType: typeof isChatItemType;
|
|
145
|
+
//# sourceMappingURL=use-agent-for-human.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-agent-for-human.d.ts","sourceRoot":"","sources":["../../src/react/use-agent-for-human.ts"],"names":[],"mappings":"AACA,OAAO,EAGL,QAAQ,EACR,WAAW,EACX,eAAe,EAEf,YAAY,EACZ,eAAe,EAChB,MAAM,YAAY,CAAC;AAGpB;;;;;;;;;;GAUG;AACH,MAAM,WAAW,sBAAsB;IACrC,oEAAoE;IACpE,MAAM,EAAE,WAAW,CAAC;IAEpB;;;OAGG;IACH,eAAe,EAAE,eAAe,CAAC;IAEjC;;;;OAIG;IACH,EAAE,EAAE,QAAQ,EAAE,CAAC;IAEf,2FAA2F;IAC3F,SAAS,EAAE,MAAM,CAAC;IAElB,4EAA4E;IAC5E,YAAY,EAAE,OAAO,CAAC;IAEtB,+FAA+F;IAC/F,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;IAEpB;;;;;;OAMG;IACH,kBAAkB,EAAE,CAAC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