mirror of
https://github.com/labring/FastGPT.git
synced 2026-04-27 02:08:10 +08:00
57a505f837
* chore: Rename service & container names for consistency in Docker configs (#6710) * chore: Rename container names for consistency in Docker configs * chore: Rename service names for consistency in Docker configs chore: Update OpenSandbox versions and image repositories (#6709) * chore: Update OpenSandbox versions and image repositories * yml version * images * init yml * port --------- Co-authored-by: archer <545436317@qq.com> refactor(chat): optimize sandbox status logic and decouple UI/Status hooks (#6713) * refactor(chat): optimize sandbox status logic and decouple UI/Status hooks * fix: useRef, rename onClose to afterClose Update .env.template (#6720) aiproxy默认的请求地址改成http协议 feat: comprehensive agent skill management and sandbox infrastructure optimization - Skill System: Implemented a full skill management module including CRUD operations, folder organization, AI-driven skill generation, and versioning (switch/update). - Sandbox Infrastructure: Introduced 'volume-manager' for PVC and Docker volume lifecycle management, replacing the MinIO sync-agent for better data persistence. - Workflow Integration: Enhanced the Agent node to support skill selection and configuration, including new UI components and data normalization. - Permission Management: Added granular permission controls for skills, supporting collaborators, owner transfers, and permission inheritance. - UI/UX: Added a dedicated Skill dashboard, sandbox debug interface (terminal, logs, and iframe proxy), and comprehensive i18n support. - Maintenance: Migrated Docker services to named volumes, optimized sandbox instance limits, and improved error handling for sandbox providers. Co-authored-by: chanzhi82020 <chenzhi@sangfor.com.cn> Co-authored-by: lavine77 Signed-off-by: Jon <ljp@sangfor.com.cn> feat: hide skill prettier * perf: hide skill code * fix: ts * lock * perf: tool code * fix: ts * lock * fix: test * fix: openapi * lock * fix: test * null model --------- Co-authored-by: archer <545436317@qq.com>
104 lines
3.6 KiB
TypeScript
104 lines
3.6 KiB
TypeScript
import { type Monaco } from '@monaco-editor/react';
|
|
import { useCallback } from 'react';
|
|
import { type CompletionModel, type CompletionPosition } from './type';
|
|
|
|
let monacoInstance: Monaco | null = null;
|
|
|
|
const usePythonCompletion = () => {
|
|
return useCallback((monaco: Monaco) => {
|
|
if (monacoInstance === monaco) return;
|
|
monacoInstance = monaco;
|
|
|
|
monaco.languages.registerCompletionItemProvider('python', {
|
|
triggerCharacters: ['_'],
|
|
provideCompletionItems: (model: CompletionModel, position: CompletionPosition) => {
|
|
const wordInfo = model.getWordUntilPosition(position);
|
|
const currentWordPrefix = wordInfo.word;
|
|
const lineContent = model.getLineContent(position.lineNumber);
|
|
const textBeforeCursor = lineContent.slice(0, position.column - 1);
|
|
|
|
// Skip built-ins when in member access context (e.g. "foo.")
|
|
if (textBeforeCursor.endsWith('.')) return { suggestions: [] };
|
|
|
|
const range = {
|
|
startLineNumber: position.lineNumber,
|
|
endLineNumber: position.lineNumber,
|
|
startColumn: wordInfo.startColumn,
|
|
endColumn: wordInfo.endColumn
|
|
};
|
|
|
|
// import line — suggest common packages
|
|
if (lineContent.startsWith('import')) {
|
|
const importLength = 'import'.length;
|
|
const afterImport = lineContent.slice(importLength);
|
|
const spaceMatch = afterImport.match(/^\s*/);
|
|
const spaceLength = spaceMatch ? spaceMatch[0].length : 0;
|
|
const startReplaceCol = importLength + spaceLength + 1;
|
|
const replaceRange = new monaco.Range(
|
|
position.lineNumber,
|
|
startReplaceCol,
|
|
position.lineNumber,
|
|
position.column
|
|
);
|
|
const needsSpace = spaceLength === 0;
|
|
return {
|
|
suggestions: [
|
|
{
|
|
label: 'numpy',
|
|
kind: monaco.languages.CompletionItemKind.Module,
|
|
insertText: `${needsSpace ? ' ' : ''}numpy as np`,
|
|
documentation: 'numerical computing library',
|
|
range: replaceRange,
|
|
sortText: 'a'
|
|
},
|
|
{
|
|
label: 'pandas',
|
|
kind: monaco.languages.CompletionItemKind.Module,
|
|
insertText: `${needsSpace ? ' ' : ''}pandas as pd`,
|
|
documentation: 'data analysis library',
|
|
range: replaceRange
|
|
}
|
|
]
|
|
};
|
|
}
|
|
|
|
// General Python built-ins
|
|
const suggestions = [
|
|
{
|
|
label: 'len',
|
|
kind: monaco.languages.CompletionItemKind.Function,
|
|
insertText: 'len()',
|
|
documentation: 'Return the length of an object.',
|
|
range,
|
|
sortText: 'a'
|
|
},
|
|
{
|
|
label: 'print',
|
|
kind: monaco.languages.CompletionItemKind.Function,
|
|
insertText: 'print(${1:value})',
|
|
insertTextRules: monaco.languages.CompletionItemInsertTextRule.InsertAsSnippet,
|
|
documentation: 'Print values to stdout.',
|
|
range
|
|
},
|
|
{
|
|
label: 'range',
|
|
kind: monaco.languages.CompletionItemKind.Function,
|
|
insertText: 'range(${1:stop})',
|
|
insertTextRules: monaco.languages.CompletionItemInsertTextRule.InsertAsSnippet,
|
|
documentation: 'Return a range object.',
|
|
range
|
|
}
|
|
];
|
|
|
|
return {
|
|
suggestions: suggestions.filter((item) =>
|
|
item.label.toLowerCase().startsWith(currentWordPrefix.toLowerCase())
|
|
)
|
|
};
|
|
}
|
|
});
|
|
}, []);
|
|
};
|
|
|
|
export default usePythonCompletion;
|