Local-first AI coding agent desktop: Electron + Rust host core + pi Agent Harness + user-installable plugins
TypeScript ai-agentcoding-agentdesktop-appelectronglobali18nlocal-firstmcppipi-agentpi-desktoppluginsreactrusttypescript
fix(plugin-net): type binary capabilities and keep existing fetch contract docs
vastsa526417126f8d
diff --git a/apps/desktop/electron/main/plugin-runtime.ts b/apps/desktop/electron/main/plugin-runtime.tsindex 5159e1ff0..1c824ac8c 100644--- a/apps/desktop/electron/main/plugin-runtime.ts+++ b/apps/desktop/electron/main/plugin-runtime.ts@@ -12,7 +12,7 @@ import type { Stats } from "node:fs";import { open as openFile } from "node:fs/promises";import { randomUUID } from "node:crypto";import { basename, dirname, extname, isAbsolute, join, relative, resolve, sep } from "node:path";-import { pluginNetFetch, parseFetchRedirect, type PluginFetchTransport } from "./plugin-net-fetch";+import { MAX_PLUGIN_BINARY_RESPONSE_BYTES, pluginNetFetch, parseFetchRedirect, type PluginFetchTransport } from "./plugin-net-fetch";import type { LoadedSkillDocument } from "./skill-document";import { assertLocalPluginRoot, pluginFsReadOptions, readRemotePluginFiles, type PluginRemoteFilesRead } from "./plugin-remote-files";import { getModuleDirectory } from "./module-path";@@ -6648,7 +6648,7 @@ export class PluginRuntime {closeOutput: async () => this.refuseAudio(loaded, "audio.closeOutput"),},net: {- getCapabilities: async () => ({ fetchRedirectModes: ["follow", "error", "manual"], binaryResponseBody: true, maxResponseBodyBytes: 16 * 1024 * 1024 }),+ getCapabilities: async () => ({ fetchRedirectModes: ["follow", "error", "manual"], binaryResponseBody: true, maxResponseBodyBytes: MAX_PLUGIN_BINARY_RESPONSE_BYTES }),fetch: async (input: {url: string;method?: string;diff --git a/docs/spec/07-plugins/03-plugin-api.md b/docs/spec/07-plugins/03-plugin-api.mdindex 10c6b7950..df1e33b77 100644--- a/docs/spec/07-plugins/03-plugin-api.md+++ b/docs/spec/07-plugins/03-plugin-api.md@@ -1253,8 +1253,8 @@ pi.net.fetch(input: {contentType?: stringbyteLength?: number}>-```+`responseType` defaults to `text` and preserves the existing bodyText response.`responseType: "base64"` reads the response body as bounded bytes and returnscanonical standard Base64 in `bodyBase64`, with `contentType` and `byteLength`.@@ -1263,11 +1263,16 @@ The host enforces a maximum of 16 MiB and accepts a smaller positive integer in`RESPONSE_TOO_LARGE`; no partial bytes are returned. Binary response mode isintended for bounded media downloads and does not grant filesystem access.-Before using binary mode on a potentially older host, query+Before using the redirect option or binary mode on a potentially older host,+query`pi.net.getCapabilities(): Promise<{ fetchRedirectModes: ("follow" | "error" | "manual")[]; binaryResponseBody?: true; maxResponseBodyBytes?: number }>`-and require `binaryResponseBody` plus a sufficient `maxResponseBodyBytes`.-This read-only query needs no network permission and performs no network I/O.-When the capability is absent, do not send a base64 request.+and require the desired redirect mode, or `binaryResponseBody` plus a+sufficient `maxResponseBodyBytes`. This read-only query needs no network+permission and performs no network I/O. A missing method, rejected query,+absent mode, or absent binary capability means unsupported: do not send the+request. Older hosts may silently ignore unknown fetch options, so passing+`redirect` or `responseType` alone is **not** capability detection.+No same-origin-only mode is introduced by this change.`redirect` is optional: omitted or `follow` preserves the existing policy (up tofive followed 3xx responses with Location, relative to the current URL, each@@ -1289,7 +1294,10 @@ audited without response bodies or headers.`fetch` answers with the upstream response unchanged — `status`, `headers`,and either text or bounded Base64 body data — so a `429` is data your plugin canread, `Retry-After` included, rather than an error the host hides. The host does-not retry, throttle, or re-issue the request.+not retry, throttle, or re-issue the request: retry and backoff after a `429`+are your plugin's own policy, and the response headers are the only backoff+signal you get. A failed call (`status >= 400`) is audited as `ok: false`,+together with the `retryAfter` it advertised when the response states one (§7).```tspi.net.websocket.connect(input: {diff --git a/packages/plugin-sdk/src/index.ts b/packages/plugin-sdk/src/index.tsindex 365090e82..aba3b7b8e 100644--- a/packages/plugin-sdk/src/index.ts+++ b/packages/plugin-sdk/src/index.ts@@ -1678,7 +1678,7 @@ export type PluginHostApi = {};net: {/** Query before using redirect on hosts that may predate this API. */- getCapabilities: () => Promise<{ fetchRedirectModes: ("follow" | "error" | "manual")[] }>;+ getCapabilities: () => Promise<PluginNetCapabilities>;fetch: (input: PluginNetFetchInput) => Promise<PluginNetFetchResult>;/*** Real-time bidirectional sockets (`net.websocket`). A connect is confined