Skip to content

Commit

Permalink
fix(aos): fix mismatched version, aos query not working
Browse files Browse the repository at this point in the history
  • Loading branch information
jfrain99 committed Feb 25, 2025
1 parent e9fc10c commit d4a4bed
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 41 deletions.
2 changes: 1 addition & 1 deletion process/process.lua
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ assignment.init(ao)
-- @table process
-- @field _version The version number of the process

local process = { _version = "2.0.3" }
local process = { _version = "2.0.5" }
-- The maximum number of messages to store in the inbox
local maxInboxCount = 10000

Expand Down
11 changes: 10 additions & 1 deletion src/commands/os.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import path from 'node:path'
import os from 'node:os'
import * as url from 'url'
import chalk from 'chalk'
import { getPkg } from '../services/get-pkg.js'


let __dirname = url.fileURLToPath(new URL('.', import.meta.url));
Expand All @@ -34,7 +35,6 @@ export function update() {
})
.concat(patch())
.concat(patch2())
.concat("print([[\nUpdated AOS to version ]] .. require('.process')._version)")
.join('\n\n')

luaFiles = `
Expand Down Expand Up @@ -63,6 +63,15 @@ if not _G.package.loaded['ao'] then
end
\n`

// get the AOS version from the package.json
const pkg = getPkg()

luaFiles = luaFiles + `
-- update process version to package.json version
_G.package.loaded['.process']['_version'] = '${pkg.version}'
print([[\nUpdated AOS to version ]] .. '${pkg.version}')
\n`

return luaFiles
}

Expand Down
23 changes: 14 additions & 9 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,11 @@ if (argv['mu-url']) {

async function runProcess() {
if (!argv.watch) {
const spinner = ora({
spinner: 'dots',
suffixText: ''
})

of()
.chain(fromPromise(() => argv.wallet ? getWalletFromArgs(argv.wallet) : getWallet()))
.chain(jwk => {
Expand All @@ -183,9 +188,15 @@ async function runProcess() {
}
return Resolved(jwk)
})
.chain(jwk => register(jwk, { address, isAddress, spawnProcess, gql })
.map(id => ({ jwk, id }))
)
.chain(jwk => {
spinner.start()
return register(jwk, { address, isAddress, spawnProcess, gql }, spinner)
.map(id => ({ jwk, id }))
.map(_ => {
spinner.stop()
return _
})
})
.toPromise()
.then(async ({ jwk, id }) => {
let editorMode = false
Expand All @@ -194,11 +205,6 @@ async function runProcess() {
const history = readHistory(id)

if (luaData.length > 0 && argv.load) {
const spinner = ora({
spinner: 'dots',
suffixText: ''
})

spinner.start()
spinner.suffixText = chalk.gray('[Connecting to process...]')
const result = await evaluate(luaData, id, jwk, { sendMessage, readResult }, spinner)
Expand Down Expand Up @@ -540,7 +546,6 @@ async function connect(jwk, id) {
spinner.suffixText = chalk.red('[Connecting to process....]')
await new Promise(resolve => setTimeout(resolve, 500 * i))
promptResult = await evaluate("require('.process')._version", id, jwk, { sendMessage, readResult }, spinner)
// console.log({ promptResult })
_prompt = promptResult?.Output?.prompt || promptResult?.Output?.data?.prompt
} else {
break
Expand Down
49 changes: 41 additions & 8 deletions src/register.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import minimist from 'minimist'
import { getPkg } from './services/get-pkg.js'
import fs from 'fs'
import path from 'path'
import chalk from 'chalk'

const promptUser = (results) => {
const choices = results.map((res, i) => {
Expand All @@ -33,20 +34,51 @@ const promptUser = (results) => {
.catch(() => Promise.reject({ ok: false, error: 'No module selected' }))
}

export function register(jwk, services) {
export function register(jwk, services, spinner) {
const getAddress = ctx => services.address(ctx.jwk).map(address => ({ address, ...ctx }))
const findProcess = (ctx) => {
const { address, name } = ctx

const argv = minimist(process.argv.slice(2))

return services
.gql(queryForAOS(name), { owners: [address, argv.address || ""] })
.map(utils.path(['data', 'transactions', 'edges']))
// Query AOS for the process, with 3 retries
const findProcessFromAOSWithRetry = (retries = 0) => {
return fromPromise(() => new Promise(r => setTimeout(r, retries == 0 ? 0 : 500)))()
.chain(() =>
services.gql(queryForAOS(name), { owners: argv.address ? [address, argv.address] : [address] })
.map(utils.path(['data', 'transactions', 'edges']))
.bichain(
(err) => {
// If we've retried 3 times, give up
if (retries > 3) {
return Rejected(err)
}
// Update the spinner suffix text to indicate the number of retries
spinner ? spinner.suffixText = chalk.gray('[Querying process from gateway, attempt #' + (retries + 1) + ']') : console.log(chalk.gray('.'))
// Retry the query
return findProcessFromAOSWithRetry(retries + 1)
},
Resolved
)
)
}
return of()
.map(() => {
// Update the spinner suffix text to indicate the number of retries
spinner ? spinner.suffixText = chalk.gray('[Querying process from gateway, attempt #1]') : console.log(chalk.gray('.'))
// Start the spinner
spinner.start()
})
.chain(findProcessFromAOSWithRetry)
.map(
(res) => {
// Stop the spinner
spinner.stop()
return res
}
)
.bichain(
_ => Rejected({ ok: false, error: 'GRAPHQL Error trying to locate process.' }),
results => results?.length > 0
? Resolved(results.reverse())
? Resolved(results)
/**
* No process was found that matches the name, module and owners
* But no catastrophic error occured.
Expand Down Expand Up @@ -214,7 +246,8 @@ function queryForAOS(name) {
{ name: "Data-Protocol", values: ["ao"] },
{ name: "Type", values: ["Process"]},
{ name: "Name", values: ["${name}"]}
]
],
sort: HEIGHT_DESC
) {
edges {
node {
Expand Down
51 changes: 29 additions & 22 deletions src/services/gql.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,28 +20,35 @@ const ARWEAVE_GRAPHQL = process.env.ARWEAVE_GRAPHQL || (
process.env.GATEWAY_URL ? new URL('/graphql', process.env.GATEWAY_URL) : 'https://arweave.net/graphql'
)
function queryArweave(body) {
return fromPromise(() => fetch(ARWEAVE_GRAPHQL, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(body)
})
.then(res => {
if (!res.ok) {
throw new Error(`(${res.status}) ${res.statusText} - GQL ERROR`)
}
return res
return fromPromise(() => {
return fetch(ARWEAVE_GRAPHQL, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(body)
})
.then(result => {
if (result.data === null) {
throw new Error(`(${result.status}) ${result.statusText} - GQL ERROR`)
}
return result

})
.then(res => res.json())


.then(res => {
if (!res.ok) {
throw new Error(`(${res.status}) ${res.statusText} - GQL ERROR`)
}
return res
})
.then(result => {
if (result.data === null) {
throw new Error(`(${result.status}) ${result.statusText} - GQL ERROR`)
}
return result
})
.then(async res => {
const json = await res.json()
// Catch errors from the gateway (timeouts, etc return a 200 ok)
if (!json.data && json.errors) {
throw new Error(`(${json.errors[0].message}) - GQL ERROR`)
}
return json
})

}
)()
}

0 comments on commit d4a4bed

Please sign in to comment.