Skip to content

Commit 3d6e644

Browse files
authored
Global host (#1748)
* resolving host at runtime * more cleanup * moo * fix test * refactor * fix build * test node 20 * fix vscode * handle undefined terminal * ignore * update deps * add "tavily" to cSpell.words in settings * remove node v20 * fix race
1 parent 1d07370 commit 3d6e644

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+1364
-1344
lines changed

.github/workflows/build.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,6 @@ jobs:
2020
with:
2121
node-version: "${{ matrix.node-version }}"
2222
cache: "pnpm"
23-
- uses: dev-proxy-tools/actions/setup@v1
24-
with:
25-
auto-record: true
26-
report-job-summary: $GITHUB_STEP_SUMMARY
2723
- run: sudo apt-get update && sudo apt-get install ffmpeg
2824
- run: pnpm install --frozen-lockfile
2925
- name: build

.vscode/settings.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
"changeext",
4040
"changelogf",
4141
"chatencoder",
42+
"chatparticipant",
4243
"chatrender",
4344
"chattypes",
4445
"Chunker",
@@ -53,6 +54,7 @@
5354
"compactable",
5455
"configjson",
5556
"configschema",
57+
"connectioninfotree",
5658
"consolecolor",
5759
"contentinfo",
5860
"contentsafety",
@@ -90,6 +92,7 @@
9092
"docify",
9193
"Dockerized",
9294
"dockerode",
95+
"docsnotebook",
9396
"docstrings",
9497
"domcontentloaded",
9598
"doptions",
@@ -112,7 +115,9 @@
112115
"filebytes",
113116
"filetree",
114117
"firstsecond",
118+
"fixcommand",
115119
"Fmepg",
120+
"fragmentcommands",
116121
"frontmatter",
117122
"fscache",
118123
"FSTAR",
@@ -189,6 +194,7 @@
189194
"makeitbetter",
190195
"managedidentity",
191196
"mapreduce",
197+
"markdowndocumentprovider",
192198
"markdownify",
193199
"markdownifypdf",
194200
"markitdown",
@@ -262,12 +268,14 @@
262268
"pricings",
263269
"PRICINGS",
264270
"priompt",
271+
"promptcommands",
265272
"promptcontext",
266273
"promptdom",
267274
"promptfoo",
268275
"promptfooconfig",
269276
"promptjson",
270277
"promptrunner",
278+
"prompttree",
271279
"prompty",
272280
"proxify",
273281
"pyimport",
@@ -291,6 +299,7 @@
291299
"scriptquickpick",
292300
"scriptresolver",
293301
"secretscanner",
302+
"servermanager",
294303
"seti",
295304
"sglang",
296305
"shiki",
@@ -319,8 +328,11 @@
319328
"sysr",
320329
"SYSTEMROOT",
321330
"tabletojson",
331+
"taskprovider",
332+
"tavily",
322333
"TAVILY",
323334
"templ",
335+
"testcontroller",
324336
"testhost",
325337
"Textify",
326338
"textsplitter",
@@ -330,6 +342,7 @@
330342
"tokenless",
331343
"tracefile",
332344
"traceparser",
345+
"tracetree",
333346
"treegrid",
334347
"treesitter",
335348
"tvly",

demo/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
.env
22
.genaiscript
3+
.github/instructions/genaiscript.instructions.md

docs/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"dependencies": {
2626
"@astrojs/check": "^0.9.4",
2727
"@astrojs/starlight": "0.34.4",
28-
"astro": "^5.11.0",
28+
"astro": "^5.12.0",
2929
"astro-embed": "^0.9.0",
3030
"rehype-mermaid": "^3.0.0",
3131
"starlight-blog": "^0.24.0",

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,9 @@
127127
"playwright": "^1.54.1",
128128
"prettier": "catalog:",
129129
"prettier-plugin-curly": "^0.3.2",
130-
"release-it": "^19.0.3",
130+
"release-it": "^19.0.4",
131131
"tsx": "catalog:",
132-
"turbo": "^2.5.4",
132+
"turbo": "^2.5.5",
133133
"zx": "catalog:"
134134
}
135135
}

packages/api/src/run.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright (c) Microsoft Corporation.
22
// Licensed under the MIT License.
33

4-
import { resolve, join, relative } from "node:path";
4+
import { resolve, join, relative, basename } from "node:path";
55
import { writeFile, appendFile } from "node:fs/promises";
66
import { confirmOrSkipInCI } from "@genaiscript/runtime";
77
import type {
@@ -65,7 +65,6 @@ import {
6565
githubCreatePullRequestReviews,
6666
githubParseEnv,
6767
githubUpdatePullRequestDescription,
68-
host,
6968
isCI,
7069
isCancelError,
7170
isJSONLFilename,
@@ -190,7 +189,7 @@ export async function runScriptInternal(
190189
infoCb,
191190
partialCb,
192191
} = options || {};
193-
const runtimeHost = resolveRuntimeHost()
192+
const runtimeHost = resolveRuntimeHost();
194193
runtimeHost.clearModelAlias("script");
195194
let result: GenerationResult;
196195
let workspaceFiles = options.workspaceFiles || [];
@@ -319,7 +318,7 @@ export async function runScriptInternal(
319318
for (let arg of files) {
320319
checkCancelled(cancellationToken);
321320
dbg(`resolving ${arg}`);
322-
const stat = await host.statFile(arg);
321+
const stat = await runtimeHost.statFile(arg);
323322
if (stat?.type === "file") {
324323
dbg(`file found %s`, arg);
325324
if (!ignorer?.([arg])?.length) {
@@ -344,11 +343,11 @@ export async function runScriptInternal(
344343
}
345344

346345
if (stat?.type === "directory") {
347-
arg = host.path.join(arg, "**", "*");
346+
arg = join(arg, "**", "*");
348347
dbg(`directory, updating to %s`, arg);
349348
}
350349
dbg(`expand ${arg} (apply .gitignore: ${applyGitIgnore})`);
351-
const ffs = await host.findFiles(arg, {
350+
const ffs = await runtimeHost.findFiles(arg, {
352351
applyGitIgnore,
353352
});
354353
if (!ffs?.length && arg.includes("*")) {
@@ -365,7 +364,7 @@ export async function runScriptInternal(
365364

366365
if (excludedFiles.length) {
367366
for (const arg of excludedFiles) {
368-
const ffs = await host.findFiles(arg);
367+
const ffs = await runtimeHost.findFiles(arg);
369368
for (const f of ffs) {
370369
dbg(`removing excluded file %s`, f);
371370
resolvedFiles.delete(filePathOrUrlToWorkspaceFile(f));
@@ -768,7 +767,7 @@ async function aggregateResults(
768767
result: GenerationResult,
769768
): Promise<void> {
770769
const statsDir = await createStatsDir();
771-
const statsFile = host.path.join(statsDir, "runs.csv");
770+
const statsFile = join(statsDir, "runs.csv");
772771
if (!(await tryStat(statsFile))) {
773772
await writeFile(
774773
statsFile,
@@ -795,7 +794,7 @@ async function aggregateResults(
795794
acc.total_tokens,
796795
acc.prompt_tokens,
797796
acc.completion_tokens,
798-
outTrace ? host.path.basename(outTrace) : "",
797+
outTrace ? basename(outTrace) : "",
799798
result.version,
800799
]
801800
.map((s) => String(s))

packages/cli/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
"execa": "catalog:",
5252
"fastify": "^5.4.0",
5353
"inflection": "catalog:",
54-
"openai": "^5.9.0",
54+
"openai": "^5.10.1",
5555
"replace-ext": "^2.0.0",
5656
"tslib": "catalog:",
5757
"typescript": "catalog:",

packages/cli/src/convert.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import {
1919
filePathOrUrlToWorkspaceFile,
2020
getConvertDir,
2121
hash,
22-
host,
2322
link,
2423
logError,
2524
logInfo,
@@ -31,11 +30,12 @@ import {
3130
tryReadText,
3231
unfence,
3332
writeText,
33+
resolveRuntimeHost,
3434
} from "@genaiscript/core";
3535
import { buildProject } from "@genaiscript/core";
3636
import { run } from "@genaiscript/api";
3737
import { setupTraceWriting } from "@genaiscript/core";
38-
import { dirname, join } from "node:path";
38+
import { dirname, join, resolve } from "node:path";
3939
import { createCancellationController } from "@genaiscript/core";
4040

4141
/**
@@ -73,6 +73,7 @@ export async function convertFiles(
7373
options || {};
7474

7575
await ensureDotGenaiscriptPath();
76+
const runtimeHost = resolveRuntimeHost();
7677
const canceller = createCancellationController();
7778
const cancellationToken = canceller.token;
7879
const signal = toSignal(cancellationToken);
@@ -93,8 +94,6 @@ export async function convertFiles(
9394
const fail = (msg: string, _exitCode: number, _url?: string) => {
9495
throw new Error(msg);
9596
};
96-
const { resolve } = host.path;
97-
9897
const toolFiles: string[] = [];
9998
if (GENAI_ANY_REGEX.test(scriptId)) toolFiles.push(scriptId);
10099
const prj = await buildProject({
@@ -130,9 +129,9 @@ export async function convertFiles(
130129
resolvedFiles.add(arg);
131130
continue;
132131
}
133-
const stats = await host.statFile(arg);
134-
if (stats?.type === "directory") arg = host.path.join(arg, "**", "*");
135-
const ffs = await host.findFiles(arg, {
132+
const stats = await runtimeHost.statFile(arg);
133+
if (stats?.type === "directory") arg = join(arg, "**", "*");
134+
const ffs = await runtimeHost.findFiles(arg, {
136135
applyGitIgnore,
137136
});
138137
if (!ffs?.length) {
@@ -148,7 +147,7 @@ export async function convertFiles(
148147
}
149148
if (excludedFiles?.length) {
150149
for (const arg of excludedFiles) {
151-
const ffs = await host.findFiles(arg);
150+
const ffs = await runtimeHost.findFiles(arg);
152151
for (const f of ffs) resolvedFiles.delete(filePathOrUrlToWorkspaceFile(f));
153152
}
154153
}

packages/cli/src/info.ts

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ import {
1414
type ModelConnectionOptions,
1515
YAMLStringify,
1616
deleteUndefinedValues,
17-
host,
1817
resolveLanguageModelConfigurations,
1918
resolveModelAlias,
2019
resolveModelConnectionInfo,
2120
resolveRuntimeHost,
2221
} from "@genaiscript/core";
2322
import { buildProject } from "@genaiscript/core";
23+
import { resolve } from "node:path";
2424

2525
/**
2626
* Outputs basic system information including node version, platform, architecture, and process ID.
@@ -63,7 +63,7 @@ async function resolveScriptsConnectionInfo(
6363
scripts: ModelConnectionOptions[],
6464
options?: { token?: boolean },
6565
): Promise<ModelConnectionInfo[]> {
66-
const runtimeHost = resolveRuntimeHost()
66+
const runtimeHost = resolveRuntimeHost();
6767
const models: Record<string, ModelConnectionOptions> = {};
6868

6969
// Deduplicate model connection options
@@ -81,7 +81,7 @@ async function resolveScriptsConnectionInfo(
8181
resolveModelConnectionInfo(conn, {
8282
...(options || {}),
8383
defaultModel: LARGE_MODEL_ID,
84-
}).then((res) => res.info),
84+
}).then((r) => r.info),
8585
),
8686
);
8787
return res;
@@ -93,11 +93,13 @@ async function resolveScriptsConnectionInfo(
9393
* @param script - The specific script ID or filename to filter by. If not provided, all scripts are included.
9494
* @param options - Configuration options, including whether to show tokens.
9595
*/
96-
export async function scriptModelInfo(script: string, options?: { token?: boolean }) {
96+
export async function scriptModelInfo(
97+
script: string,
98+
options?: { token?: boolean },
99+
): Promise<void> {
97100
const prj = await buildProject();
98101
const templates = prj.scripts.filter(
99-
(t) =>
100-
!script || t.id === script || host.path.resolve(t.filename) === host.path.resolve(script),
102+
(t) => !script || t.id === script || resolve(t.filename) === resolve(script),
101103
);
102104
const info = await resolveScriptsConnectionInfo(templates, options);
103105
console.log(YAMLStringify(info));
@@ -113,8 +115,8 @@ export async function scriptModelInfo(script: string, options?: { token?: boolea
113115
*
114116
* @param none This function does not require any parameters.
115117
*/
116-
export async function modelAliasesInfo() {
117-
const runtimeHost = resolveRuntimeHost()
118+
export async function modelAliasesInfo(): Promise<void> {
119+
const runtimeHost = resolveRuntimeHost();
118120
const res = Object.fromEntries(
119121
Object.entries(runtimeHost.modelAliases).map(([k, v]) => [
120122
k,
@@ -135,8 +137,8 @@ export async function modelAliasesInfo() {
135137
export async function modelList(
136138
provider: string,
137139
options?: { error?: boolean; format?: "json" | "yaml" },
138-
) {
139-
const runtimeHost = resolveRuntimeHost()
140+
): Promise<void> {
141+
const runtimeHost = resolveRuntimeHost();
140142
await runtimeHost.readConfig();
141143
const providers = await resolveLanguageModelConfigurations(provider, {
142144
...(options || {}),
@@ -147,12 +149,13 @@ export async function modelList(
147149
});
148150

149151
if (options?.format === "json") console.log(JSON.stringify(providers, null, 2));
150-
else
152+
else {
151153
console.log(
152154
YAMLStringify(
153155
deleteUndefinedValues(
154156
Object.fromEntries(providers.map((p) => [p.provider, p.error || p.models])),
155157
),
156158
),
157159
);
160+
}
158161
}

packages/cli/src/scripts.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export async function listScripts(
4040
const prj = await buildProject(); // Build the project to get script templates
4141
const scripts = filterScripts(prj.scripts, { ids, ...(options || {}) }); // Filter scripts based on options
4242
if (!json) console.log(scripts.map(({ id, filename }) => `${id} - ${filename}`).join("\n"));
43-
else
43+
else {
4444
console.log(
4545
JSON.stringify(
4646
scripts.map(({ id, title, group, filename, inputSchema, isSystem }) =>
@@ -57,6 +57,7 @@ export async function listScripts(
5757
2,
5858
),
5959
);
60+
}
6061
}
6162

6263
/**
@@ -69,7 +70,7 @@ export async function listScripts(
6970
* The function checks if the script exists in the project. If found, it prints
7071
* metadata and the script's function signature. If not found, it logs an error message.
7172
*/
72-
export async function scriptInfo(scriptId: string) {
73+
export async function scriptInfo(scriptId: string): Promise<void> {
7374
const prj = await buildProject();
7475
const script = prj.scripts.find((t) => t.id === scriptId);
7576
if (!script) {
@@ -105,7 +106,7 @@ export async function scriptInfo(scriptId: string) {
105106
* @param name - The name of the script to be created. If not provided, the user will be prompted to enter it.
106107
* @param options - Options for script creation, including whether to use TypeScript.
107108
*/
108-
export async function createScript(name: string, options: { typescript: boolean }) {
109+
export async function createScript(name: string, options: { typescript: boolean }): Promise<void> {
109110
const { typescript } = options;
110111
if (!name) {
111112
name = await shellInput("Enter the name of the script"); // Prompt user for script name if not provided
@@ -133,7 +134,7 @@ export async function fixScripts(options?: {
133134
githubCopilotInstructions?: boolean;
134135
docs?: boolean;
135136
force?: boolean;
136-
}) {
137+
}): Promise<void> {
137138
const project = await buildProject(); // Build the project to access information
138139
await fixPromptDefinitions(project, options); // Fix any issues in prompt definitions
139140
await fixGitHubCopilotInstructions(options);

0 commit comments

Comments
 (0)