bs-agent 0.0.25 → 0.0.26
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 +93 -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 +44 -7
- package/dist/react/index.cjs.map +1 -1
- package/dist/react/index.d.cts +9 -6
- package/dist/react/index.d.ts +9 -6
- package/dist/react/index.js +44 -7
- 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,7 +234,7 @@ 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>;
|
|
@@ -247,7 +250,7 @@ interface AgentRunner {
|
|
|
247
250
|
resumeTool: (callId: string, result: any) => Promise<void>;
|
|
248
251
|
switchSession: (sessionId?: string) => void;
|
|
249
252
|
deleteSession: (sessionId: string) => void;
|
|
250
|
-
addOptimisticMessage: (input:
|
|
253
|
+
addOptimisticMessage: (input: AgentInput) => void;
|
|
251
254
|
abort: () => void;
|
|
252
255
|
}
|
|
253
256
|
interface AgentToolContextValue {
|
|
@@ -292,4 +295,4 @@ declare function tryParseJSON(value: unknown): any;
|
|
|
292
295
|
*/
|
|
293
296
|
declare function updateAgentMessageParts(parts: MessagePart[], newPart: MessagePart): MessagePart[];
|
|
294
297
|
|
|
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 };
|
|
298
|
+
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,7 +234,7 @@ 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>;
|
|
@@ -247,7 +250,7 @@ interface AgentRunner {
|
|
|
247
250
|
resumeTool: (callId: string, result: any) => Promise<void>;
|
|
248
251
|
switchSession: (sessionId?: string) => void;
|
|
249
252
|
deleteSession: (sessionId: string) => void;
|
|
250
|
-
addOptimisticMessage: (input:
|
|
253
|
+
addOptimisticMessage: (input: AgentInput) => void;
|
|
251
254
|
abort: () => void;
|
|
252
255
|
}
|
|
253
256
|
interface AgentToolContextValue {
|
|
@@ -292,4 +295,4 @@ declare function tryParseJSON(value: unknown): any;
|
|
|
292
295
|
*/
|
|
293
296
|
declare function updateAgentMessageParts(parts: MessagePart[], newPart: MessagePart): MessagePart[];
|
|
294
297
|
|
|
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 };
|
|
298
|
+
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
|
@@ -478,7 +478,7 @@ function handleTextDelta(event, setMessages, syncSessionRef, modifier, fullTextM
|
|
|
478
478
|
}
|
|
479
479
|
function handleClientToolCall(event, setMessages, syncSessionRef, toolContext, agentId) {
|
|
480
480
|
const tool = toolContext?.getTool(agentId, event.data.toolName);
|
|
481
|
-
if (!tool?.render
|
|
481
|
+
if (!tool?.render) return;
|
|
482
482
|
setMessages((prev) => {
|
|
483
483
|
const lastMessage = prev[prev.length - 1];
|
|
484
484
|
const newPart = {
|
|
@@ -646,11 +646,29 @@ function useAgent(agent, options) {
|
|
|
646
646
|
);
|
|
647
647
|
const handleSend = useCallback3(
|
|
648
648
|
async (input, options2) => {
|
|
649
|
+
let displayText;
|
|
650
|
+
let attachments;
|
|
651
|
+
if (typeof input === "string") {
|
|
652
|
+
displayText = input;
|
|
653
|
+
} else {
|
|
654
|
+
const textParts = [];
|
|
655
|
+
const mediaParts = [];
|
|
656
|
+
for (const part of input) {
|
|
657
|
+
if (part.type === "text") {
|
|
658
|
+
textParts.push(part.text);
|
|
659
|
+
} else {
|
|
660
|
+
mediaParts.push(part);
|
|
661
|
+
}
|
|
662
|
+
}
|
|
663
|
+
displayText = textParts.join("\n");
|
|
664
|
+
if (mediaParts.length > 0) attachments = mediaParts;
|
|
665
|
+
}
|
|
649
666
|
const userMessage = {
|
|
650
667
|
role: "user",
|
|
651
|
-
content:
|
|
668
|
+
content: displayText,
|
|
652
669
|
executionId: Date.now().toString(),
|
|
653
|
-
...options2?.context ? { context: options2.context } : {}
|
|
670
|
+
...options2?.context ? { context: options2.context } : {},
|
|
671
|
+
...attachments ? { attachments } : {}
|
|
654
672
|
};
|
|
655
673
|
if (!options2?.skipUserMessage) {
|
|
656
674
|
setMessages((prev) => {
|
|
@@ -660,14 +678,15 @@ function useAgent(agent, options) {
|
|
|
660
678
|
}
|
|
661
679
|
return updatedMessages;
|
|
662
680
|
});
|
|
663
|
-
} else if (options2?.context) {
|
|
681
|
+
} else if (options2?.context || attachments) {
|
|
664
682
|
setMessages((prev) => {
|
|
665
683
|
const lastUserIdx = prev.findLastIndex((m) => m.role === "user");
|
|
666
684
|
if (lastUserIdx === -1) return prev;
|
|
667
685
|
const updatedMessages = [...prev];
|
|
668
686
|
updatedMessages[lastUserIdx] = {
|
|
669
687
|
...updatedMessages[lastUserIdx],
|
|
670
|
-
context: options2.context
|
|
688
|
+
...options2?.context ? { context: options2.context } : {},
|
|
689
|
+
...attachments ? { attachments } : {}
|
|
671
690
|
};
|
|
672
691
|
if (sessionUtils.syncSessionRef.current) {
|
|
673
692
|
sessionUtils.syncSessionRef.current(updatedMessages);
|
|
@@ -742,10 +761,28 @@ function useAgent(agent, options) {
|
|
|
742
761
|
);
|
|
743
762
|
const addOptimisticMessage = useCallback3(
|
|
744
763
|
(input) => {
|
|
764
|
+
let displayText;
|
|
765
|
+
let attachments;
|
|
766
|
+
if (typeof input === "string") {
|
|
767
|
+
displayText = input;
|
|
768
|
+
} else {
|
|
769
|
+
const textParts = [];
|
|
770
|
+
const mediaParts = [];
|
|
771
|
+
for (const part of input) {
|
|
772
|
+
if (part.type === "text") {
|
|
773
|
+
textParts.push(part.text);
|
|
774
|
+
} else {
|
|
775
|
+
mediaParts.push(part);
|
|
776
|
+
}
|
|
777
|
+
}
|
|
778
|
+
displayText = textParts.join("\n");
|
|
779
|
+
if (mediaParts.length > 0) attachments = mediaParts;
|
|
780
|
+
}
|
|
745
781
|
const userMessage = {
|
|
746
782
|
role: "user",
|
|
747
|
-
content:
|
|
748
|
-
executionId: Date.now().toString()
|
|
783
|
+
content: displayText,
|
|
784
|
+
executionId: Date.now().toString(),
|
|
785
|
+
...attachments ? { attachments } : {}
|
|
749
786
|
};
|
|
750
787
|
setMessages((prev) => {
|
|
751
788
|
const updatedMessages = [...prev, userMessage];
|