( ctx: SimulationContext, historyService: HistoryService )
| 66 | * Used by the OpenAI SDK `forceContextLimitError` provider option. |
| 67 | */ |
| 68 | export async function simulateContextLimitError( |
| 69 | ctx: SimulationContext, |
| 70 | historyService: HistoryService |
| 71 | ): Promise<void> { |
| 72 | const errorMessage = |
| 73 | "Context length exceeded: the conversation is too long to send to this OpenAI model. Please shorten the history and try again."; |
| 74 | |
| 75 | const errorPartialMessage: MuxMessage = { |
| 76 | id: ctx.assistantMessageId, |
| 77 | role: "assistant", |
| 78 | metadata: { |
| 79 | historySequence: ctx.historySequence, |
| 80 | timestamp: Date.now(), |
| 81 | model: ctx.canonicalModelString, |
| 82 | routedThroughGateway: ctx.routedThroughGateway, |
| 83 | ...(ctx.routeProvider != null ? { routeProvider: ctx.routeProvider } : {}), |
| 84 | systemMessageTokens: ctx.systemMessageTokens, |
| 85 | agentId: ctx.effectiveAgentId, |
| 86 | ...(ctx.metadataMode != null ? { mode: ctx.metadataMode } : {}), |
| 87 | thinkingLevel: ctx.effectiveThinkingLevel, |
| 88 | partial: true, |
| 89 | error: errorMessage, |
| 90 | errorType: "context_exceeded", |
| 91 | }, |
| 92 | parts: [], |
| 93 | }; |
| 94 | |
| 95 | await historyService.writePartial(ctx.workspaceId, errorPartialMessage); |
| 96 | |
| 97 | ctx.emit("stream-start", createSimulatedStreamStart(ctx)); |
| 98 | ctx.emit( |
| 99 | "error", |
| 100 | createErrorEvent(ctx.workspaceId, { |
| 101 | messageId: ctx.assistantMessageId, |
| 102 | error: errorMessage, |
| 103 | errorType: "context_exceeded", |
| 104 | }) |
| 105 | ); |
| 106 | } |
| 107 | |
| 108 | // --------------------------------------------------------------------------- |
| 109 | // simulateToolPolicyNoop simulation |
no test coverage detected