@univerjs-pro/sheets-mcp 0.10.14 → 0.11.0-nightly.202511151013

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,7 @@
1
1
  export declare const SHEET_MCP_PLUGIN_CONFIG_KEY = "sheet-mcp.config";
2
2
  export declare const configSymbol: unique symbol;
3
3
  export interface IUniverSheetMCPConfig {
4
+ /** Whether to enable worker mode */
5
+ enableWorker?: boolean;
4
6
  }
5
7
  export declare const defaultPluginConfig: IUniverSheetMCPConfig;
@@ -0,0 +1,41 @@
1
+ import { IFormulaUsage, IFormulaUsageAsA1 } from '@univerjs-pro/sheets-mcp';
2
+ import { FRange } from '@univerjs/sheets/facade';
3
+ /**
4
+ * @ignore
5
+ */
6
+ export interface IFRangeSheetsMCP {
7
+ /**
8
+ * Get all formula usages in the range
9
+ * @returns A promise that resolves to an array of formula usages
10
+ *
11
+ * @example
12
+ * ```ts
13
+ * const workbook = univerAPI.getActiveWorkbook()
14
+ * const sheet = workbook.getActiveSheet()
15
+ * const range = sheet.getRangeByA1('A1:C10')
16
+ * const usages = await range.getFormulaUsages();
17
+ * ```
18
+ */
19
+ getFormulaUsages(): Promise<IFormulaUsage[]>;
20
+ /**
21
+ * Get all formula usages in the range in A1 notation
22
+ * @returns A promise that resolves to an array of formula usages in A1 notation
23
+ *
24
+ * @example
25
+ * ```ts
26
+ * const workbook = univerAPI.getActiveWorkbook()
27
+ * const sheet = workbook.getActiveSheet()
28
+ * const range = sheet.getRangeByA1('A1:C10')
29
+ * const usagesA1 = await range.getFormulaUsagesAsA1();
30
+ * ```
31
+ */
32
+ getFormulaUsagesAsA1(): Promise<IFormulaUsageAsA1[]>;
33
+ }
34
+ export declare class FRangeSheetsMCP extends FRange implements IFRangeSheetsMCP {
35
+ getFormulaUsages(): Promise<IFormulaUsage[]>;
36
+ getFormulaUsagesAsA1(): Promise<IFormulaUsageAsA1[]>;
37
+ }
38
+ declare module '@univerjs/sheets/facade' {
39
+ interface FRange extends IFRangeSheetsMCP {
40
+ }
41
+ }
@@ -1,16 +1,14 @@
1
- import { ISheetFormulaError } from '@univerjs/engine-formula';
2
- import { IDataValidationError } from '@univerjs/sheets-data-validation/facade';
1
+ import { ILintErrorReport } from './f-workbook';
3
2
  import { FUniver } from '@univerjs/core/facade';
4
3
  import '@univerjs/sheets-formula/facade';
5
4
  import '@univerjs/sheets-data-validation/facade';
6
- interface ILintErrorReport {
7
- formulaErrors: ISheetFormulaError[];
8
- dataValidationErrors: IDataValidationError[];
9
- }
10
5
  /**
11
6
  * @ignore
12
7
  */
13
8
  export interface IFUniverLintMCP {
9
+ /**
10
+ * @deprecated use {@link FWorkbookSheetsMCP.getLintErrors} instead.
11
+ */
14
12
  getLintErrors(): Promise<ILintErrorReport>;
15
13
  }
16
14
  export declare class FUniverLintMCPMixin extends FUniver implements IFUniverLintMCP {
@@ -20,4 +18,3 @@ declare module '@univerjs/core/facade' {
20
18
  interface FUniver extends IFUniverLintMCP {
21
19
  }
22
20
  }
23
- export {};
@@ -0,0 +1,30 @@
1
+ import { ISheetFormulaError } from '@univerjs/engine-formula';
2
+ import { IDataValidationError } from '@univerjs/sheets-data-validation/facade';
3
+ import { FWorkbook } from '@univerjs/sheets/facade';
4
+ export interface ILintErrorReport {
5
+ formulaErrors: ISheetFormulaError[];
6
+ dataValidationErrors: IDataValidationError[];
7
+ }
8
+ /**
9
+ * @ignore
10
+ */
11
+ export interface IFWorkbookSheetsMCPMixin {
12
+ /**
13
+ * Get lint errors report including formula errors and data validation errors
14
+ *
15
+ * @example
16
+ * ```ts
17
+ * const workbook = univerAPI.getActiveWorkbook()
18
+ * const lintErrors = await workbook.getLintErrors();
19
+ * console.log(lintErrors.formulaErrors, lintErrors.dataValidationErrors);
20
+ * ```
21
+ */
22
+ getLintErrors(): Promise<ILintErrorReport>;
23
+ }
24
+ export declare class FWorkbookSheetsMCPMixin extends FWorkbook implements IFWorkbookSheetsMCPMixin {
25
+ getLintErrors(): Promise<ILintErrorReport>;
26
+ }
27
+ declare module '@univerjs/sheets/facade' {
28
+ interface FWorkbook extends IFWorkbookSheetsMCPMixin {
29
+ }
30
+ }
@@ -0,0 +1,39 @@
1
+ import { IFormulaUsage, IFormulaUsageAsA1 } from '@univerjs-pro/sheets-mcp';
2
+ import { FWorksheet } from '@univerjs/sheets/facade';
3
+ /**
4
+ * @ignore
5
+ */
6
+ export interface IFWorksheetSheetsMCP {
7
+ /**
8
+ * Get all formula usages in the worksheet
9
+ * @returns A promise that resolves to an array of formula usages
10
+ *
11
+ * @example
12
+ * ```ts
13
+ * const workbook = univerAPI.getActiveWorkbook()
14
+ * const sheet = workbook.getActiveSheet()
15
+ * const usages = await sheet.getFormulaUsages();
16
+ * ```
17
+ */
18
+ getFormulaUsages(): Promise<IFormulaUsage[]>;
19
+ /**
20
+ * Get all formula usages in the worksheet in A1 notation
21
+ * @returns A promise that resolves to an array of formula usages in A1 notation
22
+ *
23
+ * @example
24
+ * ```ts
25
+ * const workbook = univerAPI.getActiveWorkbook()
26
+ * const sheet = workbook.getActiveSheet()
27
+ * const usagesA1 = await sheet.getFormulaUsagesAsA1();
28
+ * ```
29
+ */
30
+ getFormulaUsagesAsA1(): Promise<IFormulaUsageAsA1[]>;
31
+ }
32
+ export declare class FWorksheetSheetsMCP extends FWorksheet implements IFWorksheetSheetsMCP {
33
+ getFormulaUsages(): Promise<IFormulaUsage[]>;
34
+ getFormulaUsagesAsA1(): Promise<IFormulaUsageAsA1[]>;
35
+ }
36
+ declare module '@univerjs/sheets/facade' {
37
+ interface FWorksheet extends IFWorksheetSheetsMCP {
38
+ }
39
+ }
@@ -1 +1,4 @@
1
1
  import './f-univer';
2
+ import './f-workbook';
3
+ import './f-worksheet';
4
+ import './f-range';
@@ -1,2 +1,3 @@
1
1
  export { UniverSheetMCPPlugin } from './plugin';
2
+ export { type IFormulaUsage, IFormulaUsageAnalyzer, type IFormulaUsageAsA1, toA1 } from './services/formula-analysis.service';
2
3
  export * from './tools';
@@ -0,0 +1,53 @@
1
+ import { ICellData, IRange, Nullable } from '@univerjs/core';
2
+ import { ICalculateFormulaService, LexerTreeBuilder } from '@univerjs/engine-formula';
3
+ /**
4
+ * Interface for formula usage information
5
+ */
6
+ export interface IFormulaUsage {
7
+ /**
8
+ * The formula's first occurrence location
9
+ */
10
+ formula: string;
11
+ /**
12
+ * The formula's first occurrence cell range
13
+ */
14
+ firstOccurrence: IRange;
15
+ /**
16
+ * The filled ranges of the formula, including the first occurrence
17
+ */
18
+ filledRanges: IRange[];
19
+ }
20
+ /**
21
+ * Interface for formula usage information in A1 notation
22
+ */
23
+ export interface IFormulaUsageAsA1 {
24
+ /**
25
+ * The formula's first occurrence location
26
+ */
27
+ formula: string;
28
+ /**
29
+ * The formula's first occurrence cell range in A1 notation
30
+ */
31
+ firstOccurrence: string;
32
+ /**
33
+ * The filled ranges of the formula in A1 notation, including the first occurrence
34
+ */
35
+ filledRanges: string;
36
+ }
37
+ export declare function toA1(usage: IFormulaUsage): IFormulaUsageAsA1;
38
+ /**
39
+ * Convert rectangle coordinates to A1 notation
40
+ * @param param0 [r1, r2, c1, c2]
41
+ * @returns A1 notation string
42
+ */
43
+ export declare function getA1Notation([r1, r2, c1, c2]: [number, number, number, number]): string;
44
+ export declare const FormulaUsageAnalyzerChannelName = "sheets.mcp.formula-usage-analyzer";
45
+ export declare const IFormulaUsageAnalyzer: import('@wendellhu/redi').IdentifierDecorator<FormulaUsageAnalyzer>;
46
+ export declare class FormulaUsageAnalyzer {
47
+ protected _formulaService: ICalculateFormulaService;
48
+ private _lexerTreeBuilder;
49
+ constructor(_formulaService: ICalculateFormulaService, _lexerTreeBuilder: LexerTreeBuilder);
50
+ getAllFormulaUsages(data: Nullable<ICellData>[][]): IFormulaUsage[];
51
+ getFormulaHash(formulaString: string, refOffsetX: number, refOffsetY: number, ignoreAbsolute?: boolean): string;
52
+ moveFormulaRefOffset(formula: string, refOffsetX: number, refOffsetY: number, ignoreAbsolute?: boolean): string;
53
+ }
@@ -0,0 +1 @@
1
+ export declare function extractFormulas(univerAPI: any, sheets?: string[]): Promise<string>;
package/lib/umd/facade.js CHANGED
@@ -1 +1 @@
1
- function _0xfa01(_0xb00263,_0x1c3e38){const _0x4bbe16=_0x4bbe();return _0xfa01=function(_0xfa01e1,_0x4e4a11){_0xfa01e1=_0xfa01e1-0x10c;let _0x309ba0=_0x4bbe16[_0xfa01e1];return _0x309ba0;},_0xfa01(_0xb00263,_0x1c3e38);}function _0x4bbe(){const _0x49b414=['9UTBAaB','1119uQMgMW','4254531rZHryM','getActiveWorkbook','object','extend','11CJSCTk','10vZqwun','@univerjs/sheets-data-validation/facade','6113346xtllJM','@univerjs/core/facade','@univerjs/sheets-formula/facade','UniverCoreFacade','12113240UEtayP','amd','3050OHPSfO','FUniver','1742685iYpoCn','getLintErrors','getAllFormulaError','35837710aAVAjq','1268084oIDxCH'];_0x4bbe=function(){return _0x49b414;};return _0x4bbe();}(function(_0x2e9f2,_0x46d8bc){const _0x280eaf=_0xfa01,_0x2b0cd4=_0x2e9f2();while(!![]){try{const _0x4ac3da=-parseInt(_0x280eaf(0x11e))/0x1*(-parseInt(_0x280eaf(0x116))/0x2)+parseInt(_0x280eaf(0x11f))/0x3+-parseInt(_0x280eaf(0x11c))/0x4*(-parseInt(_0x280eaf(0x10e))/0x5)+-parseInt(_0x280eaf(0x110))/0x6+parseInt(_0x280eaf(0x118))/0x7+parseInt(_0x280eaf(0x114))/0x8*(parseInt(_0x280eaf(0x11d))/0x9)+-parseInt(_0x280eaf(0x11b))/0xa*(parseInt(_0x280eaf(0x10d))/0xb);if(_0x4ac3da===_0x46d8bc)break;else _0x2b0cd4['push'](_0x2b0cd4['shift']());}catch(_0x47191f){_0x2b0cd4['push'](_0x2b0cd4['shift']());}}}(_0x4bbe,0xe0666),function(_0x19f152,_0xafbde9){const _0x27e30=_0xfa01;typeof exports==_0x27e30(0x121)&&typeof module<'u'?_0xafbde9(require('@univerjs/core/facade'),require('@univerjs/sheets-formula/facade'),require('@univerjs/sheets-data-validation/facade')):typeof define=='function'&&define[_0x27e30(0x115)]?define([_0x27e30(0x111),_0x27e30(0x112),_0x27e30(0x10f)],_0xafbde9):(_0x19f152=typeof globalThis<'u'?globalThis:_0x19f152||self,_0xafbde9(_0x19f152[_0x27e30(0x113)]));}(this,function(_0x49d35b){'use strict';const _0xd7b970=_0xfa01;class _0x362966 extends _0x49d35b[_0xd7b970(0x117)]{async[_0xd7b970(0x119)](){const _0x5413a8=_0xd7b970,_0x3ab580=this[_0x5413a8(0x120)](),_0x4c2626=_0x3ab580[_0x5413a8(0x11a)](),_0x276ffe=await _0x3ab580['getAllDataValidationErrorAsync']();return{'formulaErrors':_0x4c2626,'dataValidationErrors':_0x276ffe};}}_0x49d35b[_0xd7b970(0x117)][_0xd7b970(0x10c)](_0x362966);}));
1
+ function _0x1e9e(){const _0x1762e5=['getMaxRows','_worksheet','getAllFormulaError','@univerjs/sheets/facade','getFormulaUsagesAsA1','getFormulaUsages','1276924tZJTuS','49uFOLbj','extend','startRow','object','@univerjs/core','10aARqXb','UniverCoreFacade','38698060kJULcQ','getActiveWorkbook','FUniver','formula','getCellDataGrid','@univerjs/core/facade','2009624URcfug','getCellRaw','getIntersectRange','function','FRange','map','amd','filledRanges','_injector','getRange','IFormulaUsageAnalyzer','4205358bGiZlP','FWorksheet','1809798FkOJpo','4894731vmjOTK','3LGoRzD','UniverSheetsFormulaFacade','moveFormulaRefOffset','getAllDataValidationErrorAsync','getAllFormulaUsages','UniverSheetsDataValidationFacade','push','223979BEHRsn','UniverSheetsFacade','@univerjs/sheets-data-validation/facade','getMaxColumns','length','get','FWorkbook','@univerjs/sheets-formula/facade','getLintErrors','startColumn'];_0x1e9e=function(){return _0x1762e5;};return _0x1e9e();}function _0x5d5f(_0x373317,_0x5ac3e1){const _0x1e9e79=_0x1e9e();return _0x5d5f=function(_0x5d5fc2,_0x4f4b5c){_0x5d5fc2=_0x5d5fc2-0xd4;let _0x31eafe=_0x1e9e79[_0x5d5fc2];return _0x31eafe;},_0x5d5f(_0x373317,_0x5ac3e1);}(function(_0x39d5c6,_0x65c12b){const _0x2043f9=_0x5d5f,_0x18d9f0=_0x39d5c6();while(!![]){try{const _0x34a553=parseInt(_0x2043f9(0xf0))/0x1+parseInt(_0x2043f9(0xe7))/0x2*(-parseInt(_0x2043f9(0xe9))/0x3)+parseInt(_0x2043f9(0x100))/0x4*(-parseInt(_0x2043f9(0x106))/0x5)+parseInt(_0x2043f9(0xe5))/0x6+-parseInt(_0x2043f9(0x101))/0x7*(parseInt(_0x2043f9(0xda))/0x8)+-parseInt(_0x2043f9(0xe8))/0x9+parseInt(_0x2043f9(0xd4))/0xa;if(_0x34a553===_0x65c12b)break;else _0x18d9f0['push'](_0x18d9f0['shift']());}catch(_0x559218){_0x18d9f0['push'](_0x18d9f0['shift']());}}}(_0x1e9e,0xe7b2d),function(_0x21614a,_0x1f3e95){const _0x511fff=_0x5d5f;typeof exports==_0x511fff(0x104)&&typeof module<'u'?_0x1f3e95(require('@univerjs/core/facade'),require('@univerjs/sheets-formula/facade'),require('@univerjs/sheets-data-validation/facade'),require('@univerjs/sheets/facade'),require('@univerjs-pro/sheets-mcp'),require('@univerjs/core')):typeof define==_0x511fff(0xdd)&&define[_0x511fff(0xe0)]?define([_0x511fff(0xd9),_0x511fff(0xf7),_0x511fff(0xf2),_0x511fff(0xfd),'@univerjs-pro/sheets-mcp',_0x511fff(0x105)],_0x1f3e95):(_0x21614a=typeof globalThis<'u'?globalThis:_0x21614a||self,_0x1f3e95(_0x21614a[_0x511fff(0x107)],_0x21614a[_0x511fff(0xea)],_0x21614a[_0x511fff(0xee)],_0x21614a[_0x511fff(0xf1)],_0x21614a['UniverProSheetsMcp'],_0x21614a['UniverCore']));}(this,function(_0x2cc7f1,_0x5636e2,_0x661199,_0x3cb89d,_0x3a0c7f,_0x21f12c){'use strict';const _0x31c113=_0x5d5f;class _0x28abe8 extends _0x2cc7f1[_0x31c113(0xd6)]{async['getLintErrors'](){const _0x3b9cee=_0x31c113;return this[_0x3b9cee(0xd5)]()['getLintErrors']();}}_0x2cc7f1[_0x31c113(0xd6)]['extend'](_0x28abe8);class _0x142d77 extends _0x3cb89d['FWorkbook']{async[_0x31c113(0xf8)](){const _0x377ee5=_0x31c113,_0x1cdd90=this[_0x377ee5(0xfc)](),_0x305f60=await this[_0x377ee5(0xec)]();return{'formulaErrors':_0x1cdd90,'dataValidationErrors':_0x305f60};}}_0x3cb89d[_0x31c113(0xf6)][_0x31c113(0x102)](_0x142d77);class _0x13fb9b extends _0x3cb89d[_0x31c113(0xe6)]{async[_0x31c113(0xff)](){const _0x19ec40=_0x31c113,_0x4f0cbd=this[_0x19ec40(0xe2)][_0x19ec40(0xf5)](_0x3a0c7f[_0x19ec40(0xe4)]),_0x1c11ce=this['getRange'](0x0,0x0,this[_0x19ec40(0xfa)]()+0x1,this[_0x19ec40(0xf3)]()+0x1)[_0x19ec40(0xd8)]();return await _0x4f0cbd[_0x19ec40(0xed)](_0x1c11ce);}async[_0x31c113(0xfe)](){const _0x353a80=_0x31c113;return(await this[_0x353a80(0xff)]())[_0x353a80(0xdf)](_0x3a0c7f['toA1']);}}_0x3cb89d['FWorksheet'][_0x31c113(0x102)](_0x13fb9b);class _0x30e1d9 extends _0x3cb89d[_0x31c113(0xde)]{async[_0x31c113(0xff)](){const _0x1c0792=_0x31c113,_0xe52f8d=this[_0x1c0792(0xe2)][_0x1c0792(0xf5)](_0x3a0c7f[_0x1c0792(0xe4)]),_0x46f0f4=(({startRow:_0x179e8c,endRow:_0x1bf074,startColumn:_0x5c63b6,endColumn:_0x5a6eb4})=>{const _0x5b29df=_0x1c0792,_0x48887f=[];for(let _0x5e60dd=_0x179e8c;_0x5e60dd<=_0x1bf074;_0x5e60dd++){const _0x5a73bc=[];for(let _0x3e6391=_0x5c63b6;_0x3e6391<=_0x5a6eb4;_0x3e6391++)_0x5a73bc[_0x5b29df(0xef)](this[_0x5b29df(0xfb)][_0x5b29df(0xdb)](_0x5e60dd,_0x3e6391));_0x48887f['push'](_0x5a73bc);}return _0x48887f;})({'startRow':0x0,'endRow':this[_0x1c0792(0xfb)][_0x1c0792(0xfa)](),'startColumn':0x0,'endColumn':this[_0x1c0792(0xfb)][_0x1c0792(0xf3)]()}),_0x3cbc46=await _0xe52f8d[_0x1c0792(0xed)](_0x46f0f4),_0x4d39b2=this[_0x1c0792(0xe3)](),_0x11c641=[];for(let _0x42eb69=0x0;_0x42eb69<_0x3cbc46[_0x1c0792(0xf4)];_0x42eb69++){const _0x2fc43a=_0x3cbc46[_0x42eb69],_0x5bd5c8=_0x2fc43a[_0x1c0792(0xe1)],_0x657c2=[];for(let _0xbc71fa=0x0;_0xbc71fa<_0x5bd5c8[_0x1c0792(0xf4)];_0xbc71fa++){const _0x123ac7=_0x5bd5c8[_0xbc71fa],_0x27c444=_0x21f12c[_0x1c0792(0xdc)](_0x123ac7,_0x4d39b2);_0x27c444&&_0x657c2[_0x1c0792(0xef)](_0x27c444);}if(_0x657c2[_0x1c0792(0xf4)]>0x0){_0x2fc43a[_0x1c0792(0xe1)]=_0x657c2;const _0x52f8fc=_0x657c2[0x0],_0x22c3e8=_0x52f8fc[_0x1c0792(0x103)]-_0x4d39b2['startRow'],_0x349f5f=_0x52f8fc[_0x1c0792(0xf9)]-_0x4d39b2['startColumn'];_0x2fc43a[_0x1c0792(0xd7)]=await _0xe52f8d[_0x1c0792(0xeb)](_0x2fc43a['formula'],_0x22c3e8,_0x349f5f),_0x11c641[_0x1c0792(0xef)](_0x2fc43a);}}return _0x11c641;}async[_0x31c113(0xfe)](){const _0x4ec495=_0x31c113;return(await this[_0x4ec495(0xff)]())[_0x4ec495(0xdf)](_0x3a0c7f['toA1']);}}_0x3cb89d['FRange'][_0x31c113(0x102)](_0x30e1d9);}));