Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
benbot committed Nov 27, 2023
1 parent 906b7fd commit a913461
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 11 deletions.
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,4 @@ AWS_BUCKET_NAME=bucket_name
AWS_BUCKET_ENDPOINT=endpoint

CLOUD_AGENT_KEY=key
APT_ROOT_URL=http://0.0.0.0
2 changes: 1 addition & 1 deletion bruno-requests/Create Release.bru
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ headers {
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate, br
Referer: http://localhost:4200/
authorization: Bearer eyJhbGciOiJkaXIiLCJlbmMiOiJBMjU2R0NNIn0..69iUxpF7UvHXdMGi.qd9RrgVcsmGGc8jBVVdiKe-aPRuH6S8yv2ng5O8oB2LLMTj9nlXlwAsmHDk86IeSKMp2u5JvYHuHixjRgx8D5NgUn3SgZFrxS8ovcWY0eAwxMauvp17g80i0IgyOEX5EfiCBXDrYkC11twOvhEn3nL0-cRN_c2mrZ_C_2s9bFxtwrw0_zyAImenE7mF9B541-QHGNhAg_1sLcD3O4xMOx7GkMOQa29YRlENjlsN-efRAUuSLcFOIikvv82V-DgtFGcxNjR9Td3nGWPdgJ_zzMQU42AbosEE3DlopyKGyS6y6q742A7nnPWf_EpxgGz5WIoi9zmTsMrX8a_-ERIypXS0rEovl6P8hkKgHI3ytaGng7bwVKVWdCub8N2IUZgfKfIZlG3N7h2opPUI2BwvfV-yluuFqEnLKSIomdpcR6mKuIWVgnAkc_zpPDEVMll5nl44ZiMi2roDhLjgEdUVqOoGQ7agY3RIrOvXulKeWnX3nswum883DNeQPN09Y547bVoV7Qn6zlUS2BqrwW6XhOM9BMIj08Ew52N53EdcVzHetKMGfOp5xK5BWEXZajrASosPoAo2UyopG1aQIHMygy2DNxvcmPghmlD2rZfqcQZWnt-3JRP6ecKeXmStxEiMgbpM_sSR332HzenbPMtMBgeQjio6mUrebg6OR3IjUCzTFb7Ob4AryyF-vUb6WAs92DpJckfnL8ZyUSFyvAH84Jhz3RbDluDeR6hKQd7d0Ie546n6TViI8nSYpFcBjnnymYVYLfORw_9_A_St1c6t8.wdgZei2lnX_enT4ibTJHOg
authorization: Bearer {{authToken}}
Origin: http://localhost:4200
Connection: keep-alive
Sec-Fetch-Dest: empty
Expand Down
3 changes: 3 additions & 0 deletions bruno-requests/environments/Local - With Cloud.bru
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
vars {
baseUrl: http://localhost:3030
}
vars:secret [
authToken
]
12 changes: 6 additions & 6 deletions packages/server/cloud-agent-worker/src/lib/cloud-agent-worker.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { Worker, Job } from 'bullmq'

import type { PubSub } from 'server/core'
import type { AgentRunJob } from 'server/agents'
import {
BullMQWorker,
type PubSub,
RedisPubSubWrapper,
app,
BullQueue,
} from 'server/core'
import { Agent, AgentManager, type AgentRunJob } from 'server/agents'
import { Agent, AgentManager } from 'server/agents'
import { v4 as uuidv4 } from 'uuid'
import {
AGENT_DELETE,
Expand Down Expand Up @@ -122,17 +123,15 @@ export class CloudAgentWorker extends AgentManager {

async agentUpdated(agentId: string) {
this.logger.info(`Updating agent ${agentId}`)
const agentDBResult = (
const agent = (
await app.service('agents').get(agentId, {})
)

if (!agentDBResult) {
if (!agent) {
this.logger.error(`Agent ${agentId} not found when updating agent`)
throw new Error(`Agent ${agentId} not found when updating agent`)
}

const agent = agentDBResult[0]

// start or stop the agent if the enabled state changed
if (agent.enabled && !this.currentAgents[agentId]) {
await this.addAgent(agentId)
Expand All @@ -158,6 +157,7 @@ export class CloudAgentWorker extends AgentManager {
async listenForRun(agentId: string) {
this.logger.debug(`Listening for run for agent ${agentId}`)
this.logger.debug(AGENT_RUN_JOB(agentId))
this.logger.debug(agentId)
this.pubSub.subscribe(AGENT_RUN_JOB(agentId), async (data: AgentRunJob) => {
this.logger.info(
`Running spell ${data.spellId} for agent ${data.agentId}`
Expand Down
5 changes: 3 additions & 2 deletions packages/server/core/src/services/spells/spells.class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ export class SpellService<

if (spellId && !versionId) {
const count = await db('agentReleases').count('*').as('count').leftJoin('spells as spells', function() {
this.on('spells.versionId', '=', 'agentReleases.id').andOn('spells.id', '=', spellId)
})
this.on('spells.versionId', '=', 'agentReleases.id')
}).where('spells.id', '=', spellId)

if (count["count"] > 0) {
query
Expand Down Expand Up @@ -73,6 +73,7 @@ export class SpellService<
}

async create(params: SpellData) {
app.get('logger').debug('Creating spell: %o', params)
return this._create(params)
}

Expand Down
4 changes: 2 additions & 2 deletions packages/server/core/src/services/spells/spells.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ const spellDataSchemaProperties = {
createdAt: spellSchema.properties.createdAt,
updatedAt: spellSchema.properties.updatedAt,
hash: spellSchema.properties.hash,
type: Type.Optional(spellSchema.properties.type),
type: spellSchema.properties.type,
versionId: spellSchema.properties.versionId,
id: Type.Optional(spellSchema.properties.id),
id: spellSchema.properties.id,
}

export const spellDataSchema = Type.Object(spellDataSchemaProperties, {
Expand Down

0 comments on commit a913461

Please sign in to comment.