Skip to content

Commit

Permalink
Merge pull request #1381 from Oneirocom/benbot/revert-prod-push
Browse files Browse the repository at this point in the history
Reverts PR #1376
  • Loading branch information
benbot authored Nov 2, 2023
2 parents b289e6f + 000e6c2 commit 397bfba
Show file tree
Hide file tree
Showing 45 changed files with 616 additions and 263 deletions.
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

1 comment on commit 397bfba

@vercel
Copy link

@vercel vercel bot commented on 397bfba Nov 2, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.