@lov3kaizen/agentsea-react 0.4.0 → 0.5.2
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/index.d.mts +153 -6
- package/dist/index.d.ts +153 -6
- package/dist/index.js +806 -0
- package/dist/index.mjs +798 -0
- package/package.json +3 -3
package/dist/index.d.mts
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import React from 'react';
|
|
1
|
+
import React$1 from 'react';
|
|
2
2
|
import ReactMarkdown from 'react-markdown';
|
|
3
|
-
import { AgentResponse as AgentResponse$1, FormattedContent, StreamEvent } from '@lov3kaizen/agentsea-core';
|
|
3
|
+
import { AgentResponse as AgentResponse$1, FormattedContent, StreamEvent, ToolCall } from '@lov3kaizen/agentsea-core';
|
|
4
4
|
|
|
5
5
|
interface AgentResponseProps {
|
|
6
6
|
response: AgentResponse$1;
|
|
7
7
|
className?: string;
|
|
8
8
|
showMetadata?: boolean;
|
|
9
9
|
theme?: 'light' | 'dark' | 'auto';
|
|
10
|
-
components?: React.ComponentProps<typeof ReactMarkdown>['components'];
|
|
10
|
+
components?: React$1.ComponentProps<typeof ReactMarkdown>['components'];
|
|
11
11
|
}
|
|
12
|
-
declare const AgentResponse: React.FC<AgentResponseProps>;
|
|
12
|
+
declare const AgentResponse: React$1.FC<AgentResponseProps>;
|
|
13
13
|
declare const useFormattedContent: (content: string, format?: "text" | "markdown" | "html" | "react") => FormattedContent | null;
|
|
14
14
|
|
|
15
15
|
interface StreamingResponseProps {
|
|
@@ -19,7 +19,7 @@ interface StreamingResponseProps {
|
|
|
19
19
|
theme?: 'light' | 'dark' | 'auto';
|
|
20
20
|
onComplete?: (content: string) => void;
|
|
21
21
|
}
|
|
22
|
-
declare const StreamingResponse: React.FC<StreamingResponseProps>;
|
|
22
|
+
declare const StreamingResponse: React$1.FC<StreamingResponseProps>;
|
|
23
23
|
declare const useStreamingContent: () => {
|
|
24
24
|
content: string;
|
|
25
25
|
isStreaming: boolean;
|
|
@@ -27,4 +27,151 @@ declare const useStreamingContent: () => {
|
|
|
27
27
|
consumeStream: (stream: AsyncIterable<StreamEvent>) => Promise<void>;
|
|
28
28
|
};
|
|
29
29
|
|
|
30
|
-
|
|
30
|
+
type ToolCallState = 'awaiting-input' | 'input-streaming' | 'input-complete' | 'approval-requested' | 'approval-denied' | 'executing' | 'result-streaming' | 'complete' | 'error';
|
|
31
|
+
interface TrackedToolCall extends ToolCall {
|
|
32
|
+
state: ToolCallState;
|
|
33
|
+
needsApproval?: boolean;
|
|
34
|
+
approvalMessage?: string;
|
|
35
|
+
startedAt?: Date;
|
|
36
|
+
completedAt?: Date;
|
|
37
|
+
}
|
|
38
|
+
interface ThinkingPart {
|
|
39
|
+
type: 'thinking';
|
|
40
|
+
content: string;
|
|
41
|
+
isComplete: boolean;
|
|
42
|
+
}
|
|
43
|
+
interface ChatMessage {
|
|
44
|
+
id: string;
|
|
45
|
+
role: 'user' | 'assistant' | 'system' | 'tool';
|
|
46
|
+
content: string;
|
|
47
|
+
toolCalls?: TrackedToolCall[];
|
|
48
|
+
thinking?: ThinkingPart;
|
|
49
|
+
createdAt: Date;
|
|
50
|
+
metadata?: {
|
|
51
|
+
tokensUsed?: number;
|
|
52
|
+
latencyMs?: number;
|
|
53
|
+
model?: string;
|
|
54
|
+
finishReason?: string;
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
type ChatStreamChunk = {
|
|
58
|
+
type: 'content';
|
|
59
|
+
content: string;
|
|
60
|
+
delta: boolean;
|
|
61
|
+
} | {
|
|
62
|
+
type: 'thinking';
|
|
63
|
+
content: string;
|
|
64
|
+
delta: boolean;
|
|
65
|
+
} | {
|
|
66
|
+
type: 'tool_call';
|
|
67
|
+
toolCall: TrackedToolCall;
|
|
68
|
+
} | {
|
|
69
|
+
type: 'tool_result';
|
|
70
|
+
toolCall: TrackedToolCall;
|
|
71
|
+
} | {
|
|
72
|
+
type: 'tool_state';
|
|
73
|
+
toolCallId: string;
|
|
74
|
+
state: ToolCallState;
|
|
75
|
+
} | {
|
|
76
|
+
type: 'done';
|
|
77
|
+
metadata?: ChatMessage['metadata'];
|
|
78
|
+
} | {
|
|
79
|
+
type: 'error';
|
|
80
|
+
error: string;
|
|
81
|
+
};
|
|
82
|
+
interface ConnectionAdapter {
|
|
83
|
+
connect(url: string, options?: ConnectionOptions): Promise<void>;
|
|
84
|
+
send(data: ChatRequest): Promise<void>;
|
|
85
|
+
onMessage(callback: (chunk: ChatStreamChunk) => void): void;
|
|
86
|
+
onError(callback: (error: Error) => void): void;
|
|
87
|
+
onClose(callback: () => void): void;
|
|
88
|
+
close(): void;
|
|
89
|
+
}
|
|
90
|
+
interface ConnectionOptions {
|
|
91
|
+
headers?: Record<string, string>;
|
|
92
|
+
signal?: AbortSignal;
|
|
93
|
+
timeout?: number;
|
|
94
|
+
}
|
|
95
|
+
interface ChatRequest {
|
|
96
|
+
messages: ChatMessage[];
|
|
97
|
+
conversationId?: string;
|
|
98
|
+
agentId?: string;
|
|
99
|
+
stream?: boolean;
|
|
100
|
+
toolApprovals?: ToolApprovalResponse[];
|
|
101
|
+
}
|
|
102
|
+
interface ToolApprovalResponse {
|
|
103
|
+
toolCallId: string;
|
|
104
|
+
approved: boolean;
|
|
105
|
+
reason?: string;
|
|
106
|
+
}
|
|
107
|
+
interface UseChatConfig {
|
|
108
|
+
endpoint: string;
|
|
109
|
+
conversationId?: string;
|
|
110
|
+
agentId?: string;
|
|
111
|
+
initialMessages?: ChatMessage[];
|
|
112
|
+
adapter?: 'sse' | 'http' | ConnectionAdapter;
|
|
113
|
+
headers?: Record<string, string>;
|
|
114
|
+
onMessage?: (message: ChatMessage) => void;
|
|
115
|
+
onContentUpdate?: (content: string) => void;
|
|
116
|
+
onToolApproval?: (toolCall: TrackedToolCall) => void;
|
|
117
|
+
onError?: (error: Error) => void;
|
|
118
|
+
onComplete?: (response: ChatMessage) => void;
|
|
119
|
+
onThinking?: (thinking: ThinkingPart) => void;
|
|
120
|
+
autoApprove?: boolean;
|
|
121
|
+
maxRetries?: number;
|
|
122
|
+
}
|
|
123
|
+
interface UseAgentConfig {
|
|
124
|
+
endpoint: string;
|
|
125
|
+
agentId: string;
|
|
126
|
+
headers?: Record<string, string>;
|
|
127
|
+
onStart?: () => void;
|
|
128
|
+
onContentUpdate?: (content: string) => void;
|
|
129
|
+
onToolApproval?: (toolCall: TrackedToolCall) => void;
|
|
130
|
+
onError?: (error: Error) => void;
|
|
131
|
+
onComplete?: (response: AgentResponse$1) => void;
|
|
132
|
+
onThinking?: (thinking: ThinkingPart) => void;
|
|
133
|
+
}
|
|
134
|
+
interface UseChatReturn {
|
|
135
|
+
messages: ChatMessage[];
|
|
136
|
+
streamingContent: string;
|
|
137
|
+
thinkingContent: string;
|
|
138
|
+
activeToolCalls: TrackedToolCall[];
|
|
139
|
+
isLoading: boolean;
|
|
140
|
+
isStreaming: boolean;
|
|
141
|
+
error: Error | null;
|
|
142
|
+
sendMessage: (content: string) => Promise<void>;
|
|
143
|
+
approveToolCall: (toolCallId: string) => void;
|
|
144
|
+
denyToolCall: (toolCallId: string, reason?: string) => void;
|
|
145
|
+
stop: () => void;
|
|
146
|
+
clear: () => void;
|
|
147
|
+
reload: () => Promise<void>;
|
|
148
|
+
setMessages: React.Dispatch<React.SetStateAction<ChatMessage[]>>;
|
|
149
|
+
}
|
|
150
|
+
interface UseAgentReturn {
|
|
151
|
+
execute: (input: string, context?: Record<string, unknown>) => Promise<AgentResponse$1 | null>;
|
|
152
|
+
executeStream: (input: string, context?: Record<string, unknown>) => AsyncGenerator<ChatStreamChunk, void, unknown>;
|
|
153
|
+
content: string;
|
|
154
|
+
thinkingContent: string;
|
|
155
|
+
activeToolCalls: TrackedToolCall[];
|
|
156
|
+
isLoading: boolean;
|
|
157
|
+
isStreaming: boolean;
|
|
158
|
+
error: Error | null;
|
|
159
|
+
metadata: ChatMessage['metadata'] | null;
|
|
160
|
+
approveToolCall: (toolCallId: string) => void;
|
|
161
|
+
denyToolCall: (toolCallId: string, reason?: string) => void;
|
|
162
|
+
stop: () => void;
|
|
163
|
+
reset: () => void;
|
|
164
|
+
}
|
|
165
|
+
declare function generateId(): string;
|
|
166
|
+
declare function createMessage(role: ChatMessage['role'], content: string, options?: Partial<ChatMessage>): ChatMessage;
|
|
167
|
+
|
|
168
|
+
declare function useChat(config: UseChatConfig): UseChatReturn;
|
|
169
|
+
|
|
170
|
+
declare function useAgent(config: UseAgentConfig): UseAgentReturn;
|
|
171
|
+
|
|
172
|
+
declare function createSSEAdapter(): ConnectionAdapter;
|
|
173
|
+
declare function createHTTPStreamAdapter(): ConnectionAdapter;
|
|
174
|
+
declare function fetchChat(url: string, data: ChatRequest, options?: ConnectionOptions): Promise<ChatStreamChunk[]>;
|
|
175
|
+
declare function getAdapter(type: 'sse' | 'http' | ConnectionAdapter): ConnectionAdapter;
|
|
176
|
+
|
|
177
|
+
export { AgentResponse, type AgentResponseProps, type ChatMessage, type ChatRequest, type ChatStreamChunk, type ConnectionAdapter, type ConnectionOptions, StreamingResponse, type StreamingResponseProps, type ThinkingPart, type ToolApprovalResponse, type ToolCallState, type TrackedToolCall, type UseAgentConfig, type UseAgentReturn, type UseChatConfig, type UseChatReturn, createHTTPStreamAdapter, createMessage, createSSEAdapter, fetchChat, generateId, getAdapter, useAgent, useChat, useFormattedContent, useStreamingContent };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import React from 'react';
|
|
1
|
+
import React$1 from 'react';
|
|
2
2
|
import ReactMarkdown from 'react-markdown';
|
|
3
|
-
import { AgentResponse as AgentResponse$1, FormattedContent, StreamEvent } from '@lov3kaizen/agentsea-core';
|
|
3
|
+
import { AgentResponse as AgentResponse$1, FormattedContent, StreamEvent, ToolCall } from '@lov3kaizen/agentsea-core';
|
|
4
4
|
|
|
5
5
|
interface AgentResponseProps {
|
|
6
6
|
response: AgentResponse$1;
|
|
7
7
|
className?: string;
|
|
8
8
|
showMetadata?: boolean;
|
|
9
9
|
theme?: 'light' | 'dark' | 'auto';
|
|
10
|
-
components?: React.ComponentProps<typeof ReactMarkdown>['components'];
|
|
10
|
+
components?: React$1.ComponentProps<typeof ReactMarkdown>['components'];
|
|
11
11
|
}
|
|
12
|
-
declare const AgentResponse: React.FC<AgentResponseProps>;
|
|
12
|
+
declare const AgentResponse: React$1.FC<AgentResponseProps>;
|
|
13
13
|
declare const useFormattedContent: (content: string, format?: "text" | "markdown" | "html" | "react") => FormattedContent | null;
|
|
14
14
|
|
|
15
15
|
interface StreamingResponseProps {
|
|
@@ -19,7 +19,7 @@ interface StreamingResponseProps {
|
|
|
19
19
|
theme?: 'light' | 'dark' | 'auto';
|
|
20
20
|
onComplete?: (content: string) => void;
|
|
21
21
|
}
|
|
22
|
-
declare const StreamingResponse: React.FC<StreamingResponseProps>;
|
|
22
|
+
declare const StreamingResponse: React$1.FC<StreamingResponseProps>;
|
|
23
23
|
declare const useStreamingContent: () => {
|
|
24
24
|
content: string;
|
|
25
25
|
isStreaming: boolean;
|
|
@@ -27,4 +27,151 @@ declare const useStreamingContent: () => {
|
|
|
27
27
|
consumeStream: (stream: AsyncIterable<StreamEvent>) => Promise<void>;
|
|
28
28
|
};
|
|
29
29
|
|
|
30
|
-
|
|
30
|
+
type ToolCallState = 'awaiting-input' | 'input-streaming' | 'input-complete' | 'approval-requested' | 'approval-denied' | 'executing' | 'result-streaming' | 'complete' | 'error';
|
|
31
|
+
interface TrackedToolCall extends ToolCall {
|
|
32
|
+
state: ToolCallState;
|
|
33
|
+
needsApproval?: boolean;
|
|
34
|
+
approvalMessage?: string;
|
|
35
|
+
startedAt?: Date;
|
|
36
|
+
completedAt?: Date;
|
|
37
|
+
}
|
|
38
|
+
interface ThinkingPart {
|
|
39
|
+
type: 'thinking';
|
|
40
|
+
content: string;
|
|
41
|
+
isComplete: boolean;
|
|
42
|
+
}
|
|
43
|
+
interface ChatMessage {
|
|
44
|
+
id: string;
|
|
45
|
+
role: 'user' | 'assistant' | 'system' | 'tool';
|
|
46
|
+
content: string;
|
|
47
|
+
toolCalls?: TrackedToolCall[];
|
|
48
|
+
thinking?: ThinkingPart;
|
|
49
|
+
createdAt: Date;
|
|
50
|
+
metadata?: {
|
|
51
|
+
tokensUsed?: number;
|
|
52
|
+
latencyMs?: number;
|
|
53
|
+
model?: string;
|
|
54
|
+
finishReason?: string;
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
type ChatStreamChunk = {
|
|
58
|
+
type: 'content';
|
|
59
|
+
content: string;
|
|
60
|
+
delta: boolean;
|
|
61
|
+
} | {
|
|
62
|
+
type: 'thinking';
|
|
63
|
+
content: string;
|
|
64
|
+
delta: boolean;
|
|
65
|
+
} | {
|
|
66
|
+
type: 'tool_call';
|
|
67
|
+
toolCall: TrackedToolCall;
|
|
68
|
+
} | {
|
|
69
|
+
type: 'tool_result';
|
|
70
|
+
toolCall: TrackedToolCall;
|
|
71
|
+
} | {
|
|
72
|
+
type: 'tool_state';
|
|
73
|
+
toolCallId: string;
|
|
74
|
+
state: ToolCallState;
|
|
75
|
+
} | {
|
|
76
|
+
type: 'done';
|
|
77
|
+
metadata?: ChatMessage['metadata'];
|
|
78
|
+
} | {
|
|
79
|
+
type: 'error';
|
|
80
|
+
error: string;
|
|
81
|
+
};
|
|
82
|
+
interface ConnectionAdapter {
|
|
83
|
+
connect(url: string, options?: ConnectionOptions): Promise<void>;
|
|
84
|
+
send(data: ChatRequest): Promise<void>;
|
|
85
|
+
onMessage(callback: (chunk: ChatStreamChunk) => void): void;
|
|
86
|
+
onError(callback: (error: Error) => void): void;
|
|
87
|
+
onClose(callback: () => void): void;
|
|
88
|
+
close(): void;
|
|
89
|
+
}
|
|
90
|
+
interface ConnectionOptions {
|
|
91
|
+
headers?: Record<string, string>;
|
|
92
|
+
signal?: AbortSignal;
|
|
93
|
+
timeout?: number;
|
|
94
|
+
}
|
|
95
|
+
interface ChatRequest {
|
|
96
|
+
messages: ChatMessage[];
|
|
97
|
+
conversationId?: string;
|
|
98
|
+
agentId?: string;
|
|
99
|
+
stream?: boolean;
|
|
100
|
+
toolApprovals?: ToolApprovalResponse[];
|
|
101
|
+
}
|
|
102
|
+
interface ToolApprovalResponse {
|
|
103
|
+
toolCallId: string;
|
|
104
|
+
approved: boolean;
|
|
105
|
+
reason?: string;
|
|
106
|
+
}
|
|
107
|
+
interface UseChatConfig {
|
|
108
|
+
endpoint: string;
|
|
109
|
+
conversationId?: string;
|
|
110
|
+
agentId?: string;
|
|
111
|
+
initialMessages?: ChatMessage[];
|
|
112
|
+
adapter?: 'sse' | 'http' | ConnectionAdapter;
|
|
113
|
+
headers?: Record<string, string>;
|
|
114
|
+
onMessage?: (message: ChatMessage) => void;
|
|
115
|
+
onContentUpdate?: (content: string) => void;
|
|
116
|
+
onToolApproval?: (toolCall: TrackedToolCall) => void;
|
|
117
|
+
onError?: (error: Error) => void;
|
|
118
|
+
onComplete?: (response: ChatMessage) => void;
|
|
119
|
+
onThinking?: (thinking: ThinkingPart) => void;
|
|
120
|
+
autoApprove?: boolean;
|
|
121
|
+
maxRetries?: number;
|
|
122
|
+
}
|
|
123
|
+
interface UseAgentConfig {
|
|
124
|
+
endpoint: string;
|
|
125
|
+
agentId: string;
|
|
126
|
+
headers?: Record<string, string>;
|
|
127
|
+
onStart?: () => void;
|
|
128
|
+
onContentUpdate?: (content: string) => void;
|
|
129
|
+
onToolApproval?: (toolCall: TrackedToolCall) => void;
|
|
130
|
+
onError?: (error: Error) => void;
|
|
131
|
+
onComplete?: (response: AgentResponse$1) => void;
|
|
132
|
+
onThinking?: (thinking: ThinkingPart) => void;
|
|
133
|
+
}
|
|
134
|
+
interface UseChatReturn {
|
|
135
|
+
messages: ChatMessage[];
|
|
136
|
+
streamingContent: string;
|
|
137
|
+
thinkingContent: string;
|
|
138
|
+
activeToolCalls: TrackedToolCall[];
|
|
139
|
+
isLoading: boolean;
|
|
140
|
+
isStreaming: boolean;
|
|
141
|
+
error: Error | null;
|
|
142
|
+
sendMessage: (content: string) => Promise<void>;
|
|
143
|
+
approveToolCall: (toolCallId: string) => void;
|
|
144
|
+
denyToolCall: (toolCallId: string, reason?: string) => void;
|
|
145
|
+
stop: () => void;
|
|
146
|
+
clear: () => void;
|
|
147
|
+
reload: () => Promise<void>;
|
|
148
|
+
setMessages: React.Dispatch<React.SetStateAction<ChatMessage[]>>;
|
|
149
|
+
}
|
|
150
|
+
interface UseAgentReturn {
|
|
151
|
+
execute: (input: string, context?: Record<string, unknown>) => Promise<AgentResponse$1 | null>;
|
|
152
|
+
executeStream: (input: string, context?: Record<string, unknown>) => AsyncGenerator<ChatStreamChunk, void, unknown>;
|
|
153
|
+
content: string;
|
|
154
|
+
thinkingContent: string;
|
|
155
|
+
activeToolCalls: TrackedToolCall[];
|
|
156
|
+
isLoading: boolean;
|
|
157
|
+
isStreaming: boolean;
|
|
158
|
+
error: Error | null;
|
|
159
|
+
metadata: ChatMessage['metadata'] | null;
|
|
160
|
+
approveToolCall: (toolCallId: string) => void;
|
|
161
|
+
denyToolCall: (toolCallId: string, reason?: string) => void;
|
|
162
|
+
stop: () => void;
|
|
163
|
+
reset: () => void;
|
|
164
|
+
}
|
|
165
|
+
declare function generateId(): string;
|
|
166
|
+
declare function createMessage(role: ChatMessage['role'], content: string, options?: Partial<ChatMessage>): ChatMessage;
|
|
167
|
+
|
|
168
|
+
declare function useChat(config: UseChatConfig): UseChatReturn;
|
|
169
|
+
|
|
170
|
+
declare function useAgent(config: UseAgentConfig): UseAgentReturn;
|
|
171
|
+
|
|
172
|
+
declare function createSSEAdapter(): ConnectionAdapter;
|
|
173
|
+
declare function createHTTPStreamAdapter(): ConnectionAdapter;
|
|
174
|
+
declare function fetchChat(url: string, data: ChatRequest, options?: ConnectionOptions): Promise<ChatStreamChunk[]>;
|
|
175
|
+
declare function getAdapter(type: 'sse' | 'http' | ConnectionAdapter): ConnectionAdapter;
|
|
176
|
+
|
|
177
|
+
export { AgentResponse, type AgentResponseProps, type ChatMessage, type ChatRequest, type ChatStreamChunk, type ConnectionAdapter, type ConnectionOptions, StreamingResponse, type StreamingResponseProps, type ThinkingPart, type ToolApprovalResponse, type ToolCallState, type TrackedToolCall, type UseAgentConfig, type UseAgentReturn, type UseChatConfig, type UseChatReturn, createHTTPStreamAdapter, createMessage, createSSEAdapter, fetchChat, generateId, getAdapter, useAgent, useChat, useFormattedContent, useStreamingContent };
|