@gaia-ai/gaia 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/plugin.js ADDED
@@ -0,0 +1,78 @@
1
+ // src/core/exec.ts
2
+ import { execFile } from "node:child_process";
3
+ import { promisify } from "node:util";
4
+ var execFileAsync = promisify(execFile);
5
+ var ExecError = class extends Error {
6
+ constructor(file, args, exitCode, stderr, options) {
7
+ super(`exec failed: ${file}`, options);
8
+ this.file = file;
9
+ this.args = args;
10
+ this.exitCode = exitCode;
11
+ this.stderr = stderr;
12
+ this.name = "ExecError";
13
+ }
14
+ file;
15
+ args;
16
+ exitCode;
17
+ stderr;
18
+ };
19
+ var CommandRunner = class {
20
+ constructor(logger) {
21
+ this.logger = logger;
22
+ }
23
+ logger;
24
+ async run(file, args, opts = {}) {
25
+ try {
26
+ const { stdout } = await execFileAsync(file, args, {
27
+ encoding: "utf8",
28
+ ...opts
29
+ });
30
+ this.logger.debug({ file, args, cwd: opts.cwd }, "exec ok");
31
+ return stdout;
32
+ } catch (err) {
33
+ const e = err;
34
+ const exitCode = typeof e.code === "number" ? e.code : null;
35
+ const stderr = e.stderr ?? "";
36
+ this.logger.error(
37
+ { file, args, cwd: opts.cwd, exitCode, stderr },
38
+ "exec failed"
39
+ );
40
+ throw new ExecError(file, args, exitCode, stderr, { cause: err });
41
+ }
42
+ }
43
+ };
44
+ var noopLogger = {
45
+ debug() {
46
+ },
47
+ info() {
48
+ },
49
+ warn() {
50
+ },
51
+ error() {
52
+ }
53
+ };
54
+ var defaultRunner = new CommandRunner(noopLogger);
55
+ function setDefaultCommandRunner(r) {
56
+ defaultRunner = r;
57
+ }
58
+ function exec(file, args, opts = {}) {
59
+ return defaultRunner.run(file, args, opts);
60
+ }
61
+
62
+ // src/core/slug.ts
63
+ var DEFAULT_SLUG_MAX_LENGTH = 40;
64
+ function slugify(text, maxLength = DEFAULT_SLUG_MAX_LENGTH) {
65
+ const slug = text.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "");
66
+ if (slug.length <= maxLength) {
67
+ return slug;
68
+ }
69
+ return slug.slice(0, maxLength).replace(/-+$/g, "");
70
+ }
71
+ export {
72
+ CommandRunner,
73
+ DEFAULT_SLUG_MAX_LENGTH,
74
+ ExecError,
75
+ exec,
76
+ setDefaultCommandRunner,
77
+ slugify
78
+ };