@simulacra-ai/core 0.0.6 → 0.0.9
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/README.md +19 -3
- package/dist/index.cjs +27 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +7 -1
- package/dist/index.d.ts +7 -1
- package/dist/index.js +27 -3
- package/dist/index.js.map +1 -1
- package/package.json +7 -2
package/dist/index.d.cts
CHANGED
|
@@ -180,6 +180,12 @@ declare class WorkflowManager {
|
|
|
180
180
|
* This is typically not needed as workflows are started automatically when messages are sent.
|
|
181
181
|
*/
|
|
182
182
|
start_workflow(): void;
|
|
183
|
+
/**
|
|
184
|
+
* Sends a prompt and returns a promise that resolves when the full workflow
|
|
185
|
+
* completes, including all tool execution rounds.
|
|
186
|
+
*/
|
|
187
|
+
run(prompt: string): Promise<WorkflowEndEvent>;
|
|
188
|
+
run(contents: UserContent[]): Promise<WorkflowEndEvent>;
|
|
183
189
|
}
|
|
184
190
|
|
|
185
191
|
/**
|
|
@@ -1597,7 +1603,7 @@ declare class TokenLimitPolicy extends Policy {
|
|
|
1597
1603
|
* @param obj - The value to check.
|
|
1598
1604
|
* @returns The value if non-empty, otherwise undefined.
|
|
1599
1605
|
*/
|
|
1600
|
-
declare function undefined_if_empty<T = unknown>(obj: T): T | undefined;
|
|
1606
|
+
declare function undefined_if_empty<T = unknown>(obj: T): (T & {}) | undefined;
|
|
1601
1607
|
/**
|
|
1602
1608
|
* Recursively merges two values together.
|
|
1603
1609
|
*
|
package/dist/index.d.ts
CHANGED
|
@@ -180,6 +180,12 @@ declare class WorkflowManager {
|
|
|
180
180
|
* This is typically not needed as workflows are started automatically when messages are sent.
|
|
181
181
|
*/
|
|
182
182
|
start_workflow(): void;
|
|
183
|
+
/**
|
|
184
|
+
* Sends a prompt and returns a promise that resolves when the full workflow
|
|
185
|
+
* completes, including all tool execution rounds.
|
|
186
|
+
*/
|
|
187
|
+
run(prompt: string): Promise<WorkflowEndEvent>;
|
|
188
|
+
run(contents: UserContent[]): Promise<WorkflowEndEvent>;
|
|
183
189
|
}
|
|
184
190
|
|
|
185
191
|
/**
|
|
@@ -1597,7 +1603,7 @@ declare class TokenLimitPolicy extends Policy {
|
|
|
1597
1603
|
* @param obj - The value to check.
|
|
1598
1604
|
* @returns The value if non-empty, otherwise undefined.
|
|
1599
1605
|
*/
|
|
1600
|
-
declare function undefined_if_empty<T = unknown>(obj: T): T | undefined;
|
|
1606
|
+
declare function undefined_if_empty<T = unknown>(obj: T): (T & {}) | undefined;
|
|
1601
1607
|
/**
|
|
1602
1608
|
* Recursively merges two values together.
|
|
1603
1609
|
*
|
package/dist/index.js
CHANGED
|
@@ -540,6 +540,9 @@ var RETRYABLE_NETWORK_ERROR_CODES = /* @__PURE__ */ new Set([
|
|
|
540
540
|
var RETRYABLE_HTTP_STATUS_CODES = /* @__PURE__ */ new Set([408, 429, 500, 502, 503, 504, 529]);
|
|
541
541
|
function defaultRetryable(result) {
|
|
542
542
|
const error = result.error;
|
|
543
|
+
if (error instanceof OperationCanceledError) {
|
|
544
|
+
return false;
|
|
545
|
+
}
|
|
543
546
|
if (error !== null && error !== void 0 && typeof error === "object" && "status" in error) {
|
|
544
547
|
const status = error.status;
|
|
545
548
|
if (typeof status === "number") {
|
|
@@ -561,7 +564,7 @@ function defaultRetryable(result) {
|
|
|
561
564
|
}
|
|
562
565
|
if (error instanceof Error) {
|
|
563
566
|
const msg = error.message.toLowerCase();
|
|
564
|
-
if (msg.includes("timeout") || msg.includes("econnreset") || msg.includes("econnrefused") || msg.includes("socket hang up") || msg.includes("network error") || msg.includes("
|
|
567
|
+
if (msg.includes("timeout") || msg.includes("econnreset") || msg.includes("econnrefused") || msg.includes("socket hang up") || msg.includes("network error") || msg.includes("fail")) {
|
|
565
568
|
return true;
|
|
566
569
|
}
|
|
567
570
|
}
|
|
@@ -607,6 +610,7 @@ var RetryPolicy = class _RetryPolicy extends Policy {
|
|
|
607
610
|
metadata
|
|
608
611
|
};
|
|
609
612
|
} catch (error) {
|
|
613
|
+
cancellation_token.throw_if_cancellation_requested();
|
|
610
614
|
metadata.attempts = attempt;
|
|
611
615
|
const result = {
|
|
612
616
|
result: false,
|
|
@@ -2101,6 +2105,26 @@ var WorkflowManager = class {
|
|
|
2101
2105
|
throw new Error("invalid state");
|
|
2102
2106
|
}
|
|
2103
2107
|
}
|
|
2108
|
+
async run(input) {
|
|
2109
|
+
if (this.#state !== "idle") {
|
|
2110
|
+
throw new Error("invalid state");
|
|
2111
|
+
}
|
|
2112
|
+
const workflow_end = new Promise((resolve) => {
|
|
2113
|
+
const handler = (event) => {
|
|
2114
|
+
if (event.event_name === "workflow_end") {
|
|
2115
|
+
this.off("workflow_event", handler);
|
|
2116
|
+
resolve(event.event_args[0]);
|
|
2117
|
+
}
|
|
2118
|
+
};
|
|
2119
|
+
this.on("workflow_event", handler);
|
|
2120
|
+
});
|
|
2121
|
+
if (typeof input === "string") {
|
|
2122
|
+
await this.#conversation.prompt(input);
|
|
2123
|
+
} else {
|
|
2124
|
+
await this.#conversation.send_message(input);
|
|
2125
|
+
}
|
|
2126
|
+
return workflow_end;
|
|
2127
|
+
}
|
|
2104
2128
|
#on_prompt_send = ({ message }) => {
|
|
2105
2129
|
if (this.#current_workflow) {
|
|
2106
2130
|
return;
|
|
@@ -2160,8 +2184,8 @@ function defined_keys(obj) {
|
|
|
2160
2184
|
return Object.keys(obj).filter((key) => obj[key] !== void 0);
|
|
2161
2185
|
}
|
|
2162
2186
|
function undefined_if_empty(obj) {
|
|
2163
|
-
if (
|
|
2164
|
-
return
|
|
2187
|
+
if (obj === null || obj === void 0) {
|
|
2188
|
+
return void 0;
|
|
2165
2189
|
}
|
|
2166
2190
|
if (Array.isArray(obj)) {
|
|
2167
2191
|
return obj.length === 0 ? void 0 : obj;
|