smoltalk 0.0.39 → 0.0.41
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/strategies/baseStrategy.js +3 -0
- package/dist/strategies/fallbackStrategy.d.ts +5 -1
- package/dist/strategies/fallbackStrategy.js +11 -4
- package/dist/strategies/idStrategy.d.ts +1 -0
- package/dist/strategies/idStrategy.js +3 -3
- package/dist/strategies/raceStrategy.d.ts +1 -0
- package/dist/strategies/raceStrategy.js +3 -0
- package/dist/types.d.ts +1 -1
- package/package.json +1 -1
|
@@ -5,6 +5,10 @@ export declare class FallbackStrategy extends BaseStrategy {
|
|
|
5
5
|
strategies: Strategy[];
|
|
6
6
|
config: FallbackStrategyConfig;
|
|
7
7
|
constructor(strategies: Strategy[], config: FallbackStrategyConfig);
|
|
8
|
-
|
|
8
|
+
toString(): string;
|
|
9
|
+
_text(config: SmolPromptConfig): Promise<import("../types.js").Result<import("../types.js").PromptResult> | import("../types.js").Success<{
|
|
10
|
+
output: null;
|
|
11
|
+
toolCalls: never[];
|
|
12
|
+
}>>;
|
|
9
13
|
toJSON(): StrategyJSON;
|
|
10
14
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { SmolStructuredOutputError, SmolTimeoutError } from "../smolError.js";
|
|
2
|
+
import { success } from "../types.js";
|
|
2
3
|
import { BaseStrategy } from "./baseStrategy.js";
|
|
3
4
|
export class FallbackStrategy extends BaseStrategy {
|
|
4
5
|
strategies;
|
|
@@ -8,6 +9,9 @@ export class FallbackStrategy extends BaseStrategy {
|
|
|
8
9
|
this.strategies = strategies;
|
|
9
10
|
this.config = config;
|
|
10
11
|
}
|
|
12
|
+
toString() {
|
|
13
|
+
return `FallbackStrategy([${this.strategies.map((s) => s.toString()).join(", ")}], config: ${JSON.stringify(this.config)})`;
|
|
14
|
+
}
|
|
11
15
|
async _text(config) {
|
|
12
16
|
for (let i = 0; i < this.strategies.length; i++) {
|
|
13
17
|
const strategy = this.strategies[i];
|
|
@@ -16,6 +20,11 @@ export class FallbackStrategy extends BaseStrategy {
|
|
|
16
20
|
return result;
|
|
17
21
|
}
|
|
18
22
|
catch (error) {
|
|
23
|
+
// If the abort signal was triggered (e.g. by a race strategy winner
|
|
24
|
+
// or external cancellation), stop without trying further fallbacks.
|
|
25
|
+
if (config.abortSignal?.aborted) {
|
|
26
|
+
return success({ output: null, toolCalls: [] });
|
|
27
|
+
}
|
|
19
28
|
if (error instanceof SmolTimeoutError) {
|
|
20
29
|
if (this.config.fallbackOn.includes("timeout")) {
|
|
21
30
|
continue;
|
|
@@ -26,10 +35,8 @@ export class FallbackStrategy extends BaseStrategy {
|
|
|
26
35
|
continue;
|
|
27
36
|
}
|
|
28
37
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
continue;
|
|
32
|
-
}
|
|
38
|
+
if (this.config.fallbackOn.includes("error")) {
|
|
39
|
+
continue;
|
|
33
40
|
}
|
|
34
41
|
throw error;
|
|
35
42
|
}
|
|
@@ -5,6 +5,7 @@ import { StrategyJSON } from "./types.js";
|
|
|
5
5
|
export declare class IDStrategy extends BaseStrategy {
|
|
6
6
|
model: Model;
|
|
7
7
|
constructor(model: Model);
|
|
8
|
+
toString(): string;
|
|
8
9
|
_text(_config: SmolPromptConfig): Promise<import("../types.js").Result<import("../types.js").PromptResult>>;
|
|
9
10
|
toJSON(): StrategyJSON;
|
|
10
11
|
}
|
|
@@ -6,14 +6,14 @@ export class IDStrategy extends BaseStrategy {
|
|
|
6
6
|
super();
|
|
7
7
|
this.model = model;
|
|
8
8
|
}
|
|
9
|
+
toString() {
|
|
10
|
+
return `IDStrategy(model: ${this.model.getResolvedModel()})`;
|
|
11
|
+
}
|
|
9
12
|
async _text(_config) {
|
|
10
13
|
const config = {
|
|
11
14
|
..._config,
|
|
12
15
|
model: this.model.getResolvedModel(),
|
|
13
16
|
};
|
|
14
|
-
if (config.hooks?.onStrategyStart) {
|
|
15
|
-
config.hooks.onStrategyStart(config);
|
|
16
|
-
}
|
|
17
17
|
return text({ ...config, stream: false });
|
|
18
18
|
}
|
|
19
19
|
toJSON() {
|
|
@@ -4,6 +4,7 @@ import { Strategy, StrategyJSON } from "./types.js";
|
|
|
4
4
|
export declare class RaceStrategy extends BaseStrategy {
|
|
5
5
|
strategies: Strategy[];
|
|
6
6
|
constructor(strategies: Strategy[]);
|
|
7
|
+
toString(): string;
|
|
7
8
|
_text(config: SmolPromptConfig): Promise<import("../types.js").Failure | import("../types.js").Success<import("../types.js").PromptResult>>;
|
|
8
9
|
toJSON(): StrategyJSON;
|
|
9
10
|
}
|
|
@@ -5,6 +5,9 @@ export class RaceStrategy extends BaseStrategy {
|
|
|
5
5
|
super();
|
|
6
6
|
this.strategies = strategies;
|
|
7
7
|
}
|
|
8
|
+
toString() {
|
|
9
|
+
return `RaceStrategy([${this.strategies.map((s) => s.toString()).join(", ")}])`;
|
|
10
|
+
}
|
|
8
11
|
async _text(config) {
|
|
9
12
|
const controllers = this.strategies.map(() => new AbortController());
|
|
10
13
|
// Link to any existing abort signal so external cancellation still works
|
package/dist/types.d.ts
CHANGED
|
@@ -54,7 +54,7 @@ export type PromptConfig = {
|
|
|
54
54
|
onToolCall: (toolCall: ToolCall) => void;
|
|
55
55
|
onEnd: (result: PromptResult) => void;
|
|
56
56
|
onError: (error: Error) => void;
|
|
57
|
-
onStrategyStart: (config: SmolPromptConfig) => void;
|
|
57
|
+
onStrategyStart: (strategy: Strategy, config: SmolPromptConfig) => void;
|
|
58
58
|
}>;
|
|
59
59
|
strategy?: Strategy | StrategyJSON;
|
|
60
60
|
};
|