@hasna/oldpal 0.1.6 → 0.1.7

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
@@ -30073,26 +30073,50 @@ var build_default = TextInput;
30073
30073
 
30074
30074
  // packages/terminal/src/components/Input.tsx
30075
30075
  var jsx_dev_runtime = __toESM(require_jsx_dev_runtime(), 1);
30076
- function Input({ onSubmit, disabled }) {
30076
+ function Input({ onSubmit, isProcessing, queueLength = 0 }) {
30077
30077
  const [value, setValue] = import_react23.useState("");
30078
+ use_input_default((input, key) => {
30079
+ if (!value.trim())
30080
+ return;
30081
+ if ((key.shift || key.ctrl) && key.return) {
30082
+ onSubmit(value, "interrupt");
30083
+ setValue("");
30084
+ } else if (key.meta && key.return) {
30085
+ onSubmit(value, "queue");
30086
+ setValue("");
30087
+ }
30088
+ });
30078
30089
  const handleSubmit = (submittedValue) => {
30079
- if (disabled || !submittedValue.trim())
30090
+ if (!submittedValue.trim())
30080
30091
  return;
30081
- onSubmit(submittedValue);
30092
+ if (isProcessing) {
30093
+ onSubmit(submittedValue, "queue");
30094
+ } else {
30095
+ onSubmit(submittedValue, "normal");
30096
+ }
30082
30097
  setValue("");
30083
30098
  };
30099
+ let prompt = "\u276F";
30100
+ let placeholder = "Type a message...";
30101
+ if (isProcessing) {
30102
+ prompt = "\u22EF";
30103
+ placeholder = queueLength > 0 ? "Type to queue another..." : "Type to queue (Enter) or interrupt (Shift+Enter)...";
30104
+ }
30084
30105
  return /* @__PURE__ */ jsx_dev_runtime.jsxDEV(Box_default, {
30085
30106
  marginTop: 1,
30086
30107
  children: [
30087
30108
  /* @__PURE__ */ jsx_dev_runtime.jsxDEV(Text, {
30088
- dimColor: disabled,
30089
- children: "\u276F "
30090
- }, undefined, false, undefined, this),
30109
+ dimColor: isProcessing,
30110
+ children: [
30111
+ prompt,
30112
+ " "
30113
+ ]
30114
+ }, undefined, true, undefined, this),
30091
30115
  /* @__PURE__ */ jsx_dev_runtime.jsxDEV(build_default, {
30092
30116
  value,
30093
30117
  onChange: setValue,
30094
30118
  onSubmit: handleSubmit,
30095
- placeholder: disabled ? "" : "Type a message..."
30119
+ placeholder
30096
30120
  }, undefined, false, undefined, this)
30097
30121
  ]
30098
30122
  }, undefined, true, undefined, this);
@@ -30273,9 +30297,10 @@ function truncate(text, maxLength) {
30273
30297
 
30274
30298
  // packages/terminal/src/components/Status.tsx
30275
30299
  var jsx_dev_runtime4 = __toESM(require_jsx_dev_runtime(), 1);
30276
- function Status({ isProcessing, cwd: cwd2 }) {
30300
+ function Status({ isProcessing, cwd: cwd2, queueLength = 0 }) {
30277
30301
  const maxCwdLength = 50;
30278
30302
  const displayCwd = cwd2.length > maxCwdLength ? "..." + cwd2.slice(-(maxCwdLength - 3)) : cwd2;
30303
+ const queueInfo = queueLength > 0 ? ` | ${queueLength} queued` : "";
30279
30304
  return /* @__PURE__ */ jsx_dev_runtime4.jsxDEV(Box_default, {
30280
30305
  marginTop: 1,
30281
30306
  borderStyle: "single",
@@ -30293,11 +30318,15 @@ function Status({ isProcessing, cwd: cwd2 }) {
30293
30318
  dimColor: !isProcessing,
30294
30319
  children: isProcessing ? "\u25CF processing" : "\u25CF ready"
30295
30320
  }, undefined, false, undefined, this),
30321
+ /* @__PURE__ */ jsx_dev_runtime4.jsxDEV(Text, {
30322
+ dimColor: true,
30323
+ children: queueInfo
30324
+ }, undefined, false, undefined, this),
30296
30325
  /* @__PURE__ */ jsx_dev_runtime4.jsxDEV(Text, {
30297
30326
  dimColor: true,
30298
30327
  children: [
30299
- " | Ctrl+C to ",
30300
- isProcessing ? "stop" : "exit"
30328
+ " | ",
30329
+ isProcessing ? "Esc to stop" : "Ctrl+C to exit"
30301
30330
  ]
30302
30331
  }, undefined, true, undefined, this)
30303
30332
  ]
@@ -30361,11 +30390,34 @@ function App2({ cwd: cwd2 }) {
30361
30390
  const [isProcessing, setIsProcessing] = import_react25.useState(false);
30362
30391
  const [isInitializing, setIsInitializing] = import_react25.useState(true);
30363
30392
  const [error, setError] = import_react25.useState(null);
30393
+ const [messageQueue, setMessageQueue] = import_react25.useState([]);
30364
30394
  const responseRef = import_react25.useRef("");
30395
+ const clientRef = import_react25.useRef(null);
30396
+ const processQueue = import_react25.useCallback(async () => {
30397
+ if (!clientRef.current || messageQueue.length === 0)
30398
+ return;
30399
+ const nextMessage = messageQueue[0];
30400
+ setMessageQueue((prev) => prev.slice(1));
30401
+ const userMessage = {
30402
+ id: generateId(),
30403
+ role: "user",
30404
+ content: nextMessage,
30405
+ timestamp: now()
30406
+ };
30407
+ setMessages((prev) => [...prev, userMessage]);
30408
+ setCurrentResponse("");
30409
+ responseRef.current = "";
30410
+ setError(null);
30411
+ setCurrentToolCall(undefined);
30412
+ setLastToolResult(undefined);
30413
+ setIsProcessing(true);
30414
+ await clientRef.current.send(nextMessage);
30415
+ }, [messageQueue]);
30365
30416
  import_react25.useEffect(() => {
30366
30417
  const initClient = async () => {
30367
30418
  try {
30368
30419
  const newClient = new EmbeddedClient(cwd2);
30420
+ clientRef.current = newClient;
30369
30421
  newClient.onChunk((chunk) => {
30370
30422
  if (chunk.type === "text" && chunk.content) {
30371
30423
  responseRef.current += chunk.content;
@@ -30412,20 +30464,83 @@ function App2({ cwd: cwd2 }) {
30412
30464
  };
30413
30465
  initClient();
30414
30466
  }, [cwd2]);
30467
+ import_react25.useEffect(() => {
30468
+ if (!isProcessing && messageQueue.length > 0) {
30469
+ processQueue();
30470
+ }
30471
+ }, [isProcessing, messageQueue.length, processQueue]);
30415
30472
  use_input_default((input, key) => {
30416
30473
  if (key.ctrl && input === "c") {
30417
30474
  if (isProcessing && client) {
30418
30475
  client.stop();
30476
+ if (responseRef.current) {
30477
+ setMessages((prev) => [
30478
+ ...prev,
30479
+ {
30480
+ id: generateId(),
30481
+ role: "assistant",
30482
+ content: responseRef.current + `
30483
+
30484
+ [stopped]`,
30485
+ timestamp: now()
30486
+ }
30487
+ ]);
30488
+ setCurrentResponse("");
30489
+ responseRef.current = "";
30490
+ }
30419
30491
  setIsProcessing(false);
30420
30492
  } else {
30421
30493
  exit();
30422
30494
  }
30423
30495
  }
30496
+ if (key.escape && isProcessing && client) {
30497
+ client.stop();
30498
+ if (responseRef.current) {
30499
+ setMessages((prev) => [
30500
+ ...prev,
30501
+ {
30502
+ id: generateId(),
30503
+ role: "assistant",
30504
+ content: responseRef.current + `
30505
+
30506
+ [stopped]`,
30507
+ timestamp: now()
30508
+ }
30509
+ ]);
30510
+ setCurrentResponse("");
30511
+ responseRef.current = "";
30512
+ }
30513
+ setIsProcessing(false);
30514
+ }
30424
30515
  });
30425
- const handleSubmit = import_react25.useCallback(async (input) => {
30426
- if (!client || !input.trim() || isProcessing)
30516
+ const handleSubmit = import_react25.useCallback(async (input, mode = "normal") => {
30517
+ if (!client || !input.trim())
30427
30518
  return;
30428
30519
  const trimmedInput = input.trim();
30520
+ if (mode === "queue" || isProcessing && mode === "normal") {
30521
+ setMessageQueue((prev) => [...prev, trimmedInput]);
30522
+ return;
30523
+ }
30524
+ if (mode === "interrupt" && isProcessing) {
30525
+ client.stop();
30526
+ if (responseRef.current) {
30527
+ setMessages((prev) => [
30528
+ ...prev,
30529
+ {
30530
+ id: generateId(),
30531
+ role: "assistant",
30532
+ content: responseRef.current + `
30533
+
30534
+ [interrupted]`,
30535
+ timestamp: now()
30536
+ }
30537
+ ]);
30538
+ }
30539
+ setCurrentResponse("");
30540
+ responseRef.current = "";
30541
+ setIsProcessing(false);
30542
+ await new Promise((r) => setTimeout(r, 100));
30543
+ }
30429
30544
  const userMessage = {
30430
30545
  id: generateId(),
30431
30546
  role: "user",
@@ -30460,6 +30575,18 @@ function App2({ cwd: cwd2 }) {
30460
30575
  currentToolCall,
30461
30576
  lastToolResult
30462
30577
  }, undefined, false, undefined, this),
30578
+ messageQueue.length > 0 && /* @__PURE__ */ jsx_dev_runtime6.jsxDEV(Box_default, {
30579
+ marginY: 1,
30580
+ children: /* @__PURE__ */ jsx_dev_runtime6.jsxDEV(Text, {
30581
+ dimColor: true,
30582
+ children: [
30583
+ messageQueue.length,
30584
+ " message",
30585
+ messageQueue.length > 1 ? "s" : "",
30586
+ " queued"
30587
+ ]
30588
+ }, undefined, true, undefined, this)
30589
+ }, undefined, false, undefined, this),
30463
30590
  error && /* @__PURE__ */ jsx_dev_runtime6.jsxDEV(Box_default, {
30464
30591
  marginY: 1,
30465
30592
  children: /* @__PURE__ */ jsx_dev_runtime6.jsxDEV(Text, {
@@ -30478,11 +30605,13 @@ function App2({ cwd: cwd2 }) {
30478
30605
  }, undefined, false, undefined, this),
30479
30606
  /* @__PURE__ */ jsx_dev_runtime6.jsxDEV(Input, {
30480
30607
  onSubmit: handleSubmit,
30481
- disabled: isProcessing
30608
+ isProcessing,
30609
+ queueLength: messageQueue.length
30482
30610
  }, undefined, false, undefined, this),
30483
30611
  /* @__PURE__ */ jsx_dev_runtime6.jsxDEV(Status, {
30484
30612
  isProcessing,
30485
- cwd: cwd2
30613
+ cwd: cwd2,
30614
+ queueLength: messageQueue.length
30486
30615
  }, undefined, false, undefined, this)
30487
30616
  ]
30488
30617
  }, undefined, true, undefined, this);
@@ -30497,7 +30626,7 @@ var options = {
30497
30626
  help: args.includes("--help") || args.includes("-h")
30498
30627
  };
30499
30628
  if (options.version) {
30500
- console.log("oldpal v0.1.6");
30629
+ console.log("oldpal v0.1.7");
30501
30630
  process.exit(0);
30502
30631
  }
30503
30632
  if (options.help) {
@@ -30528,4 +30657,4 @@ waitUntilExit().then(() => {
30528
30657
  process.exit(0);
30529
30658
  });
30530
30659
 
30531
- //# debugId=F294B9F3A80B4E7C64756E2164756E21
30660
+ //# debugId=F204A4187B2BDE8664756E2164756E21