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

Function simulateToolPolicyNoop

src/node/services/streamSimulation.ts:118–193  ·  view source on GitHub ↗
(
  ctx: SimulationContext,
  effectiveToolPolicy: ToolPolicy | undefined,
  historyService: HistoryService
)

Source from the content-addressed store, hash-verified

116 * Used by the OpenAI SDK `simulateToolPolicyNoop` provider option.
117 */
118export async function simulateToolPolicyNoop(
119 ctx: SimulationContext,
120 effectiveToolPolicy: ToolPolicy | undefined,
121 historyService: HistoryService
122): Promise<void> {
123 const noopMessage = createMuxMessage(ctx.assistantMessageId, "assistant", "", {
124 timestamp: Date.now(),
125 model: ctx.canonicalModelString,
126 routedThroughGateway: ctx.routedThroughGateway,
127 ...(ctx.routeProvider != null ? { routeProvider: ctx.routeProvider } : {}),
128 systemMessageTokens: ctx.systemMessageTokens,
129 agentId: ctx.effectiveAgentId,
130 ...(ctx.metadataMode != null ? { mode: ctx.metadataMode } : {}),
131 thinkingLevel: ctx.effectiveThinkingLevel,
132 toolPolicy: effectiveToolPolicy,
133 });
134
135 const parts: StreamEndEvent["parts"] = [
136 {
137 type: "text",
138 text: "Tool execution skipped because the requested tool is disabled by policy.",
139 },
140 ];
141
142 ctx.emit("stream-start", createSimulatedStreamStart(ctx));
143
144 const textParts = parts.filter((part): part is MuxTextPart => part.type === "text");
145 if (textParts.length === 0) {
146 throw new Error("simulateToolPolicyNoop requires at least one text part");
147 }
148
149 for (const textPart of textParts) {
150 if (textPart.text.length === 0) {
151 continue;
152 }
153
154 const streamDeltaEvent: StreamDeltaEvent = {
155 type: "stream-delta",
156 workspaceId: ctx.workspaceId,
157 messageId: ctx.assistantMessageId,
158 delta: textPart.text,
159 tokens: 0, // Mock scenario — actual tokenization happens in streamManager
160 timestamp: Date.now(),
161 };
162 ctx.emit("stream-delta", streamDeltaEvent);
163 }
164
165 const streamEndEvent: StreamEndEvent = {
166 type: "stream-end",
167 workspaceId: ctx.workspaceId,
168 messageId: ctx.assistantMessageId,
169 metadata: {
170 model: ctx.canonicalModelString,
171 agentId: ctx.effectiveAgentId,
172 ...(ctx.metadataMode != null ? { mode: ctx.metadataMode } : {}),
173 thinkingLevel: ctx.effectiveThinkingLevel,
174 routedThroughGateway: ctx.routedThroughGateway,
175 ...(ctx.routeProvider != null ? { routeProvider: ctx.routeProvider } : {}),

Callers 2

streamMessageMethod · 0.90

Calls 5

createMuxMessageFunction · 0.90
deletePartialMethod · 0.80
updateHistoryMethod · 0.80
emitMethod · 0.65

Tested by

no test coverage detected