@giselles-ai/agent 0.1.0-alpha.7 → 0.1.22

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.
@@ -0,0 +1,17 @@
1
+ // src/hash.ts
2
+ import { createHash } from "crypto";
3
+ function computeConfigHash(config) {
4
+ const payload = JSON.stringify({
5
+ agentType: config.agentType ?? "gemini",
6
+ agentMd: config.agentMd ?? null,
7
+ files: (config.files ?? []).map((f) => ({
8
+ path: f.path,
9
+ content: f.content
10
+ }))
11
+ });
12
+ return createHash("sha256").update(payload).digest("hex").slice(0, 16);
13
+ }
14
+
15
+ export {
16
+ computeConfigHash
17
+ };
@@ -0,0 +1,8 @@
1
+ import { A as AgentConfig, D as DefinedAgent } from './types-Cto-uejG.js';
2
+ export { a as AgentFile } from './types-Cto-uejG.js';
3
+
4
+ declare function defineAgent(config: AgentConfig): DefinedAgent;
5
+
6
+ declare function computeConfigHash(config: AgentConfig): string;
7
+
8
+ export { AgentConfig, DefinedAgent, computeConfigHash, defineAgent };
package/dist/index.js ADDED
@@ -0,0 +1,25 @@
1
+ import {
2
+ computeConfigHash
3
+ } from "./chunk-K2DPJIHU.js";
4
+
5
+ // src/define-agent.ts
6
+ function defineAgent(config) {
7
+ return {
8
+ agentType: config.agentType ?? "gemini",
9
+ agentMd: config.agentMd,
10
+ files: config.files ?? [],
11
+ get snapshotId() {
12
+ const id = process.env?.GISELLE_AGENT_SNAPSHOT_ID;
13
+ if (!id) {
14
+ throw new Error(
15
+ `GISELLE_AGENT_SNAPSHOT_ID is not set. Ensure withGiselleAgent is configured in next.config.ts.`
16
+ );
17
+ }
18
+ return id;
19
+ }
20
+ };
21
+ }
22
+ export {
23
+ computeConfigHash,
24
+ defineAgent
25
+ };
@@ -0,0 +1,15 @@
1
+ import { NextConfig } from 'next';
2
+ import { A as AgentConfig } from '../types-Cto-uejG.js';
3
+
4
+ type GiselleAgentPluginOptions = {
5
+ /** Base URL for the agent API. Default: process.env.GISELLE_AGENT_BASE_URL ?? "https://studio.giselles.ai/agent-api" */
6
+ baseUrl?: string;
7
+ /** Bearer token. Default: process.env.GISELLE_AGENT_API_KEY */
8
+ token?: string;
9
+ /** Additional headers to include in the build API request */
10
+ headers?: Record<string, string | undefined>;
11
+ };
12
+
13
+ declare function withGiselleAgent(nextConfig: NextConfig, agent: AgentConfig, options?: GiselleAgentPluginOptions): () => Promise<NextConfig>;
14
+
15
+ export { type GiselleAgentPluginOptions, withGiselleAgent };
@@ -0,0 +1,82 @@
1
+ import {
2
+ computeConfigHash
3
+ } from "../chunk-K2DPJIHU.js";
4
+
5
+ // src/next/with-giselle-agent.ts
6
+ function trimTrailingSlash(url) {
7
+ return url.replace(/\/+$/, "");
8
+ }
9
+ function withGiselleAgent(nextConfig, agent, options) {
10
+ return async () => {
11
+ const baseUrl = trimTrailingSlash(
12
+ options?.baseUrl ?? process.env.GISELLE_AGENT_BASE_URL ?? "https://studio.giselles.ai/agent-api"
13
+ );
14
+ const apiUrl = `${baseUrl}/build`;
15
+ const token = options?.token ?? process.env.GISELLE_AGENT_API_KEY;
16
+ if (!token) {
17
+ console.warn("[withGiselleAgent] Skipped snapshot build: missing token.");
18
+ return nextConfig;
19
+ }
20
+ const configHash = computeConfigHash(agent);
21
+ const files = [
22
+ ...agent.files ?? []
23
+ ];
24
+ if (agent.agentMd !== void 0) {
25
+ files.push(
26
+ {
27
+ path: "/home/vercel-sandbox/.codex/AGENTS.md",
28
+ content: agent.agentMd
29
+ },
30
+ {
31
+ path: "/home/vercel-sandbox/.gemini/GEMINI.md",
32
+ content: agent.agentMd
33
+ }
34
+ );
35
+ }
36
+ const requestBody = {
37
+ config_hash: configHash,
38
+ agent_type: agent.agentType ?? "gemini",
39
+ files
40
+ };
41
+ const requestHeaders = {
42
+ "content-type": "application/json",
43
+ authorization: `Bearer ${token}`,
44
+ ...options?.headers
45
+ };
46
+ console.debug("[withGiselleAgent] POST %s", apiUrl);
47
+ console.debug(
48
+ "[withGiselleAgent] headers:",
49
+ JSON.stringify(requestHeaders, null, 2)
50
+ );
51
+ console.debug(
52
+ "[withGiselleAgent] body:",
53
+ JSON.stringify(requestBody, null, 2)
54
+ );
55
+ const response = await fetch(apiUrl, {
56
+ method: "POST",
57
+ headers: requestHeaders,
58
+ body: JSON.stringify(requestBody)
59
+ });
60
+ if (!response.ok) {
61
+ const body = await response.text().catch(() => "");
62
+ throw new Error(
63
+ `[withGiselleAgent] Build failed (${response.status}): ${body}`
64
+ );
65
+ }
66
+ const result = await response.json();
67
+ console.debug(
68
+ "[withGiselleAgent] result:",
69
+ JSON.stringify(result, null, 2)
70
+ );
71
+ return {
72
+ ...nextConfig,
73
+ env: {
74
+ ...nextConfig.env,
75
+ GISELLE_AGENT_SNAPSHOT_ID: result.snapshot_id
76
+ }
77
+ };
78
+ };
79
+ }
80
+ export {
81
+ withGiselleAgent
82
+ };
@@ -0,0 +1,254 @@
1
+ import { Sandbox } from '@vercel/sandbox';
2
+ import { z } from 'zod';
3
+ import { RelayRequest, RelayResponse } from '@giselles-ai/browser-tool';
4
+ import { RelayRequestSubscription } from '@giselles-ai/browser-tool/relay';
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
+ type BaseChatRequest = {
31
+ message: string;
32
+ session_id?: string;
33
+ sandbox_id?: string;
34
+ snapshot_id?: string;
35
+ };
36
+ type ChatCommand = {
37
+ cmd: string;
38
+ args: string[];
39
+ env?: Record<string, string>;
40
+ };
41
+ type StdoutMapper = {
42
+ push(chunk: string): string[];
43
+ flush(): string[];
44
+ };
45
+ type ChatAgent<TRequest extends BaseChatRequest> = {
46
+ requestSchema: z.ZodType<TRequest>;
47
+ snapshotId?: string;
48
+ prepareSandbox(input: {
49
+ input: TRequest;
50
+ sandbox: Sandbox;
51
+ }): Promise<void>;
52
+ createCommand(input: {
53
+ input: TRequest;
54
+ }): ChatCommand;
55
+ createStdoutMapper?: () => StdoutMapper;
56
+ };
57
+ type RunChatInput<TRequest extends BaseChatRequest> = {
58
+ agent: ChatAgent<TRequest>;
59
+ signal: AbortSignal;
60
+ input: TRequest;
61
+ };
62
+ declare function runChat<TRequest extends BaseChatRequest>(input: RunChatInput<TRequest>): Promise<Response>;
63
+
64
+ declare const codexRequestSchema: z.ZodObject<{
65
+ message: z.ZodString;
66
+ session_id: z.ZodOptional<z.ZodString>;
67
+ sandbox_id: z.ZodOptional<z.ZodString>;
68
+ snapshot_id: z.ZodOptional<z.ZodString>;
69
+ relay_session_id: z.ZodOptional<z.ZodString>;
70
+ relay_token: z.ZodOptional<z.ZodString>;
71
+ }, z.core.$strip>;
72
+ type CodexAgentRequest = z.infer<typeof codexRequestSchema>;
73
+ type CodexAgentOptions = {
74
+ snapshotId?: string;
75
+ env?: Record<string, string | undefined>;
76
+ tools?: {
77
+ browser?: {
78
+ relayUrl?: string;
79
+ relayClient?: {
80
+ headers?: Record<string, string | undefined>;
81
+ };
82
+ };
83
+ };
84
+ };
85
+ declare function createCodexAgent(options?: CodexAgentOptions): ChatAgent<CodexAgentRequest>;
86
+
87
+ declare const geminiRequestSchema: z.ZodObject<{
88
+ message: z.ZodString;
89
+ session_id: z.ZodOptional<z.ZodString>;
90
+ sandbox_id: z.ZodOptional<z.ZodString>;
91
+ snapshot_id: z.ZodOptional<z.ZodString>;
92
+ relay_session_id: z.ZodOptional<z.ZodString>;
93
+ relay_token: z.ZodOptional<z.ZodString>;
94
+ }, z.core.$strip>;
95
+ type GeminiAgentRequest = z.infer<typeof geminiRequestSchema>;
96
+ type GeminiAgentOptions = {
97
+ snapshotId?: string;
98
+ env?: Record<string, string | undefined>;
99
+ tools?: {
100
+ browser?: {
101
+ relayUrl?: string;
102
+ relayClient?: {
103
+ headers?: Record<string, string | undefined>;
104
+ };
105
+ };
106
+ };
107
+ };
108
+ declare function createGeminiAgent(options?: GeminiAgentOptions): ChatAgent<GeminiAgentRequest>;
109
+
110
+ type AgentType = "gemini" | "codex";
111
+ type AgentRequest = BaseChatRequest & {
112
+ relay_session_id?: string;
113
+ relay_token?: string;
114
+ };
115
+ type CreateAgentOptions = (GeminiAgentOptions & CodexAgentOptions) & {
116
+ type: AgentType;
117
+ };
118
+ type AgentParam<TRequest extends BaseChatRequest> = ChatAgent<TRequest> | CreateAgentOptions;
119
+ declare function createAgent(options: CreateAgentOptions): ChatAgent<AgentRequest>;
120
+
121
+ type CloudToolName = "getFormSnapshot" | "executeFormActions";
122
+ type CloudToolResult = {
123
+ toolCallId: string;
124
+ toolName: CloudToolName;
125
+ output: unknown;
126
+ };
127
+ type CloudChatRequest = BaseChatRequest & {
128
+ chat_id: string;
129
+ tool_results?: CloudToolResult[];
130
+ };
131
+ type CloudRelaySession = {
132
+ sessionId: string;
133
+ token: string;
134
+ url: string;
135
+ expiresAt: number;
136
+ };
137
+ type PendingToolState = {
138
+ requestId: string;
139
+ requestType: RelayRequest["type"];
140
+ toolName: CloudToolName;
141
+ };
142
+ type CloudChatSessionState = {
143
+ chatId: string;
144
+ agentSessionId?: string;
145
+ sandboxId?: string;
146
+ relay?: CloudRelaySession;
147
+ pendingTool?: PendingToolState | null;
148
+ updatedAt: number;
149
+ };
150
+ type CloudChatSessionPatch = {
151
+ agentSessionId?: string;
152
+ sandboxId?: string;
153
+ relay?: CloudRelaySession;
154
+ pendingTool?: PendingToolState | null;
155
+ };
156
+ interface CloudChatStateStore {
157
+ load(chatId: string): Promise<CloudChatSessionState | null>;
158
+ save(state: CloudChatSessionState): Promise<void>;
159
+ delete(chatId: string): Promise<void>;
160
+ }
161
+ declare function toolNameFromRelayRequest(request: RelayRequest): CloudToolName;
162
+ declare function reduceCloudChatEvent(event: Record<string, unknown>): CloudChatSessionPatch | null;
163
+ declare const cloudChatRunRequestSchema: z.ZodObject<{
164
+ type: z.ZodLiteral<"agent.run">;
165
+ chat_id: z.ZodString;
166
+ message: z.ZodString;
167
+ agent_type: z.ZodEnum<{
168
+ codex: "codex";
169
+ gemini: "gemini";
170
+ }>;
171
+ snapshot_id: z.ZodString;
172
+ tool_results: z.ZodOptional<z.ZodArray<z.ZodObject<{
173
+ toolCallId: z.ZodString;
174
+ toolName: z.ZodEnum<{
175
+ getFormSnapshot: "getFormSnapshot";
176
+ executeFormActions: "executeFormActions";
177
+ }>;
178
+ output: z.ZodUnknown;
179
+ }, z.core.$strip>>>;
180
+ }, z.core.$strip>;
181
+ type CloudChatRunRequest = z.infer<typeof cloudChatRunRequestSchema>;
182
+ declare function applyCloudChatPatch(input: {
183
+ chatId: string;
184
+ now: number;
185
+ base?: CloudChatSessionState | null;
186
+ patch?: CloudChatSessionPatch | null;
187
+ }): CloudChatSessionState;
188
+
189
+ type AgentApiStoreConfig = {
190
+ adapter: "redis";
191
+ url?: string;
192
+ };
193
+
194
+ type BeforeHook = (request: Request) => Response | undefined | Promise<Response | undefined>;
195
+ type AgentApiOptions = {
196
+ basePath: string;
197
+ store: AgentApiStoreConfig;
198
+ agent: Omit<CreateAgentOptions, "type" | "snapshotId">;
199
+ build?: {
200
+ baseSnapshotId?: string;
201
+ };
202
+ hooks?: {
203
+ chat?: {
204
+ before?: BeforeHook;
205
+ };
206
+ build?: {
207
+ before?: BeforeHook;
208
+ };
209
+ };
210
+ };
211
+
212
+ declare function createAgentApi(options: AgentApiOptions): {
213
+ GET: (request: Request) => Promise<Response>;
214
+ POST: (request: Request) => Promise<Response>;
215
+ OPTIONS: (request: Request) => Response;
216
+ };
217
+
218
+ type CodexStdoutMapper = {
219
+ push(chunk: string): string[];
220
+ flush(): string[];
221
+ };
222
+ declare function createCodexStdoutMapper(): CodexStdoutMapper;
223
+
224
+ type RelaySessionFactoryResult = {
225
+ sessionId: string;
226
+ token: string;
227
+ expiresAt: number;
228
+ };
229
+ type RunChatImpl<TRequest extends BaseChatRequest> = (input: RunChatInput<TRequest>) => Promise<Response>;
230
+ declare function runCloudChat<TRequest extends CloudChatRequest & {
231
+ relay_session_id?: string;
232
+ relay_token?: string;
233
+ }>(input: {
234
+ chatId: string;
235
+ request: Omit<TRequest, "session_id" | "sandbox_id" | "relay_session_id" | "relay_token">;
236
+ agent: AgentParam<TRequest>;
237
+ signal: AbortSignal;
238
+ relayUrl: string;
239
+ store: CloudChatStateStore;
240
+ createRelaySession: () => Promise<RelaySessionFactoryResult>;
241
+ runChatImpl?: RunChatImpl<TRequest>;
242
+ now?: () => number;
243
+ createRelayRequestSubscription?: (input: {
244
+ sessionId: string;
245
+ token: string;
246
+ }) => Promise<RelayRequestSubscription>;
247
+ sendRelayResponse?: (input: {
248
+ sessionId: string;
249
+ token: string;
250
+ response: RelayResponse;
251
+ }) => Promise<void>;
252
+ }): Promise<Response>;
253
+
254
+ export { Agent, 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 };