@polka-codes/core 0.9.69 → 0.9.71

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.
@@ -153,7 +153,7 @@ declare const configSchema: z.ZodOptional<z.ZodNullable<z.ZodObject<{
153
153
  export { configSchema }
154
154
  export { configSchema as configSchema_alias_1 }
155
155
 
156
- declare function createContext<TTools extends ToolRegistry>(tools: WorkflowTools<TTools>, stepFn?: <T>(name: string, fn: () => Promise<T>) => Promise<T>, logger?: Logger): WorkflowContext<TTools>;
156
+ declare function createContext<TTools extends ToolRegistry>(tools: WorkflowTools<TTools>, stepFn?: StepFn, logger?: Logger): WorkflowContext<TTools>;
157
157
  export { createContext }
158
158
  export { createContext as createContext_alias_1 }
159
159
  export { createContext as createContext_alias_2 }
@@ -821,7 +821,7 @@ export { Logger }
821
821
  export { Logger as Logger_alias_1 }
822
822
  export { Logger as Logger_alias_2 }
823
823
 
824
- declare const makeStepFn: () => (<T>(name: string, fn: () => Promise<T>) => Promise<T>);
824
+ declare const makeStepFn: () => StepFn;
825
825
  export { makeStepFn }
826
826
  export { makeStepFn as makeStepFn_alias_1 }
827
827
  export { makeStepFn as makeStepFn_alias_2 }
@@ -941,6 +941,21 @@ declare const ruleSchema: z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
941
941
  export { ruleSchema }
942
942
  export { ruleSchema as ruleSchema_alias_1 }
943
943
 
944
+ declare interface StepFn {
945
+ <T>(name: string, fn: () => Promise<T>): Promise<T>;
946
+ <T>(name: string, options: StepOptions, fn: () => Promise<T>): Promise<T>;
947
+ }
948
+ export { StepFn }
949
+ export { StepFn as StepFn_alias_1 }
950
+ export { StepFn as StepFn_alias_2 }
951
+
952
+ declare type StepOptions = {
953
+ retry?: number;
954
+ };
955
+ export { StepOptions }
956
+ export { StepOptions as StepOptions_alias_1 }
957
+ export { StepOptions as StepOptions_alias_2 }
958
+
944
959
  /**
945
960
  * Union type of all possible task events
946
961
  */
@@ -1517,7 +1532,7 @@ export { WebProvider as WebProvider_alias_1 }
1517
1532
  export { WebProvider as WebProvider_alias_2 }
1518
1533
 
1519
1534
  declare type WorkflowContext<TTools extends ToolRegistry> = {
1520
- step: <T>(name: string, fn: () => Promise<T>) => Promise<T>;
1535
+ step: StepFn;
1521
1536
  logger: Logger;
1522
1537
  tools: WorkflowTools<TTools>;
1523
1538
  };
package/dist/index.d.ts CHANGED
@@ -87,6 +87,8 @@ export { Logger } from './_tsup-dts-rollup.js';
87
87
  export { ToolSignature } from './_tsup-dts-rollup.js';
88
88
  export { ToolRegistry } from './_tsup-dts-rollup.js';
89
89
  export { WorkflowTools } from './_tsup-dts-rollup.js';
90
+ export { StepOptions } from './_tsup-dts-rollup.js';
91
+ export { StepFn } from './_tsup-dts-rollup.js';
90
92
  export { WorkflowContext } from './_tsup-dts-rollup.js';
91
93
  export { WorkflowFn } from './_tsup-dts-rollup.js';
92
94
  export { makeStepFn } from './_tsup-dts-rollup.js';
package/dist/index.js CHANGED
@@ -1753,7 +1753,7 @@ var agentWorkflow = async (input, { step, tools, logger }) => {
1753
1753
  for (let i = 0; i < maxToolRoundTrips; i++) {
1754
1754
  messages.push(...nextMessage);
1755
1755
  await event(`start-round-${i}`, { kind: "StartRequest" /* StartRequest */, userMessage: nextMessage });
1756
- const assistantMessage = await step(`agent-round-${i}`, async () => {
1756
+ const assistantMessage = await step(`agent-round-${i}`, { retry: 2 }, async () => {
1757
1757
  return await tools.generateText({
1758
1758
  messages,
1759
1759
  tools: toolSet,
@@ -2050,23 +2050,44 @@ var silentLogger = {
2050
2050
  };
2051
2051
  function createContext(tools, stepFn, logger = silentLogger) {
2052
2052
  if (!stepFn) {
2053
- stepFn = async (_name, fn) => fn();
2053
+ stepFn = async (_name, arg2, arg3) => {
2054
+ const fn = typeof arg2 === "function" ? arg2 : arg3;
2055
+ return fn();
2056
+ };
2054
2057
  }
2055
2058
  return { step: stepFn, logger, tools };
2056
2059
  }
2057
2060
  var makeStepFn = () => {
2058
2061
  const results = /* @__PURE__ */ new Map();
2059
2062
  const callStack = [];
2060
- return async (name, fn) => {
2063
+ return async (name, arg2, arg3) => {
2064
+ let fn;
2065
+ let options;
2066
+ if (typeof arg2 === "function") {
2067
+ fn = arg2;
2068
+ options = arg3;
2069
+ } else {
2070
+ options = arg2;
2071
+ fn = arg3;
2072
+ }
2061
2073
  callStack.push(name);
2062
2074
  const key = callStack.join(">");
2063
2075
  try {
2064
2076
  if (results.has(key)) {
2065
2077
  return results.get(key);
2066
2078
  }
2067
- const result = await fn();
2068
- results.set(key, result);
2069
- return result;
2079
+ const maxRetryCount = options?.retry ?? 0;
2080
+ let lastError;
2081
+ for (let retryCount = 0; retryCount <= maxRetryCount; retryCount++) {
2082
+ try {
2083
+ const result = await fn();
2084
+ results.set(key, result);
2085
+ return result;
2086
+ } catch (error) {
2087
+ lastError = error;
2088
+ }
2089
+ }
2090
+ throw lastError;
2070
2091
  } finally {
2071
2092
  callStack.pop();
2072
2093
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@polka-codes/core",
3
- "version": "0.9.69",
3
+ "version": "0.9.71",
4
4
  "license": "AGPL-3.0",
5
5
  "author": "github@polka.codes",
6
6
  "type": "module",