@reminix/runtime 0.4.0 → 0.6.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/README.md +201 -30
- package/dist/agent.d.ts +126 -0
- package/dist/agent.d.ts.map +1 -0
- package/dist/agent.js +201 -0
- package/dist/agent.js.map +1 -0
- package/dist/index.d.ts +28 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +31 -5
- package/dist/index.js.map +1 -1
- package/dist/server.d.ts +39 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +239 -0
- package/dist/server.js.map +1 -0
- package/dist/streaming.d.ts +27 -0
- package/dist/streaming.d.ts.map +1 -0
- package/dist/streaming.js +58 -0
- package/dist/streaming.js.map +1 -0
- package/dist/types.d.ts +185 -79
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +82 -2
- package/dist/types.js.map +1 -1
- package/dist/version.d.ts +6 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +6 -0
- package/dist/version.js.map +1 -0
- package/package.json +14 -8
- package/dist/executor.d.ts +0 -17
- package/dist/executor.d.ts.map +0 -1
- package/dist/executor.js +0 -22
- package/dist/executor.js.map +0 -1
- package/dist/loader.d.ts +0 -19
- package/dist/loader.d.ts.map +0 -1
- package/dist/loader.js +0 -52
- package/dist/loader.js.map +0 -1
- package/dist/registry.d.ts +0 -24
- package/dist/registry.d.ts.map +0 -1
- package/dist/registry.js +0 -208
- package/dist/registry.js.map +0 -1
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @reminix/runtime
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Agent runtime for building AI agents that integrate with the Reminix API.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
@@ -8,48 +8,219 @@ Reminix runtime for building handlers that run on Reminix.
|
|
|
8
8
|
npm install @reminix/runtime
|
|
9
9
|
# or
|
|
10
10
|
pnpm add @reminix/runtime
|
|
11
|
-
# or
|
|
12
|
-
yarn add @reminix/runtime
|
|
13
11
|
```
|
|
14
12
|
|
|
15
|
-
##
|
|
13
|
+
## Quick Start
|
|
16
14
|
|
|
17
15
|
```typescript
|
|
18
|
-
import
|
|
16
|
+
import { Agent, serve } from '@reminix/runtime';
|
|
17
|
+
|
|
18
|
+
// Create an agent with optional metadata for dashboard display
|
|
19
|
+
const agent = new Agent('my-agent', {
|
|
20
|
+
metadata: {
|
|
21
|
+
framework: 'custom',
|
|
22
|
+
model: 'gpt-4',
|
|
23
|
+
description: 'My first agent',
|
|
24
|
+
},
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
agent.onInvoke(async (input) => {
|
|
28
|
+
return { output: `Processed: ${input.message}` };
|
|
29
|
+
});
|
|
19
30
|
|
|
20
|
-
|
|
21
|
-
|
|
31
|
+
agent.onChat(async (messages) => {
|
|
32
|
+
const lastMessage = messages[messages.length - 1];
|
|
22
33
|
return {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
34
|
+
message: { role: 'assistant', content: `Reply: ${lastMessage.content}` },
|
|
35
|
+
};
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
serve(agent, { port: 8080 });
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## API Reference
|
|
42
|
+
|
|
43
|
+
### Agent Class
|
|
44
|
+
|
|
45
|
+
Create an agent with a unique name and optional metadata:
|
|
46
|
+
|
|
47
|
+
```typescript
|
|
48
|
+
import { Agent } from '@reminix/runtime';
|
|
49
|
+
|
|
50
|
+
const agent = new Agent('my-agent');
|
|
51
|
+
|
|
52
|
+
// With metadata (optional)
|
|
53
|
+
const agentWithMeta = new Agent('my-agent', {
|
|
54
|
+
metadata: {
|
|
55
|
+
framework: 'langchain',
|
|
56
|
+
model: 'gpt-4',
|
|
57
|
+
description: 'Customer support agent',
|
|
58
|
+
},
|
|
59
|
+
});
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
The `metadata` is available via the `/_discover` endpoint and displayed in the Reminix dashboard.
|
|
63
|
+
|
|
64
|
+
#### `agent.onInvoke(handler)`
|
|
65
|
+
|
|
66
|
+
Register an invoke handler:
|
|
67
|
+
|
|
68
|
+
```typescript
|
|
69
|
+
agent.onInvoke(async (input) => {
|
|
70
|
+
// input is Record<string, unknown>
|
|
71
|
+
return { output: 'result' };
|
|
72
|
+
});
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
#### `agent.onChat(handler)`
|
|
76
|
+
|
|
77
|
+
Register a chat handler:
|
|
78
|
+
|
|
79
|
+
```typescript
|
|
80
|
+
agent.onChat(async (messages) => {
|
|
81
|
+
// messages is ChatMessage[]
|
|
82
|
+
return {
|
|
83
|
+
message: { role: 'assistant', content: 'response' },
|
|
84
|
+
};
|
|
85
|
+
});
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
### Streaming Responses
|
|
89
|
+
|
|
90
|
+
Return an async generator to stream responses:
|
|
91
|
+
|
|
92
|
+
```typescript
|
|
93
|
+
agent.onInvoke(async function* (input) {
|
|
94
|
+
yield { chunk: 'Hello ' };
|
|
95
|
+
yield { chunk: 'World!' };
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
agent.onChat(async function* (messages) {
|
|
99
|
+
yield { chunk: 'Streaming ' };
|
|
100
|
+
yield { chunk: 'response...' };
|
|
101
|
+
});
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
### Serve Function
|
|
105
|
+
|
|
106
|
+
Start a server hosting your agents:
|
|
107
|
+
|
|
108
|
+
```typescript
|
|
109
|
+
import { serve } from '@reminix/runtime';
|
|
110
|
+
|
|
111
|
+
// Single agent
|
|
112
|
+
serve(agent, { host: '0.0.0.0', port: 8080 });
|
|
113
|
+
|
|
114
|
+
// Multiple agents
|
|
115
|
+
serve([agent1, agent2], { port: 8080 });
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
### Endpoints
|
|
119
|
+
|
|
120
|
+
| Method | Path | Description |
|
|
121
|
+
| ------ | ---------------------- | --------------------------- |
|
|
122
|
+
| GET | `/health` | Runtime health status |
|
|
123
|
+
| GET | `/_discover` | Runtime and agent discovery |
|
|
124
|
+
| GET | `/agent/{name}/health` | Agent capabilities |
|
|
125
|
+
| POST | `/agent/{name}/invoke` | Invoke agent |
|
|
126
|
+
| POST | `/agent/{name}/chat` | Chat with agent |
|
|
127
|
+
|
|
128
|
+
### Discovery Endpoint
|
|
129
|
+
|
|
130
|
+
The `/_discover` endpoint returns runtime and agent information:
|
|
131
|
+
|
|
132
|
+
```bash
|
|
133
|
+
curl http://localhost:8080/_discover
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
```json
|
|
137
|
+
{
|
|
138
|
+
"runtime": {
|
|
139
|
+
"version": "0.6.0",
|
|
140
|
+
"language": "typescript",
|
|
141
|
+
"framework": "hono"
|
|
142
|
+
},
|
|
143
|
+
"agents": [
|
|
144
|
+
{
|
|
145
|
+
"name": "my-agent",
|
|
146
|
+
"invoke": true,
|
|
147
|
+
"chat": true,
|
|
148
|
+
"metadata": {
|
|
149
|
+
"framework": "langchain",
|
|
150
|
+
"model": "gpt-4"
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
]
|
|
154
|
+
}
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
### Request/Response Types
|
|
158
|
+
|
|
159
|
+
#### Invoke Request
|
|
160
|
+
|
|
161
|
+
```typescript
|
|
162
|
+
{
|
|
163
|
+
input: Record<string, unknown>;
|
|
164
|
+
stream?: boolean; // default: false
|
|
165
|
+
}
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
#### Invoke Response
|
|
169
|
+
|
|
170
|
+
```typescript
|
|
171
|
+
{
|
|
172
|
+
output: unknown;
|
|
173
|
+
}
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
#### Chat Request
|
|
177
|
+
|
|
178
|
+
```typescript
|
|
179
|
+
{
|
|
180
|
+
messages: Array<{
|
|
181
|
+
role: 'system' | 'user' | 'assistant' | 'tool';
|
|
182
|
+
content: string | unknown[] | null;
|
|
183
|
+
name?: string;
|
|
184
|
+
tool_calls?: ToolCall[];
|
|
185
|
+
tool_call_id?: string;
|
|
186
|
+
}>;
|
|
187
|
+
stream?: boolean; // default: false
|
|
188
|
+
}
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
#### Chat Response
|
|
192
|
+
|
|
193
|
+
```typescript
|
|
194
|
+
{
|
|
195
|
+
message: {
|
|
196
|
+
role: 'assistant';
|
|
197
|
+
content: string | unknown[] | null;
|
|
198
|
+
tool_calls?: ToolCall[];
|
|
29
199
|
};
|
|
30
|
-
}
|
|
200
|
+
}
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
#### Streaming Response (SSE)
|
|
204
|
+
|
|
205
|
+
When `stream: true`, responses are Server-Sent Events:
|
|
206
|
+
|
|
31
207
|
```
|
|
208
|
+
data: {"chunk": "Hello "}
|
|
32
209
|
|
|
33
|
-
|
|
210
|
+
data: {"chunk": "World!"}
|
|
34
211
|
|
|
35
|
-
|
|
212
|
+
data: [DONE]
|
|
213
|
+
```
|
|
36
214
|
|
|
37
|
-
|
|
38
|
-
- `ToolCall` - Tool call made by an agent
|
|
39
|
-
- `Context` - Persistent resources provided to handlers
|
|
40
|
-
- `Request` - Current invocation request
|
|
41
|
-
- `Response` - Handler response
|
|
42
|
-
- `MemoryStore` - Memory store interface
|
|
43
|
-
- `KnowledgeBase` - Knowledge base interface
|
|
44
|
-
- `ToolRegistry` - Tool registry interface
|
|
45
|
-
- `AgentHandler` - Agent handler function type
|
|
46
|
-
- `ToolHandler` - Tool handler function type
|
|
215
|
+
## Error Handling
|
|
47
216
|
|
|
48
|
-
|
|
217
|
+
The runtime handles errors appropriately:
|
|
49
218
|
|
|
50
|
-
- `
|
|
51
|
-
- `
|
|
52
|
-
- `
|
|
219
|
+
- `404` - Agent not found
|
|
220
|
+
- `400` - Invalid request (missing input/messages, validation errors)
|
|
221
|
+
- `501` - Handler not implemented
|
|
222
|
+
- `502` - Agent handler returned invalid response
|
|
223
|
+
- `500` - Internal server error
|
|
53
224
|
|
|
54
225
|
## License
|
|
55
226
|
|
package/dist/agent.d.ts
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Agent class for building AI agents that integrate with Reminix.
|
|
3
|
+
*/
|
|
4
|
+
import type { AgentInfo, ChatHandler, ChatMessage, ChatResponse, InvokeHandler, InvokeInput, InvokeResponse, StreamChunk } from './types';
|
|
5
|
+
/**
|
|
6
|
+
* Options for creating an Agent.
|
|
7
|
+
*/
|
|
8
|
+
export interface AgentOptions {
|
|
9
|
+
/**
|
|
10
|
+
* Optional metadata for the agent (e.g., framework, model, description).
|
|
11
|
+
*/
|
|
12
|
+
metadata?: Record<string, unknown>;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Agent class for defining invoke and chat handlers.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```typescript
|
|
19
|
+
* const agent = new Agent('my-agent');
|
|
20
|
+
*
|
|
21
|
+
* agent.onInvoke(async (input) => {
|
|
22
|
+
* return { output: `Processed: ${input.message}` };
|
|
23
|
+
* });
|
|
24
|
+
*
|
|
25
|
+
* agent.onChat(async (messages) => {
|
|
26
|
+
* return {
|
|
27
|
+
* message: { role: 'assistant', content: 'Hello!' }
|
|
28
|
+
* };
|
|
29
|
+
* });
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
export declare class Agent {
|
|
33
|
+
readonly name: string;
|
|
34
|
+
private readonly _metadata;
|
|
35
|
+
private invokeHandler;
|
|
36
|
+
private chatHandler;
|
|
37
|
+
/**
|
|
38
|
+
* Create a new Agent.
|
|
39
|
+
*
|
|
40
|
+
* @param name - Unique identifier for the agent (lowercase letters, numbers, hyphens, underscores)
|
|
41
|
+
* @param options - Optional configuration including metadata
|
|
42
|
+
* @throws {Error} If name is empty or contains invalid characters
|
|
43
|
+
*/
|
|
44
|
+
constructor(name: string, options?: AgentOptions);
|
|
45
|
+
/**
|
|
46
|
+
* Get the agent's metadata.
|
|
47
|
+
*/
|
|
48
|
+
get metadata(): Record<string, unknown>;
|
|
49
|
+
/**
|
|
50
|
+
* Get agent information for discovery.
|
|
51
|
+
*/
|
|
52
|
+
toInfo(): AgentInfo;
|
|
53
|
+
/**
|
|
54
|
+
* Whether an invoke handler is registered.
|
|
55
|
+
*/
|
|
56
|
+
get hasInvoke(): boolean;
|
|
57
|
+
/**
|
|
58
|
+
* Whether a chat handler is registered.
|
|
59
|
+
*/
|
|
60
|
+
get hasChat(): boolean;
|
|
61
|
+
/**
|
|
62
|
+
* Register an invoke handler.
|
|
63
|
+
*
|
|
64
|
+
* @param handler - Function that processes invoke requests
|
|
65
|
+
* @returns The agent instance for chaining
|
|
66
|
+
*
|
|
67
|
+
* @example
|
|
68
|
+
* ```typescript
|
|
69
|
+
* agent.onInvoke(async (input) => {
|
|
70
|
+
* return { output: processData(input) };
|
|
71
|
+
* });
|
|
72
|
+
* ```
|
|
73
|
+
*/
|
|
74
|
+
onInvoke(handler: InvokeHandler): this;
|
|
75
|
+
/**
|
|
76
|
+
* Register a chat handler.
|
|
77
|
+
*
|
|
78
|
+
* @param handler - Function that processes chat requests
|
|
79
|
+
* @returns The agent instance for chaining
|
|
80
|
+
*
|
|
81
|
+
* @example
|
|
82
|
+
* ```typescript
|
|
83
|
+
* agent.onChat(async (messages) => {
|
|
84
|
+
* return {
|
|
85
|
+
* message: { role: 'assistant', content: 'Hello!' }
|
|
86
|
+
* };
|
|
87
|
+
* });
|
|
88
|
+
* ```
|
|
89
|
+
*/
|
|
90
|
+
onChat(handler: ChatHandler): this;
|
|
91
|
+
/**
|
|
92
|
+
* Handle an invoke request.
|
|
93
|
+
*
|
|
94
|
+
* @param input - The input data from the request
|
|
95
|
+
* @returns The response or an async generator for streaming
|
|
96
|
+
* @throws {Error} If no invoke handler is registered
|
|
97
|
+
* @throws {Error} If the response is invalid
|
|
98
|
+
*/
|
|
99
|
+
handleInvoke(input: InvokeInput): Promise<InvokeResponse | AsyncGenerator<StreamChunk, void, unknown>>;
|
|
100
|
+
/**
|
|
101
|
+
* Handle a chat request.
|
|
102
|
+
*
|
|
103
|
+
* @param messages - The conversation messages
|
|
104
|
+
* @returns The response or an async generator for streaming
|
|
105
|
+
* @throws {Error} If no chat handler is registered
|
|
106
|
+
* @throws {Error} If the response is invalid
|
|
107
|
+
*/
|
|
108
|
+
handleChat(messages: ChatMessage[]): Promise<ChatResponse | AsyncGenerator<StreamChunk, void, unknown>>;
|
|
109
|
+
/**
|
|
110
|
+
* String representation for debugging.
|
|
111
|
+
*/
|
|
112
|
+
toString(): string;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Error thrown when a handler is not implemented.
|
|
116
|
+
*/
|
|
117
|
+
export declare class NotImplementedError extends Error {
|
|
118
|
+
constructor(message: string);
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Error thrown when an agent handler returns invalid data.
|
|
122
|
+
*/
|
|
123
|
+
export declare class AgentError extends Error {
|
|
124
|
+
constructor(message: string);
|
|
125
|
+
}
|
|
126
|
+
//# sourceMappingURL=agent.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent.d.ts","sourceRoot":"","sources":["../src/agent.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EACV,SAAS,EACT,WAAW,EACX,WAAW,EACX,YAAY,EAEZ,aAAa,EACb,WAAW,EACX,cAAc,EAEd,WAAW,EACZ,MAAM,SAAS,CAAC;AAEjB;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACpC;AAmBD;;;;;;;;;;;;;;;;;GAiBG;AACH,qBAAa,KAAK;IAChB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,OAAO,CAAC,QAAQ,CAAC,SAAS,CAA0B;IACpD,OAAO,CAAC,aAAa,CAA8B;IACnD,OAAO,CAAC,WAAW,CAA4B;IAE/C;;;;;;OAMG;gBACS,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,YAAY;IAgBhD;;OAEG;IACH,IAAI,QAAQ,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAEtC;IAED;;OAEG;IACH,MAAM,IAAI,SAAS;IASnB;;OAEG;IACH,IAAI,SAAS,IAAI,OAAO,CAEvB;IAED;;OAEG;IACH,IAAI,OAAO,IAAI,OAAO,CAErB;IAED;;;;;;;;;;;;OAYG;IACH,QAAQ,CAAC,OAAO,EAAE,aAAa,GAAG,IAAI;IAKtC;;;;;;;;;;;;;;OAcG;IACH,MAAM,CAAC,OAAO,EAAE,WAAW,GAAG,IAAI;IAKlC;;;;;;;OAOG;IACG,YAAY,CAChB,KAAK,EAAE,WAAW,GACjB,OAAO,CAAC,cAAc,GAAG,cAAc,CAAC,WAAW,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;IAoBvE;;;;;;;OAOG;IACG,UAAU,CACd,QAAQ,EAAE,WAAW,EAAE,GACtB,OAAO,CAAC,YAAY,GAAG,cAAc,CAAC,WAAW,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;IAyBrE;;OAEG;IACH,QAAQ,IAAI,MAAM;CAMnB;AAED;;GAEG;AACH,qBAAa,mBAAoB,SAAQ,KAAK;gBAChC,OAAO,EAAE,MAAM;CAI5B;AAED;;GAEG;AACH,qBAAa,UAAW,SAAQ,KAAK;gBACvB,OAAO,EAAE,MAAM;CAI5B"}
|
package/dist/agent.js
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Agent class for building AI agents that integrate with Reminix.
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Pattern for valid agent names: lowercase letters, numbers, hyphens, underscores.
|
|
6
|
+
*/
|
|
7
|
+
const VALID_NAME_PATTERN = /^[a-z0-9_-]+$/;
|
|
8
|
+
/**
|
|
9
|
+
* Check if a value is an async generator.
|
|
10
|
+
*/
|
|
11
|
+
function isAsyncGenerator(value) {
|
|
12
|
+
return (value !== null &&
|
|
13
|
+
typeof value === 'object' &&
|
|
14
|
+
Symbol.asyncIterator in value &&
|
|
15
|
+
typeof value.next === 'function');
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Agent class for defining invoke and chat handlers.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```typescript
|
|
22
|
+
* const agent = new Agent('my-agent');
|
|
23
|
+
*
|
|
24
|
+
* agent.onInvoke(async (input) => {
|
|
25
|
+
* return { output: `Processed: ${input.message}` };
|
|
26
|
+
* });
|
|
27
|
+
*
|
|
28
|
+
* agent.onChat(async (messages) => {
|
|
29
|
+
* return {
|
|
30
|
+
* message: { role: 'assistant', content: 'Hello!' }
|
|
31
|
+
* };
|
|
32
|
+
* });
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
export class Agent {
|
|
36
|
+
/**
|
|
37
|
+
* Create a new Agent.
|
|
38
|
+
*
|
|
39
|
+
* @param name - Unique identifier for the agent (lowercase letters, numbers, hyphens, underscores)
|
|
40
|
+
* @param options - Optional configuration including metadata
|
|
41
|
+
* @throws {Error} If name is empty or contains invalid characters
|
|
42
|
+
*/
|
|
43
|
+
constructor(name, options) {
|
|
44
|
+
this.invokeHandler = null;
|
|
45
|
+
this.chatHandler = null;
|
|
46
|
+
if (!name || name.trim() === '') {
|
|
47
|
+
throw new Error('Agent name cannot be empty');
|
|
48
|
+
}
|
|
49
|
+
if (!VALID_NAME_PATTERN.test(name)) {
|
|
50
|
+
throw new Error(`Agent name "${name}" contains invalid characters. ` +
|
|
51
|
+
'Use only lowercase letters, numbers, hyphens, and underscores.');
|
|
52
|
+
}
|
|
53
|
+
this.name = name;
|
|
54
|
+
this._metadata = options?.metadata ?? {};
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Get the agent's metadata.
|
|
58
|
+
*/
|
|
59
|
+
get metadata() {
|
|
60
|
+
return this._metadata;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Get agent information for discovery.
|
|
64
|
+
*/
|
|
65
|
+
toInfo() {
|
|
66
|
+
return {
|
|
67
|
+
name: this.name,
|
|
68
|
+
invoke: this.hasInvoke,
|
|
69
|
+
chat: this.hasChat,
|
|
70
|
+
metadata: this._metadata,
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Whether an invoke handler is registered.
|
|
75
|
+
*/
|
|
76
|
+
get hasInvoke() {
|
|
77
|
+
return this.invokeHandler !== null;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Whether a chat handler is registered.
|
|
81
|
+
*/
|
|
82
|
+
get hasChat() {
|
|
83
|
+
return this.chatHandler !== null;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Register an invoke handler.
|
|
87
|
+
*
|
|
88
|
+
* @param handler - Function that processes invoke requests
|
|
89
|
+
* @returns The agent instance for chaining
|
|
90
|
+
*
|
|
91
|
+
* @example
|
|
92
|
+
* ```typescript
|
|
93
|
+
* agent.onInvoke(async (input) => {
|
|
94
|
+
* return { output: processData(input) };
|
|
95
|
+
* });
|
|
96
|
+
* ```
|
|
97
|
+
*/
|
|
98
|
+
onInvoke(handler) {
|
|
99
|
+
this.invokeHandler = handler;
|
|
100
|
+
return this;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Register a chat handler.
|
|
104
|
+
*
|
|
105
|
+
* @param handler - Function that processes chat requests
|
|
106
|
+
* @returns The agent instance for chaining
|
|
107
|
+
*
|
|
108
|
+
* @example
|
|
109
|
+
* ```typescript
|
|
110
|
+
* agent.onChat(async (messages) => {
|
|
111
|
+
* return {
|
|
112
|
+
* message: { role: 'assistant', content: 'Hello!' }
|
|
113
|
+
* };
|
|
114
|
+
* });
|
|
115
|
+
* ```
|
|
116
|
+
*/
|
|
117
|
+
onChat(handler) {
|
|
118
|
+
this.chatHandler = handler;
|
|
119
|
+
return this;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Handle an invoke request.
|
|
123
|
+
*
|
|
124
|
+
* @param input - The input data from the request
|
|
125
|
+
* @returns The response or an async generator for streaming
|
|
126
|
+
* @throws {Error} If no invoke handler is registered
|
|
127
|
+
* @throws {Error} If the response is invalid
|
|
128
|
+
*/
|
|
129
|
+
async handleInvoke(input) {
|
|
130
|
+
if (!this.invokeHandler) {
|
|
131
|
+
throw new NotImplementedError('Invoke handler not implemented');
|
|
132
|
+
}
|
|
133
|
+
const result = await this.invokeHandler(input);
|
|
134
|
+
// If it's a generator, return it for streaming
|
|
135
|
+
if (isAsyncGenerator(result)) {
|
|
136
|
+
return result;
|
|
137
|
+
}
|
|
138
|
+
// Validate non-streaming response
|
|
139
|
+
if (!('output' in result)) {
|
|
140
|
+
throw new AgentError('Invoke handler must return an object with "output" field');
|
|
141
|
+
}
|
|
142
|
+
return result;
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Handle a chat request.
|
|
146
|
+
*
|
|
147
|
+
* @param messages - The conversation messages
|
|
148
|
+
* @returns The response or an async generator for streaming
|
|
149
|
+
* @throws {Error} If no chat handler is registered
|
|
150
|
+
* @throws {Error} If the response is invalid
|
|
151
|
+
*/
|
|
152
|
+
async handleChat(messages) {
|
|
153
|
+
if (!this.chatHandler) {
|
|
154
|
+
throw new NotImplementedError('Chat handler not implemented');
|
|
155
|
+
}
|
|
156
|
+
const result = await this.chatHandler(messages);
|
|
157
|
+
// If it's a generator, return it for streaming
|
|
158
|
+
if (isAsyncGenerator(result)) {
|
|
159
|
+
return result;
|
|
160
|
+
}
|
|
161
|
+
// Validate non-streaming response
|
|
162
|
+
if (!('message' in result)) {
|
|
163
|
+
throw new AgentError('Chat handler must return an object with "message" field');
|
|
164
|
+
}
|
|
165
|
+
const message = result.message;
|
|
166
|
+
if (!message || message.role !== 'assistant') {
|
|
167
|
+
throw new AgentError('Chat handler must return a message with role "assistant"');
|
|
168
|
+
}
|
|
169
|
+
return result;
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* String representation for debugging.
|
|
173
|
+
*/
|
|
174
|
+
toString() {
|
|
175
|
+
const capabilities = [];
|
|
176
|
+
if (this.hasInvoke)
|
|
177
|
+
capabilities.push('invoke');
|
|
178
|
+
if (this.hasChat)
|
|
179
|
+
capabilities.push('chat');
|
|
180
|
+
return `Agent(${this.name}, ${capabilities.length > 0 ? capabilities.join(', ') : 'no handlers'})`;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Error thrown when a handler is not implemented.
|
|
185
|
+
*/
|
|
186
|
+
export class NotImplementedError extends Error {
|
|
187
|
+
constructor(message) {
|
|
188
|
+
super(message);
|
|
189
|
+
this.name = 'NotImplementedError';
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Error thrown when an agent handler returns invalid data.
|
|
194
|
+
*/
|
|
195
|
+
export class AgentError extends Error {
|
|
196
|
+
constructor(message) {
|
|
197
|
+
super(message);
|
|
198
|
+
this.name = 'AgentError';
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
//# sourceMappingURL=agent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent.js","sourceRoot":"","sources":["../src/agent.ts"],"names":[],"mappings":"AAAA;;GAEG;AAyBH;;GAEG;AACH,MAAM,kBAAkB,GAAG,eAAe,CAAC;AAE3C;;GAEG;AACH,SAAS,gBAAgB,CAAC,KAAc;IACtC,OAAO,CACL,KAAK,KAAK,IAAI;QACd,OAAO,KAAK,KAAK,QAAQ;QACzB,MAAM,CAAC,aAAa,IAAI,KAAK;QAC7B,OAAQ,KAAwB,CAAC,IAAI,KAAK,UAAU,CACrD,CAAC;AACJ,CAAC;AAED;;;;;;;;;;;;;;;;;GA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,OAAO,MAAsB,CAAC;IAChC,CAAC;IAED;;OAEG;IACH,QAAQ;QACN,MAAM,YAAY,GAAa,EAAE,CAAC;QAClC,IAAI,IAAI,CAAC,SAAS;YAAE,YAAY,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QAChD,IAAI,IAAI,CAAC,OAAO;YAAE,YAAY,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAC5C,OAAO,SAAS,IAAI,CAAC,IAAI,KAAK,YAAY,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,aAAa,GAAG,CAAC;IACrG,CAAC;CACF;AAED;;GAEG;AACH,MAAM,OAAO,mBAAoB,SAAQ,KAAK;IAC5C,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,qBAAqB,CAAC;IACpC,CAAC;CACF;AAED;;GAEG;AACH,MAAM,OAAO,UAAW,SAAQ,KAAK;IACnC,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,YAAY,CAAC;IAC3B,CAAC;CACF"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,31 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Reminix Runtime
|
|
3
|
-
*
|
|
2
|
+
* Reminix Agent Runtime
|
|
3
|
+
*
|
|
4
|
+
* Build AI agents that integrate seamlessly with the Reminix API.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```typescript
|
|
8
|
+
* import { Agent, serve } from '@reminix/runtime';
|
|
9
|
+
*
|
|
10
|
+
* const agent = new Agent('my-agent');
|
|
11
|
+
*
|
|
12
|
+
* agent.onInvoke(async (input) => {
|
|
13
|
+
* return { output: `Processed: ${input.message}` };
|
|
14
|
+
* });
|
|
15
|
+
*
|
|
16
|
+
* agent.onChat(async (messages) => {
|
|
17
|
+
* const lastMessage = messages[messages.length - 1];
|
|
18
|
+
* return {
|
|
19
|
+
* message: { role: 'assistant', content: `Reply to: ${lastMessage.content}` }
|
|
20
|
+
* };
|
|
21
|
+
* });
|
|
22
|
+
*
|
|
23
|
+
* serve(agent, { port: 8080 });
|
|
24
|
+
* ```
|
|
4
25
|
*/
|
|
5
|
-
export type {
|
|
6
|
-
export {
|
|
7
|
-
export {
|
|
8
|
-
export {
|
|
26
|
+
export type { ToolCallFunction, ToolCall, MessageRole, ChatMessage, AssistantMessage, InvokeRequest, ChatRequest, InvokeResponse, ChatResponse, StreamChunk, InvokeInput, InvokeResult, ChatResult, InvokeHandler, ChatHandler, AgentHealth, HealthResponse, AgentMetadata, AgentInfo, RuntimeInfo, DiscoverResponse, } from './types';
|
|
27
|
+
export { ToolCallFunctionSchema, ToolCallSchema, MessageRoleSchema, ChatMessageSchema, AssistantMessageSchema, InvokeRequestSchema, ChatRequestSchema, InvokeResponseSchema, ChatResponseSchema, StreamChunkSchema, } from './types';
|
|
28
|
+
export { Agent, NotImplementedError, AgentError, type AgentOptions } from './agent';
|
|
29
|
+
export { serve, createApp, type ServeOptions } from './server';
|
|
30
|
+
export { formatSseEvent, formatSseDone, streamToSse } from './streaming';
|
|
9
31
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAGH,YAAY,EAEV,gBAAgB,EAChB,QAAQ,EACR,WAAW,EACX,WAAW,EACX,gBAAgB,EAEhB,aAAa,EACb,WAAW,EAEX,cAAc,EACd,YAAY,EACZ,WAAW,EAEX,WAAW,EACX,YAAY,EACZ,UAAU,EACV,aAAa,EACb,WAAW,EAEX,WAAW,EACX,cAAc,EAEd,aAAa,EACb,SAAS,EACT,WAAW,EACX,gBAAgB,GACjB,MAAM,SAAS,CAAC;AAGjB,OAAO,EACL,sBAAsB,EACtB,cAAc,EACd,iBAAiB,EACjB,iBAAiB,EACjB,sBAAsB,EACtB,mBAAmB,EACnB,iBAAiB,EACjB,oBAAoB,EACpB,kBAAkB,EAClB,iBAAiB,GAClB,MAAM,SAAS,CAAC;AAGjB,OAAO,EAAE,KAAK,EAAE,mBAAmB,EAAE,UAAU,EAAE,KAAK,YAAY,EAAE,MAAM,SAAS,CAAC;AAGpF,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,KAAK,YAAY,EAAE,MAAM,UAAU,CAAC;AAG/D,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,34 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Reminix Runtime
|
|
3
|
-
*
|
|
2
|
+
* Reminix Agent Runtime
|
|
3
|
+
*
|
|
4
|
+
* Build AI agents that integrate seamlessly with the Reminix API.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```typescript
|
|
8
|
+
* import { Agent, serve } from '@reminix/runtime';
|
|
9
|
+
*
|
|
10
|
+
* const agent = new Agent('my-agent');
|
|
11
|
+
*
|
|
12
|
+
* agent.onInvoke(async (input) => {
|
|
13
|
+
* return { output: `Processed: ${input.message}` };
|
|
14
|
+
* });
|
|
15
|
+
*
|
|
16
|
+
* agent.onChat(async (messages) => {
|
|
17
|
+
* const lastMessage = messages[messages.length - 1];
|
|
18
|
+
* return {
|
|
19
|
+
* message: { role: 'assistant', content: `Reply to: ${lastMessage.content}` }
|
|
20
|
+
* };
|
|
21
|
+
* });
|
|
22
|
+
*
|
|
23
|
+
* serve(agent, { port: 8080 });
|
|
24
|
+
* ```
|
|
4
25
|
*/
|
|
5
|
-
|
|
6
|
-
export {
|
|
7
|
-
|
|
26
|
+
// Export schemas for runtime validation
|
|
27
|
+
export { ToolCallFunctionSchema, ToolCallSchema, MessageRoleSchema, ChatMessageSchema, AssistantMessageSchema, InvokeRequestSchema, ChatRequestSchema, InvokeResponseSchema, ChatResponseSchema, StreamChunkSchema, } from './types';
|
|
28
|
+
// Export Agent class, options, and errors
|
|
29
|
+
export { Agent, NotImplementedError, AgentError } from './agent';
|
|
30
|
+
// Export server
|
|
31
|
+
export { serve, createApp } from './server';
|
|
32
|
+
// Export streaming utilities
|
|
33
|
+
export { formatSseEvent, formatSseDone, streamToSse } from './streaming';
|
|
8
34
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAiCH,wCAAwC;AACxC,OAAO,EACL,sBAAsB,EACtB,cAAc,EACd,iBAAiB,EACjB,iBAAiB,EACjB,sBAAsB,EACtB,mBAAmB,EACnB,iBAAiB,EACjB,oBAAoB,EACpB,kBAAkB,EAClB,iBAAiB,GAClB,MAAM,SAAS,CAAC;AAEjB,0CAA0C;AAC1C,OAAO,EAAE,KAAK,EAAE,mBAAmB,EAAE,UAAU,EAAqB,MAAM,SAAS,CAAC;AAEpF,gBAAgB;AAChB,OAAO,EAAE,KAAK,EAAE,SAAS,EAAqB,MAAM,UAAU,CAAC;AAE/D,6BAA6B;AAC7B,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC"}
|