@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.
Files changed (100) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +252 -0
  3. package/destructive-keywords.yaml +70 -0
  4. package/dist/approval/approval-handler.d.ts +74 -0
  5. package/dist/approval/approval-handler.d.ts.map +1 -0
  6. package/dist/approval/approval-handler.js +210 -0
  7. package/dist/approval/approval-handler.js.map +1 -0
  8. package/dist/auth/oauth2-config.d.ts +104 -0
  9. package/dist/auth/oauth2-config.d.ts.map +1 -0
  10. package/dist/auth/oauth2-config.js +38 -0
  11. package/dist/auth/oauth2-config.js.map +1 -0
  12. package/dist/auth/oauth2-handler.d.ts +130 -0
  13. package/dist/auth/oauth2-handler.d.ts.map +1 -0
  14. package/dist/auth/oauth2-handler.js +265 -0
  15. package/dist/auth/oauth2-handler.js.map +1 -0
  16. package/dist/auth/oauth2-provider-loader.d.ts +68 -0
  17. package/dist/auth/oauth2-provider-loader.d.ts.map +1 -0
  18. package/dist/auth/oauth2-provider-loader.js +120 -0
  19. package/dist/auth/oauth2-provider-loader.js.map +1 -0
  20. package/dist/core/schema.d.ts +259 -0
  21. package/dist/core/schema.d.ts.map +1 -0
  22. package/dist/core/schema.js +187 -0
  23. package/dist/core/schema.js.map +1 -0
  24. package/dist/core/tool-loader.d.ts +57 -0
  25. package/dist/core/tool-loader.d.ts.map +1 -0
  26. package/dist/core/tool-loader.js +250 -0
  27. package/dist/core/tool-loader.js.map +1 -0
  28. package/dist/core/tool-registry.d.ts +48 -0
  29. package/dist/core/tool-registry.d.ts.map +1 -0
  30. package/dist/core/tool-registry.js +93 -0
  31. package/dist/core/tool-registry.js.map +1 -0
  32. package/dist/core/types.d.ts +162 -0
  33. package/dist/core/types.d.ts.map +1 -0
  34. package/dist/core/types.js +5 -0
  35. package/dist/core/types.js.map +1 -0
  36. package/dist/decorators/index.d.ts +2 -0
  37. package/dist/decorators/index.d.ts.map +1 -0
  38. package/dist/decorators/index.js +2 -0
  39. package/dist/decorators/index.js.map +1 -0
  40. package/dist/decorators/tool-decorator.d.ts +97 -0
  41. package/dist/decorators/tool-decorator.d.ts.map +1 -0
  42. package/dist/decorators/tool-decorator.js +157 -0
  43. package/dist/decorators/tool-decorator.js.map +1 -0
  44. package/dist/encodings/parameter-encoding.d.ts +51 -0
  45. package/dist/encodings/parameter-encoding.d.ts.map +1 -0
  46. package/dist/encodings/parameter-encoding.js +124 -0
  47. package/dist/encodings/parameter-encoding.js.map +1 -0
  48. package/dist/errors/matimo-error.d.ts +41 -0
  49. package/dist/errors/matimo-error.d.ts.map +1 -0
  50. package/dist/errors/matimo-error.js +71 -0
  51. package/dist/errors/matimo-error.js.map +1 -0
  52. package/dist/executors/command-executor.d.ts +19 -0
  53. package/dist/executors/command-executor.d.ts.map +1 -0
  54. package/dist/executors/command-executor.js +98 -0
  55. package/dist/executors/command-executor.js.map +1 -0
  56. package/dist/executors/function-executor.d.ts +23 -0
  57. package/dist/executors/function-executor.d.ts.map +1 -0
  58. package/dist/executors/function-executor.js +181 -0
  59. package/dist/executors/function-executor.js.map +1 -0
  60. package/dist/executors/http-executor.d.ts +78 -0
  61. package/dist/executors/http-executor.d.ts.map +1 -0
  62. package/dist/executors/http-executor.js +279 -0
  63. package/dist/executors/http-executor.js.map +1 -0
  64. package/dist/index.d.ts +30 -0
  65. package/dist/index.d.ts.map +1 -0
  66. package/dist/index.js +33 -0
  67. package/dist/index.js.map +1 -0
  68. package/dist/integrations/langchain.d.ts +46 -0
  69. package/dist/integrations/langchain.d.ts.map +1 -0
  70. package/dist/integrations/langchain.js +197 -0
  71. package/dist/integrations/langchain.js.map +1 -0
  72. package/dist/logging/index.d.ts +3 -0
  73. package/dist/logging/index.d.ts.map +1 -0
  74. package/dist/logging/index.js +3 -0
  75. package/dist/logging/index.js.map +1 -0
  76. package/dist/logging/logger.d.ts +96 -0
  77. package/dist/logging/logger.d.ts.map +1 -0
  78. package/dist/logging/logger.js +53 -0
  79. package/dist/logging/logger.js.map +1 -0
  80. package/dist/logging/winston-logger.d.ts +29 -0
  81. package/dist/logging/winston-logger.d.ts.map +1 -0
  82. package/dist/logging/winston-logger.js +73 -0
  83. package/dist/logging/winston-logger.js.map +1 -0
  84. package/dist/matimo-instance.d.ts +140 -0
  85. package/dist/matimo-instance.d.ts.map +1 -0
  86. package/dist/matimo-instance.js +412 -0
  87. package/dist/matimo-instance.js.map +1 -0
  88. package/package.json +96 -0
  89. package/tools/calculator/calculator.ts +145 -0
  90. package/tools/calculator/definition.yaml +70 -0
  91. package/tools/edit/definition.yaml +115 -0
  92. package/tools/edit/edit.ts +187 -0
  93. package/tools/execute/definition.yaml +90 -0
  94. package/tools/execute/execute.ts +207 -0
  95. package/tools/read/definition.yaml +106 -0
  96. package/tools/read/read.ts +118 -0
  97. package/tools/search/definition.yaml +148 -0
  98. package/tools/search/search.ts +192 -0
  99. package/tools/web/definition.yaml +132 -0
  100. package/tools/web/web.ts +134 -0
@@ -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
+ }