@effect-uai/core 0.5.2 → 0.7.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/README.md +1 -1
- package/dist/{Audio-BfCTGnH3.d.mts → Audio-DPlTsNdz.d.mts} +3 -2
- package/dist/Audio-DPlTsNdz.d.mts.map +1 -0
- package/dist/{Items-BH8xUkoR.d.mts → Items-D8UaXQx_.d.mts} +15 -15
- package/dist/Items-D8UaXQx_.d.mts.map +1 -0
- package/dist/SandboxError-BvKypkJm.d.mts +158 -0
- package/dist/SandboxError-BvKypkJm.d.mts.map +1 -0
- package/dist/{Tool-87ViKCCO.d.mts → Tool-CiFXYjmR.d.mts} +11 -11
- package/dist/{Tool-87ViKCCO.d.mts.map → Tool-CiFXYjmR.d.mts.map} +1 -1
- package/dist/capabilities/Capabilities.d.mts +78 -0
- package/dist/capabilities/Capabilities.d.mts.map +1 -0
- package/dist/capabilities/Capabilities.mjs +65 -0
- package/dist/capabilities/Capabilities.mjs.map +1 -0
- package/dist/domain/Audio.d.mts +1 -1
- package/dist/domain/Audio.mjs.map +1 -1
- package/dist/domain/Items.d.mts +2 -2
- package/dist/domain/Items.mjs +15 -15
- package/dist/domain/Items.mjs.map +1 -1
- package/dist/domain/Music.d.mts +131 -72
- package/dist/domain/Music.d.mts.map +1 -1
- package/dist/domain/Music.mjs +36 -9
- package/dist/domain/Music.mjs.map +1 -1
- package/dist/domain/Transcript.d.mts +8 -2
- package/dist/domain/Transcript.d.mts.map +1 -1
- package/dist/domain/Transcript.mjs.map +1 -1
- package/dist/domain/Turn.d.mts +388 -2
- package/dist/domain/Turn.d.mts.map +1 -0
- package/dist/domain/Turn.mjs +13 -13
- package/dist/domain/Turn.mjs.map +1 -1
- package/dist/embedding-model/Embedding.d.mts +12 -2
- package/dist/embedding-model/Embedding.d.mts.map +1 -1
- package/dist/embedding-model/Embedding.mjs.map +1 -1
- package/dist/embedding-model/EmbeddingModel.d.mts +36 -23
- package/dist/embedding-model/EmbeddingModel.d.mts.map +1 -1
- package/dist/embedding-model/EmbeddingModel.mjs +20 -1
- package/dist/embedding-model/EmbeddingModel.mjs.map +1 -1
- package/dist/embedding-model/EmbeddingModel.test.mjs +15 -3
- package/dist/embedding-model/EmbeddingModel.test.mjs.map +1 -1
- package/dist/index.d.mts +13 -7
- package/dist/index.mjs +9 -3
- package/dist/language-model/LanguageModel.d.mts +5 -5
- package/dist/language-model/LanguageModel.d.mts.map +1 -1
- package/dist/language-model/LanguageModel.mjs.map +1 -1
- package/dist/loop/Loop.d.mts +37 -90
- package/dist/loop/Loop.d.mts.map +1 -1
- package/dist/loop/Loop.mjs +39 -93
- package/dist/loop/Loop.mjs.map +1 -1
- package/dist/loop/Loop.test.mjs +46 -54
- package/dist/loop/Loop.test.mjs.map +1 -1
- package/dist/music-generator/MusicGenerator.d.mts +48 -25
- package/dist/music-generator/MusicGenerator.d.mts.map +1 -1
- package/dist/music-generator/MusicGenerator.mjs +17 -9
- package/dist/music-generator/MusicGenerator.mjs.map +1 -1
- package/dist/music-generator/MusicGenerator.test.mjs +81 -56
- package/dist/music-generator/MusicGenerator.test.mjs.map +1 -1
- package/dist/sandbox/Memory.d.mts +53 -0
- package/dist/sandbox/Memory.d.mts.map +1 -0
- package/dist/sandbox/Memory.mjs +68 -0
- package/dist/sandbox/Memory.mjs.map +1 -0
- package/dist/sandbox/Sandbox.d.mts +717 -0
- package/dist/sandbox/Sandbox.d.mts.map +1 -0
- package/dist/sandbox/Sandbox.mjs +192 -0
- package/dist/sandbox/Sandbox.mjs.map +1 -0
- package/dist/sandbox/SandboxError.d.mts +2 -0
- package/dist/sandbox/SandboxError.mjs +89 -0
- package/dist/sandbox/SandboxError.mjs.map +1 -0
- package/dist/sandbox/SandboxImage.d.mts +28 -0
- package/dist/sandbox/SandboxImage.d.mts.map +1 -0
- package/dist/sandbox/SandboxImage.mjs +32 -0
- package/dist/sandbox/SandboxImage.mjs.map +1 -0
- package/dist/sandbox/SandboxNetwork.d.mts +34 -0
- package/dist/sandbox/SandboxNetwork.d.mts.map +1 -0
- package/dist/sandbox/SandboxNetwork.mjs +36 -0
- package/dist/sandbox/SandboxNetwork.mjs.map +1 -0
- package/dist/speech-synthesizer/SpeechSynthesizer.d.mts +84 -3
- package/dist/speech-synthesizer/SpeechSynthesizer.d.mts.map +1 -1
- package/dist/speech-synthesizer/SpeechSynthesizer.mjs +32 -2
- package/dist/speech-synthesizer/SpeechSynthesizer.mjs.map +1 -1
- package/dist/speech-synthesizer/SpeechSynthesizer.test.mjs +59 -5
- package/dist/speech-synthesizer/SpeechSynthesizer.test.mjs.map +1 -1
- package/dist/testing/MockMusicGenerator.d.mts +12 -7
- package/dist/testing/MockMusicGenerator.d.mts.map +1 -1
- package/dist/testing/MockMusicGenerator.mjs +4 -3
- package/dist/testing/MockMusicGenerator.mjs.map +1 -1
- package/dist/testing/MockProvider.d.mts +3 -3
- package/dist/testing/MockProvider.d.mts.map +1 -1
- package/dist/testing/MockProvider.mjs.map +1 -1
- package/dist/testing/MockSandbox.d.mts +604 -0
- package/dist/testing/MockSandbox.d.mts.map +1 -0
- package/dist/testing/MockSandbox.mjs +160 -0
- package/dist/testing/MockSandbox.mjs.map +1 -0
- package/dist/testing/MockSpeechSynthesizer.d.mts +27 -12
- package/dist/testing/MockSpeechSynthesizer.d.mts.map +1 -1
- package/dist/testing/MockSpeechSynthesizer.mjs +75 -51
- package/dist/testing/MockSpeechSynthesizer.mjs.map +1 -1
- package/dist/tool/{Resolvers.d.mts → Approval.d.mts} +27 -27
- package/dist/tool/Approval.d.mts.map +1 -0
- package/dist/tool/{Resolvers.mjs → Approval.mjs} +18 -18
- package/dist/tool/Approval.mjs.map +1 -0
- package/dist/tool/{Resolvers.test.mjs → Approval.test.mjs} +40 -40
- package/dist/tool/Approval.test.mjs.map +1 -0
- package/dist/tool/HistoryCheck.d.mts +6 -6
- package/dist/tool/HistoryCheck.d.mts.map +1 -1
- package/dist/tool/HistoryCheck.mjs +5 -5
- package/dist/tool/HistoryCheck.mjs.map +1 -1
- package/dist/tool/Tool.d.mts +2 -2
- package/dist/tool/Tool.mjs +4 -4
- package/dist/tool/Tool.mjs.map +1 -1
- package/dist/tool/ToolEvent.d.mts +19 -19
- package/dist/tool/ToolEvent.d.mts.map +1 -1
- package/dist/tool/ToolEvent.mjs +8 -8
- package/dist/tool/ToolEvent.mjs.map +1 -1
- package/dist/tool/{Outcome.d.mts → ToolResult.d.mts} +29 -29
- package/dist/tool/ToolResult.d.mts.map +1 -0
- package/dist/tool/ToolResult.mjs +61 -0
- package/dist/tool/ToolResult.mjs.map +1 -0
- package/dist/tool/Toolkit.d.mts +58 -26
- package/dist/tool/Toolkit.d.mts.map +1 -1
- package/dist/tool/Toolkit.mjs +62 -34
- package/dist/tool/Toolkit.mjs.map +1 -1
- package/dist/tool/Toolkit.test.mjs +13 -13
- package/dist/tool/Toolkit.test.mjs.map +1 -1
- package/dist/transcriber/Transcriber.d.mts +11 -10
- package/dist/transcriber/Transcriber.d.mts.map +1 -1
- package/dist/transcriber/Transcriber.mjs.map +1 -1
- package/dist/transcriber/Transcriber.test.mjs +3 -3
- package/dist/transcriber/Transcriber.test.mjs.map +1 -1
- package/package.json +35 -7
- package/src/capabilities/Capabilities.ts +81 -0
- package/src/domain/Audio.ts +2 -1
- package/src/domain/Items.ts +9 -9
- package/src/domain/Music.ts +142 -68
- package/src/domain/Transcript.ts +7 -1
- package/src/domain/Turn.ts +16 -16
- package/src/embedding-model/Embedding.ts +11 -0
- package/src/embedding-model/EmbeddingModel.test.ts +15 -4
- package/src/embedding-model/EmbeddingModel.ts +48 -21
- package/src/index.ts +8 -2
- package/src/language-model/LanguageModel.ts +3 -3
- package/src/loop/Loop.test.ts +93 -91
- package/src/loop/Loop.ts +72 -170
- package/src/music-generator/MusicGenerator.test.ts +78 -53
- package/src/music-generator/MusicGenerator.ts +65 -24
- package/src/sandbox/Memory.ts +128 -0
- package/src/sandbox/Sandbox.ts +639 -0
- package/src/sandbox/SandboxError.ts +140 -0
- package/src/sandbox/SandboxImage.ts +26 -0
- package/src/sandbox/SandboxNetwork.ts +34 -0
- package/src/speech-synthesizer/SpeechSynthesizer.test.ts +92 -3
- package/src/speech-synthesizer/SpeechSynthesizer.ts +109 -0
- package/src/testing/MockMusicGenerator.ts +28 -18
- package/src/testing/MockProvider.ts +21 -20
- package/src/testing/MockSandbox.ts +342 -0
- package/src/testing/MockSpeechSynthesizer.ts +137 -77
- package/src/tool/{Resolvers.test.ts → Approval.test.ts} +45 -54
- package/src/tool/{Resolvers.ts → Approval.ts} +25 -25
- package/src/tool/HistoryCheck.ts +10 -13
- package/src/tool/Tool.ts +13 -15
- package/src/tool/ToolEvent.ts +7 -7
- package/src/tool/{Outcome.ts → ToolResult.ts} +20 -20
- package/src/tool/Toolkit.test.ts +13 -13
- package/src/tool/Toolkit.ts +97 -73
- package/src/transcriber/Transcriber.test.ts +3 -3
- package/src/transcriber/Transcriber.ts +10 -7
- package/dist/Audio-BfCTGnH3.d.mts.map +0 -1
- package/dist/Items-BH8xUkoR.d.mts.map +0 -1
- package/dist/Turn-0CwCAyVe.d.mts +0 -388
- package/dist/Turn-0CwCAyVe.d.mts.map +0 -1
- package/dist/tool/Outcome.d.mts.map +0 -1
- package/dist/tool/Outcome.mjs +0 -61
- package/dist/tool/Outcome.mjs.map +0 -1
- package/dist/tool/Resolvers.d.mts.map +0 -1
- package/dist/tool/Resolvers.mjs.map +0 -1
- package/dist/tool/Resolvers.test.mjs.map +0 -1
- /package/dist/tool/{Resolvers.test.d.mts → Approval.test.d.mts} +0 -0
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { ToolResult } from "./
|
|
1
|
+
import { ToolResult } from "./ToolResult.mjs";
|
|
2
2
|
import { Data } from "effect";
|
|
3
3
|
import * as _$effect_Unify0 from "effect/Unify";
|
|
4
4
|
|
|
5
5
|
//#region src/tool/ToolEvent.d.ts
|
|
6
6
|
declare namespace ToolEvent_d_exports {
|
|
7
|
-
export { ToolEvent, isApprovalRequested,
|
|
7
|
+
export { ToolEvent, isApprovalRequested, isOutput, isProgress };
|
|
8
8
|
}
|
|
9
9
|
type ToolEvent = Data.TaggedEnum<{
|
|
10
10
|
ApprovalRequested: {
|
|
@@ -12,7 +12,7 @@ type ToolEvent = Data.TaggedEnum<{
|
|
|
12
12
|
readonly tool: string;
|
|
13
13
|
readonly arguments: string;
|
|
14
14
|
};
|
|
15
|
-
|
|
15
|
+
Progress: {
|
|
16
16
|
readonly call_id: string;
|
|
17
17
|
readonly tool: string;
|
|
18
18
|
readonly data: unknown;
|
|
@@ -25,7 +25,7 @@ type ToolEvent = Data.TaggedEnum<{
|
|
|
25
25
|
* Namespace of constructors, type guards, and matchers for `ToolEvent`,
|
|
26
26
|
* provided by `Data.taggedEnum`. Use `ToolEvent.Output({ result })` to build
|
|
27
27
|
* an event, `ToolEvent.$is("Output")` for type narrowing,
|
|
28
|
-
* `ToolEvent.$match({ ApprovalRequested,
|
|
28
|
+
* `ToolEvent.$match({ ApprovalRequested, Progress, Output })` for
|
|
29
29
|
* exhaustive pattern matching.
|
|
30
30
|
*/
|
|
31
31
|
declare const ToolEvent: {
|
|
@@ -35,8 +35,8 @@ declare const ToolEvent: {
|
|
|
35
35
|
readonly tool: string;
|
|
36
36
|
readonly arguments: string;
|
|
37
37
|
}, "_tag">;
|
|
38
|
-
readonly
|
|
39
|
-
readonly _tag: "
|
|
38
|
+
readonly Progress: Data.TaggedEnum.ConstructorFrom<{
|
|
39
|
+
readonly _tag: "Progress";
|
|
40
40
|
readonly call_id: string;
|
|
41
41
|
readonly tool: string;
|
|
42
42
|
readonly data: unknown;
|
|
@@ -45,7 +45,7 @@ declare const ToolEvent: {
|
|
|
45
45
|
readonly _tag: "Output";
|
|
46
46
|
readonly result: ToolResult;
|
|
47
47
|
}, "_tag">;
|
|
48
|
-
readonly $is: <Tag extends "ApprovalRequested" | "
|
|
48
|
+
readonly $is: <Tag extends "ApprovalRequested" | "Progress" | "Output">(tag: Tag) => (u: unknown) => u is Extract<{
|
|
49
49
|
readonly _tag: "ApprovalRequested";
|
|
50
50
|
readonly call_id: string;
|
|
51
51
|
readonly tool: string;
|
|
@@ -53,7 +53,7 @@ declare const ToolEvent: {
|
|
|
53
53
|
}, {
|
|
54
54
|
readonly _tag: Tag;
|
|
55
55
|
}> | Extract<{
|
|
56
|
-
readonly _tag: "
|
|
56
|
+
readonly _tag: "Progress";
|
|
57
57
|
readonly call_id: string;
|
|
58
58
|
readonly tool: string;
|
|
59
59
|
readonly data: unknown;
|
|
@@ -73,8 +73,8 @@ declare const ToolEvent: {
|
|
|
73
73
|
readonly tool: string;
|
|
74
74
|
readonly arguments: string;
|
|
75
75
|
}) => any;
|
|
76
|
-
readonly
|
|
77
|
-
readonly _tag: "
|
|
76
|
+
readonly Progress: (args: {
|
|
77
|
+
readonly _tag: "Progress";
|
|
78
78
|
readonly call_id: string;
|
|
79
79
|
readonly tool: string;
|
|
80
80
|
readonly data: unknown;
|
|
@@ -89,14 +89,14 @@ declare const ToolEvent: {
|
|
|
89
89
|
readonly tool: string;
|
|
90
90
|
readonly arguments: string;
|
|
91
91
|
} | {
|
|
92
|
-
readonly _tag: "
|
|
92
|
+
readonly _tag: "Progress";
|
|
93
93
|
readonly call_id: string;
|
|
94
94
|
readonly tool: string;
|
|
95
95
|
readonly data: unknown;
|
|
96
96
|
} | {
|
|
97
97
|
readonly _tag: "Output";
|
|
98
98
|
readonly result: ToolResult;
|
|
99
|
-
}) => _$effect_Unify0.Unify<ReturnType<Cases["ApprovalRequested" | "
|
|
99
|
+
}) => _$effect_Unify0.Unify<ReturnType<Cases["ApprovalRequested" | "Progress" | "Output"]>>;
|
|
100
100
|
<Cases extends {
|
|
101
101
|
readonly ApprovalRequested: (args: {
|
|
102
102
|
readonly _tag: "ApprovalRequested";
|
|
@@ -104,8 +104,8 @@ declare const ToolEvent: {
|
|
|
104
104
|
readonly tool: string;
|
|
105
105
|
readonly arguments: string;
|
|
106
106
|
}) => any;
|
|
107
|
-
readonly
|
|
108
|
-
readonly _tag: "
|
|
107
|
+
readonly Progress: (args: {
|
|
108
|
+
readonly _tag: "Progress";
|
|
109
109
|
readonly call_id: string;
|
|
110
110
|
readonly tool: string;
|
|
111
111
|
readonly data: unknown;
|
|
@@ -120,14 +120,14 @@ declare const ToolEvent: {
|
|
|
120
120
|
readonly tool: string;
|
|
121
121
|
readonly arguments: string;
|
|
122
122
|
} | {
|
|
123
|
-
readonly _tag: "
|
|
123
|
+
readonly _tag: "Progress";
|
|
124
124
|
readonly call_id: string;
|
|
125
125
|
readonly tool: string;
|
|
126
126
|
readonly data: unknown;
|
|
127
127
|
} | {
|
|
128
128
|
readonly _tag: "Output";
|
|
129
129
|
readonly result: ToolResult;
|
|
130
|
-
}, cases: Cases): _$effect_Unify0.Unify<ReturnType<Cases["ApprovalRequested" | "
|
|
130
|
+
}, cases: Cases): _$effect_Unify0.Unify<ReturnType<Cases["ApprovalRequested" | "Progress" | "Output"]>>;
|
|
131
131
|
};
|
|
132
132
|
};
|
|
133
133
|
declare const isApprovalRequested: (u: unknown) => u is {
|
|
@@ -136,8 +136,8 @@ declare const isApprovalRequested: (u: unknown) => u is {
|
|
|
136
136
|
readonly tool: string;
|
|
137
137
|
readonly arguments: string;
|
|
138
138
|
};
|
|
139
|
-
declare const
|
|
140
|
-
readonly _tag: "
|
|
139
|
+
declare const isProgress: (u: unknown) => u is {
|
|
140
|
+
readonly _tag: "Progress";
|
|
141
141
|
readonly call_id: string;
|
|
142
142
|
readonly tool: string;
|
|
143
143
|
readonly data: unknown;
|
|
@@ -147,5 +147,5 @@ declare const isOutput: (u: unknown) => u is {
|
|
|
147
147
|
readonly result: ToolResult;
|
|
148
148
|
};
|
|
149
149
|
//#endregion
|
|
150
|
-
export { ToolEvent, isApprovalRequested,
|
|
150
|
+
export { ToolEvent, isApprovalRequested, isOutput, isProgress, ToolEvent_d_exports as t };
|
|
151
151
|
//# sourceMappingURL=ToolEvent.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ToolEvent.d.mts","names":[],"sources":["../../src/tool/ToolEvent.ts"],"mappings":";;;;;;;;KAaY,SAAA,GAAY,IAAA,CAAK,UAAA;EAC3B,iBAAA;IAAA,SACW,OAAA;IAAA,SACA,IAAA;IAAA,SACA,SAAA;EAAA;EAEX,
|
|
1
|
+
{"version":3,"file":"ToolEvent.d.mts","names":[],"sources":["../../src/tool/ToolEvent.ts"],"mappings":";;;;;;;;KAaY,SAAA,GAAY,IAAA,CAAK,UAAA;EAC3B,iBAAA;IAAA,SACW,OAAA;IAAA,SACA,IAAA;IAAA,SACA,SAAA;EAAA;EAEX,QAAA;IAAA,SACW,OAAA;IAAA,SACA,IAAA;IAAA,SACA,IAAA;EAAA;EAEX,MAAA;IAAA,SACW,MAAA,EAAQ,UAAA;EAAA;AAAA;;;;;AAWrB;;;cAAa,SAAA;EAAA;;;;;;;;;;;;;;qBAXQ,UAAA;EAAA;EAAA;;;;;;;;;;;;;;;;qBAAA,UAAA;EAAA;IAAA;;;;;;;;;;;;;;;;;;yBAAA,UAAA;MAAA;IAAA;;;;;;;;;;;;uBAAA,UAAA;IAAA;;;;;;;;;;;;;;;;yBAAA,UAAA;MAAA;IAAA;;;;;;;;;;;;uBAAA,UAAA;IAAA;;;cAaR,mBAAA,GAAmB,CAAA,cAAA,CAAA;EAAA;;;;;cACnB,UAAA,GAAU,CAAA,cAAA,CAAA;EAAA;;;;;cACV,QAAA,GAAQ,CAAA,cAAA,CAAA;EAAA;mBAfA,UAAA;AAAA"}
|
package/dist/tool/ToolEvent.mjs
CHANGED
|
@@ -5,30 +5,30 @@ import { Data } from "effect";
|
|
|
5
5
|
* The event type emitted while handling tool calls.
|
|
6
6
|
*
|
|
7
7
|
* - ApprovalRequested : gated calls waiting for approval
|
|
8
|
-
* -
|
|
8
|
+
* - Progress : per-element passthrough from a streaming tool's run
|
|
9
9
|
* - Output : terminal result (carries a structured ToolResult)
|
|
10
10
|
*
|
|
11
|
-
* Recipes thread `ToolEvent.Output.result` through `
|
|
12
|
-
* `
|
|
11
|
+
* Recipes thread `ToolEvent.Output.result` through `continueWithResults` and
|
|
12
|
+
* apply `toToolCallOutput` when appending to history.
|
|
13
13
|
*/
|
|
14
14
|
var ToolEvent_exports = /* @__PURE__ */ __exportAll({
|
|
15
15
|
ToolEvent: () => ToolEvent,
|
|
16
16
|
isApprovalRequested: () => isApprovalRequested,
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
isOutput: () => isOutput,
|
|
18
|
+
isProgress: () => isProgress
|
|
19
19
|
});
|
|
20
20
|
/**
|
|
21
21
|
* Namespace of constructors, type guards, and matchers for `ToolEvent`,
|
|
22
22
|
* provided by `Data.taggedEnum`. Use `ToolEvent.Output({ result })` to build
|
|
23
23
|
* an event, `ToolEvent.$is("Output")` for type narrowing,
|
|
24
|
-
* `ToolEvent.$match({ ApprovalRequested,
|
|
24
|
+
* `ToolEvent.$match({ ApprovalRequested, Progress, Output })` for
|
|
25
25
|
* exhaustive pattern matching.
|
|
26
26
|
*/
|
|
27
27
|
const ToolEvent = Data.taggedEnum();
|
|
28
28
|
const isApprovalRequested = ToolEvent.$is("ApprovalRequested");
|
|
29
|
-
const
|
|
29
|
+
const isProgress = ToolEvent.$is("Progress");
|
|
30
30
|
const isOutput = ToolEvent.$is("Output");
|
|
31
31
|
//#endregion
|
|
32
|
-
export { ToolEvent, isApprovalRequested,
|
|
32
|
+
export { ToolEvent, isApprovalRequested, isOutput, isProgress, ToolEvent_exports as t };
|
|
33
33
|
|
|
34
34
|
//# sourceMappingURL=ToolEvent.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ToolEvent.mjs","names":[],"sources":["../../src/tool/ToolEvent.ts"],"sourcesContent":["/**\n * The event type emitted while handling tool calls.\n *\n * - ApprovalRequested : gated calls waiting for approval\n * -
|
|
1
|
+
{"version":3,"file":"ToolEvent.mjs","names":[],"sources":["../../src/tool/ToolEvent.ts"],"sourcesContent":["/**\n * The event type emitted while handling tool calls.\n *\n * - ApprovalRequested : gated calls waiting for approval\n * - Progress : per-element passthrough from a streaming tool's run\n * - Output : terminal result (carries a structured ToolResult)\n *\n * Recipes thread `ToolEvent.Output.result` through `continueWithResults` and\n * apply `toToolCallOutput` when appending to history.\n */\nimport { Data } from \"effect\"\nimport type { ToolResult } from \"./ToolResult.js\"\n\nexport type ToolEvent = Data.TaggedEnum<{\n ApprovalRequested: {\n readonly call_id: string\n readonly tool: string\n readonly arguments: string\n }\n Progress: {\n readonly call_id: string\n readonly tool: string\n readonly data: unknown\n }\n Output: {\n readonly result: ToolResult\n }\n}>\n\n/**\n * Namespace of constructors, type guards, and matchers for `ToolEvent`,\n * provided by `Data.taggedEnum`. Use `ToolEvent.Output({ result })` to build\n * an event, `ToolEvent.$is(\"Output\")` for type narrowing,\n * `ToolEvent.$match({ ApprovalRequested, Progress, Output })` for\n * exhaustive pattern matching.\n */\nexport const ToolEvent = Data.taggedEnum<ToolEvent>()\n\nexport const isApprovalRequested = ToolEvent.$is(\"ApprovalRequested\")\nexport const isProgress = ToolEvent.$is(\"Progress\")\nexport const isOutput = ToolEvent.$is(\"Output\")\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAoCA,MAAa,YAAY,KAAK,YAAuB;AAErD,MAAa,sBAAsB,UAAU,IAAI,oBAAoB;AACrE,MAAa,aAAa,UAAU,IAAI,WAAW;AACnD,MAAa,WAAW,UAAU,IAAI,SAAS"}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { v as ToolCall, y as ToolCallOutput } from "../Items-D8UaXQx_.mjs";
|
|
2
2
|
import { Data } from "effect";
|
|
3
3
|
import * as _$effect_Unify0 from "effect/Unify";
|
|
4
4
|
|
|
5
|
-
//#region src/tool/
|
|
6
|
-
declare namespace
|
|
7
|
-
export { ToolResult, cancelled, denied, executionError,
|
|
5
|
+
//#region src/tool/ToolResult.d.ts
|
|
6
|
+
declare namespace ToolResult_d_exports {
|
|
7
|
+
export { ToolResult, cancelled, denied, executionError, failed, isFailure, isOk, toToolCallOutput };
|
|
8
8
|
}
|
|
9
9
|
type ToolResult = Data.TaggedEnum<{
|
|
10
|
-
|
|
10
|
+
Ok: {
|
|
11
11
|
readonly call_id: string;
|
|
12
12
|
readonly tool: string;
|
|
13
13
|
readonly value: unknown;
|
|
@@ -21,15 +21,15 @@ type ToolResult = Data.TaggedEnum<{
|
|
|
21
21
|
}>;
|
|
22
22
|
/**
|
|
23
23
|
* Namespace of constructors, type guards, and matchers for `ToolResult`,
|
|
24
|
-
* provided by `Data.taggedEnum`. Use `ToolResult.$is("
|
|
25
|
-
* narrowing and `ToolResult.$match({
|
|
24
|
+
* provided by `Data.taggedEnum`. Use `ToolResult.$is("Ok")` for type
|
|
25
|
+
* narrowing and `ToolResult.$match({ Ok, Failure })` for exhaustive
|
|
26
26
|
* pattern matching. Synthetic-result helpers (`denied`, `cancelled`,
|
|
27
|
-
* `executionError`, `
|
|
27
|
+
* `executionError`, `failed`) below are kinder constructors than the
|
|
28
28
|
* raw `ToolResult.Failure(...)`.
|
|
29
29
|
*/
|
|
30
30
|
declare const ToolResult: {
|
|
31
|
-
readonly
|
|
32
|
-
readonly _tag: "
|
|
31
|
+
readonly Ok: Data.TaggedEnum.ConstructorFrom<{
|
|
32
|
+
readonly _tag: "Ok";
|
|
33
33
|
readonly call_id: string;
|
|
34
34
|
readonly tool: string;
|
|
35
35
|
readonly value: unknown;
|
|
@@ -41,8 +41,8 @@ declare const ToolResult: {
|
|
|
41
41
|
readonly kind: string;
|
|
42
42
|
readonly reason?: string;
|
|
43
43
|
}, "_tag">;
|
|
44
|
-
readonly $is: <Tag extends "
|
|
45
|
-
readonly _tag: "
|
|
44
|
+
readonly $is: <Tag extends "Ok" | "Failure">(tag: Tag) => (u: unknown) => u is Extract<{
|
|
45
|
+
readonly _tag: "Ok";
|
|
46
46
|
readonly call_id: string;
|
|
47
47
|
readonly tool: string;
|
|
48
48
|
readonly value: unknown;
|
|
@@ -59,8 +59,8 @@ declare const ToolResult: {
|
|
|
59
59
|
}>;
|
|
60
60
|
readonly $match: {
|
|
61
61
|
<Cases extends {
|
|
62
|
-
readonly
|
|
63
|
-
readonly _tag: "
|
|
62
|
+
readonly Ok: (args: {
|
|
63
|
+
readonly _tag: "Ok";
|
|
64
64
|
readonly call_id: string;
|
|
65
65
|
readonly tool: string;
|
|
66
66
|
readonly value: unknown;
|
|
@@ -73,7 +73,7 @@ declare const ToolResult: {
|
|
|
73
73
|
readonly reason?: string;
|
|
74
74
|
}) => any;
|
|
75
75
|
}>(cases: Cases): (value: {
|
|
76
|
-
readonly _tag: "
|
|
76
|
+
readonly _tag: "Ok";
|
|
77
77
|
readonly call_id: string;
|
|
78
78
|
readonly tool: string;
|
|
79
79
|
readonly value: unknown;
|
|
@@ -83,10 +83,10 @@ declare const ToolResult: {
|
|
|
83
83
|
readonly tool: string;
|
|
84
84
|
readonly kind: string;
|
|
85
85
|
readonly reason?: string;
|
|
86
|
-
}) => _$effect_Unify0.Unify<ReturnType<Cases["
|
|
86
|
+
}) => _$effect_Unify0.Unify<ReturnType<Cases["Ok" | "Failure"]>>;
|
|
87
87
|
<Cases extends {
|
|
88
|
-
readonly
|
|
89
|
-
readonly _tag: "
|
|
88
|
+
readonly Ok: (args: {
|
|
89
|
+
readonly _tag: "Ok";
|
|
90
90
|
readonly call_id: string;
|
|
91
91
|
readonly tool: string;
|
|
92
92
|
readonly value: unknown;
|
|
@@ -99,7 +99,7 @@ declare const ToolResult: {
|
|
|
99
99
|
readonly reason?: string;
|
|
100
100
|
}) => any;
|
|
101
101
|
}>(value: {
|
|
102
|
-
readonly _tag: "
|
|
102
|
+
readonly _tag: "Ok";
|
|
103
103
|
readonly call_id: string;
|
|
104
104
|
readonly tool: string;
|
|
105
105
|
readonly value: unknown;
|
|
@@ -109,11 +109,11 @@ declare const ToolResult: {
|
|
|
109
109
|
readonly tool: string;
|
|
110
110
|
readonly kind: string;
|
|
111
111
|
readonly reason?: string;
|
|
112
|
-
}, cases: Cases): _$effect_Unify0.Unify<ReturnType<Cases["
|
|
112
|
+
}, cases: Cases): _$effect_Unify0.Unify<ReturnType<Cases["Ok" | "Failure"]>>;
|
|
113
113
|
};
|
|
114
114
|
};
|
|
115
|
-
declare const
|
|
116
|
-
readonly _tag: "
|
|
115
|
+
declare const isOk: (u: unknown) => u is {
|
|
116
|
+
readonly _tag: "Ok";
|
|
117
117
|
readonly call_id: string;
|
|
118
118
|
readonly tool: string;
|
|
119
119
|
readonly value: unknown;
|
|
@@ -125,14 +125,14 @@ declare const isFailure: (u: unknown) => u is {
|
|
|
125
125
|
readonly kind: string;
|
|
126
126
|
readonly reason?: string;
|
|
127
127
|
};
|
|
128
|
-
declare const
|
|
128
|
+
declare const failed: (call: ToolCall, kind: string, reason?: string) => ToolResult;
|
|
129
129
|
/** Explicit user/policy rejection. */
|
|
130
|
-
declare const denied: (call:
|
|
130
|
+
declare const denied: (call: ToolCall, reason?: string) => ToolResult;
|
|
131
131
|
/** Implicit non-answer (follow-up, inactivity, abort). */
|
|
132
|
-
declare const cancelled: (call:
|
|
132
|
+
declare const cancelled: (call: ToolCall, reason?: string) => ToolResult;
|
|
133
133
|
/** Tool's own execution failed (parse error, schema, runtime crash). */
|
|
134
|
-
declare const executionError: (call:
|
|
135
|
-
declare const
|
|
134
|
+
declare const executionError: (call: ToolCall, reason: string) => ToolResult;
|
|
135
|
+
declare const toToolCallOutput: (r: ToolResult) => ToolCallOutput;
|
|
136
136
|
//#endregion
|
|
137
|
-
export { ToolResult, cancelled, denied, executionError,
|
|
138
|
-
//# sourceMappingURL=
|
|
137
|
+
export { ToolResult, cancelled, denied, executionError, failed, isFailure, isOk, ToolResult_d_exports as t, toToolCallOutput };
|
|
138
|
+
//# sourceMappingURL=ToolResult.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ToolResult.d.mts","names":[],"sources":["../../src/tool/ToolResult.ts"],"mappings":";;;;;;;;KAqBY,UAAA,GAAa,IAAA,CAAK,UAAA;EAC5B,EAAA;IAAA,SACW,OAAA;IAAA,SACA,IAAA;IAAA,SACA,KAAA;EAAA;EAEX,OAAA;IAAA,SACW,OAAA;IAAA,SACA,IAAA;IAAA,SACA,IAAA;IAAA,SACA,MAAA;EAAA;AAAA;;;;;;AAYb;;;cAAa,UAAA;EAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cAEA,IAAA,GAAI,CAAA,cAAA,CAAA;EAAA;;;;;cACJ,SAAA,GAAS,CAAA,cAAA,CAAA;EAAA;;;;;;cAMT,MAAA,GAAU,IAAA,EAAM,QAAA,EAAU,IAAA,UAAc,MAAA,cAAkB,UAAA;;cAS1D,MAAA,GAAU,IAAA,EAAM,QAAA,EAAU,MAAA,cAAkB,UAAA;;cAI5C,SAAA,GAAa,IAAA,EAAM,QAAA,EAAU,MAAA,cAAkB,UAAA;;cAI/C,cAAA,GAAkB,IAAA,EAAM,QAAA,EAAU,MAAA,aAAiB,UAAA;AAAA,cAOnD,gBAAA,GAAoB,CAAA,EAAG,UAAA,KAAa,cAAA"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { n as __exportAll } from "../chunk-uyGKjUfl.mjs";
|
|
2
|
+
import { toolCallOutput } from "../domain/Items.mjs";
|
|
3
|
+
import { Data } from "effect";
|
|
4
|
+
//#region src/tool/ToolResult.ts
|
|
5
|
+
/**
|
|
6
|
+
* Post-execution and synthetic tool results.
|
|
7
|
+
*
|
|
8
|
+
* - Executed tools emit ToolResult.Ok.
|
|
9
|
+
* - Approval/cancellation policy emits synthetic ToolResult.Failure.
|
|
10
|
+
*
|
|
11
|
+
* Wire conversion stays at the recipe boundary via `toToolCallOutput`
|
|
12
|
+
* so recipes can inspect, redact, or audit values before serialization.
|
|
13
|
+
*
|
|
14
|
+
* `output` and `reason` are `string`, not `unknown`: the wire wants strings,
|
|
15
|
+
* and `unknown` would invite non-serializable values (Date, Map, BigInt,
|
|
16
|
+
* fn). Recipes that want structured detail JSON.stringify themselves.
|
|
17
|
+
*/
|
|
18
|
+
var ToolResult_exports = /* @__PURE__ */ __exportAll({
|
|
19
|
+
ToolResult: () => ToolResult,
|
|
20
|
+
cancelled: () => cancelled,
|
|
21
|
+
denied: () => denied,
|
|
22
|
+
executionError: () => executionError,
|
|
23
|
+
failed: () => failed,
|
|
24
|
+
isFailure: () => isFailure,
|
|
25
|
+
isOk: () => isOk,
|
|
26
|
+
toToolCallOutput: () => toToolCallOutput
|
|
27
|
+
});
|
|
28
|
+
/**
|
|
29
|
+
* Namespace of constructors, type guards, and matchers for `ToolResult`,
|
|
30
|
+
* provided by `Data.taggedEnum`. Use `ToolResult.$is("Ok")` for type
|
|
31
|
+
* narrowing and `ToolResult.$match({ Ok, Failure })` for exhaustive
|
|
32
|
+
* pattern matching. Synthetic-result helpers (`denied`, `cancelled`,
|
|
33
|
+
* `executionError`, `failed`) below are kinder constructors than the
|
|
34
|
+
* raw `ToolResult.Failure(...)`.
|
|
35
|
+
*/
|
|
36
|
+
const ToolResult = Data.taggedEnum();
|
|
37
|
+
const isOk = ToolResult.$is("Ok");
|
|
38
|
+
const isFailure = ToolResult.$is("Failure");
|
|
39
|
+
const failed = (call, kind, reason) => ToolResult.Failure({
|
|
40
|
+
call_id: call.call_id,
|
|
41
|
+
tool: call.name,
|
|
42
|
+
kind,
|
|
43
|
+
...reason !== void 0 ? { reason } : {}
|
|
44
|
+
});
|
|
45
|
+
/** Explicit user/policy rejection. */
|
|
46
|
+
const denied = (call, reason) => failed(call, "denied", reason);
|
|
47
|
+
/** Implicit non-answer (follow-up, inactivity, abort). */
|
|
48
|
+
const cancelled = (call, reason) => failed(call, "cancelled", reason);
|
|
49
|
+
/** Tool's own execution failed (parse error, schema, runtime crash). */
|
|
50
|
+
const executionError = (call, reason) => failed(call, "execution_error", reason);
|
|
51
|
+
const toToolCallOutput = (r) => ToolResult.$match(r, {
|
|
52
|
+
Ok: (v) => toolCallOutput(v.call_id, JSON.stringify(v.value)),
|
|
53
|
+
Failure: (f) => toolCallOutput(f.call_id, JSON.stringify(f.reason !== void 0 ? {
|
|
54
|
+
kind: f.kind,
|
|
55
|
+
reason: f.reason
|
|
56
|
+
} : { kind: f.kind }))
|
|
57
|
+
});
|
|
58
|
+
//#endregion
|
|
59
|
+
export { ToolResult, cancelled, denied, executionError, failed, isFailure, isOk, ToolResult_exports as t, toToolCallOutput };
|
|
60
|
+
|
|
61
|
+
//# sourceMappingURL=ToolResult.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ToolResult.mjs","names":[],"sources":["../../src/tool/ToolResult.ts"],"sourcesContent":["/**\n * Post-execution and synthetic tool results.\n *\n * - Executed tools emit ToolResult.Ok.\n * - Approval/cancellation policy emits synthetic ToolResult.Failure.\n *\n * Wire conversion stays at the recipe boundary via `toToolCallOutput`\n * so recipes can inspect, redact, or audit values before serialization.\n *\n * `output` and `reason` are `string`, not `unknown`: the wire wants strings,\n * and `unknown` would invite non-serializable values (Date, Map, BigInt,\n * fn). Recipes that want structured detail JSON.stringify themselves.\n */\nimport { Data } from \"effect\"\nimport type { ToolCall, ToolCallOutput } from \"../domain/Items.js\"\nimport { toolCallOutput } from \"../domain/Items.js\"\n\n// ---------------------------------------------------------------------------\n// ToolResult\n// ---------------------------------------------------------------------------\n\nexport type ToolResult = Data.TaggedEnum<{\n Ok: {\n readonly call_id: string\n readonly tool: string\n readonly value: unknown\n }\n Failure: {\n readonly call_id: string\n readonly tool: string\n readonly kind: string\n readonly reason?: string\n }\n}>\n\n/**\n * Namespace of constructors, type guards, and matchers for `ToolResult`,\n * provided by `Data.taggedEnum`. Use `ToolResult.$is(\"Ok\")` for type\n * narrowing and `ToolResult.$match({ Ok, Failure })` for exhaustive\n * pattern matching. Synthetic-result helpers (`denied`, `cancelled`,\n * `executionError`, `failed`) below are kinder constructors than the\n * raw `ToolResult.Failure(...)`.\n */\nexport const ToolResult = Data.taggedEnum<ToolResult>()\n\nexport const isOk = ToolResult.$is(\"Ok\")\nexport const isFailure = ToolResult.$is(\"Failure\")\n\n// Synthesizers. `denied` and `cancelled` are operationally distinct;\n// anything else is just a recipe-chosen `kind` via `failed`.\n// ---------------------------------------------------------------------------\n\nexport const failed = (call: ToolCall, kind: string, reason?: string): ToolResult =>\n ToolResult.Failure({\n call_id: call.call_id,\n tool: call.name,\n kind,\n ...(reason !== undefined ? { reason } : {}),\n })\n\n/** Explicit user/policy rejection. */\nexport const denied = (call: ToolCall, reason?: string): ToolResult =>\n failed(call, \"denied\", reason)\n\n/** Implicit non-answer (follow-up, inactivity, abort). */\nexport const cancelled = (call: ToolCall, reason?: string): ToolResult =>\n failed(call, \"cancelled\", reason)\n\n/** Tool's own execution failed (parse error, schema, runtime crash). */\nexport const executionError = (call: ToolCall, reason: string): ToolResult =>\n failed(call, \"execution_error\", reason)\n\n// ---------------------------------------------------------------------------\n// Wire conversion - the one place structured → string happens.\n// ---------------------------------------------------------------------------\n\nexport const toToolCallOutput = (r: ToolResult): ToolCallOutput =>\n ToolResult.$match(r, {\n Ok: (v) => toolCallOutput(v.call_id, JSON.stringify(v.value)),\n Failure: (f) =>\n toolCallOutput(\n f.call_id,\n JSON.stringify(\n f.reason !== undefined ? { kind: f.kind, reason: f.reason } : { kind: f.kind },\n ),\n ),\n })\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2CA,MAAa,aAAa,KAAK,YAAwB;AAEvD,MAAa,OAAO,WAAW,IAAI,KAAK;AACxC,MAAa,YAAY,WAAW,IAAI,UAAU;AAMlD,MAAa,UAAU,MAAgB,MAAc,WACnD,WAAW,QAAQ;CACjB,SAAS,KAAK;CACd,MAAM,KAAK;CACX;CACA,GAAI,WAAW,KAAA,IAAY,EAAE,QAAQ,GAAG,EAAE;CAC3C,CAAC;;AAGJ,MAAa,UAAU,MAAgB,WACrC,OAAO,MAAM,UAAU,OAAO;;AAGhC,MAAa,aAAa,MAAgB,WACxC,OAAO,MAAM,aAAa,OAAO;;AAGnC,MAAa,kBAAkB,MAAgB,WAC7C,OAAO,MAAM,mBAAmB,OAAO;AAMzC,MAAa,oBAAoB,MAC/B,WAAW,OAAO,GAAG;CACnB,KAAK,MAAM,eAAe,EAAE,SAAS,KAAK,UAAU,EAAE,MAAM,CAAC;CAC7D,UAAU,MACR,eACE,EAAE,SACF,KAAK,UACH,EAAE,WAAW,KAAA,IAAY;EAAE,MAAM,EAAE;EAAM,QAAQ,EAAE;EAAQ,GAAG,EAAE,MAAM,EAAE,MAAM,CAC/E,CACF;CACJ,CAAC"}
|
package/dist/tool/Toolkit.d.mts
CHANGED
|
@@ -1,41 +1,73 @@
|
|
|
1
|
-
import { o as
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
1
|
+
import { o as HistoryItem, v as ToolCall } from "../Items-D8UaXQx_.mjs";
|
|
2
|
+
import { Turn } from "../domain/Turn.mjs";
|
|
3
|
+
import { a as Tool, i as StreamingTool, r as AnyTool } from "../Tool-CiFXYjmR.mjs";
|
|
4
|
+
import { Step } from "../loop/Loop.mjs";
|
|
5
|
+
import { ToolResult } from "./ToolResult.mjs";
|
|
5
6
|
import { ToolEvent } from "./ToolEvent.mjs";
|
|
6
|
-
import { Stream } from "effect";
|
|
7
|
+
import { Effect, Stream } from "effect";
|
|
7
8
|
|
|
8
9
|
//#region src/tool/Toolkit.d.ts
|
|
9
10
|
declare namespace Toolkit_d_exports {
|
|
10
|
-
export {
|
|
11
|
+
export { ExecuteOptions, ToolKindR, appendToolResults, collectResults, continueWithResults, run };
|
|
11
12
|
}
|
|
12
|
-
type AnyTool = Tool<string, any, any, any>;
|
|
13
|
-
type Toolkit<Tools extends ReadonlyArray<AnyTool>> = {
|
|
14
|
-
readonly tools: Tools;
|
|
15
|
-
};
|
|
16
|
-
type ToolsR<Tools extends ReadonlyArray<AnyTool>> = Tools[number] extends Tool<any, any, any, infer R> ? R : never;
|
|
17
13
|
/**
|
|
18
14
|
* Union of every tool's `R` requirements in a mixed plain + streaming array.
|
|
19
|
-
* Used by `
|
|
20
|
-
*
|
|
21
|
-
*/
|
|
22
|
-
type ToolKindR<Tools extends ReadonlyArray<AnyKindTool<any>>> = Tools[number] extends StreamingTool<any, any, any, any, infer R> ? R : Tools[number] extends Tool<any, any, any, infer R> ? R : never;
|
|
23
|
-
declare const make: <const Tools extends ReadonlyArray<AnyTool>>(tools: Tools) => Toolkit<Tools>;
|
|
24
|
-
/**
|
|
25
|
-
* Render every tool in a toolkit to a provider-agnostic descriptor.
|
|
26
|
-
* `inputSchema` is the JSON Schema document produced by the tool's
|
|
27
|
-
* Standard Schema converter (draft 2020-12).
|
|
15
|
+
* Used by `run` to surface the services tools need at the recipe level, so
|
|
16
|
+
* the loop's stream type carries them through to `Effect.provide`.
|
|
28
17
|
*/
|
|
29
|
-
|
|
18
|
+
type ToolKindR<Tools extends ReadonlyArray<AnyTool<any>>> = Tools[number] extends StreamingTool<any, any, any, any, infer R> ? R : Tools[number] extends Tool<any, any, any, infer R> ? R : never;
|
|
30
19
|
type ExecuteOptions = {
|
|
31
20
|
readonly concurrency?: number | "unbounded";
|
|
32
21
|
};
|
|
33
22
|
/** Execute every provided call. Approval/rejection policy belongs upstream. */
|
|
34
|
-
declare const
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
23
|
+
declare const run: <Tools extends ReadonlyArray<AnyTool<any>>>(tools: Tools, calls: ReadonlyArray<ToolCall>, options?: ExecuteOptions) => Stream.Stream<ToolEvent, never, ToolKindR<Tools>>;
|
|
24
|
+
/**
|
|
25
|
+
* Append a completed turn plus tool results to a state's history, converting
|
|
26
|
+
* the results to wire-format `ToolCallOutput`s. Curried so it slots directly
|
|
27
|
+
* into `continueWithResults`:
|
|
28
|
+
*
|
|
29
|
+
* Toolkit.run(tools, calls).pipe(
|
|
30
|
+
* Toolkit.continueWithResults(Toolkit.appendToolResults(state, turn)),
|
|
31
|
+
* )
|
|
32
|
+
*
|
|
33
|
+
* Equivalent to `appendToHistory(state, turn, results.map(toToolCallOutput))`
|
|
34
|
+
* — the helper just hides the wire-conversion step.
|
|
35
|
+
*/
|
|
36
|
+
declare const appendToolResults: <S extends {
|
|
37
|
+
readonly history: ReadonlyArray<HistoryItem>;
|
|
38
|
+
}>(state: S, turn: Turn) => (results: ReadonlyArray<ToolResult>) => S;
|
|
39
|
+
/**
|
|
40
|
+
* Drain a `Stream<ToolEvent>` and return the accumulated `ToolResult`s
|
|
41
|
+
* from every `Output` event. One-shot — the type is `Effect<results>`,
|
|
42
|
+
* not a one-element stream — so it composes naturally with `Effect.map`
|
|
43
|
+
* to build state.
|
|
44
|
+
*
|
|
45
|
+
* Counterpart to `continueWithResults`: `continueWithResults` bundles
|
|
46
|
+
* drain + emit Next into one bridge; this one is the right arm of a
|
|
47
|
+
* broadcast/fork-and-merge for callers that want to vary the left arm
|
|
48
|
+
* (e.g., filter/tap ToolEvents before forwarding).
|
|
49
|
+
*/
|
|
50
|
+
declare const collectResults: <E, R>(stream: Stream.Stream<ToolEvent, E, R>) => Effect.Effect<ReadonlyArray<ToolResult>, E, R>;
|
|
51
|
+
/**
|
|
52
|
+
* Bridge from a `Stream<ToolEvent>` to the loop's emit shape. Forwards
|
|
53
|
+
* every ToolEvent downstream as a `Loop.value` and at end-of-stream emits
|
|
54
|
+
* one `Loop.next(build(results))` carrying the accumulated `ToolResult`s
|
|
55
|
+
* from terminal `Output` events.
|
|
56
|
+
*
|
|
57
|
+
* Conceptually a broadcast fork (one arm passes events through, the other
|
|
58
|
+
* drains them into a state). Implemented as a single-pass Ref tap + concat
|
|
59
|
+
* for zero buffering — the broadcast version is observationally equivalent
|
|
60
|
+
* but holds events in a PubSub until both arms drain. The public primitives
|
|
61
|
+
* (`Loop.value`, `collectResults`, `Loop.next`) compose the same pattern
|
|
62
|
+
* when you need to vary an arm.
|
|
63
|
+
*
|
|
64
|
+
* Dual: data-first `continueWithResults(stream, build)` and data-last
|
|
65
|
+
* `stream.pipe(continueWithResults(build))` both work.
|
|
66
|
+
*/
|
|
67
|
+
declare const continueWithResults: {
|
|
68
|
+
<S>(build: (results: ReadonlyArray<ToolResult>) => S): <R>(stream: Stream.Stream<ToolEvent, never, R>) => Stream.Stream<Step<ToolEvent, S>, never, R>;
|
|
69
|
+
<S, R>(stream: Stream.Stream<ToolEvent, never, R>, build: (results: ReadonlyArray<ToolResult>) => S): Stream.Stream<Step<ToolEvent, S>, never, R>;
|
|
38
70
|
};
|
|
39
71
|
//#endregion
|
|
40
|
-
export {
|
|
72
|
+
export { ExecuteOptions, ToolKindR, appendToolResults, collectResults, continueWithResults, run, Toolkit_d_exports as t };
|
|
41
73
|
//# sourceMappingURL=Toolkit.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Toolkit.d.mts","names":[],"sources":["../../src/tool/Toolkit.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"Toolkit.d.mts","names":[],"sources":["../../src/tool/Toolkit.ts"],"mappings":";;;;;;;;;;;;;;;;;KAqBY,SAAA,eAAwB,aAAA,CAAc,OAAA,UAChD,KAAA,iBAAsB,aAAA,gCAClB,CAAA,GACA,KAAA,iBAAsB,IAAA,2BACpB,CAAA;AAAA,KASI,cAAA;EAAA,SACD,WAAA;AAAA;;cAIE,GAAA,iBAAqB,aAAA,CAAc,OAAA,QAC9C,KAAA,EAAO,KAAA,EACP,KAAA,EAAO,aAAA,CAAc,QAAA,GACrB,OAAA,GAAU,cAAA,KACT,MAAA,CAAO,MAAA,CAAO,SAAA,SAAkB,SAAA,CAAU,KAAA;AAtB7C;;;;;;;;;;;;AAAA,cA2Ja,iBAAA;EAAA,SACW,OAAA,EAAS,aAAA,CAAc,WAAA;AAAA,GAAgB,KAAA,EAAO,CAAA,EAAG,IAAA,EAAM,IAAA,MAC5E,OAAA,EAAS,aAAA,CAAc,UAAA,MAAc,CAAA;;;;;;;;;;AAhJxC;;cA8Ja,cAAA,SACX,MAAA,EAAQ,MAAA,CAAO,MAAA,CAAO,SAAA,EAAW,CAAA,EAAG,CAAA,MACnC,MAAA,CAAO,MAAA,CAAO,aAAA,CAAc,UAAA,GAAa,CAAA,EAAG,CAAA;;;AA3J/C;;;;;;;;;;;;;;cAkLa,mBAAA;EAAA,IAET,KAAA,GAAQ,OAAA,EAAS,aAAA,CAAc,UAAA,MAAgB,CAAA,OAE/C,MAAA,EAAQ,MAAA,CAAO,MAAA,CAAO,SAAA,SAAkB,CAAA,MACrC,MAAA,CAAO,MAAA,CAAO,IAAA,CAAU,SAAA,EAAW,CAAA,UAAW,CAAA;EAAA,OAEjD,MAAA,EAAQ,MAAA,CAAO,MAAA,CAAO,SAAA,SAAkB,CAAA,GACxC,KAAA,GAAQ,OAAA,EAAS,aAAA,CAAc,UAAA,MAAgB,CAAA,GAC9C,MAAA,CAAO,MAAA,CAAO,IAAA,CAAU,SAAA,EAAW,CAAA,UAAW,CAAA;AAAA"}
|
package/dist/tool/Toolkit.mjs
CHANGED
|
@@ -1,45 +1,27 @@
|
|
|
1
1
|
import { n as __exportAll } from "../chunk-uyGKjUfl.mjs";
|
|
2
|
-
import {
|
|
2
|
+
import { appendToHistory } from "../domain/Turn.mjs";
|
|
3
|
+
import { next, value } from "../loop/Loop.mjs";
|
|
3
4
|
import { isStreamingTool } from "./Tool.mjs";
|
|
4
|
-
import { ToolResult, executionError,
|
|
5
|
+
import { ToolResult, executionError, failed, toToolCallOutput } from "./ToolResult.mjs";
|
|
5
6
|
import { ToolEvent, isOutput } from "./ToolEvent.mjs";
|
|
6
7
|
import { Array, Effect, Function, Ref, Schema, Stream } from "effect";
|
|
7
8
|
//#region src/tool/Toolkit.ts
|
|
8
9
|
var Toolkit_exports = /* @__PURE__ */ __exportAll({
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
});
|
|
14
|
-
const make = (tools) => ({ tools });
|
|
15
|
-
/**
|
|
16
|
-
* Render every tool in a toolkit to a provider-agnostic descriptor.
|
|
17
|
-
* `inputSchema` is the JSON Schema document produced by the tool's
|
|
18
|
-
* Standard Schema converter (draft 2020-12).
|
|
19
|
-
*/
|
|
20
|
-
const toDescriptors = (toolkit) => toolkit.tools.map((tool) => {
|
|
21
|
-
const inputSchema = tool.inputSchema["~standard"].jsonSchema.input({ target: "draft-2020-12" });
|
|
22
|
-
return tool.strict !== void 0 ? {
|
|
23
|
-
name: tool.name,
|
|
24
|
-
description: tool.description,
|
|
25
|
-
inputSchema,
|
|
26
|
-
strict: tool.strict
|
|
27
|
-
} : {
|
|
28
|
-
name: tool.name,
|
|
29
|
-
description: tool.description,
|
|
30
|
-
inputSchema
|
|
31
|
-
};
|
|
10
|
+
appendToolResults: () => appendToolResults,
|
|
11
|
+
collectResults: () => collectResults,
|
|
12
|
+
continueWithResults: () => continueWithResults,
|
|
13
|
+
run: () => run
|
|
32
14
|
});
|
|
33
15
|
/** Execute every provided call. Approval/rejection policy belongs upstream. */
|
|
34
|
-
const
|
|
35
|
-
const
|
|
16
|
+
const run = (tools, calls, options) => Stream.fromIterable(calls).pipe(Stream.flatMap((call) => runOne(tools, call), { concurrency: options?.concurrency ?? "unbounded" }));
|
|
17
|
+
const okResult = (call, tool, value) => ToolResult.Ok({
|
|
36
18
|
call_id: call.call_id,
|
|
37
19
|
tool,
|
|
38
20
|
value
|
|
39
21
|
});
|
|
40
22
|
const runOne = (tools, call) => {
|
|
41
23
|
const tool = tools.find((t) => t.name === call.name);
|
|
42
|
-
if (tool === void 0) return Stream.succeed(ToolEvent.Output({ result:
|
|
24
|
+
if (tool === void 0) return Stream.succeed(ToolEvent.Output({ result: failed(call, "unknown_tool", `No tool registered with name "${call.name}"`) }));
|
|
43
25
|
if (isStreamingTool(tool)) return runStreaming(tool, call);
|
|
44
26
|
return runPlain(tool, call);
|
|
45
27
|
};
|
|
@@ -52,7 +34,7 @@ const runPlain = (tool, call) => Stream.fromEffect(Effect.gen(function* () {
|
|
|
52
34
|
});
|
|
53
35
|
if (validated.issues !== void 0) return executionError(call, "Tool input failed schema validation");
|
|
54
36
|
const output = yield* tool.run(validated.value);
|
|
55
|
-
return
|
|
37
|
+
return okResult(call, tool.name, output);
|
|
56
38
|
}).pipe(Effect.catchCause(() => Effect.succeed(executionError(call, "Tool execution failed"))), Effect.map((result) => ToolEvent.Output({ result }))));
|
|
57
39
|
const runStreaming = (tool, call) => Stream.unwrap(Effect.gen(function* () {
|
|
58
40
|
const parsed = yield* parseJsonUnknown(call.arguments).pipe(Effect.mapError(() => "json_parse_error"));
|
|
@@ -62,16 +44,62 @@ const runStreaming = (tool, call) => Stream.unwrap(Effect.gen(function* () {
|
|
|
62
44
|
});
|
|
63
45
|
if (validated.issues !== void 0) return Stream.succeed(ToolEvent.Output({ result: executionError(call, "Tool input failed schema validation") }));
|
|
64
46
|
const ref = yield* Ref.make([]);
|
|
65
|
-
const
|
|
47
|
+
const progress = tool.run(validated.value).pipe(Stream.tap((event) => Ref.update(ref, Array.append(event))), Stream.map((data) => ToolEvent.Progress({
|
|
66
48
|
call_id: call.call_id,
|
|
67
49
|
tool: tool.name,
|
|
68
50
|
data
|
|
69
51
|
})));
|
|
70
|
-
const output = Stream.fromEffect(Ref.get(ref).pipe(Effect.map((events) => ToolEvent.Output({ result:
|
|
71
|
-
return
|
|
52
|
+
const output = Stream.fromEffect(Ref.get(ref).pipe(Effect.map((events) => ToolEvent.Output({ result: okResult(call, tool.name, tool.finalize(events)) }))));
|
|
53
|
+
return progress.pipe(Stream.concat(output));
|
|
72
54
|
})).pipe(Stream.catchCause(() => Stream.succeed(ToolEvent.Output({ result: executionError(call, "Tool execution failed") }))));
|
|
73
|
-
|
|
55
|
+
/**
|
|
56
|
+
* Append a completed turn plus tool results to a state's history, converting
|
|
57
|
+
* the results to wire-format `ToolCallOutput`s. Curried so it slots directly
|
|
58
|
+
* into `continueWithResults`:
|
|
59
|
+
*
|
|
60
|
+
* Toolkit.run(tools, calls).pipe(
|
|
61
|
+
* Toolkit.continueWithResults(Toolkit.appendToolResults(state, turn)),
|
|
62
|
+
* )
|
|
63
|
+
*
|
|
64
|
+
* Equivalent to `appendToHistory(state, turn, results.map(toToolCallOutput))`
|
|
65
|
+
* — the helper just hides the wire-conversion step.
|
|
66
|
+
*/
|
|
67
|
+
const appendToolResults = (state, turn) => (results) => appendToHistory(state, turn, results.map(toToolCallOutput));
|
|
68
|
+
/**
|
|
69
|
+
* Drain a `Stream<ToolEvent>` and return the accumulated `ToolResult`s
|
|
70
|
+
* from every `Output` event. One-shot — the type is `Effect<results>`,
|
|
71
|
+
* not a one-element stream — so it composes naturally with `Effect.map`
|
|
72
|
+
* to build state.
|
|
73
|
+
*
|
|
74
|
+
* Counterpart to `continueWithResults`: `continueWithResults` bundles
|
|
75
|
+
* drain + emit Next into one bridge; this one is the right arm of a
|
|
76
|
+
* broadcast/fork-and-merge for callers that want to vary the left arm
|
|
77
|
+
* (e.g., filter/tap ToolEvents before forwarding).
|
|
78
|
+
*/
|
|
79
|
+
const collectResults = (stream) => stream.pipe(Stream.filter(isOutput), Stream.map((e) => e.result), Stream.runCollect);
|
|
80
|
+
/**
|
|
81
|
+
* Bridge from a `Stream<ToolEvent>` to the loop's emit shape. Forwards
|
|
82
|
+
* every ToolEvent downstream as a `Loop.value` and at end-of-stream emits
|
|
83
|
+
* one `Loop.next(build(results))` carrying the accumulated `ToolResult`s
|
|
84
|
+
* from terminal `Output` events.
|
|
85
|
+
*
|
|
86
|
+
* Conceptually a broadcast fork (one arm passes events through, the other
|
|
87
|
+
* drains them into a state). Implemented as a single-pass Ref tap + concat
|
|
88
|
+
* for zero buffering — the broadcast version is observationally equivalent
|
|
89
|
+
* but holds events in a PubSub until both arms drain. The public primitives
|
|
90
|
+
* (`Loop.value`, `collectResults`, `Loop.next`) compose the same pattern
|
|
91
|
+
* when you need to vary an arm.
|
|
92
|
+
*
|
|
93
|
+
* Dual: data-first `continueWithResults(stream, build)` and data-last
|
|
94
|
+
* `stream.pipe(continueWithResults(build))` both work.
|
|
95
|
+
*/
|
|
96
|
+
const continueWithResults = Function.dual(2, (stream, build) => Stream.unwrap(Effect.gen(function* () {
|
|
97
|
+
const ref = yield* Ref.make([]);
|
|
98
|
+
const tapped = stream.pipe(Stream.tap((e) => isOutput(e) ? Ref.update(ref, (acc) => Array.append(acc, e.result)) : Effect.void), Stream.map(value));
|
|
99
|
+
const continuation = Stream.unwrap(Ref.get(ref).pipe(Effect.map((acc) => next(build(acc)))));
|
|
100
|
+
return tapped.pipe(Stream.concat(continuation));
|
|
101
|
+
})));
|
|
74
102
|
//#endregion
|
|
75
|
-
export {
|
|
103
|
+
export { appendToolResults, collectResults, continueWithResults, run, Toolkit_exports as t };
|
|
76
104
|
|
|
77
105
|
//# sourceMappingURL=Toolkit.mjs.map
|