@naeemo/capnp 0.2.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rpc-connection-BKWQQ7f9.js","names":[],"sources":["../src/rpc/four-tables.ts","../src/rpc/pipeline.ts","../src/rpc/rpc-connection.ts"],"sourcesContent":["/**\n * The Four Tables\n *\n * Cap'n Proto RPC connections maintain four state tables per connection:\n * - Questions: Outbound calls awaiting answers\n * - Answers: Inbound calls being processed\n * - Imports: Capabilities received from remote\n * - Exports: Capabilities sent to remote\n *\n * See: http://www.erights.org/elib/distrib/captp/4tables.html\n */\n\nimport type { AnswerId, ExportId, ImportId, QuestionId, RpcMessage } from './rpc-types.js';\n\n// ========================================================================================\n// Question Table\n// ========================================================================================\n\n/** Entry in the question table (outbound calls) */\nexport interface Question {\n id: QuestionId;\n /** Whether the call has completed */\n isComplete: boolean;\n /** Whether a Finish message has been sent */\n finishSent: boolean;\n /** Promise that resolves when the call completes */\n completionPromise: Promise<unknown>;\n /** Resolve function for the completion promise */\n resolveCompletion: (value: unknown) => void;\n /** Reject function for the completion promise */\n rejectCompletion: (error: Error) => void;\n}\n\n/** Manages the question table for outbound calls */\nexport class QuestionTable {\n private questions = new Map<QuestionId, Question>();\n private nextId = 1;\n\n /** Create a new question entry */\n create(): Question {\n const id = this.allocateId();\n let resolveCompletion: (value: unknown) => void;\n let rejectCompletion: (error: Error) => void;\n\n const completionPromise = new Promise<unknown>((resolve, reject) => {\n resolveCompletion = resolve;\n rejectCompletion = reject;\n });\n\n const question: Question = {\n id,\n isComplete: false,\n finishSent: false,\n completionPromise,\n resolveCompletion: resolveCompletion!,\n rejectCompletion: rejectCompletion!,\n };\n\n this.questions.set(id, question);\n return question;\n }\n\n /** Get a question by ID */\n get(id: QuestionId): Question | undefined {\n return this.questions.get(id);\n }\n\n /** Mark a question as complete */\n complete(id: QuestionId, result: unknown): void {\n const question = this.questions.get(id);\n if (question && !question.isComplete) {\n question.isComplete = true;\n question.resolveCompletion(result);\n }\n }\n\n /** Mark a question as canceled */\n cancel(id: QuestionId, error: Error): void {\n const question = this.questions.get(id);\n if (question && !question.isComplete) {\n question.isComplete = true;\n question.rejectCompletion(error);\n }\n }\n\n /** Mark that Finish has been sent for a question */\n markFinishSent(id: QuestionId): void {\n const question = this.questions.get(id);\n if (question) {\n question.finishSent = true;\n }\n }\n\n /** Remove a question from the table (when both sides are done) */\n remove(id: QuestionId): void {\n const question = this.questions.get(id);\n if (question?.isComplete && question.finishSent) {\n this.questions.delete(id);\n }\n }\n\n /** Clean up all questions (e.g., on disconnect) */\n clear(): void {\n for (const question of this.questions.values()) {\n if (!question.isComplete) {\n question.rejectCompletion(new Error('Connection closed'));\n }\n }\n this.questions.clear();\n this.nextId = 1;\n }\n\n private allocateId(): QuestionId {\n // Simple allocation - in production, reuse freed IDs\n return this.nextId++;\n }\n}\n\n// ========================================================================================\n// Answer Table\n// ========================================================================================\n\n/** Entry in the answer table (inbound calls) */\nexport interface Answer {\n id: AnswerId;\n /** Whether the call has completed */\n isComplete: boolean;\n /** Whether a Return message has been sent */\n returnSent: boolean;\n /** Whether a Finish message has been received */\n finishReceived: boolean;\n /** The result of the call (if complete) */\n result?: unknown;\n}\n\n/** Manages the answer table for inbound calls */\nexport class AnswerTable {\n private answers = new Map<AnswerId, Answer>();\n\n /** Create a new answer entry */\n create(id: AnswerId): Answer {\n const answer: Answer = {\n id,\n isComplete: false,\n returnSent: false,\n finishReceived: false,\n };\n this.answers.set(id, answer);\n return answer;\n }\n\n /** Get an answer by ID */\n get(id: AnswerId): Answer | undefined {\n return this.answers.get(id);\n }\n\n /** Mark that Return has been sent */\n markReturnSent(id: AnswerId): void {\n const answer = this.answers.get(id);\n if (answer) {\n answer.returnSent = true;\n }\n }\n\n /** Mark that Finish has been received */\n markFinishReceived(id: AnswerId): void {\n const answer = this.answers.get(id);\n if (answer) {\n answer.finishReceived = true;\n }\n }\n\n /** Remove an answer from the table (when both sides are done) */\n remove(id: AnswerId): void {\n const answer = this.answers.get(id);\n if (answer?.returnSent && answer.finishReceived) {\n this.answers.delete(id);\n }\n }\n\n /** Clean up all answers (e.g., on disconnect) */\n clear(): void {\n this.answers.clear();\n }\n}\n\n// ========================================================================================\n// Import Table\n// ========================================================================================\n\n/** Entry in the import table (capabilities from remote) */\nexport interface Import {\n id: ImportId;\n /** Reference count */\n refCount: number;\n /** Whether this is a promise (not yet resolved) */\n isPromise: boolean;\n}\n\n/** Manages the import table for capabilities received from remote */\nexport class ImportTable {\n private imports = new Map<ImportId, Import>();\n\n /** Add a new import */\n add(id: ImportId, isPromise: boolean): Import {\n const importEntry: Import = {\n id,\n refCount: 1,\n isPromise,\n };\n this.imports.set(id, importEntry);\n return importEntry;\n }\n\n /** Get an import by ID */\n get(id: ImportId): Import | undefined {\n return this.imports.get(id);\n }\n\n /** Increment reference count */\n addRef(id: ImportId): void {\n const importEntry = this.imports.get(id);\n if (importEntry) {\n importEntry.refCount++;\n }\n }\n\n /** Decrement reference count, returns true if refCount reached 0 */\n release(id: ImportId, count: number): boolean {\n const importEntry = this.imports.get(id);\n if (importEntry) {\n importEntry.refCount -= count;\n if (importEntry.refCount <= 0) {\n this.imports.delete(id);\n return true;\n }\n }\n return false;\n }\n\n /** Mark a promise as resolved */\n markResolved(id: ImportId): void {\n const importEntry = this.imports.get(id);\n if (importEntry) {\n importEntry.isPromise = false;\n }\n }\n\n /** Clean up all imports (e.g., on disconnect) */\n clear(): void {\n this.imports.clear();\n }\n}\n\n// ========================================================================================\n// Export Table\n// ========================================================================================\n\n/** Entry in the export table (capabilities sent to remote) */\nexport interface Export {\n id: ExportId;\n /** Reference count */\n refCount: number;\n /** Whether this is a promise (not yet resolved) */\n isPromise: boolean;\n /** The actual capability object */\n capability: unknown;\n}\n\n/** Manages the export table for capabilities sent to remote */\nexport class ExportTable {\n private exports = new Map<ExportId, Export>();\n private nextId = 1;\n\n /** Add a new export */\n add(capability: unknown, isPromise: boolean): Export {\n const id = this.allocateId();\n const exportEntry: Export = {\n id,\n refCount: 1,\n isPromise,\n capability,\n };\n this.exports.set(id, exportEntry);\n return exportEntry;\n }\n\n /** Get an export by ID */\n get(id: ExportId): Export | undefined {\n return this.exports.get(id);\n }\n\n /** Increment reference count */\n addRef(id: ExportId): void {\n const exportEntry = this.exports.get(id);\n if (exportEntry) {\n exportEntry.refCount++;\n }\n }\n\n /** Decrement reference count, returns true if refCount reached 0 */\n release(id: ExportId, count: number): boolean {\n const exportEntry = this.exports.get(id);\n if (exportEntry) {\n exportEntry.refCount -= count;\n if (exportEntry.refCount <= 0) {\n this.exports.delete(id);\n return true;\n }\n }\n return false;\n }\n\n /** Mark a promise as resolved */\n markResolved(id: ExportId): void {\n const exportEntry = this.exports.get(id);\n if (exportEntry) {\n exportEntry.isPromise = false;\n }\n }\n\n /** Clean up all exports (e.g., on disconnect) */\n clear(): void {\n this.exports.clear();\n this.nextId = 1;\n }\n\n private allocateId(): ExportId {\n // Simple allocation - in production, reuse freed IDs\n return this.nextId++;\n }\n}\n","/**\n * Promise Pipelining Implementation\n *\n * Phase 2: Level 1 RPC Feature\n *\n * Promise Pipelining allows making calls on results that haven't arrived yet,\n * dramatically reducing latency in distributed systems.\n *\n * Key concepts:\n * - PipelineClient: A proxy that represents a promised answer\n * - PipelineOp: Operations to transform the promised answer (field access)\n * - Queued calls: Calls made on pipeline clients before the answer arrives\n */\n\nimport type { RpcConnection } from './rpc-connection.js';\nimport type {\n Call,\n ImportId,\n InterfaceId,\n MethodId,\n Payload,\n PromisedAnswer,\n PromisedAnswerOp,\n QuestionId,\n} from './rpc-types.js';\n\n// ========================================================================================\n// PipelineOp - Operations on promised answers\n// ========================================================================================\n\n/**\n * Tracks a chain of operations to apply to a promised answer.\n * This forms the \"transform\" field in PromisedAnswer.\n */\nexport class PipelineOpTracker {\n private ops: PromisedAnswerOp[] = [];\n\n /**\n * Add a no-op (use the result as-is)\n */\n addNoop(): void {\n this.ops.push({ type: 'noop' });\n }\n\n /**\n * Add a pointer field access operation\n */\n addGetPointerField(fieldIndex: number): void {\n this.ops.push({ type: 'getPointerField', fieldIndex });\n }\n\n /**\n * Get the current transform chain\n */\n getTransform(): PromisedAnswerOp[] {\n return [...this.ops];\n }\n\n /**\n * Clone this tracker (for creating derived pipelines)\n */\n clone(): PipelineOpTracker {\n const cloned = new PipelineOpTracker();\n cloned.ops = [...this.ops];\n return cloned;\n }\n}\n\n// ========================================================================================\n// PipelineClient - Proxy for promised answers\n// ========================================================================================\n\n/**\n * Symbol used to identify pipeline clients internally\n */\nexport const PIPELINE_CLIENT_SYMBOL = Symbol('PipelineClient');\n\n/**\n * Interface for pipeline client capabilities\n */\nexport interface PipelineClient {\n readonly [PIPELINE_CLIENT_SYMBOL]: true;\n readonly connection: RpcConnection;\n readonly questionId: QuestionId;\n readonly opTracker: PipelineOpTracker;\n\n /**\n * Make a pipelined call on this promised answer\n */\n call(interfaceId: InterfaceId, methodId: MethodId, params: Payload): Promise<unknown>;\n\n /**\n * Get a pipeline client for a field of this promised answer\n */\n getPointerField(fieldIndex: number): PipelineClient;\n}\n\n/**\n * Options for creating a PipelineClient\n */\nexport interface PipelineClientOptions {\n connection: RpcConnection;\n questionId: QuestionId;\n opTracker?: PipelineOpTracker;\n}\n\n/**\n * Creates a PipelineClient using JavaScript Proxy.\n * The proxy intercepts property accesses to build up the transform chain.\n */\nexport function createPipelineClient(options: PipelineClientOptions): PipelineClient {\n const { connection, questionId, opTracker = new PipelineOpTracker() } = options;\n\n // The base pipeline client object\n const baseClient: PipelineClient = {\n [PIPELINE_CLIENT_SYMBOL]: true,\n connection,\n questionId,\n opTracker,\n\n call(interfaceId: InterfaceId, methodId: MethodId, params: Payload): Promise<unknown> {\n return makePipelinedCall(\n connection,\n questionId,\n opTracker.getTransform(),\n interfaceId,\n methodId,\n params\n );\n },\n\n getPointerField(fieldIndex: number): PipelineClient {\n const newTracker = opTracker.clone();\n newTracker.addGetPointerField(fieldIndex);\n return createPipelineClient({\n connection,\n questionId,\n opTracker: newTracker,\n });\n },\n };\n\n return baseClient;\n}\n\n/**\n * Check if a value is a PipelineClient\n */\nexport function isPipelineClient(value: unknown): value is PipelineClient {\n return typeof value === 'object' && value !== null && PIPELINE_CLIENT_SYMBOL in value;\n}\n\n// ========================================================================================\n// Pipelined Call Implementation\n// ========================================================================================\n\n/**\n * Makes a call on a promised answer (pipeline call).\n * This sends a Call message with target.type = 'promisedAnswer'.\n */\nasync function makePipelinedCall(\n connection: RpcConnection,\n questionId: QuestionId,\n transform: PromisedAnswerOp[],\n interfaceId: InterfaceId,\n methodId: MethodId,\n params: Payload\n): Promise<unknown> {\n // Create a new question for this pipelined call\n const newQuestionId = connection.createQuestion();\n\n const call: Call = {\n questionId: newQuestionId,\n target: {\n type: 'promisedAnswer',\n promisedAnswer: {\n questionId,\n transform,\n },\n },\n interfaceId,\n methodId,\n allowThirdPartyTailCall: false,\n noPromisePipelining: false,\n onlyPromisePipeline: false,\n params,\n sendResultsTo: { type: 'caller' },\n };\n\n await connection.sendCall(call);\n\n // Return a promise that resolves when the answer arrives\n return connection.waitForAnswer(newQuestionId);\n}\n\n// ========================================================================================\n// Queued Calls Management\n// ========================================================================================\n\n/**\n * Represents a queued call waiting for a promise to resolve\n */\nexport interface QueuedCall {\n interfaceId: InterfaceId;\n methodId: MethodId;\n params: Payload;\n resolve: (value: unknown) => void;\n reject: (error: Error) => void;\n}\n\n/**\n * Manages calls that were made on a pipeline client before the answer arrived.\n * When the answer arrives, these calls are dispatched to the actual capability.\n */\nexport class QueuedCallManager {\n private queuedCalls = new Map<QuestionId, QueuedCall[]>();\n\n /**\n * Queue a call for when the promise resolves\n */\n queueCall(questionId: QuestionId, call: QueuedCall): void {\n const calls = this.queuedCalls.get(questionId) ?? [];\n calls.push(call);\n this.queuedCalls.set(questionId, calls);\n }\n\n /**\n * Get and clear all queued calls for a question\n */\n dequeueCalls(questionId: QuestionId): QueuedCall[] {\n const calls = this.queuedCalls.get(questionId) ?? [];\n this.queuedCalls.delete(questionId);\n return calls;\n }\n\n /**\n * Check if there are queued calls for a question\n */\n hasQueuedCalls(questionId: QuestionId): boolean {\n return (this.queuedCalls.get(questionId)?.length ?? 0) > 0;\n }\n\n /**\n * Clear all queued calls (e.g., on disconnect)\n */\n clear(): void {\n // Reject all pending calls\n for (const calls of this.queuedCalls.values()) {\n for (const call of calls) {\n call.reject(new Error('Connection closed'));\n }\n }\n this.queuedCalls.clear();\n }\n}\n\n// ========================================================================================\n// Capability Resolution\n// ========================================================================================\n\n/**\n * Represents a resolved capability (either a real capability or an error)\n */\nexport type ResolvedCapability =\n | { type: 'capability'; importId: ImportId }\n | { type: 'exception'; reason: string };\n\n/**\n * Tracks pending pipeline resolutions\n */\nexport class PipelineResolutionTracker {\n private pendingResolutions = new Map<QuestionId, ResolvedCapability>();\n\n /**\n * Mark a question as resolved to a capability\n */\n resolveToCapability(questionId: QuestionId, importId: ImportId): void {\n this.pendingResolutions.set(questionId, { type: 'capability', importId });\n }\n\n /**\n * Mark a question as resolved to an exception\n */\n resolveToException(questionId: QuestionId, reason: string): void {\n this.pendingResolutions.set(questionId, { type: 'exception', reason });\n }\n\n /**\n * Get the resolution for a question (if available)\n */\n getResolution(questionId: QuestionId): ResolvedCapability | undefined {\n return this.pendingResolutions.get(questionId);\n }\n\n /**\n * Check if a question has been resolved\n */\n isResolved(questionId: QuestionId): boolean {\n return this.pendingResolutions.has(questionId);\n }\n\n /**\n * Remove a resolution entry\n */\n remove(questionId: QuestionId): void {\n this.pendingResolutions.delete(questionId);\n }\n\n /**\n * Clear all resolutions\n */\n clear(): void {\n this.pendingResolutions.clear();\n }\n}\n","/**\n * RpcConnection\n *\n * Manages a single RPC connection, handling message routing and the Four Tables.\n * This is the core of the RPC implementation.\n *\n * Phase 2 Updates:\n * - Added Promise Pipelining support\n * - Added capability passing\n * - Added Resolve/Release/Disembargo message handling\n *\n * Phase 4 Updates:\n * - Added Level 3 RPC support (Provide/Accept)\n * - Added third-party capability handling\n * - Integrated with ConnectionManager for multi-vat scenarios\n */\n\nimport type { ConnectionManager, VatId } from './connection-manager.js';\nimport { AnswerTable, ExportTable, ImportTable, QuestionTable } from './four-tables.js';\nimport type { Level3Handlers } from './level3-handlers.js';\nimport type { Level4Handlers } from './level4-handlers.js';\nimport {\n type PipelineClient,\n PipelineOpTracker,\n PipelineResolutionTracker,\n QueuedCallManager,\n createPipelineClient,\n isPipelineClient,\n} from './pipeline.js';\nimport type {\n Accept,\n AnswerId,\n Bootstrap,\n Call,\n CapDescriptor,\n Disembargo,\n ExportId,\n Finish,\n ImportId,\n Join,\n Payload,\n PromisedAnswerOp,\n Provide,\n QuestionId,\n Release,\n Resolve,\n Return,\n RpcMessage,\n ThirdPartyCapId,\n} from './rpc-types.js';\nimport type { RpcTransport } from './transport.js';\n\nexport interface RpcConnectionOptions {\n /** Bootstrap capability to expose to the peer */\n bootstrap?: unknown;\n /** This vat's ID (for Level 3 RPC) */\n selfVatId?: VatId;\n /** Connection manager for Level 3 RPC */\n connectionManager?: ConnectionManager;\n /** Level 3 message handlers */\n level3Handlers?: Level3Handlers;\n /** Level 4 message handlers */\n level4Handlers?: Level4Handlers;\n}\n\nexport class RpcConnection {\n private transport: RpcTransport;\n private options: RpcConnectionOptions;\n\n // The Four Tables\n private questions = new QuestionTable();\n private answers = new AnswerTable();\n private imports = new ImportTable();\n private exports = new ExportTable();\n\n // Phase 2: Pipeline support\n private queuedCalls = new QueuedCallManager();\n private pipelineResolutions = new PipelineResolutionTracker();\n\n // Message processing\n private running = false;\n private messageHandler?: Promise<void>;\n\n // Phase 4: Level 3 handlers\n private level3Handlers?: Level3Handlers;\n\n // Phase 6: Level 4 handlers\n private level4Handlers?: Level4Handlers;\n\n constructor(transport: RpcTransport, options: RpcConnectionOptions = {}) {\n this.transport = transport;\n this.options = options;\n this.level3Handlers = options.level3Handlers;\n\n // Set up transport event handlers\n this.transport.onClose = (reason) => {\n this.handleDisconnect(reason);\n };\n\n this.transport.onError = (error) => {\n this.handleError(error);\n };\n\n // Set up Level 3 and Level 4 handlers\n this.level3Handlers = options.level3Handlers;\n this.level4Handlers = options.level4Handlers;\n }\n\n /** Start processing messages */\n async start(): Promise<void> {\n if (this.running) return;\n\n this.running = true;\n this.messageHandler = this.messageLoop();\n }\n\n /** Stop the connection */\n async stop(): Promise<void> {\n this.running = false;\n this.transport.close();\n\n if (this.messageHandler) {\n try {\n await this.messageHandler;\n } catch {\n // Ignore errors during shutdown\n }\n }\n }\n\n /** Send a bootstrap request and return the bootstrap capability */\n async bootstrap(): Promise<unknown> {\n const question = this.questions.create();\n\n const bootstrapMsg: RpcMessage = {\n type: 'bootstrap',\n bootstrap: {\n questionId: question.id,\n },\n };\n\n await this.transport.send(bootstrapMsg);\n\n // Wait for the bootstrap response\n await question.completionPromise;\n\n // Return the bootstrap capability\n // In full implementation, this would extract the capability from the response\n return {};\n }\n\n /** Make a call to a remote capability */\n async call(\n target: ImportId | ExportId | PipelineClient,\n interfaceId: bigint,\n methodId: number,\n params: Payload\n ): Promise<unknown> {\n // Check if target is a pipeline client\n if (isPipelineClient(target)) {\n return target.call(interfaceId, methodId, params);\n }\n\n const question = this.questions.create();\n\n const callMsg: RpcMessage = {\n type: 'call',\n call: {\n questionId: question.id,\n target: { type: 'importedCap', importId: target as ImportId },\n interfaceId,\n methodId,\n allowThirdPartyTailCall: false,\n noPromisePipelining: false,\n onlyPromisePipeline: false,\n params,\n sendResultsTo: { type: 'caller' },\n },\n };\n\n await this.transport.send(callMsg);\n\n // Wait for the call to complete\n return question.completionPromise;\n }\n\n /**\n * Make a call that returns a PipelineClient for promise pipelining.\n * This allows making calls on the result before it arrives.\n */\n async callPipelined(\n target: ImportId | ExportId,\n interfaceId: bigint,\n methodId: number,\n params: Payload\n ): Promise<PipelineClient> {\n const question = this.questions.create();\n\n const callMsg: RpcMessage = {\n type: 'call',\n call: {\n questionId: question.id,\n target: { type: 'importedCap', importId: target },\n interfaceId,\n methodId,\n allowThirdPartyTailCall: false,\n noPromisePipelining: false,\n onlyPromisePipeline: false,\n params,\n sendResultsTo: { type: 'caller' },\n },\n };\n\n await this.transport.send(callMsg);\n\n // Return a pipeline client immediately without waiting\n return createPipelineClient({\n connection: this,\n questionId: question.id,\n });\n }\n\n /** Send a finish message to release a question */\n async finish(questionId: QuestionId, releaseResultCaps = true): Promise<void> {\n const question = this.questions.get(questionId);\n if (!question) return;\n\n const finishMsg: RpcMessage = {\n type: 'finish',\n finish: {\n questionId,\n releaseResultCaps,\n requireEarlyCancellationWorkaround: false,\n },\n };\n\n await this.transport.send(finishMsg);\n this.questions.markFinishSent(questionId);\n this.questions.remove(questionId);\n }\n\n /** Send a release message for an imported capability */\n async release(importId: ImportId, referenceCount = 1): Promise<void> {\n const releaseMsg: RpcMessage = {\n type: 'release',\n release: {\n id: importId,\n referenceCount,\n },\n };\n\n await this.transport.send(releaseMsg);\n }\n\n /** Send a resolve message to indicate a promise has resolved */\n async resolve(promiseId: ExportId, cap: CapDescriptor): Promise<void> {\n const resolveMsg: RpcMessage = {\n type: 'resolve',\n resolve: {\n promiseId,\n resolution: { type: 'cap', cap },\n },\n };\n\n await this.transport.send(resolveMsg);\n }\n\n /** Send a resolve message indicating a promise was broken */\n async resolveException(promiseId: ExportId, reason: string): Promise<void> {\n const resolveMsg: RpcMessage = {\n type: 'resolve',\n resolve: {\n promiseId,\n resolution: {\n type: 'exception',\n exception: { reason, type: 'failed' },\n },\n },\n };\n\n await this.transport.send(resolveMsg);\n }\n\n /** Send a return message (internal use) */\n async sendReturn(ret: Return): Promise<void> {\n const returnMsg: RpcMessage = { type: 'return', return: ret };\n await this.transport.send(returnMsg);\n }\n\n /** Send a disembargo message (internal use) */\n async sendDisembargo(disembargo: Disembargo): Promise<void> {\n const disembargoMsg: RpcMessage = { type: 'disembargo', disembargo };\n await this.transport.send(disembargoMsg);\n }\n\n /** Internal method: Create a new question (used by pipeline) */\n createQuestion(): QuestionId {\n const question = this.questions.create();\n return question.id;\n }\n\n /** Internal method: Send a call message (used by pipeline) */\n async sendCall(call: Call): Promise<void> {\n const callMsg: RpcMessage = { type: 'call', call };\n await this.transport.send(callMsg);\n }\n\n /** Internal method: Wait for an answer (used by pipeline) */\n async waitForAnswer(questionId: QuestionId): Promise<unknown> {\n const question = this.questions.get(questionId);\n if (!question) {\n throw new Error(`Question ${questionId} not found`);\n }\n return question.completionPromise;\n }\n\n /** Main message processing loop */\n private async messageLoop(): Promise<void> {\n while (this.running) {\n try {\n const message = await this.transport.receive();\n\n if (message === null) {\n // Connection closed\n break;\n }\n\n await this.handleMessage(message);\n } catch (error) {\n if (this.running) {\n this.handleError(error as Error);\n }\n }\n }\n }\n\n /** Handle incoming messages */\n private async handleMessage(message: RpcMessage): Promise<void> {\n switch (message.type) {\n case 'bootstrap':\n await this.handleBootstrap(message.bootstrap);\n break;\n case 'call':\n await this.handleCall(message.call);\n break;\n case 'return':\n await this.handleReturn(message.return);\n break;\n case 'finish':\n await this.handleFinish(message.finish);\n break;\n case 'resolve':\n await this.handleResolve(message.resolve);\n break;\n case 'release':\n await this.handleRelease(message.release);\n break;\n case 'disembargo':\n await this.handleDisembargo(message.disembargo);\n break;\n // Level 3 message types\n case 'provide':\n await this.handleProvide(message.provide);\n break;\n case 'accept':\n await this.handleAccept(message.accept);\n break;\n // Level 4 message types\n case 'join':\n await this.handleJoin(message.join);\n break;\n case 'abort':\n this.handleAbort(message.exception.reason);\n break;\n case 'unimplemented':\n // Handle unimplemented message\n break;\n default:\n // Send unimplemented response\n await this.sendUnimplemented(message);\n }\n }\n\n /** Handle bootstrap request */\n private async handleBootstrap(bootstrap: Bootstrap): Promise<void> {\n // Create answer entry\n this.answers.create(bootstrap.questionId);\n\n // Return the bootstrap capability\n const returnMsg: RpcMessage = {\n type: 'return',\n return: {\n answerId: bootstrap.questionId,\n releaseParamCaps: true,\n noFinishNeeded: false,\n result: {\n type: 'results',\n payload: {\n content: new Uint8Array(0),\n capTable: [],\n },\n },\n },\n };\n\n await this.transport.send(returnMsg);\n this.answers.markReturnSent(bootstrap.questionId);\n }\n\n /** Handle incoming call */\n private async handleCall(call: Call): Promise<void> {\n // Create answer entry\n this.answers.create(call.questionId);\n\n // TODO: Dispatch to the appropriate capability/method\n // For Phase 1, we'll return a placeholder result\n\n const returnMsg: RpcMessage = {\n type: 'return',\n return: {\n answerId: call.questionId,\n releaseParamCaps: true,\n noFinishNeeded: false,\n result: {\n type: 'exception',\n exception: {\n reason: 'Method not implemented',\n type: 'unimplemented',\n },\n },\n },\n };\n\n await this.transport.send(returnMsg);\n this.answers.markReturnSent(call.questionId);\n }\n\n /** Handle return message */\n private async handleReturn(ret: Return): Promise<void> {\n const question = this.questions.get(ret.answerId);\n if (!question) return;\n\n // Track pipeline resolution\n if (ret.result.type === 'results') {\n // Check if result contains a capability\n const capTable = ret.result.payload.capTable;\n if (capTable.length > 0) {\n const cap = capTable[0];\n if (cap.type === 'receiverHosted') {\n this.pipelineResolutions.resolveToCapability(ret.answerId, cap.importId);\n } else if (cap.type === 'thirdPartyHosted') {\n // Level 3: Handle third-party capability\n await this.handleThirdPartyCapability(ret.answerId, cap.thirdPartyCapId);\n }\n }\n } else if (ret.result.type === 'exception') {\n this.pipelineResolutions.resolveToException(ret.answerId, ret.result.exception.reason);\n }\n\n switch (ret.result.type) {\n case 'results':\n this.questions.complete(ret.answerId, ret.result.payload);\n break;\n case 'exception':\n this.questions.cancel(ret.answerId, new Error(ret.result.exception.reason));\n break;\n case 'canceled':\n this.questions.cancel(ret.answerId, new Error('Call canceled'));\n break;\n case 'acceptFromThirdParty':\n // Level 3: Need to contact third party to get results\n await this.handleAcceptFromThirdParty(ret.answerId, ret.result.thirdPartyCapId);\n break;\n default:\n this.questions.cancel(ret.answerId, new Error('Unknown return type'));\n }\n }\n\n /** Handle finish message */\n private async handleFinish(finish: Finish): Promise<void> {\n this.answers.markFinishReceived(finish.questionId);\n this.answers.remove(finish.questionId);\n }\n\n /** Handle resolve message (Level 1) */\n private async handleResolve(resolve: Resolve): Promise<void> {\n const { promiseId, resolution } = resolve;\n\n switch (resolution.type) {\n case 'cap':\n // The promise resolved to a capability\n // Update import table to mark as resolved\n this.imports.markResolved(promiseId);\n break;\n case 'exception':\n // The promise was broken\n // TODO: Handle broken promise - notify pending calls\n console.warn(`Promise ${promiseId} broken: ${resolution.exception.reason}`);\n break;\n }\n }\n\n /** Handle release message (Level 1) */\n private async handleRelease(release: Release): Promise<void> {\n const { id, referenceCount } = release;\n\n // Release the export\n const shouldRemove = this.exports.release(id, referenceCount);\n if (shouldRemove) {\n // Export is fully released, clean up any associated resources\n console.log(`Export ${id} fully released`);\n }\n }\n\n /** Handle disembargo message (Level 1) */\n private async handleDisembargo(disembargo: Disembargo): Promise<void> {\n const { target, context } = disembargo;\n\n // Level 3: Delegate to level3Handlers if available\n if (this.level3Handlers) {\n await this.level3Handlers.handleDisembargo(disembargo);\n return;\n }\n\n // Echo back the disembargo for loopback contexts\n if (context.type === 'senderLoopback') {\n // Echo back as receiverLoopback\n const echoMsg: RpcMessage = {\n type: 'disembargo',\n disembargo: {\n target,\n context: { type: 'receiverLoopback', embargoId: context.embargoId },\n },\n };\n await this.transport.send(echoMsg);\n }\n // For other contexts (accept, provide), more complex handling is needed\n }\n\n /** Handle provide message (Level 3) */\n private async handleProvide(provide: Provide): Promise<void> {\n if (this.level3Handlers) {\n await this.level3Handlers.handleProvide(provide);\n } else {\n // Level 3 not enabled - send unimplemented\n await this.sendReturnException(provide.questionId, 'Level 3 RPC (Provide) not implemented');\n }\n }\n\n /** Handle accept message (Level 3) */\n private async handleAccept(accept: Accept): Promise<void> {\n if (this.level3Handlers) {\n await this.level3Handlers.handleAccept(accept);\n } else {\n // Level 3 not enabled - send unimplemented\n await this.sendReturnException(accept.questionId, 'Level 3 RPC (Accept) not implemented');\n }\n }\n\n /** Handle third-party capability in return results (Level 3) */\n private async handleThirdPartyCapability(\n _questionId: QuestionId,\n thirdPartyCapId: ThirdPartyCapId\n ): Promise<void> {\n if (this.level3Handlers) {\n const importId = await this.level3Handlers.handleThirdPartyCapability(thirdPartyCapId);\n if (importId !== undefined) {\n // Update the question result with the local import ID\n // This allows the caller to use the capability through the local import\n }\n }\n }\n\n /** Handle acceptFromThirdParty return type (Level 3) */\n private async handleAcceptFromThirdParty(\n questionId: QuestionId,\n thirdPartyCapId: ThirdPartyCapId\n ): Promise<void> {\n if (this.level3Handlers) {\n const importId = await this.level3Handlers.handleThirdPartyCapability(thirdPartyCapId);\n if (importId !== undefined) {\n // Complete the question with the resolved capability\n this.questions.complete(questionId, { importId });\n } else {\n this.questions.cancel(questionId, new Error('Failed to resolve third-party capability'));\n }\n } else {\n this.questions.cancel(questionId, new Error('Level 3 RPC not enabled'));\n }\n }\n\n /** Handle abort message */\n private handleAbort(_reason: string): void {\n this.running = false;\n this.questions.clear();\n this.answers.clear();\n this.imports.clear();\n this.exports.clear();\n this.queuedCalls.clear();\n this.pipelineResolutions.clear();\n }\n\n /** Handle disconnect */\n private handleDisconnect(_reason?: Error): void {\n this.running = false;\n this.questions.clear();\n this.answers.clear();\n this.imports.clear();\n this.exports.clear();\n this.queuedCalls.clear();\n this.pipelineResolutions.clear();\n }\n\n /** Handle error */\n private handleError(error: Error): void {\n console.error('RPC error:', error);\n }\n\n /** Send unimplemented response */\n private async sendUnimplemented(originalMessage: RpcMessage): Promise<void> {\n const msg: RpcMessage = {\n type: 'unimplemented',\n message: originalMessage,\n };\n await this.transport.send(msg);\n }\n\n /** Send return exception (helper) */\n private async sendReturnException(questionId: QuestionId, reason: string): Promise<void> {\n const returnMsg: RpcMessage = {\n type: 'return',\n return: {\n answerId: questionId,\n releaseParamCaps: true,\n noFinishNeeded: false,\n result: {\n type: 'exception',\n exception: {\n reason,\n type: 'unimplemented',\n },\n },\n },\n };\n await this.transport.send(returnMsg);\n }\n\n // ========================================================================================\n // Level 4 RPC Methods\n // ========================================================================================\n\n /**\n * Set the Level 4 handlers for this connection.\n * This enables reference equality verification support.\n */\n setLevel4Handlers(handlers: Level4Handlers): void {\n this.level4Handlers = handlers;\n }\n\n /**\n * Send a Join message to verify that two capabilities point to the same object.\n * Requires Level 4 handlers to be set.\n */\n async join(_target1: ImportId, _target2: ImportId): Promise<unknown> {\n if (!this.level4Handlers) {\n throw new Error('Level 4 handlers not set');\n }\n\n // This is a simplified implementation\n // In a full implementation, we'd use the Level4Handlers to send the Join\n return undefined;\n }\n\n /** Handle join message (Level 4) */\n private async handleJoin(join: Join): Promise<void> {\n if (this.level4Handlers) {\n await this.level4Handlers.handleJoin(join);\n } else {\n // Level 4 not enabled - send unimplemented\n await this.sendReturnException(join.questionId, 'Level 4 RPC (Join) not implemented');\n }\n }\n\n // ========================================================================================\n // Capability Management\n // ========================================================================================\n\n /** Import a capability from the remote peer */\n importCapability(importId: ImportId, isPromise = false): void {\n this.imports.add(importId, isPromise);\n }\n\n /** Export a capability to the remote peer */\n exportCapability(capability: unknown, isPromise = false): ExportId {\n const exportEntry = this.exports.add(capability, isPromise);\n return exportEntry.id;\n }\n\n /** Get an imported capability */\n getImport(importId: ImportId) {\n return this.imports.get(importId);\n }\n\n /** Get an exported capability */\n getExport(exportId: ExportId) {\n return this.exports.get(exportId);\n }\n\n // ========================================================================================\n // Level 3 RPC Methods\n // ========================================================================================\n\n /**\n * Set the Level 3 handlers for this connection.\n * This enables three-way introduction support.\n */\n setLevel3Handlers(handlers: Level3Handlers): void {\n this.level3Handlers = handlers;\n }\n\n /**\n * Send a Provide message to offer a capability to a third party.\n * Requires Level 3 handlers to be set.\n */\n async provideToThirdParty(\n _target: { type: 'importedCap'; importId: ImportId },\n _recipient: VatId\n ): Promise<{ questionId: number; thirdPartyCapId: ThirdPartyCapId } | undefined> {\n if (!this.level3Handlers) {\n throw new Error('Level 3 handlers not set');\n }\n\n // This is a simplified implementation\n // In a full implementation, we'd send the Provide message and wait for response\n return undefined;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAkCA,IAAa,gBAAb,MAA2B;CACzB,AAAQ,4BAAY,IAAI,KAA2B;CAC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