rice-node-sdk 1.0.2 → 1.0.3

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.
@@ -45,9 +45,12 @@ export declare class StateClient {
45
45
  * Recalls past memories relevant to a query.
46
46
  * @param query - The query text to search for memories.
47
47
  * @param limit - Maximum number of memories to retrieve. Defaults to 5.
48
+ * @param filter - Optional metadata filter.
48
49
  * @returns A promise that resolves to an array of traces/memories.
49
50
  */
50
- reminisce(query: string, limit?: number): Promise<any[]>;
51
+ reminisce(query: string, limit?: number, filter?: {
52
+ [key: string]: any;
53
+ }): Promise<any[]>;
51
54
  /**
52
55
  * Triggers a specific skill or action.
53
56
  * @param skillName - The name of the skill to trigger.
@@ -59,4 +62,90 @@ export declare class StateClient {
59
62
  * @returns A promise that resolves to true if successful.
60
63
  */
61
64
  deleteRun(): Promise<boolean>;
65
+ /**
66
+ * Sets a variable in working memory.
67
+ * @param name - The name of the variable.
68
+ * @param value - The value to store (will be JSON-encoded).
69
+ * @param source - The source of the variable. Defaults to "explicit".
70
+ * @returns A promise that resolves to true if successful.
71
+ */
72
+ setVariable(name: string, value: any, source?: string): Promise<boolean>;
73
+ /**
74
+ * Gets a variable from working memory.
75
+ * @param name - The name of the variable to retrieve.
76
+ * @returns A promise that resolves to the variable details including value, type, and metadata.
77
+ */
78
+ getVariable(name: string): Promise<any>;
79
+ /**
80
+ * Lists all variables in working memory.
81
+ * @returns A promise that resolves to an array of variables.
82
+ */
83
+ listVariables(): Promise<any[]>;
84
+ /**
85
+ * Deletes a variable from working memory.
86
+ * @param name - The name of the variable to delete.
87
+ * @returns A promise that resolves to true if successful.
88
+ */
89
+ deleteVariable(name: string): Promise<boolean>;
90
+ /**
91
+ * Defines a concept with a schema.
92
+ * @param name - The name of the concept.
93
+ * @param schema - The schema definition (object or JSON string).
94
+ * @returns A promise that resolves to true if successful.
95
+ */
96
+ defineConcept(name: string, schema: any): Promise<boolean>;
97
+ /**
98
+ * Lists all defined concepts.
99
+ * @returns A promise that resolves to an array of concepts with their schemas.
100
+ */
101
+ listConcepts(): Promise<any[]>;
102
+ /**
103
+ * Adds a new goal.
104
+ * @param description - The description of the goal.
105
+ * @param priority - The priority level ("low", "medium", "high", "critical"). Defaults to "medium".
106
+ * @param parentId - Optional parent goal ID for hierarchical goals.
107
+ * @returns A promise that resolves to the created goal details.
108
+ */
109
+ addGoal(description: string, priority?: string, parentId?: string): Promise<any>;
110
+ /**
111
+ * Updates a goal's status.
112
+ * @param goalId - The ID of the goal to update.
113
+ * @param status - The new status ("active", "suspended", "achieved", "abandoned", "failed").
114
+ * @returns A promise that resolves to true if successful.
115
+ */
116
+ updateGoal(goalId: string, status: string): Promise<boolean>;
117
+ /**
118
+ * Lists all goals, optionally filtered by status.
119
+ * @param statusFilter - Optional status to filter by.
120
+ * @returns A promise that resolves to an array of goals.
121
+ */
122
+ listGoals(statusFilter?: string): Promise<any[]>;
123
+ /**
124
+ * Submits an action for execution.
125
+ * @param agentId - The ID of the agent submitting the action.
126
+ * @param actionType - The type of action ("reason", "retrieve", "learn", "ground").
127
+ * @param actionDetails - The action details (will be JSON-encoded).
128
+ * @returns A promise that resolves to the action result.
129
+ */
130
+ submitAction(agentId: string, actionType: string, actionDetails: any): Promise<any>;
131
+ /**
132
+ * Gets the action log for the current run.
133
+ * @param limit - Maximum number of entries to retrieve. Defaults to 100.
134
+ * @param actionTypeFilter - Optional action type to filter by.
135
+ * @returns A promise that resolves to an array of action log entries.
136
+ */
137
+ getActionLog(limit?: number, actionTypeFilter?: string): Promise<any[]>;
138
+ /**
139
+ * Runs a decision cycle, optionally with pre-proposed action candidates.
140
+ * @param agentId - The ID of the agent running the cycle.
141
+ * @param candidates - Optional array of action candidates with scores and rationales.
142
+ * @returns A promise that resolves to the cycle result.
143
+ */
144
+ runCycle(agentId: string, candidates?: any[]): Promise<any>;
145
+ /**
146
+ * Gets the decision cycle history for the current run.
147
+ * @param limit - Maximum number of cycles to retrieve. Defaults to 100.
148
+ * @returns A promise that resolves to an array of cycle records.
149
+ */
150
+ getCycleHistory(limit?: number): Promise<any[]>;
62
151
  }
@@ -135,15 +135,17 @@ class StateClient {
135
135
  * Recalls past memories relevant to a query.
136
136
  * @param query - The query text to search for memories.
137
137
  * @param limit - Maximum number of memories to retrieve. Defaults to 5.
138
+ * @param filter - Optional metadata filter.
138
139
  * @returns A promise that resolves to an array of traces/memories.
139
140
  */
140
- reminisce(query, limit = 5) {
141
+ reminisce(query, limit = 5, filter) {
141
142
  return new Promise((resolve, reject) => {
142
143
  const req = {
143
144
  embedding: [],
144
145
  limit,
145
146
  query_text: query,
146
147
  run_id: this.runId,
148
+ filter: filter ? JSON.stringify(filter) : undefined,
147
149
  };
148
150
  this.client.Reminisce(req, this.metadata, (err, response) => {
149
151
  if (err)
@@ -185,5 +187,324 @@ class StateClient {
185
187
  });
186
188
  });
187
189
  }
190
+ // ==========================================================================
191
+ // Working Memory (Structured Variables)
192
+ // ==========================================================================
193
+ /**
194
+ * Sets a variable in working memory.
195
+ * @param name - The name of the variable.
196
+ * @param value - The value to store (will be JSON-encoded).
197
+ * @param source - The source of the variable. Defaults to "explicit".
198
+ * @returns A promise that resolves to true if successful.
199
+ */
200
+ setVariable(name, value, source = "explicit") {
201
+ return new Promise((resolve, reject) => {
202
+ const req = {
203
+ run_id: this.runId,
204
+ name,
205
+ value_json: JSON.stringify(value),
206
+ source,
207
+ };
208
+ this.client.SetVariable(req, this.metadata, (err, response) => {
209
+ if (err)
210
+ reject(err);
211
+ else
212
+ resolve(response.success);
213
+ });
214
+ });
215
+ }
216
+ /**
217
+ * Gets a variable from working memory.
218
+ * @param name - The name of the variable to retrieve.
219
+ * @returns A promise that resolves to the variable details including value, type, and metadata.
220
+ */
221
+ getVariable(name) {
222
+ return new Promise((resolve, reject) => {
223
+ const req = {
224
+ run_id: this.runId,
225
+ name,
226
+ };
227
+ this.client.GetVariable(req, this.metadata, (err, response) => {
228
+ if (err)
229
+ reject(err);
230
+ else
231
+ resolve({
232
+ name: response.name,
233
+ value: JSON.parse(response.value_json || "null"),
234
+ varType: response.var_type,
235
+ createdAt: response.created_at,
236
+ lastUpdated: response.last_updated,
237
+ accessCount: response.access_count,
238
+ source: response.source,
239
+ });
240
+ });
241
+ });
242
+ }
243
+ /**
244
+ * Lists all variables in working memory.
245
+ * @returns A promise that resolves to an array of variables.
246
+ */
247
+ listVariables() {
248
+ return new Promise((resolve, reject) => {
249
+ this.client.ListVariables({ run_id: this.runId }, this.metadata, (err, response) => {
250
+ if (err)
251
+ reject(err);
252
+ else
253
+ resolve((response.variables || []).map((v) => ({
254
+ name: v.name,
255
+ value: JSON.parse(v.value_json || "null"),
256
+ varType: v.var_type,
257
+ source: v.source,
258
+ })));
259
+ });
260
+ });
261
+ }
262
+ /**
263
+ * Deletes a variable from working memory.
264
+ * @param name - The name of the variable to delete.
265
+ * @returns A promise that resolves to true if successful.
266
+ */
267
+ deleteVariable(name) {
268
+ return new Promise((resolve, reject) => {
269
+ const req = {
270
+ run_id: this.runId,
271
+ name,
272
+ };
273
+ this.client.DeleteVariable(req, this.metadata, (err, response) => {
274
+ if (err)
275
+ reject(err);
276
+ else
277
+ resolve(response.success);
278
+ });
279
+ });
280
+ }
281
+ // ==========================================================================
282
+ // Concepts (Level 4 Agency)
283
+ // ==========================================================================
284
+ /**
285
+ * Defines a concept with a schema.
286
+ * @param name - The name of the concept.
287
+ * @param schema - The schema definition (object or JSON string).
288
+ * @returns A promise that resolves to true if successful.
289
+ */
290
+ defineConcept(name, schema) {
291
+ return new Promise((resolve, reject) => {
292
+ const req = {
293
+ run_id: this.runId,
294
+ name,
295
+ schema_json: typeof schema === "string" ? schema : JSON.stringify(schema),
296
+ };
297
+ this.client.DefineConcept(req, this.metadata, (err, response) => {
298
+ if (err)
299
+ reject(err);
300
+ else
301
+ resolve(response.success);
302
+ });
303
+ });
304
+ }
305
+ /**
306
+ * Lists all defined concepts.
307
+ * @returns A promise that resolves to an array of concepts with their schemas.
308
+ */
309
+ listConcepts() {
310
+ return new Promise((resolve, reject) => {
311
+ const req = {
312
+ run_id: this.runId,
313
+ };
314
+ this.client.ListConcepts(req, this.metadata, (err, response) => {
315
+ if (err)
316
+ reject(err);
317
+ else
318
+ resolve((response.concepts || []).map((c) => ({
319
+ name: c.name,
320
+ schema: JSON.parse(c.schema_json || "{}"),
321
+ })));
322
+ });
323
+ });
324
+ }
325
+ // ==========================================================================
326
+ // Goals
327
+ // ==========================================================================
328
+ /**
329
+ * Adds a new goal.
330
+ * @param description - The description of the goal.
331
+ * @param priority - The priority level ("low", "medium", "high", "critical"). Defaults to "medium".
332
+ * @param parentId - Optional parent goal ID for hierarchical goals.
333
+ * @returns A promise that resolves to the created goal details.
334
+ */
335
+ addGoal(description, priority = "medium", parentId) {
336
+ return new Promise((resolve, reject) => {
337
+ const req = {
338
+ run_id: this.runId,
339
+ description,
340
+ priority,
341
+ parent_id: parentId || "",
342
+ };
343
+ this.client.AddGoal(req, this.metadata, (err, response) => {
344
+ if (err)
345
+ reject(err);
346
+ else
347
+ resolve(response);
348
+ });
349
+ });
350
+ }
351
+ /**
352
+ * Updates a goal's status.
353
+ * @param goalId - The ID of the goal to update.
354
+ * @param status - The new status ("active", "suspended", "achieved", "abandoned", "failed").
355
+ * @returns A promise that resolves to true if successful.
356
+ */
357
+ updateGoal(goalId, status) {
358
+ return new Promise((resolve, reject) => {
359
+ const req = {
360
+ run_id: this.runId,
361
+ goal_id: goalId,
362
+ status,
363
+ };
364
+ this.client.UpdateGoal(req, this.metadata, (err, response) => {
365
+ if (err)
366
+ reject(err);
367
+ else
368
+ resolve(response.success);
369
+ });
370
+ });
371
+ }
372
+ /**
373
+ * Lists all goals, optionally filtered by status.
374
+ * @param statusFilter - Optional status to filter by.
375
+ * @returns A promise that resolves to an array of goals.
376
+ */
377
+ listGoals(statusFilter) {
378
+ return new Promise((resolve, reject) => {
379
+ const req = {
380
+ run_id: this.runId,
381
+ status_filter: statusFilter || "",
382
+ };
383
+ this.client.ListGoals(req, this.metadata, (err, response) => {
384
+ if (err)
385
+ reject(err);
386
+ else
387
+ resolve(response.goals || []);
388
+ });
389
+ });
390
+ }
391
+ // ==========================================================================
392
+ // Actions
393
+ // ==========================================================================
394
+ /**
395
+ * Submits an action for execution.
396
+ * @param agentId - The ID of the agent submitting the action.
397
+ * @param actionType - The type of action ("reason", "retrieve", "learn", "ground").
398
+ * @param actionDetails - The action details (will be JSON-encoded).
399
+ * @returns A promise that resolves to the action result.
400
+ */
401
+ submitAction(agentId, actionType, actionDetails) {
402
+ return new Promise((resolve, reject) => {
403
+ const req = {
404
+ run_id: this.runId,
405
+ agent_id: agentId,
406
+ action_type: actionType,
407
+ action_json: JSON.stringify(actionDetails),
408
+ };
409
+ this.client.SubmitAction(req, this.metadata, (err, response) => {
410
+ if (err)
411
+ reject(err);
412
+ else
413
+ resolve({
414
+ actionId: response.action_id,
415
+ success: response.success,
416
+ result: response.result_json
417
+ ? JSON.parse(response.result_json)
418
+ : null,
419
+ error: response.error,
420
+ durationMs: response.duration_ms,
421
+ });
422
+ });
423
+ });
424
+ }
425
+ /**
426
+ * Gets the action log for the current run.
427
+ * @param limit - Maximum number of entries to retrieve. Defaults to 100.
428
+ * @param actionTypeFilter - Optional action type to filter by.
429
+ * @returns A promise that resolves to an array of action log entries.
430
+ */
431
+ getActionLog(limit = 100, actionTypeFilter) {
432
+ return new Promise((resolve, reject) => {
433
+ const req = {
434
+ run_id: this.runId,
435
+ limit,
436
+ action_type_filter: actionTypeFilter || "",
437
+ };
438
+ this.client.GetActionLog(req, this.metadata, (err, response) => {
439
+ if (err)
440
+ reject(err);
441
+ else
442
+ resolve((response.entries || []).map((e) => ({
443
+ actionId: e.action_id,
444
+ actionType: e.action_type,
445
+ action: e.action_json ? JSON.parse(e.action_json) : null,
446
+ success: e.success,
447
+ result: e.result_json ? JSON.parse(e.result_json) : null,
448
+ cycleNumber: e.cycle_number,
449
+ timestamp: e.timestamp,
450
+ })));
451
+ });
452
+ });
453
+ }
454
+ // ==========================================================================
455
+ // Decision Cycle
456
+ // ==========================================================================
457
+ /**
458
+ * Runs a decision cycle, optionally with pre-proposed action candidates.
459
+ * @param agentId - The ID of the agent running the cycle.
460
+ * @param candidates - Optional array of action candidates with scores and rationales.
461
+ * @returns A promise that resolves to the cycle result.
462
+ */
463
+ runCycle(agentId, candidates) {
464
+ return new Promise((resolve, reject) => {
465
+ const req = {
466
+ run_id: this.runId,
467
+ agent_id: agentId,
468
+ candidates: (candidates || []).map((c) => ({
469
+ action_type: c.actionType,
470
+ action_json: JSON.stringify(c.action),
471
+ score: c.score,
472
+ rationale: c.rationale || "",
473
+ })),
474
+ };
475
+ this.client.RunCycle(req, this.metadata, (err, response) => {
476
+ if (err)
477
+ reject(err);
478
+ else
479
+ resolve({
480
+ cycleNumber: response.cycle_number,
481
+ selectedAction: response.selected_action,
482
+ actionResult: response.action_result,
483
+ planningTimeMs: response.planning_time_ms,
484
+ executionTimeMs: response.execution_time_ms,
485
+ timestamp: response.timestamp,
486
+ });
487
+ });
488
+ });
489
+ }
490
+ /**
491
+ * Gets the decision cycle history for the current run.
492
+ * @param limit - Maximum number of cycles to retrieve. Defaults to 100.
493
+ * @returns A promise that resolves to an array of cycle records.
494
+ */
495
+ getCycleHistory(limit = 100) {
496
+ return new Promise((resolve, reject) => {
497
+ const req = {
498
+ run_id: this.runId,
499
+ limit,
500
+ };
501
+ this.client.GetCycleHistory(req, this.metadata, (err, response) => {
502
+ if (err)
503
+ reject(err);
504
+ else
505
+ resolve(response.cycles || []);
506
+ });
507
+ });
508
+ }
188
509
  }
189
510
  exports.StateClient = StateClient;
@@ -2,20 +2,43 @@ syntax = "proto3";
2
2
  package slate;
3
3
 
4
4
  service Cortex {
5
- // Flux
5
+ // Flux (Legacy Working Memory)
6
6
  rpc Focus(FocusRequest) returns (FocusResponse);
7
7
  rpc Drift(DriftRequest) returns (DriftResponse);
8
8
 
9
- // Echoes
9
+ // Echoes (Episodic Memory)
10
10
  rpc Commit(Trace) returns (Ack);
11
11
  rpc Reminisce(RecallRequest) returns (RecallResponse);
12
12
 
13
- // Nexus
13
+ // Nexus (Semantic Memory)
14
14
  rpc Consult(QueryRequest) returns (KnowledgeResponse);
15
15
 
16
- // Reflex
16
+ // Reflex (Procedural Memory)
17
17
  rpc Trigger(ReflexRequest) returns (ExecutionResult);
18
18
 
19
+ // Working Memory (Structured Variables)
20
+ rpc SetVariable(SetVariableRequest) returns (Ack);
21
+ rpc GetVariable(GetVariableRequest) returns (VariableResponse);
22
+ rpc ListVariables(ListVariablesRequest) returns (ListVariablesResponse);
23
+ rpc DeleteVariable(DeleteVariableRequest) returns (Ack);
24
+
25
+ // Concepts (Level 4 Agency)
26
+ rpc DefineConcept(DefineConceptRequest) returns (Ack);
27
+ rpc ListConcepts(ListConceptsRequest) returns (ListConceptsResponse);
28
+
29
+ // Goals
30
+ rpc AddGoal(AddGoalRequest) returns (GoalResponse);
31
+ rpc UpdateGoal(UpdateGoalRequest) returns (Ack);
32
+ rpc ListGoals(ListGoalsRequest) returns (ListGoalsResponse);
33
+
34
+ // Actions
35
+ rpc SubmitAction(ActionRequest) returns (ActionResponse);
36
+ rpc GetActionLog(ActionLogRequest) returns (ActionLogResponse);
37
+
38
+ // Decision Cycle
39
+ rpc RunCycle(RunCycleRequest) returns (CycleResponse);
40
+ rpc GetCycleHistory(CycleHistoryRequest) returns (CycleHistoryResponse);
41
+
19
42
  // Management
20
43
  rpc DeleteRun(RunRequest) returns (Ack);
21
44
  }
@@ -98,3 +121,174 @@ message ReflexRequest {
98
121
  message ExecutionResult {
99
122
  int32 result = 1;
100
123
  }
124
+
125
+ // =============================================================================
126
+ // Working Memory (Structured Variables)
127
+ // =============================================================================
128
+
129
+ message SetVariableRequest {
130
+ string run_id = 1;
131
+ string name = 2;
132
+ string value_json = 3; // JSON-encoded value
133
+ string source = 4; // "system", "reasoning", "retrieval", "perception", "explicit"
134
+ }
135
+
136
+ message GetVariableRequest {
137
+ string run_id = 1;
138
+ string name = 2;
139
+ }
140
+
141
+ message VariableResponse {
142
+ string name = 1;
143
+ string value_json = 2;
144
+ string var_type = 3;
145
+ string created_at = 4;
146
+ string last_updated = 5;
147
+ uint64 access_count = 6;
148
+ string source = 7;
149
+ }
150
+
151
+ message ListVariablesRequest {
152
+ string run_id = 1;
153
+ }
154
+
155
+ message ListVariablesResponse {
156
+ repeated VariableResponse variables = 1;
157
+ }
158
+
159
+ message DeleteVariableRequest {
160
+ string run_id = 1;
161
+ string name = 2;
162
+ }
163
+
164
+ // =============================================================================
165
+ // Concepts (Level 4 Agency)
166
+ // =============================================================================
167
+
168
+ message DefineConceptRequest {
169
+ string run_id = 1;
170
+ string name = 2;
171
+ string schema_json = 3;
172
+ }
173
+
174
+ message ListConceptsRequest {
175
+ string run_id = 1;
176
+ }
177
+
178
+ message Concept {
179
+ string name = 1;
180
+ string schema_json = 2;
181
+ }
182
+
183
+ message ListConceptsResponse {
184
+ repeated Concept concepts = 1;
185
+ }
186
+
187
+ // =============================================================================
188
+ // Goals
189
+ // =============================================================================
190
+
191
+ message AddGoalRequest {
192
+ string run_id = 1;
193
+ string description = 2;
194
+ string priority = 3; // "low", "medium", "high", "critical"
195
+ string parent_id = 4; // Optional parent goal ID
196
+ }
197
+
198
+ message GoalResponse {
199
+ string id = 1;
200
+ string description = 2;
201
+ string priority = 3;
202
+ string status = 4;
203
+ string parent_id = 5;
204
+ string created_at = 6;
205
+ }
206
+
207
+ message UpdateGoalRequest {
208
+ string run_id = 1;
209
+ string goal_id = 2;
210
+ string status = 3; // "active", "suspended", "achieved", "abandoned", "failed"
211
+ }
212
+
213
+ message ListGoalsRequest {
214
+ string run_id = 1;
215
+ string status_filter = 2; // Optional: filter by status
216
+ }
217
+
218
+ message ListGoalsResponse {
219
+ repeated GoalResponse goals = 1;
220
+ }
221
+
222
+ // =============================================================================
223
+ // Actions
224
+ // =============================================================================
225
+
226
+ message ActionRequest {
227
+ string run_id = 1;
228
+ string agent_id = 2;
229
+ string action_type = 3; // "reason", "retrieve", "learn", "ground"
230
+ string action_json = 4; // JSON-encoded action details
231
+ }
232
+
233
+ message ActionResponse {
234
+ string action_id = 1;
235
+ bool success = 2;
236
+ string result_json = 3;
237
+ string error = 4;
238
+ uint64 duration_ms = 5;
239
+ }
240
+
241
+ message ActionLogRequest {
242
+ string run_id = 1;
243
+ uint64 limit = 2;
244
+ string action_type_filter = 3; // Optional
245
+ }
246
+
247
+ message ActionLogResponse {
248
+ repeated ActionLogEntry entries = 1;
249
+ }
250
+
251
+ message ActionLogEntry {
252
+ string action_id = 1;
253
+ string action_type = 2;
254
+ string action_json = 3;
255
+ bool success = 4;
256
+ string result_json = 5;
257
+ uint64 cycle_number = 6;
258
+ string timestamp = 7;
259
+ }
260
+
261
+ // =============================================================================
262
+ // Decision Cycle
263
+ // =============================================================================
264
+
265
+ message RunCycleRequest {
266
+ string run_id = 1;
267
+ string agent_id = 2;
268
+ repeated ActionCandidate candidates = 3; // Optional: pre-proposed candidates
269
+ }
270
+
271
+ message ActionCandidate {
272
+ string action_type = 1;
273
+ string action_json = 2;
274
+ float score = 3;
275
+ string rationale = 4;
276
+ }
277
+
278
+ message CycleResponse {
279
+ uint64 cycle_number = 1;
280
+ ActionCandidate selected_action = 2;
281
+ ActionResponse action_result = 3;
282
+ uint64 planning_time_ms = 4;
283
+ uint64 execution_time_ms = 5;
284
+ string timestamp = 6;
285
+ }
286
+
287
+ message CycleHistoryRequest {
288
+ string run_id = 1;
289
+ uint64 limit = 2;
290
+ }
291
+
292
+ message CycleHistoryResponse {
293
+ repeated CycleResponse cycles = 1;
294
+ }