@m4trix/core 0.10.0 → 0.11.1
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 +154 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +75 -3
- package/dist/index.js +152 -1
- package/dist/index.js.map +1 -1
- package/dist/matrix/index.cjs +154 -0
- package/dist/matrix/index.cjs.map +1 -1
- package/dist/matrix/index.d.ts +72 -1
- package/dist/matrix/index.js +152 -1
- package/dist/matrix/index.js.map +1 -1
- package/package.json +1 -19
- package/dist/api/index.cjs +0 -83
- package/dist/api/index.cjs.map +0 -1
- package/dist/api/index.d.ts +0 -74
- package/dist/api/index.js +0 -81
- package/dist/api/index.js.map +0 -1
- package/dist/react/index.cjs +0 -1324
- package/dist/react/index.cjs.map +0 -1
- package/dist/react/index.d.ts +0 -213
- package/dist/react/index.js +0 -1316
- package/dist/react/index.js.map +0 -1
- package/dist/ui/index.cjs +0 -316
- package/dist/ui/index.cjs.map +0 -1
- package/dist/ui/index.d.ts +0 -30
- package/dist/ui/index.js +0 -314
- package/dist/ui/index.js.map +0 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,80 @@
|
|
|
1
1
|
export { HttpStreamOptions, MessageStream, Pump, Source, StreamChunk, StreamTransformer, ensureFullWords, httpStreamResponse } from './stream/index.js';
|
|
2
|
-
|
|
2
|
+
import { Socket } from 'socket.io';
|
|
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
|
-
import 'socket.io';
|
|
7
6
|
import '@langchain/core/messages';
|
|
8
7
|
import 'effect/ParseResult';
|
|
8
|
+
|
|
9
|
+
type Role = 'system' | 'user' | 'assistant' | string;
|
|
10
|
+
interface BaseMessage {
|
|
11
|
+
/** Unique across the conversation */
|
|
12
|
+
id: string;
|
|
13
|
+
role: Role;
|
|
14
|
+
/** ISO string or Date; normalized when you receive it */
|
|
15
|
+
timestamp: string;
|
|
16
|
+
}
|
|
17
|
+
interface TextMessage extends BaseMessage {
|
|
18
|
+
kind: 'text';
|
|
19
|
+
/** two modes: plain vs. structured */
|
|
20
|
+
content: string | {
|
|
21
|
+
format: 'markdown' | 'html';
|
|
22
|
+
body: string;
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
interface VoiceMessage extends BaseMessage {
|
|
26
|
+
kind: 'voice';
|
|
27
|
+
/** raw bytes or reference */
|
|
28
|
+
data: ArrayBuffer | Blob;
|
|
29
|
+
format: 'mp3' | 'wav' | string;
|
|
30
|
+
durationMs: number;
|
|
31
|
+
/** optional transcript if you run speech-to-text */
|
|
32
|
+
transcript?: string;
|
|
33
|
+
}
|
|
34
|
+
type Message = TextMessage | VoiceMessage;
|
|
35
|
+
|
|
36
|
+
type SocketEventName = 'conversation:create' | 'voice:input_file' | 'voice:input_chunk' | 'voice:input_commit' | 'voice:output_delta' | 'voice:output_commit' | 'voice:output_file' | 'voice:output_transcript_delta' | 'voice:output_transcript_full';
|
|
37
|
+
|
|
38
|
+
type HookContext<T> = {
|
|
39
|
+
socket: T;
|
|
40
|
+
hooks: Hooks<T>;
|
|
41
|
+
};
|
|
42
|
+
type Hooks<SocketType> = {
|
|
43
|
+
onConversationCreated?: (conversationId: string, context: HookContext<SocketType>) => void;
|
|
44
|
+
onVoiceInputFile?: (file: Blob | Uint8Array, context: HookContext<SocketType>) => void;
|
|
45
|
+
onVoiceInputChunk?: (chunk: Uint8Array, context: HookContext<SocketType>) => void;
|
|
46
|
+
onVoiceInputCommit?: (context: HookContext<SocketType>) => void;
|
|
47
|
+
onVoiceOutputDelta?: (chunk: Uint8Array, context: HookContext<SocketType>) => void;
|
|
48
|
+
onVoiceOutputCommit?: (context: HookContext<SocketType>) => void;
|
|
49
|
+
onVoiceOutputFile?: (file: Blob | Uint8Array, context: HookContext<SocketType>) => void;
|
|
50
|
+
onVoiceOutputTranscriptDelta?: (transcriptChunk: string, context: HookContext<SocketType>) => void;
|
|
51
|
+
onVoiceOutputTranscriptFull?: (transcript: string, context: HookContext<SocketType>) => void;
|
|
52
|
+
};
|
|
53
|
+
type BaseSetupSocketHandlersParams<SocketType> = {
|
|
54
|
+
enableVoiceEvents: boolean;
|
|
55
|
+
enableChatEvents: boolean;
|
|
56
|
+
enableTranscriptEvents: boolean;
|
|
57
|
+
prefix?: string;
|
|
58
|
+
hooks?: Hooks<SocketType>;
|
|
59
|
+
};
|
|
60
|
+
/**
|
|
61
|
+
* Extra keys supplied by the caller are kept,
|
|
62
|
+
* but if they collide with a base key the base type wins.
|
|
63
|
+
*/
|
|
64
|
+
type SetupSocketHandlersParams<SocketType, Extra = Record<string, never>> = Omit<Extra, keyof BaseSetupSocketHandlersParams<SocketType>> & BaseSetupSocketHandlersParams<SocketType>;
|
|
65
|
+
|
|
66
|
+
declare class SocketIoFactory {
|
|
67
|
+
private socket;
|
|
68
|
+
private prefix;
|
|
69
|
+
private hooks;
|
|
70
|
+
private constructor();
|
|
71
|
+
static setupSocketHandlers({ enableVoiceEvents, enableChatEvents, enableTranscriptEvents, prefix, socket, hooks, }: SetupSocketHandlersParams<Socket, {
|
|
72
|
+
socket: Socket;
|
|
73
|
+
}>): void;
|
|
74
|
+
private setupVoiceEvents;
|
|
75
|
+
private setupChatEvents;
|
|
76
|
+
private setupTranscriptEvents;
|
|
77
|
+
private prefixEvent;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export { BaseMessage, Message, Role, SocketEventName, SocketIoFactory, TextMessage, VoiceMessage };
|
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
|