Skip to content

Commit

Permalink
Merge pull request #225 from MyLife-Services/206-version-008-updates
Browse files Browse the repository at this point in the history
206 version 008 updates
  • Loading branch information
Mookse authored May 28, 2024
2 parents 2bd2e89 + fc5066f commit 540a033
Show file tree
Hide file tree
Showing 44 changed files with 2,140 additions and 1,386 deletions.
15 changes: 0 additions & 15 deletions inc/js/api-functions.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -158,20 +158,6 @@ async function library(ctx){
success: true,
}
}
/**
* Login function for member. Requires mid in params.
* @module
* @public
* @param {Koa} ctx - Koa Context object
* @returns {Koa} Koa Context object
* @property {string} ctx.body.challengeId
*/
async function login(ctx){
if(!ctx.params.mid?.length)
ctx.throw(400, `missing member id`) // currently only accepts single contributions via post with :cid
ctx.session.MemberSession.challenge_id = decodeURIComponent(ctx.params.mid)
ctx.body = { challengeId: ctx.session.MemberSession.challenge_id }
}
/**
* Logout function for member.
* @param {Koa} ctx - Koa Context object
Expand Down Expand Up @@ -362,7 +348,6 @@ export {
experiencesLived,
keyValidation,
library,
login,
logout,
register,
story,
Expand Down
44 changes: 24 additions & 20 deletions inc/js/core.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,6 @@ class Member extends EventEmitter {
this.factory.on('avatar-init-end',(_avatar,bytes)=>{
console.log(chalk.grey(`Member::init::avatar-init-end|memory-size=${bytes}b`))
})
this.factory.on('on-contribution-new',(_contribution)=>{
console.log(chalk.grey(`Member::on-contribution-new`),_contribution.request)
})
}
// getter/setter functions
get abilities(){
Expand Down Expand Up @@ -100,13 +97,6 @@ class Member extends EventEmitter {
set consent(_consent){
this.factory.consents.unshift(_consent.id)
}
/**
* Gets Member Contributions, i.e., questions that need posing to Member
* @returns {array} returns array of Member Contributions
*/
get contributions(){
return this.#avatar?.contributions
}
get core(){
return this.factory.core
}
Expand Down Expand Up @@ -293,21 +283,35 @@ class MyLife extends Organization { // form=server
async getMyLifeSession(){
return await this.factory.getMyLifeSession()
}
/**
* Returns Array of hosted members based on validation requirements.
* @param {Array} validations - Array of validation strings to filter membership.
* @returns {Promise<Array>} - Array of string ids, one for each hosted member.
*/
async hostedMembers(validations){
return await this.factory.hostedMembers(validations)
}
/**
* Submits a request for a library item from MyLife via API.
* @public
* @param {string} _mbr_id - Requesting Member id.
* @param {string} _assistantType - String name of assistant type.
* @param {string} _library - Library entry with or without `items`.
* @param {string} mbr_id - Requesting Member id.
* @param {string} assistantType - String name of assistant type.
* @param {string} library - Library entry with or without `items`.
* @returns {object} - The library document from Cosmos.
*/
async library(_mbr_id, _assistantType, _library){
_library.assistantType = _assistantType
_library.id = _library.id && this.globals.isValidGuid(_library.id) ? _library.id : this.globals.newGuid
_library.mbr_id = _mbr_id
_library.type = _library.type??_assistantType??'personal'
const _libraryCosmos = await this.factory.library(_library)
return this.globals.stripCosmosFields(_libraryCosmos)
async library(mbr_id, assistantType='personal-avatar', library){
const { id, type, } = library
library.assistantType = assistantType
library.id = this.globals.isValidGuid(id)
? id
: this.globals.newGuid
library.mbr_id = mbr_id
library.type = type
?? assistantType
const _library = this.globals.stripCosmosFields(
await this.factory.library(library)
)
return _library
}
/**
* Registers a new candidate to MyLife membership
Expand Down
File renamed without changes.
File renamed without changes.
11 changes: 5 additions & 6 deletions inc/js/factory-class-extenders/class-extenders.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import{
mGetSceneNext,
} from './class-experience-functions.mjs'
import {
mAssignContent,
assignContent,
} from './class-message-functions.mjs'
/**
* Extends the `Consent` class.
Expand Down Expand Up @@ -143,7 +143,7 @@ function extendClass_conversation(originClass, referencesObject) {
this.#thread = thread
this.#botId = botId
this.name = `conversation_${this.#factory.mbr_id}_${thread.thread_id}`
this.type = this.type??'chat'
this.type = this.type ?? 'chat'
}
/* public functions */
/**
Expand Down Expand Up @@ -380,7 +380,6 @@ function extendClass_file(originClass, referencesObject) {
// self-validation
if(!this.contents && this.type=='text')
throw new Error('No contents provided for text file; will not store')
// save to embedder
}
// public getters/setters
// private functions
Expand All @@ -406,7 +405,7 @@ function extendClass_message(originClass, referencesObject) {
const { content, ..._obj } = obj
super(_obj)
try{
this.#content = mAssignContent(content ?? obj)
this.#content = assignContent(content ?? obj)
} catch(e){
console.log('Message::constructor::ERROR', e)
this.#content = ''
Expand All @@ -418,7 +417,7 @@ function extendClass_message(originClass, referencesObject) {
}
set content(_content){
try{
this.#content = mAssignContent(_content)
this.#content = assignContent(_content)
} catch(e){
console.log('Message::content::ERROR', e)
}
Expand All @@ -427,7 +426,7 @@ function extendClass_message(originClass, referencesObject) {
return this
}
get micro(){
return { content: this.content, role: this.role??'user' }
return { content: this.content, role: this.role ?? 'user' }
}
}
return Message
Expand Down
29 changes: 4 additions & 25 deletions inc/js/factory-class-extenders/class-message-functions.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* @param {any} obj - Element to assign to `content` property
* @returns {string} - message text content
*/
function mAssignContent(obj){
function assignContent(obj){
const contentErrorMessage = 'No content found.'
const keyIncludes = ['category', 'content', 'input', 'message', 'text', 'value']
switch(typeof obj){
Expand All @@ -18,7 +18,7 @@ function mAssignContent(obj){
throw new Error(contentErrorMessage)
for(const element of obj){
try{
const content = mAssignContent(element)
const content = assignContent(element)
return content
} catch(e){
if(e.message===contentErrorMessage)
Expand All @@ -30,7 +30,7 @@ function mAssignContent(obj){
for(const key in obj){
try{
if(keyIncludes.includes(key)){
const content = mAssignContent(obj[key])
const content = assignContent(obj[key])
return content
}
} catch(e){
Expand All @@ -48,27 +48,6 @@ function mAssignContent(obj){
}
}
/* private module functions */
/**
* When incoming text is too large for a single message, generate dynamic text file and attach/submit.
* @module
* @private
* @param {string} _file - The file to construct.
* @returns
*/
async function mConstructFile(_file){
// construct file object
const __file = new (this.factory.file)({
name: `file_message_${this.id}`,
type: 'text',
contents: _file,
})
// save to embedder
return {
name: __file.name,
type: __file.type,
contents: await __file.arrayBuffer(),
}
}
/**
* Checks if content is a non-empty string.
* @module
Expand All @@ -81,5 +60,5 @@ function mIsNonEmptyString(content){
}
/* exports */
export {
mAssignContent,
assignContent,
}
Loading

0 comments on commit 540a033

Please sign in to comment.