feat(providers): add Pi coding agent #6319
Closedquasarea(GitHub profile, opens in a new tab)wants to merge 223 commits into
t3code/codex-turn-mapping fromrefs/pull/6319/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
- @@ -0,0 +999,21 @@999+ nativeTurnRef: null,1000+ ordinal: turnInput.providerTurnOrdinal,1001+ status: "running",1002+ startedAt,1003+ completedAt: null,1004+ };1005+ state.providerTurns.set(String(providerTurn.id), providerTurn);1006+ state.activeTurn = {1007+ input: turnInput,1008+ providerTurn,1009+ nextItemOrdinal: 0,1010+ itemOrdinals: new Map(),1011+ content: new Map(),1012+ startedAt,1013+ interrupted: false,1014+ };1015+ yield* updateThread(state, {1016+ status: "active",1017+ firstRunOrdinal: state.providerThread.firstRunOrdinal ?? turnInput.runOrdinal,1018+ });1019+ yield* updateSession("running");@@ -0,0 +223,21 @@223+ }224+225+ const versionExit = versionResult.success.value;226+ const version = parseGenericCliVersion(`${versionExit.stdout}\n${versionExit.stderr}`);227+ if (versionExit.code !== 0) {228+ return buildServerProvider({229+ presentation: PI_PRESENTATION,230+ enabled: true,231+ checkedAt,232+ models: fallbackModels,233+ probe: {234+ installed: true,235+ version,236+ status: "error",237+ auth: { status: "unknown" },238+ message: detailFromResult(versionExit) ?? "Pi CLI returned an error during health check.",239+ },240+ });241+ }242+243+ const models = modelsFromSettings(@@ -0,0 +205,21 @@205+ }206+ yield* Queue.offer(messages, message);207+ });208+209+ yield* Stream.fromQueue(outgoing).pipe(210+ Stream.run(child.stdin),211+ Effect.mapError((cause) => new PiRpcTransportError({ operation: "write", cause })),212+ Effect.catch((error) => Queue.fail(messages, error)),213+ Effect.forkScoped,214+ );215+216+ yield* child.stderr.pipe(Stream.runDrain, Effect.ignore, Effect.forkScoped);217+218+ yield* decodePiRpcStdout(child.stdout).pipe(219+ Stream.runForEach(routeMessage),220+ Effect.catch((error) => Queue.fail(messages, error)),221+ Effect.ensuring(markClosed()),222+ Effect.forkScoped,223+ );224+225+ const request = Effect.fn("PiRpcTransport.request")(function* (@@ -0,0 +552,21 @@552+ });553+ } else {554+ yield* emit({555+ type: "turn_item.updated",556+ driver: PI_DRIVER_KIND,557+ turnItem: { ...base, type: "reasoning", text, streaming: false },558+ });559+ }560+ }561+ });562+563+ const emitTool = Effect.fnUntraced(function* (564+ state: PiThreadState,565+ turn: ActivePiTurn,566+ projected: Extract<567+ PiProjectedEvent,568+ { type: "tool.started" | "tool.updated" | "tool.completed" }569+ >,570+ ) {571+ const now = yield* DateTime.now;572+ const nativeItemId = projected.toolCallId;@@ -0,0 +790,21 @@790+ status,791+ failure: {792+ class: "provider_error",793+ message: projected.errorMessage ?? "Pi run failed.",794+ code: null,795+ retryable: null,796+ },797+ threadDisposition: "reusable",798+ }799+ : {800+ type: "turn.terminal",801+ driver: PI_DRIVER_KIND,802+ providerThreadId: state.providerThread.id,803+ providerTurnId: turn.providerTurn.id,804+ runOrdinal: turn.input.runOrdinal,805+ status,806+ failure: null,807+ threadDisposition: "reusable",808+ },809+ );810+ delete state.activeTurn;@@ -0,0 +194,21 @@194+ ) {195+ if (message._tag === "response") {196+ const id = message.response.id;197+ if (id !== undefined) {198+ const pending = pendingRequests.get(id);199+ if (pending !== undefined) {200+ pendingRequests.delete(id);201+ yield* Deferred.succeed(pending, message.response);202+ return;203+ }204+ }205+ }206+ yield* Queue.offer(messages, message);207+ });208+209+ yield* Stream.fromQueue(outgoing).pipe(210+ Stream.run(child.stdin),211+ Effect.mapError((cause) => new PiRpcTransportError({ operation: "write", cause })),212+ Effect.catch((error) => Queue.fail(messages, error)),213+ Effect.forkScoped,214+ );@@ -0,0 +87,21 @@87+ Schema.Struct({ type: Schema.Literal("start") }),88+ Schema.Struct({ type: Schema.Literal("done") }),89+ Schema.Struct({ type: Schema.Literal("error") }),90+]);91+92+const PiKnownEvent = Schema.Union([93+ Schema.Struct({ type: Schema.Literal("agent_start") }),94+ Schema.Struct({95+ type: Schema.Literal("agent_end"),96+ messages: Schema.Array(PiMessage),97+ willRetry: Schema.Boolean,98+ }),99+ Schema.Struct({ type: Schema.Literal("agent_settled") }),100+ Schema.Struct({ type: Schema.Literal("turn_start") }),101+ Schema.Struct({ type: Schema.Literal("turn_end"), message: PiMessage }),102+ Schema.Struct({ type: Schema.Literal("message_start"), message: PiMessage }),103+ Schema.Struct({104+ type: Schema.Literal("message_update"),105+ message: PiMessage,106+ assistantMessageEvent: PiAssistantMessageEvent,107+ }),@@ -0,0 +447,21 @@447+ return {448+ type: "user-input",449+ requestId: id,450+ method,451+ title,452+ options,453+ ...(timeoutMs === undefined ? {} : { timeoutMs }),454+ };455+ }456+ if (method === "input") {457+ const placeholder = request["placeholder"];458+ return {459+ type: "user-input",460+ requestId: id,461+ method,462+ title,463+ ...(Predicate.isString(placeholder) ? { placeholder } : {}),464+ ...(timeoutMs === undefined ? {} : { timeoutMs }),465+ };466+ }467+ if (method === "editor") {@@ -0,0 +986,21 @@986+ thinking === "max"987+ ) {988+ yield* requestData(transport, { type: "set_thinking_level", level: thinking });989+ }990+ const startedAt = yield* DateTime.now;991+ const providerTurn: OrchestrationV2ProviderTurn = {992+ id: options.idAllocator.derive.providerTurn({993+ driver: PI_DRIVER_KIND,994+ nativeTurnId: `${state.providerThread.nativeThreadRef?.nativeId ?? state.providerThread.id}:${turnInput.runOrdinal}:${turnInput.attemptId}`,995+ }),996+ providerThreadId: state.providerThread.id,997+ nodeId: turnInput.rootNodeId,998+ runAttemptId: turnInput.attemptId,999+ nativeTurnRef: null,1000+ ordinal: turnInput.providerTurnOrdinal,1001+ status: "running",1002+ startedAt,1003+ completedAt: null,1004+ };1005+ state.providerTurns.set(String(providerTurn.id), providerTurn);1006+ state.activeTurn = {@@ -0,0 +326,21 @@326+ case "tool_execution_update":327+ return [328+ {329+ type: "tool.updated",330+ toolCallId: event.toolCallId,331+ toolName: event.toolName,332+ args: event.args,333+ partialResult: event.partialResult,334+ },335+ ];336+ case "tool_execution_end":337+ return [338+ {339+ type: "tool.completed",340+ toolCallId: event.toolCallId,341+ toolName: event.toolName,342+ result: event.result,343+ isError: event.isError,344+ },345+ ];346+ case "agent_end": {
- @@ -0,0 +315,21 @@315+ command: options.settings.binaryPath || "pi",316+ args: ["--mode", "rpc", ...launchArgs],317+ cwd,318+ env: options.environment,319+ }).pipe(Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, options.spawner));320+ const now = yield* DateTime.now;321+ let providerSession: OrchestrationV2ProviderSession = {322+ id: input.providerSessionId,323+ driver: PI_DRIVER_KIND,324+ providerInstanceId: options.instanceId,325+ status: "ready",326+ cwd,327+ model: input.modelSelection.model,328+ capabilities: PiProviderCapabilitiesV2,329+ createdAt: now,330+ updatedAt: now,331+ lastError: null,332+ };333+ const events = yield* Queue.unbounded<334+ ProviderAdapterV2Event,335+ import("../ProviderAdapter.ts").ProviderAdapterV2Error | Cause.Done<void>@@ -0,0 +157,21 @@157+ },158+ checkpointing: {159+ appCanCheckpointFilesystem: true,160+ supportsNestedCheckpointScopes: true,161+ providerCanRollbackConversation: false,162+ providerRollbackReturnsSnapshot: false,163+ providerCanReadConversationSnapshot: true,164+ },165+ identity: {166+ nativeThreadIds: "strong",167+ nativeTurnIds: "weak",168+ nativeItemIds: "strong",169+ nativeRequestIds: "strong",170+ },171+} satisfies OrchestrationV2ProviderCapabilities;172+173+interface PiAdapterV2Options {174+ readonly instanceId: ProviderInstanceId;175+ readonly settings: PiSettings;176+ readonly environment: NodeJS.ProcessEnv;177+ readonly idAllocator: IdAllocatorV2Shape;@@ -0,0 +9,21 @@9+ ProviderInstanceId,10+ ProviderSessionId,11+ RunAttemptId,12+ RunId,13+ RuntimeRequestId,14+ ThreadId,15+ type OrchestrationV2AppThread,16+} from "@t3tools/contracts";17+import * as Cause from "effect/Cause";18+import * as Deferred from "effect/Deferred";19+import * as Effect from "effect/Effect";20+import * as Fiber from "effect/Fiber";21+import * as FileSystem from "effect/FileSystem";22+import * as Layer from "effect/Layer";23+import * as Queue from "effect/Queue";24+import * as Schema from "effect/Schema";25+import * as Sink from "effect/Sink";26+import * as Stream from "effect/Stream";27+import * as ChildProcessSpawner from "effect/unstable/process/ChildProcessSpawner";28+29+import { IdAllocatorV2, layer as idAllocatorLayer } from "../IdAllocator.ts";
t3dotgg(GitHub profile, opens in a new tab) closed this
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:
51996517-1b64-46fd-80a9-fc343c40c304You 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