@wingman-ai/gateway 0.2.2 → 0.2.3
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/.wingman/agents/coding/agent.md +174 -169
- package/.wingman/agents/coding/implementor.md +25 -1
- package/.wingman/agents/main/agent.md +4 -0
- package/README.md +1 -0
- package/dist/agent/config/agentConfig.cjs +1 -1
- package/dist/agent/config/agentConfig.js +1 -1
- package/dist/agent/config/modelFactory.cjs +22 -2
- package/dist/agent/config/modelFactory.d.ts +2 -0
- package/dist/agent/config/modelFactory.js +22 -2
- package/dist/agent/tests/modelFactory.test.cjs +12 -5
- package/dist/agent/tests/modelFactory.test.js +12 -5
- package/dist/cli/commands/init.cjs +7 -6
- package/dist/cli/commands/init.js +7 -6
- package/dist/cli/commands/provider.cjs +17 -3
- package/dist/cli/commands/provider.js +17 -3
- package/dist/cli/config/loader.cjs +27 -0
- package/dist/cli/config/loader.js +27 -0
- package/dist/cli/config/schema.cjs +80 -2
- package/dist/cli/config/schema.d.ts +88 -0
- package/dist/cli/config/schema.js +67 -1
- package/dist/cli/core/agentInvoker.cjs +191 -13
- package/dist/cli/core/agentInvoker.d.ts +42 -3
- package/dist/cli/core/agentInvoker.js +163 -9
- package/dist/cli/core/sessionManager.cjs +32 -5
- package/dist/cli/core/sessionManager.js +32 -5
- package/dist/cli/index.cjs +6 -5
- package/dist/cli/index.js +6 -5
- package/dist/cli/types.d.ts +32 -0
- package/dist/gateway/http/sessions.cjs +7 -7
- package/dist/gateway/http/sessions.js +7 -7
- package/dist/gateway/server.cjs +191 -41
- package/dist/gateway/server.d.ts +8 -1
- package/dist/gateway/server.js +191 -41
- package/dist/gateway/types.d.ts +1 -0
- package/dist/providers/codex.cjs +167 -0
- package/dist/providers/codex.d.ts +15 -0
- package/dist/providers/codex.js +127 -0
- package/dist/providers/credentials.cjs +8 -0
- package/dist/providers/credentials.js +8 -0
- package/dist/providers/registry.cjs +11 -0
- package/dist/providers/registry.d.ts +1 -1
- package/dist/providers/registry.js +11 -0
- package/dist/tests/agentInvokerSummarization.test.cjs +296 -0
- package/dist/tests/agentInvokerSummarization.test.d.ts +1 -0
- package/dist/tests/agentInvokerSummarization.test.js +290 -0
- package/dist/tests/cli-config-loader.test.cjs +88 -0
- package/dist/tests/cli-config-loader.test.js +88 -0
- package/dist/tests/codex-credentials-precedence.test.cjs +94 -0
- package/dist/tests/codex-credentials-precedence.test.d.ts +1 -0
- package/dist/tests/codex-credentials-precedence.test.js +88 -0
- package/dist/tests/codex-provider.test.cjs +186 -0
- package/dist/tests/codex-provider.test.d.ts +1 -0
- package/dist/tests/codex-provider.test.js +180 -0
- package/dist/tests/gateway.test.cjs +108 -1
- package/dist/tests/gateway.test.js +108 -1
- package/dist/tests/provider-command-codex.test.cjs +57 -0
- package/dist/tests/provider-command-codex.test.d.ts +1 -0
- package/dist/tests/provider-command-codex.test.js +51 -0
- package/dist/tests/sessionStateMessages.test.cjs +38 -0
- package/dist/tests/sessionStateMessages.test.js +38 -0
- package/dist/webui/assets/{index-DDsMIOTX.css → index-BVMavpud.css} +1 -1
- package/dist/webui/assets/index-DCB2aVVf.js +182 -0
- package/dist/webui/index.html +2 -2
- package/package.json +1 -1
- package/dist/webui/assets/index-CPhfGPHc.js +0 -182
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
import { existsSync, mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { tmpdir } from "node:os";
|
|
3
|
+
import { dirname, join } from "node:path";
|
|
4
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
5
|
+
import { createCodexFetch, getCodexAuthPath, resolveCodexAuthFromFile } from "../providers/codex.js";
|
|
6
|
+
describe("codex provider", ()=>{
|
|
7
|
+
let codexHome;
|
|
8
|
+
const originalCodexHome = process.env.CODEX_HOME;
|
|
9
|
+
beforeEach(()=>{
|
|
10
|
+
codexHome = mkdtempSync(join(tmpdir(), "wingman-codex-"));
|
|
11
|
+
process.env.CODEX_HOME = codexHome;
|
|
12
|
+
delete process.env.CODEX_ACCESS_TOKEN;
|
|
13
|
+
delete process.env.CHATGPT_ACCESS_TOKEN;
|
|
14
|
+
});
|
|
15
|
+
afterEach(()=>{
|
|
16
|
+
if (void 0 === originalCodexHome) delete process.env.CODEX_HOME;
|
|
17
|
+
else process.env.CODEX_HOME = originalCodexHome;
|
|
18
|
+
if (existsSync(codexHome)) rmSync(codexHome, {
|
|
19
|
+
recursive: true,
|
|
20
|
+
force: true
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
it("reads access token and account id from codex auth file", ()=>{
|
|
24
|
+
writeCodexAuth({
|
|
25
|
+
tokens: {
|
|
26
|
+
access_token: "codex-access-token",
|
|
27
|
+
account_id: "acct_123"
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
const resolved = resolveCodexAuthFromFile();
|
|
31
|
+
expect(resolved.accessToken).toBe("codex-access-token");
|
|
32
|
+
expect(resolved.accountId).toBe("acct_123");
|
|
33
|
+
expect(resolved.authPath).toBe(join(codexHome, "auth.json"));
|
|
34
|
+
});
|
|
35
|
+
it("applies codex auth headers and forces store=false", async ()=>{
|
|
36
|
+
writeCodexAuth({
|
|
37
|
+
tokens: {
|
|
38
|
+
access_token: "file-token",
|
|
39
|
+
account_id: "acct_file"
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
const baseFetch = vi.fn(async (_input, _init)=>new Response("{}", {
|
|
43
|
+
status: 200
|
|
44
|
+
}));
|
|
45
|
+
const codexFetch = createCodexFetch({
|
|
46
|
+
baseFetch
|
|
47
|
+
});
|
|
48
|
+
await codexFetch("https://chatgpt.com/backend-api/codex/responses", {
|
|
49
|
+
method: "POST",
|
|
50
|
+
headers: {
|
|
51
|
+
"x-api-key": "placeholder"
|
|
52
|
+
},
|
|
53
|
+
body: JSON.stringify({
|
|
54
|
+
model: "codex-mini-latest",
|
|
55
|
+
input: "hello",
|
|
56
|
+
temperature: 1
|
|
57
|
+
})
|
|
58
|
+
});
|
|
59
|
+
expect(baseFetch).toHaveBeenCalledTimes(1);
|
|
60
|
+
const requestInit = baseFetch.mock.calls[0]?.[1];
|
|
61
|
+
expect(requestInit).toBeDefined();
|
|
62
|
+
const headers = new Headers(requestInit?.headers);
|
|
63
|
+
const payload = JSON.parse(String(requestInit?.body));
|
|
64
|
+
expect(headers.get("authorization")).toBe("Bearer file-token");
|
|
65
|
+
expect(headers.get("chatgpt-account-id")).toBe("acct_file");
|
|
66
|
+
expect(headers.get("x-api-key")).toBeNull();
|
|
67
|
+
expect(payload.store).toBe(false);
|
|
68
|
+
expect(payload.temperature).toBeUndefined();
|
|
69
|
+
expect(typeof payload.instructions).toBe("string");
|
|
70
|
+
expect(payload.instructions.length).toBeGreaterThan(0);
|
|
71
|
+
});
|
|
72
|
+
it("derives instructions from system/developer input when missing", async ()=>{
|
|
73
|
+
writeCodexAuth({
|
|
74
|
+
tokens: {
|
|
75
|
+
access_token: "file-token"
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
const baseFetch = vi.fn(async (_input, _init)=>new Response("{}", {
|
|
79
|
+
status: 200
|
|
80
|
+
}));
|
|
81
|
+
const codexFetch = createCodexFetch({
|
|
82
|
+
baseFetch
|
|
83
|
+
});
|
|
84
|
+
await codexFetch("https://chatgpt.com/backend-api/codex/responses", {
|
|
85
|
+
method: "POST",
|
|
86
|
+
body: JSON.stringify({
|
|
87
|
+
model: "gpt-5.3-codex",
|
|
88
|
+
input: [
|
|
89
|
+
{
|
|
90
|
+
role: "developer",
|
|
91
|
+
content: [
|
|
92
|
+
{
|
|
93
|
+
type: "input_text",
|
|
94
|
+
text: "Always run tests first."
|
|
95
|
+
}
|
|
96
|
+
]
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
role: "user",
|
|
100
|
+
content: [
|
|
101
|
+
{
|
|
102
|
+
type: "input_text",
|
|
103
|
+
text: "Fix the bug."
|
|
104
|
+
}
|
|
105
|
+
]
|
|
106
|
+
}
|
|
107
|
+
]
|
|
108
|
+
})
|
|
109
|
+
});
|
|
110
|
+
const requestInit = baseFetch.mock.calls[0]?.[1];
|
|
111
|
+
const payload = JSON.parse(String(requestInit?.body));
|
|
112
|
+
expect(payload.instructions).toBe("Always run tests first.");
|
|
113
|
+
});
|
|
114
|
+
it("preserves explicit instructions when provided", async ()=>{
|
|
115
|
+
writeCodexAuth({
|
|
116
|
+
tokens: {
|
|
117
|
+
access_token: "file-token"
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
const baseFetch = vi.fn(async (_input, _init)=>new Response("{}", {
|
|
121
|
+
status: 200
|
|
122
|
+
}));
|
|
123
|
+
const codexFetch = createCodexFetch({
|
|
124
|
+
baseFetch
|
|
125
|
+
});
|
|
126
|
+
await codexFetch("https://chatgpt.com/backend-api/codex/responses", {
|
|
127
|
+
method: "POST",
|
|
128
|
+
body: JSON.stringify({
|
|
129
|
+
model: "gpt-5.3-codex",
|
|
130
|
+
instructions: "Use concise answers.",
|
|
131
|
+
input: "hello"
|
|
132
|
+
})
|
|
133
|
+
});
|
|
134
|
+
const requestInit = baseFetch.mock.calls[0]?.[1];
|
|
135
|
+
const payload = JSON.parse(String(requestInit?.body));
|
|
136
|
+
expect(payload.instructions).toBe("Use concise answers.");
|
|
137
|
+
});
|
|
138
|
+
it("uses fallback token when codex auth file is unavailable", async ()=>{
|
|
139
|
+
const baseFetch = vi.fn(async (_input, _init)=>new Response("{}", {
|
|
140
|
+
status: 200
|
|
141
|
+
}));
|
|
142
|
+
const codexFetch = createCodexFetch({
|
|
143
|
+
baseFetch,
|
|
144
|
+
fallbackToken: "fallback-token"
|
|
145
|
+
});
|
|
146
|
+
await codexFetch("https://chatgpt.com/backend-api/codex/responses", {
|
|
147
|
+
method: "POST",
|
|
148
|
+
body: JSON.stringify({
|
|
149
|
+
model: "codex-mini-latest",
|
|
150
|
+
input: "hello"
|
|
151
|
+
})
|
|
152
|
+
});
|
|
153
|
+
const requestInit = baseFetch.mock.calls[0]?.[1];
|
|
154
|
+
expect(requestInit).toBeDefined();
|
|
155
|
+
const headers = new Headers(requestInit?.headers);
|
|
156
|
+
expect(headers.get("authorization")).toBe("Bearer fallback-token");
|
|
157
|
+
});
|
|
158
|
+
it("throws when no codex token is available", async ()=>{
|
|
159
|
+
const baseFetch = vi.fn(async (_input, _init)=>new Response("{}", {
|
|
160
|
+
status: 200
|
|
161
|
+
}));
|
|
162
|
+
const codexFetch = createCodexFetch({
|
|
163
|
+
baseFetch
|
|
164
|
+
});
|
|
165
|
+
await expect(codexFetch("https://chatgpt.com/backend-api/codex/responses", {
|
|
166
|
+
method: "POST",
|
|
167
|
+
body: JSON.stringify({
|
|
168
|
+
model: "codex-mini-latest",
|
|
169
|
+
input: "hello"
|
|
170
|
+
})
|
|
171
|
+
})).rejects.toThrow(/Codex credentials missing/);
|
|
172
|
+
});
|
|
173
|
+
});
|
|
174
|
+
function writeCodexAuth(payload) {
|
|
175
|
+
const authPath = getCodexAuthPath();
|
|
176
|
+
mkdirSync(dirname(authPath), {
|
|
177
|
+
recursive: true
|
|
178
|
+
});
|
|
179
|
+
writeFileSync(authPath, JSON.stringify(payload, null, 2));
|
|
180
|
+
}
|
|
@@ -16,7 +16,8 @@ const isBun = void 0 !== globalThis.Bun;
|
|
|
16
16
|
const describeIfBun = isBun ? external_vitest_namespaceObject.describe : external_vitest_namespaceObject.describe.skip;
|
|
17
17
|
external_vitest_namespaceObject.vi.mock("@/cli/core/agentInvoker.js", ()=>({
|
|
18
18
|
AgentInvoker: class {
|
|
19
|
-
async invokeAgent(_agentId,
|
|
19
|
+
async invokeAgent(_agentId, content, _sessionId, _attachments, options) {
|
|
20
|
+
if ("throw-no-event" === content) throw new Error("Synthetic invocation failure");
|
|
20
21
|
const signal = options?.signal;
|
|
21
22
|
await new Promise((resolve)=>{
|
|
22
23
|
const timer = setTimeout(resolve, 75);
|
|
@@ -333,6 +334,26 @@ describeIfBun("Gateway", ()=>{
|
|
|
333
334
|
desktopClient.close();
|
|
334
335
|
requester.close();
|
|
335
336
|
});
|
|
337
|
+
(0, external_vitest_namespaceObject.it)("should emit agent-error to requester when invocation throws without emitting", async ()=>{
|
|
338
|
+
const requester = await connectClient("session-error-requester");
|
|
339
|
+
const requestId = "req-invocation-error";
|
|
340
|
+
const sessionId = "session-error-test";
|
|
341
|
+
requester.send(JSON.stringify({
|
|
342
|
+
type: "req:agent",
|
|
343
|
+
id: requestId,
|
|
344
|
+
payload: {
|
|
345
|
+
agentId: "main",
|
|
346
|
+
sessionKey: sessionId,
|
|
347
|
+
content: "throw-no-event"
|
|
348
|
+
},
|
|
349
|
+
timestamp: Date.now()
|
|
350
|
+
}));
|
|
351
|
+
const errorMsg = await waitForMessage(requester, (msg)=>"event:agent" === msg.type && msg.id === requestId && msg.payload?.type === "agent-error");
|
|
352
|
+
(0, external_vitest_namespaceObject.expect)(errorMsg.payload?.error).toContain("Synthetic invocation failure");
|
|
353
|
+
(0, external_vitest_namespaceObject.expect)(errorMsg.payload?.sessionId).toBe(sessionId);
|
|
354
|
+
(0, external_vitest_namespaceObject.expect)(errorMsg.payload?.agentId).toBe("main");
|
|
355
|
+
requester.close();
|
|
356
|
+
});
|
|
336
357
|
(0, external_vitest_namespaceObject.it)("should cancel an in-flight agent request", async ()=>{
|
|
337
358
|
const requester = await connectClient("session-cancel-requester");
|
|
338
359
|
const requestId = "req-cancel-test";
|
|
@@ -361,6 +382,92 @@ describeIfBun("Gateway", ()=>{
|
|
|
361
382
|
]).toContain(ack.payload?.status);
|
|
362
383
|
requester.close();
|
|
363
384
|
});
|
|
385
|
+
(0, external_vitest_namespaceObject.it)("should queue and dequeue requests for the same session", async ()=>{
|
|
386
|
+
const requester = await connectClient("session-queue-requester");
|
|
387
|
+
const sessionId = `session-queue-${Date.now()}`;
|
|
388
|
+
const firstRequestId = `req-queue-first-${Date.now()}`;
|
|
389
|
+
const secondRequestId = `req-queue-second-${Date.now()}`;
|
|
390
|
+
const firstCompletePromise = waitForMessage(requester, (msg)=>"event:agent" === msg.type && msg.id === firstRequestId && msg.payload?.type === "agent-complete", 10000);
|
|
391
|
+
const queuedAckPromise = waitForMessage(requester, (msg)=>"ack" === msg.type && msg.id === secondRequestId && msg.payload?.action === "req:agent" && msg.payload?.status === "queued", 10000);
|
|
392
|
+
const queuedEventPromise = waitForMessage(requester, (msg)=>"event:agent" === msg.type && msg.id === secondRequestId && msg.payload?.type === "request-queued", 10000);
|
|
393
|
+
const dequeuedAckPromise = waitForMessage(requester, (msg)=>"ack" === msg.type && msg.id === secondRequestId && msg.payload?.action === "req:agent" && msg.payload?.status === "dequeued", 10000);
|
|
394
|
+
const secondCompletePromise = waitForMessage(requester, (msg)=>"event:agent" === msg.type && msg.id === secondRequestId && msg.payload?.type === "agent-complete", 10000);
|
|
395
|
+
requester.send(JSON.stringify({
|
|
396
|
+
type: "req:agent",
|
|
397
|
+
id: firstRequestId,
|
|
398
|
+
payload: {
|
|
399
|
+
agentId: "main",
|
|
400
|
+
sessionKey: sessionId,
|
|
401
|
+
content: "First queued request"
|
|
402
|
+
},
|
|
403
|
+
timestamp: Date.now()
|
|
404
|
+
}));
|
|
405
|
+
requester.send(JSON.stringify({
|
|
406
|
+
type: "req:agent",
|
|
407
|
+
id: secondRequestId,
|
|
408
|
+
payload: {
|
|
409
|
+
agentId: "main",
|
|
410
|
+
sessionKey: sessionId,
|
|
411
|
+
content: "Second queued request"
|
|
412
|
+
},
|
|
413
|
+
timestamp: Date.now()
|
|
414
|
+
}));
|
|
415
|
+
const queuedAck = await queuedAckPromise;
|
|
416
|
+
(0, external_vitest_namespaceObject.expect)(queuedAck.payload?.position).toBe(1);
|
|
417
|
+
const queuedEvent = await queuedEventPromise;
|
|
418
|
+
(0, external_vitest_namespaceObject.expect)(queuedEvent.payload?.position).toBe(1);
|
|
419
|
+
(0, external_vitest_namespaceObject.expect)(queuedEvent.payload?.sessionId).toBe(sessionId);
|
|
420
|
+
await firstCompletePromise;
|
|
421
|
+
const dequeuedAck = await dequeuedAckPromise;
|
|
422
|
+
(0, external_vitest_namespaceObject.expect)(dequeuedAck.payload?.remaining).toBe(0);
|
|
423
|
+
await secondCompletePromise;
|
|
424
|
+
requester.close();
|
|
425
|
+
});
|
|
426
|
+
(0, external_vitest_namespaceObject.it)("should cancel a queued request", async ()=>{
|
|
427
|
+
const requester = await connectClient("session-cancel-queued-requester");
|
|
428
|
+
const sessionId = `session-cancel-queued-${Date.now()}`;
|
|
429
|
+
const firstRequestId = `req-cancel-queued-first-${Date.now()}`;
|
|
430
|
+
const secondRequestId = `req-cancel-queued-second-${Date.now()}`;
|
|
431
|
+
const queuedAckPromise = waitForMessage(requester, (msg)=>"ack" === msg.type && msg.id === secondRequestId && msg.payload?.action === "req:agent" && msg.payload?.status === "queued", 10000);
|
|
432
|
+
requester.send(JSON.stringify({
|
|
433
|
+
type: "req:agent",
|
|
434
|
+
id: firstRequestId,
|
|
435
|
+
payload: {
|
|
436
|
+
agentId: "main",
|
|
437
|
+
sessionKey: sessionId,
|
|
438
|
+
content: "First request"
|
|
439
|
+
},
|
|
440
|
+
timestamp: Date.now()
|
|
441
|
+
}));
|
|
442
|
+
requester.send(JSON.stringify({
|
|
443
|
+
type: "req:agent",
|
|
444
|
+
id: secondRequestId,
|
|
445
|
+
payload: {
|
|
446
|
+
agentId: "main",
|
|
447
|
+
sessionKey: sessionId,
|
|
448
|
+
content: "Second request"
|
|
449
|
+
},
|
|
450
|
+
timestamp: Date.now()
|
|
451
|
+
}));
|
|
452
|
+
await queuedAckPromise;
|
|
453
|
+
requester.send(JSON.stringify({
|
|
454
|
+
type: "req:agent:cancel",
|
|
455
|
+
id: `cancel-${secondRequestId}`,
|
|
456
|
+
payload: {
|
|
457
|
+
requestId: secondRequestId
|
|
458
|
+
},
|
|
459
|
+
timestamp: Date.now()
|
|
460
|
+
}));
|
|
461
|
+
const cancelAck = await waitForMessage(requester, (msg)=>"ack" === msg.type && msg.payload?.action === "req:agent:cancel" && msg.payload?.requestId === secondRequestId && msg.payload?.status === "cancelled_queued", 10000);
|
|
462
|
+
(0, external_vitest_namespaceObject.expect)(cancelAck.payload?.status).toBe("cancelled_queued");
|
|
463
|
+
await waitForMessage(requester, (msg)=>"event:agent" === msg.type && msg.id === firstRequestId && msg.payload?.type === "agent-complete", 10000);
|
|
464
|
+
const queuedRequests = server.queuedSessionRequests;
|
|
465
|
+
const isStillQueued = [
|
|
466
|
+
...queuedRequests.values()
|
|
467
|
+
].some((queue)=>queue.some((item)=>item.msg?.id === secondRequestId));
|
|
468
|
+
(0, external_vitest_namespaceObject.expect)(isStillQueued).toBe(false);
|
|
469
|
+
requester.close();
|
|
470
|
+
});
|
|
364
471
|
(0, external_vitest_namespaceObject.it)("should clear session messages via API", async ()=>{
|
|
365
472
|
const createRes = await fetch(`http://localhost:${port}/api/sessions`, {
|
|
366
473
|
method: "POST",
|
|
@@ -14,7 +14,8 @@ const isBun = void 0 !== globalThis.Bun;
|
|
|
14
14
|
const describeIfBun = isBun ? describe : describe.skip;
|
|
15
15
|
vi.mock("@/cli/core/agentInvoker.js", ()=>({
|
|
16
16
|
AgentInvoker: class {
|
|
17
|
-
async invokeAgent(_agentId,
|
|
17
|
+
async invokeAgent(_agentId, content, _sessionId, _attachments, options) {
|
|
18
|
+
if ("throw-no-event" === content) throw new Error("Synthetic invocation failure");
|
|
18
19
|
const signal = options?.signal;
|
|
19
20
|
await new Promise((resolve)=>{
|
|
20
21
|
const timer = setTimeout(resolve, 75);
|
|
@@ -331,6 +332,26 @@ describeIfBun("Gateway", ()=>{
|
|
|
331
332
|
desktopClient.close();
|
|
332
333
|
requester.close();
|
|
333
334
|
});
|
|
335
|
+
it("should emit agent-error to requester when invocation throws without emitting", async ()=>{
|
|
336
|
+
const requester = await connectClient("session-error-requester");
|
|
337
|
+
const requestId = "req-invocation-error";
|
|
338
|
+
const sessionId = "session-error-test";
|
|
339
|
+
requester.send(JSON.stringify({
|
|
340
|
+
type: "req:agent",
|
|
341
|
+
id: requestId,
|
|
342
|
+
payload: {
|
|
343
|
+
agentId: "main",
|
|
344
|
+
sessionKey: sessionId,
|
|
345
|
+
content: "throw-no-event"
|
|
346
|
+
},
|
|
347
|
+
timestamp: Date.now()
|
|
348
|
+
}));
|
|
349
|
+
const errorMsg = await waitForMessage(requester, (msg)=>"event:agent" === msg.type && msg.id === requestId && msg.payload?.type === "agent-error");
|
|
350
|
+
expect(errorMsg.payload?.error).toContain("Synthetic invocation failure");
|
|
351
|
+
expect(errorMsg.payload?.sessionId).toBe(sessionId);
|
|
352
|
+
expect(errorMsg.payload?.agentId).toBe("main");
|
|
353
|
+
requester.close();
|
|
354
|
+
});
|
|
334
355
|
it("should cancel an in-flight agent request", async ()=>{
|
|
335
356
|
const requester = await connectClient("session-cancel-requester");
|
|
336
357
|
const requestId = "req-cancel-test";
|
|
@@ -359,6 +380,92 @@ describeIfBun("Gateway", ()=>{
|
|
|
359
380
|
]).toContain(ack.payload?.status);
|
|
360
381
|
requester.close();
|
|
361
382
|
});
|
|
383
|
+
it("should queue and dequeue requests for the same session", async ()=>{
|
|
384
|
+
const requester = await connectClient("session-queue-requester");
|
|
385
|
+
const sessionId = `session-queue-${Date.now()}`;
|
|
386
|
+
const firstRequestId = `req-queue-first-${Date.now()}`;
|
|
387
|
+
const secondRequestId = `req-queue-second-${Date.now()}`;
|
|
388
|
+
const firstCompletePromise = waitForMessage(requester, (msg)=>"event:agent" === msg.type && msg.id === firstRequestId && msg.payload?.type === "agent-complete", 10000);
|
|
389
|
+
const queuedAckPromise = waitForMessage(requester, (msg)=>"ack" === msg.type && msg.id === secondRequestId && msg.payload?.action === "req:agent" && msg.payload?.status === "queued", 10000);
|
|
390
|
+
const queuedEventPromise = waitForMessage(requester, (msg)=>"event:agent" === msg.type && msg.id === secondRequestId && msg.payload?.type === "request-queued", 10000);
|
|
391
|
+
const dequeuedAckPromise = waitForMessage(requester, (msg)=>"ack" === msg.type && msg.id === secondRequestId && msg.payload?.action === "req:agent" && msg.payload?.status === "dequeued", 10000);
|
|
392
|
+
const secondCompletePromise = waitForMessage(requester, (msg)=>"event:agent" === msg.type && msg.id === secondRequestId && msg.payload?.type === "agent-complete", 10000);
|
|
393
|
+
requester.send(JSON.stringify({
|
|
394
|
+
type: "req:agent",
|
|
395
|
+
id: firstRequestId,
|
|
396
|
+
payload: {
|
|
397
|
+
agentId: "main",
|
|
398
|
+
sessionKey: sessionId,
|
|
399
|
+
content: "First queued request"
|
|
400
|
+
},
|
|
401
|
+
timestamp: Date.now()
|
|
402
|
+
}));
|
|
403
|
+
requester.send(JSON.stringify({
|
|
404
|
+
type: "req:agent",
|
|
405
|
+
id: secondRequestId,
|
|
406
|
+
payload: {
|
|
407
|
+
agentId: "main",
|
|
408
|
+
sessionKey: sessionId,
|
|
409
|
+
content: "Second queued request"
|
|
410
|
+
},
|
|
411
|
+
timestamp: Date.now()
|
|
412
|
+
}));
|
|
413
|
+
const queuedAck = await queuedAckPromise;
|
|
414
|
+
expect(queuedAck.payload?.position).toBe(1);
|
|
415
|
+
const queuedEvent = await queuedEventPromise;
|
|
416
|
+
expect(queuedEvent.payload?.position).toBe(1);
|
|
417
|
+
expect(queuedEvent.payload?.sessionId).toBe(sessionId);
|
|
418
|
+
await firstCompletePromise;
|
|
419
|
+
const dequeuedAck = await dequeuedAckPromise;
|
|
420
|
+
expect(dequeuedAck.payload?.remaining).toBe(0);
|
|
421
|
+
await secondCompletePromise;
|
|
422
|
+
requester.close();
|
|
423
|
+
});
|
|
424
|
+
it("should cancel a queued request", async ()=>{
|
|
425
|
+
const requester = await connectClient("session-cancel-queued-requester");
|
|
426
|
+
const sessionId = `session-cancel-queued-${Date.now()}`;
|
|
427
|
+
const firstRequestId = `req-cancel-queued-first-${Date.now()}`;
|
|
428
|
+
const secondRequestId = `req-cancel-queued-second-${Date.now()}`;
|
|
429
|
+
const queuedAckPromise = waitForMessage(requester, (msg)=>"ack" === msg.type && msg.id === secondRequestId && msg.payload?.action === "req:agent" && msg.payload?.status === "queued", 10000);
|
|
430
|
+
requester.send(JSON.stringify({
|
|
431
|
+
type: "req:agent",
|
|
432
|
+
id: firstRequestId,
|
|
433
|
+
payload: {
|
|
434
|
+
agentId: "main",
|
|
435
|
+
sessionKey: sessionId,
|
|
436
|
+
content: "First request"
|
|
437
|
+
},
|
|
438
|
+
timestamp: Date.now()
|
|
439
|
+
}));
|
|
440
|
+
requester.send(JSON.stringify({
|
|
441
|
+
type: "req:agent",
|
|
442
|
+
id: secondRequestId,
|
|
443
|
+
payload: {
|
|
444
|
+
agentId: "main",
|
|
445
|
+
sessionKey: sessionId,
|
|
446
|
+
content: "Second request"
|
|
447
|
+
},
|
|
448
|
+
timestamp: Date.now()
|
|
449
|
+
}));
|
|
450
|
+
await queuedAckPromise;
|
|
451
|
+
requester.send(JSON.stringify({
|
|
452
|
+
type: "req:agent:cancel",
|
|
453
|
+
id: `cancel-${secondRequestId}`,
|
|
454
|
+
payload: {
|
|
455
|
+
requestId: secondRequestId
|
|
456
|
+
},
|
|
457
|
+
timestamp: Date.now()
|
|
458
|
+
}));
|
|
459
|
+
const cancelAck = await waitForMessage(requester, (msg)=>"ack" === msg.type && msg.payload?.action === "req:agent:cancel" && msg.payload?.requestId === secondRequestId && msg.payload?.status === "cancelled_queued", 10000);
|
|
460
|
+
expect(cancelAck.payload?.status).toBe("cancelled_queued");
|
|
461
|
+
await waitForMessage(requester, (msg)=>"event:agent" === msg.type && msg.id === firstRequestId && msg.payload?.type === "agent-complete", 10000);
|
|
462
|
+
const queuedRequests = server.queuedSessionRequests;
|
|
463
|
+
const isStillQueued = [
|
|
464
|
+
...queuedRequests.values()
|
|
465
|
+
].some((queue)=>queue.some((item)=>item.msg?.id === secondRequestId));
|
|
466
|
+
expect(isStillQueued).toBe(false);
|
|
467
|
+
requester.close();
|
|
468
|
+
});
|
|
362
469
|
it("should clear session messages via API", async ()=>{
|
|
363
470
|
const createRes = await fetch(`http://localhost:${port}/api/sessions`, {
|
|
364
471
|
method: "POST",
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_exports__ = {};
|
|
3
|
+
const external_node_fs_namespaceObject = require("node:fs");
|
|
4
|
+
const external_node_os_namespaceObject = require("node:os");
|
|
5
|
+
const external_node_path_namespaceObject = require("node:path");
|
|
6
|
+
const external_vitest_namespaceObject = require("vitest");
|
|
7
|
+
const provider_cjs_namespaceObject = require("../cli/commands/provider.cjs");
|
|
8
|
+
const codex_cjs_namespaceObject = require("../providers/codex.cjs");
|
|
9
|
+
(0, external_vitest_namespaceObject.describe)("provider command codex login", ()=>{
|
|
10
|
+
let codexHome;
|
|
11
|
+
const originalCodexHome = process.env.CODEX_HOME;
|
|
12
|
+
(0, external_vitest_namespaceObject.beforeEach)(()=>{
|
|
13
|
+
codexHome = (0, external_node_fs_namespaceObject.mkdtempSync)((0, external_node_path_namespaceObject.join)((0, external_node_os_namespaceObject.tmpdir)(), "wingman-provider-codex-"));
|
|
14
|
+
process.env.CODEX_HOME = codexHome;
|
|
15
|
+
});
|
|
16
|
+
(0, external_vitest_namespaceObject.afterEach)(()=>{
|
|
17
|
+
if (void 0 === originalCodexHome) delete process.env.CODEX_HOME;
|
|
18
|
+
else process.env.CODEX_HOME = originalCodexHome;
|
|
19
|
+
if ((0, external_node_fs_namespaceObject.existsSync)(codexHome)) (0, external_node_fs_namespaceObject.rmSync)(codexHome, {
|
|
20
|
+
recursive: true,
|
|
21
|
+
force: true
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
(0, external_vitest_namespaceObject.it)("uses existing codex login without requiring a token", async ()=>{
|
|
25
|
+
const authPath = (0, codex_cjs_namespaceObject.getCodexAuthPath)();
|
|
26
|
+
(0, external_node_fs_namespaceObject.mkdirSync)((0, external_node_path_namespaceObject.dirname)(authPath), {
|
|
27
|
+
recursive: true
|
|
28
|
+
});
|
|
29
|
+
(0, external_node_fs_namespaceObject.writeFileSync)(authPath, JSON.stringify({
|
|
30
|
+
tokens: {
|
|
31
|
+
access_token: "codex-access-token",
|
|
32
|
+
account_id: "acct_123"
|
|
33
|
+
}
|
|
34
|
+
}, null, 2));
|
|
35
|
+
const exitSpy = external_vitest_namespaceObject.vi.spyOn(process, "exit").mockImplementation((code)=>{
|
|
36
|
+
throw new Error(`process.exit(${code ?? "undefined"})`);
|
|
37
|
+
});
|
|
38
|
+
try {
|
|
39
|
+
await (0, external_vitest_namespaceObject.expect)((0, provider_cjs_namespaceObject.executeProviderCommand)({
|
|
40
|
+
subcommand: "login",
|
|
41
|
+
args: [
|
|
42
|
+
"codex"
|
|
43
|
+
],
|
|
44
|
+
verbosity: "silent",
|
|
45
|
+
outputMode: "json",
|
|
46
|
+
options: {}
|
|
47
|
+
})).resolves.toBeUndefined();
|
|
48
|
+
(0, external_vitest_namespaceObject.expect)(exitSpy).not.toHaveBeenCalled();
|
|
49
|
+
} finally{
|
|
50
|
+
exitSpy.mockRestore();
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
for(var __rspack_i in __webpack_exports__)exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
55
|
+
Object.defineProperty(exports, '__esModule', {
|
|
56
|
+
value: true
|
|
57
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { existsSync, mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { tmpdir } from "node:os";
|
|
3
|
+
import { dirname, join } from "node:path";
|
|
4
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
5
|
+
import { executeProviderCommand } from "../cli/commands/provider.js";
|
|
6
|
+
import { getCodexAuthPath } from "../providers/codex.js";
|
|
7
|
+
describe("provider command codex login", ()=>{
|
|
8
|
+
let codexHome;
|
|
9
|
+
const originalCodexHome = process.env.CODEX_HOME;
|
|
10
|
+
beforeEach(()=>{
|
|
11
|
+
codexHome = mkdtempSync(join(tmpdir(), "wingman-provider-codex-"));
|
|
12
|
+
process.env.CODEX_HOME = codexHome;
|
|
13
|
+
});
|
|
14
|
+
afterEach(()=>{
|
|
15
|
+
if (void 0 === originalCodexHome) delete process.env.CODEX_HOME;
|
|
16
|
+
else process.env.CODEX_HOME = originalCodexHome;
|
|
17
|
+
if (existsSync(codexHome)) rmSync(codexHome, {
|
|
18
|
+
recursive: true,
|
|
19
|
+
force: true
|
|
20
|
+
});
|
|
21
|
+
});
|
|
22
|
+
it("uses existing codex login without requiring a token", async ()=>{
|
|
23
|
+
const authPath = getCodexAuthPath();
|
|
24
|
+
mkdirSync(dirname(authPath), {
|
|
25
|
+
recursive: true
|
|
26
|
+
});
|
|
27
|
+
writeFileSync(authPath, JSON.stringify({
|
|
28
|
+
tokens: {
|
|
29
|
+
access_token: "codex-access-token",
|
|
30
|
+
account_id: "acct_123"
|
|
31
|
+
}
|
|
32
|
+
}, null, 2));
|
|
33
|
+
const exitSpy = vi.spyOn(process, "exit").mockImplementation((code)=>{
|
|
34
|
+
throw new Error(`process.exit(${code ?? "undefined"})`);
|
|
35
|
+
});
|
|
36
|
+
try {
|
|
37
|
+
await expect(executeProviderCommand({
|
|
38
|
+
subcommand: "login",
|
|
39
|
+
args: [
|
|
40
|
+
"codex"
|
|
41
|
+
],
|
|
42
|
+
verbosity: "silent",
|
|
43
|
+
outputMode: "json",
|
|
44
|
+
options: {}
|
|
45
|
+
})).resolves.toBeUndefined();
|
|
46
|
+
expect(exitSpy).not.toHaveBeenCalled();
|
|
47
|
+
} finally{
|
|
48
|
+
exitSpy.mockRestore();
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
});
|
|
@@ -65,6 +65,44 @@ const sessionManager_cjs_namespaceObject = require("../cli/core/sessionManager.c
|
|
|
65
65
|
content: "keep"
|
|
66
66
|
});
|
|
67
67
|
});
|
|
68
|
+
(0, external_vitest_namespaceObject.it)("extracts content from responses-style text blocks", ()=>{
|
|
69
|
+
const state = {
|
|
70
|
+
createdAt: 2000,
|
|
71
|
+
values: {
|
|
72
|
+
messages: [
|
|
73
|
+
{
|
|
74
|
+
role: "user",
|
|
75
|
+
content: [
|
|
76
|
+
{
|
|
77
|
+
type: "input_text",
|
|
78
|
+
text: "Build a plan"
|
|
79
|
+
}
|
|
80
|
+
]
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
role: "assistant",
|
|
84
|
+
content: [
|
|
85
|
+
{
|
|
86
|
+
type: "output_text",
|
|
87
|
+
text: "Here is the plan."
|
|
88
|
+
}
|
|
89
|
+
]
|
|
90
|
+
}
|
|
91
|
+
]
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
const result = (0, sessionManager_cjs_namespaceObject.extractMessagesFromState)(state);
|
|
95
|
+
(0, external_vitest_namespaceObject.expect)(result).not.toBeNull();
|
|
96
|
+
(0, external_vitest_namespaceObject.expect)(result).toHaveLength(2);
|
|
97
|
+
(0, external_vitest_namespaceObject.expect)(result?.[0]).toMatchObject({
|
|
98
|
+
role: "user",
|
|
99
|
+
content: "Build a plan"
|
|
100
|
+
});
|
|
101
|
+
(0, external_vitest_namespaceObject.expect)(result?.[1]).toMatchObject({
|
|
102
|
+
role: "assistant",
|
|
103
|
+
content: "Here is the plan."
|
|
104
|
+
});
|
|
105
|
+
});
|
|
68
106
|
});
|
|
69
107
|
for(var __rspack_i in __webpack_exports__)exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
70
108
|
Object.defineProperty(exports, '__esModule', {
|
|
@@ -63,4 +63,42 @@ describe("extractMessagesFromState", ()=>{
|
|
|
63
63
|
content: "keep"
|
|
64
64
|
});
|
|
65
65
|
});
|
|
66
|
+
it("extracts content from responses-style text blocks", ()=>{
|
|
67
|
+
const state = {
|
|
68
|
+
createdAt: 2000,
|
|
69
|
+
values: {
|
|
70
|
+
messages: [
|
|
71
|
+
{
|
|
72
|
+
role: "user",
|
|
73
|
+
content: [
|
|
74
|
+
{
|
|
75
|
+
type: "input_text",
|
|
76
|
+
text: "Build a plan"
|
|
77
|
+
}
|
|
78
|
+
]
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
role: "assistant",
|
|
82
|
+
content: [
|
|
83
|
+
{
|
|
84
|
+
type: "output_text",
|
|
85
|
+
text: "Here is the plan."
|
|
86
|
+
}
|
|
87
|
+
]
|
|
88
|
+
}
|
|
89
|
+
]
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
const result = extractMessagesFromState(state);
|
|
93
|
+
expect(result).not.toBeNull();
|
|
94
|
+
expect(result).toHaveLength(2);
|
|
95
|
+
expect(result?.[0]).toMatchObject({
|
|
96
|
+
role: "user",
|
|
97
|
+
content: "Build a plan"
|
|
98
|
+
});
|
|
99
|
+
expect(result?.[1]).toMatchObject({
|
|
100
|
+
role: "assistant",
|
|
101
|
+
content: "Here is the plan."
|
|
102
|
+
});
|
|
103
|
+
});
|
|
66
104
|
});
|