@usepipa/pipa 0.5.0 → 0.5.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@usepipa/pipa",
3
- "version": "0.5.0",
3
+ "version": "0.5.2",
4
4
  "description": "Run Pipa through Slack Socket Mode with OpenCode",
5
5
  "keywords": [
6
6
  "slack",
package/src/app.mjs CHANGED
@@ -165,7 +165,10 @@ export async function startPipa(options = {}) {
165
165
 
166
166
  const handle = async (thread, message, subscribe) => {
167
167
  if (!accepting || !isAuthorized(thread, message, config) || shouldIgnore(thread, message)) return;
168
- const prompt = subscribe || message.isMention ? stripMention(message.text) : message.text.trim();
168
+ const messageText = subscribe || message.isMention ? stripMention(message.text) : message.text.trim();
169
+ const missingLinks = (message.links ?? []).map((link) => link.url)
170
+ .filter((url) => typeof url === "string" && !messageText.split(/\s+/u).includes(url));
171
+ const prompt = missingLinks.length ? `${messageText}\n\nFull links:\n${[...new Set(missingLinks)].join("\n")}` : messageText;
169
172
  if (!prompt) return;
170
173
  const attachments = message.attachments ?? [];
171
174
  if (subscribe) await thread.subscribe();
package/src/opencode.mjs CHANGED
@@ -76,8 +76,6 @@ export function createOpenCodeExecutor(options = {}) {
76
76
  const fetchImpl = options.fetch ?? fetch;
77
77
  const environment = options.environment ?? process.env;
78
78
  const headers = authenticationHeaders(environment);
79
- const timeoutMs = options.timeoutMs ?? 2.5 * 60 * 60 * 1000;
80
- const requestTimeoutMs = options.requestTimeoutMs ?? 30_000;
81
79
  const pollIntervalMs = options.pollIntervalMs ?? 1_000;
82
80
  const useDataUrls = !isLoopbackUrl(baseUrl);
83
81
  const remove = options.rm ?? rm;
@@ -97,7 +95,7 @@ export function createOpenCodeExecutor(options = {}) {
97
95
  ...(init.body ? { "content-type": "application/json" } : {}),
98
96
  ...init.headers,
99
97
  },
100
- signal: AbortSignal.any([controller.signal, AbortSignal.timeout(requestTimeoutMs)]),
98
+ signal: controller.signal,
101
99
  });
102
100
  } catch (error) {
103
101
  if (controller.signal.aborted) throw controller.signal.reason;
@@ -130,13 +128,12 @@ export function createOpenCodeExecutor(options = {}) {
130
128
  const abort = () => controller.abort(signal.reason);
131
129
  if (signal?.aborted) abort();
132
130
  else signal?.addEventListener("abort", abort, { once: true });
133
- const timer = setTimeout(() => controller.abort(new Error(`OpenCode timed out after ${timeoutMs}ms.`)), timeoutMs);
134
131
  active.add(controller);
135
132
  let artifactDirectory;
136
133
 
137
134
  try {
138
135
  try {
139
- const files = await stageAttachments(attachments, temporaryDirectory, timeoutMs, useDataUrls, controller.signal);
136
+ const files = await stageAttachments(attachments, temporaryDirectory, useDataUrls, controller.signal);
140
137
  if (stopReason) throw stopReason;
141
138
  let selectedSessionId = sessionId;
142
139
  let messages;
@@ -182,7 +179,6 @@ export function createOpenCodeExecutor(options = {}) {
182
179
  baseUrl,
183
180
  fetchImpl,
184
181
  headers,
185
- requestTimeoutMs,
186
182
  sessionId: selectedSessionId,
187
183
  workingDirectory,
188
184
  controller,
@@ -223,7 +219,6 @@ export function createOpenCodeExecutor(options = {}) {
223
219
  await delay(pollIntervalMs, controller.signal);
224
220
  }
225
221
  } finally {
226
- clearTimeout(timer);
227
222
  controller.abort(new Error("OpenCode turn completed."));
228
223
  active.delete(controller);
229
224
  for (const [sessionId, turn] of activeSessions) {
@@ -342,12 +337,12 @@ export async function runOpenCodeVersion(options = {}) {
342
337
  }
343
338
  }
344
339
 
345
- async function stageAttachments(attachments, temporaryDirectory, timeoutMs, useDataUrls, signal) {
340
+ async function stageAttachments(attachments, temporaryDirectory, useDataUrls, signal) {
346
341
  const files = [];
347
342
  for (const [index, attachment] of attachments.entries()) {
348
343
  let data;
349
344
  try {
350
- data = await fetchAttachment(attachment, timeoutMs, signal);
345
+ data = await abortable(attachment.fetchData(), signal);
351
346
  } catch {
352
347
  throw new Error("Could not read one of the attached files. Please try uploading it again.");
353
348
  }
@@ -592,13 +587,6 @@ function serverUrl(baseUrl, pathname, workingDirectory) {
592
587
  return url;
593
588
  }
594
589
 
595
- function fetchAttachment(attachment, timeoutMs, signal) {
596
- return Promise.race([
597
- attachment.fetchData(),
598
- delay(timeoutMs, signal).then(() => { throw new Error(`Attachment download timed out after ${timeoutMs}ms.`); }),
599
- ]);
600
- }
601
-
602
590
  function delay(delayMs, signal) {
603
591
  return new Promise((resolve, reject) => {
604
592
  if (signal?.aborted) {
@@ -616,7 +604,7 @@ function delay(delayMs, signal) {
616
604
  });
617
605
  }
618
606
 
619
- function watchInteractions({ baseUrl, fetchImpl, headers, requestTimeoutMs, sessionId, workingDirectory, controller, onInteraction, onPermissionReplied, onPermissionsReconciled, onPermissionRejected, onDismiss, requestTurn }) {
607
+ function watchInteractions({ baseUrl, fetchImpl, headers, sessionId, workingDirectory, controller, onInteraction, onPermissionReplied, onPermissionsReconciled, onPermissionRejected, onDismiss, requestTurn }) {
620
608
  const seenIds = new Set();
621
609
  const messages = new Map();
622
610
  const parents = new Map();
@@ -682,18 +670,10 @@ function watchInteractions({ baseUrl, fetchImpl, headers, requestTimeoutMs, sess
682
670
  while (!controller.signal.aborted) {
683
671
  try {
684
672
  const url = serverUrl(baseUrl, "/event", workingDirectory);
685
- const connection = new AbortController();
686
- const connectionTimer = setTimeout(() => connection.abort(new Error("OpenCode event connection timed out.")), requestTimeoutMs);
687
- connectionTimer.unref?.();
688
- let response;
689
- try {
690
- response = await fetchImpl(url, {
691
- headers: { ...headers, accept: "text/event-stream" },
692
- signal: AbortSignal.any([controller.signal, connection.signal]),
693
- });
694
- } finally {
695
- clearTimeout(connectionTimer);
696
- }
673
+ const response = await fetchImpl(url, {
674
+ headers: { ...headers, accept: "text/event-stream" },
675
+ signal: controller.signal,
676
+ });
697
677
  if (!response.ok) throw new OpenCodeRequestError(response.status);
698
678
  await reconcile();
699
679
  if (!subscribed) {
@@ -756,8 +736,13 @@ async function settleInteraction({ type, requestId, sessionId, request: interact
756
736
  } else if (type === "permission" && (decision?.type === "reply" || decision?.type === "reject")) {
757
737
  const reply = decision.type === "reject" ? "reject" : decision.reply;
758
738
  if (!["once", "always", "reject"].includes(reply)) throw new Error("Invalid OpenCode permission decision.");
739
+ try {
740
+ await requestTurn(`/permission/${encodeURIComponent(requestId)}/reply`, { method: "POST", body: JSON.stringify({ reply }) }, workingDirectory, controller, [200, 204], false);
741
+ } catch (error) {
742
+ if (error instanceof OpenCodeRequestError && error.status === 404) return;
743
+ throw error;
744
+ }
759
745
  if (reply === "reject") onPermissionRejected?.();
760
- await requestTurn(`/permission/${encodeURIComponent(requestId)}/reply`, { method: "POST", body: JSON.stringify({ reply }) }, workingDirectory, controller, [200, 204, 404], false);
761
746
  } else {
762
747
  throw new Error(`Invalid OpenCode ${type} decision.`);
763
748
  }