@giselles-ai/agent 0.1.24 → 0.1.25

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.
@@ -7,7 +7,13 @@ function computeConfigHash(config) {
7
7
  files: (config.files ?? []).map((f) => ({
8
8
  path: f.path,
9
9
  content: f.content
10
- }))
10
+ })),
11
+ setup: config.setup?.script ?? null,
12
+ env: config.env ? Object.fromEntries(
13
+ Object.entries(config.env).sort(
14
+ ([a], [b]) => a < b ? -1 : a > b ? 1 : 0
15
+ )
16
+ ) : null
11
17
  });
12
18
  return createHash("sha256").update(payload).digest("hex").slice(0, 16);
13
19
  }
@@ -50,7 +56,9 @@ async function requestBuild(agent, options) {
50
56
  const requestBody = {
51
57
  config_hash: configHash,
52
58
  agent_type: agent.agentType ?? "gemini",
53
- files
59
+ files,
60
+ setup_script: agent.setup?.script ?? null,
61
+ env: agent.env ?? null
54
62
  };
55
63
  const requestHeaders = {
56
64
  "content-type": "application/json",
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { A as AgentConfig, D as DefinedAgent } from './types-Cto-uejG.js';
2
- export { a as AgentFile } from './types-Cto-uejG.js';
1
+ import { A as AgentConfig, D as DefinedAgent } from './types-cRejduhB.js';
2
+ export { a as AgentFile, b as AgentSetup } from './types-cRejduhB.js';
3
3
 
4
4
  declare function defineAgent(config: AgentConfig): DefinedAgent;
5
5
 
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  computeConfigHash,
3
3
  requestBuild
4
- } from "./chunk-TAQV6ZOB.js";
4
+ } from "./chunk-JGH5DCA7.js";
5
5
 
6
6
  // src/define-agent.ts
7
7
  function defineAgent(config) {
@@ -9,6 +9,8 @@ function defineAgent(config) {
9
9
  agentType: config.agentType ?? "gemini",
10
10
  agentMd: config.agentMd,
11
11
  files: config.files ?? [],
12
+ env: config.env ?? {},
13
+ setup: config.setup,
12
14
  get snapshotId() {
13
15
  const id = process.env?.GISELLE_AGENT_SNAPSHOT_ID;
14
16
  if (!id) {
@@ -1,5 +1,5 @@
1
1
  import { NextConfig } from 'next';
2
- import { A as AgentConfig } from '../types-Cto-uejG.js';
2
+ import { A as AgentConfig } from '../types-cRejduhB.js';
3
3
 
4
4
  type GiselleAgentPluginOptions = {
5
5
  /** Base URL for the agent API. Default: process.env.GISELLE_AGENT_BASE_URL ?? "https://studio.giselles.ai/agent-api" */
@@ -1,9 +1,9 @@
1
1
  import {
2
+ computeConfigHash,
2
3
  requestBuild
3
- } from "../chunk-TAQV6ZOB.js";
4
+ } from "../chunk-JGH5DCA7.js";
4
5
 
5
6
  // src/next/with-giselle-agent.ts
6
- import crypto from "crypto";
7
7
  import fs from "fs";
8
8
  import { createRequire } from "module";
9
9
  import path from "path";
@@ -18,12 +18,7 @@ function resolveBaseUrl(options) {
18
18
  return (options?.baseUrl ?? process.env.GISELLE_AGENT_BASE_URL ?? "https://studio.giselles.ai/agent-api").replace(/\/+$/, "");
19
19
  }
20
20
  function getSnapshotFile(agent) {
21
- const key = {
22
- agentType: agent.agentType,
23
- agentMd: agent.agentMd,
24
- files: agent.files
25
- };
26
- const hash = crypto.createHash("sha256").update(JSON.stringify(key)).digest("hex").slice(0, 16);
21
+ const hash = computeConfigHash(agent);
27
22
  return path.join(process.cwd(), ".next", "giselle", hash);
28
23
  }
29
24
  function hasRunRecently() {
@@ -147,6 +147,7 @@ declare const cloudChatRunRequestSchema: z.ZodObject<{
147
147
  gemini: "gemini";
148
148
  }>;
149
149
  snapshot_id: z.ZodString;
150
+ env: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
150
151
  tool_results: z.ZodOptional<z.ZodArray<z.ZodObject<{
151
152
  toolCallId: z.ZodString;
152
153
  toolName: z.ZodEnum<{
@@ -51,6 +51,8 @@ function parseBuildRequest(body) {
51
51
  const configHash = record.config_hash;
52
52
  const agentType = record.agent_type;
53
53
  const files = record.files;
54
+ const setupScript = record.setup_script;
55
+ const rawEnv = record.env;
54
56
  if (typeof configHash !== "string" || !configHash.trim()) {
55
57
  return null;
56
58
  }
@@ -61,6 +63,8 @@ function parseBuildRequest(body) {
61
63
  return null;
62
64
  }
63
65
  const parsedFiles = [];
66
+ let parsedSetupScript = null;
67
+ let parsedEnv = null;
64
68
  for (const file of files) {
65
69
  if (!file || typeof file !== "object" || Array.isArray(file)) {
66
70
  return null;
@@ -74,10 +78,30 @@ function parseBuildRequest(body) {
74
78
  content: recordFile.content
75
79
  });
76
80
  }
81
+ if (setupScript !== void 0 && setupScript !== null) {
82
+ if (typeof setupScript !== "string") {
83
+ return null;
84
+ }
85
+ parsedSetupScript = setupScript;
86
+ }
87
+ if (rawEnv !== void 0 && rawEnv !== null) {
88
+ if (typeof rawEnv !== "object" || Array.isArray(rawEnv)) {
89
+ return null;
90
+ }
91
+ const envRecord = rawEnv;
92
+ for (const value of Object.values(envRecord)) {
93
+ if (typeof value !== "string") {
94
+ return null;
95
+ }
96
+ }
97
+ parsedEnv = envRecord;
98
+ }
77
99
  return {
78
100
  config_hash: configHash.trim(),
79
101
  agent_type: agentType,
80
- files: parsedFiles
102
+ files: parsedFiles,
103
+ setup_script: parsedSetupScript,
104
+ env: parsedEnv
81
105
  };
82
106
  }
83
107
  async function buildAgent(input) {
@@ -123,6 +147,21 @@ async function buildAgent(input) {
123
147
  }))
124
148
  );
125
149
  }
150
+ if (parsed.setup_script) {
151
+ console.log("[agent-build] running setup script...");
152
+ const result = await sandbox.runCommand({
153
+ cmd: "bash",
154
+ args: ["-lc", parsed.setup_script],
155
+ ...parsed.env ? { env: parsed.env } : {}
156
+ });
157
+ if (result.exitCode !== 0) {
158
+ const stderr = typeof result.stderr === "string" ? result.stderr : "";
159
+ throw new Error(
160
+ `Setup script failed (exit ${result.exitCode}): ${stderr}`
161
+ );
162
+ }
163
+ console.log("[agent-build] setup script completed");
164
+ }
126
165
  const snapshot = await sandbox.snapshot();
127
166
  console.log(`[agent-build] snapshot created: ${snapshot.snapshotId}`);
128
167
  await cache.set(cacheKey, snapshot.snapshotId);
@@ -359,7 +398,12 @@ function createCodexAgent(options = {}) {
359
398
  return {
360
399
  cmd: "codex",
361
400
  args,
362
- env: { CODEX_API_KEY: apiKey }
401
+ env: Object.fromEntries(
402
+ Object.entries({
403
+ ...env,
404
+ CODEX_API_KEY: apiKey
405
+ }).filter((e) => e[1] != null)
406
+ )
363
407
  };
364
408
  },
365
409
  createStdoutMapper() {
@@ -501,9 +545,12 @@ function createGeminiAgent(options = {}) {
501
545
  return {
502
546
  cmd: "gemini",
503
547
  args,
504
- env: {
505
- GEMINI_API_KEY: requiredEnv2(env, "GEMINI_API_KEY")
506
- }
548
+ env: Object.fromEntries(
549
+ Object.entries({
550
+ ...env,
551
+ GEMINI_API_KEY: requiredEnv2(env, "GEMINI_API_KEY")
552
+ }).filter((e) => e[1] != null)
553
+ )
507
554
  };
508
555
  }
509
556
  };
@@ -822,6 +869,7 @@ var cloudChatRunRequestSchema = z3.object({
822
869
  message: z3.string().min(1),
823
870
  agent_type: z3.enum(["gemini", "codex"]),
824
871
  snapshot_id: z3.string().min(1),
872
+ env: z3.record(z3.string(), z3.string()).optional(),
825
873
  tool_results: z3.array(
826
874
  z3.object({
827
875
  toolCallId: z3.string().min(1),
@@ -1446,12 +1494,17 @@ function createAgentApi(options) {
1446
1494
  chat_id: parsed.data.chat_id,
1447
1495
  agent_type: parsed.data.agent_type,
1448
1496
  snapshot_id: parsed.data.snapshot_id,
1497
+ env: parsed.data.env,
1449
1498
  tool_results: parsed.data.tool_results
1450
1499
  },
1451
1500
  agent: {
1452
1501
  ...agentOptions,
1453
1502
  type: parsed.data.agent_type,
1454
- snapshotId: parsed.data.snapshot_id
1503
+ snapshotId: parsed.data.snapshot_id,
1504
+ env: {
1505
+ ...parsed.data.env,
1506
+ ...agentOptions.env
1507
+ }
1455
1508
  },
1456
1509
  signal: request.signal,
1457
1510
  store: await getStore(),
@@ -2,20 +2,32 @@ type AgentFile = {
2
2
  path: string;
3
3
  content: string;
4
4
  };
5
+ type AgentSetup = {
6
+ /** Shell script to run inside the sandbox during build. Executed as `bash -lc`. */
7
+ script: string;
8
+ };
5
9
  type AgentConfig = {
6
10
  /** Agent type. Defaults to "gemini". */
7
11
  agentType?: "gemini" | "codex";
8
12
  /** Content for AGENTS.md in the sandbox. */
9
13
  agentMd?: string;
14
+ /** Environment variables passed to the sandbox at build and run time. */
15
+ env?: Record<string, string>;
10
16
  /** Additional files to write into the sandbox. */
11
17
  files?: AgentFile[];
18
+ /** Setup configuration for the sandbox build phase. */
19
+ setup?: AgentSetup;
12
20
  };
13
21
  type DefinedAgent = {
14
22
  readonly agentType: "gemini" | "codex";
15
23
  readonly agentMd?: string;
16
24
  readonly files: AgentFile[];
25
+ /** Setup configuration. Undefined when no setup is configured. */
26
+ readonly setup?: AgentSetup;
27
+ /** Environment variables. */
28
+ readonly env: Record<string, string>;
17
29
  /** Snapshot ID resolved from env at runtime. Throws if not set. */
18
30
  readonly snapshotId: string;
19
31
  };
20
32
 
21
- export type { AgentConfig as A, DefinedAgent as D, AgentFile as a };
33
+ export type { AgentConfig as A, DefinedAgent as D, AgentFile as a, AgentSetup as b };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@giselles-ai/agent",
3
- "version": "0.1.24",
3
+ "version": "0.1.25",
4
4
  "type": "module",
5
5
  "sideEffects": false,
6
6
  "license": "Apache-2.0",
@@ -37,8 +37,8 @@
37
37
  "format": "pnpm exec biome check --write ."
38
38
  },
39
39
  "dependencies": {
40
- "@giselles-ai/browser-tool": "0.1.24",
41
- "@vercel/sandbox": "1.6.0",
40
+ "@giselles-ai/browser-tool": "0.1.25",
41
+ "@vercel/sandbox": "1.8.1",
42
42
  "@iarna/toml": "3.0.0",
43
43
  "zod": "4.3.6"
44
44
  },