@elyracode/http-tools 0.9.55 → 0.9.57

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 (2) hide show
  1. package/extensions/index.ts +55 -28
  2. package/package.json +1 -1
@@ -1,8 +1,26 @@
1
- import type { ExtensionAPI } from "@elyracode/coding-agent";
1
+ import type { AgentToolResult, ExtensionAPI } from "@elyracode/coding-agent";
2
2
  import { Type } from "typebox";
3
3
 
4
- export default function (elyra: ExtensionAPI): void {
4
+ /** Details reported by execute_http_request. */
5
+ interface HttpRequestDetails {
6
+ status?: number;
7
+ statusText?: string;
8
+ contentType?: string;
9
+ }
5
10
 
11
+ /** Details reported by read_url_content. */
12
+ interface ReadUrlDetails {
13
+ url?: string;
14
+ length?: number;
15
+ }
16
+
17
+ /** Details reported by inspect_openapi. */
18
+ interface OpenApiDetails {
19
+ endpointCount?: number;
20
+ title?: unknown;
21
+ }
22
+
23
+ export default function (elyra: ExtensionAPI): void {
6
24
  // ── Tool 1: execute_http_request ──
7
25
  // "Intelligent Postman" -- send HTTP requests and analyze responses
8
26
  elyra.registerTool({
@@ -17,23 +35,28 @@ export default function (elyra: ExtensionAPI): void {
17
35
  url: Type.String({ description: "The URL to request (e.g., http://localhost:8000/api/users)" }),
18
36
  method: Type.Optional(
19
37
  Type.Union(
20
- [Type.Literal("GET"), Type.Literal("POST"), Type.Literal("PUT"), Type.Literal("PATCH"), Type.Literal("DELETE"), Type.Literal("HEAD"), Type.Literal("OPTIONS")],
38
+ [
39
+ Type.Literal("GET"),
40
+ Type.Literal("POST"),
41
+ Type.Literal("PUT"),
42
+ Type.Literal("PATCH"),
43
+ Type.Literal("DELETE"),
44
+ Type.Literal("HEAD"),
45
+ Type.Literal("OPTIONS"),
46
+ ],
21
47
  { description: "HTTP method (default: GET)" },
22
48
  ),
23
49
  ),
24
50
  headers: Type.Optional(
25
51
  Type.Record(Type.String(), Type.String(), {
26
- description: "Request headers (e.g., { \"Authorization\": \"Bearer token\", \"Content-Type\": \"application/json\" })",
52
+ description:
53
+ 'Request headers (e.g., { "Authorization": "Bearer token", "Content-Type": "application/json" })',
27
54
  }),
28
55
  ),
29
- body: Type.Optional(
30
- Type.String({ description: "Request body (JSON string for POST/PUT/PATCH)" }),
31
- ),
32
- timeout: Type.Optional(
33
- Type.Number({ description: "Timeout in milliseconds (default: 30000)" }),
34
- ),
56
+ body: Type.Optional(Type.String({ description: "Request body (JSON string for POST/PUT/PATCH)" })),
57
+ timeout: Type.Optional(Type.Number({ description: "Timeout in milliseconds (default: 30000)" })),
35
58
  }),
36
- execute: async (_toolCallId, params) => {
59
+ execute: async (_toolCallId, params): Promise<AgentToolResult<HttpRequestDetails>> => {
37
60
  try {
38
61
  const method = params.method ?? "GET";
39
62
  const headers: Record<string, string> = {
@@ -69,9 +92,8 @@ export default function (elyra: ExtensionAPI): void {
69
92
  }
70
93
 
71
94
  // Truncate large responses
72
- const truncated = body.length > 50000
73
- ? `${body.slice(0, 50000)}\n\n... (truncated, ${body.length} chars total)`
74
- : body;
95
+ const truncated =
96
+ body.length > 50000 ? `${body.slice(0, 50000)}\n\n... (truncated, ${body.length} chars total)` : body;
75
97
 
76
98
  const lines: string[] = [
77
99
  `${method} ${params.url}`,
@@ -116,11 +138,12 @@ export default function (elyra: ExtensionAPI): void {
116
138
  url: Type.String({ description: "The URL to fetch (e.g., https://laravel.com/docs/13.x/reverb)" }),
117
139
  selector: Type.Optional(
118
140
  Type.String({
119
- description: "CSS-like content hint: 'main', 'article', 'body'. Used to focus on main content and skip navigation/footer (default: auto-detect)",
141
+ description:
142
+ "CSS-like content hint: 'main', 'article', 'body'. Used to focus on main content and skip navigation/footer (default: auto-detect)",
120
143
  }),
121
144
  ),
122
145
  }),
123
- execute: async (_toolCallId, params) => {
146
+ execute: async (_toolCallId, params): Promise<AgentToolResult<ReadUrlDetails>> => {
124
147
  try {
125
148
  const response = await fetch(params.url, {
126
149
  headers: {
@@ -132,7 +155,9 @@ export default function (elyra: ExtensionAPI): void {
132
155
 
133
156
  if (!response.ok) {
134
157
  return {
135
- content: [{ type: "text", text: `Failed to fetch ${params.url}: ${response.status} ${response.statusText}` }],
158
+ content: [
159
+ { type: "text", text: `Failed to fetch ${params.url}: ${response.status} ${response.statusText}` },
160
+ ],
136
161
  details: {},
137
162
  };
138
163
  }
@@ -153,9 +178,8 @@ export default function (elyra: ExtensionAPI): void {
153
178
  }
154
179
 
155
180
  // Truncate
156
- const truncated = text.length > 80000
157
- ? `${text.slice(0, 80000)}\n\n... (truncated, ${text.length} chars total)`
158
- : text;
181
+ const truncated =
182
+ text.length > 80000 ? `${text.slice(0, 80000)}\n\n... (truncated, ${text.length} chars total)` : text;
159
183
 
160
184
  return {
161
185
  content: [{ type: "text", text: `# Content from ${params.url}\n\n${truncated}` }],
@@ -183,7 +207,8 @@ export default function (elyra: ExtensionAPI): void {
183
207
  "or understand a third-party API structure.",
184
208
  parameters: Type.Object({
185
209
  url: Type.String({
186
- description: "URL to the OpenAPI/Swagger JSON or YAML spec (e.g., https://petstore.swagger.io/v2/swagger.json)",
210
+ description:
211
+ "URL to the OpenAPI/Swagger JSON or YAML spec (e.g., https://petstore.swagger.io/v2/swagger.json)",
187
212
  }),
188
213
  filter: Type.Optional(
189
214
  Type.String({
@@ -191,7 +216,7 @@ export default function (elyra: ExtensionAPI): void {
191
216
  }),
192
217
  ),
193
218
  }),
194
- execute: async (_toolCallId, params) => {
219
+ execute: async (_toolCallId, params): Promise<AgentToolResult<OpenApiDetails>> => {
195
220
  try {
196
221
  const response = await fetch(params.url, {
197
222
  headers: {
@@ -208,7 +233,7 @@ export default function (elyra: ExtensionAPI): void {
208
233
  };
209
234
  }
210
235
 
211
- const spec = await response.json() as Record<string, unknown>;
236
+ const spec = (await response.json()) as Record<string, unknown>;
212
237
  const info = spec.info as Record<string, unknown> | undefined;
213
238
  const paths = spec.paths as Record<string, Record<string, unknown>> | undefined;
214
239
 
@@ -247,7 +272,9 @@ export default function (elyra: ExtensionAPI): void {
247
272
  lines.push("Parameters:");
248
273
  for (const param of parameters) {
249
274
  const required = param.required ? " (required)" : "";
250
- lines.push(` - ${param.name} [${param.in}]: ${param.description ?? (param.schema as Record<string, unknown>)?.type ?? "unknown"}${required}`);
275
+ lines.push(
276
+ ` - ${param.name} [${param.in}]: ${param.description ?? (param.schema as Record<string, unknown>)?.type ?? "unknown"}${required}`,
277
+ );
251
278
  }
252
279
  }
253
280
 
@@ -277,9 +304,7 @@ export default function (elyra: ExtensionAPI): void {
277
304
  lines.unshift(`Endpoints: ${endpointCount}${params.filter ? ` (filtered by ${params.filter})` : ""}`);
278
305
 
279
306
  const text = lines.join("\n");
280
- const truncated = text.length > 80000
281
- ? `${text.slice(0, 80000)}\n\n... (truncated)`
282
- : text;
307
+ const truncated = text.length > 80000 ? `${text.slice(0, 80000)}\n\n... (truncated)` : text;
283
308
 
284
309
  return {
285
310
  content: [{ type: "text", text: truncated }],
@@ -309,7 +334,9 @@ export default function (elyra: ExtensionAPI): void {
309
334
  if (!selected) return;
310
335
 
311
336
  if (selected.startsWith("Test API")) {
312
- elyra.sendUserMessage("I want to test an API endpoint. Ask me for the URL, method, and any headers or body to send.");
337
+ elyra.sendUserMessage(
338
+ "I want to test an API endpoint. Ask me for the URL, method, and any headers or body to send.",
339
+ );
313
340
  } else if (selected.startsWith("Read URL")) {
314
341
  elyra.sendUserMessage("I want to read content from a URL. Ask me which URL to fetch.");
315
342
  } else if (selected.startsWith("OpenAPI")) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@elyracode/http-tools",
3
- "version": "0.9.55",
3
+ "version": "0.9.57",
4
4
  "description": "Elyra extension for HTTP requests -- API testing, live docs fetching, and OpenAPI parsing",
5
5
  "type": "module",
6
6
  "keywords": [