mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-11-22 17:20:18 +00:00
* feat(asset-read): expose read_asset on MCP and the CLI Enable the mcp and cli surfaces for read_asset and get_asset_render. - MCP: add per-Operation tool extensions. The read presenter attaches up to 8 images (2 MB each) inline, lists image links, supports inlineImages: false, and tells the model to call get_asset_render when a render is pending. Storage keys are stripped from the result. - CLI: generated commands can flatten object inputs into prefixed flags (cli.flatten) and omit fields (cli.omit); add per-command extensions. New `read` and `render` commands print image links, download them with --out, and support --no-wait with a printed `render <taskId>` hint. - Round frame timestamps in labels to 3 decimals. * fix(mcp): make tool input schemas portable to single-type dialects Nullable inputs were emitted as `type: ["number", "null"]` (or a `null` anyOf branch), which clients that map tool schemas onto an OpenAPI-style subset (e.g. Gemini function declarations) may reject. - Make read_asset's startPage, endPage, and degree optional instead of nullable. - Move null handling into a shared dropNullOptionals helper in @shumai/operations that also strips nulls inside nested config objects. The agent uses it, and the MCP server applies it before the SDK validates arguments, so models that send null keep working. - Test that no Operation input schema (and no listed MCP tool) uses a nullable type. * feat(asset-download): share download_asset across agent, MCP and CLI Turn the agent-only download_asset tool into an Operation on all three surfaces. - download_asset takes up to 50 file or version stack IDs and returns presigned links. proxy (default true) picks the web preview when there is one, as the agent always did; proxy: false returns the original. Folders are rejected. Read is checked on every ID before anything runs. - Agent: an extension saves the files into the .pi sandbox and keeps the agent-only storage key mode (e.g. frames from read_asset). Agent tool extensions gain description, parameterOverrides and intercept. - CLI: `shumai-cli download <assetId...> [--out <dir>] [--original]` streams files to disk without overwriting existing names. - read_asset's unsupported-type error now names the right way to download on each surface (download_asset, or `shumai-cli download`). - Add the Download Asset toggle to agent settings.
105 lines
3.5 KiB
TypeScript
105 lines
3.5 KiB
TypeScript
import { describe, expect, it } from 'vitest'
|
|
import { z } from 'zod'
|
|
import { defineOperation, type OperationDefinition } from './define'
|
|
|
|
function baseDefinition(): OperationDefinition<string, z.ZodObject<{ id: z.ZodString }>> {
|
|
return {
|
|
name: 'get_thing',
|
|
title: 'Get Thing',
|
|
description: 'Get a thing by ID.',
|
|
input: z.object({ id: z.string() }),
|
|
output: z.object({ id: z.string() }),
|
|
surfaces: ['agent', 'mcp'],
|
|
annotations: { readOnly: true, destructive: false },
|
|
}
|
|
}
|
|
|
|
describe('defineOperation', () => {
|
|
it('returns a frozen definition', () => {
|
|
const def = defineOperation(baseDefinition())
|
|
expect(def.name).toBe('get_thing')
|
|
expect(Object.isFrozen(def)).toBe(true)
|
|
})
|
|
|
|
it.each(['GetThing', 'get-thing', 'get thing', '_get', 'get__thing', '1get', 'get_'])(
|
|
'rejects non snake_case name %s',
|
|
(name) => {
|
|
expect(() => defineOperation({ ...baseDefinition(), name })).toThrow('expected snake_case')
|
|
},
|
|
)
|
|
|
|
it('requires a title and description', () => {
|
|
expect(() => defineOperation({ ...baseDefinition(), title: ' ' })).toThrow(
|
|
'must have a title and a description',
|
|
)
|
|
expect(() => defineOperation({ ...baseDefinition(), description: '' })).toThrow(
|
|
'must have a title and a description',
|
|
)
|
|
})
|
|
|
|
it('rejects empty or duplicated surfaces', () => {
|
|
expect(() => defineOperation({ ...baseDefinition(), surfaces: [] })).toThrow('each surface')
|
|
expect(() => defineOperation({ ...baseDefinition(), surfaces: ['agent', 'agent'] })).toThrow(
|
|
'each surface',
|
|
)
|
|
})
|
|
|
|
it('rejects contradictory annotations', () => {
|
|
expect(() =>
|
|
defineOperation({
|
|
...baseDefinition(),
|
|
annotations: { readOnly: true, destructive: true },
|
|
}),
|
|
).toThrow('cannot be both readOnly and destructive')
|
|
})
|
|
|
|
it('requires a cli spec for the cli surface', () => {
|
|
expect(() => defineOperation({ ...baseDefinition(), surfaces: ['cli'] })).toThrow('no cli spec')
|
|
})
|
|
|
|
it('rejects cli specs that reference unknown input fields', () => {
|
|
expect(() =>
|
|
defineOperation({
|
|
...baseDefinition(),
|
|
surfaces: ['cli'],
|
|
// Cast simulates a definition built without type checking (e.g. from JS)
|
|
cli: { command: ['get'], positional: ['missing' as 'id'] },
|
|
}),
|
|
).toThrow('unknown input "missing"')
|
|
expect(() =>
|
|
defineOperation({
|
|
...baseDefinition(),
|
|
surfaces: ['cli'],
|
|
cli: { command: ['get'], flags: { ['other' as 'id']: ['-o'] } },
|
|
}),
|
|
).toThrow('unknown input "other"')
|
|
expect(() =>
|
|
defineOperation({
|
|
...baseDefinition(),
|
|
surfaces: ['cli'],
|
|
cli: { command: ['get'], defaults: { ['extra' as 'id']: 'x' } },
|
|
}),
|
|
).toThrow('unknown input "extra"')
|
|
})
|
|
|
|
it('validates flattened and omitted cli fields', () => {
|
|
const input = z.object({
|
|
id: z.string(),
|
|
config: z.object({ size: z.number() }).optional(),
|
|
verbose: z.boolean().optional(),
|
|
})
|
|
const withCli = (cli: Record<string, unknown>) =>
|
|
defineOperation({
|
|
...baseDefinition(),
|
|
input,
|
|
surfaces: ['cli'],
|
|
cli: { command: ['get'], ...cli },
|
|
} as OperationDefinition<string, typeof input>)
|
|
|
|
expect(() => withCli({ flatten: { config: 'config' }, omit: ['verbose'] })).not.toThrow()
|
|
expect(() => withCli({ flatten: { nope: 'n' } })).toThrow('unknown input "nope"')
|
|
expect(() => withCli({ omit: ['gone'] })).toThrow('unknown input "gone"')
|
|
expect(() => withCli({ omit: ['id'] })).toThrow('omits required input "id"')
|
|
})
|
|
})
|