clanka 0.0.17 → 0.0.18
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.
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @since 1.0.0
|
|
3
3
|
*/
|
|
4
|
-
import { Stream } from "effect";
|
|
5
|
-
import { type Output, AgentFinished } from "./Agent.ts";
|
|
4
|
+
import { Effect, Layer, ServiceMap, Stream } from "effect";
|
|
5
|
+
import { type Agent, type Output, AgentFinished } from "./Agent.ts";
|
|
6
6
|
/**
|
|
7
7
|
* @since 1.0.0
|
|
8
8
|
* @category Models
|
|
@@ -13,4 +13,20 @@ export type OutputFormatter = <E, R>(stream: Stream.Stream<Output, AgentFinished
|
|
|
13
13
|
* @category Pretty
|
|
14
14
|
*/
|
|
15
15
|
export declare const pretty: OutputFormatter;
|
|
16
|
+
declare const Muxer_base: ServiceMap.ServiceClass<Muxer, "clanka/OutputFormatter/Muxer", {
|
|
17
|
+
add(agent: Agent): Effect.Effect<void>;
|
|
18
|
+
readonly output: Stream.Stream<string>;
|
|
19
|
+
}>;
|
|
20
|
+
/**
|
|
21
|
+
* @since 1.0.0
|
|
22
|
+
* @category Muxer
|
|
23
|
+
*/
|
|
24
|
+
export declare class Muxer extends Muxer_base {
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* @since 1.0.0
|
|
28
|
+
* @category Muxer
|
|
29
|
+
*/
|
|
30
|
+
export declare const layerMuxer: (formatter: OutputFormatter) => Layer.Layer<Muxer, never, never>;
|
|
31
|
+
export {};
|
|
16
32
|
//# sourceMappingURL=OutputFormatter.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OutputFormatter.d.ts","sourceRoot":"","sources":["../src/OutputFormatter.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;
|
|
1
|
+
{"version":3,"file":"OutputFormatter.d.ts","sourceRoot":"","sources":["../src/OutputFormatter.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EAAE,MAAM,EAAE,KAAK,EAAqB,UAAU,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAC7E,OAAO,EAAE,KAAK,KAAK,EAAE,KAAK,MAAM,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;AAGnE;;;GAGG;AACH,MAAM,MAAM,eAAe,GAAG,CAAC,CAAC,EAAE,CAAC,EACjC,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,aAAa,GAAG,CAAC,EAAE,CAAC,CAAC,KAChD,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,EAAE,aAAa,CAAC,EAAE,CAAC,CAAC,CAAA;AAExD;;;GAGG;AACH,eAAO,MAAM,MAAM,EAAE,eAsDlB,CAAA;;eAkBY,KAAK,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC;qBACrB,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC;;AAR1C;;;GAGG;AACH,qBAAa,KAAM,SAAQ,UAMQ;CAAG;AAEtC;;;GAGG;AACH,eAAO,MAAM,UAAU,GAAI,WAAW,eAAe,qCAmDlD,CAAA"}
|
package/dist/OutputFormatter.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @since 1.0.0
|
|
3
3
|
*/
|
|
4
|
-
import { Stream } from "effect";
|
|
4
|
+
import { Effect, Layer, PubSub, Semaphore, ServiceMap, Stream } from "effect";
|
|
5
5
|
import { AgentFinished } from "./Agent.js";
|
|
6
6
|
import chalk from "chalk";
|
|
7
7
|
/**
|
|
@@ -59,4 +59,53 @@ const scriptIcon = "\u{f0bc1}";
|
|
|
59
59
|
const subagentIcon = "\u{ee0d} ";
|
|
60
60
|
const thinkingIcon = "\u{f07f6}";
|
|
61
61
|
const doneIcon = "\u{eab2}";
|
|
62
|
+
/**
|
|
63
|
+
* @since 1.0.0
|
|
64
|
+
* @category Muxer
|
|
65
|
+
*/
|
|
66
|
+
export class Muxer extends ServiceMap.Service()("clanka/OutputFormatter/Muxer") {
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* @since 1.0.0
|
|
70
|
+
* @category Muxer
|
|
71
|
+
*/
|
|
72
|
+
export const layerMuxer = (formatter) => Layer.effect(Muxer, Effect.gen(function* () {
|
|
73
|
+
const scope = yield* Effect.scope;
|
|
74
|
+
const output = yield* PubSub.unbounded();
|
|
75
|
+
let agentCount = 0;
|
|
76
|
+
let currentAgentId = null;
|
|
77
|
+
const semaphore = Semaphore.makeUnsafe(1);
|
|
78
|
+
return Muxer.of({
|
|
79
|
+
add(agent) {
|
|
80
|
+
const id = ++agentCount;
|
|
81
|
+
return agent.output.pipe(Stream.tap(Effect.fnUntraced(function* (part_) {
|
|
82
|
+
if (currentAgentId === null || id !== currentAgentId) {
|
|
83
|
+
yield* semaphore.take(1);
|
|
84
|
+
}
|
|
85
|
+
const part = part_._tag === "SubagentPart" ? part_.part : part_;
|
|
86
|
+
switch (part._tag) {
|
|
87
|
+
case "ReasoningStart":
|
|
88
|
+
case "ScriptStart": {
|
|
89
|
+
currentAgentId = id;
|
|
90
|
+
break;
|
|
91
|
+
}
|
|
92
|
+
case "ReasoningEnd":
|
|
93
|
+
case "ScriptEnd": {
|
|
94
|
+
currentAgentId = null;
|
|
95
|
+
break;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
if (id !== currentAgentId) {
|
|
99
|
+
yield* semaphore.release(1);
|
|
100
|
+
}
|
|
101
|
+
})), formatter, Stream.runIntoPubSub(output), Effect.onExit(() => {
|
|
102
|
+
if (currentAgentId !== id)
|
|
103
|
+
return Effect.void;
|
|
104
|
+
currentAgentId = null;
|
|
105
|
+
return semaphore.release(1);
|
|
106
|
+
}), Effect.forkIn(scope), Effect.asVoid);
|
|
107
|
+
},
|
|
108
|
+
output: Stream.fromPubSub(output),
|
|
109
|
+
});
|
|
110
|
+
}));
|
|
62
111
|
//# sourceMappingURL=OutputFormatter.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OutputFormatter.js","sourceRoot":"","sources":["../src/OutputFormatter.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;
|
|
1
|
+
{"version":3,"file":"OutputFormatter.js","sourceRoot":"","sources":["../src/OutputFormatter.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAC7E,OAAO,EAA2B,aAAa,EAAE,MAAM,YAAY,CAAA;AACnE,OAAO,KAAK,MAAM,OAAO,CAAA;AAUzB;;;GAGG;AACH,MAAM,CAAC,MAAM,MAAM,GAAoB,CAAC,MAAM,EAAE,EAAE,CAChD,MAAM,CAAC,IAAI,CACT,MAAM,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE;IACpB,IAAI,MAAM,GAAG,EAAE,CAAA;IACf,IAAI,MAAM,CAAC,IAAI,KAAK,cAAc,EAAE,CAAC;QACnC,MAAM,GAAG,KAAK,CAAC,OAAO,CAAC,aAAa,MAAM,CAAC,EAAE,GAAG,CAAC,GAAG,GAAG,CAAA;QACvD,MAAM,GAAG,MAAM,CAAC,IAAI,CAAA;IACtB,CAAC;IACD,QAAQ,MAAM,CAAC,IAAI,EAAE,CAAC;QACpB,KAAK,eAAe,CAAC,CAAC,CAAC;YACrB,OAAO,GAAG,oBAAoB,CAAC,GAAG,YAAY,cAAc,MAAM,CAAC,EAAE,cAAc,MAAM,CAAC,gBAAgB,GAAG,CAAC;;EAEtH,KAAK,CAAC,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAA;QACxB,CAAC;QACD,KAAK,kBAAkB,CAAC,CAAC,CAAC;YACxB,OAAO,GAAG,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json
CHANGED
package/src/OutputFormatter.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @since 1.0.0
|
|
3
3
|
*/
|
|
4
|
-
import { Stream } from "effect"
|
|
5
|
-
import { type Output, AgentFinished } from "./Agent.ts"
|
|
4
|
+
import { Effect, Layer, PubSub, Semaphore, ServiceMap, Stream } from "effect"
|
|
5
|
+
import { type Agent, type Output, AgentFinished } from "./Agent.ts"
|
|
6
6
|
import chalk from "chalk"
|
|
7
7
|
|
|
8
8
|
/**
|
|
@@ -81,3 +81,72 @@ const scriptIcon = "\u{f0bc1}"
|
|
|
81
81
|
const subagentIcon = "\u{ee0d} "
|
|
82
82
|
const thinkingIcon = "\u{f07f6}"
|
|
83
83
|
const doneIcon = "\u{eab2}"
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* @since 1.0.0
|
|
87
|
+
* @category Muxer
|
|
88
|
+
*/
|
|
89
|
+
export class Muxer extends ServiceMap.Service<
|
|
90
|
+
Muxer,
|
|
91
|
+
{
|
|
92
|
+
add(agent: Agent): Effect.Effect<void>
|
|
93
|
+
readonly output: Stream.Stream<string>
|
|
94
|
+
}
|
|
95
|
+
>()("clanka/OutputFormatter/Muxer") {}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* @since 1.0.0
|
|
99
|
+
* @category Muxer
|
|
100
|
+
*/
|
|
101
|
+
export const layerMuxer = (formatter: OutputFormatter) =>
|
|
102
|
+
Layer.effect(
|
|
103
|
+
Muxer,
|
|
104
|
+
Effect.gen(function* () {
|
|
105
|
+
const scope = yield* Effect.scope
|
|
106
|
+
const output = yield* PubSub.unbounded<string>()
|
|
107
|
+
let agentCount = 0
|
|
108
|
+
let currentAgentId: number | null = null
|
|
109
|
+
const semaphore = Semaphore.makeUnsafe(1)
|
|
110
|
+
|
|
111
|
+
return Muxer.of({
|
|
112
|
+
add(agent) {
|
|
113
|
+
const id = ++agentCount
|
|
114
|
+
return agent.output.pipe(
|
|
115
|
+
Stream.tap(
|
|
116
|
+
Effect.fnUntraced(function* (part_) {
|
|
117
|
+
if (currentAgentId === null || id !== currentAgentId) {
|
|
118
|
+
yield* semaphore.take(1)
|
|
119
|
+
}
|
|
120
|
+
const part = part_._tag === "SubagentPart" ? part_.part : part_
|
|
121
|
+
switch (part._tag) {
|
|
122
|
+
case "ReasoningStart":
|
|
123
|
+
case "ScriptStart": {
|
|
124
|
+
currentAgentId = id
|
|
125
|
+
break
|
|
126
|
+
}
|
|
127
|
+
case "ReasoningEnd":
|
|
128
|
+
case "ScriptEnd": {
|
|
129
|
+
currentAgentId = null
|
|
130
|
+
break
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
if (id !== currentAgentId) {
|
|
134
|
+
yield* semaphore.release(1)
|
|
135
|
+
}
|
|
136
|
+
}),
|
|
137
|
+
),
|
|
138
|
+
formatter,
|
|
139
|
+
Stream.runIntoPubSub(output),
|
|
140
|
+
Effect.onExit(() => {
|
|
141
|
+
if (currentAgentId !== id) return Effect.void
|
|
142
|
+
currentAgentId = null
|
|
143
|
+
return semaphore.release(1)
|
|
144
|
+
}),
|
|
145
|
+
Effect.forkIn(scope),
|
|
146
|
+
Effect.asVoid,
|
|
147
|
+
)
|
|
148
|
+
},
|
|
149
|
+
output: Stream.fromPubSub(output),
|
|
150
|
+
})
|
|
151
|
+
}),
|
|
152
|
+
)
|