xcode-copilot-server 3.2.1 → 3.3.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/dist/banner.d.ts +11 -0
- package/dist/banner.js +20 -0
- package/dist/banner.js.map +1 -0
- package/dist/cli-validators.d.ts +3 -4
- package/dist/cli-validators.js +5 -27
- package/dist/cli-validators.js.map +1 -1
- package/dist/config.d.ts +22 -4
- package/dist/config.js +44 -1
- package/dist/config.js.map +1 -1
- package/dist/context.d.ts +1 -3
- package/dist/conversation-manager.d.ts +2 -9
- package/dist/conversation-manager.js +11 -0
- package/dist/conversation-manager.js.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/launchd/agent.d.ts +1 -1
- package/dist/providers/claude/handler.js +10 -28
- package/dist/providers/claude/handler.js.map +1 -1
- package/dist/providers/claude/provider.js +68 -3
- package/dist/providers/claude/provider.js.map +1 -1
- package/dist/providers/claude/streaming.d.ts +4 -6
- package/dist/providers/claude/streaming.js +15 -81
- package/dist/providers/claude/streaming.js.map +1 -1
- package/dist/providers/claude/tool-results.d.ts +1 -2
- package/dist/providers/claude/tool-results.js.map +1 -1
- package/dist/providers/codex/handler.js +9 -28
- package/dist/providers/codex/handler.js.map +1 -1
- package/dist/providers/codex/provider.js +77 -2
- package/dist/providers/codex/provider.js.map +1 -1
- package/dist/providers/codex/streaming.d.ts +4 -8
- package/dist/providers/codex/streaming.js +39 -141
- package/dist/providers/codex/streaming.js.map +1 -1
- package/dist/providers/codex/tool-results.d.ts +1 -2
- package/dist/providers/codex/tool-results.js.map +1 -1
- package/dist/providers/openai/handler.js +3 -6
- package/dist/providers/openai/handler.js.map +1 -1
- package/dist/providers/openai/provider.js +5 -3
- package/dist/providers/openai/provider.js.map +1 -1
- package/dist/providers/shared/prompt-utils.d.ts +11 -0
- package/dist/providers/shared/prompt-utils.js +26 -10
- package/dist/providers/shared/prompt-utils.js.map +1 -1
- package/dist/providers/shared/session-config.d.ts +2 -3
- package/dist/providers/shared/session-config.js +34 -69
- package/dist/providers/shared/session-config.js.map +1 -1
- package/dist/providers/shared/streaming-core.d.ts +3 -5
- package/dist/providers/shared/streaming-core.js +1 -1
- package/dist/providers/shared/streaming-core.js.map +1 -1
- package/dist/settings-patcher/codex.d.ts +1 -1
- package/dist/settings-patcher/index.d.ts +1 -1
- package/dist/settings-patcher/types.d.ts +1 -1
- package/dist/startup.js +8 -19
- package/dist/startup.js.map +1 -1
- package/dist/tool-bridge/index.d.ts +1 -1
- package/dist/tool-bridge/routes.d.ts +1 -1
- package/dist/tool-bridge/state.d.ts +1 -1
- package/dist/tool-bridge/tool-cache.d.ts +1 -1
- package/package.json +4 -7
|
@@ -1,53 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { sendSSEEvent as sendEvent, startReply, AnthropicProtocol, } from "copilot-sdk-proxy";
|
|
2
2
|
import { runSessionStreaming } from "../shared/streaming-core.js";
|
|
3
|
-
export
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
type: "message_start",
|
|
7
|
-
message: {
|
|
8
|
-
id: `msg_${String(Date.now())}`,
|
|
9
|
-
type: "message",
|
|
10
|
-
role: "assistant",
|
|
11
|
-
content: [],
|
|
12
|
-
model,
|
|
13
|
-
stop_reason: null,
|
|
14
|
-
usage: { input_tokens: 0, output_tokens: 0 },
|
|
15
|
-
},
|
|
16
|
-
};
|
|
17
|
-
sendEvent(reply, "message_start", messageStart);
|
|
18
|
-
}
|
|
19
|
-
function createAnthropicProtocol() {
|
|
20
|
-
let textBlockStarted = false;
|
|
21
|
-
function ensureTextBlock(r) {
|
|
22
|
-
if (!textBlockStarted) {
|
|
23
|
-
const blockStart = {
|
|
24
|
-
type: "content_block_start",
|
|
25
|
-
index: 0,
|
|
26
|
-
content_block: { type: "text", text: "" },
|
|
27
|
-
};
|
|
28
|
-
sendEvent(r, "content_block_start", blockStart);
|
|
29
|
-
textBlockStarted = true;
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
function sendBlockStop(r) {
|
|
33
|
-
sendEvent(r, "content_block_stop", {
|
|
34
|
-
type: "content_block_stop",
|
|
35
|
-
index: 0,
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
function sendEpilogue(r, stopReason) {
|
|
39
|
-
const messageDelta = {
|
|
40
|
-
type: "message_delta",
|
|
41
|
-
delta: { stop_reason: stopReason, stop_sequence: null },
|
|
42
|
-
usage: { output_tokens: 0 },
|
|
43
|
-
};
|
|
44
|
-
sendEvent(r, "message_delta", messageDelta);
|
|
45
|
-
sendEvent(r, "message_stop", { type: "message_stop" });
|
|
46
|
-
}
|
|
47
|
-
function emitToolUseBlocks(r, toolRequests) {
|
|
3
|
+
export { startReply };
|
|
4
|
+
class BridgeAnthropicProtocol extends AnthropicProtocol {
|
|
5
|
+
emitToolUseBlocks(r, toolRequests) {
|
|
48
6
|
let startIndex;
|
|
49
|
-
if (textBlockStarted) {
|
|
50
|
-
sendBlockStop(r);
|
|
7
|
+
if (this.textBlockStarted) {
|
|
8
|
+
this.sendBlockStop(r);
|
|
51
9
|
startIndex = 1;
|
|
52
10
|
}
|
|
53
11
|
else {
|
|
@@ -73,44 +31,20 @@ function createAnthropicProtocol() {
|
|
|
73
31
|
index++;
|
|
74
32
|
}
|
|
75
33
|
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
delta: { type: "text_delta", text },
|
|
84
|
-
};
|
|
85
|
-
sendEvent(r, "content_block_delta", delta);
|
|
86
|
-
}
|
|
87
|
-
},
|
|
88
|
-
emitToolsAndFinish(r, tools) {
|
|
89
|
-
emitToolUseBlocks(r, tools);
|
|
90
|
-
sendEpilogue(r, "tool_use");
|
|
91
|
-
},
|
|
92
|
-
sendCompleted(r) {
|
|
93
|
-
ensureTextBlock(r);
|
|
94
|
-
sendBlockStop(r);
|
|
95
|
-
sendEpilogue(r, "end_turn");
|
|
96
|
-
},
|
|
97
|
-
sendFailed(r) {
|
|
98
|
-
if (textBlockStarted)
|
|
99
|
-
sendBlockStop(r);
|
|
100
|
-
sendEpilogue(r, "end_turn");
|
|
101
|
-
},
|
|
102
|
-
teardown() { },
|
|
103
|
-
reset() {
|
|
104
|
-
textBlockStarted = false;
|
|
105
|
-
},
|
|
106
|
-
};
|
|
34
|
+
emitToolsAndFinish(r, tools) {
|
|
35
|
+
this.emitToolUseBlocks(r, tools);
|
|
36
|
+
this.sendEpilogue(r, "tool_use");
|
|
37
|
+
}
|
|
38
|
+
reset() {
|
|
39
|
+
this.textBlockStarted = false;
|
|
40
|
+
}
|
|
107
41
|
}
|
|
108
|
-
export async function handleAnthropicStreaming(state, session, prompt, model, logger, hasBridge
|
|
42
|
+
export async function handleAnthropicStreaming(state, session, prompt, model, logger, hasBridge, stats) {
|
|
109
43
|
const reply = state.currentReply;
|
|
110
44
|
if (!reply)
|
|
111
45
|
throw new Error("No reply set on bridge state");
|
|
112
46
|
startReply(reply, model);
|
|
113
|
-
const protocol =
|
|
47
|
+
const protocol = new BridgeAnthropicProtocol();
|
|
114
48
|
return runSessionStreaming(state, session, prompt, logger, hasBridge, protocol, reply, stats);
|
|
115
49
|
}
|
|
116
50
|
//# sourceMappingURL=streaming.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"streaming.js","sourceRoot":"","sources":["../../../src/providers/claude/streaming.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"streaming.js","sourceRoot":"","sources":["../../../src/providers/claude/streaming.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,YAAY,IAAI,SAAS,EACzB,UAAU,EACV,iBAAiB,GAClB,MAAM,mBAAmB,CAAC;AAG3B,OAAO,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAC;AAElE,OAAO,EAAE,UAAU,EAAE,CAAC;AAEtB,MAAM,uBAAwB,SAAQ,iBAAiB;IAC7C,iBAAiB,CACvB,CAAe,EACf,YAA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AI,CAAC,gBAAgB,GAAG,KAAK,CAAC;IAChC,CAAC;CACF;AAED,MAAM,CAAC,KAAK,UAAU,wBAAwB,CAC5C,KAAsB,EACtB,OAAuB,EACvB,MAAc,EACd,KAAa,EACb,MAAc,EACd,SAAkB,EAClB,KAAY;IAEZ,MAAM,KAAK,GAAG,KAAK,CAAC,YAAY,CAAC;IACjC,IAAI,CAAC,KAAK;QAAE,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAC;IAC5D,UAAU,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;IAEzB,MAAM,QAAQ,GAAG,IAAI,uBAAuB,EAAE,CAAC;IAC/C,OAAO,mBAAmB,CAAC,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,QAAQ,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC;AAChG,CAAC"}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type { AnthropicMessage } from "
|
|
1
|
+
import type { AnthropicMessage, Logger } from "copilot-sdk-proxy";
|
|
2
2
|
import type { ToolBridgeState } from "../../tool-bridge/state.js";
|
|
3
|
-
import type { Logger } from "../../logger.js";
|
|
4
3
|
export declare function resolveToolResults(messages: AnthropicMessage[], state: ToolBridgeState, logger: Logger): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tool-results.js","sourceRoot":"","sources":["../../../src/providers/claude/tool-results.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"tool-results.js","sourceRoot":"","sources":["../../../src/providers/claude/tool-results.ts"],"names":[],"mappings":"AAGA,MAAM,UAAU,kBAAkB,CAChC,QAA4B,EAC5B,KAAsB,EACtB,MAAc;IAEd,MAAM,OAAO,GAAG,QAAQ,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IAC9C,IAAI,CAAC,OAAO,IAAI,OAAO,CAAC,IAAI,KAAK,MAAM,IAAI,OAAO,OAAO,CAAC,OAAO,KAAK,QAAQ;QAAE,OAAO;IAEvF,KAAK,MAAM,KAAK,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC;QACpC,IAAI,KAAK,CAAC,IAAI,KAAK,aAAa,EAAE,CAAC;YACjC,MAAM,UAAU,GAAG,OAAO,KAAK,CAAC,OAAO,KAAK,QAAQ;gBAClD,CAAC,CAAC,KAAK,CAAC,OAAO;gBACf,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC;oBAC5B,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC;oBAC7C,CAAC,CAAC,EAAE,CAAC;YACT,MAAM,CAAC,KAAK,CAAC,6BAA6B,KAAK,CAAC,WAAW,EAAE,CAAC,CAAC;YAC/D,IAAI,CAAC,KAAK,CAAC,eAAe,CAAC,KAAK,CAAC,WAAW,EAAE,UAAU,CAAC,EAAE,CAAC;gBAC1D,MAAM,CAAC,IAAI,CAAC,0CAA0C,KAAK,CAAC,WAAW,EAAE,CAAC,CAAC;YAC7E,CAAC;QACH,CAAC;IACH,CAAC;AACH,CAAC"}
|
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
import { ResponsesRequestSchema, filterFunctionTools } from "
|
|
2
|
-
import { genId } from "./schemas.js";
|
|
3
|
-
import { formatResponsesPrompt, extractInstructions, extractFunctionCallOutputs, } from "./prompt.js";
|
|
4
|
-
import { resolveModel } from "../shared/model-resolver.js";
|
|
1
|
+
import { ResponsesRequestSchema, filterFunctionTools, genId, formatResponsesPrompt, extractInstructions, extractFunctionCallOutputs, resolveModelForSession, sendOpenAIError as sendError, } from "@copilot-proxy/core";
|
|
5
2
|
import { createSessionConfig } from "../shared/session-config.js";
|
|
3
|
+
import { filterExcludedFiles } from "../shared/prompt-utils.js";
|
|
6
4
|
import { resolveResponsesToolResults } from "./tool-results.js";
|
|
7
5
|
import { handleResponsesStreaming, startResponseStream } from "./streaming.js";
|
|
8
|
-
import { sendOpenAIError as sendError } from "../shared/errors.js";
|
|
9
6
|
export function createResponsesHandler({ service, logger, config, port, stats }, manager) {
|
|
10
7
|
return async function handleResponses(request, reply) {
|
|
11
8
|
stats.recordRequest();
|
|
@@ -67,7 +64,7 @@ export function createResponsesHandler({ service, logger, config, port, stats },
|
|
|
67
64
|
: req.input;
|
|
68
65
|
let prompt;
|
|
69
66
|
try {
|
|
70
|
-
prompt = formatResponsesPrompt(slicedInput, config.excludedFilePatterns);
|
|
67
|
+
prompt = filterExcludedFiles(formatResponsesPrompt(slicedInput), config.excludedFilePatterns);
|
|
71
68
|
}
|
|
72
69
|
catch (err) {
|
|
73
70
|
sendError(reply, 400, "invalid_request_error", err instanceof Error ? err.message : String(err));
|
|
@@ -87,29 +84,13 @@ export function createResponsesHandler({ service, logger, config, port, stats },
|
|
|
87
84
|
if (tools) {
|
|
88
85
|
logger.debug(`Tool names: ${tools.map((t) => t.name).join(", ")}`);
|
|
89
86
|
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
if (!resolved) {
|
|
96
|
-
sendError(reply, 400, "invalid_request_error", `Model "${req.model}" is not available. Available models: ${models.map((m) => m.id).join(", ")}`);
|
|
97
|
-
manager.remove(conversation.id);
|
|
98
|
-
return;
|
|
99
|
-
}
|
|
100
|
-
copilotModel = resolved;
|
|
101
|
-
if (config.reasoningEffort) {
|
|
102
|
-
const modelInfo = models.find((m) => m.id === copilotModel);
|
|
103
|
-
supportsReasoningEffort =
|
|
104
|
-
modelInfo?.capabilities.supports.reasoningEffort ?? false;
|
|
105
|
-
if (!supportsReasoningEffort) {
|
|
106
|
-
logger.debug(`Model "${copilotModel}" does not support reasoning effort, ignoring config`);
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
catch (err) {
|
|
111
|
-
logger.warn("Failed to list models, passing model through as-is:", err);
|
|
87
|
+
const resolved = await resolveModelForSession(service, req.model, config, logger);
|
|
88
|
+
if (!resolved.ok) {
|
|
89
|
+
sendError(reply, 400, "invalid_request_error", resolved.error);
|
|
90
|
+
manager.remove(conversation.id);
|
|
91
|
+
return;
|
|
112
92
|
}
|
|
93
|
+
const { model: copilotModel, supportsReasoningEffort } = resolved;
|
|
113
94
|
conversation.model = copilotModel;
|
|
114
95
|
if (hasBridge) {
|
|
115
96
|
logger.info("Tool bridge active (in-process MCP)");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handler.js","sourceRoot":"","sources":["../../../src/providers/codex/handler.ts"],"names":[],"mappings":"AAEA,OAAO,
|
|
1
|
+
{"version":3,"file":"handler.js","sourceRoot":"","sources":["../../../src/providers/codex/handler.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,sBAAsB,EACtB,mBAAmB,EACnB,KAAK,EACL,qBAAqB,EACrB,mBAAmB,EACnB,0BAA0B,EAC1B,sBAAsB,EACtB,eAAe,IAAI,SAAS,GAC7B,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAC;AAClE,OAAO,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AAEhE,OAAO,EAAE,2BAA2B,EAAE,MAAM,mBAAmB,CAAC;AAChE,OAAO,EAAE,wBAAwB,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAE/E,MAAM,UAAU,sBAAsB,CACpC,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,EAAc,EACpD,OAA4B;IAE5B,OAAO,KAAK,UAAU,eAAe,CACnC,OAAuB,EACvB,KAAmB;QAEnB,KAAK,CAAC,aAAa,EAAE,CAAC;QAEtB,MAAM,WAAW,GAAG,sBAAsB,CAAC,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QACnE,IAAI,CAAC,WAAW,CAAC,OAAO,EAAE,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.js";
|
|
2
|
-
import { createResponsesHandler } from "
|
|
2
|
+
import { createResponsesHandler, extractFunctionCallOutputs, filterFunctionTools, genId, } from "copilot-sdk-proxy";
|
|
3
|
+
import { resolveResponsesToolResults } from "./tool-results.js";
|
|
4
|
+
import { handleResponsesStreaming, startResponseStream } from "./streaming.js";
|
|
5
|
+
import { createSessionConfig } from "../shared/session-config.js";
|
|
6
|
+
import { filterExcludedFiles } from "../shared/prompt-utils.js";
|
|
3
7
|
export const codexProvider = {
|
|
4
8
|
name: "Codex",
|
|
5
9
|
routes: ["POST /v1/responses"],
|
|
@@ -18,7 +22,78 @@ export const codexProvider = {
|
|
|
18
22
|
done();
|
|
19
23
|
});
|
|
20
24
|
const manager = registerToolBridge(app, ctx.logger);
|
|
21
|
-
|
|
25
|
+
const { logger, config, port, stats } = ctx;
|
|
26
|
+
app.post("/v1/responses", createResponsesHandler(ctx, manager, {
|
|
27
|
+
beforeHandler: async (req, reply) => {
|
|
28
|
+
const callOutputs = extractFunctionCallOutputs(req.input);
|
|
29
|
+
logger.debug(`function_call_output items: ${String(callOutputs.length)}${callOutputs.length > 0 ? ` (call_ids: ${callOutputs.map((o) => o.call_id).join(", ")})` : ""}`);
|
|
30
|
+
if (callOutputs.length === 0)
|
|
31
|
+
return false;
|
|
32
|
+
const existingConv = manager.findByContinuationIds(callOutputs.map((o) => o.call_id));
|
|
33
|
+
if (!existingConv)
|
|
34
|
+
return false;
|
|
35
|
+
const state = existingConv.state;
|
|
36
|
+
logger.info(`Continuation for conversation ${existingConv.id} (hasPending=${String(state.hasPending)}, sessionActive=${String(state.sessionActive)})`);
|
|
37
|
+
state.setReply(reply);
|
|
38
|
+
startResponseStream(reply, genId("resp"), req.model);
|
|
39
|
+
reply.raw.on("close", () => {
|
|
40
|
+
if (state.currentReply === reply) {
|
|
41
|
+
logger.info("Client disconnected during continuation");
|
|
42
|
+
state.cleanup();
|
|
43
|
+
state.notifyStreamingDone();
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
resolveResponsesToolResults(callOutputs, state, logger);
|
|
47
|
+
await state.waitForStreamingDone();
|
|
48
|
+
existingConv.sentMessageCount = Array.isArray(req.input) ? req.input.length : 1;
|
|
49
|
+
return true;
|
|
50
|
+
},
|
|
51
|
+
onConversationReady: (conversation, req) => {
|
|
52
|
+
const { state } = conversation;
|
|
53
|
+
const tools = req.tools ? filterFunctionTools(req.tools) : undefined;
|
|
54
|
+
// Responses API tools use `parameters`, bridge uses `input_schema`
|
|
55
|
+
if (tools?.length) {
|
|
56
|
+
const bridgeTools = tools.map((t) => ({
|
|
57
|
+
name: t.name,
|
|
58
|
+
description: t.description,
|
|
59
|
+
input_schema: t.parameters ?? {},
|
|
60
|
+
}));
|
|
61
|
+
state.cacheTools(bridgeTools);
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
transformPrompt: (prompt) => filterExcludedFiles(prompt, config.excludedFilePatterns),
|
|
65
|
+
createSessionConfig: (baseOptions, conversation, req) => {
|
|
66
|
+
const tools = req.tools ? filterFunctionTools(req.tools) : undefined;
|
|
67
|
+
const hasBridge = !!tools?.length && config.toolBridge;
|
|
68
|
+
if (tools) {
|
|
69
|
+
logger.debug(`Tools in request: ${String(tools.length)}`);
|
|
70
|
+
logger.debug(`Tool names: ${tools.map((t) => t.name).join(", ")}`);
|
|
71
|
+
}
|
|
72
|
+
if (hasBridge) {
|
|
73
|
+
logger.info("Tool bridge active (in-process MCP)");
|
|
74
|
+
}
|
|
75
|
+
return createSessionConfig({
|
|
76
|
+
...baseOptions,
|
|
77
|
+
config,
|
|
78
|
+
hasToolBridge: hasBridge,
|
|
79
|
+
port,
|
|
80
|
+
conversationId: conversation.id,
|
|
81
|
+
});
|
|
82
|
+
},
|
|
83
|
+
handleStreaming: async ({ conversation, session, prompt, model, reply, req, responseId }) => {
|
|
84
|
+
const { state } = conversation;
|
|
85
|
+
const tools = req.tools ? filterFunctionTools(req.tools) : undefined;
|
|
86
|
+
const hasBridge = !!tools?.length && config.toolBridge;
|
|
87
|
+
state.setReply(reply);
|
|
88
|
+
const inputLength = Array.isArray(req.input) ? req.input.length : 1;
|
|
89
|
+
logger.info(`Streaming response for conversation ${conversation.id}`);
|
|
90
|
+
await handleResponsesStreaming(state, session, prompt, model, logger, hasBridge, responseId, stats);
|
|
91
|
+
conversation.sentMessageCount = inputLength;
|
|
92
|
+
if (conversation.isPrimary && state.hadError) {
|
|
93
|
+
manager.clearPrimary();
|
|
94
|
+
}
|
|
95
|
+
},
|
|
96
|
+
}));
|
|
22
97
|
},
|
|
23
98
|
};
|
|
24
99
|
//# sourceMappingURL=provider.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"provider.js","sourceRoot":"","sources":["../../../src/providers/codex/provider.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAChE,OAAO,
|
|
1
|
+
{"version":3,"file":"provider.js","sourceRoot":"","sources":["../../../src/providers/codex/provider.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAChE,OAAO,EACL,sBAAsB,EACtB,0BAA0B,EAC1B,mBAAmB,EACnB,KAAK,GACN,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAAE,2BAA2B,EAAE,MAAM,mBAAmB,CAAC;AAChE,OAAO,EAAE,wBAAwB,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAC/E,OAAO,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAC;AAClE,OAAO,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AAEhE,MAAM,CAAC,MAAM,aAAa,GAAG;IAC3B,IAAI,EAAE,OAAO;IACb,MAAM,EAAE,CAAC,oBAAoB,CAAC;IAE9B,QAAQ,CAAC,GAAG,EAAE,GAAG;QACf,GAAG,CAAC,OAAO,CAAC,WAAW,EAAE,CAAC,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE;Y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AE,CAAC;gBACzB,CAAC;YACH,CAAC;SACF,CAAC,CAAC,CAAC;IACN,CAAC;CACiB,CAAC"}
|
|
@@ -1,10 +1,6 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import
|
|
3
|
-
import type {
|
|
4
|
-
import type { Stats } from "../../stats.js";
|
|
1
|
+
import type { CopilotSession, Logger, Stats } from "copilot-sdk-proxy";
|
|
2
|
+
import { startResponseStream } from "copilot-sdk-proxy";
|
|
3
|
+
import type { SeqCounter } from "copilot-sdk-proxy";
|
|
5
4
|
import type { ToolBridgeState } from "../../tool-bridge/state.js";
|
|
6
|
-
export
|
|
7
|
-
value: number;
|
|
8
|
-
}
|
|
9
|
-
export declare function startResponseStream(reply: FastifyReply, responseId: string, model: string, seq?: SeqCounter): SeqCounter;
|
|
5
|
+
export { type SeqCounter, startResponseStream };
|
|
10
6
|
export declare function handleResponsesStreaming(state: ToolBridgeState, session: CopilotSession, prompt: string, model: string, logger: Logger, hasBridge: boolean, responseId: string, stats: Stats): Promise<void>;
|
|
@@ -1,87 +1,21 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { SSE_HEADERS, sendSSEEvent as sendEvent, sendSSEComment } from "../shared/streaming-utils.js";
|
|
1
|
+
import { sendSSEEvent as sendEvent, sendSSEComment, genId, nextSeq, startResponseStream, ResponsesProtocol, } from "copilot-sdk-proxy";
|
|
3
2
|
import { runSessionStreaming } from "../shared/streaming-core.js";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
sendEvent(reply, "response.created", { response }, nextSeq(counter));
|
|
19
|
-
sendEvent(reply, "response.in_progress", { response }, nextSeq(counter));
|
|
20
|
-
return counter;
|
|
21
|
-
}
|
|
22
|
-
function createResponsesProtocol(responseId, model, seq, getReply) {
|
|
23
|
-
let messageItem = null;
|
|
24
|
-
let messageStarted = false;
|
|
25
|
-
let outputIndex = 0;
|
|
26
|
-
const outputItems = [];
|
|
27
|
-
const accumulatedText = [];
|
|
28
|
-
// Keepalive every 15s so the client doesn't time out while
|
|
29
|
-
// waiting for internal tool execution to finish
|
|
30
|
-
const keepaliveInterval = setInterval(() => {
|
|
31
|
-
const r = getReply();
|
|
32
|
-
if (r)
|
|
33
|
-
sendSSEComment(r);
|
|
34
|
-
}, 15_000);
|
|
35
|
-
function ensureMessageItem(r) {
|
|
36
|
-
if (!messageStarted) {
|
|
37
|
-
messageItem = {
|
|
38
|
-
type: "message",
|
|
39
|
-
id: genId("msg"),
|
|
40
|
-
status: "in_progress",
|
|
41
|
-
role: "assistant",
|
|
42
|
-
content: [],
|
|
43
|
-
};
|
|
44
|
-
sendEvent(r, "response.output_item.added", {
|
|
45
|
-
output_index: outputIndex,
|
|
46
|
-
item: messageItem,
|
|
47
|
-
}, nextSeq(seq));
|
|
48
|
-
sendEvent(r, "response.content_part.added", {
|
|
49
|
-
item_id: messageItem.id,
|
|
50
|
-
output_index: outputIndex,
|
|
51
|
-
content_index: 0,
|
|
52
|
-
part: { type: "output_text", text: "", annotations: [] },
|
|
53
|
-
}, nextSeq(seq));
|
|
54
|
-
messageStarted = true;
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
function closeMessageItem(r) {
|
|
58
|
-
if (!messageStarted || !messageItem)
|
|
59
|
-
return;
|
|
60
|
-
const fullText = accumulatedText.join("");
|
|
61
|
-
sendEvent(r, "response.output_text.done", {
|
|
62
|
-
item_id: messageItem.id,
|
|
63
|
-
output_index: outputIndex,
|
|
64
|
-
content_index: 0,
|
|
65
|
-
text: fullText,
|
|
66
|
-
}, nextSeq(seq));
|
|
67
|
-
sendEvent(r, "response.content_part.done", {
|
|
68
|
-
item_id: messageItem.id,
|
|
69
|
-
output_index: outputIndex,
|
|
70
|
-
content_index: 0,
|
|
71
|
-
part: { type: "output_text", text: fullText, annotations: [] },
|
|
72
|
-
}, nextSeq(seq));
|
|
73
|
-
messageItem.status = "completed";
|
|
74
|
-
messageItem.content = [{ type: "output_text", text: fullText, annotations: [] }];
|
|
75
|
-
outputItems.push(messageItem);
|
|
76
|
-
sendEvent(r, "response.output_item.done", {
|
|
77
|
-
output_index: outputIndex,
|
|
78
|
-
item: messageItem,
|
|
79
|
-
}, nextSeq(seq));
|
|
80
|
-
outputIndex++;
|
|
81
|
-
messageStarted = false;
|
|
82
|
-
messageItem = null;
|
|
3
|
+
export { startResponseStream };
|
|
4
|
+
class BridgeResponsesProtocol extends ResponsesProtocol {
|
|
5
|
+
keepaliveInterval;
|
|
6
|
+
getReply;
|
|
7
|
+
constructor(responseId, model, seq, getReply) {
|
|
8
|
+
super(responseId, model, seq);
|
|
9
|
+
this.getReply = getReply;
|
|
10
|
+
// Keepalive every 15s so the client doesn't time out while
|
|
11
|
+
// waiting for internal tool execution to finish
|
|
12
|
+
this.keepaliveInterval = setInterval(() => {
|
|
13
|
+
const r = this.getReply();
|
|
14
|
+
if (r)
|
|
15
|
+
sendSSEComment(r);
|
|
16
|
+
}, 15_000);
|
|
83
17
|
}
|
|
84
|
-
|
|
18
|
+
emitFunctionCallItems(r, toolRequests) {
|
|
85
19
|
for (const tr of toolRequests) {
|
|
86
20
|
const callId = tr.toolCallId;
|
|
87
21
|
const itemId = genId("fc");
|
|
@@ -95,78 +29,42 @@ function createResponsesProtocol(responseId, model, seq, getReply) {
|
|
|
95
29
|
status: "in_progress",
|
|
96
30
|
};
|
|
97
31
|
sendEvent(r, "response.output_item.added", {
|
|
98
|
-
output_index: outputIndex,
|
|
32
|
+
output_index: this.outputIndex,
|
|
99
33
|
item: fcItem,
|
|
100
|
-
}, nextSeq(seq));
|
|
34
|
+
}, nextSeq(this.seq));
|
|
101
35
|
const doneItem = { ...fcItem, status: "completed" };
|
|
102
36
|
sendEvent(r, "response.output_item.done", {
|
|
103
|
-
output_index: outputIndex,
|
|
37
|
+
output_index: this.outputIndex,
|
|
104
38
|
item: doneItem,
|
|
105
|
-
}, nextSeq(seq));
|
|
106
|
-
outputItems.push(doneItem);
|
|
107
|
-
outputIndex++;
|
|
39
|
+
}, nextSeq(this.seq));
|
|
40
|
+
this.outputItems.push(doneItem);
|
|
41
|
+
this.outputIndex++;
|
|
108
42
|
}
|
|
109
43
|
}
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
44
|
+
emitToolsAndFinish(r, tools) {
|
|
45
|
+
this.closeMessageItem(r);
|
|
46
|
+
this.emitFunctionCallItems(r, tools);
|
|
47
|
+
this.sendResponseEnvelope(r, "completed");
|
|
48
|
+
}
|
|
49
|
+
teardown() {
|
|
50
|
+
clearInterval(this.keepaliveInterval);
|
|
51
|
+
}
|
|
52
|
+
reset() {
|
|
53
|
+
this.messageStarted = false;
|
|
54
|
+
this.messageItem = null;
|
|
55
|
+
this.outputIndex = 0;
|
|
56
|
+
this.outputItems.length = 0;
|
|
57
|
+
this.accumulatedText.length = 0;
|
|
58
|
+
// Sequence numbers must keep incrementing across tool-call cycles
|
|
59
|
+
// within the same response, so we deliberately leave seq alone.
|
|
120
60
|
}
|
|
121
|
-
return {
|
|
122
|
-
flushDeltas(r, deltas) {
|
|
123
|
-
ensureMessageItem(r);
|
|
124
|
-
if (!messageItem)
|
|
125
|
-
return;
|
|
126
|
-
for (const text of deltas) {
|
|
127
|
-
sendEvent(r, "response.output_text.delta", {
|
|
128
|
-
item_id: messageItem.id,
|
|
129
|
-
output_index: outputIndex,
|
|
130
|
-
content_index: 0,
|
|
131
|
-
delta: text,
|
|
132
|
-
}, nextSeq(seq));
|
|
133
|
-
accumulatedText.push(text);
|
|
134
|
-
}
|
|
135
|
-
},
|
|
136
|
-
emitToolsAndFinish(r, tools) {
|
|
137
|
-
closeMessageItem(r);
|
|
138
|
-
emitFunctionCallItems(r, tools);
|
|
139
|
-
sendResponseEnvelope(r, "completed");
|
|
140
|
-
},
|
|
141
|
-
sendCompleted(r) {
|
|
142
|
-
if (!messageStarted)
|
|
143
|
-
ensureMessageItem(r);
|
|
144
|
-
closeMessageItem(r);
|
|
145
|
-
sendResponseEnvelope(r, "completed");
|
|
146
|
-
},
|
|
147
|
-
sendFailed(r) {
|
|
148
|
-
if (messageStarted)
|
|
149
|
-
closeMessageItem(r);
|
|
150
|
-
sendResponseEnvelope(r, "failed");
|
|
151
|
-
},
|
|
152
|
-
teardown() {
|
|
153
|
-
clearInterval(keepaliveInterval);
|
|
154
|
-
},
|
|
155
|
-
reset() {
|
|
156
|
-
messageStarted = false;
|
|
157
|
-
messageItem = null;
|
|
158
|
-
outputIndex = 0;
|
|
159
|
-
outputItems.length = 0;
|
|
160
|
-
accumulatedText.length = 0;
|
|
161
|
-
},
|
|
162
|
-
};
|
|
163
61
|
}
|
|
164
62
|
export async function handleResponsesStreaming(state, session, prompt, model, logger, hasBridge, responseId, stats) {
|
|
165
63
|
const reply = state.currentReply;
|
|
166
64
|
if (!reply)
|
|
167
65
|
throw new Error("No reply set on bridge state");
|
|
168
66
|
const seq = startResponseStream(reply, responseId, model);
|
|
169
|
-
const protocol =
|
|
67
|
+
const protocol = new BridgeResponsesProtocol(responseId, model, seq, () => state.currentReply);
|
|
170
68
|
return runSessionStreaming(state, session, prompt, logger, hasBridge, protocol, reply, stats);
|
|
171
69
|
}
|
|
172
70
|
//# sourceMappingURL=streaming.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"streaming.js","sourceRoot":"","sources":["../../../src/providers/codex/streaming.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"streaming.js","sourceRoot":"","sources":["../../../src/providers/codex/streaming.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,YAAY,IAAI,SAAS,EACzB,cAAc,EACd,KAAK,EACL,OAAO,EACP,mBAAmB,EACnB,iBAAiB,GAClB,MAAM,mBAAmB,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I,CAAC,KAAK;QAAE,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAC;IAC5D,MAAM,GAAG,GAAG,mBAAmB,CAAC,KAAK,EAAE,UAAU,EAAE,KAAK,CAAC,CAAC;IAE1D,MAAM,QAAQ,GAAG,IAAI,uBAAuB,CAAC,UAAU,EAAE,KAAK,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC;IAC/F,OAAO,mBAAmB,CAAC,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,QAAQ,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC;AAChG,CAAC"}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type { FunctionCallOutputInput } from "
|
|
1
|
+
import type { FunctionCallOutputInput, Logger } from "copilot-sdk-proxy";
|
|
2
2
|
import type { ToolBridgeState } from "../../tool-bridge/state.js";
|
|
3
|
-
import type { Logger } from "../../logger.js";
|
|
4
3
|
export declare function resolveResponsesToolResults(outputs: FunctionCallOutputInput[], state: ToolBridgeState, logger: Logger): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tool-results.js","sourceRoot":"","sources":["../../../src/providers/codex/tool-results.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"tool-results.js","sourceRoot":"","sources":["../../../src/providers/codex/tool-results.ts"],"names":[],"mappings":"AAGA,MAAM,UAAU,2BAA2B,CACzC,OAAkC,EAClC,KAAsB,EACtB,MAAc;IAEd,KAAK,MAAM,IAAI,IAAI,OAAO,EAAE,CAAC;QAC3B,MAAM,CAAC,KAAK,CAAC,6BAA6B,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC;QAC1D,IAAI,CAAC,KAAK,CAAC,eAAe,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC;YACtD,MAAM,CAAC,IAAI,CAAC,sCAAsC,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC;QACpE,CAAC;IACH,CAAC;AACH,CAAC"}
|
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
import { ChatCompletionRequestSchema, extractContentText } from "
|
|
2
|
-
import {
|
|
3
|
-
import { createSessionConfig } from "../shared/session-config.js";
|
|
4
|
-
import { handleStreaming } from "./streaming.js";
|
|
5
|
-
import { sendOpenAIError as sendError } from "../shared/errors.js";
|
|
1
|
+
import { ChatCompletionRequestSchema, extractContentText, formatPrompt, createSessionConfig, handleOpenAIStreaming as handleStreaming, sendOpenAIError as sendError, } from "@copilot-proxy/core";
|
|
2
|
+
import { filterExcludedFiles } from "../shared/prompt-utils.js";
|
|
6
3
|
export function createCompletionsHandler({ service, logger, config, stats }, manager) {
|
|
7
4
|
return async function handleCompletions(request, reply) {
|
|
8
5
|
stats.recordRequest();
|
|
@@ -40,7 +37,7 @@ export function createCompletionsHandler({ service, logger, config, stats }, man
|
|
|
40
37
|
}
|
|
41
38
|
let prompt;
|
|
42
39
|
try {
|
|
43
|
-
prompt = formatPrompt(messages.slice(conversation.sentMessageCount), config.excludedFilePatterns);
|
|
40
|
+
prompt = filterExcludedFiles(formatPrompt(messages.slice(conversation.sentMessageCount)), config.excludedFilePatterns);
|
|
44
41
|
}
|
|
45
42
|
catch (err) {
|
|
46
43
|
sendError(reply, 400, "invalid_request_error", err instanceof Error ? err.message : String(err));
|