@matimo/core 0.1.0-alpha.10
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 +252 -0
- package/destructive-keywords.yaml +70 -0
- package/dist/approval/approval-handler.d.ts +74 -0
- package/dist/approval/approval-handler.d.ts.map +1 -0
- package/dist/approval/approval-handler.js +210 -0
- package/dist/approval/approval-handler.js.map +1 -0
- package/dist/auth/oauth2-config.d.ts +104 -0
- package/dist/auth/oauth2-config.d.ts.map +1 -0
- package/dist/auth/oauth2-config.js +38 -0
- package/dist/auth/oauth2-config.js.map +1 -0
- package/dist/auth/oauth2-handler.d.ts +130 -0
- package/dist/auth/oauth2-handler.d.ts.map +1 -0
- package/dist/auth/oauth2-handler.js +265 -0
- package/dist/auth/oauth2-handler.js.map +1 -0
- package/dist/auth/oauth2-provider-loader.d.ts +68 -0
- package/dist/auth/oauth2-provider-loader.d.ts.map +1 -0
- package/dist/auth/oauth2-provider-loader.js +120 -0
- package/dist/auth/oauth2-provider-loader.js.map +1 -0
- package/dist/core/schema.d.ts +259 -0
- package/dist/core/schema.d.ts.map +1 -0
- package/dist/core/schema.js +187 -0
- package/dist/core/schema.js.map +1 -0
- package/dist/core/tool-loader.d.ts +57 -0
- package/dist/core/tool-loader.d.ts.map +1 -0
- package/dist/core/tool-loader.js +250 -0
- package/dist/core/tool-loader.js.map +1 -0
- package/dist/core/tool-registry.d.ts +48 -0
- package/dist/core/tool-registry.d.ts.map +1 -0
- package/dist/core/tool-registry.js +93 -0
- package/dist/core/tool-registry.js.map +1 -0
- package/dist/core/types.d.ts +162 -0
- package/dist/core/types.d.ts.map +1 -0
- package/dist/core/types.js +5 -0
- package/dist/core/types.js.map +1 -0
- package/dist/decorators/index.d.ts +2 -0
- package/dist/decorators/index.d.ts.map +1 -0
- package/dist/decorators/index.js +2 -0
- package/dist/decorators/index.js.map +1 -0
- package/dist/decorators/tool-decorator.d.ts +97 -0
- package/dist/decorators/tool-decorator.d.ts.map +1 -0
- package/dist/decorators/tool-decorator.js +157 -0
- package/dist/decorators/tool-decorator.js.map +1 -0
- package/dist/encodings/parameter-encoding.d.ts +51 -0
- package/dist/encodings/parameter-encoding.d.ts.map +1 -0
- package/dist/encodings/parameter-encoding.js +124 -0
- package/dist/encodings/parameter-encoding.js.map +1 -0
- package/dist/errors/matimo-error.d.ts +41 -0
- package/dist/errors/matimo-error.d.ts.map +1 -0
- package/dist/errors/matimo-error.js +71 -0
- package/dist/errors/matimo-error.js.map +1 -0
- package/dist/executors/command-executor.d.ts +19 -0
- package/dist/executors/command-executor.d.ts.map +1 -0
- package/dist/executors/command-executor.js +98 -0
- package/dist/executors/command-executor.js.map +1 -0
- package/dist/executors/function-executor.d.ts +23 -0
- package/dist/executors/function-executor.d.ts.map +1 -0
- package/dist/executors/function-executor.js +181 -0
- package/dist/executors/function-executor.js.map +1 -0
- package/dist/executors/http-executor.d.ts +78 -0
- package/dist/executors/http-executor.d.ts.map +1 -0
- package/dist/executors/http-executor.js +279 -0
- package/dist/executors/http-executor.js.map +1 -0
- package/dist/index.d.ts +30 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +33 -0
- package/dist/index.js.map +1 -0
- package/dist/integrations/langchain.d.ts +46 -0
- package/dist/integrations/langchain.d.ts.map +1 -0
- package/dist/integrations/langchain.js +197 -0
- package/dist/integrations/langchain.js.map +1 -0
- package/dist/logging/index.d.ts +3 -0
- package/dist/logging/index.d.ts.map +1 -0
- package/dist/logging/index.js +3 -0
- package/dist/logging/index.js.map +1 -0
- package/dist/logging/logger.d.ts +96 -0
- package/dist/logging/logger.d.ts.map +1 -0
- package/dist/logging/logger.js +53 -0
- package/dist/logging/logger.js.map +1 -0
- package/dist/logging/winston-logger.d.ts +29 -0
- package/dist/logging/winston-logger.d.ts.map +1 -0
- package/dist/logging/winston-logger.js +73 -0
- package/dist/logging/winston-logger.js.map +1 -0
- package/dist/matimo-instance.d.ts +140 -0
- package/dist/matimo-instance.d.ts.map +1 -0
- package/dist/matimo-instance.js +412 -0
- package/dist/matimo-instance.js.map +1 -0
- package/package.json +96 -0
- package/tools/calculator/calculator.ts +145 -0
- package/tools/calculator/definition.yaml +70 -0
- package/tools/edit/definition.yaml +115 -0
- package/tools/edit/edit.ts +187 -0
- package/tools/execute/definition.yaml +90 -0
- package/tools/execute/execute.ts +207 -0
- package/tools/read/definition.yaml +106 -0
- package/tools/read/read.ts +118 -0
- package/tools/search/definition.yaml +148 -0
- package/tools/search/search.ts +192 -0
- package/tools/web/definition.yaml +132 -0
- package/tools/web/web.ts +134 -0
package/tools/web/web.ts
ADDED
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Web Tool - Fetch web content from URLs with flexible HTTP methods
|
|
4
|
+
* Function-type tool: Exports default async function
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import axios, { AxiosRequestConfig, AxiosError } from 'axios';
|
|
8
|
+
import { MatimoError, ErrorCode } from '../../src/errors/matimo-error';
|
|
9
|
+
|
|
10
|
+
interface WebParams {
|
|
11
|
+
url: string;
|
|
12
|
+
method?: string;
|
|
13
|
+
headers?: Record<string, string>;
|
|
14
|
+
body?: string;
|
|
15
|
+
timeout?: number;
|
|
16
|
+
followRedirects?: boolean;
|
|
17
|
+
parseJson?: boolean;
|
|
18
|
+
maxSize?: number;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
interface WebResult {
|
|
22
|
+
success: boolean;
|
|
23
|
+
url: string;
|
|
24
|
+
statusCode: number;
|
|
25
|
+
statusText: string;
|
|
26
|
+
contentType: string;
|
|
27
|
+
content: unknown;
|
|
28
|
+
headers: Record<string, unknown>;
|
|
29
|
+
size: number;
|
|
30
|
+
duration: number;
|
|
31
|
+
redirects?: string[];
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Fetch URL and return response with optional JSON parsing
|
|
36
|
+
*/
|
|
37
|
+
export default async function webTool(params: WebParams): Promise<WebResult> {
|
|
38
|
+
const {
|
|
39
|
+
url,
|
|
40
|
+
method = 'GET',
|
|
41
|
+
headers,
|
|
42
|
+
body,
|
|
43
|
+
timeout = 30000,
|
|
44
|
+
followRedirects = true,
|
|
45
|
+
parseJson = true,
|
|
46
|
+
maxSize = 10485760,
|
|
47
|
+
} = params;
|
|
48
|
+
|
|
49
|
+
const startTime = Date.now();
|
|
50
|
+
|
|
51
|
+
// Validate required parameter
|
|
52
|
+
if (!url) {
|
|
53
|
+
throw new MatimoError('Missing required parameter', ErrorCode.INVALID_PARAMETER, {
|
|
54
|
+
reason: 'url is required',
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// Validate URL
|
|
59
|
+
try {
|
|
60
|
+
new URL(url);
|
|
61
|
+
} catch {
|
|
62
|
+
throw new MatimoError('Invalid URL', ErrorCode.INVALID_PARAMETER, {
|
|
63
|
+
url,
|
|
64
|
+
reason: 'URL must be valid http or https',
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const requestConfig: AxiosRequestConfig = {
|
|
69
|
+
method: method.toUpperCase() || 'GET',
|
|
70
|
+
url,
|
|
71
|
+
timeout,
|
|
72
|
+
maxContentLength: maxSize,
|
|
73
|
+
maxBodyLength: maxSize,
|
|
74
|
+
headers: {
|
|
75
|
+
'User-Agent': 'Matimo/1.0 (AI Agent Tool SDK)',
|
|
76
|
+
Accept: 'application/json, text/plain, text/html, */*',
|
|
77
|
+
...headers,
|
|
78
|
+
},
|
|
79
|
+
validateStatus: () => true, // Don't throw on any status code
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
if (body && ['POST', 'PUT', 'PATCH'].includes(method.toUpperCase())) {
|
|
83
|
+
requestConfig.data = body;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
if (!followRedirects) {
|
|
87
|
+
requestConfig.maxRedirects = 0;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
try {
|
|
91
|
+
const response = await axios.request(requestConfig);
|
|
92
|
+
let content: unknown = response.data;
|
|
93
|
+
|
|
94
|
+
// Try to parse JSON if requested and content-type suggests JSON
|
|
95
|
+
if (parseJson && response.headers['content-type']?.includes('application/json')) {
|
|
96
|
+
try {
|
|
97
|
+
if (typeof response.data === 'string') {
|
|
98
|
+
content = JSON.parse(response.data);
|
|
99
|
+
} else {
|
|
100
|
+
content = response.data;
|
|
101
|
+
}
|
|
102
|
+
} catch {
|
|
103
|
+
// If JSON parsing fails, keep original content
|
|
104
|
+
content = response.data;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
const result: WebResult = {
|
|
109
|
+
success: response.status >= 200 && response.status < 300,
|
|
110
|
+
url,
|
|
111
|
+
statusCode: response.status,
|
|
112
|
+
statusText: response.statusText || '',
|
|
113
|
+
contentType: (response.headers['content-type'] as string) || 'unknown',
|
|
114
|
+
content,
|
|
115
|
+
headers: response.headers,
|
|
116
|
+
size: JSON.stringify(response.data).length,
|
|
117
|
+
duration: Date.now() - startTime,
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
return result;
|
|
121
|
+
} catch (error) {
|
|
122
|
+
const axiosError = error as AxiosError;
|
|
123
|
+
throw new MatimoError(
|
|
124
|
+
'HTTP request failed',
|
|
125
|
+
ErrorCode.NETWORK_ERROR,
|
|
126
|
+
{
|
|
127
|
+
url,
|
|
128
|
+
statusCode: axiosError.response?.status,
|
|
129
|
+
statusText: axiosError.response?.statusText,
|
|
130
|
+
originalError: axiosError.message,
|
|
131
|
+
}
|
|
132
|
+
);
|
|
133
|
+
}
|
|
134
|
+
}
|