@m4trix/core 0.12.0 → 0.13.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/dist/index.cjs +11 -278
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +0 -2
- package/dist/index.js +13 -279
- package/dist/index.js.map +1 -1
- package/dist/matrix/index.cjs +11 -7
- package/dist/matrix/index.cjs.map +1 -1
- package/dist/matrix/index.d.ts +18 -14
- package/dist/matrix/index.js +11 -7
- package/dist/matrix/index.js.map +1 -1
- package/package.json +19 -36
- package/dist/helper/index.cjs +0 -279
- package/dist/helper/index.cjs.map +0 -1
- package/dist/helper/index.d.ts +0 -108
- package/dist/helper/index.js +0 -277
- package/dist/helper/index.js.map +0 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
export { HttpStreamOptions, MessageStream, Pump, Source, StreamChunk, StreamTransformer, ensureFullWords, httpStreamResponse } from './stream/index.js';
|
|
2
2
|
import { Socket } from 'socket.io';
|
|
3
|
-
export { FormatType, MessageFilterType, TransformMessages } from './helper/index.js';
|
|
4
3
|
export { Agent, AgentBinding, AgentFactory, AgentNetwork, AgentNetworkEvent, AgentNetworkEventDef, AnyAgent, AuthResult, Channel, ChannelDef, ChannelName, ConfiguredChannel, ContextEvents, DepedencyLayer, DepedencyLayerDef, EmitPayload, EnvelopeLike, EventEnvelope, EventMeta, EventMetaSchema, EventPlane, ExposeAuthError, ExposeOptions, ExposeRequest, ExposeSelect, ExposedAPI, ExposedStream, ExpressEndpoint, ExpressEndpointOptions, ExpressHandler, ExpressRequest, ExpressResponse, LayerName, LayersFromDeps, NextEndpoint, NextEndpointOptions, NextGetHandler, OnRequestContext, RunEvents, SetupContext, Sink, SinkDef, Skill, SkillDefineContext, SkillInstance, SkillRuntimeOptions, SpawnCallbackContext, SpawnFn, SpawnerBuilder, StreamFactory, UnboundEvent, consoleTracer, consoleTracerLayer, formatSSE, isHttpStreamSink, toSSEStream } from './matrix/index.js';
|
|
5
4
|
export { Schema as S } from 'effect';
|
|
6
|
-
import '@langchain/core/messages';
|
|
7
5
|
import 'effect/ParseResult';
|
|
8
6
|
|
|
9
7
|
type Role = 'system' | 'user' | 'assistant' | string;
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Brand, Schema, Tracer, Layer, Effect, pipe, Exit, PubSub, Queue, Cause } from 'effect';
|
|
1
|
+
import { Brand, Schema, Tracer, Layer, Effect, Exit, PubSub, Queue, Cause } from 'effect';
|
|
3
2
|
export { Schema as S } from 'effect';
|
|
4
3
|
import { randomUUID } from 'crypto';
|
|
5
4
|
|
|
@@ -808,275 +807,6 @@ var SocketIoFactory = class _SocketIoFactory {
|
|
|
808
807
|
return this.prefix ? `${this.prefix}:${event}` : event;
|
|
809
808
|
}
|
|
810
809
|
};
|
|
811
|
-
var humanAndAI = (message) => message instanceof HumanMessage || message instanceof AIMessage;
|
|
812
|
-
var humanOnly = (message) => message instanceof HumanMessage;
|
|
813
|
-
var aiOnly = (message) => message instanceof AIMessage;
|
|
814
|
-
var includingTags = (message, tags) => {
|
|
815
|
-
if (tags) {
|
|
816
|
-
return tags.some(
|
|
817
|
-
(tag) => Array.isArray(message.additional_kwargs?.tags) ? message.additional_kwargs?.tags.includes(tag) : false
|
|
818
|
-
);
|
|
819
|
-
}
|
|
820
|
-
return true;
|
|
821
|
-
};
|
|
822
|
-
var excludingTags = (message, tags) => {
|
|
823
|
-
if (tags) {
|
|
824
|
-
return !tags.some(
|
|
825
|
-
(tag) => Array.isArray(message.additional_kwargs?.tags) ? message.additional_kwargs?.tags.includes(tag) : false
|
|
826
|
-
);
|
|
827
|
-
}
|
|
828
|
-
return true;
|
|
829
|
-
};
|
|
830
|
-
var typeOnFilter = {
|
|
831
|
-
["HumanAndAI" /* HumanAndAI */]: humanAndAI,
|
|
832
|
-
["HumanOnly" /* HumanOnly */]: humanOnly,
|
|
833
|
-
["AIOnly" /* AIOnly */]: aiOnly,
|
|
834
|
-
["IncludingTags" /* IncludingTags */]: includingTags,
|
|
835
|
-
["ExcludingTags" /* ExcludingTags */]: excludingTags
|
|
836
|
-
};
|
|
837
|
-
function concise(messages) {
|
|
838
|
-
return messages.map((message) => {
|
|
839
|
-
const prefix = message instanceof AIMessage ? "AI" : "Human";
|
|
840
|
-
return `${prefix}: ${message.content}`;
|
|
841
|
-
}).join("\n");
|
|
842
|
-
}
|
|
843
|
-
function verbose(messages) {
|
|
844
|
-
return messages.map((message) => {
|
|
845
|
-
const prefix = message instanceof AIMessage ? "AI" : "Human";
|
|
846
|
-
return `${prefix}:
|
|
847
|
-
${message.content}`;
|
|
848
|
-
}).join("\n-------------------\n");
|
|
849
|
-
}
|
|
850
|
-
function redactAi(messages) {
|
|
851
|
-
return messages.map((message) => {
|
|
852
|
-
const prefix = message instanceof AIMessage ? "AI" : "Human";
|
|
853
|
-
const content = message instanceof AIMessage ? "[...]" : message.content;
|
|
854
|
-
return `${prefix}: ${content}`;
|
|
855
|
-
}).join("\n");
|
|
856
|
-
}
|
|
857
|
-
function redactHuman(messages) {
|
|
858
|
-
return messages.map((message) => {
|
|
859
|
-
const prefix = message instanceof AIMessage ? "AI" : "Human";
|
|
860
|
-
const content = message instanceof AIMessage ? "[...]" : message.content;
|
|
861
|
-
return `${prefix}: ${content}`;
|
|
862
|
-
}).join("\n");
|
|
863
|
-
}
|
|
864
|
-
var typeOnFormatter = {
|
|
865
|
-
["concise" /* Concise */]: concise,
|
|
866
|
-
["verbose" /* Verbose */]: verbose,
|
|
867
|
-
["redact-ai" /* RedactAi */]: redactAi,
|
|
868
|
-
["redact-human" /* RedactHuman */]: redactHuman
|
|
869
|
-
};
|
|
870
|
-
|
|
871
|
-
// src/helper/transform-messages/TransformMessages.ts
|
|
872
|
-
var TransformMessages = class _TransformMessages {
|
|
873
|
-
constructor(effect) {
|
|
874
|
-
this.effect = effect;
|
|
875
|
-
}
|
|
876
|
-
/**
|
|
877
|
-
* Create a new TransformMessages from an array of messages.
|
|
878
|
-
*/
|
|
879
|
-
static from(messages) {
|
|
880
|
-
return new _TransformMessages(Effect.succeed(messages));
|
|
881
|
-
}
|
|
882
|
-
/**
|
|
883
|
-
* Filter messages based on a predicate function
|
|
884
|
-
*/
|
|
885
|
-
filter(predicate, tags) {
|
|
886
|
-
let finalPredicate;
|
|
887
|
-
if (typeof predicate === "string") {
|
|
888
|
-
finalPredicate = typeOnFilter[predicate];
|
|
889
|
-
} else {
|
|
890
|
-
finalPredicate = predicate;
|
|
891
|
-
}
|
|
892
|
-
return new _TransformMessages(
|
|
893
|
-
pipe(
|
|
894
|
-
this.effect,
|
|
895
|
-
Effect.map(
|
|
896
|
-
(messages) => messages.filter((message) => finalPredicate(message, tags))
|
|
897
|
-
)
|
|
898
|
-
)
|
|
899
|
-
);
|
|
900
|
-
}
|
|
901
|
-
/**
|
|
902
|
-
* Take only the last n messages, but safely.
|
|
903
|
-
* Tool calls should not be separated from the last human message.
|
|
904
|
-
* Ensures all tool call conversations in the last n messages are complete.
|
|
905
|
-
*/
|
|
906
|
-
safelyTakeLast(n, pruneAfterNOvershootingMessages = 0) {
|
|
907
|
-
return new _TransformMessages(
|
|
908
|
-
pipe(
|
|
909
|
-
this.effect,
|
|
910
|
-
Effect.map((messages) => {
|
|
911
|
-
const total = messages.length;
|
|
912
|
-
if (n <= 0 || total === 0)
|
|
913
|
-
return [];
|
|
914
|
-
const start = Math.max(0, total - n);
|
|
915
|
-
const end = total;
|
|
916
|
-
const lastSlice = messages.slice(start, end);
|
|
917
|
-
if (lastSlice[0] instanceof ToolMessage && lastSlice[0].tool_call_id) {
|
|
918
|
-
let messagesToInclude = [];
|
|
919
|
-
const remainingMessages = messages.slice(0, start);
|
|
920
|
-
for (let i = remainingMessages.length - 1; i >= 0; i--) {
|
|
921
|
-
const msg = remainingMessages[i];
|
|
922
|
-
if (pruneAfterNOvershootingMessages > 0 && messagesToInclude.length - 1 >= pruneAfterNOvershootingMessages) {
|
|
923
|
-
messagesToInclude = [];
|
|
924
|
-
const filteredSlice = [];
|
|
925
|
-
let foundFirstNonToolMessage = false;
|
|
926
|
-
for (let i2 = 0; i2 < lastSlice.length; i2++) {
|
|
927
|
-
const msg2 = lastSlice[i2];
|
|
928
|
-
if (msg2 instanceof ToolMessage) {
|
|
929
|
-
if (foundFirstNonToolMessage) {
|
|
930
|
-
filteredSlice.push(msg2);
|
|
931
|
-
}
|
|
932
|
-
} else {
|
|
933
|
-
foundFirstNonToolMessage = true;
|
|
934
|
-
filteredSlice.push(msg2);
|
|
935
|
-
}
|
|
936
|
-
}
|
|
937
|
-
return filteredSlice;
|
|
938
|
-
}
|
|
939
|
-
if (msg instanceof AIMessage && Array.isArray(msg.tool_calls)) {
|
|
940
|
-
messagesToInclude.push(msg);
|
|
941
|
-
break;
|
|
942
|
-
} else if (msg instanceof ToolMessage) {
|
|
943
|
-
messagesToInclude.push(msg);
|
|
944
|
-
} else {
|
|
945
|
-
throw new Error(
|
|
946
|
-
"Messages array invalid no adjacent AI message found"
|
|
947
|
-
);
|
|
948
|
-
}
|
|
949
|
-
}
|
|
950
|
-
return [...messagesToInclude.reverse(), ...lastSlice];
|
|
951
|
-
} else {
|
|
952
|
-
return lastSlice;
|
|
953
|
-
}
|
|
954
|
-
})
|
|
955
|
-
)
|
|
956
|
-
);
|
|
957
|
-
}
|
|
958
|
-
/**
|
|
959
|
-
* Take only the last n messages
|
|
960
|
-
*/
|
|
961
|
-
last(n) {
|
|
962
|
-
return new _TransformMessages(
|
|
963
|
-
pipe(
|
|
964
|
-
this.effect,
|
|
965
|
-
Effect.map((messages) => messages.slice(-n))
|
|
966
|
-
)
|
|
967
|
-
);
|
|
968
|
-
}
|
|
969
|
-
/**
|
|
970
|
-
* Take only the first n messages
|
|
971
|
-
*/
|
|
972
|
-
first(n) {
|
|
973
|
-
return new _TransformMessages(
|
|
974
|
-
pipe(
|
|
975
|
-
this.effect,
|
|
976
|
-
Effect.map((messages) => messages.slice(0, n))
|
|
977
|
-
)
|
|
978
|
-
);
|
|
979
|
-
}
|
|
980
|
-
/**
|
|
981
|
-
* Skip the first n messages
|
|
982
|
-
*/
|
|
983
|
-
skip(n) {
|
|
984
|
-
return new _TransformMessages(
|
|
985
|
-
pipe(
|
|
986
|
-
this.effect,
|
|
987
|
-
Effect.map((messages) => messages.slice(n))
|
|
988
|
-
)
|
|
989
|
-
);
|
|
990
|
-
}
|
|
991
|
-
/**
|
|
992
|
-
* Reverse the order of messages
|
|
993
|
-
*/
|
|
994
|
-
reverse() {
|
|
995
|
-
return new _TransformMessages(
|
|
996
|
-
pipe(
|
|
997
|
-
this.effect,
|
|
998
|
-
Effect.map((messages) => [...messages].reverse())
|
|
999
|
-
)
|
|
1000
|
-
);
|
|
1001
|
-
}
|
|
1002
|
-
/**
|
|
1003
|
-
* Map over messages with a transformation function
|
|
1004
|
-
*/
|
|
1005
|
-
map(fn) {
|
|
1006
|
-
return new _TransformMessages(
|
|
1007
|
-
pipe(
|
|
1008
|
-
this.effect,
|
|
1009
|
-
Effect.map((messages) => messages.map(fn))
|
|
1010
|
-
)
|
|
1011
|
-
);
|
|
1012
|
-
}
|
|
1013
|
-
/**
|
|
1014
|
-
* Format messages according to the specified format type
|
|
1015
|
-
*/
|
|
1016
|
-
format(formatType) {
|
|
1017
|
-
const result = Effect.runSync(
|
|
1018
|
-
pipe(
|
|
1019
|
-
this.effect,
|
|
1020
|
-
Effect.map((messages) => {
|
|
1021
|
-
if (formatType === "json" /* JSON */) {
|
|
1022
|
-
return JSON.stringify(messages, null, 2);
|
|
1023
|
-
}
|
|
1024
|
-
const formatter = typeOnFormatter[formatType];
|
|
1025
|
-
return formatter(messages);
|
|
1026
|
-
})
|
|
1027
|
-
)
|
|
1028
|
-
);
|
|
1029
|
-
return result;
|
|
1030
|
-
}
|
|
1031
|
-
// Sink methods
|
|
1032
|
-
/**
|
|
1033
|
-
* Convert to array - runs the effect and returns the result
|
|
1034
|
-
return pipe(
|
|
1035
|
-
this.effect,
|
|
1036
|
-
Effect.map((messages) => {
|
|
1037
|
-
if (formatType === FormatType.JSON) {
|
|
1038
|
-
return JSON.stringify(messages, null, 2);
|
|
1039
|
-
}
|
|
1040
|
-
|
|
1041
|
-
const formatter = typeOnFormatter[formatType];
|
|
1042
|
-
return formatter(messages);
|
|
1043
|
-
})
|
|
1044
|
-
);
|
|
1045
|
-
}
|
|
1046
|
-
|
|
1047
|
-
// Sink methods
|
|
1048
|
-
|
|
1049
|
-
/**
|
|
1050
|
-
* Convert to array - runs the effect and returns the result
|
|
1051
|
-
*/
|
|
1052
|
-
toArray() {
|
|
1053
|
-
return Effect.runSync(this.effect);
|
|
1054
|
-
}
|
|
1055
|
-
/**
|
|
1056
|
-
* Convert to string - runs the effect and returns JSON string
|
|
1057
|
-
*/
|
|
1058
|
-
toString() {
|
|
1059
|
-
const result = Effect.runSync(
|
|
1060
|
-
pipe(
|
|
1061
|
-
this.effect,
|
|
1062
|
-
Effect.map((messages) => JSON.stringify(messages, null, 2))
|
|
1063
|
-
)
|
|
1064
|
-
);
|
|
1065
|
-
return result;
|
|
1066
|
-
}
|
|
1067
|
-
/**
|
|
1068
|
-
* Get the count of messages
|
|
1069
|
-
*/
|
|
1070
|
-
count() {
|
|
1071
|
-
const result = Effect.runSync(
|
|
1072
|
-
pipe(
|
|
1073
|
-
this.effect,
|
|
1074
|
-
Effect.map((messages) => messages.length)
|
|
1075
|
-
)
|
|
1076
|
-
);
|
|
1077
|
-
return result;
|
|
1078
|
-
}
|
|
1079
|
-
};
|
|
1080
810
|
var KEBAB_CASE_REGEX = /^[a-z0-9]+(-[a-z0-9]+)*$/;
|
|
1081
811
|
var ChannelName = Brand.refined(
|
|
1082
812
|
(s) => typeof s === "string" && KEBAB_CASE_REGEX.test(s),
|
|
@@ -1829,16 +1559,20 @@ var LayerName = Brand.refined(
|
|
|
1829
1559
|
(s) => Brand.error(`Expected camelCase (e.g. myLayerFoo), got: ${s}`)
|
|
1830
1560
|
);
|
|
1831
1561
|
var DepedencyLayer = {
|
|
1832
|
-
of(
|
|
1833
|
-
const name = LayerName(
|
|
1834
|
-
const
|
|
1835
|
-
|
|
1562
|
+
of(def) {
|
|
1563
|
+
const name = LayerName(def.name);
|
|
1564
|
+
const decodeConfig = Schema.decodeUnknown(def.config);
|
|
1565
|
+
const dep = {
|
|
1836
1566
|
_tag: "SkillDependencyDef",
|
|
1837
1567
|
name,
|
|
1838
|
-
_name:
|
|
1839
|
-
|
|
1840
|
-
|
|
1568
|
+
_name: def.name,
|
|
1569
|
+
config: def.config,
|
|
1570
|
+
decodeConfig,
|
|
1571
|
+
define() {
|
|
1572
|
+
return dep;
|
|
1573
|
+
}
|
|
1841
1574
|
};
|
|
1575
|
+
return dep;
|
|
1842
1576
|
}
|
|
1843
1577
|
};
|
|
1844
1578
|
function toLayerArray(layers) {
|
|
@@ -2184,6 +1918,6 @@ var consoleTracerLayer = Layer.setTracer(
|
|
|
2184
1918
|
consoleTracer
|
|
2185
1919
|
);
|
|
2186
1920
|
|
|
2187
|
-
export { Agent, AgentFactory, AgentNetwork, AgentNetworkEvent, Channel, ChannelName, ConfiguredChannel, DepedencyLayer, EventMetaSchema, ExposeAuthError, ExpressEndpoint, LayerName, NextEndpoint, Pump, Sink, Skill, SocketIoFactory,
|
|
1921
|
+
export { Agent, AgentFactory, AgentNetwork, AgentNetworkEvent, Channel, ChannelName, ConfiguredChannel, DepedencyLayer, EventMetaSchema, ExposeAuthError, ExpressEndpoint, LayerName, NextEndpoint, Pump, Sink, Skill, SocketIoFactory, consoleTracer, consoleTracerLayer, ensureFullWords, formatSSE, httpStreamResponse, isHttpStreamSink, toSSEStream };
|
|
2188
1922
|
//# sourceMappingURL=out.js.map
|
|
2189
1923
|
//# sourceMappingURL=index.js.map
|