@causyne/agent 1.19.0 → 1.20.5
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 +0 -18
- package/package.json +1 -1
- package/src/acp/client.js +2 -1
- package/src/acp/client.ts +2 -1
- package/src/acp/server.js +5 -6
- package/src/acp/server.ts +4 -6
- package/src/agentLoop.d.ts +1 -0
- package/src/agentLoop.js +505 -241
- package/src/agentLoop.ts +527 -258
- package/src/agentPolicy.js +9 -0
- package/src/agentPolicy.ts +9 -0
- package/src/approvalPolicy.js +55 -0
- package/src/approvalPolicy.ts +66 -0
- package/src/browser/browserRuntime.js +217 -14
- package/src/browser/browserRuntime.ts +255 -14
- package/src/browser/causyneBrowser.js +1215 -68
- package/src/browser/causyneBrowser.ts +1340 -72
- package/src/cliMode.js +66 -37
- package/src/commands.js +343 -72
- package/src/config.js +22 -12
- package/src/continuum/ingest.js +1 -1
- package/src/continuum/ingest.ts +1 -1
- package/src/continuum/ui/continuumPicker.js +18 -1
- package/src/continuum/ui/continuumPicker.ts +19 -1
- package/src/dynamicCatalogue.js +87 -20
- package/src/dynamicCatalogue.ts +85 -15
- package/src/launchIntent.js +40 -0
- package/src/launchIntent.ts +49 -0
- package/src/memoryManager.js +36 -8
- package/src/modelCatalogue.js +2 -0
- package/src/planCache.js +320 -11
- package/src/planCache.ts +402 -13
- package/src/providers/acp.js +67 -1
- package/src/providers/acp.ts +65 -2
- package/src/providers/antigravity.d.ts +5 -1
- package/src/providers/antigravity.js +643 -32
- package/src/providers/antigravity.ts +671 -33
- package/src/providers/base.d.ts +9 -0
- package/src/providers/factory.js +2 -0
- package/src/providers/pi.js +157 -0
- package/src/providers/pi.ts +144 -0
- package/src/provisioning/capabilityProvisioner.js +17 -0
- package/src/provisioning/capabilityTools.js +1 -1
- package/src/sandbox.js +30 -39
- package/src/sessionJournal.js +66 -10
- package/src/sessionJournal.ts +84 -10
- package/src/taskShape.js +9 -9
- package/src/taskShape.ts +9 -9
- package/src/timeMachine.js +124 -0
- package/src/timeMachine.ts +141 -0
- package/src/toolPacks.js +4 -10
- package/src/tools/archive.js +196 -59
- package/src/tools/archive.ts +220 -0
- package/src/tools/browserAutomator.js +78 -9
- package/src/tools/browserAutomator.ts +90 -9
- package/src/tools/desktopOpen.js +114 -31
- package/src/tools/desktopOpen.ts +144 -0
- package/src/tools/gitExec.js +5 -3
- package/src/tools/nativeEngine.js +4 -3
- package/src/tools/nativeEngine.ts +5 -3
- package/src/tools/openSourceToolProvisioner.js +5 -4
- package/src/tools/openSourceToolProvisioner.ts +5 -4
- package/src/tools/registry.js +3 -0
- package/src/tools/screenshot.js +55 -71
- package/src/tools/screenshot.ts +70 -0
- package/src/tools/sysRun.js +284 -117
- package/src/tools/sysRun.ts +347 -0
- package/src/tools/toolSelfRepair.js +109 -2
- package/src/tools/toolSelfRepair.ts +100 -2
- package/src/tools/updatePlan.js +49 -1
- package/src/tools/updatePlan.ts +43 -1
- package/src/tools/viewImage.js +93 -78
- package/src/tools/viewImage.ts +116 -0
- package/src/tools/webFetch.js +20 -6
- package/src/tools/webFetch.ts +26 -6
- package/src/tui/block.d.ts +1 -0
- package/src/tui/chatRenderer.d.ts +21 -0
- package/src/tui/chatRenderer.js +118 -45
- package/src/tui/clipboardSync.js +28 -1
- package/src/tui/clipboardSync.ts +26 -1
- package/src/tui/codeProgress.js +299 -0
- package/src/tui/codeProgress.ts +304 -0
- package/src/tui/codeStreamRenderer.js +116 -0
- package/src/tui/codeStreamRenderer.ts +124 -0
- package/src/tui/commandPresentation.js +11 -0
- package/src/tui/commandPresentation.ts +18 -0
- package/src/tui/completion.js +45 -13
- package/src/tui/composerControls.js +66 -0
- package/src/tui/composerControls.ts +78 -0
- package/src/tui/diff.d.ts +2 -0
- package/src/tui/home.js +4 -2
- package/src/tui/homeTransition.js +21 -0
- package/src/tui/homeTransition.ts +27 -0
- package/src/tui/homeView.js +62 -0
- package/src/tui/homeView.ts +91 -0
- package/src/tui/layout.js +46 -0
- package/src/tui/layout.ts +52 -0
- package/src/tui/messageActionPlacement.js +16 -0
- package/src/tui/messageActionPlacement.ts +25 -0
- package/src/tui/messageInteraction.js +221 -0
- package/src/tui/messageInteraction.ts +275 -0
- package/src/tui/modelPicker.js +13 -0
- package/src/tui/modelPicker.ts +12 -0
- package/src/tui/mouseHover.js +6 -0
- package/src/tui/mouseHover.ts +5 -0
- package/src/tui/prompt.js +199 -52
- package/src/tui/resizeRecovery.js +15 -0
- package/src/tui/resizeRecovery.ts +27 -0
- package/src/tui/scrollInteraction.js +97 -0
- package/src/tui/scrollInteraction.ts +189 -0
- package/src/tui/sessionLayout.js +12 -0
- package/src/tui/sessionLayout.ts +12 -0
- package/src/tui/sessionPicker.js +280 -0
- package/src/tui/sessionPicker.ts +364 -0
- package/src/tui/sessionSidebar.js +78 -0
- package/src/tui/sessionSidebar.ts +95 -0
- package/src/tui/setup.js +1 -1
- package/src/tui/setup.ts +1 -1
- package/src/tui/stageSurface.js +128 -57
- package/src/tui/statusLine.js +5 -5
- package/src/tui/text.d.ts +5 -0
- package/src/tui/textLayout.js +23 -0
- package/src/tui/textLayout.ts +28 -0
- package/src/tui/viewport.js +204 -279
- package/src/tui/viewport.ts +326 -0
- package/src/types/contracts.ts +54 -0
- package/src/utils/paths.js +5 -4
- package/src/utils/paths.ts +5 -5
package/src/tools/updatePlan.ts
CHANGED
|
@@ -6,6 +6,43 @@ interface ToolContext {
|
|
|
6
6
|
};
|
|
7
7
|
}
|
|
8
8
|
|
|
9
|
+
function healPlanArgs(raw: unknown): unknown {
|
|
10
|
+
if (!raw || typeof raw !== 'object' || Array.isArray(raw)) return raw;
|
|
11
|
+
const input = { ...(raw as Record<string, unknown>) };
|
|
12
|
+
if (!input.plan && (input.steps || input.items || input.tasks)) {
|
|
13
|
+
input.plan = input.steps || input.items || input.tasks;
|
|
14
|
+
}
|
|
15
|
+
if (Array.isArray(input.plan)) {
|
|
16
|
+
let activeSeen = false;
|
|
17
|
+
input.plan = (input.plan as unknown[]).map((stepItem, idx) => {
|
|
18
|
+
if (!stepItem || typeof stepItem !== 'object' || Array.isArray(stepItem)) return stepItem;
|
|
19
|
+
const s = { ...(stepItem as Record<string, unknown>) };
|
|
20
|
+
if (!s.id) s.id = `step-${idx + 1}`;
|
|
21
|
+
if (!s.step && (s.content || s.title || s.name || s.description)) {
|
|
22
|
+
s.step = s.content || s.title || s.name || s.description;
|
|
23
|
+
}
|
|
24
|
+
let status = String(s.status || s.state || 'pending').toLowerCase().trim();
|
|
25
|
+
if (status === 'in-progress' || status === 'in progress' || status === 'running' || status === 'working') {
|
|
26
|
+
status = 'in_progress';
|
|
27
|
+
} else if (status === 'done' || status === 'finished' || status === 'complete') {
|
|
28
|
+
status = 'completed';
|
|
29
|
+
} else if (status !== 'pending' && status !== 'in_progress' && status !== 'completed') {
|
|
30
|
+
status = 'pending';
|
|
31
|
+
}
|
|
32
|
+
if (status === 'in_progress') {
|
|
33
|
+
if (activeSeen) {
|
|
34
|
+
status = 'pending';
|
|
35
|
+
} else {
|
|
36
|
+
activeSeen = true;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
s.status = status;
|
|
40
|
+
return s;
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
return input;
|
|
44
|
+
}
|
|
45
|
+
|
|
9
46
|
export const updatePlan = {
|
|
10
47
|
schema: {
|
|
11
48
|
name: 'update_plan',
|
|
@@ -38,7 +75,12 @@ export const updatePlan = {
|
|
|
38
75
|
if (!context.parentLoop || typeof context.parentLoop.updateImplementationPlan !== 'function') {
|
|
39
76
|
return { success: false, error: 'Implementation plans require an active Causyne session' };
|
|
40
77
|
}
|
|
41
|
-
|
|
78
|
+
let update: PlanUpdate;
|
|
79
|
+
try {
|
|
80
|
+
update = normalizePlanUpdate(args);
|
|
81
|
+
} catch {
|
|
82
|
+
update = normalizePlanUpdate(healPlanArgs(args));
|
|
83
|
+
}
|
|
42
84
|
context.parentLoop.updateImplementationPlan(update);
|
|
43
85
|
return { success: true, output: summarizePlan(update.plan), plan: update.plan };
|
|
44
86
|
} catch (error) {
|
package/src/tools/viewImage.js
CHANGED
|
@@ -1,82 +1,97 @@
|
|
|
1
|
-
import fs from 'fs/promises';
|
|
1
|
+
import fs from 'node:fs/promises';
|
|
2
|
+
import { existsSync, statSync } from 'node:fs';
|
|
3
|
+
import path from 'node:path';
|
|
2
4
|
import { resolveUserPath } from '../utils/paths.js';
|
|
3
|
-
import {
|
|
4
|
-
import path from 'path';
|
|
5
|
-
import os from 'os';
|
|
6
|
-
import { ensureCapability, loadCapabilityPackage } from '../provisioning/capabilityProvisioner.js';
|
|
7
|
-
|
|
5
|
+
import { loadCapabilityPackage } from '../provisioning/capabilityProvisioner.js';
|
|
8
6
|
export const viewImage = {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
7
|
+
schema: {
|
|
8
|
+
name: 'view_image',
|
|
9
|
+
description: 'Multi-Modal Pre-Processing Engine. View an image file from disk. Automatically normalizes and compresses huge images to save tokens. For text-only LLMs or document scans, extracts text via OCR.',
|
|
10
|
+
parameters: {
|
|
11
|
+
type: 'object',
|
|
12
|
+
properties: {
|
|
13
|
+
path: { type: 'string', description: 'Absolute or relative path to the image file' },
|
|
14
|
+
extractTextOnly: { type: 'boolean', description: 'If true, skips Vision APIs and uses local OCR to read text from the image.' }
|
|
15
|
+
},
|
|
16
|
+
required: ['path']
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
execute: async (args, sandbox) => {
|
|
20
|
+
try {
|
|
21
|
+
if (!args || !args.path) {
|
|
22
|
+
return { success: false, error: 'Missing required argument: path' };
|
|
23
|
+
}
|
|
24
|
+
const targetPath = resolveUserPath(args.path);
|
|
25
|
+
if (!existsSync(targetPath)) {
|
|
26
|
+
return { success: false, error: `Image not found at ${targetPath}` };
|
|
27
|
+
}
|
|
28
|
+
const stat = statSync(targetPath);
|
|
29
|
+
if (stat.size > 25 * 1024 * 1024) {
|
|
30
|
+
return { success: false, error: 'Image too large. Maximum raw size is 25MB.' };
|
|
31
|
+
}
|
|
32
|
+
// OCR Fallback for Text-Only LLMs if explicitly requested or sandbox is strictly non-vision
|
|
33
|
+
const forceOcr = Boolean(args.extractTextOnly || (sandbox && sandbox.llmSupportsVision === false));
|
|
34
|
+
if (forceOcr) {
|
|
35
|
+
try {
|
|
36
|
+
const Tesseract = await loadCapabilityPackage('tesseract.js');
|
|
37
|
+
if (Tesseract && typeof Tesseract.createWorker === 'function') {
|
|
38
|
+
const worker = await Tesseract.createWorker('eng');
|
|
39
|
+
const { data: { text } } = await worker.recognize(targetPath);
|
|
40
|
+
await worker.terminate();
|
|
41
|
+
return { success: true, output: `[OCR Text Extracted from ${path.basename(targetPath)}]:\n\n${text}` };
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
catch {
|
|
45
|
+
// If tesseract isn't provisioned, fall through to returning image data if not explicitly text-only
|
|
46
|
+
if (args.extractTextOnly) {
|
|
47
|
+
return {
|
|
48
|
+
success: false,
|
|
49
|
+
error: `OCR package tesseract.js is not loaded. To view the image directly, omit extractTextOnly.`
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
// Vision image reading & normalization
|
|
55
|
+
let processedBuffer;
|
|
56
|
+
let mimeType = 'image/jpeg';
|
|
57
|
+
const ext = path.extname(targetPath).toLowerCase();
|
|
58
|
+
try {
|
|
59
|
+
const sharp = await loadCapabilityPackage('sharp');
|
|
60
|
+
if (typeof sharp === 'function') {
|
|
61
|
+
processedBuffer = await sharp(targetPath)
|
|
62
|
+
.resize({ width: 1280, height: 1280, fit: 'inside', withoutEnlargement: true })
|
|
63
|
+
.jpeg({ quality: 85 })
|
|
64
|
+
.toBuffer();
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
processedBuffer = await fs.readFile(targetPath);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
catch {
|
|
71
|
+
processedBuffer = await fs.readFile(targetPath);
|
|
72
|
+
}
|
|
73
|
+
if (ext === '.png')
|
|
74
|
+
mimeType = 'image/png';
|
|
75
|
+
else if (ext === '.webp')
|
|
76
|
+
mimeType = 'image/webp';
|
|
77
|
+
else if (ext === '.gif')
|
|
78
|
+
mimeType = 'image/gif';
|
|
79
|
+
else if (ext === '.svg')
|
|
80
|
+
mimeType = 'image/svg+xml';
|
|
81
|
+
else if (ext === '.bmp')
|
|
82
|
+
mimeType = 'image/bmp';
|
|
83
|
+
const base64 = processedBuffer.toString('base64');
|
|
84
|
+
return {
|
|
85
|
+
_is_image_marker: true,
|
|
86
|
+
success: true,
|
|
87
|
+
mimeType,
|
|
88
|
+
base64,
|
|
89
|
+
filename: path.basename(targetPath),
|
|
90
|
+
path: targetPath
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
catch (error) {
|
|
94
|
+
return { success: false, error: `Error viewing image: ${error?.message || String(error)}` };
|
|
95
|
+
}
|
|
19
96
|
}
|
|
20
|
-
},
|
|
21
|
-
|
|
22
|
-
execute: async (args, sandbox) => {
|
|
23
|
-
try {
|
|
24
|
-
const targetPath = resolveUserPath(args.path);
|
|
25
|
-
if (!existsSync(targetPath)) {
|
|
26
|
-
return { success: false, error: `Image not found at ${targetPath}` };
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
const stat = statSync(targetPath);
|
|
30
|
-
if (stat.size > 20 * 1024 * 1024) {
|
|
31
|
-
return { success: false, error: 'Image too large. Maximum raw size is 20MB.' };
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
// Phase 6 AGI Upgrade: OCR Fallback for Text-Only LLMs
|
|
35
|
-
const forceOcr = args.extractTextOnly || (sandbox && sandbox.llmSupportsVision === false);
|
|
36
|
-
|
|
37
|
-
if (forceOcr) {
|
|
38
|
-
const ocr = await ensureCapability('ocr');
|
|
39
|
-
if (!ocr.ok) return { success: false, error: ocr.reason, requiresConsent: ocr.requiresConsent };
|
|
40
|
-
const Tesseract = await loadCapabilityPackage('tesseract.js');
|
|
41
|
-
|
|
42
|
-
const worker = await Tesseract.createWorker('eng');
|
|
43
|
-
const { data: { text } } = await worker.recognize(targetPath);
|
|
44
|
-
await worker.terminate();
|
|
45
|
-
|
|
46
|
-
return { success: true, output: `[OCR FALLBACK] Extracted Text from Image:\n\n${text}` };
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
// Phase 6 AGI Upgrade: Dynamic Resizing & Format Normalization
|
|
50
|
-
let processedBuffer;
|
|
51
|
-
let mimeType = 'image/jpeg';
|
|
52
|
-
|
|
53
|
-
try {
|
|
54
|
-
// sharp already lives in the Cortex tree as a pinned override, so it is
|
|
55
|
-
// loaded from there rather than installed a second time.
|
|
56
|
-
const sharp = await loadCapabilityPackage('sharp');
|
|
57
|
-
processedBuffer = await sharp(targetPath)
|
|
58
|
-
.resize({ width: 1024, height: 1024, fit: 'inside', withoutEnlargement: true })
|
|
59
|
-
.jpeg({ quality: 85 })
|
|
60
|
-
.toBuffer();
|
|
61
|
-
} catch (e) {
|
|
62
|
-
// Fallback if sharp is missing (return raw buffer but warn)
|
|
63
|
-
processedBuffer = await fs.readFile(targetPath);
|
|
64
|
-
const ext = path.extname(targetPath).toLowerCase();
|
|
65
|
-
if (ext === '.png') mimeType = 'image/png';
|
|
66
|
-
else if (ext === '.webp') mimeType = 'image/webp';
|
|
67
|
-
else if (ext === '.gif') mimeType = 'image/gif';
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
const base64 = processedBuffer.toString('base64');
|
|
71
|
-
|
|
72
|
-
return {
|
|
73
|
-
_is_image_marker: true,
|
|
74
|
-
mimeType,
|
|
75
|
-
base64,
|
|
76
|
-
filename: path.basename(targetPath)
|
|
77
|
-
};
|
|
78
|
-
} catch (error) {
|
|
79
|
-
return { success: false, error: `Error viewing image: ${error.message}` };
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
97
|
};
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import fs from 'node:fs/promises';
|
|
2
|
+
import { existsSync, statSync } from 'node:fs';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { resolveUserPath } from '../utils/paths.js';
|
|
5
|
+
import { loadCapabilityPackage } from '../provisioning/capabilityProvisioner.js';
|
|
6
|
+
|
|
7
|
+
export interface ViewImageArgs {
|
|
8
|
+
path: string;
|
|
9
|
+
extractTextOnly?: boolean;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface ViewImageResult {
|
|
13
|
+
_is_image_marker?: boolean;
|
|
14
|
+
success?: boolean;
|
|
15
|
+
output?: string;
|
|
16
|
+
error?: string;
|
|
17
|
+
mimeType?: string;
|
|
18
|
+
base64?: string;
|
|
19
|
+
filename?: string;
|
|
20
|
+
path?: string;
|
|
21
|
+
requiresConsent?: boolean;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export const viewImage = {
|
|
25
|
+
schema: {
|
|
26
|
+
name: 'view_image',
|
|
27
|
+
description: 'Multi-Modal Pre-Processing Engine. View an image file from disk. Automatically normalizes and compresses huge images to save tokens. For text-only LLMs or document scans, extracts text via OCR.',
|
|
28
|
+
parameters: {
|
|
29
|
+
type: 'object',
|
|
30
|
+
properties: {
|
|
31
|
+
path: { type: 'string', description: 'Absolute or relative path to the image file' },
|
|
32
|
+
extractTextOnly: { type: 'boolean', description: 'If true, skips Vision APIs and uses local OCR to read text from the image.' }
|
|
33
|
+
},
|
|
34
|
+
required: ['path']
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
|
|
38
|
+
execute: async (args: ViewImageArgs, sandbox?: any): Promise<ViewImageResult> => {
|
|
39
|
+
try {
|
|
40
|
+
if (!args || !args.path) {
|
|
41
|
+
return { success: false, error: 'Missing required argument: path' };
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const targetPath = resolveUserPath(args.path);
|
|
45
|
+
if (!existsSync(targetPath)) {
|
|
46
|
+
return { success: false, error: `Image not found at ${targetPath}` };
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const stat = statSync(targetPath);
|
|
50
|
+
if (stat.size > 25 * 1024 * 1024) {
|
|
51
|
+
return { success: false, error: 'Image too large. Maximum raw size is 25MB.' };
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// OCR Fallback for Text-Only LLMs if explicitly requested or sandbox is strictly non-vision
|
|
55
|
+
const forceOcr = Boolean(args.extractTextOnly || (sandbox && sandbox.llmSupportsVision === false));
|
|
56
|
+
|
|
57
|
+
if (forceOcr) {
|
|
58
|
+
try {
|
|
59
|
+
const Tesseract: any = await loadCapabilityPackage('tesseract.js');
|
|
60
|
+
if (Tesseract && typeof Tesseract.createWorker === 'function') {
|
|
61
|
+
const worker = await Tesseract.createWorker('eng');
|
|
62
|
+
const { data: { text } } = await worker.recognize(targetPath);
|
|
63
|
+
await worker.terminate();
|
|
64
|
+
return { success: true, output: `[OCR Text Extracted from ${path.basename(targetPath)}]:\n\n${text}` };
|
|
65
|
+
}
|
|
66
|
+
} catch {
|
|
67
|
+
// If tesseract isn't provisioned, fall through to returning image data if not explicitly text-only
|
|
68
|
+
if (args.extractTextOnly) {
|
|
69
|
+
return {
|
|
70
|
+
success: false,
|
|
71
|
+
error: `OCR package tesseract.js is not loaded. To view the image directly, omit extractTextOnly.`
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// Vision image reading & normalization
|
|
78
|
+
let processedBuffer: Buffer;
|
|
79
|
+
let mimeType = 'image/jpeg';
|
|
80
|
+
const ext = path.extname(targetPath).toLowerCase();
|
|
81
|
+
|
|
82
|
+
try {
|
|
83
|
+
const sharp = await loadCapabilityPackage('sharp');
|
|
84
|
+
if (typeof sharp === 'function') {
|
|
85
|
+
processedBuffer = await sharp(targetPath)
|
|
86
|
+
.resize({ width: 1280, height: 1280, fit: 'inside', withoutEnlargement: true })
|
|
87
|
+
.jpeg({ quality: 85 })
|
|
88
|
+
.toBuffer();
|
|
89
|
+
} else {
|
|
90
|
+
processedBuffer = await fs.readFile(targetPath);
|
|
91
|
+
}
|
|
92
|
+
} catch {
|
|
93
|
+
processedBuffer = await fs.readFile(targetPath);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
if (ext === '.png') mimeType = 'image/png';
|
|
97
|
+
else if (ext === '.webp') mimeType = 'image/webp';
|
|
98
|
+
else if (ext === '.gif') mimeType = 'image/gif';
|
|
99
|
+
else if (ext === '.svg') mimeType = 'image/svg+xml';
|
|
100
|
+
else if (ext === '.bmp') mimeType = 'image/bmp';
|
|
101
|
+
|
|
102
|
+
const base64 = processedBuffer.toString('base64');
|
|
103
|
+
|
|
104
|
+
return {
|
|
105
|
+
_is_image_marker: true,
|
|
106
|
+
success: true,
|
|
107
|
+
mimeType,
|
|
108
|
+
base64,
|
|
109
|
+
filename: path.basename(targetPath),
|
|
110
|
+
path: targetPath
|
|
111
|
+
};
|
|
112
|
+
} catch (error: any) {
|
|
113
|
+
return { success: false, error: `Error viewing image: ${error?.message || String(error)}` };
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
};
|
package/src/tools/webFetch.js
CHANGED
|
@@ -94,9 +94,9 @@ async function readBoundedBody(response) {
|
|
|
94
94
|
}
|
|
95
95
|
return Buffer.concat(chunks.map(chunk => Buffer.from(chunk)), size);
|
|
96
96
|
}
|
|
97
|
-
async function browserFallback(url) {
|
|
97
|
+
async function browserFallback(url, workspace) {
|
|
98
98
|
try {
|
|
99
|
-
const results = await causyneBrowser().run([{ type: 'goto', url }, { type: 'extract', selector: 'body' }]);
|
|
99
|
+
const results = await causyneBrowser(workspace ? { workspace } : undefined).run([{ type: 'goto', url }, { type: 'extract', selector: 'body' }], workspace ? { workspace } : undefined);
|
|
100
100
|
const output = results.find(result => result.action === 'extract')?.output;
|
|
101
101
|
return output ? { success: true, output } : { success: false, error: 'Browser loaded the page but extracted no readable content' };
|
|
102
102
|
}
|
|
@@ -124,12 +124,13 @@ export const webFetch = {
|
|
|
124
124
|
additionalProperties: false
|
|
125
125
|
}
|
|
126
126
|
},
|
|
127
|
-
async execute(args) {
|
|
127
|
+
async execute(args, sandbox) {
|
|
128
128
|
const controller = new AbortController();
|
|
129
129
|
const timer = setTimeout(() => controller.abort(), REQUEST_TIMEOUT_MS);
|
|
130
130
|
try {
|
|
131
131
|
if (!args.url)
|
|
132
132
|
return { success: false, error: 'url is required' };
|
|
133
|
+
const workspace = path.resolve(sandbox?.workspacePaths?.[0] ?? sandbox?.workspaceRoot ?? process.cwd());
|
|
133
134
|
const method = (args.method ?? 'GET').toUpperCase();
|
|
134
135
|
const headers = {
|
|
135
136
|
'User-Agent': 'Causyne-Agent/1.10 (+https://causyne.com)',
|
|
@@ -142,10 +143,24 @@ export const webFetch = {
|
|
|
142
143
|
const { response, finalUrl } = await fetchFollowingSafeRedirects(args.url, request);
|
|
143
144
|
const contentType = response.headers.get('content-type')?.toLowerCase() ?? '';
|
|
144
145
|
if (!response.ok && !args.outputFile && contentType.includes('text/html') && [401, 403, 429, 503].includes(response.status)) {
|
|
145
|
-
const fallback = await browserFallback(finalUrl.href);
|
|
146
|
+
const fallback = await browserFallback(finalUrl.href, workspace);
|
|
146
147
|
if (fallback.success)
|
|
147
148
|
return { ...fallback, status: response.status, finalUrl: finalUrl.href, via: 'causyne-browser' };
|
|
148
|
-
|
|
149
|
+
const nextStep = response.status === 403
|
|
150
|
+
? 'Try another public source or a supported browser capability.'
|
|
151
|
+
: response.status === 401
|
|
152
|
+
? 'This resource requires authentication.'
|
|
153
|
+
: response.status === 429
|
|
154
|
+
? 'Respect the site retry window before requesting it again.'
|
|
155
|
+
: 'The site may be temporarily unavailable; verify its status before retrying.';
|
|
156
|
+
return {
|
|
157
|
+
success: false,
|
|
158
|
+
status: response.status,
|
|
159
|
+
finalUrl: finalUrl.href,
|
|
160
|
+
failureKind: response.status === 403 ? 'site_refusal' : response.status === 429 ? 'rate_limited' : 'http_error',
|
|
161
|
+
error: `HTTP ${response.status} from ${finalUrl.hostname}; browser fallback unavailable: ${fallback.error}. ${nextStep}`,
|
|
162
|
+
requiresConsent: fallback.requiresConsent
|
|
163
|
+
};
|
|
149
164
|
}
|
|
150
165
|
if (!response.ok)
|
|
151
166
|
return { success: false, error: `HTTP ${response.status} ${response.statusText}`.trim(), status: response.status, finalUrl: finalUrl.href };
|
|
@@ -155,7 +170,6 @@ export const webFetch = {
|
|
|
155
170
|
}
|
|
156
171
|
const bytes = await readBoundedBody(response);
|
|
157
172
|
if (args.outputFile) {
|
|
158
|
-
const workspace = path.resolve(process.cwd());
|
|
159
173
|
const target = path.resolve(workspace, args.outputFile);
|
|
160
174
|
if (!isWithin(workspace, target))
|
|
161
175
|
return { success: false, error: 'Download target must stay inside the selected workspace' };
|
package/src/tools/webFetch.ts
CHANGED
|
@@ -93,9 +93,12 @@ async function readBoundedBody(response: Response): Promise<Buffer> {
|
|
|
93
93
|
return Buffer.concat(chunks.map(chunk => Buffer.from(chunk)), size);
|
|
94
94
|
}
|
|
95
95
|
|
|
96
|
-
async function browserFallback(url: string): Promise<{ success: boolean; output?: string; error?: string; requiresConsent?: boolean }> {
|
|
96
|
+
async function browserFallback(url: string, workspace?: string): Promise<{ success: boolean; output?: string; error?: string; requiresConsent?: boolean }> {
|
|
97
97
|
try {
|
|
98
|
-
const results = await causyneBrowser(
|
|
98
|
+
const results = await causyneBrowser(workspace ? { workspace } : undefined).run(
|
|
99
|
+
[{ type: 'goto', url }, { type: 'extract', selector: 'body' }],
|
|
100
|
+
workspace ? { workspace } : undefined
|
|
101
|
+
);
|
|
99
102
|
const output = results.find(result => result.action === 'extract')?.output;
|
|
100
103
|
return output ? { success: true, output } : { success: false, error: 'Browser loaded the page but extracted no readable content' };
|
|
101
104
|
} catch (error) {
|
|
@@ -124,11 +127,15 @@ export const webFetch = {
|
|
|
124
127
|
}
|
|
125
128
|
},
|
|
126
129
|
|
|
127
|
-
async execute(
|
|
130
|
+
async execute(
|
|
131
|
+
args: { url?: string; method?: string; headers?: unknown; body?: string; outputFile?: string },
|
|
132
|
+
sandbox?: { workspacePaths?: string[]; workspaceRoot?: string }
|
|
133
|
+
) {
|
|
128
134
|
const controller = new AbortController();
|
|
129
135
|
const timer = setTimeout(() => controller.abort(), REQUEST_TIMEOUT_MS);
|
|
130
136
|
try {
|
|
131
137
|
if (!args.url) return { success: false, error: 'url is required' };
|
|
138
|
+
const workspace = path.resolve(sandbox?.workspacePaths?.[0] ?? sandbox?.workspaceRoot ?? process.cwd());
|
|
132
139
|
const method = (args.method ?? 'GET').toUpperCase();
|
|
133
140
|
const headers = {
|
|
134
141
|
'User-Agent': 'Causyne-Agent/1.10 (+https://causyne.com)',
|
|
@@ -141,9 +148,23 @@ export const webFetch = {
|
|
|
141
148
|
const contentType = response.headers.get('content-type')?.toLowerCase() ?? '';
|
|
142
149
|
|
|
143
150
|
if (!response.ok && !args.outputFile && contentType.includes('text/html') && [401, 403, 429, 503].includes(response.status)) {
|
|
144
|
-
const fallback = await browserFallback(finalUrl.href);
|
|
151
|
+
const fallback = await browserFallback(finalUrl.href, workspace);
|
|
145
152
|
if (fallback.success) return { ...fallback, status: response.status, finalUrl: finalUrl.href, via: 'causyne-browser' };
|
|
146
|
-
|
|
153
|
+
const nextStep = response.status === 403
|
|
154
|
+
? 'Try another public source or a supported browser capability.'
|
|
155
|
+
: response.status === 401
|
|
156
|
+
? 'This resource requires authentication.'
|
|
157
|
+
: response.status === 429
|
|
158
|
+
? 'Respect the site retry window before requesting it again.'
|
|
159
|
+
: 'The site may be temporarily unavailable; verify its status before retrying.';
|
|
160
|
+
return {
|
|
161
|
+
success: false,
|
|
162
|
+
status: response.status,
|
|
163
|
+
finalUrl: finalUrl.href,
|
|
164
|
+
failureKind: response.status === 403 ? 'site_refusal' : response.status === 429 ? 'rate_limited' : 'http_error',
|
|
165
|
+
error: `HTTP ${response.status} from ${finalUrl.hostname}; browser fallback unavailable: ${fallback.error}. ${nextStep}`,
|
|
166
|
+
requiresConsent: fallback.requiresConsent
|
|
167
|
+
};
|
|
147
168
|
}
|
|
148
169
|
if (!response.ok) return { success: false, error: `HTTP ${response.status} ${response.statusText}`.trim(), status: response.status, finalUrl: finalUrl.href };
|
|
149
170
|
|
|
@@ -154,7 +175,6 @@ export const webFetch = {
|
|
|
154
175
|
const bytes = await readBoundedBody(response);
|
|
155
176
|
|
|
156
177
|
if (args.outputFile) {
|
|
157
|
-
const workspace = path.resolve(process.cwd());
|
|
158
178
|
const target = path.resolve(workspace, args.outputFile);
|
|
159
179
|
if (!isWithin(workspace, target)) return { success: false, error: 'Download target must stay inside the selected workspace' };
|
|
160
180
|
const temporary = `${target}.part-${crypto.randomUUID()}`;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export function panel(rows: string[], options?: { width?: number; title?: string; role?: string }): string[];
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export interface ChatFrame {
|
|
2
|
+
kind: string;
|
|
3
|
+
meta?: Record<string, unknown> | null;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
export interface ChatTranscript {
|
|
7
|
+
frames: ChatFrame[];
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export class ChatRenderer {
|
|
11
|
+
constructor(options?: Record<string, unknown>);
|
|
12
|
+
transcript: ChatTranscript | null;
|
|
13
|
+
_activeReasoning?: boolean;
|
|
14
|
+
handle(message: { type: string; [key: string]: unknown }): boolean;
|
|
15
|
+
onAgentReasoning(message: { content?: string; streaming?: boolean; elapsedMs?: number }): void;
|
|
16
|
+
stopSpinner(): void;
|
|
17
|
+
frame(kind: string, produce: () => void, meta?: Record<string, unknown> | null): void;
|
|
18
|
+
updateTailFrame(kind: string, produce: () => void, meta?: Record<string, unknown> | null): void;
|
|
19
|
+
measure(): number;
|
|
20
|
+
write(line?: string): void;
|
|
21
|
+
}
|