Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import { AgentRegistry } from './render-registry';

export class ActiveAgentObject extends AgentObject {
// arguments
agentJson: AgentObject;
config: AgentObjectData;
appContextValue: AppContextValue;
registry: AgentRegistry;
Expand Down Expand Up @@ -75,6 +76,7 @@ export class ActiveAgentObject extends AgentObject {
//

this.config = config;
this.agentJson = new AgentObject(config);
this.appContextValue = appContextValue;
this.registry = registry;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { loadMessagesFromDatabase } from '../util/loadMessagesFromDatabase';

export class ConversationObject extends EventTarget {
agent: ActiveAgentObject; // the current agent
currentAgentPlayer: Player; // the current agent's player
agentsMap: Map<string, Player>; // 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 (?)
Expand Down Expand Up @@ -46,6 +47,11 @@ export class ConversationObject extends EventTarget {
this.scene = scene;
this.getHash = getHash;
this.mentionsRegex = mentionsRegex;
this.currentAgentPlayer = new Player(agent.id, {
id: agent.id,
name: agent.agentJson.name,
bio: agent.agentJson.bio,
});
this.messageCache = new MessageCacheConstructor({
loader: async () => {
const supabase = this.agent.appContextValue.useSupabase();
Expand Down Expand Up @@ -97,6 +103,21 @@ export class ConversationObject extends EventTarget {
getAgent() {
return this.agent;
}

setCurrentAgentPlayer(player: Player) {
this.currentAgentPlayer = player;
}

getCurrentAgentPlayer() {
return this.currentAgentPlayer;
}

appendCurrentAgentSpecs(agentSpec: object) {
this.currentAgentPlayer.setPlayerSpec({
...this.currentAgentPlayer.getPlayerSpec(),
...agentSpec,
});
}
// setAgent(agent: ActiveAgentObject) {
// this.agent = agent;
// }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ const bindOutgoing = ({

export class DiscordBot extends EventTarget {
token: string;
appId: string;
channels: DiscordRoomSpec[];
dms: DiscordRoomSpec[];
userWhitelist: string[];
Expand All @@ -139,6 +140,7 @@ export class DiscordBot extends EventTarget {
// arguments
const {
token,
appId,
channels,
dms,
userWhitelist,
Expand All @@ -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;
Expand All @@ -164,6 +167,7 @@ export class DiscordBot extends EventTarget {
// initialize discord bot client
const discordBotClient = new DiscordBotClient({
token,
appId,
codecs,
jwt,
name,
Expand Down Expand Up @@ -255,6 +259,11 @@ export class DiscordBot extends EventTarget {
mentionsRegex: discordMentionRegex,
});

conversation.appendCurrentAgentSpecs({
mentionId: appId,
});


this.agent.conversationManager.addConversation(conversation);
this.channelConversations.set(channelId, conversation);

Expand Down Expand Up @@ -302,6 +311,10 @@ export class DiscordBot extends EventTarget {
mentionsRegex: discordMentionRegex,
});

conversation.appendCurrentAgentSpecs({
mentionId: appId,
});

this.agent.conversationManager.addConversation(conversation);
this.dmConversations.set(userId, conversation);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
export const Discord: React.FC<DiscordProps> = (props: DiscordProps) => {
const {
token,
appId,
channels,
dms,
userWhitelist,
Expand All @@ -25,6 +26,7 @@ export const Discord: React.FC<DiscordProps> = (props: DiscordProps) => {
if (!conversation) {
const args: DiscordArgs = {
token,
appId,
channels: channels ? (Array.isArray(channels) ? channels : [channels]) : [],
dms: dms ? (Array.isArray(dms) ? dms : [dms]) : [],
userWhitelist,
Expand All @@ -39,6 +41,7 @@ export const Discord: React.FC<DiscordProps> = (props: DiscordProps) => {
}
}, [
token,
appId,
JSON.stringify(channels),
JSON.stringify(dms),
JSON.stringify(userWhitelist),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,29 +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 = {
id: agent.id,
name,
bio,
};
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');
};
Expand All @@ -150,7 +144,7 @@ const CharactersPrompt = () => {
# Your Character
` +
'\n\n' +
formatAgent(currentAgentSpec) +
formatAgent(currentAgentPlayerSpec) +
(agents.length > 0
? (
'\n\n' +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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[];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,11 +287,11 @@ export const featureRenderers = {
<RateLimit maxUserMessages={maxUserMessages} maxUserMessagesTime={maxUserMessagesTime} message={message} />
);
},
discord: ({token, channels}) => {
discord: ({token, appId, channels}) => {
if (token) {
channels = channels && channels.map((c: string) => c.trim()).filter(Boolean);
return (
<Discord token={token} channels={channels} />
<Discord token={token} appId={appId} channels={channels} />
);
} else {
return null;
Expand Down