@indra.ai/deva.data 0.0.21 → 0.0.23

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.
@@ -1,10 +1,34 @@
1
- # ::agent_name::
1
+ # {{profile.name}}
2
2
 
3
- ::agent_profile::
3
+ {{profile}}
4
4
 
5
+ ---
6
+
7
+ ## Func
8
+
9
+ ### Insert
10
+ opts: takes in the id, collection, and data for the insert
11
+ 1. opts.id is the id for the packet
12
+ 2. opts.collection is the collection that the opts.data will insert
13
+ 3. opts.data is the object that holds the data structure to insert.
14
+
15
+ ### Update
16
+ opts: taks in the id, collection, and data to update in the collection.
17
+ 1. opts.id is the id of the item to update.
18
+ 2. opts.collection is the collection to update.
19
+ 3. opts.data is the data object to update in the colletion.
20
+
21
+ ### List
22
+ opts: The object to filter the collection for data sorted by created.
23
+ 1. opts.collection is the collection to list items from.
24
+ 2. opts.data is the filtering object which includes the limit.
25
+
26
+ ### Search
27
+
28
+ opts:
5
29
  ::begin:hidden
6
- #color = ::agent_color::
7
- #bgcolor = ::agent_bgcolor::
8
- #bg = ::agent_background::
30
+ #color = {{profile.color}}
31
+ #bgcolor = {{profile.bgcolor}}
32
+ #bg = {{profile.background}}
9
33
  ::end:hidden
10
34
  copyright: ©2025 Quinn Michaels
package/index.js CHANGED
@@ -34,12 +34,13 @@ const DATA = new Deva({
34
34
  parse(input) {return input.trim();},
35
35
  process(input) {return input.trim();},
36
36
  memory(input) {
37
- return input.replace(/\n/g, ' ')
38
- .replace(/(\b)or have specific questions about it(\b)/g, '$2')
39
- .replace(/(\b), feel free to ask(\b)/g, '$2')
40
- .replace(/\sIf you have .+ free share!/g, '')
41
- .replace(/\sIf there are .+ free share!/g, '')
42
- .replace(/\s{2,}/g, ' ');
37
+ input = input.replace(/\n/g, ' ')
38
+ .replace(/(\b)or have specific questions about it(\b)/g, '$2')
39
+ .replace(/(\b), feel free to ask(\b)/g, '$2')
40
+ .replace(/\sIf you have .+ free share!/g, '')
41
+ .replace(/\sIf there are .+ free share!/g, '')
42
+ .replace(/\s{2,}/g, ' ');
43
+ return input;
43
44
  }
44
45
  },
45
46
  listeners: {
@@ -52,23 +53,18 @@ const DATA = new Deva({
52
53
  });
53
54
  },
54
55
  async 'data:memory'(packet) {
55
- const datamem = await this.func.insert({
56
+ const data = {
57
+ id: packet.id,
58
+ client: packet.client.id,
59
+ agent: packet.agent.id,
60
+ q: this.utils.memory(packet.q),
61
+ a: this.utils.memory(packet.a),
62
+ created: Date.now(),
63
+ }
64
+ data.hash = this.lib.hash(data);
65
+ await this.func.insert({
56
66
  collection: `memory_${packet.agent.key}`,
57
- data: {
58
- id: packet.id,
59
- client: {
60
- id: packet.client.id,
61
- name: packet.client.profile.name,
62
- },
63
- agent: {
64
- id: packet.agent.id,
65
- key: packet.agent.key,
66
- name: packet.agent.profile.name,
67
- },
68
- q: this.utils.memory(packet.q),
69
- a: this.utils.memory(packet.a),
70
- created: Date.now(),
71
- }
67
+ data,
72
68
  });
73
69
  }
74
70
  },
@@ -83,7 +79,7 @@ const DATA = new Deva({
83
79
  describe: the insert function that inserts into the specified collection.
84
80
  ***************/
85
81
  async insert(opts) {
86
- this.action('func', `insert ${opts.collection}`);
82
+ this.action('func', `insert:${opts.collection}:${opts.id}`);
87
83
  let result = false;
88
84
  try {
89
85
  this.state('insert', opts.collection);
@@ -93,7 +89,7 @@ const DATA = new Deva({
93
89
  result = await db.collection(opts.collection).insertOne(opts.data); // insert the data
94
90
  } finally {
95
91
  await this.modules.client.close(); // close the connection when done
96
- this.action('return', `insert ${opts.collection}`);
92
+ this.action('return', `insert:${opts.collection}:${opts.id}`);
97
93
  return result; // return the result to the requestor.
98
94
  }
99
95
  },
@@ -127,10 +123,10 @@ const DATA = new Deva({
127
123
  params: obj - the find object
128
124
  describe: return a find from the database collection.
129
125
  ***************/
130
- async list(obj={}) {
126
+ async list(opts={}) {
131
127
  this.action('func', 'list');
132
128
  let result = false;
133
- const {collection,data} = obj;
129
+ const {collection,data} = opts;
134
130
  try {
135
131
  const {database} = this.services().personal.mongo;
136
132
  await this.modules.client.connect();
@@ -166,7 +162,7 @@ const DATA = new Deva({
166
162
 
167
163
  const query = {$text:{$search:opts.text}};
168
164
  const projection = {
169
- _id:0,
165
+ _id: 0,
170
166
  a: {
171
167
  id: 1,
172
168
  text: 1
@@ -479,16 +475,19 @@ const DATA = new Deva({
479
475
  example: #data mem:[id] [content to store in memory]
480
476
  ***************/
481
477
  know(packet) {
482
- this.context('know', `text: ${packet.q.meta.params[1]}`);
478
+ this.context('know', packet.id);
483
479
 
484
480
  return new Promise((resolve, reject) => {
485
481
  if (!packet.q.text) return resolve(this._messages.notext);
486
- this.vars.knowledge.content = packet.q.text; // store text in local
487
482
 
488
483
  const {meta, text} = packet.q;
489
- let func = 'insert', id = false;
490
- const {collection, content} = this.vars.knowledge;
491
- const data = {content};
484
+ const {collection} = this.vars.knowledge;
485
+ const data = {
486
+ id: packet.id,
487
+ content: packet.q.text,
488
+ };
489
+ let id = false,
490
+ func = 'insert';
492
491
 
493
492
  // if param[1] id is found then update record
494
493
  if (meta.params[1]) {
@@ -506,7 +505,7 @@ const DATA = new Deva({
506
505
  return resolve({
507
506
  text: `id: ${ins.insertedId || id}`,
508
507
  html: `id: ${ins.insertedId || id}`,
509
- data: ins,
508
+ data: ins.insertedId,
510
509
  });
511
510
  }).catch(err => {
512
511
  this.state('reject', 'add');
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "id": 4825562571950,
3
3
  "name": "@indra.ai/deva.data",
4
- "version": "0.0.21",
4
+ "version": "0.0.23",
5
5
  "author": "Quinn Michaels",
6
6
  "license": "MIT",
7
7
  "copyright": "2025",
@@ -123,13 +123,13 @@
123
123
  "knowledge": {
124
124
  "collection": "knowledge",
125
125
  "limit": 3,
126
- "content": false,
127
126
  "index": "knowledge_text"
128
127
  },
129
128
  "memory": {
130
129
  "collection": "memory",
131
130
  "limit": 3,
132
- "content": false
131
+ "content": false,
132
+ "index": "a_q_text"
133
133
  },
134
134
  "archive": {
135
135
  "collection": "archive",