@copilotkit/aimock 1.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/marketplace.json +17 -0
- package/.claude-plugin/plugin.json +12 -0
- package/LICENSE +21 -0
- package/README.md +82 -0
- package/dist/_virtual/_rolldown/runtime.cjs +29 -0
- package/dist/a2a-handler.cjs +203 -0
- package/dist/a2a-handler.cjs.map +1 -0
- package/dist/a2a-handler.js +199 -0
- package/dist/a2a-handler.js.map +1 -0
- package/dist/a2a-mock.cjs +292 -0
- package/dist/a2a-mock.cjs.map +1 -0
- package/dist/a2a-mock.d.cts +41 -0
- package/dist/a2a-mock.d.cts.map +1 -0
- package/dist/a2a-mock.d.ts +41 -0
- package/dist/a2a-mock.d.ts.map +1 -0
- package/dist/a2a-mock.js +290 -0
- package/dist/a2a-mock.js.map +1 -0
- package/dist/a2a-stub.cjs +4 -0
- package/dist/a2a-stub.d.cts +3 -0
- package/dist/a2a-stub.d.ts +3 -0
- package/dist/a2a-stub.js +3 -0
- package/dist/a2a-types.d.cts +68 -0
- package/dist/a2a-types.d.cts.map +1 -0
- package/dist/a2a-types.d.ts +68 -0
- package/dist/a2a-types.d.ts.map +1 -0
- package/dist/aimock-cli.cjs +112 -0
- package/dist/aimock-cli.cjs.map +1 -0
- package/dist/aimock-cli.d.cts +19 -0
- package/dist/aimock-cli.d.cts.map +1 -0
- package/dist/aimock-cli.d.ts +19 -0
- package/dist/aimock-cli.d.ts.map +1 -0
- package/dist/aimock-cli.js +110 -0
- package/dist/aimock-cli.js.map +1 -0
- package/dist/aws-event-stream.cjs +117 -0
- package/dist/aws-event-stream.cjs.map +1 -0
- package/dist/aws-event-stream.d.cts +38 -0
- package/dist/aws-event-stream.d.cts.map +1 -0
- package/dist/aws-event-stream.d.ts +38 -0
- package/dist/aws-event-stream.d.ts.map +1 -0
- package/dist/aws-event-stream.js +114 -0
- package/dist/aws-event-stream.js.map +1 -0
- package/dist/bedrock-converse.cjs +445 -0
- package/dist/bedrock-converse.cjs.map +1 -0
- package/dist/bedrock-converse.d.cts +50 -0
- package/dist/bedrock-converse.d.cts.map +1 -0
- package/dist/bedrock-converse.d.ts +50 -0
- package/dist/bedrock-converse.d.ts.map +1 -0
- package/dist/bedrock-converse.js +443 -0
- package/dist/bedrock-converse.js.map +1 -0
- package/dist/bedrock.cjs +557 -0
- package/dist/bedrock.cjs.map +1 -0
- package/dist/bedrock.d.cts +41 -0
- package/dist/bedrock.d.cts.map +1 -0
- package/dist/bedrock.d.ts +41 -0
- package/dist/bedrock.d.ts.map +1 -0
- package/dist/bedrock.js +553 -0
- package/dist/bedrock.js.map +1 -0
- package/dist/chaos.cjs +114 -0
- package/dist/chaos.cjs.map +1 -0
- package/dist/chaos.d.cts +27 -0
- package/dist/chaos.d.cts.map +1 -0
- package/dist/chaos.d.ts +27 -0
- package/dist/chaos.d.ts.map +1 -0
- package/dist/chaos.js +113 -0
- package/dist/chaos.js.map +1 -0
- package/dist/cli.cjs +268 -0
- package/dist/cli.cjs.map +1 -0
- package/dist/cli.d.cts +1 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +268 -0
- package/dist/cli.js.map +1 -0
- package/dist/cohere.cjs +434 -0
- package/dist/cohere.cjs.map +1 -0
- package/dist/cohere.d.cts +34 -0
- package/dist/cohere.d.cts.map +1 -0
- package/dist/cohere.d.ts +34 -0
- package/dist/cohere.d.ts.map +1 -0
- package/dist/cohere.js +433 -0
- package/dist/cohere.js.map +1 -0
- package/dist/config-loader.cjs +111 -0
- package/dist/config-loader.cjs.map +1 -0
- package/dist/config-loader.d.cts +100 -0
- package/dist/config-loader.d.cts.map +1 -0
- package/dist/config-loader.d.ts +100 -0
- package/dist/config-loader.d.ts.map +1 -0
- package/dist/config-loader.js +107 -0
- package/dist/config-loader.js.map +1 -0
- package/dist/embeddings.cjs +150 -0
- package/dist/embeddings.cjs.map +1 -0
- package/dist/embeddings.d.cts +12 -0
- package/dist/embeddings.d.cts.map +1 -0
- package/dist/embeddings.d.ts +12 -0
- package/dist/embeddings.d.ts.map +1 -0
- package/dist/embeddings.js +150 -0
- package/dist/embeddings.js.map +1 -0
- package/dist/fixture-loader.cjs +269 -0
- package/dist/fixture-loader.cjs.map +1 -0
- package/dist/fixture-loader.d.cts +17 -0
- package/dist/fixture-loader.d.cts.map +1 -0
- package/dist/fixture-loader.d.ts +17 -0
- package/dist/fixture-loader.d.ts.map +1 -0
- package/dist/fixture-loader.js +265 -0
- package/dist/fixture-loader.js.map +1 -0
- package/dist/gemini.cjs +403 -0
- package/dist/gemini.cjs.map +1 -0
- package/dist/gemini.d.cts +10 -0
- package/dist/gemini.d.cts.map +1 -0
- package/dist/gemini.d.ts +10 -0
- package/dist/gemini.d.ts.map +1 -0
- package/dist/gemini.js +403 -0
- package/dist/gemini.js.map +1 -0
- package/dist/helpers.cjs +276 -0
- package/dist/helpers.cjs.map +1 -0
- package/dist/helpers.d.cts +39 -0
- package/dist/helpers.d.cts.map +1 -0
- package/dist/helpers.d.ts +39 -0
- package/dist/helpers.d.ts.map +1 -0
- package/dist/helpers.js +259 -0
- package/dist/helpers.js.map +1 -0
- package/dist/index.cjs +113 -0
- package/dist/index.d.cts +42 -0
- package/dist/index.d.ts +42 -0
- package/dist/index.js +39 -0
- package/dist/interruption.cjs +40 -0
- package/dist/interruption.cjs.map +1 -0
- package/dist/interruption.d.cts +15 -0
- package/dist/interruption.d.cts.map +1 -0
- package/dist/interruption.d.ts +15 -0
- package/dist/interruption.d.ts.map +1 -0
- package/dist/interruption.js +39 -0
- package/dist/interruption.js.map +1 -0
- package/dist/journal.cjs +65 -0
- package/dist/journal.cjs.map +1 -0
- package/dist/journal.d.cts +23 -0
- package/dist/journal.d.cts.map +1 -0
- package/dist/journal.d.ts +23 -0
- package/dist/journal.d.ts.map +1 -0
- package/dist/journal.js +65 -0
- package/dist/journal.js.map +1 -0
- package/dist/jsonrpc.cjs +91 -0
- package/dist/jsonrpc.cjs.map +1 -0
- package/dist/jsonrpc.d.cts +24 -0
- package/dist/jsonrpc.d.cts.map +1 -0
- package/dist/jsonrpc.d.ts +24 -0
- package/dist/jsonrpc.d.ts.map +1 -0
- package/dist/jsonrpc.js +90 -0
- package/dist/jsonrpc.js.map +1 -0
- package/dist/llmock.cjs +223 -0
- package/dist/llmock.cjs.map +1 -0
- package/dist/llmock.d.cts +70 -0
- package/dist/llmock.d.cts.map +1 -0
- package/dist/llmock.d.ts +70 -0
- package/dist/llmock.d.ts.map +1 -0
- package/dist/llmock.js +223 -0
- package/dist/llmock.js.map +1 -0
- package/dist/logger.cjs +29 -0
- package/dist/logger.cjs.map +1 -0
- package/dist/logger.d.cts +14 -0
- package/dist/logger.d.cts.map +1 -0
- package/dist/logger.d.ts +14 -0
- package/dist/logger.d.ts.map +1 -0
- package/dist/logger.js +28 -0
- package/dist/logger.js.map +1 -0
- package/dist/mcp-handler.cjs +189 -0
- package/dist/mcp-handler.cjs.map +1 -0
- package/dist/mcp-handler.js +188 -0
- package/dist/mcp-handler.js.map +1 -0
- package/dist/mcp-mock.cjs +169 -0
- package/dist/mcp-mock.cjs.map +1 -0
- package/dist/mcp-mock.d.cts +40 -0
- package/dist/mcp-mock.d.cts.map +1 -0
- package/dist/mcp-mock.d.ts +40 -0
- package/dist/mcp-mock.d.ts.map +1 -0
- package/dist/mcp-mock.js +167 -0
- package/dist/mcp-mock.js.map +1 -0
- package/dist/mcp-stub.cjs +4 -0
- package/dist/mcp-stub.d.cts +3 -0
- package/dist/mcp-stub.d.ts +3 -0
- package/dist/mcp-stub.js +3 -0
- package/dist/mcp-types.d.cts +65 -0
- package/dist/mcp-types.d.cts.map +1 -0
- package/dist/mcp-types.d.ts +65 -0
- package/dist/mcp-types.d.ts.map +1 -0
- package/dist/messages.cjs +489 -0
- package/dist/messages.cjs.map +1 -0
- package/dist/messages.d.cts +10 -0
- package/dist/messages.d.cts.map +1 -0
- package/dist/messages.d.ts +10 -0
- package/dist/messages.d.ts.map +1 -0
- package/dist/messages.js +489 -0
- package/dist/messages.js.map +1 -0
- package/dist/metrics.cjs +160 -0
- package/dist/metrics.cjs.map +1 -0
- package/dist/metrics.d.cts +24 -0
- package/dist/metrics.d.cts.map +1 -0
- package/dist/metrics.d.ts +24 -0
- package/dist/metrics.d.ts.map +1 -0
- package/dist/metrics.js +158 -0
- package/dist/metrics.js.map +1 -0
- package/dist/moderation.cjs +91 -0
- package/dist/moderation.cjs.map +1 -0
- package/dist/moderation.d.cts +23 -0
- package/dist/moderation.d.cts.map +1 -0
- package/dist/moderation.d.ts +23 -0
- package/dist/moderation.d.ts.map +1 -0
- package/dist/moderation.js +91 -0
- package/dist/moderation.js.map +1 -0
- package/dist/ndjson-writer.cjs +31 -0
- package/dist/ndjson-writer.cjs.map +1 -0
- package/dist/ndjson-writer.d.cts +17 -0
- package/dist/ndjson-writer.d.cts.map +1 -0
- package/dist/ndjson-writer.d.ts +17 -0
- package/dist/ndjson-writer.d.ts.map +1 -0
- package/dist/ndjson-writer.js +31 -0
- package/dist/ndjson-writer.js.map +1 -0
- package/dist/ollama.cjs +519 -0
- package/dist/ollama.cjs.map +1 -0
- package/dist/ollama.d.cts +34 -0
- package/dist/ollama.d.cts.map +1 -0
- package/dist/ollama.d.ts +34 -0
- package/dist/ollama.d.ts.map +1 -0
- package/dist/ollama.js +517 -0
- package/dist/ollama.js.map +1 -0
- package/dist/recorder.cjs +311 -0
- package/dist/recorder.cjs.map +1 -0
- package/dist/recorder.d.cts +23 -0
- package/dist/recorder.d.cts.map +1 -0
- package/dist/recorder.d.ts +23 -0
- package/dist/recorder.d.ts.map +1 -0
- package/dist/recorder.js +305 -0
- package/dist/recorder.js.map +1 -0
- package/dist/rerank.cjs +71 -0
- package/dist/rerank.cjs.map +1 -0
- package/dist/rerank.d.cts +22 -0
- package/dist/rerank.d.cts.map +1 -0
- package/dist/rerank.d.ts +22 -0
- package/dist/rerank.d.ts.map +1 -0
- package/dist/rerank.js +71 -0
- package/dist/rerank.js.map +1 -0
- package/dist/responses.cjs +637 -0
- package/dist/responses.cjs.map +1 -0
- package/dist/responses.d.cts +16 -0
- package/dist/responses.d.cts.map +1 -0
- package/dist/responses.d.ts +16 -0
- package/dist/responses.d.ts.map +1 -0
- package/dist/responses.js +634 -0
- package/dist/responses.js.map +1 -0
- package/dist/router.cjs +68 -0
- package/dist/router.cjs.map +1 -0
- package/dist/router.d.cts +16 -0
- package/dist/router.d.cts.map +1 -0
- package/dist/router.d.ts +16 -0
- package/dist/router.d.ts.map +1 -0
- package/dist/router.js +65 -0
- package/dist/router.js.map +1 -0
- package/dist/search.cjs +59 -0
- package/dist/search.cjs.map +1 -0
- package/dist/search.d.cts +23 -0
- package/dist/search.d.cts.map +1 -0
- package/dist/search.d.ts +23 -0
- package/dist/search.d.ts.map +1 -0
- package/dist/search.js +59 -0
- package/dist/search.js.map +1 -0
- package/dist/server.cjs +935 -0
- package/dist/server.cjs.map +1 -0
- package/dist/server.d.cts +28 -0
- package/dist/server.d.cts.map +1 -0
- package/dist/server.d.ts +28 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +933 -0
- package/dist/server.js.map +1 -0
- package/dist/sse-writer.cjs +59 -0
- package/dist/sse-writer.cjs.map +1 -0
- package/dist/sse-writer.d.cts +19 -0
- package/dist/sse-writer.d.cts.map +1 -0
- package/dist/sse-writer.d.ts +19 -0
- package/dist/sse-writer.d.ts.map +1 -0
- package/dist/sse-writer.js +55 -0
- package/dist/sse-writer.js.map +1 -0
- package/dist/stream-collapse.cjs +496 -0
- package/dist/stream-collapse.cjs.map +1 -0
- package/dist/stream-collapse.d.cts +70 -0
- package/dist/stream-collapse.d.cts.map +1 -0
- package/dist/stream-collapse.d.ts +70 -0
- package/dist/stream-collapse.d.ts.map +1 -0
- package/dist/stream-collapse.js +489 -0
- package/dist/stream-collapse.js.map +1 -0
- package/dist/suite.cjs +46 -0
- package/dist/suite.cjs.map +1 -0
- package/dist/suite.d.cts +31 -0
- package/dist/suite.d.cts.map +1 -0
- package/dist/suite.d.ts +31 -0
- package/dist/suite.d.ts.map +1 -0
- package/dist/suite.js +46 -0
- package/dist/suite.js.map +1 -0
- package/dist/types.d.cts +243 -0
- package/dist/types.d.cts.map +1 -0
- package/dist/types.d.ts +243 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/url.cjs +21 -0
- package/dist/url.cjs.map +1 -0
- package/dist/url.d.cts +16 -0
- package/dist/url.d.cts.map +1 -0
- package/dist/url.d.ts +16 -0
- package/dist/url.d.ts.map +1 -0
- package/dist/url.js +20 -0
- package/dist/url.js.map +1 -0
- package/dist/vector-handler.cjs +239 -0
- package/dist/vector-handler.cjs.map +1 -0
- package/dist/vector-handler.js +238 -0
- package/dist/vector-handler.js.map +1 -0
- package/dist/vector-mock.cjs +229 -0
- package/dist/vector-mock.cjs.map +1 -0
- package/dist/vector-mock.d.cts +39 -0
- package/dist/vector-mock.d.cts.map +1 -0
- package/dist/vector-mock.d.ts +39 -0
- package/dist/vector-mock.d.ts.map +1 -0
- package/dist/vector-mock.js +227 -0
- package/dist/vector-mock.js.map +1 -0
- package/dist/vector-stub.cjs +4 -0
- package/dist/vector-stub.d.cts +3 -0
- package/dist/vector-stub.d.ts +3 -0
- package/dist/vector-stub.js +3 -0
- package/dist/vector-types.d.cts +32 -0
- package/dist/vector-types.d.cts.map +1 -0
- package/dist/vector-types.d.ts +32 -0
- package/dist/vector-types.d.ts.map +1 -0
- package/dist/watcher.cjs +59 -0
- package/dist/watcher.cjs.map +1 -0
- package/dist/watcher.js +58 -0
- package/dist/watcher.js.map +1 -0
- package/dist/ws-framing.cjs +187 -0
- package/dist/ws-framing.cjs.map +1 -0
- package/dist/ws-framing.d.cts +26 -0
- package/dist/ws-framing.d.cts.map +1 -0
- package/dist/ws-framing.d.ts +26 -0
- package/dist/ws-framing.d.ts.map +1 -0
- package/dist/ws-framing.js +184 -0
- package/dist/ws-framing.js.map +1 -0
- package/dist/ws-gemini-live.cjs +364 -0
- package/dist/ws-gemini-live.cjs.map +1 -0
- package/dist/ws-gemini-live.d.cts +18 -0
- package/dist/ws-gemini-live.d.cts.map +1 -0
- package/dist/ws-gemini-live.d.ts +18 -0
- package/dist/ws-gemini-live.d.ts.map +1 -0
- package/dist/ws-gemini-live.js +364 -0
- package/dist/ws-gemini-live.js.map +1 -0
- package/dist/ws-realtime.cjs +435 -0
- package/dist/ws-realtime.cjs.map +1 -0
- package/dist/ws-realtime.d.cts +17 -0
- package/dist/ws-realtime.d.cts.map +1 -0
- package/dist/ws-realtime.d.ts +17 -0
- package/dist/ws-realtime.d.ts.map +1 -0
- package/dist/ws-realtime.js +435 -0
- package/dist/ws-realtime.js.map +1 -0
- package/dist/ws-responses.cjs +164 -0
- package/dist/ws-responses.cjs.map +1 -0
- package/dist/ws-responses.d.cts +18 -0
- package/dist/ws-responses.d.cts.map +1 -0
- package/dist/ws-responses.d.ts +18 -0
- package/dist/ws-responses.d.ts.map +1 -0
- package/dist/ws-responses.js +164 -0
- package/dist/ws-responses.js.map +1 -0
- package/fixtures/example-greeting.json +12 -0
- package/fixtures/example-multi-turn.json +14 -0
- package/fixtures/example-tool-call.json +15 -0
- package/package.json +118 -0
- package/skills/write-fixtures/SKILL.md +625 -0
package/dist/cohere.cjs
ADDED
|
@@ -0,0 +1,434 @@
|
|
|
1
|
+
const require_helpers = require('./helpers.cjs');
|
|
2
|
+
const require_router = require('./router.cjs');
|
|
3
|
+
const require_sse_writer = require('./sse-writer.cjs');
|
|
4
|
+
const require_interruption = require('./interruption.cjs');
|
|
5
|
+
const require_chaos = require('./chaos.cjs');
|
|
6
|
+
const require_recorder = require('./recorder.cjs');
|
|
7
|
+
|
|
8
|
+
//#region src/cohere.ts
|
|
9
|
+
const ZERO_USAGE = {
|
|
10
|
+
billed_units: {
|
|
11
|
+
input_tokens: 0,
|
|
12
|
+
output_tokens: 0,
|
|
13
|
+
search_units: 0,
|
|
14
|
+
classifications: 0
|
|
15
|
+
},
|
|
16
|
+
tokens: {
|
|
17
|
+
input_tokens: 0,
|
|
18
|
+
output_tokens: 0
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
function cohereToCompletionRequest(req) {
|
|
22
|
+
const messages = [];
|
|
23
|
+
for (const msg of req.messages) if (msg.role === "system") messages.push({
|
|
24
|
+
role: "system",
|
|
25
|
+
content: msg.content
|
|
26
|
+
});
|
|
27
|
+
else if (msg.role === "user") messages.push({
|
|
28
|
+
role: "user",
|
|
29
|
+
content: msg.content
|
|
30
|
+
});
|
|
31
|
+
else if (msg.role === "assistant") messages.push({
|
|
32
|
+
role: "assistant",
|
|
33
|
+
content: msg.content
|
|
34
|
+
});
|
|
35
|
+
else if (msg.role === "tool") messages.push({
|
|
36
|
+
role: "tool",
|
|
37
|
+
content: msg.content,
|
|
38
|
+
tool_call_id: msg.tool_call_id
|
|
39
|
+
});
|
|
40
|
+
let tools;
|
|
41
|
+
if (req.tools && req.tools.length > 0) tools = req.tools.map((t) => ({
|
|
42
|
+
type: "function",
|
|
43
|
+
function: {
|
|
44
|
+
name: t.function.name,
|
|
45
|
+
description: t.function.description,
|
|
46
|
+
parameters: t.function.parameters
|
|
47
|
+
}
|
|
48
|
+
}));
|
|
49
|
+
return {
|
|
50
|
+
model: req.model,
|
|
51
|
+
messages,
|
|
52
|
+
stream: req.stream,
|
|
53
|
+
tools
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
function buildCohereTextResponse(content) {
|
|
57
|
+
return {
|
|
58
|
+
id: require_helpers.generateMessageId(),
|
|
59
|
+
finish_reason: "COMPLETE",
|
|
60
|
+
message: {
|
|
61
|
+
role: "assistant",
|
|
62
|
+
content: [{
|
|
63
|
+
type: "text",
|
|
64
|
+
text: content
|
|
65
|
+
}],
|
|
66
|
+
tool_calls: [],
|
|
67
|
+
tool_plan: "",
|
|
68
|
+
citations: []
|
|
69
|
+
},
|
|
70
|
+
usage: ZERO_USAGE
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
function buildCohereToolCallResponse(toolCalls, logger) {
|
|
74
|
+
const cohereCalls = toolCalls.map((tc) => {
|
|
75
|
+
try {
|
|
76
|
+
JSON.parse(tc.arguments || "{}");
|
|
77
|
+
} catch {
|
|
78
|
+
logger.warn(`Malformed JSON in fixture tool call arguments for "${tc.name}": ${tc.arguments}`);
|
|
79
|
+
}
|
|
80
|
+
return {
|
|
81
|
+
id: tc.id || require_helpers.generateToolCallId(),
|
|
82
|
+
type: "function",
|
|
83
|
+
function: {
|
|
84
|
+
name: tc.name,
|
|
85
|
+
arguments: tc.arguments || "{}"
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
});
|
|
89
|
+
return {
|
|
90
|
+
id: require_helpers.generateMessageId(),
|
|
91
|
+
finish_reason: "TOOL_CALL",
|
|
92
|
+
message: {
|
|
93
|
+
role: "assistant",
|
|
94
|
+
content: [],
|
|
95
|
+
tool_calls: cohereCalls,
|
|
96
|
+
tool_plan: "",
|
|
97
|
+
citations: []
|
|
98
|
+
},
|
|
99
|
+
usage: ZERO_USAGE
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
function buildCohereTextStreamEvents(content, chunkSize) {
|
|
103
|
+
const msgId = require_helpers.generateMessageId();
|
|
104
|
+
const events = [];
|
|
105
|
+
events.push({
|
|
106
|
+
id: msgId,
|
|
107
|
+
type: "message-start",
|
|
108
|
+
delta: { message: {
|
|
109
|
+
role: "assistant",
|
|
110
|
+
content: [],
|
|
111
|
+
tool_plan: "",
|
|
112
|
+
tool_calls: [],
|
|
113
|
+
citations: []
|
|
114
|
+
} }
|
|
115
|
+
});
|
|
116
|
+
events.push({
|
|
117
|
+
type: "content-start",
|
|
118
|
+
index: 0,
|
|
119
|
+
delta: { message: { content: { type: "text" } } }
|
|
120
|
+
});
|
|
121
|
+
for (let i = 0; i < content.length; i += chunkSize) {
|
|
122
|
+
const slice = content.slice(i, i + chunkSize);
|
|
123
|
+
events.push({
|
|
124
|
+
type: "content-delta",
|
|
125
|
+
index: 0,
|
|
126
|
+
delta: { message: { content: {
|
|
127
|
+
type: "text",
|
|
128
|
+
text: slice
|
|
129
|
+
} } }
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
events.push({
|
|
133
|
+
type: "content-end",
|
|
134
|
+
index: 0
|
|
135
|
+
});
|
|
136
|
+
events.push({
|
|
137
|
+
type: "message-end",
|
|
138
|
+
delta: {
|
|
139
|
+
finish_reason: "COMPLETE",
|
|
140
|
+
usage: ZERO_USAGE
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
return events;
|
|
144
|
+
}
|
|
145
|
+
function buildCohereToolCallStreamEvents(toolCalls, chunkSize, logger) {
|
|
146
|
+
const msgId = require_helpers.generateMessageId();
|
|
147
|
+
const events = [];
|
|
148
|
+
events.push({
|
|
149
|
+
id: msgId,
|
|
150
|
+
type: "message-start",
|
|
151
|
+
delta: { message: {
|
|
152
|
+
role: "assistant",
|
|
153
|
+
content: [],
|
|
154
|
+
tool_plan: "",
|
|
155
|
+
tool_calls: [],
|
|
156
|
+
citations: []
|
|
157
|
+
} }
|
|
158
|
+
});
|
|
159
|
+
events.push({
|
|
160
|
+
type: "tool-plan-delta",
|
|
161
|
+
delta: { message: { tool_plan: "I will use the requested tool." } }
|
|
162
|
+
});
|
|
163
|
+
for (let idx = 0; idx < toolCalls.length; idx++) {
|
|
164
|
+
const tc = toolCalls[idx];
|
|
165
|
+
const callId = tc.id || require_helpers.generateToolCallId();
|
|
166
|
+
let argsJson;
|
|
167
|
+
try {
|
|
168
|
+
JSON.parse(tc.arguments || "{}");
|
|
169
|
+
argsJson = tc.arguments || "{}";
|
|
170
|
+
} catch {
|
|
171
|
+
logger.warn(`Malformed JSON in fixture tool call arguments for "${tc.name}": ${tc.arguments}`);
|
|
172
|
+
argsJson = "{}";
|
|
173
|
+
}
|
|
174
|
+
events.push({
|
|
175
|
+
type: "tool-call-start",
|
|
176
|
+
index: idx,
|
|
177
|
+
delta: { message: { tool_calls: {
|
|
178
|
+
id: callId,
|
|
179
|
+
type: "function",
|
|
180
|
+
function: {
|
|
181
|
+
name: tc.name,
|
|
182
|
+
arguments: ""
|
|
183
|
+
}
|
|
184
|
+
} } }
|
|
185
|
+
});
|
|
186
|
+
for (let i = 0; i < argsJson.length; i += chunkSize) {
|
|
187
|
+
const slice = argsJson.slice(i, i + chunkSize);
|
|
188
|
+
events.push({
|
|
189
|
+
type: "tool-call-delta",
|
|
190
|
+
index: idx,
|
|
191
|
+
delta: { message: { tool_calls: { function: { arguments: slice } } } }
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
events.push({
|
|
195
|
+
type: "tool-call-end",
|
|
196
|
+
index: idx
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
events.push({
|
|
200
|
+
type: "message-end",
|
|
201
|
+
delta: {
|
|
202
|
+
finish_reason: "TOOL_CALL",
|
|
203
|
+
usage: ZERO_USAGE
|
|
204
|
+
}
|
|
205
|
+
});
|
|
206
|
+
return events;
|
|
207
|
+
}
|
|
208
|
+
async function writeCohereSSEStream(res, events, optionsOrLatency) {
|
|
209
|
+
const opts = typeof optionsOrLatency === "number" ? { latency: optionsOrLatency } : optionsOrLatency ?? {};
|
|
210
|
+
const latency = opts.latency ?? 0;
|
|
211
|
+
const profile = opts.streamingProfile;
|
|
212
|
+
const signal = opts.signal;
|
|
213
|
+
const onChunkSent = opts.onChunkSent;
|
|
214
|
+
if (res.writableEnded) return true;
|
|
215
|
+
res.setHeader("Content-Type", "text/event-stream");
|
|
216
|
+
res.setHeader("Cache-Control", "no-cache");
|
|
217
|
+
res.setHeader("Connection", "keep-alive");
|
|
218
|
+
let chunkIndex = 0;
|
|
219
|
+
for (const event of events) {
|
|
220
|
+
const chunkDelay = require_sse_writer.calculateDelay(chunkIndex, profile, latency);
|
|
221
|
+
if (chunkDelay > 0) await require_sse_writer.delay(chunkDelay, signal);
|
|
222
|
+
if (signal?.aborted) return false;
|
|
223
|
+
if (res.writableEnded) return true;
|
|
224
|
+
res.write(`event: ${event.type}\ndata: ${JSON.stringify(event)}\n\n`);
|
|
225
|
+
onChunkSent?.();
|
|
226
|
+
if (signal?.aborted) return false;
|
|
227
|
+
chunkIndex++;
|
|
228
|
+
}
|
|
229
|
+
if (!res.writableEnded) res.end();
|
|
230
|
+
return true;
|
|
231
|
+
}
|
|
232
|
+
async function handleCohere(req, res, raw, fixtures, journal, defaults, setCorsHeaders) {
|
|
233
|
+
const { logger } = defaults;
|
|
234
|
+
setCorsHeaders(res);
|
|
235
|
+
let cohereReq;
|
|
236
|
+
try {
|
|
237
|
+
cohereReq = JSON.parse(raw);
|
|
238
|
+
} catch {
|
|
239
|
+
journal.add({
|
|
240
|
+
method: req.method ?? "POST",
|
|
241
|
+
path: req.url ?? "/v2/chat",
|
|
242
|
+
headers: require_helpers.flattenHeaders(req.headers),
|
|
243
|
+
body: null,
|
|
244
|
+
response: {
|
|
245
|
+
status: 400,
|
|
246
|
+
fixture: null
|
|
247
|
+
}
|
|
248
|
+
});
|
|
249
|
+
require_sse_writer.writeErrorResponse(res, 400, JSON.stringify({ error: {
|
|
250
|
+
message: "Malformed JSON",
|
|
251
|
+
type: "invalid_request_error"
|
|
252
|
+
} }));
|
|
253
|
+
return;
|
|
254
|
+
}
|
|
255
|
+
if (!cohereReq.model) {
|
|
256
|
+
journal.add({
|
|
257
|
+
method: req.method ?? "POST",
|
|
258
|
+
path: req.url ?? "/v2/chat",
|
|
259
|
+
headers: require_helpers.flattenHeaders(req.headers),
|
|
260
|
+
body: null,
|
|
261
|
+
response: {
|
|
262
|
+
status: 400,
|
|
263
|
+
fixture: null
|
|
264
|
+
}
|
|
265
|
+
});
|
|
266
|
+
require_sse_writer.writeErrorResponse(res, 400, JSON.stringify({ error: {
|
|
267
|
+
message: "model is required",
|
|
268
|
+
type: "invalid_request_error"
|
|
269
|
+
} }));
|
|
270
|
+
return;
|
|
271
|
+
}
|
|
272
|
+
if (!cohereReq.messages || !Array.isArray(cohereReq.messages)) {
|
|
273
|
+
journal.add({
|
|
274
|
+
method: req.method ?? "POST",
|
|
275
|
+
path: req.url ?? "/v2/chat",
|
|
276
|
+
headers: require_helpers.flattenHeaders(req.headers),
|
|
277
|
+
body: null,
|
|
278
|
+
response: {
|
|
279
|
+
status: 400,
|
|
280
|
+
fixture: null
|
|
281
|
+
}
|
|
282
|
+
});
|
|
283
|
+
require_sse_writer.writeErrorResponse(res, 400, JSON.stringify({ error: {
|
|
284
|
+
message: "Invalid request: messages array is required",
|
|
285
|
+
type: "invalid_request_error"
|
|
286
|
+
} }));
|
|
287
|
+
return;
|
|
288
|
+
}
|
|
289
|
+
const completionReq = cohereToCompletionRequest(cohereReq);
|
|
290
|
+
const fixture = require_router.matchFixture(fixtures, completionReq, journal.fixtureMatchCounts);
|
|
291
|
+
if (fixture) journal.incrementFixtureMatchCount(fixture, fixtures);
|
|
292
|
+
if (require_chaos.applyChaos(res, fixture, defaults.chaos, req.headers, journal, {
|
|
293
|
+
method: req.method ?? "POST",
|
|
294
|
+
path: req.url ?? "/v2/chat",
|
|
295
|
+
headers: require_helpers.flattenHeaders(req.headers),
|
|
296
|
+
body: completionReq
|
|
297
|
+
}, defaults.registry, defaults.logger)) return;
|
|
298
|
+
if (!fixture) {
|
|
299
|
+
if (defaults.record) {
|
|
300
|
+
if (await require_recorder.proxyAndRecord(req, res, completionReq, "cohere", req.url ?? "/v2/chat", fixtures, defaults, raw)) {
|
|
301
|
+
journal.add({
|
|
302
|
+
method: req.method ?? "POST",
|
|
303
|
+
path: req.url ?? "/v2/chat",
|
|
304
|
+
headers: require_helpers.flattenHeaders(req.headers),
|
|
305
|
+
body: completionReq,
|
|
306
|
+
response: {
|
|
307
|
+
status: res.statusCode ?? 200,
|
|
308
|
+
fixture: null
|
|
309
|
+
}
|
|
310
|
+
});
|
|
311
|
+
return;
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
const strictStatus = defaults.strict ? 503 : 404;
|
|
315
|
+
const strictMessage = defaults.strict ? "Strict mode: no fixture matched" : "No fixture matched";
|
|
316
|
+
if (defaults.strict) logger.error(`STRICT: No fixture matched for ${req.method ?? "POST"} ${req.url ?? "/v2/chat"}`);
|
|
317
|
+
journal.add({
|
|
318
|
+
method: req.method ?? "POST",
|
|
319
|
+
path: req.url ?? "/v2/chat",
|
|
320
|
+
headers: require_helpers.flattenHeaders(req.headers),
|
|
321
|
+
body: completionReq,
|
|
322
|
+
response: {
|
|
323
|
+
status: strictStatus,
|
|
324
|
+
fixture: null
|
|
325
|
+
}
|
|
326
|
+
});
|
|
327
|
+
require_sse_writer.writeErrorResponse(res, strictStatus, JSON.stringify({ error: {
|
|
328
|
+
message: strictMessage,
|
|
329
|
+
type: "invalid_request_error"
|
|
330
|
+
} }));
|
|
331
|
+
return;
|
|
332
|
+
}
|
|
333
|
+
const response = fixture.response;
|
|
334
|
+
const latency = fixture.latency ?? defaults.latency;
|
|
335
|
+
const chunkSize = Math.max(1, fixture.chunkSize ?? defaults.chunkSize);
|
|
336
|
+
if (require_helpers.isErrorResponse(response)) {
|
|
337
|
+
const status = response.status ?? 500;
|
|
338
|
+
journal.add({
|
|
339
|
+
method: req.method ?? "POST",
|
|
340
|
+
path: req.url ?? "/v2/chat",
|
|
341
|
+
headers: require_helpers.flattenHeaders(req.headers),
|
|
342
|
+
body: completionReq,
|
|
343
|
+
response: {
|
|
344
|
+
status,
|
|
345
|
+
fixture
|
|
346
|
+
}
|
|
347
|
+
});
|
|
348
|
+
require_sse_writer.writeErrorResponse(res, status, JSON.stringify(response));
|
|
349
|
+
return;
|
|
350
|
+
}
|
|
351
|
+
if (require_helpers.isTextResponse(response)) {
|
|
352
|
+
const journalEntry = journal.add({
|
|
353
|
+
method: req.method ?? "POST",
|
|
354
|
+
path: req.url ?? "/v2/chat",
|
|
355
|
+
headers: require_helpers.flattenHeaders(req.headers),
|
|
356
|
+
body: completionReq,
|
|
357
|
+
response: {
|
|
358
|
+
status: 200,
|
|
359
|
+
fixture
|
|
360
|
+
}
|
|
361
|
+
});
|
|
362
|
+
if (cohereReq.stream !== true) {
|
|
363
|
+
const body = buildCohereTextResponse(response.content);
|
|
364
|
+
res.writeHead(200, { "Content-Type": "application/json" });
|
|
365
|
+
res.end(JSON.stringify(body));
|
|
366
|
+
} else {
|
|
367
|
+
const events = buildCohereTextStreamEvents(response.content, chunkSize);
|
|
368
|
+
const interruption = require_interruption.createInterruptionSignal(fixture);
|
|
369
|
+
if (!await writeCohereSSEStream(res, events, {
|
|
370
|
+
latency,
|
|
371
|
+
streamingProfile: fixture.streamingProfile,
|
|
372
|
+
signal: interruption?.signal,
|
|
373
|
+
onChunkSent: interruption?.tick
|
|
374
|
+
})) {
|
|
375
|
+
if (!res.writableEnded) res.destroy();
|
|
376
|
+
journalEntry.response.interrupted = true;
|
|
377
|
+
journalEntry.response.interruptReason = interruption?.reason();
|
|
378
|
+
}
|
|
379
|
+
interruption?.cleanup();
|
|
380
|
+
}
|
|
381
|
+
return;
|
|
382
|
+
}
|
|
383
|
+
if (require_helpers.isToolCallResponse(response)) {
|
|
384
|
+
const journalEntry = journal.add({
|
|
385
|
+
method: req.method ?? "POST",
|
|
386
|
+
path: req.url ?? "/v2/chat",
|
|
387
|
+
headers: require_helpers.flattenHeaders(req.headers),
|
|
388
|
+
body: completionReq,
|
|
389
|
+
response: {
|
|
390
|
+
status: 200,
|
|
391
|
+
fixture
|
|
392
|
+
}
|
|
393
|
+
});
|
|
394
|
+
if (cohereReq.stream !== true) {
|
|
395
|
+
const body = buildCohereToolCallResponse(response.toolCalls, logger);
|
|
396
|
+
res.writeHead(200, { "Content-Type": "application/json" });
|
|
397
|
+
res.end(JSON.stringify(body));
|
|
398
|
+
} else {
|
|
399
|
+
const events = buildCohereToolCallStreamEvents(response.toolCalls, chunkSize, logger);
|
|
400
|
+
const interruption = require_interruption.createInterruptionSignal(fixture);
|
|
401
|
+
if (!await writeCohereSSEStream(res, events, {
|
|
402
|
+
latency,
|
|
403
|
+
streamingProfile: fixture.streamingProfile,
|
|
404
|
+
signal: interruption?.signal,
|
|
405
|
+
onChunkSent: interruption?.tick
|
|
406
|
+
})) {
|
|
407
|
+
if (!res.writableEnded) res.destroy();
|
|
408
|
+
journalEntry.response.interrupted = true;
|
|
409
|
+
journalEntry.response.interruptReason = interruption?.reason();
|
|
410
|
+
}
|
|
411
|
+
interruption?.cleanup();
|
|
412
|
+
}
|
|
413
|
+
return;
|
|
414
|
+
}
|
|
415
|
+
journal.add({
|
|
416
|
+
method: req.method ?? "POST",
|
|
417
|
+
path: req.url ?? "/v2/chat",
|
|
418
|
+
headers: require_helpers.flattenHeaders(req.headers),
|
|
419
|
+
body: completionReq,
|
|
420
|
+
response: {
|
|
421
|
+
status: 500,
|
|
422
|
+
fixture
|
|
423
|
+
}
|
|
424
|
+
});
|
|
425
|
+
require_sse_writer.writeErrorResponse(res, 500, JSON.stringify({ error: {
|
|
426
|
+
message: "Fixture response did not match any known type",
|
|
427
|
+
type: "server_error"
|
|
428
|
+
} }));
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
//#endregion
|
|
432
|
+
exports.cohereToCompletionRequest = cohereToCompletionRequest;
|
|
433
|
+
exports.handleCohere = handleCohere;
|
|
434
|
+
//# sourceMappingURL=cohere.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cohere.cjs","names":["generateMessageId","generateToolCallId","calculateDelay","delay","flattenHeaders","matchFixture","applyChaos","proxyAndRecord","isErrorResponse","isTextResponse","createInterruptionSignal","isToolCallResponse"],"sources":["../src/cohere.ts"],"sourcesContent":["/**\n * Cohere v2 Chat API endpoint support.\n *\n * Translates incoming /v2/chat requests into the ChatCompletionRequest\n * format used by the fixture router, and converts fixture responses back into\n * Cohere's typed SSE streaming (or non-streaming) format.\n *\n * Cohere uses typed SSE events (event: + data: lines), similar to the\n * Claude Messages handler in messages.ts.\n */\n\nimport type * as http from \"node:http\";\nimport type {\n ChatCompletionRequest,\n ChatMessage,\n Fixture,\n HandlerDefaults,\n StreamingProfile,\n ToolCall,\n ToolDefinition,\n} from \"./types.js\";\nimport {\n generateMessageId,\n generateToolCallId,\n isTextResponse,\n isToolCallResponse,\n isErrorResponse,\n flattenHeaders,\n} from \"./helpers.js\";\nimport { matchFixture } from \"./router.js\";\nimport { writeErrorResponse, delay, calculateDelay } from \"./sse-writer.js\";\nimport { createInterruptionSignal } from \"./interruption.js\";\nimport type { Journal } from \"./journal.js\";\nimport type { Logger } from \"./logger.js\";\nimport { applyChaos } from \"./chaos.js\";\nimport { proxyAndRecord } from \"./recorder.js\";\n\n// ─── Cohere v2 Chat request types ───────────────────────────────────────────\n\ninterface CohereMessage {\n role: \"user\" | \"assistant\" | \"system\" | \"tool\";\n content: string;\n tool_call_id?: string;\n}\n\ninterface CohereToolDef {\n type: string;\n function: {\n name: string;\n description?: string;\n parameters?: object;\n };\n}\n\ninterface CohereRequest {\n model: string;\n messages: CohereMessage[];\n stream?: boolean;\n tools?: CohereToolDef[];\n response_format?: { type: string; json_schema?: object };\n}\n\n// ─── Cohere SSE event types ─────────────────────────────────────────────────\n\ninterface CohereSSEEvent {\n type: string;\n [key: string]: unknown;\n}\n\n// ─── Zero-value usage block ─────────────────────────────────────────────────\n\nconst ZERO_USAGE = {\n billed_units: { input_tokens: 0, output_tokens: 0, search_units: 0, classifications: 0 },\n tokens: { input_tokens: 0, output_tokens: 0 },\n};\n\n// ─── Input conversion: Cohere → ChatCompletionRequest ───────────────────────\n\nexport function cohereToCompletionRequest(req: CohereRequest): ChatCompletionRequest {\n const messages: ChatMessage[] = [];\n\n for (const msg of req.messages) {\n if (msg.role === \"system\") {\n messages.push({ role: \"system\", content: msg.content });\n } else if (msg.role === \"user\") {\n messages.push({ role: \"user\", content: msg.content });\n } else if (msg.role === \"assistant\") {\n messages.push({ role: \"assistant\", content: msg.content });\n } else if (msg.role === \"tool\") {\n messages.push({\n role: \"tool\",\n content: msg.content,\n tool_call_id: msg.tool_call_id,\n });\n }\n }\n\n // Convert tools\n let tools: ToolDefinition[] | undefined;\n if (req.tools && req.tools.length > 0) {\n tools = req.tools.map((t) => ({\n type: \"function\" as const,\n function: {\n name: t.function.name,\n description: t.function.description,\n parameters: t.function.parameters,\n },\n }));\n }\n\n return {\n model: req.model,\n messages,\n stream: req.stream,\n tools,\n };\n}\n\n// ─── Response building: fixture → Cohere v2 Chat format ─────────────────────\n\n// Non-streaming text response\nfunction buildCohereTextResponse(content: string): object {\n return {\n id: generateMessageId(),\n finish_reason: \"COMPLETE\",\n message: {\n role: \"assistant\",\n content: [{ type: \"text\", text: content }],\n tool_calls: [],\n tool_plan: \"\",\n citations: [],\n },\n usage: ZERO_USAGE,\n };\n}\n\n// Non-streaming tool call response\nfunction buildCohereToolCallResponse(toolCalls: ToolCall[], logger: Logger): object {\n const cohereCalls = toolCalls.map((tc) => {\n // Validate arguments JSON\n try {\n JSON.parse(tc.arguments || \"{}\");\n } catch {\n logger.warn(\n `Malformed JSON in fixture tool call arguments for \"${tc.name}\": ${tc.arguments}`,\n );\n }\n return {\n id: tc.id || generateToolCallId(),\n type: \"function\",\n function: {\n name: tc.name,\n arguments: tc.arguments || \"{}\",\n },\n };\n });\n\n return {\n id: generateMessageId(),\n finish_reason: \"TOOL_CALL\",\n message: {\n role: \"assistant\",\n content: [],\n tool_calls: cohereCalls,\n tool_plan: \"\",\n citations: [],\n },\n usage: ZERO_USAGE,\n };\n}\n\n// ─── Streaming event builders ───────────────────────────────────────────────\n\nfunction buildCohereTextStreamEvents(content: string, chunkSize: number): CohereSSEEvent[] {\n const msgId = generateMessageId();\n const events: CohereSSEEvent[] = [];\n\n // message-start\n events.push({\n id: msgId,\n type: \"message-start\",\n delta: {\n message: {\n role: \"assistant\",\n content: [],\n tool_plan: \"\",\n tool_calls: [],\n citations: [],\n },\n },\n });\n\n // content-start (type: \"text\" only, no text field)\n events.push({\n type: \"content-start\",\n index: 0,\n delta: {\n message: {\n content: { type: \"text\" },\n },\n },\n });\n\n // content-delta — text chunks\n for (let i = 0; i < content.length; i += chunkSize) {\n const slice = content.slice(i, i + chunkSize);\n events.push({\n type: \"content-delta\",\n index: 0,\n delta: {\n message: {\n content: { type: \"text\", text: slice },\n },\n },\n });\n }\n\n // content-end\n events.push({\n type: \"content-end\",\n index: 0,\n });\n\n // message-end\n events.push({\n type: \"message-end\",\n delta: {\n finish_reason: \"COMPLETE\",\n usage: ZERO_USAGE,\n },\n });\n\n return events;\n}\n\nfunction buildCohereToolCallStreamEvents(\n toolCalls: ToolCall[],\n chunkSize: number,\n logger: Logger,\n): CohereSSEEvent[] {\n const msgId = generateMessageId();\n const events: CohereSSEEvent[] = [];\n\n // message-start\n events.push({\n id: msgId,\n type: \"message-start\",\n delta: {\n message: {\n role: \"assistant\",\n content: [],\n tool_plan: \"\",\n tool_calls: [],\n citations: [],\n },\n },\n });\n\n // tool-plan-delta\n events.push({\n type: \"tool-plan-delta\",\n delta: {\n message: {\n tool_plan: \"I will use the requested tool.\",\n },\n },\n });\n\n for (let idx = 0; idx < toolCalls.length; idx++) {\n const tc = toolCalls[idx];\n const callId = tc.id || generateToolCallId();\n\n // Validate arguments JSON\n let argsJson: string;\n try {\n JSON.parse(tc.arguments || \"{}\");\n argsJson = tc.arguments || \"{}\";\n } catch {\n logger.warn(\n `Malformed JSON in fixture tool call arguments for \"${tc.name}\": ${tc.arguments}`,\n );\n argsJson = \"{}\";\n }\n\n // tool-call-start\n events.push({\n type: \"tool-call-start\",\n index: idx,\n delta: {\n message: {\n tool_calls: {\n id: callId,\n type: \"function\",\n function: {\n name: tc.name,\n arguments: \"\",\n },\n },\n },\n },\n });\n\n // tool-call-delta — chunked arguments\n for (let i = 0; i < argsJson.length; i += chunkSize) {\n const slice = argsJson.slice(i, i + chunkSize);\n events.push({\n type: \"tool-call-delta\",\n index: idx,\n delta: {\n message: {\n tool_calls: {\n function: {\n arguments: slice,\n },\n },\n },\n },\n });\n }\n\n // tool-call-end\n events.push({\n type: \"tool-call-end\",\n index: idx,\n });\n }\n\n // message-end\n events.push({\n type: \"message-end\",\n delta: {\n finish_reason: \"TOOL_CALL\",\n usage: ZERO_USAGE,\n },\n });\n\n return events;\n}\n\n// ─── SSE writer for Cohere typed events ─────────────────────────────────────\n\ninterface CohereStreamOptions {\n latency?: number;\n streamingProfile?: StreamingProfile;\n signal?: AbortSignal;\n onChunkSent?: () => void;\n}\n\nasync function writeCohereSSEStream(\n res: http.ServerResponse,\n events: CohereSSEEvent[],\n optionsOrLatency?: number | CohereStreamOptions,\n): Promise<boolean> {\n const opts: CohereStreamOptions =\n typeof optionsOrLatency === \"number\" ? { latency: optionsOrLatency } : (optionsOrLatency ?? {});\n const latency = opts.latency ?? 0;\n const profile = opts.streamingProfile;\n const signal = opts.signal;\n const onChunkSent = opts.onChunkSent;\n\n if (res.writableEnded) return true;\n res.setHeader(\"Content-Type\", \"text/event-stream\");\n res.setHeader(\"Cache-Control\", \"no-cache\");\n res.setHeader(\"Connection\", \"keep-alive\");\n\n let chunkIndex = 0;\n for (const event of events) {\n const chunkDelay = calculateDelay(chunkIndex, profile, latency);\n if (chunkDelay > 0) await delay(chunkDelay, signal);\n if (signal?.aborted) return false;\n if (res.writableEnded) return true;\n res.write(`event: ${event.type}\\ndata: ${JSON.stringify(event)}\\n\\n`);\n onChunkSent?.();\n if (signal?.aborted) return false;\n chunkIndex++;\n }\n\n if (!res.writableEnded) {\n res.end();\n }\n return true;\n}\n\n// ─── Request handler ────────────────────────────────────────────────────────\n\nexport async function handleCohere(\n req: http.IncomingMessage,\n res: http.ServerResponse,\n raw: string,\n fixtures: Fixture[],\n journal: Journal,\n defaults: HandlerDefaults,\n setCorsHeaders: (res: http.ServerResponse) => void,\n): Promise<void> {\n const { logger } = defaults;\n setCorsHeaders(res);\n\n let cohereReq: CohereRequest;\n try {\n cohereReq = JSON.parse(raw) as CohereRequest;\n } catch {\n journal.add({\n method: req.method ?? \"POST\",\n path: req.url ?? \"/v2/chat\",\n headers: flattenHeaders(req.headers),\n body: null,\n response: { status: 400, fixture: null },\n });\n writeErrorResponse(\n res,\n 400,\n JSON.stringify({\n error: {\n message: \"Malformed JSON\",\n type: \"invalid_request_error\",\n },\n }),\n );\n return;\n }\n\n // Validate required model field\n if (!cohereReq.model) {\n journal.add({\n method: req.method ?? \"POST\",\n path: req.url ?? \"/v2/chat\",\n headers: flattenHeaders(req.headers),\n body: null,\n response: { status: 400, fixture: null },\n });\n writeErrorResponse(\n res,\n 400,\n JSON.stringify({\n error: {\n message: \"model is required\",\n type: \"invalid_request_error\",\n },\n }),\n );\n return;\n }\n\n if (!cohereReq.messages || !Array.isArray(cohereReq.messages)) {\n journal.add({\n method: req.method ?? \"POST\",\n path: req.url ?? \"/v2/chat\",\n headers: flattenHeaders(req.headers),\n body: null,\n response: { status: 400, fixture: null },\n });\n writeErrorResponse(\n res,\n 400,\n JSON.stringify({\n error: {\n message: \"Invalid request: messages array is required\",\n type: \"invalid_request_error\",\n },\n }),\n );\n return;\n }\n\n // Convert to ChatCompletionRequest for fixture matching\n const completionReq = cohereToCompletionRequest(cohereReq);\n\n const fixture = matchFixture(fixtures, completionReq, journal.fixtureMatchCounts);\n\n if (fixture) {\n journal.incrementFixtureMatchCount(fixture, fixtures);\n }\n\n if (\n applyChaos(\n res,\n fixture,\n defaults.chaos,\n req.headers,\n journal,\n {\n method: req.method ?? \"POST\",\n path: req.url ?? \"/v2/chat\",\n headers: flattenHeaders(req.headers),\n body: completionReq,\n },\n defaults.registry,\n defaults.logger,\n )\n )\n return;\n\n if (!fixture) {\n if (defaults.record) {\n const proxied = await proxyAndRecord(\n req,\n res,\n completionReq,\n \"cohere\",\n req.url ?? \"/v2/chat\",\n fixtures,\n defaults,\n raw,\n );\n if (proxied) {\n journal.add({\n method: req.method ?? \"POST\",\n path: req.url ?? \"/v2/chat\",\n headers: flattenHeaders(req.headers),\n body: completionReq,\n response: { status: res.statusCode ?? 200, fixture: null },\n });\n return;\n }\n }\n const strictStatus = defaults.strict ? 503 : 404;\n const strictMessage = defaults.strict\n ? \"Strict mode: no fixture matched\"\n : \"No fixture matched\";\n if (defaults.strict) {\n logger.error(\n `STRICT: No fixture matched for ${req.method ?? \"POST\"} ${req.url ?? \"/v2/chat\"}`,\n );\n }\n journal.add({\n method: req.method ?? \"POST\",\n path: req.url ?? \"/v2/chat\",\n headers: flattenHeaders(req.headers),\n body: completionReq,\n response: { status: strictStatus, fixture: null },\n });\n writeErrorResponse(\n res,\n strictStatus,\n JSON.stringify({\n error: {\n message: strictMessage,\n type: \"invalid_request_error\",\n },\n }),\n );\n return;\n }\n\n const response = fixture.response;\n const latency = fixture.latency ?? defaults.latency;\n const chunkSize = Math.max(1, fixture.chunkSize ?? defaults.chunkSize);\n\n // Error response\n if (isErrorResponse(response)) {\n const status = response.status ?? 500;\n journal.add({\n method: req.method ?? \"POST\",\n path: req.url ?? \"/v2/chat\",\n headers: flattenHeaders(req.headers),\n body: completionReq,\n response: { status, fixture },\n });\n writeErrorResponse(res, status, JSON.stringify(response));\n return;\n }\n\n // Text response\n if (isTextResponse(response)) {\n const journalEntry = journal.add({\n method: req.method ?? \"POST\",\n path: req.url ?? \"/v2/chat\",\n headers: flattenHeaders(req.headers),\n body: completionReq,\n response: { status: 200, fixture },\n });\n if (cohereReq.stream !== true) {\n const body = buildCohereTextResponse(response.content);\n res.writeHead(200, { \"Content-Type\": \"application/json\" });\n res.end(JSON.stringify(body));\n } else {\n const events = buildCohereTextStreamEvents(response.content, chunkSize);\n const interruption = createInterruptionSignal(fixture);\n const completed = await writeCohereSSEStream(res, events, {\n latency,\n streamingProfile: fixture.streamingProfile,\n signal: interruption?.signal,\n onChunkSent: interruption?.tick,\n });\n if (!completed) {\n if (!res.writableEnded) res.destroy();\n journalEntry.response.interrupted = true;\n journalEntry.response.interruptReason = interruption?.reason();\n }\n interruption?.cleanup();\n }\n return;\n }\n\n // Tool call response\n if (isToolCallResponse(response)) {\n const journalEntry = journal.add({\n method: req.method ?? \"POST\",\n path: req.url ?? \"/v2/chat\",\n headers: flattenHeaders(req.headers),\n body: completionReq,\n response: { status: 200, fixture },\n });\n if (cohereReq.stream !== true) {\n const body = buildCohereToolCallResponse(response.toolCalls, logger);\n res.writeHead(200, { \"Content-Type\": \"application/json\" });\n res.end(JSON.stringify(body));\n } else {\n const events = buildCohereToolCallStreamEvents(response.toolCalls, chunkSize, logger);\n const interruption = createInterruptionSignal(fixture);\n const completed = await writeCohereSSEStream(res, events, {\n latency,\n streamingProfile: fixture.streamingProfile,\n signal: interruption?.signal,\n onChunkSent: interruption?.tick,\n });\n if (!completed) {\n if (!res.writableEnded) res.destroy();\n journalEntry.response.interrupted = true;\n journalEntry.response.interruptReason = interruption?.reason();\n }\n interruption?.cleanup();\n }\n return;\n }\n\n // Unknown response type\n journal.add({\n method: req.method ?? \"POST\",\n path: req.url ?? \"/v2/chat\",\n headers: flattenHeaders(req.headers),\n body: completionReq,\n response: { status: 500, fixture },\n });\n writeErrorResponse(\n res,\n 500,\n JSON.stringify({\n error: {\n message: \"Fixture response did not match any known type\",\n type: \"server_error\",\n },\n }),\n );\n}\n"],"mappings":";;;;;;;;AAuEA,MAAM,aAAa;CACjB,cAAc;EAAE,cAAc;EAAG,eAAe;EAAG,cAAc;EAAG,iBAAiB;EAAG;CACxF,QAAQ;EAAE,cAAc;EAAG,eAAe;EAAG;CAC9C;AAID,SAAgB,0BAA0B,KAA2C;CACnF,MAAM,WAA0B,EAAE;AAElC,MAAK,MAAM,OAAO,IAAI,SACpB,KAAI,IAAI,SAAS,SACf,UAAS,KAAK;EAAE,MAAM;EAAU,SAAS,IAAI;EAAS,CAAC;UAC9C,IAAI,SAAS,OACtB,UAAS,KAAK;EAAE,MAAM;EAAQ,SAAS,IAAI;EAAS,CAAC;UAC5C,IAAI,SAAS,YACtB,UAAS,KAAK;EAAE,MAAM;EAAa,SAAS,IAAI;EAAS,CAAC;UACjD,IAAI,SAAS,OACtB,UAAS,KAAK;EACZ,MAAM;EACN,SAAS,IAAI;EACb,cAAc,IAAI;EACnB,CAAC;CAKN,IAAI;AACJ,KAAI,IAAI,SAAS,IAAI,MAAM,SAAS,EAClC,SAAQ,IAAI,MAAM,KAAK,O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EhE,iBAAc,SAAS;;AAEzB;;AAIF,SAAQ,IAAI;EACV,QAAQ,IAAI,UAAU;EACtB,MAAM,IAAI,OAAO;EACjB,SAASN,+BAAe,IAAI,QAAQ;EACpC,MAAM;EACN,UAAU;GAAE,QAAQ;GAAK;GAAS;EACnC,CAAC;AACF,uCACE,KACA,KACA,KAAK,UAAU,EACb,OAAO;EACL,SAAS;EACT,MAAM;EACP,EACF,CAAC,CACH"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { Journal } from "./journal.cjs";
|
|
2
|
+
import { ChatCompletionRequest, Fixture, HandlerDefaults } from "./types.cjs";
|
|
3
|
+
import * as http from "node:http";
|
|
4
|
+
|
|
5
|
+
//#region src/cohere.d.ts
|
|
6
|
+
|
|
7
|
+
interface CohereMessage {
|
|
8
|
+
role: "user" | "assistant" | "system" | "tool";
|
|
9
|
+
content: string;
|
|
10
|
+
tool_call_id?: string;
|
|
11
|
+
}
|
|
12
|
+
interface CohereToolDef {
|
|
13
|
+
type: string;
|
|
14
|
+
function: {
|
|
15
|
+
name: string;
|
|
16
|
+
description?: string;
|
|
17
|
+
parameters?: object;
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
interface CohereRequest {
|
|
21
|
+
model: string;
|
|
22
|
+
messages: CohereMessage[];
|
|
23
|
+
stream?: boolean;
|
|
24
|
+
tools?: CohereToolDef[];
|
|
25
|
+
response_format?: {
|
|
26
|
+
type: string;
|
|
27
|
+
json_schema?: object;
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
declare function cohereToCompletionRequest(req: CohereRequest): ChatCompletionRequest;
|
|
31
|
+
declare function handleCohere(req: http.IncomingMessage, res: http.ServerResponse, raw: string, fixtures: Fixture[], journal: Journal, defaults: HandlerDefaults, setCorsHeaders: (res: http.ServerResponse) => void): Promise<void>;
|
|
32
|
+
//#endregion
|
|
33
|
+
export { cohereToCompletionRequest, handleCohere };
|
|
34
|
+
//# sourceMappingURL=cohere.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cohere.d.cts","names":[],"sources":["../src/cohere.ts"],"sourcesContent":[],"mappings":";;;;;;UAuCU,aAAA,CAuC+B;MAAM,EAAA,MAAA,GAAA,WAAA,GAAA,QAAA,GAAA,MAAA;SAAgB,EAAA,MAAA;EAAqB,YAAA,CAAA,EAAA,MAAA;AAmTpF;UApVU,aAAA,CAoVwB;MAC3B,EAAA,MAAK;UACA,EAAA;IAEA,IAAA,EAAA,MAAA;IACD,WAAA,CAAA,EAAA,MAAA;IACC,UAAA,CAAA,EAAA,MAAA;;;UAjVF,aAAA,CAmVA;;YAjVE;;UAEF;;;;;;iBAoBM,yBAAA,MAA+B,gBAAgB;iBAmTzC,YAAA,MACf,IAAA,CAAK,sBACL,IAAA,CAAK,uCAEA,oBACD,mBACC,uCACY,IAAA,CAAK,0BAC1B"}
|
package/dist/cohere.d.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { Journal } from "./journal.js";
|
|
2
|
+
import { ChatCompletionRequest, Fixture, HandlerDefaults } from "./types.js";
|
|
3
|
+
import * as http from "node:http";
|
|
4
|
+
|
|
5
|
+
//#region src/cohere.d.ts
|
|
6
|
+
|
|
7
|
+
interface CohereMessage {
|
|
8
|
+
role: "user" | "assistant" | "system" | "tool";
|
|
9
|
+
content: string;
|
|
10
|
+
tool_call_id?: string;
|
|
11
|
+
}
|
|
12
|
+
interface CohereToolDef {
|
|
13
|
+
type: string;
|
|
14
|
+
function: {
|
|
15
|
+
name: string;
|
|
16
|
+
description?: string;
|
|
17
|
+
parameters?: object;
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
interface CohereRequest {
|
|
21
|
+
model: string;
|
|
22
|
+
messages: CohereMessage[];
|
|
23
|
+
stream?: boolean;
|
|
24
|
+
tools?: CohereToolDef[];
|
|
25
|
+
response_format?: {
|
|
26
|
+
type: string;
|
|
27
|
+
json_schema?: object;
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
declare function cohereToCompletionRequest(req: CohereRequest): ChatCompletionRequest;
|
|
31
|
+
declare function handleCohere(req: http.IncomingMessage, res: http.ServerResponse, raw: string, fixtures: Fixture[], journal: Journal, defaults: HandlerDefaults, setCorsHeaders: (res: http.ServerResponse) => void): Promise<void>;
|
|
32
|
+
//#endregion
|
|
33
|
+
export { cohereToCompletionRequest, handleCohere };
|
|
34
|
+
//# sourceMappingURL=cohere.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cohere.d.ts","names":[],"sources":["../src/cohere.ts"],"sourcesContent":[],"mappings":";;;;;;UAuCU,aAAA,CAuC+B;MAAM,EAAA,MAAA,GAAA,WAAA,GAAA,QAAA,GAAA,MAAA;SAAgB,EAAA,MAAA;EAAqB,YAAA,CAAA,EAAA,MAAA;AAmTpF;UApVU,aAAA,CAoVwB;MAC3B,EAAA,MAAK;UACA,EAAA;IAEA,IAAA,EAAA,MAAA;IACD,WAAA,CAAA,EAAA,MAAA;IACC,UAAA,CAAA,EAAA,MAAA;;;UAjVF,aAAA,CAmVA;;YAjVE;;UAEF;;;;;;iBAoBM,yBAAA,MAA+B,gBAAgB;iBAmTzC,YAAA,MACf,IAAA,CAAK,sBACL,IAAA,CAAK,uCAEA,oBACD,mBACC,uCACY,IAAA,CAAK,0BAC1B"}
|