一些检查失败了
automerge / automerge (push) Has been cancelled
react-native-android-build-apk / AssembleRelease (push) Has been cancelled
Build macOS M1 / Main (push) Has been cancelled
Joplin Continuous Integration / Main (macos-15-intel) (push) Has been cancelled
Joplin Continuous Integration / Main (ubuntu-22.04) (push) Has been cancelled
Joplin Continuous Integration / Main (ubuntu-22.04-arm) (push) Has been cancelled
Joplin Continuous Integration / Main (windows-11-vs2026-arm) (push) Has been cancelled
Joplin Continuous Integration / Main (windows-2025) (push) Has been cancelled
Joplin Continuous Integration / ServerDockerImage (ubuntu-22.04) (push) Has been cancelled
Joplin Continuous Integration / ServerDockerImage (ubuntu-22.04-arm) (push) Has been cancelled
Joplin UI tests / Main (ubuntu-22.04) (push) Has been cancelled
Joplin UI tests / Main (windows-2025) (push) Has been cancelled
Joplin UI tests / Mobile (push) Has been cancelled
Close stale issues / ProcessStaleIssues (push) Has been cancelled
41 行
1.2 KiB
TypeScript
41 行
1.2 KiB
TypeScript
import { _ } from '../../../../locale';
|
|
import Folder from '../../../../models/Folder';
|
|
import { ToolError } from '../types';
|
|
import buildTool from '../utils/buildTool';
|
|
|
|
interface Input {
|
|
title?: string;
|
|
parent_id?: string;
|
|
}
|
|
|
|
const tool = buildTool({
|
|
id: 'create_notebook',
|
|
userDescription: (input: Input) => _('Created notebook: %s', input.title ?? _('(no title)')),
|
|
description: 'Create a new notebook. Optionally nest it under an existing notebook by passing parent_id.',
|
|
inputSchema: {
|
|
type: 'object',
|
|
properties: {
|
|
title: { type: 'string', description: 'Notebook title.' },
|
|
parent_id: { type: 'string', description: 'Optional id of the parent notebook to nest under.' },
|
|
},
|
|
required: ['title'],
|
|
},
|
|
handler: async (input: Input) => {
|
|
if (!input.title || !input.title.trim()) throw new ToolError('Missing "title" parameter');
|
|
|
|
if (input.parent_id) {
|
|
const parent = await Folder.load(input.parent_id);
|
|
if (!parent) throw new ToolError(`Parent notebook not found: ${input.parent_id}`);
|
|
}
|
|
|
|
const saved = await Folder.save({
|
|
title: input.title,
|
|
parent_id: input.parent_id ?? '',
|
|
}, { userSideValidation: true });
|
|
|
|
return { id: saved.id, title: saved.title, parent_id: saved.parent_id || null };
|
|
},
|
|
});
|
|
|
|
export default tool;
|