mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-11-23 03:06:57 +00:00
Merge pull request #1 from shumaiOne/feat/sandbox-integration-v2
feat(agent): integrate sandboxed bash tool and sandbox settings
This commit is contained in:
@@ -0,0 +1 @@
|
||||
src/generated/** linguist-generated
|
||||
@@ -29,6 +29,11 @@ jobs:
|
||||
- name: Install dependencies
|
||||
run: bun install
|
||||
|
||||
- name: Install system dependencies
|
||||
run: |
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y ripgrep bubblewrap socat
|
||||
|
||||
- name: Lint
|
||||
run: bun run lint
|
||||
|
||||
|
||||
@@ -25,6 +25,9 @@ WORKDIR /app
|
||||
COPY --from=mwader/static-ffmpeg:8.1 /ffmpeg /usr/local/bin/
|
||||
COPY --from=mwader/static-ffmpeg:8.1 /ffprobe /usr/local/bin/
|
||||
|
||||
# Install system dependencies for sandbox runtime
|
||||
RUN apt-get update && apt-get install -y ripgrep bubblewrap socat && rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# Copy sharp/img from builder (they are native and already installed)
|
||||
COPY --from=builder /app/node_modules/sharp ./node_modules/sharp
|
||||
COPY --from=builder /app/node_modules/@img ./node_modules/@img
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
"": {
|
||||
"name": "shumai",
|
||||
"dependencies": {
|
||||
"@anthropic-ai/sandbox-runtime": "^0.0.52",
|
||||
"@aws-sdk/client-s3": "^3.1031.0",
|
||||
"@aws-sdk/s3-request-presigner": "^3.1031.0",
|
||||
"@dnd-kit/dom": "^0.4.0",
|
||||
@@ -152,6 +153,8 @@
|
||||
"packages": {
|
||||
"@alloc/quick-lru": ["@alloc/quick-lru@5.2.0", "", {}, "sha512-UrcABB+4bUrFABwbluTIBErXwvbsU/V7TZWfmbgJfbkwiBuziS9gxdODUyuiecfdGQ85jglMW6juS3+z5TsKLw=="],
|
||||
|
||||
"@anthropic-ai/sandbox-runtime": ["@anthropic-ai/sandbox-runtime@0.0.52", "", { "dependencies": { "@pondwader/socks5-server": "^1.0.10", "commander": "^12.1.0", "node-forge": "^1.4.0", "shell-quote": "^1.8.3", "zod": "^3.24.1" }, "bin": { "srt": "dist/cli.js" } }, "sha512-vYaM7OslFmOAzNgfy5gxvt3NoWFeCbr7C0AKyuduQq7Gdxbg2NnYmE7deBf8Nxj3ZNECTcC5RhAfz0lZwvbtBA=="],
|
||||
|
||||
"@anthropic-ai/sdk": ["@anthropic-ai/sdk@0.90.0", "", { "dependencies": { "json-schema-to-ts": "^3.1.1" }, "peerDependencies": { "zod": "^3.25.0 || ^4.0.0" }, "optionalPeers": ["zod"], "bin": { "anthropic-ai-sdk": "bin/cli" } }, "sha512-MzZtPabJF1b0FTDl6Z6H5ljphPwACLGP13lu8MTiB8jXaW/YXlpOp+Po2cVou3MPM5+f5toyLnul9whKCy7fBg=="],
|
||||
|
||||
"@apidevtools/json-schema-ref-parser": ["@apidevtools/json-schema-ref-parser@14.0.1", "", { "dependencies": { "@types/json-schema": "^7.0.15", "js-yaml": "^4.1.0" } }, "sha512-Oc96zvmxx1fqoSEdUmfmvvb59/KDOnUoJ7s2t7bISyAn0XEz57LCCw8k2Y4Pf3mwKaZLMciESALORLgfe2frCw=="],
|
||||
@@ -704,6 +707,8 @@
|
||||
|
||||
"@pkgr/core": ["@pkgr/core@0.2.9", "", {}, "sha512-QNqXyfVS2wm9hweSYD2O7F0G06uurj9kZ96TRQE5Y9hU7+tgdZwIkbAKc5Ocy1HxEY2kuDQa6cQ1WRs/O5LFKA=="],
|
||||
|
||||
"@pondwader/socks5-server": ["@pondwader/socks5-server@1.0.10", "", {}, "sha512-bQY06wzzR8D2+vVCUoBsr5QS2U6UgPUQRmErNwtsuI6vLcyRKkafjkr3KxbtGFf9aBBIV2mcvlsKD1UYaIV+sg=="],
|
||||
|
||||
"@preact/signals-core": ["@preact/signals-core@1.14.1", "", {}, "sha512-vxPpfXqrwUe9lpjqfYNjAF/0RF/eFGeLgdJzdmIIZjpOnTmGmAB4BjWone562mJGMRP4frU6iZ6ei3PDsu52Ng=="],
|
||||
|
||||
"@prisma/adapter-pg": ["@prisma/adapter-pg@7.7.0", "", { "dependencies": { "@prisma/driver-adapter-utils": "7.7.0", "@types/pg": "^8.16.0", "pg": "^8.16.3", "postgres-array": "3.0.4" } }, "sha512-q33Ta8sKbgzEpAy0lx45tAq//yMv0qcb+8nj+TCA3P4wiAY+OBFEFk/NDkZncAfHaNJeGo5WJpJdpbL+ijYx8g=="],
|
||||
@@ -2364,6 +2369,8 @@
|
||||
|
||||
"node-fetch-native": ["node-fetch-native@1.6.7", "", {}, "sha512-g9yhqoedzIUm0nTnTqAQvueMPVOuIY16bqgAJJC8XOOubYFNwz6IER9qs0Gq2Xd0+CecCKFjtdDTMA4u4xG06Q=="],
|
||||
|
||||
"node-forge": ["node-forge@1.4.0", "", {}, "sha512-LarFH0+6VfriEhqMMcLX2F7SwSXeWwnEAJEsYm5QKWchiVYVvJyV9v7UDvUv+w5HO23ZpQTXDv/GxdDdMyOuoQ=="],
|
||||
|
||||
"node-readfiles": ["node-readfiles@0.2.0", "", { "dependencies": { "es6-promise": "^3.2.1" } }, "sha512-SU00ZarexNlE4Rjdm83vglt5Y9yiQ+XI1XpflWlb7q7UTN1JUItm69xMeiQCTxtTfnzt+83T8Cx+vI2ED++VDA=="],
|
||||
|
||||
"node-releases": ["node-releases@2.0.37", "", {}, "sha512-1h5gKZCF+pO/o3Iqt5Jp7wc9rH3eJJ0+nh/CIoiRwjRxde/hAHyLPXYN4V3CqKAbiZPSeJFSWHmJsbkicta0Eg=="],
|
||||
@@ -2688,6 +2695,8 @@
|
||||
|
||||
"shebang-regex": ["shebang-regex@3.0.0", "", {}, "sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A=="],
|
||||
|
||||
"shell-quote": ["shell-quote@1.8.3", "", {}, "sha512-ObmnIF4hXNg1BqhnHmgbDETF8dLPCggZWBjkQfhZpbszZnYur5DUljTcCHii5LC3J5E0yeO/1LIMyH+UvHQgyw=="],
|
||||
|
||||
"should": ["should@13.2.3", "", { "dependencies": { "should-equal": "^2.0.0", "should-format": "^3.0.3", "should-type": "^1.4.0", "should-type-adaptors": "^1.0.1", "should-util": "^1.0.0" } }, "sha512-ggLesLtu2xp+ZxI+ysJTmNjh2U0TsC+rQ/pfED9bUZZ4DKefP27D+7YJVVTvKsmjLpIi9jAa7itwDGkDDmt1GQ=="],
|
||||
|
||||
"should-equal": ["should-equal@2.0.0", "", { "dependencies": { "should-type": "^1.4.0" } }, "sha512-ZP36TMrK9euEuWQYBig9W55WPC7uo37qzAEmbjHz4gfyuXrEUgF8cUvQVO+w+d3OMfPvSRQJ22lSm8MQJ43LTA=="],
|
||||
@@ -3048,6 +3057,10 @@
|
||||
|
||||
"zwitch": ["zwitch@2.0.4", "", {}, "sha512-bXE4cR/kVZhKZX/RjPEflHaKVhUVl85noU3v6b8apfQEc1x4A+zBxjZ4lN8LqGd6WZ3dl98pY4o717VFmoPp+A=="],
|
||||
|
||||
"@anthropic-ai/sandbox-runtime/commander": ["commander@12.1.0", "", {}, "sha512-Vw8qHK3bZM9y/P10u3Vib8o/DdkvA2OtPtZvD871QKjy74Wj1WSKFILMPRPSdUSx5RFK1arlJzEtA4PkFgnbuA=="],
|
||||
|
||||
"@anthropic-ai/sandbox-runtime/zod": ["zod@3.25.76", "", {}, "sha512-gzUt/qt81nXsFGKIFcC3YnfEAx5NkunCfnDlvuBSSFS02bcXu4Lmea0AFIUwbLWxWPx3d9p8S5QoaujKcNQxcQ=="],
|
||||
|
||||
"@apidevtools/swagger-parser/ajv": ["ajv@8.18.0", "", { "dependencies": { "fast-deep-equal": "^3.1.3", "fast-uri": "^3.0.1", "json-schema-traverse": "^1.0.0", "require-from-string": "^2.0.2" } }, "sha512-PlXPeEWMXMZ7sPYOHqmDyCJzcfNrUr3fGNKtezX14ykXOEIvyK81d+qydx89KY5O71FKMPaQ2vBfBFI5NHR63A=="],
|
||||
|
||||
"@aws-crypto/sha1-browser/@smithy/util-utf8": ["@smithy/util-utf8@2.3.0", "", { "dependencies": { "@smithy/util-buffer-from": "^2.2.0", "tslib": "^2.6.2" } }, "sha512-R8Rdn8Hy72KKcebgLiv8jQcQkXoLMOGGv5uI1/k0l+snqkOzQ1R0ChUBCxWMlBsFMekWjq0wRudIweFs7sKT5A=="],
|
||||
|
||||
@@ -88,7 +88,11 @@ services:
|
||||
ports:
|
||||
- '7233:7233'
|
||||
healthcheck:
|
||||
test: ["CMD-SHELL", "temporal operator cluster health --address localhost:7233 || temporal operator cluster health --address $$(hostname -i):7233"]
|
||||
test:
|
||||
[
|
||||
'CMD-SHELL',
|
||||
'temporal operator cluster health --address localhost:7233 || temporal operator cluster health --address $$(hostname -i):7233',
|
||||
]
|
||||
interval: 5s
|
||||
timeout: 5s
|
||||
start_period: 30s
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
"build": "bun run build.ts"
|
||||
},
|
||||
"dependencies": {
|
||||
"@anthropic-ai/sandbox-runtime": "^0.0.52",
|
||||
"@aws-sdk/client-s3": "^3.1031.0",
|
||||
"@aws-sdk/s3-request-presigner": "^3.1031.0",
|
||||
"@dnd-kit/dom": "^0.4.0",
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
-- CreateTable
|
||||
CREATE TABLE "sandboxes" (
|
||||
"id" TEXT NOT NULL,
|
||||
"allowedDomains" TEXT[] DEFAULT ARRAY['github.com', 'api.github.com', 'raw.githubusercontent.com']::TEXT[],
|
||||
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"updated_at" TIMESTAMP(3) NOT NULL,
|
||||
"team_id" TEXT NOT NULL,
|
||||
|
||||
CONSTRAINT "sandboxes_pkey" PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "sandboxes_team_id_key" ON "sandboxes"("team_id");
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "sandboxes" ADD CONSTRAINT "sandboxes_team_id_fkey" FOREIGN KEY ("team_id") REFERENCES "teams"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
@@ -0,0 +1,2 @@
|
||||
-- AlterTable
|
||||
ALTER TABLE "sandboxes" ALTER COLUMN "allowedDomains" SET DEFAULT ARRAY['npmjs.org', '*.npmjs.org', 'registry.npmjs.org', 'registry.yarnpkg.com', 'pypi.org', '*.pypi.org', 'github.com', '*.github.com', 'api.github.com', 'raw.githubusercontent.com']::TEXT[];
|
||||
@@ -219,10 +219,23 @@ model Team {
|
||||
userMetadata UserMetadata[] @relation("TeamToUserMetadata")
|
||||
providers Provider[] @relation("TeamToProvider")
|
||||
skills Skill[] @relation("TeamToSkill")
|
||||
sandbox Sandbox? @relation("TeamToSandbox")
|
||||
|
||||
@@map("teams")
|
||||
}
|
||||
|
||||
model Sandbox {
|
||||
id String @id @default(ulid())
|
||||
allowedDomains String[] @default(["npmjs.org", "*.npmjs.org", "registry.npmjs.org", "registry.yarnpkg.com", "pypi.org", "*.pypi.org", "github.com", "*.github.com", "api.github.com", "raw.githubusercontent.com"])
|
||||
createdAt DateTime @default(now()) @map("created_at")
|
||||
updatedAt DateTime @updatedAt @map("updated_at")
|
||||
|
||||
teamId String @unique @map("team_id")
|
||||
team Team @relation("TeamToSandbox", fields: [teamId], references: [id], onDelete: Cascade)
|
||||
|
||||
@@map("sandboxes")
|
||||
}
|
||||
|
||||
model Skill {
|
||||
id String @id @default(ulid())
|
||||
name String
|
||||
|
||||
@@ -85,9 +85,7 @@ describe('DatabaseSessionManager', () => {
|
||||
type: 'message',
|
||||
message: {
|
||||
role: 'toolResult',
|
||||
content: [
|
||||
{ type: 'image', data: '__S3_DATA__' },
|
||||
],
|
||||
content: [{ type: 'image', data: '__S3_DATA__' }],
|
||||
details: { sourceKeys: ['key1'] },
|
||||
},
|
||||
}
|
||||
@@ -110,8 +108,10 @@ describe('DatabaseSessionManager', () => {
|
||||
const context = manager.buildSessionContext()
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
const reInjectedMessage = context.messages[0] as any
|
||||
|
||||
expect(reInjectedMessage.content[0].data).toBe(Buffer.from('fake-image-data').toString('base64'))
|
||||
|
||||
expect(reInjectedMessage.content[0].data).toBe(
|
||||
Buffer.from('fake-image-data').toString('base64'),
|
||||
)
|
||||
expect(s3Service.getObject).toHaveBeenCalledWith(expect.any(String), 'key1')
|
||||
})
|
||||
|
||||
@@ -143,4 +143,19 @@ describe('DatabaseSessionManager', () => {
|
||||
expect(context.messages[0].content).toBe('M1')
|
||||
expect(context.messages[1].content).toBe('M2')
|
||||
})
|
||||
|
||||
it('handles skill environment variables', async () => {
|
||||
const manager = await DatabaseSessionManager.create({ agentId })
|
||||
const envs = { TEST_VAR: 'test_value', OTHER_VAR: 'other_value' }
|
||||
|
||||
manager.addSkillEnvs(envs)
|
||||
expect(manager.getSkillEnvs()).toEqual(envs)
|
||||
|
||||
manager.addSkillEnvs({ TEST_VAR: 'new_value', NEW_VAR: 'new' })
|
||||
expect(manager.getSkillEnvs()).toEqual({
|
||||
TEST_VAR: 'new_value',
|
||||
OTHER_VAR: 'other_value',
|
||||
NEW_VAR: 'new',
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -5,6 +5,7 @@ import { SessionEntry, SessionManager } from '@mariozechner/pi-coding-agent'
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
export class DatabaseSessionManager extends (SessionManager as any) {
|
||||
private dbSessionId: string
|
||||
private skillEnvs: Record<string, string> = {}
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
private writeQueue: Promise<any> = Promise.resolve()
|
||||
|
||||
@@ -13,6 +14,14 @@ export class DatabaseSessionManager extends (SessionManager as any) {
|
||||
this.dbSessionId = sessionId
|
||||
}
|
||||
|
||||
addSkillEnvs(envs: Record<string, string>) {
|
||||
this.skillEnvs = { ...this.skillEnvs, ...envs }
|
||||
}
|
||||
|
||||
getSkillEnvs() {
|
||||
return this.skillEnvs
|
||||
}
|
||||
|
||||
static async create(params: {
|
||||
agentId: string
|
||||
userId?: string
|
||||
@@ -46,7 +55,10 @@ export class DatabaseSessionManager extends (SessionManager as any) {
|
||||
if (item.type === 'image' && item.data === '__S3_DATA__' && sourceKeys[keyIdx]) {
|
||||
const key = sourceKeys[keyIdx]
|
||||
try {
|
||||
const { buffer } = await s3Service.getObject(process.env.S3_BUCKET || 'shumai', key)
|
||||
const { buffer } = await s3Service.getObject(
|
||||
process.env.S3_BUCKET || 'shumai',
|
||||
key,
|
||||
)
|
||||
item.data = buffer.toString('base64')
|
||||
} catch (err) {
|
||||
console.error(`Failed to re-inject image data for key ${key}:`, err)
|
||||
|
||||
+46
-8
@@ -1,26 +1,26 @@
|
||||
import { prisma } from '@/db'
|
||||
import { logger } from '@/logger'
|
||||
import { Usage } from '@/services/ai/provider/provider'
|
||||
import { s3Service } from '@/services/s3/s3'
|
||||
import { SandboxManager } from '@anthropic-ai/sandbox-runtime'
|
||||
import { getModel, type ImageContent, type TextContent } from '@mariozechner/pi-ai'
|
||||
import {
|
||||
AuthStorage,
|
||||
createAgentSession,
|
||||
DefaultResourceLoader,
|
||||
defineTool,
|
||||
ModelRegistry,
|
||||
SessionManager,
|
||||
SettingsManager,
|
||||
defineTool,
|
||||
type ToolDefinition,
|
||||
} from '@mariozechner/pi-coding-agent'
|
||||
import { Type, type TSchema } from '@sinclair/typebox'
|
||||
import * as fs from 'fs'
|
||||
import * as path from 'path'
|
||||
import { DatabaseSessionManager } from './database-session-manager'
|
||||
import { analyzeAssetMediaTool } from './tools/analyze-asset-media'
|
||||
import { readSkillTool } from './tools/read-skill'
|
||||
import { Usage } from '@/services/ai/provider/provider'
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
export type Tool = any
|
||||
import { createReadSkillTool } from './tools/read-skill'
|
||||
import { createSandboxedBashTool } from './tools/sandboxed-bash'
|
||||
|
||||
export interface AutofillField {
|
||||
id: string
|
||||
@@ -37,6 +37,12 @@ export class AgentExecutor {
|
||||
})
|
||||
}
|
||||
|
||||
private async getSandbox(teamId: string) {
|
||||
return this.prismaClient.sandbox.findUnique({
|
||||
where: { teamId },
|
||||
})
|
||||
}
|
||||
|
||||
async chat(teamId: string, prompt: string): Promise<{ text: string; usage: Usage }> {
|
||||
const agent = await this.prismaClient.agent.findFirst({
|
||||
where: {
|
||||
@@ -64,7 +70,7 @@ export class AgentExecutor {
|
||||
agentsInstruction: string,
|
||||
sessionId?: string,
|
||||
userId?: string,
|
||||
tools: Tool[] = [],
|
||||
tools: ToolDefinition[] = [],
|
||||
): Promise<{ text: string; usage: Usage; sessionId: string }> {
|
||||
const t = await this.getTeam(teamId)
|
||||
if (!t) throw new Error('failed to get team')
|
||||
@@ -163,6 +169,33 @@ export class AgentExecutor {
|
||||
cwd: process.cwd(),
|
||||
})
|
||||
|
||||
const sandbox = await this.getSandbox(teamId)
|
||||
const allowedDomains = sandbox?.allowedDomains || []
|
||||
|
||||
const piDir = path.join(process.cwd(), '.pi')
|
||||
if (!fs.existsSync(piDir)) fs.mkdirSync(piDir, { recursive: true })
|
||||
|
||||
const allowWrite = [piDir, '/tmp']
|
||||
|
||||
// NOTE: SandboxManager.initialize is a global operation that applies to the entire process.
|
||||
// anthropic-experimental/sandbox-runtime currently does not support separate managers per session/team.
|
||||
// Since this application is not designed for multi-tenancy at the process level (i.e. only one
|
||||
// team's chat happens at a time per worker instance), re-initializing here with current team's
|
||||
// settings is acceptable.
|
||||
await SandboxManager.initialize({
|
||||
network: {
|
||||
allowedDomains,
|
||||
deniedDomains: [],
|
||||
},
|
||||
filesystem: {
|
||||
allowWrite,
|
||||
denyWrite: ['.env', '.env.*', '*.pem', '*.key'],
|
||||
denyRead: ['~/.ssh', '~/.aws', '~/.gnupg'],
|
||||
},
|
||||
})
|
||||
|
||||
const sandboxedBash = createSandboxedBashTool(process.cwd(), sessionManager)
|
||||
|
||||
const { session } = await createAgentSession({
|
||||
cwd: process.cwd(),
|
||||
agentDir,
|
||||
@@ -172,7 +205,12 @@ export class AgentExecutor {
|
||||
resourceLoader,
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
sessionManager: sessionManager as any as SessionManager,
|
||||
customTools: [analyzeAssetMediaTool, readSkillTool, ...tools],
|
||||
customTools: [
|
||||
analyzeAssetMediaTool,
|
||||
createReadSkillTool(sessionManager),
|
||||
sandboxedBash,
|
||||
...tools,
|
||||
],
|
||||
})
|
||||
const content: (TextContent | ImageContent)[] = []
|
||||
|
||||
|
||||
@@ -36,7 +36,10 @@ describe('analyzeAssetMediaTool', () => {
|
||||
const buffer = Buffer.from([
|
||||
0x00, 0x00, 0x00, 0x18, 0x66, 0x74, 0x79, 0x70, 0x69, 0x73, 0x6f, 0x6d,
|
||||
])
|
||||
vi.mocked(s3Service.getObject).mockResolvedValue({ buffer, contentType: 'application/octet-stream' })
|
||||
vi.mocked(s3Service.getObject).mockResolvedValue({
|
||||
buffer,
|
||||
contentType: 'application/octet-stream',
|
||||
})
|
||||
|
||||
const result = await analyzeAssetMediaTool.execute(
|
||||
'1',
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { describe, it, expect, vi, beforeEach } from 'vitest'
|
||||
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest'
|
||||
import { prisma } from '@/db'
|
||||
import { setupTestDbHooks } from '@/db-test-hooks'
|
||||
import { readSkillTool } from './read-skill'
|
||||
import { createReadSkillTool } from './read-skill'
|
||||
import { s3Service } from '@/services/s3/s3'
|
||||
import * as fs from 'fs'
|
||||
|
||||
@@ -18,11 +18,17 @@ vi.mock('adm-zip', () => {
|
||||
describe('readSkillTool', () => {
|
||||
setupTestDbHooks()
|
||||
|
||||
const mockSessionManager = {
|
||||
addSkillEnvs: vi.fn(),
|
||||
}
|
||||
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks()
|
||||
})
|
||||
|
||||
it('should return error if skill not found', async () => {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
const readSkillTool = createReadSkillTool(mockSessionManager as any)
|
||||
const result = await readSkillTool.execute(
|
||||
'1',
|
||||
{ skillId: 'non-existent' },
|
||||
@@ -54,6 +60,8 @@ describe('readSkillTool', () => {
|
||||
return ''
|
||||
})
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
const readSkillTool = createReadSkillTool(mockSessionManager as any)
|
||||
const result = await readSkillTool.execute(
|
||||
'1',
|
||||
{ skillId: skill.id },
|
||||
@@ -102,8 +110,13 @@ describe('readSkillTool', () => {
|
||||
})
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- mocking s3Service return
|
||||
;(s3Service.getObject as any).mockResolvedValue({ buffer: Buffer.from('zipdata'), contentType: 'application/zip' })
|
||||
;(s3Service.getObject as any).mockResolvedValue({
|
||||
buffer: Buffer.from('zipdata'),
|
||||
contentType: 'application/zip',
|
||||
})
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
const readSkillTool = createReadSkillTool(mockSessionManager as any)
|
||||
const result = await readSkillTool.execute(
|
||||
'1',
|
||||
{ skillId: skill.id },
|
||||
@@ -118,4 +131,176 @@ describe('readSkillTool', () => {
|
||||
expect(s3Service.getObject).toHaveBeenCalled()
|
||||
expect(fs.writeFileSync).toHaveBeenCalledWith(expect.stringContaining('.hash'), 'new-hash')
|
||||
})
|
||||
|
||||
describe('environment variables', () => {
|
||||
let originalEnv: NodeJS.ProcessEnv
|
||||
|
||||
beforeEach(() => {
|
||||
originalEnv = { ...process.env }
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
process.env = originalEnv
|
||||
})
|
||||
|
||||
it('should use user-configured value if it is non-empty', async () => {
|
||||
const team = await prisma.team.create({ data: { name: 'Test Team' } })
|
||||
const skill = await prisma.skill.create({
|
||||
data: {
|
||||
name: 'Skill Env Test 1',
|
||||
assetId: 'asset1',
|
||||
hash: 'hash1',
|
||||
teamId: team.id,
|
||||
config: {
|
||||
environmentVariables: [{ name: 'CONFIGURED_VAR', default: 'user-val' }],
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
delete process.env.CONFIGURED_VAR
|
||||
|
||||
vi.spyOn(fs, 'existsSync').mockReturnValue(true)
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- mocking node fs readFileSync which has complex overloaded signatures
|
||||
vi.spyOn(fs, 'readFileSync').mockImplementation((path: any) => {
|
||||
if (path.toString().endsWith('.hash')) return 'hash1'
|
||||
if (path.toString().endsWith('SKILL.md')) return '# Content'
|
||||
return ''
|
||||
})
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
const readSkillTool = createReadSkillTool(mockSessionManager as any)
|
||||
await readSkillTool.execute(
|
||||
'1',
|
||||
{ skillId: skill.id },
|
||||
undefined,
|
||||
undefined,
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
{} as unknown as any,
|
||||
)
|
||||
|
||||
expect(mockSessionManager.addSkillEnvs).toHaveBeenCalledWith({
|
||||
CONFIGURED_VAR: 'user-val',
|
||||
})
|
||||
})
|
||||
|
||||
it('should favor user-configured value even if host environment variable is also defined', async () => {
|
||||
const team = await prisma.team.create({ data: { name: 'Test Team' } })
|
||||
const skill = await prisma.skill.create({
|
||||
data: {
|
||||
name: 'Skill Env Test 2',
|
||||
assetId: 'asset1',
|
||||
hash: 'hash2',
|
||||
teamId: team.id,
|
||||
config: {
|
||||
environmentVariables: [{ name: 'OVERRIDDEN_VAR', default: 'user-val' }],
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
process.env.OVERRIDDEN_VAR = 'host-val'
|
||||
|
||||
vi.spyOn(fs, 'existsSync').mockReturnValue(true)
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- mocking node fs readFileSync which has complex overloaded signatures
|
||||
vi.spyOn(fs, 'readFileSync').mockImplementation((path: any) => {
|
||||
if (path.toString().endsWith('.hash')) return 'hash2'
|
||||
if (path.toString().endsWith('SKILL.md')) return '# Content'
|
||||
return ''
|
||||
})
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
const readSkillTool = createReadSkillTool(mockSessionManager as any)
|
||||
await readSkillTool.execute(
|
||||
'1',
|
||||
{ skillId: skill.id },
|
||||
undefined,
|
||||
undefined,
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
{} as unknown as any,
|
||||
)
|
||||
|
||||
expect(mockSessionManager.addSkillEnvs).toHaveBeenCalledWith({
|
||||
OVERRIDDEN_VAR: 'user-val',
|
||||
})
|
||||
})
|
||||
|
||||
it('should fall back to host environment variable if user-configured value is empty string', async () => {
|
||||
const team = await prisma.team.create({ data: { name: 'Test Team' } })
|
||||
const skill = await prisma.skill.create({
|
||||
data: {
|
||||
name: 'Skill Env Test 3',
|
||||
assetId: 'asset1',
|
||||
hash: 'hash3',
|
||||
teamId: team.id,
|
||||
config: {
|
||||
environmentVariables: [{ name: 'FALLBACK_VAR', default: '' }],
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
process.env.FALLBACK_VAR = 'host-val'
|
||||
|
||||
vi.spyOn(fs, 'existsSync').mockReturnValue(true)
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- mocking node fs readFileSync which has complex overloaded signatures
|
||||
vi.spyOn(fs, 'readFileSync').mockImplementation((path: any) => {
|
||||
if (path.toString().endsWith('.hash')) return 'hash3'
|
||||
if (path.toString().endsWith('SKILL.md')) return '# Content'
|
||||
return ''
|
||||
})
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
const readSkillTool = createReadSkillTool(mockSessionManager as any)
|
||||
await readSkillTool.execute(
|
||||
'1',
|
||||
{ skillId: skill.id },
|
||||
undefined,
|
||||
undefined,
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
{} as unknown as any,
|
||||
)
|
||||
|
||||
expect(mockSessionManager.addSkillEnvs).toHaveBeenCalledWith({
|
||||
FALLBACK_VAR: 'host-val',
|
||||
})
|
||||
})
|
||||
|
||||
it('should fall back to host environment variable if user-configured value is undefined', async () => {
|
||||
const team = await prisma.team.create({ data: { name: 'Test Team' } })
|
||||
const skill = await prisma.skill.create({
|
||||
data: {
|
||||
name: 'Skill Env Test 4',
|
||||
assetId: 'asset1',
|
||||
hash: 'hash4',
|
||||
teamId: team.id,
|
||||
config: {
|
||||
environmentVariables: [{ name: 'FALLBACK_VAR_UNDEF' }],
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
process.env.FALLBACK_VAR_UNDEF = 'host-val2'
|
||||
|
||||
vi.spyOn(fs, 'existsSync').mockReturnValue(true)
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- mocking node fs readFileSync which has complex overloaded signatures
|
||||
vi.spyOn(fs, 'readFileSync').mockImplementation((path: any) => {
|
||||
if (path.toString().endsWith('.hash')) return 'hash4'
|
||||
if (path.toString().endsWith('SKILL.md')) return '# Content'
|
||||
return ''
|
||||
})
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
const readSkillTool = createReadSkillTool(mockSessionManager as any)
|
||||
await readSkillTool.execute(
|
||||
'1',
|
||||
{ skillId: skill.id },
|
||||
undefined,
|
||||
undefined,
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
{} as unknown as any,
|
||||
)
|
||||
|
||||
expect(mockSessionManager.addSkillEnvs).toHaveBeenCalledWith({
|
||||
FALLBACK_VAR_UNDEF: 'host-val2',
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -5,97 +5,118 @@ import { defineTool } from '@mariozechner/pi-coding-agent'
|
||||
import * as path from 'path'
|
||||
import * as fs from 'fs'
|
||||
import AdmZip from 'adm-zip'
|
||||
import type { DatabaseSessionManager } from '../database-session-manager'
|
||||
|
||||
const readSkillSchema = Type.Object({
|
||||
skillId: Type.String({ description: 'The ID of the skill to read' }),
|
||||
})
|
||||
|
||||
export const readSkillTool = defineTool<typeof readSkillSchema, { skillId: string }>({
|
||||
name: 'read_skill',
|
||||
label: 'Read Agent Skill',
|
||||
description: 'Downloads and reads an agent skill to understand how to use it.',
|
||||
parameters: readSkillSchema,
|
||||
execute: async (_toolCallId, params) => {
|
||||
try {
|
||||
const skill = await prisma.skill.findUnique({
|
||||
where: { id: params.skillId },
|
||||
})
|
||||
|
||||
if (!skill) {
|
||||
return {
|
||||
content: [{ type: 'text', text: `Skill with ID ${params.skillId} not found.` }],
|
||||
details: { skillId: params.skillId },
|
||||
}
|
||||
}
|
||||
|
||||
const skillDir = path.join(process.cwd(), '.pi', 'skills', skill.id)
|
||||
const hashFile = path.join(skillDir, '.hash')
|
||||
let needsDownload = true
|
||||
|
||||
if (fs.existsSync(hashFile)) {
|
||||
const localHash = fs.readFileSync(hashFile, 'utf8')
|
||||
if (localHash === skill.hash) {
|
||||
needsDownload = false
|
||||
}
|
||||
}
|
||||
|
||||
if (needsDownload) {
|
||||
if (fs.existsSync(skillDir)) {
|
||||
fs.rmSync(skillDir, { recursive: true, force: true })
|
||||
}
|
||||
fs.mkdirSync(skillDir, { recursive: true })
|
||||
|
||||
const asset = await prisma.asset.findUnique({
|
||||
where: { id: skill.assetId },
|
||||
export const createReadSkillTool = (sessionManager: DatabaseSessionManager) =>
|
||||
defineTool<typeof readSkillSchema, { skillId: string }>({
|
||||
name: 'read_skill',
|
||||
label: 'Read Agent Skill',
|
||||
description: 'Downloads and reads an agent skill to understand how to use it.',
|
||||
parameters: readSkillSchema,
|
||||
execute: async (_toolCallId, params) => {
|
||||
try {
|
||||
const skill = await prisma.skill.findUnique({
|
||||
where: { id: params.skillId },
|
||||
})
|
||||
|
||||
if (!asset || !asset.key) {
|
||||
throw new Error('Skill asset not found or has no key')
|
||||
if (!skill) {
|
||||
return {
|
||||
content: [{ type: 'text', text: `Skill with ID ${params.skillId} not found.` }],
|
||||
details: { skillId: params.skillId },
|
||||
}
|
||||
}
|
||||
|
||||
const { buffer: zipBuffer } = await s3Service.getObject(process.env.S3_BUCKET || 'shumai', asset.key)
|
||||
// Capture environment variables if present in config
|
||||
const config = skill.config as unknown as PrismaJson.SkillConfig
|
||||
if (config?.environmentVariables && Array.isArray(config.environmentVariables)) {
|
||||
const envs: Record<string, string> = {}
|
||||
for (const envVar of config.environmentVariables) {
|
||||
const value =
|
||||
envVar.default !== undefined && envVar.default !== null && envVar.default !== ''
|
||||
? envVar.default
|
||||
: process.env[envVar.name]
|
||||
if (value !== undefined) {
|
||||
envs[envVar.name] = value
|
||||
}
|
||||
}
|
||||
sessionManager.addSkillEnvs(envs)
|
||||
}
|
||||
|
||||
const zip = new AdmZip(zipBuffer)
|
||||
zip.extractAllTo(skillDir, true)
|
||||
const skillDir = path.join(process.cwd(), '.pi', 'skills', skill.id)
|
||||
const hashFile = path.join(skillDir, '.hash')
|
||||
let needsDownload = true
|
||||
|
||||
fs.writeFileSync(hashFile, skill.hash)
|
||||
}
|
||||
if (fs.existsSync(hashFile)) {
|
||||
const localHash = fs.readFileSync(hashFile, 'utf8')
|
||||
if (localHash === skill.hash) {
|
||||
needsDownload = false
|
||||
}
|
||||
}
|
||||
|
||||
// Read SKILL.md
|
||||
let skillMdPath = path.join(skillDir, 'SKILL.md')
|
||||
if (!fs.existsSync(skillMdPath)) {
|
||||
skillMdPath = path.join(skillDir, 'skill.md')
|
||||
}
|
||||
if (needsDownload) {
|
||||
if (fs.existsSync(skillDir)) {
|
||||
fs.rmSync(skillDir, { recursive: true, force: true })
|
||||
}
|
||||
fs.mkdirSync(skillDir, { recursive: true })
|
||||
|
||||
if (!fs.existsSync(skillMdPath)) {
|
||||
const asset = await prisma.asset.findUnique({
|
||||
where: { id: skill.assetId },
|
||||
})
|
||||
|
||||
if (!asset || !asset.key) {
|
||||
throw new Error('Skill asset not found or has no key')
|
||||
}
|
||||
|
||||
const { buffer: zipBuffer } = await s3Service.getObject(
|
||||
process.env.S3_BUCKET || 'shumai',
|
||||
asset.key,
|
||||
)
|
||||
|
||||
const zip = new AdmZip(zipBuffer)
|
||||
zip.extractAllTo(skillDir, true)
|
||||
|
||||
fs.writeFileSync(hashFile, skill.hash)
|
||||
}
|
||||
|
||||
// Read SKILL.md
|
||||
let skillMdPath = path.join(skillDir, 'SKILL.md')
|
||||
if (!fs.existsSync(skillMdPath)) {
|
||||
skillMdPath = path.join(skillDir, 'skill.md')
|
||||
}
|
||||
|
||||
if (!fs.existsSync(skillMdPath)) {
|
||||
return {
|
||||
content: [
|
||||
{
|
||||
type: 'text',
|
||||
text: `Skill downloaded but SKILL.md not found in ${skillDir}`,
|
||||
},
|
||||
],
|
||||
details: { skillId: params.skillId },
|
||||
}
|
||||
}
|
||||
|
||||
const skillMdContent = fs.readFileSync(skillMdPath, 'utf8')
|
||||
return {
|
||||
content: [{ type: 'text', text: skillMdContent }],
|
||||
details: { skillId: params.skillId },
|
||||
}
|
||||
} catch (error) {
|
||||
return {
|
||||
content: [
|
||||
{
|
||||
type: 'text',
|
||||
text: `Skill downloaded but SKILL.md not found in ${skillDir}`,
|
||||
text: `Error reading skill ${params.skillId}: ${
|
||||
error instanceof Error ? error.message : String(error)
|
||||
}`,
|
||||
},
|
||||
],
|
||||
details: { skillId: params.skillId },
|
||||
}
|
||||
}
|
||||
|
||||
const skillMdContent = fs.readFileSync(skillMdPath, 'utf8')
|
||||
return {
|
||||
content: [{ type: 'text', text: skillMdContent }],
|
||||
details: { skillId: params.skillId },
|
||||
}
|
||||
} catch (error) {
|
||||
return {
|
||||
content: [
|
||||
{
|
||||
type: 'text',
|
||||
text: `Error reading skill ${params.skillId}: ${
|
||||
error instanceof Error ? error.message : String(error)
|
||||
}`,
|
||||
},
|
||||
],
|
||||
details: { skillId: params.skillId },
|
||||
}
|
||||
}
|
||||
},
|
||||
})
|
||||
},
|
||||
})
|
||||
|
||||
@@ -0,0 +1,185 @@
|
||||
import { describe, it, expect, vi, beforeEach } from 'vitest'
|
||||
import { createSandboxedBashTool } from './sandboxed-bash'
|
||||
import { SandboxManager } from '@anthropic-ai/sandbox-runtime'
|
||||
import { spawn } from 'node:child_process'
|
||||
import { EventEmitter } from 'node:events'
|
||||
|
||||
vi.mock('@anthropic-ai/sandbox-runtime')
|
||||
vi.mock('node:child_process')
|
||||
|
||||
describe('createSandboxedBashTool', () => {
|
||||
const mockCwd = '/mock/cwd'
|
||||
const mockSessionManager = {
|
||||
getSkillEnvs: vi.fn(),
|
||||
}
|
||||
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks()
|
||||
mockSessionManager.getSkillEnvs.mockReturnValue({ TEST_ENV: 'test-value' })
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- SandboxManager.wrapWithSandbox is a mocked async function from a 3rd party library
|
||||
;(SandboxManager.wrapWithSandbox as any).mockImplementation(
|
||||
async (cmd: string) => `sandboxed-${cmd}`,
|
||||
)
|
||||
})
|
||||
|
||||
const createMockSignal = () => {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- signal needs to be partially compatible with AbortSignal but we need to emit events for testing
|
||||
const signal = new EventEmitter() as any
|
||||
signal.addEventListener = vi.fn((event: string, cb: (ev: Event) => unknown) => {
|
||||
signal.on(event, cb)
|
||||
})
|
||||
signal.removeEventListener = vi.fn((event: string, cb: (ev: Event) => unknown) => {
|
||||
signal.off(event, cb)
|
||||
})
|
||||
signal.aborted = false
|
||||
return signal
|
||||
}
|
||||
|
||||
const createMockOnUpdate = () => vi.fn()
|
||||
|
||||
it('should execute a command in the sandbox with injected env vars', async () => {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- mockSessionManager is a partial mock of DatabaseSessionManager
|
||||
const tool = createSandboxedBashTool(mockCwd, mockSessionManager as any)
|
||||
|
||||
const mockStdout = new EventEmitter()
|
||||
const mockStderr = new EventEmitter()
|
||||
const mockChild = Object.assign(new EventEmitter(), {
|
||||
stdout: mockStdout,
|
||||
stderr: mockStderr,
|
||||
pid: 123,
|
||||
kill: vi.fn(),
|
||||
})
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- spawn is mocked to return a partial ChildProcess
|
||||
;(spawn as any).mockReturnValue(mockChild)
|
||||
|
||||
const onUpdate = createMockOnUpdate()
|
||||
const signal = createMockSignal()
|
||||
|
||||
// pi-coding-agent AgentTool.execute signature: (toolCallId, params, signal?, onUpdate?)
|
||||
const executePromise = tool.execute('1', { command: 'echo hello' }, signal, onUpdate)
|
||||
|
||||
await vi.waitFor(() => expect(spawn).toHaveBeenCalled())
|
||||
|
||||
expect(SandboxManager.wrapWithSandbox).toHaveBeenCalledWith('echo hello')
|
||||
expect(spawn).toHaveBeenCalledWith(
|
||||
'bash',
|
||||
['-c', 'sandboxed-echo hello'],
|
||||
expect.objectContaining({
|
||||
env: expect.objectContaining({
|
||||
TEST_ENV: 'test-value',
|
||||
}),
|
||||
}),
|
||||
)
|
||||
|
||||
// Simulate stdout data
|
||||
mockStdout.emit('data', Buffer.from('hello output'))
|
||||
mockChild.emit('close', 0)
|
||||
|
||||
const result = await executePromise
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- ToolResponse content is an array of content blocks
|
||||
expect((result as any).content[0].text).toContain('hello output')
|
||||
})
|
||||
|
||||
it('should handle process errors', async () => {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- mockSessionManager is a partial mock
|
||||
const tool = createSandboxedBashTool(mockCwd, mockSessionManager as any)
|
||||
const mockChild = new EventEmitter()
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- spawn returns mocked ChildProcess
|
||||
;(spawn as any).mockReturnValue(mockChild)
|
||||
|
||||
const signal = createMockSignal()
|
||||
const executePromise = tool.execute('1', { command: 'fail' }, signal, createMockOnUpdate())
|
||||
|
||||
await vi.waitFor(() => expect(spawn).toHaveBeenCalled())
|
||||
mockChild.emit('error', new Error('spawn failed'))
|
||||
|
||||
await expect(executePromise).rejects.toThrow('spawn failed')
|
||||
})
|
||||
|
||||
it('should handle non-zero exit codes', async () => {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- mockSessionManager is a partial mock
|
||||
const tool = createSandboxedBashTool(mockCwd, mockSessionManager as any)
|
||||
const mockChild = Object.assign(new EventEmitter(), {
|
||||
stdout: new EventEmitter(),
|
||||
stderr: new EventEmitter(),
|
||||
pid: 1,
|
||||
})
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- spawn returns mocked ChildProcess
|
||||
;(spawn as any).mockReturnValue(mockChild)
|
||||
|
||||
const signal = createMockSignal()
|
||||
const executePromise = tool.execute('1', { command: 'exit 1' }, signal, createMockOnUpdate())
|
||||
|
||||
await vi.waitFor(() => expect(spawn).toHaveBeenCalled())
|
||||
mockChild.emit('close', 1)
|
||||
|
||||
await expect(executePromise).rejects.toThrow(/exited with code 1/)
|
||||
})
|
||||
|
||||
it('should handle timeouts', async () => {
|
||||
vi.useFakeTimers()
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- mockSessionManager is a partial mock
|
||||
const tool = createSandboxedBashTool(mockCwd, mockSessionManager as any)
|
||||
const mockChild = Object.assign(new EventEmitter(), {
|
||||
stdout: new EventEmitter(),
|
||||
stderr: new EventEmitter(),
|
||||
pid: 456,
|
||||
kill: vi.fn(),
|
||||
})
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- spawn returns mocked ChildProcess
|
||||
;(spawn as any).mockReturnValue(mockChild)
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- process.kill return type is boolean
|
||||
const killSpy = vi.spyOn(process, 'kill').mockImplementation(() => true as any)
|
||||
|
||||
const signal = createMockSignal()
|
||||
const executePromise = tool.execute(
|
||||
'1',
|
||||
{ command: 'sleep 10', timeout: 2 },
|
||||
signal,
|
||||
createMockOnUpdate(),
|
||||
)
|
||||
|
||||
await vi.waitFor(() => expect(spawn).toHaveBeenCalled())
|
||||
|
||||
await vi.advanceTimersByTimeAsync(2100)
|
||||
|
||||
expect(killSpy).toHaveBeenCalledWith(-456, 'SIGKILL')
|
||||
|
||||
mockChild.emit('close', null)
|
||||
|
||||
await expect(executePromise).rejects.toThrow(/timed out/)
|
||||
vi.useRealTimers()
|
||||
killSpy.mockRestore()
|
||||
})
|
||||
|
||||
it('should handle abort signals', async () => {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- mockSessionManager is a partial mock
|
||||
const tool = createSandboxedBashTool(mockCwd, mockSessionManager as any)
|
||||
const mockChild = Object.assign(new EventEmitter(), {
|
||||
stdout: new EventEmitter(),
|
||||
stderr: new EventEmitter(),
|
||||
pid: 789,
|
||||
kill: vi.fn(),
|
||||
})
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- spawn returns mocked ChildProcess
|
||||
;(spawn as any).mockReturnValue(mockChild)
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- process.kill return type is boolean
|
||||
const killSpy = vi.spyOn(process, 'kill').mockImplementation(() => true as any)
|
||||
|
||||
const signal = createMockSignal()
|
||||
const executePromise = tool.execute('1', { command: 'long-run' }, signal, createMockOnUpdate())
|
||||
|
||||
await vi.waitFor(() => expect(spawn).toHaveBeenCalled())
|
||||
|
||||
signal.aborted = true
|
||||
signal.emit('abort')
|
||||
|
||||
expect(killSpy).toHaveBeenCalledWith(-789, 'SIGKILL')
|
||||
|
||||
mockChild.emit('close', null)
|
||||
|
||||
await expect(executePromise).rejects.toThrow(/aborted/)
|
||||
killSpy.mockRestore()
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,73 @@
|
||||
import { SandboxManager } from '@anthropic-ai/sandbox-runtime'
|
||||
import { createBashTool } from '@mariozechner/pi-coding-agent'
|
||||
import { spawn } from 'node:child_process'
|
||||
import type { DatabaseSessionManager } from '../database-session-manager'
|
||||
|
||||
export const createSandboxedBashTool = (cwd: string, sessionManager: DatabaseSessionManager) => {
|
||||
return createBashTool(cwd, {
|
||||
operations: {
|
||||
async exec(command, executeCwd, { onData, signal, timeout }) {
|
||||
const wrappedCommand = await SandboxManager.wrapWithSandbox(command)
|
||||
return new Promise((resolve, reject) => {
|
||||
const child = spawn('bash', ['-c', wrappedCommand], {
|
||||
cwd: executeCwd,
|
||||
detached: true,
|
||||
stdio: ['ignore', 'pipe', 'pipe'],
|
||||
env: {
|
||||
...sessionManager.getSkillEnvs(),
|
||||
},
|
||||
})
|
||||
|
||||
let timedOut = false
|
||||
let timeoutHandle: NodeJS.Timeout | undefined
|
||||
|
||||
if (timeout !== undefined && timeout > 0) {
|
||||
timeoutHandle = setTimeout(() => {
|
||||
timedOut = true
|
||||
if (child.pid) {
|
||||
try {
|
||||
process.kill(-child.pid, 'SIGKILL')
|
||||
} catch {
|
||||
child.kill('SIGKILL')
|
||||
}
|
||||
}
|
||||
}, timeout * 1000)
|
||||
}
|
||||
|
||||
child.stdout?.on('data', onData)
|
||||
child.stderr?.on('data', onData)
|
||||
|
||||
child.on('error', (err) => {
|
||||
if (timeoutHandle) clearTimeout(timeoutHandle)
|
||||
reject(err)
|
||||
})
|
||||
|
||||
const onAbort = () => {
|
||||
if (child.pid) {
|
||||
try {
|
||||
process.kill(-child.pid, 'SIGKILL')
|
||||
} catch {
|
||||
child.kill('SIGKILL')
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
signal?.addEventListener('abort', onAbort, { once: true })
|
||||
|
||||
child.on('close', (code) => {
|
||||
if (timeoutHandle) clearTimeout(timeoutHandle)
|
||||
signal?.removeEventListener('abort', onAbort)
|
||||
|
||||
if (signal?.aborted) {
|
||||
reject(new Error('aborted'))
|
||||
} else if (timedOut) {
|
||||
reject(new Error(`timeout:${timeout}`))
|
||||
} else {
|
||||
resolve({ exitCode: code })
|
||||
}
|
||||
})
|
||||
})
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
@@ -1,5 +1,10 @@
|
||||
import type { WorkflowTask } from '@/generated/prisma/client'
|
||||
import { getActivities, executeActivity, TaskQueueDb, TaskQueueAgent } from '@/workflow/workflow-utils'
|
||||
import {
|
||||
getActivities,
|
||||
executeActivity,
|
||||
TaskQueueDb,
|
||||
TaskQueueAgent,
|
||||
} from '@/workflow/workflow-utils'
|
||||
|
||||
export async function aiChat(task: WorkflowTask): Promise<void> {
|
||||
const {
|
||||
|
||||
+7
-2
@@ -18,7 +18,9 @@ describe('S3 API', () => {
|
||||
contentType: 'image/webp',
|
||||
eTag: '"test"',
|
||||
})
|
||||
const mockGet = vi.spyOn(s3Service, 'getObject').mockResolvedValue({ buffer: Buffer.from('test'), contentType: 'image/webp' })
|
||||
const mockGet = vi
|
||||
.spyOn(s3Service, 'getObject')
|
||||
.mockResolvedValue({ buffer: Buffer.from('test'), contentType: 'image/webp' })
|
||||
|
||||
const res = await app.request('/files/b1/test.webp')
|
||||
|
||||
@@ -36,7 +38,10 @@ describe('S3 API', () => {
|
||||
contentType: 'application/octet-stream',
|
||||
eTag: '"test"',
|
||||
})
|
||||
vi.spyOn(s3Service, 'getObject').mockResolvedValue({ buffer: Buffer.from('test'), contentType: 'application/octet-stream' })
|
||||
vi.spyOn(s3Service, 'getObject').mockResolvedValue({
|
||||
buffer: Buffer.from('test'),
|
||||
contentType: 'application/octet-stream',
|
||||
})
|
||||
|
||||
const res = await app.request('/files/b1/test')
|
||||
|
||||
|
||||
@@ -37,6 +37,8 @@ describe('team api', () => {
|
||||
let mockListUserMetadata: any // eslint-disable-line @typescript-eslint/no-explicit-any
|
||||
let mockUpsertUserMetadata: any // eslint-disable-line @typescript-eslint/no-explicit-any
|
||||
let mockCreateNotification: any // eslint-disable-line @typescript-eslint/no-explicit-any
|
||||
let mockGetSandboxSettings: any // eslint-disable-line @typescript-eslint/no-explicit-any
|
||||
let mockUpdateSandboxSettings: any // eslint-disable-line @typescript-eslint/no-explicit-any
|
||||
|
||||
beforeEach(() => {
|
||||
mockCreateTeam = vi.spyOn(teamService, 'createTeam')
|
||||
@@ -49,6 +51,8 @@ describe('team api', () => {
|
||||
mockListUserMetadata = vi.spyOn(userMetadataService, 'listMetadata')
|
||||
mockUpsertUserMetadata = vi.spyOn(userMetadataService, 'upsertMetadata')
|
||||
mockCreateNotification = vi.spyOn(notificationService, 'create').mockResolvedValue()
|
||||
mockGetSandboxSettings = vi.spyOn(teamService, 'getSandboxSettings')
|
||||
mockUpdateSandboxSettings = vi.spyOn(teamService, 'updateSandboxSettings')
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
@@ -184,4 +188,30 @@ describe('team api', () => {
|
||||
expect(data.value).toBe('value1')
|
||||
expect(mockUpsertUserMetadata).toHaveBeenCalledWith('user1', 't1', 'key1', 'value1')
|
||||
})
|
||||
|
||||
it('GET /teams/:teamId/sandbox returns sandbox settings', async () => {
|
||||
mockGetSandboxSettings.mockResolvedValue({ allowedDomains: ['example.com'] })
|
||||
|
||||
const res = await app.request('/teams/t1/sandbox')
|
||||
|
||||
expect(res.status).toBe(200)
|
||||
const data = await res.json()
|
||||
expect(data.allowedDomains).toEqual(['example.com'])
|
||||
expect(mockGetSandboxSettings).toHaveBeenCalledWith('t1')
|
||||
})
|
||||
|
||||
it('PUT /teams/:teamId/sandbox updates sandbox settings', async () => {
|
||||
mockUpdateSandboxSettings.mockResolvedValue({ allowedDomains: ['new.com'] })
|
||||
|
||||
const res = await app.request('/teams/t1/sandbox', {
|
||||
method: 'PUT',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ allowedDomains: ['new.com'] }),
|
||||
})
|
||||
|
||||
expect(res.status).toBe(200)
|
||||
const data = await res.json()
|
||||
expect(data.allowedDomains).toEqual(['new.com'])
|
||||
expect(mockUpdateSandboxSettings).toHaveBeenCalledWith('t1', { allowedDomains: ['new.com'] })
|
||||
})
|
||||
})
|
||||
|
||||
@@ -10,6 +10,7 @@ import {
|
||||
getUserTeamsRequestSchema,
|
||||
updateTeamSettingsRequestSchema,
|
||||
listMembersQuerySchema,
|
||||
updateSandboxSettingsRequestSchema,
|
||||
} from '@/dtos/team'
|
||||
import { updateUserMetadataRequestSchema } from '@/dtos/user-metadata'
|
||||
import type { Prisma } from '@/generated/prisma/client'
|
||||
@@ -124,6 +125,37 @@ const route = new Hono<{ Variables: { user: User } }>()
|
||||
return c.json(settings)
|
||||
},
|
||||
)
|
||||
.get('/teams/:teamId/sandbox', async (c) => {
|
||||
const user = c.get('user')
|
||||
const teamId = c.req.param('teamId')
|
||||
|
||||
await authzService.hasPermission({
|
||||
teamId,
|
||||
user,
|
||||
permission: Permission.Read,
|
||||
})
|
||||
|
||||
const sandbox = await teamService.getSandboxSettings(teamId)
|
||||
return c.json(sandbox)
|
||||
})
|
||||
.put(
|
||||
'/teams/:teamId/sandbox',
|
||||
zValidator('json', updateSandboxSettingsRequestSchema),
|
||||
async (c) => {
|
||||
const user = c.get('user')
|
||||
const teamId = c.req.param('teamId')
|
||||
const req = c.req.valid('json')
|
||||
|
||||
await authzService.hasPermission({
|
||||
teamId,
|
||||
user,
|
||||
permission: Permission.Admin,
|
||||
})
|
||||
|
||||
const sandbox = await teamService.updateSandboxSettings(teamId, req)
|
||||
return c.json(sandbox)
|
||||
},
|
||||
)
|
||||
.get('/teams/:teamId/user-metadata', async (c) => {
|
||||
const user = c.get('user')
|
||||
const teamId = c.req.param('teamId')
|
||||
|
||||
@@ -75,6 +75,14 @@ export const ImageTranscodeStrategy = {
|
||||
export type ImageTranscodeStrategy =
|
||||
(typeof ImageTranscodeStrategy)[keyof typeof ImageTranscodeStrategy]
|
||||
|
||||
export const sandboxSettingsSchema = z.object({
|
||||
allowedDomains: z.array(z.string()),
|
||||
})
|
||||
export type SandboxSettings = z.infer<typeof sandboxSettingsSchema>
|
||||
|
||||
export const updateSandboxSettingsRequestSchema = sandboxSettingsSchema
|
||||
export type UpdateSandboxSettingsRequest = z.infer<typeof updateSandboxSettingsRequestSchema>
|
||||
|
||||
// Service Layer Interfaces
|
||||
export interface ServiceCreateTeamRequest {
|
||||
name: string
|
||||
|
||||
Generated
+5
@@ -47,6 +47,11 @@ export type AuthToken = Prisma.AuthTokenModel
|
||||
*
|
||||
*/
|
||||
export type Team = Prisma.TeamModel
|
||||
/**
|
||||
* Model Sandbox
|
||||
*
|
||||
*/
|
||||
export type Sandbox = Prisma.SandboxModel
|
||||
/**
|
||||
* Model Skill
|
||||
*
|
||||
|
||||
Generated
+5
@@ -71,6 +71,11 @@ export type AuthToken = Prisma.AuthTokenModel
|
||||
*
|
||||
*/
|
||||
export type Team = Prisma.TeamModel
|
||||
/**
|
||||
* Model Sandbox
|
||||
*
|
||||
*/
|
||||
export type Sandbox = Prisma.SandboxModel
|
||||
/**
|
||||
* Model Skill
|
||||
*
|
||||
|
||||
Generated
+14
-4
File diff suppressed because one or more lines are too long
+88
-1
@@ -390,6 +390,7 @@ export const ModelName = {
|
||||
Verification: 'Verification',
|
||||
AuthToken: 'AuthToken',
|
||||
Team: 'Team',
|
||||
Sandbox: 'Sandbox',
|
||||
Skill: 'Skill',
|
||||
TeamMember: 'TeamMember',
|
||||
Project: 'Project',
|
||||
@@ -428,7 +429,7 @@ export type TypeMap<ExtArgs extends runtime.Types.Extensions.InternalArgs = runt
|
||||
omit: GlobalOmitOptions
|
||||
}
|
||||
meta: {
|
||||
modelProps: "user" | "session" | "account" | "verification" | "authToken" | "team" | "skill" | "teamMember" | "project" | "projectMember" | "shareLink" | "asset" | "assetMetadataValue" | "assetComment" | "assetCommentAttachment" | "assetEmbedding" | "invite" | "metadataField" | "notification" | "systemSettings" | "task" | "workflowTask" | "agent" | "agentSkill" | "agentSession" | "agentSessionEntry" | "userMetadata" | "model" | "provider"
|
||||
modelProps: "user" | "session" | "account" | "verification" | "authToken" | "team" | "sandbox" | "skill" | "teamMember" | "project" | "projectMember" | "shareLink" | "asset" | "assetMetadataValue" | "assetComment" | "assetCommentAttachment" | "assetEmbedding" | "invite" | "metadataField" | "notification" | "systemSettings" | "task" | "workflowTask" | "agent" | "agentSkill" | "agentSession" | "agentSessionEntry" | "userMetadata" | "model" | "provider"
|
||||
txIsolationLevel: TransactionIsolationLevel
|
||||
}
|
||||
model: {
|
||||
@@ -876,6 +877,80 @@ export type TypeMap<ExtArgs extends runtime.Types.Extensions.InternalArgs = runt
|
||||
}
|
||||
}
|
||||
}
|
||||
Sandbox: {
|
||||
payload: Prisma.$SandboxPayload<ExtArgs>
|
||||
fields: Prisma.SandboxFieldRefs
|
||||
operations: {
|
||||
findUnique: {
|
||||
args: Prisma.SandboxFindUniqueArgs<ExtArgs>
|
||||
result: runtime.Types.Utils.PayloadToResult<Prisma.$SandboxPayload> | null
|
||||
}
|
||||
findUniqueOrThrow: {
|
||||
args: Prisma.SandboxFindUniqueOrThrowArgs<ExtArgs>
|
||||
result: runtime.Types.Utils.PayloadToResult<Prisma.$SandboxPayload>
|
||||
}
|
||||
findFirst: {
|
||||
args: Prisma.SandboxFindFirstArgs<ExtArgs>
|
||||
result: runtime.Types.Utils.PayloadToResult<Prisma.$SandboxPayload> | null
|
||||
}
|
||||
findFirstOrThrow: {
|
||||
args: Prisma.SandboxFindFirstOrThrowArgs<ExtArgs>
|
||||
result: runtime.Types.Utils.PayloadToResult<Prisma.$SandboxPayload>
|
||||
}
|
||||
findMany: {
|
||||
args: Prisma.SandboxFindManyArgs<ExtArgs>
|
||||
result: runtime.Types.Utils.PayloadToResult<Prisma.$SandboxPayload>[]
|
||||
}
|
||||
create: {
|
||||
args: Prisma.SandboxCreateArgs<ExtArgs>
|
||||
result: runtime.Types.Utils.PayloadToResult<Prisma.$SandboxPayload>
|
||||
}
|
||||
createMany: {
|
||||
args: Prisma.SandboxCreateManyArgs<ExtArgs>
|
||||
result: BatchPayload
|
||||
}
|
||||
createManyAndReturn: {
|
||||
args: Prisma.SandboxCreateManyAndReturnArgs<ExtArgs>
|
||||
result: runtime.Types.Utils.PayloadToResult<Prisma.$SandboxPayload>[]
|
||||
}
|
||||
delete: {
|
||||
args: Prisma.SandboxDeleteArgs<ExtArgs>
|
||||
result: runtime.Types.Utils.PayloadToResult<Prisma.$SandboxPayload>
|
||||
}
|
||||
update: {
|
||||
args: Prisma.SandboxUpdateArgs<ExtArgs>
|
||||
result: runtime.Types.Utils.PayloadToResult<Prisma.$SandboxPayload>
|
||||
}
|
||||
deleteMany: {
|
||||
args: Prisma.SandboxDeleteManyArgs<ExtArgs>
|
||||
result: BatchPayload
|
||||
}
|
||||
updateMany: {
|
||||
args: Prisma.SandboxUpdateManyArgs<ExtArgs>
|
||||
result: BatchPayload
|
||||
}
|
||||
updateManyAndReturn: {
|
||||
args: Prisma.SandboxUpdateManyAndReturnArgs<ExtArgs>
|
||||
result: runtime.Types.Utils.PayloadToResult<Prisma.$SandboxPayload>[]
|
||||
}
|
||||
upsert: {
|
||||
args: Prisma.SandboxUpsertArgs<ExtArgs>
|
||||
result: runtime.Types.Utils.PayloadToResult<Prisma.$SandboxPayload>
|
||||
}
|
||||
aggregate: {
|
||||
args: Prisma.SandboxAggregateArgs<ExtArgs>
|
||||
result: runtime.Types.Utils.Optional<Prisma.AggregateSandbox>
|
||||
}
|
||||
groupBy: {
|
||||
args: Prisma.SandboxGroupByArgs<ExtArgs>
|
||||
result: runtime.Types.Utils.Optional<Prisma.SandboxGroupByOutputType>[]
|
||||
}
|
||||
count: {
|
||||
args: Prisma.SandboxCountArgs<ExtArgs>
|
||||
result: runtime.Types.Utils.Optional<Prisma.SandboxCountAggregateOutputType> | number
|
||||
}
|
||||
}
|
||||
}
|
||||
Skill: {
|
||||
payload: Prisma.$SkillPayload<ExtArgs>
|
||||
fields: Prisma.SkillFieldRefs
|
||||
@@ -2703,6 +2778,17 @@ export const TeamScalarFieldEnum = {
|
||||
export type TeamScalarFieldEnum = (typeof TeamScalarFieldEnum)[keyof typeof TeamScalarFieldEnum]
|
||||
|
||||
|
||||
export const SandboxScalarFieldEnum = {
|
||||
id: 'id',
|
||||
allowedDomains: 'allowedDomains',
|
||||
createdAt: 'createdAt',
|
||||
updatedAt: 'updatedAt',
|
||||
teamId: 'teamId'
|
||||
} as const
|
||||
|
||||
export type SandboxScalarFieldEnum = (typeof SandboxScalarFieldEnum)[keyof typeof SandboxScalarFieldEnum]
|
||||
|
||||
|
||||
export const SkillScalarFieldEnum = {
|
||||
id: 'id',
|
||||
name: 'name',
|
||||
@@ -3460,6 +3546,7 @@ export type GlobalOmitConfig = {
|
||||
verification?: Prisma.VerificationOmit
|
||||
authToken?: Prisma.AuthTokenOmit
|
||||
team?: Prisma.TeamOmit
|
||||
sandbox?: Prisma.SandboxOmit
|
||||
skill?: Prisma.SkillOmit
|
||||
teamMember?: Prisma.TeamMemberOmit
|
||||
project?: Prisma.ProjectOmit
|
||||
|
||||
@@ -57,6 +57,7 @@ export const ModelName = {
|
||||
Verification: 'Verification',
|
||||
AuthToken: 'AuthToken',
|
||||
Team: 'Team',
|
||||
Sandbox: 'Sandbox',
|
||||
Skill: 'Skill',
|
||||
TeamMember: 'TeamMember',
|
||||
Project: 'Project',
|
||||
@@ -184,6 +185,17 @@ export const TeamScalarFieldEnum = {
|
||||
export type TeamScalarFieldEnum = (typeof TeamScalarFieldEnum)[keyof typeof TeamScalarFieldEnum]
|
||||
|
||||
|
||||
export const SandboxScalarFieldEnum = {
|
||||
id: 'id',
|
||||
allowedDomains: 'allowedDomains',
|
||||
createdAt: 'createdAt',
|
||||
updatedAt: 'updatedAt',
|
||||
teamId: 'teamId'
|
||||
} as const
|
||||
|
||||
export type SandboxScalarFieldEnum = (typeof SandboxScalarFieldEnum)[keyof typeof SandboxScalarFieldEnum]
|
||||
|
||||
|
||||
export const SkillScalarFieldEnum = {
|
||||
id: 'id',
|
||||
name: 'name',
|
||||
|
||||
Generated
+1
@@ -14,6 +14,7 @@ export type * from './models/Account.ts'
|
||||
export type * from './models/Verification.ts'
|
||||
export type * from './models/AuthToken.ts'
|
||||
export type * from './models/Team.ts'
|
||||
export type * from './models/Sandbox.ts'
|
||||
export type * from './models/Skill.ts'
|
||||
export type * from './models/TeamMember.ts'
|
||||
export type * from './models/Project.ts'
|
||||
|
||||
Generated
-8
@@ -727,14 +727,6 @@ export type AssetScalarRelationFilter = {
|
||||
isNot?: Prisma.AssetWhereInput
|
||||
}
|
||||
|
||||
export type StringNullableListFilter<$PrismaModel = never> = {
|
||||
equals?: string[] | Prisma.ListStringFieldRefInput<$PrismaModel> | null
|
||||
has?: string | Prisma.StringFieldRefInput<$PrismaModel> | null
|
||||
hasEvery?: string[] | Prisma.ListStringFieldRefInput<$PrismaModel>
|
||||
hasSome?: string[] | Prisma.ListStringFieldRefInput<$PrismaModel>
|
||||
isEmpty?: boolean
|
||||
}
|
||||
|
||||
export type AssetParentIdTargetIdCompoundUniqueInput = {
|
||||
parentId: string
|
||||
targetId: string
|
||||
|
||||
Generated
+1308
File diff suppressed because it is too large
Load Diff
Generated
+164
@@ -197,6 +197,7 @@ export type TeamWhereInput = {
|
||||
userMetadata?: Prisma.UserMetadataListRelationFilter
|
||||
providers?: Prisma.ProviderListRelationFilter
|
||||
skills?: Prisma.SkillListRelationFilter
|
||||
sandbox?: Prisma.XOR<Prisma.SandboxNullableScalarRelationFilter, Prisma.SandboxWhereInput> | null
|
||||
}
|
||||
|
||||
export type TeamOrderByWithRelationInput = {
|
||||
@@ -215,6 +216,7 @@ export type TeamOrderByWithRelationInput = {
|
||||
userMetadata?: Prisma.UserMetadataOrderByRelationAggregateInput
|
||||
providers?: Prisma.ProviderOrderByRelationAggregateInput
|
||||
skills?: Prisma.SkillOrderByRelationAggregateInput
|
||||
sandbox?: Prisma.SandboxOrderByWithRelationInput
|
||||
}
|
||||
|
||||
export type TeamWhereUniqueInput = Prisma.AtLeast<{
|
||||
@@ -236,6 +238,7 @@ export type TeamWhereUniqueInput = Prisma.AtLeast<{
|
||||
userMetadata?: Prisma.UserMetadataListRelationFilter
|
||||
providers?: Prisma.ProviderListRelationFilter
|
||||
skills?: Prisma.SkillListRelationFilter
|
||||
sandbox?: Prisma.XOR<Prisma.SandboxNullableScalarRelationFilter, Prisma.SandboxWhereInput> | null
|
||||
}, "id" | "rootFolderId">
|
||||
|
||||
export type TeamOrderByWithAggregationInput = {
|
||||
@@ -277,6 +280,7 @@ export type TeamCreateInput = {
|
||||
userMetadata?: Prisma.UserMetadataCreateNestedManyWithoutTeamInput
|
||||
providers?: Prisma.ProviderCreateNestedManyWithoutTeamInput
|
||||
skills?: Prisma.SkillCreateNestedManyWithoutTeamInput
|
||||
sandbox?: Prisma.SandboxCreateNestedOneWithoutTeamInput
|
||||
}
|
||||
|
||||
export type TeamUncheckedCreateInput = {
|
||||
@@ -294,6 +298,7 @@ export type TeamUncheckedCreateInput = {
|
||||
userMetadata?: Prisma.UserMetadataUncheckedCreateNestedManyWithoutTeamInput
|
||||
providers?: Prisma.ProviderUncheckedCreateNestedManyWithoutTeamInput
|
||||
skills?: Prisma.SkillUncheckedCreateNestedManyWithoutTeamInput
|
||||
sandbox?: Prisma.SandboxUncheckedCreateNestedOneWithoutTeamInput
|
||||
}
|
||||
|
||||
export type TeamUpdateInput = {
|
||||
@@ -311,6 +316,7 @@ export type TeamUpdateInput = {
|
||||
userMetadata?: Prisma.UserMetadataUpdateManyWithoutTeamNestedInput
|
||||
providers?: Prisma.ProviderUpdateManyWithoutTeamNestedInput
|
||||
skills?: Prisma.SkillUpdateManyWithoutTeamNestedInput
|
||||
sandbox?: Prisma.SandboxUpdateOneWithoutTeamNestedInput
|
||||
}
|
||||
|
||||
export type TeamUncheckedUpdateInput = {
|
||||
@@ -328,6 +334,7 @@ export type TeamUncheckedUpdateInput = {
|
||||
userMetadata?: Prisma.UserMetadataUncheckedUpdateManyWithoutTeamNestedInput
|
||||
providers?: Prisma.ProviderUncheckedUpdateManyWithoutTeamNestedInput
|
||||
skills?: Prisma.SkillUncheckedUpdateManyWithoutTeamNestedInput
|
||||
sandbox?: Prisma.SandboxUncheckedUpdateOneWithoutTeamNestedInput
|
||||
}
|
||||
|
||||
export type TeamCreateManyInput = {
|
||||
@@ -391,6 +398,20 @@ export type TeamNullableScalarRelationFilter = {
|
||||
isNot?: Prisma.TeamWhereInput | null
|
||||
}
|
||||
|
||||
export type TeamCreateNestedOneWithoutSandboxInput = {
|
||||
create?: Prisma.XOR<Prisma.TeamCreateWithoutSandboxInput, Prisma.TeamUncheckedCreateWithoutSandboxInput>
|
||||
connectOrCreate?: Prisma.TeamCreateOrConnectWithoutSandboxInput
|
||||
connect?: Prisma.TeamWhereUniqueInput
|
||||
}
|
||||
|
||||
export type TeamUpdateOneRequiredWithoutSandboxNestedInput = {
|
||||
create?: Prisma.XOR<Prisma.TeamCreateWithoutSandboxInput, Prisma.TeamUncheckedCreateWithoutSandboxInput>
|
||||
connectOrCreate?: Prisma.TeamCreateOrConnectWithoutSandboxInput
|
||||
upsert?: Prisma.TeamUpsertWithoutSandboxInput
|
||||
connect?: Prisma.TeamWhereUniqueInput
|
||||
update?: Prisma.XOR<Prisma.XOR<Prisma.TeamUpdateToOneWithWhereWithoutSandboxInput, Prisma.TeamUpdateWithoutSandboxInput>, Prisma.TeamUncheckedUpdateWithoutSandboxInput>
|
||||
}
|
||||
|
||||
export type TeamCreateNestedOneWithoutSkillsInput = {
|
||||
create?: Prisma.XOR<Prisma.TeamCreateWithoutSkillsInput, Prisma.TeamUncheckedCreateWithoutSkillsInput>
|
||||
connectOrCreate?: Prisma.TeamCreateOrConnectWithoutSkillsInput
|
||||
@@ -537,6 +558,90 @@ export type TeamUpdateOneRequiredWithoutProvidersNestedInput = {
|
||||
update?: Prisma.XOR<Prisma.XOR<Prisma.TeamUpdateToOneWithWhereWithoutProvidersInput, Prisma.TeamUpdateWithoutProvidersInput>, Prisma.TeamUncheckedUpdateWithoutProvidersInput>
|
||||
}
|
||||
|
||||
export type TeamCreateWithoutSandboxInput = {
|
||||
id?: string
|
||||
name: string
|
||||
settings?:PrismaJson.Settings | Prisma.NullableJsonNullValueInput
|
||||
createdAt?: Date | string
|
||||
updatedAt?: Date | string
|
||||
rootFolder?: Prisma.AssetCreateNestedOneWithoutTeamRootFolderInput
|
||||
members?: Prisma.TeamMemberCreateNestedManyWithoutTeamInput
|
||||
projects?: Prisma.ProjectCreateNestedManyWithoutTeamInput
|
||||
metadataFields?: Prisma.MetadataFieldCreateNestedManyWithoutTeamInput
|
||||
invites?: Prisma.InviteCreateNestedManyWithoutTeamInput
|
||||
notifications?: Prisma.NotificationCreateNestedManyWithoutTeamInput
|
||||
userMetadata?: Prisma.UserMetadataCreateNestedManyWithoutTeamInput
|
||||
providers?: Prisma.ProviderCreateNestedManyWithoutTeamInput
|
||||
skills?: Prisma.SkillCreateNestedManyWithoutTeamInput
|
||||
}
|
||||
|
||||
export type TeamUncheckedCreateWithoutSandboxInput = {
|
||||
id?: string
|
||||
name: string
|
||||
settings?:PrismaJson.Settings | Prisma.NullableJsonNullValueInput
|
||||
createdAt?: Date | string
|
||||
updatedAt?: Date | string
|
||||
rootFolderId?: string | null
|
||||
members?: Prisma.TeamMemberUncheckedCreateNestedManyWithoutTeamInput
|
||||
projects?: Prisma.ProjectUncheckedCreateNestedManyWithoutTeamInput
|
||||
metadataFields?: Prisma.MetadataFieldUncheckedCreateNestedManyWithoutTeamInput
|
||||
invites?: Prisma.InviteUncheckedCreateNestedManyWithoutTeamInput
|
||||
notifications?: Prisma.NotificationUncheckedCreateNestedManyWithoutTeamInput
|
||||
userMetadata?: Prisma.UserMetadataUncheckedCreateNestedManyWithoutTeamInput
|
||||
providers?: Prisma.ProviderUncheckedCreateNestedManyWithoutTeamInput
|
||||
skills?: Prisma.SkillUncheckedCreateNestedManyWithoutTeamInput
|
||||
}
|
||||
|
||||
export type TeamCreateOrConnectWithoutSandboxInput = {
|
||||
where: Prisma.TeamWhereUniqueInput
|
||||
create: Prisma.XOR<Prisma.TeamCreateWithoutSandboxInput, Prisma.TeamUncheckedCreateWithoutSandboxInput>
|
||||
}
|
||||
|
||||
export type TeamUpsertWithoutSandboxInput = {
|
||||
update: Prisma.XOR<Prisma.TeamUpdateWithoutSandboxInput, Prisma.TeamUncheckedUpdateWithoutSandboxInput>
|
||||
create: Prisma.XOR<Prisma.TeamCreateWithoutSandboxInput, Prisma.TeamUncheckedCreateWithoutSandboxInput>
|
||||
where?: Prisma.TeamWhereInput
|
||||
}
|
||||
|
||||
export type TeamUpdateToOneWithWhereWithoutSandboxInput = {
|
||||
where?: Prisma.TeamWhereInput
|
||||
data: Prisma.XOR<Prisma.TeamUpdateWithoutSandboxInput, Prisma.TeamUncheckedUpdateWithoutSandboxInput>
|
||||
}
|
||||
|
||||
export type TeamUpdateWithoutSandboxInput = {
|
||||
id?: Prisma.StringFieldUpdateOperationsInput | string
|
||||
name?: Prisma.StringFieldUpdateOperationsInput | string
|
||||
settings?:PrismaJson.Settings | Prisma.NullableJsonNullValueInput
|
||||
createdAt?: Prisma.DateTimeFieldUpdateOperationsInput | Date | string
|
||||
updatedAt?: Prisma.DateTimeFieldUpdateOperationsInput | Date | string
|
||||
rootFolder?: Prisma.AssetUpdateOneWithoutTeamRootFolderNestedInput
|
||||
members?: Prisma.TeamMemberUpdateManyWithoutTeamNestedInput
|
||||
projects?: Prisma.ProjectUpdateManyWithoutTeamNestedInput
|
||||
metadataFields?: Prisma.MetadataFieldUpdateManyWithoutTeamNestedInput
|
||||
invites?: Prisma.InviteUpdateManyWithoutTeamNestedInput
|
||||
notifications?: Prisma.NotificationUpdateManyWithoutTeamNestedInput
|
||||
userMetadata?: Prisma.UserMetadataUpdateManyWithoutTeamNestedInput
|
||||
providers?: Prisma.ProviderUpdateManyWithoutTeamNestedInput
|
||||
skills?: Prisma.SkillUpdateManyWithoutTeamNestedInput
|
||||
}
|
||||
|
||||
export type TeamUncheckedUpdateWithoutSandboxInput = {
|
||||
id?: Prisma.StringFieldUpdateOperationsInput | string
|
||||
name?: Prisma.StringFieldUpdateOperationsInput | string
|
||||
settings?:PrismaJson.Settings | Prisma.NullableJsonNullValueInput
|
||||
createdAt?: Prisma.DateTimeFieldUpdateOperationsInput | Date | string
|
||||
updatedAt?: Prisma.DateTimeFieldUpdateOperationsInput | Date | string
|
||||
rootFolderId?: Prisma.NullableStringFieldUpdateOperationsInput | string | null
|
||||
members?: Prisma.TeamMemberUncheckedUpdateManyWithoutTeamNestedInput
|
||||
projects?: Prisma.ProjectUncheckedUpdateManyWithoutTeamNestedInput
|
||||
metadataFields?: Prisma.MetadataFieldUncheckedUpdateManyWithoutTeamNestedInput
|
||||
invites?: Prisma.InviteUncheckedUpdateManyWithoutTeamNestedInput
|
||||
notifications?: Prisma.NotificationUncheckedUpdateManyWithoutTeamNestedInput
|
||||
userMetadata?: Prisma.UserMetadataUncheckedUpdateManyWithoutTeamNestedInput
|
||||
providers?: Prisma.ProviderUncheckedUpdateManyWithoutTeamNestedInput
|
||||
skills?: Prisma.SkillUncheckedUpdateManyWithoutTeamNestedInput
|
||||
}
|
||||
|
||||
export type TeamCreateWithoutSkillsInput = {
|
||||
id?: string
|
||||
name: string
|
||||
@@ -551,6 +656,7 @@ export type TeamCreateWithoutSkillsInput = {
|
||||
notifications?: Prisma.NotificationCreateNestedManyWithoutTeamInput
|
||||
userMetadata?: Prisma.UserMetadataCreateNestedManyWithoutTeamInput
|
||||
providers?: Prisma.ProviderCreateNestedManyWithoutTeamInput
|
||||
sandbox?: Prisma.SandboxCreateNestedOneWithoutTeamInput
|
||||
}
|
||||
|
||||
export type TeamUncheckedCreateWithoutSkillsInput = {
|
||||
@@ -567,6 +673,7 @@ export type TeamUncheckedCreateWithoutSkillsInput = {
|
||||
notifications?: Prisma.NotificationUncheckedCreateNestedManyWithoutTeamInput
|
||||
userMetadata?: Prisma.UserMetadataUncheckedCreateNestedManyWithoutTeamInput
|
||||
providers?: Prisma.ProviderUncheckedCreateNestedManyWithoutTeamInput
|
||||
sandbox?: Prisma.SandboxUncheckedCreateNestedOneWithoutTeamInput
|
||||
}
|
||||
|
||||
export type TeamCreateOrConnectWithoutSkillsInput = {
|
||||
@@ -599,6 +706,7 @@ export type TeamUpdateWithoutSkillsInput = {
|
||||
notifications?: Prisma.NotificationUpdateManyWithoutTeamNestedInput
|
||||
userMetadata?: Prisma.UserMetadataUpdateManyWithoutTeamNestedInput
|
||||
providers?: Prisma.ProviderUpdateManyWithoutTeamNestedInput
|
||||
sandbox?: Prisma.SandboxUpdateOneWithoutTeamNestedInput
|
||||
}
|
||||
|
||||
export type TeamUncheckedUpdateWithoutSkillsInput = {
|
||||
@@ -615,6 +723,7 @@ export type TeamUncheckedUpdateWithoutSkillsInput = {
|
||||
notifications?: Prisma.NotificationUncheckedUpdateManyWithoutTeamNestedInput
|
||||
userMetadata?: Prisma.UserMetadataUncheckedUpdateManyWithoutTeamNestedInput
|
||||
providers?: Prisma.ProviderUncheckedUpdateManyWithoutTeamNestedInput
|
||||
sandbox?: Prisma.SandboxUncheckedUpdateOneWithoutTeamNestedInput
|
||||
}
|
||||
|
||||
export type TeamCreateWithoutMembersInput = {
|
||||
@@ -631,6 +740,7 @@ export type TeamCreateWithoutMembersInput = {
|
||||
userMetadata?: Prisma.UserMetadataCreateNestedManyWithoutTeamInput
|
||||
providers?: Prisma.ProviderCreateNestedManyWithoutTeamInput
|
||||
skills?: Prisma.SkillCreateNestedManyWithoutTeamInput
|
||||
sandbox?: Prisma.SandboxCreateNestedOneWithoutTeamInput
|
||||
}
|
||||
|
||||
export type TeamUncheckedCreateWithoutMembersInput = {
|
||||
@@ -647,6 +757,7 @@ export type TeamUncheckedCreateWithoutMembersInput = {
|
||||
userMetadata?: Prisma.UserMetadataUncheckedCreateNestedManyWithoutTeamInput
|
||||
providers?: Prisma.ProviderUncheckedCreateNestedManyWithoutTeamInput
|
||||
skills?: Prisma.SkillUncheckedCreateNestedManyWithoutTeamInput
|
||||
sandbox?: Prisma.SandboxUncheckedCreateNestedOneWithoutTeamInput
|
||||
}
|
||||
|
||||
export type TeamCreateOrConnectWithoutMembersInput = {
|
||||
@@ -679,6 +790,7 @@ export type TeamUpdateWithoutMembersInput = {
|
||||
userMetadata?: Prisma.UserMetadataUpdateManyWithoutTeamNestedInput
|
||||
providers?: Prisma.ProviderUpdateManyWithoutTeamNestedInput
|
||||
skills?: Prisma.SkillUpdateManyWithoutTeamNestedInput
|
||||
sandbox?: Prisma.SandboxUpdateOneWithoutTeamNestedInput
|
||||
}
|
||||
|
||||
export type TeamUncheckedUpdateWithoutMembersInput = {
|
||||
@@ -695,6 +807,7 @@ export type TeamUncheckedUpdateWithoutMembersInput = {
|
||||
userMetadata?: Prisma.UserMetadataUncheckedUpdateManyWithoutTeamNestedInput
|
||||
providers?: Prisma.ProviderUncheckedUpdateManyWithoutTeamNestedInput
|
||||
skills?: Prisma.SkillUncheckedUpdateManyWithoutTeamNestedInput
|
||||
sandbox?: Prisma.SandboxUncheckedUpdateOneWithoutTeamNestedInput
|
||||
}
|
||||
|
||||
export type TeamCreateWithoutProjectsInput = {
|
||||
@@ -711,6 +824,7 @@ export type TeamCreateWithoutProjectsInput = {
|
||||
userMetadata?: Prisma.UserMetadataCreateNestedManyWithoutTeamInput
|
||||
providers?: Prisma.ProviderCreateNestedManyWithoutTeamInput
|
||||
skills?: Prisma.SkillCreateNestedManyWithoutTeamInput
|
||||
sandbox?: Prisma.SandboxCreateNestedOneWithoutTeamInput
|
||||
}
|
||||
|
||||
export type TeamUncheckedCreateWithoutProjectsInput = {
|
||||
@@ -727,6 +841,7 @@ export type TeamUncheckedCreateWithoutProjectsInput = {
|
||||
userMetadata?: Prisma.UserMetadataUncheckedCreateNestedManyWithoutTeamInput
|
||||
providers?: Prisma.ProviderUncheckedCreateNestedManyWithoutTeamInput
|
||||
skills?: Prisma.SkillUncheckedCreateNestedManyWithoutTeamInput
|
||||
sandbox?: Prisma.SandboxUncheckedCreateNestedOneWithoutTeamInput
|
||||
}
|
||||
|
||||
export type TeamCreateOrConnectWithoutProjectsInput = {
|
||||
@@ -759,6 +874,7 @@ export type TeamUpdateWithoutProjectsInput = {
|
||||
userMetadata?: Prisma.UserMetadataUpdateManyWithoutTeamNestedInput
|
||||
providers?: Prisma.ProviderUpdateManyWithoutTeamNestedInput
|
||||
skills?: Prisma.SkillUpdateManyWithoutTeamNestedInput
|
||||
sandbox?: Prisma.SandboxUpdateOneWithoutTeamNestedInput
|
||||
}
|
||||
|
||||
export type TeamUncheckedUpdateWithoutProjectsInput = {
|
||||
@@ -775,6 +891,7 @@ export type TeamUncheckedUpdateWithoutProjectsInput = {
|
||||
userMetadata?: Prisma.UserMetadataUncheckedUpdateManyWithoutTeamNestedInput
|
||||
providers?: Prisma.ProviderUncheckedUpdateManyWithoutTeamNestedInput
|
||||
skills?: Prisma.SkillUncheckedUpdateManyWithoutTeamNestedInput
|
||||
sandbox?: Prisma.SandboxUncheckedUpdateOneWithoutTeamNestedInput
|
||||
}
|
||||
|
||||
export type TeamCreateWithoutRootFolderInput = {
|
||||
@@ -791,6 +908,7 @@ export type TeamCreateWithoutRootFolderInput = {
|
||||
userMetadata?: Prisma.UserMetadataCreateNestedManyWithoutTeamInput
|
||||
providers?: Prisma.ProviderCreateNestedManyWithoutTeamInput
|
||||
skills?: Prisma.SkillCreateNestedManyWithoutTeamInput
|
||||
sandbox?: Prisma.SandboxCreateNestedOneWithoutTeamInput
|
||||
}
|
||||
|
||||
export type TeamUncheckedCreateWithoutRootFolderInput = {
|
||||
@@ -807,6 +925,7 @@ export type TeamUncheckedCreateWithoutRootFolderInput = {
|
||||
userMetadata?: Prisma.UserMetadataUncheckedCreateNestedManyWithoutTeamInput
|
||||
providers?: Prisma.ProviderUncheckedCreateNestedManyWithoutTeamInput
|
||||
skills?: Prisma.SkillUncheckedCreateNestedManyWithoutTeamInput
|
||||
sandbox?: Prisma.SandboxUncheckedCreateNestedOneWithoutTeamInput
|
||||
}
|
||||
|
||||
export type TeamCreateOrConnectWithoutRootFolderInput = {
|
||||
@@ -839,6 +958,7 @@ export type TeamUpdateWithoutRootFolderInput = {
|
||||
userMetadata?: Prisma.UserMetadataUpdateManyWithoutTeamNestedInput
|
||||
providers?: Prisma.ProviderUpdateManyWithoutTeamNestedInput
|
||||
skills?: Prisma.SkillUpdateManyWithoutTeamNestedInput
|
||||
sandbox?: Prisma.SandboxUpdateOneWithoutTeamNestedInput
|
||||
}
|
||||
|
||||
export type TeamUncheckedUpdateWithoutRootFolderInput = {
|
||||
@@ -855,6 +975,7 @@ export type TeamUncheckedUpdateWithoutRootFolderInput = {
|
||||
userMetadata?: Prisma.UserMetadataUncheckedUpdateManyWithoutTeamNestedInput
|
||||
providers?: Prisma.ProviderUncheckedUpdateManyWithoutTeamNestedInput
|
||||
skills?: Prisma.SkillUncheckedUpdateManyWithoutTeamNestedInput
|
||||
sandbox?: Prisma.SandboxUncheckedUpdateOneWithoutTeamNestedInput
|
||||
}
|
||||
|
||||
export type TeamCreateWithoutInvitesInput = {
|
||||
@@ -871,6 +992,7 @@ export type TeamCreateWithoutInvitesInput = {
|
||||
userMetadata?: Prisma.UserMetadataCreateNestedManyWithoutTeamInput
|
||||
providers?: Prisma.ProviderCreateNestedManyWithoutTeamInput
|
||||
skills?: Prisma.SkillCreateNestedManyWithoutTeamInput
|
||||
sandbox?: Prisma.SandboxCreateNestedOneWithoutTeamInput
|
||||
}
|
||||
|
||||
export type TeamUncheckedCreateWithoutInvitesInput = {
|
||||
@@ -887,6 +1009,7 @@ export type TeamUncheckedCreateWithoutInvitesInput = {
|
||||
userMetadata?: Prisma.UserMetadataUncheckedCreateNestedManyWithoutTeamInput
|
||||
providers?: Prisma.ProviderUncheckedCreateNestedManyWithoutTeamInput
|
||||
skills?: Prisma.SkillUncheckedCreateNestedManyWithoutTeamInput
|
||||
sandbox?: Prisma.SandboxUncheckedCreateNestedOneWithoutTeamInput
|
||||
}
|
||||
|
||||
export type TeamCreateOrConnectWithoutInvitesInput = {
|
||||
@@ -919,6 +1042,7 @@ export type TeamUpdateWithoutInvitesInput = {
|
||||
userMetadata?: Prisma.UserMetadataUpdateManyWithoutTeamNestedInput
|
||||
providers?: Prisma.ProviderUpdateManyWithoutTeamNestedInput
|
||||
skills?: Prisma.SkillUpdateManyWithoutTeamNestedInput
|
||||
sandbox?: Prisma.SandboxUpdateOneWithoutTeamNestedInput
|
||||
}
|
||||
|
||||
export type TeamUncheckedUpdateWithoutInvitesInput = {
|
||||
@@ -935,6 +1059,7 @@ export type TeamUncheckedUpdateWithoutInvitesInput = {
|
||||
userMetadata?: Prisma.UserMetadataUncheckedUpdateManyWithoutTeamNestedInput
|
||||
providers?: Prisma.ProviderUncheckedUpdateManyWithoutTeamNestedInput
|
||||
skills?: Prisma.SkillUncheckedUpdateManyWithoutTeamNestedInput
|
||||
sandbox?: Prisma.SandboxUncheckedUpdateOneWithoutTeamNestedInput
|
||||
}
|
||||
|
||||
export type TeamCreateWithoutMetadataFieldsInput = {
|
||||
@@ -951,6 +1076,7 @@ export type TeamCreateWithoutMetadataFieldsInput = {
|
||||
userMetadata?: Prisma.UserMetadataCreateNestedManyWithoutTeamInput
|
||||
providers?: Prisma.ProviderCreateNestedManyWithoutTeamInput
|
||||
skills?: Prisma.SkillCreateNestedManyWithoutTeamInput
|
||||
sandbox?: Prisma.SandboxCreateNestedOneWithoutTeamInput
|
||||
}
|
||||
|
||||
export type TeamUncheckedCreateWithoutMetadataFieldsInput = {
|
||||
@@ -967,6 +1093,7 @@ export type TeamUncheckedCreateWithoutMetadataFieldsInput = {
|
||||
userMetadata?: Prisma.UserMetadataUncheckedCreateNestedManyWithoutTeamInput
|
||||
providers?: Prisma.ProviderUncheckedCreateNestedManyWithoutTeamInput
|
||||
skills?: Prisma.SkillUncheckedCreateNestedManyWithoutTeamInput
|
||||
sandbox?: Prisma.SandboxUncheckedCreateNestedOneWithoutTeamInput
|
||||
}
|
||||
|
||||
export type TeamCreateOrConnectWithoutMetadataFieldsInput = {
|
||||
@@ -999,6 +1126,7 @@ export type TeamUpdateWithoutMetadataFieldsInput = {
|
||||
userMetadata?: Prisma.UserMetadataUpdateManyWithoutTeamNestedInput
|
||||
providers?: Prisma.ProviderUpdateManyWithoutTeamNestedInput
|
||||
skills?: Prisma.SkillUpdateManyWithoutTeamNestedInput
|
||||
sandbox?: Prisma.SandboxUpdateOneWithoutTeamNestedInput
|
||||
}
|
||||
|
||||
export type TeamUncheckedUpdateWithoutMetadataFieldsInput = {
|
||||
@@ -1015,6 +1143,7 @@ export type TeamUncheckedUpdateWithoutMetadataFieldsInput = {
|
||||
userMetadata?: Prisma.UserMetadataUncheckedUpdateManyWithoutTeamNestedInput
|
||||
providers?: Prisma.ProviderUncheckedUpdateManyWithoutTeamNestedInput
|
||||
skills?: Prisma.SkillUncheckedUpdateManyWithoutTeamNestedInput
|
||||
sandbox?: Prisma.SandboxUncheckedUpdateOneWithoutTeamNestedInput
|
||||
}
|
||||
|
||||
export type TeamCreateWithoutNotificationsInput = {
|
||||
@@ -1031,6 +1160,7 @@ export type TeamCreateWithoutNotificationsInput = {
|
||||
userMetadata?: Prisma.UserMetadataCreateNestedManyWithoutTeamInput
|
||||
providers?: Prisma.ProviderCreateNestedManyWithoutTeamInput
|
||||
skills?: Prisma.SkillCreateNestedManyWithoutTeamInput
|
||||
sandbox?: Prisma.SandboxCreateNestedOneWithoutTeamInput
|
||||
}
|
||||
|
||||
export type TeamUncheckedCreateWithoutNotificationsInput = {
|
||||
@@ -1047,6 +1177,7 @@ export type TeamUncheckedCreateWithoutNotificationsInput = {
|
||||
userMetadata?: Prisma.UserMetadataUncheckedCreateNestedManyWithoutTeamInput
|
||||
providers?: Prisma.ProviderUncheckedCreateNestedManyWithoutTeamInput
|
||||
skills?: Prisma.SkillUncheckedCreateNestedManyWithoutTeamInput
|
||||
sandbox?: Prisma.SandboxUncheckedCreateNestedOneWithoutTeamInput
|
||||
}
|
||||
|
||||
export type TeamCreateOrConnectWithoutNotificationsInput = {
|
||||
@@ -1079,6 +1210,7 @@ export type TeamUpdateWithoutNotificationsInput = {
|
||||
userMetadata?: Prisma.UserMetadataUpdateManyWithoutTeamNestedInput
|
||||
providers?: Prisma.ProviderUpdateManyWithoutTeamNestedInput
|
||||
skills?: Prisma.SkillUpdateManyWithoutTeamNestedInput
|
||||
sandbox?: Prisma.SandboxUpdateOneWithoutTeamNestedInput
|
||||
}
|
||||
|
||||
export type TeamUncheckedUpdateWithoutNotificationsInput = {
|
||||
@@ -1095,6 +1227,7 @@ export type TeamUncheckedUpdateWithoutNotificationsInput = {
|
||||
userMetadata?: Prisma.UserMetadataUncheckedUpdateManyWithoutTeamNestedInput
|
||||
providers?: Prisma.ProviderUncheckedUpdateManyWithoutTeamNestedInput
|
||||
skills?: Prisma.SkillUncheckedUpdateManyWithoutTeamNestedInput
|
||||
sandbox?: Prisma.SandboxUncheckedUpdateOneWithoutTeamNestedInput
|
||||
}
|
||||
|
||||
export type TeamCreateWithoutUserMetadataInput = {
|
||||
@@ -1111,6 +1244,7 @@ export type TeamCreateWithoutUserMetadataInput = {
|
||||
notifications?: Prisma.NotificationCreateNestedManyWithoutTeamInput
|
||||
providers?: Prisma.ProviderCreateNestedManyWithoutTeamInput
|
||||
skills?: Prisma.SkillCreateNestedManyWithoutTeamInput
|
||||
sandbox?: Prisma.SandboxCreateNestedOneWithoutTeamInput
|
||||
}
|
||||
|
||||
export type TeamUncheckedCreateWithoutUserMetadataInput = {
|
||||
@@ -1127,6 +1261,7 @@ export type TeamUncheckedCreateWithoutUserMetadataInput = {
|
||||
notifications?: Prisma.NotificationUncheckedCreateNestedManyWithoutTeamInput
|
||||
providers?: Prisma.ProviderUncheckedCreateNestedManyWithoutTeamInput
|
||||
skills?: Prisma.SkillUncheckedCreateNestedManyWithoutTeamInput
|
||||
sandbox?: Prisma.SandboxUncheckedCreateNestedOneWithoutTeamInput
|
||||
}
|
||||
|
||||
export type TeamCreateOrConnectWithoutUserMetadataInput = {
|
||||
@@ -1159,6 +1294,7 @@ export type TeamUpdateWithoutUserMetadataInput = {
|
||||
notifications?: Prisma.NotificationUpdateManyWithoutTeamNestedInput
|
||||
providers?: Prisma.ProviderUpdateManyWithoutTeamNestedInput
|
||||
skills?: Prisma.SkillUpdateManyWithoutTeamNestedInput
|
||||
sandbox?: Prisma.SandboxUpdateOneWithoutTeamNestedInput
|
||||
}
|
||||
|
||||
export type TeamUncheckedUpdateWithoutUserMetadataInput = {
|
||||
@@ -1175,6 +1311,7 @@ export type TeamUncheckedUpdateWithoutUserMetadataInput = {
|
||||
notifications?: Prisma.NotificationUncheckedUpdateManyWithoutTeamNestedInput
|
||||
providers?: Prisma.ProviderUncheckedUpdateManyWithoutTeamNestedInput
|
||||
skills?: Prisma.SkillUncheckedUpdateManyWithoutTeamNestedInput
|
||||
sandbox?: Prisma.SandboxUncheckedUpdateOneWithoutTeamNestedInput
|
||||
}
|
||||
|
||||
export type TeamCreateWithoutProvidersInput = {
|
||||
@@ -1191,6 +1328,7 @@ export type TeamCreateWithoutProvidersInput = {
|
||||
notifications?: Prisma.NotificationCreateNestedManyWithoutTeamInput
|
||||
userMetadata?: Prisma.UserMetadataCreateNestedManyWithoutTeamInput
|
||||
skills?: Prisma.SkillCreateNestedManyWithoutTeamInput
|
||||
sandbox?: Prisma.SandboxCreateNestedOneWithoutTeamInput
|
||||
}
|
||||
|
||||
export type TeamUncheckedCreateWithoutProvidersInput = {
|
||||
@@ -1207,6 +1345,7 @@ export type TeamUncheckedCreateWithoutProvidersInput = {
|
||||
notifications?: Prisma.NotificationUncheckedCreateNestedManyWithoutTeamInput
|
||||
userMetadata?: Prisma.UserMetadataUncheckedCreateNestedManyWithoutTeamInput
|
||||
skills?: Prisma.SkillUncheckedCreateNestedManyWithoutTeamInput
|
||||
sandbox?: Prisma.SandboxUncheckedCreateNestedOneWithoutTeamInput
|
||||
}
|
||||
|
||||
export type TeamCreateOrConnectWithoutProvidersInput = {
|
||||
@@ -1239,6 +1378,7 @@ export type TeamUpdateWithoutProvidersInput = {
|
||||
notifications?: Prisma.NotificationUpdateManyWithoutTeamNestedInput
|
||||
userMetadata?: Prisma.UserMetadataUpdateManyWithoutTeamNestedInput
|
||||
skills?: Prisma.SkillUpdateManyWithoutTeamNestedInput
|
||||
sandbox?: Prisma.SandboxUpdateOneWithoutTeamNestedInput
|
||||
}
|
||||
|
||||
export type TeamUncheckedUpdateWithoutProvidersInput = {
|
||||
@@ -1255,6 +1395,7 @@ export type TeamUncheckedUpdateWithoutProvidersInput = {
|
||||
notifications?: Prisma.NotificationUncheckedUpdateManyWithoutTeamNestedInput
|
||||
userMetadata?: Prisma.UserMetadataUncheckedUpdateManyWithoutTeamNestedInput
|
||||
skills?: Prisma.SkillUncheckedUpdateManyWithoutTeamNestedInput
|
||||
sandbox?: Prisma.SandboxUncheckedUpdateOneWithoutTeamNestedInput
|
||||
}
|
||||
|
||||
|
||||
@@ -1367,6 +1508,7 @@ export type TeamSelect<ExtArgs extends runtime.Types.Extensions.InternalArgs = r
|
||||
userMetadata?: boolean | Prisma.Team$userMetadataArgs<ExtArgs>
|
||||
providers?: boolean | Prisma.Team$providersArgs<ExtArgs>
|
||||
skills?: boolean | Prisma.Team$skillsArgs<ExtArgs>
|
||||
sandbox?: boolean | Prisma.Team$sandboxArgs<ExtArgs>
|
||||
_count?: boolean | Prisma.TeamCountOutputTypeDefaultArgs<ExtArgs>
|
||||
}, ExtArgs["result"]["team"]>
|
||||
|
||||
@@ -1410,6 +1552,7 @@ export type TeamInclude<ExtArgs extends runtime.Types.Extensions.InternalArgs =
|
||||
userMetadata?: boolean | Prisma.Team$userMetadataArgs<ExtArgs>
|
||||
providers?: boolean | Prisma.Team$providersArgs<ExtArgs>
|
||||
skills?: boolean | Prisma.Team$skillsArgs<ExtArgs>
|
||||
sandbox?: boolean | Prisma.Team$sandboxArgs<ExtArgs>
|
||||
_count?: boolean | Prisma.TeamCountOutputTypeDefaultArgs<ExtArgs>
|
||||
}
|
||||
export type TeamIncludeCreateManyAndReturn<ExtArgs extends runtime.Types.Extensions.InternalArgs = runtime.Types.Extensions.DefaultArgs> = {
|
||||
@@ -1431,6 +1574,7 @@ export type $TeamPayload<ExtArgs extends runtime.Types.Extensions.InternalArgs =
|
||||
userMetadata: Prisma.$UserMetadataPayload<ExtArgs>[]
|
||||
providers: Prisma.$ProviderPayload<ExtArgs>[]
|
||||
skills: Prisma.$SkillPayload<ExtArgs>[]
|
||||
sandbox: Prisma.$SandboxPayload<ExtArgs> | null
|
||||
}
|
||||
scalars: runtime.Types.Extensions.GetPayloadResult<{
|
||||
id: string
|
||||
@@ -1845,6 +1989,7 @@ export interface Prisma__TeamClient<T, Null = never, ExtArgs extends runtime.Typ
|
||||
userMetadata<T extends Prisma.Team$userMetadataArgs<ExtArgs> = {}>(args?: Prisma.Subset<T, Prisma.Team$userMetadataArgs<ExtArgs>>): Prisma.PrismaPromise<runtime.Types.Result.GetResult<Prisma.$UserMetadataPayload<ExtArgs>, T, "findMany", GlobalOmitOptions> | Null>
|
||||
providers<T extends Prisma.Team$providersArgs<ExtArgs> = {}>(args?: Prisma.Subset<T, Prisma.Team$providersArgs<ExtArgs>>): Prisma.PrismaPromise<runtime.Types.Result.GetResult<Prisma.$ProviderPayload<ExtArgs>, T, "findMany", GlobalOmitOptions> | Null>
|
||||
skills<T extends Prisma.Team$skillsArgs<ExtArgs> = {}>(args?: Prisma.Subset<T, Prisma.Team$skillsArgs<ExtArgs>>): Prisma.PrismaPromise<runtime.Types.Result.GetResult<Prisma.$SkillPayload<ExtArgs>, T, "findMany", GlobalOmitOptions> | Null>
|
||||
sandbox<T extends Prisma.Team$sandboxArgs<ExtArgs> = {}>(args?: Prisma.Subset<T, Prisma.Team$sandboxArgs<ExtArgs>>): Prisma.Prisma__SandboxClient<runtime.Types.Result.GetResult<Prisma.$SandboxPayload<ExtArgs>, T, "findUniqueOrThrow", GlobalOmitOptions> | null, null, ExtArgs, GlobalOmitOptions>
|
||||
/**
|
||||
* Attaches callbacks for the resolution and/or rejection of the Promise.
|
||||
* @param onfulfilled The callback to execute when the Promise is resolved.
|
||||
@@ -2491,6 +2636,25 @@ export type Team$skillsArgs<ExtArgs extends runtime.Types.Extensions.InternalArg
|
||||
distinct?: Prisma.SkillScalarFieldEnum | Prisma.SkillScalarFieldEnum[]
|
||||
}
|
||||
|
||||
/**
|
||||
* Team.sandbox
|
||||
*/
|
||||
export type Team$sandboxArgs<ExtArgs extends runtime.Types.Extensions.InternalArgs = runtime.Types.Extensions.DefaultArgs> = {
|
||||
/**
|
||||
* Select specific fields to fetch from the Sandbox
|
||||
*/
|
||||
select?: Prisma.SandboxSelect<ExtArgs> | null
|
||||
/**
|
||||
* Omit specific fields from the Sandbox
|
||||
*/
|
||||
omit?: Prisma.SandboxOmit<ExtArgs> | null
|
||||
/**
|
||||
* Choose, which related nodes to fetch as well
|
||||
*/
|
||||
include?: Prisma.SandboxInclude<ExtArgs> | null
|
||||
where?: Prisma.SandboxWhereInput
|
||||
}
|
||||
|
||||
/**
|
||||
* Team without action
|
||||
*/
|
||||
|
||||
@@ -45,9 +45,12 @@ describe('SkillService', () => {
|
||||
},
|
||||
})
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- mocking s3Service return value
|
||||
const getObjectSpy = vi.spyOn(s3Service, 'getObject').mockResolvedValue({ buffer: zipBuffer, contentType: 'application/zip' } as any)
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- mocking s3Service return value
|
||||
const getObjectSpy = vi.spyOn(s3Service, 'getObject').mockResolvedValue({
|
||||
buffer: zipBuffer,
|
||||
contentType: 'application/zip',
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
} as any)
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
const putObjectSpy = vi.spyOn(s3Service, 'putObject').mockResolvedValue(undefined as any)
|
||||
|
||||
const skill = await skillService.upsertSkill(team.id, {
|
||||
|
||||
@@ -179,4 +179,53 @@ describe('TeamService', () => {
|
||||
const newSettings = await teamService.getSettings(team.id)
|
||||
expect(newSettings).toEqual({ theme: 'dark' })
|
||||
})
|
||||
|
||||
it('should create sandbox when team is created', async () => {
|
||||
const user = await prisma.user.create({
|
||||
data: { name: 'Test User', email: `test-sandbox-${Date.now()}@example.com`, password: 'pw' },
|
||||
})
|
||||
|
||||
const team = await teamService.createTeam(user, {
|
||||
name: 'Sandbox Team',
|
||||
})
|
||||
|
||||
const sandbox = await prisma.sandbox.findUnique({
|
||||
where: { teamId: team.id },
|
||||
})
|
||||
|
||||
expect(sandbox).toBeDefined()
|
||||
expect(sandbox?.allowedDomains).toContain('github.com')
|
||||
})
|
||||
|
||||
it('should get and update sandbox settings', async () => {
|
||||
const user = await prisma.user.create({
|
||||
data: { name: 'Test User', email: `test-settings-${Date.now()}@example.com`, password: 'pw' },
|
||||
})
|
||||
const team = await teamService.createTeam(user, {
|
||||
name: 'Settings Team',
|
||||
})
|
||||
|
||||
// Should have default settings
|
||||
const settings = await teamService.getSandboxSettings(team.id)
|
||||
expect(settings.allowedDomains).toContain('github.com')
|
||||
|
||||
// Should update settings
|
||||
const updated = await teamService.updateSandboxSettings(team.id, {
|
||||
allowedDomains: ['example.com'],
|
||||
})
|
||||
expect(updated.allowedDomains).toEqual(['example.com'])
|
||||
|
||||
// Should persist to DB
|
||||
const persisted = await teamService.getSandboxSettings(team.id)
|
||||
expect(persisted.allowedDomains).toEqual(['example.com'])
|
||||
})
|
||||
|
||||
it('should return empty allowedDomains if sandbox is missing for old team', async () => {
|
||||
const team = await prisma.team.create({
|
||||
data: { name: 'Old Team' },
|
||||
})
|
||||
|
||||
const settings = await teamService.getSandboxSettings(team.id)
|
||||
expect(settings.allowedDomains).toEqual([])
|
||||
})
|
||||
})
|
||||
|
||||
@@ -11,6 +11,7 @@ import {
|
||||
TeamInfo,
|
||||
GetMeResponse,
|
||||
UserInfo,
|
||||
SandboxSettings,
|
||||
} from '@/dtos/team'
|
||||
|
||||
export class TeamService {
|
||||
@@ -25,6 +26,7 @@ export class TeamService {
|
||||
enablePublicSignup: true,
|
||||
transcode: { videoStrategy: 'disable', imageStrategy: 'disable' },
|
||||
},
|
||||
sandbox: { create: {} },
|
||||
},
|
||||
})
|
||||
await providerService.initBuiltinProviders(team.id)
|
||||
@@ -41,6 +43,7 @@ export class TeamService {
|
||||
name: req.name,
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
settings: {} as any,
|
||||
sandbox: { create: {} },
|
||||
},
|
||||
})
|
||||
|
||||
@@ -202,6 +205,31 @@ export class TeamService {
|
||||
return updated.settings || {}
|
||||
}
|
||||
|
||||
async getSandboxSettings(teamId: string): Promise<SandboxSettings> {
|
||||
const sandbox = await prisma.sandbox.findUnique({
|
||||
where: { teamId },
|
||||
})
|
||||
return {
|
||||
allowedDomains: sandbox?.allowedDomains || [],
|
||||
}
|
||||
}
|
||||
|
||||
async updateSandboxSettings(teamId: string, settings: SandboxSettings): Promise<SandboxSettings> {
|
||||
const sandbox = await prisma.sandbox.upsert({
|
||||
where: { teamId },
|
||||
create: {
|
||||
teamId,
|
||||
allowedDomains: settings.allowedDomains,
|
||||
},
|
||||
update: {
|
||||
allowedDomains: settings.allowedDomains,
|
||||
},
|
||||
})
|
||||
return {
|
||||
allowedDomains: sandbox.allowedDomains,
|
||||
}
|
||||
}
|
||||
|
||||
async getSignupInfo() {
|
||||
const count = await prisma.user.count()
|
||||
const defaultTeam = await this.ensureDefaultTeam()
|
||||
|
||||
@@ -11,9 +11,11 @@ export interface GetMediaInfoActivityParams {
|
||||
mediaType: string
|
||||
}
|
||||
|
||||
export async function getMediaInfoActivity(
|
||||
params: { filePath: string; assetId: string; mediaType: string },
|
||||
): Promise<PrismaJson.MediaInfo> {
|
||||
export async function getMediaInfoActivity(params: {
|
||||
filePath: string
|
||||
assetId: string
|
||||
mediaType: string
|
||||
}): Promise<PrismaJson.MediaInfo> {
|
||||
const isVideo = params.mediaType.startsWith('video/')
|
||||
const isImage = params.mediaType.startsWith('image/')
|
||||
|
||||
|
||||
@@ -0,0 +1,136 @@
|
||||
import { useState } from 'react'
|
||||
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query'
|
||||
import { client } from '@/ui/api/client'
|
||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/ui/components/ui/card'
|
||||
import { Input } from '@/ui/components/ui/input'
|
||||
import { Button } from '@/ui/components/ui/button'
|
||||
import { Loader2, Plus, X, Globe } from 'lucide-react'
|
||||
import { toast } from 'sonner'
|
||||
|
||||
export function SandboxSettings({ teamId }: { teamId: string }) {
|
||||
const queryClient = useQueryClient()
|
||||
const [newDomain, setNewDomain] = useState('')
|
||||
|
||||
const { data: sandbox, isLoading } = useQuery({
|
||||
queryKey: ['teams', teamId, 'sandbox'],
|
||||
queryFn: async () => {
|
||||
const res = await client.api.teams[':teamId'].sandbox.$get({
|
||||
param: { teamId },
|
||||
})
|
||||
if (!res.ok) throw new Error('Failed to fetch sandbox settings')
|
||||
return await res.json()
|
||||
},
|
||||
})
|
||||
|
||||
const { mutate: updateSandbox, isPending: isUpdating } = useMutation({
|
||||
mutationFn: async (allowedDomains: string[]) => {
|
||||
const res = await client.api.teams[':teamId'].sandbox.$put({
|
||||
param: { teamId },
|
||||
json: { allowedDomains },
|
||||
})
|
||||
if (!res.ok) throw new Error('Failed to update sandbox settings')
|
||||
return await res.json()
|
||||
},
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ['teams', teamId, 'sandbox'] })
|
||||
toast.success('Sandbox settings updated')
|
||||
},
|
||||
onError: (err) => {
|
||||
toast.error(err instanceof Error ? err.message : 'Failed to update sandbox settings')
|
||||
},
|
||||
})
|
||||
|
||||
const handleAddDomain = (e: React.FormEvent) => {
|
||||
e.preventDefault()
|
||||
if (!newDomain.trim()) return
|
||||
if (sandbox?.allowedDomains.includes(newDomain.trim())) {
|
||||
toast.error('Domain already exists')
|
||||
return
|
||||
}
|
||||
const updated = [...(sandbox?.allowedDomains || []), newDomain.trim()]
|
||||
updateSandbox(updated)
|
||||
setNewDomain('')
|
||||
}
|
||||
|
||||
const handleRemoveDomain = (domain: string) => {
|
||||
const updated = (sandbox?.allowedDomains || []).filter((d) => d !== domain)
|
||||
updateSandbox(updated)
|
||||
}
|
||||
|
||||
if (isLoading) {
|
||||
return (
|
||||
<div className="flex items-center justify-center p-8">
|
||||
<Loader2 className="h-8 w-8 animate-spin text-muted-foreground" />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="h-full overflow-y-auto space-y-6 pr-1">
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<div className="flex items-center gap-2">
|
||||
<Globe className="w-5 h-5 text-blue-500" />
|
||||
<CardTitle>Network Sandbox</CardTitle>
|
||||
</div>
|
||||
<CardDescription>
|
||||
Configure allowed domains for the sandboxed agent. By default, only essential domains
|
||||
are allowed.
|
||||
</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<form onSubmit={handleAddDomain} className="flex gap-2 mb-6">
|
||||
<Input
|
||||
placeholder="e.g. api.openai.com"
|
||||
value={newDomain}
|
||||
onChange={(e) => setNewDomain(e.target.value)}
|
||||
disabled={isUpdating}
|
||||
/>
|
||||
<Button type="submit" disabled={isUpdating}>
|
||||
{isUpdating ? (
|
||||
<Loader2 className="w-4 h-4 animate-spin" />
|
||||
) : (
|
||||
<Plus className="w-4 h-4 mr-2" />
|
||||
)}
|
||||
Add Domain
|
||||
</Button>
|
||||
</form>
|
||||
|
||||
<div className="space-y-2">
|
||||
<h4 className="text-sm font-medium text-slate-500 mb-3">Allowed Domains</h4>
|
||||
<div className="flex flex-wrap gap-2">
|
||||
{sandbox?.allowedDomains.map((domain) => (
|
||||
<div
|
||||
key={domain}
|
||||
className="flex items-center gap-1 px-3 py-1.5 bg-slate-100 dark:bg-slate-800 rounded-full text-sm border border-slate-200 dark:border-slate-700 transition-all hover:border-slate-300 dark:hover:border-slate-600"
|
||||
>
|
||||
<span className="font-medium text-slate-700 dark:text-slate-300">{domain}</span>
|
||||
<button
|
||||
onClick={() => handleRemoveDomain(domain)}
|
||||
className="ml-1 text-slate-400 hover:text-red-500 transition-colors"
|
||||
disabled={isUpdating}
|
||||
>
|
||||
<X className="w-3.5 h-3.5" />
|
||||
</button>
|
||||
</div>
|
||||
))}
|
||||
{sandbox?.allowedDomains.length === 0 && (
|
||||
<div className="text-sm text-slate-400 italic">No custom domains allowed</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle>Filesystem Restriction</CardTitle>
|
||||
<CardDescription>
|
||||
The agent is restricted to reading and writing only within the <code>.pi</code> and{' '}
|
||||
<code>/tmp</code> folders. These settings are currently hardcoded for security.
|
||||
</CardDescription>
|
||||
</CardHeader>
|
||||
</Card>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -31,8 +31,6 @@ import {
|
||||
AlertDialogHeader,
|
||||
AlertDialogTitle,
|
||||
} from '@/ui/components/ui/alert-dialog'
|
||||
// @ts-ignore - Import browser distribution to avoid Node.js built-ins in the bundle
|
||||
import JSZip from 'jszip/dist/jszip.min.js'
|
||||
import { SkillInfo } from '@/dtos/skill'
|
||||
|
||||
interface SkillsConfigCardProps {
|
||||
@@ -305,31 +303,17 @@ const AddSkillDialog = ({
|
||||
return
|
||||
}
|
||||
|
||||
const fileToUpload = files[0]
|
||||
if (!fileToUpload.name.toLowerCase().endsWith('.zip')) {
|
||||
alert('Only .zip files are supported.')
|
||||
return
|
||||
}
|
||||
|
||||
setIsProcessing(true)
|
||||
|
||||
try {
|
||||
let fileToUpload: File | Blob
|
||||
let fileName: string
|
||||
let contentType = 'application/zip'
|
||||
|
||||
// Check if it's a ZIP file or a collection of files (folder)
|
||||
const isZip = files.length === 1 && files[0].name.toLowerCase().endsWith('.zip')
|
||||
|
||||
if (isZip) {
|
||||
fileToUpload = files[0]
|
||||
fileName = files[0].name
|
||||
contentType = files[0].type || 'application/zip'
|
||||
} else {
|
||||
const zip = new JSZip()
|
||||
for (let i = 0; i < files.length; i++) {
|
||||
const f = files[i]
|
||||
// Use relative path for folder structure if available
|
||||
const path = f.webkitRelativePath || f.name
|
||||
zip.file(path, f)
|
||||
}
|
||||
fileToUpload = await zip.generateAsync({ type: 'blob' })
|
||||
fileName = 'skill_package.zip'
|
||||
}
|
||||
const fileName = fileToUpload.name
|
||||
const contentType = fileToUpload.type || 'application/zip'
|
||||
|
||||
// 1. Get Presigned URL and Asset ID
|
||||
const attachRes = await client.api.projects[':projectId'].attachments.$post({
|
||||
@@ -373,12 +357,12 @@ const AddSkillDialog = ({
|
||||
<DialogHeader>
|
||||
<DialogTitle>Add New Skill</DialogTitle>
|
||||
<DialogDescription>
|
||||
Import a skill from a local ZIP/folder or a GitHub repository.
|
||||
Import a skill from a local ZIP archive or a GitHub repository.
|
||||
</DialogDescription>
|
||||
</DialogHeader>
|
||||
|
||||
<div className="space-y-6 pt-4">
|
||||
{/* File/Folder Upload Section */}
|
||||
{/* File Upload Section */}
|
||||
<div className="space-y-3">
|
||||
<Label>Package Upload</Label>
|
||||
<div
|
||||
@@ -395,10 +379,6 @@ const AddSkillDialog = ({
|
||||
ref={fileInputRef}
|
||||
className="hidden"
|
||||
accept=".zip"
|
||||
// @ts-ignore
|
||||
webkitdirectory=""
|
||||
directory=""
|
||||
multiple
|
||||
onChange={(e) => handleFileUpload(e.target.files)}
|
||||
/>
|
||||
<div className="p-3 bg-slate-100 dark:bg-slate-800 rounded-full group-hover:bg-blue-100 dark:group-hover:bg-blue-900/30 transition-colors">
|
||||
@@ -406,7 +386,7 @@ const AddSkillDialog = ({
|
||||
</div>
|
||||
<div className="mt-3 text-center">
|
||||
<p className="text-sm font-medium text-slate-700 dark:text-slate-300">
|
||||
Select ZIP file or folder
|
||||
Select ZIP file
|
||||
</p>
|
||||
<p className="text-[10px] text-slate-500 dark:text-slate-400 mt-1 uppercase tracking-wider font-semibold">
|
||||
Packages must contain a SKILL.md
|
||||
|
||||
@@ -10,9 +10,10 @@ import { useState } from 'react'
|
||||
import { ProvidersSettings } from '@/ui/components/settings/ProvidersSettings'
|
||||
import { SkillsConfigCard } from '@/ui/components/settings/SkillsConfigCard'
|
||||
import { AgentsSettings } from '@/ui/components/settings/AgentsSettings'
|
||||
import { Bot } from 'lucide-react'
|
||||
import { SandboxSettings } from '@/ui/components/settings/SandboxSettings'
|
||||
import { Bot, Shield } from 'lucide-react'
|
||||
|
||||
type SettingsTab = 'general' | 'transcode' | 'skills' | 'providers' | 'agents'
|
||||
type SettingsTab = 'general' | 'transcode' | 'skills' | 'providers' | 'agents' | 'sandbox'
|
||||
|
||||
function TeamSettingsPage() {
|
||||
const { teamId } = Route.useParams()
|
||||
@@ -196,6 +197,22 @@ function TeamSettingsPage() {
|
||||
<div className="ml-auto w-1.5 h-1.5 rounded-full bg-blue-600 dark:bg-blue-400" />
|
||||
)}
|
||||
</button>
|
||||
|
||||
<button
|
||||
onClick={() => setActiveTab('sandbox')}
|
||||
className={cn(
|
||||
'w-full flex items-center gap-3 px-4 py-3 text-sm font-medium rounded-lg transition-all',
|
||||
activeTab === 'sandbox'
|
||||
? 'bg-blue-50 dark:bg-blue-900/20 text-blue-700 dark:text-blue-300 ring-1 ring-blue-200 dark:ring-blue-800'
|
||||
: 'text-slate-600 dark:text-slate-400 hover:bg-slate-50 dark:hover:bg-slate-800 hover:text-slate-900 dark:hover:text-white',
|
||||
)}
|
||||
>
|
||||
<Shield className="w-5 h-5" />
|
||||
Agent Sandbox
|
||||
{activeTab === 'sandbox' && (
|
||||
<div className="ml-auto w-1.5 h-1.5 rounded-full bg-blue-600 dark:bg-blue-400" />
|
||||
)}
|
||||
</button>
|
||||
</nav>
|
||||
</aside>
|
||||
|
||||
@@ -210,6 +227,7 @@ function TeamSettingsPage() {
|
||||
{activeTab === 'skills' && 'Skills Management'}
|
||||
{activeTab === 'providers' && 'AI Providers'}
|
||||
{activeTab === 'agents' && 'AI Agents'}
|
||||
{activeTab === 'sandbox' && 'Agent Sandbox Settings'}
|
||||
</h2>
|
||||
<p className="text-sm text-slate-500 dark:text-slate-400 mt-1">
|
||||
{activeTab === 'general' && 'View your personal information and team role.'}
|
||||
@@ -219,6 +237,8 @@ function TeamSettingsPage() {
|
||||
{activeTab === 'providers' &&
|
||||
'Configure AI providers and their models for this team.'}
|
||||
{activeTab === 'agents' && 'Manage AI agents and their personalities.'}
|
||||
{activeTab === 'sandbox' &&
|
||||
'Configure security and network restrictions for the AI agent.'}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
@@ -397,6 +417,12 @@ function TeamSettingsPage() {
|
||||
<AgentsSettings teamId={teamId} />
|
||||
</div>
|
||||
)}
|
||||
|
||||
{activeTab === 'sandbox' && (
|
||||
<div className="h-full overflow-y-auto pr-1">
|
||||
<SandboxSettings teamId={teamId} />
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
|
||||
@@ -42,7 +42,10 @@ describe('WorkflowService', () => {
|
||||
})
|
||||
|
||||
it('should process ai_transcription task locally', async () => {
|
||||
vi.mocked(s3Service.getObject).mockResolvedValue({ buffer: Buffer.from('fake data'), contentType: 'audio/mpeg' })
|
||||
vi.mocked(s3Service.getObject).mockResolvedValue({
|
||||
buffer: Buffer.from('fake data'),
|
||||
contentType: 'audio/mpeg',
|
||||
})
|
||||
|
||||
const asset = await prisma.asset.create({
|
||||
data: {
|
||||
|
||||
@@ -1,5 +1,11 @@
|
||||
import type { WorkflowTask } from '@/generated/prisma/client'
|
||||
import { getActivities, executeActivity, TaskQueueDb, TaskQueueTranscode, sleep } from '../workflow-utils'
|
||||
import {
|
||||
getActivities,
|
||||
executeActivity,
|
||||
TaskQueueDb,
|
||||
TaskQueueTranscode,
|
||||
sleep,
|
||||
} from '../workflow-utils'
|
||||
|
||||
export async function aiTranscriptionMedia(task: WorkflowTask): Promise<void> {
|
||||
const {
|
||||
|
||||
Reference in New Issue
Block a user