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