@giselles-ai/sandkit 0.1.0
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/LICENSE +21 -0
- package/README.md +163 -0
- package/dist/adapters/drizzle.d.ts +83 -0
- package/dist/adapters/drizzle.js +9 -0
- package/dist/adapters/drizzle.js.map +1 -0
- package/dist/adapters/memory.d.ts +6 -0
- package/dist/adapters/memory.js +8 -0
- package/dist/adapters/memory.js.map +1 -0
- package/dist/adapters/sqlite-bun.d.ts +7 -0
- package/dist/adapters/sqlite-bun.js +8 -0
- package/dist/adapters/sqlite-bun.js.map +1 -0
- package/dist/bin.js +697 -0
- package/dist/bin.js.map +1 -0
- package/dist/chunk-7DLK7LOM.js +44 -0
- package/dist/chunk-7DLK7LOM.js.map +1 -0
- package/dist/chunk-BDPTYR6V.js +407 -0
- package/dist/chunk-BDPTYR6V.js.map +1 -0
- package/dist/chunk-CSOBTLWV.js +202 -0
- package/dist/chunk-CSOBTLWV.js.map +1 -0
- package/dist/chunk-DLGUA3H7.js +9 -0
- package/dist/chunk-DLGUA3H7.js.map +1 -0
- package/dist/chunk-FSDVHEEX.js +45 -0
- package/dist/chunk-FSDVHEEX.js.map +1 -0
- package/dist/chunk-HVYCAAZQ.js +25 -0
- package/dist/chunk-HVYCAAZQ.js.map +1 -0
- package/dist/chunk-LC3IYBAL.js +100 -0
- package/dist/chunk-LC3IYBAL.js.map +1 -0
- package/dist/chunk-REGOUXVI.js +58 -0
- package/dist/chunk-REGOUXVI.js.map +1 -0
- package/dist/chunk-RMMOQD5Y.js +211 -0
- package/dist/chunk-RMMOQD5Y.js.map +1 -0
- package/dist/chunk-UDFWES6J.js +486 -0
- package/dist/chunk-UDFWES6J.js.map +1 -0
- package/dist/chunk-VISDS5T7.js +202 -0
- package/dist/chunk-VISDS5T7.js.map +1 -0
- package/dist/chunk-XM4HGRXW.js +37 -0
- package/dist/chunk-XM4HGRXW.js.map +1 -0
- package/dist/cli/index.d.ts +19 -0
- package/dist/cli/index.js +397 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/index.d.ts +78 -0
- package/dist/index.js +1102 -0
- package/dist/index.js.map +1 -0
- package/dist/integrations/mock.d.ts +19 -0
- package/dist/integrations/mock.js +207 -0
- package/dist/integrations/mock.js.map +1 -0
- package/dist/integrations/vercel.d.ts +7 -0
- package/dist/integrations/vercel.js +400 -0
- package/dist/integrations/vercel.js.map +1 -0
- package/dist/policies/ai-gateway.d.ts +15 -0
- package/dist/policies/ai-gateway.js +12 -0
- package/dist/policies/ai-gateway.js.map +1 -0
- package/dist/policies/codex.d.ts +10 -0
- package/dist/policies/codex.js +12 -0
- package/dist/policies/codex.js.map +1 -0
- package/dist/policies/gemini.d.ts +10 -0
- package/dist/policies/gemini.js +12 -0
- package/dist/policies/gemini.js.map +1 -0
- package/dist/schema/index.d.ts +60 -0
- package/dist/schema/index.js +31 -0
- package/dist/schema/index.js.map +1 -0
- package/dist/types-BCgprbo8.d.ts +47 -0
- package/dist/types-BEKQnjeb.d.ts +139 -0
- package/dist/types-Cy36bS1j.d.ts +138 -0
- package/package.json +126 -0
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createId
|
|
3
|
+
} from "./chunk-DLGUA3H7.js";
|
|
4
|
+
|
|
5
|
+
// src/adapters/memory.ts
|
|
6
|
+
var defaultWorkspaceStatus = "active";
|
|
7
|
+
var defaultWorkspaceName = "default";
|
|
8
|
+
var defaultRunStatus = "started";
|
|
9
|
+
var getNow = () => (/* @__PURE__ */ new Date()).toISOString();
|
|
10
|
+
function cloneSetupStateValue(value) {
|
|
11
|
+
if (value === void 0) {
|
|
12
|
+
return void 0;
|
|
13
|
+
}
|
|
14
|
+
if (Array.isArray(value)) {
|
|
15
|
+
return [...value];
|
|
16
|
+
}
|
|
17
|
+
if (typeof value === "object" && value !== null) {
|
|
18
|
+
return { ...value };
|
|
19
|
+
}
|
|
20
|
+
return value;
|
|
21
|
+
}
|
|
22
|
+
function normalizeWorkspaceRecord(workspace) {
|
|
23
|
+
return {
|
|
24
|
+
...workspace,
|
|
25
|
+
metadata: workspace.metadata && { ...workspace.metadata }
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
var mergeMetadata = (existing, next) => {
|
|
29
|
+
if (typeof next === "undefined") {
|
|
30
|
+
return existing;
|
|
31
|
+
}
|
|
32
|
+
if (existing === void 0 || existing === null) {
|
|
33
|
+
return { ...next };
|
|
34
|
+
}
|
|
35
|
+
return { ...existing, ...next };
|
|
36
|
+
};
|
|
37
|
+
function createMemorySetupStatesAdapter() {
|
|
38
|
+
const setupStates = /* @__PURE__ */ new Map();
|
|
39
|
+
return {
|
|
40
|
+
async getSetupState(id) {
|
|
41
|
+
const state = setupStates.get(id);
|
|
42
|
+
if (!state) {
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
return {
|
|
46
|
+
id: state.id,
|
|
47
|
+
state: {
|
|
48
|
+
kind: state.state.kind,
|
|
49
|
+
sessionId: state.state.sessionId,
|
|
50
|
+
state: cloneSetupStateValue(state.state.state)
|
|
51
|
+
},
|
|
52
|
+
createdAt: state.createdAt,
|
|
53
|
+
updatedAt: state.updatedAt
|
|
54
|
+
};
|
|
55
|
+
},
|
|
56
|
+
async putSetupState(input) {
|
|
57
|
+
const now = getNow();
|
|
58
|
+
const existing = setupStates.get(input.id);
|
|
59
|
+
const next = existing ? {
|
|
60
|
+
...existing,
|
|
61
|
+
state: {
|
|
62
|
+
kind: input.state.kind,
|
|
63
|
+
sessionId: input.state.sessionId,
|
|
64
|
+
state: cloneSetupStateValue(input.state.state)
|
|
65
|
+
},
|
|
66
|
+
updatedAt: now
|
|
67
|
+
} : {
|
|
68
|
+
id: input.id,
|
|
69
|
+
state: {
|
|
70
|
+
kind: input.state.kind,
|
|
71
|
+
sessionId: input.state.sessionId,
|
|
72
|
+
state: cloneSetupStateValue(input.state.state)
|
|
73
|
+
},
|
|
74
|
+
createdAt: now,
|
|
75
|
+
updatedAt: now
|
|
76
|
+
};
|
|
77
|
+
setupStates.set(input.id, next);
|
|
78
|
+
return next;
|
|
79
|
+
},
|
|
80
|
+
async deleteSetupState(id) {
|
|
81
|
+
setupStates.delete(id);
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
function createMemoryRunAdapter() {
|
|
86
|
+
const runs = /* @__PURE__ */ new Map();
|
|
87
|
+
return {
|
|
88
|
+
async createRun(input) {
|
|
89
|
+
const now = getNow();
|
|
90
|
+
const normalizedId = input.id?.trim() && input.id.trim().length > 0 ? input.id.trim() : createId("run");
|
|
91
|
+
const run = {
|
|
92
|
+
id: normalizedId,
|
|
93
|
+
workspaceId: input.workspaceId,
|
|
94
|
+
provider: input.provider,
|
|
95
|
+
executionTargetId: input.executionTargetId,
|
|
96
|
+
command: input.command,
|
|
97
|
+
args: input.args ?? [],
|
|
98
|
+
status: input.status ?? defaultRunStatus,
|
|
99
|
+
startedAt: input.startedAt ?? now,
|
|
100
|
+
policySnapshotId: input.policySnapshotId ?? void 0
|
|
101
|
+
};
|
|
102
|
+
runs.set(normalizedId, run);
|
|
103
|
+
return { ...run, args: run.args ? [...run.args] : run.args };
|
|
104
|
+
},
|
|
105
|
+
async finishRun(id, input) {
|
|
106
|
+
const current = runs.get(id);
|
|
107
|
+
if (!current) {
|
|
108
|
+
throw new Error(`Run with id "${id}" does not exist`);
|
|
109
|
+
}
|
|
110
|
+
const next = {
|
|
111
|
+
...current,
|
|
112
|
+
status: input.status,
|
|
113
|
+
finishedAt: input.finishedAt,
|
|
114
|
+
exitCode: input.exitCode ?? current.exitCode,
|
|
115
|
+
stdout: input.stdout ?? current.stdout,
|
|
116
|
+
stderr: input.stderr ?? current.stderr,
|
|
117
|
+
providerCommit: input.providerCommit,
|
|
118
|
+
policySnapshotId: current.policySnapshotId
|
|
119
|
+
};
|
|
120
|
+
runs.set(id, next);
|
|
121
|
+
return { ...next, args: next.args ? [...next.args] : next.args };
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
function createMemoryPolicySnapshotAdapter() {
|
|
126
|
+
const policySnapshots = /* @__PURE__ */ new Map();
|
|
127
|
+
return {
|
|
128
|
+
async createPolicySnapshot(input) {
|
|
129
|
+
const now = getNow();
|
|
130
|
+
const normalizedId = input.id?.trim() && input.id.trim().length > 0 ? input.id.trim() : createId("policy-snapshot");
|
|
131
|
+
if (policySnapshots.has(normalizedId)) {
|
|
132
|
+
throw new Error(`Policy snapshot with id "${normalizedId}" already exists`);
|
|
133
|
+
}
|
|
134
|
+
const snapshot = {
|
|
135
|
+
id: normalizedId,
|
|
136
|
+
workspaceId: input.workspaceId,
|
|
137
|
+
policyId: input.policyId,
|
|
138
|
+
config: input.config,
|
|
139
|
+
createdAt: input.createdAt ?? now
|
|
140
|
+
};
|
|
141
|
+
policySnapshots.set(normalizedId, snapshot);
|
|
142
|
+
return { ...snapshot, config: snapshot.config };
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
function createMemoryWorkspaceAdapter() {
|
|
147
|
+
const workspaces = /* @__PURE__ */ new Map();
|
|
148
|
+
return {
|
|
149
|
+
async createWorkspace(input = {}) {
|
|
150
|
+
const now = getNow();
|
|
151
|
+
const normalizedId = input.id?.trim() && input.id.trim().length > 0 ? input.id.trim() : createId("workspace");
|
|
152
|
+
if (workspaces.has(normalizedId)) {
|
|
153
|
+
throw new Error(`Workspace with id "${normalizedId}" already exists`);
|
|
154
|
+
}
|
|
155
|
+
const workspace = {
|
|
156
|
+
id: normalizedId,
|
|
157
|
+
name: input.name ?? defaultWorkspaceName,
|
|
158
|
+
status: input.status ?? defaultWorkspaceStatus,
|
|
159
|
+
metadata: input.metadata ? { ...input.metadata } : void 0,
|
|
160
|
+
sandboxId: input.sandboxId === "" ? void 0 : input.sandboxId?.trim() || void 0,
|
|
161
|
+
lastResumedAt: input.lastResumedAt,
|
|
162
|
+
createdAt: now,
|
|
163
|
+
updatedAt: now
|
|
164
|
+
};
|
|
165
|
+
workspaces.set(normalizedId, workspace);
|
|
166
|
+
return normalizeWorkspaceRecord(workspace);
|
|
167
|
+
},
|
|
168
|
+
async getWorkspace(id) {
|
|
169
|
+
const workspace = workspaces.get(id);
|
|
170
|
+
return workspace ? normalizeWorkspaceRecord(workspace) : null;
|
|
171
|
+
},
|
|
172
|
+
async updateWorkspace(id, input) {
|
|
173
|
+
const current = workspaces.get(id);
|
|
174
|
+
if (!current) {
|
|
175
|
+
throw new Error(`Workspace with id "${id}" does not exist`);
|
|
176
|
+
}
|
|
177
|
+
const next = {
|
|
178
|
+
...current,
|
|
179
|
+
metadata: mergeMetadata(current.metadata, input.metadata),
|
|
180
|
+
name: input.name ?? current.name,
|
|
181
|
+
status: input.status ?? current.status,
|
|
182
|
+
sandboxId: input.sandboxId === null ? void 0 : input.sandboxId ?? current.sandboxId,
|
|
183
|
+
lastResumedAt: input.lastResumedAt === null ? void 0 : input.lastResumedAt ?? current.lastResumedAt,
|
|
184
|
+
updatedAt: getNow()
|
|
185
|
+
};
|
|
186
|
+
workspaces.set(id, next);
|
|
187
|
+
return normalizeWorkspaceRecord(next);
|
|
188
|
+
}
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
var createMemoryAdapter = () => ({
|
|
192
|
+
id: "memory",
|
|
193
|
+
workspaces: createMemoryWorkspaceAdapter(),
|
|
194
|
+
setupStates: createMemorySetupStatesAdapter(),
|
|
195
|
+
runs: createMemoryRunAdapter(),
|
|
196
|
+
policySnapshots: createMemoryPolicySnapshotAdapter()
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
export {
|
|
200
|
+
createMemoryAdapter
|
|
201
|
+
};
|
|
202
|
+
//# sourceMappingURL=chunk-CSOBTLWV.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/adapters/memory.ts"],"sourcesContent":["import { createId } from \"../core/ids.ts\";\nimport type {\n WorkspaceAdapter,\n WorkspaceCreateInput,\n WorkspaceRecord,\n WorkspaceUpdateInput,\n SandkitAdapter,\n SharedSetupState,\n SetupStateRecord,\n SetupStatePutInput,\n RunAdapter,\n RunCreateInput,\n RunFinishInput,\n RunRecord,\n PolicySnapshotAdapter,\n PolicySnapshotCreateInput,\n PolicySnapshotRecord,\n} from \"./types\";\n\nconst defaultWorkspaceStatus = \"active\";\nconst defaultWorkspaceName = \"default\";\nconst defaultRunStatus = \"started\" as const;\n\nconst getNow = () => new Date().toISOString();\n\nfunction cloneSetupStateValue(value: SharedSetupState[\"state\"]): SharedSetupState[\"state\"] {\n if (value === undefined) {\n return undefined;\n }\n\n if (Array.isArray(value)) {\n return [...value];\n }\n\n if (typeof value === \"object\" && value !== null) {\n return { ...value } as SharedSetupState[\"state\"];\n }\n\n return value;\n}\n\nfunction normalizeWorkspaceRecord(workspace: WorkspaceRecord): WorkspaceRecord {\n return {\n ...workspace,\n metadata: workspace.metadata && { ...workspace.metadata },\n };\n}\n\nconst mergeMetadata = (\n existing: WorkspaceRecord[\"metadata\"],\n next?: WorkspaceRecord[\"metadata\"],\n) => {\n if (typeof next === \"undefined\") {\n return existing;\n }\n if (existing === undefined || existing === null) {\n return { ...next };\n }\n return { ...existing, ...next };\n};\n\nfunction createMemorySetupStatesAdapter(): {\n getSetupState: (id: string) => Promise<SetupStateRecord | null>;\n putSetupState: (input: SetupStatePutInput) => Promise<SetupStateRecord>;\n deleteSetupState: (id: string) => Promise<void>;\n} {\n const setupStates = new Map<string, SetupStateRecord>();\n\n return {\n async getSetupState(id: string) {\n const state = setupStates.get(id);\n if (!state) {\n return null;\n }\n\n return {\n id: state.id,\n state: {\n kind: state.state.kind,\n sessionId: state.state.sessionId,\n state: cloneSetupStateValue(state.state.state),\n },\n createdAt: state.createdAt,\n updatedAt: state.updatedAt,\n };\n },\n async putSetupState(input: SetupStatePutInput) {\n const now = getNow();\n const existing = setupStates.get(input.id);\n const next: SetupStateRecord = existing\n ? {\n ...existing,\n state: {\n kind: input.state.kind,\n sessionId: input.state.sessionId,\n state: cloneSetupStateValue(input.state.state),\n },\n updatedAt: now,\n }\n : {\n id: input.id,\n state: {\n kind: input.state.kind,\n sessionId: input.state.sessionId,\n state: cloneSetupStateValue(input.state.state),\n },\n createdAt: now,\n updatedAt: now,\n };\n\n setupStates.set(input.id, next);\n return next;\n },\n async deleteSetupState(id: string) {\n setupStates.delete(id);\n },\n };\n}\n\nfunction createMemoryRunAdapter(): RunAdapter {\n const runs = new Map<string, RunRecord>();\n\n return {\n async createRun(input: RunCreateInput): Promise<RunRecord> {\n const now = getNow();\n const normalizedId =\n input.id?.trim() && input.id.trim().length > 0 ? input.id.trim() : createId(\"run\");\n\n const run: RunRecord = {\n id: normalizedId,\n workspaceId: input.workspaceId,\n provider: input.provider,\n executionTargetId: input.executionTargetId,\n command: input.command,\n args: input.args ?? [],\n status: input.status ?? defaultRunStatus,\n startedAt: input.startedAt ?? now,\n policySnapshotId: input.policySnapshotId ?? undefined,\n };\n\n runs.set(normalizedId, run);\n return { ...run, args: run.args ? [...run.args] : run.args };\n },\n async finishRun(id: string, input: RunFinishInput): Promise<RunRecord> {\n const current = runs.get(id);\n if (!current) {\n throw new Error(`Run with id \"${id}\" does not exist`);\n }\n\n const next: RunRecord = {\n ...current,\n status: input.status,\n finishedAt: input.finishedAt,\n exitCode: input.exitCode ?? current.exitCode,\n stdout: input.stdout ?? current.stdout,\n stderr: input.stderr ?? current.stderr,\n providerCommit: input.providerCommit,\n policySnapshotId: current.policySnapshotId,\n };\n\n runs.set(id, next);\n return { ...next, args: next.args ? [...next.args] : next.args };\n },\n };\n}\n\nfunction createMemoryPolicySnapshotAdapter(): PolicySnapshotAdapter {\n const policySnapshots = new Map<string, PolicySnapshotRecord>();\n\n return {\n async createPolicySnapshot(input: PolicySnapshotCreateInput): Promise<PolicySnapshotRecord> {\n const now = getNow();\n const normalizedId =\n input.id?.trim() && input.id.trim().length > 0\n ? input.id.trim()\n : createId(\"policy-snapshot\");\n\n if (policySnapshots.has(normalizedId)) {\n throw new Error(`Policy snapshot with id \"${normalizedId}\" already exists`);\n }\n\n const snapshot: PolicySnapshotRecord = {\n id: normalizedId,\n workspaceId: input.workspaceId,\n policyId: input.policyId,\n config: input.config,\n createdAt: input.createdAt ?? now,\n };\n\n policySnapshots.set(normalizedId, snapshot);\n return { ...snapshot, config: snapshot.config };\n },\n };\n}\n\nfunction createMemoryWorkspaceAdapter(): WorkspaceAdapter {\n const workspaces = new Map<string, WorkspaceRecord>();\n\n return {\n async createWorkspace(input: WorkspaceCreateInput = {}) {\n const now = getNow();\n const normalizedId =\n input.id?.trim() && input.id.trim().length > 0 ? input.id.trim() : createId(\"workspace\");\n\n if (workspaces.has(normalizedId)) {\n throw new Error(`Workspace with id \"${normalizedId}\" already exists`);\n }\n\n const workspace: WorkspaceRecord = {\n id: normalizedId,\n name: input.name ?? defaultWorkspaceName,\n status: input.status ?? defaultWorkspaceStatus,\n metadata: input.metadata ? { ...input.metadata } : undefined,\n sandboxId: input.sandboxId === \"\" ? undefined : input.sandboxId?.trim() || undefined,\n lastResumedAt: input.lastResumedAt,\n createdAt: now,\n updatedAt: now,\n };\n workspaces.set(normalizedId, workspace);\n return normalizeWorkspaceRecord(workspace);\n },\n async getWorkspace(id: string) {\n const workspace = workspaces.get(id);\n return workspace ? normalizeWorkspaceRecord(workspace) : null;\n },\n async updateWorkspace(id: string, input: WorkspaceUpdateInput) {\n const current = workspaces.get(id);\n if (!current) {\n throw new Error(`Workspace with id \"${id}\" does not exist`);\n }\n\n const next: WorkspaceRecord = {\n ...current,\n metadata: mergeMetadata(current.metadata, input.metadata),\n name: input.name ?? current.name,\n status: input.status ?? current.status,\n sandboxId: input.sandboxId === null ? undefined : (input.sandboxId ?? current.sandboxId),\n lastResumedAt:\n input.lastResumedAt === null ? undefined : (input.lastResumedAt ?? current.lastResumedAt),\n updatedAt: getNow(),\n };\n\n workspaces.set(id, next);\n return normalizeWorkspaceRecord(next);\n },\n };\n}\n\nexport const createMemoryAdapter = (): SandkitAdapter => ({\n id: \"memory\",\n workspaces: createMemoryWorkspaceAdapter(),\n setupStates: createMemorySetupStatesAdapter(),\n runs: createMemoryRunAdapter(),\n policySnapshots: createMemoryPolicySnapshotAdapter(),\n});\n"],"mappings":";;;;;AAmBA,IAAM,yBAAyB;AAC/B,IAAM,uBAAuB;AAC7B,IAAM,mBAAmB;AAEzB,IAAM,SAAS,OAAM,oBAAI,KAAK,GAAE,YAAY;AAE5C,SAAS,qBAAqB,OAA6D;AACzF,MAAI,UAAU,QAAW;AACvB,WAAO;AAAA,EACT;AAEA,MAAI,MAAM,QAAQ,KAAK,GAAG;AACxB,WAAO,CAAC,GAAG,KAAK;AAAA,EAClB;AAEA,MAAI,OAAO,UAAU,YAAY,UAAU,MAAM;AAC/C,WAAO,EAAE,GAAG,MAAM;AAAA,EACpB;AAEA,SAAO;AACT;AAEA,SAAS,yBAAyB,WAA6C;AAC7E,SAAO;AAAA,IACL,GAAG;AAAA,IACH,UAAU,UAAU,YAAY,EAAE,GAAG,UAAU,SAAS;AAAA,EAC1D;AACF;AAEA,IAAM,gBAAgB,CACpB,UACA,SACG;AACH,MAAI,OAAO,SAAS,aAAa;AAC/B,WAAO;AAAA,EACT;AACA,MAAI,aAAa,UAAa,aAAa,MAAM;AAC/C,WAAO,EAAE,GAAG,KAAK;AAAA,EACnB;AACA,SAAO,EAAE,GAAG,UAAU,GAAG,KAAK;AAChC;AAEA,SAAS,iCAIP;AACA,QAAM,cAAc,oBAAI,IAA8B;AAEtD,SAAO;AAAA,IACL,MAAM,cAAc,IAAY;AAC9B,YAAM,QAAQ,YAAY,IAAI,EAAE;AAChC,UAAI,CAAC,OAAO;AACV,eAAO;AAAA,MACT;AAEA,aAAO;AAAA,QACL,IAAI,MAAM;AAAA,QACV,OAAO;AAAA,UACL,MAAM,MAAM,MAAM;AAAA,UAClB,WAAW,MAAM,MAAM;AAAA,UACvB,OAAO,qBAAqB,MAAM,MAAM,KAAK;AAAA,QAC/C;AAAA,QACA,WAAW,MAAM;AA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WAAW,MAAM,cAAc,OAAO,SAAa,MAAM,aAAa,QAAQ;AAAA,QAC9E,eACE,MAAM,kBAAkB,OAAO,SAAa,MAAM,iBAAiB,QAAQ;AAAA,QAC7E,WAAW,OAAO;AAAA,MACpB;AAEA,iBAAW,IAAI,IAAI,IAAI;AACvB,aAAO,yBAAyB,IAAI;AAAA,IACtC;AAAA,EACF;AACF;AAEO,IAAM,sBAAsB,OAAuB;AAAA,EACxD,IAAI;AAAA,EACJ,YAAY,6BAA6B;AAAA,EACzC,aAAa,+BAA+B;AAAA,EAC5C,MAAM,uBAAuB;AAAA,EAC7B,iBAAiB,kCAAkC;AACrD;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/core/ids.ts"],"sourcesContent":["export function createId(prefix: string): string {\n return `${prefix}_${crypto.randomUUID()}`;\n}\n"],"mappings":";AAAO,SAAS,SAAS,QAAwB;AAC/C,SAAO,GAAG,MAAM,IAAI,OAAO,WAAW,CAAC;AACzC;","names":[]}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import {
|
|
2
|
+
allowService
|
|
3
|
+
} from "./chunk-VISDS5T7.js";
|
|
4
|
+
|
|
5
|
+
// src/policies/codex.ts
|
|
6
|
+
var CODEX_DOMAINS = ["api.openai.com", "*.openai.com", "openrouter.ai", "*.openrouter.ai"];
|
|
7
|
+
function resolveCodexCredential(options) {
|
|
8
|
+
if (options === void 0) {
|
|
9
|
+
return { kind: "default" };
|
|
10
|
+
}
|
|
11
|
+
if (typeof options.apiKey !== "string" || options.apiKey.trim().length === 0) {
|
|
12
|
+
throw new Error(
|
|
13
|
+
'codex(...) explicit override requires a non-empty "apiKey". Omit the options object to use CODEX_API_KEY.'
|
|
14
|
+
);
|
|
15
|
+
}
|
|
16
|
+
return { kind: "value", value: options.apiKey };
|
|
17
|
+
}
|
|
18
|
+
function resolveCodexDefaultApiKey() {
|
|
19
|
+
return process.env.CODEX_API_KEY;
|
|
20
|
+
}
|
|
21
|
+
function codex(options) {
|
|
22
|
+
return {
|
|
23
|
+
id: "codex",
|
|
24
|
+
name: "Codex",
|
|
25
|
+
description: "Allow outbound access commonly needed by Codex-style clients.",
|
|
26
|
+
domains: CODEX_DOMAINS,
|
|
27
|
+
headers: [
|
|
28
|
+
{
|
|
29
|
+
headerName: "authorization",
|
|
30
|
+
valuePrefix: "Bearer ",
|
|
31
|
+
credential: resolveCodexCredential(options)
|
|
32
|
+
}
|
|
33
|
+
]
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
function allowCodex() {
|
|
37
|
+
return allowService(codex());
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export {
|
|
41
|
+
resolveCodexDefaultApiKey,
|
|
42
|
+
codex,
|
|
43
|
+
allowCodex
|
|
44
|
+
};
|
|
45
|
+
//# sourceMappingURL=chunk-FSDVHEEX.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/policies/codex.ts"],"sourcesContent":["import { allowService } from \"./dsl.ts\";\nimport type { PolicyServiceDescriptor, WorkspacePolicy } from \"./types.ts\";\n\nconst CODEX_DOMAINS = [\"api.openai.com\", \"*.openai.com\", \"openrouter.ai\", \"*.openrouter.ai\"];\n\nexport interface CodexOptions {\n readonly apiKey?: string;\n}\n\nfunction resolveCodexCredential(options?: CodexOptions) {\n if (options === undefined) {\n return { kind: \"default\" } as const;\n }\n\n if (typeof options.apiKey !== \"string\" || options.apiKey.trim().length === 0) {\n throw new Error(\n 'codex(...) explicit override requires a non-empty \"apiKey\". Omit the options object to use CODEX_API_KEY.',\n );\n }\n\n return { kind: \"value\", value: options.apiKey } as const;\n}\n\nexport function resolveCodexDefaultApiKey(): string | undefined {\n return process.env.CODEX_API_KEY;\n}\n\nexport function codex(options?: CodexOptions): PolicyServiceDescriptor {\n return {\n id: \"codex\",\n name: \"Codex\",\n description: \"Allow outbound access commonly needed by Codex-style clients.\",\n domains: CODEX_DOMAINS,\n headers: [\n {\n headerName: \"authorization\",\n valuePrefix: \"Bearer \",\n credential: resolveCodexCredential(options),\n },\n ],\n };\n}\n\nexport function allowCodex(): WorkspacePolicy {\n return allowService(codex());\n}\n"],"mappings":";;;;;AAGA,IAAM,gBAAgB,CAAC,kBAAkB,gBAAgB,iBAAiB,iBAAiB;AAM3F,SAAS,uBAAuB,SAAwB;AACtD,MAAI,YAAY,QAAW;AACzB,WAAO,EAAE,MAAM,UAAU;AAAA,EAC3B;AAEA,MAAI,OAAO,QAAQ,WAAW,YAAY,QAAQ,OAAO,KAAK,EAAE,WAAW,GAAG;AAC5E,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AAEA,SAAO,EAAE,MAAM,SAAS,OAAO,QAAQ,OAAO;AAChD;AAEO,SAAS,4BAAgD;AAC9D,SAAO,QAAQ,IAAI;AACrB;AAEO,SAAS,MAAM,SAAiD;AACrE,SAAO;AAAA,IACL,IAAI;AAAA,IACJ,MAAM;AAAA,IACN,aAAa;AAAA,IACb,SAAS;AAAA,IACT,SAAS;AAAA,MACP;AAAA,QACE,YAAY;AAAA,QACZ,aAAa;AAAA,QACb,YAAY,uBAAuB,OAAO;AAAA,MAC5C;AAAA,IACF;AAAA,EACF;AACF;AAEO,SAAS,aAA8B;AAC5C,SAAO,aAAa,MAAM,CAAC;AAC7B;","names":[]}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// src/types.ts
|
|
2
|
+
var sandboxProviderContract = /* @__PURE__ */ Symbol("sandkit.sandbox.provider");
|
|
3
|
+
function createSandboxProvider(provider, driverFactory) {
|
|
4
|
+
return {
|
|
5
|
+
[sandboxProviderContract]: {
|
|
6
|
+
provider,
|
|
7
|
+
driverFactory
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
function getSandboxDriverFactory(sandboxProvider) {
|
|
12
|
+
const driverFactory = sandboxProvider[sandboxProviderContract]?.driverFactory;
|
|
13
|
+
if (!driverFactory) {
|
|
14
|
+
throw new Error(
|
|
15
|
+
"SandkitOptions.sandbox is invalid. Pass a provider created by Sandkit integrations such as vercelSandbox(...)."
|
|
16
|
+
);
|
|
17
|
+
}
|
|
18
|
+
return driverFactory;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export {
|
|
22
|
+
createSandboxProvider,
|
|
23
|
+
getSandboxDriverFactory
|
|
24
|
+
};
|
|
25
|
+
//# sourceMappingURL=chunk-HVYCAAZQ.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/types.ts"],"sourcesContent":["import type { SandkitAdapter, WorkspaceRecord } from \"./adapters/types.ts\";\nimport type {\n PolicySnapshotAdapter,\n PolicySnapshotRecord,\n PolicySnapshotCreateInput,\n RunAdapter,\n RunCreateInput,\n RunFinishInput,\n RunRecord,\n RunStatus,\n SetupStateAdapter,\n SetupStateRecord,\n SetupStatePutInput,\n WorkspaceMetadata,\n SharedSetup,\n SharedSetupState,\n WorkspaceStatus,\n} from \"./adapters/types.ts\";\nimport type { WorkspacePolicy } from \"./policies/types.ts\";\n\nexport type JsonPrimitive = boolean | number | string | null;\n\nexport type JsonValue =\n | JsonPrimitive\n | JsonValue[]\n | {\n [key: string]: JsonValue;\n };\n\nexport type {\n SandkitAdapter,\n WorkspaceRecord,\n RunAdapter,\n RunCreateInput,\n RunFinishInput,\n RunRecord,\n PolicySnapshotAdapter,\n PolicySnapshotRecord,\n PolicySnapshotCreateInput,\n RunStatus,\n SetupStateAdapter,\n SetupStateRecord,\n SetupStatePutInput,\n SharedSetup,\n SharedSetupState,\n};\nexport type { WorkspacePolicy };\n\nexport interface WorkspaceCreateOptions {\n id?: string;\n name?: string;\n metadata?: WorkspaceMetadata;\n policy?: WorkspacePolicy;\n sandbox?: {\n /**\n * Durable workspace default for provider port publication. This affects\n * create/restore behavior for live session/public URL flows, not the\n * durable runCommand() unit-of-work model itself.\n */\n readonly exposedPorts?: readonly number[];\n };\n status?: WorkspaceStatus;\n sandboxId?: string;\n lastResumedAt?: string;\n}\n\nexport interface CommandResult {\n exitCode: number;\n stderr: string;\n stdout: string;\n}\n\nexport interface SandboxSessionLease {\n readonly sandboxId: string;\n readonly observedAt: string;\n readonly expiresAt: string;\n}\n\nexport interface WorkspaceSandboxLease {\n readonly sandboxId: string;\n readonly observedAt: string;\n readonly expiresAt: string;\n readonly remainingMs: number;\n}\n\nexport interface WorkspaceSessionProcess {\n readonly processId: string;\n wait(): Promise<CommandResult>;\n /**\n * Accesses the same normalized log stream used by onStdout/onStderr callbacks.\n * Sandkit keeps a single internal stream, so callbacks and logs() observe\n * the same sequence and buffered historical chunks are replayed to new readers.\n */\n logs?: () => AsyncIterable<WorkspaceSessionLog>;\n}\n\nexport interface WorkspaceSessionLog {\n readonly stream: \"stdout\" | \"stderr\";\n readonly chunk: string;\n}\n\nexport interface WorkspaceSessionProcessStartInput {\n readonly command: string;\n readonly args: readonly string[];\n /**\n * Optional per-call policy override for this session process.\n */\n readonly policy?: WorkspacePolicy;\n /**\n * Callbacks consume chunks from Sandkit's normalized process log stream.\n */\n readonly onStdout?: ((chunk: string) => void) | undefined;\n /**\n * Callbacks consume chunks from Sandkit's normalized process log stream.\n */\n readonly onStderr?: ((chunk: string) => void) | undefined;\n}\n\nexport interface SandboxRunCommandOptions {\n readonly command: string;\n readonly args?: readonly string[];\n readonly policy?: WorkspacePolicy;\n}\n\nexport interface PersistedSandboxState {\n readonly kind: string;\n readonly sessionId: string;\n readonly state?: JsonValue;\n}\n\nexport interface SandboxDriver {\n readonly id: string;\n readonly provider: string;\n applyPolicy(policy: WorkspacePolicy): Promise<void>;\n /**\n * Returns lease timing observed from the current sandbox instance.\n * Some providers expose this as an interpreted timeout value.\n * Sandkit persists lease updates only from explicit session open/extend paths,\n * so callers should not treat mere reads as lease refreshes.\n */\n getSessionLease(): Promise<SandboxSessionLease>;\n runCommand(command: string, args: string[]): Promise<CommandResult>;\n startProcess?(input: WorkspaceSessionProcessStartInput): Promise<WorkspaceSessionProcess>;\n /** Persists and restores durability state through commit() and attach/restore APIs. */\n snapshot(): Promise<PersistedSandboxState>;\n url?(port: number): Promise<string>;\n extendTimeout?(durationMs: number): Promise<void>;\n}\n\nexport interface SandboxCreateOptions {\n readonly policy: WorkspacePolicy;\n readonly exposedPorts?: readonly number[];\n readonly timeoutMs?: number;\n}\n\nexport interface SandboxDriverFactory {\n createSandbox(workspace: WorkspaceRecord, options: SandboxCreateOptions): Promise<SandboxDriver>;\n resumeSandbox(\n workspace: WorkspaceRecord,\n snapshot: PersistedSandboxState,\n options: SandboxCreateOptions,\n ): Promise<SandboxDriver>;\n isSessionUnavailableError?(error: unknown): boolean;\n}\n\nexport interface VercelSandboxOptions {\n runtime?: string;\n /**\n * Provider default sandbox lease timeout in milliseconds. Sandkit uses this\n * when creating or restoring a sandbox unless openSession({ timeoutMs })\n * supplies a live-session override.\n */\n defaultTimeout?: number;\n /**\n * Legacy alias retained for compatibility with existing call sites.\n * Prefer defaultTimeout for new code.\n */\n timeout?: number;\n}\n\nconst sandboxProviderContract = Symbol(\"sandkit.sandbox.provider\");\n\ntype SandboxProviderRecord = {\n readonly provider: string;\n readonly driverFactory: SandboxDriverFactory;\n};\n\nexport interface SandkitSandboxProvider {\n readonly [sandboxProviderContract]: SandboxProviderRecord;\n}\n\nexport function createSandboxProvider(\n provider: string,\n driverFactory: SandboxDriverFactory,\n): SandkitSandboxProvider {\n return {\n [sandboxProviderContract]: {\n provider,\n driverFactory,\n },\n };\n}\n\nexport function getSandboxDriverFactory(\n sandboxProvider: SandkitSandboxProvider,\n): SandboxDriverFactory {\n const driverFactory = sandboxProvider[sandboxProviderContract]?.driverFactory;\n if (!driverFactory) {\n throw new Error(\n \"SandkitOptions.sandbox is invalid. Pass a provider created by Sandkit integrations such as vercelSandbox(...).\",\n );\n }\n\n return driverFactory;\n}\n\nexport interface SandkitOptions {\n readonly database?: SandkitAdapter | undefined;\n readonly setup?: SharedSetup | undefined;\n readonly network?: readonly unknown[] | undefined;\n readonly sandbox: SandkitSandboxProvider;\n}\n"],"mappings":";AAoLA,IAAM,0BAA0B,uBAAO,0BAA0B;AAW1D,SAAS,sBACd,UACA,eACwB;AACxB,SAAO;AAAA,IACL,CAAC,uBAAuB,GAAG;AAAA,MACzB;AAAA,MACA;AAAA,IACF;AAAA,EACF;AACF;AAEO,SAAS,wBACd,iBACsB;AACtB,QAAM,gBAAgB,gBAAgB,uBAAuB,GAAG;AAChE,MAAI,CAAC,eAAe;AAClB,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AACT;","names":[]}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
// src/schema/generate.ts
|
|
2
|
+
var typeMap = {
|
|
3
|
+
sqlite: {
|
|
4
|
+
text: { type: "text" },
|
|
5
|
+
integer: { type: "integer" },
|
|
6
|
+
boolean: { type: "integer", options: "{ mode: 'boolean' }" },
|
|
7
|
+
json: { type: "text", options: "{ mode: 'json' }" },
|
|
8
|
+
timestamp: { type: "integer", options: "{ mode: 'timestamp_ms' }" }
|
|
9
|
+
},
|
|
10
|
+
postgresql: {
|
|
11
|
+
text: { type: "text" },
|
|
12
|
+
integer: { type: "integer" },
|
|
13
|
+
boolean: { type: "boolean" },
|
|
14
|
+
json: { type: "jsonb" },
|
|
15
|
+
timestamp: { type: "timestamp" }
|
|
16
|
+
},
|
|
17
|
+
mysql: {
|
|
18
|
+
text: { type: "text" },
|
|
19
|
+
integer: { type: "int" },
|
|
20
|
+
boolean: { type: "boolean" },
|
|
21
|
+
json: { type: "json" },
|
|
22
|
+
timestamp: { type: "timestamp" }
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
var tableFactoryByDialect = {
|
|
26
|
+
sqlite: "sqliteTable",
|
|
27
|
+
postgresql: "pgTable",
|
|
28
|
+
mysql: "mysqlTable"
|
|
29
|
+
};
|
|
30
|
+
function renderTextSchema(model) {
|
|
31
|
+
const exportNameByTable = new Map(
|
|
32
|
+
model.tables.map((table) => [table.name, table.exportName ?? table.name])
|
|
33
|
+
);
|
|
34
|
+
const entries = model.tables.map((table) => {
|
|
35
|
+
const builder = tableFactoryByDialect[model.dialect];
|
|
36
|
+
const tableExpr = model.dialect === "sqlite" ? `${builder}("${table.name}", {` : `${builder}("${table.name}", {
|
|
37
|
+
`;
|
|
38
|
+
const row = table.columns.map((column) => {
|
|
39
|
+
const mappedDialect = typeMap[model.dialect];
|
|
40
|
+
if (!mappedDialect) {
|
|
41
|
+
throw new Error(`Unsupported dialect "${model.dialect}"`);
|
|
42
|
+
}
|
|
43
|
+
const mappedType = mappedDialect[column.type];
|
|
44
|
+
if (!mappedType) {
|
|
45
|
+
throw new Error(
|
|
46
|
+
`Unsupported column type "${column.type}" for dialect "${model.dialect}"`
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
const optionsSuffix = mappedType.options ? `, ${mappedType.options}` : "";
|
|
50
|
+
const defaultValue = column.defaultValue === null ? "default null" : "";
|
|
51
|
+
const required = column.nullable === true ? "" : ".notNull()";
|
|
52
|
+
const unique = column.unique ? ".unique()" : "";
|
|
53
|
+
const primary = column.primaryKey ? ".primaryKey()" : "";
|
|
54
|
+
const ref = column.references ? `.references(() => ${exportNameByTable.get(column.references.table) ?? column.references.table}.${column.references.field})` : "";
|
|
55
|
+
return ` ${column.name}: ${mappedType.type}("${column.name}"${optionsSuffix})${required}${defaultValue}${unique}${primary}${ref}`;
|
|
56
|
+
}).join(",\n");
|
|
57
|
+
const rows = row ? `
|
|
58
|
+
${row}
|
|
59
|
+
` : "\n";
|
|
60
|
+
const exportName = table.exportName ?? table.name;
|
|
61
|
+
return `export const ${exportName} = ${tableExpr}${rows}});`;
|
|
62
|
+
}).join("\n\n");
|
|
63
|
+
const imports = {
|
|
64
|
+
sqlite: 'import { integer, sqliteTable, text } from "drizzle-orm/sqlite-core";',
|
|
65
|
+
postgresql: 'import { boolean, integer, jsonb, pgTable, text, timestamp } from "drizzle-orm/pg-core";',
|
|
66
|
+
mysql: 'import { boolean, int, json, mysqlTable, text, timestamp } from "drizzle-orm/mysql-core";'
|
|
67
|
+
};
|
|
68
|
+
return `// This file is generated from Sandkit schema model.
|
|
69
|
+
// Provider: ${model.dialect}
|
|
70
|
+
// Version: ${model.version}
|
|
71
|
+
|
|
72
|
+
${imports[model.dialect]}
|
|
73
|
+
|
|
74
|
+
${entries}
|
|
75
|
+
|
|
76
|
+
export const sandkitSchema = {
|
|
77
|
+
${model.tables.map((table) => {
|
|
78
|
+
const exportName = table.exportName ?? table.name;
|
|
79
|
+
return ` ${exportName},`;
|
|
80
|
+
}).join("\n")}
|
|
81
|
+
};
|
|
82
|
+
`;
|
|
83
|
+
}
|
|
84
|
+
function createGeneratePayload(dialect, model) {
|
|
85
|
+
return {
|
|
86
|
+
dialect,
|
|
87
|
+
generatedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
88
|
+
summary: {
|
|
89
|
+
tableCount: model.tables.length,
|
|
90
|
+
tableNames: model.tables.map((table) => table.name)
|
|
91
|
+
},
|
|
92
|
+
schemaText: renderTextSchema(model)
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export {
|
|
97
|
+
renderTextSchema,
|
|
98
|
+
createGeneratePayload
|
|
99
|
+
};
|
|
100
|
+
//# sourceMappingURL=chunk-LC3IYBAL.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/schema/generate.ts"],"sourcesContent":["import type { SandkitSchemaModel, SandkitDialect } from \"./model\";\n\ninterface TypedColumnExpr {\n type: string;\n options?: string;\n}\n\ntype SchemaTypeMap = Record<\n string,\n {\n text: TypedColumnExpr;\n integer: TypedColumnExpr;\n boolean: TypedColumnExpr;\n json: TypedColumnExpr;\n timestamp: TypedColumnExpr;\n }\n>;\n\nconst typeMap: SchemaTypeMap = {\n sqlite: {\n text: { type: \"text\" },\n integer: { type: \"integer\" },\n boolean: { type: \"integer\", options: \"{ mode: 'boolean' }\" },\n json: { type: \"text\", options: \"{ mode: 'json' }\" },\n timestamp: { type: \"integer\", options: \"{ mode: 'timestamp_ms' }\" },\n },\n postgresql: {\n text: { type: \"text\" },\n integer: { type: \"integer\" },\n boolean: { type: \"boolean\" },\n json: { type: \"jsonb\" },\n timestamp: { type: \"timestamp\" },\n },\n mysql: {\n text: { type: \"text\" },\n integer: { type: \"int\" },\n boolean: { type: \"boolean\" },\n json: { type: \"json\" },\n timestamp: { type: \"timestamp\" },\n },\n} as const;\n\nconst tableFactoryByDialect = {\n sqlite: \"sqliteTable\",\n postgresql: \"pgTable\",\n mysql: \"mysqlTable\",\n} as const;\n\nexport function renderTextSchema(model: SandkitSchemaModel): string {\n const exportNameByTable = new Map(\n model.tables.map((table) => [table.name, table.exportName ?? table.name]),\n );\n\n const entries = model.tables\n .map((table) => {\n const builder = tableFactoryByDialect[model.dialect];\n const tableExpr =\n model.dialect === \"sqlite\"\n ? `${builder}(\"${table.name}\", {`\n : `${builder}(\"${table.name}\", {\\n`;\n\n const row = table.columns\n .map((column) => {\n const mappedDialect = typeMap[model.dialect];\n if (!mappedDialect) {\n throw new Error(`Unsupported dialect \"${model.dialect}\"`);\n }\n\n const mappedType = mappedDialect[column.type];\n if (!mappedType) {\n throw new Error(\n `Unsupported column type \"${column.type}\" for dialect \"${model.dialect}\"`,\n );\n }\n\n const optionsSuffix = mappedType.options ? `, ${mappedType.options}` : \"\";\n const defaultValue = column.defaultValue === null ? \"default null\" : \"\";\n const required = column.nullable === true ? \"\" : \".notNull()\";\n const unique = column.unique ? \".unique()\" : \"\";\n const primary = column.primaryKey ? \".primaryKey()\" : \"\";\n const ref = column.references\n ? `.references(() => ${\n exportNameByTable.get(column.references.table) ?? column.references.table\n }.${column.references.field})`\n : \"\";\n return ` ${column.name}: ${mappedType.type}(\"${column.name}\"${optionsSuffix})${required}${defaultValue}${unique}${primary}${ref}`;\n })\n .join(\",\\n\");\n\n const rows = row ? `\\n${row}\\n` : \"\\n\";\n const exportName = table.exportName ?? table.name;\n return `export const ${exportName} = ${tableExpr}${rows}});`;\n })\n .join(\"\\n\\n\");\n\n const imports = {\n sqlite: 'import { integer, sqliteTable, text } from \"drizzle-orm/sqlite-core\";',\n postgresql:\n 'import { boolean, integer, jsonb, pgTable, text, timestamp } from \"drizzle-orm/pg-core\";',\n mysql:\n 'import { boolean, int, json, mysqlTable, text, timestamp } from \"drizzle-orm/mysql-core\";',\n } as const;\n\n return `// This file is generated from Sandkit schema model.\\n// Provider: ${model.dialect}\\n// Version: ${model.version}\\n\\n${imports[model.dialect]}\\n\\n${entries}\\n\\nexport const sandkitSchema = {\\n${model.tables\n .map((table) => {\n const exportName = table.exportName ?? table.name;\n return ` ${exportName},`;\n })\n .join(\"\\n\")}\\n};\\n`;\n}\n\nexport function createGeneratePayload(dialect: SandkitDialect, model: SandkitSchemaModel) {\n return {\n dialect,\n generatedAt: new Date().toISOString(),\n summary: {\n tableCount: model.tables.length,\n tableNames: model.tables.map((table) => table.name),\n },\n schemaText: renderTextSchema(model),\n };\n}\n"],"mappings":";AAkBA,IAAM,UAAyB;AAAA,EAC7B,QAAQ;AAAA,IACN,MAAM,EAAE,MAAM,OAAO;AAAA,IACrB,SAAS,EAAE,MAAM,UAAU;AAAA,IAC3B,SAAS,EAAE,MAAM,WAAW,SAAS,sBAAsB;AAAA,IAC3D,MAAM,EAAE,MAAM,QAAQ,SAAS,mBAAmB;AAAA,IAClD,WAAW,EAAE,MAAM,WAAW,SAAS,2BAA2B;AAAA,EACpE;AAAA,EACA,YAAY;AAAA,IACV,MAAM,EAAE,MAAM,OAAO;AAAA,IACrB,SAAS,EAAE,MAAM,UAAU;AAAA,IAC3B,SAAS,EAAE,MAAM,UAAU;AAAA,IAC3B,MAAM,EAAE,MAAM,QAAQ;AAAA,IACtB,WAAW,EAAE,MAAM,YAAY;AAAA,EACjC;AAAA,EACA,OAAO;AAAA,IACL,MAAM,EAAE,MAAM,OAAO;AAAA,IACrB,SAAS,EAAE,MAAM,MAAM;AAAA,IACvB,SAAS,EAAE,MAAM,UAAU;AAAA,IAC3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KAAK,OAAO,IAAI,IAAI,aAAa,IAAI,QAAQ,GAAG,YAAY,GAAG,MAAM,GAAG,OAAO,GAAG,GAAG;AAAA,IAClI,CAAC,EACA,KAAK,KAAK;AAEb,UAAM,OAAO,MAAM;AAAA,EAAK,GAAG;AAAA,IAAO;AAClC,UAAM,aAAa,MAAM,cAAc,MAAM;AAC7C,WAAO,gBAAgB,UAAU,MAAM,SAAS,GAAG,IAAI;AAAA,EACzD,CAAC,EACA,KAAK,MAAM;AAEd,QAAM,UAAU;AAAA,IACd,QAAQ;AAAA,IACR,YACE;AAAA,IACF,OACE;AAAA,EACJ;AAEA,SAAO;AAAA,eAAsE,MAAM,OAAO;AAAA,cAAiB,MAAM,OAAO;AAAA;AAAA,EAAO,QAAQ,MAAM,OAAO,CAAC;AAAA;AAAA,EAAO,OAAO;AAAA;AAAA;AAAA,EAAuC,MAAM,OAC7M,IAAI,CAAC,UAAU;AACd,UAAM,aAAa,MAAM,cAAc,MAAM;AAC7C,WAAO,KAAK,UAAU;AAAA,EACxB,CAAC,EACA,KAAK,IAAI,CAAC;AAAA;AAAA;AACf;AAEO,SAAS,sBAAsB,SAAyB,OAA2B;AACxF,SAAO;AAAA,IACL;AAAA,IACA,cAAa,oBAAI,KAAK,GAAE,YAAY;AAAA,IACpC,SAAS;AAAA,MACP,YAAY,MAAM,OAAO;AAAA,MACzB,YAAY,MAAM,OAAO,IAAI,CAAC,UAAU,MAAM,IAAI;AAAA,IACpD;AAAA,IACA,YAAY,iBAAiB,KAAK;AAAA,EACpC;AACF;","names":[]}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import {
|
|
2
|
+
allowService
|
|
3
|
+
} from "./chunk-VISDS5T7.js";
|
|
4
|
+
|
|
5
|
+
// src/policies/ai-gateway.ts
|
|
6
|
+
var DEFAULT_AI_GATEWAY_BASE_URL = "https://ai-gateway.vercel.sh/v1";
|
|
7
|
+
function resolveAiGatewayBaseUrl(baseUrl) {
|
|
8
|
+
const provided = (baseUrl ?? process.env.AI_GATEWAY_BASE_URL ?? DEFAULT_AI_GATEWAY_BASE_URL).trim();
|
|
9
|
+
if (!provided) {
|
|
10
|
+
throw new Error("aiGateway() requires a non-empty base URL.");
|
|
11
|
+
}
|
|
12
|
+
return provided;
|
|
13
|
+
}
|
|
14
|
+
function resolveAiGatewayBaseDomains(baseUrl) {
|
|
15
|
+
let parsed;
|
|
16
|
+
try {
|
|
17
|
+
parsed = new URL(baseUrl);
|
|
18
|
+
} catch {
|
|
19
|
+
throw new Error(`aiGateway() received an invalid base URL: ${baseUrl}`);
|
|
20
|
+
}
|
|
21
|
+
const hostname = parsed.hostname.trim().toLowerCase();
|
|
22
|
+
if (!hostname) {
|
|
23
|
+
throw new Error("aiGateway() requires a URL with a valid hostname.");
|
|
24
|
+
}
|
|
25
|
+
return [hostname, `*.${hostname}`];
|
|
26
|
+
}
|
|
27
|
+
function resolveAiGatewayCredential() {
|
|
28
|
+
return { kind: "default" };
|
|
29
|
+
}
|
|
30
|
+
function resolveAiGatewayDefaultApiKey() {
|
|
31
|
+
return process.env.AI_GATEWAY_API_KEY;
|
|
32
|
+
}
|
|
33
|
+
function aiGateway(options) {
|
|
34
|
+
const configuredBaseUrl = resolveAiGatewayBaseUrl(options?.baseUrl);
|
|
35
|
+
return {
|
|
36
|
+
id: "aiGateway",
|
|
37
|
+
name: "AI Gateway",
|
|
38
|
+
description: "Allow outbound access to the configured AI Gateway endpoint host.",
|
|
39
|
+
domains: resolveAiGatewayBaseDomains(configuredBaseUrl),
|
|
40
|
+
headers: [
|
|
41
|
+
{
|
|
42
|
+
headerName: "authorization",
|
|
43
|
+
valuePrefix: "Bearer ",
|
|
44
|
+
credential: resolveAiGatewayCredential()
|
|
45
|
+
}
|
|
46
|
+
]
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
function allowAiGateway() {
|
|
50
|
+
return allowService(aiGateway());
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export {
|
|
54
|
+
resolveAiGatewayDefaultApiKey,
|
|
55
|
+
aiGateway,
|
|
56
|
+
allowAiGateway
|
|
57
|
+
};
|
|
58
|
+
//# sourceMappingURL=chunk-REGOUXVI.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/policies/ai-gateway.ts"],"sourcesContent":["import { allowService } from \"./dsl.ts\";\nimport type { PolicyServiceDescriptor, WorkspacePolicy } from \"./types.ts\";\n\nconst DEFAULT_AI_GATEWAY_BASE_URL = \"https://ai-gateway.vercel.sh/v1\";\n\nexport interface AiGatewayOptions {\n readonly baseUrl?: string;\n}\n\nfunction resolveAiGatewayBaseUrl(baseUrl?: string): string {\n const provided = (\n baseUrl ??\n process.env.AI_GATEWAY_BASE_URL ??\n DEFAULT_AI_GATEWAY_BASE_URL\n ).trim();\n if (!provided) {\n throw new Error(\"aiGateway() requires a non-empty base URL.\");\n }\n return provided;\n}\n\nfunction resolveAiGatewayBaseDomains(baseUrl: string): string[] {\n let parsed: URL;\n try {\n parsed = new URL(baseUrl);\n } catch {\n throw new Error(`aiGateway() received an invalid base URL: ${baseUrl}`);\n }\n\n const hostname = parsed.hostname.trim().toLowerCase();\n\n if (!hostname) {\n throw new Error(\"aiGateway() requires a URL with a valid hostname.\");\n }\n\n // Use hostname only for policy matching; ports are intentionally ignored so allow-lists\n // stay compatible with Vercel Sandbox host/domain matching.\n return [hostname, `*.${hostname}`];\n}\n\nfunction resolveAiGatewayCredential(): { kind: \"default\" } {\n return { kind: \"default\" };\n}\n\nexport function resolveAiGatewayDefaultApiKey(): string | undefined {\n return process.env.AI_GATEWAY_API_KEY;\n}\n\n/**\n * Allow outbound access to the currently configured AI Gateway endpoint host/domain.\n * The configured endpoint is not treated as a generic capability; it follows\n * `AI_GATEWAY_BASE_URL` and derives allowed host/domain entries from its hostname.\n */\nexport function aiGateway(options?: AiGatewayOptions): PolicyServiceDescriptor {\n const configuredBaseUrl = resolveAiGatewayBaseUrl(options?.baseUrl);\n\n return {\n id: \"aiGateway\",\n name: \"AI Gateway\",\n description: \"Allow outbound access to the configured AI Gateway endpoint host.\",\n domains: resolveAiGatewayBaseDomains(configuredBaseUrl),\n headers: [\n {\n headerName: \"authorization\",\n valuePrefix: \"Bearer \",\n credential: resolveAiGatewayCredential(),\n },\n ],\n };\n}\n\nexport function allowAiGateway(): WorkspacePolicy {\n return allowService(aiGateway());\n}\n"],"mappings":";;;;;AAGA,IAAM,8BAA8B;AAMpC,SAAS,wBAAwB,SAA0B;AACzD,QAAM,YACJ,WACA,QAAQ,IAAI,uBACZ,6BACA,KAAK;AACP,MAAI,CAAC,UAAU;AACb,UAAM,IAAI,MAAM,4CAA4C;AAAA,EAC9D;AACA,SAAO;AACT;AAEA,SAAS,4BAA4B,SAA2B;AAC9D,MAAI;AACJ,MAAI;AACF,aAAS,IAAI,IAAI,OAAO;AAAA,EAC1B,QAAQ;AACN,UAAM,IAAI,MAAM,6CAA6C,OAAO,EAAE;AAAA,EACxE;AAEA,QAAM,WAAW,OAAO,SAAS,KAAK,EAAE,YAAY;AAEpD,MAAI,CAAC,UAAU;AACb,UAAM,IAAI,MAAM,mDAAmD;AAAA,EACrE;AAIA,SAAO,CAAC,UAAU,KAAK,QAAQ,EAAE;AACnC;AAEA,SAAS,6BAAkD;AACzD,SAAO,EAAE,MAAM,UAAU;AAC3B;AAEO,SAAS,gCAAoD;AAClE,SAAO,QAAQ,IAAI;AACrB;AAOO,SAAS,UAAU,SAAqD;AAC7E,QAAM,oBAAoB,wBAAwB,SAAS,OAAO;AAElE,SAAO;AAAA,IACL,IAAI;AAAA,IACJ,MAAM;AAAA,IACN,aAAa;AAAA,IACb,SAAS,4BAA4B,iBAAiB;AAAA,IACtD,SAAS;AAAA,MACP;AAAA,QACE,YAAY;AAAA,QACZ,aAAa;AAAA,QACb,YAAY,2BAA2B;AAAA,MACzC;AAAA,IACF;AAAA,EACF;AACF;AAEO,SAAS,iBAAkC;AAChD,SAAO,aAAa,UAAU,CAAC;AACjC;","names":[]}
|