@ishibashi0112/spreadsheet-grid-core 1.13.0 → 1.14.0

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.
Files changed (43) hide show
  1. package/dist/controllers/debouncedValueStore.cjs +1 -1
  2. package/dist/controllers/debouncedValueStore.d.ts +2 -1
  3. package/dist/controllers/debouncedValueStore.js +10 -9
  4. package/dist/controllers/historyController.cjs +1 -1
  5. package/dist/controllers/historyController.js +1 -0
  6. package/dist/controllers/serverSideRowModel.cjs +1 -1
  7. package/dist/controllers/serverSideRowModel.d.ts +2 -1
  8. package/dist/controllers/serverSideRowModel.js +37 -36
  9. package/dist/engine/createGridEngine.cjs +1 -1
  10. package/dist/engine/createGridEngine.js +44 -37
  11. package/dist/engine/exportCommands.cjs +2 -2
  12. package/dist/engine/exportCommands.js +75 -54
  13. package/dist/engine/gridApi.cjs +10 -10
  14. package/dist/engine/gridApi.d.ts +5 -1
  15. package/dist/engine/gridApi.js +433 -236
  16. package/dist/engine/newRowController.cjs +1 -1
  17. package/dist/engine/newRowController.d.ts +4 -1
  18. package/dist/engine/newRowController.js +23 -1
  19. package/dist/index.cjs +1 -1
  20. package/dist/index.d.ts +2 -0
  21. package/dist/index.js +5 -4
  22. package/dist/locales/en.cjs +1 -1
  23. package/dist/locales/en.js +1 -0
  24. package/dist/logic/cellValueWrites.cjs +1 -0
  25. package/dist/logic/cellValueWrites.d.ts +21 -0
  26. package/dist/logic/cellValueWrites.js +70 -0
  27. package/dist/logic/exportData.cjs +1 -1
  28. package/dist/logic/exportData.d.ts +8 -2
  29. package/dist/logic/exportData.js +45 -27
  30. package/dist/logic/gridAgentTools.cjs +2 -0
  31. package/dist/logic/gridAgentTools.d.ts +125 -0
  32. package/dist/logic/gridAgentTools.js +673 -0
  33. package/dist/logic/gridAsk.cjs +3 -3
  34. package/dist/logic/gridAsk.d.ts +10 -0
  35. package/dist/logic/gridAsk.js +169 -156
  36. package/dist/logic/gridAskLocaleText.cjs +1 -1
  37. package/dist/logic/gridAskLocaleText.d.ts +5 -0
  38. package/dist/logic/gridAskLocaleText.js +1 -0
  39. package/dist/logic/grouping.cjs +1 -1
  40. package/dist/logic/grouping.d.ts +1 -0
  41. package/dist/logic/grouping.js +16 -2
  42. package/dist/model/gridTypes.core.d.ts +120 -2
  43. package/package.json +1 -1
@@ -0,0 +1,125 @@
1
+ import type { CellCoord, GridCellValueEdit, GridColumn as PublicGridColumn, GridExportData, GridExportOptions, GridRowCounts, GridRowKey, GridSelection, GridSetCellValuesResult, GridState, GridStatePatch } from '../model/gridTypes.core.js';
2
+ import { type GridAskOptions } from './gridAsk.js';
3
+ /** エージェントの道具が使うグリッドのハンドルのメソッド(React 版・Solid 版の `SpreadsheetGridHandle` をそのまま渡せる)。 */
4
+ export type GridAgentTarget = {
5
+ getState(): GridState;
6
+ applyState(state: GridStatePatch): void;
7
+ getRowCounts(): GridRowCounts;
8
+ getRowKey(viewRowIndex: number): GridRowKey | null;
9
+ getViewRowIndex(rowKey: GridRowKey): number;
10
+ getColIndex(columnKey: string): number;
11
+ getActiveCell(): CellCoord | null;
12
+ getSelection(): GridSelection;
13
+ revealRow(rowKey: GridRowKey, options?: {
14
+ columnKey?: string | undefined;
15
+ }): void;
16
+ scrollToRow(viewRowIndex: number, options?: {
17
+ align?: 'auto' | 'start' | 'center' | 'end' | undefined;
18
+ }): void;
19
+ getExportData(options?: GridExportOptions): GridExportData;
20
+ setCellValues(edits: readonly GridCellValueEdit[], options?: {
21
+ dryRun?: boolean | undefined;
22
+ }): GridSetCellValuesResult;
23
+ };
24
+ /** `confirm` に渡す、セルを書く前の確認です。 */
25
+ export type GridAgentConfirmRequest = {
26
+ /** 道具の名前(`<name>_set_cells`)。 */
27
+ tool: string;
28
+ /** 利用者に見せる文(`localeText` の `agentEditSummary`。既定 `3 セルを書き換えます(状態・在庫)`)。 */
29
+ summary: string;
30
+ /**
31
+ * 書くセル(行のキー・列のキー・値)。書かないと分かっているセル(見せていない列・今の表示に無い行・編集できないセル・
32
+ * 候補に無い値・検査で断られる値・今と同じ値)は入らない。1 つも書かないときは確認を呼ばない。
33
+ */
34
+ edits: GridCellValueEdit[];
35
+ /** AI の側で止めたときに abort する(確認の画面を閉じるのに使う)。 */
36
+ signal?: AbortSignal | undefined;
37
+ };
38
+ /** `onToolCall` に渡す、道具を 1 回呼んだ記録です。 */
39
+ export type GridAgentToolCall = {
40
+ name: string;
41
+ input: unknown;
42
+ output: GridAgentToolOutput;
43
+ };
44
+ /** 道具の結果です。失敗は `{ ok: false, error }`(throw しない)。 */
45
+ export type GridAgentToolOutput = {
46
+ ok: true;
47
+ [key: string]: unknown;
48
+ } | {
49
+ ok: false;
50
+ error: string;
51
+ };
52
+ /** 道具の実行のオプション(WebMCP / AI SDK の中断)。 */
53
+ export type GridAgentExecuteOptions = {
54
+ signal?: AbortSignal | undefined;
55
+ };
56
+ /** AI に渡す道具の定義(JSON にできる。サーバーへ送ってツールの一覧にする)。 */
57
+ export type GridAgentToolDefinition = {
58
+ name: string;
59
+ description: string;
60
+ /** 入力の JSON Schema(OpenAI の `strict: true` / Claude の strict でも通る形)。 */
61
+ inputSchema: Record<string, unknown>;
62
+ };
63
+ /**
64
+ * WebMCP の道具の注釈(`readOnlyHint` = 表を変えない、`untrustedContentHint` = 利用者の書いた行の文字を返す、
65
+ * `consequentialHint` = データを変える = セルを書く道具)。
66
+ */
67
+ export type GridAgentToolAnnotations = {
68
+ readOnlyHint?: boolean | undefined;
69
+ untrustedContentHint?: boolean | undefined;
70
+ consequentialHint?: boolean | undefined;
71
+ };
72
+ /** 実行できる道具(WebMCP の `registerTool` に渡せる形)。 */
73
+ export type GridAgentTool = GridAgentToolDefinition & {
74
+ annotations: GridAgentToolAnnotations;
75
+ execute: (input: unknown, options?: GridAgentExecuteOptions) => Promise<GridAgentToolOutput>;
76
+ };
77
+ export type GridAgentTools = {
78
+ /** 実行できる道具(`registerGridAgentTools` に渡す)。 */
79
+ tools: GridAgentTool[];
80
+ /** AI に渡す定義(`tools` から `execute` と `annotations` を外したもの)。 */
81
+ definitions: GridAgentToolDefinition[];
82
+ /** 名前で道具を実行します(AI SDK の `onToolCall` などから)。input は JSON の文字でもよい。 */
83
+ execute: (name: string, input: unknown, options?: GridAgentExecuteOptions) => Promise<GridAgentToolOutput>;
84
+ };
85
+ export type GridAgentToolsOptions<T> = Omit<GridAskOptions<T>, 'columns'> & {
86
+ /** グリッドのハンドル(React の ref か、ハンドルを返す関数)。 */
87
+ grid: {
88
+ readonly current: GridAgentTarget | null | undefined;
89
+ } | (() => GridAgentTarget | null | undefined);
90
+ /** グリッドと同じ列定義(`/ai` の `GridAskOptions.columns` と同じ)。 */
91
+ columns: readonly PublicGridColumn<T, any>[];
92
+ /** 道具の名前の頭(既定 `'grid'`。`inventory` で `inventory_get_view`)。英数字と `_` `-` だけ(ほかは `_` に)。 */
93
+ name?: string | undefined;
94
+ /** 表の説明(道具の説明に入る。例: `'商品の在庫の表'`)。1 つのページに表が 2 つあるときに AI が見分けられるように。 */
95
+ description?: string | undefined;
96
+ /** 行を読む道具 `<name>_read_rows` を出すか(既定 false)。`maxRows` は 1 回で読む行の上限(既定 50)。 */
97
+ readRows?: boolean | {
98
+ maxRows?: number | undefined;
99
+ } | undefined;
100
+ /** 選んだセルを読む道具 `<name>_read_selection` を出すか(既定 false)。`maxCells` は読むセルの上限(既定 500)。 */
101
+ readSelection?: boolean | {
102
+ maxCells?: number | undefined;
103
+ } | undefined;
104
+ /** セルに書く道具 `<name>_set_cells` を出すか(既定 false)。`maxCells` は 1 回で書くセルの上限(既定 500)。 */
105
+ editCells?: boolean | {
106
+ maxCells?: number | undefined;
107
+ } | undefined;
108
+ /** セルを書く前に聞く(false か、false で解決する Promise で書かない)。省略時は聞かずに書く(元に戻す 1 回で戻る)。 */
109
+ confirm?: ((request: GridAgentConfirmRequest) => boolean | Promise<boolean>) | undefined;
110
+ /** 道具を呼ぶたびに呼ばれる(画面に記録を出すときなど)。 */
111
+ onToolCall?: ((call: GridAgentToolCall) => void) | undefined;
112
+ };
113
+ /**
114
+ * AI エージェントがグリッドを操作する道具を作ります(1.14.0 から)。`tools` を `registerGridAgentTools` で
115
+ * ブラウザのエージェント(WebMCP)へ登録するか、`definitions` を自分のチャットの AI に渡して `execute` で動かします。
116
+ */
117
+ export declare const createGridAgentTools: <T>(options: GridAgentToolsOptions<T>) => GridAgentTools;
118
+ /**
119
+ * 道具をブラウザのエージェント(WebMCP の `document.modelContext.registerTool`)へ登録します(1.14.0 から)。
120
+ * WebMCP の無いブラウザでは何もせず `false` を返します。`signal` を abort すると登録を外します。
121
+ * 1 つでも登録できなければ(同じ名前の道具がある など)、この呼び出しで登録した道具をすべて外して `false` を返します。
122
+ */
123
+ export declare const registerGridAgentTools: (agentTools: Pick<GridAgentTools, "tools">, options?: {
124
+ signal?: AbortSignal | undefined;
125
+ }) => Promise<boolean>;