@opentabs-dev/opentabs-plugin-microsoft-word 0.0.74
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/README.md +159 -0
- package/dist/adapter.iife.js +15874 -0
- package/dist/adapter.iife.js.map +7 -0
- package/dist/docx-utils.d.ts +63 -0
- package/dist/docx-utils.d.ts.map +1 -0
- package/dist/docx-utils.js +370 -0
- package/dist/docx-utils.js.map +1 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +78 -0
- package/dist/index.js.map +1 -0
- package/dist/microsoft-word-api.d.ts +17 -0
- package/dist/microsoft-word-api.d.ts.map +1 -0
- package/dist/microsoft-word-api.js +142 -0
- package/dist/microsoft-word-api.js.map +1 -0
- package/dist/tools/append-to-document.d.ts +8 -0
- package/dist/tools/append-to-document.d.ts.map +1 -0
- package/dist/tools/append-to-document.js +26 -0
- package/dist/tools/append-to-document.js.map +1 -0
- package/dist/tools/copy-item.d.ts +9 -0
- package/dist/tools/copy-item.d.ts.map +1 -0
- package/dist/tools/copy-item.js +69 -0
- package/dist/tools/copy-item.js.map +1 -0
- package/dist/tools/create-document.d.ts +20 -0
- package/dist/tools/create-document.d.ts.map +1 -0
- package/dist/tools/create-document.js +73 -0
- package/dist/tools/create-document.js.map +1 -0
- package/dist/tools/create-folder.d.ts +20 -0
- package/dist/tools/create-folder.d.ts.map +1 -0
- package/dist/tools/create-folder.js +30 -0
- package/dist/tools/create-folder.js.map +1 -0
- package/dist/tools/create-sharing-link.d.ts +22 -0
- package/dist/tools/create-sharing-link.d.ts.map +1 -0
- package/dist/tools/create-sharing-link.js +31 -0
- package/dist/tools/create-sharing-link.js.map +1 -0
- package/dist/tools/delete-item.d.ts +7 -0
- package/dist/tools/delete-item.d.ts.map +1 -0
- package/dist/tools/delete-item.js +24 -0
- package/dist/tools/delete-item.js.map +1 -0
- package/dist/tools/delete-permission.d.ts +8 -0
- package/dist/tools/delete-permission.d.ts.map +1 -0
- package/dist/tools/delete-permission.js +23 -0
- package/dist/tools/delete-permission.js.map +1 -0
- package/dist/tools/docx-edit-helpers.d.ts +10 -0
- package/dist/tools/docx-edit-helpers.d.ts.map +1 -0
- package/dist/tools/docx-edit-helpers.js +103 -0
- package/dist/tools/docx-edit-helpers.js.map +1 -0
- package/dist/tools/get-active-document.d.ts +18 -0
- package/dist/tools/get-active-document.d.ts.map +1 -0
- package/dist/tools/get-active-document.js +50 -0
- package/dist/tools/get-active-document.js.map +1 -0
- package/dist/tools/get-current-user.d.ts +9 -0
- package/dist/tools/get-current-user.d.ts.map +1 -0
- package/dist/tools/get-current-user.js +23 -0
- package/dist/tools/get-current-user.js.map +1 -0
- package/dist/tools/get-document-text.d.ts +8 -0
- package/dist/tools/get-document-text.d.ts.map +1 -0
- package/dist/tools/get-document-text.js +87 -0
- package/dist/tools/get-document-text.js.map +1 -0
- package/dist/tools/get-drive.d.ts +15 -0
- package/dist/tools/get-drive.d.ts.map +1 -0
- package/dist/tools/get-drive.js +19 -0
- package/dist/tools/get-drive.js.map +1 -0
- package/dist/tools/get-file-content.d.ts +8 -0
- package/dist/tools/get-file-content.d.ts.map +1 -0
- package/dist/tools/get-file-content.js +74 -0
- package/dist/tools/get-file-content.js.map +1 -0
- package/dist/tools/get-item.d.ts +19 -0
- package/dist/tools/get-item.d.ts.map +1 -0
- package/dist/tools/get-item.js +25 -0
- package/dist/tools/get-item.js.map +1 -0
- package/dist/tools/get-preview-url.d.ts +7 -0
- package/dist/tools/get-preview-url.d.ts.map +1 -0
- package/dist/tools/get-preview-url.js +22 -0
- package/dist/tools/get-preview-url.js.map +1 -0
- package/dist/tools/list-children.d.ts +21 -0
- package/dist/tools/list-children.d.ts.map +1 -0
- package/dist/tools/list-children.js +33 -0
- package/dist/tools/list-children.js.map +1 -0
- package/dist/tools/list-permissions.d.ts +13 -0
- package/dist/tools/list-permissions.d.ts.map +1 -0
- package/dist/tools/list-permissions.js +23 -0
- package/dist/tools/list-permissions.js.map +1 -0
- package/dist/tools/list-recent-documents.d.ts +19 -0
- package/dist/tools/list-recent-documents.d.ts.map +1 -0
- package/dist/tools/list-recent-documents.js +27 -0
- package/dist/tools/list-recent-documents.js.map +1 -0
- package/dist/tools/list-shared-with-me.d.ts +19 -0
- package/dist/tools/list-shared-with-me.d.ts.map +1 -0
- package/dist/tools/list-shared-with-me.js +28 -0
- package/dist/tools/list-shared-with-me.js.map +1 -0
- package/dist/tools/list-versions.d.ts +11 -0
- package/dist/tools/list-versions.d.ts.map +1 -0
- package/dist/tools/list-versions.js +23 -0
- package/dist/tools/list-versions.js.map +1 -0
- package/dist/tools/move-item.d.ts +20 -0
- package/dist/tools/move-item.d.ts.map +1 -0
- package/dist/tools/move-item.js +27 -0
- package/dist/tools/move-item.js.map +1 -0
- package/dist/tools/rename-item.d.ts +20 -0
- package/dist/tools/rename-item.d.ts.map +1 -0
- package/dist/tools/rename-item.js +27 -0
- package/dist/tools/rename-item.js.map +1 -0
- package/dist/tools/replace-text-in-document.d.ts +10 -0
- package/dist/tools/replace-text-in-document.d.ts.map +1 -0
- package/dist/tools/replace-text-in-document.js +31 -0
- package/dist/tools/replace-text-in-document.js.map +1 -0
- package/dist/tools/restore-version.d.ts +8 -0
- package/dist/tools/restore-version.d.ts.map +1 -0
- package/dist/tools/restore-version.js +23 -0
- package/dist/tools/restore-version.js.map +1 -0
- package/dist/tools/schemas.d.ts +155 -0
- package/dist/tools/schemas.d.ts.map +1 -0
- package/dist/tools/schemas.js +90 -0
- package/dist/tools/schemas.js.map +1 -0
- package/dist/tools/search-files.d.ts +20 -0
- package/dist/tools/search-files.d.ts.map +1 -0
- package/dist/tools/search-files.js +29 -0
- package/dist/tools/search-files.js.map +1 -0
- package/dist/tools/update-document.d.ts +8 -0
- package/dist/tools/update-document.d.ts.map +1 -0
- package/dist/tools/update-document.js +26 -0
- package/dist/tools/update-document.js.map +1 -0
- package/dist/tools/update-file-content.d.ts +21 -0
- package/dist/tools/update-file-content.d.ts.map +1 -0
- package/dist/tools/update-file-content.js +66 -0
- package/dist/tools/update-file-content.js.map +1 -0
- package/dist/tools/upload-file.d.ts +21 -0
- package/dist/tools/upload-file.d.ts.map +1 -0
- package/dist/tools/upload-file.js +64 -0
- package/dist/tools/upload-file.js.map +1 -0
- package/dist/tools.json +1940 -0
- package/package.json +55 -0
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
// --- User ---
|
|
3
|
+
export const userSchema = z.object({
|
|
4
|
+
id: z.string().describe('User ID'),
|
|
5
|
+
display_name: z.string().describe('Display name'),
|
|
6
|
+
email: z.string().describe('Email address'),
|
|
7
|
+
});
|
|
8
|
+
export const mapUser = (u) => ({
|
|
9
|
+
id: u.id ?? '',
|
|
10
|
+
display_name: u.displayName ?? '',
|
|
11
|
+
email: u.mail ?? u.userPrincipalName ?? '',
|
|
12
|
+
});
|
|
13
|
+
// --- Drive ---
|
|
14
|
+
export const quotaSchema = z.object({
|
|
15
|
+
total: z.number().describe('Total storage in bytes'),
|
|
16
|
+
used: z.number().describe('Used storage in bytes'),
|
|
17
|
+
remaining: z.number().describe('Remaining storage in bytes'),
|
|
18
|
+
state: z.string().describe('Quota state (normal, nearing, critical, exceeded)'),
|
|
19
|
+
});
|
|
20
|
+
export const driveSchema = z.object({
|
|
21
|
+
id: z.string().describe('Drive ID'),
|
|
22
|
+
name: z.string().describe('Drive name'),
|
|
23
|
+
drive_type: z.string().describe('Drive type (personal, business, documentLibrary)'),
|
|
24
|
+
quota: quotaSchema.describe('Storage quota information'),
|
|
25
|
+
});
|
|
26
|
+
export const mapDrive = (d) => ({
|
|
27
|
+
id: d.id ?? '',
|
|
28
|
+
name: d.name ?? '',
|
|
29
|
+
drive_type: d.driveType ?? '',
|
|
30
|
+
quota: {
|
|
31
|
+
total: d.quota?.total ?? 0,
|
|
32
|
+
used: d.quota?.used ?? 0,
|
|
33
|
+
remaining: d.quota?.remaining ?? 0,
|
|
34
|
+
state: d.quota?.state ?? '',
|
|
35
|
+
},
|
|
36
|
+
});
|
|
37
|
+
// --- Drive Item (file or folder) ---
|
|
38
|
+
export const driveItemSchema = z.object({
|
|
39
|
+
id: z.string().describe('Item ID'),
|
|
40
|
+
name: z.string().describe('File or folder name'),
|
|
41
|
+
size: z.number().describe('Size in bytes (0 for folders)'),
|
|
42
|
+
is_folder: z.boolean().describe('Whether the item is a folder'),
|
|
43
|
+
mime_type: z.string().describe('MIME type (empty for folders)'),
|
|
44
|
+
web_url: z.string().describe('URL to open in browser'),
|
|
45
|
+
created_at: z.string().describe('ISO 8601 creation timestamp'),
|
|
46
|
+
last_modified_at: z.string().describe('ISO 8601 last modification timestamp'),
|
|
47
|
+
parent_path: z.string().describe('Parent folder path'),
|
|
48
|
+
parent_id: z.string().describe('Parent folder ID'),
|
|
49
|
+
description: z.string().describe('Item description'),
|
|
50
|
+
});
|
|
51
|
+
export const mapDriveItem = (i) => ({
|
|
52
|
+
id: i.id ?? '',
|
|
53
|
+
name: i.name ?? '',
|
|
54
|
+
size: i.size ?? 0,
|
|
55
|
+
is_folder: !!i.folder,
|
|
56
|
+
mime_type: i.file?.mimeType ?? '',
|
|
57
|
+
web_url: i.webUrl ?? '',
|
|
58
|
+
created_at: i.createdDateTime ?? '',
|
|
59
|
+
last_modified_at: i.lastModifiedDateTime ?? '',
|
|
60
|
+
parent_path: i.parentReference?.path ?? '',
|
|
61
|
+
parent_id: i.parentReference?.id ?? '',
|
|
62
|
+
description: i.description ?? '',
|
|
63
|
+
});
|
|
64
|
+
// --- Permission ---
|
|
65
|
+
export const permissionSchema = z.object({
|
|
66
|
+
id: z.string().describe('Permission ID'),
|
|
67
|
+
roles: z.array(z.string()).describe('Permission roles (read, write, owner)'),
|
|
68
|
+
link_url: z.string().describe('Sharing link URL (empty if not a link permission)'),
|
|
69
|
+
link_type: z.string().describe('Link type (view, edit, embed) — empty if not a link'),
|
|
70
|
+
granted_to: z.string().describe('Display name of the grantee — empty if anonymous link'),
|
|
71
|
+
});
|
|
72
|
+
export const mapPermission = (p) => ({
|
|
73
|
+
id: p.id ?? '',
|
|
74
|
+
roles: p.roles ?? [],
|
|
75
|
+
link_url: p.link?.webUrl ?? '',
|
|
76
|
+
link_type: p.link?.type ?? '',
|
|
77
|
+
granted_to: p.grantedTo?.user?.displayName ?? p.grantedToIdentities?.[0]?.user?.displayName ?? '',
|
|
78
|
+
});
|
|
79
|
+
// --- Version ---
|
|
80
|
+
export const versionSchema = z.object({
|
|
81
|
+
id: z.string().describe('Version ID'),
|
|
82
|
+
last_modified_at: z.string().describe('ISO 8601 last modification timestamp'),
|
|
83
|
+
size: z.number().describe('Size in bytes'),
|
|
84
|
+
});
|
|
85
|
+
export const mapVersion = (v) => ({
|
|
86
|
+
id: v.id ?? '',
|
|
87
|
+
last_modified_at: v.lastModifiedDateTime ?? '',
|
|
88
|
+
size: v.size ?? 0,
|
|
89
|
+
});
|
|
90
|
+
//# sourceMappingURL=schemas.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schemas.js","sourceRoot":"","sources":["../../src/tools/schemas.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,eAAe;AAEf,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,CAAC,MAAM,CAAC;IACjC,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,SAAS,CAAC;IAClC,YAAY,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,cAAc,CAAC;IACjD,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,eAAe,CAAC;CAC5C,CAAC,CAAC;AASH,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,CAAU,EAAE,EAAE,CAAC,CAAC;IACtC,EAAE,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE;IACd,YAAY,EAAE,CAAC,CAAC,WAAW,IAAI,EAAE;IACjC,KA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AAC,CAAC,IAAI,EAAE,IAAI,IAAI,EAAE;IAC7B,UAAU,EAAE,CAAC,CAAC,SAAS,EAAE,IAAI,EAAE,WAAW,IAAI,CAAC,CAAC,mBAAmB,EAAE,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,WAAW,IAAI,EAAE;CAClG,CAAC,CAAC;AAEH,kBAAkB;AAElB,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,CAAC,MAAM,CAAC;IACpC,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,YAAY,CAAC;IACrC,gBAAgB,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,sCAAsC,CAAC;IAC7E,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,eAAe,CAAC;CAC3C,CAAC,CAAC;AAQH,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,CAAa,EAAE,EAAE,CAAC,CAAC;IAC5C,EAAE,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE;IACd,gBAAgB,EAAE,CAAC,CAAC,oBAAoB,IAAI,EAAE;IAC9C,IAAI,EAAE,CAAC,CAAC,IAAI,IAAI,CAAC;CAClB,CAAC,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export declare const searchFiles: import("@opentabs-dev/plugin-sdk").ToolDefinition<z.ZodObject<{
|
|
3
|
+
query: z.ZodString;
|
|
4
|
+
top: z.ZodOptional<z.ZodNumber>;
|
|
5
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
6
|
+
items: z.ZodArray<z.ZodObject<{
|
|
7
|
+
id: z.ZodString;
|
|
8
|
+
name: z.ZodString;
|
|
9
|
+
size: z.ZodNumber;
|
|
10
|
+
is_folder: z.ZodBoolean;
|
|
11
|
+
mime_type: z.ZodString;
|
|
12
|
+
web_url: z.ZodString;
|
|
13
|
+
created_at: z.ZodString;
|
|
14
|
+
last_modified_at: z.ZodString;
|
|
15
|
+
parent_path: z.ZodString;
|
|
16
|
+
parent_id: z.ZodString;
|
|
17
|
+
description: z.ZodString;
|
|
18
|
+
}, z.core.$strip>>;
|
|
19
|
+
}, z.core.$strip>>;
|
|
20
|
+
//# sourceMappingURL=search-files.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"search-files.d.ts","sourceRoot":"","sources":["../../src/tools/search-files.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAIxB,eAAO,MAAM,WAAW;;;;;;;;;;;;;;;;;kBAuBtB,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { defineTool } from '@opentabs-dev/plugin-sdk';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { api } from '../microsoft-word-api.js';
|
|
4
|
+
import { driveItemSchema, mapDriveItem } from './schemas.js';
|
|
5
|
+
export const searchFiles = defineTool({
|
|
6
|
+
name: 'search_files',
|
|
7
|
+
displayName: 'Search Files',
|
|
8
|
+
description: 'Search for files and folders by name in OneDrive.',
|
|
9
|
+
summary: 'Search files and folders',
|
|
10
|
+
icon: 'search',
|
|
11
|
+
group: 'Files',
|
|
12
|
+
input: z.object({
|
|
13
|
+
query: z.string().min(1).describe('Search query text'),
|
|
14
|
+
top: z.number().int().min(1).max(50).optional().describe('Max results (default 10, max 50)'),
|
|
15
|
+
}),
|
|
16
|
+
output: z.object({
|
|
17
|
+
items: z.array(driveItemSchema).describe('Matching files and folders'),
|
|
18
|
+
}),
|
|
19
|
+
handle: async (params) => {
|
|
20
|
+
const q = params.query.replace(/'/g, "''");
|
|
21
|
+
const data = await api(`/me/drive/root/search(q='${q}')`, {
|
|
22
|
+
query: {
|
|
23
|
+
$top: params.top ?? 10,
|
|
24
|
+
},
|
|
25
|
+
});
|
|
26
|
+
return { items: (data.value ?? []).map(mapDriveItem) };
|
|
27
|
+
},
|
|
28
|
+
});
|
|
29
|
+
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E;gBACL,IAAI,EAAE,MAAM,CAAC,GAAG,IAAI,EAAE;aACvB;SACF,CAAC,CAAC;QACH,OAAO,EAAE,KAAK,EAAE,CAAC,IAAI,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,YAAY,CAAC,EAAE,CAAC;IACzD,CAAC;CACF,CAAC,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export declare const updateDocument: import("@opentabs-dev/plugin-sdk").ToolDefinition<z.ZodObject<{
|
|
3
|
+
item_id: z.ZodString;
|
|
4
|
+
paragraphs: z.ZodArray<z.ZodString>;
|
|
5
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
6
|
+
success: z.ZodBoolean;
|
|
7
|
+
}, z.core.$strip>>;
|
|
8
|
+
//# sourceMappingURL=update-document.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"update-document.d.ts","sourceRoot":"","sources":["../../src/tools/update-document.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAIxB,eAAO,MAAM,cAAc;;;;;kBAwBzB,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { defineTool } from '@opentabs-dev/plugin-sdk';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { replaceBodyContent } from '../docx-utils.js';
|
|
4
|
+
import { downloadDocxEntries, uploadModifiedDocx } from './docx-edit-helpers.js';
|
|
5
|
+
export const updateDocument = defineTool({
|
|
6
|
+
name: 'update_document',
|
|
7
|
+
displayName: 'Update Document',
|
|
8
|
+
description: 'Replace the entire text content of an existing Word document (.docx). Downloads the document, replaces all body content with the new paragraphs, and re-uploads. WARNING: This removes all existing formatting (bold, italic, headings, etc.) — use replace_text_in_document for formatting-safe edits.',
|
|
9
|
+
summary: 'Replace all text in a Word document',
|
|
10
|
+
icon: 'file-pen',
|
|
11
|
+
group: 'Documents',
|
|
12
|
+
input: z.object({
|
|
13
|
+
item_id: z.string().describe('File ID of the .docx document to update'),
|
|
14
|
+
paragraphs: z.array(z.string()).min(1).describe('New text paragraphs to replace the document body content'),
|
|
15
|
+
}),
|
|
16
|
+
output: z.object({
|
|
17
|
+
success: z.boolean().describe('Whether the document was updated'),
|
|
18
|
+
}),
|
|
19
|
+
handle: async (params) => {
|
|
20
|
+
const { entries, documentXml, documentXmlIndex } = await downloadDocxEntries(params.item_id);
|
|
21
|
+
const newXml = replaceBodyContent(documentXml, params.paragraphs);
|
|
22
|
+
await uploadModifiedDocx(params.item_id, entries, documentXmlIndex, newXml);
|
|
23
|
+
return { success: true };
|
|
24
|
+
},
|
|
25
|
+
});
|
|
26
|
+
//# sourceMappingURL=update-document.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"update-document.js","sourceRoot":"","sources":["../../src/tools/update-document.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AACtD,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AACtD,OAAO,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAEjF,MAAM,CAAC,MAAM,cAAc,GAAG,UAAU,CAAC;IACvC,IAAI,EAAE,iBAAiB;IACvB,WAAW,EAAE,iBAAiB;IAC9B,WAAW,EACT,ySAAyS;IAC3S,OAAO,EAAE,qCAAqC;IAC9C,IAAI,EAAE,UAAU;IAChB,KAAK,EAAE,WAAW;IAClB,KAAK,EAAE,CAAC,CAAC,MAAM,CAAC;QACd,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,yCAAyC,CAAC;QACvE,UAAU,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,0DAA0D,CAAC;KAC5G,CAAC;IACF,MAAM,EAAE,CAAC,CAAC,MAAM,CAAC;QACf,OAAO,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,QAAQ,CAAC,kCAAkC,CAAC;KAClE,CAAC;IACF,MAAM,EAAE,KAAK,EAAC,MAAM,EAAC,EAAE;QACrB,MAAM,EAAE,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAE,GAAG,MAAM,mBAAmB,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;QAE7F,MAAM,MAAM,GAAG,kBAAkB,CAAC,WAAW,EAAE,MAAM,CAAC,UAAU,CAAC,CAAC;QAElE,MAAM,kBAAkB,CAAC,MAAM,CAAC,OAAO,EAAE,OAAO,EAAE,gBAAgB,EAAE,MAAM,CAAC,CAAC;QAE5E,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;IAC3B,CAAC;CACF,CAAC,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export declare const updateFileContent: import("@opentabs-dev/plugin-sdk").ToolDefinition<z.ZodObject<{
|
|
3
|
+
item_id: z.ZodString;
|
|
4
|
+
content: z.ZodString;
|
|
5
|
+
content_type: z.ZodOptional<z.ZodString>;
|
|
6
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
7
|
+
item: z.ZodObject<{
|
|
8
|
+
id: z.ZodString;
|
|
9
|
+
name: z.ZodString;
|
|
10
|
+
size: z.ZodNumber;
|
|
11
|
+
is_folder: z.ZodBoolean;
|
|
12
|
+
mime_type: z.ZodString;
|
|
13
|
+
web_url: z.ZodString;
|
|
14
|
+
created_at: z.ZodString;
|
|
15
|
+
last_modified_at: z.ZodString;
|
|
16
|
+
parent_path: z.ZodString;
|
|
17
|
+
parent_id: z.ZodString;
|
|
18
|
+
description: z.ZodString;
|
|
19
|
+
}, z.core.$strip>;
|
|
20
|
+
}, z.core.$strip>>;
|
|
21
|
+
//# sourceMappingURL=update-file-content.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"update-file-content.d.ts","sourceRoot":"","sources":["../../src/tools/update-file-content.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAMxB,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;;;;;;kBA+D5B,CAAC"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { ToolError, clearAuthCache, defineTool } from '@opentabs-dev/plugin-sdk';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { getGraphToken } from '../microsoft-word-api.js';
|
|
4
|
+
import { driveItemSchema, mapDriveItem } from './schemas.js';
|
|
5
|
+
const GRAPH_API_BASE = 'https://graph.microsoft.com/v1.0';
|
|
6
|
+
export const updateFileContent = defineTool({
|
|
7
|
+
name: 'update_file_content',
|
|
8
|
+
displayName: 'Update File Content',
|
|
9
|
+
description: 'Update the content of an existing file by its ID.',
|
|
10
|
+
summary: "Update a file's content",
|
|
11
|
+
icon: 'file-pen',
|
|
12
|
+
group: 'Files',
|
|
13
|
+
input: z.object({
|
|
14
|
+
item_id: z.string().describe('File ID'),
|
|
15
|
+
content: z.string().describe('New file content'),
|
|
16
|
+
content_type: z.string().optional().describe('MIME type (default "text/plain")'),
|
|
17
|
+
}),
|
|
18
|
+
output: z.object({
|
|
19
|
+
item: driveItemSchema.describe('The updated file'),
|
|
20
|
+
}),
|
|
21
|
+
handle: async (params) => {
|
|
22
|
+
const token = getGraphToken();
|
|
23
|
+
const url = `${GRAPH_API_BASE}/me/drive/items/${params.item_id}/content`;
|
|
24
|
+
let response;
|
|
25
|
+
try {
|
|
26
|
+
response = await fetch(url, {
|
|
27
|
+
method: 'PUT',
|
|
28
|
+
credentials: 'omit',
|
|
29
|
+
headers: {
|
|
30
|
+
Authorization: `Bearer ${token}`,
|
|
31
|
+
'Content-Type': params.content_type ?? 'text/plain',
|
|
32
|
+
},
|
|
33
|
+
body: params.content,
|
|
34
|
+
signal: AbortSignal.timeout(30_000),
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
catch (err) {
|
|
38
|
+
if (err instanceof DOMException && err.name === 'TimeoutError') {
|
|
39
|
+
throw ToolError.timeout('Microsoft Graph API request timed out.');
|
|
40
|
+
}
|
|
41
|
+
throw ToolError.internal(`Network error: ${err instanceof Error ? err.message : 'unknown'}`);
|
|
42
|
+
}
|
|
43
|
+
if (response.status === 401 || response.status === 403) {
|
|
44
|
+
clearAuthCache('microsoft-word');
|
|
45
|
+
throw ToolError.auth('Authentication expired — please refresh the page.');
|
|
46
|
+
}
|
|
47
|
+
if (response.status === 404) {
|
|
48
|
+
throw ToolError.notFound('The requested file was not found.');
|
|
49
|
+
}
|
|
50
|
+
if (!response.ok) {
|
|
51
|
+
let errorMsg = `Microsoft Graph API error (${response.status})`;
|
|
52
|
+
try {
|
|
53
|
+
const errBody = (await response.json());
|
|
54
|
+
if (errBody.error?.message)
|
|
55
|
+
errorMsg = errBody.error.message;
|
|
56
|
+
}
|
|
57
|
+
catch {
|
|
58
|
+
// ignore parse errors
|
|
59
|
+
}
|
|
60
|
+
throw ToolError.internal(errorMsg);
|
|
61
|
+
}
|
|
62
|
+
const data = (await response.json());
|
|
63
|
+
return { item: mapDriveItem(data) };
|
|
64
|
+
},
|
|
65
|
+
});
|
|
66
|
+
//# sourceMappingURL=update-file-content.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"update-file-content.js","sourceRoot":"","sources":["../../src/tools/update-file-content.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AACjF,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AACzD,OAAO,EAAqB,eAAe,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAEhF,MAAM,cAAc,GAAG,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{ z } from 'zod';
|
|
2
|
+
export declare const uploadFile: import("@opentabs-dev/plugin-sdk").ToolDefinition<z.ZodObject<{
|
|
3
|
+
path: z.ZodString;
|
|
4
|
+
content: z.ZodString;
|
|
5
|
+
content_type: z.ZodOptional<z.ZodString>;
|
|
6
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
7
|
+
item: z.ZodObject<{
|
|
8
|
+
id: z.ZodString;
|
|
9
|
+
name: z.ZodString;
|
|
10
|
+
size: z.ZodNumber;
|
|
11
|
+
is_folder: z.ZodBoolean;
|
|
12
|
+
mime_type: z.ZodString;
|
|
13
|
+
web_url: z.ZodString;
|
|
14
|
+
created_at: z.ZodString;
|
|
15
|
+
last_modified_at: z.ZodString;
|
|
16
|
+
parent_path: z.ZodString;
|
|
17
|
+
parent_id: z.ZodString;
|
|
18
|
+
description: z.ZodString;
|
|
19
|
+
}, z.core.$strip>;
|
|
20
|
+
}, z.core.$strip>>;
|
|
21
|
+
//# sourceMappingURL=upload-file.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"upload-file.d.ts","sourceRoot":"","sources":["../../src/tools/upload-file.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAMxB,eAAO,MAAM,UAAU;;;;;;;;;;;;;;;;;;kBA6DrB,CAAC"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { ToolError, clearAuthCache, defineTool } from '@opentabs-dev/plugin-sdk';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { getGraphToken } from '../microsoft-word-api.js';
|
|
4
|
+
import { driveItemSchema, mapDriveItem } from './schemas.js';
|
|
5
|
+
const GRAPH_API_BASE = 'https://graph.microsoft.com/v1.0';
|
|
6
|
+
export const uploadFile = defineTool({
|
|
7
|
+
name: 'upload_file',
|
|
8
|
+
displayName: 'Upload File',
|
|
9
|
+
description: 'Upload a text file to OneDrive. Creates a new file or overwrites existing. Specify the full path relative to drive root (e.g., "Documents/report.txt").',
|
|
10
|
+
summary: 'Upload a text file to OneDrive',
|
|
11
|
+
icon: 'upload',
|
|
12
|
+
group: 'Files',
|
|
13
|
+
input: z.object({
|
|
14
|
+
path: z.string().min(1).describe('File path relative to drive root (e.g., "Documents/report.txt")'),
|
|
15
|
+
content: z.string().describe('File content as text'),
|
|
16
|
+
content_type: z.string().optional().describe('MIME type (default "text/plain")'),
|
|
17
|
+
}),
|
|
18
|
+
output: z.object({
|
|
19
|
+
item: driveItemSchema.describe('The uploaded file'),
|
|
20
|
+
}),
|
|
21
|
+
handle: async (params) => {
|
|
22
|
+
const token = getGraphToken();
|
|
23
|
+
const encodedPath = encodeURIComponent(params.path).replace(/%2F/g, '/');
|
|
24
|
+
const url = `${GRAPH_API_BASE}/me/drive/root:/${encodedPath}:/content`;
|
|
25
|
+
let response;
|
|
26
|
+
try {
|
|
27
|
+
response = await fetch(url, {
|
|
28
|
+
method: 'PUT',
|
|
29
|
+
credentials: 'omit',
|
|
30
|
+
headers: {
|
|
31
|
+
Authorization: `Bearer ${token}`,
|
|
32
|
+
'Content-Type': params.content_type ?? 'text/plain',
|
|
33
|
+
},
|
|
34
|
+
body: params.content,
|
|
35
|
+
signal: AbortSignal.timeout(30_000),
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
catch (err) {
|
|
39
|
+
if (err instanceof DOMException && err.name === 'TimeoutError') {
|
|
40
|
+
throw ToolError.timeout('Microsoft Graph API request timed out.');
|
|
41
|
+
}
|
|
42
|
+
throw ToolError.internal(`Network error: ${err instanceof Error ? err.message : 'unknown'}`);
|
|
43
|
+
}
|
|
44
|
+
if (response.status === 401 || response.status === 403) {
|
|
45
|
+
clearAuthCache('microsoft-word');
|
|
46
|
+
throw ToolError.auth('Authentication expired — please refresh the page.');
|
|
47
|
+
}
|
|
48
|
+
if (!response.ok) {
|
|
49
|
+
let errorMsg = `Microsoft Graph API error (${response.status})`;
|
|
50
|
+
try {
|
|
51
|
+
const errBody = (await response.json());
|
|
52
|
+
if (errBody.error?.message)
|
|
53
|
+
errorMsg = errBody.error.message;
|
|
54
|
+
}
|
|
55
|
+
catch {
|
|
56
|
+
// ignore parse errors
|
|
57
|
+
}
|
|
58
|
+
throw ToolError.internal(errorMsg);
|
|
59
|
+
}
|
|
60
|
+
const data = (await response.json());
|
|
61
|
+
return { item: mapDriveItem(data) };
|
|
62
|
+
},
|
|
63
|
+
});
|
|
64
|
+
//# sourceMappingURL=upload-file.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"upload-file.js","sourceRoot":"","sources":["../../src/tools/upload-file.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AACjF,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AACzD,OAAO,EAAqB,eAAe,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAEhF,MAAM,cAAc,GAAG,kCAAkC,CAAC;AAE1D,MAAM,CAAC,MAAM,UAAU,GAAG,UAAU,CAAC;IACnC,IAAI,EAAE,aAAa;IACnB,WAAW,EAAE,aAAa;IAC1B,WAAW,EACT,yJAAyJ;IAC3J,OAAO,EAAE,gCAAgC;IACzC,IAAI,EAAE,QAAQ;IACd,KAAK,EAAE,OAAO;IACd,KAAK,EAAE,CAAC,CAAC,MAAM,CAAC;QACd,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,iEAAiE,CAAC;QACnG,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,sBAAsB,CAAC;QACpD,YAAY,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,kCAAkC,CAAC;KACjF,CAAC;IACF,MAAM,EAAE,CAAC,CAAC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