@theia/ai-codex 1.77.0-next.0 → 1.77.0-next.101
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/lib/browser/codex-chat-agent.d.ts +2 -2
- package/lib/browser/codex-chat-agent.d.ts.map +1 -1
- package/lib/browser/codex-chat-agent.js +57 -66
- package/lib/browser/codex-chat-agent.js.map +1 -1
- package/lib/browser/codex-chat-agent.spec.js +151 -153
- package/lib/browser/codex-chat-agent.spec.js.map +1 -1
- package/lib/browser/codex-frontend-module.js +32 -34
- package/lib/browser/codex-frontend-module.js.map +1 -1
- package/lib/browser/codex-frontend-service.d.ts +1 -1
- package/lib/browser/codex-frontend-service.d.ts.map +1 -1
- package/lib/browser/codex-frontend-service.js +25 -32
- package/lib/browser/codex-frontend-service.js.map +1 -1
- package/lib/browser/codex-frontend-service.spec.js +53 -55
- package/lib/browser/codex-frontend-service.spec.js.map +1 -1
- package/lib/browser/codex-tool-call-content.js +2 -6
- package/lib/browser/codex-tool-call-content.js.map +1 -1
- package/lib/browser/renderers/collapsible-tool-renderer.js +6 -10
- package/lib/browser/renderers/collapsible-tool-renderer.js.map +1 -1
- package/lib/browser/renderers/command-execution-renderer.d.ts +1 -1
- package/lib/browser/renderers/command-execution-renderer.d.ts.map +1 -1
- package/lib/browser/renderers/command-execution-renderer.js +16 -20
- package/lib/browser/renderers/command-execution-renderer.js.map +1 -1
- package/lib/browser/renderers/todo-list-renderer.d.ts +1 -1
- package/lib/browser/renderers/todo-list-renderer.d.ts.map +1 -1
- package/lib/browser/renderers/todo-list-renderer.js +22 -26
- package/lib/browser/renderers/todo-list-renderer.js.map +1 -1
- package/lib/browser/renderers/web-search-renderer.d.ts +1 -1
- package/lib/browser/renderers/web-search-renderer.d.ts.map +1 -1
- package/lib/browser/renderers/web-search-renderer.js +15 -19
- package/lib/browser/renderers/web-search-renderer.js.map +1 -1
- package/lib/common/codex-preferences.js +8 -11
- package/lib/common/codex-preferences.js.map +1 -1
- package/lib/common/codex-service.js +3 -6
- package/lib/common/codex-service.js.map +1 -1
- package/lib/common/index.d.ts +2 -2
- package/lib/common/index.d.ts.map +1 -1
- package/lib/common/index.js +2 -5
- package/lib/common/index.js.map +1 -1
- package/lib/node/codex-backend-module.js +12 -14
- package/lib/node/codex-backend-module.js.map +1 -1
- package/lib/node/codex-service-impl.d.ts +1 -1
- package/lib/node/codex-service-impl.d.ts.map +1 -1
- package/lib/node/codex-service-impl.js +9 -13
- package/lib/node/codex-service-impl.js.map +1 -1
- package/package.json +20 -11
- package/src/browser/codex-chat-agent.spec.ts +2 -2
- package/src/browser/codex-chat-agent.ts +2 -2
- package/src/browser/codex-frontend-module.ts +7 -7
- package/src/browser/codex-frontend-service.spec.ts +3 -3
- package/src/browser/codex-frontend-service.ts +1 -1
- package/src/browser/renderers/command-execution-renderer.tsx +1 -1
- package/src/browser/renderers/todo-list-renderer.tsx +2 -2
- package/src/browser/renderers/web-search-renderer.tsx +1 -1
- package/src/common/index.ts +2 -2
- package/src/node/codex-backend-module.ts +2 -2
- package/src/node/codex-service-impl.ts +1 -1
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
// *****************************************************************************
|
|
3
2
|
// Copyright (C) 2025 EclipseSource GmbH.
|
|
4
3
|
//
|
|
@@ -14,33 +13,32 @@
|
|
|
14
13
|
//
|
|
15
14
|
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
16
15
|
// *****************************************************************************
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
const mock_logger_1 = require("@theia/core/lib/common/test/mock-logger");
|
|
16
|
+
import { FrontendApplicationConfigProvider } from '@theia/core/lib/browser/frontend-application-config-provider';
|
|
17
|
+
import { enableJSDOM } from '@theia/core/lib/browser/test/jsdom';
|
|
18
|
+
let disableJSDOM = enableJSDOM();
|
|
19
|
+
FrontendApplicationConfigProvider.set({});
|
|
20
|
+
import { expect } from 'chai';
|
|
21
|
+
import * as sinon from 'sinon';
|
|
22
|
+
import { Container } from '@theia/core/shared/inversify';
|
|
23
|
+
import { TokenUsageService } from '@theia/ai-core';
|
|
24
|
+
import { FileService } from '@theia/filesystem/lib/browser/file-service';
|
|
25
|
+
import { WorkspaceService } from '@theia/workspace/lib/browser';
|
|
26
|
+
import { URI } from '@theia/core/lib/common/uri';
|
|
27
|
+
import { ChangeSetFileElementFactory } from '@theia/ai-chat/lib/browser/change-set-file-element';
|
|
28
|
+
import { ChatAgentLocation, MarkdownChatResponseContentImpl, ThinkingChatResponseContentImpl, ErrorChatResponseContentImpl } from '@theia/ai-chat';
|
|
29
|
+
import { CodexFrontendService } from './codex-frontend-service.js';
|
|
30
|
+
import { CodexChatAgent, CODEX_CHAT_AGENT_ID, CODEX_TOOL_CALLS_KEY, CODEX_INPUT_TOKENS_KEY, CODEX_OUTPUT_TOKENS_KEY } from './codex-chat-agent.js';
|
|
31
|
+
import { ILogger } from '@theia/core/lib/common/logger';
|
|
32
|
+
import { MockLogger } from '@theia/core/lib/common/test/mock-logger';
|
|
35
33
|
disableJSDOM();
|
|
36
34
|
describe('CodexChatAgent', () => {
|
|
37
35
|
let container;
|
|
38
36
|
let mockRequest;
|
|
39
37
|
before(async () => {
|
|
40
|
-
disableJSDOM =
|
|
38
|
+
disableJSDOM = enableJSDOM();
|
|
41
39
|
});
|
|
42
40
|
beforeEach(() => {
|
|
43
|
-
container = new
|
|
41
|
+
container = new Container();
|
|
44
42
|
const mockCodexService = {
|
|
45
43
|
send: sinon.stub()
|
|
46
44
|
};
|
|
@@ -54,16 +52,16 @@ describe('CodexChatAgent', () => {
|
|
|
54
52
|
read: sinon.stub().resolves({ value: { toString: () => 'content' } })
|
|
55
53
|
};
|
|
56
54
|
const mockWorkspaceService = {
|
|
57
|
-
roots: Promise.resolve([{ resource: new
|
|
55
|
+
roots: Promise.resolve([{ resource: new URI('file:///test') }])
|
|
58
56
|
};
|
|
59
57
|
const mockFileChangeFactory = sinon.stub();
|
|
60
|
-
container.bind(
|
|
61
|
-
container.bind(
|
|
62
|
-
container.bind(
|
|
63
|
-
container.bind(
|
|
64
|
-
container.bind(
|
|
65
|
-
container.bind(
|
|
66
|
-
container.bind(
|
|
58
|
+
container.bind(CodexFrontendService).toConstantValue(mockCodexService);
|
|
59
|
+
container.bind(TokenUsageService).toConstantValue(mockTokenUsageService);
|
|
60
|
+
container.bind(FileService).toConstantValue(mockFileService);
|
|
61
|
+
container.bind(WorkspaceService).toConstantValue(mockWorkspaceService);
|
|
62
|
+
container.bind(ChangeSetFileElementFactory).toConstantValue(mockFileChangeFactory);
|
|
63
|
+
container.bind(CodexChatAgent).toSelf();
|
|
64
|
+
container.bind(ILogger).to(MockLogger).inSingletonScope();
|
|
67
65
|
const addContentStub = sinon.stub();
|
|
68
66
|
const responseContentChangedStub = sinon.stub();
|
|
69
67
|
const completeStub = sinon.stub();
|
|
@@ -151,34 +149,34 @@ describe('CodexChatAgent', () => {
|
|
|
151
149
|
}
|
|
152
150
|
describe('agent metadata', () => {
|
|
153
151
|
it('should have correct id', () => {
|
|
154
|
-
const agent = container.get(
|
|
155
|
-
|
|
152
|
+
const agent = container.get(CodexChatAgent);
|
|
153
|
+
expect(agent.id).to.equal(CODEX_CHAT_AGENT_ID);
|
|
156
154
|
});
|
|
157
155
|
it('should have correct name', () => {
|
|
158
|
-
const agent = container.get(
|
|
159
|
-
|
|
156
|
+
const agent = container.get(CodexChatAgent);
|
|
157
|
+
expect(agent.name).to.equal('Codex');
|
|
160
158
|
});
|
|
161
159
|
it('should have correct description', () => {
|
|
162
|
-
const agent = container.get(
|
|
163
|
-
|
|
164
|
-
|
|
160
|
+
const agent = container.get(CodexChatAgent);
|
|
161
|
+
expect(agent.description).to.include('OpenAI');
|
|
162
|
+
expect(agent.description).to.include('Codex');
|
|
165
163
|
});
|
|
166
164
|
it('should support all chat locations', () => {
|
|
167
|
-
const agent = container.get(
|
|
168
|
-
|
|
165
|
+
const agent = container.get(CodexChatAgent);
|
|
166
|
+
expect(agent.locations).to.deep.equal(ChatAgentLocation.ALL);
|
|
169
167
|
});
|
|
170
168
|
it('should have three modes', () => {
|
|
171
|
-
const agent = container.get(
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
169
|
+
const agent = container.get(CodexChatAgent);
|
|
170
|
+
expect(agent.modes).to.have.lengthOf(3);
|
|
171
|
+
expect(agent.modes[0].id).to.equal('workspace-write');
|
|
172
|
+
expect(agent.modes[1].id).to.equal('read-only');
|
|
173
|
+
expect(agent.modes[2].id).to.equal('danger-full-access');
|
|
176
174
|
});
|
|
177
175
|
});
|
|
178
176
|
describe('invoke() integration tests', () => {
|
|
179
177
|
it('should process agent_message events through invoke', async () => {
|
|
180
|
-
const agent = container.get(
|
|
181
|
-
const mockCodexService = container.get(
|
|
178
|
+
const agent = container.get(CodexChatAgent);
|
|
179
|
+
const mockCodexService = container.get(CodexFrontendService);
|
|
182
180
|
const events = [
|
|
183
181
|
createAgentMessageEvent('Hello, I can help you with that.'),
|
|
184
182
|
createTurnCompletedEvent(50, 25)
|
|
@@ -187,15 +185,15 @@ describe('CodexChatAgent', () => {
|
|
|
187
185
|
await agent.invoke(mockRequest);
|
|
188
186
|
const addContentStub = mockRequest.response.response.addContent;
|
|
189
187
|
const completeStub = mockRequest.response.complete;
|
|
190
|
-
|
|
188
|
+
expect(addContentStub.calledOnce).to.be.true;
|
|
191
189
|
const addedContent = addContentStub.firstCall.args[0];
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
190
|
+
expect(addedContent).to.be.instanceOf(MarkdownChatResponseContentImpl);
|
|
191
|
+
expect(addedContent.content.value).to.equal('Hello, I can help you with that.');
|
|
192
|
+
expect(completeStub.calledOnce).to.be.true;
|
|
195
193
|
});
|
|
196
194
|
it('should process reasoning events through invoke', async () => {
|
|
197
|
-
const agent = container.get(
|
|
198
|
-
const mockCodexService = container.get(
|
|
195
|
+
const agent = container.get(CodexChatAgent);
|
|
196
|
+
const mockCodexService = container.get(CodexFrontendService);
|
|
199
197
|
const events = [
|
|
200
198
|
createReasoningEvent('Let me think about the best approach...'),
|
|
201
199
|
createTurnCompletedEvent(30, 15)
|
|
@@ -204,16 +202,16 @@ describe('CodexChatAgent', () => {
|
|
|
204
202
|
await agent.invoke(mockRequest);
|
|
205
203
|
const addContentStub = mockRequest.response.response.addContent;
|
|
206
204
|
const completeStub = mockRequest.response.complete;
|
|
207
|
-
|
|
205
|
+
expect(addContentStub.calledOnce).to.be.true;
|
|
208
206
|
const addedContent = addContentStub.firstCall.args[0];
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
207
|
+
expect(addedContent).to.be.instanceOf(ThinkingChatResponseContentImpl);
|
|
208
|
+
expect(addedContent.content).to.equal('Let me think about the best approach...');
|
|
209
|
+
expect(completeStub.calledOnce).to.be.true;
|
|
212
210
|
});
|
|
213
211
|
it('should process command_execution tool calls through invoke', async () => {
|
|
214
|
-
const agent = container.get(
|
|
215
|
-
const mockCodexService = container.get(
|
|
216
|
-
mockRequest.getDataByKey.withArgs(
|
|
212
|
+
const agent = container.get(CodexChatAgent);
|
|
213
|
+
const mockCodexService = container.get(CodexFrontendService);
|
|
214
|
+
mockRequest.getDataByKey.withArgs(CODEX_TOOL_CALLS_KEY).returns(undefined);
|
|
217
215
|
const events = [
|
|
218
216
|
{
|
|
219
217
|
type: 'item.started',
|
|
@@ -233,50 +231,50 @@ describe('CodexChatAgent', () => {
|
|
|
233
231
|
// Should add tool call twice: once on start (pending), once on completion
|
|
234
232
|
const addContentStub = mockRequest.response.response.addContent;
|
|
235
233
|
const completeStub = mockRequest.response.complete;
|
|
236
|
-
|
|
237
|
-
|
|
234
|
+
expect(addContentStub.callCount).to.equal(2);
|
|
235
|
+
expect(completeStub.calledOnce).to.be.true;
|
|
238
236
|
});
|
|
239
237
|
it('should process turn.completed events through invoke', async () => {
|
|
240
|
-
const agent = container.get(
|
|
241
|
-
const mockCodexService = container.get(
|
|
238
|
+
const agent = container.get(CodexChatAgent);
|
|
239
|
+
const mockCodexService = container.get(CodexFrontendService);
|
|
242
240
|
const events = [
|
|
243
241
|
createAgentMessageEvent('Done!'),
|
|
244
242
|
createTurnCompletedEvent(150, 75)
|
|
245
243
|
];
|
|
246
244
|
mockCodexService.send.resolves(createMockStream(events));
|
|
247
245
|
mockRequest.session.getRequests.returns([mockRequest]);
|
|
248
|
-
mockRequest.getDataByKey.withArgs(
|
|
249
|
-
mockRequest.getDataByKey.withArgs(
|
|
246
|
+
mockRequest.getDataByKey.withArgs(CODEX_INPUT_TOKENS_KEY).returns(0);
|
|
247
|
+
mockRequest.getDataByKey.withArgs(CODEX_OUTPUT_TOKENS_KEY).returns(0);
|
|
250
248
|
await agent.invoke(mockRequest);
|
|
251
249
|
const addDataStub = mockRequest.addData;
|
|
252
250
|
const completeStub = mockRequest.response.complete;
|
|
253
251
|
const setTokenUsageStub = mockRequest.response.setTokenUsage;
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
252
|
+
expect(addDataStub.calledWith(CODEX_INPUT_TOKENS_KEY, 150)).to.be.true;
|
|
253
|
+
expect(addDataStub.calledWith(CODEX_OUTPUT_TOKENS_KEY, 75)).to.be.true;
|
|
254
|
+
expect(setTokenUsageStub.calledOnce).to.be.true;
|
|
255
|
+
expect(setTokenUsageStub.firstCall.args[0]).to.deep.equal({
|
|
258
256
|
inputTokens: 150,
|
|
259
257
|
outputTokens: 75,
|
|
260
258
|
cacheCreationInputTokens: 0
|
|
261
259
|
});
|
|
262
|
-
|
|
260
|
+
expect(completeStub.calledOnce).to.be.true;
|
|
263
261
|
});
|
|
264
262
|
it('should handle errors from codexService.send', async () => {
|
|
265
|
-
const agent = container.get(
|
|
266
|
-
const mockCodexService = container.get(
|
|
263
|
+
const agent = container.get(CodexChatAgent);
|
|
264
|
+
const mockCodexService = container.get(CodexFrontendService);
|
|
267
265
|
const testError = new Error('Network failure');
|
|
268
266
|
mockCodexService.send.rejects(testError);
|
|
269
267
|
await agent.invoke(mockRequest);
|
|
270
268
|
const addContentStub = mockRequest.response.response.addContent;
|
|
271
269
|
const errorStub = mockRequest.response.error;
|
|
272
|
-
|
|
270
|
+
expect(addContentStub.calledOnce).to.be.true;
|
|
273
271
|
const addedContent = addContentStub.firstCall.args[0];
|
|
274
|
-
|
|
275
|
-
|
|
272
|
+
expect(addedContent).to.be.instanceOf(ErrorChatResponseContentImpl);
|
|
273
|
+
expect(errorStub.calledWith(testError)).to.be.true;
|
|
276
274
|
});
|
|
277
275
|
it('should call response.complete() on successful completion', async () => {
|
|
278
|
-
const agent = container.get(
|
|
279
|
-
const mockCodexService = container.get(
|
|
276
|
+
const agent = container.get(CodexChatAgent);
|
|
277
|
+
const mockCodexService = container.get(CodexFrontendService);
|
|
280
278
|
const events = [
|
|
281
279
|
createAgentMessageEvent('Success'),
|
|
282
280
|
createTurnCompletedEvent(10, 5)
|
|
@@ -285,21 +283,21 @@ describe('CodexChatAgent', () => {
|
|
|
285
283
|
await agent.invoke(mockRequest);
|
|
286
284
|
const completeStub = mockRequest.response.complete;
|
|
287
285
|
const errorStub = mockRequest.response.error;
|
|
288
|
-
|
|
289
|
-
|
|
286
|
+
expect(completeStub.calledOnce).to.be.true;
|
|
287
|
+
expect(errorStub.called).to.be.false;
|
|
290
288
|
});
|
|
291
289
|
it('should call response.error() on failure', async () => {
|
|
292
|
-
const agent = container.get(
|
|
293
|
-
const mockCodexService = container.get(
|
|
290
|
+
const agent = container.get(CodexChatAgent);
|
|
291
|
+
const mockCodexService = container.get(CodexFrontendService);
|
|
294
292
|
const error = new Error('Test error');
|
|
295
293
|
mockCodexService.send.rejects(error);
|
|
296
294
|
await agent.invoke(mockRequest);
|
|
297
295
|
const errorStub = mockRequest.response.error;
|
|
298
|
-
|
|
296
|
+
expect(errorStub.calledWith(error)).to.be.true;
|
|
299
297
|
});
|
|
300
298
|
it('should extract prompt and session ID correctly', async () => {
|
|
301
|
-
const agent = container.get(
|
|
302
|
-
const mockCodexService = container.get(
|
|
299
|
+
const agent = container.get(CodexChatAgent);
|
|
300
|
+
const mockCodexService = container.get(CodexFrontendService);
|
|
303
301
|
const customRequest = {
|
|
304
302
|
...mockRequest,
|
|
305
303
|
request: { text: '@Codex write a test' },
|
|
@@ -312,14 +310,14 @@ describe('CodexChatAgent', () => {
|
|
|
312
310
|
const events = [createTurnCompletedEvent(10, 5)];
|
|
313
311
|
mockCodexService.send.resolves(createMockStream(events));
|
|
314
312
|
await agent.invoke(customRequest);
|
|
315
|
-
|
|
313
|
+
expect(mockCodexService.send.calledOnce).to.be.true;
|
|
316
314
|
const callArgs = mockCodexService.send.firstCall.args[0];
|
|
317
|
-
|
|
318
|
-
|
|
315
|
+
expect(callArgs.prompt).to.equal('write a test');
|
|
316
|
+
expect(callArgs.sessionId).to.equal('session-123');
|
|
319
317
|
});
|
|
320
318
|
it('should pass sandboxMode from modeId to codexService.send', async () => {
|
|
321
|
-
const agent = container.get(
|
|
322
|
-
const mockCodexService = container.get(
|
|
319
|
+
const agent = container.get(CodexChatAgent);
|
|
320
|
+
const mockCodexService = container.get(CodexFrontendService);
|
|
323
321
|
const customRequest = {
|
|
324
322
|
...mockRequest,
|
|
325
323
|
request: { text: 'test prompt', modeId: 'read-only' },
|
|
@@ -328,13 +326,13 @@ describe('CodexChatAgent', () => {
|
|
|
328
326
|
const events = [createTurnCompletedEvent(10, 5)];
|
|
329
327
|
mockCodexService.send.resolves(createMockStream(events));
|
|
330
328
|
await agent.invoke(customRequest);
|
|
331
|
-
|
|
329
|
+
expect(mockCodexService.send.calledOnce).to.be.true;
|
|
332
330
|
const callArgs = mockCodexService.send.firstCall.args[0];
|
|
333
|
-
|
|
331
|
+
expect(callArgs.sandboxMode).to.equal('read-only');
|
|
334
332
|
});
|
|
335
333
|
it('should default sandboxMode to workspace-write when modeId is undefined', async () => {
|
|
336
|
-
const agent = container.get(
|
|
337
|
-
const mockCodexService = container.get(
|
|
334
|
+
const agent = container.get(CodexChatAgent);
|
|
335
|
+
const mockCodexService = container.get(CodexFrontendService);
|
|
338
336
|
const customRequest = {
|
|
339
337
|
...mockRequest,
|
|
340
338
|
request: { text: 'test prompt' },
|
|
@@ -343,13 +341,13 @@ describe('CodexChatAgent', () => {
|
|
|
343
341
|
const events = [createTurnCompletedEvent(10, 5)];
|
|
344
342
|
mockCodexService.send.resolves(createMockStream(events));
|
|
345
343
|
await agent.invoke(customRequest);
|
|
346
|
-
|
|
344
|
+
expect(mockCodexService.send.calledOnce).to.be.true;
|
|
347
345
|
const callArgs = mockCodexService.send.firstCall.args[0];
|
|
348
|
-
|
|
346
|
+
expect(callArgs.sandboxMode).to.equal('workspace-write');
|
|
349
347
|
});
|
|
350
348
|
it('should default sandboxMode to workspace-write when modeId is invalid', async () => {
|
|
351
|
-
const agent = container.get(
|
|
352
|
-
const mockCodexService = container.get(
|
|
349
|
+
const agent = container.get(CodexChatAgent);
|
|
350
|
+
const mockCodexService = container.get(CodexFrontendService);
|
|
353
351
|
const customRequest = {
|
|
354
352
|
...mockRequest,
|
|
355
353
|
request: { text: 'test prompt', modeId: 'invalid-mode' },
|
|
@@ -358,34 +356,34 @@ describe('CodexChatAgent', () => {
|
|
|
358
356
|
const events = [createTurnCompletedEvent(10, 5)];
|
|
359
357
|
mockCodexService.send.resolves(createMockStream(events));
|
|
360
358
|
await agent.invoke(customRequest);
|
|
361
|
-
|
|
359
|
+
expect(mockCodexService.send.calledOnce).to.be.true;
|
|
362
360
|
const callArgs = mockCodexService.send.firstCall.args[0];
|
|
363
|
-
|
|
361
|
+
expect(callArgs.sandboxMode).to.equal('workspace-write');
|
|
364
362
|
});
|
|
365
363
|
});
|
|
366
364
|
describe('protected methods', () => {
|
|
367
365
|
it('getToolCalls should create new map if not exists', () => {
|
|
368
|
-
const agent = container.get(
|
|
369
|
-
mockRequest.getDataByKey.withArgs(
|
|
366
|
+
const agent = container.get(CodexChatAgent);
|
|
367
|
+
mockRequest.getDataByKey.withArgs(CODEX_TOOL_CALLS_KEY).returns(undefined);
|
|
370
368
|
const testAccess = agent;
|
|
371
369
|
const result = testAccess.getToolCalls(mockRequest);
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
370
|
+
expect(result).to.be.instanceOf(Map);
|
|
371
|
+
expect(result.size).to.equal(0);
|
|
372
|
+
expect(mockRequest.addData.calledWith(CODEX_TOOL_CALLS_KEY, result)).to.be.true;
|
|
375
373
|
});
|
|
376
374
|
it('getToolCalls should return existing map', () => {
|
|
377
|
-
const agent = container.get(
|
|
375
|
+
const agent = container.get(CodexChatAgent);
|
|
378
376
|
const existingMap = new Map();
|
|
379
377
|
existingMap.set('test-id', {});
|
|
380
|
-
mockRequest.getDataByKey.withArgs(
|
|
378
|
+
mockRequest.getDataByKey.withArgs(CODEX_TOOL_CALLS_KEY).returns(existingMap);
|
|
381
379
|
const testAccess = agent;
|
|
382
380
|
const result = testAccess.getToolCalls(mockRequest);
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
381
|
+
expect(result).to.equal(existingMap);
|
|
382
|
+
expect(result.size).to.equal(1);
|
|
383
|
+
expect(mockRequest.addData.called).to.be.false;
|
|
386
384
|
});
|
|
387
385
|
it('isToolInvocation should return true for command_execution item', () => {
|
|
388
|
-
const agent = container.get(
|
|
386
|
+
const agent = container.get(CodexChatAgent);
|
|
389
387
|
const item = {
|
|
390
388
|
type: 'command_execution',
|
|
391
389
|
id: 'cmd-1',
|
|
@@ -394,10 +392,10 @@ describe('CodexChatAgent', () => {
|
|
|
394
392
|
aggregated_output: ''
|
|
395
393
|
};
|
|
396
394
|
const testAccess = agent;
|
|
397
|
-
|
|
395
|
+
expect(testAccess.isToolInvocation(item)).to.be.true;
|
|
398
396
|
});
|
|
399
397
|
it('isToolInvocation should return true for file_change item', () => {
|
|
400
|
-
const agent = container.get(
|
|
398
|
+
const agent = container.get(CodexChatAgent);
|
|
401
399
|
const item = {
|
|
402
400
|
type: 'file_change',
|
|
403
401
|
id: 'file-1',
|
|
@@ -405,10 +403,10 @@ describe('CodexChatAgent', () => {
|
|
|
405
403
|
status: 'running'
|
|
406
404
|
};
|
|
407
405
|
const testAccess = agent;
|
|
408
|
-
|
|
406
|
+
expect(testAccess.isToolInvocation(item)).to.be.true;
|
|
409
407
|
});
|
|
410
408
|
it('isToolInvocation should return true for mcp_tool_call item', () => {
|
|
411
|
-
const agent = container.get(
|
|
409
|
+
const agent = container.get(CodexChatAgent);
|
|
412
410
|
const item = {
|
|
413
411
|
type: 'mcp_tool_call',
|
|
414
412
|
id: 'mcp-1',
|
|
@@ -417,40 +415,40 @@ describe('CodexChatAgent', () => {
|
|
|
417
415
|
status: 'running'
|
|
418
416
|
};
|
|
419
417
|
const testAccess = agent;
|
|
420
|
-
|
|
418
|
+
expect(testAccess.isToolInvocation(item)).to.be.true;
|
|
421
419
|
});
|
|
422
420
|
it('isToolInvocation should return true for web_search item', () => {
|
|
423
|
-
const agent = container.get(
|
|
421
|
+
const agent = container.get(CodexChatAgent);
|
|
424
422
|
const item = {
|
|
425
423
|
type: 'web_search',
|
|
426
424
|
id: 'search-1',
|
|
427
425
|
query: 'test query'
|
|
428
426
|
};
|
|
429
427
|
const testAccess = agent;
|
|
430
|
-
|
|
428
|
+
expect(testAccess.isToolInvocation(item)).to.be.true;
|
|
431
429
|
});
|
|
432
430
|
it('isToolInvocation should return true for todo_list item', () => {
|
|
433
|
-
const agent = container.get(
|
|
431
|
+
const agent = container.get(CodexChatAgent);
|
|
434
432
|
const item = {
|
|
435
433
|
type: 'todo_list',
|
|
436
434
|
id: 'todo-1',
|
|
437
435
|
items: []
|
|
438
436
|
};
|
|
439
437
|
const testAccess = agent;
|
|
440
|
-
|
|
438
|
+
expect(testAccess.isToolInvocation(item)).to.be.true;
|
|
441
439
|
});
|
|
442
440
|
it('isToolInvocation should return false for agent_message item', () => {
|
|
443
|
-
const agent = container.get(
|
|
441
|
+
const agent = container.get(CodexChatAgent);
|
|
444
442
|
const item = {
|
|
445
443
|
type: 'agent_message',
|
|
446
444
|
id: 'msg-1',
|
|
447
445
|
text: 'Hello'
|
|
448
446
|
};
|
|
449
447
|
const testAccess = agent;
|
|
450
|
-
|
|
448
|
+
expect(testAccess.isToolInvocation(item)).to.be.false;
|
|
451
449
|
});
|
|
452
450
|
it('extractToolArguments should extract command_execution arguments', () => {
|
|
453
|
-
const agent = container.get(
|
|
451
|
+
const agent = container.get(CodexChatAgent);
|
|
454
452
|
const item = {
|
|
455
453
|
type: 'command_execution',
|
|
456
454
|
id: 'cmd-1',
|
|
@@ -462,12 +460,12 @@ describe('CodexChatAgent', () => {
|
|
|
462
460
|
const testAccess = agent;
|
|
463
461
|
const result = testAccess.extractToolArguments(item);
|
|
464
462
|
const parsed = JSON.parse(result);
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
463
|
+
expect(parsed.command).to.equal('npm test');
|
|
464
|
+
expect(parsed.status).to.equal('completed');
|
|
465
|
+
expect(parsed.exit_code).to.equal(0);
|
|
468
466
|
});
|
|
469
467
|
it('extractToolArguments should extract file_change arguments', () => {
|
|
470
|
-
const agent = container.get(
|
|
468
|
+
const agent = container.get(CodexChatAgent);
|
|
471
469
|
const item = {
|
|
472
470
|
type: 'file_change',
|
|
473
471
|
id: 'file-1',
|
|
@@ -477,73 +475,73 @@ describe('CodexChatAgent', () => {
|
|
|
477
475
|
const testAccess = agent;
|
|
478
476
|
const result = testAccess.extractToolArguments(item);
|
|
479
477
|
const parsed = JSON.parse(result);
|
|
480
|
-
|
|
481
|
-
|
|
478
|
+
expect(parsed.changes).to.deep.equal([{ path: '/test/file.ts', kind: 'add' }]);
|
|
479
|
+
expect(parsed.status).to.equal('completed');
|
|
482
480
|
});
|
|
483
481
|
it('updateTokens should store token data and update session suggestion', () => {
|
|
484
|
-
const agent = container.get(
|
|
482
|
+
const agent = container.get(CodexChatAgent);
|
|
485
483
|
mockRequest.session.getRequests.returns([mockRequest]);
|
|
486
|
-
mockRequest.getDataByKey.withArgs(
|
|
487
|
-
mockRequest.getDataByKey.withArgs(
|
|
484
|
+
mockRequest.getDataByKey.withArgs(CODEX_INPUT_TOKENS_KEY).returns(100);
|
|
485
|
+
mockRequest.getDataByKey.withArgs(CODEX_OUTPUT_TOKENS_KEY).returns(50);
|
|
488
486
|
const testAccess = agent;
|
|
489
487
|
testAccess.updateTokens(mockRequest, 100, 50);
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
488
|
+
expect(mockRequest.addData.calledWith(CODEX_INPUT_TOKENS_KEY, 100)).to.be.true;
|
|
489
|
+
expect(mockRequest.addData.calledWith(CODEX_OUTPUT_TOKENS_KEY, 50)).to.be.true;
|
|
490
|
+
expect(mockRequest.session.setSuggestions.called).to.be.true;
|
|
493
491
|
});
|
|
494
492
|
it('getSessionTotalTokens should sum tokens across multiple requests', () => {
|
|
495
|
-
const agent = container.get(
|
|
493
|
+
const agent = container.get(CodexChatAgent);
|
|
496
494
|
const request1 = {
|
|
497
495
|
getDataByKey: sinon.stub()
|
|
498
496
|
};
|
|
499
|
-
request1.getDataByKey.withArgs(
|
|
500
|
-
request1.getDataByKey.withArgs(
|
|
497
|
+
request1.getDataByKey.withArgs(CODEX_INPUT_TOKENS_KEY).returns(100);
|
|
498
|
+
request1.getDataByKey.withArgs(CODEX_OUTPUT_TOKENS_KEY).returns(50);
|
|
501
499
|
const request2 = {
|
|
502
500
|
getDataByKey: sinon.stub()
|
|
503
501
|
};
|
|
504
|
-
request2.getDataByKey.withArgs(
|
|
505
|
-
request2.getDataByKey.withArgs(
|
|
502
|
+
request2.getDataByKey.withArgs(CODEX_INPUT_TOKENS_KEY).returns(200);
|
|
503
|
+
request2.getDataByKey.withArgs(CODEX_OUTPUT_TOKENS_KEY).returns(75);
|
|
506
504
|
mockRequest.session.getRequests.returns([request1, request2]);
|
|
507
505
|
const testAccess = agent;
|
|
508
506
|
const result = testAccess.getSessionTotalTokens(mockRequest);
|
|
509
|
-
|
|
510
|
-
|
|
507
|
+
expect(result.inputTokens).to.equal(300);
|
|
508
|
+
expect(result.outputTokens).to.equal(125);
|
|
511
509
|
});
|
|
512
510
|
it('getSessionTotalTokens should handle requests with no token data', () => {
|
|
513
|
-
const agent = container.get(
|
|
511
|
+
const agent = container.get(CodexChatAgent);
|
|
514
512
|
const request1 = {
|
|
515
513
|
getDataByKey: sinon.stub().returns(undefined)
|
|
516
514
|
};
|
|
517
515
|
mockRequest.session.getRequests.returns([request1]);
|
|
518
516
|
const testAccess = agent;
|
|
519
517
|
const result = testAccess.getSessionTotalTokens(mockRequest);
|
|
520
|
-
|
|
521
|
-
|
|
518
|
+
expect(result.inputTokens).to.equal(0);
|
|
519
|
+
expect(result.outputTokens).to.equal(0);
|
|
522
520
|
});
|
|
523
521
|
it('extractSandboxMode should return read-only for read-only modeId', () => {
|
|
524
|
-
const agent = container.get(
|
|
522
|
+
const agent = container.get(CodexChatAgent);
|
|
525
523
|
const testAccess = agent;
|
|
526
|
-
|
|
524
|
+
expect(testAccess.extractSandboxMode('read-only')).to.equal('read-only');
|
|
527
525
|
});
|
|
528
526
|
it('extractSandboxMode should return workspace-write for workspace-write modeId', () => {
|
|
529
|
-
const agent = container.get(
|
|
527
|
+
const agent = container.get(CodexChatAgent);
|
|
530
528
|
const testAccess = agent;
|
|
531
|
-
|
|
529
|
+
expect(testAccess.extractSandboxMode('workspace-write')).to.equal('workspace-write');
|
|
532
530
|
});
|
|
533
531
|
it('extractSandboxMode should return danger-full-access for danger-full-access modeId', () => {
|
|
534
|
-
const agent = container.get(
|
|
532
|
+
const agent = container.get(CodexChatAgent);
|
|
535
533
|
const testAccess = agent;
|
|
536
|
-
|
|
534
|
+
expect(testAccess.extractSandboxMode('danger-full-access')).to.equal('danger-full-access');
|
|
537
535
|
});
|
|
538
536
|
it('extractSandboxMode should default to workspace-write for undefined modeId', () => {
|
|
539
|
-
const agent = container.get(
|
|
537
|
+
const agent = container.get(CodexChatAgent);
|
|
540
538
|
const testAccess = agent;
|
|
541
|
-
|
|
539
|
+
expect(testAccess.extractSandboxMode(undefined)).to.equal('workspace-write');
|
|
542
540
|
});
|
|
543
541
|
it('extractSandboxMode should default to workspace-write for invalid modeId', () => {
|
|
544
|
-
const agent = container.get(
|
|
542
|
+
const agent = container.get(CodexChatAgent);
|
|
545
543
|
const testAccess = agent;
|
|
546
|
-
|
|
544
|
+
expect(testAccess.extractSandboxMode('invalid-mode')).to.equal('workspace-write');
|
|
547
545
|
});
|
|
548
546
|
});
|
|
549
547
|
});
|