Skip to content

Pedelec API

Pedelec is the browser client that owns the Chrome Extension bridge and creates or resumes PedelecSession objects.

import { Pedelec } from "@kaoruisaac/pedelec";
new Pedelec(options?: PedelecOptions)
type PedelecOptions = {
runtimeFullAccess?: boolean;
bridgeTimeoutMs?: number;
};
Parameter Type Default Description
options.runtimeFullAccess boolean false Request explicit Full Runtime Access for this Instance; Session opt-in and both Extension grants are also required.
options.bridgeTimeoutMs number 30_000 Maximum wait for an Extension bridge response. Values below 1 are clamped to 1.

The constructor attempts to connect to the Pedelec Chrome Extension immediately. Construct it only in a browser page after hydration.

const pedelec = new Pedelec({
bridgeTimeoutMs: 30_000,
});
createSession(): Promise<PedelecSession<string>>;
createSession<const TTools extends readonly ToolDefinition[]>(
input: CreateSessionInput<TTools>,
): Promise<PedelecSession<ToolNameOf<TTools>>>;

Creates a new Core session and subscribes the current SDK channel to it.

type CreateSessionInput<TTools extends readonly ToolDefinition[]> =
| {
provider?: ProviderCode;
effortLevel?: EffortLevel;
model?: never;
effort?: never;
skills?: SkillsInput<TTools>;
runtimeFullAccess?: boolean;
autoEndOnDisconnect?: boolean;
}
| {
provider?: ProviderCode;
model: string;
effort?: Effort;
effortLevel?: never;
skills?: SkillsInput<TTools>;
runtimeFullAccess?: boolean;
autoEndOnDisconnect?: boolean;
};
  • No provider: use Desktop defaultProvider; verify it is available.
  • provider may be combined with provider-independent effortLevel in Desktop profile mode.
  • Explicit model mode uses model with optional provider-native effort; it must not include effortLevel.
  • Model-only explicit mode uses provider-default effort behavior. Omitted effortLevel is normalized to default only in profile mode.
  • autoEndOnDisconnect: defaults to true.

createSession() always uses the managed convenience flow and does not accept Workspace configuration. For an application-managed Workspace, call openWorkspace() and then workspace.createSession(). See the PedelecWorkspace reference for the Workspace methods, lifecycle, concurrency, and security boundary.

A PedelecSession registered in this client.

  • approval and transport errors;
  • DEFAULT_PROVIDER_NOT_SET;
  • DEFAULT_PROVIDER_UNAVAILABLE;
  • INVALID_INPUT;
  • MODEL_REQUIRED when profile-mode Ollama has no model in the selected effort profile;
  • provider/Core creation errors.
const session = await pedelec.createSession({
provider: "codex",
autoEndOnDisconnect: true,
});
webmcp<const TTools extends readonly ToolDefinition[]>(
input: WebMcpInput<TTools>,
): Promise<WebMcpBinding>

Registers the same App Tool definitions with document.modelContext.registerTool when the browser provides it. This method does not create a Session and does not require Extension or Desktop readiness. See the Tools API for WebMcpInput, availability, dispose(), and the handler context limit.

openWorkspace(): Promise<PedelecWorkspace | null>
openWorkspace(path: string): Promise<PedelecWorkspace>

Opens or initializes a workspace capability. Without a path, Pedelec Desktop opens the native directory picker and cancellation resolves to null. An explicit path bypasses the picker. The returned workspace exposes path, createSession(), listFiles(), listFolders(), uploadFile(), readFile(), and run().

const workspace = await pedelec.openWorkspace();
if (!workspace) return;
const session = await workspace.createSession({ provider: "codex" });
const files = await workspace.listFiles();
const result = await workspace.run("console.log('hello');");

This is a sensitive Desktop API and may trigger the current origin’s approval flow. Workspace validation, runtime initialization, and marker handling are performed by Core. The picker overload has no generic SDK bridge timeout while the native picker is open; the explicit-path overload uses the configured bridge timeout. Extension disconnects and explicit bridge errors still reject.

listProviders(): Promise<ProviderInfo[]>

Returns provider discovery results from Desktop Core.

type ProviderInfo = {
name: string;
code: ProviderCode;
available: boolean;
isDefault: boolean;
error: string | null;
};
const providers = await pedelec.listProviders();
const ready = providers.filter((provider) => provider.available);

isDefault identifies the provider selected by the current Desktop settings. It is independent of available, so it remains true when the selected provider is unavailable. available is a discovery/setup signal, not a guarantee that every model or remote service is ready. The SDK ignores unknown fields added to Extension responses for forward compatibility.

Extension, native host, Core IPC, and bridge timeout errors.

getSettings(): Promise<PedelecSettings>

Reads the SDK-visible Desktop defaults.

type PedelecSettings = {
defaultProvider: ProviderCode | null;
};

The SDK validates the returned shape. An incompatible response rejects with SDK_PROTOCOL_ERROR.

const settings = await pedelec.getSettings();
console.log(settings.defaultProvider);
getApprovalStatus(): Promise<ApprovalStatus>
type ApprovalStatus = {
installed: boolean;
approved: boolean;
origin: string | null;
appConnected: boolean;
};

Reads the current origin’s Extension approval state.

Special behavior: when the Extension is unavailable or disconnected, this method resolves instead of throwing:

{
installed: false,
approved: false,
origin: location.origin,
appConnected: false
}

Other errors, such as protocol/storage failures, may reject.

Calling this method does not open the approval popup. createSession() or resumeSession() triggers approval when required.

checkAvailability(): Promise<PedelecAvailability>

Checks Extension reachability, current-origin approval, and (only after approval) Desktop readiness. It does not create or resume a session and never opens the approval popup.

const availability = await pedelec.checkAvailability();
if (availability.available) {
// Extension, approval, and Desktop settings probe all succeeded.
}

getSettings() and listProviders() require origin approval and can trigger its popup. They expose only public defaults and name/code/available/isDefault/error respectively. getApprovalStatus().appConnected is the non-sensitive Core ping result for connectivity; it does not imply approval or provider readiness.

It resolves structured unavailable states for bridge, Native Host, Core, timeout, and settings-protocol failures. launchAttempted: true means a status ping or settings probe was sent and may have invoked auto-launch; it does not prove Desktop was launched.

resumeSession(sessionId: string): Promise<PedelecSession<string>>

Subscribes this SDK client to an existing Core session and hydrates its associated workspace. This is a reattachment operation, not ended-thread reactivation: if Core reports ended, the returned handle remains ended. The returned Session already includes session.workspace; the application does not need to call openWorkspace() separately.

const session = await pedelec.resumeSession(savedSessionId);
Parameter Type Description
sessionId string Non-empty Core session/thread identifier.

A session handle registered in this client. A newly resumed handle may not contain provider/effort metadata because the current bridge response returns only the ID.

  • INVALID_INPUT for an empty ID;
  • approval errors;
  • SDK_ORIGIN_UNAVAILABLE when the caller origin cannot be forwarded;
  • THREAD_ACCESS_DENIED when the session belongs to another origin;
  • THREAD_NOT_FOUND when Core no longer knows the ID; and
  • transport errors.

After resume, register chat, status, error, ended, and tool handlers again.

request<T>(
type: string,
payload?: Record<string, unknown>,
): Promise<T>

Low-level bridge request API.

const result = await pedelec.request<{ sessionId: string }>(
"create_session",
{
input: {
provider: "codex",
autoEndOnDisconnect: true,
},
},
);

The method:

  • lazily ensures that a current Extension port exists, retrying after a transient disconnect;
  • applies bridgeTimeoutMs;
  • generates a request ID;
  • posts through the Extension port; and
  • normalizes failed bridge responses as PedelecError.

T is compile-time only.

When the Extension port disconnects, requests already sent through that port reject and registered sessions receive an SDK error event. The parent client remains reusable and reconnects on the next new operation; old session handles do not silently migrate. A transport-detached old handle cannot call session.resume(); resume an intentional surviving session with resumeSession(sessionId).

Sandbox is the default. Full Access requires three separate conditions: an Instance created with runtimeFullAccess: true, explicit user approval of both Allow Agent Sessions and Allow Full Runtime Access in the Extension, and runtimeFullAccess: true on session creation.

const privileged = new Pedelec({ runtimeFullAccess: true });
// After the user explicitly grants both permissions in the Extension:
const sandbox = await privileged.createSession({ runtimeFullAccess: false });
const full = await privileged.createSession({ runtimeFullAccess: true });

Review the Extension permissions before creating sessions. An Instance requesting Full Access cannot create any session with only the Agent Sessions grant, including a Sandbox session. A standard Instance cannot request a Full Access session, even if another Instance on the same Origin has permission. Ordinary Origin approval never substitutes for the Full Access grant; the Popup offers an additional permission review with Full Access unchecked by default. getApprovalStatus() only reads status and does not open that review.

The Thread mode is fixed at creation and preserved on resume. Instances on the same Origin and Threads in the same Workspace retain their own requested modes. workspace.run() defaults to Sandbox and can request Full Access per invocation, and Provider sandbox settings are unchanged. Full Access changes the TypeScript Runtime’s OS permissions only. Revoking the Full Access grant rejects subsequent high-privilege execution and attempts to cancel affected running processes; unrelated Origins retain their grants.

Upgrade the SDK, Extension, and Desktop together when using Full Access. Missing mode acknowledgment is an error, never a successful downgrade. See Error Codes for authorization and protocol failures.