@m4trix/core 0.10.0 → 0.11.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.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  export { HttpStreamOptions, MessageStream, Pump, Source, StreamChunk, StreamTransformer, ensureFullWords, httpStreamResponse } from './stream/index.js';
2
2
  export { BaseMessage, Message, Role, SocketEventName, SocketIoFactory, TextMessage, VoiceMessage } from './api/index.js';
3
3
  export { FormatType, MessageFilterType, TransformMessages } from './helper/index.js';
4
- export { Agent, AgentBinding, AgentFactory, AgentNetwork, AgentNetworkEvent, AgentNetworkEventDef, AnyAgent, AuthResult, Channel, ChannelDef, ChannelName, ConfiguredChannel, ContextEvents, EmitPayload, EnvelopeLike, EventEnvelope, EventMeta, EventMetaSchema, EventPlane, ExposeAuthError, ExposeOptions, ExposeRequest, ExposeSelect, ExposedAPI, ExposedStream, ExpressEndpoint, ExpressEndpointOptions, ExpressHandler, ExpressRequest, ExpressResponse, NextEndpoint, NextEndpointOptions, NextGetHandler, OnRequestContext, RunEvents, SetupContext, Sink, SinkDef, SpawnCallbackContext, SpawnFn, SpawnerBuilder, StreamFactory, UnboundEvent, consoleTracer, consoleTracerLayer, formatSSE, isHttpStreamSink, toSSEStream } from './matrix/index.js';
4
+ export { Agent, AgentBinding, AgentFactory, AgentNetwork, AgentNetworkEvent, AgentNetworkEventDef, AnyAgent, AuthResult, Channel, ChannelDef, ChannelName, ConfiguredChannel, ContextEvents, 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, SkillDependency, SkillDependencyDef, SkillInstance, SkillRuntimeOptions, SpawnCallbackContext, SpawnFn, SpawnerBuilder, StreamFactory, UnboundEvent, consoleTracer, consoleTracerLayer, formatSSE, isHttpStreamSink, toSSEStream } from './matrix/index.js';
5
5
  export { Schema as S } from 'effect';
6
6
  import 'socket.io';
7
7
  import '@langchain/core/messages';
package/dist/index.js CHANGED
@@ -1823,6 +1823,157 @@ var AgentFactory = class _AgentFactory {
1823
1823
  );
1824
1824
  }
1825
1825
  };
1826
+ var CAMEL_CASE_REGEX = /^[a-z][a-zA-Z0-9]*$/;
1827
+ var LayerName = Brand.refined(
1828
+ (s) => typeof s === "string" && CAMEL_CASE_REGEX.test(s),
1829
+ (s) => Brand.error(`Expected camelCase (e.g. myLayerFoo), got: ${s}`)
1830
+ );
1831
+ var SkillDependency = {
1832
+ of(config) {
1833
+ const name = LayerName(config.name);
1834
+ const decode = Schema.decodeUnknown(config.shape);
1835
+ return {
1836
+ _tag: "SkillDependencyDef",
1837
+ name,
1838
+ _name: config.name,
1839
+ shape: config.shape,
1840
+ decode
1841
+ };
1842
+ }
1843
+ };
1844
+ function toLayerArray(layers) {
1845
+ if (layers.length === 1 && Array.isArray(layers[0])) {
1846
+ return layers[0];
1847
+ }
1848
+ return [...layers];
1849
+ }
1850
+ function assertUniqueLayerNames(layers) {
1851
+ const seen = /* @__PURE__ */ new Set();
1852
+ for (const dep of layers) {
1853
+ const key = dep.name;
1854
+ if (seen.has(key)) {
1855
+ throw new Error(`Duplicate layer name: ${key}`);
1856
+ }
1857
+ seen.add(key);
1858
+ }
1859
+ }
1860
+ var Skill = class _Skill {
1861
+ constructor(params) {
1862
+ this._inputSchema = params.inputSchema;
1863
+ this._chunkSchema = params.chunkSchema;
1864
+ this._doneSchema = params.doneSchema;
1865
+ this._layers = params.layers;
1866
+ this._defineFn = params.defineFn;
1867
+ }
1868
+ getState() {
1869
+ return {
1870
+ inputSchema: this._inputSchema,
1871
+ chunkSchema: this._chunkSchema,
1872
+ doneSchema: this._doneSchema,
1873
+ layers: this._layers,
1874
+ defineFn: this._defineFn
1875
+ };
1876
+ }
1877
+ static of(_options) {
1878
+ return new _Skill({
1879
+ layers: []
1880
+ });
1881
+ }
1882
+ input(schema) {
1883
+ return new _Skill({
1884
+ ...this.getState(),
1885
+ inputSchema: schema
1886
+ });
1887
+ }
1888
+ chunk(schema) {
1889
+ return new _Skill({
1890
+ ...this.getState(),
1891
+ chunkSchema: schema
1892
+ });
1893
+ }
1894
+ done(schema) {
1895
+ return new _Skill({
1896
+ ...this.getState(),
1897
+ doneSchema: schema
1898
+ });
1899
+ }
1900
+ use(...layers) {
1901
+ const normalized = toLayerArray(layers);
1902
+ const allLayers = [...this._layers, ...normalized];
1903
+ assertUniqueLayerNames(allLayers);
1904
+ return new _Skill({
1905
+ ...this.getState(),
1906
+ layers: allLayers
1907
+ });
1908
+ }
1909
+ define(fn) {
1910
+ const state = this.getState();
1911
+ const inputSchema = state.inputSchema;
1912
+ const chunkSchema = state.chunkSchema;
1913
+ const doneSchema = state.doneSchema;
1914
+ const defineFn = fn;
1915
+ if (!inputSchema || !chunkSchema || !doneSchema || !defineFn) {
1916
+ throw new Error(
1917
+ "Skill.define requires input(), chunk(), and done() to be called before define()"
1918
+ );
1919
+ }
1920
+ const decodeInput = Schema.decodeUnknown(inputSchema);
1921
+ const decodeChunk = Schema.decodeUnknown(chunkSchema);
1922
+ const decodeDone = Schema.decodeUnknown(doneSchema);
1923
+ const runDefine = async (input, runtime) => {
1924
+ const layersObj = runtime?.layers ?? {};
1925
+ const chunks = [];
1926
+ const emit = (chunk) => {
1927
+ const decoded = Effect.runSync(
1928
+ decodeChunk(chunk)
1929
+ );
1930
+ chunks.push(decoded);
1931
+ };
1932
+ const done = await defineFn({
1933
+ input,
1934
+ emit,
1935
+ layers: layersObj
1936
+ });
1937
+ const decodedDone = Effect.runSync(
1938
+ decodeDone(done)
1939
+ );
1940
+ return { chunks, done: decodedDone };
1941
+ };
1942
+ return {
1943
+ invokeStream: async function* (input, runtime) {
1944
+ const decodedInput = Effect.runSync(
1945
+ decodeInput(input)
1946
+ );
1947
+ const layersObj = runtime?.layers ?? {};
1948
+ const chunks = [];
1949
+ const emit = (chunk) => {
1950
+ const decoded = Effect.runSync(
1951
+ decodeChunk(chunk)
1952
+ );
1953
+ chunks.push(decoded);
1954
+ };
1955
+ const done = await defineFn({
1956
+ input: decodedInput,
1957
+ emit,
1958
+ layers: layersObj
1959
+ });
1960
+ const decodedDone = Effect.runSync(
1961
+ decodeDone(done)
1962
+ );
1963
+ for (const c of chunks) {
1964
+ yield c;
1965
+ }
1966
+ yield { _tag: "Done", done: decodedDone };
1967
+ },
1968
+ invoke: async (input, runtime) => {
1969
+ const decodedInput = Effect.runSync(
1970
+ decodeInput(input)
1971
+ );
1972
+ return runDefine(decodedInput, runtime);
1973
+ }
1974
+ };
1975
+ }
1976
+ };
1826
1977
 
1827
1978
  // src/matrix/io/protocols/sse.ts
1828
1979
  function formatSSE(envelope) {
@@ -2033,6 +2184,6 @@ var consoleTracerLayer = Layer.setTracer(
2033
2184
  consoleTracer
2034
2185
  );
2035
2186
 
2036
- export { Agent, AgentFactory, AgentNetwork, AgentNetworkEvent, Channel, ChannelName, ConfiguredChannel, EventMetaSchema, ExposeAuthError, ExpressEndpoint, NextEndpoint, Pump, Sink, SocketIoFactory, TransformMessages, consoleTracer, consoleTracerLayer, ensureFullWords, formatSSE, httpStreamResponse, isHttpStreamSink, toSSEStream };
2187
+ export { Agent, AgentFactory, AgentNetwork, AgentNetworkEvent, Channel, ChannelName, ConfiguredChannel, EventMetaSchema, ExposeAuthError, ExpressEndpoint, LayerName, NextEndpoint, Pump, Sink, Skill, SkillDependency, SocketIoFactory, TransformMessages, consoleTracer, consoleTracerLayer, ensureFullWords, formatSSE, httpStreamResponse, isHttpStreamSink, toSSEStream };
2037
2188
  //# sourceMappingURL=out.js.map
2038
2189
  //# sourceMappingURL=index.js.map