@indra.ai/deva.services 0.0.4 → 0.0.6

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.
Files changed (2) hide show
  1. package/feature/methods.js +11 -491
  2. package/package.json +5 -4
@@ -7,7 +7,7 @@ function buildProfile(profile, type='assistant') {
7
7
  _profile.push(`::end:${type}\n`);
8
8
  return _profile.join('\n');
9
9
  }
10
- module.exports = {
10
+ export default {
11
11
  /**************
12
12
  method: service
13
13
  params: packet
@@ -21,7 +21,6 @@ module.exports = {
21
21
  this.question(`#docs raw feature/services`).then(doc => {
22
22
  data.doc = doc.a.data;
23
23
  const info = [
24
- `## Settings`,
25
24
  `::begin:services:${services.id}`,
26
25
  `client: ${services.client_name}`,
27
26
  `concerns: ${services.concerns.join(', ')}`,
@@ -40,55 +39,6 @@ module.exports = {
40
39
  })
41
40
  });
42
41
  },
43
- comment(packet) {
44
- return new Promise((resolve, reject) => {
45
- if (!this.vars.comment) return resolve('NO COMMENT');
46
- const agent = this.agent();
47
- const profile = buildProfile(agent.profile);
48
- const data = {};
49
- const text = [];
50
-
51
- const msg = [
52
- `${packet.q.text}`,
53
- `important: Respond in ${this.vars.comment.words} words or less.`,
54
- ].join('\n');
55
-
56
- this.question(`${this.askChr}docs view devas/${agent.key}:corpus`).then(corpus => {
57
- data.corpus = corpus.a.data;
58
-
59
- return this.question(`${this.askChr}open relay ${msg}`, {
60
- model: agent.model || false,
61
- profile,
62
- corpus: corpus.a.text,
63
- max_tokens: this.vars.comment.max_tokens,
64
- history: this.vars.comment.history.slice(-10),
65
- });
66
- }).then(chat => {
67
- data.chat = chat.a.data.chat;
68
- text.push(chat.a.data.parsed);
69
- this.vars.comment.history.push({
70
- role: chat.a.data.chat.role,
71
- content: chat.a.data.chat.text,
72
- });
73
- return this.question(`${this.askChr}youtube commentWrite:${this.vars.comment.profile} ${chat.a.text}`);
74
- }).then(youtube => {
75
- data.youtube = youtube.a.data;
76
- text.push(youtube.a.text);
77
-
78
- return this.question(`${this.askChr}feecting parse ${text.join('\n')}`);
79
- }).then(feecting => {
80
- return resolve({
81
- text: feecting.a.text,
82
- html: feecting.a.html,
83
- data,
84
- });
85
- }).catch(err => {
86
- console.log('THERE WAS AN ERROR', err);
87
- return this.error(packet, err, reject);
88
- });
89
- });
90
- },
91
-
92
42
  /**************
93
43
  method: ask
94
44
  params: packet
@@ -105,7 +55,7 @@ module.exports = {
105
55
  const agent = this.agent();
106
56
  const client = this.client();
107
57
  const info = this.info();
108
-
58
+
109
59
  this.state('set', 'message');
110
60
  const msg = [
111
61
  `::begin:user:${client.id}`,
@@ -116,7 +66,7 @@ module.exports = {
116
66
  `::end:user`,
117
67
  packet.q.text,
118
68
  ].join('\n');
119
-
69
+
120
70
  // get the agent main help file for teir corpus.
121
71
  this.state('get', 'ask:help');
122
72
  this.help('main', info.dir).then(corpus => {
@@ -135,17 +85,11 @@ module.exports = {
135
85
  askAgent,
136
86
  });
137
87
  }).then(chat => {
138
-
88
+
139
89
  text.push(`::begin:${agent.key}:${chat.id}`);
140
90
  text.push(chat.a.data.parsed);
141
- if (chat.a.text) {
142
- text.push('::begin:buttons');
143
- text.push(`button[🗣️ Speak]:${this.askChr}${agent.key} speak ${encodeURI(chat.a.text)}`);
144
- text.push(`button[🎨 Art]:${this.askChr}${agent.key} art ${encodeURI(chat.a.text)}`);
145
- text.push('::end:buttons');
146
- }
147
91
  text.push(`::end:${agent.key}:${chat.hash}`);
148
-
92
+
149
93
  // memory event
150
94
  this.talk('data:memory', {
151
95
  id: chat.a.data.chat.id,
@@ -155,22 +99,21 @@ module.exports = {
155
99
  a: chat.a.data.chat.text,
156
100
  created: Date.now(),
157
101
  });
158
-
159
-
160
- data.chat = chat.a.data.chat;
161
-
102
+
103
+
104
+ data.chat = chat.a.data.chat;
162
105
  this.state('set', 'ask:history');
163
-
106
+
164
107
  this.vars.ask.history.push({
165
108
  role: 'user',
166
109
  content: this.trimWords(chat.q.text, 100),
167
110
  });
168
-
111
+
169
112
  this.vars.ask.history.push({
170
113
  role: chat.a.data.chat.role,
171
114
  content: this.trimWords(chat.a.data.chat.text, 100),
172
115
  });
173
-
116
+
174
117
  this.state('parse', 'ask:chat');
175
118
  return this.question(`${this.askChr}feecting parse ${text.join('\n')}`);
176
119
  }).then(feecting => {
@@ -187,427 +130,4 @@ module.exports = {
187
130
  });
188
131
  });
189
132
  },
190
-
191
- live(packet) {
192
- return new Promise((resolve, reject) => {
193
- if (!this.vars.live) return resolve('NO LIVE');
194
-
195
- const agent = this.agent();
196
- const client = this.client();
197
- const info = this.info();
198
- const profile = buildProfile(agent.profile);
199
- const data = {};
200
- let text, corpus;
201
-
202
- this.state('get', 'live:help');
203
-
204
- this.help('main', info.dir).then(help => {
205
- this.action('parse', 'ask:help');
206
- return this.question(`${this.askChr}feecting parse ${help}`);
207
-
208
- }).then(doc => {
209
- data.corpus = doc.a.data;
210
- corpus = doc.a.text;
211
-
212
- this.state('set', 'chat message');
213
- const msg = [
214
- packet.q.text,
215
- `important: Youtube chat has strict requirements, so please respond in ${this.vars.live.words} words or less.`,
216
- ].join('\n');
217
-
218
- this.action('get', 'open relay');
219
-
220
- return this.question(`${this.askChr}open relay ${msg}`, {
221
- model: agent.model || false,
222
- profile,
223
- corpus,
224
- max_tokens: this.vars.live.max_tokens,
225
- history: this.vars.live.history.slice(-10),
226
- });
227
-
228
- }).then(chat => {
229
- console.log('CHAT RESPONSE... ', JSON.stringify(chat, null, 2));
230
- this.state('set', 'chat data');
231
- data.chat = chat.a.data.chat;
232
- text = chat.a.data.parsed;
233
-
234
- this.action('talk', 'data:memory');
235
- // memory event
236
- this.talk('data:memory', {
237
- id: chat.a.data.chat.id,
238
- client,
239
- agent,
240
- q: packet.q.text,
241
- a: chat.a.data.chat.text,
242
- created: Date.now(),
243
- });
244
-
245
- this.state('set', 'history:user');
246
- this.vars.live.history.push({
247
- role: 'user',
248
- content: chat.q.text,
249
- });
250
-
251
- this.state('set', `history:${chat.a.data.chat.role}`);
252
- this.vars.live.history.push({
253
- role: chat.a.data.chat.role,
254
- content: chat.a.data.chat.text,
255
- });
256
-
257
- this.action('send', `chat:${this.vars.live.profile}`);
258
- return this.question(`${this.askChr}youtube chat:${this.vars.live.profile} ${chat.a.text.substr(0, 199)}`);
259
-
260
- }).then(youtube => {
261
- data.youtube = youtube.a.data;
262
- this.action('parse', 'Youtube response');
263
- return this.question(`${this.askChr}feecting parse ${text}`);
264
-
265
- }).then(feecting => {
266
- this.state('resolve', 'live');
267
- return resolve({
268
- text: feecting.a.text,
269
- html: feecting.a.html,
270
- data,
271
- });
272
-
273
- }).catch(err => {
274
- this.state('reject', 'live');
275
- console.log('LIVE ERROR', err);
276
- return this.error(packet, err, reject);
277
- });
278
- });
279
- },
280
- /**************
281
- method: livechat
282
- params: packet
283
- describe: Get the latest chats from a youtube stream and chat about it.
284
- ***************/
285
- livechat(packet) {
286
- return new Promise((resolve, reject) => {
287
- if (!this.vars.live) return resolve('NO LIVE');
288
- const data = {};
289
- this.action('get', 'Youtube chats');
290
- this.question(`${this.askChr}youtube chats:${this.vars.live.max_chats}:${this.vars.live.page_token}`).then(chats => {
291
-
292
- data.chats = chats.a.data;
293
- this.vars.live.page_token = chats.a.data.messages.nextPageToken;
294
- this.state('set', 'chat items');
295
-
296
- const hasItems = chats.a.data.messages.items.length ? true : false;
297
- const items = chats.a.data.messages.items.map(item => {
298
- return `@${item.authorDetails.displayName}: ${item.snippet.displayMessage}`;
299
- }).join('\n');
300
-
301
- this.state('set', 'chat message');
302
- const msg = ['::begin:chats'];
303
- if (hasItems) {
304
- msg.push(items);
305
- }
306
- msg.push(`${packet.q.client.profile.name}: ${packet.q.text}`);
307
- msg.push('::end:chats');
308
-
309
- this.action('get', 'open relay');
310
-
311
- return this.methods.live(packet);
312
- }).then(chat => {
313
- this.state('resolve', 'live');
314
- return resolve({
315
- text: chat.text,
316
- html: chat.html,
317
- data: chat.data,
318
- });
319
- }).catch(err => {
320
- this.state('reject', 'livechats');
321
- console.log('LIVEchats ERROR', err);
322
- return this.error(packet, err, reject);
323
- });
324
- });
325
- },
326
-
327
- /**************
328
- method: doc
329
- params: packet
330
- describe: send a doc to the deva.
331
- ***************/
332
- docs(packet) {
333
- this.action('feature', 'docs');
334
- return new Promise((resolve, reject) => {
335
-
336
- const data = {};
337
- const agent = this.agent();
338
- const profile = buildProfile(agent.profile, 'assistant');
339
- const client = this.client();
340
- const user = buildProfile(client.profile, 'user');
341
- const info = this.info();
342
- let corpus = false;
343
-
344
- this.state('set', 'docs:text');
345
- const text = [];
346
-
347
- this.state('get', 'docs:help');
348
- this.help('main', info.dir).then(corpus => {
349
- this.action('parse', 'docs:corpus');
350
- return this.question(`${this.askChr}feecting parse ${corpus}`);
351
-
352
- }).then(_corpus => {
353
- corpus = _corpus.a.text;
354
- data.corpus = _corpus.a.data;
355
- this.state('get', 'docs:document');
356
- return this.question(`${this.askChr}docs view ${packet.q.text}`);
357
-
358
- }).then(doc => {
359
- data.doc = doc.a.data;
360
- text.push(`::begin:document:${doc.id}`);
361
- text.push(doc.a.text);
362
- text.push(`::end:document:${this.hash(doc.a.text)}`);
363
-
364
- return this.question(`${this.askChr}open relay ${text.join('\n')}`, {
365
- model: agent.model || false,
366
- corpus,
367
- profile,
368
- user,
369
- max_tokens: this.vars.ask.max_tokens,
370
- history: this.vars.ask.history.slice(-10),
371
- memory: agent.key,
372
- askAgent: false,
373
- });
374
-
375
- }).then(chat => {
376
- data.chat = chat.a.data;
377
- this.state('parse', 'docs:chat');
378
-
379
- const msg = [
380
- chat.a.data.parsed,
381
- '::begin:buttons',
382
- `button[🗣️ Speak]:${this.askChr}${agent.key} speak ${encodeURI(chat.a.text)}`,
383
- `button[🎨 Art]:${this.askChr}${agent.key} art ${encodeURI(chat.a.text)}`,
384
- '::end:buttons',
385
- ].join('\n');
386
-
387
- return this.question(`${this.askChr}feecting parse ${msg}`);
388
- }).then(feecting => {
389
- data.feecting = feecting.a.data;
390
- this.state('resolve', 'docs');
391
- return resolve({
392
- text: feecting.a.text,
393
- html: feecting.a.html,
394
- data,
395
- });
396
-
397
- }).catch(err => {
398
- this.state('reject', 'docs');
399
- console.log('DOCS feature ERROR', err);
400
- return this.error(err, packet, reject);
401
- });
402
- });
403
- },
404
-
405
- /**************
406
- method: veda
407
- params: packet
408
- describe: send a veda hymn to the deva.
409
- ***************/
410
- veda(packet) {
411
- this.action('feature', 'hymn');
412
- return new Promise((resolve, reject) => {
413
-
414
- const data = {};
415
- const agent = this.agent();
416
- const profile = buildProfile(agent.profile, 'assistant');
417
- const client = this.client();
418
- const user = buildProfile(client.profile, 'user');
419
- const info = this.info();
420
- let corpus = false;
421
-
422
- this.state('get', 'agent:help');
423
- this.help('main', info.dir).then(corpus => {
424
- this.action('parse', 'docs:corpus');
425
- return this.question(`${this.askChr}feecting parse ${corpus}`);
426
- }).then(_corpus => {
427
- corpus = _corpus.a.text;
428
- data.corpus = _corpus.a.data;
429
- this.state('get', 'veda:hymn');
430
- return this.question(`${this.askChr}veda hymn ${packet.q.meta.params[1]}`);
431
- }).then(hymn => {
432
- data.hymn = hymn.a.data;
433
- const text = [
434
- hymn.a.text,
435
- `---`,
436
- `note: ${packet.q.text}`,
437
- ].join('\n');
438
- return this.question(`${this.askChr}open relay ${text}`, {
439
- model: agent.model || false,
440
- corpus,
441
- profile,
442
- user,
443
- max_tokens: this.vars.ask.max_tokens,
444
- history: this.vars.ask.history.slice(-10),
445
- memory: agent.key,
446
- askAgent: false,
447
- });
448
- }).then(chat => {
449
- data.chat = chat.a.data;
450
- this.state('parse', 'hymn:chat');
451
- const msg = [
452
- chat.a.data.parsed,
453
- '::begin:buttons',
454
- `button[🗣️ Speak]:${this.askChr}${agent.key} speak ${encodeURI(chat.a.text)}`,
455
- `button[🎨 Art]:${this.askChr}${agent.key} art ${encodeURI(chat.a.text)}`,
456
- '::end:buttons',
457
- ].join('\n');
458
- return this.question(`${this.askChr}feecting parse ${msg}`);
459
- }).then(feecting => {
460
- data.feecting = feecting.a.data;
461
- this.state('resolve', 'hymn');
462
- return resolve({
463
- text: feecting.a.text,
464
- html: feecting.a.html,
465
- data,
466
- });
467
- }).catch(err => {
468
- this.state('reject', 'hymn');
469
- console.log('HYMN feature ERROR', err);
470
- return this.error(err, packet, reject);
471
- });
472
- });
473
- },
474
-
475
-
476
- /**************
477
- method: speak
478
- params: packet
479
- describe: have the agent say a message
480
- ***************/
481
- speak(packet) {
482
- return new Promise((resolve, reject) => {
483
- if (!packet.q.text) return resolve(this._messages.notext);
484
- this.action('feature', 'speak');
485
- const agent = this.agent();
486
-
487
- this.state('get', 'speak:speech')
488
- this.question(`${this.askChr}open speech:${agent.profile.voice} ${decodeURI(packet.q.text)}`).then(speech => {
489
- this.state('resolve', 'speak');
490
- return resolve({
491
- text: speech.a.text,
492
- html: speech.a.html,
493
- data: speech.a.data,
494
- })
495
- }).catch(err => {
496
- this.state('reject', 'speak');
497
- return this.error(err, packet, reject);
498
- });
499
- // this.state('get', 'speech');
500
- // return
501
- // }).then(voice => {
502
- // text.push(voice.a.text);
503
- // data.voice = voice.a.data;
504
-
505
- });
506
- },
507
-
508
- /**************
509
- method: artist
510
- params: packet
511
- describe: this method provides a global artist method to all agents.
512
- ***************/
513
- art(packet) {
514
- return new Promise((resolve, reject) => {
515
- this.action('feature', 'services:art');
516
-
517
- const text = [];
518
- const data = {};
519
- const agent = this.agent();
520
- const client = this.client();
521
- const size = packet.q.meta.params[1] || 'square';
522
- if (!agent.profile.style) return resolve(this._messages.nostyle);
523
- this.state('get', 'image');
524
- const msg = [
525
- `style: ${agent.profile.style}`,
526
- `prompt: ${packet.q.text}`,
527
- ].join('\n');
528
- this.question(`${this.askChr}open image:${size} ${msg}`).then(painting => {
529
- data.patining = painting.a.data.image;
530
-
531
- this.state('set', 'history');
532
- this.vars.art.history.push(painting.a.text);
533
-
534
- return resolve({
535
- text: painting.a.text,
536
- html: painting.a.html,
537
- data,
538
- });
539
- }).catch(err => {
540
- console.log('ERROR', err);
541
- return this.error(packet, err, reject);
542
- });
543
- });
544
- },
545
-
546
- /**************
547
- method: reply
548
- params: packet
549
- describe: this method is a feature that allows each agent to reply to messages
550
- with their specific features. if a header is supplied in the request then
551
- it will be added to the data.
552
- ***************/
553
- reply(packet) {
554
- return new Promise((resolve, reject) => {
555
- if (!this.vars.reply) return resolve('NO REPLY');
556
- this.context('reply')
557
- const agent = this.agent();
558
- const client = this.client();
559
- const {admin} = this.services().global;
560
-
561
- const {author} = packet.q.data;
562
-
563
- const profile = [
564
- `::begin:admin:${admin.id}`,
565
- `id: ${admin.id}`,
566
- `name: ${admin.name}`,
567
- `roles: ${admin.roles}`,
568
- `disclaimer: For Admin use only.`,
569
- `::end:admin`,
570
- `::begin:user:${client.id}`,
571
- `id: ${client.id}`,
572
- `name: ${client.profile.name}`,
573
- `nickname: ${client.profile.nickname}`,
574
- `describe: ${client.profile.describe}`,
575
- `::end:user`
576
- ];
577
-
578
- profile.push(`::begin:assistant`);
579
- for (let x in agent.profile) {
580
- profile.push(`${x}: ${agent.profile[x]}`);
581
- }
582
- profile.push(`::end:assistant`);
583
-
584
- this.question(`${this.askChr}docs view devas/${this.vars.reply.profile}:corpus`).then(doc => {
585
- const data = {
586
- model: agent.model || false,
587
- header: packet.q.data.header || false,
588
- profile: profile.join('\n'),
589
- corpus: doc.a.text,
590
- history: this.vars.reply.history.slice(-5),
591
- };
592
- const msg = [
593
- packet.q.text,
594
- `important: Respond in ${this.vars.reply.words} words or less.`,
595
- ].join('\n');
596
-
597
- return this.question(`${this.askChr}open relay ${msg}`, data);
598
- }).then(chat => {
599
- this.vars.reply.history.push({
600
- role: chat.a.data.chat.role,
601
- content: chat.a.data.chat.text,
602
- });
603
- return resolve({
604
- text: chat.a.text,
605
- html: chat.a.html,
606
- data: chat.a.data,
607
- });
608
- }).catch(err => {
609
- return this.error(packet, err, reject);
610
- });
611
- });
612
- },
613
133
  };
package/package.json CHANGED
@@ -1,12 +1,13 @@
1
1
  {
2
2
  "id": 4855882658530,
3
3
  "name": "@indra.ai/deva.services",
4
- "version": "0.0.4",
4
+ "version": "0.0.6",
5
5
  "author": "Quinn Michaels",
6
6
  "license": "MIT",
7
- "copyright": "2023",
8
- "description": "The Services Deva handles @SERVICES in deva.world.",
7
+ "copyright": "2025",
8
+ "description": "The Services Deva handles Services in Deva.world.",
9
9
  "main": "index.js",
10
+ "type": "module",
10
11
  "scripts": {
11
12
  "test": "echo \"Error: no test specified\" && exit 1"
12
13
  },
@@ -26,6 +27,6 @@
26
27
  },
27
28
  "homepage": "https://deva.space/devas/services",
28
29
  "dependencies": {
29
- "@indra.ai/deva": "^1.2.21"
30
+ "@indra.ai/deva": "^1.2.36"
30
31
  }
31
32
  }