rice-node-sdk 1.0.6 → 1.0.7
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 +24 -0
- package/dist/state/index.d.ts +9 -0
- package/dist/state/index.js +20 -0
- package/dist/state/proto/state.proto +17 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -266,6 +266,25 @@ console.log(cycleResult.planningTimeMs);
|
|
|
266
266
|
const history = await client.state.getCycleHistory(10);
|
|
267
267
|
```
|
|
268
268
|
|
|
269
|
+
### Pub/Sub (Real-time Events)
|
|
270
|
+
|
|
271
|
+
Subscribe to real-time events from the State service, such as variable updates or memory commits. This is useful for multi-agent coordination.
|
|
272
|
+
|
|
273
|
+
```typescript
|
|
274
|
+
// Subscribe to variable updates
|
|
275
|
+
const stream = client.state.subscribe(["VariableUpdate"]);
|
|
276
|
+
|
|
277
|
+
stream.on("data", (event) => {
|
|
278
|
+
console.log("Received event:", event.type);
|
|
279
|
+
if (event.type === "VariableUpdate") {
|
|
280
|
+
const variable = JSON.parse(event.payload);
|
|
281
|
+
console.log(`Variable ${variable.name} updated to:`, variable.value_json);
|
|
282
|
+
}
|
|
283
|
+
});
|
|
284
|
+
|
|
285
|
+
stream.on("error", (err) => console.error("Stream error:", err));
|
|
286
|
+
```
|
|
287
|
+
|
|
269
288
|
## AI Tool Definitions
|
|
270
289
|
|
|
271
290
|
The SDK provides pre-built tool definitions tailored for popular LLM providers. These tools map directly to State memory operations.
|
|
@@ -408,6 +427,7 @@ if (call) {
|
|
|
408
427
|
| `getActionLog` | Get the action log for the current run | `client.state.getActionLog()` |
|
|
409
428
|
| `runCycle` | Run a decision cycle with action candidates | `client.state.runCycle()` |
|
|
410
429
|
| `getCycleHistory` | Get history of decision cycles | `client.state.getCycleHistory()` |
|
|
430
|
+
| `subscribe` | Subscribe to real-time state events | `client.state.subscribe()` |
|
|
411
431
|
|
|
412
432
|
## API Reference
|
|
413
433
|
|
|
@@ -489,8 +509,12 @@ interface StateClient {
|
|
|
489
509
|
): Promise<CycleResult>;
|
|
490
510
|
getCycleHistory(limit?: number): Promise<CycleResult[]>;
|
|
491
511
|
|
|
512
|
+
// Events
|
|
513
|
+
subscribe(eventTypes?: string[]): NodeJS.EventEmitter;
|
|
514
|
+
|
|
492
515
|
// Session Management
|
|
493
516
|
setRunId(runId: string): void;
|
|
517
|
+
|
|
494
518
|
deleteRun(): Promise<boolean>;
|
|
495
519
|
|
|
496
520
|
// Skills
|
package/dist/state/index.d.ts
CHANGED
|
@@ -148,4 +148,13 @@ export declare class StateClient {
|
|
|
148
148
|
* @returns A promise that resolves to an array of cycle records.
|
|
149
149
|
*/
|
|
150
150
|
getCycleHistory(limit?: number): Promise<any[]>;
|
|
151
|
+
/**
|
|
152
|
+
* Subscribe to real-time events for the current run_id.
|
|
153
|
+
* Returns a gRPC ClientReadableStream that emits 'data', 'error', and 'end' events.
|
|
154
|
+
*
|
|
155
|
+
* usage:
|
|
156
|
+
* const stream = client.subscribe();
|
|
157
|
+
* stream.on('data', (event: any) => { ... });
|
|
158
|
+
*/
|
|
159
|
+
subscribe(eventTypes?: string[]): any;
|
|
151
160
|
}
|
package/dist/state/index.js
CHANGED
|
@@ -506,5 +506,25 @@ class StateClient {
|
|
|
506
506
|
});
|
|
507
507
|
});
|
|
508
508
|
}
|
|
509
|
+
// ==========================================================================
|
|
510
|
+
// Events (Pub/Sub)
|
|
511
|
+
// ==========================================================================
|
|
512
|
+
/**
|
|
513
|
+
* Subscribe to real-time events for the current run_id.
|
|
514
|
+
* Returns a gRPC ClientReadableStream that emits 'data', 'error', and 'end' events.
|
|
515
|
+
*
|
|
516
|
+
* usage:
|
|
517
|
+
* const stream = client.subscribe();
|
|
518
|
+
* stream.on('data', (event: any) => { ... });
|
|
519
|
+
*/
|
|
520
|
+
subscribe(eventTypes = []) {
|
|
521
|
+
const request = {
|
|
522
|
+
run_id: this.runId,
|
|
523
|
+
event_types: eventTypes,
|
|
524
|
+
};
|
|
525
|
+
// For streaming RPCs, we don't provide a callback.
|
|
526
|
+
// The call object itself is the stream.
|
|
527
|
+
return this.client.Subscribe(request, this.metadata);
|
|
528
|
+
}
|
|
509
529
|
}
|
|
510
530
|
exports.StateClient = StateClient;
|
|
@@ -41,6 +41,9 @@ service Cortex {
|
|
|
41
41
|
|
|
42
42
|
// Management
|
|
43
43
|
rpc DeleteRun(RunRequest) returns (Ack);
|
|
44
|
+
|
|
45
|
+
// Events
|
|
46
|
+
rpc Subscribe(SubscribeRequest) returns (stream Event);
|
|
44
47
|
}
|
|
45
48
|
|
|
46
49
|
message FocusRequest {
|
|
@@ -292,3 +295,17 @@ message CycleHistoryRequest {
|
|
|
292
295
|
message CycleHistoryResponse {
|
|
293
296
|
repeated CycleResponse cycles = 1;
|
|
294
297
|
}
|
|
298
|
+
|
|
299
|
+
message SubscribeRequest {
|
|
300
|
+
string run_id = 1;
|
|
301
|
+
repeated string event_types = 2; // Optional filter e.g. ["Focus", "Commit"]
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
message Event {
|
|
305
|
+
string id = 1;
|
|
306
|
+
string type = 2; // "Focus", "Commit", "VariableUpdate", "GoalUpdate"
|
|
307
|
+
string run_id = 3;
|
|
308
|
+
string agent_id = 4;
|
|
309
|
+
string payload = 5; // JSON string of the object involved
|
|
310
|
+
string created_at = 6;
|
|
311
|
+
}
|