Skip to content

Commit

Permalink
bruno updates and small agent & spell fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
benbot committed Nov 21, 2023
1 parent a5bbe62 commit 906b7fd
Show file tree
Hide file tree
Showing 11 changed files with 126 additions and 56 deletions.
6 changes: 3 additions & 3 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ POSTHOG_API_KEY=key
VITE_APP_PRODUCTION=false
PRODUCTION=false

VITE_APP_STANDALONE=true
STANDALONE=true
VITE_APP_STANDALONE=false
STANDALONE=false

REDISCLOUD_HOST=localhost
REDISCLOUD_URL=redis://localhost:6379
Expand All @@ -59,4 +59,4 @@ AWS_REGION=region
AWS_BUCKET_NAME=bucket_name
AWS_BUCKET_ENDPOINT=endpoint

CLOUD_AGENT_KEY=key
CLOUD_AGENT_KEY=key
39 changes: 39 additions & 0 deletions bruno-requests/Create Release.bru
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
meta {
name: Create Release
type: http
seq: 3
}

post {
url: {{baseUrl}}/agents/createRelease/d9289fe5-71ad-4472-bcbe-f692ecd7d733?projectId=clp77m6sc0003ffjuezrwphn7
body: json
auth: none
}

query {
projectId: clp77m6sc0003ffjuezrwphn7
}

headers {
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/119.0
Accept: */*
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
Origin: http://localhost:4200
Connection: keep-alive
Sec-Fetch-Dest: empty
Sec-Fetch-Mode: cors
Sec-Fetch-Site: same-site
DNT: 1
Sec-GPC: 1
}

body:json {
{
"agentId": "d9289fe5-71ad-4472-bcbe-f692ecd7d733",
"versionTag": "Test",
"projectId": "clp77m6sc0003ffjuezrwphn7"
}
}
31 changes: 31 additions & 0 deletions bruno-requests/Get Agents.bru
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
meta {
name: Get Agents
type: http
seq: 3
}

get {
url: {{baseUrl}}/agents?projectId=clp77m6sc0003ffjuezrwphn7
body: none
auth: none
}

query {
projectId: clp77m6sc0003ffjuezrwphn7
}

headers {
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/119.0
Accept: */*
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
Origin: http://localhost:4200
Connection: keep-alive
Sec-Fetch-Dest: empty
Sec-Fetch-Mode: cors
Sec-Fetch-Site: same-site
DNT: 1
Sec-GPC: 1
}
19 changes: 0 additions & 19 deletions bruno-requests/Get All Agents.bru

This file was deleted.

19 changes: 0 additions & 19 deletions bruno-requests/Get An Agents.bru

This file was deleted.

31 changes: 31 additions & 0 deletions bruno-requests/Get One Agent.bru
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
meta {
name: Get One Agent
type: http
seq: 2
}

get {
url: {{baseUrl}}/agents/d9289fe5-71ad-4472-bcbe-f692ecd7d733?projectId=clp77m6sc0003ffjuezrwphn7
body: none
auth: none
}

query {
projectId: clp77m6sc0003ffjuezrwphn7
}

headers {
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/119.0
Accept: */*
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
Origin: http://localhost:4200
Connection: keep-alive
Sec-Fetch-Dest: empty
Sec-Fetch-Mode: cors
Sec-Fetch-Site: same-site
DNT: 1
Sec-GPC: 1
}
3 changes: 3 additions & 0 deletions bruno-requests/environments/Local - With Cloud.bru
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
vars {
baseUrl: http://localhost:3030
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const getAgent = async (
apiKey: string,
isCloud: boolean
): Promise<Agent> => {
const agent = await app.service('agents').get(agentId)
const agent = await app.service('agents').get(agentId, {})
if (!agent) {
throw new NotFound('Agent not found with id ' + agentId)
}
Expand Down
12 changes: 7 additions & 5 deletions packages/server/core/src/services/agents/agents.class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,16 @@ export class AgentService<
})
}

} else if(agentId && currentReleaseVersionId) {
} else if (agentId && currentReleaseVersionId) {

query
.leftJoin('agentRelease as releases', function() {
this.on('agents.id', '=', 'agentReleases.agentId').andOn(currentReleaseVersionId, '=', 'agentReleases.releaseVersion')
})
}

const data = await query.andWhere('agents.id', '=', agentId)
if (data.length !== 1) {
const data = await query.andWhere('agents.id', '=', agentId).limit(1).first()
if (!data) {
throw new NotFound(`No record found for id '${agentId}'`)
}

Expand All @@ -70,7 +70,7 @@ export class AgentService<
async update(id: string, data: AgentData, params?: ServiceParams) {
// Call the original update method to handle other updates
return this._update(id, data, params);
}
}

// we use this ping to avoid firing a patched event on the agent
// every time the agent is pinged
Expand Down Expand Up @@ -160,14 +160,16 @@ export class AgentService<
* @param agentId - the ID of the agent to copy from
* @param versionTag - the version tag to associate with the newly created agent
*/
async createRelease(agentId: string, versionTag: string): Promise<{agent: Agent, release: any}> {
async createRelease(agentId: string, versionTag: string): Promise<{ agent: Agent, release: any }> {
// Get the agent by its agentId
const agentData = await this.app.service('agents').get(agentId, {});

if (!agentData) {
throw new Error(`Agent with ID ${agentId} not found.`);
}

console.log(agentData)

// Copy data from the fetched agent, omitting the ID field to create a new agent
const newAgent = await this.app.service('agents').create(agentData);

Expand Down
16 changes: 9 additions & 7 deletions packages/server/core/src/services/spells/spells.class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,32 +38,34 @@ export class SpellService<
const query = super.createQuery(params)

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

if (count["count"] > 0) {
query
.leftJoin('agentRelease as releases', function() {
this.on('agents.id', '=', 'agentReleases.agentId')
this.on('spells.versionId', '=', 'agentReleases.id')
})
}

} else if(spellId && versionId) {
query
.leftJoin('agentRelease as releases', function() {
this.on('spelld.versionId', '=', 'agentReleases.id').andOn(versionId, '=', 'agentReleases.id')
this.on('spelld.versionId', '=', 'agentReleases.id').andOn('agentReleases.id', '=', versionId)
})
}

const data = await query.andWhere('spells.id', '=', spellId)
if (data.length !== 1) {
const data = await query.andWhere('spells.id', '=', spellId).first()
if (!data) {
throw new NotFound(`No record found for id '${spellId}'`)
}

return data
}

async find(params: ServiceParams) {
return this._find(params)
return this._find(params) as Promise<Paginated<SpellInterface>>
}

async update(spellId: string, params: SpellData) {
Expand Down Expand Up @@ -92,7 +94,7 @@ export class SpellService<
const spellData = await app
.service('spells')
.find({ query: { projectId, name } })
const spell = spellData[0]
const spell = spellData.data[0]

// Check if spell exists and that diff is available
if (!spell) throw new BadRequest(`No spell with ${name} name found.`)
Expand Down
4 changes: 2 additions & 2 deletions packages/shared/core/src/nodes/document/GetDocuments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ export class GetDocuments extends MagickComponent<Promise<InputReturn>> {
? typeData.toLowerCase().trim()
: 'none')

let max_count
let max_count = 1
if (typeof node.data.max_count === 'string') {
max_count = parseInt(node.data.max_count)
} else if (typeof node.data.max_count === 'number') {
Expand All @@ -148,7 +148,7 @@ export class GetDocuments extends MagickComponent<Promise<InputReturn>> {
query: {
projectId,
type,
$limit: max_count ?? 1,
$limit: max_count,
embedding,
},
})
Expand Down

0 comments on commit 906b7fd

Please sign in to comment.