From 1042e59f4f9587c7e1e679da5661d35d7f84115a Mon Sep 17 00:00:00 2001 From: Abdurrehman Subhani Date: Thu, 26 Dec 2024 12:43:27 +0500 Subject: [PATCH 01/13] add discord appid to discord component props and args --- .../packages/react-agents/components/plugins/discord.tsx | 2 ++ .../packages/react-agents/types/react-agents.d.ts | 2 ++ 2 files changed, 4 insertions(+) diff --git a/packages/usdk/packages/upstreet-agent/packages/react-agents/components/plugins/discord.tsx b/packages/usdk/packages/upstreet-agent/packages/react-agents/components/plugins/discord.tsx index ba06c7629..4815e3278 100644 --- a/packages/usdk/packages/upstreet-agent/packages/react-agents/components/plugins/discord.tsx +++ b/packages/usdk/packages/upstreet-agent/packages/react-agents/components/plugins/discord.tsx @@ -14,6 +14,7 @@ export const Discord: React.FC = (props: DiscordProps) => { channels, dms, userWhitelist, + appId, } = props; const agent = useAgent(); const conversation = useConversation(); @@ -31,6 +32,7 @@ export const Discord: React.FC = (props: DiscordProps) => { agent, codecs, jwt: authToken, + appId, }; const discordBot = agent.discordManager.addDiscordBot(args); return () => { diff --git a/packages/usdk/packages/upstreet-agent/packages/react-agents/types/react-agents.d.ts b/packages/usdk/packages/upstreet-agent/packages/react-agents/types/react-agents.d.ts index f81439d4e..e6270f128 100644 --- a/packages/usdk/packages/upstreet-agent/packages/react-agents/types/react-agents.d.ts +++ b/packages/usdk/packages/upstreet-agent/packages/react-agents/types/react-agents.d.ts @@ -121,12 +121,14 @@ export type DiscordRoomSpec = RegExp | string; export type DiscordRoomSpecs = DiscordRoomSpec | DiscordRoomSpec[]; export type DiscordProps = { token: string; + appId: string; channels?: DiscordRoomSpecs; dms?: DiscordRoomSpecs; userWhitelist?: string[]; }; export type DiscordArgs = { token: string; + appId: string; channels: DiscordRoomSpec[]; dms: DiscordRoomSpec[]; userWhitelist: string[]; From 99a5aef3a6344af9af6e7968382ff7a4d109f43d Mon Sep 17 00:00:00 2001 From: Abdurrehman Subhani Date: Thu, 26 Dec 2024 12:44:50 +0500 Subject: [PATCH 02/13] add missing token and appId missing exceptions --- .../packages/react-agents/components/plugins/discord.tsx | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/packages/usdk/packages/upstreet-agent/packages/react-agents/components/plugins/discord.tsx b/packages/usdk/packages/upstreet-agent/packages/react-agents/components/plugins/discord.tsx index 4815e3278..8105eac55 100644 --- a/packages/usdk/packages/upstreet-agent/packages/react-agents/components/plugins/discord.tsx +++ b/packages/usdk/packages/upstreet-agent/packages/react-agents/components/plugins/discord.tsx @@ -24,6 +24,14 @@ export const Discord: React.FC = (props: DiscordProps) => { useEffect(() => { if (!conversation) { + + if (!token) { + throw new Error('Discord Bot token is required'); + } + if (!appId) { + throw new Error('Discord Bot appId is required'); + } + const args: DiscordArgs = { token, channels: channels ? (Array.isArray(channels) ? channels : [channels]) : [], From 2965ca6fc393ee6bece150feba704a7d188fade7 Mon Sep 17 00:00:00 2001 From: Abdurrehman Subhani Date: Thu, 26 Dec 2024 12:47:27 +0500 Subject: [PATCH 03/13] add appId attribute in discord manager and client --- .../packages/react-agents/classes/discord-manager.ts | 3 +++ .../packages/react-agents/lib/discord/discord-client.js | 3 +++ 2 files changed, 6 insertions(+) diff --git a/packages/usdk/packages/upstreet-agent/packages/react-agents/classes/discord-manager.ts b/packages/usdk/packages/upstreet-agent/packages/react-agents/classes/discord-manager.ts index 52e5d37eb..390a03b09 100644 --- a/packages/usdk/packages/upstreet-agent/packages/react-agents/classes/discord-manager.ts +++ b/packages/usdk/packages/upstreet-agent/packages/react-agents/classes/discord-manager.ts @@ -126,6 +126,7 @@ const bindOutgoing = ({ export class DiscordBot extends EventTarget { token: string; + appId: string; channels: DiscordRoomSpec[]; dms: DiscordRoomSpec[]; userWhitelist: string[]; @@ -139,6 +140,7 @@ export class DiscordBot extends EventTarget { // arguments const { token, + appId, channels, dms, userWhitelist, @@ -164,6 +166,7 @@ export class DiscordBot extends EventTarget { // initialize discord bot client const discordBotClient = new DiscordBotClient({ token, + appId, codecs, jwt, name, diff --git a/packages/usdk/packages/upstreet-agent/packages/react-agents/lib/discord/discord-client.js b/packages/usdk/packages/upstreet-agent/packages/react-agents/lib/discord/discord-client.js index 4089113fc..98a5ecaed 100644 --- a/packages/usdk/packages/upstreet-agent/packages/react-agents/lib/discord/discord-client.js +++ b/packages/usdk/packages/upstreet-agent/packages/react-agents/lib/discord/discord-client.js @@ -352,6 +352,7 @@ export class DiscordOutput extends EventTarget { export class DiscordBotClient extends EventTarget { token; codecs; + appId; ws = null; input = null; // going from the agent into the discord bot output = null; // coming out of the discord bot to the agent @@ -361,6 +362,7 @@ export class DiscordBotClient extends EventTarget { constructor({ token, + appId, codecs, jwt, name, @@ -379,6 +381,7 @@ export class DiscordBotClient extends EventTarget { this.token = token; this.codecs = codecs; + this.appId = appId; this.input = new DiscordInput(); this.output = new DiscordOutput({ codecs, From a000641e733385708edb6004c0033b1954b50ca2 Mon Sep 17 00:00:00 2001 From: Abdurrehman Subhani Date: Thu, 26 Dec 2024 12:56:12 +0500 Subject: [PATCH 04/13] read and pass appId prop in features renderer --- .../packages/react-agents/util/agent-features-renderer.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/usdk/packages/upstreet-agent/packages/react-agents/util/agent-features-renderer.tsx b/packages/usdk/packages/upstreet-agent/packages/react-agents/util/agent-features-renderer.tsx index e78e27993..7e1989566 100644 --- a/packages/usdk/packages/upstreet-agent/packages/react-agents/util/agent-features-renderer.tsx +++ b/packages/usdk/packages/upstreet-agent/packages/react-agents/util/agent-features-renderer.tsx @@ -287,11 +287,11 @@ export const featureRenderers = { ); }, - discord: ({token, channels}) => { + discord: ({token, appId, channels}) => { if (token) { channels = channels && channels.map((c: string) => c.trim()).filter(Boolean); return ( - + ); } else { return null; From 6b08665253859d181add2b6ba6d8bec6fa436ad0 Mon Sep 17 00:00:00 2001 From: Abdurrehman Subhani Date: Thu, 26 Dec 2024 13:18:47 +0500 Subject: [PATCH 05/13] add agentSpecs attribute to the conversation --- .../classes/conversation-object.ts | 21 +++++++++++++++++++ .../components/util/default-components.tsx | 6 +----- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/packages/usdk/packages/upstreet-agent/packages/react-agents/classes/conversation-object.ts b/packages/usdk/packages/upstreet-agent/packages/react-agents/classes/conversation-object.ts index 6cbab9d2d..9cbb4a64c 100644 --- a/packages/usdk/packages/upstreet-agent/packages/react-agents/classes/conversation-object.ts +++ b/packages/usdk/packages/upstreet-agent/packages/react-agents/classes/conversation-object.ts @@ -19,6 +19,7 @@ import { loadMessagesFromDatabase } from '../util/loadMessagesFromDatabase'; export class ConversationObject extends EventTarget { agent: ActiveAgentObject; // the current agent + agentSpecs: object; // the current agent's spec agentsMap: Map; // note: agents does not include the current agent scene: SceneObject | null; getHash: GetHashFn; // XXX this can be a string, since conversation hashes do not change (?) @@ -46,6 +47,11 @@ export class ConversationObject extends EventTarget { this.scene = scene; this.getHash = getHash; this.mentionsRegex = mentionsRegex; + this.agentSpecs = { + id: agent.id, + name: agent.name, + bio: agent.bio, + }; this.messageCache = new MessageCacheConstructor({ loader: async () => { const supabase = this.agent.appContextValue.useSupabase(); @@ -97,6 +103,21 @@ export class ConversationObject extends EventTarget { getAgent() { return this.agent; } + + setAgentSpec(agentSpec: object) { + this.agentSpecs = agentSpec; + } + + getAgentSpec() { + return this.agentSpecs; + } + + appendAgentSpec(agentSpec: object) { + this.agentSpecs = { + ...this.agentSpecs, + ...agentSpec, + }; + } // setAgent(agent: ActiveAgentObject) { // this.agent = agent; // } diff --git a/packages/usdk/packages/upstreet-agent/packages/react-agents/components/util/default-components.tsx b/packages/usdk/packages/upstreet-agent/packages/react-agents/components/util/default-components.tsx index 364df23f2..0f4a89729 100644 --- a/packages/usdk/packages/upstreet-agent/packages/react-agents/components/util/default-components.tsx +++ b/packages/usdk/packages/upstreet-agent/packages/react-agents/components/util/default-components.tsx @@ -122,11 +122,7 @@ const CharactersPrompt = () => { const bio = usePersonality(); if (conversation) { const agents = conversation.getAgents(); - const currentAgentSpec = { - id: agent.id, - name, - bio, - }; + const currentAgentSpec = conversation.getAgentSpec(); const agentSpecs = agents.map((agent) => { const agentSpec = agent.getPlayerSpec() as any; return { From 83dbed668814764a6ae9cef83759e5534d2ea601 Mon Sep 17 00:00:00 2001 From: Abdurrehman Subhani Date: Thu, 26 Dec 2024 13:21:29 +0500 Subject: [PATCH 06/13] remove discord appId integration updates from branch --- .../packages/react-agents/classes/discord-manager.ts | 3 --- .../packages/react-agents/components/plugins/discord.tsx | 9 --------- .../packages/react-agents/lib/discord/discord-client.js | 3 --- .../packages/react-agents/types/react-agents.d.ts | 2 -- .../react-agents/util/agent-features-renderer.tsx | 4 ++-- 5 files changed, 2 insertions(+), 19 deletions(-) diff --git a/packages/usdk/packages/upstreet-agent/packages/react-agents/classes/discord-manager.ts b/packages/usdk/packages/upstreet-agent/packages/react-agents/classes/discord-manager.ts index 390a03b09..52e5d37eb 100644 --- a/packages/usdk/packages/upstreet-agent/packages/react-agents/classes/discord-manager.ts +++ b/packages/usdk/packages/upstreet-agent/packages/react-agents/classes/discord-manager.ts @@ -126,7 +126,6 @@ const bindOutgoing = ({ export class DiscordBot extends EventTarget { token: string; - appId: string; channels: DiscordRoomSpec[]; dms: DiscordRoomSpec[]; userWhitelist: string[]; @@ -140,7 +139,6 @@ export class DiscordBot extends EventTarget { // arguments const { token, - appId, channels, dms, userWhitelist, @@ -166,7 +164,6 @@ export class DiscordBot extends EventTarget { // initialize discord bot client const discordBotClient = new DiscordBotClient({ token, - appId, codecs, jwt, name, diff --git a/packages/usdk/packages/upstreet-agent/packages/react-agents/components/plugins/discord.tsx b/packages/usdk/packages/upstreet-agent/packages/react-agents/components/plugins/discord.tsx index 8105eac55..2301a342e 100644 --- a/packages/usdk/packages/upstreet-agent/packages/react-agents/components/plugins/discord.tsx +++ b/packages/usdk/packages/upstreet-agent/packages/react-agents/components/plugins/discord.tsx @@ -24,14 +24,6 @@ export const Discord: React.FC = (props: DiscordProps) => { useEffect(() => { if (!conversation) { - - if (!token) { - throw new Error('Discord Bot token is required'); - } - if (!appId) { - throw new Error('Discord Bot appId is required'); - } - const args: DiscordArgs = { token, channels: channels ? (Array.isArray(channels) ? channels : [channels]) : [], @@ -40,7 +32,6 @@ export const Discord: React.FC = (props: DiscordProps) => { agent, codecs, jwt: authToken, - appId, }; const discordBot = agent.discordManager.addDiscordBot(args); return () => { diff --git a/packages/usdk/packages/upstreet-agent/packages/react-agents/lib/discord/discord-client.js b/packages/usdk/packages/upstreet-agent/packages/react-agents/lib/discord/discord-client.js index 98a5ecaed..4089113fc 100644 --- a/packages/usdk/packages/upstreet-agent/packages/react-agents/lib/discord/discord-client.js +++ b/packages/usdk/packages/upstreet-agent/packages/react-agents/lib/discord/discord-client.js @@ -352,7 +352,6 @@ export class DiscordOutput extends EventTarget { export class DiscordBotClient extends EventTarget { token; codecs; - appId; ws = null; input = null; // going from the agent into the discord bot output = null; // coming out of the discord bot to the agent @@ -362,7 +361,6 @@ export class DiscordBotClient extends EventTarget { constructor({ token, - appId, codecs, jwt, name, @@ -381,7 +379,6 @@ export class DiscordBotClient extends EventTarget { this.token = token; this.codecs = codecs; - this.appId = appId; this.input = new DiscordInput(); this.output = new DiscordOutput({ codecs, diff --git a/packages/usdk/packages/upstreet-agent/packages/react-agents/types/react-agents.d.ts b/packages/usdk/packages/upstreet-agent/packages/react-agents/types/react-agents.d.ts index e6270f128..f81439d4e 100644 --- a/packages/usdk/packages/upstreet-agent/packages/react-agents/types/react-agents.d.ts +++ b/packages/usdk/packages/upstreet-agent/packages/react-agents/types/react-agents.d.ts @@ -121,14 +121,12 @@ export type DiscordRoomSpec = RegExp | string; export type DiscordRoomSpecs = DiscordRoomSpec | DiscordRoomSpec[]; export type DiscordProps = { token: string; - appId: string; channels?: DiscordRoomSpecs; dms?: DiscordRoomSpecs; userWhitelist?: string[]; }; export type DiscordArgs = { token: string; - appId: string; channels: DiscordRoomSpec[]; dms: DiscordRoomSpec[]; userWhitelist: string[]; diff --git a/packages/usdk/packages/upstreet-agent/packages/react-agents/util/agent-features-renderer.tsx b/packages/usdk/packages/upstreet-agent/packages/react-agents/util/agent-features-renderer.tsx index 7e1989566..e78e27993 100644 --- a/packages/usdk/packages/upstreet-agent/packages/react-agents/util/agent-features-renderer.tsx +++ b/packages/usdk/packages/upstreet-agent/packages/react-agents/util/agent-features-renderer.tsx @@ -287,11 +287,11 @@ export const featureRenderers = { ); }, - discord: ({token, appId, channels}) => { + discord: ({token, channels}) => { if (token) { channels = channels && channels.map((c: string) => c.trim()).filter(Boolean); return ( - + ); } else { return null; From 6c88a77a09e40f013c9ff3b93bdd8631332a8055 Mon Sep 17 00:00:00 2001 From: Abdurrehman Subhani Date: Thu, 26 Dec 2024 13:21:57 +0500 Subject: [PATCH 07/13] remove appId from discord.tsx --- .../packages/react-agents/components/plugins/discord.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/usdk/packages/upstreet-agent/packages/react-agents/components/plugins/discord.tsx b/packages/usdk/packages/upstreet-agent/packages/react-agents/components/plugins/discord.tsx index 2301a342e..ba06c7629 100644 --- a/packages/usdk/packages/upstreet-agent/packages/react-agents/components/plugins/discord.tsx +++ b/packages/usdk/packages/upstreet-agent/packages/react-agents/components/plugins/discord.tsx @@ -14,7 +14,6 @@ export const Discord: React.FC = (props: DiscordProps) => { channels, dms, userWhitelist, - appId, } = props; const agent = useAgent(); const conversation = useConversation(); From 573d8b6fc7306a8fd50090b397b2140ddf13dffd Mon Sep 17 00:00:00 2001 From: Abdurrehman Subhani Date: Thu, 26 Dec 2024 13:24:28 +0500 Subject: [PATCH 08/13] rename agentSpec to currentAgentSpec to add clarity --- .../classes/conversation-object.ts | 18 +++++++++--------- .../components/util/default-components.tsx | 2 +- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/packages/usdk/packages/upstreet-agent/packages/react-agents/classes/conversation-object.ts b/packages/usdk/packages/upstreet-agent/packages/react-agents/classes/conversation-object.ts index 9cbb4a64c..50bf5df84 100644 --- a/packages/usdk/packages/upstreet-agent/packages/react-agents/classes/conversation-object.ts +++ b/packages/usdk/packages/upstreet-agent/packages/react-agents/classes/conversation-object.ts @@ -19,7 +19,7 @@ import { loadMessagesFromDatabase } from '../util/loadMessagesFromDatabase'; export class ConversationObject extends EventTarget { agent: ActiveAgentObject; // the current agent - agentSpecs: object; // the current agent's spec + currentAgentSpecs: object; // the current agent's spec agentsMap: Map; // note: agents does not include the current agent scene: SceneObject | null; getHash: GetHashFn; // XXX this can be a string, since conversation hashes do not change (?) @@ -47,7 +47,7 @@ export class ConversationObject extends EventTarget { this.scene = scene; this.getHash = getHash; this.mentionsRegex = mentionsRegex; - this.agentSpecs = { + this.currentAgentSpecs = { id: agent.id, name: agent.name, bio: agent.bio, @@ -104,17 +104,17 @@ export class ConversationObject extends EventTarget { return this.agent; } - setAgentSpec(agentSpec: object) { - this.agentSpecs = agentSpec; + setCurrentAgentSpecs(agentSpec: object) { + this.currentAgentSpecs = agentSpec; } - getAgentSpec() { - return this.agentSpecs; + getCurrentAgentSpecs() { + return this.currentAgentSpecs; } - appendAgentSpec(agentSpec: object) { - this.agentSpecs = { - ...this.agentSpecs, + appendCurrentAgentSpecs(agentSpec: object) { + this.currentAgentSpecs = { + ...this.currentAgentSpecs, ...agentSpec, }; } diff --git a/packages/usdk/packages/upstreet-agent/packages/react-agents/components/util/default-components.tsx b/packages/usdk/packages/upstreet-agent/packages/react-agents/components/util/default-components.tsx index 0f4a89729..cf933fe12 100644 --- a/packages/usdk/packages/upstreet-agent/packages/react-agents/components/util/default-components.tsx +++ b/packages/usdk/packages/upstreet-agent/packages/react-agents/components/util/default-components.tsx @@ -122,7 +122,7 @@ const CharactersPrompt = () => { const bio = usePersonality(); if (conversation) { const agents = conversation.getAgents(); - const currentAgentSpec = conversation.getAgentSpec(); + const currentAgentSpec = conversation.getCurrentAgentSpecs(); const agentSpecs = agents.map((agent) => { const agentSpec = agent.getPlayerSpec() as any; return { From 2c86880fac3ddd816b0a5ca777f642ce52be72de Mon Sep 17 00:00:00 2001 From: Abdurrehman Subhani Date: Thu, 26 Dec 2024 15:25:47 +0500 Subject: [PATCH 09/13] add appId to discord component and types --- .../packages/react-agents/components/plugins/discord.tsx | 3 +++ .../packages/react-agents/types/react-agents.d.ts | 2 ++ 2 files changed, 5 insertions(+) diff --git a/packages/usdk/packages/upstreet-agent/packages/react-agents/components/plugins/discord.tsx b/packages/usdk/packages/upstreet-agent/packages/react-agents/components/plugins/discord.tsx index ba06c7629..0661c08df 100644 --- a/packages/usdk/packages/upstreet-agent/packages/react-agents/components/plugins/discord.tsx +++ b/packages/usdk/packages/upstreet-agent/packages/react-agents/components/plugins/discord.tsx @@ -11,6 +11,7 @@ import { export const Discord: React.FC = (props: DiscordProps) => { const { token, + appId, channels, dms, userWhitelist, @@ -25,6 +26,7 @@ export const Discord: React.FC = (props: DiscordProps) => { if (!conversation) { const args: DiscordArgs = { token, + appId, channels: channels ? (Array.isArray(channels) ? channels : [channels]) : [], dms: dms ? (Array.isArray(dms) ? dms : [dms]) : [], userWhitelist, @@ -39,6 +41,7 @@ export const Discord: React.FC = (props: DiscordProps) => { } }, [ token, + appId, JSON.stringify(channels), JSON.stringify(dms), JSON.stringify(userWhitelist), diff --git a/packages/usdk/packages/upstreet-agent/packages/react-agents/types/react-agents.d.ts b/packages/usdk/packages/upstreet-agent/packages/react-agents/types/react-agents.d.ts index f81439d4e..e6270f128 100644 --- a/packages/usdk/packages/upstreet-agent/packages/react-agents/types/react-agents.d.ts +++ b/packages/usdk/packages/upstreet-agent/packages/react-agents/types/react-agents.d.ts @@ -121,12 +121,14 @@ export type DiscordRoomSpec = RegExp | string; export type DiscordRoomSpecs = DiscordRoomSpec | DiscordRoomSpec[]; export type DiscordProps = { token: string; + appId: string; channels?: DiscordRoomSpecs; dms?: DiscordRoomSpecs; userWhitelist?: string[]; }; export type DiscordArgs = { token: string; + appId: string; channels: DiscordRoomSpec[]; dms: DiscordRoomSpec[]; userWhitelist: string[]; From 20c8cc2fa5523f8091ca9a9bdccc4d4a0eff40dd Mon Sep 17 00:00:00 2001 From: Abdurrehman Subhani Date: Thu, 26 Dec 2024 15:28:30 +0500 Subject: [PATCH 10/13] add appId to feat renderer and discord client --- .../packages/react-agents/classes/discord-manager.ts | 4 ++++ .../packages/react-agents/util/agent-features-renderer.tsx | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/usdk/packages/upstreet-agent/packages/react-agents/classes/discord-manager.ts b/packages/usdk/packages/upstreet-agent/packages/react-agents/classes/discord-manager.ts index 52e5d37eb..cd11228aa 100644 --- a/packages/usdk/packages/upstreet-agent/packages/react-agents/classes/discord-manager.ts +++ b/packages/usdk/packages/upstreet-agent/packages/react-agents/classes/discord-manager.ts @@ -126,6 +126,7 @@ const bindOutgoing = ({ export class DiscordBot extends EventTarget { token: string; + appId: string; channels: DiscordRoomSpec[]; dms: DiscordRoomSpec[]; userWhitelist: string[]; @@ -139,6 +140,7 @@ export class DiscordBot extends EventTarget { // arguments const { token, + appId, channels, dms, userWhitelist, @@ -147,6 +149,7 @@ export class DiscordBot extends EventTarget { jwt, } = args; this.token = token; + this.appId = appId; this.channels = channels; this.dms = dms; this.userWhitelist = userWhitelist; @@ -164,6 +167,7 @@ export class DiscordBot extends EventTarget { // initialize discord bot client const discordBotClient = new DiscordBotClient({ token, + appId, codecs, jwt, name, diff --git a/packages/usdk/packages/upstreet-agent/packages/react-agents/util/agent-features-renderer.tsx b/packages/usdk/packages/upstreet-agent/packages/react-agents/util/agent-features-renderer.tsx index e78e27993..7e1989566 100644 --- a/packages/usdk/packages/upstreet-agent/packages/react-agents/util/agent-features-renderer.tsx +++ b/packages/usdk/packages/upstreet-agent/packages/react-agents/util/agent-features-renderer.tsx @@ -287,11 +287,11 @@ export const featureRenderers = { ); }, - discord: ({token, channels}) => { + discord: ({token, appId, channels}) => { if (token) { channels = channels && channels.map((c: string) => c.trim()).filter(Boolean); return ( - + ); } else { return null; From 72511ae22e162ac2a1b65cc2a0049c4b8ae60e55 Mon Sep 17 00:00:00 2001 From: Abdurrehman Subhani Date: Thu, 26 Dec 2024 15:34:50 +0500 Subject: [PATCH 11/13] add mentionId to current agent's specs --- .../packages/react-agents/classes/discord-manager.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/packages/usdk/packages/upstreet-agent/packages/react-agents/classes/discord-manager.ts b/packages/usdk/packages/upstreet-agent/packages/react-agents/classes/discord-manager.ts index cd11228aa..7d32f4617 100644 --- a/packages/usdk/packages/upstreet-agent/packages/react-agents/classes/discord-manager.ts +++ b/packages/usdk/packages/upstreet-agent/packages/react-agents/classes/discord-manager.ts @@ -259,6 +259,11 @@ export class DiscordBot extends EventTarget { mentionsRegex: discordMentionRegex, }); + conversation.appendCurrentAgentSpecs({ + mentionId: appId, + }); + + this.agent.conversationManager.addConversation(conversation); this.channelConversations.set(channelId, conversation); @@ -306,6 +311,10 @@ export class DiscordBot extends EventTarget { mentionsRegex: discordMentionRegex, }); + conversation.appendCurrentAgentSpecs({ + mentionId: appId, + }); + this.agent.conversationManager.addConversation(conversation); this.dmConversations.set(userId, conversation); From 0200cc05dfc1634ec7cedabb5b9281242d7fd47e Mon Sep 17 00:00:00 2001 From: Abdurrehman Subhani Date: Thu, 26 Dec 2024 15:53:26 +0500 Subject: [PATCH 12/13] add missing agentJson to active agent json --- .../packages/react-agents/classes/active-agent-object.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/usdk/packages/upstreet-agent/packages/react-agents/classes/active-agent-object.ts b/packages/usdk/packages/upstreet-agent/packages/react-agents/classes/active-agent-object.ts index c5b32cf51..756fb9618 100644 --- a/packages/usdk/packages/upstreet-agent/packages/react-agents/classes/active-agent-object.ts +++ b/packages/usdk/packages/upstreet-agent/packages/react-agents/classes/active-agent-object.ts @@ -44,6 +44,7 @@ import { AgentRegistry } from './render-registry'; export class ActiveAgentObject extends AgentObject { // arguments + agentJson: AgentObject; config: AgentObjectData; appContextValue: AppContextValue; registry: AgentRegistry; @@ -75,6 +76,7 @@ export class ActiveAgentObject extends AgentObject { // this.config = config; + this.agentJson = new AgentObject(config); this.appContextValue = appContextValue; this.registry = registry; From a0ee2c236851d9f2608b3f28be141f86046b4478 Mon Sep 17 00:00:00 2001 From: Abdurrehman Subhani Date: Thu, 26 Dec 2024 16:17:10 +0500 Subject: [PATCH 13/13] use Player for agent in conversation to maintain standardized logic --- .../classes/conversation-object.ts | 24 +++++++++---------- .../components/util/default-components.tsx | 20 +++++++--------- 2 files changed, 21 insertions(+), 23 deletions(-) diff --git a/packages/usdk/packages/upstreet-agent/packages/react-agents/classes/conversation-object.ts b/packages/usdk/packages/upstreet-agent/packages/react-agents/classes/conversation-object.ts index 50bf5df84..b9d067c79 100644 --- a/packages/usdk/packages/upstreet-agent/packages/react-agents/classes/conversation-object.ts +++ b/packages/usdk/packages/upstreet-agent/packages/react-agents/classes/conversation-object.ts @@ -19,7 +19,7 @@ import { loadMessagesFromDatabase } from '../util/loadMessagesFromDatabase'; export class ConversationObject extends EventTarget { agent: ActiveAgentObject; // the current agent - currentAgentSpecs: object; // the current agent's spec + currentAgentPlayer: Player; // the current agent's player agentsMap: Map; // note: agents does not include the current agent scene: SceneObject | null; getHash: GetHashFn; // XXX this can be a string, since conversation hashes do not change (?) @@ -47,11 +47,11 @@ export class ConversationObject extends EventTarget { this.scene = scene; this.getHash = getHash; this.mentionsRegex = mentionsRegex; - this.currentAgentSpecs = { + this.currentAgentPlayer = new Player(agent.id, { id: agent.id, - name: agent.name, - bio: agent.bio, - }; + name: agent.agentJson.name, + bio: agent.agentJson.bio, + }); this.messageCache = new MessageCacheConstructor({ loader: async () => { const supabase = this.agent.appContextValue.useSupabase(); @@ -104,19 +104,19 @@ export class ConversationObject extends EventTarget { return this.agent; } - setCurrentAgentSpecs(agentSpec: object) { - this.currentAgentSpecs = agentSpec; + setCurrentAgentPlayer(player: Player) { + this.currentAgentPlayer = player; } - getCurrentAgentSpecs() { - return this.currentAgentSpecs; + getCurrentAgentPlayer() { + return this.currentAgentPlayer; } appendCurrentAgentSpecs(agentSpec: object) { - this.currentAgentSpecs = { - ...this.currentAgentSpecs, + this.currentAgentPlayer.setPlayerSpec({ + ...this.currentAgentPlayer.getPlayerSpec(), ...agentSpec, - }; + }); } // setAgent(agent: ActiveAgentObject) { // this.agent = agent; diff --git a/packages/usdk/packages/upstreet-agent/packages/react-agents/components/util/default-components.tsx b/packages/usdk/packages/upstreet-agent/packages/react-agents/components/util/default-components.tsx index cf933fe12..86e3bf93c 100644 --- a/packages/usdk/packages/upstreet-agent/packages/react-agents/components/util/default-components.tsx +++ b/packages/usdk/packages/upstreet-agent/packages/react-agents/components/util/default-components.tsx @@ -117,25 +117,23 @@ const ScenePrompt = () => { }; const CharactersPrompt = () => { const conversation = useConversation(); - const agent = useAgent(); - const name = useName(); - const bio = usePersonality(); if (conversation) { const agents = conversation.getAgents(); - const currentAgentSpec = conversation.getCurrentAgentSpecs(); + const currentAgentPlayerSpec = conversation.getCurrentAgentPlayer().getPlayerSpec(); const agentSpecs = agents.map((agent) => { - const agentSpec = agent.getPlayerSpec() as any; - return { - name: agentSpec?.name, + const agentSpecs = agent.getPlayerSpec() as any; + const agentSpec = { id: agent.playerId, - bio: agentSpec?.bio, - }; + name: agentSpecs?.name, + bio: agentSpecs?.bio, + } + return agentSpec; }); const formatAgent = (agent: any) => { return [ - `Name: ${agent.name}`, `UserId: ${agent.id}`, + `Name: ${agent.name}`, `Bio: ${agent.bio}`, ].join('\n'); }; @@ -146,7 +144,7 @@ const CharactersPrompt = () => { # Your Character ` + '\n\n' + - formatAgent(currentAgentSpec) + + formatAgent(currentAgentPlayerSpec) + (agents.length > 0 ? ( '\n\n' +