MCPcopy
hub / github.com/di-sukharev/opencommit / on

Method on

out/cli.cjs:70305–70309  ·  view source on GitHub ↗

* Adds the listener function to the end of the listeners array for the event. * No checks are made to see if the listener has already been added. Multiple calls passing * the same combination of event and listener will result in the listener being added, and * called, multiple times. * @

(event, listener)

Source from the content-addressed store, hash-verified

70303 }
70304 /**
70305 * Adds the listener function to the end of the listeners array for the event.
70306 * No checks are made to see if the listener has already been added. Multiple calls passing
70307 * the same combination of event and listener will result in the listener being added, and
70308 * called, multiple times.
70309 * @returns this MessageStream, so that calls can be chained
70310 */
70311 on(event, listener) {
70312 const listeners = __classPrivateFieldGet7(this, _MessageStream_listeners, "f")[event] || (__classPrivateFieldGet7(this, _MessageStream_listeners, "f")[event] = []);

Callers 1

[(_MessageStream_currentMessageSnapshot = /* @__PURE__ */ new WeakMap(), _MessageStream_connectedPromise = /* @__PURE__ */ new WeakMap(), _MessageStream_resolveConnectedPromise = /* @__PURE__ */ new WeakMap(), _MessageStream_rejectConnectedPromise = /* @__PURE__ */ new WeakMap(), _MessageStream_endPromise = /* @__PURE__ */ new WeakMap(), _MessageStream_resolveEndPromise = /* @__PURE__ */ new WeakMap(), _MessageStream_rejectEndPromise = /* @__PURE__ */ new WeakMap(), _MessageStream_listeners = /* @__PURE__ */ new WeakMap(), _MessageStream_ended = /* @__PURE__ */ new WeakMap(), _MessageStream_errored = /* @__PURE__ */ new WeakMap(), _MessageStream_aborted = /* @__PURE__ */ new WeakMap(), _MessageStream_catchingPromiseCreated = /* @__PURE__ */ new WeakMap(), _MessageStream_handleError = /* @__PURE__ */ new WeakMap(), _MessageStream_instances = /* @__PURE__ */ new WeakSet(), _MessageStream_getFinalMessage = function _MessageStream_getFinalMessage2() { if (this.receivedMessages.length === 0) { throw new AnthropicError("stream ended without producing a Message with role=assistant"); } return this.receivedMessages.at(-1); }, _MessageStream_getFinalText = function _MessageStream_getFinalText2() { if (this.receivedMessages.length === 0) { throw new AnthropicError("stream ended without producing a Message with role=assistant"); } const textBlocks = this.receivedMessages.at(-1).content.filter((block) => block.type === "text").map((block) => block.text); if (textBlocks.length === 0) { throw new AnthropicError("stream ended without producing a content block with type=text"); } return textBlocks.join(" "); }, _MessageStream_beginRequest = function _MessageStream_beginRequest2() { if (this.ended) return; __classPrivateFieldSet6(this, _MessageStream_currentMessageSnapshot, void 0, "f"); }, _MessageStream_addStreamEvent = function _MessageStream_addStreamEvent2(event) { if (this.ended) return; const messageSnapshot = __classPrivateFieldGet7(this, _MessageStream_instances, "m", _MessageStream_accumulateMessage).call(this, event); this._emit("streamEvent", event, messageSnapshot); switch (event.type) { case "content_block_delta": { if (event.delta.type === "text_delta") { this._emit("text", event.delta.text, messageSnapshot.content.at(-1).text || ""); } break; } case "message_stop": { this._addMessageParam(messageSnapshot); this._addMessage(messageSnapshot, true); break; } case "content_block_stop": { this._emit("contentBlock", messageSnapshot.content.at(-1)); break; } case "message_start": { __classPrivateFieldSet6(this, _MessageStream_currentMessageSnapshot, messageSnapshot, "f"); break; } case "content_block_start": case "message_delta": break; } }, _MessageStream_endRequest = function _MessageStream_endRequest2() { if (this.ended) { throw new AnthropicError(`stream has ended, this shouldn't happen`); } const snapshot = __classPrivateFieldGet7(this, _MessageStream_currentMessageSnapshot, "f"); if (!snapshot) { throw new AnthropicError(`request ended without sending any chunks`); } __classPrivateFieldSet6(this, _MessageStream_currentMessageSnapshot, void 0, "f"); return snapshot; }, _MessageStream_accumulateMessage = function _MessageStream_accumulateMessage2(event) { let snapshot = __classPrivateFieldGet7(this, _MessageStream_currentMessageSnapshot, "f"); if (event.type === "message_start") { if (snapshot) { throw new AnthropicError(`Unexpected event order, got ${event.type} before receiving "message_stop"`); } return event.message; } if (!snapshot) { throw new AnthropicError(`Unexpected event order, got ${event.type} before "message_start"`); } switch (event.type) { case "message_stop": return snapshot; case "message_delta": snapshot.stop_reason = event.delta.stop_reason; snapshot.stop_sequence = event.delta.stop_sequence; snapshot.usage.output_tokens = event.usage.output_tokens; return snapshot; case "content_block_start": snapshot.content.push(event.content_block); return snapshot; case "content_block_delta": { const snapshotContent = snapshot.content.at(event.index); if (snapshotContent?.type === "text" && event.delta.type === "text_delta") { snapshotContent.text += event.delta.text; } return snapshot; } case "content_block_stop": return snapshot; } }, Symbol.asyncIterator)]Method · 0.95

Calls 2

__classPrivateFieldGet7Function · 0.85
pushMethod · 0.45

Tested by

no test coverage detected