mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-11-23 22:59:09 +00:00
Merge pull request #209 from shumaiOne/feat/skill-permission
feat(skill): add team owner skill permission control
This commit is contained in:
@@ -11,6 +11,7 @@ data/
|
||||
*.db
|
||||
*.diff
|
||||
*.orig
|
||||
.agents
|
||||
|
||||
# Playwright
|
||||
/playwright-report/
|
||||
|
||||
@@ -243,7 +243,7 @@ export async function createAgentSession(params: CreateAgentSessionParams) {
|
||||
sandboxState.blockedHost = ''
|
||||
},
|
||||
})
|
||||
const readSkill = createReadSkillTool(onEnvsAdded)
|
||||
const readSkill = createReadSkillTool(userId, onEnvsAdded)
|
||||
|
||||
const systemTools: AgentTool[] = []
|
||||
if (userId) {
|
||||
|
||||
@@ -23,126 +23,103 @@ export function createAnalyzeImageTool(
|
||||
'Retrieves and views the image content. Call this tool if you need to analyze the image.',
|
||||
parameters: analyzeImageSchema,
|
||||
execute: async (_toolCallId, params) => {
|
||||
try {
|
||||
const assetId = params.assetId
|
||||
const assetId = params.assetId
|
||||
|
||||
if (!userId) {
|
||||
return {
|
||||
content: [{ type: 'text', text: 'User ID is required for authorization.' }],
|
||||
details: {},
|
||||
}
|
||||
if (!userId) {
|
||||
throw new Error('User ID is required for authorization.')
|
||||
}
|
||||
|
||||
await authzService.hasPermission({
|
||||
user: { id: userId } as User,
|
||||
permission: Permission.Read,
|
||||
type: ResourceType.Asset,
|
||||
id: assetId,
|
||||
})
|
||||
|
||||
const asset = await prisma.asset.findUnique({
|
||||
where: { id: assetId },
|
||||
include: { storageKey: true },
|
||||
})
|
||||
|
||||
if (!asset) {
|
||||
throw new Error(`Asset with ID ${assetId} not found.`)
|
||||
}
|
||||
|
||||
// Get default media key
|
||||
let mediaKey = asset.storageKey?.key
|
||||
if (asset.media) {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
const mediaInfo = asset.media as any
|
||||
if (mediaInfo.imageTranscodes && mediaInfo.imageTranscodes.length > 0) {
|
||||
mediaKey = mediaInfo.imageTranscodes[0].key || mediaKey
|
||||
}
|
||||
}
|
||||
|
||||
await authzService.hasPermission({
|
||||
user: { id: userId } as User,
|
||||
permission: Permission.Read,
|
||||
type: ResourceType.Asset,
|
||||
id: assetId,
|
||||
if (!mediaKey) {
|
||||
throw new Error('No media content found for this asset.')
|
||||
}
|
||||
|
||||
// Check if trigger comment has draw annotations for this asset
|
||||
let annotations: unknown = null
|
||||
if (userCommentId) {
|
||||
const comment = await prisma.assetComment.findUnique({
|
||||
where: { id: userCommentId },
|
||||
})
|
||||
|
||||
const asset = await prisma.asset.findUnique({
|
||||
where: { id: assetId },
|
||||
include: { storageKey: true },
|
||||
})
|
||||
|
||||
if (!asset) {
|
||||
return {
|
||||
content: [{ type: 'text', text: `Asset with ID ${assetId} not found.` }],
|
||||
details: {},
|
||||
if (comment && comment.assetId === assetId && comment.annotation) {
|
||||
const list = comment.annotation
|
||||
if (Array.isArray(list) && list.length > 0) {
|
||||
annotations = list
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Get default media key
|
||||
let mediaKey = asset.storageKey?.key
|
||||
if (asset.media) {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
const mediaInfo = asset.media as any
|
||||
if (mediaInfo.imageTranscodes && mediaInfo.imageTranscodes.length > 0) {
|
||||
mediaKey = mediaInfo.imageTranscodes[0].key || mediaKey
|
||||
}
|
||||
}
|
||||
let keyToUse = mediaKey
|
||||
|
||||
if (!mediaKey) {
|
||||
return {
|
||||
content: [{ type: 'text', text: 'No media content found for this asset.' }],
|
||||
details: {},
|
||||
}
|
||||
}
|
||||
|
||||
// Check if trigger comment has draw annotations for this asset
|
||||
let annotations: unknown = null
|
||||
if (userCommentId) {
|
||||
const comment = await prisma.assetComment.findUnique({
|
||||
where: { id: userCommentId },
|
||||
})
|
||||
if (comment && comment.assetId === assetId && comment.annotation) {
|
||||
const list = comment.annotation
|
||||
if (Array.isArray(list) && list.length > 0) {
|
||||
annotations = list
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let keyToUse = mediaKey
|
||||
|
||||
if (annotations) {
|
||||
// Trigger transcode workflow to draw annotation
|
||||
const task = await prisma.workflowTask.create({
|
||||
data: {
|
||||
assetId,
|
||||
if (annotations) {
|
||||
// Trigger transcode workflow to draw annotation
|
||||
const task = await prisma.workflowTask.create({
|
||||
data: {
|
||||
assetId,
|
||||
projectId: asset.projectId || 'none',
|
||||
type: WorkflowTaskType.transcode_image_annotation,
|
||||
status: WorkflowTaskStatus.pending,
|
||||
payload: {
|
||||
projectId: asset.projectId || 'none',
|
||||
type: WorkflowTaskType.transcode_image_annotation,
|
||||
status: WorkflowTaskStatus.pending,
|
||||
payload: {
|
||||
projectId: asset.projectId || 'none',
|
||||
imageAnnotation: {
|
||||
annotations: annotations as PrismaJson.AnnotationList,
|
||||
},
|
||||
imageAnnotation: {
|
||||
annotations: annotations as PrismaJson.AnnotationList,
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
const completedTask = await workflowService.executeWait(task)
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
const output = completedTask.output as any
|
||||
if (output?.key) {
|
||||
keyToUse = output.key
|
||||
} else {
|
||||
throw new Error('Image annotation transcode workflow failed to output S3 key.')
|
||||
}
|
||||
}
|
||||
|
||||
// Retrieve the image content from S3
|
||||
const bucket = process.env.S3_BUCKET || 'shumai'
|
||||
const { buffer, contentType } = await s3Service.getObject(bucket, keyToUse)
|
||||
|
||||
const content: ImageContent[] = [
|
||||
{
|
||||
type: 'image',
|
||||
data: buffer.toString('base64'),
|
||||
mimeType: contentType || 'image/webp',
|
||||
},
|
||||
]
|
||||
})
|
||||
|
||||
return {
|
||||
content,
|
||||
details: {
|
||||
sourceKeys: [keyToUse],
|
||||
},
|
||||
}
|
||||
} catch (error) {
|
||||
return {
|
||||
content: [
|
||||
{
|
||||
type: 'text',
|
||||
text: `Error analyzing image: ${
|
||||
error instanceof Error ? error.message : String(error)
|
||||
}`,
|
||||
},
|
||||
],
|
||||
details: {},
|
||||
const completedTask = await workflowService.executeWait(task)
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
const output = completedTask.output as any
|
||||
if (output?.key) {
|
||||
keyToUse = output.key
|
||||
} else {
|
||||
throw new Error('Image annotation transcode workflow failed to output S3 key.')
|
||||
}
|
||||
}
|
||||
|
||||
// Retrieve the image content from S3
|
||||
const bucket = process.env.S3_BUCKET || 'shumai'
|
||||
const { buffer, contentType } = await s3Service.getObject(bucket, keyToUse)
|
||||
|
||||
const content: ImageContent[] = [
|
||||
{
|
||||
type: 'image',
|
||||
data: buffer.toString('base64'),
|
||||
mimeType: contentType || 'image/webp',
|
||||
},
|
||||
]
|
||||
|
||||
return {
|
||||
content,
|
||||
details: {
|
||||
sourceKeys: [keyToUse],
|
||||
},
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,45 +58,33 @@ export function createCreateFileTool(userId: string): AgentTool<typeof createFil
|
||||
description: 'Create a new file in a specified parent folder from a local file path.',
|
||||
parameters: createFileSchema,
|
||||
execute: async (_toolCallId, params) => {
|
||||
try {
|
||||
const absolutePath = path.resolve(process.cwd(), params.path)
|
||||
if (!fs.existsSync(absolutePath)) {
|
||||
throw new Error(`Local file not found at path: ${params.path}`)
|
||||
}
|
||||
const absolutePath = path.resolve(process.cwd(), params.path)
|
||||
if (!fs.existsSync(absolutePath)) {
|
||||
throw new Error(`Local file not found at path: ${params.path}`)
|
||||
}
|
||||
|
||||
const fileSize = fs.statSync(absolutePath).size
|
||||
const mimeType = getMimeType(absolutePath)
|
||||
const fileSize = fs.statSync(absolutePath).size
|
||||
const mimeType = getMimeType(absolutePath)
|
||||
|
||||
// Generate compliant S3 key matching normal file upload format
|
||||
const s3Key = `files/${ulid()}/${sanitizeFilename(path.basename(absolutePath))}`
|
||||
await s3Service.uploadFileToKey(absolutePath, s3Key, mimeType)
|
||||
// Generate compliant S3 key matching normal file upload format
|
||||
const s3Key = `files/${ulid()}/${sanitizeFilename(path.basename(absolutePath))}`
|
||||
await s3Service.uploadFileToKey(absolutePath, s3Key, mimeType)
|
||||
|
||||
const result = await executeAgentToolWorkflow({
|
||||
toolName: 'create_file',
|
||||
args: {
|
||||
parent: params.parent,
|
||||
s3Key,
|
||||
name: path.basename(absolutePath),
|
||||
size: fileSize,
|
||||
contentType: mimeType,
|
||||
},
|
||||
userId,
|
||||
assetId: params.parent,
|
||||
})
|
||||
return {
|
||||
content: [{ type: 'text', text: JSON.stringify(result, null, 2) }],
|
||||
details: result,
|
||||
}
|
||||
} catch (error) {
|
||||
return {
|
||||
content: [
|
||||
{
|
||||
type: 'text',
|
||||
text: `Error creating file: ${error instanceof Error ? error.message : String(error)}`,
|
||||
},
|
||||
],
|
||||
details: {},
|
||||
}
|
||||
const result = await executeAgentToolWorkflow({
|
||||
toolName: 'create_file',
|
||||
args: {
|
||||
parent: params.parent,
|
||||
s3Key,
|
||||
name: path.basename(absolutePath),
|
||||
size: fileSize,
|
||||
contentType: mimeType,
|
||||
},
|
||||
userId,
|
||||
assetId: params.parent,
|
||||
})
|
||||
return {
|
||||
content: [{ type: 'text', text: JSON.stringify(result, null, 2) }],
|
||||
details: result,
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
@@ -19,27 +19,15 @@ export function createCreateFolderTool(userId: string): AgentTool<typeof createF
|
||||
description: 'Create a new folder in a specified parent folder.',
|
||||
parameters: createFolderSchema,
|
||||
execute: async (_toolCallId, params) => {
|
||||
try {
|
||||
const result = await executeAgentToolWorkflow({
|
||||
toolName: 'create_folder',
|
||||
args: params,
|
||||
userId,
|
||||
assetId: params.parent,
|
||||
})
|
||||
return {
|
||||
content: [{ type: 'text', text: JSON.stringify(result, null, 2) }],
|
||||
details: result,
|
||||
}
|
||||
} catch (error) {
|
||||
return {
|
||||
content: [
|
||||
{
|
||||
type: 'text',
|
||||
text: `Error creating folder: ${error instanceof Error ? error.message : String(error)}`,
|
||||
},
|
||||
],
|
||||
details: {},
|
||||
}
|
||||
const result = await executeAgentToolWorkflow({
|
||||
toolName: 'create_folder',
|
||||
args: params,
|
||||
userId,
|
||||
assetId: params.parent,
|
||||
})
|
||||
return {
|
||||
content: [{ type: 'text', text: JSON.stringify(result, null, 2) }],
|
||||
details: result,
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
@@ -59,45 +59,33 @@ export function createCreateVersionTool(userId: string): AgentTool<typeof create
|
||||
description: 'Create a new version of an existing file from a local file path.',
|
||||
parameters: createVersionSchema,
|
||||
execute: async (_toolCallId, params) => {
|
||||
try {
|
||||
const absolutePath = path.resolve(process.cwd(), params.path)
|
||||
if (!fs.existsSync(absolutePath)) {
|
||||
throw new Error(`Local file not found at path: ${params.path}`)
|
||||
}
|
||||
const absolutePath = path.resolve(process.cwd(), params.path)
|
||||
if (!fs.existsSync(absolutePath)) {
|
||||
throw new Error(`Local file not found at path: ${params.path}`)
|
||||
}
|
||||
|
||||
const fileSize = fs.statSync(absolutePath).size
|
||||
const mimeType = getMimeType(absolutePath)
|
||||
const fileSize = fs.statSync(absolutePath).size
|
||||
const mimeType = getMimeType(absolutePath)
|
||||
|
||||
// Generate compliant S3 key matching normal file upload format
|
||||
const s3Key = `files/${ulid()}/${sanitizeFilename(path.basename(absolutePath))}`
|
||||
await s3Service.uploadFileToKey(absolutePath, s3Key, mimeType)
|
||||
// Generate compliant S3 key matching normal file upload format
|
||||
const s3Key = `files/${ulid()}/${sanitizeFilename(path.basename(absolutePath))}`
|
||||
await s3Service.uploadFileToKey(absolutePath, s3Key, mimeType)
|
||||
|
||||
const result = await executeAgentToolWorkflow({
|
||||
toolName: 'create_version',
|
||||
args: {
|
||||
parent: params.parent,
|
||||
s3Key,
|
||||
name: path.basename(absolutePath),
|
||||
size: fileSize,
|
||||
contentType: mimeType,
|
||||
},
|
||||
userId,
|
||||
assetId: params.parent,
|
||||
})
|
||||
return {
|
||||
content: [{ type: 'text', text: JSON.stringify(result, null, 2) }],
|
||||
details: result,
|
||||
}
|
||||
} catch (error) {
|
||||
return {
|
||||
content: [
|
||||
{
|
||||
type: 'text',
|
||||
text: `Error creating file version: ${error instanceof Error ? error.message : String(error)}`,
|
||||
},
|
||||
],
|
||||
details: {},
|
||||
}
|
||||
const result = await executeAgentToolWorkflow({
|
||||
toolName: 'create_version',
|
||||
args: {
|
||||
parent: params.parent,
|
||||
s3Key,
|
||||
name: path.basename(absolutePath),
|
||||
size: fileSize,
|
||||
contentType: mimeType,
|
||||
},
|
||||
userId,
|
||||
assetId: params.parent,
|
||||
})
|
||||
return {
|
||||
content: [{ type: 'text', text: JSON.stringify(result, null, 2) }],
|
||||
details: result,
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
@@ -34,27 +34,15 @@ export function createListAssetsTool(userId: string): AgentTool<typeof listAsset
|
||||
description: 'List the assets (files and folders) inside a parent folder with pagination.',
|
||||
parameters: listAssetsSchema,
|
||||
execute: async (_toolCallId, params) => {
|
||||
try {
|
||||
const result = await executeAgentToolWorkflow({
|
||||
toolName: 'list_assets',
|
||||
args: params,
|
||||
userId,
|
||||
assetId: params.parent,
|
||||
})
|
||||
return {
|
||||
content: [{ type: 'text', text: JSON.stringify(result, null, 2) }],
|
||||
details: result,
|
||||
}
|
||||
} catch (error) {
|
||||
return {
|
||||
content: [
|
||||
{
|
||||
type: 'text',
|
||||
text: `Error listing assets: ${error instanceof Error ? error.message : String(error)}`,
|
||||
},
|
||||
],
|
||||
details: {},
|
||||
}
|
||||
const result = await executeAgentToolWorkflow({
|
||||
toolName: 'list_assets',
|
||||
args: params,
|
||||
userId,
|
||||
assetId: params.parent,
|
||||
})
|
||||
return {
|
||||
content: [{ type: 'text', text: JSON.stringify(result, null, 2) }],
|
||||
details: result,
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
@@ -151,49 +151,37 @@ describe('readPdfPagesTool', () => {
|
||||
expect(result.details.sourceKeys).toEqual(['pdf_pages/page_1.webp', 'pdf_pages/page_2.webp'])
|
||||
})
|
||||
|
||||
it('should return error text if start page is less than 1', async () => {
|
||||
it('should throw error if start page is less than 1', async () => {
|
||||
const tool = createReadPdfPagesTool('user-1')
|
||||
const result = await tool.execute('call-1', { assetId: 'asset-1', start: 0, end: 5 })
|
||||
|
||||
expect(result.content[0]).toEqual({
|
||||
type: 'text',
|
||||
text: 'Invalid page range: start page (0) must be at least 1.',
|
||||
})
|
||||
await expect(tool.execute('call-1', { assetId: 'asset-1', start: 0, end: 5 })).rejects.toThrow(
|
||||
'Invalid page range: start page (0) must be at least 1.',
|
||||
)
|
||||
})
|
||||
|
||||
it('should return error text if start page is greater than end page', async () => {
|
||||
it('should throw error if start page is greater than end page', async () => {
|
||||
const tool = createReadPdfPagesTool('user-1')
|
||||
const result = await tool.execute('call-1', { assetId: 'asset-1', start: 5, end: 2 })
|
||||
|
||||
expect(result.content[0]).toEqual({
|
||||
type: 'text',
|
||||
text: 'Invalid page range: start page (5) must be less than or equal to end page (2).',
|
||||
})
|
||||
await expect(tool.execute('call-1', { assetId: 'asset-1', start: 5, end: 2 })).rejects.toThrow(
|
||||
'Invalid page range: start page (5) must be less than or equal to end page (2).',
|
||||
)
|
||||
})
|
||||
|
||||
it('should return error text if page range exceeds maximum limit of 20', async () => {
|
||||
it('should throw error if page range exceeds maximum limit of 20', async () => {
|
||||
const tool = createReadPdfPagesTool('user-1')
|
||||
const result = await tool.execute('call-1', { assetId: 'asset-1', start: 1, end: 25 })
|
||||
|
||||
expect(result.content[0]).toEqual({
|
||||
type: 'text',
|
||||
text: 'Page range (25 pages requested) exceeds the maximum limit of 20 pages per request.',
|
||||
})
|
||||
await expect(tool.execute('call-1', { assetId: 'asset-1', start: 1, end: 25 })).rejects.toThrow(
|
||||
'Page range (25 pages requested) exceeds the maximum limit of 20 pages per request.',
|
||||
)
|
||||
})
|
||||
|
||||
it('should return error text if asset not found', async () => {
|
||||
it('should throw error if asset not found', async () => {
|
||||
vi.mocked(prisma.asset.findUnique).mockResolvedValue(null)
|
||||
|
||||
const tool = createReadPdfPagesTool('user-1')
|
||||
const result = await tool.execute('call-1', { assetId: 'asset-1', start: 1, end: 3 })
|
||||
|
||||
expect(result.content[0]).toEqual({
|
||||
type: 'text',
|
||||
text: 'Asset with ID asset-1 not found.',
|
||||
})
|
||||
await expect(tool.execute('call-1', { assetId: 'asset-1', start: 1, end: 3 })).rejects.toThrow(
|
||||
'Asset with ID asset-1 not found.',
|
||||
)
|
||||
})
|
||||
|
||||
it('should return error text if proxyType is not pdf', async () => {
|
||||
it('should throw error if proxyType is not pdf', async () => {
|
||||
vi.mocked(prisma.asset.findUnique).mockResolvedValue({
|
||||
id: 'asset-1',
|
||||
projectId: 'project-1',
|
||||
@@ -201,15 +189,12 @@ describe('readPdfPagesTool', () => {
|
||||
} as unknown as Asset)
|
||||
|
||||
const tool = createReadPdfPagesTool('user-1')
|
||||
const result = await tool.execute('call-1', { assetId: 'asset-1', start: 1, end: 3 })
|
||||
|
||||
expect(result.content[0]).toEqual({
|
||||
type: 'text',
|
||||
text: 'Asset asset-1 is not a PDF or document.',
|
||||
})
|
||||
await expect(tool.execute('call-1', { assetId: 'asset-1', start: 1, end: 3 })).rejects.toThrow(
|
||||
'Asset asset-1 is not a PDF or document.',
|
||||
)
|
||||
})
|
||||
|
||||
it('should return error text if proxyType is null/undefined (unprocessed)', async () => {
|
||||
it('should throw error if proxyType is null/undefined (unprocessed)', async () => {
|
||||
vi.mocked(prisma.asset.findUnique).mockResolvedValue({
|
||||
id: 'asset-1',
|
||||
projectId: 'project-1',
|
||||
@@ -217,11 +202,8 @@ describe('readPdfPagesTool', () => {
|
||||
} as unknown as Asset)
|
||||
|
||||
const tool = createReadPdfPagesTool('user-1')
|
||||
const result = await tool.execute('call-1', { assetId: 'asset-1', start: 1, end: 3 })
|
||||
|
||||
expect(result.content[0]).toEqual({
|
||||
type: 'text',
|
||||
text: 'Asset asset-1 is not a PDF or document.',
|
||||
})
|
||||
await expect(tool.execute('call-1', { assetId: 'asset-1', start: 1, end: 3 })).rejects.toThrow(
|
||||
'Asset asset-1 is not a PDF or document.',
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -25,161 +25,115 @@ export function createReadPdfPagesTool(
|
||||
'Converts specific page range of a PDF document into 1080p WebP images for visual analysis. Maximum 20 pages allowed per call.',
|
||||
parameters: readPdfPagesSchema,
|
||||
execute: async (_toolCallId, params) => {
|
||||
try {
|
||||
if (params.start < 1) {
|
||||
return {
|
||||
content: [
|
||||
{
|
||||
type: 'text',
|
||||
text: `Invalid page range: start page (${params.start}) must be at least 1.`,
|
||||
},
|
||||
],
|
||||
details: {},
|
||||
}
|
||||
}
|
||||
if (params.start < 1) {
|
||||
throw new Error(`Invalid page range: start page (${params.start}) must be at least 1.`)
|
||||
}
|
||||
|
||||
if (params.start > params.end) {
|
||||
return {
|
||||
content: [
|
||||
{
|
||||
type: 'text',
|
||||
text: `Invalid page range: start page (${params.start}) must be less than or equal to end page (${params.end}).`,
|
||||
},
|
||||
],
|
||||
details: {},
|
||||
}
|
||||
}
|
||||
if (params.start > params.end) {
|
||||
throw new Error(
|
||||
`Invalid page range: start page (${params.start}) must be less than or equal to end page (${params.end}).`,
|
||||
)
|
||||
}
|
||||
|
||||
const MAX_PAGE_RANGE = 20
|
||||
const requestedPages = params.end - params.start + 1
|
||||
if (requestedPages > MAX_PAGE_RANGE) {
|
||||
return {
|
||||
content: [
|
||||
{
|
||||
type: 'text',
|
||||
text: `Page range (${requestedPages} pages requested) exceeds the maximum limit of ${MAX_PAGE_RANGE} pages per request.`,
|
||||
},
|
||||
],
|
||||
details: {},
|
||||
}
|
||||
}
|
||||
const MAX_PAGE_RANGE = 20
|
||||
const requestedPages = params.end - params.start + 1
|
||||
if (requestedPages > MAX_PAGE_RANGE) {
|
||||
throw new Error(
|
||||
`Page range (${requestedPages} pages requested) exceeds the maximum limit of ${MAX_PAGE_RANGE} pages per request.`,
|
||||
)
|
||||
}
|
||||
|
||||
const targetAssetId = params.assetId
|
||||
const targetAssetId = params.assetId
|
||||
|
||||
if (!userId) {
|
||||
return {
|
||||
content: [{ type: 'text', text: 'User ID is required for authorization.' }],
|
||||
details: {},
|
||||
}
|
||||
}
|
||||
if (!userId) {
|
||||
throw new Error('User ID is required for authorization.')
|
||||
}
|
||||
|
||||
await authzService.hasPermission({
|
||||
user: { id: userId } as User,
|
||||
permission: Permission.Read,
|
||||
type: ResourceType.Asset,
|
||||
id: targetAssetId,
|
||||
await authzService.hasPermission({
|
||||
user: { id: userId } as User,
|
||||
permission: Permission.Read,
|
||||
type: ResourceType.Asset,
|
||||
id: targetAssetId,
|
||||
})
|
||||
|
||||
const asset = await prisma.asset.findUnique({
|
||||
where: { id: targetAssetId },
|
||||
})
|
||||
|
||||
if (!asset) {
|
||||
throw new Error(`Asset with ID ${targetAssetId} not found.`)
|
||||
}
|
||||
|
||||
const proxyType = (asset.media as PrismaJson.MediaInfo | null)?.proxyType
|
||||
if (proxyType !== 'pdf') {
|
||||
throw new Error(`Asset ${targetAssetId} is not a PDF or document.`)
|
||||
}
|
||||
|
||||
// Fetch trigger comment details for comment page and annotations
|
||||
let commentTimestamp: number | null = null
|
||||
let annotations: unknown = null
|
||||
if (userCommentId) {
|
||||
const comment = await prisma.assetComment.findUnique({
|
||||
where: { id: userCommentId },
|
||||
})
|
||||
|
||||
const asset = await prisma.asset.findUnique({
|
||||
where: { id: targetAssetId },
|
||||
})
|
||||
|
||||
if (!asset) {
|
||||
return {
|
||||
content: [{ type: 'text', text: `Asset with ID ${targetAssetId} not found.` }],
|
||||
details: {},
|
||||
}
|
||||
}
|
||||
|
||||
const proxyType = (asset.media as PrismaJson.MediaInfo | null)?.proxyType
|
||||
if (proxyType !== 'pdf') {
|
||||
return {
|
||||
content: [{ type: 'text', text: `Asset ${targetAssetId} is not a PDF or document.` }],
|
||||
details: {},
|
||||
}
|
||||
}
|
||||
|
||||
// Fetch trigger comment details for comment page and annotations
|
||||
let commentTimestamp: number | null = null
|
||||
let annotations: unknown = null
|
||||
if (userCommentId) {
|
||||
const comment = await prisma.assetComment.findUnique({
|
||||
where: { id: userCommentId },
|
||||
})
|
||||
if (comment && comment.assetId === targetAssetId) {
|
||||
commentTimestamp = comment.second !== null ? comment.second : null
|
||||
if (comment.annotation) {
|
||||
const list = comment.annotation
|
||||
if (Array.isArray(list) && list.length > 0) {
|
||||
annotations = list
|
||||
}
|
||||
if (comment && comment.assetId === targetAssetId) {
|
||||
commentTimestamp = comment.second !== null ? comment.second : null
|
||||
if (comment.annotation) {
|
||||
const list = comment.annotation
|
||||
if (Array.isArray(list) && list.length > 0) {
|
||||
annotations = list
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Trigger transcode workflow to render PDF pages
|
||||
const task = await prisma.workflowTask.create({
|
||||
data: {
|
||||
assetId: targetAssetId,
|
||||
// Trigger transcode workflow to render PDF pages
|
||||
const task = await prisma.workflowTask.create({
|
||||
data: {
|
||||
assetId: targetAssetId,
|
||||
projectId: asset.projectId || 'none',
|
||||
type: WorkflowTaskType.transcode_pdf_pages,
|
||||
status: WorkflowTaskStatus.pending,
|
||||
payload: {
|
||||
projectId: asset.projectId || 'none',
|
||||
type: WorkflowTaskType.transcode_pdf_pages,
|
||||
status: WorkflowTaskStatus.pending,
|
||||
payload: {
|
||||
projectId: asset.projectId || 'none',
|
||||
pdfPages: {
|
||||
start: params.start,
|
||||
end: params.end,
|
||||
commentTimestamp,
|
||||
annotations: annotations as PrismaJson.AnnotationList,
|
||||
},
|
||||
pdfPages: {
|
||||
start: params.start,
|
||||
end: params.end,
|
||||
commentTimestamp,
|
||||
annotations: annotations as PrismaJson.AnnotationList,
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
const completedTask = await workflowService.executeWait(task)
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
const output = completedTask.output as any
|
||||
const pages = output?.pages as Array<{ key: string; page: number }> | undefined
|
||||
|
||||
if (!pages || pages.length === 0) {
|
||||
throw new Error('No PDF page images were generated.')
|
||||
}
|
||||
|
||||
const content: ImageContent[] = []
|
||||
const sourceKeys: string[] = []
|
||||
const bucket = process.env.S3_BUCKET || 'shumai'
|
||||
|
||||
for (const pageItem of pages) {
|
||||
const { buffer, contentType } = await s3Service.getObject(bucket, pageItem.key)
|
||||
content.push({
|
||||
type: 'image',
|
||||
data: buffer.toString('base64'),
|
||||
mimeType: contentType || 'image/webp',
|
||||
})
|
||||
sourceKeys.push(pageItem.key)
|
||||
}
|
||||
|
||||
const completedTask = await workflowService.executeWait(task)
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
const output = completedTask.output as any
|
||||
const pages = output?.pages as Array<{ key: string; page: number }> | undefined
|
||||
|
||||
if (!pages || pages.length === 0) {
|
||||
return {
|
||||
content: [{ type: 'text', text: 'No PDF page images were generated.' }],
|
||||
details: {},
|
||||
}
|
||||
}
|
||||
|
||||
const content: ImageContent[] = []
|
||||
const sourceKeys: string[] = []
|
||||
const bucket = process.env.S3_BUCKET || 'shumai'
|
||||
|
||||
for (const pageItem of pages) {
|
||||
const { buffer, contentType } = await s3Service.getObject(bucket, pageItem.key)
|
||||
content.push({
|
||||
type: 'image',
|
||||
data: buffer.toString('base64'),
|
||||
mimeType: contentType || 'image/webp',
|
||||
})
|
||||
sourceKeys.push(pageItem.key)
|
||||
}
|
||||
|
||||
return {
|
||||
content,
|
||||
details: {
|
||||
sourceKeys,
|
||||
},
|
||||
}
|
||||
} catch (error) {
|
||||
return {
|
||||
content: [
|
||||
{
|
||||
type: 'text',
|
||||
text: `Error reading PDF pages: ${
|
||||
error instanceof Error ? error.message : String(error)
|
||||
}`,
|
||||
},
|
||||
],
|
||||
details: {},
|
||||
}
|
||||
return {
|
||||
content,
|
||||
details: {
|
||||
sourceKeys,
|
||||
},
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
@@ -18,16 +18,11 @@ describe('readSkillTool', () => {
|
||||
vi.clearAllMocks()
|
||||
})
|
||||
|
||||
it('should return error if skill not found', async () => {
|
||||
const readSkillTool = createReadSkillTool(() => {})
|
||||
const result = await readSkillTool.execute(
|
||||
'1',
|
||||
{ skillId: 'non-existent' },
|
||||
undefined,
|
||||
undefined,
|
||||
)
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
expect((result.content[0] as any).text).toContain('not found')
|
||||
it('should throw error if skill not found', async () => {
|
||||
const readSkillTool = createReadSkillTool(undefined, () => {})
|
||||
await expect(
|
||||
readSkillTool.execute('1', { skillId: 'non-existent' }, undefined, undefined),
|
||||
).rejects.toThrow('not found')
|
||||
})
|
||||
|
||||
it('should read skill from cache if hash matches', async () => {
|
||||
@@ -49,7 +44,7 @@ describe('readSkillTool', () => {
|
||||
return ''
|
||||
})
|
||||
|
||||
const readSkillTool = createReadSkillTool(() => {})
|
||||
const readSkillTool = createReadSkillTool(undefined, () => {})
|
||||
const result = await readSkillTool.execute('1', { skillId: skill.id }, undefined, undefined)
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
@@ -101,7 +96,7 @@ describe('readSkillTool', () => {
|
||||
contentType: 'application/zip',
|
||||
})
|
||||
|
||||
const readSkillTool = createReadSkillTool(() => {})
|
||||
const readSkillTool = createReadSkillTool(undefined, () => {})
|
||||
const result = await readSkillTool.execute('1', { skillId: skill.id }, undefined, undefined)
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
@@ -146,7 +141,7 @@ describe('readSkillTool', () => {
|
||||
})
|
||||
|
||||
let capturedEnvs: Record<string, string> = {}
|
||||
const readSkillTool = createReadSkillTool((envs) => {
|
||||
const readSkillTool = createReadSkillTool(undefined, (envs) => {
|
||||
capturedEnvs = { ...capturedEnvs, ...envs }
|
||||
})
|
||||
await readSkillTool.execute('1', { skillId: skill.id }, undefined, undefined)
|
||||
@@ -181,7 +176,7 @@ describe('readSkillTool', () => {
|
||||
})
|
||||
|
||||
let capturedEnvs: Record<string, string> = {}
|
||||
const readSkillTool = createReadSkillTool((envs) => {
|
||||
const readSkillTool = createReadSkillTool(undefined, (envs) => {
|
||||
capturedEnvs = { ...capturedEnvs, ...envs }
|
||||
})
|
||||
await readSkillTool.execute('1', { skillId: skill.id }, undefined, undefined)
|
||||
@@ -216,7 +211,7 @@ describe('readSkillTool', () => {
|
||||
})
|
||||
|
||||
let capturedEnvs: Record<string, string> = {}
|
||||
const readSkillTool = createReadSkillTool((envs) => {
|
||||
const readSkillTool = createReadSkillTool(undefined, (envs) => {
|
||||
capturedEnvs = { ...capturedEnvs, ...envs }
|
||||
})
|
||||
await readSkillTool.execute('1', { skillId: skill.id }, undefined, undefined)
|
||||
@@ -251,7 +246,7 @@ describe('readSkillTool', () => {
|
||||
})
|
||||
|
||||
let capturedEnvs: Record<string, string> = {}
|
||||
const readSkillTool = createReadSkillTool((envs) => {
|
||||
const readSkillTool = createReadSkillTool(undefined, (envs) => {
|
||||
capturedEnvs = { ...capturedEnvs, ...envs }
|
||||
})
|
||||
await readSkillTool.execute('1', { skillId: skill.id }, undefined, undefined)
|
||||
@@ -261,4 +256,56 @@ describe('readSkillTool', () => {
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('permissions', () => {
|
||||
it('should allow loading skill matching user role level or lower', async () => {
|
||||
const team = await prisma.team.create({ data: { name: 'Permission Team' } })
|
||||
const ownerUser = await prisma.user.create({
|
||||
data: { name: 'Owner User', email: 'owner@test.com' },
|
||||
})
|
||||
const reviewerUser = await prisma.user.create({
|
||||
data: { name: 'Reviewer User', email: 'reviewer@test.com' },
|
||||
})
|
||||
|
||||
await prisma.teamMember.create({
|
||||
data: { teamId: team.id, userId: ownerUser.id, role: 'owner' },
|
||||
})
|
||||
await prisma.teamMember.create({
|
||||
data: { teamId: team.id, userId: reviewerUser.id, role: 'reviewer' },
|
||||
})
|
||||
|
||||
const ownerSkill = await prisma.skill.create({
|
||||
data: {
|
||||
name: 'Owner Skill',
|
||||
assetId: 'asset1',
|
||||
hash: 'hash-owner',
|
||||
teamId: team.id,
|
||||
permission: 'owner',
|
||||
},
|
||||
})
|
||||
|
||||
vi.spyOn(fs, 'existsSync').mockReturnValue(true)
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
vi.spyOn(fs, 'readFileSync').mockImplementation((path: any) => {
|
||||
if (path.toString().endsWith('.hash')) return 'hash-owner'
|
||||
if (path.toString().endsWith('SKILL.md')) return '# Owner Skill'
|
||||
return ''
|
||||
})
|
||||
|
||||
const ownerTool = createReadSkillTool(ownerUser.id, () => {})
|
||||
const resultOwner = await ownerTool.execute(
|
||||
'1',
|
||||
{ skillId: ownerSkill.id },
|
||||
undefined,
|
||||
undefined,
|
||||
)
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
expect((resultOwner.content[0] as any).text).toBe('# Owner Skill')
|
||||
|
||||
const reviewerTool = createReadSkillTool(reviewerUser.id, () => {})
|
||||
await expect(
|
||||
reviewerTool.execute('1', { skillId: ownerSkill.id }, undefined, undefined),
|
||||
).rejects.toThrow('Permission denied')
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -7,7 +7,14 @@ const readSkillSchema = Type.Object({
|
||||
skillId: Type.String({ description: 'The ID of the skill to read' }),
|
||||
})
|
||||
|
||||
const ROLE_HIERARCHY: Record<string, number> = {
|
||||
owner: 3,
|
||||
editor: 2,
|
||||
reviewer: 1,
|
||||
}
|
||||
|
||||
export const createReadSkillTool = (
|
||||
userId: string | undefined,
|
||||
onEnvsAdded: (envs: Record<string, string>) => void,
|
||||
): AgentTool<typeof readSkillSchema, { skillId: string }> => ({
|
||||
name: 'read_skill',
|
||||
@@ -15,41 +22,47 @@ export const createReadSkillTool = (
|
||||
description: 'Downloads and reads an agent skill to understand how to use it.',
|
||||
parameters: readSkillSchema,
|
||||
execute: async (_toolCallId, params) => {
|
||||
try {
|
||||
const skill = await prisma.skill.findUnique({
|
||||
where: { id: params.skillId },
|
||||
})
|
||||
const skill = await prisma.skill.findUnique({
|
||||
where: { id: params.skillId },
|
||||
})
|
||||
|
||||
if (!skill) {
|
||||
return {
|
||||
content: [{ type: 'text', text: `Skill with ID ${params.skillId} not found.` }],
|
||||
details: { skillId: params.skillId },
|
||||
}
|
||||
}
|
||||
if (!skill) {
|
||||
throw new Error(`Skill with ID ${params.skillId} not found.`)
|
||||
}
|
||||
|
||||
// Capture environment variables using agentService
|
||||
const envs = await agentService.getSkillEnvs(params.skillId)
|
||||
onEnvsAdded(envs)
|
||||
const requiredLevel = ROLE_HIERARCHY[skill.permission] || 1
|
||||
|
||||
// Retrieve skill content using agentService
|
||||
const skillMdContent = await agentService.getSkillContent(params.skillId)
|
||||
|
||||
return {
|
||||
content: [{ type: 'text', text: skillMdContent }],
|
||||
details: { skillId: params.skillId },
|
||||
}
|
||||
} catch (error) {
|
||||
return {
|
||||
content: [
|
||||
{
|
||||
type: 'text',
|
||||
text: `Error reading skill ${params.skillId}: ${
|
||||
error instanceof Error ? error.message : String(error)
|
||||
}`,
|
||||
if (userId) {
|
||||
const member = await prisma.teamMember.findUnique({
|
||||
where: {
|
||||
teamIdUserId: {
|
||||
teamId: skill.teamId,
|
||||
userId,
|
||||
},
|
||||
],
|
||||
details: { skillId: params.skillId },
|
||||
},
|
||||
})
|
||||
const userLevel = member ? ROLE_HIERARCHY[member.role] || 0 : 0
|
||||
if (userLevel < requiredLevel) {
|
||||
throw new Error(
|
||||
`Permission denied: Insufficient role to load skill "${skill.name}". Minimum required role is "${skill.permission}".`,
|
||||
)
|
||||
}
|
||||
} else if (requiredLevel > 1) {
|
||||
throw new Error(
|
||||
`Permission denied: User context required to load skill "${skill.name}". Minimum required role is "${skill.permission}".`,
|
||||
)
|
||||
}
|
||||
|
||||
// Capture environment variables using agentService
|
||||
const envs = await agentService.getSkillEnvs(params.skillId)
|
||||
onEnvsAdded(envs)
|
||||
|
||||
// Retrieve skill content using agentService
|
||||
const skillMdContent = await agentService.getSkillContent(params.skillId)
|
||||
|
||||
return {
|
||||
content: [{ type: 'text', text: skillMdContent }],
|
||||
details: { skillId: params.skillId },
|
||||
}
|
||||
},
|
||||
})
|
||||
|
||||
@@ -26,118 +26,95 @@ export function createScreenshotTool(
|
||||
'Takes screenshots for a video at specified interval. It returns the images to the agent context.',
|
||||
parameters: screenshotSchema,
|
||||
execute: async (_toolCallId, params) => {
|
||||
try {
|
||||
const assetId = params.assetId
|
||||
const assetId = params.assetId
|
||||
|
||||
if (!userId) {
|
||||
return {
|
||||
content: [{ type: 'text', text: 'User ID is required for authorization.' }],
|
||||
details: {},
|
||||
}
|
||||
}
|
||||
if (!userId) {
|
||||
throw new Error('User ID is required for authorization.')
|
||||
}
|
||||
|
||||
await authzService.hasPermission({
|
||||
user: { id: userId } as User,
|
||||
permission: Permission.Read,
|
||||
type: ResourceType.Asset,
|
||||
id: assetId,
|
||||
await authzService.hasPermission({
|
||||
user: { id: userId } as User,
|
||||
permission: Permission.Read,
|
||||
type: ResourceType.Asset,
|
||||
id: assetId,
|
||||
})
|
||||
|
||||
const asset = await prisma.asset.findUnique({
|
||||
where: { id: assetId },
|
||||
})
|
||||
|
||||
if (!asset) {
|
||||
throw new Error(`Asset with ID ${assetId} not found.`)
|
||||
}
|
||||
|
||||
// Fetch trigger comment details for timestamp and annotations
|
||||
let commentTimestamp: number | null = null
|
||||
let annotations: unknown = null
|
||||
if (userCommentId) {
|
||||
const comment = await prisma.assetComment.findUnique({
|
||||
where: { id: userCommentId },
|
||||
})
|
||||
|
||||
const asset = await prisma.asset.findUnique({
|
||||
where: { id: assetId },
|
||||
})
|
||||
|
||||
if (!asset) {
|
||||
return {
|
||||
content: [{ type: 'text', text: `Asset with ID ${assetId} not found.` }],
|
||||
details: {},
|
||||
}
|
||||
}
|
||||
|
||||
// Fetch trigger comment details for timestamp and annotations
|
||||
let commentTimestamp: number | null = null
|
||||
let annotations: unknown = null
|
||||
if (userCommentId) {
|
||||
const comment = await prisma.assetComment.findUnique({
|
||||
where: { id: userCommentId },
|
||||
})
|
||||
if (comment && comment.assetId === assetId) {
|
||||
commentTimestamp = comment.second !== null ? comment.second : null
|
||||
if (comment.annotation) {
|
||||
const list = comment.annotation
|
||||
if (Array.isArray(list) && list.length > 0) {
|
||||
annotations = list
|
||||
}
|
||||
if (comment && comment.assetId === assetId) {
|
||||
commentTimestamp = comment.second !== null ? comment.second : null
|
||||
if (comment.annotation) {
|
||||
const list = comment.annotation
|
||||
if (Array.isArray(list) && list.length > 0) {
|
||||
annotations = list
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Trigger transcode workflow to take screenshots
|
||||
const task = await prisma.workflowTask.create({
|
||||
data: {
|
||||
assetId,
|
||||
// Trigger transcode workflow to take screenshots
|
||||
const task = await prisma.workflowTask.create({
|
||||
data: {
|
||||
assetId,
|
||||
projectId: asset.projectId || 'none',
|
||||
type: WorkflowTaskType.transcode_screenshot,
|
||||
status: WorkflowTaskStatus.pending,
|
||||
payload: {
|
||||
projectId: asset.projectId || 'none',
|
||||
type: WorkflowTaskType.transcode_screenshot,
|
||||
status: WorkflowTaskStatus.pending,
|
||||
payload: {
|
||||
projectId: asset.projectId || 'none',
|
||||
screenshot: {
|
||||
start: params.start,
|
||||
end: params.end,
|
||||
count: params.count,
|
||||
commentTimestamp,
|
||||
annotations: annotations as PrismaJson.AnnotationList,
|
||||
},
|
||||
screenshot: {
|
||||
start: params.start,
|
||||
end: params.end,
|
||||
count: params.count,
|
||||
commentTimestamp,
|
||||
annotations: annotations as PrismaJson.AnnotationList,
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
const completedTask = await workflowService.executeWait(task)
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
const output = completedTask.output as any
|
||||
const screenshots = output?.screenshots as
|
||||
| Array<{ key: string; timestamp: number }>
|
||||
| undefined
|
||||
|
||||
if (!screenshots || screenshots.length === 0) {
|
||||
throw new Error('No screenshots were generated.')
|
||||
}
|
||||
|
||||
const content: ImageContent[] = []
|
||||
const sourceKeys: string[] = []
|
||||
const bucket = process.env.S3_BUCKET || 'shumai'
|
||||
|
||||
for (const shot of screenshots) {
|
||||
const { buffer, contentType } = await s3Service.getObject(bucket, shot.key)
|
||||
content.push({
|
||||
type: 'image',
|
||||
data: buffer.toString('base64'),
|
||||
mimeType: contentType || 'image/webp',
|
||||
})
|
||||
sourceKeys.push(shot.key)
|
||||
}
|
||||
|
||||
const completedTask = await workflowService.executeWait(task)
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
const output = completedTask.output as any
|
||||
const screenshots = output?.screenshots as
|
||||
| Array<{ key: string; timestamp: number }>
|
||||
| undefined
|
||||
|
||||
if (!screenshots || screenshots.length === 0) {
|
||||
return {
|
||||
content: [{ type: 'text', text: 'No screenshots were generated.' }],
|
||||
details: {},
|
||||
}
|
||||
}
|
||||
|
||||
const content: ImageContent[] = []
|
||||
const sourceKeys: string[] = []
|
||||
const bucket = process.env.S3_BUCKET || 'shumai'
|
||||
|
||||
for (const shot of screenshots) {
|
||||
const { buffer, contentType } = await s3Service.getObject(bucket, shot.key)
|
||||
content.push({
|
||||
type: 'image',
|
||||
data: buffer.toString('base64'),
|
||||
mimeType: contentType || 'image/webp',
|
||||
})
|
||||
sourceKeys.push(shot.key)
|
||||
}
|
||||
|
||||
return {
|
||||
content,
|
||||
details: {
|
||||
sourceKeys,
|
||||
},
|
||||
}
|
||||
} catch (error) {
|
||||
return {
|
||||
content: [
|
||||
{
|
||||
type: 'text',
|
||||
text: `Error taking screenshots: ${
|
||||
error instanceof Error ? error.message : String(error)
|
||||
}`,
|
||||
},
|
||||
],
|
||||
details: {},
|
||||
}
|
||||
return {
|
||||
content,
|
||||
details: {
|
||||
sourceKeys,
|
||||
},
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
@@ -47,6 +47,7 @@ describe('Skill API', () => {
|
||||
config: null,
|
||||
assetId: 'asset1',
|
||||
hash: 'hash1',
|
||||
permission: 'reviewer' as const,
|
||||
createdAt: new Date().toISOString(),
|
||||
updatedAt: new Date().toISOString(),
|
||||
},
|
||||
@@ -79,6 +80,7 @@ describe('Skill API', () => {
|
||||
config: null,
|
||||
assetId: 'asset1',
|
||||
hash: 'hash1',
|
||||
permission: 'reviewer' as const,
|
||||
createdAt: new Date().toISOString(),
|
||||
updatedAt: new Date().toISOString(),
|
||||
}
|
||||
@@ -110,6 +112,7 @@ describe('Skill API', () => {
|
||||
config: null,
|
||||
assetId: 'asset1',
|
||||
hash: 'hash1',
|
||||
permission: 'reviewer' as const,
|
||||
createdAt: new Date().toISOString(),
|
||||
updatedAt: new Date().toISOString(),
|
||||
}
|
||||
@@ -174,6 +177,7 @@ describe('Skill API', () => {
|
||||
config: mockConfig,
|
||||
assetId: 'asset1',
|
||||
hash: 'hash1',
|
||||
permission: 'reviewer' as const,
|
||||
createdAt: new Date().toISOString(),
|
||||
updatedAt: new Date().toISOString(),
|
||||
}
|
||||
@@ -197,4 +201,38 @@ describe('Skill API', () => {
|
||||
expect(skillService.updateSkillConfig).toHaveBeenCalledWith('skill1', mockConfig)
|
||||
})
|
||||
})
|
||||
|
||||
describe('PATCH /skills/:id/permission', () => {
|
||||
test('Success', async () => {
|
||||
const mockSkill = {
|
||||
id: 'skill1',
|
||||
name: 'Skill 1',
|
||||
description: 'Desc 1',
|
||||
config: null,
|
||||
assetId: 'asset1',
|
||||
hash: 'hash1',
|
||||
permission: 'owner' as const,
|
||||
createdAt: new Date().toISOString(),
|
||||
updatedAt: new Date().toISOString(),
|
||||
}
|
||||
vi.spyOn(skillService, 'updateSkillPermission').mockResolvedValue(mockSkill)
|
||||
|
||||
const res = await app.request('/skills/skill1/permission', {
|
||||
method: 'PATCH',
|
||||
headers: { 'Content-Type': 'application/json', Authorization: 'Bearer test' },
|
||||
body: JSON.stringify({ permission: 'owner' }),
|
||||
})
|
||||
|
||||
expect(res.status).toBe(200)
|
||||
expect(await res.json()).toEqual(mockSkill)
|
||||
expect(authzService.hasPermission).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
type: ResourceType.Skill,
|
||||
id: 'skill1',
|
||||
permission: Permission.Admin,
|
||||
}),
|
||||
)
|
||||
expect(skillService.updateSkillPermission).toHaveBeenCalledWith('skill1', 'owner')
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -2,7 +2,11 @@ import { Hono } from 'hono'
|
||||
import { zValidator } from '@hono/zod-validator'
|
||||
import { authzService, Permission, ResourceType } from '@shumai/core/src/authz/authz'
|
||||
import { skillService } from '@shumai/core/src/skill/skill'
|
||||
import { upsertSkillRequestSchema, updateSkillConfigRequestSchema } from '@shumai/dtos'
|
||||
import {
|
||||
upsertSkillRequestSchema,
|
||||
updateSkillConfigRequestSchema,
|
||||
updateSkillPermissionRequestSchema,
|
||||
} from '@shumai/dtos'
|
||||
import type { Prisma } from '@shumai/db'
|
||||
|
||||
type User = Prisma.UserGetPayload<Record<string, never>>
|
||||
@@ -73,5 +77,24 @@ const route = new Hono<{ Variables: { user: User } }>()
|
||||
const skill = await skillService.updateSkillConfig(id, req.config)
|
||||
return c.json(skill)
|
||||
})
|
||||
.patch(
|
||||
'/skills/:id/permission',
|
||||
zValidator('json', updateSkillPermissionRequestSchema),
|
||||
async (c) => {
|
||||
const user = c.get('user')
|
||||
const id = c.req.param('id')
|
||||
const req = c.req.valid('json')
|
||||
|
||||
await authzService.hasPermission({
|
||||
user,
|
||||
permission: Permission.Admin,
|
||||
type: ResourceType.Skill,
|
||||
id,
|
||||
})
|
||||
|
||||
const skill = await skillService.updateSkillPermission(id, req.permission)
|
||||
return c.json(skill)
|
||||
},
|
||||
)
|
||||
|
||||
export default route
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { prisma } from '@shumai/db'
|
||||
import { prisma, type TeamMemberRole } from '@shumai/db'
|
||||
import { SkillInfo, UpsertSkillRequest } from '@shumai/dtos'
|
||||
import { s3Service } from '@shumai/core/src/s3/s3'
|
||||
import AdmZip from 'adm-zip'
|
||||
@@ -125,6 +125,14 @@ export class SkillService {
|
||||
return this.toSkillInfo(skill)
|
||||
}
|
||||
|
||||
async updateSkillPermission(id: string, permission: TeamMemberRole): Promise<SkillInfo> {
|
||||
const skill = await this.prismaClient.skill.update({
|
||||
where: { id },
|
||||
data: { permission },
|
||||
})
|
||||
return this.toSkillInfo(skill)
|
||||
}
|
||||
|
||||
async listSkills(teamId: string): Promise<SkillInfo[]> {
|
||||
const skills = await this.prismaClient.skill.findMany({
|
||||
where: { teamId },
|
||||
@@ -276,6 +284,7 @@ export class SkillService {
|
||||
config: s.config as PrismaJson.SkillConfig,
|
||||
assetId: s.assetId,
|
||||
hash: s.hash,
|
||||
permission: s.permission || 'reviewer',
|
||||
createdAt: s.createdAt.toISOString(),
|
||||
updatedAt: s.updatedAt.toISOString(),
|
||||
}
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
-- AlterTable
|
||||
ALTER TABLE "skills" ADD COLUMN "permission" "TeamMemberRole" NOT NULL DEFAULT 'reviewer';
|
||||
@@ -262,6 +262,7 @@ model Skill {
|
||||
config Json? @default("{}")
|
||||
assetId String @map("asset_id")
|
||||
hash String @map("hash")
|
||||
permission TeamMemberRole @default(reviewer)
|
||||
createdAt DateTime @default(now()) @map("created_at")
|
||||
updatedAt DateTime @updatedAt @map("updated_at")
|
||||
|
||||
|
||||
+14
-14
@@ -223,13 +223,6 @@ export type EnumTeamMemberRoleFilter<$PrismaModel = never> = {
|
||||
not?: Prisma.NestedEnumTeamMemberRoleFilter<$PrismaModel> | $Enums.TeamMemberRole
|
||||
}
|
||||
|
||||
export type EnumTeamMemberScopeFilter<$PrismaModel = never> = {
|
||||
equals?: $Enums.TeamMemberScope | Prisma.EnumTeamMemberScopeFieldRefInput<$PrismaModel>
|
||||
in?: $Enums.TeamMemberScope[] | Prisma.ListEnumTeamMemberScopeFieldRefInput<$PrismaModel>
|
||||
notIn?: $Enums.TeamMemberScope[] | Prisma.ListEnumTeamMemberScopeFieldRefInput<$PrismaModel>
|
||||
not?: Prisma.NestedEnumTeamMemberScopeFilter<$PrismaModel> | $Enums.TeamMemberScope
|
||||
}
|
||||
|
||||
export type EnumTeamMemberRoleWithAggregatesFilter<$PrismaModel = never> = {
|
||||
equals?: $Enums.TeamMemberRole | Prisma.EnumTeamMemberRoleFieldRefInput<$PrismaModel>
|
||||
in?: $Enums.TeamMemberRole[] | Prisma.ListEnumTeamMemberRoleFieldRefInput<$PrismaModel>
|
||||
@@ -240,6 +233,13 @@ export type EnumTeamMemberRoleWithAggregatesFilter<$PrismaModel = never> = {
|
||||
_max?: Prisma.NestedEnumTeamMemberRoleFilter<$PrismaModel>
|
||||
}
|
||||
|
||||
export type EnumTeamMemberScopeFilter<$PrismaModel = never> = {
|
||||
equals?: $Enums.TeamMemberScope | Prisma.EnumTeamMemberScopeFieldRefInput<$PrismaModel>
|
||||
in?: $Enums.TeamMemberScope[] | Prisma.ListEnumTeamMemberScopeFieldRefInput<$PrismaModel>
|
||||
notIn?: $Enums.TeamMemberScope[] | Prisma.ListEnumTeamMemberScopeFieldRefInput<$PrismaModel>
|
||||
not?: Prisma.NestedEnumTeamMemberScopeFilter<$PrismaModel> | $Enums.TeamMemberScope
|
||||
}
|
||||
|
||||
export type EnumTeamMemberScopeWithAggregatesFilter<$PrismaModel = never> = {
|
||||
equals?: $Enums.TeamMemberScope | Prisma.EnumTeamMemberScopeFieldRefInput<$PrismaModel>
|
||||
in?: $Enums.TeamMemberScope[] | Prisma.ListEnumTeamMemberScopeFieldRefInput<$PrismaModel>
|
||||
@@ -838,13 +838,6 @@ export type NestedEnumTeamMemberRoleFilter<$PrismaModel = never> = {
|
||||
not?: Prisma.NestedEnumTeamMemberRoleFilter<$PrismaModel> | $Enums.TeamMemberRole
|
||||
}
|
||||
|
||||
export type NestedEnumTeamMemberScopeFilter<$PrismaModel = never> = {
|
||||
equals?: $Enums.TeamMemberScope | Prisma.EnumTeamMemberScopeFieldRefInput<$PrismaModel>
|
||||
in?: $Enums.TeamMemberScope[] | Prisma.ListEnumTeamMemberScopeFieldRefInput<$PrismaModel>
|
||||
notIn?: $Enums.TeamMemberScope[] | Prisma.ListEnumTeamMemberScopeFieldRefInput<$PrismaModel>
|
||||
not?: Prisma.NestedEnumTeamMemberScopeFilter<$PrismaModel> | $Enums.TeamMemberScope
|
||||
}
|
||||
|
||||
export type NestedEnumTeamMemberRoleWithAggregatesFilter<$PrismaModel = never> = {
|
||||
equals?: $Enums.TeamMemberRole | Prisma.EnumTeamMemberRoleFieldRefInput<$PrismaModel>
|
||||
in?: $Enums.TeamMemberRole[] | Prisma.ListEnumTeamMemberRoleFieldRefInput<$PrismaModel>
|
||||
@@ -855,6 +848,13 @@ export type NestedEnumTeamMemberRoleWithAggregatesFilter<$PrismaModel = never> =
|
||||
_max?: Prisma.NestedEnumTeamMemberRoleFilter<$PrismaModel>
|
||||
}
|
||||
|
||||
export type NestedEnumTeamMemberScopeFilter<$PrismaModel = never> = {
|
||||
equals?: $Enums.TeamMemberScope | Prisma.EnumTeamMemberScopeFieldRefInput<$PrismaModel>
|
||||
in?: $Enums.TeamMemberScope[] | Prisma.ListEnumTeamMemberScopeFieldRefInput<$PrismaModel>
|
||||
notIn?: $Enums.TeamMemberScope[] | Prisma.ListEnumTeamMemberScopeFieldRefInput<$PrismaModel>
|
||||
not?: Prisma.NestedEnumTeamMemberScopeFilter<$PrismaModel> | $Enums.TeamMemberScope
|
||||
}
|
||||
|
||||
export type NestedEnumTeamMemberScopeWithAggregatesFilter<$PrismaModel = never> = {
|
||||
equals?: $Enums.TeamMemberScope | Prisma.EnumTeamMemberScopeFieldRefInput<$PrismaModel>
|
||||
in?: $Enums.TeamMemberScope[] | Prisma.ListEnumTeamMemberScopeFieldRefInput<$PrismaModel>
|
||||
|
||||
+4
-4
File diff suppressed because one or more lines are too long
@@ -3022,6 +3022,7 @@ export const SkillScalarFieldEnum = {
|
||||
config: 'config',
|
||||
assetId: 'assetId',
|
||||
hash: 'hash',
|
||||
permission: 'permission',
|
||||
createdAt: 'createdAt',
|
||||
updatedAt: 'updatedAt',
|
||||
teamId: 'teamId'
|
||||
|
||||
@@ -207,6 +207,7 @@ export const SkillScalarFieldEnum = {
|
||||
config: 'config',
|
||||
assetId: 'assetId',
|
||||
hash: 'hash',
|
||||
permission: 'permission',
|
||||
createdAt: 'createdAt',
|
||||
updatedAt: 'updatedAt',
|
||||
teamId: 'teamId'
|
||||
|
||||
+44
-1
@@ -32,6 +32,7 @@ export type SkillMinAggregateOutputType = {
|
||||
description: string | null
|
||||
assetId: string | null
|
||||
hash: string | null
|
||||
permission: $Enums.TeamMemberRole | null
|
||||
createdAt: Date | null
|
||||
updatedAt: Date | null
|
||||
teamId: string | null
|
||||
@@ -43,6 +44,7 @@ export type SkillMaxAggregateOutputType = {
|
||||
description: string | null
|
||||
assetId: string | null
|
||||
hash: string | null
|
||||
permission: $Enums.TeamMemberRole | null
|
||||
createdAt: Date | null
|
||||
updatedAt: Date | null
|
||||
teamId: string | null
|
||||
@@ -55,6 +57,7 @@ export type SkillCountAggregateOutputType = {
|
||||
config:PrismaJson.SkillConfig
|
||||
assetId: number
|
||||
hash: number
|
||||
permission: number
|
||||
createdAt: number
|
||||
updatedAt: number
|
||||
teamId: number
|
||||
@@ -68,6 +71,7 @@ export type SkillMinAggregateInputType = {
|
||||
description?: true
|
||||
assetId?: true
|
||||
hash?: true
|
||||
permission?: true
|
||||
createdAt?: true
|
||||
updatedAt?: true
|
||||
teamId?: true
|
||||
@@ -79,6 +83,7 @@ export type SkillMaxAggregateInputType = {
|
||||
description?: true
|
||||
assetId?: true
|
||||
hash?: true
|
||||
permission?: true
|
||||
createdAt?: true
|
||||
updatedAt?: true
|
||||
teamId?: true
|
||||
@@ -91,6 +96,7 @@ export type SkillCountAggregateInputType = {
|
||||
config?: true
|
||||
assetId?: true
|
||||
hash?: true
|
||||
permission?: true
|
||||
createdAt?: true
|
||||
updatedAt?: true
|
||||
teamId?: true
|
||||
@@ -176,6 +182,7 @@ export type SkillGroupByOutputType = {
|
||||
config:PrismaJson.SkillConfig | null
|
||||
assetId: string
|
||||
hash: string
|
||||
permission: $Enums.TeamMemberRole
|
||||
createdAt: Date
|
||||
updatedAt: Date
|
||||
teamId: string
|
||||
@@ -209,6 +216,7 @@ export type SkillWhereInput = {
|
||||
config?: Prisma.JsonNullableFilter<"Skill">
|
||||
assetId?: Prisma.StringFilter<"Skill"> | string
|
||||
hash?: Prisma.StringFilter<"Skill"> | string
|
||||
permission?: Prisma.EnumTeamMemberRoleFilter<"Skill"> | $Enums.TeamMemberRole
|
||||
createdAt?: Prisma.DateTimeFilter<"Skill"> | Date | string
|
||||
updatedAt?: Prisma.DateTimeFilter<"Skill"> | Date | string
|
||||
teamId?: Prisma.StringFilter<"Skill"> | string
|
||||
@@ -223,6 +231,7 @@ export type SkillOrderByWithRelationInput = {
|
||||
config?: Prisma.SortOrderInput | Prisma.SortOrder
|
||||
assetId?: Prisma.SortOrder
|
||||
hash?: Prisma.SortOrder
|
||||
permission?: Prisma.SortOrder
|
||||
createdAt?: Prisma.SortOrder
|
||||
updatedAt?: Prisma.SortOrder
|
||||
teamId?: Prisma.SortOrder
|
||||
@@ -241,6 +250,7 @@ export type SkillWhereUniqueInput = Prisma.AtLeast<{
|
||||
config?: Prisma.JsonNullableFilter<"Skill">
|
||||
assetId?: Prisma.StringFilter<"Skill"> | string
|
||||
hash?: Prisma.StringFilter<"Skill"> | string
|
||||
permission?: Prisma.EnumTeamMemberRoleFilter<"Skill"> | $Enums.TeamMemberRole
|
||||
createdAt?: Prisma.DateTimeFilter<"Skill"> | Date | string
|
||||
updatedAt?: Prisma.DateTimeFilter<"Skill"> | Date | string
|
||||
teamId?: Prisma.StringFilter<"Skill"> | string
|
||||
@@ -255,6 +265,7 @@ export type SkillOrderByWithAggregationInput = {
|
||||
config?: Prisma.SortOrderInput | Prisma.SortOrder
|
||||
assetId?: Prisma.SortOrder
|
||||
hash?: Prisma.SortOrder
|
||||
permission?: Prisma.SortOrder
|
||||
createdAt?: Prisma.SortOrder
|
||||
updatedAt?: Prisma.SortOrder
|
||||
teamId?: Prisma.SortOrder
|
||||
@@ -273,6 +284,7 @@ export type SkillScalarWhereWithAggregatesInput = {
|
||||
config?: Prisma.JsonNullableWithAggregatesFilter<"Skill">
|
||||
assetId?: Prisma.StringWithAggregatesFilter<"Skill"> | string
|
||||
hash?: Prisma.StringWithAggregatesFilter<"Skill"> | string
|
||||
permission?: Prisma.EnumTeamMemberRoleWithAggregatesFilter<"Skill"> | $Enums.TeamMemberRole
|
||||
createdAt?: Prisma.DateTimeWithAggregatesFilter<"Skill"> | Date | string
|
||||
updatedAt?: Prisma.DateTimeWithAggregatesFilter<"Skill"> | Date | string
|
||||
teamId?: Prisma.StringWithAggregatesFilter<"Skill"> | string
|
||||
@@ -285,6 +297,7 @@ export type SkillCreateInput = {
|
||||
config?:PrismaJson.SkillConfig | Prisma.NullableJsonNullValueInput
|
||||
assetId: string
|
||||
hash: string
|
||||
permission?: $Enums.TeamMemberRole
|
||||
createdAt?: Date | string
|
||||
updatedAt?: Date | string
|
||||
team: Prisma.TeamCreateNestedOneWithoutSkillsInput
|
||||
@@ -298,6 +311,7 @@ export type SkillUncheckedCreateInput = {
|
||||
config?:PrismaJson.SkillConfig | Prisma.NullableJsonNullValueInput
|
||||
assetId: string
|
||||
hash: string
|
||||
permission?: $Enums.TeamMemberRole
|
||||
createdAt?: Date | string
|
||||
updatedAt?: Date | string
|
||||
teamId: string
|
||||
@@ -311,6 +325,7 @@ export type SkillUpdateInput = {
|
||||
config?:PrismaJson.SkillConfig | Prisma.NullableJsonNullValueInput
|
||||
assetId?: Prisma.StringFieldUpdateOperationsInput | string
|
||||
hash?: Prisma.StringFieldUpdateOperationsInput | string
|
||||
permission?: Prisma.EnumTeamMemberRoleFieldUpdateOperationsInput | $Enums.TeamMemberRole
|
||||
createdAt?: Prisma.DateTimeFieldUpdateOperationsInput | Date | string
|
||||
updatedAt?: Prisma.DateTimeFieldUpdateOperationsInput | Date | string
|
||||
team?: Prisma.TeamUpdateOneRequiredWithoutSkillsNestedInput
|
||||
@@ -324,6 +339,7 @@ export type SkillUncheckedUpdateInput = {
|
||||
config?:PrismaJson.SkillConfig | Prisma.NullableJsonNullValueInput
|
||||
assetId?: Prisma.StringFieldUpdateOperationsInput | string
|
||||
hash?: Prisma.StringFieldUpdateOperationsInput | string
|
||||
permission?: Prisma.EnumTeamMemberRoleFieldUpdateOperationsInput | $Enums.TeamMemberRole
|
||||
createdAt?: Prisma.DateTimeFieldUpdateOperationsInput | Date | string
|
||||
updatedAt?: Prisma.DateTimeFieldUpdateOperationsInput | Date | string
|
||||
teamId?: Prisma.StringFieldUpdateOperationsInput | string
|
||||
@@ -337,6 +353,7 @@ export type SkillCreateManyInput = {
|
||||
config?:PrismaJson.SkillConfig | Prisma.NullableJsonNullValueInput
|
||||
assetId: string
|
||||
hash: string
|
||||
permission?: $Enums.TeamMemberRole
|
||||
createdAt?: Date | string
|
||||
updatedAt?: Date | string
|
||||
teamId: string
|
||||
@@ -349,6 +366,7 @@ export type SkillUpdateManyMutationInput = {
|
||||
config?:PrismaJson.SkillConfig | Prisma.NullableJsonNullValueInput
|
||||
assetId?: Prisma.StringFieldUpdateOperationsInput | string
|
||||
hash?: Prisma.StringFieldUpdateOperationsInput | string
|
||||
permission?: Prisma.EnumTeamMemberRoleFieldUpdateOperationsInput | $Enums.TeamMemberRole
|
||||
createdAt?: Prisma.DateTimeFieldUpdateOperationsInput | Date | string
|
||||
updatedAt?: Prisma.DateTimeFieldUpdateOperationsInput | Date | string
|
||||
}
|
||||
@@ -360,6 +378,7 @@ export type SkillUncheckedUpdateManyInput = {
|
||||
config?:PrismaJson.SkillConfig | Prisma.NullableJsonNullValueInput
|
||||
assetId?: Prisma.StringFieldUpdateOperationsInput | string
|
||||
hash?: Prisma.StringFieldUpdateOperationsInput | string
|
||||
permission?: Prisma.EnumTeamMemberRoleFieldUpdateOperationsInput | $Enums.TeamMemberRole
|
||||
createdAt?: Prisma.DateTimeFieldUpdateOperationsInput | Date | string
|
||||
updatedAt?: Prisma.DateTimeFieldUpdateOperationsInput | Date | string
|
||||
teamId?: Prisma.StringFieldUpdateOperationsInput | string
|
||||
@@ -387,6 +406,7 @@ export type SkillCountOrderByAggregateInput = {
|
||||
config?: Prisma.SortOrder
|
||||
assetId?: Prisma.SortOrder
|
||||
hash?: Prisma.SortOrder
|
||||
permission?: Prisma.SortOrder
|
||||
createdAt?: Prisma.SortOrder
|
||||
updatedAt?: Prisma.SortOrder
|
||||
teamId?: Prisma.SortOrder
|
||||
@@ -398,6 +418,7 @@ export type SkillMaxOrderByAggregateInput = {
|
||||
description?: Prisma.SortOrder
|
||||
assetId?: Prisma.SortOrder
|
||||
hash?: Prisma.SortOrder
|
||||
permission?: Prisma.SortOrder
|
||||
createdAt?: Prisma.SortOrder
|
||||
updatedAt?: Prisma.SortOrder
|
||||
teamId?: Prisma.SortOrder
|
||||
@@ -409,6 +430,7 @@ export type SkillMinOrderByAggregateInput = {
|
||||
description?: Prisma.SortOrder
|
||||
assetId?: Prisma.SortOrder
|
||||
hash?: Prisma.SortOrder
|
||||
permission?: Prisma.SortOrder
|
||||
createdAt?: Prisma.SortOrder
|
||||
updatedAt?: Prisma.SortOrder
|
||||
teamId?: Prisma.SortOrder
|
||||
@@ -461,6 +483,10 @@ export type SkillUncheckedUpdateManyWithoutTeamNestedInput = {
|
||||
deleteMany?: Prisma.SkillScalarWhereInput | Prisma.SkillScalarWhereInput[]
|
||||
}
|
||||
|
||||
export type EnumTeamMemberRoleFieldUpdateOperationsInput = {
|
||||
set?: $Enums.TeamMemberRole
|
||||
}
|
||||
|
||||
export type SkillCreateNestedOneWithoutAgentSkillsInput = {
|
||||
create?: Prisma.XOR<Prisma.SkillCreateWithoutAgentSkillsInput, Prisma.SkillUncheckedCreateWithoutAgentSkillsInput>
|
||||
connectOrCreate?: Prisma.SkillCreateOrConnectWithoutAgentSkillsInput
|
||||
@@ -482,6 +508,7 @@ export type SkillCreateWithoutTeamInput = {
|
||||
config?:PrismaJson.SkillConfig | Prisma.NullableJsonNullValueInput
|
||||
assetId: string
|
||||
hash: string
|
||||
permission?: $Enums.TeamMemberRole
|
||||
createdAt?: Date | string
|
||||
updatedAt?: Date | string
|
||||
agentSkills?: Prisma.AgentSkillCreateNestedManyWithoutSkillInput
|
||||
@@ -494,6 +521,7 @@ export type SkillUncheckedCreateWithoutTeamInput = {
|
||||
config?:PrismaJson.SkillConfig | Prisma.NullableJsonNullValueInput
|
||||
assetId: string
|
||||
hash: string
|
||||
permission?: $Enums.TeamMemberRole
|
||||
createdAt?: Date | string
|
||||
updatedAt?: Date | string
|
||||
agentSkills?: Prisma.AgentSkillUncheckedCreateNestedManyWithoutSkillInput
|
||||
@@ -535,6 +563,7 @@ export type SkillScalarWhereInput = {
|
||||
config?: Prisma.JsonNullableFilter<"Skill">
|
||||
assetId?: Prisma.StringFilter<"Skill"> | string
|
||||
hash?: Prisma.StringFilter<"Skill"> | string
|
||||
permission?: Prisma.EnumTeamMemberRoleFilter<"Skill"> | $Enums.TeamMemberRole
|
||||
createdAt?: Prisma.DateTimeFilter<"Skill"> | Date | string
|
||||
updatedAt?: Prisma.DateTimeFilter<"Skill"> | Date | string
|
||||
teamId?: Prisma.StringFilter<"Skill"> | string
|
||||
@@ -547,6 +576,7 @@ export type SkillCreateWithoutAgentSkillsInput = {
|
||||
config?:PrismaJson.SkillConfig | Prisma.NullableJsonNullValueInput
|
||||
assetId: string
|
||||
hash: string
|
||||
permission?: $Enums.TeamMemberRole
|
||||
createdAt?: Date | string
|
||||
updatedAt?: Date | string
|
||||
team: Prisma.TeamCreateNestedOneWithoutSkillsInput
|
||||
@@ -559,6 +589,7 @@ export type SkillUncheckedCreateWithoutAgentSkillsInput = {
|
||||
config?:PrismaJson.SkillConfig | Prisma.NullableJsonNullValueInput
|
||||
assetId: string
|
||||
hash: string
|
||||
permission?: $Enums.TeamMemberRole
|
||||
createdAt?: Date | string
|
||||
updatedAt?: Date | string
|
||||
teamId: string
|
||||
@@ -587,6 +618,7 @@ export type SkillUpdateWithoutAgentSkillsInput = {
|
||||
config?:PrismaJson.SkillConfig | Prisma.NullableJsonNullValueInput
|
||||
assetId?: Prisma.StringFieldUpdateOperationsInput | string
|
||||
hash?: Prisma.StringFieldUpdateOperationsInput | string
|
||||
permission?: Prisma.EnumTeamMemberRoleFieldUpdateOperationsInput | $Enums.TeamMemberRole
|
||||
createdAt?: Prisma.DateTimeFieldUpdateOperationsInput | Date | string
|
||||
updatedAt?: Prisma.DateTimeFieldUpdateOperationsInput | Date | string
|
||||
team?: Prisma.TeamUpdateOneRequiredWithoutSkillsNestedInput
|
||||
@@ -599,6 +631,7 @@ export type SkillUncheckedUpdateWithoutAgentSkillsInput = {
|
||||
config?:PrismaJson.SkillConfig | Prisma.NullableJsonNullValueInput
|
||||
assetId?: Prisma.StringFieldUpdateOperationsInput | string
|
||||
hash?: Prisma.StringFieldUpdateOperationsInput | string
|
||||
permission?: Prisma.EnumTeamMemberRoleFieldUpdateOperationsInput | $Enums.TeamMemberRole
|
||||
createdAt?: Prisma.DateTimeFieldUpdateOperationsInput | Date | string
|
||||
updatedAt?: Prisma.DateTimeFieldUpdateOperationsInput | Date | string
|
||||
teamId?: Prisma.StringFieldUpdateOperationsInput | string
|
||||
@@ -611,6 +644,7 @@ export type SkillCreateManyTeamInput = {
|
||||
config?:PrismaJson.SkillConfig | Prisma.NullableJsonNullValueInput
|
||||
assetId: string
|
||||
hash: string
|
||||
permission?: $Enums.TeamMemberRole
|
||||
createdAt?: Date | string
|
||||
updatedAt?: Date | string
|
||||
}
|
||||
@@ -622,6 +656,7 @@ export type SkillUpdateWithoutTeamInput = {
|
||||
config?:PrismaJson.SkillConfig | Prisma.NullableJsonNullValueInput
|
||||
assetId?: Prisma.StringFieldUpdateOperationsInput | string
|
||||
hash?: Prisma.StringFieldUpdateOperationsInput | string
|
||||
permission?: Prisma.EnumTeamMemberRoleFieldUpdateOperationsInput | $Enums.TeamMemberRole
|
||||
createdAt?: Prisma.DateTimeFieldUpdateOperationsInput | Date | string
|
||||
updatedAt?: Prisma.DateTimeFieldUpdateOperationsInput | Date | string
|
||||
agentSkills?: Prisma.AgentSkillUpdateManyWithoutSkillNestedInput
|
||||
@@ -634,6 +669,7 @@ export type SkillUncheckedUpdateWithoutTeamInput = {
|
||||
config?:PrismaJson.SkillConfig | Prisma.NullableJsonNullValueInput
|
||||
assetId?: Prisma.StringFieldUpdateOperationsInput | string
|
||||
hash?: Prisma.StringFieldUpdateOperationsInput | string
|
||||
permission?: Prisma.EnumTeamMemberRoleFieldUpdateOperationsInput | $Enums.TeamMemberRole
|
||||
createdAt?: Prisma.DateTimeFieldUpdateOperationsInput | Date | string
|
||||
updatedAt?: Prisma.DateTimeFieldUpdateOperationsInput | Date | string
|
||||
agentSkills?: Prisma.AgentSkillUncheckedUpdateManyWithoutSkillNestedInput
|
||||
@@ -646,6 +682,7 @@ export type SkillUncheckedUpdateManyWithoutTeamInput = {
|
||||
config?:PrismaJson.SkillConfig | Prisma.NullableJsonNullValueInput
|
||||
assetId?: Prisma.StringFieldUpdateOperationsInput | string
|
||||
hash?: Prisma.StringFieldUpdateOperationsInput | string
|
||||
permission?: Prisma.EnumTeamMemberRoleFieldUpdateOperationsInput | $Enums.TeamMemberRole
|
||||
createdAt?: Prisma.DateTimeFieldUpdateOperationsInput | Date | string
|
||||
updatedAt?: Prisma.DateTimeFieldUpdateOperationsInput | Date | string
|
||||
}
|
||||
@@ -688,6 +725,7 @@ export type SkillSelect<ExtArgs extends runtime.Types.Extensions.InternalArgs =
|
||||
config?: boolean
|
||||
assetId?: boolean
|
||||
hash?: boolean
|
||||
permission?: boolean
|
||||
createdAt?: boolean
|
||||
updatedAt?: boolean
|
||||
teamId?: boolean
|
||||
@@ -703,6 +741,7 @@ export type SkillSelectCreateManyAndReturn<ExtArgs extends runtime.Types.Extensi
|
||||
config?: boolean
|
||||
assetId?: boolean
|
||||
hash?: boolean
|
||||
permission?: boolean
|
||||
createdAt?: boolean
|
||||
updatedAt?: boolean
|
||||
teamId?: boolean
|
||||
@@ -716,6 +755,7 @@ export type SkillSelectUpdateManyAndReturn<ExtArgs extends runtime.Types.Extensi
|
||||
config?: boolean
|
||||
assetId?: boolean
|
||||
hash?: boolean
|
||||
permission?: boolean
|
||||
createdAt?: boolean
|
||||
updatedAt?: boolean
|
||||
teamId?: boolean
|
||||
@@ -729,12 +769,13 @@ export type SkillSelectScalar = {
|
||||
config?: boolean
|
||||
assetId?: boolean
|
||||
hash?: boolean
|
||||
permission?: boolean
|
||||
createdAt?: boolean
|
||||
updatedAt?: boolean
|
||||
teamId?: boolean
|
||||
}
|
||||
|
||||
export type SkillOmit<ExtArgs extends runtime.Types.Extensions.InternalArgs = runtime.Types.Extensions.DefaultArgs> = runtime.Types.Extensions.GetOmit<"id" | "name" | "description" | "config" | "assetId" | "hash" | "createdAt" | "updatedAt" | "teamId", ExtArgs["result"]["skill"]>
|
||||
export type SkillOmit<ExtArgs extends runtime.Types.Extensions.InternalArgs = runtime.Types.Extensions.DefaultArgs> = runtime.Types.Extensions.GetOmit<"id" | "name" | "description" | "config" | "assetId" | "hash" | "permission" | "createdAt" | "updatedAt" | "teamId", ExtArgs["result"]["skill"]>
|
||||
export type SkillInclude<ExtArgs extends runtime.Types.Extensions.InternalArgs = runtime.Types.Extensions.DefaultArgs> = {
|
||||
team?: boolean | Prisma.TeamDefaultArgs<ExtArgs>
|
||||
agentSkills?: boolean | Prisma.Skill$agentSkillsArgs<ExtArgs>
|
||||
@@ -763,6 +804,7 @@ export type $SkillPayload<ExtArgs extends runtime.Types.Extensions.InternalArgs
|
||||
config:PrismaJson.SkillConfig | null
|
||||
assetId: string
|
||||
hash: string
|
||||
permission: $Enums.TeamMemberRole
|
||||
createdAt: Date
|
||||
updatedAt: Date
|
||||
teamId: string
|
||||
@@ -1197,6 +1239,7 @@ export interface SkillFieldRefs {
|
||||
readonly config: Prisma.FieldRef<"Skill", 'Json'>
|
||||
readonly assetId: Prisma.FieldRef<"Skill", 'String'>
|
||||
readonly hash: Prisma.FieldRef<"Skill", 'String'>
|
||||
readonly permission: Prisma.FieldRef<"Skill", 'TeamMemberRole'>
|
||||
readonly createdAt: Prisma.FieldRef<"Skill", 'DateTime'>
|
||||
readonly updatedAt: Prisma.FieldRef<"Skill", 'DateTime'>
|
||||
readonly teamId: Prisma.FieldRef<"Skill", 'String'>
|
||||
|
||||
@@ -452,10 +452,6 @@ export type TeamMemberUncheckedUpdateManyWithoutTeamNestedInput = {
|
||||
deleteMany?: Prisma.TeamMemberScalarWhereInput | Prisma.TeamMemberScalarWhereInput[]
|
||||
}
|
||||
|
||||
export type EnumTeamMemberRoleFieldUpdateOperationsInput = {
|
||||
set?: $Enums.TeamMemberRole
|
||||
}
|
||||
|
||||
export type EnumTeamMemberScopeFieldUpdateOperationsInput = {
|
||||
set?: $Enums.TeamMemberScope
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ export interface SkillInfo {
|
||||
config: SkillConfig | null
|
||||
assetId: string
|
||||
hash: string
|
||||
permission: 'owner' | 'editor' | 'reviewer'
|
||||
createdAt: string
|
||||
updatedAt: string
|
||||
}
|
||||
@@ -41,6 +42,12 @@ export const updateSkillConfigRequestSchema = z.object({
|
||||
|
||||
export type UpdateSkillConfigRequest = z.infer<typeof updateSkillConfigRequestSchema>
|
||||
|
||||
export const updateSkillPermissionRequestSchema = z.object({
|
||||
permission: z.enum(['owner', 'editor', 'reviewer']),
|
||||
})
|
||||
|
||||
export type UpdateSkillPermissionRequest = z.infer<typeof updateSkillPermissionRequestSchema>
|
||||
|
||||
export interface ListSkillsResponse {
|
||||
skills: SkillInfo[]
|
||||
}
|
||||
|
||||
@@ -34,6 +34,14 @@ import {
|
||||
} from '@/ui/components/ui/alert-dialog'
|
||||
import { SkillInfo } from '@shumai/dtos'
|
||||
import { m } from '@/ui/paraglide/messages.js'
|
||||
import { usePermissions } from '@/ui/hooks/use-permissions'
|
||||
import {
|
||||
Select,
|
||||
SelectContent,
|
||||
SelectItem,
|
||||
SelectTrigger,
|
||||
SelectValue,
|
||||
} from '@/ui/components/ui/select'
|
||||
|
||||
const Github = (props: React.SVGProps<SVGSVGElement>) => (
|
||||
<svg
|
||||
@@ -59,6 +67,7 @@ interface SkillsConfigCardProps {
|
||||
|
||||
export const SkillsConfigCard: React.FC<SkillsConfigCardProps> = ({ teamId }) => {
|
||||
const queryClient = useQueryClient()
|
||||
const { canAdmin } = usePermissions()
|
||||
const [isAddDialogOpen, setIsAddDialogOpen] = useState(false)
|
||||
const [isConfigDialogOpen, setIsConfigDialogOpen] = useState(false)
|
||||
const [isDeleteDialogOpen, setIsDeleteDialogOpen] = useState(false)
|
||||
@@ -88,6 +97,29 @@ export const SkillsConfigCard: React.FC<SkillsConfigCardProps> = ({ teamId }) =>
|
||||
},
|
||||
})
|
||||
|
||||
// Update Skill Permission
|
||||
const updatePermissionMutation = useMutation({
|
||||
mutationFn: async ({
|
||||
id,
|
||||
permission,
|
||||
}: {
|
||||
id: string
|
||||
permission: 'owner' | 'editor' | 'reviewer'
|
||||
}) => {
|
||||
const res = await client.api.skills[':id'].permission.$patch({
|
||||
param: { id },
|
||||
json: { permission },
|
||||
})
|
||||
if (!res.ok) throw new Error(m.failed_to_update_permission())
|
||||
},
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ['teams', teamId, 'skills'] })
|
||||
},
|
||||
onError: (err: Error) => {
|
||||
alert(err.message || m.failed_to_update_permission())
|
||||
},
|
||||
})
|
||||
|
||||
const skills = data?.skills || []
|
||||
|
||||
return (
|
||||
@@ -127,6 +159,7 @@ export const SkillsConfigCard: React.FC<SkillsConfigCardProps> = ({ teamId }) =>
|
||||
<SkillItem
|
||||
key={skill.id}
|
||||
skill={skill}
|
||||
canAdmin={canAdmin}
|
||||
onDelete={() => {
|
||||
setSelectedSkill(skill)
|
||||
setIsDeleteDialogOpen(true)
|
||||
@@ -135,6 +168,9 @@ export const SkillsConfigCard: React.FC<SkillsConfigCardProps> = ({ teamId }) =>
|
||||
setSelectedSkill(skill)
|
||||
setIsConfigDialogOpen(true)
|
||||
}}
|
||||
onPermissionChange={(permission) =>
|
||||
updatePermissionMutation.mutate({ id: skill.id, permission })
|
||||
}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
@@ -194,12 +230,16 @@ export const SkillsConfigCard: React.FC<SkillsConfigCardProps> = ({ teamId }) =>
|
||||
|
||||
const SkillItem = ({
|
||||
skill,
|
||||
canAdmin,
|
||||
onDelete,
|
||||
onConfigure,
|
||||
onPermissionChange,
|
||||
}: {
|
||||
skill: SkillInfo
|
||||
canAdmin: boolean
|
||||
onDelete: () => void
|
||||
onConfigure: () => void
|
||||
onPermissionChange: (permission: 'owner' | 'editor' | 'reviewer') => void
|
||||
}) => {
|
||||
return (
|
||||
<div
|
||||
@@ -232,11 +272,26 @@ const SkillItem = ({
|
||||
{skill.description || m.no_description_provided()}
|
||||
</p>
|
||||
</div>
|
||||
<div className="mt-4 flex items-center justify-between text-[10px] text-muted-foreground uppercase tracking-wider font-semibold">
|
||||
<span>
|
||||
<div className="mt-4 flex items-center justify-between gap-2 pt-2 border-t border-border/50 text-xs">
|
||||
<span className="text-[10px] text-muted-foreground uppercase tracking-wider font-semibold">
|
||||
{m.updated_date()} {new Date(skill.updatedAt).toLocaleDateString()}
|
||||
</span>
|
||||
<div className="px-2 py-0.5 rounded-full bg-primary/10 text-primary">{m.installed()}</div>
|
||||
<div className="flex items-center gap-2" onClick={(e) => e.stopPropagation()}>
|
||||
<Select
|
||||
value={skill.permission || 'reviewer'}
|
||||
onValueChange={(val) => onPermissionChange(val as 'owner' | 'editor' | 'reviewer')}
|
||||
disabled={!canAdmin}
|
||||
>
|
||||
<SelectTrigger className="h-7 text-xs px-2 bg-background border-border w-[140px]">
|
||||
<SelectValue placeholder={m.skill_permission()} />
|
||||
</SelectTrigger>
|
||||
<SelectContent align="end">
|
||||
<SelectItem value="reviewer">{m.permission_all_users()}</SelectItem>
|
||||
<SelectItem value="editor">{m.permission_owner_and_editor()}</SelectItem>
|
||||
<SelectItem value="owner">{m.permission_owner_only()}</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
|
||||
@@ -322,6 +322,11 @@
|
||||
"skills_description": "Add, update and configure AI skills for the team.",
|
||||
"skills_management": "Skills Management",
|
||||
"skills_management_description": "Extend your chatbot's capabilities with custom skills.",
|
||||
"skill_permission": "Permission",
|
||||
"permission_all_users": "All Users",
|
||||
"permission_owner_and_editor": "Owner & Editor",
|
||||
"permission_owner_only": "Owner Only",
|
||||
"failed_to_update_permission": "Failed to update permission",
|
||||
"add_skill": "Add Skill",
|
||||
"no_skills_installed": "No skills installed",
|
||||
"add_skill_to_get_started": "Add a skill via GitHub URL or upload a ZIP file to get started.",
|
||||
|
||||
@@ -322,6 +322,11 @@
|
||||
"skills_description": "为团队添加、更新和配置 AI 技能。",
|
||||
"skills_management": "技能管理",
|
||||
"skills_management_description": "使用自定义技能扩展聊天机器人的功能。",
|
||||
"skill_permission": "权限",
|
||||
"permission_all_users": "所有成员",
|
||||
"permission_owner_and_editor": "管理员与编辑",
|
||||
"permission_owner_only": "仅管理员",
|
||||
"failed_to_update_permission": "更新权限失败",
|
||||
"add_skill": "添加技能",
|
||||
"no_skills_installed": "暂无已安装的技能",
|
||||
"add_skill_to_get_started": "通过 GitHub URL 添加技能或上传 ZIP 文件以开始使用。",
|
||||
|
||||
+5
@@ -305,6 +305,11 @@ export * from "./skills.js";
|
||||
export * from "./skills_description.js";
|
||||
export * from "./skills_management.js";
|
||||
export * from "./skills_management_description.js";
|
||||
export * from "./skill_permission.js";
|
||||
export * from "./permission_all_users.js";
|
||||
export * from "./permission_owner_and_editor.js";
|
||||
export * from "./permission_owner_only.js";
|
||||
export * from "./failed_to_update_permission.js";
|
||||
export * from "./add_skill.js";
|
||||
export * from "./no_skills_installed.js";
|
||||
export * from "./add_skill_to_get_started.js";
|
||||
|
||||
+5
@@ -307,6 +307,11 @@ export * from './skills.js'
|
||||
export * from './skills_description.js'
|
||||
export * from './skills_management.js'
|
||||
export * from './skills_management_description.js'
|
||||
export * from './skill_permission.js'
|
||||
export * from './permission_all_users.js'
|
||||
export * from './permission_owner_and_editor.js'
|
||||
export * from './permission_owner_only.js'
|
||||
export * from './failed_to_update_permission.js'
|
||||
export * from './add_skill.js'
|
||||
export * from './no_skills_installed.js'
|
||||
export * from './add_skill_to_get_started.js'
|
||||
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
/**
|
||||
* | output |
|
||||
* | --- |
|
||||
* | "Failed to update permission" |
|
||||
*
|
||||
* @param {Failed_To_Update_PermissionInputs} inputs
|
||||
* @param {{ locale?: "en" | "zh" }} options
|
||||
* @returns {LocalizedString}
|
||||
*/
|
||||
export const failed_to_update_permission: ((inputs?: Failed_To_Update_PermissionInputs, options?: {
|
||||
locale?: "en" | "zh";
|
||||
}) => LocalizedString) & import("../runtime.js").MessageMetadata<Failed_To_Update_PermissionInputs, {
|
||||
locale?: "en" | "zh";
|
||||
}, {}>;
|
||||
export type LocalizedString = import("../runtime.js").LocalizedString;
|
||||
export type Failed_To_Update_PermissionInputs = {};
|
||||
@@ -0,0 +1,29 @@
|
||||
/* eslint-disable */
|
||||
import { getLocale, experimentalStaticLocale } from '../runtime.js';
|
||||
|
||||
/** @typedef {import('../runtime.js').LocalizedString} LocalizedString */
|
||||
|
||||
/** @typedef {{}} Failed_To_Update_PermissionInputs */
|
||||
|
||||
const en_failed_to_update_permission = /** @type {(inputs: Failed_To_Update_PermissionInputs) => LocalizedString} */ () => {
|
||||
return /** @type {LocalizedString} */ (`Failed to update permission`)
|
||||
};
|
||||
|
||||
const zh_failed_to_update_permission = /** @type {(inputs: Failed_To_Update_PermissionInputs) => LocalizedString} */ () => {
|
||||
return /** @type {LocalizedString} */ (`更新权限失败`)
|
||||
};
|
||||
|
||||
/**
|
||||
* | output |
|
||||
* | --- |
|
||||
* | "Failed to update permission" |
|
||||
*
|
||||
* @param {Failed_To_Update_PermissionInputs} inputs
|
||||
* @param {{ locale?: "en" | "zh" }} options
|
||||
* @returns {LocalizedString}
|
||||
*/
|
||||
export const failed_to_update_permission = /** @type {((inputs?: Failed_To_Update_PermissionInputs, options?: { locale?: "en" | "zh" }) => LocalizedString) & import('../runtime.js').MessageMetadata<Failed_To_Update_PermissionInputs, { locale?: "en" | "zh" }, {}>} */ ((inputs = {}, options = {}) => {
|
||||
const locale = experimentalStaticLocale ?? options.locale ?? getLocale()
|
||||
if (locale === "en") return en_failed_to_update_permission(inputs)
|
||||
return zh_failed_to_update_permission(inputs)
|
||||
});
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
/**
|
||||
* | output |
|
||||
* | --- |
|
||||
* | "All Users" |
|
||||
*
|
||||
* @param {Permission_All_UsersInputs} inputs
|
||||
* @param {{ locale?: "en" | "zh" }} options
|
||||
* @returns {LocalizedString}
|
||||
*/
|
||||
export const permission_all_users: ((inputs?: Permission_All_UsersInputs, options?: {
|
||||
locale?: "en" | "zh";
|
||||
}) => LocalizedString) & import("../runtime.js").MessageMetadata<Permission_All_UsersInputs, {
|
||||
locale?: "en" | "zh";
|
||||
}, {}>;
|
||||
export type LocalizedString = import("../runtime.js").LocalizedString;
|
||||
export type Permission_All_UsersInputs = {};
|
||||
@@ -0,0 +1,29 @@
|
||||
/* eslint-disable */
|
||||
import { getLocale, experimentalStaticLocale } from '../runtime.js';
|
||||
|
||||
/** @typedef {import('../runtime.js').LocalizedString} LocalizedString */
|
||||
|
||||
/** @typedef {{}} Permission_All_UsersInputs */
|
||||
|
||||
const en_permission_all_users = /** @type {(inputs: Permission_All_UsersInputs) => LocalizedString} */ () => {
|
||||
return /** @type {LocalizedString} */ (`All Users`)
|
||||
};
|
||||
|
||||
const zh_permission_all_users = /** @type {(inputs: Permission_All_UsersInputs) => LocalizedString} */ () => {
|
||||
return /** @type {LocalizedString} */ (`所有成员`)
|
||||
};
|
||||
|
||||
/**
|
||||
* | output |
|
||||
* | --- |
|
||||
* | "All Users" |
|
||||
*
|
||||
* @param {Permission_All_UsersInputs} inputs
|
||||
* @param {{ locale?: "en" | "zh" }} options
|
||||
* @returns {LocalizedString}
|
||||
*/
|
||||
export const permission_all_users = /** @type {((inputs?: Permission_All_UsersInputs, options?: { locale?: "en" | "zh" }) => LocalizedString) & import('../runtime.js').MessageMetadata<Permission_All_UsersInputs, { locale?: "en" | "zh" }, {}>} */ ((inputs = {}, options = {}) => {
|
||||
const locale = experimentalStaticLocale ?? options.locale ?? getLocale()
|
||||
if (locale === "en") return en_permission_all_users(inputs)
|
||||
return zh_permission_all_users(inputs)
|
||||
});
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
/**
|
||||
* | output |
|
||||
* | --- |
|
||||
* | "Owner & Editor" |
|
||||
*
|
||||
* @param {Permission_Owner_And_EditorInputs} inputs
|
||||
* @param {{ locale?: "en" | "zh" }} options
|
||||
* @returns {LocalizedString}
|
||||
*/
|
||||
export const permission_owner_and_editor: ((inputs?: Permission_Owner_And_EditorInputs, options?: {
|
||||
locale?: "en" | "zh";
|
||||
}) => LocalizedString) & import("../runtime.js").MessageMetadata<Permission_Owner_And_EditorInputs, {
|
||||
locale?: "en" | "zh";
|
||||
}, {}>;
|
||||
export type LocalizedString = import("../runtime.js").LocalizedString;
|
||||
export type Permission_Owner_And_EditorInputs = {};
|
||||
@@ -0,0 +1,29 @@
|
||||
/* eslint-disable */
|
||||
import { getLocale, experimentalStaticLocale } from '../runtime.js';
|
||||
|
||||
/** @typedef {import('../runtime.js').LocalizedString} LocalizedString */
|
||||
|
||||
/** @typedef {{}} Permission_Owner_And_EditorInputs */
|
||||
|
||||
const en_permission_owner_and_editor = /** @type {(inputs: Permission_Owner_And_EditorInputs) => LocalizedString} */ () => {
|
||||
return /** @type {LocalizedString} */ (`Owner & Editor`)
|
||||
};
|
||||
|
||||
const zh_permission_owner_and_editor = /** @type {(inputs: Permission_Owner_And_EditorInputs) => LocalizedString} */ () => {
|
||||
return /** @type {LocalizedString} */ (`管理员与编辑`)
|
||||
};
|
||||
|
||||
/**
|
||||
* | output |
|
||||
* | --- |
|
||||
* | "Owner & Editor" |
|
||||
*
|
||||
* @param {Permission_Owner_And_EditorInputs} inputs
|
||||
* @param {{ locale?: "en" | "zh" }} options
|
||||
* @returns {LocalizedString}
|
||||
*/
|
||||
export const permission_owner_and_editor = /** @type {((inputs?: Permission_Owner_And_EditorInputs, options?: { locale?: "en" | "zh" }) => LocalizedString) & import('../runtime.js').MessageMetadata<Permission_Owner_And_EditorInputs, { locale?: "en" | "zh" }, {}>} */ ((inputs = {}, options = {}) => {
|
||||
const locale = experimentalStaticLocale ?? options.locale ?? getLocale()
|
||||
if (locale === "en") return en_permission_owner_and_editor(inputs)
|
||||
return zh_permission_owner_and_editor(inputs)
|
||||
});
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
/**
|
||||
* | output |
|
||||
* | --- |
|
||||
* | "Owner Only" |
|
||||
*
|
||||
* @param {Permission_Owner_OnlyInputs} inputs
|
||||
* @param {{ locale?: "en" | "zh" }} options
|
||||
* @returns {LocalizedString}
|
||||
*/
|
||||
export const permission_owner_only: ((inputs?: Permission_Owner_OnlyInputs, options?: {
|
||||
locale?: "en" | "zh";
|
||||
}) => LocalizedString) & import("../runtime.js").MessageMetadata<Permission_Owner_OnlyInputs, {
|
||||
locale?: "en" | "zh";
|
||||
}, {}>;
|
||||
export type LocalizedString = import("../runtime.js").LocalizedString;
|
||||
export type Permission_Owner_OnlyInputs = {};
|
||||
@@ -0,0 +1,29 @@
|
||||
/* eslint-disable */
|
||||
import { getLocale, experimentalStaticLocale } from '../runtime.js';
|
||||
|
||||
/** @typedef {import('../runtime.js').LocalizedString} LocalizedString */
|
||||
|
||||
/** @typedef {{}} Permission_Owner_OnlyInputs */
|
||||
|
||||
const en_permission_owner_only = /** @type {(inputs: Permission_Owner_OnlyInputs) => LocalizedString} */ () => {
|
||||
return /** @type {LocalizedString} */ (`Owner Only`)
|
||||
};
|
||||
|
||||
const zh_permission_owner_only = /** @type {(inputs: Permission_Owner_OnlyInputs) => LocalizedString} */ () => {
|
||||
return /** @type {LocalizedString} */ (`仅管理员`)
|
||||
};
|
||||
|
||||
/**
|
||||
* | output |
|
||||
* | --- |
|
||||
* | "Owner Only" |
|
||||
*
|
||||
* @param {Permission_Owner_OnlyInputs} inputs
|
||||
* @param {{ locale?: "en" | "zh" }} options
|
||||
* @returns {LocalizedString}
|
||||
*/
|
||||
export const permission_owner_only = /** @type {((inputs?: Permission_Owner_OnlyInputs, options?: { locale?: "en" | "zh" }) => LocalizedString) & import('../runtime.js').MessageMetadata<Permission_Owner_OnlyInputs, { locale?: "en" | "zh" }, {}>} */ ((inputs = {}, options = {}) => {
|
||||
const locale = experimentalStaticLocale ?? options.locale ?? getLocale()
|
||||
if (locale === "en") return en_permission_owner_only(inputs)
|
||||
return zh_permission_owner_only(inputs)
|
||||
});
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
/**
|
||||
* | output |
|
||||
* | --- |
|
||||
* | "Permission" |
|
||||
*
|
||||
* @param {Skill_PermissionInputs} inputs
|
||||
* @param {{ locale?: "en" | "zh" }} options
|
||||
* @returns {LocalizedString}
|
||||
*/
|
||||
export const skill_permission: ((inputs?: Skill_PermissionInputs, options?: {
|
||||
locale?: "en" | "zh";
|
||||
}) => LocalizedString) & import("../runtime.js").MessageMetadata<Skill_PermissionInputs, {
|
||||
locale?: "en" | "zh";
|
||||
}, {}>;
|
||||
export type LocalizedString = import("../runtime.js").LocalizedString;
|
||||
export type Skill_PermissionInputs = {};
|
||||
@@ -0,0 +1,29 @@
|
||||
/* eslint-disable */
|
||||
import { getLocale, experimentalStaticLocale } from '../runtime.js';
|
||||
|
||||
/** @typedef {import('../runtime.js').LocalizedString} LocalizedString */
|
||||
|
||||
/** @typedef {{}} Skill_PermissionInputs */
|
||||
|
||||
const en_skill_permission = /** @type {(inputs: Skill_PermissionInputs) => LocalizedString} */ () => {
|
||||
return /** @type {LocalizedString} */ (`Permission`)
|
||||
};
|
||||
|
||||
const zh_skill_permission = /** @type {(inputs: Skill_PermissionInputs) => LocalizedString} */ () => {
|
||||
return /** @type {LocalizedString} */ (`权限`)
|
||||
};
|
||||
|
||||
/**
|
||||
* | output |
|
||||
* | --- |
|
||||
* | "Permission" |
|
||||
*
|
||||
* @param {Skill_PermissionInputs} inputs
|
||||
* @param {{ locale?: "en" | "zh" }} options
|
||||
* @returns {LocalizedString}
|
||||
*/
|
||||
export const skill_permission = /** @type {((inputs?: Skill_PermissionInputs, options?: { locale?: "en" | "zh" }) => LocalizedString) & import('../runtime.js').MessageMetadata<Skill_PermissionInputs, { locale?: "en" | "zh" }, {}>} */ ((inputs = {}, options = {}) => {
|
||||
const locale = experimentalStaticLocale ?? options.locale ?? getLocale()
|
||||
if (locale === "en") return en_skill_permission(inputs)
|
||||
return zh_skill_permission(inputs)
|
||||
});
|
||||
Reference in New Issue
Block a user