Skip to content
This repository was archived by the owner on May 29, 2026. It is now read-only.

Commit be17dad

Browse files
[web] @genaiscript/web modernization (#1638)
* [web] Code cleanup * [runtime] Add in worker initialization
1 parent 8ea184a commit be17dad

56 files changed

Lines changed: 3297 additions & 3313 deletions

Some content is hidden

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

docs/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
"version": "2.0.4",
66
"license": "MIT",
77
"scripts": {
8+
"install:playwright": " pnpm exec playwright install --with-deps",
9+
"postinstall": "pnpm install:playwright",
810
"dev": "astro telemetry disable && astro dev --host",
911
"start": "astro dev --host",
1012
"check": "astro check",

packages/globals/README.md

Lines changed: 0 additions & 13 deletions
This file was deleted.

packages/globals/eslint.config.mjs

Lines changed: 0 additions & 7 deletions
This file was deleted.

packages/globals/package.json

Lines changed: 0 additions & 75 deletions
This file was deleted.

packages/globals/src/index.ts

Lines changed: 0 additions & 8 deletions
This file was deleted.

packages/globals/tsconfig.json

Lines changed: 0 additions & 18 deletions
This file was deleted.

packages/globals/vitest.config.ts

Lines changed: 0 additions & 22 deletions
This file was deleted.

packages/runtime/src/index.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,17 @@ export * from "./nodehost.js";
88
export * from "./playwright.js";
99
export * from "./runtime.js";
1010
export * from "./version.js";
11+
12+
import { installGlobals } from "@genaiscript/core";
13+
import { NodeHost } from "./nodehost.js";
14+
15+
installGlobals();
16+
17+
async function main() {
18+
await NodeHost.install(undefined, undefined);
19+
}
20+
21+
main().catch((err) => {
22+
console.error("Error during NodeHost installation:", err);
23+
process.exit(1);
24+
});

packages/runtime/src/runtime.ts

Lines changed: 2 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
*/
99
import type {
1010
Awaitable,
11-
BrowserPage,
1211
ChatGenerationContext,
1312
ElementOrArray,
1413
FileStats,
@@ -28,19 +27,7 @@ import type {
2827
import { delay, uniq, uniqBy, chunk } from "es-toolkit";
2928
import { z } from "zod";
3029

31-
let globalPromptContext: PromptContext | undefined;
32-
33-
/**
34-
* Initialize the global prompt context.
35-
* @param ctx The prompt context to initialize.
36-
*/
37-
export function initialize(ctx: PromptContext) {
38-
globalPromptContext = ctx;
39-
}
40-
41-
function checkInitialized() {
42-
if (!globalPromptContext) throw new Error("GenAIScript runtime not initialized");
43-
}
30+
const globalPromptContext: PromptContext = globalThis as unknown as PromptContext;
4431

4532
/**
4633
* Utility functions exported for general use
@@ -91,7 +78,6 @@ export async function classify<L extends Record<string, string>>(
9178
logprobs?: Record<keyof typeof labels | "other", Logprob>;
9279
usage?: RunPromptUsage;
9380
}> {
94-
checkInitialized();
9581
const { other, explanations, ...rest } = options || {};
9682

9783
const entries = Object.entries({
@@ -231,7 +217,6 @@ export async function cast(
231217
ctx?: ChatGenerationContext;
232218
},
233219
): Promise<{ data?: unknown; error?: string; text: string }> {
234-
checkInitialized();
235220
const {
236221
ctx = globalPromptContext.env.generator,
237222
multiple,
@@ -282,13 +267,11 @@ export async function markdownifyPdf(
282267
ctx?: ChatGenerationContext;
283268
},
284269
) {
285-
checkInitialized();
286270
const {
287271
ctx = globalPromptContext.env.generator,
288272
label = `markdownify PDF`,
289273
model = "ocr",
290274
responseType = "markdown",
291-
systemSafety = true,
292275
instructions,
293276
...rest
294277
} = options || {};
@@ -369,7 +352,6 @@ export async function fileTree(
369352
preview?: (file: WorkspaceFile, stats: FileStats) => Awaitable<unknown>;
370353
},
371354
): Promise<string> {
372-
checkInitialized();
373355
const { frontmatter, preview, query, size, ignore, ...rest } = options || {};
374356
const readText = !!(frontmatter || preview);
375357
// TODO
@@ -407,7 +389,7 @@ export async function fileTree(
407389
metadata.push(
408390
...frontmatter
409391
.map((field) => [field, fm[field]])
410-
.filter(([_, v]) => v !== undefined)
392+
.filter(([, v]) => v !== undefined)
411393
.map(([k, v]) => `${k}: ${JSON.stringify(v)}`),
412394
);
413395
}
@@ -450,54 +432,3 @@ export async function fileTree(
450432
}
451433
}
452434

453-
/**
454-
* Injects @mozilla/readability into a page to extract structured data from an article.
455-
* This function evaluates the page content using the Readability library to parse and extract details such as title, content, text, and metadata.
456-
*
457-
* @param page - The browser page instance to evaluate and extract content from.
458-
* @returns An object containing the parsed article details, including title, content, text content, length, excerpt, byline, direction, site name, language, and published time, or null if parsing fails.
459-
* @see https://github.com/mishushakov/llm-scraper/
460-
*/
461-
export async function parseReadableContent<T = string>(
462-
page: BrowserPage,
463-
): Promise<null | {
464-
/** article title */
465-
title: string | null | undefined;
466-
467-
/** HTML string of processed article content */
468-
content: T | null | undefined;
469-
470-
/** text content of the article, with all the HTML tags removed */
471-
textContent: string | null | undefined;
472-
473-
/** length of an article, in characters */
474-
length: number | null | undefined;
475-
476-
/** article description, or short excerpt from the content */
477-
excerpt: string | null | undefined;
478-
479-
/** author metadata */
480-
byline: string | null | undefined;
481-
482-
/** content direction */
483-
dir: string | null | undefined;
484-
485-
/** name of the site */
486-
siteName: string | null | undefined;
487-
488-
/** content language */
489-
lang: string | null | undefined;
490-
491-
/** published time */
492-
publishedTime: string | null | undefined;
493-
}> {
494-
const results = await page.evaluate(async () => {
495-
const readability = await import(
496-
// @ts-ignore
497-
"https://cdn.skypack.dev/@mozilla/readability"
498-
);
499-
const doc = document.cloneNode(true);
500-
return new readability.Readability(doc).parse();
501-
});
502-
return results;
503-
}

packages/runtime/src/utils/pathUtils-cjs.cts

Lines changed: 0 additions & 4 deletions
This file was deleted.

0 commit comments

Comments
 (0)