( port: number, target: string | undefined, preset: string | undefined, limit: number, all: boolean, )
| 166 | const VALID_PRESETS = ["feishu", "slack", "discord", "telegram", "whatsapp", "plain"]; |
| 167 | |
| 168 | async function cmdShare( |
| 169 | port: number, |
| 170 | target: string | undefined, |
| 171 | preset: string | undefined, |
| 172 | limit: number, |
| 173 | all: boolean, |
| 174 | ): Promise<void> { |
| 175 | // Default target = "last" if user just typed `clawrouter share`. |
| 176 | const tgt = target ?? "last"; |
| 177 | |
| 178 | if (tgt === "list") { |
| 179 | try { |
| 180 | const entries = (await queryProxy(`/share/list?limit=${limit}`, port)) as ShareEntry[]; |
| 181 | if (entries.length === 0) { |
| 182 | console.log("\nNo responses persisted yet."); |
| 183 | console.log( |
| 184 | " Send a request through ClawRouter and try again, or check BLOCKRUN_RESPONSE_STORE.\n", |
| 185 | ); |
| 186 | return; |
| 187 | } |
| 188 | console.log(`\nRecent responses (${entries.length}):\n`); |
| 189 | for (const e of entries) { |
| 190 | const t = new Date(e.timestamp).toLocaleString(); |
| 191 | const summary = e.requestSummary || "(no prompt)"; |
| 192 | const len = e.responseLength ? ` ${e.responseLength}b` : ""; |
| 193 | console.log(` ${e.id} ${t} [${e.model ?? "?"}${len}]`); |
| 194 | console.log(` ${summary}`); |
| 195 | } |
| 196 | console.log( |
| 197 | `\nUse: clawrouter share <id> --as=<feishu|slack|discord|telegram|whatsapp|plain>\n`, |
| 198 | ); |
| 199 | } catch (err) { |
| 200 | console.error(`✗ Cannot fetch share list: ${err instanceof Error ? err.message : err}`); |
| 201 | console.error(` Is the proxy running on port ${port}?`); |
| 202 | process.exit(1); |
| 203 | } |
| 204 | return; |
| 205 | } |
| 206 | |
| 207 | // Render path: target is "last" or a specific id. |
| 208 | const idOrLast = tgt === "last" ? "last" : tgt; |
| 209 | |
| 210 | // --all: render every preset to /tmp/, print the paths. |
| 211 | if (all) { |
| 212 | try { |
| 213 | const { writeFile } = await import("node:fs/promises"); |
| 214 | const { tmpdir } = await import("node:os"); |
| 215 | const { join: pjoin } = await import("node:path"); |
| 216 | const paths: string[] = []; |
| 217 | for (const p of VALID_PRESETS) { |
| 218 | const path = |
| 219 | idOrLast === "last" ? `/share/last?as=${p}` : `/share/${idOrLast}/render?as=${p}`; |
| 220 | const result = (await queryProxy(path, port)) as ShareRendered; |
| 221 | const file = pjoin(tmpdir(), `claw-share-${result.id}-${p}.txt`); |
| 222 | await writeFile(file, result.rendered, "utf8"); |
| 223 | paths.push(file); |
| 224 | } |
| 225 | console.log("\n✓ Wrote all 6 preset variants:"); |
no test coverage detected