Feat/oh my pi provider #8157
Closedsimardwtf(GitHub profile, opens in a new tab)wants to merge 9 commits into
main fromrefs/pull/8157/headopened View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:XXL
simardwtf(GitHub profile, opens in a new tab) closed this
- @@ -0,0 +101,21 @@101+ const checkProvider = checkOhMyPiProviderStatus(effectiveConfig, processEnv).pipe(102+ Effect.map(stamp),103+ Effect.provideService(Crypto.Crypto, crypto),104+ Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, spawner),105+ );106+ const snapshotSettings = makeProviderSnapshotSettingsSource(effectiveConfig, serverSettings);107+ const snapshot = yield* makeManagedServerProvider<ProviderSnapshotSettings<OhMyPiSettings>>({108+ maintenanceCapabilities,109+ getSettings: snapshotSettings.getSettings,110+ streamSettings: snapshotSettings.streamSettings,111+ haveSettingsChanged: haveProviderSnapshotSettingsChanged,112+ initialSnapshot: (settings) =>113+ buildInitialOhMyPiProviderSnapshot(settings.provider).pipe(Effect.map(stamp)),114+ checkProvider,115+ }).pipe(116+ Effect.mapError(117+ (cause) =>118+ new ProviderDriverError({119+ driver: DRIVER_KIND,120+ instanceId,121+ detail: `Failed to build Oh My Pi snapshot: ${cause.message ?? String(cause)}`,@@ -24,11 +33,4 @@2433 readonly label: string;2534 readonly icon: Icon;2635 readonly settingsSchema: ProviderSettingsSchema;27- /**28- * Optional short label rendered as a `variant="warning"` badge next to29- * the instance title. Used to flag drivers that still ship under an30- * early-access or preview gate — the flag is a property of the driver31- * kind (not a specific instance), so every instance of that driver —32- * built-in default or custom — advertises the same marker.33- */3436 readonly badgeLabel?: string;@@ -0,0 +257,21 @@257+ provider: PROVIDER,258+ threadId: input.threadId,259+ turnId: activeTurnId,260+ requestId: runtimeRequestId,261+ permissionRequest,262+ decision: resolved,263+ }),264+ );265+ const optionId = resolved === "cancel" ? undefined : permissionOptionId(params, resolved);266+ return {267+ outcome: optionId268+ ? { outcome: "selected" as const, optionId }269+ : ({ outcome: "cancelled" } as const),270+ };271+ }).pipe(272+ Effect.mapError((cause) => ({273+ _tag: "AcpTransportError" as const,274+ message: cause instanceof Error ? cause.message : String(cause),275+ detail: "Failed to process Oh My Pi permission request.",276+ cause,277+ }) as never),@@ -0,0 +427,21 @@427+ const text = input.input?.trim();428+ const attachments = yield* Effect.forEach(input.attachments ?? [], (attachment) =>429+ Effect.gen(function* () {430+ const path = resolveAttachmentPath({431+ attachmentsDir: serverConfig.attachmentsDir,432+ attachment,433+ });434+ if (!path) {435+ return yield* new ProviderAdapterRequestError({436+ provider: PROVIDER,437+ method: "session/prompt",438+ detail: `Invalid attachment id '${attachment.id}'.`,439+ });440+ }441+ const bytes = yield* fileSystem.readFile(path).pipe(442+ Effect.mapError(443+ (cause) =>444+ new ProviderAdapterRequestError({445+ provider: PROVIDER,446+ method: "session/prompt",447+ detail: cause.message,
- @@ -0,0 +496,21 @@496+ );497+ ctx.turns.push({ id: turnId, items: [{ prompt, result }] });498+ if (ctx.activeTurnId === turnId) {499+ const updatedAt = yield* nowIso;500+ const { activeTurnId: _activeTurnId, ...ready } = ctx.session;501+ ctx.activeTurnId = undefined;502+ ctx.session = { ...ready, status: "ready", updatedAt };503+ yield* publish({504+ type: "turn.completed",505+ ...(yield* stamp()),506+ provider: PROVIDER,507+ threadId: input.threadId,508+ turnId,509+ payload: {510+ state: result.stopReason === "cancelled" ? "cancelled" : "completed",511+ stopReason: result.stopReason ?? null,512+ },513+ });514+ }515+ return { threadId: input.threadId, turnId, resumeCursor: ctx.session.resumeCursor };516+ });@@ -0,0 +525,21 @@525+ if (turnId !== undefined && active !== undefined && turnId !== active) return;526+ yield* settleApprovals(ctx);527+ yield* ctx.acp.cancel.pipe(528+ Effect.mapError((error) => mapAcpToAdapterError(PROVIDER, threadId, "session/cancel", error)),529+ Effect.ignore,530+ );531+ if (active) {532+ const updatedAt = yield* nowIso;533+ const { activeTurnId: _activeTurnId, ...ready } = ctx.session;534+ ctx.activeTurnId = undefined;535+ ctx.session = { ...ready, status: "ready", updatedAt };536+ yield* publish({537+ type: "turn.completed",538+ ...(yield* stamp()),539+ provider: PROVIDER,540+ threadId,541+ turnId: active,542+ payload: { state: "cancelled", stopReason: "cancelled" },543+ });544+ }545+ });
- @@ -8,3 +16,4 @@816 [ProviderDriverKind.make("opencode")]: OpenCodeIcon,917 [ProviderDriverKind.make("cursor")]: CursorIcon,1018 [ProviderDriverKind.make("grok")]: GrokIcon,19+ [ProviderDriverKind.make("ohMyPi")]: PiAgentIcon,@@ -24,11 +33,4 @@2433 readonly label: string;2534 readonly icon: Icon;2635 readonly settingsSchema: ProviderSettingsSchema;27- /**28- * Optional short label rendered as a `variant="warning"` badge next to29- * the instance title. Used to flag drivers that still ship under an30- * early-access or preview gate — the flag is a property of the driver31- * kind (not a specific instance), so every instance of that driver —32- * built-in default or custom — advertises the same marker.33- */3436 readonly badgeLabel?: string;@@ -67,3 +69,9 @@6769 icon: OpenCodeIcon,6870 settingsSchema: OpenCodeSettings,6971 },72+ {73+ value: ProviderDriverKind.make("ohMyPi"),74+ label: "Oh My Pi",75+ icon: PiAgentIcon,76+ settingsSchema: OhMyPiSettings,77+ },
- @@ -0,0 +72,21 @@72+}73+74+function parseResumeCursor(value: unknown): string | undefined {75+ if (typeof value !== "object" || value === null || Array.isArray(value)) return undefined;76+ const candidate = value as { schemaVersion?: unknown; sessionId?: unknown };77+ if (candidate.schemaVersion !== RESUME_VERSION) return undefined;78+ return typeof candidate.sessionId === "string" && candidate.sessionId.trim()79+ ? candidate.sessionId.trim()80+ : undefined;81+}82+83+function permissionOptionId(84+ request: EffectAcpSchema.RequestPermissionRequest,85+ decision: Exclude<ProviderApprovalDecision, "cancel">,86+): string | undefined {87+ const kind =88+ decision === "acceptForSession"89+ ? "allow_always"90+ : decision === "accept"91+ ? "allow_once"92+ : "reject_once";@@ -0,0 +375,21 @@375+ case "ContentDelta":376+ yield* publish(377+ makeAcpContentDeltaEvent({378+ stamp: eventStamp,379+ provider: PROVIDER,380+ threadId: ctx.threadId,381+ turnId,382+ ...(event.itemId ? { itemId: event.itemId } : {}),383+ text: event.text,384+ rawPayload: event.rawPayload,385+ }),386+ );387+ return;388+ }389+ }),390+ ),391+ ).pipe(392+ Effect.catch((cause) =>393+ Effect.logError("Failed to process Oh My Pi ACP notification.", { cause }),394+ ),395+ Effect.forkChild,@@ -0,0 +451,21 @@451+ );452+ return {453+ type: "image" as const,454+ data: Buffer.from(bytes).toString("base64"),455+ mimeType: attachment.mimeType,456+ } satisfies EffectAcpSchema.ContentBlock;457+ }),458+ );459+ const prompt: Array<EffectAcpSchema.ContentBlock> = [460+ ...(text ? [{ type: "text" as const, text }] : []),461+ ...attachments,462+ ];463+ if (prompt.length === 0) {464+ return yield* new ProviderAdapterValidationError({465+ provider: PROVIDER,466+ operation: "sendTurn",467+ issue: "Turn requires non-empty text or an attachment.",468+ });469+ }470+471+ const turnId = ctx.activeTurnId ?? TurnId.make(yield* nextId);@@ -0,0 +133,21 @@133+ const session = sessions.get(threadId);134+ return session && !session.stopped135+ ? Effect.succeed(session)136+ : Effect.fail(new ProviderAdapterSessionNotFoundError({ provider: PROVIDER, threadId }));137+ };138+139+ const settleApprovals = (ctx: SessionContext) =>140+ Effect.forEach(141+ Array.from(ctx.pendingApprovals.values()),142+ (pending) => Deferred.succeed(pending, "cancel").pipe(Effect.ignore),143+ { discard: true },144+ );145+146+ const stopInternal = (ctx: SessionContext) =>147+ Effect.gen(function* () {148+ if (ctx.stopped) return;149+ ctx.stopped = true;150+ yield* settleApprovals(ctx);151+ if (ctx.notificationFiber) yield* Fiber.interrupt(ctx.notificationFiber);152+ yield* Effect.ignore(Scope.close(ctx.scope, Exit.void));153+ sessions.delete(ctx.threadId);@@ -2087,3 +2087,4 @@20872087 ];20882088 }208920892090+ const targets = target@@ -0,0 +507,21 @@507+ threadId: input.threadId,508+ turnId,509+ payload: {510+ state: result.stopReason === "cancelled" ? "cancelled" : "completed",511+ stopReason: result.stopReason ?? null,512+ },513+ });514+ }515+ return { threadId: input.threadId, turnId, resumeCursor: ctx.session.resumeCursor };516+ });517+518+ const interruptTurn: ProviderAdapterShape<ProviderAdapterError>["interruptTurn"] = (519+ threadId,520+ turnId,521+ ) =>522+ Effect.gen(function* () {523+ const ctx = yield* requireSession(threadId);524+ const active = ctx.activeTurnId;525+ if (turnId !== undefined && active !== undefined && turnId !== active) return;526+ yield* settleApprovals(ctx);527+ yield* ctx.acp.cancel.pipe(@@ -0,0 +471,21 @@471+ const turnId = ctx.activeTurnId ?? TurnId.make(yield* nextId);472+ const isSteer = ctx.activeTurnId !== undefined;473+ ctx.activeTurnId = turnId;474+ ctx.session = {475+ ...ctx.session,476+ status: "running",477+ activeTurnId: turnId,478+ updatedAt: yield* nowIso,479+ };480+ if (!isSteer) {481+ yield* publish({482+ type: "turn.started",483+ ...(yield* stamp()),484+ provider: PROVIDER,485+ threadId: input.threadId,486+ turnId,487+ payload: { model: OH_MY_PI_MANAGED_MODEL },488+ });489+ }490+491+ const result = yield* ctx.acp.prompt({ prompt }).pipe(@@ -3155,2 +3160,2 @@31553160 ),31563161 Flag.optional,@@ -66,4 +66,4 @@66666767 ## Desktop artifacts686869-`vp run dist:desktop:artifact --platform <mac|linux|win> --target <target> --arch <arch>`: Builds a desktop artifact for a specific platform/target/arch.69+`vp run dist:desktop:artifact --platform <mac|linux|win> --target <target[,target...]> --arch <arch>`: Builds one or more desktop artifact targets for a specific platform and architecture.@@ -0,0 +93,21 @@93+const runVersion = (settings: OhMyPiSettings, environment: NodeJS.ProcessEnv) =>94+ Effect.gen(function* () {95+ const command = settings.binaryPath || "omp";96+ const spawn = yield* resolveSpawnCommand(command, ["--version"], { env: environment });97+ return yield* spawnAndCollect(98+ command,99+ ChildProcess.make(spawn.command, spawn.args, { env: environment, shell: spawn.shell }),100+ );101+ });102+103+const verifyAcpStartup = (settings: OhMyPiSettings, environment: NodeJS.ProcessEnv) =>104+ Effect.gen(function* () {105+ const childProcessSpawner = yield* ChildProcessSpawner.ChildProcessSpawner;106+ const runtime = yield* makeOhMyPiAcpRuntime({107+ ohMyPiSettings: settings,108+ environment,109+ childProcessSpawner,110+ cwd: process.cwd(),111+ clientInfo: { name: "t3-code-provider-probe", version: "0.0.0" },112+ });113+ yield* runtime.start();@@ -0,0 +451,21 @@451+ );452+ return {453+ type: "image" as const,454+ data: Buffer.from(bytes).toString("base64"),455+ mimeType: attachment.mimeType,456+ } satisfies EffectAcpSchema.ContentBlock;457+ }),458+ );459+ const prompt: Array<EffectAcpSchema.ContentBlock> = [460+ ...(text ? [{ type: "text" as const, text }] : []),461+ ...attachments,462+ ];463+ if (prompt.length === 0) {464+ return yield* new ProviderAdapterValidationError({465+ provider: PROVIDER,466+ operation: "sendTurn",467+ issue: "Turn requires non-empty text or an attachment.",468+ });469+ }470+471+ const turnId = ctx.activeTurnId ?? TurnId.make(yield* nextId);
Sign in to join this conversation.


Important
Review skipped#
Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
.coderabbit.yamlfile in this repository. To trigger a single review, invoke the@coderabbitai reviewcommand.⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID:
cf254846-a2e0-4dd6-b513-e41126633a59You can disable this status message by setting the
reviews.review_statustofalsein the CodeRabbit configuration file.Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
❤️ Share