@ragwalla/agents-sdk 1.0.3 → 1.0.4
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/README.md
CHANGED
|
@@ -24,19 +24,31 @@ const agent = await ragwalla.agents.create({
|
|
|
24
24
|
instructions: 'You are a helpful AI assistant.'
|
|
25
25
|
});
|
|
26
26
|
|
|
27
|
-
//
|
|
28
|
-
const
|
|
29
|
-
|
|
27
|
+
// Get WebSocket token for real-time chat
|
|
28
|
+
const tokenResponse = await ragwalla.agents.getToken({
|
|
29
|
+
agent_id: agent.id,
|
|
30
|
+
expires_in: 3600
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
// Create WebSocket connection
|
|
34
|
+
const ws = ragwalla.createWebSocket();
|
|
35
|
+
|
|
36
|
+
ws.on('connected', () => {
|
|
37
|
+
ws.sendMessage({ role: 'user', content: 'Hello!' });
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
ws.on('message', (message) => {
|
|
41
|
+
console.log('Agent:', message.content);
|
|
30
42
|
});
|
|
31
43
|
|
|
32
|
-
|
|
44
|
+
await ws.connect(agent.id, 'main', tokenResponse.token);
|
|
33
45
|
```
|
|
34
46
|
|
|
35
47
|
## Features
|
|
36
48
|
|
|
37
49
|
- ✅ **Agent Management** - Create, update, and manage AI agents
|
|
38
|
-
- ✅ **Chat
|
|
39
|
-
- ✅ **
|
|
50
|
+
- ✅ **Real-time WebSocket Chat** - Live streaming chat with automatic reconnection
|
|
51
|
+
- ✅ **WebSocket-Only Communication** - All agent chat happens via WebSocket (no HTTP chat endpoints)
|
|
40
52
|
- ✅ **Vector Search** - Semantic search across knowledge bases
|
|
41
53
|
- ✅ **Tool Management** - Attach functions and assistants to agents
|
|
42
54
|
- ✅ **Quota Management** - Track usage and limits
|
|
@@ -100,42 +112,39 @@ const updatedAgent = await ragwalla.agents.update(agent.id, {
|
|
|
100
112
|
await ragwalla.agents.delete(agent.id);
|
|
101
113
|
```
|
|
102
114
|
|
|
103
|
-
## Chat
|
|
115
|
+
## Important: WebSocket-Only Chat
|
|
104
116
|
|
|
105
|
-
|
|
117
|
+
**All agent chat communication happens via WebSocket, not HTTP.** The ragwalla-hono-worker server does not support HTTP chat completion endpoints. You must use WebSocket connections for real-time agent communication.
|
|
106
118
|
|
|
107
|
-
|
|
108
|
-
const response = await ragwalla.agents.createChatCompletion(agent.id, {
|
|
109
|
-
messages: [
|
|
110
|
-
{ role: 'user', content: 'What is the weather like?' }
|
|
111
|
-
],
|
|
112
|
-
max_tokens: 150,
|
|
113
|
-
temperature: 0.7
|
|
114
|
-
});
|
|
119
|
+
### Why WebSocket?
|
|
115
120
|
|
|
116
|
-
|
|
117
|
-
|
|
121
|
+
- ✅ Real-time streaming responses
|
|
122
|
+
- ✅ Bidirectional communication
|
|
123
|
+
- ✅ Lower latency
|
|
124
|
+
- ✅ Automatic reconnection
|
|
125
|
+
- ✅ Connection state management
|
|
126
|
+
|
|
127
|
+
### Available HTTP Endpoints (CRUD Only)
|
|
118
128
|
|
|
119
|
-
|
|
129
|
+
HTTP endpoints are only for managing agents, not chatting:
|
|
120
130
|
|
|
121
131
|
```typescript
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
{ role: 'user', content: 'Write a story about AI' }
|
|
125
|
-
],
|
|
126
|
-
stream: true,
|
|
127
|
-
max_tokens: 500
|
|
128
|
-
});
|
|
132
|
+
// ✅ Create agent (HTTP)
|
|
133
|
+
await ragwalla.agents.create({ name: 'Agent' });
|
|
129
134
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
135
|
+
// ✅ List agents (HTTP)
|
|
136
|
+
await ragwalla.agents.list();
|
|
137
|
+
|
|
138
|
+
// ✅ Update agent (HTTP)
|
|
139
|
+
await ragwalla.agents.update(agentId, { instructions: '...' });
|
|
140
|
+
|
|
141
|
+
// ✅ Delete agent (HTTP)
|
|
142
|
+
await ragwalla.agents.delete(agentId);
|
|
143
|
+
|
|
144
|
+
// ✅ Get WebSocket token (HTTP)
|
|
145
|
+
await ragwalla.agents.getToken({ agent_id: agentId });
|
|
146
|
+
|
|
147
|
+
// ❌ NO HTTP chat endpoints - use WebSocket instead!
|
|
139
148
|
```
|
|
140
149
|
|
|
141
150
|
## Real-time WebSocket Chat
|
|
@@ -323,11 +332,17 @@ export default {
|
|
|
323
332
|
instructions: 'You are an AI assistant running in Cloudflare Workers.'
|
|
324
333
|
});
|
|
325
334
|
|
|
326
|
-
|
|
327
|
-
|
|
335
|
+
// Get WebSocket token for chat
|
|
336
|
+
const tokenResponse = await ragwalla.agents.getToken({
|
|
337
|
+
agent_id: agent.id,
|
|
338
|
+
expires_in: 3600
|
|
328
339
|
});
|
|
329
340
|
|
|
330
|
-
return new Response(JSON.stringify(
|
|
341
|
+
return new Response(JSON.stringify({
|
|
342
|
+
agent,
|
|
343
|
+
token: tokenResponse.token,
|
|
344
|
+
message: 'Use WebSocket to chat with this agent'
|
|
345
|
+
}), {
|
|
331
346
|
headers: { 'Content-Type': 'application/json' }
|
|
332
347
|
});
|
|
333
348
|
}
|
|
@@ -358,8 +373,8 @@ await ws.connect(agentId, 'main', token);
|
|
|
358
373
|
|
|
359
374
|
Check the `examples/` directory for complete usage examples:
|
|
360
375
|
|
|
361
|
-
- `basic-usage.ts` -
|
|
362
|
-
- `streaming-chat.ts` - Streaming
|
|
376
|
+
- `basic-usage.ts` - Agent CRUD operations and token generation
|
|
377
|
+
- `streaming-chat.ts` - Streaming responses via WebSocket
|
|
363
378
|
- `websocket-chat.ts` - Real-time WebSocket communication
|
|
364
379
|
- `vector-search.ts` - Vector store search examples
|
|
365
380
|
- `cloudflare-workers.ts` - Complete Cloudflare Workers implementation
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { HTTPClient } from '../client/http-client';
|
|
2
|
-
import { Agent, CreateAgentRequest,
|
|
2
|
+
import { Agent, CreateAgentRequest, ConnectionToken, Tool } from '../types';
|
|
3
3
|
export declare class AgentsResource {
|
|
4
4
|
private client;
|
|
5
5
|
constructor(client: HTTPClient);
|
|
@@ -37,19 +37,13 @@ export declare class AgentsResource {
|
|
|
37
37
|
}>;
|
|
38
38
|
/**
|
|
39
39
|
* Get connection token for WebSocket access
|
|
40
|
+
* Note: This endpoint generates a token for WebSocket authentication.
|
|
41
|
+
* Use the token with RagwallaWebSocket.connect() to establish a real-time connection.
|
|
40
42
|
*/
|
|
41
43
|
getToken(params?: {
|
|
42
44
|
agent_id?: string;
|
|
43
45
|
expires_in?: number;
|
|
44
46
|
}): Promise<ConnectionToken>;
|
|
45
|
-
/**
|
|
46
|
-
* Send a message to an agent (non-streaming)
|
|
47
|
-
*/
|
|
48
|
-
createChatCompletion(agentId: string, request: ChatCompletionRequest): Promise<ChatCompletionResponse>;
|
|
49
|
-
/**
|
|
50
|
-
* Send a message to an agent (streaming)
|
|
51
|
-
*/
|
|
52
|
-
createChatCompletionStream(agentId: string, request: ChatCompletionRequest): Promise<ReadableStream<ChatCompletionResponse>>;
|
|
53
47
|
/**
|
|
54
48
|
* List tools attached to an agent
|
|
55
49
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agents.d.ts","sourceRoot":"","sources":["../../src/resources/agents.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,EACL,KAAK,EACL,kBAAkB,EAClB,
|
|
1
|
+
{"version":3,"file":"agents.d.ts","sourceRoot":"","sources":["../../src/resources/agents.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,EACL,KAAK,EACL,kBAAkB,EAClB,eAAe,EACf,IAAI,EACL,MAAM,UAAU,CAAC;AAElB,qBAAa,cAAc;IACb,OAAO,CAAC,MAAM;gBAAN,MAAM,EAAE,UAAU;IAEtC;;OAEG;IACG,MAAM,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AO,CAAC,IAAI,CAAC;IAIrE;;OAEG;IACG,UAAU,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,OAAO,CAAA;KAAE,CAAC;CAG7G"}
|
package/dist/resources/agents.js
CHANGED
|
@@ -35,25 +35,11 @@ export class AgentsResource {
|
|
|
35
35
|
}
|
|
36
36
|
/**
|
|
37
37
|
* Get connection token for WebSocket access
|
|
38
|
+
* Note: This endpoint generates a token for WebSocket authentication.
|
|
39
|
+
* Use the token with RagwallaWebSocket.connect() to establish a real-time connection.
|
|
38
40
|
*/
|
|
39
41
|
async getToken(params) {
|
|
40
|
-
return this.client.post('/v1/agents/
|
|
41
|
-
}
|
|
42
|
-
/**
|
|
43
|
-
* Send a message to an agent (non-streaming)
|
|
44
|
-
*/
|
|
45
|
-
async createChatCompletion(agentId, request) {
|
|
46
|
-
if (request.stream) {
|
|
47
|
-
throw new Error('Use createChatCompletionStream for streaming requests');
|
|
48
|
-
}
|
|
49
|
-
return this.client.post(`/v1/agents/${agentId}/chat/completions`, request);
|
|
50
|
-
}
|
|
51
|
-
/**
|
|
52
|
-
* Send a message to an agent (streaming)
|
|
53
|
-
*/
|
|
54
|
-
async createChatCompletionStream(agentId, request) {
|
|
55
|
-
const streamRequest = { ...request, stream: true };
|
|
56
|
-
return this.client.postEventStream(`/v1/agents/${agentId}/chat/completions`, streamRequest);
|
|
42
|
+
return this.client.post('/v1/agents/auth/websocket', params);
|
|
57
43
|
}
|
|
58
44
|
/**
|
|
59
45
|
* List tools attached to an agent
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agents.js","sourceRoot":"","sources":["../../src/resources/agents.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"agents.js","sourceRoot":"","sources":["../../src/resources/agents.ts"],"names":[],"mappings":"AAQA,MAAM,OA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