@toolforge-js/sdk 0.7.0 → 0.8.0
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/cli/index.js +18 -15
- package/dist/components/index.d.ts +32 -32
- package/dist/components/index.js +1 -1
- package/dist/{agent-DBDnKm26.js → tool-UVAGtnlr.js} +109 -109
- package/package.json +3 -2
package/dist/cli/index.js
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
|
-
import { C as __toESM, S as __require, _ as startAgentMessageSchema, a as
|
|
1
|
+
import { C as __toESM, S as __require, _ as startAgentMessageSchema, a as AGENT_TAG_NAME, b as stopToolMessageSchema, c as getErrorMessage, d as runWithRetries, f as ackMessageSchema, g as runnerId, h as initCommunicationMessageSchema, i as AGENT_STEP_TAG_NAME, l as invariant, m as heartbeatAckMessageSchema, n as TOOL_TAG_NAME, o as Agent, p as baseMessageSchema, r as Tool, s as convertToWords, t as TOOL_HANDLER_TAG_NAME, u as exponentialBackoff, v as startToolMessageSchema, x as __commonJS, y as stopAgentMessageSchema } from "../tool-UVAGtnlr.js";
|
|
2
2
|
import { t as toolForgeConfigSchema } from "../config-schema-CcWOtgOv.js";
|
|
3
3
|
import * as z$1 from "zod";
|
|
4
4
|
import z from "zod";
|
|
5
|
-
import { P, match } from "ts-pattern";
|
|
6
|
-
import { setTimeout as setTimeout$1 } from "node:timers/promises";
|
|
7
|
-
import { nanoid } from "nanoid";
|
|
8
5
|
import { readFileSync } from "node:fs";
|
|
9
6
|
import * as path from "node:path";
|
|
10
7
|
import { EventEmitter } from "node:events";
|
|
8
|
+
import ora from "ora";
|
|
11
9
|
import { pino } from "pino";
|
|
10
|
+
import { P, match } from "ts-pattern";
|
|
11
|
+
import { setTimeout as setTimeout$1 } from "node:timers/promises";
|
|
12
12
|
import chokidar from "chokidar";
|
|
13
|
+
import { nanoid } from "nanoid";
|
|
13
14
|
import picocolors from "picocolors";
|
|
14
15
|
import * as fs from "node:fs/promises";
|
|
15
16
|
import * as os from "node:os";
|
|
@@ -3800,8 +3801,8 @@ var ForgeRunner = class extends EventEmitter {
|
|
|
3800
3801
|
//#endregion
|
|
3801
3802
|
//#region src/cli/index.ts
|
|
3802
3803
|
const version = JSON.parse(readFileSync(path.resolve(__dirname, "../../package.json"), "utf-8")).version;
|
|
3803
|
-
program.name("toolforge
|
|
3804
|
-
program.command("dev").description("start the tool forge development server").option("-c, --config <path>", "path to the tool-forge config file", "toolforge.config.ts").option("-d, --debug", "enable debug logging", false).action(async function startServer() {
|
|
3804
|
+
program.name("toolforge").description("Tool Forge SDK cli").version(version);
|
|
3805
|
+
program.command("dev").description("start the tool forge development server").option("-c, --config <path>", "path to the tool-forge config file", (val) => z$1.string().parse(val), "toolforge.config.ts").option("-d, --debug", "enable debug logging", false).action(async function startServer() {
|
|
3805
3806
|
const debug = z$1.boolean().optional().default(false).parse(this.opts().debug);
|
|
3806
3807
|
await startToolForge({
|
|
3807
3808
|
configRelPath: z$1.string().parse(this.opts().config),
|
|
@@ -3809,7 +3810,15 @@ program.command("dev").description("start the tool forge development server").op
|
|
|
3809
3810
|
mode: "development"
|
|
3810
3811
|
});
|
|
3811
3812
|
});
|
|
3812
|
-
program.command("
|
|
3813
|
+
program.command("start").description("start the tool forge server in production mode").option("-c, --config <path>", "path to the tool-forge config file", (val) => z$1.string().parse(val), "toolforge.config.ts").option("-d, --debug", "enable debug logging", false).action(async function startServer() {
|
|
3814
|
+
const debug = z$1.boolean().optional().default(false).parse(this.opts().debug);
|
|
3815
|
+
await startToolForge({
|
|
3816
|
+
configRelPath: z$1.string().parse(this.opts().config),
|
|
3817
|
+
debug,
|
|
3818
|
+
mode: "production"
|
|
3819
|
+
});
|
|
3820
|
+
});
|
|
3821
|
+
program.command("build").description("build the tools for production").option("-c, --config <path>", "path to the tool-forge config file", (val) => z$1.string().parse(val), "toolforge.config.ts").option("-d, --debug", "enable debug logging", false).action(async function() {
|
|
3813
3822
|
const logger = pino({
|
|
3814
3823
|
level: z$1.boolean().optional().default(false).parse(this.opts().debug) ? "debug" : "info",
|
|
3815
3824
|
transport: { target: "pino-pretty" }
|
|
@@ -3838,22 +3847,16 @@ program.command("build").description("build the tools for production").option("-
|
|
|
3838
3847
|
process.exit(1);
|
|
3839
3848
|
}
|
|
3840
3849
|
});
|
|
3841
|
-
program.command("start").description("start the tool forge server in production mode").option("-c, --config <path>", "path to the tool-forge config file", "toolforge.config.ts").option("-d, --debug", "enable debug logging", false).action(async function startServer() {
|
|
3842
|
-
const debug = z$1.boolean().optional().default(false).parse(this.opts().debug);
|
|
3843
|
-
await startToolForge({
|
|
3844
|
-
configRelPath: z$1.string().parse(this.opts().config),
|
|
3845
|
-
debug,
|
|
3846
|
-
mode: "production"
|
|
3847
|
-
});
|
|
3848
|
-
});
|
|
3849
3850
|
async function startToolForge({ configRelPath, debug, mode }) {
|
|
3850
3851
|
const logger = pino({
|
|
3851
3852
|
level: debug ? "debug" : "info",
|
|
3852
3853
|
transport: { target: "pino-pretty" }
|
|
3853
3854
|
});
|
|
3854
3855
|
try {
|
|
3856
|
+
const spinner = ora("loading configuration...").start();
|
|
3855
3857
|
const configPath = path.resolve(process.cwd(), configRelPath);
|
|
3856
3858
|
const config = toolForgeConfigSchema.parse(await import(configPath).then((mod) => mod.default));
|
|
3859
|
+
spinner.stop();
|
|
3857
3860
|
logger.debug({ config }, "loaded config from %s", configPath);
|
|
3858
3861
|
const runner = new ForgeRunner(config, { mode }, logger);
|
|
3859
3862
|
runner.on("error", async (error) => {
|
|
@@ -5074,7 +5074,7 @@ declare class Block {
|
|
|
5074
5074
|
type: "number" | "currency" | "percentage";
|
|
5075
5075
|
decimals: number;
|
|
5076
5076
|
currency: string;
|
|
5077
|
-
currencyDisplay: "symbol" | "
|
|
5077
|
+
currencyDisplay: "symbol" | "name" | "code";
|
|
5078
5078
|
thousandsSeparator: string;
|
|
5079
5079
|
decimalSeparator: string;
|
|
5080
5080
|
showPercentageSymbol: boolean;
|
|
@@ -5111,7 +5111,7 @@ declare class Block {
|
|
|
5111
5111
|
type: "number" | "currency" | "percentage";
|
|
5112
5112
|
decimals: number;
|
|
5113
5113
|
currency: string;
|
|
5114
|
-
currencyDisplay: "symbol" | "
|
|
5114
|
+
currencyDisplay: "symbol" | "name" | "code";
|
|
5115
5115
|
thousandsSeparator: string;
|
|
5116
5116
|
decimalSeparator: string;
|
|
5117
5117
|
showPercentageSymbol: boolean;
|
|
@@ -5180,7 +5180,7 @@ declare class Block {
|
|
|
5180
5180
|
type: "number" | "currency" | "percentage";
|
|
5181
5181
|
decimals: number;
|
|
5182
5182
|
currency: string;
|
|
5183
|
-
currencyDisplay: "symbol" | "
|
|
5183
|
+
currencyDisplay: "symbol" | "name" | "code";
|
|
5184
5184
|
thousandsSeparator: string;
|
|
5185
5185
|
decimalSeparator: string;
|
|
5186
5186
|
showPercentageSymbol: boolean;
|
|
@@ -5215,7 +5215,7 @@ declare class Block {
|
|
|
5215
5215
|
type: "number" | "currency" | "percentage";
|
|
5216
5216
|
decimals: number;
|
|
5217
5217
|
currency: string;
|
|
5218
|
-
currencyDisplay: "symbol" | "
|
|
5218
|
+
currencyDisplay: "symbol" | "name" | "code";
|
|
5219
5219
|
thousandsSeparator: string;
|
|
5220
5220
|
decimalSeparator: string;
|
|
5221
5221
|
showPercentageSymbol: boolean;
|
|
@@ -5235,7 +5235,7 @@ declare class Block {
|
|
|
5235
5235
|
chartType: "progress-bar";
|
|
5236
5236
|
value: number;
|
|
5237
5237
|
max: number;
|
|
5238
|
-
variant: "error" | "
|
|
5238
|
+
variant: "error" | "default" | "success" | "neutral" | "warning";
|
|
5239
5239
|
title?: string | undefined;
|
|
5240
5240
|
description?: string | undefined;
|
|
5241
5241
|
label?: string | number | undefined;
|
|
@@ -5251,7 +5251,7 @@ declare class Block {
|
|
|
5251
5251
|
value: number;
|
|
5252
5252
|
max: number;
|
|
5253
5253
|
radius: number;
|
|
5254
|
-
variant: "error" | "
|
|
5254
|
+
variant: "error" | "default" | "success" | "neutral" | "warning";
|
|
5255
5255
|
title?: string | undefined;
|
|
5256
5256
|
description?: string | undefined;
|
|
5257
5257
|
};
|
|
@@ -5315,7 +5315,7 @@ declare class Block {
|
|
|
5315
5315
|
type: "number" | "currency" | "percentage";
|
|
5316
5316
|
decimals: number;
|
|
5317
5317
|
currency: string;
|
|
5318
|
-
currencyDisplay: "symbol" | "
|
|
5318
|
+
currencyDisplay: "symbol" | "name" | "code";
|
|
5319
5319
|
thousandsSeparator: string;
|
|
5320
5320
|
decimalSeparator: string;
|
|
5321
5321
|
showPercentageSymbol: boolean;
|
|
@@ -5336,7 +5336,7 @@ declare class Block {
|
|
|
5336
5336
|
type: "number" | "currency" | "percentage";
|
|
5337
5337
|
decimals: number;
|
|
5338
5338
|
currency: string;
|
|
5339
|
-
currencyDisplay: "symbol" | "
|
|
5339
|
+
currencyDisplay: "symbol" | "name" | "code";
|
|
5340
5340
|
thousandsSeparator: string;
|
|
5341
5341
|
decimalSeparator: string;
|
|
5342
5342
|
showPercentageSymbol: boolean;
|
|
@@ -5381,7 +5381,7 @@ declare class Block {
|
|
|
5381
5381
|
type: "number" | "currency" | "percentage";
|
|
5382
5382
|
decimals: number;
|
|
5383
5383
|
currency: string;
|
|
5384
|
-
currencyDisplay: "symbol" | "
|
|
5384
|
+
currencyDisplay: "symbol" | "name" | "code";
|
|
5385
5385
|
thousandsSeparator: string;
|
|
5386
5386
|
decimalSeparator: string;
|
|
5387
5387
|
showPercentageSymbol: boolean;
|
|
@@ -5406,7 +5406,7 @@ declare class Block {
|
|
|
5406
5406
|
type: "number" | "currency" | "percentage";
|
|
5407
5407
|
decimals: number;
|
|
5408
5408
|
currency: string;
|
|
5409
|
-
currencyDisplay: "symbol" | "
|
|
5409
|
+
currencyDisplay: "symbol" | "name" | "code";
|
|
5410
5410
|
thousandsSeparator: string;
|
|
5411
5411
|
decimalSeparator: string;
|
|
5412
5412
|
showPercentageSymbol: boolean;
|
|
@@ -5416,7 +5416,7 @@ declare class Block {
|
|
|
5416
5416
|
suffix?: string | undefined;
|
|
5417
5417
|
} | undefined;
|
|
5418
5418
|
change?: string | number | undefined;
|
|
5419
|
-
changeType?: "
|
|
5419
|
+
changeType?: "neutral" | "positive" | "negative" | undefined;
|
|
5420
5420
|
chart?: {
|
|
5421
5421
|
values: (number | {
|
|
5422
5422
|
value: number;
|
|
@@ -5436,14 +5436,14 @@ declare class Block {
|
|
|
5436
5436
|
type: "chart";
|
|
5437
5437
|
max: number;
|
|
5438
5438
|
chartType: "progress-bar";
|
|
5439
|
-
variant: "error" | "
|
|
5439
|
+
variant: "error" | "default" | "success" | "neutral" | "warning";
|
|
5440
5440
|
label?: string | number | undefined;
|
|
5441
5441
|
} | {
|
|
5442
5442
|
value: number;
|
|
5443
5443
|
type: "chart";
|
|
5444
5444
|
max: number;
|
|
5445
5445
|
chartType: "progress-circle";
|
|
5446
|
-
variant: "error" | "
|
|
5446
|
+
variant: "error" | "default" | "success" | "neutral" | "warning";
|
|
5447
5447
|
radius: number;
|
|
5448
5448
|
} | {
|
|
5449
5449
|
data: Record<string, any>[];
|
|
@@ -5486,7 +5486,7 @@ declare class Block {
|
|
|
5486
5486
|
type: "default";
|
|
5487
5487
|
} | {
|
|
5488
5488
|
type: "badge";
|
|
5489
|
-
variant: "error" | "
|
|
5489
|
+
variant: "error" | "default" | "success" | "neutral" | "warning";
|
|
5490
5490
|
} | {
|
|
5491
5491
|
type: "image";
|
|
5492
5492
|
width: number;
|
|
@@ -5496,7 +5496,7 @@ declare class Block {
|
|
|
5496
5496
|
type: "progress";
|
|
5497
5497
|
chartType: "bar" | "circle";
|
|
5498
5498
|
maxValue: number;
|
|
5499
|
-
variant: "error" | "
|
|
5499
|
+
variant: "error" | "default" | "success" | "neutral" | "warning";
|
|
5500
5500
|
} | {
|
|
5501
5501
|
type: "link";
|
|
5502
5502
|
target: "_blank" | "_self";
|
|
@@ -5507,7 +5507,7 @@ declare class Block {
|
|
|
5507
5507
|
type: "number" | "currency" | "percentage";
|
|
5508
5508
|
decimals: number;
|
|
5509
5509
|
currency: string;
|
|
5510
|
-
currencyDisplay: "symbol" | "
|
|
5510
|
+
currencyDisplay: "symbol" | "name" | "code";
|
|
5511
5511
|
thousandsSeparator: string;
|
|
5512
5512
|
decimalSeparator: string;
|
|
5513
5513
|
showPercentageSymbol: boolean;
|
|
@@ -5572,7 +5572,7 @@ declare class Block {
|
|
|
5572
5572
|
type: "number" | "currency" | "percentage";
|
|
5573
5573
|
decimals: number;
|
|
5574
5574
|
currency: string;
|
|
5575
|
-
currencyDisplay: "symbol" | "
|
|
5575
|
+
currencyDisplay: "symbol" | "name" | "code";
|
|
5576
5576
|
thousandsSeparator: string;
|
|
5577
5577
|
decimalSeparator: string;
|
|
5578
5578
|
showPercentageSymbol: boolean;
|
|
@@ -5582,7 +5582,7 @@ declare class Block {
|
|
|
5582
5582
|
suffix?: string | undefined;
|
|
5583
5583
|
} | undefined;
|
|
5584
5584
|
change?: string | number | undefined;
|
|
5585
|
-
changeType?: "
|
|
5585
|
+
changeType?: "neutral" | "positive" | "negative" | undefined;
|
|
5586
5586
|
chart?: {
|
|
5587
5587
|
values: (number | {
|
|
5588
5588
|
value: number;
|
|
@@ -5602,14 +5602,14 @@ declare class Block {
|
|
|
5602
5602
|
type: "chart";
|
|
5603
5603
|
max: number;
|
|
5604
5604
|
chartType: "progress-bar";
|
|
5605
|
-
variant: "error" | "
|
|
5605
|
+
variant: "error" | "default" | "success" | "neutral" | "warning";
|
|
5606
5606
|
label?: string | number | undefined;
|
|
5607
5607
|
} | {
|
|
5608
5608
|
value: number;
|
|
5609
5609
|
type: "chart";
|
|
5610
5610
|
max: number;
|
|
5611
5611
|
chartType: "progress-circle";
|
|
5612
|
-
variant: "error" | "
|
|
5612
|
+
variant: "error" | "default" | "success" | "neutral" | "warning";
|
|
5613
5613
|
radius: number;
|
|
5614
5614
|
} | {
|
|
5615
5615
|
data: Record<string, any>[];
|
|
@@ -5654,7 +5654,7 @@ declare class Block {
|
|
|
5654
5654
|
type: "number" | "currency" | "percentage";
|
|
5655
5655
|
decimals: number;
|
|
5656
5656
|
currency: string;
|
|
5657
|
-
currencyDisplay: "symbol" | "
|
|
5657
|
+
currencyDisplay: "symbol" | "name" | "code";
|
|
5658
5658
|
thousandsSeparator: string;
|
|
5659
5659
|
decimalSeparator: string;
|
|
5660
5660
|
showPercentageSymbol: boolean;
|
|
@@ -5687,7 +5687,7 @@ declare class Block {
|
|
|
5687
5687
|
type: "number" | "currency" | "percentage";
|
|
5688
5688
|
decimals: number;
|
|
5689
5689
|
currency: string;
|
|
5690
|
-
currencyDisplay: "symbol" | "
|
|
5690
|
+
currencyDisplay: "symbol" | "name" | "code";
|
|
5691
5691
|
thousandsSeparator: string;
|
|
5692
5692
|
decimalSeparator: string;
|
|
5693
5693
|
showPercentageSymbol: boolean;
|
|
@@ -5717,7 +5717,7 @@ declare class Block {
|
|
|
5717
5717
|
type: "number" | "currency" | "percentage";
|
|
5718
5718
|
decimals: number;
|
|
5719
5719
|
currency: string;
|
|
5720
|
-
currencyDisplay: "symbol" | "
|
|
5720
|
+
currencyDisplay: "symbol" | "name" | "code";
|
|
5721
5721
|
thousandsSeparator: string;
|
|
5722
5722
|
decimalSeparator: string;
|
|
5723
5723
|
showPercentageSymbol: boolean;
|
|
@@ -5738,7 +5738,7 @@ declare class Block {
|
|
|
5738
5738
|
type: "number" | "currency" | "percentage";
|
|
5739
5739
|
decimals: number;
|
|
5740
5740
|
currency: string;
|
|
5741
|
-
currencyDisplay: "symbol" | "
|
|
5741
|
+
currencyDisplay: "symbol" | "name" | "code";
|
|
5742
5742
|
thousandsSeparator: string;
|
|
5743
5743
|
decimalSeparator: string;
|
|
5744
5744
|
showPercentageSymbol: boolean;
|
|
@@ -5798,7 +5798,7 @@ declare class Block {
|
|
|
5798
5798
|
type: "number" | "currency" | "percentage";
|
|
5799
5799
|
decimals: number;
|
|
5800
5800
|
currency: string;
|
|
5801
|
-
currencyDisplay: "symbol" | "
|
|
5801
|
+
currencyDisplay: "symbol" | "name" | "code";
|
|
5802
5802
|
thousandsSeparator: string;
|
|
5803
5803
|
decimalSeparator: string;
|
|
5804
5804
|
showPercentageSymbol: boolean;
|
|
@@ -5829,7 +5829,7 @@ declare class Block {
|
|
|
5829
5829
|
type: "number" | "currency" | "percentage";
|
|
5830
5830
|
decimals: number;
|
|
5831
5831
|
currency: string;
|
|
5832
|
-
currencyDisplay: "symbol" | "
|
|
5832
|
+
currencyDisplay: "symbol" | "name" | "code";
|
|
5833
5833
|
thousandsSeparator: string;
|
|
5834
5834
|
decimalSeparator: string;
|
|
5835
5835
|
showPercentageSymbol: boolean;
|
|
@@ -5843,7 +5843,7 @@ declare class Block {
|
|
|
5843
5843
|
chartType: "progress-bar";
|
|
5844
5844
|
value: number;
|
|
5845
5845
|
max: number;
|
|
5846
|
-
variant: "error" | "
|
|
5846
|
+
variant: "error" | "default" | "success" | "neutral" | "warning";
|
|
5847
5847
|
title?: string | undefined;
|
|
5848
5848
|
description?: string | undefined;
|
|
5849
5849
|
label?: string | number | undefined;
|
|
@@ -5853,7 +5853,7 @@ declare class Block {
|
|
|
5853
5853
|
value: number;
|
|
5854
5854
|
max: number;
|
|
5855
5855
|
radius: number;
|
|
5856
|
-
variant: "error" | "
|
|
5856
|
+
variant: "error" | "default" | "success" | "neutral" | "warning";
|
|
5857
5857
|
title?: string | undefined;
|
|
5858
5858
|
description?: string | undefined;
|
|
5859
5859
|
} | {
|
|
@@ -5901,7 +5901,7 @@ declare class Block {
|
|
|
5901
5901
|
type: "number" | "currency" | "percentage";
|
|
5902
5902
|
decimals: number;
|
|
5903
5903
|
currency: string;
|
|
5904
|
-
currencyDisplay: "symbol" | "
|
|
5904
|
+
currencyDisplay: "symbol" | "name" | "code";
|
|
5905
5905
|
thousandsSeparator: string;
|
|
5906
5906
|
decimalSeparator: string;
|
|
5907
5907
|
showPercentageSymbol: boolean;
|
|
@@ -5924,7 +5924,7 @@ declare class Block {
|
|
|
5924
5924
|
type: "default";
|
|
5925
5925
|
} | {
|
|
5926
5926
|
type: "badge";
|
|
5927
|
-
variant: "error" | "
|
|
5927
|
+
variant: "error" | "default" | "success" | "neutral" | "warning";
|
|
5928
5928
|
} | {
|
|
5929
5929
|
type: "image";
|
|
5930
5930
|
width: number;
|
|
@@ -5934,7 +5934,7 @@ declare class Block {
|
|
|
5934
5934
|
type: "progress";
|
|
5935
5935
|
chartType: "bar" | "circle";
|
|
5936
5936
|
maxValue: number;
|
|
5937
|
-
variant: "error" | "
|
|
5937
|
+
variant: "error" | "default" | "success" | "neutral" | "warning";
|
|
5938
5938
|
} | {
|
|
5939
5939
|
type: "link";
|
|
5940
5940
|
target: "_blank" | "_self";
|
|
@@ -5945,7 +5945,7 @@ declare class Block {
|
|
|
5945
5945
|
type: "number" | "currency" | "percentage";
|
|
5946
5946
|
decimals: number;
|
|
5947
5947
|
currency: string;
|
|
5948
|
-
currencyDisplay: "symbol" | "
|
|
5948
|
+
currencyDisplay: "symbol" | "name" | "code";
|
|
5949
5949
|
thousandsSeparator: string;
|
|
5950
5950
|
decimalSeparator: string;
|
|
5951
5951
|
showPercentageSymbol: boolean;
|
package/dist/components/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as
|
|
1
|
+
import { a as AGENT_TAG_NAME, i as AGENT_STEP_TAG_NAME, n as TOOL_TAG_NAME, t as TOOL_HANDLER_TAG_NAME } from "../tool-UVAGtnlr.js";
|
|
2
2
|
|
|
3
3
|
//#region src/components/tool.ts
|
|
4
4
|
/**
|
|
@@ -1771,6 +1771,47 @@ const agentErrorMessageSchema = baseMessageSchema.extend({
|
|
|
1771
1771
|
})
|
|
1772
1772
|
});
|
|
1773
1773
|
|
|
1774
|
+
//#endregion
|
|
1775
|
+
//#region ../core/dist/utils.js
|
|
1776
|
+
function exponentialBackoff(attempt, initialDelay = 1e3, maxRetryDelay = 3e4, jitterFactor = .5, backoffMultiplier = 2) {
|
|
1777
|
+
let delay = initialDelay * Math.pow(backoffMultiplier, attempt - 1);
|
|
1778
|
+
const jitter = delay * jitterFactor * Math.random();
|
|
1779
|
+
delay += jitter;
|
|
1780
|
+
return Math.min(delay, maxRetryDelay);
|
|
1781
|
+
}
|
|
1782
|
+
function runWithRetries(fn, retries = 3, config = {}) {
|
|
1783
|
+
let attempt = 0;
|
|
1784
|
+
const execute = async () => {
|
|
1785
|
+
try {
|
|
1786
|
+
return await fn();
|
|
1787
|
+
} catch (error) {
|
|
1788
|
+
if (attempt < retries) {
|
|
1789
|
+
attempt++;
|
|
1790
|
+
await setTimeout(exponentialBackoff(attempt, config.initialDelayMs, config.maxDelayMs, config.backoffMultiplier));
|
|
1791
|
+
return execute();
|
|
1792
|
+
}
|
|
1793
|
+
throw error;
|
|
1794
|
+
}
|
|
1795
|
+
};
|
|
1796
|
+
return execute();
|
|
1797
|
+
}
|
|
1798
|
+
|
|
1799
|
+
//#endregion
|
|
1800
|
+
//#region src/lib/utils.ts
|
|
1801
|
+
function convertToWords(input) {
|
|
1802
|
+
if (input.includes("-") || input.includes("_")) return input.split(/[-_]+/).filter((word) => word.length > 0).map((word) => word.toLowerCase());
|
|
1803
|
+
return input.split(/(?=[A-Z])/).filter((word) => word.length > 0).map((word) => word.toLowerCase());
|
|
1804
|
+
}
|
|
1805
|
+
function invariant(cond, message) {
|
|
1806
|
+
if (!cond) throw new Error(message);
|
|
1807
|
+
}
|
|
1808
|
+
function getErrorMessage(error, defaultMessage = "Something went wrong. Please try again") {
|
|
1809
|
+
let errorMessage = defaultMessage;
|
|
1810
|
+
if (error instanceof z$1.ZodError) errorMessage = error.issues.length ? error.issues.map((e) => e.message).join(", ") : error.message;
|
|
1811
|
+
else if (error instanceof Error) errorMessage = error.message;
|
|
1812
|
+
return errorMessage;
|
|
1813
|
+
}
|
|
1814
|
+
|
|
1774
1815
|
//#endregion
|
|
1775
1816
|
//#region src/internal/block.ts
|
|
1776
1817
|
var Block = class {
|
|
@@ -2002,47 +2043,6 @@ var Block = class {
|
|
|
2002
2043
|
}
|
|
2003
2044
|
};
|
|
2004
2045
|
|
|
2005
|
-
//#endregion
|
|
2006
|
-
//#region ../core/dist/utils.js
|
|
2007
|
-
function exponentialBackoff(attempt, initialDelay = 1e3, maxRetryDelay = 3e4, jitterFactor = .5, backoffMultiplier = 2) {
|
|
2008
|
-
let delay = initialDelay * Math.pow(backoffMultiplier, attempt - 1);
|
|
2009
|
-
const jitter = delay * jitterFactor * Math.random();
|
|
2010
|
-
delay += jitter;
|
|
2011
|
-
return Math.min(delay, maxRetryDelay);
|
|
2012
|
-
}
|
|
2013
|
-
function runWithRetries(fn, retries = 3, config = {}) {
|
|
2014
|
-
let attempt = 0;
|
|
2015
|
-
const execute = async () => {
|
|
2016
|
-
try {
|
|
2017
|
-
return await fn();
|
|
2018
|
-
} catch (error) {
|
|
2019
|
-
if (attempt < retries) {
|
|
2020
|
-
attempt++;
|
|
2021
|
-
await setTimeout(exponentialBackoff(attempt, config.initialDelayMs, config.maxDelayMs, config.backoffMultiplier));
|
|
2022
|
-
return execute();
|
|
2023
|
-
}
|
|
2024
|
-
throw error;
|
|
2025
|
-
}
|
|
2026
|
-
};
|
|
2027
|
-
return execute();
|
|
2028
|
-
}
|
|
2029
|
-
|
|
2030
|
-
//#endregion
|
|
2031
|
-
//#region src/lib/utils.ts
|
|
2032
|
-
function convertToWords(input) {
|
|
2033
|
-
if (input.includes("-") || input.includes("_")) return input.split(/[-_]+/).filter((word) => word.length > 0).map((word) => word.toLowerCase());
|
|
2034
|
-
return input.split(/(?=[A-Z])/).filter((word) => word.length > 0).map((word) => word.toLowerCase());
|
|
2035
|
-
}
|
|
2036
|
-
function invariant(cond, message) {
|
|
2037
|
-
if (!cond) throw new Error(message);
|
|
2038
|
-
}
|
|
2039
|
-
function getErrorMessage(error, defaultMessage = "Something went wrong. Please try again") {
|
|
2040
|
-
let errorMessage = defaultMessage;
|
|
2041
|
-
if (error instanceof z$1.ZodError) errorMessage = error.issues.length ? error.issues.map((e) => e.message).join(", ") : error.message;
|
|
2042
|
-
else if (error instanceof Error) errorMessage = error.message;
|
|
2043
|
-
return errorMessage;
|
|
2044
|
-
}
|
|
2045
|
-
|
|
2046
2046
|
//#endregion
|
|
2047
2047
|
//#region src/internal/loader.ts
|
|
2048
2048
|
var Loader = class {
|
|
@@ -2624,73 +2624,6 @@ var IO = class {
|
|
|
2624
2624
|
}
|
|
2625
2625
|
};
|
|
2626
2626
|
|
|
2627
|
-
//#endregion
|
|
2628
|
-
//#region src/internal/tool.ts
|
|
2629
|
-
const TOOL_HANDLER_TAG_NAME = Symbol("TOOL_HANDLER");
|
|
2630
|
-
const TOOL_TAG_NAME = Symbol("TOOL");
|
|
2631
|
-
/**
|
|
2632
|
-
* Tool class is responsible for running the tool's logic.
|
|
2633
|
-
* It manages the tool lifecycle, communication with the worker, and handles sending messages back to the ForgeRunner.
|
|
2634
|
-
* It uses the IO component to facilitate input/output operations for the tool.
|
|
2635
|
-
*/
|
|
2636
|
-
var Tool = class {
|
|
2637
|
-
#metadata;
|
|
2638
|
-
#abortController = new AbortController();
|
|
2639
|
-
#handler;
|
|
2640
|
-
#io;
|
|
2641
|
-
#block;
|
|
2642
|
-
#logger;
|
|
2643
|
-
constructor(options, logger) {
|
|
2644
|
-
this.#metadata = options.metadata;
|
|
2645
|
-
this.#handler = options.handler;
|
|
2646
|
-
this.#logger = logger.child({
|
|
2647
|
-
sessionId: this.#metadata.sessionId,
|
|
2648
|
-
component: "TOOL"
|
|
2649
|
-
});
|
|
2650
|
-
this.#io = new IO({
|
|
2651
|
-
sessionId: this.#metadata.sessionId,
|
|
2652
|
-
runnerId: this.#metadata.runnerId,
|
|
2653
|
-
webSocketClient: options.webSocketClient,
|
|
2654
|
-
signal: this.#abortController.signal,
|
|
2655
|
-
executionContext: { type: "TOOL" }
|
|
2656
|
-
}, this.#logger);
|
|
2657
|
-
this.#block = new Block({ signal: this.#abortController.signal });
|
|
2658
|
-
this.#logger.debug("initialized Tool instance");
|
|
2659
|
-
}
|
|
2660
|
-
async run() {
|
|
2661
|
-
return new Promise(async (resolve, reject) => {
|
|
2662
|
-
if (this.#abortController.signal.aborted) {
|
|
2663
|
-
this.#logger.info("tool execution aborted before start");
|
|
2664
|
-
return Promise.reject(/* @__PURE__ */ new Error("tool execution aborted"));
|
|
2665
|
-
}
|
|
2666
|
-
this.#abortController.signal.addEventListener("abort", () => {
|
|
2667
|
-
this.#logger.info("tool execution aborted");
|
|
2668
|
-
reject(/* @__PURE__ */ new Error("Tool execution aborted"));
|
|
2669
|
-
});
|
|
2670
|
-
try {
|
|
2671
|
-
this.#logger.info("running tool handler...");
|
|
2672
|
-
const output = await this.#handler({
|
|
2673
|
-
io: this.#io,
|
|
2674
|
-
signal: this.#abortController.signal,
|
|
2675
|
-
block: this.#block,
|
|
2676
|
-
metadata: this.#metadata
|
|
2677
|
-
});
|
|
2678
|
-
this.#logger.info("tool handler completed successfully");
|
|
2679
|
-
this.#io[STOP_SYMBOL]();
|
|
2680
|
-
resolve(output);
|
|
2681
|
-
} catch (error) {
|
|
2682
|
-
this.#logger.error(error, "error running tool handler");
|
|
2683
|
-
return reject(error);
|
|
2684
|
-
}
|
|
2685
|
-
});
|
|
2686
|
-
}
|
|
2687
|
-
stop() {
|
|
2688
|
-
this.#logger.info("stopping Tool...");
|
|
2689
|
-
this.#abortController.abort();
|
|
2690
|
-
this.#logger.info("Tool stopped");
|
|
2691
|
-
}
|
|
2692
|
-
};
|
|
2693
|
-
|
|
2694
2627
|
//#endregion
|
|
2695
2628
|
//#region src/internal/workflow-builder.ts
|
|
2696
2629
|
var WorkflowBuilder = class {
|
|
@@ -3090,4 +3023,71 @@ var Agent = class {
|
|
|
3090
3023
|
};
|
|
3091
3024
|
|
|
3092
3025
|
//#endregion
|
|
3093
|
-
|
|
3026
|
+
//#region src/internal/tool.ts
|
|
3027
|
+
const TOOL_HANDLER_TAG_NAME = Symbol("TOOL_HANDLER");
|
|
3028
|
+
const TOOL_TAG_NAME = Symbol("TOOL");
|
|
3029
|
+
/**
|
|
3030
|
+
* Tool class is responsible for running the tool's logic.
|
|
3031
|
+
* It manages the tool lifecycle, communication with the worker, and handles sending messages back to the ForgeRunner.
|
|
3032
|
+
* It uses the IO component to facilitate input/output operations for the tool.
|
|
3033
|
+
*/
|
|
3034
|
+
var Tool = class {
|
|
3035
|
+
#metadata;
|
|
3036
|
+
#abortController = new AbortController();
|
|
3037
|
+
#handler;
|
|
3038
|
+
#io;
|
|
3039
|
+
#block;
|
|
3040
|
+
#logger;
|
|
3041
|
+
constructor(options, logger) {
|
|
3042
|
+
this.#metadata = options.metadata;
|
|
3043
|
+
this.#handler = options.handler;
|
|
3044
|
+
this.#logger = logger.child({
|
|
3045
|
+
sessionId: this.#metadata.sessionId,
|
|
3046
|
+
component: "TOOL"
|
|
3047
|
+
});
|
|
3048
|
+
this.#io = new IO({
|
|
3049
|
+
sessionId: this.#metadata.sessionId,
|
|
3050
|
+
runnerId: this.#metadata.runnerId,
|
|
3051
|
+
webSocketClient: options.webSocketClient,
|
|
3052
|
+
signal: this.#abortController.signal,
|
|
3053
|
+
executionContext: { type: "TOOL" }
|
|
3054
|
+
}, this.#logger);
|
|
3055
|
+
this.#block = new Block({ signal: this.#abortController.signal });
|
|
3056
|
+
this.#logger.debug("initialized Tool instance");
|
|
3057
|
+
}
|
|
3058
|
+
async run() {
|
|
3059
|
+
return new Promise(async (resolve, reject) => {
|
|
3060
|
+
if (this.#abortController.signal.aborted) {
|
|
3061
|
+
this.#logger.info("tool execution aborted before start");
|
|
3062
|
+
return Promise.reject(/* @__PURE__ */ new Error("tool execution aborted"));
|
|
3063
|
+
}
|
|
3064
|
+
this.#abortController.signal.addEventListener("abort", () => {
|
|
3065
|
+
this.#logger.info("tool execution aborted");
|
|
3066
|
+
reject(/* @__PURE__ */ new Error("Tool execution aborted"));
|
|
3067
|
+
});
|
|
3068
|
+
try {
|
|
3069
|
+
this.#logger.info("running tool handler...");
|
|
3070
|
+
const output = await this.#handler({
|
|
3071
|
+
io: this.#io,
|
|
3072
|
+
signal: this.#abortController.signal,
|
|
3073
|
+
block: this.#block,
|
|
3074
|
+
metadata: this.#metadata
|
|
3075
|
+
});
|
|
3076
|
+
this.#logger.info("tool handler completed successfully");
|
|
3077
|
+
this.#io[STOP_SYMBOL]();
|
|
3078
|
+
resolve(output);
|
|
3079
|
+
} catch (error) {
|
|
3080
|
+
this.#logger.error(error, "error running tool handler");
|
|
3081
|
+
return reject(error);
|
|
3082
|
+
}
|
|
3083
|
+
});
|
|
3084
|
+
}
|
|
3085
|
+
stop() {
|
|
3086
|
+
this.#logger.info("stopping Tool...");
|
|
3087
|
+
this.#abortController.abort();
|
|
3088
|
+
this.#logger.info("Tool stopped");
|
|
3089
|
+
}
|
|
3090
|
+
};
|
|
3091
|
+
|
|
3092
|
+
//#endregion
|
|
3093
|
+
export { __toESM as C, __require as S, startAgentMessageSchema as _, AGENT_TAG_NAME as a, stopToolMessageSchema as b, getErrorMessage as c, runWithRetries as d, ackMessageSchema as f, runnerId as g, initCommunicationMessageSchema as h, AGENT_STEP_TAG_NAME as i, invariant as l, heartbeatAckMessageSchema as m, TOOL_TAG_NAME as n, Agent as o, baseMessageSchema as p, Tool as r, convertToWords as s, TOOL_HANDLER_TAG_NAME as t, exponentialBackoff as u, startToolMessageSchema as v, __commonJS as x, stopAgentMessageSchema as y };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@toolforge-js/sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist",
|
|
@@ -21,6 +21,7 @@
|
|
|
21
21
|
"es-toolkit": "1.39.10",
|
|
22
22
|
"esbuild": "0.27.0",
|
|
23
23
|
"nanoid": "5.1.5",
|
|
24
|
+
"ora": "9.0.0",
|
|
24
25
|
"picocolors": "1.1.1",
|
|
25
26
|
"pino": "9.11.0",
|
|
26
27
|
"pino-pretty": "13.1.1",
|
|
@@ -34,6 +35,6 @@
|
|
|
34
35
|
"typescript": "5.9.2"
|
|
35
36
|
},
|
|
36
37
|
"bin": {
|
|
37
|
-
"toolforge
|
|
38
|
+
"toolforge": "index.js"
|
|
38
39
|
}
|
|
39
40
|
}
|