@akshar5/cohall 0.12.12 → 0.12.14

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 (41) hide show
  1. package/CHANGELOG.md +28 -0
  2. package/README.md +15 -5
  3. package/bin/{chunk-1ekexd73.js → chunk-318jbf1v.js} +17 -13
  4. package/bin/chunk-318jbf1v.js.map +10 -0
  5. package/bin/{chunk-94dpwj2b.js → chunk-6r5hdtcx.js} +4 -4
  6. package/bin/{chunk-vm7gzczr.js → chunk-7vn72ejw.js} +3 -3
  7. package/bin/{chunk-zkhqkh0y.js → chunk-89z9anfx.js} +32 -15
  8. package/bin/chunk-89z9anfx.js.map +11 -0
  9. package/bin/{chunk-04a27ybz.js → chunk-aj2btss5.js} +2 -5
  10. package/bin/{chunk-04a27ybz.js.map → chunk-aj2btss5.js.map} +3 -3
  11. package/bin/{chunk-f8qjez08.js → chunk-dy48ndmb.js} +32 -15
  12. package/bin/chunk-dy48ndmb.js.map +15 -0
  13. package/bin/{chunk-qbcgvhf1.js → chunk-hg08s7y1.js} +2 -2
  14. package/bin/{chunk-qbcgvhf1.js.map → chunk-hg08s7y1.js.map} +1 -1
  15. package/bin/{chunk-bpnafwbg.js → chunk-kc5awrf4.js} +65 -14
  16. package/bin/chunk-kc5awrf4.js.map +13 -0
  17. package/bin/{chunk-g6b3zmtw.js → chunk-m82xx6vz.js} +1 -1
  18. package/bin/{chunk-1m1566kp.js → chunk-t16mw8kv.js} +3 -3
  19. package/bin/{chunk-4trfnawd.js → chunk-tc7gfcwe.js} +7 -7
  20. package/bin/chunk-tc7gfcwe.js.map +10 -0
  21. package/bin/{chunk-c78dff66.js → chunk-vphkssrc.js} +69 -21
  22. package/bin/chunk-vphkssrc.js.map +14 -0
  23. package/bin/{chunk-baep7sfx.js → chunk-wexfaech.js} +2 -2
  24. package/bin/cohall.js +13 -10
  25. package/bin/cohall.js.map +3 -3
  26. package/docs/install.md +3 -1
  27. package/docs/integrations.md +22 -4
  28. package/docs/onboarding.md +8 -3
  29. package/docs/services.md +3 -0
  30. package/package.json +1 -1
  31. package/bin/chunk-1ekexd73.js.map +0 -10
  32. package/bin/chunk-4trfnawd.js.map +0 -10
  33. package/bin/chunk-bpnafwbg.js.map +0 -13
  34. package/bin/chunk-c78dff66.js.map +0 -14
  35. package/bin/chunk-f8qjez08.js.map +0 -15
  36. package/bin/chunk-zkhqkh0y.js.map +0 -11
  37. /package/bin/{chunk-94dpwj2b.js.map → chunk-6r5hdtcx.js.map} +0 -0
  38. /package/bin/{chunk-vm7gzczr.js.map → chunk-7vn72ejw.js.map} +0 -0
  39. /package/bin/{chunk-g6b3zmtw.js.map → chunk-m82xx6vz.js.map} +0 -0
  40. /package/bin/{chunk-1m1566kp.js.map → chunk-t16mw8kv.js.map} +0 -0
  41. /package/bin/{chunk-baep7sfx.js.map → chunk-wexfaech.js.map} +0 -0
@@ -61,11 +61,11 @@ import {
61
61
  taskDeadlineError,
62
62
  taskDeadlinePassed,
63
63
  taskSlot
64
- } from "./chunk-04a27ybz.js";
64
+ } from "./chunk-aj2btss5.js";
65
65
  import {
66
66
  __export,
67
67
  version
68
- } from "./chunk-qbcgvhf1.js";
68
+ } from "./chunk-hg08s7y1.js";
69
69
 
70
70
  // apps/relay/src/main.ts
71
71
  import { Effect as Effect3, ManagedRuntime, Schema as Schema3, Schedule } from "effect";
@@ -1589,6 +1589,18 @@ var makeService = (db, retainedTerminalTasks = 1000) => {
1589
1589
  status: "cancelling"
1590
1590
  }, { kind: "cancelling", detail: "Client requested task cancellation" });
1591
1591
  });
1592
+ const cancelDescendants = Effect2.fn("RelayStore.cancelDescendants")(function* (taskId) {
1593
+ const rows = yield* Effect2.try({
1594
+ try: () => db.query(`WITH RECURSIVE descendants(id) AS (
1595
+ SELECT id FROM tasks WHERE parent_task_id = ?
1596
+ UNION SELECT tasks.id FROM tasks JOIN descendants ON tasks.parent_task_id = descendants.id
1597
+ )
1598
+ SELECT tasks.* FROM tasks JOIN descendants USING (id)
1599
+ WHERE tasks.status IN ('queued', 'assigned', 'running', 'needs_input')`).all(taskId),
1600
+ catch: operationError("RelayStore.cancelDescendants")
1601
+ });
1602
+ return yield* Effect2.forEach(rows, (row) => taskFromRow(db, row).pipe(Effect2.flatMap((task) => requestCancellation(task.id).pipe(Effect2.catchIf((cause) => task.provider === "grok-bot" && cause.message.startsWith("Stop this bot in Grok Bot"), () => Effect2.succeed(task))))));
1603
+ });
1592
1604
  const requeueTasksFor = Effect2.fn("RelayStore.requeueTasksFor")(function* (deviceId) {
1593
1605
  const timestamp = now();
1594
1606
  yield* Effect2.try({
@@ -1614,14 +1626,19 @@ var makeService = (db, retainedTerminalTasks = 1000) => {
1614
1626
  });
1615
1627
  return row?.session_id;
1616
1628
  });
1617
- const threadDevice = Effect2.fn("RelayStore.threadDevice")(function* (threadId) {
1618
- const row = yield* Effect2.try({
1619
- try: () => db.query(`SELECT target_device_id FROM tasks
1629
+ const threadTurn = Effect2.fn("RelayStore.threadTurn")(function* (threadId) {
1630
+ return yield* Effect2.try({
1631
+ try: () => {
1632
+ const row = db.query(`SELECT target_device_id, provider FROM tasks
1620
1633
  WHERE thread_id = ? AND parent_task_id IS NULL AND provider <> 'grok-bot'
1621
- ORDER BY created_at DESC, rowid DESC LIMIT 1`).get(threadId),
1622
- catch: operationError("RelayStore.threadDevice")
1634
+ ORDER BY created_at DESC, rowid DESC LIMIT 1`).get(threadId);
1635
+ return row === null ? undefined : {
1636
+ deviceId: row.target_device_id,
1637
+ provider: Schema2.decodeUnknownSync(Provider)(row.provider)
1638
+ };
1639
+ },
1640
+ catch: operationError("RelayStore.threadTurn")
1623
1641
  });
1624
- return row?.target_device_id;
1625
1642
  });
1626
1643
  const createPairing = Effect2.fn("RelayStore.createPairing")(function* (input) {
1627
1644
  const roles = [...new Set(input.roles)];
@@ -1773,6 +1790,7 @@ var makeService = (db, retainedTerminalTasks = 1000) => {
1773
1790
  failTask: (taskId, deviceId, error, runId) => terminal(taskId, deviceId, "failed", undefined, error, undefined, undefined, runId),
1774
1791
  acknowledgeCancellation: (taskId, deviceId, runId) => terminal(taskId, deviceId, "cancelled", undefined, undefined, undefined, undefined, runId),
1775
1792
  requestCancellation,
1793
+ cancelDescendants,
1776
1794
  requeueTasksFor,
1777
1795
  createUpgradeOperations,
1778
1796
  listOperations,
@@ -1785,7 +1803,7 @@ var makeService = (db, retainedTerminalTasks = 1000) => {
1785
1803
  failOperation,
1786
1804
  requeueOperationsFor,
1787
1805
  sessionFor,
1788
- threadDevice,
1806
+ threadTurn,
1789
1807
  createPairing,
1790
1808
  exchangePairing,
1791
1809
  authenticateSession,
@@ -2056,7 +2074,7 @@ var body = (request, decode2) => Effect3.tryPromise({
2056
2074
  catch: () => new RequestError({ status: 400, message: "Expected a JSON request body" })
2057
2075
  }).pipe(Effect3.flatMap(decode2), Effect3.mapError((cause) => cause instanceof RequestError ? cause : new RequestError({ status: 400, message: String(cause).slice(0, 2048) })));
2058
2076
  var pathId = (schema, value) => Schema3.decodeUnknownEffect(schema)(value).pipe(Effect3.mapError(() => new RequestError({ status: 400, message: `Invalid identifier: ${value}` })));
2059
- var scoreDevice = (device, input, sourceDeviceId, threadDeviceId) => {
2077
+ var scoreDevice = (device, input, sourceDeviceId, threadDeviceId, occupied) => {
2060
2078
  const prompt = `${input.prompt} ${input.context ?? ""}`.toLowerCase();
2061
2079
  const needsXcode = /\b(xcode|ios|macos|swiftui|app store)\b/.test(prompt);
2062
2080
  const needsBrowser = /\b(browser|chrome|youtube|twitter|logged[- ]?in|signed[- ]?in|x\.com)\b/.test(prompt);
@@ -2066,7 +2084,7 @@ var scoreDevice = (device, input, sourceDeviceId, threadDeviceId) => {
2066
2084
  const child = paths.relative(path, workspace);
2067
2085
  return child !== ".." && !child.startsWith(`..${paths.sep}`) && !paths.isAbsolute(child);
2068
2086
  });
2069
- return (device.status === "offline" ? 0 : 100) + (matchesWorkspace ? 80 : 0) + (needsXcode && device.capabilities.some((capability) => capability.id === "xcode") ? 60 : 0) + (needsBrowser && device.capabilities.some((capability) => capability.id === "browser-session") ? 40 : 0) + (threadDeviceId === device.id ? 70 : 0) + (sourceDeviceId === device.id ? -5 : 0);
2087
+ return (device.status === "offline" ? 0 : device.status === "busy" || occupied.has(device.id) ? 90 : 100) + (matchesWorkspace ? 80 : 0) + (needsXcode && device.capabilities.some((capability) => capability.id === "xcode") ? 60 : 0) + (needsBrowser && device.capabilities.some((capability) => capability.id === "browser-session") ? 40 : 0) + (threadDeviceId === device.id ? 70 : 0) + (sourceDeviceId === device.id ? -5 : 0);
2070
2088
  };
2071
2089
  var resolveDelegation = (input, sourceDeviceId) => Effect3.gen(function* () {
2072
2090
  const store = yield* exports_store.Service;
@@ -2094,14 +2112,32 @@ var resolveDelegation = (input, sourceDeviceId) => Effect3.gen(function* () {
2094
2112
  message: "A child task must use its parent's thread"
2095
2113
  });
2096
2114
  }
2097
- const resolvedInput = parent === undefined ? input : { ...input, threadId: parent.threadId };
2115
+ if (parent?.status === "cancelling" || parent?.status === "cancelled")
2116
+ return yield* new RequestError({
2117
+ status: 409,
2118
+ message: "The parent task has been cancelled"
2119
+ });
2098
2120
  const devices = yield* store.listDevices().pipe(Effect3.mapError((cause) => new RequestError({ status: 500, message: cause.message })));
2099
- const provider = input.provider ?? (input.botId === undefined ? "codex" : "grok-bot");
2121
+ const threadTurn = parent === undefined && input.threadId !== undefined && input.botId === undefined ? yield* store.threadTurn(input.threadId).pipe(Effect3.mapError((cause) => new RequestError({ status: 500, message: cause.message }))) : undefined;
2122
+ const provider = input.provider ?? (input.botId === undefined ? threadTurn?.provider ?? "codex" : "grok-bot");
2100
2123
  if (input.expiresAt !== undefined && provider === "grok-bot")
2101
2124
  return yield* new RequestError({
2102
2125
  status: 400,
2103
2126
  message: "Task deadlines require a coding provider"
2104
2127
  });
2128
+ const expiresAt = parent?.expiresAt === undefined || provider === "grok-bot" || input.expiresAt !== undefined && Date.parse(input.expiresAt) <= Date.parse(parent.expiresAt) ? input.expiresAt : parent.expiresAt;
2129
+ const inheritsDeadline = expiresAt !== undefined && expiresAt !== input.expiresAt;
2130
+ if (inheritsDeadline && Date.parse(expiresAt) <= Date.now())
2131
+ return yield* new RequestError({
2132
+ status: 409,
2133
+ message: "The parent task's deadline has passed"
2134
+ });
2135
+ const deadlineSource = inheritsDeadline ? " inherited from the parent task" : "";
2136
+ const resolvedInput = parent === undefined ? { ...input, provider } : {
2137
+ ...input,
2138
+ threadId: parent.threadId,
2139
+ ...expiresAt === undefined ? {} : { expiresAt }
2140
+ };
2105
2141
  const hasAttachments = (input.attachments?.length ?? 0) > 0;
2106
2142
  if (hasAttachments && provider === "grok-bot") {
2107
2143
  return yield* new RequestError({
@@ -2128,10 +2164,10 @@ var resolveDelegation = (input, sourceDeviceId) => Effect3.gen(function* () {
2128
2164
  message: `${target.name} does not advertise the ${provider} provider`
2129
2165
  });
2130
2166
  }
2131
- if (input.expiresAt !== undefined && !target.capabilities.some((capability) => capability.id === "task-deadlines"))
2167
+ if (expiresAt !== undefined && !target.capabilities.some((capability) => capability.id === "task-deadlines"))
2132
2168
  return yield* new RequestError({
2133
2169
  status: 409,
2134
- message: `${target.name} does not support task deadlines; upgrade its Cohall worker`
2170
+ message: `${target.name} does not support task deadlines${deadlineSource}; upgrade its Cohall worker`
2135
2171
  });
2136
2172
  if (hasAttachments && !target.capabilities.some((capability) => capability.id === "task-attachments")) {
2137
2173
  return yield* new RequestError({
@@ -2153,7 +2189,7 @@ var resolveDelegation = (input, sourceDeviceId) => Effect3.gen(function* () {
2153
2189
  }
2154
2190
  return { input: resolvedInput, targetDeviceId: target.id };
2155
2191
  }
2156
- const providerDevices = devices.filter((device) => device.providers.includes(provider) && (input.expiresAt === undefined || device.capabilities.some((capability) => capability.id === "task-deadlines")) && (input.botId === undefined || device.bots?.some((bot) => bot.id === input.botId)));
2192
+ const providerDevices = devices.filter((device) => device.providers.includes(provider) && (expiresAt === undefined || device.capabilities.some((capability) => capability.id === "task-deadlines")) && (input.botId === undefined || device.bots?.some((bot) => bot.id === input.botId)));
2157
2193
  const candidates = hasAttachments ? providerDevices.filter((device) => device.capabilities.some((capability) => capability.id === "task-attachments")) : providerDevices;
2158
2194
  if (input.botId !== undefined && candidates.length > 1) {
2159
2195
  return yield* new RequestError({
@@ -2161,12 +2197,20 @@ var resolveDelegation = (input, sourceDeviceId) => Effect3.gen(function* () {
2161
2197
  message: `Bot ${input.botId} is advertised by more than one device; select a device`
2162
2198
  });
2163
2199
  }
2164
- const threadDeviceId = parent === undefined && input.threadId !== undefined && provider !== "grok-bot" ? yield* store.threadDevice(input.threadId).pipe(Effect3.mapError((cause) => new RequestError({ status: 500, message: cause.message }))) : undefined;
2165
- const selected = candidates.filter((device) => !blocked.has(device.id)).sort((left, right) => scoreDevice(right, input, sourceDeviceId, threadDeviceId) - scoreDevice(left, input, sourceDeviceId, threadDeviceId))[0];
2200
+ const threadDeviceId = threadTurn?.deviceId;
2201
+ const occupied = new Set((yield* store.deviceOverview().pipe(Effect3.mapError((cause) => new RequestError({ status: 500, message: cause.message })))).filter((device) => device.active + device.cancelling > 0).map((device) => device.id));
2202
+ const selected = candidates.filter((device) => !blocked.has(device.id)).sort((left, right) => scoreDevice(right, input, sourceDeviceId, threadDeviceId, occupied) - scoreDevice(left, input, sourceDeviceId, threadDeviceId, occupied))[0];
2166
2203
  if (selected === undefined) {
2167
2204
  return yield* new RequestError({
2168
2205
  status: 409,
2169
- message: candidates.length > 0 ? "No available delegation target avoids an unfinished parent's worker slot; select another device or bot" : hasAttachments && providerDevices.length > 0 ? `No Cohall device advertising the ${provider} provider supports file attachments; upgrade a Cohall worker` : input.expiresAt !== undefined ? `No Cohall device advertising the ${provider} provider supports task deadlines; upgrade a Cohall worker` : input.botId === undefined ? `No Cohall device advertises the ${provider} provider` : `No Cohall device advertises bot ${input.botId}; refresh the bot list`
2206
+ message: candidates.length > 0 ? "No available delegation target avoids an unfinished parent's worker slot; select another device or bot" : hasAttachments && providerDevices.length > 0 ? `No Cohall device advertising the ${provider} provider supports file attachments; upgrade a Cohall worker` : expiresAt !== undefined ? `No Cohall device advertising the ${provider} provider supports task deadlines${deadlineSource}; upgrade a Cohall worker` : input.botId === undefined ? `No Cohall device advertises the ${provider} provider` : `No Cohall device advertises bot ${input.botId}; refresh the bot list`
2207
+ });
2208
+ }
2209
+ const threadDevice = candidates.find((device) => device.id === threadDeviceId);
2210
+ if (threadDevice?.status === "offline" && threadDevice.id !== selected.id) {
2211
+ return yield* new RequestError({
2212
+ status: 409,
2213
+ message: `This thread ran on ${threadDevice.name}, which is offline. Pass --target @${threadDevice.name} to queue the follow-up for it, or target another device to start a new session without the thread's history`
2170
2214
  });
2171
2215
  }
2172
2216
  return { input: resolvedInput, targetDeviceId: selected.id };
@@ -2664,8 +2708,12 @@ var runRelay = async () => {
2664
2708
  if (request.method === "POST" && cancel?.[1] !== undefined) {
2665
2709
  const id = yield* pathId(TaskId, cancel[1]);
2666
2710
  const updated = yield* store.requestCancellation(id);
2667
- if (updated.status === "cancelling") {
2711
+ if (updated.status === "cancelling")
2668
2712
  sendCancellation(updated);
2713
+ if (updated.status === "cancelling" || updated.status === "cancelled") {
2714
+ for (const child of yield* store.cancelDescendants(id))
2715
+ if (child.status === "cancelling")
2716
+ sendCancellation(child);
2669
2717
  }
2670
2718
  return json(updated);
2671
2719
  }
@@ -2834,4 +2882,4 @@ export {
2834
2882
  canDispatchTaskToDevice
2835
2883
  };
2836
2884
 
2837
- //# debugId=7733522C4FF7C62F64756E2164756E21
2885
+ //# debugId=1855EB6BC39E3C5964756E2164756E21