@giselles-ai/agent 0.1.23 → 0.1.24
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/server/index.d.ts +3 -25
- package/dist/server/index.js +40 -98
- package/package.json +2 -2
package/dist/server/index.d.ts
CHANGED
|
@@ -3,30 +3,6 @@ import { z } from 'zod';
|
|
|
3
3
|
import { RelayRequest, RelayResponse } from '@giselles-ai/browser-tool';
|
|
4
4
|
import { RelayRequestSubscription } from '@giselles-ai/browser-tool/relay';
|
|
5
5
|
|
|
6
|
-
type AgentType$1 = "codex" | "gemini";
|
|
7
|
-
declare class Agent {
|
|
8
|
-
private _type;
|
|
9
|
-
private _snapshotId;
|
|
10
|
-
private _pendingOps;
|
|
11
|
-
private constructor();
|
|
12
|
-
static create(type: AgentType$1, options: {
|
|
13
|
-
snapshotId: string;
|
|
14
|
-
}): Agent;
|
|
15
|
-
get type(): AgentType$1;
|
|
16
|
-
get snapshotId(): string;
|
|
17
|
-
get dirty(): boolean;
|
|
18
|
-
addFiles(files: Array<{
|
|
19
|
-
path: string;
|
|
20
|
-
content: Buffer;
|
|
21
|
-
}>): this;
|
|
22
|
-
setAgentMd(content: string | Buffer): this;
|
|
23
|
-
runCommands(commands: Array<{
|
|
24
|
-
cmd: string;
|
|
25
|
-
args?: string[];
|
|
26
|
-
}>): this;
|
|
27
|
-
prepare(): Promise<void>;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
6
|
type BaseChatRequest = {
|
|
31
7
|
message: string;
|
|
32
8
|
session_id?: string;
|
|
@@ -143,6 +119,7 @@ type CloudChatSessionState = {
|
|
|
143
119
|
chatId: string;
|
|
144
120
|
agentSessionId?: string;
|
|
145
121
|
sandboxId?: string;
|
|
122
|
+
snapshotId?: string;
|
|
146
123
|
relay?: CloudRelaySession;
|
|
147
124
|
pendingTool?: PendingToolState | null;
|
|
148
125
|
updatedAt: number;
|
|
@@ -150,6 +127,7 @@ type CloudChatSessionState = {
|
|
|
150
127
|
type CloudChatSessionPatch = {
|
|
151
128
|
agentSessionId?: string;
|
|
152
129
|
sandboxId?: string;
|
|
130
|
+
snapshotId?: string;
|
|
153
131
|
relay?: CloudRelaySession;
|
|
154
132
|
pendingTool?: PendingToolState | null;
|
|
155
133
|
};
|
|
@@ -251,4 +229,4 @@ declare function runCloudChat<TRequest extends CloudChatRequest & {
|
|
|
251
229
|
}) => Promise<void>;
|
|
252
230
|
}): Promise<Response>;
|
|
253
231
|
|
|
254
|
-
export {
|
|
232
|
+
export { type AgentApiOptions, type AgentApiStoreConfig, type AgentParam, type AgentRequest, type AgentType, type BaseChatRequest, type ChatAgent, type ChatCommand, type CloudChatRequest, type CloudChatRunRequest, type CloudChatSessionPatch, type CloudChatSessionState, type CloudChatStateStore, type CloudRelaySession, type CloudToolName, type CloudToolResult, type CreateAgentOptions, type PendingToolState, type RelaySessionFactoryResult, type RunChatImpl, type RunChatInput, type StdoutMapper, applyCloudChatPatch, cloudChatRunRequestSchema, createAgent, createAgentApi, createCodexAgent, createCodexStdoutMapper, createGeminiAgent, reduceCloudChatEvent, runChat, runCloudChat, toolNameFromRelayRequest };
|
package/dist/server/index.js
CHANGED
|
@@ -1,87 +1,3 @@
|
|
|
1
|
-
// src/agent.ts
|
|
2
|
-
import { Sandbox } from "@vercel/sandbox";
|
|
3
|
-
var Agent = class _Agent {
|
|
4
|
-
_type;
|
|
5
|
-
_snapshotId;
|
|
6
|
-
_pendingOps = [];
|
|
7
|
-
constructor(type, snapshotId) {
|
|
8
|
-
this._type = type;
|
|
9
|
-
this._snapshotId = snapshotId;
|
|
10
|
-
}
|
|
11
|
-
static create(type, options) {
|
|
12
|
-
const trimmed = options.snapshotId.trim();
|
|
13
|
-
if (!trimmed) {
|
|
14
|
-
throw new Error("snapshotId is required.");
|
|
15
|
-
}
|
|
16
|
-
return new _Agent(type, trimmed);
|
|
17
|
-
}
|
|
18
|
-
get type() {
|
|
19
|
-
return this._type;
|
|
20
|
-
}
|
|
21
|
-
get snapshotId() {
|
|
22
|
-
return this._snapshotId;
|
|
23
|
-
}
|
|
24
|
-
get dirty() {
|
|
25
|
-
return this._pendingOps.length > 0;
|
|
26
|
-
}
|
|
27
|
-
addFiles(files) {
|
|
28
|
-
if (files.length === 0) {
|
|
29
|
-
return this;
|
|
30
|
-
}
|
|
31
|
-
this._pendingOps.push({
|
|
32
|
-
kind: "writeFiles",
|
|
33
|
-
files
|
|
34
|
-
});
|
|
35
|
-
return this;
|
|
36
|
-
}
|
|
37
|
-
setAgentMd(content) {
|
|
38
|
-
const buffer = typeof content === "string" ? Buffer.from(content) : content;
|
|
39
|
-
console.log(`[agent] setAgentMd called, content length=${buffer.length}`);
|
|
40
|
-
return this.addFiles([
|
|
41
|
-
{ path: "/home/vercel-sandbox/.codex/AGENTS.md", content: buffer }
|
|
42
|
-
]);
|
|
43
|
-
}
|
|
44
|
-
runCommands(commands) {
|
|
45
|
-
for (const command of commands) {
|
|
46
|
-
this._pendingOps.push({
|
|
47
|
-
kind: "runCommand",
|
|
48
|
-
cmd: command.cmd,
|
|
49
|
-
args: command.args ?? []
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
return this;
|
|
53
|
-
}
|
|
54
|
-
async prepare() {
|
|
55
|
-
console.log(
|
|
56
|
-
`[agent] prepare called, dirty=${this.dirty}, pendingOps=${this._pendingOps.length}`
|
|
57
|
-
);
|
|
58
|
-
if (!this.dirty) {
|
|
59
|
-
return;
|
|
60
|
-
}
|
|
61
|
-
const ops = this._pendingOps;
|
|
62
|
-
const sandbox = await Sandbox.create({
|
|
63
|
-
source: { type: "snapshot", snapshotId: this._snapshotId }
|
|
64
|
-
});
|
|
65
|
-
console.log(
|
|
66
|
-
`[sandbox] created sandbox=${sandbox.sandboxId} from snapshot=${this._snapshotId}`
|
|
67
|
-
);
|
|
68
|
-
for (const op of ops) {
|
|
69
|
-
switch (op.kind) {
|
|
70
|
-
case "writeFiles":
|
|
71
|
-
await sandbox.writeFiles(op.files);
|
|
72
|
-
break;
|
|
73
|
-
case "runCommand":
|
|
74
|
-
await sandbox.runCommand(op.cmd, op.args);
|
|
75
|
-
break;
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
const snapshot = await sandbox.snapshot();
|
|
79
|
-
console.log(`[agent] prepare done, new snapshotId=${snapshot.snapshotId}`);
|
|
80
|
-
this._snapshotId = snapshot.snapshotId;
|
|
81
|
-
this._pendingOps = [];
|
|
82
|
-
}
|
|
83
|
-
};
|
|
84
|
-
|
|
85
1
|
// src/agent-api.ts
|
|
86
2
|
import {
|
|
87
3
|
createRelayHandler,
|
|
@@ -89,7 +5,7 @@ import {
|
|
|
89
5
|
} from "@giselles-ai/browser-tool/relay";
|
|
90
6
|
|
|
91
7
|
// src/build.ts
|
|
92
|
-
import { Sandbox
|
|
8
|
+
import { Sandbox } from "@vercel/sandbox";
|
|
93
9
|
var CACHE_KEY_PREFIX = "agent-build:snapshot:";
|
|
94
10
|
var CACHE_TTL_SEC = 60 * 60 * 24;
|
|
95
11
|
var memoryCache = /* @__PURE__ */ new Map();
|
|
@@ -193,7 +109,7 @@ async function buildAgent(input) {
|
|
|
193
109
|
const response2 = { snapshot_id: cached, cached: true };
|
|
194
110
|
return Response.json(response2);
|
|
195
111
|
}
|
|
196
|
-
const sandbox = await
|
|
112
|
+
const sandbox = await Sandbox.create({
|
|
197
113
|
source: { type: "snapshot", snapshotId: baseSnapshotId }
|
|
198
114
|
});
|
|
199
115
|
console.log(
|
|
@@ -633,7 +549,7 @@ function createAgent(options) {
|
|
|
633
549
|
|
|
634
550
|
// src/chat-run.ts
|
|
635
551
|
import { Writable } from "stream";
|
|
636
|
-
import { Sandbox as
|
|
552
|
+
import { Sandbox as Sandbox2 } from "@vercel/sandbox";
|
|
637
553
|
function emitText(controller, text, encoder) {
|
|
638
554
|
if (text.length === 0) {
|
|
639
555
|
return;
|
|
@@ -687,23 +603,39 @@ function runChat(input) {
|
|
|
687
603
|
const mapper = input.agent.createStdoutMapper?.();
|
|
688
604
|
void (async () => {
|
|
689
605
|
try {
|
|
690
|
-
const
|
|
691
|
-
const
|
|
692
|
-
if (!snapshotId) {
|
|
693
|
-
throw new Error(
|
|
694
|
-
"Agent must provide snapshotId when sandbox_id is not provided."
|
|
695
|
-
);
|
|
696
|
-
}
|
|
697
|
-
const created = await Sandbox3.create({
|
|
606
|
+
const createFromSnapshot = async (snapshotId2) => {
|
|
607
|
+
const created = await Sandbox2.create({
|
|
698
608
|
source: {
|
|
699
609
|
type: "snapshot",
|
|
700
|
-
snapshotId
|
|
610
|
+
snapshotId: snapshotId2
|
|
701
611
|
}
|
|
702
612
|
});
|
|
703
613
|
console.log(
|
|
704
|
-
`[sandbox] created sandbox=${created.sandboxId} from snapshot=${
|
|
614
|
+
`[sandbox] created sandbox=${created.sandboxId} from snapshot=${snapshotId2}`
|
|
705
615
|
);
|
|
706
616
|
return created;
|
|
617
|
+
};
|
|
618
|
+
const snapshotId = parsed.snapshot_id?.trim() || input.agent.snapshotId?.trim();
|
|
619
|
+
const sandbox = await (async () => {
|
|
620
|
+
if (parsed.sandbox_id) {
|
|
621
|
+
try {
|
|
622
|
+
return await Sandbox2.get({ sandboxId: parsed.sandbox_id });
|
|
623
|
+
} catch (error) {
|
|
624
|
+
if (!snapshotId) {
|
|
625
|
+
throw error;
|
|
626
|
+
}
|
|
627
|
+
console.log(
|
|
628
|
+
`[sandbox] sandbox=${parsed.sandbox_id} expired, recreating from snapshot=${snapshotId}`
|
|
629
|
+
);
|
|
630
|
+
return createFromSnapshot(snapshotId);
|
|
631
|
+
}
|
|
632
|
+
}
|
|
633
|
+
if (!snapshotId) {
|
|
634
|
+
throw new Error(
|
|
635
|
+
"Agent must provide snapshotId when sandbox_id is not provided."
|
|
636
|
+
);
|
|
637
|
+
}
|
|
638
|
+
return createFromSnapshot(snapshotId);
|
|
707
639
|
})();
|
|
708
640
|
enqueueEvent({ type: "sandbox", sandbox_id: sandbox.sandboxId });
|
|
709
641
|
await input.agent.prepareSandbox({
|
|
@@ -740,6 +672,11 @@ function runChat(input) {
|
|
|
740
672
|
}),
|
|
741
673
|
signal: abortController.signal
|
|
742
674
|
});
|
|
675
|
+
const snapshot = await sandbox.snapshot();
|
|
676
|
+
enqueueEvent({
|
|
677
|
+
type: "snapshot",
|
|
678
|
+
snapshot_id: snapshot.snapshotId
|
|
679
|
+
});
|
|
743
680
|
} catch (error) {
|
|
744
681
|
if (abortController.signal.aborted) {
|
|
745
682
|
return;
|
|
@@ -855,6 +792,9 @@ function reduceCloudChatEvent(event) {
|
|
|
855
792
|
if (event.type === "sandbox" && typeof event.sandbox_id === "string") {
|
|
856
793
|
return { sandboxId: event.sandbox_id };
|
|
857
794
|
}
|
|
795
|
+
if (event.type === "snapshot" && typeof event.snapshot_id === "string") {
|
|
796
|
+
return { snapshotId: event.snapshot_id };
|
|
797
|
+
}
|
|
858
798
|
if (event.type === "relay.session" && typeof event.sessionId === "string" && typeof event.token === "string" && typeof event.relayUrl === "string" && typeof event.expiresAt === "number") {
|
|
859
799
|
return {
|
|
860
800
|
relay: {
|
|
@@ -895,6 +835,7 @@ function applyCloudChatPatch(input) {
|
|
|
895
835
|
chatId: input.chatId,
|
|
896
836
|
agentSessionId: input.patch?.agentSessionId ?? input.base?.agentSessionId,
|
|
897
837
|
sandboxId: input.patch?.sandboxId ?? input.base?.sandboxId,
|
|
838
|
+
snapshotId: input.patch?.snapshotId ?? input.base?.snapshotId,
|
|
898
839
|
relay: input.patch?.relay ?? input.base?.relay,
|
|
899
840
|
pendingTool: input.patch?.pendingTool !== void 0 ? input.patch.pendingTool : input.base?.pendingTool,
|
|
900
841
|
updatedAt: input.now
|
|
@@ -1016,6 +957,7 @@ async function runCloudChat(input) {
|
|
|
1016
957
|
...input.request,
|
|
1017
958
|
...existing?.agentSessionId ? { session_id: existing.agentSessionId } : {},
|
|
1018
959
|
...existing?.sandboxId ? { sandbox_id: existing.sandboxId } : {},
|
|
960
|
+
...existing?.snapshotId ? { snapshot_id: existing.snapshotId } : {},
|
|
1019
961
|
relay_session_id: relaySession.sessionId,
|
|
1020
962
|
relay_token: relaySession.token
|
|
1021
963
|
};
|
|
@@ -1116,6 +1058,7 @@ async function resumeCloudChat(input) {
|
|
|
1116
1058
|
...input.request,
|
|
1117
1059
|
...input.existing.agentSessionId ? { session_id: input.existing.agentSessionId } : {},
|
|
1118
1060
|
...input.existing.sandboxId ? { sandbox_id: input.existing.sandboxId } : {},
|
|
1061
|
+
...input.existing.snapshotId ? { snapshot_id: input.existing.snapshotId } : {},
|
|
1119
1062
|
relay_session_id: relaySession.sessionId,
|
|
1120
1063
|
relay_token: relaySession.token
|
|
1121
1064
|
};
|
|
@@ -1584,7 +1527,6 @@ function createAgentApi(options) {
|
|
|
1584
1527
|
};
|
|
1585
1528
|
}
|
|
1586
1529
|
export {
|
|
1587
|
-
Agent,
|
|
1588
1530
|
applyCloudChatPatch,
|
|
1589
1531
|
cloudChatRunRequestSchema,
|
|
1590
1532
|
createAgent,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@giselles-ai/agent",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.24",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
"format": "pnpm exec biome check --write ."
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@giselles-ai/browser-tool": "0.1.
|
|
40
|
+
"@giselles-ai/browser-tool": "0.1.24",
|
|
41
41
|
"@vercel/sandbox": "1.6.0",
|
|
42
42
|
"@iarna/toml": "3.0.0",
|
|
43
43
|
"zod": "4.3.6"
|