Merge pull request #53 from shumaiOne/refactor/monorepo

refactor(monorepo): migrate monolithic codebase to multi-package workspaces monorepo
This commit is contained in:
Yiling-J
2026-06-02 19:45:21 +08:00
committed by GitHub
472 changed files with 45874 additions and 36465 deletions
+73 -38
View File
@@ -109,14 +109,51 @@ The backend is built with:
- **ORM**: Prisma (with Pgvector18) - **ORM**: Prisma (with Pgvector18)
- **Database**: Pgvector18 - **Database**: Pgvector18
### Layered Architecture ## Workspace Architecture
We follow a strict layered architecture: The project is a monorepo managed by **Bun Workspaces**. It follows a strictly decoupled architecture where each domain or layer is its own package:
1. **API Layer (`src/api`)**: Handles HTTP requests, validation, and calls Service layer. **Do not access DB directly.**, **Do not return prisma object directly in api, use dto to avoid leak** - **WebUI (`packages/webui`)**: React-based frontend.
2. **DTO Layer (`src/dtos`)**: All dtos used in api, which also used by ui for type-safty. - **API (`packages/api`)**: Hono-based HTTP entry point. Handles requests and calls Core services.
3. **Service Layer (`src/services`)**: Contains business logic and interacts with the Database via Prisma. - **Core (`packages/core`)**: Business logic, services, and infrastructure utilities.
4. **Data Layer (`src/db.ts`)**: Exports the Prisma Client instance. - **Database (`packages/db`)**: Prisma client, schema, and migrations.
- **DTOs (`packages/dtos`)**: Shared type definitions and Zod schemas used by both API and WebUI.
- **Workers**: Specialized packages for background task execution:
- `@shumai/workflow-core`: Common workflow engine logic.
- `@shumai/agent`: AI agent workflows and activities.
- `@shumai/transcode`: Media processing workflows and activities.
### Layered Communication Rules
1. **API Layer** calls **Core Layer**. Do not access the database directly in the API layer.
2. **Core Layer** calls **Database Layer** and other Core services.
3. **DTO Layer** is imported by all layers to ensure end-to-end type safety.
4. **No Direct DB Leak**: Do not return Prisma objects directly from the API; always map them to DTOs.
## Dependency Management
We follow Bun's monorepo conventions for dependency management:
1. **Self-Contained Packages**: Every workspace package MUST declare its own runtime `dependencies` in its local `package.json`. Do not rely on dependencies being available via the root.
2. **Shared DevDependencies**: Common development tools (e.g., `typescript`, `eslint`, `vitest`, `prettier`, `prisma`) MUST be declared in the root `package.json` to ensure version consistency across the workspace.
3. **Local DevDependencies**: Tools specific to a single package (e.g., `@vitejs/plugin-react` for `webui`) should be declared in that package's local `package.json`.
4. **Workspace Imports**: Use `workspace:*` for internal package dependencies.
5. **Clean Root**: The root `package.json` must not contain runtime `dependencies`. It is reserved for shared `devDependencies` and workspace-wide `scripts`.
6. **Installation**: Always run `bun install` from the root. Use the `--filter` flag if you only want to update a specific package (e.g., `bun install --filter @shumai/webui`).
## TypeScript Configuration
We use a root-level `tsconfig.json` to manage path mappings for the entire workspace. This ensures that imports across packages resolve correctly during typechecking and in the IDE.
1. **Path Mappings**: All workspace packages MUST have an entry in the `paths` object in the root `tsconfig.json`.
```json
"paths": {
"@shumai/core": ["packages/core/src/index.ts"],
"@shumai/core/src/*": ["packages/core/src/*"]
}
```
2. **Package tsconfig**: Each package should have its own `tsconfig.json` that extends the root configuration and defines its specific `include`/`exclude` rules.
3. **Cross-Package Resolution**: When adding a new package, you MUST update the root `tsconfig.json` path mappings to ensure it can be imported by other packages.
### Service Layer Patterns ### Service Layer Patterns
@@ -130,7 +167,7 @@ We follow a strict layered architecture:
``` ```
- **Usage**: Import and use the exported instance. - **Usage**: Import and use the exported instance.
```typescript ```typescript
import { myService } from '../services/myService' import { myService } from '@shumai/core/src/services/myService'
await myService.doSomething() await myService.doSomething()
``` ```
@@ -161,7 +198,7 @@ The frontend is built with:
### Development ### Development
- **Run Dev**: `bun --hot src/index.ts` (Runs on port 3000) - **Run Dev**: `bun run dev` (Runs on port 3000)
## Testing ## Testing
@@ -179,16 +216,15 @@ We use **Vitest** for testing (via `bun run test`). **Do not use `bun test`** as
### Service Tests ### Service Tests
- Located in `src/services/*.test.ts`. - Located in `packages/core/src/**/*.test.ts`.
- For comprehensive testing against a real database instance, we use `Testcontainers` alongside a `PrismaTestingHelper` which wraps each test within an automatic PostgreSQL transaction rollback boundary. - For comprehensive testing against a real database instance, we use `Testcontainers` alongside a `PrismaTestingHelper` which wraps each test within an automatic PostgreSQL transaction rollback boundary.
- All service tests must use `setupTestDbHooks()` to initialize the database boundaries for each test suite inside the `describe` block. This automatically registers `beforeEach` and `afterEach` hooks to manage transaction state. - All service tests must use `setupTestDbHooks()` from `@shumai/db` to initialize the database boundaries for each test suite inside the `describe` block. This automatically registers `beforeEach` and `afterEach` hooks to manage transaction state.
- Import `prisma` from `@/db` directly to interact with the database in tests. The testing helper automatically proxies it. - Import `prisma` from `@shumai/db` directly to interact with the database in tests. The testing helper automatically proxies it.
```typescript ```typescript
import { describe, it, expect } from 'vitest' import { describe, it, expect } from 'vitest'
import { prisma } from '@/db' import { prisma, setupTestDbHooks } from '@shumai/db'
import { setupTestDbHooks } from '@/db-test-hooks' import { teamService } from '@shumai/core/src/team/team'
import { teamService } from './team'
describe('TeamService', () => { describe('TeamService', () => {
setupTestDbHooks() setupTestDbHooks()
@@ -208,13 +244,13 @@ The `bunfig.toml` is configured to run `setup-tests.ts` automatically as a prelo
### API Tests ### API Tests
- Located in `src/api/*.test.ts`. - Located in `packages/api/src/api/**/*.test.ts`.
- Mock the Service layer using `vi.spyOn(service, 'method')` or `vi.mock('@/services/myService')`. - Mock the Service layer using `vi.spyOn(service, 'method')` or `vi.mock('@shumai/core/src/team/team')`.
- Verify that the API calls the Service methods correctly. - Verify that the API calls the Service methods correctly.
```typescript ```typescript
import { describe, it, expect, vi } from 'vitest' import { describe, it, expect, vi } from 'vitest'
import { teamService } from '@/services/team/team' import { teamService } from '@shumai/core/src/team/team'
import app from './team' import app from './team'
describe('Team API', () => { describe('Team API', () => {
@@ -233,22 +269,22 @@ describe('Team API', () => {
## Prisma Configuration & Migrations ## Prisma Configuration & Migrations
- Schema: `prisma/schema.prisma` - Schema: `packages/db/prisma/schema.prisma`
- Generated Client: `src/generated/prisma` - Generated Client: `packages/db/src/generated/prisma`
- Config: `prisma.config.ts` (Required for Prisma 7+) - Config: `prisma.config.ts` (Required for Prisma 7+)
### Strict JSON Typing ### Strict JSON Typing
We use `prisma-json-types-generator` to enforce strict type-safety for Prisma `Json` columns, rather than typing them as generic `JsonValue`. We use `prisma-json-types-generator` to enforce strict type-safety for Prisma `Json` columns, rather than typing them as generic `JsonValue`.
- **Defining Types**: In `prisma/schema.prisma`, annotate the JSON column with a triple-slash comment specifying the type name from `src/prisma-json-types.ts`: - **Defining Types**: In `packages/db/prisma/schema.prisma`, annotate the JSON column with a triple-slash comment specifying the type name from `packages/db/src/prisma-json-types.ts`:
```prisma ```prisma
model WorkflowTask { model WorkflowTask {
/// [WorkflowTaskPayload] /// [WorkflowTaskPayload]
payload Json? payload Json?
} }
``` ```
- **Declaring Types**: All typed JSON shapes must be defined in `src/prisma-json-types.ts` under the global `PrismaJson` namespace: - **Declaring Types**: All typed JSON shapes must be defined in `packages/db/src/prisma-json-types.ts` under the global `PrismaJson` namespace:
```typescript ```typescript
declare global { declare global {
namespace PrismaJson { namespace PrismaJson {
@@ -280,20 +316,20 @@ model Example {
} }
``` ```
- **No Manual Assignment**: Do not manually generate or assign ULIDs in application code (e.g., `src/services/*.ts`) for creating database records. Let Prisma handle it via the schema default. - **No Manual Assignment**: Do not manually generate or assign ULIDs in application code (e.g., `packages/core/src/*.ts`) for creating database records. Let Prisma handle it via the schema default.
- Exception: File names generated by `FileService` may still use `ulid()` internally, but this is separate from the database ID. - Exception: File names generated by `FileService` may still use `ulid()` internally, but this is separate from the database ID.
- **Sorting**: All list APIs must order results by `id` descending (`orderBy: { id: 'desc' }`) to ensure consistent, time-based sorting (since ULIDs are sortable). Do not sort by `createdAt` as it is not indexed. - **Sorting**: All list APIs must order results by `id` descending (`orderBy: { id: 'desc' }`) to ensure consistent, time-based sorting (since ULIDs are sortable). Do not sort by `createdAt` as it is not indexed.
## Infinite Scroll & Pagination ## Infinite Scroll & Pagination
- **Frontend**: Use the `useInfiniteScroll` hook for all list UIs. - **Frontend**: Use the `useInfiniteScroll` hook for all list UIs.
- Located in `src/ui/hooks/use-infinite-scroll.ts`. - Located in `packages/webui/hooks/use-infinite-scroll.ts`.
- Pass a `fetchData` function that accepts `page` and `limit`. - Pass a `fetchData` function that accepts `page` and `limit`.
- **Backend**: - **Backend**:
- Most list APIs support cursor pagination using opaque tokens (via `hyrumtoken` logic) using the `paginateQuery` helper function. - Most list APIs support cursor pagination using opaque tokens (via `hyrumtoken` logic) using the `paginateQuery` helper function.
- Pass `PaginationParams` containing `first` (limit) and `after` (cursor). - Pass `PaginationParams` containing `first` (limit) and `after` (cursor).
- The default `limit` should be **20**. - The default `limit` should be **20**.
- Always use the `paginateQuery` helper function from `src/services/pagination.ts` for consistent cursor pagination. - Always use the `paginateQuery` helper function from `packages/core/src/pagination.ts` for consistent cursor pagination.
## Temporal Workflow & Activities ## Temporal Workflow & Activities
@@ -301,12 +337,16 @@ We use a custom workflow engine that supports both **Local** (polling-based) and
### Architecture ### Architecture
1. **Workflows (`src/services/workflow/workflows`)**: Orchestrate multiple activities. They must be deterministic and compatible with Temporal's V8 isolate. Use `src/services/workflow/workflow-utils.ts` for environment-aware functions like `sleep` and `getActivities`. 1. **Workflows**: Orchestrate multiple activities. They must be deterministic and compatible with Temporal's V8 isolate. Defined in worker packages (e.g., `@shumai/agent/src/workflows`, `@shumai/transcode/src/workflows`).
2. **Activities (`src/services/workflow/activities`)**: Perform the actual work (DB updates, API calls, media processing). Grouped by domain (e.g., `ai.ts`, `transcode.ts`). 2. **Activities**: Perform the actual work (DB updates, API calls, media processing). Grouped by domain in worker packages (e.g., `@shumai/agent/src/activities`, `@shumai/transcode/src/activities`).
3. **Executors**: 3. **Executors**:
- `LocalExecutor`: Polls the database for `pending` tasks and executes them directly. - `LocalExecutor` (in `@shumai/workflow-core`): Polls the database for `pending` tasks and executes them directly.
- `TemporalExecutor`: Submits tasks to a Temporal cluster. - `TemporalExecutor` (in `@shumai/workflow-core`): Submits tasks to a Temporal cluster.
4. **Automatic Submission**: New `WorkflowTask` records are automatically submitted to the `WorkflowService` via a Prisma Client Extension defined in `src/db.ts`. 4. **Automatic Submission**: New `WorkflowTask` records are automatically submitted to the `WorkflowService` via a Prisma Client Extension defined in `@shumai/db`.
### Dynamic Registration
To avoid circular dependencies, workflows and activities are dynamically registered onto the `LocalExecutor` registry at bootstrap time via initializer functions (e.g., `initAgentWorkflows()`, `initTranscodeWorkflows()`).
### Non-Retryable Error Handling ### Non-Retryable Error Handling
@@ -338,21 +378,16 @@ To prevent Temporal from indefinitely retrying fatal, expected business validati
await activityB({ ... }) await activityB({ ... })
} }
``` ```
- **Registration**: All workflows must be exported from `src/services/workflow/workflows/index.ts` for Temporal worker registration. - **Environment Compatibility**: Always use `getActivities()` from `@shumai/workflow-core` to ensure the code works in both Local and Temporal environments.
- **Environment Compatibility**: Always use `getActivities()` from `workflow-utils.ts` to ensure the code works in both Local and Temporal environments.
- **Activity Access**: Activities should be accessed via `getActivities()` within a workflow. Do not call services directly inside a workflow function to maintain Temporal compatibility. - **Activity Access**: Activities should be accessed via `getActivities()` within a workflow. Do not call services directly inside a workflow function to maintain Temporal compatibility.
### Activity Patterns ### Activity Patterns
- **Location**: Defined in `src/services/workflow/activities/<domain>.ts`. - **Implementation**: Activities _can_ and _should_ call other services (e.g., `aiService`, `transcodeService`) or interact with the database directly. Database (Prisma) queries or updates are allowed in all activity types (e.g., agent or transcode) for simplicity.
- **Export**: Export individual activity functions and re-export them in `src/services/workflow/activities/index.ts`.
- **Implementation**: Activities _can_ and _should_ call other services (e.g., `aiService`, `transcodeService`) or interact with the database.
- **Database Access Restriction**: **Agent activities (or other non-database activities) are strictly prohibited from calling the database directly.** All database queries or updates must be isolated within dedicated database activities defined in `src/workflow/activities/db.ts` (running on `db_queue` / `TaskQueueDb`). Workflow functions coordinate execution by first invoking the database activity to resolve and store state, then passing the resolved data to the agent/non-database activity.
## Import conventions ## Import conventions
- When importing across layers, always use absolute paths with the `@` alias for the root of the project (e.g. `import { AssetInfo } from '@/services/asset/models'`). - When importing across workspace packages, always use absolute workspace imports (e.g. `import { prisma } from '@shumai/db'`, `import { teamService } from '@shumai/core/src/team/team'`).
- For types that have been migrated from `@/ui/api/api`, use the equivalent types from the `src/services/<domain>/models.ts` instead.
- **DTO Naming**: Do not append the `Dto` suffix to types or interfaces (e.g. use `JoinRequest` instead of `JoinRequestDto`). - **DTO Naming**: Do not append the `Dto` suffix to types or interfaces (e.g. use `JoinRequest` instead of `JoinRequestDto`).
## Radix UI / Shadcn UI Patterns ## Radix UI / Shadcn UI Patterns
@@ -363,7 +398,7 @@ To prevent Temporal from indefinitely retrying fatal, expected business validati
We use **pino** for logging. Always use **structured logging** to ensure logs are easily searchable and machine-readable. We use **pino** for logging. Always use **structured logging** to ensure logs are easily searchable and machine-readable.
- **Import**: `import { logger } from '@/logger'` - **Import**: `import { logger } from '@shumai/core/src/logger'`
- **Usage**: Pass an object as the first argument containing the metadata, and a string as the second argument for the descriptive message. - **Usage**: Pass an object as the first argument containing the metadata, and a string as the second argument for the descriptive message.
```typescript ```typescript
logger.info({ userId: user.id, projectId }, 'Project deleted successfully') logger.info({ userId: user.id, projectId }, 'Project deleted successfully')
+9 -7
View File
@@ -5,11 +5,14 @@ WORKDIR /app
# Copy package files # Copy package files
COPY package.json bun.lock ./ COPY package.json bun.lock ./
COPY prisma ./prisma COPY --parents packages/*/package.json ./
COPY --parents apps/*/package.json ./
# Install dependencies (including devDependencies for build tools) # Install dependencies (including devDependencies for build tools)
RUN bun install --frozen-lockfile RUN bun install --frozen-lockfile
RUN ls -la packages/transcode/node_modules
# Copy source code # Copy source code
COPY . . COPY . .
@@ -29,22 +32,21 @@ COPY --from=mwader/static-ffmpeg:8.1 /ffprobe /usr/local/bin/
RUN apt-get update && apt-get install -y ripgrep bubblewrap socat && rm -rf /var/lib/apt/lists/* 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 sharp/img from builder (they are native and already installed)
COPY --from=builder /app/node_modules/sharp ./node_modules/sharp # COPY --from=builder /app/packages/transcode/node_modules/sharp ./node_modules/sharp
COPY --from=builder /app/node_modules/@img ./node_modules/@img # COPY --from=builder /app/packages/transcode/node_modules/@img ./node_modules/@img
# Manually install temporalio packages and prisma # Manually install temporalio packages and prisma
# These need native bindings or CLI access in the runner environment # These need native bindings or CLI access in the runner environment
RUN bun add @temporalio/activity @temporalio/client @temporalio/worker @temporalio/workflow && \ RUN bun add @temporalio/activity @temporalio/client @temporalio/worker @temporalio/workflow && \
bun add --dev --omit peer prisma bun add --dev --omit peer prisma sharp
# Copy build artifacts and prisma config # Copy build artifacts and prisma config
COPY --from=builder /app/dist ./ COPY --from=builder /app/dist ./
COPY --from=builder /app/prisma ./prisma COPY --from=builder /app/packages/db/prisma ./packages/db/prisma
COPY --from=builder /app/prisma.config.ts.prod ./prisma.config.ts COPY --from=builder /app/prisma.config.ts.prod ./prisma.config.ts
# Expose port (Bun Hono defaults to 3000) # Expose port (Bun Hono defaults to 3000)
EXPOSE 3000 EXPOSE 3000
# Default command: run migrations and start API server # Default command: run migrations and start API server
# Can be overridden to run workers: bun worker-cli.js [domain] CMD ["sh", "-c", "bun prisma migrate deploy && bun apps/web/src/index.js"]
CMD ["sh", "-c", "bun prisma migrate deploy && bun index.js serve"]
+14
View File
@@ -0,0 +1,14 @@
{
"name": "@shumai/agent-app",
"version": "0.1.0",
"private": true,
"type": "module",
"bin": {
"shumai-agent": "./src/index.ts"
},
"dependencies": {
"@shumai/agent": "workspace:*",
"@shumai/core": "workspace:*",
"@shumai/workflow-core": "workspace:*"
}
}
+19
View File
@@ -0,0 +1,19 @@
import { loadEnvConfig } from '@shumai/core/src/env-loader'
loadEnvConfig(process.cwd(), process.env.NODE_ENV !== 'production')
import { workflowService } from '@shumai/workflow-core'
import { TaskQueueAgent } from '@shumai/workflow-core'
import { initAgentWorkflows } from '@shumai/agent'
async function run() {
// Initialize workflows and activities
initAgentWorkflows()
console.log('🚀 Starting Agent Worker...')
await workflowService.startWorkers(TaskQueueAgent)
}
run().catch((err) => {
console.error(err)
process.exit(1)
})
+4
View File
@@ -0,0 +1,4 @@
{
"extends": "../../tsconfig.json",
"include": ["src/**/*"]
}
+14
View File
@@ -0,0 +1,14 @@
{
"name": "@shumai/transcode-app",
"version": "0.1.0",
"private": true,
"type": "module",
"bin": {
"shumai-transcode": "./src/index.ts"
},
"dependencies": {
"@shumai/transcode": "workspace:*",
"@shumai/core": "workspace:*",
"@shumai/workflow-core": "workspace:*"
}
}
+19
View File
@@ -0,0 +1,19 @@
import { loadEnvConfig } from '@shumai/core/src/env-loader'
loadEnvConfig(process.cwd(), process.env.NODE_ENV !== 'production')
import { workflowService } from '@shumai/workflow-core'
import { TaskQueueTranscode } from '@shumai/workflow-core'
import { initTranscodeWorkflows } from '@shumai/transcode'
async function run() {
// Initialize workflows and activities
initTranscodeWorkflows()
console.log('🚀 Starting Transcode Worker...')
await workflowService.startWorkers(TaskQueueTranscode)
}
run().catch((err) => {
console.error(err)
process.exit(1)
})
+4
View File
@@ -0,0 +1,4 @@
{
"extends": "../../tsconfig.json",
"include": ["src/**/*"]
}
+17
View File
@@ -0,0 +1,17 @@
{
"name": "@shumai/web-app",
"version": "0.1.0",
"private": true,
"type": "module",
"dependencies": {
"@shumai/api": "workspace:*",
"@shumai/core": "workspace:*",
"@shumai/db": "workspace:*",
"@shumai/dtos": "workspace:*",
"@shumai/workflow-core": "workspace:*",
"@shumai/agent": "workspace:*",
"@shumai/transcode": "workspace:*",
"@shumai/webui": "workspace:*",
"hono": "^4.12.14"
}
}
+71
View File
@@ -0,0 +1,71 @@
import { loadEnvConfig } from '@shumai/core/src/env-loader'
loadEnvConfig(process.cwd(), process.env.NODE_ENV !== 'production')
import index from '@shumai/webui/index.html'
import { initAgentWorkflows } from '@shumai/agent'
import { assetService } from '@shumai/core/src/asset/asset'
import { metadataService } from '@shumai/core/src/metadata/metadata'
import { initTranscodeWorkflows } from '@shumai/transcode'
import { workflowService } from '@shumai/workflow-core'
import { app } from '@shumai/api'
// Initialize workflows and activities for local executor mode
initAgentWorkflows()
initTranscodeWorkflows()
// Start services
await metadataService.syncSystemFields().catch(console.error)
assetService.startCleanupJob()
workflowService.start()
if (process.env.WORKFLOW_EXECUTOR === 'temporal') {
const args = process.argv.slice(2)
let workersOption = ''
for (let i = 0; i < args.length; i++) {
if (args[i] === '--workers') {
workersOption = args[i + 1] || ''
} else if (args[i].startsWith('--workers=')) {
workersOption = args[i].split('=')[1]
}
}
const queuesToStart: string[] = []
if (workersOption === 'agent' || workersOption === 'ai') {
queuesToStart.push('agent_queue')
} else if (workersOption === 'transcode') {
queuesToStart.push('transcode_queue')
} else if (workersOption === 'all') {
queuesToStart.push('agent_queue', 'transcode_queue')
}
Promise.all(queuesToStart.map((q) => workflowService.startWorkers(q))).catch(console.error)
}
const server = Bun.serve({
port: 3000,
fetch: app.fetch,
routes: {
// Serve index.html for root
'/': index,
// Proxy API requests to Hono
'/api/*': app.fetch,
'/files/*': app.fetch,
// Catch-all for SPA routing (fallback to index.html)
'/*': index,
},
development: process.env.NODE_ENV !== 'production',
})
console.log(`🚀 Server running at ${server.url}`)
const shutdown = () => {
console.log('\nShutting down gracefully...')
assetService.stopCleanupJob()
server.stop(true)
process.exit(0)
}
process.on('SIGINT', shutdown)
process.on('SIGTERM', shutdown)
+4
View File
@@ -0,0 +1,4 @@
{
"extends": "../../tsconfig.json",
"include": ["src/**/*"]
}
+4 -12
View File
@@ -1,10 +1,9 @@
#!/usr/bin/env bun #!/usr/bin/env bun
import { temporalWorkflow } from './src/workflow/bun-temporal-plugin'
import { bunPluginPino } from 'bun-plugin-pino' import { bunPluginPino } from 'bun-plugin-pino'
import tailwindPlugin from 'bun-plugin-tailwind' import tailwindPlugin from 'bun-plugin-tailwind'
import { existsSync } from 'fs' import { existsSync } from 'fs'
import { rm } from 'fs/promises' import { rm } from 'fs/promises'
import { resolve } from 'path' import { temporalWorkflow } from './packages/workflow-core/src/bun-temporal-plugin'
console.log('\n🚀 Starting build process...\n') console.log('\n🚀 Starting build process...\n')
@@ -16,21 +15,14 @@ if (existsSync(outdir)) {
} }
await Bun.build({ await Bun.build({
entrypoints: ['./src/index.ts'], entrypoints: ['./apps/web/src/index.ts'],
root: '.',
target: 'bun', target: 'bun',
outdir: outdir, outdir: outdir,
minify: false, minify: false,
plugins: [ plugins: [
temporalWorkflow({ temporalWorkflow({
bundleOptions: { bundleOptions: {},
webpackConfigHook: (config) => {
if (!config.resolve) config.resolve = {}
if (!config.resolve.alias) config.resolve.alias = {}
// @ts-ignore
config.resolve.alias['@'] = resolve(process.cwd(), 'src')
return config
},
},
}), }),
tailwindPlugin, tailwindPlugin,
bunPluginPino({ transports: ['pino-pretty'] }), bunPluginPino({ transports: ['pino-pretty'] }),
+560 -1122
View File
File diff suppressed because it is too large Load Diff
+3 -2
View File
@@ -71,9 +71,10 @@ export default tseslint.config(
ignores: [ ignores: [
'**/dist/**', '**/dist/**',
'**/node_modules/**', '**/node_modules/**',
'**/src/generated/**', '**/packages/db/src/generated/**',
'**/packages/core/src/generated/**',
'**/data/**', '**/data/**',
'**/src/ui/components/ui/**', '**/packages/webui/components/ui/**',
], ],
}, },
js.configs.recommended, js.configs.recommended,
+14 -125
View File
@@ -3,8 +3,12 @@
"version": "0.1.0", "version": "0.1.0",
"private": true, "private": true,
"type": "module", "type": "module",
"workspaces": [
"packages/*",
"apps/*"
],
"scripts": { "scripts": {
"dev": "bun run --hot src/index.ts serve", "dev": "bun run --hot apps/web/src/index.ts",
"typecheck": "tsc --noEmit", "typecheck": "tsc --noEmit",
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0", "lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
"test": "bun --bun vitest run", "test": "bun --bun vitest run",
@@ -12,147 +16,32 @@
"db:migrate": "bun run prisma migrate dev", "db:migrate": "bun run prisma migrate dev",
"db:deploy": "bun run prisma migrate deploy", "db:deploy": "bun run prisma migrate deploy",
"generate-providers": "bun run scripts/generate-builtin-providers.ts", "generate-providers": "bun run scripts/generate-builtin-providers.ts",
"worker": "bun src/index.ts worker", "worker:agent": "bun apps/agent/src/index.ts",
"worker:transcode": "bun apps/transcode/src/index.ts",
"build": "bun run build.ts" "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",
"@base-ui/react": "^1.5.0",
"@dnd-kit/dom": "^0.4.0",
"@dnd-kit/react": "^0.4.0",
"@earendil-works/pi-agent-core": "0.78.0",
"@earendil-works/pi-ai": "0.75.4",
"@google/genai": "^1.50.1",
"@hono/zod-validator": "^0.7.6",
"@hookform/resolvers": "^5.4.0",
"@lexical/code": "^0.42.0",
"@lexical/link": "^0.42.0",
"@lexical/list": "^0.42.0",
"@lexical/markdown": "^0.42.0",
"@lexical/react": "^0.42.0",
"@lexical/rich-text": "^0.42.0",
"@lexical/selection": "^0.42.0",
"@lexical/table": "^0.42.0",
"@lexical/utils": "^0.42.0",
"@prisma/adapter-pg": "^7.7.0",
"@prisma/client": "^7.7.0",
"@radix-ui/react-accordion": "1.2.2",
"@radix-ui/react-alert-dialog": "1.1.4",
"@radix-ui/react-aspect-ratio": "1.1.1",
"@radix-ui/react-avatar": "1.1.2",
"@radix-ui/react-checkbox": "1.1.3",
"@radix-ui/react-collapsible": "1.1.2",
"@radix-ui/react-context-menu": "2.2.4",
"@radix-ui/react-dialog": "^1.1.15",
"@radix-ui/react-dropdown-menu": "2.1.4",
"@radix-ui/react-hover-card": "1.1.4",
"@radix-ui/react-label": "^2.1.8",
"@radix-ui/react-menubar": "1.1.4",
"@radix-ui/react-navigation-menu": "1.2.3",
"@radix-ui/react-popover": "1.1.4",
"@radix-ui/react-progress": "1.1.1",
"@radix-ui/react-radio-group": "1.2.2",
"@radix-ui/react-scroll-area": "1.2.2",
"@radix-ui/react-select": "2.1.4",
"@radix-ui/react-separator": "^1.1.8",
"@radix-ui/react-slider": "1.2.2",
"@radix-ui/react-slot": "^1.2.4",
"@radix-ui/react-switch": "1.1.2",
"@radix-ui/react-tabs": "1.1.2",
"@radix-ui/react-toast": "1.2.4",
"@radix-ui/react-toggle": "1.1.1",
"@radix-ui/react-toggle-group": "1.1.1",
"@radix-ui/react-tooltip": "^1.2.8",
"@sinclair/typebox": "^0.34.49",
"@swc/wasm": "^1.15.33",
"@tailwindcss/vite": "^4.1.17",
"@tanstack/react-form": "^1.32.0",
"@tanstack/react-query": "5.90.10",
"@tanstack/react-router": "^1.136.8",
"@tanstack/react-table": "^8.21.3",
"@temporalio/activity": "^1.16.1",
"@temporalio/client": "^1.16.1",
"@temporalio/worker": "^1.16.1",
"@temporalio/workflow": "^1.16.1",
"@vitejs/plugin-react": "^5.1.1",
"adm-zip": "^0.5.17",
"autoprefixer": "^10.4.20",
"better-auth": "^1.6.6",
"bun": "^1.3.13",
"bun-plugin-tailwind": "^0.1.2",
"class-variance-authority": "^0.7.1",
"clsx": "^2.1.1",
"cmdk": "^1.1.1",
"date-fns": "^4.4.0",
"dotenv-expand": "^13.0.0",
"embla-carousel-react": "^8.6.0",
"extract-zip": "^2.0.1",
"hono": "^4.12.14",
"input-otp": "^1.4.2",
"jittered-fractional-indexing": "^1.0.1",
"konva": "^10.0.12",
"lexical": "^0.42.0",
"loader-utils": "^3.3.1",
"lucide-react": "^1.17.0",
"next-themes": "^0.4.6",
"pg": "^8.20.0",
"pino": "^10.3.1",
"pino-pretty": "^13.1.3",
"radix-ui": "^1.4.3",
"react": "19.2.0",
"react-day-picker": "^10.0.1",
"react-dom": "19.2.0",
"react-hook-form": "^7.76.1",
"react-intersection-observer": "^10.0.0",
"react-konva": "^19.2.1",
"react-markdown": "^10.1.0",
"react-resizable-panels": "^4",
"recharts": "3.8.0",
"sharp": "^0.34.5",
"sonner": "^2.0.7",
"tailwind-merge": "^2.5.5",
"tailwindcss-animate": "^1.0.7",
"ulid": "^3.0.2",
"use-image": "^1.1.4",
"vaul": "^1.1.2",
"video.js": "^8.23.4",
"vite": "^7.2.2",
"zod": "^4.4.3",
"zustand": "^5.0.8"
},
"devDependencies": { "devDependencies": {
"@eslint/js": "^9.39.1", "@eslint/js": "^9.39.1",
"@tailwindcss/postcss": "^4.1.9",
"@tanstack/router-cli": "^1.136.8",
"@tanstack/router-plugin": "^1.136.8",
"@testcontainers/postgresql": "^11.14.0", "@testcontainers/postgresql": "^11.14.0",
"@types/adm-zip": "^0.5.8",
"@types/bun": "^1.3.12", "@types/bun": "^1.3.12",
"@types/extract-zip": "^2.0.3",
"@types/node": "^22", "@types/node": "^22",
"@types/pg": "^8.20.0",
"@types/react": "^19",
"@types/react-dom": "^19",
"bun-plugin-pino": "^1.5.0", "bun-plugin-pino": "^1.5.0",
"bun-plugin-tailwind": "^0.1.2",
"bun-types": "^1.3.12", "bun-types": "^1.3.12",
"pino-pretty": "^13.1.3",
"eslint": "^9.39.1", "eslint": "^9.39.1",
"eslint-config-prettier": "^10.1.8", "eslint-config-prettier": "^10.1.8",
"eslint-plugin-prettier": "^5.5.5", "eslint-plugin-prettier": "^5.5.5",
"eslint-plugin-react": "^7.37.5", "eslint-plugin-react": "^7.37.5",
"globals": "^16.5.0", "globals": "^16.5.0",
"orval": "7.14.0",
"postcss": "^8.5",
"prisma": "^7.7.0", "prisma": "^7.7.0",
"prisma-json-types-generator": "^4.1.1",
"tailwindcss": "^4.2.2",
"testcontainers": "^11.14.0", "testcontainers": "^11.14.0",
"tw-animate-css": "1.3.3",
"typescript": "^5.9.3", "typescript": "^5.9.3",
"typescript-eslint": "^8.46.4", "typescript-eslint": "^8.46.4",
"unplugin-auto-import": "^21.0.0", "vitest": "^4.1.4",
"vite-tsconfig-paths": "^6.1.1", "vite-tsconfig-paths": "^6.1.1"
"vitest": "^4.1.4" },
"dependencies": {
"jittered-fractional-indexing": "^1.0.1"
} }
} }
+28
View File
@@ -0,0 +1,28 @@
{
"name": "@shumai/agent",
"version": "0.1.0",
"private": true,
"type": "module",
"main": "./src/index.ts",
"types": "./src/index.ts",
"dependencies": {
"@shumai/db": "workspace:*",
"@shumai/dtos": "workspace:*",
"@shumai/core": "workspace:*",
"@shumai/workflow-core": "workspace:*",
"@google/genai": "^1.50.1",
"@anthropic-ai/sandbox-runtime": "^0.0.52",
"@earendil-works/pi-agent-core": "0.78.0",
"@earendil-works/pi-ai": "0.75.4",
"@temporalio/activity": "^1.16.1",
"@temporalio/worker": "^1.16.1",
"@temporalio/workflow": "^1.16.1",
"@sinclair/typebox": "^0.34.49",
"ulid": "^3.0.2",
"adm-zip": "^0.5.17",
"zod": "^4.4.3"
},
"devDependencies": {
"@types/adm-zip": "^0.5.8"
}
}
@@ -1,11 +1,11 @@
import { describe, it, expect, vi, beforeEach } from 'vitest' import { describe, it, expect, vi, beforeEach } from 'vitest'
import { agentChatActivity, autofillAiActivity, type AgentExecutionContext } from './agent' import { agentChatActivity, autofillAiActivity, type AgentExecutionContext } from './agent'
import * as piAgent from '@/agent' import * as piAgent from '../index'
import { type AgentHarness, type Session } from '@earendil-works/pi-agent-core' import { type AgentHarness, type Session } from '@earendil-works/pi-agent-core'
import { type DatabaseSessionMetadata } from '@/agent/database-session-storage' import { type DatabaseSessionMetadata } from '../database-session-storage'
vi.mock('@/agent', async () => { vi.mock('../index', async () => {
const actual = await vi.importActual('@/agent') const actual = await vi.importActual('../index')
return { return {
...actual, ...actual,
createAgentSession: vi.fn(), createAgentSession: vi.fn(),
@@ -1,28 +1,266 @@
import { prisma } from '@/db' import { createAgentSession, fieldsToTypeBoxSchema, type AutofillField } from '../index'
import { DatabaseSessionStorage } from '../database-session-storage'
import { prisma, AssetType, Prisma, type Skill } from '@shumai/db'
import { logger } from '@shumai/core/src/logger'
import { s3Service } from '@shumai/core/src/s3/s3'
import { type AgentTool, type AgentMessage, type SessionTreeEntry } from '@earendil-works/pi-agent-core'
import { type ImageContent } from '@earendil-works/pi-ai'
import { ApplicationFailure } from '@temporalio/activity' import { ApplicationFailure } from '@temporalio/activity'
import type { AgentMessage, SessionTreeEntry } from '@earendil-works/pi-agent-core' import { assetService } from '@shumai/core/src/asset/asset'
import { ulid } from 'ulid' import { VersionStackService } from '@shumai/core/src/versionStack/versionStack'
import { metadataService } from '@/services/metadata/metadata' import { uploadService } from '@shumai/core/src/upload/upload'
import { UpdateAssetMetadataRequest } from '@/dtos/metadata' import { authzService, Permission, ResourceType } from '@shumai/core/src/authz/authz'
import { WorkflowTaskStatus, AssetStatus, Prisma, AssetType } from '@/generated/prisma/client'
import type { AgentExecutionContext } from './agent'
import { assetService } from '@/services/asset/asset'
import { VersionStackService } from '@/services/versionStack/versionStack'
import { uploadService } from '@/services/upload/upload'
import { authzService, Permission, ResourceType } from '@/services/authz/authz'
import { generateKeyBetween } from 'jittered-fractional-indexing' import { generateKeyBetween } from 'jittered-fractional-indexing'
import { paginateQuery, encodeCursor } from '@/services/pagination' import { paginateQuery, encodeCursor } from '@shumai/core/src/pagination'
import { ulid } from 'ulid'
import { metadataService } from '@shumai/core/src/metadata/metadata'
export interface InitializeAgentSessionParams { import { UpdateAssetMetadataRequest } from '@shumai/dtos'
export interface Usage {
inputTokens: number
outputTokens: number
model: string
}
export type AgentWithProviderAndModel = Prisma.AgentGetPayload<{
include: {
provider: true
modelRef: true
}
}>
export type DbProviderWithModels = Prisma.ProviderGetPayload<{
include: {
models: true
}
}>
export interface AgentExecutionContext {
agent: AgentWithProviderAndModel
dbProviders: DbProviderWithModels[]
teamSkills: Skill[]
allowedDomains: string[]
}
async function executeAgentPrompt(params: {
teamId: string
agentId: string
prompt: string
images: string[]
agentsInstruction: string
sessionId?: string
userId?: string
tools?: AgentTool[]
context: AgentExecutionContext
}): Promise<{ text: string; usage: Usage; sessionId: string }> {
const { agent, dbProviders, teamSkills, allowedDomains } = params.context
if (!agent.provider) {
throw ApplicationFailure.create({
message: 'agent has no provider configured',
nonRetryable: true,
})
}
if (!agent.modelRef) {
throw ApplicationFailure.create({
message: 'agent has no model configured',
nonRetryable: true,
})
}
const providerName = agent.provider.name
const modelId = agent.modelRef.modelId
let systemPrompt = `You are the AI assistant for shumai.
shumai is a professional creative collaboration platform similar to frame.io, where users can upload creative files, manage projects, assign tasks, get precise feedback, and share their work. As the agent, your role is to help users use and manage this platform.
shumai has its own cloud file system. If a user asks you to perform file system operations (for example: creating a folder, creating a file, stacking a version, or listing assets), you MUST use the corresponding agent system tools (e.g., 'create_folder', 'create_file', 'create_version', 'list_assets'). Do NOT use local bash commands or the local bash tool to perform these operations locally on the host environment; all operations must be executed through the platform's cloud file system tools so they are correctly registered and visible within the platform.
If you need to create files in the local filesystem (for example, a temporary file for uploading), only the '.pi' folder in the current directory has write permissions. Do NOT attempt to create files in any other directories.`
if (agent.soul) {
systemPrompt = `${systemPrompt}\n\nAgent Personality and Core Instructions:\n${agent.soul}`
}
if (params.agentsInstruction) {
systemPrompt = `${systemPrompt}\n\nContext and Instructions:\n${params.agentsInstruction}`
}
const modelConfig = agent.modelRef?.config
if (modelConfig?.input) {
systemPrompt += `\n\nYour current model supports the following input types: ${modelConfig.input.join(', ')}.`
}
const { session, harness } = await createAgentSession({
agentId: params.agentId,
providerName,
modelId,
systemPrompt,
teamSkills: teamSkills.map((s) => ({
id: s.id,
name: s.name,
description: s.description,
})),
allowedDomains,
sessionId: params.sessionId,
userId: params.userId,
customTools: params.tools || [],
providers: dbProviders.map((p) => ({
name: p.name,
config: p.config,
models: p.models.map((m) => ({
modelId: m.modelId,
name: m.name,
config: m.config,
})),
})),
})
const imagesToPass: ImageContent[] = []
if (params.images && params.images.length > 0) {
for (const key of params.images) {
const { buffer, contentType } = await s3Service.getObject(
process.env.S3_BUCKET || 'shumai',
key,
)
imagesToPass.push({
type: 'image',
data: buffer.toString('base64'),
mimeType: contentType,
})
}
}
try {
const assistantMessage = await harness.prompt(params.prompt, { images: imagesToPass })
const sessionEntries = await session.getEntries()
sessionEntries.forEach((entry) => {
if (entry.type === 'message') {
const msg = entry.message
if (msg.role === 'toolResult') {
const logMsg = { ...msg, content: undefined }
logger.debug(logMsg, 'agent message')
} else {
logger.debug(msg, 'agent message')
}
}
})
const text = assistantMessage.content
.filter((c) => c.type === 'text')
.map((c) => {
if ('text' in c && typeof c.text === 'string') {
return c.text
}
return ''
})
.join('\n')
const usage: Usage = {
model: modelId,
inputTokens: assistantMessage.usage?.input || 0,
outputTokens: assistantMessage.usage?.output || 0,
}
const storage = session.getStorage()
let sessionId = ''
if (storage instanceof DatabaseSessionStorage) {
sessionId = storage.sessionId
}
return { text, usage, sessionId }
} finally {
// Cleanup handled by agent session if needed
}
}
export interface AgentChatParams {
teamId: string
agentId: string
message: string
imageUrls: string[]
projectId: string
folderId: string
agentsInstruction?: string
sessionId: string
userId?: string
explicitMention?: boolean
context: AgentExecutionContext
}
export async function agentChatActivity(params: AgentChatParams) {
const cleanMessage = params.message.replace(/<@[A-Z0-9]+>/g, '').trim()
const sessionId = params.sessionId
return executeAgentPrompt({
teamId: params.teamId,
agentId: params.agentId,
prompt: cleanMessage,
images: params.imageUrls,
agentsInstruction: params.agentsInstruction || '',
sessionId,
userId: params.userId,
context: params.context,
})
}
export interface AutofillAiParams {
teamId: string
images: string[]
fields: AutofillField[]
context: AgentExecutionContext
}
export async function autofillAiActivity(params: AutofillAiParams) {
const prompt = 'Analyze the provided images and extract metadata.'
const toolSchema = fieldsToTypeBoxSchema(params.fields)
let capturedData: Record<string, unknown> | null = null
const autofillTool: AgentTool = {
name: 'autofill_metadata',
label: 'Autofill Metadata',
description: 'Extract metadata from the images.',
parameters: toolSchema,
execute: async (_toolCallId, toolParams) => {
capturedData = toolParams as Record<string, unknown>
return {
content: [{ type: 'text', text: 'Metadata captured successfully.' }],
details: {},
}
},
}
const fullPrompt = `${prompt}\n\nPlease use the "autofill_metadata" tool to provide the extracted metadata.`
const { agent } = params.context
const { usage, sessionId } = await executeAgentPrompt({
teamId: params.teamId,
agentId: agent.id,
prompt: fullPrompt,
images: params.images,
agentsInstruction: '',
sessionId: undefined,
userId: undefined,
tools: [autofillTool],
context: params.context,
})
return {
text: capturedData ? JSON.stringify(capturedData) : '{}',
usage,
sessionId,
}
}
export async function initializeAgentSessionActivity(params: {
teamId: string teamId: string
agentId: string agentId: string
userCommentId: string userCommentId: string
userId?: string userId?: string
} }): Promise<string> {
export async function initializeAgentSessionActivity(
params: InitializeAgentSessionParams,
): Promise<string> {
const agentId = params.agentId === 'default' ? 'default' : params.agentId const agentId = params.agentId === 'default' ? 'default' : params.agentId
// Ensure user exists for agent // Ensure user exists for agent
@@ -178,7 +416,7 @@ export async function initializeAgentSessionActivity(
data: { data: {
id: entryId, id: entryId,
sessionId, sessionId,
entry: entryJson, entry: entryJson as unknown as PrismaJson.PiSessionEntry,
}, },
}) })
prevId = entryId prevId = entryId
@@ -201,15 +439,13 @@ export async function deleteCommentActivity(commentId: string) {
}) })
} }
export interface CreateCommentParams { export async function createCommentActivity(params: {
assetId: string assetId: string
message: string message: string
sessionId?: string | null sessionId?: string | null
agentId?: string | null agentId?: string | null
replyToId?: string | null replyToId?: string | null
} }) {
export async function createCommentActivity(params: CreateCommentParams) {
if (params.sessionId) { if (params.sessionId) {
const agentId = params.agentId && params.agentId !== 'default' ? params.agentId : 'default' const agentId = params.agentId && params.agentId !== 'default' ? params.agentId : 'default'
@@ -276,13 +512,11 @@ export async function createCommentActivity(params: CreateCommentParams) {
}) })
} }
export interface UpdateCommentParams { export async function updateCommentActivity(params: {
commentId: string commentId: string
message: string message: string
sessionId?: string | null sessionId?: string | null
} }) {
export async function updateCommentActivity(params: UpdateCommentParams) {
return prisma.assetComment.update({ return prisma.assetComment.update({
where: { id: params.commentId }, where: { id: params.commentId },
data: { data: {
@@ -292,18 +526,10 @@ export async function updateCommentActivity(params: UpdateCommentParams) {
}) })
} }
// ========================================== export async function getAgentChatContextActivity(params: {
// New Context-Fetching and Embedding DB Activities
// ==========================================
export interface GetAgentChatContextParams {
teamId: string teamId: string
agentId: string agentId: string
} }): Promise<AgentExecutionContext> {
export async function getAgentChatContextActivity(
params: GetAgentChatContextParams,
): Promise<AgentExecutionContext> {
const team = await prisma.team.findUnique({ const team = await prisma.team.findUnique({
where: { id: params.teamId }, where: { id: params.teamId },
}) })
@@ -364,13 +590,9 @@ export async function getAgentChatContextActivity(
} }
} }
export interface GetAgentAutofillContextParams { export async function getAgentAutofillContextActivity(params: {
teamId: string teamId: string
} }): Promise<AgentExecutionContext> {
export async function getAgentAutofillContextActivity(
params: GetAgentAutofillContextParams,
): Promise<AgentExecutionContext> {
const agent = await prisma.agent.findFirst({ const agent = await prisma.agent.findFirst({
where: { where: {
type: 'autofill', type: 'autofill',
@@ -442,80 +664,6 @@ export async function getAgentAutofillContextActivity(
} }
} }
export interface GetEmbeddingContextParams {
teamId: string
assetId: string
}
export async function getEmbeddingContextActivity(params: GetEmbeddingContextParams) {
const team = await prisma.team.findUnique({
where: { id: params.teamId },
})
if (!team) {
throw ApplicationFailure.create({ message: 'failed to get team', nonRetryable: true })
}
const agent = await prisma.agent.findFirst({
where: {
type: 'embedding',
enabled: true,
user: { teamMembers: { some: { teamId: params.teamId } } },
},
})
if (!agent) {
throw ApplicationFailure.create({
message: 'embedding feature is disabled or agent not found',
nonRetryable: true,
})
}
const asset = await prisma.asset.findUnique({
where: { id: params.assetId },
include: { storageKey: true },
})
if (!asset) {
throw ApplicationFailure.create({ message: 'failed to get asset', nonRetryable: true })
}
if (!asset.mediaType) {
throw ApplicationFailure.create({ message: 'asset has no media type', nonRetryable: true })
}
return {
agent,
asset,
}
}
export interface SaveAssetEmbeddingsParams {
assetId: string
embeddings: Array<{
embedding: number[]
startTime?: number
endTime?: number
}>
}
export async function saveAssetEmbeddingsActivity(params: SaveAssetEmbeddingsParams) {
for (const item of params.embeddings) {
const embVec = JSON.stringify(item.embedding)
if (item.startTime !== undefined && item.endTime !== undefined) {
await prisma.$executeRaw`
INSERT INTO asset_embeddings (id, asset_id, embedding, start_time, end_time, updated_at)
VALUES (gen_random_uuid()::text, ${params.assetId}, ${embVec}::vector, ${item.startTime}, ${item.endTime}, NOW())
`
} else {
await prisma.$executeRaw`
INSERT INTO asset_embeddings (id, asset_id, embedding, updated_at)
VALUES (gen_random_uuid()::text, ${params.assetId}, ${embVec}::vector, NOW())
`
}
}
}
// ==========================================
// Moved Database Activities
// ==========================================
export async function getAssetActivity(assetId: string) { export async function getAssetActivity(assetId: string) {
return prisma.asset.findUnique({ return prisma.asset.findUnique({
where: { id: assetId }, where: { id: assetId },
@@ -542,97 +690,23 @@ export async function getProjectAutofillFieldsActivity(projectId: string) {
return fields.filter((f) => f.field.aiAutofill).map((f) => f.field) return fields.filter((f) => f.field.aiAutofill).map((f) => f.field)
} }
export interface UpdateAssetMetadataParams { export async function updateAssetMetadataActivity(params: {
assetId: string assetId: string
metadata: UpdateAssetMetadataRequest[] metadata: UpdateAssetMetadataRequest[]
} }) {
export async function updateAssetMetadataActivity(params: UpdateAssetMetadataParams) {
return metadataService.updateAssetMetadata(params.assetId, params.metadata) return metadataService.updateAssetMetadata(params.assetId, params.metadata)
} }
export interface UpdateTaskStatusParams {
taskId: string
status: WorkflowTaskStatus
output?: unknown
}
export async function updateTaskStatusActivity(params: UpdateTaskStatusParams): Promise<void> {
await prisma.workflowTask.update({
where: { id: params.taskId },
data: {
status: params.status,
output: params.output,
},
})
}
export interface UpdateAssetStatusParams {
assetId: string
status: AssetStatus
}
export async function updateAssetStatusActivity(params: UpdateAssetStatusParams): Promise<void> {
await prisma.asset.update({
where: { id: params.assetId },
data: { status: params.status },
})
}
export interface UpdateTaskUsageParams {
taskId: string
inputTokens: number
outputTokens: number
model: string
}
export async function updateTaskUsageActivity(params: UpdateTaskUsageParams): Promise<void> {
await prisma.workflowTask.update({
where: { id: params.taskId },
data: {
inputTokens: params.inputTokens,
outputTokens: params.outputTokens,
model: params.model,
},
})
}
export interface UpdateWorkflowTaskParams {
taskId: string
status?: WorkflowTaskStatus
heartbeat?: boolean
output?: unknown
inputTokens?: number
outputTokens?: number
model?: string | null
}
export async function updateWorkflowTaskActivity(params: UpdateWorkflowTaskParams): Promise<void> {
await prisma.workflowTask.update({
where: { id: params.taskId },
data: {
...(params.status !== undefined ? { status: params.status } : {}),
...(params.heartbeat ? { heartbeat: new Date() } : {}),
...(params.output !== undefined ? { output: params.output as Prisma.InputJsonValue } : {}),
...(params.inputTokens !== undefined ? { inputTokens: params.inputTokens } : {}),
...(params.outputTokens !== undefined ? { outputTokens: params.outputTokens } : {}),
...(params.model !== undefined ? { model: params.model } : {}),
},
})
}
// ==========================================
// Agent System Tools & Context Activities
// ==========================================
export async function getAssetPathContextActivity(assetId: string): Promise<string> { export async function getAssetPathContextActivity(assetId: string): Promise<string> {
const parts: { name: string; id: string }[] = [] const parts: { name: string; id: string }[] = []
let currentId: string | null = assetId let currentId: string | null = assetId
while (currentId) { while (currentId) {
/* prettier-ignore */ /* prettier-ignore */
// eslint-disable-next-line @typescript-eslint/no-explicit-any const assetNode = (await prisma.asset.findUnique({
const assetNode: { id: string; name: string; parentId: string | null; type: AssetType } | null = (await prisma.asset.findUnique({ where: { id: currentId }, select: { id: true, name: true, parentId: true, type: true } })) as any where: { id: currentId },
select: { id: true, name: true, parentId: true, type: true },
})) as { id: string; name: string; parentId: string | null; type: AssetType } | null
if (!assetNode) break if (!assetNode) break
if (assetNode.name) { if (assetNode.name) {
@@ -1,8 +1,8 @@
import { describe, it, expect, vi, beforeEach } from 'vitest' import { describe, it, expect, vi, beforeEach } from 'vitest'
import { generateEmbeddingActivity } from './ai' import { generateEmbeddingActivity } from './ai'
import { s3Service } from '@/services/s3/s3' import { s3Service } from '@shumai/core/src/s3/s3'
vi.mock('@/services/s3/s3', () => ({ vi.mock('@shumai/core/src/s3/s3', () => ({
s3Service: { s3Service: {
getObject: vi.fn(), getObject: vi.fn(),
putObject: vi.fn(), putObject: vi.fn(),
@@ -1,12 +1,13 @@
import { GoogleGenAI } from '@google/genai' import { GoogleGenAI } from '@google/genai'
import { s3Service } from '@/services/s3/s3' import { s3Service } from '@shumai/core/src/s3/s3'
import { transcodeService } from '@/transcode/transcode' import { transcodeService } from '@shumai/transcode'
import { exec } from 'child_process' import { exec } from 'child_process'
import * as fs from 'fs' import * as fs from 'fs'
import * as os from 'os' import * as os from 'os'
import * as path from 'path' import * as path from 'path'
import { promisify } from 'util' import { promisify } from 'util'
import { ApplicationFailure } from '@temporalio/activity' import { ApplicationFailure } from '@temporalio/activity'
import { prisma } from '@shumai/db'
const execAsync = promisify(exec) const execAsync = promisify(exec)
@@ -259,3 +260,69 @@ export async function extractAiMetadataActivity(
return generatedFiles return generatedFiles
} }
export async function getEmbeddingContextActivity(params: {
teamId: string
assetId: string
}) {
const team = await prisma.team.findUnique({
where: { id: params.teamId },
})
if (!team) {
throw ApplicationFailure.create({ message: 'failed to get team', nonRetryable: true })
}
const agent = await prisma.agent.findFirst({
where: {
type: 'embedding',
enabled: true,
user: { teamMembers: { some: { teamId: params.teamId } } },
},
})
if (!agent) {
throw ApplicationFailure.create({
message: 'embedding feature is disabled or agent not found',
nonRetryable: true,
})
}
const asset = await prisma.asset.findUnique({
where: { id: params.assetId },
include: { storageKey: true },
})
if (!asset) {
throw ApplicationFailure.create({ message: 'failed to get asset', nonRetryable: true })
}
if (!asset.mediaType) {
throw ApplicationFailure.create({ message: 'asset has no media type', nonRetryable: true })
}
return {
agent,
asset,
}
}
export async function saveAssetEmbeddingsActivity(params: {
assetId: string
embeddings: Array<{
embedding: number[]
startTime?: number
endTime?: number
}>
}) {
for (const item of params.embeddings) {
const embVec = JSON.stringify(item.embedding)
if (item.startTime !== undefined && item.endTime !== undefined) {
await prisma.$executeRaw`
INSERT INTO asset_embeddings (id, asset_id, embedding, start_time, end_time, updated_at)
VALUES (gen_random_uuid()::text, ${params.assetId}, ${embVec}::vector, ${item.startTime}, ${item.endTime}, NOW())
`
} else {
await prisma.$executeRaw`
INSERT INTO asset_embeddings (id, asset_id, embedding, updated_at)
VALUES (gen_random_uuid()::text, ${params.assetId}, ${embVec}::vector, NOW())
`
}
}
}
@@ -1,10 +1,10 @@
import { prisma } from '@/db' import { prisma } from '@shumai/db'
import { setupTestDbHooks } from '@/db-test-hooks' import { setupTestDbHooks } from '@shumai/db/test'
import { s3Service } from '@/services/s3/s3' import { s3Service } from '@shumai/core/src/s3/s3'
import { type SessionTreeEntry } from '@earendil-works/pi-agent-core' import { type SessionTreeEntry } from '@earendil-works/pi-agent-core'
import { describe, expect, it, vi } from 'vitest' import { describe, expect, it, vi } from 'vitest'
import { DatabaseSessionStorage } from './database-session-storage' import { DatabaseSessionStorage } from './database-session-storage'
import { agentService } from '@/services/agent/agent' import { agentService } from '@shumai/core/src/agent/agent'
import { createAgentSession } from './index' import { createAgentSession } from './index'
import * as sandboxedBashModule from './tools/sandboxed-bash' import * as sandboxedBashModule from './tools/sandboxed-bash'
@@ -1,5 +1,5 @@
import { prisma } from '@/db' import { prisma } from '@shumai/db'
import { s3Service } from '@/services/s3/s3' import { s3Service } from '@shumai/core/src/s3/s3'
import { ulid } from 'ulid' import { ulid } from 'ulid'
import { import {
type AgentMessage, type AgentMessage,
@@ -8,7 +8,7 @@ import {
type SessionTreeEntry, type SessionTreeEntry,
type SessionTreeEntryBase, type SessionTreeEntryBase,
} from '@earendil-works/pi-agent-core' } from '@earendil-works/pi-agent-core'
import { agentService } from '@/services/agent/agent' import { agentService } from '@shumai/core/src/agent/agent'
export interface DatabaseSessionMetadata extends SessionMetadata { export interface DatabaseSessionMetadata extends SessionMetadata {
agentId: string agentId: string
@@ -5,7 +5,7 @@ import { getModel } from '@earendil-works/pi-ai'
import { Type, type TSchema } from '@sinclair/typebox' import { Type, type TSchema } from '@sinclair/typebox'
import * as fs from 'fs' import * as fs from 'fs'
import * as path from 'path' import * as path from 'path'
import { agentService } from '@/services/agent/agent' import { agentService } from '@shumai/core/src/agent/agent'
import { DatabaseSessionStorage } from './database-session-storage' import { DatabaseSessionStorage } from './database-session-storage'
import { analyzeAssetMediaTool } from './tools/analyze-asset-media' import { analyzeAssetMediaTool } from './tools/analyze-asset-media'
import { createCreateFileTool } from './tools/create-file' import { createCreateFileTool } from './tools/create-file'
@@ -285,3 +285,41 @@ export function formatSkillsForPrompt(
return lines.join('\n') return lines.join('\n')
} }
import { registerWorkflow, registerActivities } from '@shumai/workflow-core'
import { WorkflowTaskType } from '@shumai/db'
import { agentEmbeddingMedia } from './workflows/agent-embedding'
import { queryEmbeddingForSearch } from './workflows/query-embedding-for-search'
import { agentAutofillMedia } from './workflows/agent-autofill'
import { agentChat } from './workflows/agent-chat'
import { agentToolCall } from './workflows/agent-tool-call'
import * as agentActivities from './activities/agent'
import * as aiActivities from './activities/ai'
export function initAgentWorkflows() {
registerWorkflow(WorkflowTaskType.ai_embedding, agentEmbeddingMedia)
registerWorkflow(WorkflowTaskType.query_embedding_for_search, queryEmbeddingForSearch)
registerWorkflow(WorkflowTaskType.ai_metadata_autofill, agentAutofillMedia)
registerWorkflow(WorkflowTaskType.chat, agentChat)
registerWorkflow(WorkflowTaskType.agent_tool_call, agentToolCall)
registerActivities(agentActivities)
registerActivities(aiActivities)
}
export * from './database-session-storage'
export * from './activities/agent'
export {
type GeneratedEmbedding,
type GenerateEmbeddingParams,
generateEmbeddingActivity,
type GenerateTextEmbeddingParams,
generateTextEmbeddingActivity,
type ExtractAiMetadataParams,
extractAiMetadataActivity,
} from './activities/ai'
export * from './workflows/agent-autofill'
export * from './workflows/agent-chat'
export * from './workflows/agent-embedding'
export * from './workflows/agent-tool-call'
export * from './workflows/query-embedding-for-search'
@@ -1,8 +1,8 @@
import { describe, it, expect, vi, beforeEach } from 'vitest' import { describe, it, expect, vi, beforeEach } from 'vitest'
import { analyzeAssetMediaTool } from './analyze-asset-media' import { analyzeAssetMediaTool } from './analyze-asset-media'
import { s3Service } from '@/services/s3/s3' import { s3Service } from '@shumai/core/src/s3/s3'
vi.mock('@/services/s3/s3') vi.mock('@shumai/core/src/s3/s3')
describe('analyzeAssetMediaTool', () => { describe('analyzeAssetMediaTool', () => {
beforeEach(() => { beforeEach(() => {
@@ -1,8 +1,8 @@
import { s3Service } from '@/services/s3/s3' import { s3Service } from '@shumai/core/src/s3/s3'
import { Type } from '@sinclair/typebox' import { Type } from '@sinclair/typebox'
import { type AgentTool } from '@earendil-works/pi-agent-core' import { type AgentTool } from '@earendil-works/pi-agent-core'
import { type ImageContent, type TextContent } from '@earendil-works/pi-ai' import { type ImageContent, type TextContent } from '@earendil-works/pi-ai'
import { detectSupportedMimeType } from '@/utils/mime' import { detectSupportedMimeType } from '@shumai/core/src/utils/mime'
const analyzeAssetMediaSchema = Type.Object({ const analyzeAssetMediaSchema = Type.Object({
key: Type.String({ key: Type.String({
@@ -3,8 +3,8 @@ import { type AgentTool } from '@earendil-works/pi-agent-core'
import { executeAgentToolWorkflow } from './utils' import { executeAgentToolWorkflow } from './utils'
import * as fs from 'fs' import * as fs from 'fs'
import * as path from 'path' import * as path from 'path'
import { s3Service } from '@/services/s3/s3' import { s3Service } from '@shumai/core/src/s3/s3'
import { detectSupportedMimeType } from '@/utils/mime' import { detectSupportedMimeType } from '@shumai/core/src/utils/mime'
import { ulid } from 'ulid' import { ulid } from 'ulid'
function getMimeType(filePath: string): string { function getMimeType(filePath: string): string {
@@ -3,8 +3,8 @@ import { type AgentTool } from '@earendil-works/pi-agent-core'
import { executeAgentToolWorkflow } from './utils' import { executeAgentToolWorkflow } from './utils'
import * as fs from 'fs' import * as fs from 'fs'
import * as path from 'path' import * as path from 'path'
import { s3Service } from '@/services/s3/s3' import { s3Service } from '@shumai/core/src/s3/s3'
import { detectSupportedMimeType } from '@/utils/mime' import { detectSupportedMimeType } from '@shumai/core/src/utils/mime'
import { ulid } from 'ulid' import { ulid } from 'ulid'
function getMimeType(filePath: string): string { function getMimeType(filePath: string): string {
@@ -1,19 +1,15 @@
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest' import { vi } from 'vitest'
import { prisma } from '@/db'
import { setupTestDbHooks } from '@/db-test-hooks'
import { createReadSkillTool } from './read-skill'
import { s3Service } from '@/services/s3/s3'
import * as fs from 'fs'
vi.mock('@/services/s3/s3') vi.mock('@shumai/core/src/s3/s3')
vi.mock('fs') vi.mock('fs')
vi.mock('adm-zip', () => {
return { import { describe, it, expect, beforeEach, afterEach } from 'vitest'
default: class { import { prisma } from '@shumai/db'
extractAllTo = vi.fn() import { setupTestDbHooks } from '@shumai/db/test'
}, import { createReadSkillTool } from './read-skill'
} import { s3Service } from '@shumai/core/src/s3/s3'
}) import AdmZip from 'adm-zip'
import * as fs from 'fs'
describe('readSkillTool', () => { describe('readSkillTool', () => {
setupTestDbHooks() setupTestDbHooks()
@@ -95,9 +91,13 @@ describe('readSkillTool', () => {
return '' return ''
}) })
const zip = new AdmZip()
zip.addFile('SKILL.md', Buffer.from('# Extracted Content'))
const zipBuffer = zip.toBuffer()
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- mocking s3Service return // eslint-disable-next-line @typescript-eslint/no-explicit-any -- mocking s3Service return
;(s3Service.getObject as any).mockResolvedValue({ ;(s3Service.getObject as any).mockResolvedValue({
buffer: Buffer.from('zipdata'), buffer: zipBuffer,
contentType: 'application/zip', contentType: 'application/zip',
}) })
@@ -1,7 +1,7 @@
import { prisma } from '@/db' import { prisma } from '@shumai/db'
import { Type } from '@sinclair/typebox' import { Type } from '@sinclair/typebox'
import { type AgentTool } from '@earendil-works/pi-agent-core' import { type AgentTool } from '@earendil-works/pi-agent-core'
import { agentService } from '@/services/agent/agent' import { agentService } from '@shumai/core/src/agent/agent'
const readSkillSchema = Type.Object({ const readSkillSchema = Type.Object({
skillId: Type.String({ description: 'The ID of the skill to read' }), skillId: Type.String({ description: 'The ID of the skill to read' }),
@@ -1,4 +1,4 @@
import { logger } from '@/logger' import { logger } from '@shumai/core/src/logger'
import { SandboxManager } from '@anthropic-ai/sandbox-runtime' import { SandboxManager } from '@anthropic-ai/sandbox-runtime'
import { type AgentTool, type AgentToolResult } from '@earendil-works/pi-agent-core' import { type AgentTool, type AgentToolResult } from '@earendil-works/pi-agent-core'
import { Type } from '@sinclair/typebox' import { Type } from '@sinclair/typebox'
@@ -1,6 +1,6 @@
import { prisma } from '@/db' import { prisma } from '@shumai/db'
import { workflowService } from '@/workflow/workflow' import { workflowService } from '@shumai/workflow-core'
import { WorkflowTaskType, WorkflowTaskStatus } from '@/generated/prisma/client' import { WorkflowTaskType, WorkflowTaskStatus } from '@shumai/db'
export async function executeAgentToolWorkflow(params: { export async function executeAgentToolWorkflow(params: {
toolName: string toolName: string
@@ -1,11 +1,11 @@
import { describe, it, expect, vi, beforeEach } from 'vitest' import { describe, it, expect, vi, beforeEach } from 'vitest'
import { agentAutofillMedia } from './agent-autofill' import { agentAutofillMedia } from './agent-autofill'
import { prisma } from '@/db' import { prisma } from '@shumai/db'
import { setupTestDbHooks } from '@/db-test-hooks' import { setupTestDbHooks } from '@shumai/db/test'
import * as workflowUtils from '@/workflow/workflow-utils' import * as workflowUtils from '@shumai/workflow-core'
vi.mock('@/workflow/workflow-utils', async () => { vi.mock('@shumai/workflow-core', async () => {
const actual = await vi.importActual('@/workflow/workflow-utils') const actual = await vi.importActual('@shumai/workflow-core')
return { return {
...actual, ...actual,
getActivities: vi.fn(), getActivities: vi.fn(),
@@ -1,12 +1,11 @@
import { ApplicationFailure } from '@temporalio/workflow' import { ApplicationFailure } from '@temporalio/workflow'
import type { WorkflowTask } from '@/generated/prisma/client' import type { WorkflowTask } from '@shumai/db'
import { import {
getActivities, getActivities,
executeActivity, executeActivity,
TaskQueueDb,
TaskQueueAgent, TaskQueueAgent,
TaskQueueTranscode, TaskQueueTranscode,
} from '@/workflow/workflow-utils' } from '@shumai/workflow-core'
export async function agentAutofillMedia(task: WorkflowTask): Promise<void> { export async function agentAutofillMedia(task: WorkflowTask): Promise<void> {
const { const {
@@ -28,18 +27,18 @@ export async function agentAutofillMedia(task: WorkflowTask): Promise<void> {
let placeholderCommentId: string | undefined let placeholderCommentId: string | undefined
let tmpDir: string | undefined let tmpDir: string | undefined
let transcodeWorkerQueue: string | undefined let transcodeWorkerQueue = ''
try { try {
// Update status to processing // Update status to processing
await executeActivity(TaskQueueDb, updateTaskStatusActivity, { await executeActivity(TaskQueueAgent, updateTaskStatusActivity, {
taskId: task.id, taskId: task.id,
status: 'processing', status: 'processing',
}) })
// 0. Create Placeholder Comment // 0. Create Placeholder Comment
const payload = task.payload const payload = task.payload
const placeholder = await executeActivity(TaskQueueDb, createCommentActivity, { const placeholder = await executeActivity(TaskQueueAgent, createCommentActivity, {
assetId: task.assetId, assetId: task.assetId,
message: '__AUTOFILL__', message: '__AUTOFILL__',
sessionId: payload?.agent?.sessionId || task.id, sessionId: payload?.agent?.sessionId || task.id,
@@ -48,7 +47,7 @@ export async function agentAutofillMedia(task: WorkflowTask): Promise<void> {
placeholderCommentId = placeholder.id placeholderCommentId = placeholder.id
// 1. Get Asset // 1. Get Asset
const asset = await executeActivity(TaskQueueDb, getAssetActivity, task.assetId) const asset = await executeActivity(TaskQueueAgent, getAssetActivity, task.assetId)
const key = asset?.storageKey?.key const key = asset?.storageKey?.key
if (!asset || !asset.project || !key) { if (!asset || !asset.project || !key) {
throw ApplicationFailure.create({ message: 'Asset or project not found', nonRetryable: true }) throw ApplicationFailure.create({ message: 'Asset or project not found', nonRetryable: true })
@@ -81,12 +80,12 @@ export async function agentAutofillMedia(task: WorkflowTask): Promise<void> {
if (generatedFiles.length === 0) { if (generatedFiles.length === 0) {
// If no images could be extracted, we can't do much // If no images could be extracted, we can't do much
if (placeholderCommentId) { if (placeholderCommentId) {
await executeActivity(TaskQueueDb, updateCommentActivity, { await executeActivity(TaskQueueAgent, updateCommentActivity, {
commentId: placeholderCommentId, commentId: placeholderCommentId,
message: 'Autofill completed: No images could be extracted for analysis.', message: 'Autofill completed: No images could be extracted for analysis.',
}) })
} }
await executeActivity(TaskQueueDb, updateTaskStatusActivity, { await executeActivity(TaskQueueAgent, updateTaskStatusActivity, {
taskId: task.id, taskId: task.id,
status: 'completed', status: 'completed',
}) })
@@ -94,23 +93,23 @@ export async function agentAutofillMedia(task: WorkflowTask): Promise<void> {
} }
// 3. Get Project Autofill Fields // 3. Get Project Autofill Fields
const fields = await executeActivity(TaskQueueDb, getProjectAutofillFieldsActivity, projectId) const fields = await executeActivity(TaskQueueAgent, getProjectAutofillFieldsActivity, projectId)
if (fields.length === 0) { if (fields.length === 0) {
if (placeholderCommentId) { if (placeholderCommentId) {
await executeActivity(TaskQueueDb, updateCommentActivity, { await executeActivity(TaskQueueAgent, updateCommentActivity, {
commentId: placeholderCommentId, commentId: placeholderCommentId,
message: 'Autofill completed: No autofill fields defined in project.', message: 'Autofill completed: No autofill fields defined in project.',
}) })
} }
await executeActivity(TaskQueueDb, updateTaskStatusActivity, { await executeActivity(TaskQueueAgent, updateTaskStatusActivity, {
taskId: task.id, taskId: task.id,
status: 'completed', status: 'completed',
}) })
return return
} }
// 3b. Fetch Agent Context (Database Activity on db_queue) // 3b. Fetch Agent Context
const context = await executeActivity(TaskQueueDb, getAgentAutofillContextActivity, { const context = await executeActivity(TaskQueueAgent, getAgentAutofillContextActivity, {
teamId, teamId,
}) })
@@ -120,17 +119,19 @@ export async function agentAutofillMedia(task: WorkflowTask): Promise<void> {
const aiResult = await executeActivity(agentWorkerQueue, autofillAiActivity, { const aiResult = await executeActivity(agentWorkerQueue, autofillAiActivity, {
teamId, teamId,
images: generatedFiles, images: generatedFiles,
fields: fields.map((f) => ({ fields: fields.map(
id: f.key, (f: { key: string; config: Record<string, unknown>; description?: string | null }) => ({
config: f.config as unknown as PrismaJson.FieldConfig, id: f.key,
description: f.description, config: f.config as unknown as PrismaJson.FieldConfig,
})), description: f.description,
}),
),
context, context,
}) })
if (aiResult.usage) { if (aiResult.usage) {
// Update Usage // Update Usage
await executeActivity(TaskQueueDb, updateTaskUsageActivity, { await executeActivity(TaskQueueAgent, updateTaskUsageActivity, {
taskId: task.id, taskId: task.id,
inputTokens: aiResult.usage.inputTokens, inputTokens: aiResult.usage.inputTokens,
outputTokens: aiResult.usage.outputTokens, outputTokens: aiResult.usage.outputTokens,
@@ -146,7 +147,7 @@ export async function agentAutofillMedia(task: WorkflowTask): Promise<void> {
})) }))
if (metadataUpdates.length > 0) { if (metadataUpdates.length > 0) {
await executeActivity(TaskQueueDb, updateAssetMetadataActivity, { await executeActivity(TaskQueueAgent, updateAssetMetadataActivity, {
assetId: asset.id, assetId: asset.id,
metadata: metadataUpdates, metadata: metadataUpdates,
}) })
@@ -154,7 +155,7 @@ export async function agentAutofillMedia(task: WorkflowTask): Promise<void> {
// 7. Update Placeholder Comment // 7. Update Placeholder Comment
if (placeholderCommentId) { if (placeholderCommentId) {
await executeActivity(TaskQueueDb, updateCommentActivity, { await executeActivity(TaskQueueAgent, updateCommentActivity, {
commentId: placeholderCommentId, commentId: placeholderCommentId,
message: 'Autofill completed successfully.', message: 'Autofill completed successfully.',
sessionId: aiResult.sessionId, sessionId: aiResult.sessionId,
@@ -162,7 +163,7 @@ export async function agentAutofillMedia(task: WorkflowTask): Promise<void> {
} }
// Update status to completed // Update status to completed
await executeActivity(TaskQueueDb, updateTaskStatusActivity, { await executeActivity(TaskQueueAgent, updateTaskStatusActivity, {
taskId: task.id, taskId: task.id,
status: 'completed', status: 'completed',
}) })
@@ -172,7 +173,7 @@ export async function agentAutofillMedia(task: WorkflowTask): Promise<void> {
// Update placeholder comment with error message // Update placeholder comment with error message
if (placeholderCommentId) { if (placeholderCommentId) {
try { try {
await executeActivity(TaskQueueDb, updateCommentActivity, { await executeActivity(TaskQueueAgent, updateCommentActivity, {
commentId: placeholderCommentId, commentId: placeholderCommentId,
message: `Autofill failed: ${err instanceof Error ? err.message : String(err)}`, message: `Autofill failed: ${err instanceof Error ? err.message : String(err)}`,
}) })
@@ -182,7 +183,7 @@ export async function agentAutofillMedia(task: WorkflowTask): Promise<void> {
} }
// Update status to failed // Update status to failed
await executeActivity(TaskQueueDb, updateTaskStatusActivity, { await executeActivity(TaskQueueAgent, updateTaskStatusActivity, {
taskId: task.id, taskId: task.id,
status: 'failed', status: 'failed',
output: { error: err instanceof Error ? err.message : String(err) }, output: { error: err instanceof Error ? err.message : String(err) },
@@ -1,11 +1,11 @@
import { describe, it, expect, vi, beforeEach } from 'vitest' import { describe, it, expect, vi, beforeEach } from 'vitest'
import { agentChat } from './agent-chat' import { agentChat } from './agent-chat'
import { prisma } from '@/db' import { prisma } from '@shumai/db'
import { setupTestDbHooks } from '@/db-test-hooks' import { setupTestDbHooks } from '@shumai/db/test'
import * as workflowUtils from '@/workflow/workflow-utils' import * as workflowUtils from '@shumai/workflow-core'
vi.mock('@/workflow/workflow-utils', async () => { vi.mock('@shumai/workflow-core', async () => {
const actual = await vi.importActual('@/workflow/workflow-utils') const actual = await vi.importActual('@shumai/workflow-core')
return { return {
...actual, ...actual,
getActivities: vi.fn(), getActivities: vi.fn(),
@@ -1,11 +1,6 @@
import { ApplicationFailure } from '@temporalio/workflow' import { ApplicationFailure } from '@temporalio/workflow'
import type { WorkflowTask } from '@/generated/prisma/client' import type { WorkflowTask } from '@shumai/db'
import { import { executeActivity, getActivities, TaskQueueAgent } from '@shumai/workflow-core'
executeActivity,
getActivities,
TaskQueueAgent,
TaskQueueDb,
} from '@/workflow/workflow-utils'
export async function agentChat(task: WorkflowTask): Promise<void> { export async function agentChat(task: WorkflowTask): Promise<void> {
const { const {
@@ -27,7 +22,7 @@ export async function agentChat(task: WorkflowTask): Promise<void> {
try { try {
// Update status to processing // Update status to processing
await executeActivity(TaskQueueDb, updateTaskStatusActivity, { await executeActivity(TaskQueueAgent, updateTaskStatusActivity, {
taskId: task.id, taskId: task.id,
status: 'processing', status: 'processing',
}) })
@@ -52,13 +47,13 @@ export async function agentChat(task: WorkflowTask): Promise<void> {
nonRetryable: true, nonRetryable: true,
}) })
} }
const userComment = await executeActivity(TaskQueueDb, getCommentActivity, userCommentId) const userComment = await executeActivity(TaskQueueAgent, getCommentActivity, userCommentId)
if (!userComment) { if (!userComment) {
throw ApplicationFailure.create({ message: 'User comment not found', nonRetryable: true }) throw ApplicationFailure.create({ message: 'User comment not found', nonRetryable: true })
} }
// 2. Create Placeholder Comment // 2. Create Placeholder Comment
const placeholder = await executeActivity(TaskQueueDb, createCommentActivity, { const placeholder = await executeActivity(TaskQueueAgent, createCommentActivity, {
assetId: task.assetId, assetId: task.assetId,
message: '__CHAT__', message: '__CHAT__',
sessionId: sessionId || 'pending', sessionId: sessionId || 'pending',
@@ -68,15 +63,15 @@ export async function agentChat(task: WorkflowTask): Promise<void> {
placeholderCommentId = placeholder.id placeholderCommentId = placeholder.id
// 3. Get Asset // 3. Get Asset
const asset = await executeActivity(TaskQueueDb, getAssetActivity, task.assetId) const asset = await executeActivity(TaskQueueAgent, getAssetActivity, task.assetId)
if (!asset || !asset.project) { if (!asset || !asset.project) {
throw ApplicationFailure.create({ message: 'Asset or project not found', nonRetryable: true }) throw ApplicationFailure.create({ message: 'Asset or project not found', nonRetryable: true })
} }
const teamId = asset.project.teamId const teamId = asset.project.teamId
// 4. Initialize Session if missing (Database Activity on db_queue) // 4. Initialize Session if missing
if (!sessionId) { if (!sessionId) {
sessionId = await executeActivity(TaskQueueDb, initializeAgentSessionActivity, { sessionId = await executeActivity(TaskQueueAgent, initializeAgentSessionActivity, {
teamId, teamId,
agentId: agentId, agentId: agentId,
userCommentId, userCommentId,
@@ -84,8 +79,8 @@ export async function agentChat(task: WorkflowTask): Promise<void> {
}) })
} }
// 4b. Fetch Agent Context (Database Activity on db_queue) // 4b. Fetch Agent Context
const context = await executeActivity(TaskQueueDb, getAgentChatContextActivity, { const context = await executeActivity(TaskQueueAgent, getAgentChatContextActivity, {
teamId, teamId,
agentId: agentId, agentId: agentId,
}) })
@@ -101,7 +96,7 @@ export async function agentChat(task: WorkflowTask): Promise<void> {
} }
const pathContext = await executeActivity( const pathContext = await executeActivity(
TaskQueueDb, TaskQueueAgent,
getAssetPathContextActivity, getAssetPathContextActivity,
task.assetId, task.assetId,
) )
@@ -150,9 +145,9 @@ export async function agentChat(task: WorkflowTask): Promise<void> {
// 7. Update Placeholder Comment // 7. Update Placeholder Comment
if (placeholderCommentId) { if (placeholderCommentId) {
if (aiResult.text.trim() === '__NO_REPLY__') { if (aiResult.text.trim() === '__NO_REPLY__') {
await executeActivity(TaskQueueDb, deleteCommentActivity, placeholderCommentId) await executeActivity(TaskQueueAgent, deleteCommentActivity, placeholderCommentId)
} else { } else {
await executeActivity(TaskQueueDb, updateCommentActivity, { await executeActivity(TaskQueueAgent, updateCommentActivity, {
commentId: placeholderCommentId, commentId: placeholderCommentId,
message: aiResult.text, message: aiResult.text,
sessionId: aiResult.sessionId, sessionId: aiResult.sessionId,
@@ -162,7 +157,7 @@ export async function agentChat(task: WorkflowTask): Promise<void> {
// 8. Update Usage // 8. Update Usage
if (aiResult.usage) { if (aiResult.usage) {
await executeActivity(TaskQueueDb, updateTaskUsageActivity, { await executeActivity(TaskQueueAgent, updateTaskUsageActivity, {
taskId: task.id, taskId: task.id,
inputTokens: aiResult.usage.inputTokens, inputTokens: aiResult.usage.inputTokens,
outputTokens: aiResult.usage.outputTokens, outputTokens: aiResult.usage.outputTokens,
@@ -171,7 +166,7 @@ export async function agentChat(task: WorkflowTask): Promise<void> {
} }
// Update status to completed // Update status to completed
await executeActivity(TaskQueueDb, updateTaskStatusActivity, { await executeActivity(TaskQueueAgent, updateTaskStatusActivity, {
taskId: task.id, taskId: task.id,
status: 'completed', status: 'completed',
output: { sessionId: aiResult.sessionId }, output: { sessionId: aiResult.sessionId },
@@ -187,7 +182,7 @@ export async function agentChat(task: WorkflowTask): Promise<void> {
? `AI error: ${err.message.substring(9)}` ? `AI error: ${err.message.substring(9)}`
: 'Sorry, I encountered an error while processing your request.' : 'Sorry, I encountered an error while processing your request.'
await executeActivity(TaskQueueDb, updateCommentActivity, { await executeActivity(TaskQueueAgent, updateCommentActivity, {
commentId: placeholderCommentId, commentId: placeholderCommentId,
message: errorMessage, message: errorMessage,
}) })
@@ -197,7 +192,7 @@ export async function agentChat(task: WorkflowTask): Promise<void> {
} }
// Update status to failed // Update status to failed
await executeActivity(TaskQueueDb, updateTaskStatusActivity, { await executeActivity(TaskQueueAgent, updateTaskStatusActivity, {
taskId: task.id, taskId: task.id,
status: 'failed', status: 'failed',
output: { error: err instanceof Error ? err.message : String(err) }, output: { error: err instanceof Error ? err.message : String(err) },
@@ -1,11 +1,11 @@
import { describe, it, expect, vi, beforeEach } from 'vitest' import { describe, it, expect, vi, beforeEach } from 'vitest'
import { agentEmbeddingMedia } from './agent-embedding' import { agentEmbeddingMedia } from './agent-embedding'
import { prisma } from '@/db' import { prisma } from '@shumai/db'
import { setupTestDbHooks } from '@/db-test-hooks' import { setupTestDbHooks } from '@shumai/db/test'
import * as workflowUtils from '@/workflow/workflow-utils' import * as workflowUtils from '@shumai/workflow-core'
vi.mock('@/workflow/workflow-utils', async () => { vi.mock('@shumai/workflow-core', async () => {
const actual = await vi.importActual('@/workflow/workflow-utils') const actual = await vi.importActual('@shumai/workflow-core')
return { return {
...actual, ...actual,
getActivities: vi.fn(), getActivities: vi.fn(),
@@ -1,6 +1,6 @@
import { ApplicationFailure } from '@temporalio/workflow' import { ApplicationFailure } from '@temporalio/workflow'
import type { WorkflowTask } from '@/generated/prisma/client' import type { WorkflowTask } from '@shumai/db'
import { getActivities, executeActivity, TaskQueueDb, TaskQueueAgent } from '../workflow-utils' import { getActivities, executeActivity, TaskQueueAgent } from '@shumai/workflow-core'
export async function agentEmbeddingMedia(task: WorkflowTask): Promise<void> { export async function agentEmbeddingMedia(task: WorkflowTask): Promise<void> {
const { const {
@@ -18,14 +18,14 @@ export async function agentEmbeddingMedia(task: WorkflowTask): Promise<void> {
try { try {
// Update status to processing // Update status to processing
await executeActivity(TaskQueueDb, updateTaskStatusActivity, { await executeActivity(TaskQueueAgent, updateTaskStatusActivity, {
taskId: task.id, taskId: task.id,
status: 'processing', status: 'processing',
}) })
// 0. Create Placeholder Comment // 0. Create Placeholder Comment
const payload = task.payload const payload = task.payload
const placeholder = await executeActivity(TaskQueueDb, createCommentActivity, { const placeholder = await executeActivity(TaskQueueAgent, createCommentActivity, {
assetId: task.assetId, assetId: task.assetId,
message: '__EMBEDDING__', message: '__EMBEDDING__',
sessionId: payload?.agent?.sessionId || task.id, sessionId: payload?.agent?.sessionId || task.id,
@@ -37,8 +37,8 @@ export async function agentEmbeddingMedia(task: WorkflowTask): Promise<void> {
throw ApplicationFailure.create({ message: 'Task has no teamId', nonRetryable: true }) throw ApplicationFailure.create({ message: 'Task has no teamId', nonRetryable: true })
} }
// 1. Fetch Agent Context (Database Activity on db_queue) // 1. Fetch Agent Context
const context = await executeActivity(TaskQueueDb, getEmbeddingContextActivity, { const context = await executeActivity(TaskQueueAgent, getEmbeddingContextActivity, {
teamId: task.teamId, teamId: task.teamId,
assetId: task.assetId, assetId: task.assetId,
}) })
@@ -54,7 +54,7 @@ export async function agentEmbeddingMedia(task: WorkflowTask): Promise<void> {
// Save computed embeddings // Save computed embeddings
if (result.embeddings.length > 0) { if (result.embeddings.length > 0) {
await executeActivity(TaskQueueDb, saveAssetEmbeddingsActivity, { await executeActivity(TaskQueueAgent, saveAssetEmbeddingsActivity, {
assetId: task.assetId, assetId: task.assetId,
embeddings: result.embeddings, embeddings: result.embeddings,
}) })
@@ -62,7 +62,7 @@ export async function agentEmbeddingMedia(task: WorkflowTask): Promise<void> {
// Update Usage // Update Usage
if (result.usage) { if (result.usage) {
await executeActivity(TaskQueueDb, updateTaskUsageActivity, { await executeActivity(TaskQueueAgent, updateTaskUsageActivity, {
taskId: task.id, taskId: task.id,
inputTokens: result.usage.inputTokens, inputTokens: result.usage.inputTokens,
outputTokens: result.usage.outputTokens, outputTokens: result.usage.outputTokens,
@@ -72,14 +72,14 @@ export async function agentEmbeddingMedia(task: WorkflowTask): Promise<void> {
// 7. Update Placeholder Comment // 7. Update Placeholder Comment
if (placeholderCommentId) { if (placeholderCommentId) {
await executeActivity(TaskQueueDb, updateCommentActivity, { await executeActivity(TaskQueueAgent, updateCommentActivity, {
commentId: placeholderCommentId, commentId: placeholderCommentId,
message: 'Embedding completed successfully.', message: 'Embedding completed successfully.',
}) })
} }
// Update status to completed // Update status to completed
await executeActivity(TaskQueueDb, updateTaskStatusActivity, { await executeActivity(TaskQueueAgent, updateTaskStatusActivity, {
taskId: task.id, taskId: task.id,
status: 'completed', status: 'completed',
}) })
@@ -89,7 +89,7 @@ export async function agentEmbeddingMedia(task: WorkflowTask): Promise<void> {
// Update placeholder comment with error message // Update placeholder comment with error message
if (placeholderCommentId) { if (placeholderCommentId) {
try { try {
await executeActivity(TaskQueueDb, updateCommentActivity, { await executeActivity(TaskQueueAgent, updateCommentActivity, {
commentId: placeholderCommentId, commentId: placeholderCommentId,
message: `Embedding failed: ${err instanceof Error ? err.message : String(err)}`, message: `Embedding failed: ${err instanceof Error ? err.message : String(err)}`,
}) })
@@ -99,7 +99,7 @@ export async function agentEmbeddingMedia(task: WorkflowTask): Promise<void> {
} }
// Update status to failed // Update status to failed
await executeActivity(TaskQueueDb, updateTaskStatusActivity, { await executeActivity(TaskQueueAgent, updateTaskStatusActivity, {
taskId: task.id, taskId: task.id,
status: 'failed', status: 'failed',
output: { error: err instanceof Error ? err.message : String(err) }, output: { error: err instanceof Error ? err.message : String(err) },
@@ -1,13 +1,13 @@
import { ApplicationFailure } from '@temporalio/workflow' import { ApplicationFailure } from '@temporalio/workflow'
import type { WorkflowTask } from '@/generated/prisma/client' import type { WorkflowTask } from '@shumai/db'
import { getActivities, executeActivity, TaskQueueDb } from '../workflow-utils' import { getActivities, executeActivity, TaskQueueAgent } from '@shumai/workflow-core'
export async function agentToolCall(task: WorkflowTask): Promise<void> { export async function agentToolCall(task: WorkflowTask): Promise<void> {
const { updateTaskStatusActivity, executeAgentToolActivity } = getActivities() const { updateTaskStatusActivity, executeAgentToolActivity } = getActivities()
try { try {
// Update status to processing // Update status to processing
await executeActivity(TaskQueueDb, updateTaskStatusActivity, { await executeActivity(TaskQueueAgent, updateTaskStatusActivity, {
taskId: task.id, taskId: task.id,
status: 'processing', status: 'processing',
}) })
@@ -22,8 +22,8 @@ export async function agentToolCall(task: WorkflowTask): Promise<void> {
const { toolName, args, userId } = payload.agentToolCall const { toolName, args, userId } = payload.agentToolCall
// Execute the database activity on db_queue // Execute the agent activity on agent_queue
const result = await executeActivity(TaskQueueDb, executeAgentToolActivity, { const result = await executeActivity(TaskQueueAgent, executeAgentToolActivity, {
taskId: task.id, taskId: task.id,
toolName, toolName,
args, args,
@@ -31,7 +31,7 @@ export async function agentToolCall(task: WorkflowTask): Promise<void> {
}) })
// Update status to completed with output // Update status to completed with output
await executeActivity(TaskQueueDb, updateTaskStatusActivity, { await executeActivity(TaskQueueAgent, updateTaskStatusActivity, {
taskId: task.id, taskId: task.id,
status: 'completed', status: 'completed',
output: result, output: result,
@@ -40,7 +40,7 @@ export async function agentToolCall(task: WorkflowTask): Promise<void> {
console.error(`AgentToolCall failed for task ${task.id}:`, err) console.error(`AgentToolCall failed for task ${task.id}:`, err)
// Update status to failed // Update status to failed
await executeActivity(TaskQueueDb, updateTaskStatusActivity, { await executeActivity(TaskQueueAgent, updateTaskStatusActivity, {
taskId: task.id, taskId: task.id,
status: 'failed', status: 'failed',
output: { error: err instanceof Error ? err.message : String(err) }, output: { error: err instanceof Error ? err.message : String(err) },
@@ -1,5 +1,5 @@
import type { WorkflowTask } from '@/generated/prisma/client' import type { WorkflowTask } from '@shumai/db'
import { getActivities, executeActivity, TaskQueueDb } from '../workflow-utils' import { getActivities, executeActivity, TaskQueueAgent } from '@shumai/workflow-core'
export async function queryEmbeddingForSearch(task: WorkflowTask): Promise<void> { export async function queryEmbeddingForSearch(task: WorkflowTask): Promise<void> {
const { generateTextEmbeddingActivity, updateWorkflowTaskActivity } = getActivities() const { generateTextEmbeddingActivity, updateWorkflowTaskActivity } = getActivities()
@@ -13,20 +13,20 @@ export async function queryEmbeddingForSearch(task: WorkflowTask): Promise<void>
try { try {
// 1. Mark as processing // 1. Mark as processing
await executeActivity(TaskQueueDb, updateWorkflowTaskActivity, { await executeActivity(TaskQueueAgent, updateWorkflowTaskActivity, {
taskId: task.id, taskId: task.id,
status: 'processing', status: 'processing',
heartbeat: true, heartbeat: true,
}) })
// 2. Generate embedding // 2. Generate embedding
const result = await generateTextEmbeddingActivity({ const result = await executeActivity(TaskQueueAgent, generateTextEmbeddingActivity, {
text, text,
teamId: task.teamId!, teamId: task.teamId!,
}) })
// 3. Save output and complete // 3. Save output and complete
await executeActivity(TaskQueueDb, updateWorkflowTaskActivity, { await executeActivity(TaskQueueAgent, updateWorkflowTaskActivity, {
taskId: task.id, taskId: task.id,
status: 'completed', status: 'completed',
output: { embedding: result.embedding }, output: { embedding: result.embedding },
@@ -36,7 +36,7 @@ export async function queryEmbeddingForSearch(task: WorkflowTask): Promise<void>
}) })
} catch (err) { } catch (err) {
console.error(`queryEmbeddingForSearch failed for task ${task.id}:`, err) console.error(`queryEmbeddingForSearch failed for task ${task.id}:`, err)
await executeActivity(TaskQueueDb, updateWorkflowTaskActivity, { await executeActivity(TaskQueueAgent, updateWorkflowTaskActivity, {
taskId: task.id, taskId: task.id,
status: 'failed', status: 'failed',
output: { output: {
+7
View File
@@ -0,0 +1,7 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"ignoreDeprecations": "6.0"
},
"include": ["src/**/*"]
}
+18
View File
@@ -0,0 +1,18 @@
{
"name": "@shumai/api",
"version": "0.1.0",
"private": true,
"type": "module",
"main": "./src/index.ts",
"types": "./src/index.ts",
"dependencies": {
"@shumai/core": "workspace:*",
"@shumai/db": "workspace:*",
"@shumai/dtos": "workspace:*",
"hono": "^4.12.14",
"@hono/zod-validator": "^0.7.6",
"zod": "^4.4.3",
"pino": "^10.3.1",
"ulid": "^3.0.2"
}
}
@@ -1,10 +1,10 @@
import { describe, it, expect, vi, beforeEach } from 'vitest' import { describe, it, expect, vi, beforeEach } from 'vitest'
import { agentService } from '@/services/agent/agent' import { agentService } from '@shumai/core/src/agent/agent'
import { authzService } from '@/services/authz/authz' import { authzService } from '@shumai/core/src/authz/authz'
import app from './agent' import app from './agent'
vi.mock('@/services/agent/agent') vi.mock('@shumai/core/src/agent/agent')
vi.mock('@/services/authz/authz') vi.mock('@shumai/core/src/authz/authz')
describe('Agent API', () => { describe('Agent API', () => {
beforeEach(() => { beforeEach(() => {
@@ -1,15 +1,15 @@
import { Hono } from 'hono' import { Hono } from 'hono'
import { zValidator } from '@hono/zod-validator' import { zValidator } from '@hono/zod-validator'
import { agentService } from '@/services/agent/agent' import { agentService } from '@shumai/core/src/agent/agent'
import { authzService, Permission, ResourceType } from '@/services/authz/authz' import { authzService, Permission, ResourceType } from '@shumai/core/src/authz/authz'
import { import {
createAgentRequestSchema, createAgentRequestSchema,
updateAgentRequestSchema, updateAgentRequestSchema,
AgentInfo, AgentInfo,
AgentType, AgentType,
} from '@/dtos/agent' } from '@shumai/dtos'
import type { Prisma } from '@/generated/prisma/client' import type { Prisma } from '@shumai/db'
type User = Prisma.UserGetPayload<Record<string, never>> type User = Prisma.UserGetPayload<Record<string, never>>
@@ -1,12 +1,12 @@
import { describe, expect, it, vi, beforeEach } from 'vitest' import { describe, expect, it, vi, beforeEach } from 'vitest'
import { Hono } from 'hono' import { Hono } from 'hono'
import attachmentRoute from './attachment' import attachmentRoute from './attachment'
import { assetService } from '@/services/asset/asset' import { assetService } from '@shumai/core/src/asset/asset'
import { AssetType } from '@/generated/prisma/client' import { AssetType } from '@shumai/db'
import { authMiddleware } from '@/api/middleware/auth' import { authMiddleware } from './middleware/auth'
import { authzService, Permission, ResourceType } from '@/services/authz/authz' import { authzService, Permission, ResourceType } from '@shumai/core/src/authz/authz'
vi.mock('@/api/middleware/auth', () => ({ vi.mock('./middleware/auth', () => ({
// any is used here because Hono's Context and Next types are complex to mock in vitest.mock // any is used here because Hono's Context and Next types are complex to mock in vitest.mock
// eslint-disable-next-line @typescript-eslint/no-explicit-any // eslint-disable-next-line @typescript-eslint/no-explicit-any
authMiddleware: async (c: any, next: any) => { authMiddleware: async (c: any, next: any) => {
@@ -16,10 +16,10 @@ vi.mock('@/api/middleware/auth', () => ({
}, },
})) }))
vi.mock('@/services/authz/authz') vi.mock('@shumai/core/src/authz/authz')
vi.mock('@/services/asset/asset') vi.mock('@shumai/core/src/asset/asset')
vi.mock('@/services/s3/s3', () => ({ vi.mock('@shumai/core/src/s3/s3', () => ({
s3Service: { s3Service: {
presign: vi.fn().mockResolvedValue('http://mock-s3-url'), presign: vi.fn().mockResolvedValue('http://mock-s3-url'),
}, },
@@ -1,12 +1,12 @@
import { Hono } from 'hono' import { Hono } from 'hono'
import { zValidator } from '@hono/zod-validator' import { zValidator } from '@hono/zod-validator'
import { postAttachmentRequestSchema } from '@/dtos/asset' import { postAttachmentRequestSchema } from '@shumai/dtos'
import { assetService } from '@/services/asset/asset' import { assetService } from '@shumai/core/src/asset/asset'
import { s3Service } from '@/services/s3/s3' import { s3Service } from '@shumai/core/src/s3/s3'
import { AssetType } from '@/generated/prisma/client' import { AssetType } from '@shumai/db'
import { ulid } from 'ulid' import { ulid } from 'ulid'
import { authzService, Permission, ResourceType } from '@/services/authz/authz' import { authzService, Permission, ResourceType } from '@shumai/core/src/authz/authz'
import type { Prisma } from '@/generated/prisma/client' import type { Prisma } from '@shumai/db'
type User = Prisma.UserGetPayload<Record<string, never>> type User = Prisma.UserGetPayload<Record<string, never>>
@@ -1,7 +1,7 @@
import { describe, expect, it, vi, beforeEach, afterEach } from 'vitest' import { describe, expect, it, vi, beforeEach, afterEach } from 'vitest'
import { Hono } from 'hono' import { Hono } from 'hono'
import authnRoute from './authn' import authnRoute from './authn'
import { teamService } from '@/services/team/team' import { teamService } from '@shumai/core/src/team/team'
describe('authn api', () => { describe('authn api', () => {
// eslint-disable-next-line @typescript-eslint/no-explicit-any // eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -1,9 +1,9 @@
import { Hono } from 'hono' import { Hono } from 'hono'
import { teamService } from '@/services/team/team' import { teamService } from '@shumai/core/src/team/team'
import { auth } from '@/services/auth/auth' import { auth } from '@shumai/core/src/auth/auth'
import { z } from 'zod' import { z } from 'zod'
import { zValidator } from '@hono/zod-validator' import { zValidator } from '@hono/zod-validator'
import { prisma } from '@/db' import { prisma } from '@shumai/db'
import { ulid } from 'ulid' import { ulid } from 'ulid'
const app = new Hono() const app = new Hono()
@@ -1,17 +1,17 @@
import { describe, it, expect, vi, beforeEach } from 'vitest' import { describe, it, expect, vi, beforeEach } from 'vitest'
import { collectionService } from '@/services/collection/collection' import { collectionService } from '@shumai/core/src/collection/collection'
import { authzService, Permission, ResourceType } from '@/services/authz/authz' import { authzService, Permission, ResourceType } from '@shumai/core/src/authz/authz'
import { Hono, Context, Next } from 'hono' import { Hono, Context, Next } from 'hono'
import collectionRoute from './collection' import collectionRoute from './collection'
vi.mock('@/api/middleware/auth', () => ({ vi.mock('./middleware/auth', () => ({
authMiddleware: async (c: Context, next: Next) => { authMiddleware: async (c: Context, next: Next) => {
c.set('user', { id: 'user-1', name: 'Test User' }) c.set('user', { id: 'user-1', name: 'Test User' })
await next() await next()
}, },
})) }))
vi.mock('@/services/authz/authz', () => ({ vi.mock('@shumai/core/src/authz/authz', () => ({
authzService: { authzService: {
hasPermission: vi.fn().mockResolvedValue(undefined), hasPermission: vi.fn().mockResolvedValue(undefined),
}, },
@@ -1,15 +1,15 @@
import { zValidator } from '@hono/zod-validator' import { zValidator } from '@hono/zod-validator'
import { Hono } from 'hono' import { Hono } from 'hono'
import { collectionService } from '@/services/collection/collection' import { collectionService } from '@shumai/core/src/collection/collection'
import { authzService, Permission, ResourceType } from '@/services/authz/authz' import { authzService, Permission, ResourceType } from '@shumai/core/src/authz/authz'
import { import {
createCollectionRequestSchema, createCollectionRequestSchema,
updateCollectionRequestSchema, updateCollectionRequestSchema,
listCollectionsRequestSchema, listCollectionsRequestSchema,
CollectionInfo, CollectionInfo,
CollectionFilter, CollectionFilter,
} from '@/dtos/collection' } from '@shumai/dtos'
import type { Prisma } from '@/generated/prisma/client' import type { Prisma } from '@shumai/db'
type User = Prisma.UserGetPayload<Record<string, never>> type User = Prisma.UserGetPayload<Record<string, never>>
@@ -1,15 +1,15 @@
import { describe, expect, it, vi, beforeEach, afterEach } from 'vitest' import { describe, expect, it, vi, beforeEach, afterEach } from 'vitest'
import { Hono, type Context, type Next } from 'hono' import { Hono, type Context, type Next } from 'hono'
import { prisma } from '@/db' import { prisma } from '@shumai/db'
import fileRoute from './file' import fileRoute from './file'
import { assetService } from '@/services/asset/asset' import { assetService } from '@shumai/core/src/asset/asset'
import { metadataService } from '@/services/metadata/metadata' import { metadataService } from '@shumai/core/src/metadata/metadata'
import { notificationService } from '@/services/notification/notification' import { notificationService } from '@shumai/core/src/notification/notification'
import { s3Service } from '@/services/s3/s3' import { s3Service } from '@shumai/core/src/s3/s3'
import { authMiddleware } from '@/api/middleware/auth' import { authMiddleware } from './middleware/auth'
import { authzService, ResourceType, Permission } from '@/services/authz/authz' import { authzService, ResourceType, Permission } from '@shumai/core/src/authz/authz'
vi.mock('@/services/authz/authz', () => ({ vi.mock('@shumai/core/src/authz/authz', () => ({
authzService: { authzService: {
hasPermission: vi.fn().mockResolvedValue(undefined), hasPermission: vi.fn().mockResolvedValue(undefined),
}, },
@@ -24,7 +24,7 @@ vi.mock('@/services/authz/authz', () => ({
}, },
})) }))
vi.mock('@/api/middleware/auth', () => ({ vi.mock('./middleware/auth', () => ({
authMiddleware: async (c: Context, next: Next) => { authMiddleware: async (c: Context, next: Next) => {
c.set('user', { id: 'user1', name: 'Test User' }) c.set('user', { id: 'user1', name: 'Test User' })
await next() await next()
@@ -1,11 +1,11 @@
import { Hono } from 'hono' import { Hono } from 'hono'
import { zValidator } from '@hono/zod-validator' import { zValidator } from '@hono/zod-validator'
import { prisma } from '@/db' import { prisma } from '@shumai/db'
import { authzService, Permission, ResourceType } from '@/services/authz/authz' import { authzService, Permission, ResourceType } from '@shumai/core/src/authz/authz'
import { assetService } from '@/services/asset/asset' import { assetService } from '@shumai/core/src/asset/asset'
import { metadataService } from '@/services/metadata/metadata' import { metadataService } from '@shumai/core/src/metadata/metadata'
import { notificationService } from '@/services/notification/notification' import { notificationService } from '@shumai/core/src/notification/notification'
import { s3Service } from '@/services/s3/s3' import { s3Service } from '@shumai/core/src/s3/s3'
import { import {
updateFileRequestSchema, updateFileRequestSchema,
updateAssetOrderRequestSchema, updateAssetOrderRequestSchema,
@@ -13,12 +13,12 @@ import {
restoreFilesRequestSchema, restoreFilesRequestSchema,
createCommentRequestSchema, createCommentRequestSchema,
uploadFileRequestSchema, uploadFileRequestSchema,
} from '@/dtos/asset' } from '@shumai/dtos'
import { updateAssetMetadataRequestSchema } from '@/dtos/metadata' import { updateAssetMetadataRequestSchema } from '@shumai/dtos'
import { paginationParamsSchema } from '@/dtos/pagination' import { paginationParamsSchema } from '@shumai/dtos'
import { ulid } from 'ulid' import { ulid } from 'ulid'
import { z } from 'zod' import { z } from 'zod'
import type { Prisma } from '@/generated/prisma/client' import type { Prisma } from '@shumai/db'
type User = Prisma.UserGetPayload<Record<string, never>> type User = Prisma.UserGetPayload<Record<string, never>>
@@ -1,12 +1,12 @@
import { describe, expect, it, vi, beforeEach, afterEach } from 'vitest' import { describe, expect, it, vi, beforeEach, afterEach } from 'vitest'
import { Hono } from 'hono' import { Hono } from 'hono'
import folderRoute from './folder' import folderRoute from './folder'
import { assetService } from '@/services/asset/asset' import { assetService } from '@shumai/core/src/asset/asset'
import { searchService } from '@/services/search/search' import { searchService } from '@shumai/core/src/search/search'
import { authzService, ResourceType, Permission } from '@/services/authz/authz' import { authzService, ResourceType, Permission } from '@shumai/core/src/authz/authz'
import { authMiddleware } from '@/api/middleware/auth' import { authMiddleware } from './middleware/auth'
vi.mock('@/services/authz/authz', () => ({ vi.mock('@shumai/core/src/authz/authz', () => ({
authzService: { authzService: {
hasPermission: vi.fn().mockResolvedValue(undefined), hasPermission: vi.fn().mockResolvedValue(undefined),
}, },
@@ -20,7 +20,7 @@ vi.mock('@/services/authz/authz', () => ({
}, },
})) }))
vi.mock('@/api/middleware/auth', () => ({ vi.mock('./middleware/auth', () => ({
// eslint-disable-next-line @typescript-eslint/no-explicit-any // eslint-disable-next-line @typescript-eslint/no-explicit-any
authMiddleware: async (c: any, next: any) => { authMiddleware: async (c: any, next: any) => {
c.set('user', { id: 'user1', name: 'Test User' }) c.set('user', { id: 'user1', name: 'Test User' })
@@ -1,17 +1,17 @@
import { Hono } from 'hono' import { Hono } from 'hono'
import { zValidator } from '@hono/zod-validator' import { zValidator } from '@hono/zod-validator'
import { authzService, Permission, ResourceType } from '@/services/authz/authz' import { authzService, Permission, ResourceType } from '@shumai/core/src/authz/authz'
import { assetService } from '@/services/asset/asset' import { assetService } from '@shumai/core/src/asset/asset'
import { searchService } from '@/services/search/search' import { searchService } from '@shumai/core/src/search/search'
import { import {
createFolderRequestSchema, createFolderRequestSchema,
updateFolderRequestSchema, updateFolderRequestSchema,
deleteFoldersRequestSchema, deleteFoldersRequestSchema,
restoreFoldersRequestSchema, restoreFoldersRequestSchema,
} from '@/dtos/folder' } from '@shumai/dtos'
import { listChildrenRequestSchema, updateAssetOrderRequestSchema } from '@/dtos/asset' import { listChildrenRequestSchema, updateAssetOrderRequestSchema } from '@shumai/dtos'
import { searchRequestSchema } from '@/dtos/search' import { searchRequestSchema } from '@shumai/dtos'
import type { Prisma } from '@/generated/prisma/client' import type { Prisma } from '@shumai/db'
type User = Prisma.UserGetPayload<Record<string, never>> type User = Prisma.UserGetPayload<Record<string, never>>
@@ -2,15 +2,15 @@ import { describe, expect, it, vi, beforeEach } from 'vitest'
import { Hono, type Context, type Next } from 'hono' import { Hono, type Context, type Next } from 'hono'
import inviteRoute from './invite' import inviteRoute from './invite'
import publicInviteRoute from './public-invite' import publicInviteRoute from './public-invite'
import { authzService, Permission, ResourceType } from '@/services/authz/authz' import { authzService, Permission, ResourceType } from '@shumai/core/src/authz/authz'
import { inviteService } from '@/services/invite/invite' import { inviteService } from '@shumai/core/src/invite/invite'
import { notificationService } from '@/services/notification/notification' import { notificationService } from '@shumai/core/src/notification/notification'
vi.mock('@/services/invite/invite') vi.mock('@shumai/core/src/invite/invite')
vi.mock('@/services/notification/notification') vi.mock('@shumai/core/src/notification/notification')
vi.mock('@/services/authz/authz') vi.mock('@shumai/core/src/authz/authz')
vi.mock('@/api/middleware/auth', () => ({ vi.mock('./middleware/auth', () => ({
authMiddleware: async ( authMiddleware: async (
c: Context<{ Variables: { user: { id: string; name: string } } }>, c: Context<{ Variables: { user: { id: string; name: string } } }>,
next: Next, next: Next,
@@ -5,12 +5,12 @@ import {
createTeamInviteRequestSchema, createTeamInviteRequestSchema,
joinRequestSchema, joinRequestSchema,
InviteInfo, InviteInfo,
} from '@/dtos/invite' } from '@shumai/dtos'
import { authzService, Permission, ResourceType } from '@/services/authz/authz' import { authzService, Permission, ResourceType } from '@shumai/core/src/authz/authz'
import { inviteService } from '@/services/invite/invite' import { inviteService } from '@shumai/core/src/invite/invite'
import { notificationService } from '@/services/notification/notification' import { notificationService } from '@shumai/core/src/notification/notification'
import { NotificationType } from '@/generated/prisma/client' import { NotificationType } from '@shumai/db'
import type { Prisma } from '@/generated/prisma/client' import type { Prisma } from '@shumai/db'
type User = Prisma.UserGetPayload<Record<string, never>> type User = Prisma.UserGetPayload<Record<string, never>>
@@ -1,10 +1,10 @@
import { describe, expect, it, vi, beforeEach } from 'vitest' import { describe, expect, it, vi, beforeEach } from 'vitest'
import { Hono, type Context, type Next } from 'hono' import { Hono, type Context, type Next } from 'hono'
import metadataRoute from './metadata' import metadataRoute from './metadata'
import { metadataService } from '@/services/metadata/metadata' import { metadataService } from '@shumai/core/src/metadata/metadata'
import { authzService, Permission, ResourceType } from '@/services/authz/authz' import { authzService, Permission, ResourceType } from '@shumai/core/src/authz/authz'
vi.mock('@/api/middleware/auth', () => ({ vi.mock('./middleware/auth', () => ({
authMiddleware: async ( authMiddleware: async (
c: Context<{ Variables: { user: { id: string; name: string } } }>, c: Context<{ Variables: { user: { id: string; name: string } } }>,
next: Next, next: Next,
@@ -14,8 +14,8 @@ vi.mock('@/api/middleware/auth', () => ({
}, },
})) }))
vi.mock('@/services/authz/authz') vi.mock('@shumai/core/src/authz/authz')
vi.mock('@/services/metadata/metadata') vi.mock('@shumai/core/src/metadata/metadata')
describe('metadata api', () => { describe('metadata api', () => {
const app = new Hono<{ Variables: { user: { id: string; name: string } } }>() const app = new Hono<{ Variables: { user: { id: string; name: string } } }>()
@@ -1,14 +1,14 @@
import { zValidator } from '@hono/zod-validator' import { zValidator } from '@hono/zod-validator'
import { Hono } from 'hono' import { Hono } from 'hono'
import { metadataService } from '@/services/metadata/metadata' import { metadataService } from '@shumai/core/src/metadata/metadata'
import { authzService, Permission, ResourceType } from '@/services/authz/authz' import { authzService, Permission, ResourceType } from '@shumai/core/src/authz/authz'
import { import {
createFieldRequestSchema, createFieldRequestSchema,
updateFieldRequestSchema, updateFieldRequestSchema,
updateProjectFieldsOrderRequestSchema, updateProjectFieldsOrderRequestSchema,
FieldInfo, FieldInfo,
} from '@/dtos/metadata' } from '@shumai/dtos'
import type { Prisma } from '@/generated/prisma/client' import type { Prisma } from '@shumai/db'
type User = Prisma.UserGetPayload<Record<string, never>> type User = Prisma.UserGetPayload<Record<string, never>>
@@ -1,6 +1,6 @@
import type { Prisma } from '@/generated/prisma/client' import type { Prisma } from '@shumai/db'
import { auth } from '@/services/auth/auth' import { auth } from '@shumai/core/src/auth/auth'
import { prisma } from '@/db' import { prisma } from '@shumai/db'
import { createMiddleware } from 'hono/factory' import { createMiddleware } from 'hono/factory'
type User = Prisma.UserGetPayload<Record<string, never>> type User = Prisma.UserGetPayload<Record<string, never>>
@@ -1,11 +1,11 @@
import { describe, expect, it, vi, beforeEach } from 'vitest' import { describe, expect, it, vi, beforeEach } from 'vitest'
import { Hono, type Context, type Next } from 'hono' import { Hono, type Context, type Next } from 'hono'
import notificationRoute from './notification' import notificationRoute from './notification'
import { notificationService } from '@/services/notification/notification' import { notificationService } from '@shumai/core/src/notification/notification'
import { authzService, Permission, ResourceType } from '@/services/authz/authz' import { authzService, Permission, ResourceType } from '@shumai/core/src/authz/authz'
import { userMetadataService } from '@/services/user-metadata/user-metadata' import { userMetadataService } from '@shumai/core/src/user-metadata/user-metadata'
vi.mock('@/api/middleware/auth', () => ({ vi.mock('./middleware/auth', () => ({
authMiddleware: async ( authMiddleware: async (
c: Context<{ Variables: { user: { id: string; name: string } } }>, c: Context<{ Variables: { user: { id: string; name: string } } }>,
next: Next, next: Next,
@@ -15,9 +15,9 @@ vi.mock('@/api/middleware/auth', () => ({
}, },
})) }))
vi.mock('@/services/authz/authz') vi.mock('@shumai/core/src/authz/authz')
vi.mock('@/services/notification/notification') vi.mock('@shumai/core/src/notification/notification')
vi.mock('@/services/user-metadata/user-metadata') vi.mock('@shumai/core/src/user-metadata/user-metadata')
describe('notification api', () => { describe('notification api', () => {
const app = new Hono<{ Variables: { user: { id: string; name: string } } }>() const app = new Hono<{ Variables: { user: { id: string; name: string } } }>()
@@ -1,14 +1,14 @@
import { zValidator } from '@hono/zod-validator' import { zValidator } from '@hono/zod-validator'
import { Hono } from 'hono' import { Hono } from 'hono'
import { notificationService } from '@/services/notification/notification' import { notificationService } from '@shumai/core/src/notification/notification'
import { authzService, Permission, ResourceType } from '@/services/authz/authz' import { authzService, Permission, ResourceType } from '@shumai/core/src/authz/authz'
import { import {
listNotificationsRequestSchema, listNotificationsRequestSchema,
markNotificationReadRequestSchema, markNotificationReadRequestSchema,
notificationSettingsSchema, notificationSettingsSchema,
} from '@/dtos/notification' } from '@shumai/dtos'
import { userMetadataService } from '@/services/user-metadata/user-metadata' import { userMetadataService } from '@shumai/core/src/user-metadata/user-metadata'
import type { Prisma } from '@/generated/prisma/client' import type { Prisma } from '@shumai/db'
type User = Prisma.UserGetPayload<Record<string, never>> type User = Prisma.UserGetPayload<Record<string, never>>
@@ -1,11 +1,11 @@
import { describe, expect, it, vi, beforeEach } from 'vitest' import { describe, expect, it, vi, beforeEach } from 'vitest'
import { Hono, type Context, type Next } from 'hono' import { Hono, type Context, type Next } from 'hono'
import projectRoute from './project' import projectRoute from './project'
import { authzService, Permission, ResourceType } from '@/services/authz/authz' import { authzService, Permission, ResourceType } from '@shumai/core/src/authz/authz'
import { projectService } from '@/services/project/project' import { projectService } from '@shumai/core/src/project/project'
import { assetService } from '@/services/asset/asset' import { assetService } from '@shumai/core/src/asset/asset'
vi.mock('@/api/middleware/auth', () => ({ vi.mock('./middleware/auth', () => ({
authMiddleware: async ( authMiddleware: async (
c: Context<{ Variables: { user: { id: string; name: string } } }>, c: Context<{ Variables: { user: { id: string; name: string } } }>,
next: Next, next: Next,
@@ -15,9 +15,9 @@ vi.mock('@/api/middleware/auth', () => ({
}, },
})) }))
vi.mock('@/services/authz/authz') vi.mock('@shumai/core/src/authz/authz')
vi.mock('@/services/project/project') vi.mock('@shumai/core/src/project/project')
vi.mock('@/services/asset/asset') vi.mock('@shumai/core/src/asset/asset')
describe('project api', () => { describe('project api', () => {
const app = new Hono<{ Variables: { user: { id: string; name: string } } }>() const app = new Hono<{ Variables: { user: { id: string; name: string } } }>()
@@ -1,17 +1,17 @@
import { Hono } from 'hono' import { Hono } from 'hono'
import { zValidator } from '@hono/zod-validator' import { zValidator } from '@hono/zod-validator'
import { authzService, Permission, ResourceType } from '@/services/authz/authz' import { authzService, Permission, ResourceType } from '@shumai/core/src/authz/authz'
import { projectService } from '@/services/project/project' import { projectService } from '@shumai/core/src/project/project'
import { assetService } from '@/services/asset/asset' import { assetService } from '@shumai/core/src/asset/asset'
import { reparentAssetsRequestSchema, copyAssetsRequestSchema } from '@/dtos/asset' import { reparentAssetsRequestSchema, copyAssetsRequestSchema } from '@shumai/dtos'
import { import {
createProjectRequestSchema, createProjectRequestSchema,
updateProjectRequestSchema, updateProjectRequestSchema,
listProjectsRequestSchema, listProjectsRequestSchema,
recentlyDeletedRequestSchema, recentlyDeletedRequestSchema,
} from '@/dtos/project' } from '@shumai/dtos'
import { listMembersQuerySchema } from '@/dtos/team' import { listMembersQuerySchema } from '@shumai/dtos'
import type { Prisma } from '@/generated/prisma/client' import type { Prisma } from '@shumai/db'
type User = Prisma.UserGetPayload<Record<string, never>> type User = Prisma.UserGetPayload<Record<string, never>>
@@ -1,10 +1,10 @@
import { describe, expect, it, vi, beforeEach } from 'vitest' import { describe, expect, it, vi, beforeEach } from 'vitest'
import { Hono, type Context, type Next } from 'hono' import { Hono, type Context, type Next } from 'hono'
import providerRoute from './provider' import providerRoute from './provider'
import { providerService } from '@/services/provider/provider' import { providerService } from '@shumai/core/src/provider/provider'
import { authzService, Permission, ResourceType } from '@/services/authz/authz' import { authzService, Permission, ResourceType } from '@shumai/core/src/authz/authz'
vi.mock('@/api/middleware/auth', () => ({ vi.mock('./middleware/auth', () => ({
authMiddleware: async ( authMiddleware: async (
c: Context<{ Variables: { user: { id: string; name: string } } }>, c: Context<{ Variables: { user: { id: string; name: string } } }>,
next: Next, next: Next,
@@ -14,8 +14,8 @@ vi.mock('@/api/middleware/auth', () => ({
}, },
})) }))
vi.mock('@/services/authz/authz') vi.mock('@shumai/core/src/authz/authz')
vi.mock('@/services/provider/provider') vi.mock('@shumai/core/src/provider/provider')
describe('provider api', () => { describe('provider api', () => {
const app = new Hono<{ Variables: { user: { id: string; name: string } } }>() const app = new Hono<{ Variables: { user: { id: string; name: string } } }>()
@@ -1,9 +1,9 @@
import { zValidator } from '@hono/zod-validator' import { zValidator } from '@hono/zod-validator'
import { Hono } from 'hono' import { Hono } from 'hono'
import { authzService, Permission, ResourceType } from '@/services/authz/authz' import { authzService, Permission, ResourceType } from '@shumai/core/src/authz/authz'
import { providerService } from '@/services/provider/provider' import { providerService } from '@shumai/core/src/provider/provider'
import { createProviderRequestSchema, updateProviderRequestSchema } from '@/dtos/provider' import { createProviderRequestSchema, updateProviderRequestSchema } from '@shumai/dtos'
import type { Prisma } from '@/generated/prisma/client' import type { Prisma } from '@shumai/db'
type User = Prisma.UserGetPayload<Record<string, never>> type User = Prisma.UserGetPayload<Record<string, never>>
@@ -1,6 +1,6 @@
import { Hono } from 'hono' import { Hono } from 'hono'
import { inviteService } from '@/services/invite/invite' import { inviteService } from '@shumai/core/src/invite/invite'
import { InviteInfo } from '@/dtos/invite' import { InviteInfo } from '@shumai/dtos'
const app = new Hono() const app = new Hono()
@@ -1,16 +1,16 @@
import { Hono } from 'hono' import { Hono } from 'hono'
import { zValidator } from '@hono/zod-validator' import { zValidator } from '@hono/zod-validator'
import { shareService } from '@/services/share/share' import { shareService } from '@shumai/core/src/share/share'
import { assetService } from '@/services/asset/asset' import { assetService } from '@shumai/core/src/asset/asset'
import { paginationParamsSchema } from '@/dtos/pagination' import { paginationParamsSchema } from '@shumai/dtos'
import { z } from 'zod' import { z } from 'zod'
import { metadataService } from '@/services/metadata/metadata' import { metadataService } from '@shumai/core/src/metadata/metadata'
import { FieldInfo } from '@/dtos/metadata' import { FieldInfo } from '@shumai/dtos'
import type { Prisma as PrismaType } from '@/generated/prisma/client' import type { Prisma as PrismaType } from '@shumai/db'
import { auth } from '@/services/auth/auth' import { auth } from '@shumai/core/src/auth/auth'
import { prisma } from '@/db' import { prisma } from '@shumai/db'
import { createCommentRequestSchema } from '@/dtos/asset' import { createCommentRequestSchema } from '@shumai/dtos'
import { notificationService } from '@/services/notification/notification' import { notificationService } from '@shumai/core/src/notification/notification'
const app = new Hono() const app = new Hono()
@@ -1,5 +1,5 @@
import { describe, it, expect, vi, beforeEach } from 'vitest' import { describe, it, expect, vi, beforeEach } from 'vitest'
import { s3Service } from '@/services/s3/s3' import { s3Service } from '@shumai/core/src/s3/s3'
import { Hono } from 'hono' import { Hono } from 'hono'
const { mockServeStatic } = vi.hoisted(() => ({ const { mockServeStatic } = vi.hoisted(() => ({
+1 -1
View File
@@ -1,5 +1,5 @@
import { Hono } from 'hono' import { Hono } from 'hono'
import { s3Service } from '@/services/s3/s3' import { s3Service } from '@shumai/core/src/s3/s3'
import { serveStatic } from 'hono/bun' import { serveStatic } from 'hono/bun'
const route = new Hono() const route = new Hono()
@@ -2,12 +2,12 @@ import { describe, expect, test, vi, beforeEach } from 'vitest'
import { Hono } from 'hono' import { Hono } from 'hono'
import shareRoute from './share' import shareRoute from './share'
import publicShareRoute from './public-share' import publicShareRoute from './public-share'
import { authMiddleware } from '@/api/middleware/auth' import { authMiddleware } from './middleware/auth'
import { shareService } from '@/services/share/share' import { shareService } from '@shumai/core/src/share/share'
import { assetService } from '@/services/asset/asset' import { assetService } from '@shumai/core/src/asset/asset'
import { authzService, Permission, ResourceType } from '@/services/authz/authz' import { authzService, Permission, ResourceType } from '@shumai/core/src/authz/authz'
vi.mock('@/api/middleware/auth', () => ({ vi.mock('./middleware/auth', () => ({
// eslint-disable-next-line @typescript-eslint/no-explicit-any // eslint-disable-next-line @typescript-eslint/no-explicit-any
authMiddleware: async (c: any, next: any) => { authMiddleware: async (c: any, next: any) => {
// eslint-disable-next-line @typescript-eslint/no-explicit-any // eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -16,7 +16,7 @@ vi.mock('@/api/middleware/auth', () => ({
}, },
})) }))
vi.mock('@/services/authz/authz', () => ({ vi.mock('@shumai/core/src/authz/authz', () => ({
authzService: { authzService: {
hasPermission: vi.fn().mockResolvedValue(undefined), hasPermission: vi.fn().mockResolvedValue(undefined),
}, },
@@ -1,14 +1,14 @@
import { Hono } from 'hono' import { Hono } from 'hono'
import { zValidator } from '@hono/zod-validator' import { zValidator } from '@hono/zod-validator'
import { authzService, Permission, ResourceType } from '@/services/authz/authz' import { authzService, Permission, ResourceType } from '@shumai/core/src/authz/authz'
import { shareService } from '@/services/share/share' import { shareService } from '@shumai/core/src/share/share'
import { import {
createShareLinkRequestSchema, createShareLinkRequestSchema,
updateShareLinkRequestSchema, updateShareLinkRequestSchema,
listShareLinksRequestSchema, listShareLinksRequestSchema,
addAssetToShareRequestSchema, addAssetToShareRequestSchema,
} from '@/dtos/share' } from '@shumai/dtos'
import type { Prisma } from '@/generated/prisma/client' import type { Prisma } from '@shumai/db'
type User = Prisma.UserGetPayload<Record<string, never>> type User = Prisma.UserGetPayload<Record<string, never>>
@@ -1,11 +1,11 @@
import { describe, expect, test, vi, beforeEach } from 'vitest' import { describe, expect, test, vi, beforeEach } from 'vitest'
import { Hono } from 'hono' import { Hono } from 'hono'
import skillRoute from './skill' import skillRoute from './skill'
import { skillService } from '@/services/skill/skill' import { skillService } from '@shumai/core/src/skill/skill'
import { authMiddleware } from '@/api/middleware/auth' import { authMiddleware } from './middleware/auth'
import { authzService, ResourceType, Permission } from '@/services/authz/authz' import { authzService, ResourceType, Permission } from '@shumai/core/src/authz/authz'
vi.mock('@/api/middleware/auth', () => ({ vi.mock('./middleware/auth', () => ({
// eslint-disable-next-line @typescript-eslint/no-explicit-any // eslint-disable-next-line @typescript-eslint/no-explicit-any
authMiddleware: async (c: any, next: any) => { authMiddleware: async (c: any, next: any) => {
// eslint-disable-next-line @typescript-eslint/no-explicit-any // eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -14,7 +14,7 @@ vi.mock('@/api/middleware/auth', () => ({
}, },
})) }))
vi.mock('@/services/authz/authz', () => ({ vi.mock('@shumai/core/src/authz/authz', () => ({
authzService: { authzService: {
hasPermission: vi.fn().mockResolvedValue(undefined), hasPermission: vi.fn().mockResolvedValue(undefined),
}, },
@@ -1,9 +1,9 @@
import { Hono } from 'hono' import { Hono } from 'hono'
import { zValidator } from '@hono/zod-validator' import { zValidator } from '@hono/zod-validator'
import { authzService, Permission, ResourceType } from '@/services/authz/authz' import { authzService, Permission, ResourceType } from '@shumai/core/src/authz/authz'
import { skillService } from '@/services/skill/skill' import { skillService } from '@shumai/core/src/skill/skill'
import { upsertSkillRequestSchema, updateSkillConfigRequestSchema } from '@/dtos/skill' import { upsertSkillRequestSchema, updateSkillConfigRequestSchema } from '@shumai/dtos'
import type { Prisma } from '@/generated/prisma/client' import type { Prisma } from '@shumai/db'
type User = Prisma.UserGetPayload<Record<string, never>> type User = Prisma.UserGetPayload<Record<string, never>>
@@ -1,13 +1,13 @@
import { describe, expect, it, vi, beforeEach, afterEach } from 'vitest' import { describe, expect, it, vi, beforeEach, afterEach } from 'vitest'
import { Hono } from 'hono' import { Hono } from 'hono'
import teamRoute from './team' import teamRoute from './team'
import { authMiddleware } from '@/api/middleware/auth' import { authMiddleware } from './middleware/auth'
import { teamService } from '@/services/team/team' import { teamService } from '@shumai/core/src/team/team'
import { userMetadataService } from '@/services/user-metadata/user-metadata' import { userMetadataService } from '@shumai/core/src/user-metadata/user-metadata'
import { notificationService } from '@/services/notification/notification' import { notificationService } from '@shumai/core/src/notification/notification'
import { authzService, ResourceType, Permission } from '@/services/authz/authz' import { authzService, ResourceType, Permission } from '@shumai/core/src/authz/authz'
vi.mock('@/services/authz/authz', () => ({ vi.mock('@shumai/core/src/authz/authz', () => ({
authzService: { authzService: {
hasPermission: vi.fn().mockResolvedValue(undefined), hasPermission: vi.fn().mockResolvedValue(undefined),
}, },
@@ -21,7 +21,7 @@ vi.mock('@/services/authz/authz', () => ({
}, },
})) }))
vi.mock('@/api/middleware/auth', () => ({ vi.mock('./middleware/auth', () => ({
// eslint-disable-next-line @typescript-eslint/no-explicit-any // eslint-disable-next-line @typescript-eslint/no-explicit-any
authMiddleware: async (c: any, next: any) => { authMiddleware: async (c: any, next: any) => {
c.set('user', { id: 'user1', name: 'Test User' }) c.set('user', { id: 'user1', name: 'Test User' })
@@ -1,19 +1,19 @@
import { Hono } from 'hono' import { Hono } from 'hono'
import { zValidator } from '@hono/zod-validator' import { zValidator } from '@hono/zod-validator'
import { authzService, Permission, ResourceType } from '@/services/authz/authz' import { authzService, Permission, ResourceType } from '@shumai/core/src/authz/authz'
import { teamService } from '@/services/team/team' import { teamService } from '@shumai/core/src/team/team'
import { userMetadataService } from '@/services/user-metadata/user-metadata' import { userMetadataService } from '@shumai/core/src/user-metadata/user-metadata'
import { notificationService } from '@/services/notification/notification' import { notificationService } from '@shumai/core/src/notification/notification'
import { NotificationType } from '@/generated/prisma/client' import { NotificationType } from '@shumai/db'
import { import {
createTeamRequestSchema, createTeamRequestSchema,
getUserTeamsRequestSchema, getUserTeamsRequestSchema,
updateTeamSettingsRequestSchema, updateTeamSettingsRequestSchema,
listMembersQuerySchema, listMembersQuerySchema,
updateSandboxSettingsRequestSchema, updateSandboxSettingsRequestSchema,
} from '@/dtos/team' } from '@shumai/dtos'
import { updateUserMetadataRequestSchema } from '@/dtos/user-metadata' import { updateUserMetadataRequestSchema } from '@shumai/dtos'
import type { Prisma } from '@/generated/prisma/client' import type { Prisma } from '@shumai/db'
type User = Prisma.UserGetPayload<Record<string, never>> type User = Prisma.UserGetPayload<Record<string, never>>
@@ -1,13 +1,13 @@
import { describe, expect, it, vi, beforeEach } from 'vitest' import { describe, expect, it, vi, beforeEach } from 'vitest'
import { Hono } from 'hono' import { Hono } from 'hono'
import uploadRoute from './upload' import uploadRoute from './upload'
import { authMiddleware } from '@/api/middleware/auth' import { authMiddleware } from './middleware/auth'
import { uploadService } from '@/services/upload/upload' import { uploadService } from '@shumai/core/src/upload/upload'
import type { CreateUploadTaskResponse, TaskInfo } from '@/dtos/upload' import type { CreateUploadTaskResponse, TaskInfo } from '@shumai/dtos'
import type { PaginatedData } from '@/services/pagination' import type { PaginatedData } from '@shumai/core/src/pagination'
import { authzService, ResourceType, Permission } from '@/services/authz/authz' import { authzService, ResourceType, Permission } from '@shumai/core/src/authz/authz'
vi.mock('@/api/middleware/auth', () => ({ vi.mock('./middleware/auth', () => ({
// We use any here because mocking Hono context and middleware // We use any here because mocking Hono context and middleware
// with full type safety is overly complex for these unit tests. // with full type safety is overly complex for these unit tests.
// eslint-disable-next-line @typescript-eslint/no-explicit-any // eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -18,7 +18,7 @@ vi.mock('@/api/middleware/auth', () => ({
}, },
})) }))
vi.mock('@/services/authz/authz', () => ({ vi.mock('@shumai/core/src/authz/authz', () => ({
authzService: { authzService: {
hasPermission: vi.fn().mockResolvedValue(undefined), hasPermission: vi.fn().mockResolvedValue(undefined),
}, },
@@ -33,7 +33,7 @@ vi.mock('@/services/authz/authz', () => ({
}, },
})) }))
vi.mock('@/services/notification/notification', () => ({ vi.mock('@shumai/core/src/notification/notification', () => ({
notificationService: { notificationService: {
create: vi.fn().mockResolvedValue(undefined), create: vi.fn().mockResolvedValue(undefined),
}, },
@@ -1,17 +1,17 @@
import { Hono } from 'hono' import { Hono } from 'hono'
import { zValidator } from '@hono/zod-validator' import { zValidator } from '@hono/zod-validator'
import { uploadService } from '@/services/upload/upload' import { uploadService } from '@shumai/core/src/upload/upload'
import { import {
confirmFileUploadRequestSchema, confirmFileUploadRequestSchema,
createUploadTaskRequestSchema, createUploadTaskRequestSchema,
localUploadQuerySchema, localUploadQuerySchema,
} from '@/dtos/upload' } from '@shumai/dtos'
import { paginationParamsSchema } from '@/dtos/pagination' import { paginationParamsSchema } from '@shumai/dtos'
import { authzService, Permission, ResourceType } from '@/services/authz/authz' import { authzService, Permission, ResourceType } from '@shumai/core/src/authz/authz'
import { notificationService } from '@/services/notification/notification' import { notificationService } from '@shumai/core/src/notification/notification'
import { NotificationType } from '@/generated/prisma/client' import { NotificationType } from '@shumai/db'
import { s3Service, verifyLocalUrlSignature } from '@/services/s3/s3' import { s3Service, verifyLocalUrlSignature } from '@shumai/core/src/s3/s3'
import type { Prisma } from '@/generated/prisma/client' import type { Prisma } from '@shumai/db'
type User = Prisma.UserGetPayload<Record<string, never>> type User = Prisma.UserGetPayload<Record<string, never>>
@@ -1,12 +1,12 @@
import { describe, expect, it, vi, beforeEach, afterEach } from 'vitest' import { describe, expect, it, vi, beforeEach, afterEach } from 'vitest'
import { Hono } from 'hono' import { Hono } from 'hono'
import versionStackRoute from './versionStack' import versionStackRoute from './versionStack'
import { authMiddleware } from '@/api/middleware/auth' import { authMiddleware } from './middleware/auth'
import { versionStackService } from '@/services/versionStack/versionStack' import { versionStackService } from '@shumai/core/src/versionStack/versionStack'
import { assetService } from '@/services/asset/asset' import { assetService } from '@shumai/core/src/asset/asset'
import { authzService, ResourceType, Permission } from '@/services/authz/authz' import { authzService, ResourceType, Permission } from '@shumai/core/src/authz/authz'
vi.mock('@/services/authz/authz', () => ({ vi.mock('@shumai/core/src/authz/authz', () => ({
authzService: { authzService: {
hasPermission: vi.fn().mockResolvedValue(undefined), hasPermission: vi.fn().mockResolvedValue(undefined),
}, },
@@ -21,7 +21,7 @@ vi.mock('@/services/authz/authz', () => ({
}, },
})) }))
vi.mock('@/api/middleware/auth', () => ({ vi.mock('./middleware/auth', () => ({
// eslint-disable-next-line @typescript-eslint/no-explicit-any // eslint-disable-next-line @typescript-eslint/no-explicit-any
authMiddleware: async (c: any, next: any) => { authMiddleware: async (c: any, next: any) => {
c.set('user', { id: 'user1', name: 'Test User' }) c.set('user', { id: 'user1', name: 'Test User' })
@@ -1,13 +1,10 @@
import { Hono } from 'hono' import { Hono } from 'hono'
import { zValidator } from '@hono/zod-validator' import { zValidator } from '@hono/zod-validator'
import { versionStackService } from '@/services/versionStack/versionStack' import { versionStackService } from '@shumai/core/src/versionStack/versionStack'
import { assetService } from '@/services/asset/asset' import { assetService } from '@shumai/core/src/asset/asset'
import { authzService, Permission, ResourceType } from '@/services/authz/authz' import { authzService, Permission, ResourceType } from '@shumai/core/src/authz/authz'
import { import { createVersionStackRequestSchema, changeStackFileVersionRequestSchema } from '@shumai/dtos'
createVersionStackRequestSchema, import type { Prisma } from '@shumai/db'
changeStackFileVersionRequestSchema,
} from '@/dtos/versionStack'
import type { Prisma } from '@/generated/prisma/client'
type User = Prisma.UserGetPayload<Record<string, never>> type User = Prisma.UserGetPayload<Record<string, never>>
+59
View File
@@ -0,0 +1,59 @@
import type { Prisma } from '@shumai/db'
import { Hono } from 'hono'
import agentRoute from './api/agent'
import attachmentRoute from './api/attachment'
import authnRoute from './api/authn'
import collectionRoute from './api/collection'
import fileRoute from './api/file'
import folderRoute from './api/folder'
import inviteRoute from './api/invite'
import metadataRoute from './api/metadata'
import { authMiddleware } from './api/middleware/auth'
import notificationRoute from './api/notification'
import projectRoute from './api/project'
import providerRoute from './api/provider'
import publicInviteRoute from './api/public-invite'
import publicShareRoute from './api/public-share'
import s3Route from './api/s3'
import shareRoute from './api/share'
import skillRoute from './api/skill'
import teamRoute from './api/team'
import uploadRoute from './api/upload'
import versionStackRoute from './api/versionStack'
type User = Prisma.UserGetPayload<Record<string, never>>
export const app = new Hono()
const apiRoute = new Hono<{ Variables: { user: User } }>()
// Public Routes
.route('/', authnRoute)
.route('/', publicInviteRoute)
.route('/', publicShareRoute)
// Protected Routes
.use('*', authMiddleware)
.route('/', inviteRoute)
.route('/', providerRoute)
.route('/', notificationRoute)
.route('/', metadataRoute)
.route('/', projectRoute)
.route('/', collectionRoute)
.route('/', teamRoute)
.route('/', versionStackRoute)
.route('/', fileRoute)
.route('/', folderRoute)
.route('/', agentRoute)
.route('/', attachmentRoute)
.route('/', uploadRoute)
.route('/', shareRoute)
.route('/', skillRoute)
app.route('/files', s3Route)
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const apiAppRoute = app.route('/api', apiRoute)
export type AppType = typeof apiAppRoute
export default app
+7
View File
@@ -0,0 +1,7 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"ignoreDeprecations": "6.0"
},
"include": ["src/**/*"]
}
+32
View File
@@ -0,0 +1,32 @@
{
"name": "@shumai/core",
"version": "0.1.0",
"private": true,
"type": "module",
"main": "./src/index.ts",
"types": "./src/index.ts",
"dependencies": {
"@shumai/db": "workspace:*",
"@shumai/dtos": "workspace:*",
"@aws-sdk/client-s3": "^3.1031.0",
"@aws-sdk/s3-request-presigner": "^3.1031.0",
"@sinclair/typebox": "^0.34.49",
"adm-zip": "^0.5.17",
"better-auth": "1.6.11",
"date-fns": "^4.4.0",
"dotenv": "^16.4.7",
"dotenv-expand": "^13.0.0",
"extract-zip": "^2.0.1",
"jittered-fractional-indexing": "^1.0.1",
"pino": "^10.3.1",
"tweetnacl": "^1.0.3",
"ulid": "^3.0.2",
"yaml": "^2.7.0",
"hono": "^4.12.14",
"zod": "^4.4.3"
},
"devDependencies": {
"@types/adm-zip": "^0.5.8",
"@types/extract-zip": "^2.0.3"
}
}
@@ -1,7 +1,7 @@
import { describe, expect, test } from 'vitest' import { describe, expect, test } from 'vitest'
import { AgentService } from './agent' import { AgentService } from './agent'
import { prisma } from '@/db' import { prisma } from '@shumai/db'
import { setupTestDbHooks } from '@/db-test-hooks' import { setupTestDbHooks } from '@shumai/db/test'
describe('AgentService', () => { describe('AgentService', () => {
setupTestDbHooks() setupTestDbHooks()
@@ -1,12 +1,12 @@
import { prisma } from '@/db' import { prisma } from '@shumai/db'
import { import {
CreateAgentParams, CreateAgentParams,
DeleteAgentParams, DeleteAgentParams,
ListAgentsParams, ListAgentsParams,
UpdateAgentParams, UpdateAgentParams,
} from '@/dtos/agent' } from '@shumai/dtos'
import '@/prisma-json-types' import '@shumai/db/src/prisma-json-types'
import { s3Service } from '@/services/s3/s3' import { s3Service } from '@shumai/core/src/s3/s3'
import AdmZip from 'adm-zip' import AdmZip from 'adm-zip'
import * as fs from 'fs' import * as fs from 'fs'
import * as path from 'path' import * as path from 'path'
@@ -1,11 +1,11 @@
import { describe, expect, it, vi, beforeEach, afterEach } from 'vitest' import { describe, expect, it, vi, beforeEach, afterEach } from 'vitest'
import { prisma } from '@/db' import { prisma } from '@shumai/db'
import { setupTestDbHooks } from '@/db-test-hooks' import { setupTestDbHooks } from '@shumai/db/test'
import { AssetType, AssetStatus, Prisma } from '@/generated/prisma/client.ts' import { AssetType, AssetStatus, Prisma } from '@shumai/db'
import { AssetService } from './asset' import { AssetService } from './asset'
vi.mock('@/services/s3/s3', () => ({ vi.mock('@shumai/core/src/s3/s3', () => ({
s3Service: { s3Service: {
presign: vi.fn().mockResolvedValue('http://mock-s3-url'), presign: vi.fn().mockResolvedValue('http://mock-s3-url'),
putObject: vi.fn().mockResolvedValue(undefined), putObject: vi.fn().mockResolvedValue(undefined),
@@ -1385,7 +1385,7 @@ describe('AssetService', () => {
describe('Asset Cascade Bug (Reproduction)', () => { describe('Asset Cascade Bug (Reproduction)', () => {
it('should NOT cascade delete children from DB before their S3 files are deleted', async () => { it('should NOT cascade delete children from DB before their S3 files are deleted', async () => {
const { project } = await setupBasicAssets() const { project } = await setupBasicAssets()
const { s3Service } = await import('@/services/s3/s3') const { s3Service } = await import('../s3/s3')
// 1. Create Folder A // 1. Create Folder A
const folderA = await prisma.asset.create({ const folderA = await prisma.asset.create({
@@ -1448,7 +1448,7 @@ describe('AssetService', () => {
it('should delete the entire directory prefix for assets with complex keys (e.g., file/ULID/raw)', async () => { it('should delete the entire directory prefix for assets with complex keys (e.g., file/ULID/raw)', async () => {
const { project } = await setupBasicAssets() const { project } = await setupBasicAssets()
const { s3Service } = await import('@/services/s3/s3') const { s3Service } = await import('../s3/s3')
// Create an asset with a complex key // Create an asset with a complex key
const complexFile = await prisma.asset.create({ const complexFile = await prisma.asset.create({
@@ -1,4 +1,4 @@
import { prisma } from '@/db' import { prisma } from '@shumai/db'
import { import {
AncestorFolder, AncestorFolder,
AssetInfo, AssetInfo,
@@ -15,12 +15,12 @@ import {
ReparentAssetsRequest, ReparentAssetsRequest,
UpdateAssetNameRequest, UpdateAssetNameRequest,
UpdateAssetOrderRequest, UpdateAssetOrderRequest,
UserInfo, AssetUserInfo,
} from '@/dtos/asset' } from '@shumai/dtos'
import { Asset, AssetStatus, AssetType, Prisma, StorageKey } from '@/generated/prisma/client.ts' import { type Asset, AssetStatus, AssetType, Prisma, type StorageKey } from '@shumai/db'
import { logger } from '@/logger' import { logger } from '@shumai/core/src/logger'
import { PaginatedData, paginateQuery, PaginationParams } from '@/services/pagination' import { PaginatedData, paginateQuery, PaginationParams } from '@shumai/core/src/pagination'
import { s3Service } from '@/services/s3/s3' import { s3Service } from '@shumai/core/src/s3/s3'
import { generateKeyBetween } from 'jittered-fractional-indexing' import { generateKeyBetween } from 'jittered-fractional-indexing'
type AssetWithIncludes = Prisma.AssetGetPayload<{ type AssetWithIncludes = Prisma.AssetGetPayload<{
@@ -1670,7 +1670,7 @@ export class AssetService {
} }
} }
const mentions: UserInfo[] = [] const mentions: AssetUserInfo[] = []
const botMentionMatch = (c.message || '').match(/<@([^>]+)>/g) const botMentionMatch = (c.message || '').match(/<@([^>]+)>/g)
if (botMentionMatch) { if (botMentionMatch) {
const userIds = botMentionMatch.map((m: string) => m.replace('<@', '').replace('>', '')) const userIds = botMentionMatch.map((m: string) => m.replace('<@', '').replace('>', ''))
@@ -1682,7 +1682,7 @@ export class AssetService {
} }
} }
const creator: UserInfo = { id: '', name: '' } const creator: AssetUserInfo = { id: '', name: '' }
if (c.sessionId) { if (c.sessionId) {
creator.id = c.creatorId || '' creator.id = c.creatorId || ''
creator.name = c.creator?.name || 'Ai Bot' creator.name = c.creator?.name || 'Ai Bot'
@@ -1,8 +1,8 @@
import { betterAuth } from 'better-auth' import { betterAuth } from 'better-auth'
import { prismaAdapter } from 'better-auth/adapters/prisma' import { prismaAdapter } from 'better-auth/adapters/prisma'
import { prisma } from '@/db' import { prisma } from '@shumai/db'
import { teamService } from '@/services/team/team' import { teamService } from '@shumai/core/src/team/team'
import { inviteService } from '@/services/invite/invite' import { inviteService } from '@shumai/core/src/invite/invite'
import { createAuthMiddleware } from 'better-auth/api' import { createAuthMiddleware } from 'better-auth/api'
export const auth = betterAuth({ export const auth = betterAuth({
@@ -1,8 +1,8 @@
import { setupTestDbHooks } from '@/db-test-hooks' import { setupTestDbHooks } from '@shumai/db/test'
import { describe, expect, it } from 'vitest' import { describe, expect, it } from 'vitest'
import { prisma } from '@/db' import { prisma } from '@shumai/db'
import { authzService, Permission, ResourceType } from '@/services/authz/authz' import { authzService, Permission, ResourceType } from '@shumai/core/src/authz/authz'
describe('AuthzService', () => { describe('AuthzService', () => {
setupTestDbHooks() setupTestDbHooks()
@@ -1,5 +1,5 @@
import { prisma } from '@/db' import { prisma } from '@shumai/db'
import type { Prisma } from '@/generated/prisma/client.ts' import type { Prisma } from '@shumai/db'
type User = Prisma.UserGetPayload<Record<string, never>> type User = Prisma.UserGetPayload<Record<string, never>>
export enum Permission { export enum Permission {
@@ -1,6 +1,6 @@
import { describe, it, expect } from 'vitest' import { describe, it, expect } from 'vitest'
import { prisma } from '@/db' import { prisma } from '@shumai/db'
import { setupTestDbHooks } from '@/db-test-hooks' import { setupTestDbHooks } from '@shumai/db/test'
import { collectionService } from './collection' import { collectionService } from './collection'
import { projectService } from '../project/project' import { projectService } from '../project/project'
@@ -1,10 +1,10 @@
import { prisma } from '@/db' import { prisma } from '@shumai/db'
import { paginateQuery } from '../pagination' import { paginateQuery } from '../pagination'
import { import {
CreateCollectionRequest, CreateCollectionRequest,
UpdateCollectionRequest, UpdateCollectionRequest,
ListCollectionsRequest, ListCollectionsRequest,
} from '@/dtos/collection' } from '@shumai/dtos'
export class CollectionService { export class CollectionService {
async createCollection(projectId: string, req: CreateCollectionRequest) { async createCollection(projectId: string, req: CreateCollectionRequest) {
File diff suppressed because it is too large Load Diff
+20
View File
@@ -0,0 +1,20 @@
export * from './agent/agent'
export * from './asset/asset'
export * from './auth/auth'
export * from './authz/authz'
export * from './collection/collection'
export * from './invite/invite'
export * from './metadata/metadata'
export * from './notification/notification'
export * from './project/project'
export * from './provider/provider'
export * from './s3/s3'
export * from './search/search'
export * from './share/share'
export * from './skill/skill'
export * from './team/team'
export * from './upload/upload'
export * from './user-metadata/user-metadata'
export * from './versionStack/versionStack'
export * from './hyrumtoken'
export * from './pagination'

Some files were not shown because too many files have changed in this diff Show More