feat(providers): add ACP registry for Gemini, Pi, and more #6071
Closedadhyaay-karnwal(GitHub profile, opens in a new tab)wants to merge 1 commit into
main fromrefs/pull/6071/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 +10,21 @@10+import * as Crypto from "effect/Crypto";11+import * as Effect from "effect/Effect";12+import * as Layer from "effect/Layer";13+import * as Scope from "effect/Scope";14+import * as ChildProcessSpawner from "effect/unstable/process/ChildProcessSpawner";15+import * as EffectAcpErrors from "effect-acp/errors";16+import type * as EffectAcpSchema from "effect-acp/schema";17+import { normalizeModelSlug } from "@t3tools/shared/model";18+19+import * as AcpSessionRuntime from "./AcpSessionRuntime.ts";20+21+export interface GenericAcpSpawnSettings {22+ readonly command: string;23+ readonly args: ReadonlyArray<string>;24+}25+26+export interface GenericAcpRuntimeInput extends Omit<27+ AcpSessionRuntime.AcpSessionRuntimeOptions,28+ "spawn"29+> {30+ readonly childProcessSpawner: ChildProcessSpawner.ChildProcessSpawner["Service"];@@ -0,0 +606,21 @@606+ url: mcpSession.endpoint,607+ headers: [608+ {609+ name: "Authorization",610+ value: mcpSession.authorizationHeader,611+ },612+ ],613+ },614+ ],615+ }616+ : {}),617+ ...acpNativeLoggers,618+ }).pipe(619+ Effect.provideService(Crypto.Crypto, crypto),620+ Effect.provideService(Scope.Scope, sessionScope),621+ Effect.mapError(622+ (cause) =>623+ new ProviderAdapterProcessError({624+ provider: PROVIDER,625+ threadId: input.threadId,626+ detail: cause.message,@@ -0,0 +921,21 @@921+ input.attachments ?? [],922+ (attachment) =>923+ Effect.gen(function* () {924+ const attachmentPath = resolveAttachmentPath({925+ attachmentsDir: serverConfig.attachmentsDir,926+ attachment,927+ });928+ if (!attachmentPath) {929+ return yield* new ProviderAdapterRequestError({930+ provider: PROVIDER,931+ method: "session/prompt",932+ detail: `Invalid attachment id '${attachment.id}'.`,933+ });934+ }935+ const bytes = yield* fileSystem.readFile(attachmentPath).pipe(936+ Effect.mapError(937+ (cause) =>938+ new ProviderAdapterRequestError({939+ provider: PROVIDER,940+ method: "session/prompt",941+ detail: cause.message,
- @@ -256,5 +247,8 @@256247 Driver257248 </div>258249 <RadioGroup259- value={driver}260- onValueChange={(value) => setDriver(ProviderDriverKind.make(value))}250+ value={pickerValue}251+ onValueChange={(value) => {252+ const parsed = parseAddProviderPickerValue(value);253+ setDriver(parsed.driver);254+ setCatalogId(parsed.catalogId);@@ -0,0 +34,21 @@34+ installHint: agent.installHint,35+ iconKey: agent.iconKey,36+ distributionType: launch ? (agent.local ? "local" : agent.npx ? "npx" : "uvx") : "unsupported",37+ launch,38+ };39+}40+41+function registryEntry(agent: AcpRegistryIndexAgent): AcpRegistryCatalogEntry {42+ const featured = featuredAgentById(agent.id);43+ if (featured) {44+ return {45+ ...featuredEntry(featured),46+ ...(agent.version ? { version: agent.version } : {}),47+ ...(agent.icon ? { iconUrl: agent.icon } : {}),48+ ...(agent.website || agent.repository49+ ? { docsUrl: featured.docsUrl ?? agent.website ?? agent.repository }50+ : {}),51+ };52+ }53+54+ if (agent.distribution.npx) {@@ -0,0 +213,21 @@213+ enabled: true,214+ checkedAt,215+ models: fallbackModels,216+ probe: {217+ installed: false,218+ version: null,219+ status: "error",220+ auth: { status: "unknown" },221+ message: `${command} is not installed or not on PATH. ${installHintForSettings(settings)}`,222+ },223+ });224+ }225+226+ const version =227+ Result.isSuccess(versionResult) && Option.isSome(versionResult.success)228+ ? parseGenericCliVersion(229+ `${versionResult.success.value.stdout}\n${versionResult.success.value.stderr}`,230+ )231+ : null;232+233+ const discovered = yield* discoverModelsViaAcp(settings, environment).pipe(@@ -0,0 +1387,21 @@1387+ });1388+1389+ const stopSession: ProviderAdapterShape<ProviderAdapterError>["stopSession"] = (threadId) =>1390+ withThreadLock(1391+ threadId,1392+ Effect.gen(function* () {1393+ const ctx = yield* requireSession(threadId);1394+ yield* stopSessionInternal(ctx);1395+ }),1396+ );1397+1398+ const listSessions: ProviderAdapterShape<ProviderAdapterError>["listSessions"] = () =>1399+ Effect.sync(() => Array.from(sessions.values(), (c) => ({ ...c.session })));1400+1401+ const hasSession: ProviderAdapterShape<ProviderAdapterError>["hasSession"] = (threadId) =>1402+ Effect.sync(() => {1403+ const c = sessions.get(threadId);1404+ return c !== undefined && !c.stopped;1405+ });1406+1407+ const stopAll: ProviderAdapterShape<ProviderAdapterError>["stopAll"] = () =>@@ -0,0 +193,21 @@193+ if (agent.local) return agent.local;194+ if (agent.npx) {195+ return {196+ command: "npx",197+ args: ["-y", agent.npx.package, ...agent.npx.args],198+ };199+ }200+ if (agent.uvx) {201+ return {202+ command: "uvx",203+ args: [agent.uvx.package, ...agent.uvx.args],204+ };205+ }206+ return undefined;207+}208+209+/**210+ * Split a launch-args string the way Codex/Claude settings do: whitespace211+ * separated, with simple single/double quotes.212+ */213+export function parseAcpLaunchArgs(value: string | null | undefined): ReadonlyArray<string> {@@ -0,0 +116,21 @@116+ const processEnv = mergeProviderInstanceEnvironment(environment);117+ const continuationIdentity = defaultProviderContinuationIdentity({118+ driverKind: DRIVER_KIND,119+ instanceId,120+ });121+ const stampIdentity = withInstanceIdentity({122+ instanceId,123+ displayName,124+ accentColor,125+ continuationGroupKey: continuationIdentity.continuationKey,126+ });127+ const effectiveConfig = { ...config, enabled } satisfies AcpRegistrySettings;128+ const maintenanceCapabilities = yield* resolveProviderMaintenanceCapabilitiesEffect(UPDATE, {129+ binaryPath: effectiveConfig.command,130+ env: processEnv,131+ });132+133+ const adapter = yield* makeGenericAcpAdapter(134+ {135+ enabled: effectiveConfig.enabled,136+ command: effectiveConfig.command.trim() || "acp",
- @@ -0,0 +78,21 @@78+ | EffectAcpSchema.LoadSessionResponse79+ | EffectAcpSchema.NewSessionResponse80+ | EffectAcpSchema.ResumeSessionResponse,81+): string | undefined {82+ return sessionSetupResult.models?.currentModelId?.trim() || undefined;83+}84+85+export function applyGenericAcpModelSelection<E>(input: {86+ readonly runtime: Pick<AcpSessionRuntime.AcpSessionRuntime["Service"], "setSessionModel">;87+ readonly currentModelId: string | undefined;88+ readonly requestedModelId: string | undefined;89+ readonly mapError: (cause: EffectAcpErrors.AcpError) => E;90+}): Effect.Effect<string | undefined, E> {91+ const shouldSwitchModel =92+ input.requestedModelId !== undefined && input.requestedModelId !== input.currentModelId;93+ if (!shouldSwitchModel) {94+ return Effect.succeed(input.currentModelId);95+ }96+ return input.runtime97+ .setSessionModel(input.requestedModelId)98+ .pipe(Effect.mapError(input.mapError), Effect.as(input.requestedModelId));@@ -0,0 +118,21 @@118+ driverKind: DRIVER_KIND,119+ instanceId,120+ });121+ const stampIdentity = withInstanceIdentity({122+ instanceId,123+ displayName,124+ accentColor,125+ continuationGroupKey: continuationIdentity.continuationKey,126+ });127+ const effectiveConfig = { ...config, enabled } satisfies AcpRegistrySettings;128+ const maintenanceCapabilities = yield* resolveProviderMaintenanceCapabilitiesEffect(UPDATE, {129+ binaryPath: effectiveConfig.command,130+ env: processEnv,131+ });132+133+ const adapter = yield* makeGenericAcpAdapter(134+ {135+ enabled: effectiveConfig.enabled,136+ command: effectiveConfig.command.trim() || "acp",137+ args: parseAcpLaunchArgs(effectiveConfig.launchArgs),138+ },
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:
befafb07-7156-4658-80a0-91751a185ab5You 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