diff --git a/deno.json b/deno.json index e8ccaa9..7e2b7de 100644 --- a/deno.json +++ b/deno.json @@ -1,6 +1,6 @@ { "name": "@subql/ai-app-framework", - "version": "1.0.0-4", + "version": "1.0.0-11", "exports": { "./cli": "./src/index.ts", ".": "./src/mod.ts" diff --git a/deno.lock b/deno.lock index c86826e..5297492 100644 --- a/deno.lock +++ b/deno.lock @@ -40,6 +40,7 @@ "jsr:@std/streams@^1.0.5": "1.0.6", "jsr:@std/tar@~0.1.1": "0.1.1", "jsr:@subql/ai-app-framework@1.0.0-1": "1.0.0-1", + "jsr:@subql/ai-app-framework@1.0.0-3": "1.0.0-3", "npm:@lancedb/lancedb@0.10": "0.10.0_apache-arrow@17.0.0", "npm:@sinclair/typebox@*": "0.33.11", "npm:@sinclair/typebox@~0.33.11": "0.33.11", @@ -272,6 +273,9 @@ "npm:vscode-jsonrpc", "npm:yargs" ] + }, + "@subql/ai-app-framework@1.0.0-3": { + "integrity": "e3754a07ab39b02a4fd7d875d6af800659a5c773a64d0c77a1ef57d320d9fd81" } }, "npm": { diff --git a/src/index.ts b/src/index.ts index 9c53cb6..b2ab328 100755 --- a/src/index.ts +++ b/src/index.ts @@ -43,6 +43,20 @@ const sharedArgs = { }, } satisfies Record; +const debugArgs = { + debug: { + description: "Enable debug logging", + type: "boolean", + default: false, + }, + logFmt: { + description: "Set the logger format", + type: "string", + choices: ["json", "pretty"], + default: "pretty", + }, +} satisfies Record; + function ipfsFromArgs( argv: ArgumentsCamelCase>, ): IPFSClient { @@ -60,6 +74,7 @@ yargs(Deno.args) "Run a SubQuery AI app", { ...sharedArgs, + ...debugArgs, host: { alias: "h", description: "The ollama RPC host", @@ -91,17 +106,6 @@ yargs(Deno.args) type: "number", default: 10_000, // 10s }, - debug: { - description: "Enable debug logging", - type: "boolean", - default: false, - }, - logFmt: { - description: "Set the logger format", - type: "string", - choices: ["json", "pretty"], - default: "pretty", - }, }, async (argv) => { try { @@ -132,6 +136,7 @@ yargs(Deno.args) "Get information on a project", { ...sharedArgs, + ...debugArgs, json: { description: "Log the project in JSON format", default: false, @@ -140,6 +145,10 @@ yargs(Deno.args) }, async (argv) => { try { + await initLogger( + argv.logFmt as "json" | "pretty", + argv.debug ? "debug" : undefined, + ); const { projectInfo } = await import("./subcommands/info.ts"); await projectInfo(argv.project, ipfsFromArgs(argv), argv.json); Deno.exit(0); @@ -214,6 +223,7 @@ yargs(Deno.args) "Publishes a project to IPFS so it can be easily distributed", { ...sharedArgs, + ...debugArgs, silent: { description: "Disable all logging except for the output", type: "boolean", @@ -221,6 +231,13 @@ yargs(Deno.args) }, async (argv) => { try { + if (!argv.silent) { + await initLogger( + argv.logFmt as "json" | "pretty", + argv.debug ? "debug" : undefined, + ); + } + const { publishProject } = await import("./subcommands/bundle.ts"); if (argv.silent) { setSpinner(ora({ isSilent: true })); diff --git a/src/loader.ts b/src/loader.ts index 617bf61..d8913be 100644 --- a/src/loader.ts +++ b/src/loader.ts @@ -1,6 +1,8 @@ import { dirname } from "@std/path/dirname"; -import { CIDReg, type IPFSClient } from "./ipfs.ts"; import { resolve } from "@std/path/resolve"; +import { fromFileUrl } from "@std/path/from-file-url"; +import { CIDReg, type IPFSClient } from "./ipfs.ts"; + import { UntarStream } from "@std/tar"; import { ensureDir, exists } from "@std/fs"; import type { Source } from "./util.ts"; @@ -31,7 +33,7 @@ async function loadScript(path: string): Promise { /** * Loads a local manifest file (either json, ts or js) */ -export async function loadManfiest(path: string): Promise { +async function loadManfiest(path: string): Promise { let manifest: unknown; try { manifest = await loadJson(path); @@ -104,7 +106,11 @@ export async function pullContent( try { // This should throw if the project is not a valid URL. This allows loading lancedb from gcs/s3 - new URL(path); + const url = new URL(path); + + if (url.protocol === "file:") { + return [fromFileUrl(path), "local"]; + } return [path, "remote"]; } catch (_e) { @@ -118,12 +124,18 @@ export class Loader { #ipfs: IPFSClient; #force: boolean; + readonly projectPath: string; + constructor( - readonly projectPath: string, + projectPath: string, ipfs: IPFSClient, readonly tmpDir?: string, force?: boolean, ) { + this.projectPath = projectPath.startsWith("file://") + ? fromFileUrl(projectPath) + : projectPath; + this.#ipfs = ipfs; this.#force = force ?? false; } @@ -154,10 +166,13 @@ export class Loader { const [manifestPath, source] = await this.pullContent( this.projectPath, "manifest.json", + undefined, + Deno.cwd(), ); - const manifest = await loadManfiest(manifestPath); logger.debug(`getManifest [${source}] ${manifestPath}`); + const manifest = await loadManfiest(manifestPath); + return [manifestPath, manifest, source]; } diff --git a/subquery-delegator b/subquery-delegator index c72c4f2..f859358 160000 --- a/subquery-delegator +++ b/subquery-delegator @@ -1 +1 @@ -Subproject commit c72c4f248834ecae21fbe28af58a7199ebc81135 +Subproject commit f859358a75737101c7615a28339e3337010d9d7b