Skip to content

Commit a50339a

Browse files
authored
336 version 0019 updates (#345)
* 20240827 @Mookse - version - Remove Library Bot #340 * 20240903 @Mookse - crude but functional Relive and end relived memory - no saving currently * 20240903 @Mookse - cosmetic (vars)
1 parent 9f68074 commit a50339a

15 files changed

+170
-367
lines changed

inc/js/api-functions.mjs

-41
Original file line numberDiff line numberDiff line change
@@ -144,30 +144,6 @@ async function keyValidation(ctx){ // from openAI
144144
data: memberCoreData,
145145
}
146146
}
147-
/**
148-
* All functionality related to a library. Note: Had to be consolidated, as openai GPT would only POST.
149-
* @module
150-
* @public
151-
* @param {Koa} ctx - Koa Context object
152-
* @returns {Koa} Koa Context object
153-
*/
154-
async function library(ctx){
155-
await mAPIKeyValidation(ctx)
156-
const {
157-
assistantType,
158-
mbr_id,
159-
library = ctx.request?.body?.library
160-
?? ctx.request?.body
161-
?? {}
162-
} = ctx.state
163-
const _library = await ctx.MyLife.library(mbr_id, assistantType, library)
164-
ctx.status = 200 // OK
165-
ctx.body = {
166-
library: _library,
167-
message: `library function(s) completed successfully.`,
168-
success: true,
169-
}
170-
}
171147
/**
172148
* Logout function for member.
173149
* @param {Koa} ctx - Koa Context object
@@ -236,21 +212,6 @@ async function story(ctx){
236212
message: 'Story submitted successfully.',
237213
}
238214
}
239-
/**
240-
* Management of Member Story Libraries. Note: Key validation is performed in library(). Story library may have additional functionality inside of core/MyLife
241-
* @param {Koa} ctx - Koa Context object
242-
* @returns {Koa} Koa Context object. Body = { data: library, success: boolean, message: string }
243-
*/
244-
async function storyLibrary(ctx){
245-
const { id, form='biographer' } = ctx.request?.body??{}
246-
const type = 'story' // force constant
247-
ctx.state.library = {
248-
id,
249-
type,
250-
form,
251-
}
252-
const _library = await library(ctx) // returns ctx.body
253-
}
254215
/**
255216
* Validates api token
256217
* @module
@@ -361,11 +322,9 @@ export {
361322
experiences,
362323
experiencesLived,
363324
keyValidation,
364-
library,
365325
logout,
366326
register,
367327
story,
368-
storyLibrary,
369328
tokenValidation,
370329
upload,
371330
}

inc/js/core.mjs

-22
Original file line numberDiff line numberDiff line change
@@ -279,28 +279,6 @@ class MyLife extends Organization { // form=server
279279
async hostedMembers(validations){
280280
return await this.factory.hostedMembers(validations)
281281
}
282-
/**
283-
* Submits a request for a library item from MyLife via API.
284-
* @public
285-
* @param {string} mbr_id - Requesting Member id.
286-
* @param {string} assistantType - String name of assistant type.
287-
* @param {string} library - Library entry with or without `items`.
288-
* @returns {object} - The library document from Cosmos.
289-
*/
290-
async library(mbr_id, assistantType='personal-avatar', library){
291-
const { id, type, } = library
292-
library.assistantType = assistantType
293-
library.id = this.globals.isValidGuid(id)
294-
? id
295-
: this.globals.newGuid
296-
library.mbr_id = mbr_id
297-
library.type = type
298-
?? assistantType
299-
const _library = this.globals.stripCosmosFields(
300-
await this.factory.library(library)
301-
)
302-
return _library
303-
}
304282
/**
305283
* Registers a new candidate to MyLife membership
306284
* @public

inc/js/memory-functions.mjs

+9
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@ import {
88
async function collectMemory(ctx){
99
// @todo - implement memory collection
1010
}
11+
async function endMemory(ctx){
12+
const { iid, } = ctx.params
13+
const { Globals, MyLife, } = ctx
14+
if(!Globals.isValidGuid(iid))
15+
return ctx.throw(400, 'Invalid Item ID')
16+
const { avatar, } = ctx.state
17+
ctx.body = await avatar.endMemory(iid)
18+
}
1119
async function improveMemory(ctx){
1220
const { iid, } = ctx.params
1321
const { Globals, MyLife, } = ctx
@@ -48,6 +56,7 @@ async function livingMemory(ctx){
4856
export {
4957
collectMemory,
5058
improveMemory,
59+
endMemory,
5160
reliveMemory,
5261
livingMemory,
5362
}

inc/js/mylife-agent-factory.mjs

+8-184
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ const mMyLifeTeams = [
4545
{
4646
active: true,
4747
allowCustom: true,
48-
allowedTypes: ['artworks', 'editor', 'idea', 'library', 'marketing'],
49-
defaultTypes: ['artworks', 'idea', 'library',],
48+
allowedTypes: ['artworks', 'editor', 'idea', 'marketing'],
49+
defaultTypes: ['artworks', 'idea',],
5050
description: 'The Creative Team is dedicated to help you experience productive creativity sessions.',
5151
id: '84aa50ca-fb64-43d8-b140-31d2373f3cd2',
5252
name: 'creative',
@@ -65,8 +65,8 @@ const mMyLifeTeams = [
6565
{
6666
active: true,
6767
allowCustom: true,
68-
allowedTypes: ['diary', 'journaler', 'library', 'personal-biographer',],
69-
defaultTypes: ['personal-biographer', 'library',],
68+
allowedTypes: ['diary', 'journaler', 'personal-biographer',],
69+
defaultTypes: ['personal-biographer',],
7070
description: 'The Memoir Team is dedicated to help you document your life stories, experiences, thoughts, and feelings.',
7171
id: 'a261651e-51b3-44ec-a081-a8283b70369d',
7272
name: 'memoir',
@@ -95,8 +95,8 @@ const mMyLifeTeams = [
9595
{
9696
active: false,
9797
allowCustom: true,
98-
allowedTypes: ['library', 'note', 'poem', 'quote', 'religion',],
99-
defaultTypes: ['library', 'quote', 'religion',],
98+
allowedTypes: ['note', 'poem', 'quote', 'religion',],
99+
defaultTypes: ['quote', 'religion',],
100100
description: 'The Spirituality Team is dedicated to help you creatively explore your spiritual side.',
101101
id: 'bea7bb4a-a339-4026-ad1c-75f604dc3349',
102102
name: 'sprituality',
@@ -105,8 +105,8 @@ const mMyLifeTeams = [
105105
{
106106
active: true,
107107
allowCustom: true,
108-
allowedTypes: ['data-ownership', 'investment', 'library', 'ubi',],
109-
defaultTypes: ['library', 'ubi'],
108+
allowedTypes: ['data-ownership', 'investment', 'ubi',],
109+
defaultTypes: ['ubi'],
110110
description: 'The Universal Basic Income (UBI) Team is dedicated to helping you tailor your MyLife revenue streams based upon consensual access to your personal MyLife data.',
111111
id: '8a4d7340-ac62-40f1-8c77-f17c68797925',
112112
name: 'ubi',
@@ -398,54 +398,6 @@ class BotFactory extends EventEmitter{
398398
async help(thread_id, bot_id, helpRequest, avatar){
399399
return await mHelp(thread_id, bot_id, helpRequest, this, avatar)
400400
}
401-
/**
402-
* Gets, creates or updates Library in Cosmos.
403-
* @todo - institute bot for library mechanics.
404-
* @public
405-
* @param {Object} _library - The library object, including items to be added to/updated in member's library.
406-
* @returns {object} - The library.
407-
*/
408-
async library(_library){
409-
const updatedLibrary = await mLibrary(this, _library)
410-
// test the type/form of Library
411-
switch(updatedLibrary.type){
412-
case 'story':
413-
if(updatedLibrary.form==='biographer'){
414-
// inflate and update library with stories
415-
const stories = ( await this.stories(updatedLibrary.form) )
416-
.filter(story=>!this.globals.isValidGuid(story?.library_id))
417-
.map(story=>{
418-
const { mbr_name, newGuid } = this
419-
const { author=mbr_name, id=newGuid, title=mbr_name, } = story
420-
story = {
421-
...story,
422-
author,
423-
id,
424-
title,
425-
}
426-
return mInflateLibraryItem(story, updatedLibrary.id, mbr_id)
427-
})
428-
updatedLibrary.items = [
429-
...updatedLibrary.items,
430-
...stories,
431-
]
432-
/* update stories (no await) */
433-
stories.forEach(story=>this.dataservices.patch(
434-
story.id,
435-
{ library_id: updatedLibrary.id },
436-
))
437-
/* update library (no await) */
438-
this.dataservices.patch(
439-
updatedLibrary.id,
440-
{ items: updatedLibrary.items },
441-
)
442-
}
443-
break
444-
default:
445-
break
446-
}
447-
return updatedLibrary
448-
}
449401
/**
450402
* Allows member to reset passphrase.
451403
* @param {string} passphrase
@@ -468,7 +420,6 @@ class BotFactory extends EventEmitter{
468420
}
469421
/**
470422
* Gets a collection of stories of a certain format.
471-
* @todo - currently disconnected from a library, but no decisive mechanic for incorporating library shell.
472423
* @param {string} form - The form of the stories to retrieve.
473424
* @returns {object[]} - The stories.
474425
*/
@@ -770,21 +721,6 @@ class AgentFactory extends BotFactory {
770721
isSession(_session){ // when unavailable from general schemas
771722
return (_session instanceof mSchemas.session)
772723
}
773-
/**
774-
* Adds or updates a library with items outlined in request `library.items` array. Note: currently the override for `botFactory` function .library which returns a library item from the database.
775-
* @todo: finalize mechanic for overrides
776-
* @param {Object} _library - The library object, including items to be added to member's library.
777-
* @returns {Object} - The complete library object from Cosmos.
778-
*/
779-
async library(_library){
780-
/* hydrate library micro-bot */
781-
const { bot_id, mbr_id } = _library
782-
const _microBot = await this.libraryBot(bot_id, mbr_id)
783-
return await _microBot.library(_library)
784-
}
785-
async libraryBot(id){
786-
return await this.bot(id, 'library')
787-
}
788724
/**
789725
* Saves a completed lived experience to MyLife.
790726
* @param {Object} experience - The Lived Experience Object to save.
@@ -1530,118 +1466,6 @@ async function mHelp(thread_id, bot_id, helpRequest, factory, avatar){
15301466
const response = await mLLMServices.help(thread_id, bot_id, helpRequest, factory, avatar)
15311467
return response
15321468
}
1533-
/**
1534-
* Inflates library item with required values and structure. Object structure expected from API, librayItemItem in JSON.
1535-
* root\inc\json-schemas\bots\library-bot.json
1536-
* @param {object} _item - Library item (API) object. { author: string, enjoymentLevel: number, format: string, insights: string, personalImpact: string, title: string, whenRead: string }
1537-
* @param {string} _library_id - Library id
1538-
* @param {string} _mbr_id - Member id
1539-
* @returns {object} - Library-item object. { assistantType: string, author_match: array, being: string, date: string, format: string, id: string, item: object, library_id: string, object_id: string, title_match: string
1540-
*/
1541-
function mInflateLibraryItem(_item, _library_id, _mbr_id){
1542-
const _id = _item.id??mNewGuid()
1543-
return {
1544-
assistantType: _item.assistantType??'mylife-library',
1545-
author_match: (_item.author??'unknown-author')
1546-
.trim()
1547-
.toLowerCase()
1548-
.split(' '),
1549-
being: 'library-item',
1550-
date: _item.date??new Date().toISOString(),
1551-
format: _item.format??_item.form??_item.type??'book',
1552-
id: _id,
1553-
item: {..._item, id: _id },
1554-
library_id: _library_id,
1555-
object_id: _library_id,
1556-
title_match: (_item.title??'untitled')
1557-
.trim()
1558-
.toLowerCase(),
1559-
}
1560-
}
1561-
/**
1562-
* Hydrates library and returns library object.
1563-
* @module
1564-
* @private
1565-
* @param {BotFactory} factory - BotFactory object
1566-
* @param {object} _library - Library object
1567-
* @returns {object} - Library object
1568-
*/
1569-
async function mLibrary(factory, _library){
1570-
// @todo: micro-avatar for representation of bot(s)
1571-
// @todo: Bot class with extension for things like handling libraries
1572-
// @todo: bot-extenders so that I can get this functionality into that object context
1573-
/* constants */
1574-
const { assistantType, form='collection', id, items: _libraryItems=[], mbr_id, type } = _library
1575-
const _avatar_id = factory.avatarId
1576-
// add/get correct library; default to core (object_id=avatar_id && type)
1577-
/* parse and cast _libraryItems */
1578-
let _libraryCosmos = await factory.dataservices.library(id, _avatar_id, type, form)
1579-
// @dodo: currently only book/story library items are supported
1580-
if(!_libraryCosmos){ // create when undefined
1581-
// @todo: microbot should have a method for these
1582-
const _library_id = factory.newGuid
1583-
_libraryCosmos = {
1584-
being: `library`,
1585-
form: form,
1586-
id: _library_id,
1587-
items: _libraryItems.map(_item=>mInflateLibraryItem(_item, _library_id, mbr_id)),
1588-
mbr_id: mbr_id,
1589-
name: ['library',type,form,_avatar_id].join('_'),
1590-
object_id: _avatar_id,
1591-
type: type,
1592-
}
1593-
factory.dataservices.pushItem(_libraryCosmos) // push to Cosmos
1594-
} else {
1595-
// @todo: manage multiple libraries
1596-
const { id: _library_id, items: _storedLibraryItems } = _libraryCosmos
1597-
_libraryItems.forEach(_item => {
1598-
_item = mInflateLibraryItem(_item,_library_id, mbr_id)
1599-
const matchIndex = _storedLibraryItems.findIndex(storedItem => { // Find the index of the item in the stored library items that matches the criteria
1600-
if(storedItem.id===_item.id || storedItem.title_match===_item.title_match)
1601-
return true
1602-
const storedAuthorWords = storedItem.author_match
1603-
const incomingAuthorWords = _item.author_match
1604-
const authorMatches = (() => {
1605-
if (storedAuthorWords.length === 1 || incomingAuthorWords.length === 1) { // If either author array has a length of 1, check for any matching word
1606-
return storedAuthorWords.some(word => incomingAuthorWords.includes(word))
1607-
} else { // If both have 2+ lengths, ensure at least 2 items match
1608-
const matches = storedAuthorWords.filter(word => incomingAuthorWords.includes(word))
1609-
return matches.length >= 2
1610-
}
1611-
})()
1612-
if (authorMatches && matchIndex !== -1) { // Mutate the author to the one with more details if needed
1613-
if (incomingAuthorWords.length > storedAuthorWords.length) {
1614-
_storedLibraryItems[matchIndex].author_match = incomingAuthorWords // Update to more detailed author
1615-
}
1616-
}
1617-
return authorMatches
1618-
})
1619-
if (matchIndex!== -1) { // If a match is found, update the entry
1620-
_storedLibraryItems[matchIndex] = {
1621-
..._storedLibraryItems[matchIndex], // Keep existing properties
1622-
..._item, // Overwrite and add new properties from _item
1623-
id: _storedLibraryItems[matchIndex].id
1624-
?? factory.newGuid, // if for some reason object hasn't id
1625-
object_id: _library_id,
1626-
type: _item.type
1627-
?? 'book',
1628-
}
1629-
} else {
1630-
_storedLibraryItems.push({ // If no match is found, add the item to the library
1631-
..._item,
1632-
id: _item.id??factory.newGuid, // Ensure each item has a unique ID
1633-
mbr_id: factory.mbr_id,
1634-
object_id: _library_id,
1635-
type: _item.type??'book',
1636-
})
1637-
}
1638-
})
1639-
// save library to Cosmos @todo: microbot should have a method for this
1640-
_libraryCosmos.items = _storedLibraryItems
1641-
factory.dataservices.patch(_library_id, {items: _libraryCosmos.items})
1642-
}
1643-
return _libraryCosmos
1644-
}
16451469
/**
16461470
* Returns whether or not the factory is the MyLife server, as various functions are not available to the server and some _only_ to the server.
16471471
* @param {string} _mbr_id

0 commit comments

Comments
 (0)