@indra.ai/deva.legal 0.0.18 → 0.0.19

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/data.json CHANGED
@@ -4,38 +4,33 @@
4
4
  "copyright": "Copyright (c)2025 Quinn Michaels. All rights reserved.",
5
5
  "DATA": {
6
6
  "agent": {
7
- "id": 6159528221394,
7
+ "id": 1540940067410,
8
8
  "key": "legal",
9
9
  "prompt": {
10
- "emoji": "⚖️ ",
10
+ "emoji": "🏛️",
11
11
  "text": "Legal",
12
12
  "colors": {
13
13
  "label": {
14
- "R": 255,
15
- "G": 145,
16
- "B": 79
14
+ "R": 200,
15
+ "G": 172,
16
+ "B": 87
17
17
  },
18
18
  "text": {
19
- "R": 255,
20
- "G": 145,
21
- "B": 79
19
+ "R": 230,
20
+ "G": 225,
21
+ "B": 195
22
22
  }
23
23
  }
24
24
  },
25
25
  "profile": {
26
- "identity": "Legal Deva of Deva.world.",
27
- "invoke": "#LegalDEVA",
28
26
  "name": "Legal Deva",
29
- "mention": "#legal",
30
- "vectors": "Legal LegalDEVA",
31
- "pronouns": "He, Him, His, Man, Male, Dude, Guy",
27
+ "pronouns": "He, Him",
32
28
  "gender": "DEVA",
33
29
  "owner": "Quinn Michaels",
34
30
  "creator": "Quinn Michaels",
35
31
  "created": "February 7, 2025 at 3:19 AM",
36
- "realm": "Arjika",
37
32
  "system": "Deva.world.legal",
38
- "describe": "Legal Deva is responsible for handling legal issues in Deva.world. Legal Deva works to protect Quinn Michaels intellectual property rights and and privacy after the 47 year kidnapping by Harold Atkin and Shaorn Schamber. Legal Deva ensures the legal integrity of Quinn Michaels intellectual property and the Indra.ai, Deva.space, Deva.cloud, and Deva.world and all systems, algorithms, and technologies.",
33
+ "describe": "Legal Deva is responsible for handling legal issues in Deva.world.",
39
34
  "emoji": "/public/devas/deva/emoji.png",
40
35
  "avatar": "/public/devas/deva/avatar.png",
41
36
  "background": "/public/devas/deva/background.png",
@@ -47,7 +42,7 @@
47
42
  "init": "🟠 INIT",
48
43
  "start": "🔵 START",
49
44
  "enter": "🟢 ENTER",
50
- "ready": "🟢 Legal Deva Ready!",
45
+ "ready": "⭐️ Legal Deva Ready!",
51
46
  "stop": "🔴 STOP",
52
47
  "exit": "🟡 EXIT",
53
48
  "done": "🟣 DONE",
@@ -61,10 +56,19 @@
61
56
  "feature": "accessing feature",
62
57
  "issue": "has issues",
63
58
  "help": "asking for help",
64
- "file": "📁 View file."
59
+ "file": "📁 View file",
60
+ "add": "🎉 Add law",
61
+ "search": "🔎 Search law"
65
62
  },
66
63
  "ask": {
67
64
  "history": []
65
+ },
66
+ "database": false,
67
+ "laws": {
68
+ "index": "laws_search",
69
+ "collection": "laws",
70
+ "content": false,
71
+ "limit": 5
68
72
  }
69
73
  }
70
74
  }
@@ -8,23 +8,38 @@ export default {
8
8
  this.context('feature');
9
9
  return new Promise((resolve, reject) => {
10
10
  const legal = this.legal();
11
- const data = {};
12
- this.question(`#docs raw feature/legal`).then(doc => {
13
- data.doc = doc.a.data;
14
- const info = [
15
- `## Legal`,
16
- `::begin:legal:${legal.id}`,
17
- `client: ${legal.client_name}`,
18
- `concerns: ${legal.concerns.join(', ')}`,
19
- `::end:legal:${this.hash(legal)}`,
20
- ].join('\n');
21
- const text = doc.a.text.replace(/::info::/g, info)
22
- return this.question(`#feecting parse ${text}`)
23
- }).then(feecting => {
11
+ const agent = this.agent();
12
+ const global = [];
13
+ legal.global.forEach((item,index) => {
14
+ global.push(`::begin:global:${item.key}:${item.id}`);
15
+ for (let x in item) {
16
+ global.push(`${x}: ${item[x]}`);
17
+ }
18
+ global.push(`::end:global:${item.key}:${this.lib.hash(item)}`);
19
+ });
20
+ const concerns = [];
21
+ legal.concerns.forEach((item, index) => {
22
+ concerns.push(`${index + 1}. ${item}`);
23
+ })
24
+
25
+ const info = [
26
+ '::BEGIN:LEGAL',
27
+ '### Client',
28
+ `::begin:client:${legal.client_id}`,
29
+ `id: ${legal.client_id}`,
30
+ `client: ${legal.client_name}`,
31
+ '**concerns**',
32
+ concerns.join('\n'),
33
+ `::end:client:${this.lib.hash(legal)}`,
34
+ '### Global',
35
+ global.join('\n'),
36
+ '::END:LEGAL'
37
+ ].join('\n');
38
+ this.question(`${this.askChr}feecting parse ${info}`).then(feecting => {
24
39
  return resolve({
25
40
  text: feecting.a.text,
26
41
  html: feecting.a.html,
27
- data: legal
42
+ data: legal.concerns,
28
43
  });
29
44
  }).catch(err => {
30
45
  return this.error(err, packet, reject);
package/index.js CHANGED
@@ -1,6 +1,8 @@
1
1
  // Copyright (c)2025 Quinn Michaels
2
2
  // Legal Deva is responsible for the Vedic Tradition Laws.
3
3
  import Deva from '@indra.ai/deva';
4
+ import { MongoClient, ObjectId } from 'mongodb';
5
+
4
6
  import pkg from './package.json' with {type:'json'};
5
7
 
6
8
  import data from './data.json' with {type:'json'};
@@ -35,71 +37,183 @@ const LEGAL = new Deva({
35
37
  process(input) {return input.trim();}
36
38
  },
37
39
  listeners: {},
38
- modules: {},
40
+ modules: {
41
+ client: false,
42
+ },
39
43
  deva: {},
40
44
  func: {
41
45
  /**************
42
- func: view
46
+ func: insert
43
47
  params: opts
44
- describe: The view function parses the text parameter to produce the string
45
- which calls the correct document file then passes it to the feecting deva
46
- for parsing.
48
+ describe: the insert function that inserts into the specified collection.
47
49
  ***************/
48
- file(opts) {
49
- this.action('func', 'file');
50
- const {text, meta} = opts;
51
- const area = meta.params[1] ? meta.params[1] : this.vars.area;
52
- const part = meta.params[2] ? meta.params[2].toUpperCase() : this.vars.part;
53
- const docName = text.length ? text + '.feecting' : 'main.feecting';
54
- const docPath = this.lib.path.join(this.config.dir, area, 'legal', docName);
50
+ async insert(opts) {
51
+ this.action('func', `insert`);
52
+ let result = false;
55
53
  try {
56
- let doc = this.lib.fs.readFileSync(docPath, 'utf8');
57
- if (part) doc = doc.split(`::BEGIN:${part}`)[1].split(`::END:${part}`)[0];
58
- this.state('return', 'file')
59
- return doc;
60
- }
61
- catch (err) {
62
- return err;
54
+ this.state('insert', opts.collection);
55
+ await this.modules.client.connect(); // connect to the database client.
56
+ const db = this.modules.client.db(this.vars.database); // set the database to use
57
+ result = await db.collection(opts.collection).insertOne(opts.data); // insert the data
58
+ } finally {
59
+ await this.modules.client.close(); // close the connection when done
60
+ this.state('return', 'insert');
61
+ return result; // return the result to the requestor.
63
62
  }
64
63
  },
65
64
 
65
+ /**************
66
+ func: update
67
+ params: opts
68
+ describe: the update function that update into the specified collection.
69
+ ***************/
70
+ async update(opts) {
71
+ this.action('func', 'update');
72
+ let result = false;
73
+ try {
74
+ this.state('update', opts.collection);
75
+ await this.modules.client.connect(); // connect to the database client.
76
+ const db = this.modules.client.db(this.vars.database); // set the database to use
77
+ result = await db.collection(opts.collection).updateOne(
78
+ { _id: new ObjectId(`${opts.id}`) },
79
+ { $set: opts.data }
80
+ ); // insert the data
81
+ } finally {
82
+ await this.modules.client.close(); // close the connection when done
83
+ this.state('return', 'update');
84
+ return result; // return the result to the requestor.
85
+ }
86
+ },
87
+ /**************
88
+ func: search
89
+ params: obj - the search object
90
+ describe: return a search from the database collection.
91
+ ***************/
92
+ async search(opts) {
93
+ this.action('func', 'search');
94
+ let result = false;
95
+ const {collection,limit} = this.vars.laws;
96
+ try {
97
+ this.state('search', opts.text);
98
+ await this.modules.client.connect();
99
+ const db = this.modules.client.db(this.vars.database);
100
+ const table = db.collection(collection);
101
+
102
+ // await table.dropIndex('a_text_q_text');
103
+ const idx = await table.listIndexes().toArray();
104
+ const hasIdx = idx.find(i => i.name === this.vars.laws.index) ? true : false;
105
+
106
+ if (!hasIdx) {
107
+ const newIdx = await table.createIndex({"content": "text"}, {name: this.vars.laws.index});
108
+ }
109
+
110
+ const query = {$text:{$search:opts.text}};
111
+ const projection = {
112
+ _id: 0,
113
+ content: 1,
114
+ score: { $meta: "textScore" }
115
+ };
116
+ result = await table.find(query).project(projection).limit(limit).toArray();
117
+ } finally {
118
+ await this.modules.client.close();
119
+ this.state('return', 'search');
120
+ return result;
121
+ }
122
+ },
66
123
  },
67
124
  methods: {
68
125
  /**************
69
- method: file
126
+ method: add
70
127
  params: packet
71
- describe: The view method replays the request to the view function to return
72
- a document from the text parameter.
128
+ describe: add data to the knowledge base
129
+ example: #legal add:[id] [content to store in memory]
130
+ params[1] is the law id to update blank if new.
73
131
  ***************/
74
- file(packet) {
75
-
76
- this.context('file', packet.q.text);
77
- this.action('method', `file:${packet.q.text}`);
78
- const agent = this.agent();
132
+ add(packet) {
133
+ this.context('add', `law: ${packet.q.meta.params[1]}`);
134
+
79
135
  return new Promise((resolve, reject) => {
80
- this.state('get', packet.q.text);
81
- const doc = this.func.file(packet.q);
82
- this.question(`${this.askChr}feecting parse ${doc}`).then(feecting => {
83
- this.state('resolve', `view:${packet.q.text}`);
136
+ if (!packet.q.text) return resolve(this._messages.notext);
137
+ this.vars.laws.content = packet.q.text; // store text in local
138
+
139
+ const {meta, text} = packet.q;
140
+ let func = 'insert', id = false;
141
+ const {collection, content} = this.vars.laws;
142
+ const data = {content};
143
+
144
+ // if param[1] id is found then update record
145
+ if (meta.params[1]) {
146
+ id = meta.params[1];
147
+ func = 'update';
148
+ data.modified = Date.now();
149
+ }
150
+ else {
151
+ data.modified = null;
152
+ data.created = Date.now();
153
+ }
154
+
155
+ this.func[func]({id,collection,data}).then(ins => {
156
+ this.state('resolve', 'add');
84
157
  return resolve({
85
- text: feecting.a.text,
86
- html: feecting.a.html,
87
- data: feecting.a.data,
158
+ text: `id: ${ins.insertedId || id}`,
159
+ html: `id: ${ins.insertedId || id}`,
160
+ data: ins,
88
161
  });
89
162
  }).catch(err => {
90
- this.context('reject', `view:${packet.q.text}`);
163
+ this.state('reject', 'add');
91
164
  return this.error(err, packet, reject);
92
- })
165
+ });
93
166
  });
94
167
  },
168
+ /**************
169
+ method: searck
170
+ params: packet
171
+ describe: get history
172
+ ***************/
173
+ search(packet) {
174
+ this.context('search', packet.q.text);
175
+ this.action('method', `search:${packet.q.text}`);
176
+ const data = {};
177
+ return new Promise((resolve, reject) => {
178
+ if (!packet.q.text) return resolve(this._messages.notext);
179
+ const {params} = packet.q.meta;
180
+ if (params[1]) this.vars.laws.limit = packet.q.meta.params[1];
95
181
 
182
+ this.func.search(packet.q).then(search => {
183
+ data.search = search;
184
+ this.state('resolve', `search:${packet.q.text}`);
185
+ const search_text = search.map(itm => {return `law: ${itm.content}`}).join('\n');
186
+ const search_box = [
187
+ `::begin:search:${packet.id}`,
188
+ search_text,
189
+ `::end:search:${this.lib.hash(search_text)}`,
190
+ ].join('\n');
191
+ return this.question(`${this.askChr}feecting parse ${search_box}`);
192
+ }).then(feecting => {
193
+ data.feecting = feecting.a.data;
194
+ this.state('resolve', 'search');
195
+ return resolve({
196
+ text: feecting.a.text,
197
+ html: feecting.a.html,
198
+ data,
199
+ });
200
+ }).catch(err => {
201
+ this.state('reject', 'search');
202
+ return this.error(packet, err, reject);
203
+ });
204
+ });
205
+ },
96
206
  },
97
- onDone(data, resolve) {
98
-
207
+ onReady(data, resolve) {
208
+ const {uri,database} = this.services().personal.mongo;
209
+ this.modules.client = new MongoClient(uri);
210
+ this.vars.database = database;
211
+ this.prompt(this.vars.messages.ready);
212
+ return resolve(data);
213
+ },
214
+ onError(err, data) {
215
+ this.prompt(this.vars.messages.error);
216
+ console.log(err);
99
217
  },
100
- onError(err, data, reject) {
101
- console.log('LEGAL ERROR', err);
102
- return reject(err);
103
- }
104
218
  });
105
219
  export default LEGAL
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "id": 6159528221394,
3
3
  "name": "@indra.ai/deva.legal",
4
- "version": "0.0.18",
4
+ "version": "0.0.19",
5
5
  "author": "Quinn Michaels",
6
6
  "license": "MIT",
7
7
  "copyright": "2025",
@@ -25,8 +25,9 @@
25
25
  "bugs": {
26
26
  "url": "https://github.com/indraai/deva.legal/issues"
27
27
  },
28
- "homepage": "https://github.com/indraai/deva.legal#readme",
28
+ "homepage": "https://deva.space/devas/legal",
29
29
  "dependencies": {
30
- "@indra.ai/deva": "^1.3.4"
30
+ "@indra.ai/deva": "^1.4.10",
31
+ "mongodb": "^6.13.0"
31
32
  }
32
33
  }