162c9ca422
- Added `src/export/share.ts`: `/share` now snapshots the session JSON, gzips and seals it with a fresh AES-256-GCM key, and pushes the blob to a secret gist or the share server (1 MB cap with image/string/entry truncation via `sealToFit`); links are `<serverUrl>/<id>#<key>` with the key only in the fragment. - Added `share-loader.js` and `scripts/generate-share-viewer.ts` building the static viewer the relay serves at `GET /s/<id>`: it fetches the sealed blob, decrypts in-browser, and hands the JSON to the export template via `window.__OMP_SESSION_DATA__`. - Reworked the `/share` command in `command-controller.ts`/`builtin-registry.ts` off the plaintext-gist HTML upload, exported `LoadedCustomShare`, and exposed the session `SecretObfuscator` getter on `AgentSession` for redaction. - Added `share.serverUrl` and `share.redactSecrets` settings backed by `DEFAULT_SHARE_URL` from pi-wire. - HTML exports now embed subagent transcripts: `collectSubSessions` walks `<session>/<AgentId>.jsonl` recursively into `SessionData.subSessions`, with `includeSubSessions` opt-out and the exported `buildSessionData` reused by share snapshots. - Added `share.test.ts` (snapshot/seal/server-url contracts) and `export-subsessions.test.ts`.
66 lines
1.6 KiB
TypeScript
66 lines
1.6 KiB
TypeScript
/**
|
|
* Custom share script loader.
|
|
*
|
|
* Allows users to define a custom share handler at ~/.omp/agent/share.ts
|
|
* that will be used instead of the default GitHub Gist sharing.
|
|
*/
|
|
import * as fs from "node:fs";
|
|
import * as path from "node:path";
|
|
import { getAgentDir } from "@oh-my-pi/pi-utils";
|
|
|
|
export interface CustomShareResult {
|
|
/** URL to display/open (optional - script may handle everything itself) */
|
|
url?: string;
|
|
/** Additional message to show the user */
|
|
message?: string;
|
|
}
|
|
|
|
export type CustomShareFn = (htmlPath: string) => Promise<CustomShareResult | string | undefined>;
|
|
|
|
export interface LoadedCustomShare {
|
|
path: string;
|
|
fn: CustomShareFn;
|
|
}
|
|
|
|
const SHARE_SCRIPT_CANDIDATES = ["share.ts", "share.js", "share.mjs"];
|
|
|
|
/**
|
|
* Get the path to the custom share script if it exists.
|
|
*/
|
|
export function getCustomSharePath(): string | null {
|
|
const agentDir = getAgentDir();
|
|
|
|
for (const candidate of SHARE_SCRIPT_CANDIDATES) {
|
|
const scriptPath = path.join(agentDir, candidate);
|
|
if (fs.existsSync(scriptPath)) {
|
|
return scriptPath;
|
|
}
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
/**
|
|
* Load the custom share script if it exists.
|
|
*/
|
|
export async function loadCustomShare(): Promise<LoadedCustomShare | null> {
|
|
const scriptPath = getCustomSharePath();
|
|
if (!scriptPath) {
|
|
return null;
|
|
}
|
|
|
|
try {
|
|
const module = await import(scriptPath);
|
|
const fn = module.default;
|
|
|
|
if (typeof fn !== "function") {
|
|
throw new Error("share script must export a default function");
|
|
}
|
|
|
|
return { path: scriptPath, fn };
|
|
} catch (err) {
|
|
const message = err instanceof Error ? err.message : String(err);
|
|
throw new Error(`Failed to load share script: ${message}`);
|
|
}
|
|
}
|