@hasna/oldpal 0.1.9 → 0.2.0

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/dist/index.js CHANGED
@@ -29368,10 +29368,101 @@ function parseDuckDuckGoResults(html, maxResults) {
29368
29368
  return results;
29369
29369
  }
29370
29370
 
29371
+ class CurlTool {
29372
+ static tool = {
29373
+ name: "curl",
29374
+ description: "Fetch content from a URL (like curl). Returns text content from web pages, JSON from APIs, etc.",
29375
+ parameters: {
29376
+ type: "object",
29377
+ properties: {
29378
+ url: {
29379
+ type: "string",
29380
+ description: "The URL to fetch"
29381
+ },
29382
+ method: {
29383
+ type: "string",
29384
+ description: "HTTP method (GET, POST, PUT, DELETE). Defaults to GET.",
29385
+ enum: ["GET", "POST", "PUT", "DELETE"],
29386
+ default: "GET"
29387
+ },
29388
+ headers: {
29389
+ type: "object",
29390
+ description: "Optional headers to send with the request"
29391
+ },
29392
+ body: {
29393
+ type: "string",
29394
+ description: "Request body for POST/PUT requests"
29395
+ }
29396
+ },
29397
+ required: ["url"]
29398
+ }
29399
+ };
29400
+ static executor = async (input) => {
29401
+ const url = input.url;
29402
+ const method = input.method || "GET";
29403
+ const headers = input.headers || {};
29404
+ const body = input.body;
29405
+ const timeout = 30000;
29406
+ try {
29407
+ const parsedUrl = new URL(url);
29408
+ const hostname = parsedUrl.hostname;
29409
+ if (hostname === "localhost" || hostname === "127.0.0.1" || hostname.startsWith("192.168.") || hostname.startsWith("10.") || hostname.startsWith("172.")) {
29410
+ return "Error: Cannot fetch from local/private network addresses for security reasons";
29411
+ }
29412
+ const controller = new AbortController;
29413
+ const timeoutId = setTimeout(() => controller.abort(), timeout);
29414
+ const response = await fetch(url, {
29415
+ method,
29416
+ signal: controller.signal,
29417
+ headers: {
29418
+ "User-Agent": "oldpal/1.0 (AI Assistant)",
29419
+ ...headers
29420
+ },
29421
+ body: body && ["POST", "PUT"].includes(method) ? body : undefined
29422
+ });
29423
+ clearTimeout(timeoutId);
29424
+ const contentType = response.headers.get("content-type") || "";
29425
+ let responseBody;
29426
+ if (contentType.includes("application/json")) {
29427
+ try {
29428
+ const json = await response.json();
29429
+ responseBody = JSON.stringify(json, null, 2);
29430
+ } catch {
29431
+ responseBody = await response.text();
29432
+ }
29433
+ } else {
29434
+ responseBody = await response.text();
29435
+ if (contentType.includes("text/html")) {
29436
+ responseBody = extractReadableText(responseBody);
29437
+ }
29438
+ }
29439
+ const maxLength = 30000;
29440
+ if (responseBody.length > maxLength) {
29441
+ responseBody = responseBody.slice(0, maxLength) + `
29442
+
29443
+ [Content truncated...]`;
29444
+ }
29445
+ const statusLine = `HTTP ${response.status} ${response.statusText}`;
29446
+ return `${statusLine}
29447
+
29448
+ ${responseBody || "(empty response)"}`;
29449
+ } catch (error) {
29450
+ if (error instanceof Error) {
29451
+ if (error.name === "AbortError") {
29452
+ return `Error: Request timed out after ${timeout}ms`;
29453
+ }
29454
+ return `Error: ${error.message}`;
29455
+ }
29456
+ return `Error: ${String(error)}`;
29457
+ }
29458
+ };
29459
+ }
29460
+
29371
29461
  class WebTools {
29372
29462
  static registerAll(registry) {
29373
29463
  registry.register(WebFetchTool.tool, WebFetchTool.executor);
29374
29464
  registry.register(WebSearchTool.tool, WebSearchTool.executor);
29465
+ registry.register(CurlTool.tool, CurlTool.executor);
29375
29466
  }
29376
29467
  }
29377
29468
 
@@ -31028,7 +31119,7 @@ function parseMarkdown(text) {
31028
31119
  // packages/terminal/src/components/Messages.tsx
31029
31120
  var jsx_dev_runtime3 = __toESM(require_jsx_dev_runtime(), 1);
31030
31121
  function Messages4({ messages, currentResponse, currentToolCall, lastToolResult, activityLog = [] }) {
31031
- const visibleMessages = messages.slice(-15);
31122
+ const visibleMessages = messages.slice(-10);
31032
31123
  return /* @__PURE__ */ jsx_dev_runtime3.jsxDEV(Box_default, {
31033
31124
  flexDirection: "column",
31034
31125
  children: [
@@ -31036,59 +31127,49 @@ function Messages4({ messages, currentResponse, currentToolCall, lastToolResult,
31036
31127
  message
31037
31128
  }, message.id, false, undefined, this)),
31038
31129
  activityLog.map((entry) => {
31039
- if (entry.type === "tool_call" && entry.toolCall) {
31130
+ if (entry.type === "text" && entry.content) {
31040
31131
  return /* @__PURE__ */ jsx_dev_runtime3.jsxDEV(Box_default, {
31041
31132
  marginY: 1,
31042
31133
  children: [
31043
31134
  /* @__PURE__ */ jsx_dev_runtime3.jsxDEV(Text, {
31044
31135
  dimColor: true,
31045
- children: "\u25D0 "
31136
+ children: "\u25CF "
31046
31137
  }, undefined, false, undefined, this),
31047
- /* @__PURE__ */ jsx_dev_runtime3.jsxDEV(Text, {
31048
- dimColor: true,
31049
- children: formatToolCall(entry.toolCall)
31138
+ /* @__PURE__ */ jsx_dev_runtime3.jsxDEV(Box_default, {
31139
+ flexGrow: 1,
31140
+ children: /* @__PURE__ */ jsx_dev_runtime3.jsxDEV(Markdown, {
31141
+ content: entry.content
31142
+ }, undefined, false, undefined, this)
31050
31143
  }, undefined, false, undefined, this)
31051
31144
  ]
31052
31145
  }, entry.id, true, undefined, this);
31053
31146
  }
31147
+ if (entry.type === "tool_call" && entry.toolCall) {
31148
+ return /* @__PURE__ */ jsx_dev_runtime3.jsxDEV(Box_default, {
31149
+ marginTop: 1,
31150
+ children: /* @__PURE__ */ jsx_dev_runtime3.jsxDEV(Text, {
31151
+ dimColor: true,
31152
+ children: [
31153
+ " \u25D0 ",
31154
+ formatToolCall(entry.toolCall)
31155
+ ]
31156
+ }, undefined, true, undefined, this)
31157
+ }, entry.id, false, undefined, this);
31158
+ }
31054
31159
  if (entry.type === "tool_result" && entry.toolResult) {
31055
31160
  return /* @__PURE__ */ jsx_dev_runtime3.jsxDEV(Box_default, {
31056
- marginLeft: 2,
31161
+ marginBottom: 1,
31057
31162
  children: /* @__PURE__ */ jsx_dev_runtime3.jsxDEV(Text, {
31058
31163
  dimColor: true,
31059
31164
  children: [
31060
- "\u2192 ",
31061
- truncate(entry.toolResult.content, 100)
31165
+ " \u2192 ",
31166
+ truncate(entry.toolResult.content, 80)
31062
31167
  ]
31063
31168
  }, undefined, true, undefined, this)
31064
31169
  }, entry.id, false, undefined, this);
31065
31170
  }
31066
31171
  return null;
31067
31172
  }),
31068
- currentToolCall && !activityLog.some((e) => e.toolCall?.id === currentToolCall.id) && /* @__PURE__ */ jsx_dev_runtime3.jsxDEV(Box_default, {
31069
- marginY: 1,
31070
- children: [
31071
- /* @__PURE__ */ jsx_dev_runtime3.jsxDEV(Text, {
31072
- dimColor: true,
31073
- children: "\u25D0 "
31074
- }, undefined, false, undefined, this),
31075
- /* @__PURE__ */ jsx_dev_runtime3.jsxDEV(Text, {
31076
- dimColor: true,
31077
- children: formatToolCall(currentToolCall)
31078
- }, undefined, false, undefined, this)
31079
- ]
31080
- }, undefined, true, undefined, this),
31081
- lastToolResult && !activityLog.some((e) => e.toolResult?.toolCallId === lastToolResult.toolCallId) && /* @__PURE__ */ jsx_dev_runtime3.jsxDEV(Box_default, {
31082
- marginY: 1,
31083
- marginLeft: 2,
31084
- children: /* @__PURE__ */ jsx_dev_runtime3.jsxDEV(Text, {
31085
- dimColor: true,
31086
- children: [
31087
- "\u2192 ",
31088
- truncate(lastToolResult.content, 100)
31089
- ]
31090
- }, undefined, true, undefined, this)
31091
- }, undefined, false, undefined, this),
31092
31173
  currentResponse && /* @__PURE__ */ jsx_dev_runtime3.jsxDEV(Box_default, {
31093
31174
  marginY: 1,
31094
31175
  children: [
@@ -31103,7 +31184,17 @@ function Messages4({ messages, currentResponse, currentToolCall, lastToolResult,
31103
31184
  }, undefined, false, undefined, this)
31104
31185
  }, undefined, false, undefined, this)
31105
31186
  ]
31106
- }, undefined, true, undefined, this)
31187
+ }, undefined, true, undefined, this),
31188
+ currentToolCall && /* @__PURE__ */ jsx_dev_runtime3.jsxDEV(Box_default, {
31189
+ marginTop: 1,
31190
+ children: /* @__PURE__ */ jsx_dev_runtime3.jsxDEV(Text, {
31191
+ dimColor: true,
31192
+ children: [
31193
+ " \u25D0 ",
31194
+ formatToolCall(currentToolCall)
31195
+ ]
31196
+ }, undefined, true, undefined, this)
31197
+ }, undefined, false, undefined, this)
31107
31198
  ]
31108
31199
  }, undefined, true, undefined, this);
31109
31200
  }
@@ -31164,6 +31255,12 @@ function formatToolCall(toolCall) {
31164
31255
  switch (name) {
31165
31256
  case "bash":
31166
31257
  return `Running: ${truncate(String(input.command || ""), 60)}`;
31258
+ case "curl":
31259
+ return `Fetching: ${truncate(String(input.url || ""), 60)}`;
31260
+ case "web_fetch":
31261
+ return `Fetching: ${truncate(String(input.url || ""), 60)}`;
31262
+ case "web_search":
31263
+ return `Searching: ${truncate(String(input.query || ""), 60)}`;
31167
31264
  case "read":
31168
31265
  return `Reading: ${truncate(String(input.path || input.file_path || ""), 60)}`;
31169
31266
  case "write":
@@ -31341,6 +31438,19 @@ function App2({ cwd: cwd2 }) {
31341
31438
  responseRef.current += chunk.content;
31342
31439
  setCurrentResponse(responseRef.current);
31343
31440
  } else if (chunk.type === "tool_use" && chunk.toolCall) {
31441
+ if (responseRef.current.trim()) {
31442
+ setActivityLog((prev) => [
31443
+ ...prev,
31444
+ {
31445
+ id: generateId(),
31446
+ type: "text",
31447
+ content: responseRef.current,
31448
+ timestamp: now()
31449
+ }
31450
+ ]);
31451
+ setCurrentResponse("");
31452
+ responseRef.current = "";
31453
+ }
31344
31454
  toolCallsRef.current.push(chunk.toolCall);
31345
31455
  setActivityLog((prev) => [
31346
31456
  ...prev,
@@ -31352,7 +31462,6 @@ function App2({ cwd: cwd2 }) {
31352
31462
  }
31353
31463
  ]);
31354
31464
  setCurrentToolCall(chunk.toolCall);
31355
- setLastToolResult(undefined);
31356
31465
  } else if (chunk.type === "tool_result" && chunk.toolResult) {
31357
31466
  toolResultsRef.current.push(chunk.toolResult);
31358
31467
  setActivityLog((prev) => [
@@ -31364,7 +31473,6 @@ function App2({ cwd: cwd2 }) {
31364
31473
  timestamp: now()
31365
31474
  }
31366
31475
  ]);
31367
- setLastToolResult(chunk.toolResult);
31368
31476
  setCurrentToolCall(undefined);
31369
31477
  } else if (chunk.type === "error" && chunk.error) {
31370
31478
  setError(chunk.error);
@@ -31372,25 +31480,39 @@ function App2({ cwd: cwd2 }) {
31372
31480
  } else if (chunk.type === "usage" && chunk.usage) {
31373
31481
  setTokenUsage(chunk.usage);
31374
31482
  } else if (chunk.type === "done") {
31375
- if (responseRef.current || toolCallsRef.current.length > 0) {
31483
+ if (responseRef.current.trim()) {
31484
+ setActivityLog((prev) => [
31485
+ ...prev,
31486
+ {
31487
+ id: generateId(),
31488
+ type: "text",
31489
+ content: responseRef.current,
31490
+ timestamp: now()
31491
+ }
31492
+ ]);
31493
+ }
31494
+ const fullContent = activityLog.filter((e) => e.type === "text").map((e) => e.content).join(`
31495
+ `) + (responseRef.current ? `
31496
+ ` + responseRef.current : "");
31497
+ if (fullContent.trim() || toolCallsRef.current.length > 0) {
31376
31498
  setMessages((prev) => [
31377
31499
  ...prev,
31378
31500
  {
31379
31501
  id: generateId(),
31380
31502
  role: "assistant",
31381
- content: responseRef.current,
31503
+ content: fullContent.trim(),
31382
31504
  timestamp: now(),
31383
31505
  toolCalls: toolCallsRef.current.length > 0 ? [...toolCallsRef.current] : undefined,
31384
31506
  toolResults: toolResultsRef.current.length > 0 ? [...toolResultsRef.current] : undefined
31385
31507
  }
31386
31508
  ]);
31387
- setCurrentResponse("");
31388
- responseRef.current = "";
31389
- toolCallsRef.current = [];
31390
- toolResultsRef.current = [];
31391
31509
  }
31510
+ setCurrentResponse("");
31511
+ responseRef.current = "";
31512
+ toolCallsRef.current = [];
31513
+ toolResultsRef.current = [];
31392
31514
  setCurrentToolCall(undefined);
31393
- setLastToolResult(undefined);
31515
+ setActivityLog([]);
31394
31516
  setIsProcessing(false);
31395
31517
  if (newClient) {
31396
31518
  setTokenUsage(newClient.getTokenUsage());
@@ -31578,7 +31700,7 @@ var options = {
31578
31700
  help: args.includes("--help") || args.includes("-h")
31579
31701
  };
31580
31702
  if (options.version) {
31581
- console.log("oldpal v0.1.9");
31703
+ console.log("oldpal v0.2.0");
31582
31704
  process.exit(0);
31583
31705
  }
31584
31706
  if (options.help) {
@@ -31609,4 +31731,4 @@ waitUntilExit().then(() => {
31609
31731
  process.exit(0);
31610
31732
  });
31611
31733
 
31612
- //# debugId=307434E7D5151E5864756E2164756E21
31734
+ //# debugId=21C263FACC119E6E64756E2164756E21