agentxl 1.0.0 → 1.1.2
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 +21 -0
- package/README.md +352 -197
- package/bin/agentxl-folder-picker.exe +0 -0
- package/bin/agentxl.js +44 -8
- package/dist/agent/models.d.ts +9 -9
- package/dist/agent/models.d.ts.map +1 -1
- package/dist/agent/models.js +44 -8
- package/dist/agent/models.js.map +1 -1
- package/dist/agent/prompt/folder-context.d.ts +26 -0
- package/dist/agent/prompt/folder-context.d.ts.map +1 -0
- package/dist/agent/prompt/folder-context.js +105 -0
- package/dist/agent/prompt/folder-context.js.map +1 -0
- package/dist/agent/prompt/system-prompt.d.ts +21 -0
- package/dist/agent/prompt/system-prompt.d.ts.map +1 -0
- package/dist/agent/prompt/system-prompt.js +130 -0
- package/dist/agent/prompt/system-prompt.js.map +1 -0
- package/dist/agent/session.d.ts +10 -4
- package/dist/agent/session.d.ts.map +1 -1
- package/dist/agent/session.js +53 -15
- package/dist/agent/session.js.map +1 -1
- package/dist/agent/tools/excel.d.ts +24 -0
- package/dist/agent/tools/excel.d.ts.map +1 -0
- package/dist/agent/tools/excel.js +132 -0
- package/dist/agent/tools/excel.js.map +1 -0
- package/dist/server/document-converter.d.ts +71 -0
- package/dist/server/document-converter.d.ts.map +1 -0
- package/dist/server/document-converter.js +353 -0
- package/dist/server/document-converter.js.map +1 -0
- package/dist/server/excel-bridge.d.ts +38 -0
- package/dist/server/excel-bridge.d.ts.map +1 -0
- package/dist/server/excel-bridge.js +75 -0
- package/dist/server/excel-bridge.js.map +1 -0
- package/dist/server/folder-picker.d.ts +9 -0
- package/dist/server/folder-picker.d.ts.map +1 -0
- package/dist/server/folder-picker.js +204 -0
- package/dist/server/folder-picker.js.map +1 -0
- package/dist/server/folder-scanner.d.ts +43 -0
- package/dist/server/folder-scanner.d.ts.map +1 -0
- package/dist/server/folder-scanner.js +161 -0
- package/dist/server/folder-scanner.js.map +1 -0
- package/dist/server/http.d.ts +19 -0
- package/dist/server/http.d.ts.map +1 -0
- package/dist/server/http.js +62 -0
- package/dist/server/http.js.map +1 -0
- package/dist/server/index.d.ts +16 -4
- package/dist/server/index.d.ts.map +1 -1
- package/dist/server/index.js +70 -246
- package/dist/server/index.js.map +1 -1
- package/dist/server/json-store.d.ts +19 -0
- package/dist/server/json-store.d.ts.map +1 -0
- package/dist/server/json-store.js +37 -0
- package/dist/server/json-store.js.map +1 -0
- package/dist/server/routes/agent.d.ts +16 -0
- package/dist/server/routes/agent.d.ts.map +1 -0
- package/dist/server/routes/agent.js +196 -0
- package/dist/server/routes/agent.js.map +1 -0
- package/dist/server/routes/excel.d.ts +10 -0
- package/dist/server/routes/excel.d.ts.map +1 -0
- package/dist/server/routes/excel.js +41 -0
- package/dist/server/routes/excel.js.map +1 -0
- package/dist/server/routes/folder.d.ts +15 -0
- package/dist/server/routes/folder.d.ts.map +1 -0
- package/dist/server/routes/folder.js +184 -0
- package/dist/server/routes/folder.js.map +1 -0
- package/dist/server/routes/workbook.d.ts +7 -0
- package/dist/server/routes/workbook.d.ts.map +1 -0
- package/dist/server/routes/workbook.js +31 -0
- package/dist/server/routes/workbook.js.map +1 -0
- package/dist/server/static.d.ts +12 -0
- package/dist/server/static.d.ts.map +1 -0
- package/dist/server/static.js +83 -0
- package/dist/server/static.js.map +1 -0
- package/dist/server/workbook-folder-store.d.ts +24 -0
- package/dist/server/workbook-folder-store.d.ts.map +1 -0
- package/dist/server/workbook-folder-store.js +76 -0
- package/dist/server/workbook-folder-store.js.map +1 -0
- package/dist/server/workbook-identity.d.ts +8 -0
- package/dist/server/workbook-identity.d.ts.map +1 -0
- package/dist/server/workbook-identity.js +57 -0
- package/dist/server/workbook-identity.js.map +1 -0
- package/manifest/manifest-hosted.xml +107 -0
- package/package.json +24 -10
- package/taskpane/dist/assets/index-BnD8psE_.js +224 -0
- package/taskpane/dist/assets/index-BuAcDfRq.css +1 -0
- package/taskpane/dist/index.html +2 -2
- package/taskpane/dist/assets/index-6sMpIYxE.css +0 -1
- package/taskpane/dist/assets/index-DyLrQ3Aa.js +0 -164
package/dist/agent/session.js
CHANGED
|
@@ -7,8 +7,10 @@
|
|
|
7
7
|
import { join } from "path";
|
|
8
8
|
import { homedir } from "os";
|
|
9
9
|
import { existsSync } from "fs";
|
|
10
|
-
import { createAgentSession, AuthStorage, ModelRegistry, SessionManager, SettingsManager, } from "@mariozechner/pi-coding-agent";
|
|
10
|
+
import { createAgentSession, createReadOnlyTools, createBashTool, AuthStorage, DefaultResourceLoader, ModelRegistry, SessionManager, SettingsManager, } from "@mariozechner/pi-coding-agent";
|
|
11
11
|
import { getDefaultModel } from "./models.js";
|
|
12
|
+
import { excelTool } from "./tools/excel.js";
|
|
13
|
+
import { AGENTXL_SYSTEM_PROMPT } from "./prompt/system-prompt.js";
|
|
12
14
|
// ---------------------------------------------------------------------------
|
|
13
15
|
// Paths
|
|
14
16
|
// ---------------------------------------------------------------------------
|
|
@@ -31,10 +33,12 @@ function resolveAuthPath() {
|
|
|
31
33
|
// ---------------------------------------------------------------------------
|
|
32
34
|
// Singletons — rebuilt on resetSession() to pick up auth changes
|
|
33
35
|
// ---------------------------------------------------------------------------
|
|
34
|
-
let authStorage =
|
|
36
|
+
let authStorage = AuthStorage.create(resolveAuthPath());
|
|
35
37
|
let modelRegistry = new ModelRegistry(authStorage);
|
|
36
38
|
/** Active agent session (null until first prompt) */
|
|
37
39
|
let currentSession = null;
|
|
40
|
+
/** The cwd the current session was created with */
|
|
41
|
+
let currentSessionCwd = null;
|
|
38
42
|
/** Provider selected for the active session */
|
|
39
43
|
let selectedProvider = null;
|
|
40
44
|
// ---------------------------------------------------------------------------
|
|
@@ -45,7 +49,7 @@ let selectedProvider = null;
|
|
|
45
49
|
* Called by resetSession() so runtime auth changes are picked up.
|
|
46
50
|
*/
|
|
47
51
|
function rebuildAuth() {
|
|
48
|
-
authStorage =
|
|
52
|
+
authStorage = AuthStorage.create(resolveAuthPath());
|
|
49
53
|
modelRegistry = new ModelRegistry(authStorage);
|
|
50
54
|
selectedProvider = null;
|
|
51
55
|
}
|
|
@@ -54,42 +58,75 @@ function rebuildAuth() {
|
|
|
54
58
|
// ---------------------------------------------------------------------------
|
|
55
59
|
/**
|
|
56
60
|
* Initialize a new agent session.
|
|
57
|
-
* Picks the best available model, creates a Pi SDK session with
|
|
58
|
-
* tools
|
|
61
|
+
* Picks the best available model, creates a Pi SDK session with read-only
|
|
62
|
+
* tools pointed at the given working directory (linked folder).
|
|
63
|
+
*
|
|
64
|
+
* @param cwd - Working directory for file tools. Defaults to process.cwd().
|
|
59
65
|
*/
|
|
60
|
-
export async function initSession() {
|
|
66
|
+
export async function initSession(cwd) {
|
|
61
67
|
// Refresh to pick up any new keys
|
|
62
68
|
modelRegistry.refresh();
|
|
63
|
-
const
|
|
69
|
+
const effectiveCwd = cwd || process.cwd();
|
|
70
|
+
const model = getDefaultModel(modelRegistry, effectiveCwd);
|
|
64
71
|
if (!model) {
|
|
65
72
|
throw new Error("No model available. Run 'agentxl login' to set up authentication " +
|
|
66
73
|
"(API key or subscription).");
|
|
67
74
|
}
|
|
68
75
|
// Track the selected provider
|
|
69
76
|
selectedProvider = model.provider;
|
|
77
|
+
const readOnly = createReadOnlyTools(effectiveCwd);
|
|
78
|
+
const bash = createBashTool(effectiveCwd);
|
|
79
|
+
const tools = [...readOnly, bash];
|
|
80
|
+
const settingsManager = SettingsManager.inMemory({
|
|
81
|
+
compaction: { enabled: true },
|
|
82
|
+
});
|
|
83
|
+
// Build a ResourceLoader that appends AgentXL's behavioral rules
|
|
84
|
+
// on top of Pi's built-in system prompt (tool docs, skills, AGENTS.md).
|
|
85
|
+
const resourceLoader = new DefaultResourceLoader({
|
|
86
|
+
cwd: effectiveCwd,
|
|
87
|
+
settingsManager,
|
|
88
|
+
appendSystemPrompt: AGENTXL_SYSTEM_PROMPT,
|
|
89
|
+
noExtensions: true,
|
|
90
|
+
noSkills: true,
|
|
91
|
+
noPromptTemplates: true,
|
|
92
|
+
noThemes: true,
|
|
93
|
+
});
|
|
94
|
+
await resourceLoader.reload();
|
|
70
95
|
const { session } = await createAgentSession({
|
|
71
96
|
model,
|
|
97
|
+
cwd: effectiveCwd,
|
|
72
98
|
thinkingLevel: "medium",
|
|
73
|
-
tools
|
|
74
|
-
customTools: [], // Excel
|
|
99
|
+
tools, // read, grep, find, ls, bash — pointed at linked folder
|
|
100
|
+
customTools: [excelTool], // Single Excel tool — agent writes Office.js code
|
|
101
|
+
resourceLoader, // Pi base prompt + AgentXL append
|
|
75
102
|
sessionManager: SessionManager.inMemory(),
|
|
76
|
-
settingsManager
|
|
77
|
-
compaction: { enabled: false },
|
|
78
|
-
}),
|
|
103
|
+
settingsManager,
|
|
79
104
|
authStorage,
|
|
80
105
|
modelRegistry,
|
|
81
106
|
});
|
|
82
107
|
currentSession = session;
|
|
108
|
+
currentSessionCwd = effectiveCwd;
|
|
83
109
|
return session;
|
|
84
110
|
}
|
|
85
111
|
/**
|
|
86
112
|
* Get the current session, or create one if none exists.
|
|
113
|
+
* If `cwd` is provided and differs from the current session's cwd,
|
|
114
|
+
* the session is recreated so file tools point to the correct folder.
|
|
115
|
+
*
|
|
116
|
+
* @param cwd - Working directory for file tools (linked folder path).
|
|
87
117
|
*/
|
|
88
|
-
export async function getSession() {
|
|
118
|
+
export async function getSession(cwd) {
|
|
119
|
+
const effectiveCwd = cwd || process.cwd();
|
|
120
|
+
// Recreate session if the working directory changed
|
|
121
|
+
if (currentSession && currentSessionCwd !== effectiveCwd) {
|
|
122
|
+
currentSession.dispose();
|
|
123
|
+
currentSession = null;
|
|
124
|
+
currentSessionCwd = null;
|
|
125
|
+
}
|
|
89
126
|
if (currentSession) {
|
|
90
127
|
return currentSession;
|
|
91
128
|
}
|
|
92
|
-
return initSession();
|
|
129
|
+
return initSession(effectiveCwd);
|
|
93
130
|
}
|
|
94
131
|
/**
|
|
95
132
|
* Check if any provider has auth configured.
|
|
@@ -111,7 +148,7 @@ export function getAuthProvider() {
|
|
|
111
148
|
return selectedProvider;
|
|
112
149
|
// No session yet — preview what getDefaultModel() would pick
|
|
113
150
|
modelRegistry.refresh();
|
|
114
|
-
const model = getDefaultModel(modelRegistry);
|
|
151
|
+
const model = getDefaultModel(modelRegistry, currentSessionCwd ?? process.cwd());
|
|
115
152
|
return model?.provider ?? null;
|
|
116
153
|
}
|
|
117
154
|
/**
|
|
@@ -123,6 +160,7 @@ export function resetSession() {
|
|
|
123
160
|
if (currentSession) {
|
|
124
161
|
currentSession.dispose();
|
|
125
162
|
currentSession = null;
|
|
163
|
+
currentSessionCwd = null;
|
|
126
164
|
}
|
|
127
165
|
rebuildAuth();
|
|
128
166
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"session.js","sourceRoot":"","sources":["../../src/agent/session.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAC5B,OAAO,EAAE,OAAO,EAAE,MAAM,IAAI,CAAC;AAC7B,OAAO,EAAE,UAAU,EAAE,MAAM,IAAI,CAAC;AAChC,OAAO,EACL,kBAAkB,EAClB,WAAW,EACX,aAAa,EACb,cAAc,EACd,eAAe,GAEhB,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"session.js","sourceRoot":"","sources":["../../src/agent/session.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAC5B,OAAO,EAAE,OAAO,EAAE,MAAM,IAAI,CAAC;AAC7B,OAAO,EAAE,UAAU,EAAE,MAAM,IAAI,CAAC;AAChC,OAAO,EACL,kBAAkB,EAClB,mBAAmB,EACnB,cAAc,EACd,WAAW,EACX,qBAAqB,EACrB,aAAa,EACb,cAAc,EACd,eAAe,GAEhB,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAE,eAAe,EAAE,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Ac,CAAC,OAAO,EAAE,CAAC;QACzB,cAAc,GAAG,IAAI,CAAC;QACtB,iBAAiB,GAAG,IAAI,CAAC;IAC3B,CAAC;IACD,WAAW,EAAE,CAAC;AAChB,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY;IAChC,IAAI,cAAc,EAAE,CAAC;QACnB,IAAI,CAAC;YACH,MAAM,cAAc,CAAC,KAAK,EAAE,CAAC;QAC/B,CAAC;QAAC,MAAM,CAAC;YACP,2DAA2D;QAC7D,CAAC;IACH,CAAC;AACH,CAAC;AAED,sBAAsB;AACtB,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Single Excel custom tool — the agent writes Office.js code,
|
|
3
|
+
* the taskpane executes it in the active workbook.
|
|
4
|
+
*
|
|
5
|
+
* This replaces the 10-tool approach with one flexible tool:
|
|
6
|
+
* the agent has full Office.js API access and gets real results back.
|
|
7
|
+
*/
|
|
8
|
+
import type { ToolDefinition } from "@mariozechner/pi-coding-agent";
|
|
9
|
+
/**
|
|
10
|
+
* The `excel` tool definition.
|
|
11
|
+
*
|
|
12
|
+
* The agent sends Office.js code that runs inside:
|
|
13
|
+
* Excel.run(async (context) => { <code here> })
|
|
14
|
+
*
|
|
15
|
+
* The code has access to `context` (the Excel RequestContext).
|
|
16
|
+
* It should return a value — the return value is sent back to the agent.
|
|
17
|
+
*
|
|
18
|
+
* Common patterns the agent should use:
|
|
19
|
+
* - Read: context.workbook.worksheets.getActiveWorksheet().getRange("A1:D10").load("values"); await context.sync(); return range.values;
|
|
20
|
+
* - Write: context.workbook.worksheets.getActiveWorksheet().getRange("A1").values = [["Hello"]]; await context.sync();
|
|
21
|
+
* - Chart: const sheet = context.workbook.worksheets.getActiveWorksheet(); const chart = sheet.charts.add("ColumnClustered", sheet.getRange("A1:B5")); await context.sync();
|
|
22
|
+
*/
|
|
23
|
+
export declare const excelTool: ToolDefinition;
|
|
24
|
+
//# sourceMappingURL=excel.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"excel.d.ts","sourceRoot":"","sources":["../../../src/agent/tools/excel.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAIH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAEpE;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,SAAS,EAAE,cA8GvB,CAAC"}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Single Excel custom tool — the agent writes Office.js code,
|
|
3
|
+
* the taskpane executes it in the active workbook.
|
|
4
|
+
*
|
|
5
|
+
* This replaces the 10-tool approach with one flexible tool:
|
|
6
|
+
* the agent has full Office.js API access and gets real results back.
|
|
7
|
+
*/
|
|
8
|
+
import { Type } from "@sinclair/typebox";
|
|
9
|
+
import { registerPendingExecution } from "../../server/excel-bridge.js";
|
|
10
|
+
/**
|
|
11
|
+
* The `excel` tool definition.
|
|
12
|
+
*
|
|
13
|
+
* The agent sends Office.js code that runs inside:
|
|
14
|
+
* Excel.run(async (context) => { <code here> })
|
|
15
|
+
*
|
|
16
|
+
* The code has access to `context` (the Excel RequestContext).
|
|
17
|
+
* It should return a value — the return value is sent back to the agent.
|
|
18
|
+
*
|
|
19
|
+
* Common patterns the agent should use:
|
|
20
|
+
* - Read: context.workbook.worksheets.getActiveWorksheet().getRange("A1:D10").load("values"); await context.sync(); return range.values;
|
|
21
|
+
* - Write: context.workbook.worksheets.getActiveWorksheet().getRange("A1").values = [["Hello"]]; await context.sync();
|
|
22
|
+
* - Chart: const sheet = context.workbook.worksheets.getActiveWorksheet(); const chart = sheet.charts.add("ColumnClustered", sheet.getRange("A1:B5")); await context.sync();
|
|
23
|
+
*/
|
|
24
|
+
export const excelTool = {
|
|
25
|
+
name: "excel",
|
|
26
|
+
label: "Excel",
|
|
27
|
+
description: `Execute Office.js code in the user's active Excel workbook.
|
|
28
|
+
|
|
29
|
+
The code runs inside Excel.run(async (context) => { ... }).
|
|
30
|
+
You have access to \`context\` (Excel.RequestContext).
|
|
31
|
+
|
|
32
|
+
IMPORTANT RULES:
|
|
33
|
+
- Always call \`await context.sync()\` after loading properties or making changes.
|
|
34
|
+
- To read properties, call \`.load("propertyName")\` then \`await context.sync()\` before accessing.
|
|
35
|
+
- Return a value to send results back (e.g., cell values, sheet names).
|
|
36
|
+
- For writes, return a confirmation string describing what was written.
|
|
37
|
+
- Do NOT use \`range.note\` or \`cell.note\` for citations/comments. In this runtime, use \`worksheet.comments.add(cellAddress, content)\`.
|
|
38
|
+
|
|
39
|
+
COMMON PATTERNS:
|
|
40
|
+
|
|
41
|
+
Read cell values:
|
|
42
|
+
\`\`\`
|
|
43
|
+
const range = context.workbook.worksheets.getActiveWorksheet().getRange("A1:D10");
|
|
44
|
+
range.load("values");
|
|
45
|
+
await context.sync();
|
|
46
|
+
return range.values;
|
|
47
|
+
\`\`\`
|
|
48
|
+
|
|
49
|
+
Write values:
|
|
50
|
+
\`\`\`
|
|
51
|
+
const sheet = context.workbook.worksheets.getActiveWorksheet();
|
|
52
|
+
sheet.getRange("A1").values = [["Revenue", "Q1", "Q2"], [100, 200, 300]];
|
|
53
|
+
await context.sync();
|
|
54
|
+
return "Wrote 2 rows to A1:C2";
|
|
55
|
+
\`\`\`
|
|
56
|
+
|
|
57
|
+
Add or replace a citation comment:
|
|
58
|
+
\`\`\`
|
|
59
|
+
const sheet = context.workbook.worksheets.getActiveWorksheet();
|
|
60
|
+
const address = "B5";
|
|
61
|
+
try {
|
|
62
|
+
sheet.comments.getItemByCell(address).delete();
|
|
63
|
+
await context.sync();
|
|
64
|
+
} catch {}
|
|
65
|
+
sheet.comments.add(address, "📄 Source: Lease.pdf\n📑 Page: 14\n💬 ...quoted excerpt...\n🤖 Extracted by AgentXL");
|
|
66
|
+
await context.sync();
|
|
67
|
+
return "Added citation comment to B5";
|
|
68
|
+
\`\`\`
|
|
69
|
+
|
|
70
|
+
Get all sheet names:
|
|
71
|
+
\`\`\`
|
|
72
|
+
const sheets = context.workbook.worksheets;
|
|
73
|
+
sheets.load("items/name");
|
|
74
|
+
await context.sync();
|
|
75
|
+
return sheets.items.map(s => s.name);
|
|
76
|
+
\`\`\`
|
|
77
|
+
|
|
78
|
+
Create a chart:
|
|
79
|
+
\`\`\`
|
|
80
|
+
const sheet = context.workbook.worksheets.getActiveWorksheet();
|
|
81
|
+
const chart = sheet.charts.add("ColumnClustered", sheet.getRange("A1:B5"), "Auto");
|
|
82
|
+
chart.title.text = "Sales";
|
|
83
|
+
await context.sync();
|
|
84
|
+
return "Created column chart from A1:B5";
|
|
85
|
+
\`\`\`
|
|
86
|
+
|
|
87
|
+
Format cells:
|
|
88
|
+
\`\`\`
|
|
89
|
+
const range = context.workbook.worksheets.getActiveWorksheet().getRange("A1:D1");
|
|
90
|
+
range.format.font.bold = true;
|
|
91
|
+
range.format.fill.color = "#4472C4";
|
|
92
|
+
range.format.font.color = "#FFFFFF";
|
|
93
|
+
await context.sync();
|
|
94
|
+
return "Formatted header row A1:D1";
|
|
95
|
+
\`\`\`
|
|
96
|
+
|
|
97
|
+
Add a worksheet:
|
|
98
|
+
\`\`\`
|
|
99
|
+
const sheet = context.workbook.worksheets.add("Summary");
|
|
100
|
+
sheet.activate();
|
|
101
|
+
await context.sync();
|
|
102
|
+
return "Added and activated worksheet 'Summary'";
|
|
103
|
+
\`\`\``,
|
|
104
|
+
parameters: Type.Object({
|
|
105
|
+
code: Type.String({
|
|
106
|
+
description: "Office.js code to execute inside Excel.run(async (context) => { ... }). " +
|
|
107
|
+
"Has access to `context` (Excel.RequestContext). Return a value to get results back.",
|
|
108
|
+
}),
|
|
109
|
+
description: Type.String({
|
|
110
|
+
description: "Brief human-readable description of what this code does (shown in UI).",
|
|
111
|
+
}),
|
|
112
|
+
}),
|
|
113
|
+
execute: async (toolCallId, params) => {
|
|
114
|
+
// The actual execution happens in the taskpane via Office.js.
|
|
115
|
+
// We register a pending execution and wait for the taskpane to
|
|
116
|
+
// POST the result back to /api/excel/result.
|
|
117
|
+
try {
|
|
118
|
+
const result = await registerPendingExecution(toolCallId);
|
|
119
|
+
return {
|
|
120
|
+
content: [{ type: "text", text: typeof result === "string" ? result : JSON.stringify(result) }],
|
|
121
|
+
details: {},
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
catch (err) {
|
|
125
|
+
return {
|
|
126
|
+
content: [{ type: "text", text: `Error: ${err instanceof Error ? err.message : String(err)}` }],
|
|
127
|
+
details: {},
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
},
|
|
131
|
+
};
|
|
132
|
+
//# sourceMappingURL=excel.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"excel.js","sourceRoot":"","sources":["../../../src/agent/tools/excel.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AACzC,OAAO,EAAE,wBAAwB,EAAE,MAAM,8BAA8B,CAAC;AAGxE;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,MAAM,SAAS,GAAmB;IACvC,IAAI,EAAE,OAAO;IACb,KAAK,EAAE,OAAO;IACd,WAAW,EAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA4ER;IAEL,UAAU,EAAE,IAAI,CAAC,MAAM,CAAC;QACtB,IAAI,EAAE,IAAI,CAAC,MAAM,CAAC;YAChB,WAAW,EACT,0EAA0E;gBAC1E,qFAAqF;SACxF,CAAC;QACF,WAAW,EAAE,IAAI,CAAC,MAAM,CAAC;YACvB,WAAW,EACT,wEAAwE;SAC3E,CAAC;KACH,CAAC;IAEF,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,EAAE,EAAE;QACpC,8DAA8D;QAC9D,+DAA+D;QAC/D,6CAA6C;QAC7C,IAAI,CAAC;YACH,MAAM,MAAM,GAAG,MAAM,wBAAwB,CAAC,UAAU,CAAC,CAAC;YAC1D,OAAO;gBACL,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAe,EAAE,IAAI,EAAE,OAAO,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,EAAE,CAAC;gBACxG,OAAO,EAAE,EAAE;aACZ,CAAC;QACJ,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,OAAO;gBACL,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAe,EAAE,IAAI,EAAE,UAAU,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC;gBACxG,OAAO,EAAE,EAAE;aACZ,CAAC;QACJ,CAAC;IACH,CAAC;CACF,CAAC"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Document pre-converter — converts binary documents to readable Markdown.
|
|
3
|
+
*
|
|
4
|
+
* Runs at scan time (or on demand). Cached converted files live alongside
|
|
5
|
+
* the source files in a `.agentxl-cache/` directory inside the linked folder.
|
|
6
|
+
*
|
|
7
|
+
* PDF conversion strategy:
|
|
8
|
+
* 1. Try pdf-parse (fast, local, free) — extracts embedded text
|
|
9
|
+
* 2. Check if extracted text is meaningful (chars-per-page heuristic)
|
|
10
|
+
* 3. If scanned/image PDF → fall back to Mistral OCR API
|
|
11
|
+
*
|
|
12
|
+
* XLSX and DOCX are NOT pre-converted — the agent writes extraction code
|
|
13
|
+
* at runtime via bash, which is more powerful for structured data.
|
|
14
|
+
*/
|
|
15
|
+
import type { FolderInventory } from "./folder-scanner.js";
|
|
16
|
+
/**
|
|
17
|
+
* Minimum average characters per page to consider text extraction successful.
|
|
18
|
+
* Below this threshold, the PDF is likely scanned/image-based and needs OCR.
|
|
19
|
+
*/
|
|
20
|
+
declare const MIN_CHARS_PER_PAGE = 50;
|
|
21
|
+
/**
|
|
22
|
+
* Check if extracted text is meaningful (not just whitespace/control chars).
|
|
23
|
+
* Scanned PDFs often return empty or near-empty text.
|
|
24
|
+
*/
|
|
25
|
+
declare function isTextMeaningful(text: string, pageCount: number): boolean;
|
|
26
|
+
interface OcrConfig {
|
|
27
|
+
provider: "azure-mistral" | "mistral";
|
|
28
|
+
endpoint?: string;
|
|
29
|
+
apiKey: string;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Detect which OCR provider is available.
|
|
33
|
+
* Priority: Azure Mistral (enterprise) → direct Mistral → null
|
|
34
|
+
*/
|
|
35
|
+
declare function getOcrConfig(): OcrConfig | null;
|
|
36
|
+
export interface ConversionResult {
|
|
37
|
+
/** Number of PDFs converted via text extraction */
|
|
38
|
+
converted: number;
|
|
39
|
+
/** Number of PDFs converted via Mistral OCR */
|
|
40
|
+
ocrConverted: number;
|
|
41
|
+
/** Number already cached (skipped) */
|
|
42
|
+
cached: number;
|
|
43
|
+
/** Number that failed */
|
|
44
|
+
failed: number;
|
|
45
|
+
/** Error messages for failures */
|
|
46
|
+
errors: string[];
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Pre-convert all PDFs in an inventory to Markdown.
|
|
50
|
+
* Skips files where the cache is still valid (source not modified).
|
|
51
|
+
*
|
|
52
|
+
* @param inventory - Folder inventory from scanner
|
|
53
|
+
* @returns Summary of conversion results
|
|
54
|
+
*/
|
|
55
|
+
export declare function convertDocuments(inventory: FolderInventory): Promise<ConversionResult>;
|
|
56
|
+
/**
|
|
57
|
+
* Get the markdown path for a source file, if it has been converted.
|
|
58
|
+
* Returns null if no cached conversion exists.
|
|
59
|
+
*/
|
|
60
|
+
export declare function getConvertedPath(folderRoot: string, relativePath: string): string | null;
|
|
61
|
+
/**
|
|
62
|
+
* Build a list of converted markdown files for agent context.
|
|
63
|
+
* Returns entries like: `invoice.pdf → .agentxl-cache/invoice.pdf.md`
|
|
64
|
+
*/
|
|
65
|
+
export declare function listConvertedFiles(inventory: FolderInventory): Array<{
|
|
66
|
+
source: string;
|
|
67
|
+
converted: string;
|
|
68
|
+
}>;
|
|
69
|
+
export { isTextMeaningful, getOcrConfig, MIN_CHARS_PER_PAGE };
|
|
70
|
+
export type { OcrConfig };
|
|
71
|
+
//# sourceMappingURL=document-converter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"document-converter.d.ts","sourceRoot":"","sources":["../../src/server/document-converter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAIH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAK3D;;;GAGG;AACH,QAAA,MAAM,kBAAkB,KAAK,CAAC;AAiD9B;;;GAGG;AACH,iBAAS,gBAAgB,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAQlE;AAMD,UAAU,SAAS;IACjB,QAAQ,EAAE,eAAe,GAAG,SAAS,CAAC;IACtC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;CAChB;AAED;;;GAGG;AACH,iBAAS,YAAY,IAAI,SAAS,GAAG,IAAI,CAexC;AAiPD,MAAM,WAAW,gBAAgB;IAC/B,mDAAmD;IACnD,SAAS,EAAE,MAAM,CAAC;IAClB,+CAA+C;IAC/C,YAAY,EAAE,MAAM,CAAC;IACrB,sCAAsC;IACtC,MAAM,EAAE,MAAM,CAAC;IACf,yBAAyB;IACzB,MAAM,EAAE,MAAM,CAAC;IACf,kCAAkC;IAClC,MAAM,EAAE,MAAM,EAAE,CAAC;CAClB;AAED;;;;;;GAMG;AACH,wBAAsB,gBAAgB,CACpC,SAAS,EAAE,eAAe,GACzB,OAAO,CAAC,gBAAgB,CAAC,CAkD3B;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAC9B,UAAU,EAA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