@indra.ai/deva.services
Version:
The Services Deva handles Services in Deva.world.
111 lines (105 loc) • 3.75 kB
JavaScript
;
// Services Deva Feature Methods
// Copyright ©2000-2026 Quinn Arjuna Michaels; All rights reserved.
// Owner Signature Required For Lawful Use.
// Distributed under VLA:15754610084891131184 LICENSE.md
// Sunday, July 5, 2026 - 1:48:08 PM
export default {
/**************
method: service
params: packet
describe: The global service feature that installs with every agent
***************/
services(packet) {
this.context('feature');
return new Promise((resolve, reject) => {
const services = this.services();
const agent = this.agent();
const global = [];
services.global.forEach((item,index) => {
global.push(`::begin:${item.key}:${item.id}`);
for (let x in item) {
global.push(`${x}: ${item[x]}`);
}
const thehash = this.lib.hash(item);
global.push(`hash: ${thehash}`);
global.push(`::end:${item.key}:${thehash}`);
});
const concerns = [];
services.concerns.forEach((item, index) => {
concerns.push(`${index + 1}. ${item}`);
})
const info = [
'::BEGIN:SERVICES',
`::begin:client`,
'## Client',
`id: ${services.client_id}`,
`client: ${services.client_name}`,
`::end:client}`,
concerns.length ? `::begin:concerns` : '',
concerns.length ? '## Concerns' : '',
concerns.length ? concerns.join('\n') : '',
concerns.length ? `::end:concerns` : '',
'::begin:global',
'## Global',
global.join('\n'),
'::end:global',
'::END:SERVICES',
].join('\n');
this.question(`${this.askChr}feecting parse ${info}`).then(feecting => {
return resolve({
text: feecting.a.text,
html: feecting.a.html,
data: services.concerns,
});
}).catch(err => {
return this.error(err, packet, reject);
})
});
},
/**************
method: file
params: packet
describe: The view method replays the request to the view function to return
a document from the text parameter.
***************/
file(packet) {
const {id,q} = packet;
const {text, meta} = q;
const agent = this.agent();
this.zone('services');
this.feature('services', `file:${q.text}`);
this.action('method', `file:${q.text}`);
this.context('file', q.text);
return new Promise((resolve, reject) => {
const splitText = text.split(':');
const area = meta.params[1] ? meta.params[1] : 'public';
const part = splitText[1] ? splitText[1].toUpperCase() : 'MAIN';
const docName = splitText[0].length ? splitText[0] + '.feecting' : 'main.feecting';
const docPath = this.lib.path.join(this.config.dir, area, agent.key, docName);
let doc = false;
try {
const doc_file = this.lib.fs.readFileSync(docPath, 'utf8');
const doc_content = doc_file.split(`::BEGIN:${part}`)[1].split(`::END:${part}`)[0];
doc = [
`${this.container.begin}:FILE:${part.toUpperCase()}:${id.uid}`,
doc_content,
`${this.container.end}:FILE:${part.toUpperCase()}:${id.uid}`,
].join('\n');
} catch (err) {
return this.err(err, packet, reject);
}
this.question(`${this.askChr}feecting parse ${doc}`, {vars:this.vars}).then(feecting => {
this.state('resolve', `view:${packet.q.text}`);
return resolve({
text: feecting.a.text,
html: feecting.a.html,
data: feecting.a.data,
});
}).catch(err => {
this.state('reject', `file:${packet.q.text}`);
return this.err(err, packet, reject);
})
});
},
};