MCPcopy
hub / github.com/coder/mux / streamWithHistory

Method streamWithHistory

src/node/services/agentSession.ts:3462–3679  ·  view source on GitHub ↗
(
    modelString: string,
    options?: SendMessageOptions,
    openaiTruncationModeOverride?: "auto" | "disabled",
    disablePostCompactionAttachments?: boolean,
    agentInitiated?: boolean,
    abortSignal?: AbortSignal,
    goalKind?: GoalSyntheticMessageKind
  )

Source from the content-addressed store, hash-verified

3460 }
3461
3462 private async streamWithHistory(
3463 modelString: string,
3464 options?: SendMessageOptions,
3465 openaiTruncationModeOverride?: "auto" | "disabled",
3466 disablePostCompactionAttachments?: boolean,
3467 agentInitiated?: boolean,
3468 abortSignal?: AbortSignal,
3469 goalKind?: GoalSyntheticMessageKind
3470 ): Promise<Result<void, SendMessageError>> {
3471 const isStartupAbortRequested = (): boolean => abortSignal?.aborted === true;
3472
3473 if (this.disposed || isStartupAbortRequested()) {
3474 return Ok(undefined);
3475 }
3476
3477 // Reset per-stream flags (used for retries / crash-safe bookkeeping).
3478 this.compactionMonitor.resetForNewStream();
3479 this.clearLiveUsageState();
3480 this.ackPendingPostCompactionStateOnStreamEnd = false;
3481 this.activeStreamHadAnyDelta = false;
3482 this.activeStreamErrorEventReceived = false;
3483 this.activeStreamFailureHandled = false;
3484 this.activeStreamHadPostCompactionInjection = false;
3485 const providersConfigForCompaction = this.getProvidersConfigForCompaction();
3486 this.activeStreamContext = {
3487 modelString,
3488 options,
3489 agentInitiated,
3490 openaiTruncationModeOverride,
3491 ...(goalKind != null ? { goalKind } : {}),
3492 providersConfig: providersConfigForCompaction,
3493 };
3494 this.activeStreamUserMessageId = undefined;
3495
3496 const commitResult = await this.historyService.commitPartial(this.workspaceId);
3497 if (!commitResult.success) {
3498 return Err(createUnknownSendMessageError(commitResult.error));
3499 }
3500
3501 if (isStartupAbortRequested()) {
3502 return Ok(undefined);
3503 }
3504
3505 let historyResult = await this.historyService.getHistoryFromLatestBoundary(this.workspaceId);
3506 if (isStartupAbortRequested()) {
3507 return Ok(undefined);
3508 }
3509
3510 if (!historyResult.success) {
3511 return Err(createUnknownSendMessageError(historyResult.error));
3512 }
3513
3514 if (historyResult.data.length === 0) {
3515 return Err(
3516 createUnknownSendMessageError(
3517 "Cannot resume stream: workspace history is empty. Send a new message instead."
3518 )
3519 );

Tested by

no test coverage detected