Files
FastGPT/vitest.config.mts
Jon 4e7366f28e Add agent skills service (#6510)
* feat: Add agent skill management features and API endpoints

* feat: Add skill version management and SKILL.md utilities

* feat: Add skill import functionality with YAML frontmatter parsing

* feat: Add skill sandbox management and cleanup functionality

* feat: Add save and deploy functionality for skills

* feat: standardize skill package ZIP structure

- Enforce a standardized ZIP structure for skill packages where all files are contained within a root folder named after the skill.
- Implement `standardizeSkillPackage` utility to normalize ZIP archives during creation, import, and deployment.
- Transition sandbox operations to a dedicated `workDirectory` (/workspace/projects) for improved isolation.
- Enhance `SKILL.md` detection to support case-insensitivity and single-level subfolder locations.
- Update creation, import, and save-deploy APIs to maintain structural consistency across the skill lifecycle.
- Update test suites to verify the new folder-based standardized structure.

* feat: implement agent skill execution in session sandboxes

- Introduce a suite of sandbox tools (`sandbox_read_file`, `sandbox_write_file`, `sandbox_edit_file`, `sandbox_execute`, `sandbox_search`) for LLM-driven skill execution.
- Implement session-runtime sandbox lifecycle management, including automated skill deployment, standardization, and cleanup.
- Enhance the Master Agent decision system with a dedicated "Skill Execution Mode" and progressive disclosure of skill documentation via `SKILL.md` loading.
- Update the agent workflow dispatch to support dynamic sandbox initialization and prompt injection based on selected skill IDs.
- Refactor sandbox-related logging and ensure consistent buffer handling for skill packaging.

* feat: introduce AgentCapability abstraction and refactor sandbox infrastructure

- Add AgentCapability interface to decouple agent tool contributions from sandbox internals
- Implement SandboxSkillsCapability as first capability, replacing direct AgentSandboxContext usage
- Refactor dispatchRunAgent to aggregate capabilities (systemPrompt, tools, handlers, dispose)
- Add provider field to SandboxProviderConfig and buildDockerSyncEnv() for Docker runtime MinIO sync
- Restructure createEditDebugSandbox into three phases: config resolution, pre-flight, sandbox ops
- Add downloadSkillPackage and standardizeSkillPackage steps before sandbox creation
- Add useEditDebugSandbox input param to agent node for explicit sandbox mode selection
- Extend storage, sandboxSchema, versionSchema with supporting fields
- Add version controller tests

* feat: add sandboxStatus and skillCall SSE events for sandbox lifecycle

Provide real-time progress feedback during sandbox cold-start for
both session-runtime and edit-debug sandboxes via new SSE events.

- Add `sandboxStatus` and `skillCall` to SseResponseEventEnum
- Add SandboxStatusItemType, SandboxStatusPhase, SkillCallItemType types
- lifecycle.ts: accept onProgress callback, emit 7 lifecycle phases
- sandboxController.ts: accept onProgress callback, emit 5 lifecycle phases
- sandboxSkills.ts: wire workflowStreamResponse → onProgress; emit skillCall
  when sandbox_read_file detects a SKILL.md path
- agent/index.ts: pass workflowStreamResponse to createSandboxSkillsCapability
- edit.ts: convert REST endpoint to SSE stream; ready phase carries endpoint
- fetch.ts: route sandboxStatus to direct onMessage, skillCall to queue
- ChatBox: render sandboxStatus as loading bubble with phase label;
  render skillCall as stepTitle value item
- i18n: add sandbox_status_* and skill_calling keys (zh-CN, en, zh-Hant)

* refactor: Rename MongoAgentSkill to MongoAgentSkills and update references

* feat: Add support for extracting and handling various archive formats

* refactor: Remove markdown field from skill definitions

* refactor: Simplify skill handling and discovery in sandbox

* feat: Update storage and docker configurations for sandbox

* fix: Update storage key prefix in agentSkill module

* refactor: Rename agentSkill to agentSkills across codebase

* feat: Enhance agent skills API with validation and limits

* feat: Add skill size limits and improve package handling

* feat: Add support for custom entrypoints in sandbox configs

* feat: Renew sandbox expiration and support custom images

* feat: Add lazy sandbox init, fetch-user-file tool, and image file support

- Sandbox capability now initializes lazily (no container created until first
  tool call), reducing cold-start latency for conversations without tool usage
- Add sandbox_fetch_user_file tool to allow LLM to download user-uploaded
  files (documents and images) directly into sandbox filesystem
- Extend file input handling to include both document and image type files;
  introduce allFilesMap (all types) alongside filesMap (documents only)
- Preload skill metadata from SKILL.md in ZIP before sandbox creation, so
  system prompt is available without waiting for container startup
- Add executeWithRetry for silent sandbox rebuild on expiry/connection errors
- Add extractSkillMdInfoFromBuffer to read SKILL.md + path from ZIP in-memory
- Fix session artifact storage path: sessions/{id}/projects/ → agent-sessions/{id}/
- Add lazyInit phase to SandboxStatusPhase; pass skillName to
  download/upload/extract i18n keys for clearer progress display

* refactor: replace sandbox TTL lifecycle with status-based instance model

Redesign sandbox persistence layer: replace SkillSandboxSchemaType with
SandboxInstanceSchemaType (fields: appId, userId, chatId, status, lastActiveAt,
nested detail), rename collection from skill_sandbox_info to
agent_sandbox_instances, and add SandboxStatusEnum (running/stopped).

Remove expiry-driven cleanup: delete sandboxCleanup.ts and all TTL-related
fields (expiresAt, timeout, lastActivityTime) and API types (RenewSandbox*).
Add duplicate-name guard in importSkill. Update workflow dispatch, API routes,
tests, and mocks to align with the new schema.

* chore: add skill folder/directory support

* feat(agent-skills): integrate AI-assisted SKILL.md generation into create API

* refactor(sandbox): migrate to @fastgpt-sdk/sandbox-adapter and add multi-provider support

- Replace @anyany/sandbox_provider imports with @fastgpt-sdk/sandbox-adapter across
  sandboxController, lifecycle, and types
- Add SealosDevbox as a second supported provider alongside OpenSandbox,
  with discriminated-union typed configs (OpenSandboxProviderConfig /
  SealosDevboxProviderConfig)
- Centralize provider adapter construction in sandboxConfig:
  buildSandboxAdapter, connectToProviderSandbox,
  disconnectFromProviderSandbox, getProviderSandboxEndpoint,
  selectSandboxEntrypoint
- Migrate sandbox.resume() → sandbox.start() per updated SDK contract
- Add unit tests for new sandboxConfig provider helpers
- Fix vitest path aliases; add zip to sandbox-sync-agent Dockerfile

* feat(agent-skills): add skill export/download API

* feat(agent-skills): harden export API and add debug chat/session endpoints

- Replace authUserPer with authSkill + ReadPermissionVal in export handler
- Add EXPORT_SKILL audit event and i18n keys (en/zh-CN/zh-Hant)
- Add AGENT_SKILLS.EXPORT logger category
- Add debug chat and debug session (list/delete) API routes with tests
- Update export tests to match new authSkill-based error behavior

* feat(agent-skills): add skillId filter for apps and skill binding in chat agent form

* feat: Add skill debug session records API functionality

* refactor: Migrate agent skills API types to Zod schemas

* feat: Migrate agentSkills API to OpenAPI specification

* feat: Add internationalization support for agent skills

* refactor: Refactor sandbox tool descriptions and environment vars

* refactor: Rename version-related files and update imports

---------

Co-authored-by: chanzhi82020 <chenzhi@sangfor.com.cn>
2026-03-21 12:20:18 +08:00

58 lines
1.7 KiB
TypeScript

import { resolve } from 'path';
import { defineConfig } from 'vitest/config';
export default defineConfig({
resolve: {
alias: {
'@': resolve('projects/app/src'),
'@fastgpt/global': resolve('packages/global'),
'@fastgpt/service': resolve('packages/service'),
'@fastgpt/web': resolve('packages/web'),
'@test': resolve('test')
}
},
test: {
coverage: {
enabled: true,
reporter: ['html', 'json-summary', 'json'],
// reporter: ['text', 'text-summary', 'html', 'json-summary', 'json'],
reportOnFailure: true,
all: false, // 只包含被测试实际覆盖的文件,不包含空目录
include: ['projects/app/**/*.ts', 'packages/**/*.ts'],
exclude: [
'**/node_modules/**',
'**/*.spec.ts',
'**/*/*.d.ts',
'**/test/**',
'**/*.test.ts',
'**/*/constants.ts',
'**/*/*.const.ts',
'**/*/type.ts',
'**/*/types.ts',
'**/*/type/*',
'**/*/schema.ts',
'**/*/*.schema.ts',
'packages/global/openapi/**/*',
'packages/global/core/workflow/template/**/*'
],
cleanOnRerun: false
},
outputFile: 'test-results.json',
setupFiles: 'test/setup.ts',
globalSetup: 'test/globalSetup.ts',
// File-level execution: serial (one file at a time to avoid MongoDB conflicts)
fileParallelism: false,
// Test-level execution within a file: parallel (up to 5 concurrent tests)
maxConcurrency: 10,
pool: 'threads',
testTimeout: 20000,
hookTimeout: 30000,
reporters: ['github-actions', 'default'],
include: [
'test/**/*.test.ts',
'projects/app/test/**/*.test.ts',
'projects/marketplace/test/**/*.test.ts'
]
}
});