@agenticmail/enterprise 0.5.316 → 0.5.318
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.
- package/dist/agent-tools-263HM5QU.js +13949 -0
- package/dist/agent-tools-AT4D276V.js +13949 -0
- package/dist/chunk-36XNMIHA.js +5087 -0
- package/dist/chunk-6G5SXLXC.js +4921 -0
- package/dist/chunk-6PWDS7KY.js +5087 -0
- package/dist/chunk-D24JY75H.js +1519 -0
- package/dist/chunk-MMYBDHDB.js +4921 -0
- package/dist/chunk-OW4GLBHP.js +1519 -0
- package/dist/cli-agent-FNMDJN7T.js +2357 -0
- package/dist/cli-agent-ZSHUPBBN.js +2357 -0
- package/dist/cli-serve-DTQLN5UI.js +140 -0
- package/dist/cli-serve-LNTT73P2.js +140 -0
- package/dist/cli.js +3 -3
- package/dist/index.js +17 -17
- package/dist/integrations-TF4EBCJ7.js +43830 -0
- package/dist/microsoft-HPLA5ZL5.js +2414 -0
- package/dist/microsoft-UFLZBEAC.js +1619 -0
- package/dist/runtime-HTIM7GZR.js +45 -0
- package/dist/runtime-QQ6LAY4U.js +45 -0
- package/dist/server-DFR7FI3Q.js +28 -0
- package/dist/server-TXV3ZVVR.js +28 -0
- package/dist/setup-ADSKKBGV.js +20 -0
- package/dist/setup-LW4MLU2N.js +20 -0
- package/package.json +1 -1
- package/src/agent-tools/index.ts +7 -2
- package/src/agent-tools/tools/microsoft/contacts.ts +176 -0
- package/src/agent-tools/tools/microsoft/excel.ts +261 -0
- package/src/agent-tools/tools/microsoft/graph-api.ts +50 -0
- package/src/agent-tools/tools/microsoft/index.ts +79 -0
- package/src/agent-tools/tools/microsoft/onedrive.ts +228 -0
- package/src/agent-tools/tools/microsoft/onenote.ts +186 -0
- package/src/agent-tools/tools/microsoft/outlook-calendar.ts +286 -0
- package/src/agent-tools/tools/microsoft/outlook-mail.ts +431 -0
- package/src/agent-tools/tools/microsoft/sharepoint.ts +328 -0
- package/src/agent-tools/tools/microsoft/teams.ts +244 -0
- package/src/agent-tools/tools/microsoft/todo.ts +181 -0
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Microsoft Graph API helper
|
|
3
|
+
*
|
|
4
|
+
* Shared fetch wrapper for all Microsoft 365 tools.
|
|
5
|
+
* Uses Microsoft Graph API v1.0.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
const GRAPH_BASE = 'https://graph.microsoft.com/v1.0';
|
|
9
|
+
|
|
10
|
+
export async function graph(
|
|
11
|
+
token: string,
|
|
12
|
+
path: string,
|
|
13
|
+
opts?: {
|
|
14
|
+
method?: string;
|
|
15
|
+
body?: any;
|
|
16
|
+
query?: Record<string, string>;
|
|
17
|
+
rawBody?: BodyInit;
|
|
18
|
+
headers?: Record<string, string>;
|
|
19
|
+
beta?: boolean;
|
|
20
|
+
}
|
|
21
|
+
): Promise<any> {
|
|
22
|
+
const method = opts?.method || 'GET';
|
|
23
|
+
const base = opts?.beta ? 'https://graph.microsoft.com/beta' : GRAPH_BASE;
|
|
24
|
+
const url = new URL(base + path);
|
|
25
|
+
if (opts?.query) {
|
|
26
|
+
for (const [k, v] of Object.entries(opts.query)) {
|
|
27
|
+
if (v !== undefined && v !== '') url.searchParams.set(k, v);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
const headers: Record<string, string> = {
|
|
31
|
+
Authorization: `Bearer ${token}`,
|
|
32
|
+
...opts?.headers,
|
|
33
|
+
};
|
|
34
|
+
if (!opts?.rawBody && !opts?.headers?.['Content-Type']) {
|
|
35
|
+
headers['Content-Type'] = 'application/json';
|
|
36
|
+
}
|
|
37
|
+
const res = await fetch(url.toString(), {
|
|
38
|
+
method,
|
|
39
|
+
headers,
|
|
40
|
+
body: opts?.rawBody || (opts?.body ? JSON.stringify(opts.body) : undefined),
|
|
41
|
+
});
|
|
42
|
+
if (!res.ok) {
|
|
43
|
+
const err = await res.text();
|
|
44
|
+
throw new Error(`Microsoft Graph ${res.status}: ${err}`);
|
|
45
|
+
}
|
|
46
|
+
if (res.status === 204) return {};
|
|
47
|
+
const ct = res.headers.get('content-type') || '';
|
|
48
|
+
if (ct.includes('application/json')) return res.json();
|
|
49
|
+
return { content: await res.text() };
|
|
50
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Microsoft 365 Tools — Index
|
|
3
|
+
*
|
|
4
|
+
* All Microsoft Graph API tools for enterprise agents.
|
|
5
|
+
* Requires agent to have Microsoft OAuth configured with appropriate scopes.
|
|
6
|
+
*
|
|
7
|
+
* Services covered:
|
|
8
|
+
* - Outlook Mail (send, read, search, drafts, folders, attachments)
|
|
9
|
+
* - Outlook Calendar (events, free/busy, scheduling)
|
|
10
|
+
* - OneDrive (files, folders, search, sharing)
|
|
11
|
+
* - Teams (messages, channels, chats)
|
|
12
|
+
* - To Do (tasks, lists)
|
|
13
|
+
* - Contacts (people, address book)
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
export { createOutlookMailTools } from './outlook-mail.js';
|
|
17
|
+
export { createOutlookCalendarTools } from './outlook-calendar.js';
|
|
18
|
+
export { createOneDriveTools } from './onedrive.js';
|
|
19
|
+
export { createTeamsTools } from './teams.js';
|
|
20
|
+
export { createTodoTools } from './todo.js';
|
|
21
|
+
export { createOutlookContactsTools } from './contacts.js';
|
|
22
|
+
export { createExcelTools } from './excel.js';
|
|
23
|
+
export { createSharePointTools } from './sharepoint.js';
|
|
24
|
+
export { createOneNoteTools } from './onenote.js';
|
|
25
|
+
|
|
26
|
+
import type { AnyAgentTool, ToolCreationOptions } from '../../types.js';
|
|
27
|
+
import type { TokenProvider } from '../oauth-token-provider.js';
|
|
28
|
+
export type { TokenProvider };
|
|
29
|
+
|
|
30
|
+
import { createOutlookMailTools } from './outlook-mail.js';
|
|
31
|
+
import { createOutlookCalendarTools } from './outlook-calendar.js';
|
|
32
|
+
import { createOneDriveTools } from './onedrive.js';
|
|
33
|
+
import { createTeamsTools } from './teams.js';
|
|
34
|
+
import { createTodoTools } from './todo.js';
|
|
35
|
+
import { createOutlookContactsTools } from './contacts.js';
|
|
36
|
+
import { createExcelTools } from './excel.js';
|
|
37
|
+
import { createSharePointTools } from './sharepoint.js';
|
|
38
|
+
import { createOneNoteTools } from './onenote.js';
|
|
39
|
+
|
|
40
|
+
export interface MicrosoftToolsConfig {
|
|
41
|
+
tokenProvider: TokenProvider;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Create all Microsoft 365 tools for an agent.
|
|
46
|
+
*
|
|
47
|
+
* 9 services, 70+ tools:
|
|
48
|
+
* - Outlook Mail (13 tools) — inbox, send, reply, forward, search, drafts, attachments
|
|
49
|
+
* - Outlook Calendar (7 tools) — events, create, free/busy, respond to invites
|
|
50
|
+
* - OneDrive (7 tools) — files, folders, search, upload, share
|
|
51
|
+
* - Teams (8 tools) — channels, chats, messages, presence
|
|
52
|
+
* - To Do (6 tools) — task lists, tasks CRUD
|
|
53
|
+
* - Contacts (5 tools) — address book, people search
|
|
54
|
+
* - Excel (7 tools) — read/write cells, ranges, tables, worksheets
|
|
55
|
+
* - SharePoint (10 tools) — sites, document libraries, lists, search
|
|
56
|
+
* - OneNote (6 tools) — notebooks, sections, pages, read/write
|
|
57
|
+
*
|
|
58
|
+
* Core services (mail, calendar, onedrive, tasks) load by default.
|
|
59
|
+
* Enable additional services via enabledMicrosoftServices option.
|
|
60
|
+
*/
|
|
61
|
+
export function createAllMicrosoftTools(config: MicrosoftToolsConfig, options?: ToolCreationOptions): AnyAgentTool[] {
|
|
62
|
+
const enabled = (options as any)?.enabledMicrosoftServices as string[] | undefined;
|
|
63
|
+
const has = (s: string) => enabled ? enabled.includes(s) : false;
|
|
64
|
+
const core = !enabled; // default: load core services
|
|
65
|
+
|
|
66
|
+
const tools: AnyAgentTool[] = [];
|
|
67
|
+
// Core services (always loaded unless explicitly selecting)
|
|
68
|
+
if (core || has('mail')) tools.push(...createOutlookMailTools(config, options));
|
|
69
|
+
if (core || has('calendar')) tools.push(...createOutlookCalendarTools(config, options));
|
|
70
|
+
if (core || has('onedrive')) tools.push(...createOneDriveTools(config, options));
|
|
71
|
+
if (core || has('tasks')) tools.push(...createTodoTools(config, options));
|
|
72
|
+
// Extended services (opt-in)
|
|
73
|
+
if (has('teams')) tools.push(...createTeamsTools(config, options));
|
|
74
|
+
if (has('contacts')) tools.push(...createOutlookContactsTools(config, options));
|
|
75
|
+
if (has('excel')) tools.push(...createExcelTools(config, options));
|
|
76
|
+
if (has('sharepoint')) tools.push(...createSharePointTools(config, options));
|
|
77
|
+
if (has('onenote')) tools.push(...createOneNoteTools(config, options));
|
|
78
|
+
return tools;
|
|
79
|
+
}
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Microsoft OneDrive Tools
|
|
3
|
+
*
|
|
4
|
+
* File management via Microsoft Graph API — upload, download, search, share, folders.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import type { AnyAgentTool, ToolCreationOptions } from '../../types.js';
|
|
8
|
+
import { jsonResult, errorResult } from '../../common.js';
|
|
9
|
+
import type { MicrosoftToolsConfig } from './index.js';
|
|
10
|
+
import { graph } from './graph-api.js';
|
|
11
|
+
|
|
12
|
+
export function createOneDriveTools(config: MicrosoftToolsConfig, _options?: ToolCreationOptions): AnyAgentTool[] {
|
|
13
|
+
const tp = config.tokenProvider;
|
|
14
|
+
|
|
15
|
+
return [
|
|
16
|
+
{
|
|
17
|
+
name: 'onedrive_list',
|
|
18
|
+
description: 'List files and folders in OneDrive. Defaults to root folder.',
|
|
19
|
+
category: 'utility' as const,
|
|
20
|
+
parameters: {
|
|
21
|
+
type: 'object' as const,
|
|
22
|
+
properties: {
|
|
23
|
+
path: { type: 'string', description: 'Folder path (e.g., "/Documents/Reports") or item ID. Default: root' },
|
|
24
|
+
maxResults: { type: 'number', description: 'Max items to return (default: 50)' },
|
|
25
|
+
},
|
|
26
|
+
required: [],
|
|
27
|
+
},
|
|
28
|
+
async execute(_id: string, params: any) {
|
|
29
|
+
try {
|
|
30
|
+
const token = await tp.getAccessToken();
|
|
31
|
+
const top = params.maxResults || 50;
|
|
32
|
+
const basePath = params.path
|
|
33
|
+
? `/me/drive/root:${params.path}:/children`
|
|
34
|
+
: '/me/drive/root/children';
|
|
35
|
+
const data = await graph(token, basePath, {
|
|
36
|
+
query: { '$top': String(top), '$select': 'id,name,size,createdDateTime,lastModifiedDateTime,webUrl,folder,file,parentReference' }
|
|
37
|
+
});
|
|
38
|
+
const items = (data.value || []).map((i: any) => ({
|
|
39
|
+
id: i.id, name: i.name, size: i.size,
|
|
40
|
+
type: i.folder ? 'folder' : 'file',
|
|
41
|
+
mimeType: i.file?.mimeType,
|
|
42
|
+
childCount: i.folder?.childCount,
|
|
43
|
+
created: i.createdDateTime,
|
|
44
|
+
modified: i.lastModifiedDateTime,
|
|
45
|
+
webUrl: i.webUrl,
|
|
46
|
+
path: i.parentReference?.path,
|
|
47
|
+
}));
|
|
48
|
+
return jsonResult({ items, count: items.length });
|
|
49
|
+
} catch (e: any) { return errorResult(e.message); }
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
|
|
53
|
+
{
|
|
54
|
+
name: 'onedrive_search',
|
|
55
|
+
description: 'Search for files in OneDrive by name or content.',
|
|
56
|
+
category: 'utility' as const,
|
|
57
|
+
parameters: {
|
|
58
|
+
type: 'object' as const,
|
|
59
|
+
properties: {
|
|
60
|
+
query: { type: 'string', description: 'Search query' },
|
|
61
|
+
maxResults: { type: 'number', description: 'Max results (default: 20)' },
|
|
62
|
+
},
|
|
63
|
+
required: ['query'],
|
|
64
|
+
},
|
|
65
|
+
async execute(_id: string, params: any) {
|
|
66
|
+
try {
|
|
67
|
+
const token = await tp.getAccessToken();
|
|
68
|
+
const top = params.maxResults || 20;
|
|
69
|
+
const data = await graph(token, `/me/drive/root/search(q='${encodeURIComponent(params.query)}')`, {
|
|
70
|
+
query: { '$top': String(top), '$select': 'id,name,size,webUrl,file,folder,lastModifiedDateTime,parentReference' }
|
|
71
|
+
});
|
|
72
|
+
const items = (data.value || []).map((i: any) => ({
|
|
73
|
+
id: i.id, name: i.name, size: i.size,
|
|
74
|
+
type: i.folder ? 'folder' : 'file',
|
|
75
|
+
mimeType: i.file?.mimeType,
|
|
76
|
+
modified: i.lastModifiedDateTime,
|
|
77
|
+
webUrl: i.webUrl,
|
|
78
|
+
path: i.parentReference?.path,
|
|
79
|
+
}));
|
|
80
|
+
return jsonResult({ items, count: items.length, query: params.query });
|
|
81
|
+
} catch (e: any) { return errorResult(e.message); }
|
|
82
|
+
},
|
|
83
|
+
},
|
|
84
|
+
|
|
85
|
+
{
|
|
86
|
+
name: 'onedrive_read',
|
|
87
|
+
description: 'Read/download a file from OneDrive. For text files returns content; for binary returns download URL.',
|
|
88
|
+
category: 'utility' as const,
|
|
89
|
+
parameters: {
|
|
90
|
+
type: 'object' as const,
|
|
91
|
+
properties: {
|
|
92
|
+
itemId: { type: 'string', description: 'File item ID' },
|
|
93
|
+
path: { type: 'string', description: 'File path (alternative to itemId, e.g., "/Documents/report.txt")' },
|
|
94
|
+
},
|
|
95
|
+
required: [],
|
|
96
|
+
},
|
|
97
|
+
async execute(_id: string, params: any) {
|
|
98
|
+
try {
|
|
99
|
+
const token = await tp.getAccessToken();
|
|
100
|
+
const itemPath = params.itemId
|
|
101
|
+
? `/me/drive/items/${params.itemId}`
|
|
102
|
+
: `/me/drive/root:${params.path}:`;
|
|
103
|
+
// Get metadata
|
|
104
|
+
const meta = await graph(token, itemPath, {
|
|
105
|
+
query: { '$select': 'id,name,size,file,webUrl,@microsoft.graph.downloadUrl' }
|
|
106
|
+
});
|
|
107
|
+
const isText = meta.file?.mimeType?.startsWith('text/') ||
|
|
108
|
+
/\.(txt|md|csv|json|xml|html|css|js|ts|py|rb|go|rs|yaml|yml|toml|ini|cfg|log|sh|bat|ps1|sql)$/i.test(meta.name || '');
|
|
109
|
+
|
|
110
|
+
if (isText && meta.size < 1048576) { // < 1MB text files: return content
|
|
111
|
+
const contentRes = await fetch(meta['@microsoft.graph.downloadUrl'] || `https://graph.microsoft.com/v1.0${itemPath}/content`, {
|
|
112
|
+
headers: { Authorization: `Bearer ${token}` },
|
|
113
|
+
});
|
|
114
|
+
const content = await contentRes.text();
|
|
115
|
+
return jsonResult({ id: meta.id, name: meta.name, size: meta.size, content });
|
|
116
|
+
}
|
|
117
|
+
return jsonResult({
|
|
118
|
+
id: meta.id, name: meta.name, size: meta.size,
|
|
119
|
+
mimeType: meta.file?.mimeType,
|
|
120
|
+
downloadUrl: meta['@microsoft.graph.downloadUrl'],
|
|
121
|
+
webUrl: meta.webUrl,
|
|
122
|
+
});
|
|
123
|
+
} catch (e: any) { return errorResult(e.message); }
|
|
124
|
+
},
|
|
125
|
+
},
|
|
126
|
+
|
|
127
|
+
{
|
|
128
|
+
name: 'onedrive_upload',
|
|
129
|
+
description: 'Upload a text file to OneDrive. For small files (< 4MB).',
|
|
130
|
+
category: 'utility' as const,
|
|
131
|
+
parameters: {
|
|
132
|
+
type: 'object' as const,
|
|
133
|
+
properties: {
|
|
134
|
+
path: { type: 'string', description: 'Destination path (e.g., "/Documents/report.md")' },
|
|
135
|
+
content: { type: 'string', description: 'File content (text)' },
|
|
136
|
+
conflictBehavior: { type: 'string', description: 'rename, replace, or fail (default: replace)' },
|
|
137
|
+
},
|
|
138
|
+
required: ['path', 'content'],
|
|
139
|
+
},
|
|
140
|
+
async execute(_id: string, params: any) {
|
|
141
|
+
try {
|
|
142
|
+
const token = await tp.getAccessToken();
|
|
143
|
+
const conflict = params.conflictBehavior || 'replace';
|
|
144
|
+
const res = await fetch(`https://graph.microsoft.com/v1.0/me/drive/root:${params.path}:/content?@microsoft.graph.conflictBehavior=${conflict}`, {
|
|
145
|
+
method: 'PUT',
|
|
146
|
+
headers: { Authorization: `Bearer ${token}`, 'Content-Type': 'text/plain' },
|
|
147
|
+
body: params.content,
|
|
148
|
+
});
|
|
149
|
+
if (!res.ok) throw new Error(`Upload failed: ${res.status} ${await res.text()}`);
|
|
150
|
+
const data = await res.json();
|
|
151
|
+
return jsonResult({ id: data.id, name: data.name, size: data.size, webUrl: data.webUrl });
|
|
152
|
+
} catch (e: any) { return errorResult(e.message); }
|
|
153
|
+
},
|
|
154
|
+
},
|
|
155
|
+
|
|
156
|
+
{
|
|
157
|
+
name: 'onedrive_create_folder',
|
|
158
|
+
description: 'Create a new folder in OneDrive.',
|
|
159
|
+
category: 'utility' as const,
|
|
160
|
+
parameters: {
|
|
161
|
+
type: 'object' as const,
|
|
162
|
+
properties: {
|
|
163
|
+
name: { type: 'string', description: 'Folder name' },
|
|
164
|
+
parentPath: { type: 'string', description: 'Parent folder path (default: root)' },
|
|
165
|
+
},
|
|
166
|
+
required: ['name'],
|
|
167
|
+
},
|
|
168
|
+
async execute(_id: string, params: any) {
|
|
169
|
+
try {
|
|
170
|
+
const token = await tp.getAccessToken();
|
|
171
|
+
const parentPath = params.parentPath
|
|
172
|
+
? `/me/drive/root:${params.parentPath}:/children`
|
|
173
|
+
: '/me/drive/root/children';
|
|
174
|
+
const folder = await graph(token, parentPath, {
|
|
175
|
+
method: 'POST',
|
|
176
|
+
body: { name: params.name, folder: {}, '@microsoft.graph.conflictBehavior': 'rename' },
|
|
177
|
+
});
|
|
178
|
+
return jsonResult({ id: folder.id, name: folder.name, webUrl: folder.webUrl });
|
|
179
|
+
} catch (e: any) { return errorResult(e.message); }
|
|
180
|
+
},
|
|
181
|
+
},
|
|
182
|
+
|
|
183
|
+
{
|
|
184
|
+
name: 'onedrive_delete',
|
|
185
|
+
description: 'Delete a file or folder from OneDrive.',
|
|
186
|
+
category: 'utility' as const,
|
|
187
|
+
parameters: {
|
|
188
|
+
type: 'object' as const,
|
|
189
|
+
properties: {
|
|
190
|
+
itemId: { type: 'string', description: 'Item ID to delete' },
|
|
191
|
+
},
|
|
192
|
+
required: ['itemId'],
|
|
193
|
+
},
|
|
194
|
+
async execute(_id: string, params: any) {
|
|
195
|
+
try {
|
|
196
|
+
const token = await tp.getAccessToken();
|
|
197
|
+
await graph(token, `/me/drive/items/${params.itemId}`, { method: 'DELETE' });
|
|
198
|
+
return jsonResult({ deleted: true, itemId: params.itemId });
|
|
199
|
+
} catch (e: any) { return errorResult(e.message); }
|
|
200
|
+
},
|
|
201
|
+
},
|
|
202
|
+
|
|
203
|
+
{
|
|
204
|
+
name: 'onedrive_share',
|
|
205
|
+
description: 'Create a sharing link for a file or folder.',
|
|
206
|
+
category: 'utility' as const,
|
|
207
|
+
parameters: {
|
|
208
|
+
type: 'object' as const,
|
|
209
|
+
properties: {
|
|
210
|
+
itemId: { type: 'string', description: 'Item ID to share' },
|
|
211
|
+
type: { type: 'string', description: 'view or edit (default: view)' },
|
|
212
|
+
scope: { type: 'string', description: 'anonymous (anyone) or organization (default: organization)' },
|
|
213
|
+
},
|
|
214
|
+
required: ['itemId'],
|
|
215
|
+
},
|
|
216
|
+
async execute(_id: string, params: any) {
|
|
217
|
+
try {
|
|
218
|
+
const token = await tp.getAccessToken();
|
|
219
|
+
const link = await graph(token, `/me/drive/items/${params.itemId}/createLink`, {
|
|
220
|
+
method: 'POST',
|
|
221
|
+
body: { type: params.type || 'view', scope: params.scope || 'organization' },
|
|
222
|
+
});
|
|
223
|
+
return jsonResult({ url: link.link?.webUrl, type: link.link?.type, scope: link.link?.scope });
|
|
224
|
+
} catch (e: any) { return errorResult(e.message); }
|
|
225
|
+
},
|
|
226
|
+
},
|
|
227
|
+
];
|
|
228
|
+
}
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Microsoft OneNote Tools
|
|
3
|
+
*
|
|
4
|
+
* Notebooks, sections, and pages via Microsoft Graph API.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import type { AnyAgentTool, ToolCreationOptions } from '../../types.js';
|
|
8
|
+
import { jsonResult, errorResult } from '../../common.js';
|
|
9
|
+
import type { MicrosoftToolsConfig } from './index.js';
|
|
10
|
+
import { graph } from './graph-api.js';
|
|
11
|
+
|
|
12
|
+
export function createOneNoteTools(config: MicrosoftToolsConfig, _options?: ToolCreationOptions): AnyAgentTool[] {
|
|
13
|
+
const tp = config.tokenProvider;
|
|
14
|
+
|
|
15
|
+
return [
|
|
16
|
+
{
|
|
17
|
+
name: 'onenote_list_notebooks',
|
|
18
|
+
description: 'List all OneNote notebooks.',
|
|
19
|
+
category: 'utility' as const,
|
|
20
|
+
parameters: { type: 'object' as const, properties: {}, required: [] },
|
|
21
|
+
async execute(_id: string) {
|
|
22
|
+
try {
|
|
23
|
+
const token = await tp.getAccessToken();
|
|
24
|
+
const data = await graph(token, '/me/onenote/notebooks', {
|
|
25
|
+
query: { '$select': 'id,displayName,createdDateTime,lastModifiedDateTime,isShared,links', '$orderby': 'lastModifiedDateTime desc' }
|
|
26
|
+
});
|
|
27
|
+
const notebooks = (data.value || []).map((n: any) => ({
|
|
28
|
+
id: n.id, name: n.displayName, created: n.createdDateTime,
|
|
29
|
+
modified: n.lastModifiedDateTime, isShared: n.isShared,
|
|
30
|
+
webUrl: n.links?.oneNoteWebUrl?.href,
|
|
31
|
+
}));
|
|
32
|
+
return jsonResult({ notebooks, count: notebooks.length });
|
|
33
|
+
} catch (e: any) { return errorResult(e.message); }
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
|
|
37
|
+
{
|
|
38
|
+
name: 'onenote_list_sections',
|
|
39
|
+
description: 'List sections in a OneNote notebook.',
|
|
40
|
+
category: 'utility' as const,
|
|
41
|
+
parameters: {
|
|
42
|
+
type: 'object' as const,
|
|
43
|
+
properties: {
|
|
44
|
+
notebookId: { type: 'string', description: 'Notebook ID' },
|
|
45
|
+
},
|
|
46
|
+
required: ['notebookId'],
|
|
47
|
+
},
|
|
48
|
+
async execute(_id: string, params: any) {
|
|
49
|
+
try {
|
|
50
|
+
const token = await tp.getAccessToken();
|
|
51
|
+
const data = await graph(token, `/me/onenote/notebooks/${params.notebookId}/sections`, {
|
|
52
|
+
query: { '$select': 'id,displayName,createdDateTime,lastModifiedDateTime' }
|
|
53
|
+
});
|
|
54
|
+
const sections = (data.value || []).map((s: any) => ({
|
|
55
|
+
id: s.id, name: s.displayName,
|
|
56
|
+
created: s.createdDateTime, modified: s.lastModifiedDateTime,
|
|
57
|
+
}));
|
|
58
|
+
return jsonResult({ sections, count: sections.length });
|
|
59
|
+
} catch (e: any) { return errorResult(e.message); }
|
|
60
|
+
},
|
|
61
|
+
},
|
|
62
|
+
|
|
63
|
+
{
|
|
64
|
+
name: 'onenote_list_pages',
|
|
65
|
+
description: 'List pages in a OneNote section.',
|
|
66
|
+
category: 'utility' as const,
|
|
67
|
+
parameters: {
|
|
68
|
+
type: 'object' as const,
|
|
69
|
+
properties: {
|
|
70
|
+
sectionId: { type: 'string', description: 'Section ID' },
|
|
71
|
+
maxResults: { type: 'number', description: 'Max pages (default: 20)' },
|
|
72
|
+
},
|
|
73
|
+
required: ['sectionId'],
|
|
74
|
+
},
|
|
75
|
+
async execute(_id: string, params: any) {
|
|
76
|
+
try {
|
|
77
|
+
const token = await tp.getAccessToken();
|
|
78
|
+
const data = await graph(token, `/me/onenote/sections/${params.sectionId}/pages`, {
|
|
79
|
+
query: {
|
|
80
|
+
'$top': String(params.maxResults || 20),
|
|
81
|
+
'$select': 'id,title,createdDateTime,lastModifiedDateTime,links,level,order',
|
|
82
|
+
'$orderby': 'lastModifiedDateTime desc',
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
const pages = (data.value || []).map((p: any) => ({
|
|
86
|
+
id: p.id, title: p.title,
|
|
87
|
+
created: p.createdDateTime, modified: p.lastModifiedDateTime,
|
|
88
|
+
webUrl: p.links?.oneNoteWebUrl?.href,
|
|
89
|
+
}));
|
|
90
|
+
return jsonResult({ pages, count: pages.length });
|
|
91
|
+
} catch (e: any) { return errorResult(e.message); }
|
|
92
|
+
},
|
|
93
|
+
},
|
|
94
|
+
|
|
95
|
+
{
|
|
96
|
+
name: 'onenote_read_page',
|
|
97
|
+
description: 'Read the HTML content of a OneNote page.',
|
|
98
|
+
category: 'utility' as const,
|
|
99
|
+
parameters: {
|
|
100
|
+
type: 'object' as const,
|
|
101
|
+
properties: {
|
|
102
|
+
pageId: { type: 'string', description: 'Page ID' },
|
|
103
|
+
},
|
|
104
|
+
required: ['pageId'],
|
|
105
|
+
},
|
|
106
|
+
async execute(_id: string, params: any) {
|
|
107
|
+
try {
|
|
108
|
+
const token = await tp.getAccessToken();
|
|
109
|
+
const res = await fetch(`https://graph.microsoft.com/v1.0/me/onenote/pages/${params.pageId}/content`, {
|
|
110
|
+
headers: { Authorization: `Bearer ${token}` },
|
|
111
|
+
});
|
|
112
|
+
if (!res.ok) throw new Error(`OneNote API ${res.status}: ${await res.text()}`);
|
|
113
|
+
const html = await res.text();
|
|
114
|
+
// Strip HTML tags for a cleaner text view
|
|
115
|
+
const text = html.replace(/<[^>]+>/g, ' ').replace(/\s+/g, ' ').trim();
|
|
116
|
+
return jsonResult({ pageId: params.pageId, html, text: text.substring(0, 10000) });
|
|
117
|
+
} catch (e: any) { return errorResult(e.message); }
|
|
118
|
+
},
|
|
119
|
+
},
|
|
120
|
+
|
|
121
|
+
{
|
|
122
|
+
name: 'onenote_create_page',
|
|
123
|
+
description: 'Create a new page in a OneNote section. Content is HTML.',
|
|
124
|
+
category: 'utility' as const,
|
|
125
|
+
parameters: {
|
|
126
|
+
type: 'object' as const,
|
|
127
|
+
properties: {
|
|
128
|
+
sectionId: { type: 'string', description: 'Section ID to create the page in' },
|
|
129
|
+
title: { type: 'string', description: 'Page title' },
|
|
130
|
+
content: { type: 'string', description: 'Page content (HTML or plain text)' },
|
|
131
|
+
},
|
|
132
|
+
required: ['sectionId', 'title', 'content'],
|
|
133
|
+
},
|
|
134
|
+
async execute(_id: string, params: any) {
|
|
135
|
+
try {
|
|
136
|
+
const token = await tp.getAccessToken();
|
|
137
|
+
const html = `<!DOCTYPE html><html><head><title>${params.title}</title></head><body>${params.content}</body></html>`;
|
|
138
|
+
const res = await fetch(`https://graph.microsoft.com/v1.0/me/onenote/sections/${params.sectionId}/pages`, {
|
|
139
|
+
method: 'POST',
|
|
140
|
+
headers: {
|
|
141
|
+
Authorization: `Bearer ${token}`,
|
|
142
|
+
'Content-Type': 'application/xhtml+xml',
|
|
143
|
+
},
|
|
144
|
+
body: html,
|
|
145
|
+
});
|
|
146
|
+
if (!res.ok) throw new Error(`OneNote API ${res.status}: ${await res.text()}`);
|
|
147
|
+
const page = await res.json();
|
|
148
|
+
return jsonResult({
|
|
149
|
+
id: page.id, title: page.title,
|
|
150
|
+
webUrl: page.links?.oneNoteWebUrl?.href,
|
|
151
|
+
created: true,
|
|
152
|
+
});
|
|
153
|
+
} catch (e: any) { return errorResult(e.message); }
|
|
154
|
+
},
|
|
155
|
+
},
|
|
156
|
+
|
|
157
|
+
{
|
|
158
|
+
name: 'onenote_update_page',
|
|
159
|
+
description: 'Append content to an existing OneNote page.',
|
|
160
|
+
category: 'utility' as const,
|
|
161
|
+
parameters: {
|
|
162
|
+
type: 'object' as const,
|
|
163
|
+
properties: {
|
|
164
|
+
pageId: { type: 'string', description: 'Page ID' },
|
|
165
|
+
content: { type: 'string', description: 'HTML content to append' },
|
|
166
|
+
position: { type: 'string', description: 'Where to add: after (end of body) or before (start of body). Default: after' },
|
|
167
|
+
},
|
|
168
|
+
required: ['pageId', 'content'],
|
|
169
|
+
},
|
|
170
|
+
async execute(_id: string, params: any) {
|
|
171
|
+
try {
|
|
172
|
+
const token = await tp.getAccessToken();
|
|
173
|
+
await graph(token, `/me/onenote/pages/${params.pageId}/content`, {
|
|
174
|
+
method: 'PATCH',
|
|
175
|
+
body: [{
|
|
176
|
+
target: 'body',
|
|
177
|
+
action: params.position === 'before' ? 'prepend' : 'append',
|
|
178
|
+
content: params.content,
|
|
179
|
+
}],
|
|
180
|
+
});
|
|
181
|
+
return jsonResult({ updated: true, pageId: params.pageId });
|
|
182
|
+
} catch (e: any) { return errorResult(e.message); }
|
|
183
|
+
},
|
|
184
|
+
},
|
|
185
|
+
];
|
|
186
|
+
}
|