Skip to content

Commit

Permalink
use genaiscript.cjs from vscode extension folder
Browse files Browse the repository at this point in the history
  • Loading branch information
pelikhan committed Mar 27, 2024
1 parent 5d81506 commit 1a13b6e
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 33 deletions.
1 change: 0 additions & 1 deletion docs/src/content/docs/getting-started/installation.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ to bug fixes earlier than the marketplace release.

- ...
- .genaiscript/ folder created by the extension to store supporting files
- genaiscript.cjs command line
- cache/ various cache files
- retreival/ retreival database caches
- ... supporting files
Expand Down
5 changes: 2 additions & 3 deletions packages/core/src/clihelp.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { CORE_VERSION, RunTemplateOptions } from "."
import { Fragment } from "./ast"
import { GENAISCRIPT_CLI_JS, NPM_CLI_PACKAGE } from "./constants"
import { NPM_CLI_PACKAGE } from "./constants"
import { MarkdownTrace } from "./trace"

export function generateCliArguments(
Expand Down Expand Up @@ -52,9 +52,8 @@ ${generateCliArguments(template, fragment, options, "batch")}
- You will need to install [Node.js](https://nodejs.org/en/).
- The \`${GENAISCRIPT_CLI_JS}\` is written by the Visual Studio Code extension automatically.
- The CLI uses the same secrets in the \`.env\` file.
- Run \`node .genaiscript/genaiscript help run\` for the full list of options.
- Run \`npx genaiscript help run\` for the full list of options.
`
)
}
1 change: 0 additions & 1 deletion packages/core/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ export const AZURE_OPENAI_API_VERSION = "2023-09-01-preview"
export const TOOL_ID = "genaiscript"
export const GENAISCRIPT_FOLDER = "." + TOOL_ID
export const CLI_JS = TOOL_ID + ".cjs"
export const GENAISCRIPT_CLI_JS = GENAISCRIPT_FOLDER + "/" + CLI_JS
export const GENAI_SRC = "genaisrc"
export const GENAI_EXT = ".genai.js"
export const TOOL_NAME = "GenAIScript"
Expand Down
17 changes: 7 additions & 10 deletions packages/vscode/src/fragmentcommands.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import * as vscode from "vscode"
import {
Fragment,
GENAISCRIPT_CLI_JS,
PromptTemplate,
dotGenaiscriptPath,
groupBy,
Expand All @@ -11,7 +10,6 @@ import { ExtensionState } from "./state"
import {
checkDirectoryExists,
checkFileExists,
saveAllTextDocuments,
} from "./fs"

type TemplateQuickPickItem = {
Expand Down Expand Up @@ -83,10 +81,10 @@ export function activateFragmentCommands(state: ExtensionState) {
const fragmentPrompt = async (
options:
| {
fragment?: Fragment | string | vscode.Uri
template?: PromptTemplate
debug?: boolean
}
fragment?: Fragment | string | vscode.Uri
template?: PromptTemplate
debug?: boolean
}
| vscode.Uri
) => {
if (typeof options === "object" && options instanceof vscode.Uri)
Expand Down Expand Up @@ -128,7 +126,7 @@ export function activateFragmentCommands(state: ExtensionState) {
vscode.workspace.workspaceFolders[0],
{
name: "GenAIScript",
program: GENAISCRIPT_CLI_JS,
program: state.cliJsPath,
request: "launch",
skipFiles: ["<node_internals>/**", dotGenaiscriptPath("**")],
type: "node",
Expand Down Expand Up @@ -198,9 +196,8 @@ export function templatesToQuickPickItems(
template.filename
)) ??
template.id,
description: `${template.id} ${
template.description || ""
}`,
description: `${template.id} ${template.description || ""
}`,
template,
}
)
Expand Down
5 changes: 1 addition & 4 deletions packages/vscode/src/retreivalcommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,8 @@ import {
GENAISCRIPT_FOLDER,
TOOL_NAME,
clearIndex,
initToken,
isIndexable,
upsert,
search as retreivalSearch,
CLI_JS,
ICON_LOGO_NAME,
RETRIEVAL_DEFAULT_INDEX,
} from "genaiscript-core"
Expand Down Expand Up @@ -105,7 +102,7 @@ export function activateRetreivalCommands(state: ExtensionState) {
iconPath: new vscode.ThemeIcon(ICON_LOGO_NAME),
})
terminal.sendText(
`node ${host.path.join(GENAISCRIPT_FOLDER, CLI_JS)} retreival index "${host.path.join(vscode.workspace.asRelativePath(uri.fsPath), "**")}" --name ${indexName}`
`node "${state.cliJsPath}" retreival index "${host.path.join(vscode.workspace.asRelativePath(uri.fsPath), "**")}" --name ${indexName}`
)
terminal.show()
}
Expand Down
4 changes: 1 addition & 3 deletions packages/vscode/src/servermanager.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import {
CLI_JS,
GENAISCRIPT_FOLDER,
HighlightService,
ICON_LOGO_NAME,
RetreivalService,
Expand Down Expand Up @@ -45,7 +43,7 @@ export class TerminalServerManager implements ServerManager {
iconPath: new vscode.ThemeIcon(ICON_LOGO_NAME),
})
this._terminal.sendText(
`node ${host.path.join(GENAISCRIPT_FOLDER, CLI_JS)} serve`
`node "${this.state.cliJsPath}" serve`
)
this._terminal.show()
}
Expand Down
22 changes: 11 additions & 11 deletions packages/vscode/src/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,11 +179,6 @@ export class ExtensionState extends EventTarget {
const dir = vscode.Uri.file(dotGenaiscriptPath("."))
await vscode.workspace.fs.createDirectory(dir)

const p = Utils.joinPath(this.context.extensionUri, CLI_JS)
const cli = vscode.Uri.file(dotGenaiscriptPath(CLI_JS))

// genaiscript.cjs
await vscode.workspace.fs.copy(p, cli, { overwrite: true })
// add .gitignore
await writeFile(
dir,
Expand All @@ -206,6 +201,11 @@ retrieval/
)
}

get cliJsPath() {
const res = Utils.joinPath(this.context.extensionUri, CLI_JS).fsPath
return res
}

aiRequestCache() {
return this._aiRequestCache
}
Expand Down Expand Up @@ -529,9 +529,9 @@ ${e.message}`
const spec = `# Specification
${files
.map((uri) => this.host.path.relative(fspath, uri.fsPath))
.map((fn) => `- [${fn}](./${fn})`)
.join("\n")}
.map((uri) => this.host.path.relative(fspath, uri.fsPath))
.map((fn) => `- [${fn}](./${fn})`)
.join("\n")}
`
this.host.clearVirtualFiles()
this.host.setVirtualFile(specn, spec)
Expand Down Expand Up @@ -610,9 +610,9 @@ ${files
r.source = TOOL_NAME
r.code = target
? {
value,
target,
}
value,
target,
}
: undefined
return r
})
Expand Down

0 comments on commit 1a13b6e

Please sign in to comment.