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

Method _addMessage

out/cli.cjs:70256–70261  ·  view source on GitHub ↗
(message, emit = true)

Source from the content-addressed store, hash-verified

70254 executor().then(() => {
70255 this._emitFinal();
70256 this._emit("end");
70257 }, __classPrivateFieldGet7(this, _MessageStream_handleError, "f"));
70258 }
70259 _addMessageParam(message) {
70260 this.messages.push(message);
70261 }
70262 _addMessage(message, emit = true) {
70263 this.receivedMessages.push(message);
70264 if (emit) {

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

_emitMethod · 0.95
pushMethod · 0.45

Tested by

no test coverage detected