Skip to content

Commit

Permalink
Merge pull request #433 from MyLife-Services/431-version-27-updates
Browse files Browse the repository at this point in the history
431 version 27 updates
  • Loading branch information
Mookse authored Nov 12, 2024
2 parents 271bbe9 + 5ae0e7a commit 8f51c46
Show file tree
Hide file tree
Showing 31 changed files with 810 additions and 622 deletions.
1 change: 0 additions & 1 deletion inc/js/agents/system/asset-agent.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ class AssetAgent {
uploadFiles.push(this.#extractFile(file))
})
if(uploadFiles.length){ // only upload new files
console.log('upload::uploadFiles', uploadFiles)
const fileStreams = uploadFiles.map(file=>fs.createReadStream(file.filepath))
const dataRecord = await this.#llm.upload(this.#vectorstoreId, fileStreams, this.mbr_id)
const { response, success } = dataRecord
Expand Down
3 changes: 0 additions & 3 deletions inc/js/agents/system/bot-agent.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ class Bot {
#llm
#type
constructor(botData, llm, factory){
console.log(`bot pre-created`, this.feedback)
this.#factory = factory
this.#llm = llm
const { feedback=[], greeting=mDefaultGreeting, greetings=mDefaultGreetings, type=mDefaultBotType, ..._botData } = botData
Expand Down Expand Up @@ -141,7 +140,6 @@ class Bot {
const { bot_id: _llm_id, id, type, } = this
let { llm_id=_llm_id, thread_id, } = this // @stub - deprecate bot_id
this.#conversation = await mConversationStart('chat', type, id, thread_id, llm_id, this.#llm, this.#factory, message)
console.log(`getConversation::thread_id`, thread_id, this.#conversation.thread_id)
if(!thread_id?.length){
thread_id = this.#conversation.thread_id
this.update({
Expand Down Expand Up @@ -1042,7 +1040,6 @@ async function mConversationDelete(Conversation, factory, llm){
})
await factory.deleteItem(Conversation.id) /* delete conversation from Cosmos */
await llm.deleteThread(thread_id) /* delete thread from LLM */
console.log('mDeleteConversation', Conversation.id, thread_id)
return true
}
/**
Expand Down
39 changes: 0 additions & 39 deletions inc/js/agents/system/evolution-agent.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,6 @@ export class EvolutionAgent extends EventEmitter {
get contributions() {
return this.#contributions
}
/**
* Get the factory object.
* @returns {AgentFactory} The avatar's factory object.
*/
get factory() {
return this.#avatar.factory
}
/**
* Get the owning member id.
* @returns {string} The avatar member-owner id.
Expand Down Expand Up @@ -253,37 +246,6 @@ function mFormatCategory(_category) {
.trimStart()
.slice(0, 64)
}
/**
* Digest a request to generate a new Contribution.
* @module
* @emits {on-contribution-new} - Emitted when a new Contribution is generated.
* @param {EvolutionAgent} evoAgent - `this` Evolution Assistant.
* @param {string} _category - The category to process.
* @param {string} _phase - The phase to process.
* @returns {Contribution} A new Contribution object.
*/
async function mGetContribution(evoAgent, _category, _phase) {
const _avatar = evoAgent.avatar
_category = mFormatCategory(_category)
// Process question and map to `new Contribution` class
const _contribution = new (_avatar.factory.contribution)({
avatar_id: _avatar.id,
context: `I am a contribution object in MyLife, comprising data and functionality around a data evolution request to my associated avatar [${_avatar.id}]`,
// id: _avatar.factory.newGuid,
mbr_id: _avatar.mbr_id, // Contributions are system objects
phase: _phase,
purpose: `Contribute to the data evolution of underlying avatar for category [${_category}]`,
request: {
category: _category,
content: _avatar?.[_category]??false,
impersonation: _avatar.being,
phase: _phase,
},
responses: [],
})
mAssignContributionListeners(evoAgent, _contribution)
return await _contribution.init(_avatar.factory) // fires emitters
}
/**
* Log an object to the console and emit it to the parent.
* @module
Expand Down Expand Up @@ -318,7 +280,6 @@ function mSetContribution(evoAgent, _current, _proposed) {
/* @todo: verify that categories are changing */
const _currentContribution = evoAgent.contributions
.find(_contribution => _contribution.id === _current.contributionId)
console.log('evolution-assistant:mSetContribution():320', _currentContribution.inspect(true))
if(_currentContribution.stage === 'prepared'){ // ready to process
// join array and submit for gpt-summarization
mSubmitContribution(evoAgent, _contributions.responses.join('\n'))
Expand Down
5 changes: 0 additions & 5 deletions inc/js/api-functions.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,12 @@ async function entry(ctx){
const { assistantType, mbr_id } = ctx.state
if(!ctx.request.body?.summary?.length)
throw new Error('No entry summary provided. Use `summary` field.')
console.log(chalk.yellowBright('entry()::entry attempted:'), ctx.request.body)
const summary = {
...ctx.request.body,
assistantType,
mbr_id,
}
const entry = await ctx.MyLife.entry(summary)
console.log(chalk.yellowBright('entry()::entry submitted:'), entry, summary)
ctx.status = 200
ctx.body = {
id: entry.id,
Expand All @@ -48,7 +46,6 @@ async function experienceBuilder(ctx){
const { assistantType, mbr_id } = ctx.state
const { eid, sid } = ctx.params
const { experience } = ctx.request.body?.experience
console.log(chalk.yellowBright('experienceBuilder()'), { assistantType, mbr_id, eid, sid, experience })
if(!experience)
ctx.throw(400, 'No experience provided for builder. Use `experience` field.')
}
Expand Down Expand Up @@ -231,14 +228,12 @@ async function memory(ctx){
const { assistantType, mbr_id } = ctx.state
if(!ctx.request.body?.summary?.length)
throw new Error('No memory summary provided. Use `summary` field.')
console.log(chalk.yellowBright('memory()::memory attempted:'), ctx.request.body)
const summary = {
...ctx.request.body,
assistantType,
mbr_id,
}
const memory = await ctx.MyLife.memory(summary)
console.log(chalk.yellowBright('memory()::memory submitted:'), memory, summary)
ctx.status = 200
ctx.body = {
id: memory.id,
Expand Down
54 changes: 29 additions & 25 deletions inc/js/core.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class Member extends EventEmitter {
*/
async init(avatar){
this.#avatar = avatar
?? await this.factory.getAvatar()
?? await this.#factory.getAvatar()
return this
}
// getter/setter functions
Expand Down Expand Up @@ -56,7 +56,7 @@ class Member extends EventEmitter {
}
set avatar(_Avatar){
// oops, hack around how to get dna of avatar class; review options [could block at factory-getter level, most efficient and logical]
if(!this.factory.isAvatar(_Avatar))
if(!this.#factory.isAvatar(_Avatar))
throw new Error('avatar requires Avatar Class')
this.#avatar = _Avatar
}
Expand All @@ -80,19 +80,19 @@ class Member extends EventEmitter {
return this.agent.chat
}
get consent(){
return this.factory.consent // **caution**: returns <<PROMISE>>
return this.#factory.consent // **caution**: returns <<PROMISE>>
}
set consent(_consent){
this.factory.consents.unshift(_consent.id)
this.#factory.consents.unshift(_consent.id)
}
get core(){
return this.factory.core
return this.#factory.core
}
get dataservice(){
return this.dataservices
}
get dataservices(){
return this.factory.dataservices
return this.#factory.dataservices
}
get description(){
return this.core.description
Expand All @@ -110,7 +110,7 @@ class Member extends EventEmitter {
return this.core.form
}
get globals(){
return this.factory.globals
return this.#factory.globals
}
get hobbies(){
return this.core.hobbies
Expand All @@ -122,7 +122,7 @@ class Member extends EventEmitter {
return this.sysid
}
get mbr_id(){
return this.factory.mbr_id
return this.#factory.mbr_id
}
get member(){
return this.core
Expand All @@ -139,6 +139,9 @@ class Member extends EventEmitter {
get preferences(){
return this.core.preferences
}
get schemas(){
return this.#factory.schemas
}
get skills(){
return this.core.skills
}
Expand All @@ -155,15 +158,15 @@ class Member extends EventEmitter {
async testEmitters(){
// test emitters with callbacks
this.emit('testEmitter',_response=>{
console.log('callback emitters enabled:',_response)

})
}
}
class Organization extends Member { // form=organization
#Menu
#Router
constructor(_Factory){
super(_Factory)
constructor(Factory){
super(Factory)
}
/* public functions */
async init(avatar){
Expand All @@ -190,7 +193,7 @@ class Organization extends Member { // form=organization
}
get menu(){
if(!this.#Menu){
this.#Menu = new (this.factory.schemas.menu)(this).menu
this.#Menu = new (this.schemas.menu)(this).menu
}
return this.#Menu
}
Expand All @@ -211,7 +214,7 @@ class Organization extends Member { // form=organization
}
get router(){
if(!this.#Router){
this.#Router = initRouter(new (this.factory.schemas.menu)(this))
this.#Router = initRouter(new (this.schemas.menu)(this))
}
return this.#Router
}
Expand All @@ -233,12 +236,14 @@ class Organization extends Member { // form=organization
}
class MyLife extends Organization { // form=server
#avatar // MyLife's private class avatar, _same_ object reference as Member Class's `#avatar`
#factory
#version = '0.0.0' // indicates error
constructor(factory){ // no session presumed to exist
super(factory)
constructor(Factory){ // no session presumed to exist
super(Factory)
this.#factory = Factory
}
async init(){
this.#avatar = await this.factory.getAvatar()
this.#avatar = await this.#factory.getAvatar()
return await super.init(this.#avatar)
}
/* public functions */
Expand All @@ -247,7 +252,7 @@ class MyLife extends Organization { // form=server
* @returns {Object[]} - An array of the currently available public experiences.
*/
async availableExperiences(){
const experiences = ( await this.factory.availableExperiences() )
const experiences = ( await this.#factory.availableExperiences() )
.map(experience=>{ // map to display versions [from `mylife-avatar.mjs`]
const { autoplay=false, description, id, name, purpose, skippable=true, } = experience
return {
Expand Down Expand Up @@ -277,7 +282,7 @@ class MyLife extends Organization { // form=server
async datacore(mbr_id){
if(!mbr_id || mbr_id===this.mbr_id)
throw new Error('datacore cannot be accessed')
const core = this.globals.sanitize(await this.factory.datacore(mbr_id))
const core = this.globals.sanitize(await this.#factory.datacore(mbr_id))
return core
}
/**
Expand All @@ -302,10 +307,10 @@ class MyLife extends Organization { // form=server
* @returns {void} returns nothing, performs operation
*/
getAlerts(){
this.factory.getAlerts()
this.#factory.getAlerts()
}
async getMyLifeSession(){
return await this.factory.getMyLifeSession()
return await this.#factory.getMyLifeSession()
}
async hostedMemberList(){
let members = await this.hostedMembers()
Expand All @@ -317,7 +322,7 @@ class MyLife extends Organization { // form=server
* @returns {Promise<Array>} - Array of string ids, one for each hosted member.
*/
async hostedMembers(validations){
return await this.factory.hostedMembers(validations)
return await this.#factory.hostedMembers(validations)
}
/**
* Returns whether a specified member id is hosted on this instance.
Expand All @@ -330,7 +335,6 @@ class MyLife extends Organization { // form=server
let isValidated = false
if(isHosted)
isValidated = await this.testPartitionKey(memberId)
console.log('isMemberHosted:', isHosted, isValidated, memberId)
return isValidated
}
/**
Expand All @@ -339,7 +343,7 @@ class MyLife extends Organization { // form=server
* @param {object} candidate { 'avatarName': string, 'email': string, 'humanName': string, }
*/
async registerCandidate(candidate){
return await this.factory.registerCandidate(candidate)
return await this.#factory.registerCandidate(candidate)
}
/**
* Submits and returns the memory to MyLife via API.
Expand Down Expand Up @@ -378,7 +382,7 @@ class MyLife extends Organization { // form=server
mbr_id,
name: `${ being }_${ title.substring(0,64) }_${ mbr_id }`,
}
const savedStory = this.globals.sanitize(await this.factory.summary(story))
const savedStory = this.globals.sanitize(await this.#factory.summary(story))
return savedStory
}
/**
Expand All @@ -388,7 +392,7 @@ class MyLife extends Organization { // form=server
* @returns {boolean} returns true if partition key is valid
*/
async testPartitionKey(_mbr_id){
return await this.factory.testPartitionKey(_mbr_id)
return await this.#factory.testPartitionKey(_mbr_id)
}
/* getters/setters */
/**
Expand Down
5 changes: 1 addition & 4 deletions inc/js/factory-class-extenders/class-extenders.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,6 @@ function extendClass_message(originClass, referencesObject) {
try{
this.#content = assignContent(content ?? obj)
} catch(e){
console.log('Message::constructor::ERROR', e)
this.#content = ''
}
}
Expand All @@ -443,9 +442,7 @@ function extendClass_message(originClass, referencesObject) {
set content(_content){
try{
this.#content = assignContent(_content)
} catch(e){
console.log('Message::content::ERROR', e)
}
} catch(e){}
}
get message(){
return this
Expand Down
23 changes: 21 additions & 2 deletions inc/js/functions.mjs
Original file line number Diff line number Diff line change
@@ -1,11 +1,30 @@
/* imports */
import fs from 'fs/promises'
import path from 'path'
import { fileURLToPath } from 'url'
import {
upload as apiUpload,
} from './api-functions.mjs'
/* variables */
const __filename = fileURLToPath(import.meta.url)
const __dirname = path.dirname(__filename)
/* module export functions */
/**
* Renders the about page for the application. Visitors see the rendered page, members see the page as responses from their Avatar.
* @param {Koa} ctx - Koa Context object
* @returns {object|void} - Renders page in place (visitor) or Koa Context object (member)
*/
async function about(ctx){
ctx.state.title = `About MyLife`
await ctx.render('about')
if(ctx.state.locked){
ctx.state.title = `About MyLife`
await ctx.render('about')
} else {
const { avatar: Avatar, } = ctx.state
const aboutFilePath = path.resolve(__dirname, '../..', 'views/about.html')
const html = await fs.readFile(aboutFilePath, 'utf-8')
const response = await Avatar.renderContent(html)
ctx.body = response
}
}
/**
* Activate a specific Bot.
Expand Down
Loading

0 comments on commit 8f51c46

Please sign in to comment.