llmist 2.0.0 → 2.1.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/{chunk-LFSIEPAE.js → chunk-LSCCBXS7.js} +2 -2
- package/dist/{chunk-LBHWVCZ2.js → chunk-PDYVT3FI.js} +106 -1
- package/dist/chunk-PDYVT3FI.js.map +1 -0
- package/dist/cli.cjs +266 -96
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +163 -98
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +105 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -2
- package/dist/index.d.ts +4 -2
- package/dist/index.js +2 -2
- package/dist/{mock-stream-BQHut0lQ.d.cts → mock-stream-HF7MBNhi.d.cts} +82 -6
- package/dist/{mock-stream-BQHut0lQ.d.ts → mock-stream-HF7MBNhi.d.ts} +82 -6
- package/dist/testing/index.cjs +105 -0
- package/dist/testing/index.cjs.map +1 -1
- package/dist/testing/index.d.cts +2 -2
- package/dist/testing/index.d.ts +2 -2
- package/dist/testing/index.js +1 -1
- package/package.json +1 -1
- package/dist/chunk-LBHWVCZ2.js.map +0 -1
- /package/dist/{chunk-LFSIEPAE.js.map → chunk-LSCCBXS7.js.map} +0 -0
package/dist/index.cjs
CHANGED
|
@@ -1047,6 +1047,100 @@ var init_gadget = __esm({
|
|
|
1047
1047
|
throw new AbortError();
|
|
1048
1048
|
}
|
|
1049
1049
|
}
|
|
1050
|
+
/**
|
|
1051
|
+
* Register a cleanup function to run when execution is aborted (timeout or cancellation).
|
|
1052
|
+
* The cleanup function is called immediately if the signal is already aborted.
|
|
1053
|
+
* Errors thrown by the cleanup function are silently ignored.
|
|
1054
|
+
*
|
|
1055
|
+
* Use this to clean up resources like browser instances, database connections,
|
|
1056
|
+
* or child processes when the gadget is cancelled due to timeout.
|
|
1057
|
+
*
|
|
1058
|
+
* @param ctx - The execution context containing the abort signal
|
|
1059
|
+
* @param cleanup - Function to run on abort (can be sync or async)
|
|
1060
|
+
*
|
|
1061
|
+
* @example
|
|
1062
|
+
* ```typescript
|
|
1063
|
+
* class BrowserGadget extends Gadget({
|
|
1064
|
+
* description: 'Fetches web page content',
|
|
1065
|
+
* schema: z.object({ url: z.string() }),
|
|
1066
|
+
* }) {
|
|
1067
|
+
* async execute(params: this['params'], ctx?: ExecutionContext): Promise<string> {
|
|
1068
|
+
* const browser = await chromium.launch();
|
|
1069
|
+
* this.onAbort(ctx, () => browser.close());
|
|
1070
|
+
*
|
|
1071
|
+
* const page = await browser.newPage();
|
|
1072
|
+
* this.onAbort(ctx, () => page.close());
|
|
1073
|
+
*
|
|
1074
|
+
* await page.goto(params.url);
|
|
1075
|
+
* const content = await page.content();
|
|
1076
|
+
*
|
|
1077
|
+
* await browser.close();
|
|
1078
|
+
* return content;
|
|
1079
|
+
* }
|
|
1080
|
+
* }
|
|
1081
|
+
* ```
|
|
1082
|
+
*/
|
|
1083
|
+
onAbort(ctx, cleanup) {
|
|
1084
|
+
if (!ctx?.signal) return;
|
|
1085
|
+
const safeCleanup = () => {
|
|
1086
|
+
try {
|
|
1087
|
+
const result = cleanup();
|
|
1088
|
+
if (result && typeof result === "object" && "catch" in result) {
|
|
1089
|
+
result.catch(() => {
|
|
1090
|
+
});
|
|
1091
|
+
}
|
|
1092
|
+
} catch {
|
|
1093
|
+
}
|
|
1094
|
+
};
|
|
1095
|
+
if (ctx.signal.aborted) {
|
|
1096
|
+
safeCleanup();
|
|
1097
|
+
return;
|
|
1098
|
+
}
|
|
1099
|
+
ctx.signal.addEventListener("abort", safeCleanup, { once: true });
|
|
1100
|
+
}
|
|
1101
|
+
/**
|
|
1102
|
+
* Create an AbortController linked to the execution context's signal.
|
|
1103
|
+
* When the parent signal aborts, the returned controller also aborts with the same reason.
|
|
1104
|
+
*
|
|
1105
|
+
* Useful for passing abort signals to child operations like fetch() while still
|
|
1106
|
+
* being able to abort them independently if needed.
|
|
1107
|
+
*
|
|
1108
|
+
* @param ctx - The execution context containing the parent abort signal
|
|
1109
|
+
* @returns A new AbortController linked to the parent signal
|
|
1110
|
+
*
|
|
1111
|
+
* @example
|
|
1112
|
+
* ```typescript
|
|
1113
|
+
* class FetchGadget extends Gadget({
|
|
1114
|
+
* description: 'Fetches data from URL',
|
|
1115
|
+
* schema: z.object({ url: z.string() }),
|
|
1116
|
+
* }) {
|
|
1117
|
+
* async execute(params: this['params'], ctx?: ExecutionContext): Promise<string> {
|
|
1118
|
+
* const controller = this.createLinkedAbortController(ctx);
|
|
1119
|
+
*
|
|
1120
|
+
* // fetch() will automatically abort when parent times out
|
|
1121
|
+
* const response = await fetch(params.url, { signal: controller.signal });
|
|
1122
|
+
* return response.text();
|
|
1123
|
+
* }
|
|
1124
|
+
* }
|
|
1125
|
+
* ```
|
|
1126
|
+
*/
|
|
1127
|
+
createLinkedAbortController(ctx) {
|
|
1128
|
+
const controller = new AbortController();
|
|
1129
|
+
if (ctx?.signal) {
|
|
1130
|
+
if (ctx.signal.aborted) {
|
|
1131
|
+
controller.abort(ctx.signal.reason);
|
|
1132
|
+
} else {
|
|
1133
|
+
ctx.signal.addEventListener(
|
|
1134
|
+
"abort",
|
|
1135
|
+
() => {
|
|
1136
|
+
controller.abort(ctx.signal.reason);
|
|
1137
|
+
},
|
|
1138
|
+
{ once: true }
|
|
1139
|
+
);
|
|
1140
|
+
}
|
|
1141
|
+
}
|
|
1142
|
+
return controller;
|
|
1143
|
+
}
|
|
1050
1144
|
/**
|
|
1051
1145
|
* Auto-generated instruction text for the LLM.
|
|
1052
1146
|
* Combines name, description, and parameter schema into a formatted instruction.
|
|
@@ -3859,6 +3953,17 @@ var init_agent = __esm({
|
|
|
3859
3953
|
llmOptions = { ...llmOptions, ...action.modifiedOptions };
|
|
3860
3954
|
}
|
|
3861
3955
|
}
|
|
3956
|
+
await this.safeObserve(async () => {
|
|
3957
|
+
if (this.hooks.observers?.onLLMCallReady) {
|
|
3958
|
+
const context = {
|
|
3959
|
+
iteration: currentIteration,
|
|
3960
|
+
maxIterations: this.maxIterations,
|
|
3961
|
+
options: llmOptions,
|
|
3962
|
+
logger: this.logger
|
|
3963
|
+
};
|
|
3964
|
+
await this.hooks.observers.onLLMCallReady(context);
|
|
3965
|
+
}
|
|
3966
|
+
});
|
|
3862
3967
|
this.logger.info("Calling LLM", { model: this.model });
|
|
3863
3968
|
this.logger.silly("LLM request details", {
|
|
3864
3969
|
model: llmOptions.model,
|