@batonfx/foldkit 0.1.1 → 0.2.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/.turbo/turbo-build.log +2 -2
- package/dist/index.js +452 -23
- package/package.json +2 -2
- package/src/chat.ts +264 -25
- package/test/chat.scene.test.ts +152 -0
- package/test/chat.story.test.ts +110 -0
- package/test/chat.test.ts +13 -5
package/.turbo/turbo-build.log
CHANGED
package/dist/index.js
CHANGED
|
@@ -18,12 +18,21 @@ var __export = (target, all) => {
|
|
|
18
18
|
var exports_chat = {};
|
|
19
19
|
__export(exports_chat, {
|
|
20
20
|
update: () => update3,
|
|
21
|
+
toolStatusOf: () => toolStatusOf,
|
|
21
22
|
subscriptions: () => subscriptions,
|
|
23
|
+
promptInputStatusOf: () => promptInputStatusOf,
|
|
22
24
|
initialModel: () => initialModel,
|
|
25
|
+
conversationItems: () => conversationItems,
|
|
26
|
+
WaitingConversationItem: () => WaitingConversationItem,
|
|
23
27
|
UserEntry: () => UserEntry,
|
|
28
|
+
UserConversationItem: () => UserConversationItem,
|
|
29
|
+
ToolStatus: () => ToolStatus,
|
|
30
|
+
ToolPendingPhase: () => ToolPendingPhase,
|
|
24
31
|
ToolOutcome: () => ToolOutcome,
|
|
25
32
|
ToolEntry: () => ToolEntry,
|
|
33
|
+
ToolConversationItem: () => ToolConversationItem,
|
|
26
34
|
SubmittedMessage: () => SubmittedMessage,
|
|
35
|
+
StreamingConversationItem: () => StreamingConversationItem,
|
|
27
36
|
SentUserMessage: () => SentUserMessage,
|
|
28
37
|
SendUserMessage: () => SendUserMessage,
|
|
29
38
|
Running: () => Running,
|
|
@@ -33,12 +42,17 @@ __export(exports_chat, {
|
|
|
33
42
|
ResolvedApproval: () => ResolvedApproval,
|
|
34
43
|
ResolveApproval: () => ResolveApproval,
|
|
35
44
|
ReceivedAgent: () => ReceivedAgent,
|
|
45
|
+
PromptInputStatus: () => PromptInputStatus,
|
|
36
46
|
OutMessage: () => OutMessage,
|
|
47
|
+
OpenedSession: () => OpenedSession,
|
|
37
48
|
Model: () => Model,
|
|
49
|
+
MessageAlign: () => MessageAlign,
|
|
38
50
|
Message: () => Message2,
|
|
39
51
|
Idle: () => Idle,
|
|
52
|
+
FailureConversationItem: () => FailureConversationItem,
|
|
40
53
|
FailedAgentCommand: () => FailedAgentCommand,
|
|
41
54
|
Failed: () => Failed,
|
|
55
|
+
ConversationItem: () => ConversationItem,
|
|
42
56
|
ClickedDeny: () => ClickedDeny,
|
|
43
57
|
ClickedCancel: () => ClickedCancel,
|
|
44
58
|
ClickedApprove: () => ClickedApprove,
|
|
@@ -48,7 +62,9 @@ __export(exports_chat, {
|
|
|
48
62
|
CancelRun: () => CancelRun,
|
|
49
63
|
AwaitingApproval: () => AwaitingApproval,
|
|
50
64
|
AssistantEntry: () => AssistantEntry,
|
|
51
|
-
|
|
65
|
+
AssistantConversationItem: () => AssistantConversationItem,
|
|
66
|
+
ApprovalRequired: () => ApprovalRequired,
|
|
67
|
+
ApprovalConversationItem: () => ApprovalConversationItem
|
|
52
68
|
});
|
|
53
69
|
// ../../node_modules/.bun/effect@4.0.0-beta.93/node_modules/effect/dist/Array.js
|
|
54
70
|
var exports_Array = {};
|
|
@@ -11990,6 +12006,7 @@ function resolveAt(key) {
|
|
|
11990
12006
|
}
|
|
11991
12007
|
var resolveIdentifier = /* @__PURE__ */ resolveAt("identifier");
|
|
11992
12008
|
var resolveTitle = /* @__PURE__ */ resolveAt("title");
|
|
12009
|
+
var resolveDescription = /* @__PURE__ */ resolveAt("description");
|
|
11993
12010
|
var resolveBrands = /* @__PURE__ */ resolveAt("brands");
|
|
11994
12011
|
var getExpected = /* @__PURE__ */ memoize((ast) => {
|
|
11995
12012
|
const identifier2 = resolveIdentifier(ast);
|
|
@@ -14563,6 +14580,7 @@ function runChecks(checks, s) {
|
|
|
14563
14580
|
var ClassTypeId = "~effect/Schema/Class";
|
|
14564
14581
|
var STRUCTURAL_ANNOTATION_KEY = "~structural";
|
|
14565
14582
|
var resolveIdentifier2 = resolveIdentifier;
|
|
14583
|
+
var resolveDescription2 = resolveDescription;
|
|
14566
14584
|
function isJson(u) {
|
|
14567
14585
|
const onPath = new Set;
|
|
14568
14586
|
const validated = new Set;
|
|
@@ -38588,6 +38606,275 @@ var merge7 = (...toolkits) => {
|
|
|
38588
38606
|
}
|
|
38589
38607
|
return makeProto2(tools);
|
|
38590
38608
|
};
|
|
38609
|
+
// ../../node_modules/.bun/effect@4.0.0-beta.93/node_modules/effect/dist/unstable/ai/Tool.js
|
|
38610
|
+
var exports_Tool = {};
|
|
38611
|
+
__export(exports_Tool, {
|
|
38612
|
+
unsafeSecureJsonParse: () => unsafeSecureJsonParse,
|
|
38613
|
+
providerDefined: () => providerDefined,
|
|
38614
|
+
make: () => make45,
|
|
38615
|
+
isUserDefined: () => isUserDefined,
|
|
38616
|
+
isProviderDefined: () => isProviderDefined,
|
|
38617
|
+
isEmptyParamsRecord: () => isEmptyParamsRecord,
|
|
38618
|
+
isDynamic: () => isDynamic,
|
|
38619
|
+
getStrictMode: () => getStrictMode,
|
|
38620
|
+
getJsonSchemaFromSchema: () => getJsonSchemaFromSchema,
|
|
38621
|
+
getJsonSchema: () => getJsonSchema,
|
|
38622
|
+
getDescription: () => getDescription,
|
|
38623
|
+
dynamic: () => dynamic,
|
|
38624
|
+
TypeId: () => TypeId49,
|
|
38625
|
+
Title: () => Title,
|
|
38626
|
+
Strict: () => Strict,
|
|
38627
|
+
Readonly: () => Readonly,
|
|
38628
|
+
ProviderDefinedTypeId: () => ProviderDefinedTypeId,
|
|
38629
|
+
OpenWorld: () => OpenWorld,
|
|
38630
|
+
NameMapper: () => NameMapper,
|
|
38631
|
+
Meta: () => Meta,
|
|
38632
|
+
Idempotent: () => Idempotent,
|
|
38633
|
+
EmptyParams: () => EmptyParams,
|
|
38634
|
+
DynamicTypeId: () => DynamicTypeId,
|
|
38635
|
+
Destructive: () => Destructive
|
|
38636
|
+
});
|
|
38637
|
+
var TypeId49 = "~effect/ai/Tool";
|
|
38638
|
+
var ProviderDefinedTypeId = "~effect/ai/Tool/ProviderDefined";
|
|
38639
|
+
var DynamicTypeId = "~effect/ai/Tool/Dynamic";
|
|
38640
|
+
var isUserDefined = (u) => hasProperty(u, TypeId49) && !isProviderDefined(u) && !isDynamic(u);
|
|
38641
|
+
var isProviderDefined = (u) => hasProperty(u, ProviderDefinedTypeId);
|
|
38642
|
+
var isDynamic = (u) => hasProperty(u, DynamicTypeId);
|
|
38643
|
+
var Proto14 = {
|
|
38644
|
+
[TypeId49]: {
|
|
38645
|
+
_Requirements: identity
|
|
38646
|
+
},
|
|
38647
|
+
pipe() {
|
|
38648
|
+
return pipeArguments(this, arguments);
|
|
38649
|
+
},
|
|
38650
|
+
addDependency() {
|
|
38651
|
+
return userDefinedProto({
|
|
38652
|
+
...this
|
|
38653
|
+
});
|
|
38654
|
+
},
|
|
38655
|
+
setParameters(parametersSchema) {
|
|
38656
|
+
return userDefinedProto({
|
|
38657
|
+
...this,
|
|
38658
|
+
parametersSchema
|
|
38659
|
+
});
|
|
38660
|
+
},
|
|
38661
|
+
setSuccess(successSchema) {
|
|
38662
|
+
return userDefinedProto({
|
|
38663
|
+
...this,
|
|
38664
|
+
successSchema
|
|
38665
|
+
});
|
|
38666
|
+
},
|
|
38667
|
+
setFailure(failureSchema) {
|
|
38668
|
+
return userDefinedProto({
|
|
38669
|
+
...this,
|
|
38670
|
+
failureSchema
|
|
38671
|
+
});
|
|
38672
|
+
},
|
|
38673
|
+
annotate(tag2, value3) {
|
|
38674
|
+
return userDefinedProto({
|
|
38675
|
+
...this,
|
|
38676
|
+
annotations: add(this.annotations, tag2, value3)
|
|
38677
|
+
});
|
|
38678
|
+
},
|
|
38679
|
+
annotateMerge(context4) {
|
|
38680
|
+
return userDefinedProto({
|
|
38681
|
+
...this,
|
|
38682
|
+
annotations: merge2(this.annotations, context4)
|
|
38683
|
+
});
|
|
38684
|
+
}
|
|
38685
|
+
};
|
|
38686
|
+
var ProviderDefinedProto = {
|
|
38687
|
+
...Proto14,
|
|
38688
|
+
[ProviderDefinedTypeId]: ProviderDefinedTypeId
|
|
38689
|
+
};
|
|
38690
|
+
var DynamicProto = {
|
|
38691
|
+
...Proto14,
|
|
38692
|
+
[DynamicTypeId]: DynamicTypeId
|
|
38693
|
+
};
|
|
38694
|
+
var userDefinedProto = (options2) => {
|
|
38695
|
+
const self = Object.assign(Object.create(Proto14), options2);
|
|
38696
|
+
self.id = `effect/ai/Tool/${options2.name}`;
|
|
38697
|
+
return self;
|
|
38698
|
+
};
|
|
38699
|
+
var providerDefinedProto = (options2) => Object.assign(Object.create(ProviderDefinedProto), {
|
|
38700
|
+
...options2
|
|
38701
|
+
});
|
|
38702
|
+
var dynamicProto = (options2) => {
|
|
38703
|
+
const self = Object.assign(Object.create(DynamicProto), options2);
|
|
38704
|
+
self.id = `effect/ai/Tool/${options2.name}`;
|
|
38705
|
+
return self;
|
|
38706
|
+
};
|
|
38707
|
+
var make45 = (name, options2) => {
|
|
38708
|
+
const successSchema = options2?.success ?? Void2;
|
|
38709
|
+
const failureSchema = options2?.failure ?? Never2;
|
|
38710
|
+
return userDefinedProto({
|
|
38711
|
+
name,
|
|
38712
|
+
description: options2?.description,
|
|
38713
|
+
parametersSchema: options2?.parameters ?? EmptyParams,
|
|
38714
|
+
successSchema,
|
|
38715
|
+
failureSchema,
|
|
38716
|
+
failureMode: options2?.failureMode ?? "error",
|
|
38717
|
+
annotations: empty4(),
|
|
38718
|
+
needsApproval: options2?.needsApproval
|
|
38719
|
+
});
|
|
38720
|
+
};
|
|
38721
|
+
var dynamic = (name, options2) => {
|
|
38722
|
+
const successSchema = options2?.success ?? Unknown2;
|
|
38723
|
+
const failureSchema = options2?.failure ?? Never2;
|
|
38724
|
+
const rawParameters = options2?.parameters ?? Unknown2;
|
|
38725
|
+
const isEffectSchema = isSchema(rawParameters);
|
|
38726
|
+
const parametersSchema = isEffectSchema ? rawParameters : Unknown2;
|
|
38727
|
+
const jsonSchema2 = isEffectSchema ? undefined : rawParameters;
|
|
38728
|
+
return dynamicProto({
|
|
38729
|
+
name,
|
|
38730
|
+
description: options2?.description,
|
|
38731
|
+
parametersSchema,
|
|
38732
|
+
successSchema,
|
|
38733
|
+
failureSchema,
|
|
38734
|
+
failureMode: options2?.failureMode ?? "error",
|
|
38735
|
+
annotations: empty4(),
|
|
38736
|
+
needsApproval: options2?.needsApproval,
|
|
38737
|
+
jsonSchema: jsonSchema2
|
|
38738
|
+
});
|
|
38739
|
+
};
|
|
38740
|
+
var providerDefined = (options2) => (args2) => {
|
|
38741
|
+
const failureMode = isNotUndefined(args2) && "failureMode" in args2 ? args2.failureMode : undefined;
|
|
38742
|
+
const successSchema = options2?.success ?? Void2;
|
|
38743
|
+
const failureSchema = options2?.failure ?? Never2;
|
|
38744
|
+
return providerDefinedProto({
|
|
38745
|
+
id: options2.id,
|
|
38746
|
+
name: options2.customName,
|
|
38747
|
+
providerName: options2.providerName,
|
|
38748
|
+
args: args2,
|
|
38749
|
+
argsSchema: options2?.args ?? Void2,
|
|
38750
|
+
requiresHandler: options2.requiresHandler ?? false,
|
|
38751
|
+
parametersSchema: options2?.parameters ?? Void2,
|
|
38752
|
+
successSchema,
|
|
38753
|
+
failureSchema,
|
|
38754
|
+
failureMode: failureMode ?? "error"
|
|
38755
|
+
});
|
|
38756
|
+
};
|
|
38757
|
+
|
|
38758
|
+
class NameMapper {
|
|
38759
|
+
#customToProvider = /* @__PURE__ */ new Map;
|
|
38760
|
+
#providerToCustom = /* @__PURE__ */ new Map;
|
|
38761
|
+
constructor(tools) {
|
|
38762
|
+
for (const tool of tools) {
|
|
38763
|
+
if (isProviderDefined(tool)) {
|
|
38764
|
+
this.#customToProvider.set(tool.name, tool.providerName);
|
|
38765
|
+
this.#providerToCustom.set(tool.providerName, tool.name);
|
|
38766
|
+
}
|
|
38767
|
+
}
|
|
38768
|
+
}
|
|
38769
|
+
get customNames() {
|
|
38770
|
+
return Array.from(this.#customToProvider.keys());
|
|
38771
|
+
}
|
|
38772
|
+
get providerNames() {
|
|
38773
|
+
return Array.from(this.#providerToCustom.keys());
|
|
38774
|
+
}
|
|
38775
|
+
getCustomName(providerName) {
|
|
38776
|
+
return this.#providerToCustom.get(providerName) ?? providerName;
|
|
38777
|
+
}
|
|
38778
|
+
getProviderName(customName) {
|
|
38779
|
+
return this.#customToProvider.get(customName) ?? customName;
|
|
38780
|
+
}
|
|
38781
|
+
}
|
|
38782
|
+
var getDescription = (tool) => {
|
|
38783
|
+
if (tool.description !== undefined) {
|
|
38784
|
+
return tool.description;
|
|
38785
|
+
}
|
|
38786
|
+
if (isSchema(tool.parametersSchema)) {
|
|
38787
|
+
return resolveDescription2(tool.parametersSchema.ast);
|
|
38788
|
+
}
|
|
38789
|
+
return;
|
|
38790
|
+
};
|
|
38791
|
+
var getJsonSchema = (tool, options2) => {
|
|
38792
|
+
if (isDynamic(tool) && tool.jsonSchema !== undefined) {
|
|
38793
|
+
return tool.jsonSchema;
|
|
38794
|
+
}
|
|
38795
|
+
return getJsonSchemaFromSchema(tool.parametersSchema, options2);
|
|
38796
|
+
};
|
|
38797
|
+
var getJsonSchemaFromSchema = (schema, options2) => {
|
|
38798
|
+
if (isNotUndefined(options2?.transformer)) {
|
|
38799
|
+
return options2.transformer(schema).jsonSchema;
|
|
38800
|
+
}
|
|
38801
|
+
const document = toJsonSchemaDocument2(schema);
|
|
38802
|
+
if (Object.keys(document.definitions).length > 0) {
|
|
38803
|
+
document.schema.$defs = document.definitions;
|
|
38804
|
+
}
|
|
38805
|
+
return document.schema;
|
|
38806
|
+
};
|
|
38807
|
+
|
|
38808
|
+
class Title extends (/* @__PURE__ */ Service()("effect/ai/Tool/Title")) {
|
|
38809
|
+
}
|
|
38810
|
+
|
|
38811
|
+
class Meta extends (/* @__PURE__ */ Service()("effect/ai/Tool/Meta")) {
|
|
38812
|
+
}
|
|
38813
|
+
var Readonly = /* @__PURE__ */ Reference("effect/ai/Tool/Readonly", {
|
|
38814
|
+
defaultValue: constFalse
|
|
38815
|
+
});
|
|
38816
|
+
var Destructive = /* @__PURE__ */ Reference("effect/ai/Tool/Destructive", {
|
|
38817
|
+
defaultValue: constTrue
|
|
38818
|
+
});
|
|
38819
|
+
var Idempotent = /* @__PURE__ */ Reference("effect/ai/Tool/Idempotent", {
|
|
38820
|
+
defaultValue: constFalse
|
|
38821
|
+
});
|
|
38822
|
+
var OpenWorld = /* @__PURE__ */ Reference("effect/ai/Tool/OpenWorld", {
|
|
38823
|
+
defaultValue: constTrue
|
|
38824
|
+
});
|
|
38825
|
+
var Strict = /* @__PURE__ */ Reference("effect/ai/Tool/Strict", {
|
|
38826
|
+
defaultValue: () => {
|
|
38827
|
+
return;
|
|
38828
|
+
}
|
|
38829
|
+
});
|
|
38830
|
+
var getStrictMode = (tool) => get2(tool.annotations, Strict);
|
|
38831
|
+
var suspectProtoRx = /"__proto__"\s*:/;
|
|
38832
|
+
var suspectConstructorRx = /"constructor"\s*:/;
|
|
38833
|
+
function _parse(text2) {
|
|
38834
|
+
const obj = JSON.parse(text2);
|
|
38835
|
+
if (obj === null || typeof obj !== "object") {
|
|
38836
|
+
return obj;
|
|
38837
|
+
}
|
|
38838
|
+
if (suspectProtoRx.test(text2) === false && suspectConstructorRx.test(text2) === false) {
|
|
38839
|
+
return obj;
|
|
38840
|
+
}
|
|
38841
|
+
return filter13(obj);
|
|
38842
|
+
}
|
|
38843
|
+
function filter13(obj) {
|
|
38844
|
+
let next2 = [obj];
|
|
38845
|
+
while (next2.length) {
|
|
38846
|
+
const nodes = next2;
|
|
38847
|
+
next2 = [];
|
|
38848
|
+
for (const node of nodes) {
|
|
38849
|
+
if (Object.prototype.hasOwnProperty.call(node, "__proto__")) {
|
|
38850
|
+
throw new SyntaxError("Object contains forbidden prototype property");
|
|
38851
|
+
}
|
|
38852
|
+
if (Object.prototype.hasOwnProperty.call(node, "constructor") && Object.prototype.hasOwnProperty.call(node.constructor, "prototype")) {
|
|
38853
|
+
throw new SyntaxError("Object contains forbidden prototype property");
|
|
38854
|
+
}
|
|
38855
|
+
for (const key in node) {
|
|
38856
|
+
const value3 = node[key];
|
|
38857
|
+
if (value3 && typeof value3 === "object") {
|
|
38858
|
+
next2.push(value3);
|
|
38859
|
+
}
|
|
38860
|
+
}
|
|
38861
|
+
}
|
|
38862
|
+
}
|
|
38863
|
+
return obj;
|
|
38864
|
+
}
|
|
38865
|
+
var unsafeSecureJsonParse = (text2) => {
|
|
38866
|
+
const prevLimit = getStackTraceLimit();
|
|
38867
|
+
setStackTraceLimit(0);
|
|
38868
|
+
try {
|
|
38869
|
+
return _parse(text2);
|
|
38870
|
+
} finally {
|
|
38871
|
+
setStackTraceLimit(prevLimit);
|
|
38872
|
+
}
|
|
38873
|
+
};
|
|
38874
|
+
var EmptyParams = /* @__PURE__ */ Record2(String6, Never2);
|
|
38875
|
+
function isEmptyParamsRecord(indexSignature) {
|
|
38876
|
+
return indexSignature.parameter === string2 && isNever2(indexSignature.type);
|
|
38877
|
+
}
|
|
38591
38878
|
// ../core/src/agent-event.ts
|
|
38592
38879
|
var exports_agent_event = {};
|
|
38593
38880
|
__export(exports_agent_event, {
|
|
@@ -38812,6 +39099,25 @@ var allowAll = exports_Layer.succeed(Permissions, Permissions.of({
|
|
|
38812
39099
|
await: () => exports_Effect.succeed(exports_Option.none())
|
|
38813
39100
|
}));
|
|
38814
39101
|
|
|
39102
|
+
// ../core/src/skill-source.ts
|
|
39103
|
+
class SkillSourceError extends exports_Schema.TaggedErrorClass()("@batonfx/core/SkillSourceError", {
|
|
39104
|
+
source: exports_Schema.String,
|
|
39105
|
+
message: exports_Schema.String,
|
|
39106
|
+
cause: exports_Schema.optionalKey(exports_Schema.Defect())
|
|
39107
|
+
}) {
|
|
39108
|
+
}
|
|
39109
|
+
class SkillSource extends exports_Context.Service()("@batonfx/core/SkillSource") {
|
|
39110
|
+
}
|
|
39111
|
+
var fromSkills = (skills) => {
|
|
39112
|
+
const all5 = [...skills];
|
|
39113
|
+
const byName = new Map(all5.map((skill) => [skill.frontmatter.name, skill]));
|
|
39114
|
+
return exports_Layer.succeed(SkillSource, SkillSource.of({
|
|
39115
|
+
all: exports_Effect.succeed(all5),
|
|
39116
|
+
get: (name) => exports_Effect.succeed(byName.get(name))
|
|
39117
|
+
}));
|
|
39118
|
+
};
|
|
39119
|
+
var empty20 = fromSkills([]);
|
|
39120
|
+
|
|
38815
39121
|
// ../core/src/steering.ts
|
|
38816
39122
|
class Steering extends exports_Context.Service()("@batonfx/core/Steering") {
|
|
38817
39123
|
}
|
|
@@ -38837,9 +39143,22 @@ var decision = {
|
|
|
38837
39143
|
}),
|
|
38838
39144
|
stop: { _tag: "Stop" }
|
|
38839
39145
|
};
|
|
38840
|
-
var
|
|
38841
|
-
var recurs2 = (n) =>
|
|
39146
|
+
var make46 = (decide) => ({ decide });
|
|
39147
|
+
var recurs2 = (n) => make46((info) => exports_Effect.succeed(info.turn < n + 1 ? decision.continue() : decision.stop));
|
|
38842
39148
|
var defaultPolicy = recurs2(8);
|
|
39149
|
+
|
|
39150
|
+
// ../core/src/agent.ts
|
|
39151
|
+
var activateSkillToolName = "activate_skill";
|
|
39152
|
+
var activateSkillParameters = exports_Schema.Struct({ name: exports_Schema.String });
|
|
39153
|
+
var activateSkillTool = exports_Tool.make(activateSkillToolName, {
|
|
39154
|
+
description: "Load the full body for one listed Baton skill by name before applying that skill.",
|
|
39155
|
+
parameters: activateSkillParameters,
|
|
39156
|
+
success: exports_Schema.Struct({
|
|
39157
|
+
name: exports_Schema.String,
|
|
39158
|
+
body: exports_Schema.String,
|
|
39159
|
+
allowedTools: exports_Schema.Array(exports_Schema.String)
|
|
39160
|
+
})
|
|
39161
|
+
});
|
|
38843
39162
|
// ../core/src/agent-tool.ts
|
|
38844
39163
|
var defaultParameters = exports_Schema.Struct({ prompt: exports_Schema.String });
|
|
38845
39164
|
// ../core/src/handoff.ts
|
|
@@ -38862,24 +39181,6 @@ var registrations = exports_Effect.fn("ModelRegistry.registrations.call")(functi
|
|
|
38862
39181
|
const service4 = yield* Service2;
|
|
38863
39182
|
return yield* service4.registrations;
|
|
38864
39183
|
});
|
|
38865
|
-
// ../core/src/skill-source.ts
|
|
38866
|
-
class SkillSourceError extends exports_Schema.TaggedErrorClass()("@batonfx/core/SkillSourceError", {
|
|
38867
|
-
source: exports_Schema.String,
|
|
38868
|
-
message: exports_Schema.String,
|
|
38869
|
-
cause: exports_Schema.optionalKey(exports_Schema.Defect())
|
|
38870
|
-
}) {
|
|
38871
|
-
}
|
|
38872
|
-
class SkillSource extends exports_Context.Service()("@batonfx/core/SkillSource") {
|
|
38873
|
-
}
|
|
38874
|
-
var fromSkills = (skills) => {
|
|
38875
|
-
const all5 = [...skills];
|
|
38876
|
-
const byName = new Map(all5.map((skill) => [skill.frontmatter.name, skill]));
|
|
38877
|
-
return exports_Layer.succeed(SkillSource, SkillSource.of({
|
|
38878
|
-
all: exports_Effect.succeed(all5),
|
|
38879
|
-
get: (name) => exports_Effect.succeed(byName.get(name))
|
|
38880
|
-
}));
|
|
38881
|
-
};
|
|
38882
|
-
var empty20 = fromSkills([]);
|
|
38883
39184
|
// ../transport/src/wire.ts
|
|
38884
39185
|
var RunFailure = exports_Schema.Union([
|
|
38885
39186
|
exports_agent_event.AgentError,
|
|
@@ -39169,10 +39470,13 @@ var UserEntryFields = { text: exports_Schema.String };
|
|
|
39169
39470
|
var AssistantEntryFields = { text: exports_Schema.String, reasoning: exports_Schema.NullOr(exports_Schema.String) };
|
|
39170
39471
|
var RunCompletedFields = { text: exports_Schema.String };
|
|
39171
39472
|
var StringReasonFields = { reason: exports_Schema.String };
|
|
39473
|
+
var OpenedSessionFields = { sessionId: exports_Schema.String };
|
|
39474
|
+
var ToolPendingPhase = exports_Schema.Literals(["called", "executing"]);
|
|
39172
39475
|
var ToolEntryFields = {
|
|
39173
39476
|
callId: exports_Schema.String,
|
|
39174
39477
|
name: exports_Schema.String,
|
|
39175
39478
|
params: exports_Schema.Unknown,
|
|
39479
|
+
phase: ToolPendingPhase,
|
|
39176
39480
|
outcome: exports_Schema.suspend(() => ToolOutcome),
|
|
39177
39481
|
progress: exports_Schema.Array(exports_Schema.String)
|
|
39178
39482
|
};
|
|
@@ -39214,6 +39518,7 @@ var Model = exports_Schema.Struct({
|
|
|
39214
39518
|
draft: exports_Schema.String
|
|
39215
39519
|
});
|
|
39216
39520
|
var ReceivedAgent = m("ReceivedAgent", ReceivedAgentFields);
|
|
39521
|
+
var OpenedSession = m("OpenedSession", OpenedSessionFields);
|
|
39217
39522
|
var ChangedDraft = m("ChangedDraft", UserEntryFields);
|
|
39218
39523
|
var SubmittedMessage = m("SubmittedMessage");
|
|
39219
39524
|
var ClickedCancel = m("ClickedCancel");
|
|
@@ -39225,6 +39530,7 @@ var CancelledRun = m("CancelledRun");
|
|
|
39225
39530
|
var FailedAgentCommand = m("FailedAgentCommand", StringReasonFields);
|
|
39226
39531
|
var Message2 = exports_Schema.Union([
|
|
39227
39532
|
ReceivedAgent,
|
|
39533
|
+
OpenedSession,
|
|
39228
39534
|
ChangedDraft,
|
|
39229
39535
|
SubmittedMessage,
|
|
39230
39536
|
ClickedCancel,
|
|
@@ -39241,6 +39547,43 @@ var RunFailed = m("RunFailed", {
|
|
|
39241
39547
|
message: exports_Schema.String
|
|
39242
39548
|
});
|
|
39243
39549
|
var OutMessage = exports_Schema.Union([RunCompleted, ApprovalRequired, RunFailed]);
|
|
39550
|
+
var MessageAlign = exports_Schema.Literals(["start", "end"]);
|
|
39551
|
+
var PromptInputStatus = exports_Schema.Literals(["idle", "submitted", "streaming", "error"]);
|
|
39552
|
+
var ToolStatus = exports_Schema.Literals(["input-streaming", "input-available", "output-available", "output-error"]);
|
|
39553
|
+
var UserConversationItem = m("UserConversationItem", { key: exports_Schema.String, align: MessageAlign, entry: UserEntry });
|
|
39554
|
+
var AssistantConversationItem = m("AssistantConversationItem", { key: exports_Schema.String, align: MessageAlign, entry: AssistantEntry });
|
|
39555
|
+
var ToolConversationItem = m("ToolConversationItem", {
|
|
39556
|
+
key: exports_Schema.String,
|
|
39557
|
+
align: MessageAlign,
|
|
39558
|
+
entry: ToolEntry,
|
|
39559
|
+
status: ToolStatus,
|
|
39560
|
+
input: exports_Schema.String
|
|
39561
|
+
});
|
|
39562
|
+
var StreamingConversationItem = m("StreamingConversationItem", {
|
|
39563
|
+
key: exports_Schema.String,
|
|
39564
|
+
align: MessageAlign,
|
|
39565
|
+
text: exports_Schema.String,
|
|
39566
|
+
reasoning: exports_Schema.String,
|
|
39567
|
+
isStreaming: exports_Schema.Boolean
|
|
39568
|
+
});
|
|
39569
|
+
var WaitingConversationItem = m("WaitingConversationItem", { key: exports_Schema.String, align: MessageAlign });
|
|
39570
|
+
var ApprovalConversationItem = m("ApprovalConversationItem", {
|
|
39571
|
+
key: exports_Schema.String,
|
|
39572
|
+
align: MessageAlign,
|
|
39573
|
+
token: exports_Schema.String,
|
|
39574
|
+
toolName: exports_Schema.String,
|
|
39575
|
+
params: exports_Schema.Unknown
|
|
39576
|
+
});
|
|
39577
|
+
var FailureConversationItem = m("FailureConversationItem", { key: exports_Schema.String, align: MessageAlign, message: exports_Schema.String });
|
|
39578
|
+
var ConversationItem = exports_Schema.Union([
|
|
39579
|
+
UserConversationItem,
|
|
39580
|
+
AssistantConversationItem,
|
|
39581
|
+
ToolConversationItem,
|
|
39582
|
+
StreamingConversationItem,
|
|
39583
|
+
WaitingConversationItem,
|
|
39584
|
+
ApprovalConversationItem,
|
|
39585
|
+
FailureConversationItem
|
|
39586
|
+
]);
|
|
39244
39587
|
var initialModel = (sessionId = null) => ({
|
|
39245
39588
|
sessionId,
|
|
39246
39589
|
connection: "disconnected",
|
|
@@ -39278,14 +39621,16 @@ var flushStreaming = (model) => {
|
|
|
39278
39621
|
const entry = text2.length === 0 && reasoning.length === 0 ? [] : [AssistantEntry({ text: text2, reasoning: reasoning || null })];
|
|
39279
39622
|
return { ...model, entries: [...model.entries, ...entry], streaming: null };
|
|
39280
39623
|
};
|
|
39281
|
-
var upsertToolCall = (entries3, call) => {
|
|
39624
|
+
var upsertToolCall = (entries3, call, phase = "called") => {
|
|
39282
39625
|
const index2 = entries3.findIndex((entry) => entry._tag === "ToolEntry" && entry.callId === call.id);
|
|
39283
39626
|
const previous = index2 >= 0 ? entries3[index2] : undefined;
|
|
39284
39627
|
const previousToolEntry = previous?._tag === "ToolEntry" ? previous : undefined;
|
|
39628
|
+
const nextPhase = previousToolEntry?.phase === "executing" || phase === "executing" ? "executing" : "called";
|
|
39285
39629
|
const next2 = ToolEntry({
|
|
39286
39630
|
callId: call.id,
|
|
39287
39631
|
name: call.name,
|
|
39288
39632
|
params: call.params === undefined ? previousToolEntry?.params : call.params,
|
|
39633
|
+
phase: nextPhase,
|
|
39289
39634
|
outcome: previousToolEntry?.outcome ?? Pending(),
|
|
39290
39635
|
progress: previousToolEntry?.progress ?? []
|
|
39291
39636
|
});
|
|
@@ -39299,6 +39644,7 @@ var resolveTool = (entries3, result4) => {
|
|
|
39299
39644
|
callId: entry.callId,
|
|
39300
39645
|
name: entry.name,
|
|
39301
39646
|
params: entry.params,
|
|
39647
|
+
phase: entry.phase,
|
|
39302
39648
|
outcome: Completed({ isFailure: result4.isFailure, result: result4.result }),
|
|
39303
39649
|
progress: entry.progress
|
|
39304
39650
|
}) : entry);
|
|
@@ -39307,6 +39653,7 @@ var addProgress = (entries3, callId, message) => entries3.map((entry) => entry._
|
|
|
39307
39653
|
callId: entry.callId,
|
|
39308
39654
|
name: entry.name,
|
|
39309
39655
|
params: entry.params,
|
|
39656
|
+
phase: entry.phase,
|
|
39310
39657
|
outcome: entry.outcome,
|
|
39311
39658
|
progress: entry.progress.concat(message)
|
|
39312
39659
|
}) : entry);
|
|
@@ -39377,13 +39724,14 @@ var applyEvent = (model, event) => {
|
|
|
39377
39724
|
case "ModelPart":
|
|
39378
39725
|
return [applyPart(model, event.turn, event.part), exports_Option.none()];
|
|
39379
39726
|
case "ToolExecutionStarted":
|
|
39727
|
+
return [{ ...model, entries: upsertToolCall(model.entries, event.call, "executing") }, exports_Option.none()];
|
|
39380
39728
|
case "ApprovalRequested":
|
|
39381
39729
|
return [{ ...model, entries: upsertToolCall(model.entries, event.call) }, exports_Option.none()];
|
|
39382
39730
|
case "ToolProgress":
|
|
39383
39731
|
return event.message === undefined ? [model, exports_Option.none()] : [{ ...model, entries: addProgress(model.entries, event.toolCallId, event.message) }, exports_Option.none()];
|
|
39384
39732
|
case "ToolExecutionCompleted":
|
|
39385
39733
|
return [
|
|
39386
|
-
{ ...model, entries: resolveTool(upsertToolCall(model.entries, event.call), event.result) },
|
|
39734
|
+
{ ...model, entries: resolveTool(upsertToolCall(model.entries, event.call, "executing"), event.result) },
|
|
39387
39735
|
exports_Option.none()
|
|
39388
39736
|
];
|
|
39389
39737
|
case "TurnCompleted":
|
|
@@ -39449,6 +39797,73 @@ var applyFrame = (model, frame) => {
|
|
|
39449
39797
|
return applyStatus(withSeq, frame.status);
|
|
39450
39798
|
}
|
|
39451
39799
|
};
|
|
39800
|
+
var jsonText = (value3) => {
|
|
39801
|
+
try {
|
|
39802
|
+
return JSON.stringify(value3, null, 2) ?? "undefined";
|
|
39803
|
+
} catch {
|
|
39804
|
+
return String(value3);
|
|
39805
|
+
}
|
|
39806
|
+
};
|
|
39807
|
+
var promptInputStatusOf = (run4) => {
|
|
39808
|
+
switch (run4._tag) {
|
|
39809
|
+
case "Idle":
|
|
39810
|
+
return "idle";
|
|
39811
|
+
case "Running":
|
|
39812
|
+
return "streaming";
|
|
39813
|
+
case "AwaitingApproval":
|
|
39814
|
+
return "submitted";
|
|
39815
|
+
case "Failed":
|
|
39816
|
+
return "error";
|
|
39817
|
+
}
|
|
39818
|
+
};
|
|
39819
|
+
var toolStatusOf = (entry) => {
|
|
39820
|
+
switch (entry.outcome._tag) {
|
|
39821
|
+
case "Pending":
|
|
39822
|
+
return entry.phase === "executing" ? "input-available" : "input-streaming";
|
|
39823
|
+
case "Completed":
|
|
39824
|
+
return entry.outcome.isFailure ? "output-error" : "output-available";
|
|
39825
|
+
}
|
|
39826
|
+
};
|
|
39827
|
+
var conversationItemFor = (entry, index2) => {
|
|
39828
|
+
switch (entry._tag) {
|
|
39829
|
+
case "UserEntry":
|
|
39830
|
+
return UserConversationItem({ key: `entry-${index2}-user`, align: "end", entry });
|
|
39831
|
+
case "AssistantEntry":
|
|
39832
|
+
return AssistantConversationItem({ key: `entry-${index2}-assistant`, align: "start", entry });
|
|
39833
|
+
case "ToolEntry":
|
|
39834
|
+
return ToolConversationItem({
|
|
39835
|
+
key: `tool-${entry.callId}`,
|
|
39836
|
+
align: "start",
|
|
39837
|
+
entry,
|
|
39838
|
+
status: toolStatusOf(entry),
|
|
39839
|
+
input: jsonText(entry.params)
|
|
39840
|
+
});
|
|
39841
|
+
}
|
|
39842
|
+
};
|
|
39843
|
+
var conversationItems = (model) => {
|
|
39844
|
+
const entries3 = model.entries.map(conversationItemFor);
|
|
39845
|
+
const streaming = model.streaming === null ? [] : [
|
|
39846
|
+
StreamingConversationItem({
|
|
39847
|
+
key: "streaming-assistant",
|
|
39848
|
+
align: "start",
|
|
39849
|
+
text: model.streaming.text,
|
|
39850
|
+
reasoning: model.streaming.reasoning,
|
|
39851
|
+
isStreaming: true
|
|
39852
|
+
})
|
|
39853
|
+
];
|
|
39854
|
+
const waiting = model.run._tag === "Running" && model.streaming === null ? [WaitingConversationItem({ key: "waiting-assistant", align: "start" })] : [];
|
|
39855
|
+
const approval = model.run._tag === "AwaitingApproval" ? [
|
|
39856
|
+
ApprovalConversationItem({
|
|
39857
|
+
key: `approval-${model.run.token}`,
|
|
39858
|
+
align: "start",
|
|
39859
|
+
token: model.run.token,
|
|
39860
|
+
toolName: model.run.toolName,
|
|
39861
|
+
params: model.run.params
|
|
39862
|
+
})
|
|
39863
|
+
] : [];
|
|
39864
|
+
const failure2 = model.run._tag === "Failed" ? [FailureConversationItem({ key: "run-failure", align: "start", message: model.run.message })] : [];
|
|
39865
|
+
return [...entries3, ...streaming, ...waiting, ...approval, ...failure2];
|
|
39866
|
+
};
|
|
39452
39867
|
var isServerFrame = (incoming) => incoming._tag === "Event" || incoming._tag === "Suspended" || incoming._tag === "Failed" || incoming._tag === "Ended" || incoming._tag === "Snapshot" || incoming._tag === "SessionStatus";
|
|
39453
39868
|
var update3 = (model, message) => {
|
|
39454
39869
|
switch (message._tag) {
|
|
@@ -39473,6 +39888,20 @@ var update3 = (model, message) => {
|
|
|
39473
39888
|
exports_Option.some(RunFailed({ message: message.incoming.reason }))
|
|
39474
39889
|
];
|
|
39475
39890
|
}
|
|
39891
|
+
case "OpenedSession":
|
|
39892
|
+
return [
|
|
39893
|
+
{
|
|
39894
|
+
...model,
|
|
39895
|
+
sessionId: message.sessionId,
|
|
39896
|
+
connection: "connecting",
|
|
39897
|
+
lastSeq: -1,
|
|
39898
|
+
run: Idle(),
|
|
39899
|
+
entries: [],
|
|
39900
|
+
streaming: null
|
|
39901
|
+
},
|
|
39902
|
+
[],
|
|
39903
|
+
exports_Option.none()
|
|
39904
|
+
];
|
|
39476
39905
|
case "ChangedDraft":
|
|
39477
39906
|
return [{ ...model, draft: message.text }, [], exports_Option.none()];
|
|
39478
39907
|
case "SubmittedMessage": {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://json.schemastore.org/package.json",
|
|
3
3
|
"name": "@batonfx/foldkit",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.2.0",
|
|
5
5
|
"private": false,
|
|
6
6
|
"type": "module",
|
|
7
7
|
"exports": {
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"typecheck": "bun tsc --noEmit"
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@batonfx/transport": "0.
|
|
17
|
+
"@batonfx/transport": "0.2.0"
|
|
18
18
|
},
|
|
19
19
|
"peerDependencies": {
|
|
20
20
|
"effect": ">=4.0.0-beta.88 <4.0.1",
|