@xpert-ai/chatkit-wps-addin 0.2.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.
- package/LICENSE +201 -0
- package/README.md +114 -0
- package/dist/assets/icon-32.png +0 -0
- package/dist/assets/icon-80.png +0 -0
- package/dist/assets/index-BKTU3sMk.js +1 -0
- package/dist/assets/taskpane-6flg2Ej3.js +199 -0
- package/dist/assets/taskpane-BLKT3Knq.css +1 -0
- package/dist/assets/wps-api-DgiVmik0.js +1 -0
- package/dist/config.js +8 -0
- package/dist/index.d.ts +126 -0
- package/dist/index.html +13 -0
- package/dist/index.js +358 -0
- package/dist/manifest.xml +6 -0
- package/dist/publish.xml +8 -0
- package/dist/ribbon.xml +19 -0
- package/dist/server/index.d.ts +2 -0
- package/dist/server/index.d.ts.map +1 -0
- package/dist/server/index.js +235 -0
- package/dist/server/index.js.map +1 -0
- package/dist/taskpane.html +14 -0
- package/env.example +19 -0
- package/package.json +65 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
*{box-sizing:border-box}html,body,#root{width:100%;height:100%;margin:0}body{color:#111827;background:#f8fafc;font-family:system-ui,-apple-system,BlinkMacSystemFont,Segoe UI,sans-serif}.taskpane{display:flex;width:100%;height:100%;min-width:280px;flex-direction:column;overflow:hidden;background:#fff}.taskpane.centered{align-items:center;justify-content:center;padding:16px;background:#f8fafc}.chatkit-shell{min-height:0;flex:1 1 auto}.status-banner{display:flex;align-items:center;gap:8px;flex:0 0 auto;padding:8px 10px;border-bottom:1px solid #fecaca;overflow-wrap:anywhere;font-size:12px;line-height:1.35}.status-banner.error{color:#7f1d1d;background:#fef2f2}.status-banner span{min-width:0;flex:1 1 auto}.link-button{border:0;padding:0;flex:0 0 auto;color:#0f766e;background:transparent;font:inherit;font-weight:650;cursor:pointer}.status-card{width:min(100%,320px);border:1px solid #d1d5db;border-radius:8px;padding:16px;background:#fff;box-shadow:0 10px 30px #0f172a14}.status-card h1{margin:0 0 8px;font-size:16px;font-weight:650;line-height:1.25}.status-card p{margin:0;color:#4b5563;font-size:13px;line-height:1.45}.taskpane.settings{overflow:auto;padding:14px;background:#f8fafc}.settings-panel{width:min(100%,420px);margin:0 auto;border:1px solid #d1d5db;border-radius:8px;padding:16px;background:#fff;box-shadow:0 10px 30px #0f172a14}.settings-header{margin-bottom:14px}.settings-header h1{margin:0 0 6px;font-size:16px;font-weight:650;line-height:1.25}.settings-header p{margin:0;color:#4b5563;font-size:13px;line-height:1.45}.settings-panel label{display:block;margin-top:10px}.settings-panel label span{display:block;margin-bottom:4px;color:#374151;font-size:12px;font-weight:600}.settings-panel input{width:100%;min-height:34px;border:1px solid #cbd5e1;border-radius:6px;padding:7px 9px;color:#111827;background:#fff;font:inherit;font-size:13px}.settings-panel input:focus{border-color:#0f766e;outline:2px solid rgb(15 118 110 / 18%);outline-offset:0}.settings-error{border:1px solid #fecaca;border-radius:6px;padding:8px;color:#7f1d1d;background:#fef2f2;overflow-wrap:anywhere;font-size:12px;line-height:1.35}.settings-actions{display:flex;gap:8px;margin-top:14px}.settings-actions button{min-height:34px;border:1px solid #0f766e;border-radius:6px;padding:7px 10px;background:#0f766e;color:#fff;font:inherit;font-size:13px;font-weight:650;cursor:pointer}.settings-actions button[type=button]{border-color:#cbd5e1;color:#374151;background:#fff}.settings-actions button:disabled{cursor:default;opacity:.65}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
(function(){const o=document.createElement("link").relList;if(o&&o.supports&&o.supports("modulepreload"))return;for(const e of document.querySelectorAll('link[rel="modulepreload"]'))c(e);new MutationObserver(e=>{for(const i of e)if(i.type==="childList")for(const r of i.addedNodes)r.tagName==="LINK"&&r.rel==="modulepreload"&&c(r)}).observe(document,{childList:!0,subtree:!0});function n(e){const i={};return e.integrity&&(i.integrity=e.integrity),e.referrerPolicy&&(i.referrerPolicy=e.referrerPolicy),e.crossOrigin==="use-credentials"?i.credentials="include":e.crossOrigin==="anonymous"?i.credentials="omit":i.credentials="same-origin",i}function c(e){if(e.ep)return;e.ep=!0;const i=n(e);fetch(e.href,i)}})();function a(){var c,e,i,r,s,l;const t=globalThis,o=t.Application??((c=t.window)==null?void 0:c.Application);if(o)return o;const n=((i=(e=t.wps)==null?void 0:e.WpsApplication)==null?void 0:i.call(e))??((l=(s=(r=t.window)==null?void 0:r.wps)==null?void 0:s.WpsApplication)==null?void 0:l.call(s));return n&&(t.Application=n,t.window&&(t.window.Application=n)),n}function p(){const t=a();if(!t)throw new Error("WPS application is not available.");return t}function u(t){const o=t.ActiveDocument;if(!o)throw new Error("No active WPS document is available.");return o}function f(t){const o=t.Selection;if(!o)throw new Error("No active WPS selection is available.");return o}export{u as a,f as b,p as g,a as r};
|
package/dist/config.js
ADDED
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { ClientToolMessageInput } from '../../../chatkit/src/index.ts';
|
|
2
|
+
|
|
3
|
+
export declare function createOfficeBridgeClientToolHandler(options?: CreateOfficeBridgeClientToolHandlerOptions): OfficeBridgeClientToolHandler;
|
|
4
|
+
|
|
5
|
+
export declare type CreateOfficeBridgeClientToolHandlerOptions<TToolName extends string = WordToolName> = {
|
|
6
|
+
adapter?: OfficeHostAdapter<TToolName>;
|
|
7
|
+
registry?: OfficeToolRegistry<TToolName>;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export declare function createOfficeToolRegistry<TToolName extends string>(adapters: Array<OfficeHostAdapter<TToolName>>): OfficeToolRegistry<TToolName>;
|
|
11
|
+
|
|
12
|
+
export declare function createWpsWordAdapter(options?: WpsAdapterOptions): OfficeHostAdapter<WordToolName>;
|
|
13
|
+
|
|
14
|
+
export declare class DefaultOfficeToolRegistry<TToolName extends string> implements OfficeToolRegistry<TToolName> {
|
|
15
|
+
#private;
|
|
16
|
+
constructor(adapters: Array<OfficeHostAdapter<TToolName>>);
|
|
17
|
+
supports(toolName: string): toolName is TToolName;
|
|
18
|
+
execute(toolName: string, params: Record<string, unknown>): Promise<unknown>;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
declare function findTextMatches(text: string, query: string, options: {
|
|
22
|
+
matchCase?: boolean;
|
|
23
|
+
matchWholeWord?: boolean;
|
|
24
|
+
}): TextMatch[];
|
|
25
|
+
|
|
26
|
+
export declare function isWordToolName(value: string): value is WordToolName;
|
|
27
|
+
|
|
28
|
+
declare type NormalizedTableData = {
|
|
29
|
+
rowCount: number;
|
|
30
|
+
columnCount: number;
|
|
31
|
+
values?: WordTableValues;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
declare function normalizeHeadingLevel(value: unknown): number;
|
|
35
|
+
|
|
36
|
+
export declare const OFFICE_WORD_TOOL_NAMES: readonly ["office_word_snapshot", "office_word_insert_text", "office_word_replace_selection", "office_word_insert_heading", "office_word_insert_table", "office_word_search_text"];
|
|
37
|
+
|
|
38
|
+
export declare type OfficeBridgeClientToolHandler = (call: OfficeToolCall) => Promise<ClientToolMessageInput> | ClientToolMessageInput;
|
|
39
|
+
|
|
40
|
+
export declare type OfficeHostAdapter<TToolName extends string = string> = {
|
|
41
|
+
readonly host: string;
|
|
42
|
+
supports(toolName: string): toolName is TToolName;
|
|
43
|
+
execute(toolName: TToolName, params: Record<string, unknown>): Promise<unknown>;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
export declare type OfficeToolCall = {
|
|
47
|
+
name: string;
|
|
48
|
+
params?: Record<string, unknown>;
|
|
49
|
+
id?: string;
|
|
50
|
+
tool_call_id?: string;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
export declare type OfficeToolRegistry<TToolName extends string = string> = {
|
|
54
|
+
supports(toolName: string): toolName is TToolName;
|
|
55
|
+
execute(toolName: string, params: Record<string, unknown>): Promise<unknown>;
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
export declare type OfficeToolResult = {
|
|
59
|
+
ok: true;
|
|
60
|
+
result: unknown;
|
|
61
|
+
} | {
|
|
62
|
+
ok: false;
|
|
63
|
+
error: string;
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
declare function readHeadingStyle(level: number): number;
|
|
67
|
+
|
|
68
|
+
declare function readNormalizedTableData(params: Record<string, unknown>): NormalizedTableData;
|
|
69
|
+
|
|
70
|
+
declare type TextMatch = {
|
|
71
|
+
index: number;
|
|
72
|
+
text: string;
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
export declare type WordBodyInsertLocation = Exclude<WordInsertLocation, 'Replace'>;
|
|
76
|
+
|
|
77
|
+
export declare type WordInsertLocation = 'Start' | 'End' | 'Replace';
|
|
78
|
+
|
|
79
|
+
export declare type WordTableValues = string[][];
|
|
80
|
+
|
|
81
|
+
export declare type WordToolName = (typeof OFFICE_WORD_TOOL_NAMES)[number];
|
|
82
|
+
|
|
83
|
+
declare type WpsAdapterOptions = {
|
|
84
|
+
maxSnapshotCharacters?: number;
|
|
85
|
+
maxSearchResults?: number;
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
export declare const wpsInternalTestUtils: {
|
|
89
|
+
findTextMatches: typeof findTextMatches;
|
|
90
|
+
normalizeHeadingLevel: typeof normalizeHeadingLevel;
|
|
91
|
+
readHeadingStyle: typeof readHeadingStyle;
|
|
92
|
+
readNormalizedTableData: typeof readNormalizedTableData;
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
export declare class WpsWordAdapter implements OfficeHostAdapter<WordToolName> {
|
|
96
|
+
#private;
|
|
97
|
+
readonly host = "WPS Writer";
|
|
98
|
+
constructor(options?: WpsAdapterOptions);
|
|
99
|
+
supports(toolName: string): toolName is WordToolName;
|
|
100
|
+
execute(toolName: WordToolName, params: Record<string, unknown>): Promise<unknown>;
|
|
101
|
+
private snapshot;
|
|
102
|
+
private insertText;
|
|
103
|
+
private replaceSelection;
|
|
104
|
+
private insertHeading;
|
|
105
|
+
private insertTable;
|
|
106
|
+
private searchText;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export { }
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
declare global {
|
|
113
|
+
interface Window {
|
|
114
|
+
Application?: WpsApplication;
|
|
115
|
+
wps?: WpsNamespace;
|
|
116
|
+
ribbon?: unknown;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
declare global {
|
|
122
|
+
interface Window {
|
|
123
|
+
XPERTAI_WPS_CONFIG?: RuntimeWpsConfig;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
package/dist/index.html
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8" />
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
6
|
+
<title>XpertAI WPS Loader</title>
|
|
7
|
+
<script type="module" crossorigin src="./assets/index-BKTU3sMk.js"></script>
|
|
8
|
+
<link rel="modulepreload" crossorigin href="./assets/wps-api-DgiVmik0.js">
|
|
9
|
+
</head>
|
|
10
|
+
<body>
|
|
11
|
+
<div id="root">XpertAI WPS Copilot</div>
|
|
12
|
+
</body>
|
|
13
|
+
</html>
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,358 @@
|
|
|
1
|
+
var b = (t) => {
|
|
2
|
+
throw TypeError(t);
|
|
3
|
+
};
|
|
4
|
+
var W = (t, e, n) => e.has(t) || b("Cannot " + n);
|
|
5
|
+
var d = (t, e, n) => (W(t, e, "read from private field"), n ? n.call(t) : e.get(t)), m = (t, e, n) => e.has(t) ? b("Cannot add the same private member more than once") : e instanceof WeakSet ? e.add(t) : e.set(t, n), x = (t, e, n, r) => (W(t, e, "write to private field"), r ? r.call(t, n) : e.set(t, n), n);
|
|
6
|
+
const D = [
|
|
7
|
+
"office_word_snapshot",
|
|
8
|
+
"office_word_insert_text",
|
|
9
|
+
"office_word_replace_selection",
|
|
10
|
+
"office_word_insert_heading",
|
|
11
|
+
"office_word_insert_table",
|
|
12
|
+
"office_word_search_text"
|
|
13
|
+
], k = new Set(D);
|
|
14
|
+
function z(t) {
|
|
15
|
+
return k.has(t);
|
|
16
|
+
}
|
|
17
|
+
function F() {
|
|
18
|
+
var r, o, c, i, s, a;
|
|
19
|
+
const t = globalThis, e = t.Application ?? ((r = t.window) == null ? void 0 : r.Application);
|
|
20
|
+
if (e)
|
|
21
|
+
return e;
|
|
22
|
+
const n = ((c = (o = t.wps) == null ? void 0 : o.WpsApplication) == null ? void 0 : c.call(o)) ?? ((a = (s = (i = t.window) == null ? void 0 : i.wps) == null ? void 0 : s.WpsApplication) == null ? void 0 : a.call(s));
|
|
23
|
+
return n && (t.Application = n, t.window && (t.window.Application = n)), n;
|
|
24
|
+
}
|
|
25
|
+
function l() {
|
|
26
|
+
const t = F();
|
|
27
|
+
if (!t)
|
|
28
|
+
throw new Error("WPS application is not available.");
|
|
29
|
+
return t;
|
|
30
|
+
}
|
|
31
|
+
function h(t) {
|
|
32
|
+
const e = t.ActiveDocument;
|
|
33
|
+
if (!e)
|
|
34
|
+
throw new Error("No active WPS document is available.");
|
|
35
|
+
return e;
|
|
36
|
+
}
|
|
37
|
+
function U(t) {
|
|
38
|
+
const e = t.Selection;
|
|
39
|
+
if (!e)
|
|
40
|
+
throw new Error("No active WPS selection is available.");
|
|
41
|
+
return e;
|
|
42
|
+
}
|
|
43
|
+
const $ = 5e3, V = 20;
|
|
44
|
+
function L(t) {
|
|
45
|
+
return typeof t == "string" && t.trim() ? t.trim() : void 0;
|
|
46
|
+
}
|
|
47
|
+
function _(t, e) {
|
|
48
|
+
const n = L(t);
|
|
49
|
+
if (!n)
|
|
50
|
+
throw new Error(`${e} must be a non-empty string.`);
|
|
51
|
+
return n;
|
|
52
|
+
}
|
|
53
|
+
function v(t) {
|
|
54
|
+
return typeof t == "boolean" ? t : void 0;
|
|
55
|
+
}
|
|
56
|
+
function w(t) {
|
|
57
|
+
if (!(typeof t != "number" || !Number.isInteger(t) || t <= 0))
|
|
58
|
+
return t;
|
|
59
|
+
}
|
|
60
|
+
function y(t, e) {
|
|
61
|
+
const n = w(t);
|
|
62
|
+
if (n === void 0)
|
|
63
|
+
throw new Error(`${e} must be a positive integer.`);
|
|
64
|
+
return n;
|
|
65
|
+
}
|
|
66
|
+
function T(t, e = "End") {
|
|
67
|
+
var r;
|
|
68
|
+
const n = (r = L(t)) == null ? void 0 : r.toLowerCase();
|
|
69
|
+
if (!n)
|
|
70
|
+
return e;
|
|
71
|
+
if (n === "start")
|
|
72
|
+
return "Start";
|
|
73
|
+
if (n === "end")
|
|
74
|
+
return "End";
|
|
75
|
+
throw new Error("location must be Start or End.");
|
|
76
|
+
}
|
|
77
|
+
function I(t) {
|
|
78
|
+
if (t === void 0)
|
|
79
|
+
return 1;
|
|
80
|
+
const e = y(t, "level");
|
|
81
|
+
if (e > 9)
|
|
82
|
+
throw new Error("level must be between 1 and 9.");
|
|
83
|
+
return e;
|
|
84
|
+
}
|
|
85
|
+
function J(t) {
|
|
86
|
+
if (t == null)
|
|
87
|
+
return "";
|
|
88
|
+
if (typeof t == "string" || typeof t == "number" || typeof t == "boolean")
|
|
89
|
+
return String(t);
|
|
90
|
+
throw new Error("table values must contain only strings, numbers, booleans, or nulls.");
|
|
91
|
+
}
|
|
92
|
+
function X(t) {
|
|
93
|
+
if (t !== void 0) {
|
|
94
|
+
if (!Array.isArray(t))
|
|
95
|
+
throw new Error("values must be a two-dimensional array.");
|
|
96
|
+
return t.map((e) => {
|
|
97
|
+
if (!Array.isArray(e))
|
|
98
|
+
throw new Error("values must be a two-dimensional array.");
|
|
99
|
+
return e.map(J);
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
function P(t) {
|
|
104
|
+
const e = X(t.values), n = w(t.rowCount), r = w(t.columnCount);
|
|
105
|
+
if (!e)
|
|
106
|
+
return {
|
|
107
|
+
rowCount: y(t.rowCount, "rowCount"),
|
|
108
|
+
columnCount: y(t.columnCount, "columnCount")
|
|
109
|
+
};
|
|
110
|
+
const o = e.length, c = e.reduce(
|
|
111
|
+
(a, u) => Math.max(a, u.length),
|
|
112
|
+
0
|
|
113
|
+
), i = n ?? o, s = r ?? c;
|
|
114
|
+
if (i <= 0 || s <= 0)
|
|
115
|
+
throw new Error("values must include at least one row and one column.");
|
|
116
|
+
return {
|
|
117
|
+
rowCount: i,
|
|
118
|
+
columnCount: s,
|
|
119
|
+
values: Array.from(
|
|
120
|
+
{ length: i },
|
|
121
|
+
(a, u) => Array.from(
|
|
122
|
+
{ length: s },
|
|
123
|
+
(S, B) => {
|
|
124
|
+
var E;
|
|
125
|
+
return ((E = e[u]) == null ? void 0 : E[B]) ?? "";
|
|
126
|
+
}
|
|
127
|
+
)
|
|
128
|
+
)
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
function A(t) {
|
|
132
|
+
var e;
|
|
133
|
+
return ((e = t.Content) == null ? void 0 : e.Text) ?? "";
|
|
134
|
+
}
|
|
135
|
+
function N(t, e) {
|
|
136
|
+
var i;
|
|
137
|
+
const n = t.Content;
|
|
138
|
+
if (!n)
|
|
139
|
+
throw new Error("The active WPS document does not expose a content range.");
|
|
140
|
+
const r = n.Start ?? 0, o = n.End ?? A(t).length, c = e === "Start" ? r : o;
|
|
141
|
+
return ((i = t.Range) == null ? void 0 : i.call(t, c, c)) ?? n;
|
|
142
|
+
}
|
|
143
|
+
function R(t, e, n) {
|
|
144
|
+
const r = N(t, n);
|
|
145
|
+
return n === "Start" && r.InsertBefore ? (r.InsertBefore(e), r) : n === "End" && r.InsertAfter ? (r.InsertAfter(e), r) : (r.Text = e, r);
|
|
146
|
+
}
|
|
147
|
+
function M(t) {
|
|
148
|
+
return -(t + 1);
|
|
149
|
+
}
|
|
150
|
+
function j(t, e) {
|
|
151
|
+
t != null && t.Cell && e.forEach((n, r) => {
|
|
152
|
+
n.forEach((o, c) => {
|
|
153
|
+
var s;
|
|
154
|
+
const i = (s = t.Cell) == null ? void 0 : s.call(t, r + 1, c + 1);
|
|
155
|
+
i != null && i.Range && (i.Range.Text = o);
|
|
156
|
+
});
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
function q(t) {
|
|
160
|
+
return {
|
|
161
|
+
name: t.Name ?? "WPS Writer",
|
|
162
|
+
build: t.Build,
|
|
163
|
+
version: t.Version
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
function O(t) {
|
|
167
|
+
return /^[\p{L}\p{N}_]$/u.test(t);
|
|
168
|
+
}
|
|
169
|
+
function G(t, e, n) {
|
|
170
|
+
const r = e > 0 ? t[e - 1] : "", o = e + n < t.length ? t[e + n] : "";
|
|
171
|
+
return !O(r) && !O(o);
|
|
172
|
+
}
|
|
173
|
+
function H(t, e, n) {
|
|
174
|
+
const r = n.matchCase ? t : t.toLocaleLowerCase(), o = n.matchCase ? e : e.toLocaleLowerCase(), c = [];
|
|
175
|
+
let i = 0;
|
|
176
|
+
for (; i <= r.length; ) {
|
|
177
|
+
const s = r.indexOf(o, i);
|
|
178
|
+
if (s === -1)
|
|
179
|
+
break;
|
|
180
|
+
i = s + Math.max(o.length, 1), !(n.matchWholeWord && !G(t, s, e.length)) && c.push({
|
|
181
|
+
index: s + 1,
|
|
182
|
+
text: t.slice(s, s + e.length)
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
return c;
|
|
186
|
+
}
|
|
187
|
+
var p, g;
|
|
188
|
+
class K {
|
|
189
|
+
constructor(e = {}) {
|
|
190
|
+
m(this, p);
|
|
191
|
+
m(this, g);
|
|
192
|
+
this.host = "WPS Writer", x(this, p, e.maxSnapshotCharacters ?? $), x(this, g, e.maxSearchResults ?? V);
|
|
193
|
+
}
|
|
194
|
+
supports(e) {
|
|
195
|
+
return z(e);
|
|
196
|
+
}
|
|
197
|
+
async execute(e, n) {
|
|
198
|
+
switch (e) {
|
|
199
|
+
case "office_word_snapshot":
|
|
200
|
+
return this.snapshot(n);
|
|
201
|
+
case "office_word_insert_text":
|
|
202
|
+
return this.insertText(n);
|
|
203
|
+
case "office_word_replace_selection":
|
|
204
|
+
return this.replaceSelection(n);
|
|
205
|
+
case "office_word_insert_heading":
|
|
206
|
+
return this.insertHeading(n);
|
|
207
|
+
case "office_word_insert_table":
|
|
208
|
+
return this.insertTable(n);
|
|
209
|
+
case "office_word_search_text":
|
|
210
|
+
return this.searchText(n);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
snapshot(e) {
|
|
214
|
+
var i;
|
|
215
|
+
const n = w(e.maxCharacters) ?? d(this, p), r = l(), o = h(r), c = A(o);
|
|
216
|
+
return {
|
|
217
|
+
host: q(r),
|
|
218
|
+
requirements: {
|
|
219
|
+
wpsJsApi: !0
|
|
220
|
+
},
|
|
221
|
+
documentName: o.Name,
|
|
222
|
+
bodyTextLength: c.length,
|
|
223
|
+
bodyTextPreview: c.slice(0, n),
|
|
224
|
+
bodyTextTruncated: c.length > n,
|
|
225
|
+
selectionText: ((i = r.Selection) == null ? void 0 : i.Text) ?? ""
|
|
226
|
+
};
|
|
227
|
+
}
|
|
228
|
+
insertText(e) {
|
|
229
|
+
const n = _(e.text, "text"), r = T(e.location), o = h(l());
|
|
230
|
+
return R(o, n, r), {
|
|
231
|
+
inserted: !0,
|
|
232
|
+
location: r,
|
|
233
|
+
textLength: n.length
|
|
234
|
+
};
|
|
235
|
+
}
|
|
236
|
+
replaceSelection(e) {
|
|
237
|
+
const n = _(e.text, "text"), r = U(l());
|
|
238
|
+
return r.TypeText ? r.TypeText(n) : r.Text = n, {
|
|
239
|
+
replaced: !0,
|
|
240
|
+
textLength: n.length
|
|
241
|
+
};
|
|
242
|
+
}
|
|
243
|
+
insertHeading(e) {
|
|
244
|
+
const n = _(e.text, "text"), r = I(e.level), o = T(e.location), c = h(l()), i = R(c, `${n}\r`, o);
|
|
245
|
+
return i.Style = M(r), {
|
|
246
|
+
inserted: !0,
|
|
247
|
+
level: r,
|
|
248
|
+
location: o,
|
|
249
|
+
textLength: n.length
|
|
250
|
+
};
|
|
251
|
+
}
|
|
252
|
+
insertTable(e) {
|
|
253
|
+
var s, a, u;
|
|
254
|
+
const n = T(e.location), r = P(e), o = h(l()), c = N(o, n), i = (a = (s = o.Tables) == null ? void 0 : s.Add) == null ? void 0 : a.call(
|
|
255
|
+
s,
|
|
256
|
+
c,
|
|
257
|
+
r.rowCount,
|
|
258
|
+
r.columnCount
|
|
259
|
+
);
|
|
260
|
+
if (!((u = o.Tables) != null && u.Add))
|
|
261
|
+
throw new Error("The active WPS document does not expose table insertion.");
|
|
262
|
+
return r.values && j(i, r.values), {
|
|
263
|
+
inserted: !0,
|
|
264
|
+
location: n,
|
|
265
|
+
rowCount: r.rowCount,
|
|
266
|
+
columnCount: r.columnCount
|
|
267
|
+
};
|
|
268
|
+
}
|
|
269
|
+
searchText(e) {
|
|
270
|
+
const n = _(e.query, "query"), r = w(e.maxResults) ?? d(this, g), o = v(e.matchCase), c = v(e.matchWholeWord), i = h(l()), s = H(A(i), n, {
|
|
271
|
+
matchCase: o,
|
|
272
|
+
matchWholeWord: c
|
|
273
|
+
}), a = s.slice(0, r).map((u, S) => ({
|
|
274
|
+
index: S + 1,
|
|
275
|
+
start: u.index,
|
|
276
|
+
text: u.text
|
|
277
|
+
}));
|
|
278
|
+
return {
|
|
279
|
+
query: n,
|
|
280
|
+
count: s.length,
|
|
281
|
+
results: a,
|
|
282
|
+
truncated: s.length > a.length
|
|
283
|
+
};
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
p = new WeakMap(), g = new WeakMap();
|
|
287
|
+
function Q(t = {}) {
|
|
288
|
+
return new K(t);
|
|
289
|
+
}
|
|
290
|
+
const rt = {
|
|
291
|
+
findTextMatches: H,
|
|
292
|
+
normalizeHeadingLevel: I,
|
|
293
|
+
readHeadingStyle: M,
|
|
294
|
+
readNormalizedTableData: P
|
|
295
|
+
};
|
|
296
|
+
var f;
|
|
297
|
+
class Y {
|
|
298
|
+
constructor(e) {
|
|
299
|
+
m(this, f);
|
|
300
|
+
x(this, f, e);
|
|
301
|
+
}
|
|
302
|
+
supports(e) {
|
|
303
|
+
return d(this, f).some((n) => n.supports(e));
|
|
304
|
+
}
|
|
305
|
+
async execute(e, n) {
|
|
306
|
+
const r = d(this, f).find((o) => o.supports(e));
|
|
307
|
+
if (!r)
|
|
308
|
+
throw new Error(`Unknown Office tool: ${e}`);
|
|
309
|
+
return r.execute(e, n);
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
f = new WeakMap();
|
|
313
|
+
function Z(t) {
|
|
314
|
+
return new Y(t);
|
|
315
|
+
}
|
|
316
|
+
function tt(t) {
|
|
317
|
+
return typeof t == "object" && t !== null && !Array.isArray(t) ? t : {};
|
|
318
|
+
}
|
|
319
|
+
function C(t, e, n) {
|
|
320
|
+
return {
|
|
321
|
+
tool_call_id: t.tool_call_id ?? t.id,
|
|
322
|
+
name: t.name,
|
|
323
|
+
status: e,
|
|
324
|
+
content: JSON.stringify(n)
|
|
325
|
+
};
|
|
326
|
+
}
|
|
327
|
+
function et(t) {
|
|
328
|
+
return t instanceof Error ? t.message : String(t);
|
|
329
|
+
}
|
|
330
|
+
function ot(t = {}) {
|
|
331
|
+
const e = t.registry ?? Z([t.adapter ?? Q()]);
|
|
332
|
+
return async (n) => {
|
|
333
|
+
if (!e.supports(n.name))
|
|
334
|
+
return C(n, "error", {
|
|
335
|
+
ok: !1,
|
|
336
|
+
error: `Unknown Office tool: ${n.name}`
|
|
337
|
+
});
|
|
338
|
+
try {
|
|
339
|
+
const r = await e.execute(n.name, tt(n.params));
|
|
340
|
+
return C(n, "success", { ok: !0, result: r });
|
|
341
|
+
} catch (r) {
|
|
342
|
+
return C(n, "error", {
|
|
343
|
+
ok: !1,
|
|
344
|
+
error: et(r)
|
|
345
|
+
});
|
|
346
|
+
}
|
|
347
|
+
};
|
|
348
|
+
}
|
|
349
|
+
export {
|
|
350
|
+
Y as DefaultOfficeToolRegistry,
|
|
351
|
+
D as OFFICE_WORD_TOOL_NAMES,
|
|
352
|
+
K as WpsWordAdapter,
|
|
353
|
+
ot as createOfficeBridgeClientToolHandler,
|
|
354
|
+
Z as createOfficeToolRegistry,
|
|
355
|
+
Q as createWpsWordAdapter,
|
|
356
|
+
z as isWordToolName,
|
|
357
|
+
rt as wpsInternalTestUtils
|
|
358
|
+
};
|
package/dist/publish.xml
ADDED
package/dist/ribbon.xml
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui" onLoad="ribbon.OnAddinLoad">
|
|
3
|
+
<ribbon startFromScratch="false">
|
|
4
|
+
<tabs>
|
|
5
|
+
<tab id="xpertAiTab" label="XpertAI">
|
|
6
|
+
<group id="xpertAiChatKitGroup" label="ChatKit">
|
|
7
|
+
<button
|
|
8
|
+
id="btnOpenChatKit"
|
|
9
|
+
label="XpertAI Copilot"
|
|
10
|
+
onAction="ribbon.OnAction"
|
|
11
|
+
getEnabled="ribbon.OnGetEnabled"
|
|
12
|
+
getImage="ribbon.GetImage"
|
|
13
|
+
getVisible="ribbon.OnGetVisible"
|
|
14
|
+
size="large"/>
|
|
15
|
+
</group>
|
|
16
|
+
</tab>
|
|
17
|
+
</tabs>
|
|
18
|
+
</ribbon>
|
|
19
|
+
</customUI>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../server/index.ts"],"names":[],"mappings":""}
|