|
1 | | -import { RemoteConversation, RemoteWorkspace } from '../index'; |
| 1 | +import { Conversation, Agent, Workspace, RemoteConversation, RemoteWorkspace } from '../index'; |
2 | 2 |
|
3 | 3 | describe('OpenHands Agent Server TypeScript Client', () => { |
4 | 4 | describe('Exports', () => { |
5 | | - it('should export RemoteConversation', () => { |
| 5 | + it('should export Conversation', () => { |
| 6 | + expect(Conversation).toBeDefined(); |
| 7 | + expect(typeof Conversation).toBe('function'); |
| 8 | + }); |
| 9 | + |
| 10 | + it('should export Agent', () => { |
| 11 | + expect(Agent).toBeDefined(); |
| 12 | + expect(typeof Agent).toBe('function'); |
| 13 | + }); |
| 14 | + |
| 15 | + it('should export Workspace', () => { |
| 16 | + expect(Workspace).toBeDefined(); |
| 17 | + expect(typeof Workspace).toBe('function'); |
| 18 | + }); |
| 19 | + |
| 20 | + it('should export RemoteConversation for backwards compatibility', () => { |
6 | 21 | expect(RemoteConversation).toBeDefined(); |
7 | 22 | expect(typeof RemoteConversation).toBe('function'); |
8 | 23 | }); |
9 | 24 |
|
10 | | - it('should export RemoteWorkspace', () => { |
| 25 | + it('should export RemoteWorkspace for backwards compatibility', () => { |
11 | 26 | expect(RemoteWorkspace).toBeDefined(); |
12 | 27 | expect(typeof RemoteWorkspace).toBe('function'); |
13 | 28 | }); |
14 | 29 | }); |
15 | 30 |
|
16 | | - describe('RemoteConversation', () => { |
17 | | - it('should create instance with config', () => { |
18 | | - const config = { |
| 31 | + describe('New API - Conversation', () => { |
| 32 | + it('should create instance with agent and workspace', () => { |
| 33 | + const agent = new Agent({ |
| 34 | + llm: { |
| 35 | + model: 'gpt-4', |
| 36 | + api_key: 'test-key', |
| 37 | + }, |
| 38 | + }); |
| 39 | + |
| 40 | + const workspace = new Workspace({ |
19 | 41 | host: 'http://localhost:8000', |
| 42 | + workingDir: '/tmp', |
20 | 43 | apiKey: 'test-key', |
21 | | - }; |
| 44 | + }); |
22 | 45 |
|
23 | | - const conversation = new RemoteConversation(config); |
| 46 | + const conversation = new Conversation(agent, workspace); |
24 | 47 | expect(conversation).toBeInstanceOf(RemoteConversation); |
| 48 | + expect(conversation.workspace).toBe(workspace); |
25 | 49 | }); |
| 50 | + }); |
26 | 51 |
|
27 | | - it('should throw error when accessing workspace before initialization', () => { |
28 | | - const config = { |
29 | | - host: 'http://localhost:8000', |
30 | | - apiKey: 'test-key', |
31 | | - }; |
| 52 | + describe('Agent', () => { |
| 53 | + it('should create instance with LLM config', () => { |
| 54 | + const agent = new Agent({ |
| 55 | + llm: { |
| 56 | + model: 'gpt-4', |
| 57 | + api_key: 'test-key', |
| 58 | + }, |
| 59 | + }); |
| 60 | + |
| 61 | + expect(agent).toBeInstanceOf(Agent); |
| 62 | + expect(agent.kind).toBe('Agent'); |
| 63 | + expect(agent.llm.model).toBe('gpt-4'); |
| 64 | + expect(agent.llm.api_key).toBe('test-key'); |
| 65 | + }); |
| 66 | + |
| 67 | + it('should allow custom kind', () => { |
| 68 | + const agent = new Agent({ |
| 69 | + kind: 'CustomAgent', |
| 70 | + llm: { |
| 71 | + model: 'gpt-4', |
| 72 | + api_key: 'test-key', |
| 73 | + }, |
| 74 | + }); |
32 | 75 |
|
33 | | - const conversation = new RemoteConversation(config); |
34 | | - expect(() => conversation.workspace).toThrow( |
35 | | - 'Workspace not initialized. Create or load a conversation first.' |
36 | | - ); |
| 76 | + expect(agent.kind).toBe('CustomAgent'); |
37 | 77 | }); |
38 | 78 | }); |
39 | 79 |
|
40 | | - describe('RemoteWorkspace', () => { |
| 80 | + describe('Workspace', () => { |
41 | 81 | it('should create instance with options', () => { |
42 | | - const options = { |
| 82 | + const workspace = new Workspace({ |
43 | 83 | host: 'http://localhost:8000', |
44 | 84 | workingDir: '/tmp', |
45 | 85 | apiKey: 'test-key', |
46 | | - }; |
| 86 | + }); |
47 | 87 |
|
48 | | - const workspace = new RemoteWorkspace(options); |
49 | 88 | expect(workspace).toBeInstanceOf(RemoteWorkspace); |
50 | 89 | expect(workspace.host).toBe('http://localhost:8000'); |
51 | 90 | expect(workspace.workingDir).toBe('/tmp'); |
|
0 commit comments