@giselles-ai/sandbox-agent 0.1.8 → 0.1.9
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/react/index.d.ts +2 -1
- package/dist/react/index.js +23 -9
- package/package.json +1 -1
package/dist/react/index.d.ts
CHANGED
|
@@ -28,6 +28,7 @@ type AgentToolHandler = {
|
|
|
28
28
|
type UseAgentOptions = {
|
|
29
29
|
endpoint: string;
|
|
30
30
|
tools?: Record<string, AgentToolHandler>;
|
|
31
|
+
headers?: Record<string, string>;
|
|
31
32
|
};
|
|
32
33
|
type AgentHookState = {
|
|
33
34
|
status: AgentStatus;
|
|
@@ -43,6 +44,6 @@ type AgentHookState = {
|
|
|
43
44
|
document?: string;
|
|
44
45
|
}) => Promise<void>;
|
|
45
46
|
};
|
|
46
|
-
declare function useAgent({ endpoint, tools }: UseAgentOptions): AgentHookState;
|
|
47
|
+
declare function useAgent({ endpoint, tools, headers: customHeaders, }: UseAgentOptions): AgentHookState;
|
|
47
48
|
|
|
48
49
|
export { type AgentHookState, type AgentMessage, type AgentStatus, type AgentToolContext, type AgentToolHandler, type ToolEvent, type UseAgentOptions, useAgent };
|
package/dist/react/index.js
CHANGED
|
@@ -77,7 +77,11 @@ function normalizeTools(tools) {
|
|
|
77
77
|
}
|
|
78
78
|
return Object.values(tools);
|
|
79
79
|
}
|
|
80
|
-
function useAgent({
|
|
80
|
+
function useAgent({
|
|
81
|
+
endpoint,
|
|
82
|
+
tools,
|
|
83
|
+
headers: customHeaders
|
|
84
|
+
}) {
|
|
81
85
|
const [relayStatus, setRelayStatus] = useState("idle");
|
|
82
86
|
const [running, setRunning] = useState(false);
|
|
83
87
|
const [messages, setMessages] = useState([]);
|
|
@@ -128,7 +132,8 @@ function useAgent({ endpoint, tools }) {
|
|
|
128
132
|
const response = await fetch(relayBase, {
|
|
129
133
|
method: "POST",
|
|
130
134
|
headers: {
|
|
131
|
-
"content-type": "application/json"
|
|
135
|
+
"content-type": "application/json",
|
|
136
|
+
...customHeaders
|
|
132
137
|
},
|
|
133
138
|
body: JSON.stringify({
|
|
134
139
|
type: "relay.respond",
|
|
@@ -144,7 +149,7 @@ function useAgent({ endpoint, tools }) {
|
|
|
144
149
|
ok: response.ok
|
|
145
150
|
});
|
|
146
151
|
},
|
|
147
|
-
[normalizedEndpoint]
|
|
152
|
+
[normalizedEndpoint, customHeaders]
|
|
148
153
|
);
|
|
149
154
|
const addWarnings = useCallback((next) => {
|
|
150
155
|
if (next.length === 0) {
|
|
@@ -221,9 +226,16 @@ function useAgent({ endpoint, tools }) {
|
|
|
221
226
|
cleanupRelay();
|
|
222
227
|
setRelayStatus("connecting");
|
|
223
228
|
const relayBase = currentSession.relayUrl ?? normalizedEndpoint;
|
|
224
|
-
const
|
|
225
|
-
|
|
226
|
-
);
|
|
229
|
+
const sseUrl = new URL(relayBase, window.location.origin);
|
|
230
|
+
sseUrl.searchParams.set("type", "relay.events");
|
|
231
|
+
sseUrl.searchParams.set("sessionId", currentSession.sessionId);
|
|
232
|
+
sseUrl.searchParams.set("token", currentSession.token);
|
|
233
|
+
if (customHeaders) {
|
|
234
|
+
for (const [key, value] of Object.entries(customHeaders)) {
|
|
235
|
+
sseUrl.searchParams.set(key, value);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
const source = new EventSource(sseUrl.toString());
|
|
227
239
|
console.info(`${LOG_PREFIX} sse.connect`, {
|
|
228
240
|
sessionId: currentSession.sessionId
|
|
229
241
|
});
|
|
@@ -272,7 +284,7 @@ function useAgent({ endpoint, tools }) {
|
|
|
272
284
|
}, 1500);
|
|
273
285
|
}
|
|
274
286
|
};
|
|
275
|
-
}, [cleanupRelay, handleRelayEvent, normalizedEndpoint]);
|
|
287
|
+
}, [cleanupRelay, handleRelayEvent, normalizedEndpoint, customHeaders]);
|
|
276
288
|
useEffect(() => {
|
|
277
289
|
mountedRef.current = true;
|
|
278
290
|
return () => {
|
|
@@ -442,7 +454,8 @@ function useAgent({ endpoint, tools }) {
|
|
|
442
454
|
const response = await fetch(normalizedEndpoint, {
|
|
443
455
|
method: "POST",
|
|
444
456
|
headers: {
|
|
445
|
-
"content-type": "application/json"
|
|
457
|
+
"content-type": "application/json",
|
|
458
|
+
...customHeaders
|
|
446
459
|
},
|
|
447
460
|
body: JSON.stringify({
|
|
448
461
|
type: "agent.run",
|
|
@@ -499,7 +512,8 @@ function useAgent({ endpoint, tools }) {
|
|
|
499
512
|
handleStreamEvent,
|
|
500
513
|
normalizedEndpoint,
|
|
501
514
|
running,
|
|
502
|
-
sandboxId
|
|
515
|
+
sandboxId,
|
|
516
|
+
customHeaders
|
|
503
517
|
]
|
|
504
518
|
);
|
|
505
519
|
const status = running ? "running" : relayStatus;
|