Skip to content

Commit 8f51c46

Browse files
authored
Merge pull request #433 from MyLife-Services/431-version-27-updates
431 version 27 updates
2 parents 271bbe9 + 5ae0e7a commit 8f51c46

31 files changed

+810
-622
lines changed

inc/js/agents/system/asset-agent.mjs

-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ class AssetAgent {
6363
uploadFiles.push(this.#extractFile(file))
6464
})
6565
if(uploadFiles.length){ // only upload new files
66-
console.log('upload::uploadFiles', uploadFiles)
6766
const fileStreams = uploadFiles.map(file=>fs.createReadStream(file.filepath))
6867
const dataRecord = await this.#llm.upload(this.#vectorstoreId, fileStreams, this.mbr_id)
6968
const { response, success } = dataRecord

inc/js/agents/system/bot-agent.mjs

-3
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ class Bot {
3636
#llm
3737
#type
3838
constructor(botData, llm, factory){
39-
console.log(`bot pre-created`, this.feedback)
4039
this.#factory = factory
4140
this.#llm = llm
4241
const { feedback=[], greeting=mDefaultGreeting, greetings=mDefaultGreetings, type=mDefaultBotType, ..._botData } = botData
@@ -141,7 +140,6 @@ class Bot {
141140
const { bot_id: _llm_id, id, type, } = this
142141
let { llm_id=_llm_id, thread_id, } = this // @stub - deprecate bot_id
143142
this.#conversation = await mConversationStart('chat', type, id, thread_id, llm_id, this.#llm, this.#factory, message)
144-
console.log(`getConversation::thread_id`, thread_id, this.#conversation.thread_id)
145143
if(!thread_id?.length){
146144
thread_id = this.#conversation.thread_id
147145
this.update({
@@ -1042,7 +1040,6 @@ async function mConversationDelete(Conversation, factory, llm){
10421040
})
10431041
await factory.deleteItem(Conversation.id) /* delete conversation from Cosmos */
10441042
await llm.deleteThread(thread_id) /* delete thread from LLM */
1045-
console.log('mDeleteConversation', Conversation.id, thread_id)
10461043
return true
10471044
}
10481045
/**

inc/js/agents/system/evolution-agent.mjs

-39
Original file line numberDiff line numberDiff line change
@@ -82,13 +82,6 @@ export class EvolutionAgent extends EventEmitter {
8282
get contributions() {
8383
return this.#contributions
8484
}
85-
/**
86-
* Get the factory object.
87-
* @returns {AgentFactory} The avatar's factory object.
88-
*/
89-
get factory() {
90-
return this.#avatar.factory
91-
}
9285
/**
9386
* Get the owning member id.
9487
* @returns {string} The avatar member-owner id.
@@ -253,37 +246,6 @@ function mFormatCategory(_category) {
253246
.trimStart()
254247
.slice(0, 64)
255248
}
256-
/**
257-
* Digest a request to generate a new Contribution.
258-
* @module
259-
* @emits {on-contribution-new} - Emitted when a new Contribution is generated.
260-
* @param {EvolutionAgent} evoAgent - `this` Evolution Assistant.
261-
* @param {string} _category - The category to process.
262-
* @param {string} _phase - The phase to process.
263-
* @returns {Contribution} A new Contribution object.
264-
*/
265-
async function mGetContribution(evoAgent, _category, _phase) {
266-
const _avatar = evoAgent.avatar
267-
_category = mFormatCategory(_category)
268-
// Process question and map to `new Contribution` class
269-
const _contribution = new (_avatar.factory.contribution)({
270-
avatar_id: _avatar.id,
271-
context: `I am a contribution object in MyLife, comprising data and functionality around a data evolution request to my associated avatar [${_avatar.id}]`,
272-
// id: _avatar.factory.newGuid,
273-
mbr_id: _avatar.mbr_id, // Contributions are system objects
274-
phase: _phase,
275-
purpose: `Contribute to the data evolution of underlying avatar for category [${_category}]`,
276-
request: {
277-
category: _category,
278-
content: _avatar?.[_category]??false,
279-
impersonation: _avatar.being,
280-
phase: _phase,
281-
},
282-
responses: [],
283-
})
284-
mAssignContributionListeners(evoAgent, _contribution)
285-
return await _contribution.init(_avatar.factory) // fires emitters
286-
}
287249
/**
288250
* Log an object to the console and emit it to the parent.
289251
* @module
@@ -318,7 +280,6 @@ function mSetContribution(evoAgent, _current, _proposed) {
318280
/* @todo: verify that categories are changing */
319281
const _currentContribution = evoAgent.contributions
320282
.find(_contribution => _contribution.id === _current.contributionId)
321-
console.log('evolution-assistant:mSetContribution():320', _currentContribution.inspect(true))
322283
if(_currentContribution.stage === 'prepared'){ // ready to process
323284
// join array and submit for gpt-summarization
324285
mSubmitContribution(evoAgent, _contributions.responses.join('\n'))

inc/js/api-functions.mjs

-5
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,12 @@ async function entry(ctx){
2525
const { assistantType, mbr_id } = ctx.state
2626
if(!ctx.request.body?.summary?.length)
2727
throw new Error('No entry summary provided. Use `summary` field.')
28-
console.log(chalk.yellowBright('entry()::entry attempted:'), ctx.request.body)
2928
const summary = {
3029
...ctx.request.body,
3130
assistantType,
3231
mbr_id,
3332
}
3433
const entry = await ctx.MyLife.entry(summary)
35-
console.log(chalk.yellowBright('entry()::entry submitted:'), entry, summary)
3634
ctx.status = 200
3735
ctx.body = {
3836
id: entry.id,
@@ -48,7 +46,6 @@ async function experienceBuilder(ctx){
4846
const { assistantType, mbr_id } = ctx.state
4947
const { eid, sid } = ctx.params
5048
const { experience } = ctx.request.body?.experience
51-
console.log(chalk.yellowBright('experienceBuilder()'), { assistantType, mbr_id, eid, sid, experience })
5249
if(!experience)
5350
ctx.throw(400, 'No experience provided for builder. Use `experience` field.')
5451
}
@@ -231,14 +228,12 @@ async function memory(ctx){
231228
const { assistantType, mbr_id } = ctx.state
232229
if(!ctx.request.body?.summary?.length)
233230
throw new Error('No memory summary provided. Use `summary` field.')
234-
console.log(chalk.yellowBright('memory()::memory attempted:'), ctx.request.body)
235231
const summary = {
236232
...ctx.request.body,
237233
assistantType,
238234
mbr_id,
239235
}
240236
const memory = await ctx.MyLife.memory(summary)
241-
console.log(chalk.yellowBright('memory()::memory submitted:'), memory, summary)
242237
ctx.status = 200
243238
ctx.body = {
244239
id: memory.id,

inc/js/core.mjs

+29-25
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class Member extends EventEmitter {
1919
*/
2020
async init(avatar){
2121
this.#avatar = avatar
22-
?? await this.factory.getAvatar()
22+
?? await this.#factory.getAvatar()
2323
return this
2424
}
2525
// getter/setter functions
@@ -56,7 +56,7 @@ class Member extends EventEmitter {
5656
}
5757
set avatar(_Avatar){
5858
// oops, hack around how to get dna of avatar class; review options [could block at factory-getter level, most efficient and logical]
59-
if(!this.factory.isAvatar(_Avatar))
59+
if(!this.#factory.isAvatar(_Avatar))
6060
throw new Error('avatar requires Avatar Class')
6161
this.#avatar = _Avatar
6262
}
@@ -80,19 +80,19 @@ class Member extends EventEmitter {
8080
return this.agent.chat
8181
}
8282
get consent(){
83-
return this.factory.consent // **caution**: returns <<PROMISE>>
83+
return this.#factory.consent // **caution**: returns <<PROMISE>>
8484
}
8585
set consent(_consent){
86-
this.factory.consents.unshift(_consent.id)
86+
this.#factory.consents.unshift(_consent.id)
8787
}
8888
get core(){
89-
return this.factory.core
89+
return this.#factory.core
9090
}
9191
get dataservice(){
9292
return this.dataservices
9393
}
9494
get dataservices(){
95-
return this.factory.dataservices
95+
return this.#factory.dataservices
9696
}
9797
get description(){
9898
return this.core.description
@@ -110,7 +110,7 @@ class Member extends EventEmitter {
110110
return this.core.form
111111
}
112112
get globals(){
113-
return this.factory.globals
113+
return this.#factory.globals
114114
}
115115
get hobbies(){
116116
return this.core.hobbies
@@ -122,7 +122,7 @@ class Member extends EventEmitter {
122122
return this.sysid
123123
}
124124
get mbr_id(){
125-
return this.factory.mbr_id
125+
return this.#factory.mbr_id
126126
}
127127
get member(){
128128
return this.core
@@ -139,6 +139,9 @@ class Member extends EventEmitter {
139139
get preferences(){
140140
return this.core.preferences
141141
}
142+
get schemas(){
143+
return this.#factory.schemas
144+
}
142145
get skills(){
143146
return this.core.skills
144147
}
@@ -155,15 +158,15 @@ class Member extends EventEmitter {
155158
async testEmitters(){
156159
// test emitters with callbacks
157160
this.emit('testEmitter',_response=>{
158-
console.log('callback emitters enabled:',_response)
161+
159162
})
160163
}
161164
}
162165
class Organization extends Member { // form=organization
163166
#Menu
164167
#Router
165-
constructor(_Factory){
166-
super(_Factory)
168+
constructor(Factory){
169+
super(Factory)
167170
}
168171
/* public functions */
169172
async init(avatar){
@@ -190,7 +193,7 @@ class Organization extends Member { // form=organization
190193
}
191194
get menu(){
192195
if(!this.#Menu){
193-
this.#Menu = new (this.factory.schemas.menu)(this).menu
196+
this.#Menu = new (this.schemas.menu)(this).menu
194197
}
195198
return this.#Menu
196199
}
@@ -211,7 +214,7 @@ class Organization extends Member { // form=organization
211214
}
212215
get router(){
213216
if(!this.#Router){
214-
this.#Router = initRouter(new (this.factory.schemas.menu)(this))
217+
this.#Router = initRouter(new (this.schemas.menu)(this))
215218
}
216219
return this.#Router
217220
}
@@ -233,12 +236,14 @@ class Organization extends Member { // form=organization
233236
}
234237
class MyLife extends Organization { // form=server
235238
#avatar // MyLife's private class avatar, _same_ object reference as Member Class's `#avatar`
239+
#factory
236240
#version = '0.0.0' // indicates error
237-
constructor(factory){ // no session presumed to exist
238-
super(factory)
241+
constructor(Factory){ // no session presumed to exist
242+
super(Factory)
243+
this.#factory = Factory
239244
}
240245
async init(){
241-
this.#avatar = await this.factory.getAvatar()
246+
this.#avatar = await this.#factory.getAvatar()
242247
return await super.init(this.#avatar)
243248
}
244249
/* public functions */
@@ -247,7 +252,7 @@ class MyLife extends Organization { // form=server
247252
* @returns {Object[]} - An array of the currently available public experiences.
248253
*/
249254
async availableExperiences(){
250-
const experiences = ( await this.factory.availableExperiences() )
255+
const experiences = ( await this.#factory.availableExperiences() )
251256
.map(experience=>{ // map to display versions [from `mylife-avatar.mjs`]
252257
const { autoplay=false, description, id, name, purpose, skippable=true, } = experience
253258
return {
@@ -277,7 +282,7 @@ class MyLife extends Organization { // form=server
277282
async datacore(mbr_id){
278283
if(!mbr_id || mbr_id===this.mbr_id)
279284
throw new Error('datacore cannot be accessed')
280-
const core = this.globals.sanitize(await this.factory.datacore(mbr_id))
285+
const core = this.globals.sanitize(await this.#factory.datacore(mbr_id))
281286
return core
282287
}
283288
/**
@@ -302,10 +307,10 @@ class MyLife extends Organization { // form=server
302307
* @returns {void} returns nothing, performs operation
303308
*/
304309
getAlerts(){
305-
this.factory.getAlerts()
310+
this.#factory.getAlerts()
306311
}
307312
async getMyLifeSession(){
308-
return await this.factory.getMyLifeSession()
313+
return await this.#factory.getMyLifeSession()
309314
}
310315
async hostedMemberList(){
311316
let members = await this.hostedMembers()
@@ -317,7 +322,7 @@ class MyLife extends Organization { // form=server
317322
* @returns {Promise<Array>} - Array of string ids, one for each hosted member.
318323
*/
319324
async hostedMembers(validations){
320-
return await this.factory.hostedMembers(validations)
325+
return await this.#factory.hostedMembers(validations)
321326
}
322327
/**
323328
* Returns whether a specified member id is hosted on this instance.
@@ -330,7 +335,6 @@ class MyLife extends Organization { // form=server
330335
let isValidated = false
331336
if(isHosted)
332337
isValidated = await this.testPartitionKey(memberId)
333-
console.log('isMemberHosted:', isHosted, isValidated, memberId)
334338
return isValidated
335339
}
336340
/**
@@ -339,7 +343,7 @@ class MyLife extends Organization { // form=server
339343
* @param {object} candidate { 'avatarName': string, 'email': string, 'humanName': string, }
340344
*/
341345
async registerCandidate(candidate){
342-
return await this.factory.registerCandidate(candidate)
346+
return await this.#factory.registerCandidate(candidate)
343347
}
344348
/**
345349
* Submits and returns the memory to MyLife via API.
@@ -378,7 +382,7 @@ class MyLife extends Organization { // form=server
378382
mbr_id,
379383
name: `${ being }_${ title.substring(0,64) }_${ mbr_id }`,
380384
}
381-
const savedStory = this.globals.sanitize(await this.factory.summary(story))
385+
const savedStory = this.globals.sanitize(await this.#factory.summary(story))
382386
return savedStory
383387
}
384388
/**
@@ -388,7 +392,7 @@ class MyLife extends Organization { // form=server
388392
* @returns {boolean} returns true if partition key is valid
389393
*/
390394
async testPartitionKey(_mbr_id){
391-
return await this.factory.testPartitionKey(_mbr_id)
395+
return await this.#factory.testPartitionKey(_mbr_id)
392396
}
393397
/* getters/setters */
394398
/**

inc/js/factory-class-extenders/class-extenders.mjs

+1-4
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,6 @@ function extendClass_message(originClass, referencesObject) {
432432
try{
433433
this.#content = assignContent(content ?? obj)
434434
} catch(e){
435-
console.log('Message::constructor::ERROR', e)
436435
this.#content = ''
437436
}
438437
}
@@ -443,9 +442,7 @@ function extendClass_message(originClass, referencesObject) {
443442
set content(_content){
444443
try{
445444
this.#content = assignContent(_content)
446-
} catch(e){
447-
console.log('Message::content::ERROR', e)
448-
}
445+
} catch(e){}
449446
}
450447
get message(){
451448
return this

inc/js/functions.mjs

+21-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,30 @@
11
/* imports */
2+
import fs from 'fs/promises'
3+
import path from 'path'
4+
import { fileURLToPath } from 'url'
25
import {
36
upload as apiUpload,
47
} from './api-functions.mjs'
8+
/* variables */
9+
const __filename = fileURLToPath(import.meta.url)
10+
const __dirname = path.dirname(__filename)
511
/* module export functions */
12+
/**
13+
* Renders the about page for the application. Visitors see the rendered page, members see the page as responses from their Avatar.
14+
* @param {Koa} ctx - Koa Context object
15+
* @returns {object|void} - Renders page in place (visitor) or Koa Context object (member)
16+
*/
617
async function about(ctx){
7-
ctx.state.title = `About MyLife`
8-
await ctx.render('about')
18+
if(ctx.state.locked){
19+
ctx.state.title = `About MyLife`
20+
await ctx.render('about')
21+
} else {
22+
const { avatar: Avatar, } = ctx.state
23+
const aboutFilePath = path.resolve(__dirname, '../..', 'views/about.html')
24+
const html = await fs.readFile(aboutFilePath, 'utf-8')
25+
const response = await Avatar.renderContent(html)
26+
ctx.body = response
27+
}
928
}
1029
/**
1130
* Activate a specific Bot.

0 commit comments

Comments
 (0)