bs-agent 0.0.25 → 0.0.27
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/README.md +143 -15
- package/dist/{agent-Dr1JI3mA.d.cts → agent-D9xuE8wR.d.cts} +29 -4
- package/dist/{agent-Dr1JI3mA.d.ts → agent-D9xuE8wR.d.ts} +29 -4
- package/dist/core/index.cjs.map +1 -1
- package/dist/core/index.d.cts +2 -2
- package/dist/core/index.d.ts +2 -2
- package/dist/core/index.js.map +1 -1
- package/dist/react/index.cjs +59 -9
- package/dist/react/index.cjs.map +1 -1
- package/dist/react/index.d.cts +9 -13
- package/dist/react/index.d.ts +9 -13
- package/dist/react/index.js +59 -9
- package/dist/react/index.js.map +1 -1
- package/package.json +1 -1
package/dist/react/index.d.cts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { I as ImagePart, F as FilePart, m as ToolType, B as BuildShipAgent, b as AgentInput } from '../agent-D9xuE8wR.cjs';
|
|
2
|
+
export { d as ContentPart, j as TextPart } from '../agent-D9xuE8wR.cjs';
|
|
2
3
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
3
4
|
import * as react from 'react';
|
|
4
5
|
import { ReactNode } from 'react';
|
|
@@ -65,6 +66,8 @@ type Message = {
|
|
|
65
66
|
executionId?: string;
|
|
66
67
|
/** Context passed with this message, persisted for use on resume. */
|
|
67
68
|
context?: Record<string, any>;
|
|
69
|
+
/** Multimodal attachments for user messages (images, files). */
|
|
70
|
+
attachments?: Array<ImagePart | FilePart>;
|
|
68
71
|
};
|
|
69
72
|
type Session = {
|
|
70
73
|
id: string;
|
|
@@ -95,14 +98,14 @@ interface UseAgentOptions {
|
|
|
95
98
|
declare function useAgent(agent: BuildShipAgent, options?: UseAgentOptions): {
|
|
96
99
|
inProgress: boolean;
|
|
97
100
|
messages: Message[];
|
|
98
|
-
handleSend: (input:
|
|
101
|
+
handleSend: (input: AgentInput, options?: {
|
|
99
102
|
context?: object;
|
|
100
103
|
skipUserMessage?: boolean;
|
|
101
104
|
additionalHeaders?: Record<string, string>;
|
|
102
105
|
additionalBody?: Record<string, unknown>;
|
|
103
106
|
}) => Promise<void>;
|
|
104
107
|
resumeTool: (callId: string, result: any) => Promise<void>;
|
|
105
|
-
addOptimisticMessage: (input:
|
|
108
|
+
addOptimisticMessage: (input: AgentInput) => void;
|
|
106
109
|
abort: () => void;
|
|
107
110
|
sessionId: string;
|
|
108
111
|
switchSession: (sessionId?: string) => void;
|
|
@@ -231,23 +234,16 @@ interface AgentRunner {
|
|
|
231
234
|
sessionId: string;
|
|
232
235
|
sessions: Session[];
|
|
233
236
|
debugData: Record<string, DebugDataType>;
|
|
234
|
-
handleSend: (input:
|
|
237
|
+
handleSend: (input: AgentInput, options?: {
|
|
235
238
|
context?: Record<string, unknown>;
|
|
236
239
|
skipUserMessage?: boolean;
|
|
237
240
|
additionalHeaders?: Record<string, string>;
|
|
238
241
|
additionalBody?: Record<string, unknown>;
|
|
239
|
-
/** @deprecated Use `useClientTool` hook instead. */
|
|
240
|
-
clientTools?: Array<{
|
|
241
|
-
name: string;
|
|
242
|
-
description: string;
|
|
243
|
-
parameters: unknown;
|
|
244
|
-
await?: boolean;
|
|
245
|
-
}>;
|
|
246
242
|
}) => Promise<void>;
|
|
247
243
|
resumeTool: (callId: string, result: any) => Promise<void>;
|
|
248
244
|
switchSession: (sessionId?: string) => void;
|
|
249
245
|
deleteSession: (sessionId: string) => void;
|
|
250
|
-
addOptimisticMessage: (input:
|
|
246
|
+
addOptimisticMessage: (input: AgentInput) => void;
|
|
251
247
|
abort: () => void;
|
|
252
248
|
}
|
|
253
249
|
interface AgentToolContextValue {
|
|
@@ -292,4 +288,4 @@ declare function tryParseJSON(value: unknown): any;
|
|
|
292
288
|
*/
|
|
293
289
|
declare function updateAgentMessageParts(parts: MessagePart[], newPart: MessagePart): MessagePart[];
|
|
294
290
|
|
|
295
|
-
export { AGENT_DEBUG_DATA_KEY, AGENT_SESSIONS_KEY, AgentContextProvider, type AgentRunner, AgentToolContext, type AgentToolContextValue, type ClientToolConfig, type ClientToolDefinition, type ClientToolRenderProps, DEFAULT_SESSION_NAME, type DebugDataType, type HandoffItem, type Message, type MessagePart, type ReasoningItem, type RunErrorItem, type Session, TEMPORARY_SESSION_ID, type ToolConfig, type ToolExecutionItem, ToolRenderer, ToolType, type WidgetExecutionItem, cleanSchema, tryParseJSON, updateAgentMessageParts, useAgent, useAgentContext, useAgentGlobalState, useClientTool };
|
|
291
|
+
export { AGENT_DEBUG_DATA_KEY, AGENT_SESSIONS_KEY, AgentContextProvider, AgentInput, type AgentRunner, AgentToolContext, type AgentToolContextValue, type ClientToolConfig, type ClientToolDefinition, type ClientToolRenderProps, DEFAULT_SESSION_NAME, type DebugDataType, FilePart, type HandoffItem, ImagePart, type Message, type MessagePart, type ReasoningItem, type RunErrorItem, type Session, TEMPORARY_SESSION_ID, type ToolConfig, type ToolExecutionItem, ToolRenderer, ToolType, type WidgetExecutionItem, cleanSchema, tryParseJSON, updateAgentMessageParts, useAgent, useAgentContext, useAgentGlobalState, useClientTool };
|
package/dist/react/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { I as ImagePart, F as FilePart, m as ToolType, B as BuildShipAgent, b as AgentInput } from '../agent-D9xuE8wR.js';
|
|
2
|
+
export { d as ContentPart, j as TextPart } from '../agent-D9xuE8wR.js';
|
|
2
3
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
3
4
|
import * as react from 'react';
|
|
4
5
|
import { ReactNode } from 'react';
|
|
@@ -65,6 +66,8 @@ type Message = {
|
|
|
65
66
|
executionId?: string;
|
|
66
67
|
/** Context passed with this message, persisted for use on resume. */
|
|
67
68
|
context?: Record<string, any>;
|
|
69
|
+
/** Multimodal attachments for user messages (images, files). */
|
|
70
|
+
attachments?: Array<ImagePart | FilePart>;
|
|
68
71
|
};
|
|
69
72
|
type Session = {
|
|
70
73
|
id: string;
|
|
@@ -95,14 +98,14 @@ interface UseAgentOptions {
|
|
|
95
98
|
declare function useAgent(agent: BuildShipAgent, options?: UseAgentOptions): {
|
|
96
99
|
inProgress: boolean;
|
|
97
100
|
messages: Message[];
|
|
98
|
-
handleSend: (input:
|
|
101
|
+
handleSend: (input: AgentInput, options?: {
|
|
99
102
|
context?: object;
|
|
100
103
|
skipUserMessage?: boolean;
|
|
101
104
|
additionalHeaders?: Record<string, string>;
|
|
102
105
|
additionalBody?: Record<string, unknown>;
|
|
103
106
|
}) => Promise<void>;
|
|
104
107
|
resumeTool: (callId: string, result: any) => Promise<void>;
|
|
105
|
-
addOptimisticMessage: (input:
|
|
108
|
+
addOptimisticMessage: (input: AgentInput) => void;
|
|
106
109
|
abort: () => void;
|
|
107
110
|
sessionId: string;
|
|
108
111
|
switchSession: (sessionId?: string) => void;
|
|
@@ -231,23 +234,16 @@ interface AgentRunner {
|
|
|
231
234
|
sessionId: string;
|
|
232
235
|
sessions: Session[];
|
|
233
236
|
debugData: Record<string, DebugDataType>;
|
|
234
|
-
handleSend: (input:
|
|
237
|
+
handleSend: (input: AgentInput, options?: {
|
|
235
238
|
context?: Record<string, unknown>;
|
|
236
239
|
skipUserMessage?: boolean;
|
|
237
240
|
additionalHeaders?: Record<string, string>;
|
|
238
241
|
additionalBody?: Record<string, unknown>;
|
|
239
|
-
/** @deprecated Use `useClientTool` hook instead. */
|
|
240
|
-
clientTools?: Array<{
|
|
241
|
-
name: string;
|
|
242
|
-
description: string;
|
|
243
|
-
parameters: unknown;
|
|
244
|
-
await?: boolean;
|
|
245
|
-
}>;
|
|
246
242
|
}) => Promise<void>;
|
|
247
243
|
resumeTool: (callId: string, result: any) => Promise<void>;
|
|
248
244
|
switchSession: (sessionId?: string) => void;
|
|
249
245
|
deleteSession: (sessionId: string) => void;
|
|
250
|
-
addOptimisticMessage: (input:
|
|
246
|
+
addOptimisticMessage: (input: AgentInput) => void;
|
|
251
247
|
abort: () => void;
|
|
252
248
|
}
|
|
253
249
|
interface AgentToolContextValue {
|
|
@@ -292,4 +288,4 @@ declare function tryParseJSON(value: unknown): any;
|
|
|
292
288
|
*/
|
|
293
289
|
declare function updateAgentMessageParts(parts: MessagePart[], newPart: MessagePart): MessagePart[];
|
|
294
290
|
|
|
295
|
-
export { AGENT_DEBUG_DATA_KEY, AGENT_SESSIONS_KEY, AgentContextProvider, type AgentRunner, AgentToolContext, type AgentToolContextValue, type ClientToolConfig, type ClientToolDefinition, type ClientToolRenderProps, DEFAULT_SESSION_NAME, type DebugDataType, type HandoffItem, type Message, type MessagePart, type ReasoningItem, type RunErrorItem, type Session, TEMPORARY_SESSION_ID, type ToolConfig, type ToolExecutionItem, ToolRenderer, ToolType, type WidgetExecutionItem, cleanSchema, tryParseJSON, updateAgentMessageParts, useAgent, useAgentContext, useAgentGlobalState, useClientTool };
|
|
291
|
+
export { AGENT_DEBUG_DATA_KEY, AGENT_SESSIONS_KEY, AgentContextProvider, AgentInput, type AgentRunner, AgentToolContext, type AgentToolContextValue, type ClientToolConfig, type ClientToolDefinition, type ClientToolRenderProps, DEFAULT_SESSION_NAME, type DebugDataType, FilePart, type HandoffItem, ImagePart, type Message, type MessagePart, type ReasoningItem, type RunErrorItem, type Session, TEMPORARY_SESSION_ID, type ToolConfig, type ToolExecutionItem, ToolRenderer, ToolType, type WidgetExecutionItem, cleanSchema, tryParseJSON, updateAgentMessageParts, useAgent, useAgentContext, useAgentGlobalState, useClientTool };
|
package/dist/react/index.js
CHANGED
|
@@ -20,6 +20,18 @@ var TEMPORARY_SESSION_ID = "sess_temp";
|
|
|
20
20
|
|
|
21
21
|
// src/react/session-utils.ts
|
|
22
22
|
import { useCallback, useMemo, useRef } from "react";
|
|
23
|
+
function sanitizeMessagesForStorage(messages) {
|
|
24
|
+
return messages.map((msg) => {
|
|
25
|
+
if (!msg.attachments || msg.attachments.length === 0) return msg;
|
|
26
|
+
return {
|
|
27
|
+
...msg,
|
|
28
|
+
attachments: msg.attachments.map((att) => {
|
|
29
|
+
const { data, ...metadata } = att;
|
|
30
|
+
return metadata;
|
|
31
|
+
})
|
|
32
|
+
};
|
|
33
|
+
});
|
|
34
|
+
}
|
|
23
35
|
var useSessionUtils = (agentId, allSessions, setAllSessions, currentSessionId, setCurrentSessionId, messagesRef) => {
|
|
24
36
|
const agentSessions = useMemo(() => allSessions[agentId] || {}, [agentId, allSessions]);
|
|
25
37
|
const syncSessionRef = useRef();
|
|
@@ -27,13 +39,14 @@ var useSessionUtils = (agentId, allSessions, setAllSessions, currentSessionId, s
|
|
|
27
39
|
if (!currentSessionId || currentSessionId === TEMPORARY_SESSION_ID) {
|
|
28
40
|
return;
|
|
29
41
|
}
|
|
42
|
+
const messagesToPersist = sanitizeMessagesForStorage(updatedMessages ?? messagesRef.current);
|
|
30
43
|
setAllSessions((prev) => ({
|
|
31
44
|
...prev,
|
|
32
45
|
[agentId]: {
|
|
33
46
|
...prev[agentId],
|
|
34
47
|
[currentSessionId]: {
|
|
35
48
|
...prev[agentId]?.[currentSessionId],
|
|
36
|
-
messages:
|
|
49
|
+
messages: messagesToPersist,
|
|
37
50
|
updatedAt: Date.now()
|
|
38
51
|
}
|
|
39
52
|
}
|
|
@@ -90,7 +103,7 @@ var useSessionUtils = (agentId, allSessions, setAllSessions, currentSessionId, s
|
|
|
90
103
|
id: sessionId,
|
|
91
104
|
createdAt: Date.now(),
|
|
92
105
|
updatedAt: Date.now(),
|
|
93
|
-
messages: currentMessages,
|
|
106
|
+
messages: sanitizeMessagesForStorage(currentMessages),
|
|
94
107
|
name: sessionName
|
|
95
108
|
}
|
|
96
109
|
}
|
|
@@ -478,7 +491,7 @@ function handleTextDelta(event, setMessages, syncSessionRef, modifier, fullTextM
|
|
|
478
491
|
}
|
|
479
492
|
function handleClientToolCall(event, setMessages, syncSessionRef, toolContext, agentId) {
|
|
480
493
|
const tool = toolContext?.getTool(agentId, event.data.toolName);
|
|
481
|
-
if (!tool?.render
|
|
494
|
+
if (!tool?.render) return;
|
|
482
495
|
setMessages((prev) => {
|
|
483
496
|
const lastMessage = prev[prev.length - 1];
|
|
484
497
|
const newPart = {
|
|
@@ -646,11 +659,29 @@ function useAgent(agent, options) {
|
|
|
646
659
|
);
|
|
647
660
|
const handleSend = useCallback3(
|
|
648
661
|
async (input, options2) => {
|
|
662
|
+
let displayText;
|
|
663
|
+
let attachments;
|
|
664
|
+
if (typeof input === "string") {
|
|
665
|
+
displayText = input;
|
|
666
|
+
} else {
|
|
667
|
+
const textParts = [];
|
|
668
|
+
const mediaParts = [];
|
|
669
|
+
for (const part of input) {
|
|
670
|
+
if (part.type === "text") {
|
|
671
|
+
textParts.push(part.text);
|
|
672
|
+
} else {
|
|
673
|
+
mediaParts.push(part);
|
|
674
|
+
}
|
|
675
|
+
}
|
|
676
|
+
displayText = textParts.join("\n");
|
|
677
|
+
if (mediaParts.length > 0) attachments = mediaParts;
|
|
678
|
+
}
|
|
649
679
|
const userMessage = {
|
|
650
680
|
role: "user",
|
|
651
|
-
content:
|
|
681
|
+
content: displayText,
|
|
652
682
|
executionId: Date.now().toString(),
|
|
653
|
-
...options2?.context ? { context: options2.context } : {}
|
|
683
|
+
...options2?.context ? { context: options2.context } : {},
|
|
684
|
+
...attachments ? { attachments } : {}
|
|
654
685
|
};
|
|
655
686
|
if (!options2?.skipUserMessage) {
|
|
656
687
|
setMessages((prev) => {
|
|
@@ -660,14 +691,15 @@ function useAgent(agent, options) {
|
|
|
660
691
|
}
|
|
661
692
|
return updatedMessages;
|
|
662
693
|
});
|
|
663
|
-
} else if (options2?.context) {
|
|
694
|
+
} else if (options2?.context || attachments) {
|
|
664
695
|
setMessages((prev) => {
|
|
665
696
|
const lastUserIdx = prev.findLastIndex((m) => m.role === "user");
|
|
666
697
|
if (lastUserIdx === -1) return prev;
|
|
667
698
|
const updatedMessages = [...prev];
|
|
668
699
|
updatedMessages[lastUserIdx] = {
|
|
669
700
|
...updatedMessages[lastUserIdx],
|
|
670
|
-
context: options2.context
|
|
701
|
+
...options2?.context ? { context: options2.context } : {},
|
|
702
|
+
...attachments ? { attachments } : {}
|
|
671
703
|
};
|
|
672
704
|
if (sessionUtils.syncSessionRef.current) {
|
|
673
705
|
sessionUtils.syncSessionRef.current(updatedMessages);
|
|
@@ -742,10 +774,28 @@ function useAgent(agent, options) {
|
|
|
742
774
|
);
|
|
743
775
|
const addOptimisticMessage = useCallback3(
|
|
744
776
|
(input) => {
|
|
777
|
+
let displayText;
|
|
778
|
+
let attachments;
|
|
779
|
+
if (typeof input === "string") {
|
|
780
|
+
displayText = input;
|
|
781
|
+
} else {
|
|
782
|
+
const textParts = [];
|
|
783
|
+
const mediaParts = [];
|
|
784
|
+
for (const part of input) {
|
|
785
|
+
if (part.type === "text") {
|
|
786
|
+
textParts.push(part.text);
|
|
787
|
+
} else {
|
|
788
|
+
mediaParts.push(part);
|
|
789
|
+
}
|
|
790
|
+
}
|
|
791
|
+
displayText = textParts.join("\n");
|
|
792
|
+
if (mediaParts.length > 0) attachments = mediaParts;
|
|
793
|
+
}
|
|
745
794
|
const userMessage = {
|
|
746
795
|
role: "user",
|
|
747
|
-
content:
|
|
748
|
-
executionId: Date.now().toString()
|
|
796
|
+
content: displayText,
|
|
797
|
+
executionId: Date.now().toString(),
|
|
798
|
+
...attachments ? { attachments } : {}
|
|
749
799
|
};
|
|
750
800
|
setMessages((prev) => {
|
|
751
801
|
const updatedMessages = [...prev, userMessage];
|