@giselles-ai/sandbox-agent 0.1.3 → 0.1.5
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 -2
- package/dist/react/index.js +36 -36
- package/package.json +2 -2
package/dist/react/index.d.ts
CHANGED
|
@@ -47,8 +47,8 @@ type ToolEvent = {
|
|
|
47
47
|
parameters?: unknown;
|
|
48
48
|
output?: unknown;
|
|
49
49
|
};
|
|
50
|
-
type
|
|
51
|
-
type AgentStatus =
|
|
50
|
+
type RelayStatus = "idle" | "connecting" | "connected" | "error";
|
|
51
|
+
type AgentStatus = RelayStatus | "running";
|
|
52
52
|
type UseAgentOptions = {
|
|
53
53
|
endpoint: string;
|
|
54
54
|
};
|
package/dist/react/index.js
CHANGED
|
@@ -295,7 +295,7 @@ function PromptPanel({
|
|
|
295
295
|
// src/react/use-agent.ts
|
|
296
296
|
import { execute as execute2, snapshot as snapshot2 } from "@giselles-ai/browser-tool/dom";
|
|
297
297
|
import { useCallback as useCallback2, useEffect, useMemo as useMemo3, useRef, useState as useState3 } from "react";
|
|
298
|
-
var LOG_PREFIX = "[agent-
|
|
298
|
+
var LOG_PREFIX = "[agent-relay-client]";
|
|
299
299
|
function isRecord2(value) {
|
|
300
300
|
return Boolean(value) && typeof value === "object";
|
|
301
301
|
}
|
|
@@ -367,7 +367,7 @@ function dedupeStringArray(next) {
|
|
|
367
367
|
return Array.from(nextSet);
|
|
368
368
|
}
|
|
369
369
|
function useAgent({ endpoint }) {
|
|
370
|
-
const [
|
|
370
|
+
const [relayStatus, setRelayStatus] = useState3("idle");
|
|
371
371
|
const [running, setRunning] = useState3(false);
|
|
372
372
|
const [messages, setMessages] = useState3([]);
|
|
373
373
|
const [tools, setTools] = useState3([]);
|
|
@@ -386,7 +386,7 @@ function useAgent({ endpoint }) {
|
|
|
386
386
|
const sessionRef = useRef(null);
|
|
387
387
|
const messagesAssistantId = useRef(null);
|
|
388
388
|
const assistantBufferRef = useRef("");
|
|
389
|
-
const
|
|
389
|
+
const cleanupRelay = useCallback2(() => {
|
|
390
390
|
if (eventSourceRef.current) {
|
|
391
391
|
eventSourceRef.current.close();
|
|
392
392
|
eventSourceRef.current = null;
|
|
@@ -396,7 +396,7 @@ function useAgent({ endpoint }) {
|
|
|
396
396
|
reconnectTimerRef.current = null;
|
|
397
397
|
}
|
|
398
398
|
}, []);
|
|
399
|
-
const
|
|
399
|
+
const handleRelayResponse = useCallback2(
|
|
400
400
|
async (payload) => {
|
|
401
401
|
const currentSession = sessionRef.current;
|
|
402
402
|
if (!currentSession) {
|
|
@@ -412,14 +412,14 @@ function useAgent({ endpoint }) {
|
|
|
412
412
|
requestId,
|
|
413
413
|
responseType
|
|
414
414
|
});
|
|
415
|
-
const
|
|
416
|
-
const response = await fetch(
|
|
415
|
+
const relayBase = currentSession.relayUrl ?? normalizedEndpoint;
|
|
416
|
+
const response = await fetch(relayBase, {
|
|
417
417
|
method: "POST",
|
|
418
418
|
headers: {
|
|
419
419
|
"content-type": "application/json"
|
|
420
420
|
},
|
|
421
421
|
body: JSON.stringify({
|
|
422
|
-
type: "
|
|
422
|
+
type: "relay.respond",
|
|
423
423
|
sessionId: currentSession.sessionId,
|
|
424
424
|
token: currentSession.token,
|
|
425
425
|
response: payload
|
|
@@ -434,7 +434,7 @@ function useAgent({ endpoint }) {
|
|
|
434
434
|
},
|
|
435
435
|
[normalizedEndpoint]
|
|
436
436
|
);
|
|
437
|
-
const
|
|
437
|
+
const handleRelayEvent = useCallback2(
|
|
438
438
|
async (event) => {
|
|
439
439
|
if (!isRecord2(event) || typeof event.type !== "string") {
|
|
440
440
|
return;
|
|
@@ -463,7 +463,7 @@ function useAgent({ endpoint }) {
|
|
|
463
463
|
requestId,
|
|
464
464
|
fieldCount: fields.length
|
|
465
465
|
});
|
|
466
|
-
await
|
|
466
|
+
await handleRelayResponse({
|
|
467
467
|
type: "snapshot_response",
|
|
468
468
|
requestId,
|
|
469
469
|
fields
|
|
@@ -486,41 +486,41 @@ function useAgent({ endpoint }) {
|
|
|
486
486
|
setWarnings(
|
|
487
487
|
(current) => dedupeStringArray([...current, ...report.warnings])
|
|
488
488
|
);
|
|
489
|
-
await
|
|
489
|
+
await handleRelayResponse({
|
|
490
490
|
type: "execute_response",
|
|
491
491
|
requestId,
|
|
492
492
|
report
|
|
493
493
|
});
|
|
494
494
|
return;
|
|
495
495
|
}
|
|
496
|
-
await
|
|
496
|
+
await handleRelayResponse({
|
|
497
497
|
type: "error_response",
|
|
498
498
|
requestId,
|
|
499
|
-
message: `Unsupported
|
|
499
|
+
message: `Unsupported relay request type: ${event.type}`
|
|
500
500
|
});
|
|
501
|
-
} catch (
|
|
502
|
-
const message =
|
|
501
|
+
} catch (relayError) {
|
|
502
|
+
const message = relayError instanceof Error ? relayError.message : "Relay execution failed.";
|
|
503
503
|
setError(message);
|
|
504
|
-
|
|
505
|
-
await
|
|
504
|
+
setRelayStatus("error");
|
|
505
|
+
await handleRelayResponse({
|
|
506
506
|
type: "error_response",
|
|
507
507
|
requestId,
|
|
508
508
|
message
|
|
509
509
|
});
|
|
510
510
|
}
|
|
511
511
|
},
|
|
512
|
-
[
|
|
512
|
+
[handleRelayResponse]
|
|
513
513
|
);
|
|
514
514
|
const connect = useCallback2(() => {
|
|
515
515
|
const currentSession = sessionRef.current;
|
|
516
516
|
if (!currentSession) {
|
|
517
517
|
return;
|
|
518
518
|
}
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
const
|
|
519
|
+
cleanupRelay();
|
|
520
|
+
setRelayStatus("connecting");
|
|
521
|
+
const relayBase = currentSession.relayUrl ?? normalizedEndpoint;
|
|
522
522
|
const source = new EventSource(
|
|
523
|
-
`${
|
|
523
|
+
`${relayBase}?type=relay.events&sessionId=${encodeURIComponent(currentSession.sessionId)}&token=${encodeURIComponent(currentSession.token)}`
|
|
524
524
|
);
|
|
525
525
|
console.info(`${LOG_PREFIX} sse.connect`, {
|
|
526
526
|
sessionId: currentSession.sessionId
|
|
@@ -530,7 +530,7 @@ function useAgent({ endpoint }) {
|
|
|
530
530
|
if (!mountedRef.current) {
|
|
531
531
|
return;
|
|
532
532
|
}
|
|
533
|
-
|
|
533
|
+
setRelayStatus("connected");
|
|
534
534
|
console.info(`${LOG_PREFIX} sse.open`, {
|
|
535
535
|
sessionId: currentSession.sessionId
|
|
536
536
|
});
|
|
@@ -546,7 +546,7 @@ function useAgent({ endpoint }) {
|
|
|
546
546
|
sessionId: currentSession.sessionId,
|
|
547
547
|
type: typeof payload === "object" && payload && "type" in payload && typeof payload.type === "string" ? payload.type : "unknown"
|
|
548
548
|
});
|
|
549
|
-
void
|
|
549
|
+
void handleRelayEvent(payload);
|
|
550
550
|
} catch (error2) {
|
|
551
551
|
console.error(`${LOG_PREFIX} sse.message.parse_error`, {
|
|
552
552
|
sessionId: currentSession.sessionId,
|
|
@@ -559,7 +559,7 @@ function useAgent({ endpoint }) {
|
|
|
559
559
|
if (!mountedRef.current) {
|
|
560
560
|
return;
|
|
561
561
|
}
|
|
562
|
-
|
|
562
|
+
setRelayStatus("connecting");
|
|
563
563
|
console.warn(`${LOG_PREFIX} sse.error`, {
|
|
564
564
|
sessionId: currentSession.sessionId
|
|
565
565
|
});
|
|
@@ -570,23 +570,23 @@ function useAgent({ endpoint }) {
|
|
|
570
570
|
}, 1500);
|
|
571
571
|
}
|
|
572
572
|
};
|
|
573
|
-
}, [
|
|
573
|
+
}, [cleanupRelay, handleRelayEvent, normalizedEndpoint]);
|
|
574
574
|
useEffect(() => {
|
|
575
575
|
mountedRef.current = true;
|
|
576
576
|
return () => {
|
|
577
577
|
mountedRef.current = false;
|
|
578
|
-
|
|
578
|
+
cleanupRelay();
|
|
579
579
|
};
|
|
580
|
-
}, [
|
|
580
|
+
}, [cleanupRelay]);
|
|
581
581
|
const handleStreamEvent = useCallback2(
|
|
582
582
|
(event) => {
|
|
583
583
|
if (typeof event.type !== "string") {
|
|
584
584
|
return;
|
|
585
585
|
}
|
|
586
|
-
if (event.type === "
|
|
586
|
+
if (event.type === "relay.session") {
|
|
587
587
|
const sessionId = asString(event.sessionId);
|
|
588
588
|
const token = asString(event.token);
|
|
589
|
-
const
|
|
589
|
+
const relayUrl = asString(event.relayUrl);
|
|
590
590
|
const expiresAt = asNumber(event.expiresAt) ?? Date.now() + 10 * 60 * 1e3;
|
|
591
591
|
if (!sessionId || !token) {
|
|
592
592
|
return;
|
|
@@ -595,9 +595,9 @@ function useAgent({ endpoint }) {
|
|
|
595
595
|
sessionId,
|
|
596
596
|
token,
|
|
597
597
|
expiresAt,
|
|
598
|
-
|
|
598
|
+
relayUrl
|
|
599
599
|
};
|
|
600
|
-
console.info(`${LOG_PREFIX} stream.
|
|
600
|
+
console.info(`${LOG_PREFIX} stream.relay_session`, {
|
|
601
601
|
sessionId
|
|
602
602
|
});
|
|
603
603
|
connect();
|
|
@@ -721,9 +721,9 @@ function useAgent({ endpoint }) {
|
|
|
721
721
|
if (!trimmedMessage || running) {
|
|
722
722
|
return;
|
|
723
723
|
}
|
|
724
|
-
|
|
724
|
+
cleanupRelay();
|
|
725
725
|
sessionRef.current = null;
|
|
726
|
-
|
|
726
|
+
setRelayStatus("idle");
|
|
727
727
|
setError(null);
|
|
728
728
|
setRunning(true);
|
|
729
729
|
assistantBufferRef.current = "";
|
|
@@ -785,14 +785,14 @@ function useAgent({ endpoint }) {
|
|
|
785
785
|
} catch (sendError) {
|
|
786
786
|
const messageText = sendError instanceof Error ? sendError.message : "Failed to send message.";
|
|
787
787
|
setError(messageText);
|
|
788
|
-
|
|
788
|
+
setRelayStatus("error");
|
|
789
789
|
throw sendError;
|
|
790
790
|
} finally {
|
|
791
791
|
setRunning(false);
|
|
792
792
|
}
|
|
793
793
|
},
|
|
794
794
|
[
|
|
795
|
-
|
|
795
|
+
cleanupRelay,
|
|
796
796
|
geminiSessionId,
|
|
797
797
|
handleStreamEvent,
|
|
798
798
|
normalizedEndpoint,
|
|
@@ -800,7 +800,7 @@ function useAgent({ endpoint }) {
|
|
|
800
800
|
sandboxId
|
|
801
801
|
]
|
|
802
802
|
);
|
|
803
|
-
const status = running ? "running" :
|
|
803
|
+
const status = running ? "running" : relayStatus;
|
|
804
804
|
return {
|
|
805
805
|
status,
|
|
806
806
|
messages,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@giselles-ai/sandbox-agent",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.5",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"format": "pnpm exec biome check --write ."
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@giselles-ai/browser-tool": "0.1.
|
|
34
|
+
"@giselles-ai/browser-tool": "0.1.5",
|
|
35
35
|
"zod": "4.3.6"
|
|
36
36
|
},
|
|
37
37
|
"peerDependencies": {
|