Batuhan/pi 2#6
Conversation
Introduce a new @beeper/pickle-pi package (package.json, README, tsconfig and a large set of src/tests) as the Beeper-first Pi appservice/bridge skeleton. Add an HTTPProxyHandlingBridgeConnector type and wire runtime handling: RuntimeBridge now exposes getOwnUserId() and will delegate provisioning HTTP requests to connector.handleHTTPProxy when present. Update bridge types to include getOwnUserId and the new connector interface, and adjust workspace/tsconfig to include the new package.
Introduce a new media-store module to save/read Matrix media with stable ids and sidecar metadata (saveMediaBuffer, saveMatrixAttachment, readMediaBuffer/readStoredMedia, helpers for mime/kind/id). Add media-store tests and export it from the package index. Extend rooms to support fork and subagent metadata (createForkMetadata, createSubagentMetadata) and accept them when creating session rooms. Expand types with PicklePiForkMetadata, PicklePiSubagentMetadata, and binding kind/subagent/fork fields. Enhance the registry with additional lookup helpers (by id, by cwd, child/subagent bindings), updateBinding and setActiveLeaf methods, and add tests to cover indexing child and subagent bindings.
Initialize the Beeper appservice in bridge entrypoints and construct RuntimeBridge with appservice info (homeserver/token) instead of the previous client helper. This adds createBeeperAppServiceInit usage and wires appservice.registration.asToken and homeserver into matrix config, and passes appservice + beeper metadata into RuntimeBridge (packages/bridge/src/index.ts, node.ts). Also extend approval handling: add session/room approval reaction constants and decision types, normalize hyphenated decision values, and update parsing logic to derive approvedAlways and decision correctly. Tests updated to cover new allow_session/allow_room cases (packages/pi/src/*).
Propagate appservice configuration through the bridge and pickle stacks so bridges can initialize Matrix clients as appservice bots. Key changes: - Bridge: add BridgeMatrixConfig.appservice and set matrix.appservice/homeserver/token from the created appservice when building beeper bridges; introduce createBeeperRuntimeOptions helper and return RuntimeBridge with the assembled runtime options. - Pickle native (Go): extend MatrixCoreInitOptions with Appservice, extract client init logic into initClient which handles both appservice login (verifies flows and logs in as appservice bot) and normal token-based clients. - Pickle JS: pass the appservice option through to core.init and update generated/runtime types and MatrixClientOptions to include appservice. These changes enable using the appservice registration/token for homeserver, token and bot identity instead of relying solely on an account access token.
Expose an initialState option for portal room creation and propagate it through types, runtime, and native appservice code so initial state events are included on room creation. Allow callers to provide an existing appservice via options.matrix?.appservice (prefer it over creating a new one) in bridge factory functions and propagate the resolved appservice into the matrix config. Also include a small provisioning change (query value in test and conservative lookup in provisioningLogin).
Avoid awaiting each publishBeeperStreamPart call serially by introducing a publishPart helper that fires publishes, tracks them in a pendingPublishes set, logs errors, and removes completed promises. A waitForPublishes call ensures all publishes finish before editing the final message. Also set preliminary: false on tool execution end UI chunks to mark tool output as final.
Add exports for beeper-stream and pi-event-map and update tsdown entries. Apply initialMessageMetadata to outgoing messages and include messageMetadata in finalize; allow a terminalPart override. Extend final-message accumulator to track tool input text and tool names, add ensureToolPart and parseMaybeJSON to assemble tool parts and finalize content. Improve event mapping to handle text/thinking start/end and toolcall_start/delta/end, normalize tool outputs and parse stringified arguments. Update stream mapping to include dynamic flag, timestamps and preliminary/completed fields on tool parts.
Extract open/close helpers for text and reasoning parts and use them across the stream mapping logic. mapPiMessageDelta and closeOpenMessageParts now delegate to openTextPart/openReasoningPart and closeTextPart/closeReasoningPart to avoid duplicate starts and centralize id management. pi-event-map was updated to use the new helpers for assistant message events. Narrowed BeeperStreamPublisherClient.messages to only include edit/send. Tests updated to reflect the new start/delta/end chunk behavior.
Set room name when events include a generated session title and tidy up notice wording. Add piEventSessionTitle and call it from the appservice to send an m.room.name state event. Adjust piEventNoticeText wording (remove redundant "Pi" prefixes, improve queue phrasing, sentence-case thinking levels, change "aborted"→"canceled", simplify retry labels) and add a sentenceCase helper. Update tests to cover session title extraction and the revised notice texts.
Add end-to-end support for appservice transactions: a new test ensures transactions are forwarded before acknowledgement. AppserviceWebsocket gains a handleTransaction option and invokes it when transactions arrive. RuntimeBridge forwards transactions to matrixClient.appservice.applyTransaction via a new handler. Native Pickle core adds an appservice_apply_transaction operation, a transaction options/type, a beeperStream event processor for dispatching transaction events, and wiring into initialization. Client and generated runtime types are updated to expose applyTransaction. Also set beeper: true in matrix configs when creating bridges.
Add content compaction to ensure final Matrix event content stays under a 60 KiB limit. Introduce MAX_MATRIX_EVENT_CONTENT_BYTES and compactFinalContent which trims and restructures the AI message (via compactAIMessage, compactParts, compactMetadata) and the body (truncateWithNotice) while preserving tool call metadata when possible. Add helpers eventContentBytes and copyDefined and adjust finalize flow to use the compacted content before editing the event. Also add a test verifying large tool output is compacted without dropping text or tool call information.
Multiple fixes and enhancements across bridge, pi, and native core packages: - bridge: include txn_id from the HTTP PUT path into the transaction object so handlers receive the transaction id; update websocket tests to gate and assert handling behavior. - beeper: treat null the same as undefined in booleanField so null values are ignored. - beeper-stream: add support for reusing an existing target message descriptor (messages.get), ensure publish does not mutate final content/sequence on failed publishes by only advancing seq and applying final part after a successful publish; added tests for reuse and failure behavior. - pi agent/cli: catch and log errors from headless session prompt and send an m.notice on failure; set process.exitCode=1 when printing CLI usage. - pi internals: tighten path checks in media-store by resolving paths, improve tool input/ID mapping in pi-event-map, make pi-notice labels robust when attempt is undefined, and improve errorText fallback. - pi runtime/native core: ensure PICKLE_PI_OWNED_SESSION env var is restored after session creation, clear appserviceProcessor on shutdown, and return an explicit error when the appservice transaction pipeline is unavailable. Includes corresponding tests and minor refactors to support these behaviors.
Add package exports for config, media-store, rooms, spaces, and types (pointing to their .mjs and .d.mts build outputs). Update tsdown.config.ts entries to include the corresponding source files (config.ts, media-store.ts, rooms.ts, spaces.ts, types.ts) so docs/type artifacts are generated for those modules.
Inject a configurable BridgeLogger into the runtime bridge and replace usages of defaultLogger with the injected logger. Add log option to CreateBridgeOptions and propagate it through createBeeperBridge. Improve appservice transaction handling to recognize MSC2409 unstable to_device field, log stream-related transactions, and parse/dispatch MSC2409 to_device events. Include recording/debug logs when creating, registering and publishing beeper streams and when processing stream syncs. Make beeper stream edits keep a subscribable stream descriptor (instead of null) and include the stream descriptor in event size calculations so final content compaction accounts for it. Update types and client event mapping to surface beeper stream update events, and add/adjust tests to cover stream subscribe/update mapping and MSC2409 handling. Also add a small isRecord helper and related minor refactors.
# Conflicts: # packages/pi/src/appservice.test.ts # packages/pi/src/beeper-stream.test.ts # packages/pi/src/beeper-stream.ts # packages/pickle/native/internal/core/appservice_test.go # packages/pickle/native/internal/core/core.go # packages/pickle/native/internal/core/messages.go # packages/pickle/src/client.test.ts # packages/pickle/src/streams/beeper.ts # packages/pickle/src/types.ts
|
Warning Rate limit exceeded
You’ve run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (17)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
No description provided.