mirror of
https://github.com/badlogic/pi-mono.git
synced 2026-11-05 23:37:25 +00:00
p2 rewritten by the Chord v2 authoring rules (decision "App authoring rules confirmed by the p2 audit"), in four parts merged together: - core: session lifecycle (relocate, clone, fork, archive) and search rebuild are persisted jobs on a new server store; Sessions v6 with client-chosen ids and visible operations; Retry answers with the worker's real outcome; workers push branch, subagent and status state to the server; roots take the method's ctx. - services: models, envs, ports, login, mcp, logs, sharing and voice follow external state (self.follow, followNative) instead of copy loops; methods answer after their state commits; presence from host.references. - chat: chat mode, artifacts and prompt resources follow Durable and native state; shell commands are Chord jobs (shellId is the requestId); status pushed before send and stop answer; race-free draft claim. - ui: optimistic updates on web (useOptimistic) and terminal (TuiScope.optimistic, extended in Chord with a reducer and a pending flag), pending states for long work, visible rollback, load waterfalls removed; merged with the one composer and immediate first send (ccff9876e) and the folder + button (5a31a6d5f). docs/optimistic-ui.md describes the pattern.
46 lines
1.5 KiB
TypeScript
46 lines
1.5 KiB
TypeScript
import { BACKGROUND_CONTEXT, contribute, defineFacet, liveIn } from "@p2/app/v1";
|
|
import {
|
|
navigate,
|
|
OpenPeerConversation,
|
|
Slots,
|
|
useComposerState,
|
|
useConnected,
|
|
useObject,
|
|
useReadable,
|
|
} from "@p2/app/v1/web";
|
|
import type { ReactNode } from "react";
|
|
import { Sessions } from "../sessions/contract.ts";
|
|
|
|
function Attribution({ children }: { children?: ReactNode }) {
|
|
const sessions = useObject(Sessions, {});
|
|
const listed = useReadable(liveIn(sessions, "owner", "guest")?.sessions) ?? [];
|
|
const owner = liveIn(sessions, "owner");
|
|
// As Pi Mobile: peer labels link only while connected; errors go to the app's toast.
|
|
const connected = useConnected();
|
|
const { setError, fail } = useComposerState();
|
|
const open = (session: string): void => {
|
|
const current = listed.find((entry) => entry.id === session);
|
|
if (!current) {
|
|
setError("The source conversation is unavailable");
|
|
return;
|
|
}
|
|
if (current.archivedAt === null) navigate({ session });
|
|
// An archived source opens once restored (the view refuses an archived session).
|
|
else
|
|
void owner
|
|
?.restore({ id: session }, BACKGROUND_CONTEXT)
|
|
.then(() => navigate({ session }))
|
|
.catch(fail);
|
|
};
|
|
return (
|
|
<OpenPeerConversation.Provider value={owner && connected ? open : undefined}>
|
|
{children}
|
|
</OpenPeerConversation.Provider>
|
|
);
|
|
}
|
|
|
|
export default defineFacet((host) => {
|
|
contribute(host, "p2.web-conversations", (self) => {
|
|
self.contribute(Slots, { "chat-attribution": Attribution });
|
|
});
|
|
});
|