@akshar5/cohall 0.12.11 → 0.12.13
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/CHANGELOG.md +31 -0
- package/README.md +15 -5
- package/bin/{chunk-8w5szr2v.js → chunk-1w61mtsq.js} +2 -2
- package/bin/{chunk-pen1bdmd.js → chunk-2y4g3v66.js} +106 -25
- package/bin/chunk-2y4g3v66.js.map +13 -0
- package/bin/{chunk-808wdkdd.js → chunk-61fzgtwp.js} +1 -1
- package/bin/{chunk-ydpe597h.js → chunk-8zk47d0f.js} +29 -12
- package/bin/chunk-8zk47d0f.js.map +11 -0
- package/bin/{chunk-mwgjve0a.js → chunk-ccfjcqrz.js} +16 -14
- package/bin/chunk-ccfjcqrz.js.map +11 -0
- package/bin/{chunk-t26anmqq.js → chunk-f9qd4ajk.js} +16 -12
- package/bin/chunk-f9qd4ajk.js.map +10 -0
- package/bin/{chunk-cdpcpqte.js → chunk-fg90k4rs.js} +23 -9
- package/bin/chunk-fg90k4rs.js.map +15 -0
- package/bin/{chunk-gwqa0ajn.js → chunk-m5ecnn3k.js} +2 -2
- package/bin/{chunk-gwqa0ajn.js.map → chunk-m5ecnn3k.js.map} +1 -1
- package/bin/{chunk-8662zgwj.js → chunk-mnz2sma9.js} +1 -1
- package/bin/{chunk-1frv7xwq.js → chunk-q6dqsm9t.js} +15 -6
- package/bin/chunk-q6dqsm9t.js.map +10 -0
- package/bin/{chunk-swqxs7nr.js → chunk-zwf5dpj9.js} +63 -11
- package/bin/chunk-zwf5dpj9.js.map +14 -0
- package/bin/cohall.js +7 -7
- package/docs/install.md +2 -2
- package/docs/integrations.md +34 -9
- package/docs/services.md +25 -6
- package/package.json +1 -1
- package/bin/chunk-1frv7xwq.js.map +0 -10
- package/bin/chunk-cdpcpqte.js.map +0 -15
- package/bin/chunk-mwgjve0a.js.map +0 -11
- package/bin/chunk-pen1bdmd.js.map +0 -13
- package/bin/chunk-swqxs7nr.js.map +0 -14
- package/bin/chunk-t26anmqq.js.map +0 -10
- package/bin/chunk-ydpe597h.js.map +0 -11
- /package/bin/{chunk-8w5szr2v.js.map → chunk-1w61mtsq.js.map} +0 -0
- /package/bin/{chunk-808wdkdd.js.map → chunk-61fzgtwp.js.map} +0 -0
- /package/bin/{chunk-8662zgwj.js.map → chunk-mnz2sma9.js.map} +0 -0
|
@@ -65,7 +65,7 @@ import {
|
|
|
65
65
|
import {
|
|
66
66
|
__export,
|
|
67
67
|
version
|
|
68
|
-
} from "./chunk-
|
|
68
|
+
} from "./chunk-m5ecnn3k.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,6 +1626,15 @@ var makeService = (db, retainedTerminalTasks = 1000) => {
|
|
|
1614
1626
|
});
|
|
1615
1627
|
return row?.session_id;
|
|
1616
1628
|
});
|
|
1629
|
+
const threadDevice = Effect2.fn("RelayStore.threadDevice")(function* (threadId) {
|
|
1630
|
+
const row = yield* Effect2.try({
|
|
1631
|
+
try: () => db.query(`SELECT target_device_id FROM tasks
|
|
1632
|
+
WHERE thread_id = ? AND parent_task_id IS NULL AND provider <> 'grok-bot'
|
|
1633
|
+
ORDER BY created_at DESC, rowid DESC LIMIT 1`).get(threadId),
|
|
1634
|
+
catch: operationError("RelayStore.threadDevice")
|
|
1635
|
+
});
|
|
1636
|
+
return row?.target_device_id;
|
|
1637
|
+
});
|
|
1617
1638
|
const createPairing = Effect2.fn("RelayStore.createPairing")(function* (input) {
|
|
1618
1639
|
const roles = [...new Set(input.roles)];
|
|
1619
1640
|
if (roles.length === 0) {
|
|
@@ -1764,6 +1785,7 @@ var makeService = (db, retainedTerminalTasks = 1000) => {
|
|
|
1764
1785
|
failTask: (taskId, deviceId, error, runId) => terminal(taskId, deviceId, "failed", undefined, error, undefined, undefined, runId),
|
|
1765
1786
|
acknowledgeCancellation: (taskId, deviceId, runId) => terminal(taskId, deviceId, "cancelled", undefined, undefined, undefined, undefined, runId),
|
|
1766
1787
|
requestCancellation,
|
|
1788
|
+
cancelDescendants,
|
|
1767
1789
|
requeueTasksFor,
|
|
1768
1790
|
createUpgradeOperations,
|
|
1769
1791
|
listOperations,
|
|
@@ -1776,6 +1798,7 @@ var makeService = (db, retainedTerminalTasks = 1000) => {
|
|
|
1776
1798
|
failOperation,
|
|
1777
1799
|
requeueOperationsFor,
|
|
1778
1800
|
sessionFor,
|
|
1801
|
+
threadDevice,
|
|
1779
1802
|
createPairing,
|
|
1780
1803
|
exchangePairing,
|
|
1781
1804
|
authenticateSession,
|
|
@@ -2046,7 +2069,7 @@ var body = (request, decode2) => Effect3.tryPromise({
|
|
|
2046
2069
|
catch: () => new RequestError({ status: 400, message: "Expected a JSON request body" })
|
|
2047
2070
|
}).pipe(Effect3.flatMap(decode2), Effect3.mapError((cause) => cause instanceof RequestError ? cause : new RequestError({ status: 400, message: String(cause).slice(0, 2048) })));
|
|
2048
2071
|
var pathId = (schema, value) => Schema3.decodeUnknownEffect(schema)(value).pipe(Effect3.mapError(() => new RequestError({ status: 400, message: `Invalid identifier: ${value}` })));
|
|
2049
|
-
var scoreDevice = (device, input, sourceDeviceId) => {
|
|
2072
|
+
var scoreDevice = (device, input, sourceDeviceId, threadDeviceId) => {
|
|
2050
2073
|
const prompt = `${input.prompt} ${input.context ?? ""}`.toLowerCase();
|
|
2051
2074
|
const needsXcode = /\b(xcode|ios|macos|swiftui|app store)\b/.test(prompt);
|
|
2052
2075
|
const needsBrowser = /\b(browser|chrome|youtube|twitter|logged[- ]?in|signed[- ]?in|x\.com)\b/.test(prompt);
|
|
@@ -2056,7 +2079,7 @@ var scoreDevice = (device, input, sourceDeviceId) => {
|
|
|
2056
2079
|
const child = paths.relative(path, workspace);
|
|
2057
2080
|
return child !== ".." && !child.startsWith(`..${paths.sep}`) && !paths.isAbsolute(child);
|
|
2058
2081
|
});
|
|
2059
|
-
return (device.status === "
|
|
2082
|
+
return (device.status === "online" ? 100 : device.status === "busy" ? 90 : 0) + (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);
|
|
2060
2083
|
};
|
|
2061
2084
|
var resolveDelegation = (input, sourceDeviceId) => Effect3.gen(function* () {
|
|
2062
2085
|
const store = yield* exports_store.Service;
|
|
@@ -2084,7 +2107,11 @@ var resolveDelegation = (input, sourceDeviceId) => Effect3.gen(function* () {
|
|
|
2084
2107
|
message: "A child task must use its parent's thread"
|
|
2085
2108
|
});
|
|
2086
2109
|
}
|
|
2087
|
-
|
|
2110
|
+
if (parent?.status === "cancelling" || parent?.status === "cancelled")
|
|
2111
|
+
return yield* new RequestError({
|
|
2112
|
+
status: 409,
|
|
2113
|
+
message: "The parent task has been cancelled"
|
|
2114
|
+
});
|
|
2088
2115
|
const devices = yield* store.listDevices().pipe(Effect3.mapError((cause) => new RequestError({ status: 500, message: cause.message })));
|
|
2089
2116
|
const provider = input.provider ?? (input.botId === undefined ? "codex" : "grok-bot");
|
|
2090
2117
|
if (input.expiresAt !== undefined && provider === "grok-bot")
|
|
@@ -2092,6 +2119,19 @@ var resolveDelegation = (input, sourceDeviceId) => Effect3.gen(function* () {
|
|
|
2092
2119
|
status: 400,
|
|
2093
2120
|
message: "Task deadlines require a coding provider"
|
|
2094
2121
|
});
|
|
2122
|
+
const expiresAt = parent?.expiresAt === undefined || provider === "grok-bot" || input.expiresAt !== undefined && Date.parse(input.expiresAt) <= Date.parse(parent.expiresAt) ? input.expiresAt : parent.expiresAt;
|
|
2123
|
+
const inheritsDeadline = expiresAt !== undefined && expiresAt !== input.expiresAt;
|
|
2124
|
+
if (inheritsDeadline && Date.parse(expiresAt) <= Date.now())
|
|
2125
|
+
return yield* new RequestError({
|
|
2126
|
+
status: 409,
|
|
2127
|
+
message: "The parent task's deadline has passed"
|
|
2128
|
+
});
|
|
2129
|
+
const deadlineSource = inheritsDeadline ? " inherited from the parent task" : "";
|
|
2130
|
+
const resolvedInput = parent === undefined ? input : {
|
|
2131
|
+
...input,
|
|
2132
|
+
threadId: parent.threadId,
|
|
2133
|
+
...expiresAt === undefined ? {} : { expiresAt }
|
|
2134
|
+
};
|
|
2095
2135
|
const hasAttachments = (input.attachments?.length ?? 0) > 0;
|
|
2096
2136
|
if (hasAttachments && provider === "grok-bot") {
|
|
2097
2137
|
return yield* new RequestError({
|
|
@@ -2118,10 +2158,10 @@ var resolveDelegation = (input, sourceDeviceId) => Effect3.gen(function* () {
|
|
|
2118
2158
|
message: `${target.name} does not advertise the ${provider} provider`
|
|
2119
2159
|
});
|
|
2120
2160
|
}
|
|
2121
|
-
if (
|
|
2161
|
+
if (expiresAt !== undefined && !target.capabilities.some((capability) => capability.id === "task-deadlines"))
|
|
2122
2162
|
return yield* new RequestError({
|
|
2123
2163
|
status: 409,
|
|
2124
|
-
message: `${target.name} does not support task deadlines; upgrade its Cohall worker`
|
|
2164
|
+
message: `${target.name} does not support task deadlines${deadlineSource}; upgrade its Cohall worker`
|
|
2125
2165
|
});
|
|
2126
2166
|
if (hasAttachments && !target.capabilities.some((capability) => capability.id === "task-attachments")) {
|
|
2127
2167
|
return yield* new RequestError({
|
|
@@ -2143,7 +2183,7 @@ var resolveDelegation = (input, sourceDeviceId) => Effect3.gen(function* () {
|
|
|
2143
2183
|
}
|
|
2144
2184
|
return { input: resolvedInput, targetDeviceId: target.id };
|
|
2145
2185
|
}
|
|
2146
|
-
const providerDevices = devices.filter((device) => device.providers.includes(provider) && (
|
|
2186
|
+
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)));
|
|
2147
2187
|
const candidates = hasAttachments ? providerDevices.filter((device) => device.capabilities.some((capability) => capability.id === "task-attachments")) : providerDevices;
|
|
2148
2188
|
if (input.botId !== undefined && candidates.length > 1) {
|
|
2149
2189
|
return yield* new RequestError({
|
|
@@ -2151,11 +2191,19 @@ var resolveDelegation = (input, sourceDeviceId) => Effect3.gen(function* () {
|
|
|
2151
2191
|
message: `Bot ${input.botId} is advertised by more than one device; select a device`
|
|
2152
2192
|
});
|
|
2153
2193
|
}
|
|
2154
|
-
const
|
|
2194
|
+
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;
|
|
2195
|
+
const selected = candidates.filter((device) => !blocked.has(device.id)).sort((left, right) => scoreDevice(right, input, sourceDeviceId, threadDeviceId) - scoreDevice(left, input, sourceDeviceId, threadDeviceId))[0];
|
|
2155
2196
|
if (selected === undefined) {
|
|
2156
2197
|
return yield* new RequestError({
|
|
2157
2198
|
status: 409,
|
|
2158
|
-
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` :
|
|
2199
|
+
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`
|
|
2200
|
+
});
|
|
2201
|
+
}
|
|
2202
|
+
const threadDevice = candidates.find((device) => device.id === threadDeviceId);
|
|
2203
|
+
if (threadDevice?.status === "offline" && threadDevice.id !== selected.id) {
|
|
2204
|
+
return yield* new RequestError({
|
|
2205
|
+
status: 409,
|
|
2206
|
+
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`
|
|
2159
2207
|
});
|
|
2160
2208
|
}
|
|
2161
2209
|
return { input: resolvedInput, targetDeviceId: selected.id };
|
|
@@ -2653,8 +2701,12 @@ var runRelay = async () => {
|
|
|
2653
2701
|
if (request.method === "POST" && cancel?.[1] !== undefined) {
|
|
2654
2702
|
const id = yield* pathId(TaskId, cancel[1]);
|
|
2655
2703
|
const updated = yield* store.requestCancellation(id);
|
|
2656
|
-
if (updated.status === "cancelling")
|
|
2704
|
+
if (updated.status === "cancelling")
|
|
2657
2705
|
sendCancellation(updated);
|
|
2706
|
+
if (updated.status === "cancelling" || updated.status === "cancelled") {
|
|
2707
|
+
for (const child of yield* store.cancelDescendants(id))
|
|
2708
|
+
if (child.status === "cancelling")
|
|
2709
|
+
sendCancellation(child);
|
|
2658
2710
|
}
|
|
2659
2711
|
return json(updated);
|
|
2660
2712
|
}
|
|
@@ -2823,4 +2875,4 @@ export {
|
|
|
2823
2875
|
canDispatchTaskToDevice
|
|
2824
2876
|
};
|
|
2825
2877
|
|
|
2826
|
-
//# debugId=
|
|
2878
|
+
//# debugId=ABF7C99E84E3868A64756E2164756E21
|