Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Permissions, 429 handling, other fixes #1375

Merged
merged 52 commits into from
Nov 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
22dd814
adding close spell after rename
Emmyn5600 Oct 10, 2023
b900be5
npm install axios-retry
Knar33 Oct 19, 2023
a0a2a4d
exponential retry with 5 retries
Knar33 Oct 19, 2023
428b4f7
only retry on 429
Knar33 Oct 19, 2023
c2e385d
error.code is not the http response code
Knar33 Oct 19, 2023
c2136f8
added BACKOFF_RETRY_LIMIT env variable
Knar33 Oct 20, 2023
21c2b62
seems like an error (this is never true)
Knar33 Oct 24, 2023
0480f95
use discord unique user id instead of username
Knar33 Oct 24, 2023
fb10f53
Remove console log
parzival418 Oct 30, 2023
6023c9d
Move track google AI usage into result block
parzival418 Oct 30, 2023
735a276
Add feathers permissions package
parzival418 Oct 30, 2023
afdf2db
Add sessionId to module
parzival418 Oct 30, 2023
613c5f0
Pass session id into spellrunner
parzival418 Oct 30, 2023
05c43d0
Add session id to remote plugin emit args
parzival418 Oct 30, 2023
4961b2e
Add sessionId to module
parzival418 Oct 30, 2023
bdbb01f
Add session id to module context type
parzival418 Oct 30, 2023
6ecb6cd
Add session id from payload into socket params
parzival418 Oct 30, 2023
d56ee95
Handle sending events to sessionId if it exists in channels
parzival418 Oct 30, 2023
23321eb
Use agent commander in agent run service class function
parzival418 Oct 30, 2023
cd0d92b
Require a role to access the API
parzival418 Oct 30, 2023
a964a71
Modify agent commander to use agent or agentId and sessionid
parzival418 Oct 30, 2023
ec3e0a7
Pass sessionId down into runComponent
parzival418 Oct 30, 2023
8c35e4d
Add permissions to agentImage
parzival418 Oct 30, 2023
ae392cd
Add permissions to the rest of the services
parzival418 Oct 30, 2023
2510347
Fix permissions
parzival418 Oct 30, 2023
579d2ab
changes output node logging to be more descriptive
Oct 30, 2023
818f95c
Merge pull request #1372 from Oneirocom/benbot/quick-output-log-fix
benbot Oct 30, 2023
a06d941
Merge pull request #1366 from Oneirocom/discord-snowflake
benbot Oct 30, 2023
0c1d60f
Merge pull request #1363 from Oneirocom/429
benbot Oct 30, 2023
4a09403
Add log env to root logger creation
parzival418 Oct 30, 2023
6573556
Pass down spellId propertly to run agent commander
parzival418 Oct 30, 2023
7e9abd0
Add permissions to incoming API calls for permissioning full access c…
parzival418 Oct 30, 2023
b6810b0
Add permissions to agent HTTP service
parzival418 Oct 30, 2023
4101551
Improve logging. Got session ID channel routing to work.
parzival418 Oct 31, 2023
180f01b
log fix
Oct 31, 2023
d444b26
Merge pull request #1373 from Oneirocom/benbot/log-fix
benbot Oct 31, 2023
9d8e7d5
Pass in server environment on server initApp
parzival418 Oct 31, 2023
133610e
Add support for environment setter in initApp
parzival418 Oct 31, 2023
f9bf812
Remove embeddings and spell references in event emitting to client
parzival418 Oct 31, 2023
01ea86a
Don't publish events if they arent from the server
parzival418 Oct 31, 2023
e374007
Add a few more points of data from the remote plugin emitter
parzival418 Oct 31, 2023
8a0fb0e
fix eslint errors
Oct 31, 2023
b500d0b
fix eslint errors
Oct 31, 2023
ff50c80
Fix typescripot build errors by moving permissions library into the repo
parzival418 Oct 31, 2023
2934d7f
Merge
parzival418 Oct 31, 2023
871e278
Merge pull request #1371 from Oneirocom/permissions
benbot Oct 31, 2023
69e0d94
Merge pull request #1357 from Oneirocom/fix_rename_spell
benbot Oct 31, 2023
2278658
Remove console logs
parzival418 Nov 1, 2023
d2a19fb
Add some logging to spell runner class
parzival418 Nov 1, 2023
c02aa9e
Add logging to channels
parzival418 Nov 1, 2023
536c993
Add some traces to spell runner
parzival418 Nov 1, 2023
9550c51
Merge pull request #1374 from Oneirocom/playtest-fixes
benbot Nov 1, 2023
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
22 changes: 10 additions & 12 deletions apps/server/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,16 @@ import { getPinoTransport } from '@hyperdx/node-opentelemetry'
import { PRODUCTION } from '@magickml/config'

if (PRODUCTION) {
initLogger({
name: 'cloud-agent-worker',
transport: {
targets: [
getPinoTransport('info')
]
},
level: 'info',
})
initLogger({
name: 'cloud-agent-worker',
transport: {
targets: [getPinoTransport('info')]
},
level: 'info'
})
} else {
initLogger({ name: 'cloud-agent-worker' })
}
initLogger({ name: 'cloud-agent-worker' })
}
const logger = getLogger()

// log handle errors
Expand Down Expand Up @@ -69,7 +67,7 @@ const routes: Route[] = [...spells, ...apis, ...serverRoutes]
* form and multipart-json requests, and routes.
*/
async function init() {
await initApp()
await initApp('server')
await initAgentCommander()
// load plugins
await (async () => {
Expand Down
46 changes: 46 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@
"@use-gesture/react": "10.2.27",
"@welldone-software/why-did-you-render": "7.0.1",
"axios": "1.4.0",
"axios-retry": "^3.8.0",
"bullmq": "4.6.0",
"class-variance-authority": "^0.7.0",
"classnames": "2.3.2",
Expand All @@ -125,6 +126,7 @@
"ethers": "5.7.2",
"expletives": "0.1.5",
"express": "4.18.2",
"feathers-permissions": "^2.1.4",
"feathers-sync": "3.0.3",
"flatted": "3.2.7",
"flexlayout-react": "0.7.7",
Expand Down Expand Up @@ -206,7 +208,6 @@
"tailwindcss-animate": "^1.0.7",
"tesseract.js": "4.0.6",
"three": "^0.154.0",
"ts-node": "10.9.1",
"tslib": "^2.3.0",
"twitter-api-v2": "1.14.3",
"typechat": "^0.0.10",
Expand Down
3 changes: 3 additions & 0 deletions packages/agents/src/lib/Agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ export class Agent implements AgentInterface {

async runWorker(job: Job<AgentRunJob>) {
// the job name is the agent id. Only run if the agent id matches.
this.logger.debug('running worker', { id: this.id, data: job.data })
if (this.id !== job.data.agentId) return

const { data } = job
Expand Down Expand Up @@ -235,6 +236,7 @@ export class Agent implements AgentInterface {
...this.secrets,
...data.secrets,
},
sessionId: data?.sessionId,
publicVariables: this.publicVariables,
runSubspell: data.runSubspell,
app,
Expand Down Expand Up @@ -269,6 +271,7 @@ export class Agent implements AgentInterface {

export interface AgentRunJob {
inputs: MagickSpellInput
sessionId?: string
jobId: string
agentId: string
spellId: string
Expand Down
39 changes: 26 additions & 13 deletions packages/agents/src/lib/AgentCommander.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ import { AgentResult, AgentRunJob } from './Agent'
import { AGENT_RESPONSE_TIMEOUT_MSEC } from '@magickml/config'

export type RunRootSpellArgs = {
agent: Agent
agent?: Agent
agentId?: string
inputs: MagickSpellInput
componentName?: string
runSubspell?: boolean
Expand All @@ -25,6 +26,7 @@ export type RunRootSpellArgs = {
isSubSpell?: boolean
currentJob?: Job<AgentRunJob>
subSpellDepth?: number
sessionId?: string
}

interface AgentCommanderArgs {
Expand All @@ -41,7 +43,10 @@ export class AgentCommander extends EventEmitter {
}

runSpellWithResponse(args: RunRootSpellArgs) {
const { agent } = args
const { agentId, agent } = args
const id = agentId || agent?.id
if (!id) throw new Error('Agent or agent id is required')

return new Promise((resolve, reject) => {
;(async () => {
setTimeout(() => {
Expand All @@ -50,7 +55,7 @@ export class AgentCommander extends EventEmitter {

let jobId: null | string = null

const agentMessageName = AGENT_RUN_RESULT(agent.id)
const agentMessageName = AGENT_RUN_RESULT(id)

this.pubSub.subscribe(agentMessageName, (data: AgentResult) => {
if (data.result.error) {
Expand All @@ -66,7 +71,7 @@ export class AgentCommander extends EventEmitter {
}
})

const agentErrorName = AGENT_RUN_ERROR(agent.id)
const agentErrorName = AGENT_RUN_ERROR(id)
this.pubSub.subscribe(agentErrorName, (data: AgentResult) => {
if (data.jobId === jobId) {
this.pubSub.unsubscribe(agentErrorName)
Expand All @@ -83,46 +88,54 @@ export class AgentCommander extends EventEmitter {
private runRootSpellArgsToString(
jobId: string,
{
agent,
agentId,
inputs,
componentName,
runSubspell,
secrets,
publicVariables,
spellId,
subSpellDepth,
sessionId,
}: RunRootSpellArgs
) {
return JSON.stringify({
jobId,
agentId: agent.id,
spellId: spellId || agent.rootSpellId,
agentId,
spellId: spellId,
inputs,
componentName,
runSubspell,
secrets,
publicVariables,
subSpellDepth,
sessionId,
})
}

async runSubSpell(args: RunRootSpellArgs) {
const { agent } = args
const { agentId, agent } = args
const id = agentId || agent?.id
if (!id) throw new Error('Agent or agent id is required')

const jobId = uuidv4()
await this.pubSub.publish(
AGENT_RUN_JOB(agent.id),
AGENT_RUN_JOB(id),
this.runRootSpellArgsToString(jobId, args)
)
return jobId
}

async runSpell(args: RunRootSpellArgs) {
const { agent } = args
this.logger.debug(`Running Spell on Agent: ${agent.id}`)
this.logger.debug(AGENT_RUN_JOB(agent.id))
const { agent, agentId } = args
const id = agentId || agent?.id
if (!id) throw new Error('Agent or agent id is required')

this.logger.debug(`Running Spell on Agent: ${id}`)
this.logger.debug(AGENT_RUN_JOB(id))
const jobId = uuidv4()
await this.pubSub.publish(
AGENT_RUN_JOB(agent.id),
AGENT_RUN_JOB(id),
this.runRootSpellArgsToString(jobId, args)
)
return jobId
Expand Down
Loading
Loading