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

Commit 257c5e9

Browse files
committed
refactor: update type definitions and improve global declarations for YAML, CSV, and other utilities
1 parent fd944ae commit 257c5e9

12 files changed

Lines changed: 156 additions & 65 deletions

File tree

packages/cli/src/action.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,12 @@ export async function actionConfigure(
260260
].filter(Boolean);
261261

262262
const actionYmlFilename = resolve(out, "action.yml");
263-
const action = YAMLTryParse(await tryReadText(actionYmlFilename));
263+
const action = YAMLTryParse(await tryReadText(actionYmlFilename)) as {
264+
description?: string;
265+
inputs?: Record<string, GitHubActionFieldType>;
266+
outputs?: Record<string, GitHubActionFieldType>;
267+
branding?: Record<string, unknown>;
268+
};
264269
if (action && !force) {
265270
logVerbose(`updating action.yml`);
266271
action.description = script.description || pkg?.description;

packages/core/src/globals.ts

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import { frontmatterTryParse, splitMarkdown, updateFrontmatter } from "./frontma
1212
import { JSONLStringify, JSONLTryParse } from "./jsonl.js";
1313
import { HTMLTablesToJSON, HTMLToMarkdown, HTMLToText } from "./html.js";
1414
import { CancelError } from "./error.js";
15-
import { fetchText } from "./fetchtext.js";
1615
import { GitHubClient } from "./githubclient.js";
1716
import { GitClient } from "./git.js";
1817
import { estimateTokens, truncateTextToTokens } from "./tokens.js";
@@ -62,26 +61,26 @@ export function installGlobals() {
6261
glb.YAML = createYAML();
6362

6463
// Freeze CSV utilities
65-
glb.CSV = Object.freeze<CSV>({
64+
glb.CSV = Object.freeze<CSVObject>({
6665
parse: CSVParse, // Parse CSV string to objects
6766
stringify: CSVStringify, // Convert objects to CSV string
6867
markdownify: dataToMarkdownTable, // Convert CSV to Markdown format
6968
chunk: CSVChunk,
7069
});
7170

7271
// Freeze INI utilities
73-
glb.INI = Object.freeze<INI>({
72+
glb.INI = Object.freeze<INIObject>({
7473
parse: INIParse, // Parse INI string to objects
7574
stringify: INIStringify, // Convert objects to INI string
7675
});
7776

7877
// Freeze XML utilities
79-
glb.XML = Object.freeze<XML>({
78+
glb.XML = Object.freeze<XMLObject>({
8079
parse: XMLParse, // Parse XML string to objects
8180
});
8281

8382
// Freeze Markdown utilities with frontmatter operations
84-
glb.MD = Object.freeze<MD>({
83+
glb.MD = Object.freeze<MDObject>({
8584
stringify: MarkdownStringify,
8685
frontmatter: (text, format) => frontmatterTryParse(text, { format })?.value ?? {}, // Parse frontmatter from markdown
8786
content: (text) => splitMarkdown(text)?.content, // Extract content from markdown
@@ -97,12 +96,12 @@ export function installGlobals() {
9796
});
9897

9998
// Freeze JSONL utilities
100-
glb.JSONL = Object.freeze<JSONL>({
99+
glb.JSONL = Object.freeze<JSONLObject>({
101100
parse: JSONLTryParse, // Parse JSONL string to objects
102101
stringify: JSONLStringify, // Convert objects to JSONL string
103102
});
104103

105-
glb.JSON5 = Object.freeze<JSON5>({
104+
glb.JSON5 = Object.freeze<JSON5Object>({
106105
parse: JSON5TryParse,
107106
stringify: JSON5Stringify,
108107
});
@@ -113,7 +112,7 @@ export function installGlobals() {
113112
});
114113

115114
// Freeze HTML utilities
116-
glb.HTML = Object.freeze<HTML>({
115+
glb.HTML = Object.freeze<HTMLObject>({
117116
convertTablesToJSON: HTMLTablesToJSON, // Convert HTML tables to JSON
118117
convertToMarkdown: HTMLToMarkdown, // Convert HTML to Markdown
119118
convertToText: HTMLToText, // Convert HTML to plain text
@@ -149,19 +148,10 @@ export function installGlobals() {
149148
chunk: chunk,
150149
});
151150

152-
/**
153-
* Asynchronous function to fetch text from a URL or file.
154-
* Handles both HTTP(S) URLs and local workspace files.
155-
* @param urlOrFile - URL or file descriptor.
156-
* @param [fetchOptions] - Options for fetching.
157-
* @returns Fetch result.
158-
*/
159-
glb.fetchText = fetchText; // Assign fetchText function to global
160-
161151
// ffmpeg
162152
glb.ffmpeg = new FFmepgClient();
163153

164-
glb.DIFF = Object.freeze<DIFF>({
154+
glb.DIFF = Object.freeze<DIFFObject>({
165155
parse: tryDiffParse,
166156
createPatch: diffCreatePatch,
167157
findChunk: diffFindChunk,

packages/core/src/types.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3086,7 +3086,7 @@ export interface Parsers {
30863086
prompty(file: WorkspaceFile): Promise<PromptyDocument>;
30873087
}
30883088

3089-
export interface YAML {
3089+
export interface YAMLObject {
30903090
/**
30913091
* Parses a YAML string into a JavaScript object using JSON5.
30923092
*/
@@ -3224,7 +3224,7 @@ export type DiffChangeType = "normal" | "add" | "del";
32243224

32253225
export type DiffChange = DiffNormalChange | DiffAddChange | DiffDeleteChange;
32263226

3227-
export interface DIFF {
3227+
export interface DIFFObject {
32283228
/**
32293229
* Parses a diff string into a structured object
32303230
* @param input
@@ -3260,7 +3260,7 @@ export interface DIFF {
32603260
): string;
32613261
}
32623262

3263-
export interface XML {
3263+
export interface XMLObject {
32643264
/**
32653265
* Parses an XML payload to an object
32663266
* @param text
@@ -3308,7 +3308,7 @@ export interface HTMLToMarkdownOptions {
33083308
disableGfm?: boolean;
33093309
}
33103310

3311-
export interface HTML {
3311+
export interface HTMLObject {
33123312
/**
33133313
* Converts all HTML tables to JSON.
33143314
* @param html
@@ -4083,7 +4083,7 @@ export interface GitHub {
40834083
client(owner: string, repo: string): GitHub;
40844084
}
40854085

4086-
export interface MD {
4086+
export interface MDObject {
40874087
/**
40884088
* Parses front matter from markdown
40894089
* @param text
@@ -4129,7 +4129,7 @@ export interface MD {
41294129

41304130
export interface GitHubAIDisclaimerOptions extends Record<string, unknown> {}
41314131

4132-
export interface JSONL {
4132+
export interface JSONLObject {
41334133
/**
41344134
* Parses a JSONL string to an array of objects
41354135
* @param text
@@ -4142,7 +4142,7 @@ export interface JSONL {
41424142
stringify(objs: any[]): string;
41434143
}
41444144

4145-
export interface INI {
4145+
export interface INIObject {
41464146
/**
41474147
* Parses a .ini file
41484148
* @param text
@@ -4156,7 +4156,7 @@ export interface INI {
41564156
stringify(value: any): string;
41574157
}
41584158

4159-
export interface JSON5 {
4159+
export interface JSON5Object {
41604160
/**
41614161
* Parses a JSON/YAML/XML string to an object
41624162
* @param text
@@ -4178,7 +4178,7 @@ export interface CSVStringifyOptions {
41784178
/**
41794179
* Interface representing CSV operations.
41804180
*/
4181-
export interface CSV {
4181+
export interface CSVObject {
41824182
/**
41834183
* Parses a CSV string to an array of objects.
41844184
*

packages/core/src/types/prompt_template.d.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3076,7 +3076,7 @@ interface Parsers {
30763076
prompty(file: WorkspaceFile): Promise<PromptyDocument>;
30773077
}
30783078

3079-
interface YAML {
3079+
interface YAMLObject {
30803080
/**
30813081
* Parses a YAML string into a JavaScript object using JSON5.
30823082
*/
@@ -3212,7 +3212,7 @@ type DiffChangeType = "normal" | "add" | "del";
32123212

32133213
type DiffChange = DiffNormalChange | DiffAddChange | DiffDeleteChange;
32143214

3215-
interface DIFF {
3215+
interface DIFFObject {
32163216
/**
32173217
* Parses a diff string into a structured object
32183218
* @param input
@@ -3248,7 +3248,7 @@ interface DIFF {
32483248
): string;
32493249
}
32503250

3251-
interface XML {
3251+
interface XMLObject {
32523252
/**
32533253
* Parses an XML payload to an object
32543254
* @param text
@@ -3296,7 +3296,7 @@ interface HTMLToMarkdownOptions {
32963296
disableGfm?: boolean;
32973297
}
32983298

3299-
interface HTML {
3299+
interface HTMLObject {
33003300
/**
33013301
* Converts all HTML tables to JSON.
33023302
* @param html
@@ -4075,7 +4075,7 @@ interface GitHub {
40754075
client(owner: string, repo: string): GitHub;
40764076
}
40774077

4078-
interface MD {
4078+
interface MDObject {
40794079
/**
40804080
* Parses front matter from markdown
40814081
* @param text
@@ -4119,7 +4119,7 @@ interface MD {
41194119
): string;
41204120
}
41214121

4122-
interface JSONL {
4122+
interface JSONLObject {
41234123
/**
41244124
* Parses a JSONL string to an array of objects
41254125
* @param text
@@ -4132,7 +4132,7 @@ interface JSONL {
41324132
stringify(objs: any[]): string;
41334133
}
41344134

4135-
interface INI {
4135+
interface INIObject {
41364136
/**
41374137
* Parses a .ini file
41384138
* @param text
@@ -4146,7 +4146,7 @@ interface INI {
41464146
stringify(value: any): string;
41474147
}
41484148

4149-
interface JSON5 {
4149+
interface JSON5Object {
41504150
/**
41514151
* Parses a JSON/YAML/XML string to an object
41524152
* @param text
@@ -4168,7 +4168,7 @@ interface CSVStringifyOptions {
41684168
/**
41694169
* Interface representing CSV operations.
41704170
*/
4171-
interface CSV {
4171+
interface CSVObject {
41724172
/**
41734173
* Parses a CSV string to an array of objects.
41744174
*

packages/core/src/types/prompt_type.d.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -154,42 +154,42 @@ declare let workspace: WorkspaceFileSystem;
154154
/**
155155
* YAML parsing and stringifying functions.
156156
*/
157-
declare let YAML: YAML;
157+
declare let YAML: YAMLObject;
158158

159159
/**
160160
* INI parsing and stringifying.
161161
*/
162-
declare let INI: INI;
162+
declare let INI: INIObject;
163163

164164
/**
165165
* CSV parsing and stringifying.
166166
*/
167-
declare let CSV: CSV;
167+
declare let CSV: CSVObject;
168168

169169
/**
170170
* XML parsing and stringifying.
171171
*/
172-
declare let XML: XML;
172+
declare let XML: XMLObject;
173173

174174
/**
175175
* HTML parsing
176176
*/
177-
declare let HTML: HTML;
177+
declare let HTML: HTMLObject;
178178

179179
/**
180180
* Markdown and frontmatter parsing.
181181
*/
182-
declare let MD: MD;
182+
declare let MD: MDObject;
183183

184184
/**
185185
* JSONL parsing and stringifying.
186186
*/
187-
declare let JSONL: JSONL;
187+
declare let JSONL: JSONLObject;
188188

189189
/**
190190
* JSON5 parsing
191191
*/
192-
declare let JSON5: JSON5;
192+
declare let JSON5: JSON5Object;
193193

194194
/**
195195
* JSON Schema utilities
@@ -199,7 +199,7 @@ declare let JSONSchema: JSONSchemaUtilities;
199199
/**
200200
* Diff utilities
201201
*/
202-
declare let DIFF: DIFF;
202+
declare let DIFF: DIFFObject;
203203

204204
/**
205205
* Access to current LLM chat session information

packages/core/src/yaml.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import { parse, stringify } from "yaml";
1111
import { filenameOrFileToContent } from "./unwrappers.js";
1212
import { dedent } from "./indent.js";
13-
import type { WorkspaceFile, YAML } from "./types.js";
13+
import type { WorkspaceFile, YAMLObject } from "./types.js";
1414

1515
/**
1616
* Safely attempts to parse a YAML string into a JavaScript object.
@@ -28,7 +28,7 @@ import type { WorkspaceFile, YAML } from "./types.js";
2828
* @returns The parsed object, or the defaultValue if parsing fails or
2929
* conditions are met.
3030
*/
31-
export function YAMLTryParse<T = any>(
31+
export function YAMLTryParse<T = unknown>(
3232
text: string | WorkspaceFile,
3333
defaultValue?: T,
3434
options?: { ignoreLiterals?: boolean },
@@ -40,7 +40,7 @@ export function YAMLTryParse<T = any>(
4040
// Check if parsed result is a primitive and ignoreLiterals is true
4141
if (ignoreLiterals && ["number", "boolean", "string"].includes(typeof res)) return defaultValue;
4242
return res ?? defaultValue;
43-
} catch (e) {
43+
} catch {
4444
// Return defaultValue in case of a parsing error
4545
return defaultValue;
4646
}
@@ -54,6 +54,7 @@ export function YAMLTryParse<T = any>(
5454
* @param text - The YAML string or workspace file to parse.
5555
* @returns The parsed JavaScript object.
5656
*/
57+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
5758
export function YAMLParse(text: string | WorkspaceFile): any {
5859
text = filenameOrFileToContent(text);
5960
return parse(text);
@@ -66,6 +67,7 @@ export function YAMLParse(text: string | WorkspaceFile): any {
6667
* @param obj - The object to convert to YAML.
6768
* @returns The YAML string representation of the object.
6869
*/
70+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
6971
export function YAMLStringify(obj: any): string {
7072
return stringify(obj, undefined, 2);
7173
}
@@ -82,7 +84,8 @@ export function YAMLStringify(obj: any): string {
8284
* @param values - Corresponding interpolated values to be included in the YAML string.
8385
* @returns A parsed object generated from the combined template strings and values.
8486
*/
85-
export function createYAML(): YAML {
87+
export function createYAML(): YAMLObject {
88+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
8689
const res = (strings: TemplateStringsArray, ...values: any[]): any => {
8790
let result = strings[0];
8891
values.forEach((value, i) => {
@@ -93,5 +96,5 @@ export function createYAML(): YAML {
9396
};
9497
res.parse = YAMLParse;
9598
res.stringify = YAMLStringify;
96-
return Object.freeze<YAML>(res) satisfies YAML;
99+
return Object.freeze<YAMLObject>(res) satisfies YAMLObject;
97100
}

packages/runtime/src/cast.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import type {
77
PromptGeneratorOptions,
88
StringLike,
99
} from "@genaiscript/core";
10-
import { resolveChatGenerationContext, resolveRuntime } from "./runtime.js";
10+
import { resolveChatGenerationContext } from "./runtime.js";
1111

1212
/**
1313
* Converts unstructured text or data into structured JSON format.
@@ -28,7 +28,6 @@ export async function cast(
2828
},
2929
): Promise<{ data?: unknown; error?: string; text: string }> {
3030
const ctx = resolveChatGenerationContext(options);
31-
const { parsers } = resolveRuntime();
3231
const { multiple, instructions, label = `cast text to schema`, ...rest } = options || {};
3332
const responseSchema = multiple
3433
? ({

0 commit comments

Comments
 (0)