-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Basic agents private beta frontend
- Loading branch information
1 parent
cdad239
commit 69903f2
Showing
13 changed files
with
260 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,13 @@ | ||
import { boot } from 'quasar/wrappers'; | ||
import { client } from 'src/apis/subscriptions/services.gen'; | ||
import { client as agentsClient } from 'src/apis/agents/services.gen'; | ||
import { client as subscriptionsClient } from 'src/apis/subscriptions/services.gen'; | ||
import env from 'src/config/env'; | ||
|
||
export default boot(() => { | ||
client.setConfig({ | ||
subscriptionsClient.setConfig({ | ||
baseURL: env.LTAI_SUBSCRIPTIONS_API_URL, | ||
}); | ||
agentsClient.setConfig({ | ||
baseURL: env.LTAI_AGENTS_API_URL, | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
import { defineStore } from 'pinia'; | ||
import { | ||
getAgentPublicInfoAgentAgentIdGet, | ||
getAgentSecretAgentAgentIdSecretGet, | ||
getAgentSecretMessageAgentAgentIdSecretMessageGet, | ||
} from 'src/apis/agents'; | ||
import { UIAgent } from 'src/types/agent'; | ||
import { useAccountStore } from 'stores/account'; | ||
import { useSubscriptionStore } from 'stores/subscription'; | ||
|
||
type AgentState = { | ||
agents: UIAgent[]; | ||
isLoaded: boolean; | ||
}; | ||
|
||
export const useAgentStore = defineStore('agents', { | ||
state: (): AgentState => ({ | ||
agents: [], | ||
isLoaded: false, | ||
}), | ||
actions: { | ||
async load() { | ||
const { subscriptions } = useSubscriptionStore(); | ||
const { account } = useAccountStore(); | ||
|
||
if (account === null) { | ||
this.isLoaded = true; | ||
return; | ||
} | ||
|
||
const activeAgentSubscriptions = subscriptions.filter((sub) => sub.is_active && sub.type === 'agent'); | ||
|
||
if (activeAgentSubscriptions.length === 0) { | ||
this.isLoaded = true; | ||
return; | ||
} | ||
|
||
this.agents = ( | ||
await Promise.all( | ||
activeAgentSubscriptions.map(async (agentSubscription) => { | ||
const agent = await getAgentPublicInfoAgentAgentIdGet({ | ||
path: { agent_id: agentSubscription.id }, | ||
}); | ||
return agent.data; | ||
}), | ||
) | ||
).filter((agent) => agent !== undefined); | ||
console.log(this.agents); | ||
|
||
this.isLoaded = true; | ||
}, | ||
|
||
async getAgentSecret(agentId: string) { | ||
const { signMessage } = useAccountStore(); | ||
|
||
const messageResponse = await getAgentSecretMessageAgentAgentIdSecretMessageGet({ path: { agent_id: agentId } }); | ||
|
||
if (messageResponse.data === undefined) { | ||
throw new Error( | ||
messageResponse.error.detail?.toString() ?? 'Unable to fetch the message to sign to get the agent secret', | ||
); | ||
} | ||
|
||
const signature = await signMessage(messageResponse.data.message); | ||
|
||
const secretResponse = await getAgentSecretAgentAgentIdSecretGet({ | ||
path: { agent_id: agentId }, | ||
query: { | ||
signature, | ||
}, | ||
}); | ||
|
||
// TODO: handle errors in the call to this function | ||
if (secretResponse.data === undefined) { | ||
throw new Error(secretResponse.error.detail?.toString() ?? 'Unable to get the agent secret'); | ||
} | ||
|
||
this.agents = this.agents.map((agent) => { | ||
if (agent.id === agentId) { | ||
return { ...agent, secret: secretResponse.data.secret }; | ||
} | ||
return agent; | ||
}); | ||
}, | ||
}, | ||
}); |
Oops, something went wrong.