@m4trix/core 0.15.0 → 0.15.2

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.
@@ -452,6 +452,106 @@ declare class EventAggregatorInstance<TTriggerEvent, TEmitEvent> {
452
452
  }): Promise<void>;
453
453
  }
454
454
 
455
+ /**
456
+ * A Tracer that logs spans to console when they end. No optional dependencies
457
+ * required. Use `consoleTracerLayer` when running your program to enable.
458
+ *
459
+ * @example
460
+ * ```ts
461
+ * import { Effect } from 'effect';
462
+ * import { AgentNetwork, consoleTracerLayer } from '@m4trix/core/matrix';
463
+ *
464
+ * const network = AgentNetwork.setup(({ ... }) => { ... });
465
+ * const program = network.run().pipe(
466
+ * Effect.provide(consoleTracerLayer),
467
+ * Effect.scoped
468
+ * );
469
+ * Effect.runPromise(program);
470
+ * ```
471
+ */
472
+ declare const consoleTracer: Tracer.Tracer;
473
+ /**
474
+ * Layer that provides the console tracer. Pipe your program with
475
+ * `Effect.provide(consoleTracerLayer)` before running to see spans in stdout.
476
+ */
477
+ declare const consoleTracerLayer: Layer.Layer<never>;
478
+
479
+ /** Thrown when auth denies the request */
480
+ declare class ExposeAuthError extends Error {
481
+ readonly status: number;
482
+ constructor(message: string, status?: number);
483
+ }
484
+
485
+ /** Format a single SSE message (event + data) */
486
+ declare function formatSSE(envelope: Envelope): string;
487
+ /** Create a ReadableStream that encodes envelopes as SSE */
488
+ declare function toSSEStream(source: AsyncIterable<Envelope>, signal?: AbortSignal | null): ReadableStream<Uint8Array>;
489
+
490
+ /** Next.js App Router GET/POST handler signature */
491
+ type NextGetHandler = (request: Request) => Promise<Response>;
492
+ /** Options for NextEndpoint.from() - required to define how request maps to contextId and runId */
493
+ type NextEndpointOptions = {
494
+ requestToContextId: (request: Request) => string;
495
+ requestToRunId: (request: Request) => string;
496
+ };
497
+ /**
498
+ * Adapter for Next.js App Router. Maps an ExposedAPI to a route handler
499
+ * that streams events as SSE. Use for both GET and POST; POST with JSON body
500
+ * is recommended for passing the start event payload.
501
+ *
502
+ * @example
503
+ * const api = agentNetwork.expose({ protocol: "sse", auth, select });
504
+ * const handler = NextEndpoint.from(api, {
505
+ * requestToContextId: (req) => req.headers.get('x-correlation-id') ?? crypto.randomUUID(),
506
+ * requestToRunId: () => crypto.randomUUID(),
507
+ * }).handler();
508
+ * export const GET = handler;
509
+ * export const POST = handler;
510
+ */
511
+ declare const NextEndpoint: {
512
+ from(api: ExposedAPI, options: NextEndpointOptions): {
513
+ handler(): NextGetHandler;
514
+ };
515
+ };
516
+
517
+ /** Minimal Express-like request (compatible with express.Request) */
518
+ type ExpressRequest = {
519
+ on(event: 'close', fn: () => void): void;
520
+ };
521
+ /** Options for ExpressEndpoint.from() - required to define how request maps to contextId and runId */
522
+ type ExpressEndpointOptions = {
523
+ requestToContextId: (req: ExpressRequest) => string;
524
+ requestToRunId: (req: ExpressRequest) => string;
525
+ };
526
+ /** Minimal Express-like response (compatible with express.Response) */
527
+ type ExpressResponse = {
528
+ setHeader(name: string, value: string | number): void;
529
+ flushHeaders?(): void;
530
+ write(chunk: Uint8Array): void;
531
+ flush?(): void;
532
+ end(): void;
533
+ status(code: number): ExpressResponse;
534
+ send(body: string): void;
535
+ };
536
+ /** Express route handler signature */
537
+ type ExpressHandler = (req: ExpressRequest, res: ExpressResponse) => void | Promise<void>;
538
+ /**
539
+ * Adapter for Express. Maps an ExposedAPI to an Express route handler
540
+ * that streams events as SSE.
541
+ *
542
+ * @example
543
+ * const api = agentNetwork.expose({ protocol: "sse", auth, select });
544
+ * app.get("/events", ExpressEndpoint.from(api, {
545
+ * requestToContextId: (req) => req.headers?.['x-correlation-id'] ?? crypto.randomUUID(),
546
+ * requestToRunId: () => crypto.randomUUID(),
547
+ * }).handler());
548
+ */
549
+ declare const ExpressEndpoint: {
550
+ from(api: ExposedAPI, options: ExpressEndpointOptions): {
551
+ handler(): ExpressHandler;
552
+ };
553
+ };
554
+
455
555
  /**
456
556
  * Branded type for layer/dependency names. Enforces camelCase at runtime via refinement.
457
557
  * Used internally for parsing, validation, and uniqueness enforcement across layers.
@@ -478,7 +578,9 @@ type DependenciesToLayers<T> = T extends DepedencyLayerDef<infer N, infer DepTyp
478
578
  } : never;
479
579
  type UnionToIntersection<U> = (U extends unknown ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
480
580
  /** Build layers object from union of dependency types */
481
- type LayersFromDeps<T extends DepedencyLayerDef<string, unknown, Schema.Schema.Any>> = [T] extends [never] ? Record<string, never> : UnionToIntersection<DependenciesToLayers<T>>;
581
+ type LayersFromDeps<T extends DepedencyLayerDef<string, unknown, Schema.Schema.Any>> = [
582
+ T
583
+ ] extends [never] ? Record<string, never> : UnionToIntersection<DependenciesToLayers<T>>;
482
584
  type DepedencyLayerBuilder<N extends string, ConfigSchema extends Schema.Schema.Any> = DepedencyLayerDef<N, object, ConfigSchema> & {
483
585
  define<_DepType>(): 'config' extends keyof _DepType ? ReservedConfigError : DepedencyLayerDef<N, _DepType, ConfigSchema>;
484
586
  };
@@ -541,104 +643,4 @@ declare class Skill<TInput = unknown, TChunk = unknown, TDone = unknown, TDeps e
541
643
  define(fn: DefineFn<TInput, TChunk, TDone, LayersFromDeps<TDeps>>): SkillInstance<TInput, TChunk, TDone, LayersFromDeps<TDeps>>;
542
644
  }
543
645
 
544
- /** Thrown when auth denies the request */
545
- declare class ExposeAuthError extends Error {
546
- readonly status: number;
547
- constructor(message: string, status?: number);
548
- }
549
-
550
- /** Format a single SSE message (event + data) */
551
- declare function formatSSE(envelope: Envelope): string;
552
- /** Create a ReadableStream that encodes envelopes as SSE */
553
- declare function toSSEStream(source: AsyncIterable<Envelope>, signal?: AbortSignal | null): ReadableStream<Uint8Array>;
554
-
555
- /** Next.js App Router GET/POST handler signature */
556
- type NextGetHandler = (request: Request) => Promise<Response>;
557
- /** Options for NextEndpoint.from() - required to define how request maps to contextId and runId */
558
- type NextEndpointOptions = {
559
- requestToContextId: (request: Request) => string;
560
- requestToRunId: (request: Request) => string;
561
- };
562
- /**
563
- * Adapter for Next.js App Router. Maps an ExposedAPI to a route handler
564
- * that streams events as SSE. Use for both GET and POST; POST with JSON body
565
- * is recommended for passing the start event payload.
566
- *
567
- * @example
568
- * const api = agentNetwork.expose({ protocol: "sse", auth, select });
569
- * const handler = NextEndpoint.from(api, {
570
- * requestToContextId: (req) => req.headers.get('x-correlation-id') ?? crypto.randomUUID(),
571
- * requestToRunId: () => crypto.randomUUID(),
572
- * }).handler();
573
- * export const GET = handler;
574
- * export const POST = handler;
575
- */
576
- declare const NextEndpoint: {
577
- from(api: ExposedAPI, options: NextEndpointOptions): {
578
- handler(): NextGetHandler;
579
- };
580
- };
581
-
582
- /** Minimal Express-like request (compatible with express.Request) */
583
- type ExpressRequest = {
584
- on(event: 'close', fn: () => void): void;
585
- };
586
- /** Options for ExpressEndpoint.from() - required to define how request maps to contextId and runId */
587
- type ExpressEndpointOptions = {
588
- requestToContextId: (req: ExpressRequest) => string;
589
- requestToRunId: (req: ExpressRequest) => string;
590
- };
591
- /** Minimal Express-like response (compatible with express.Response) */
592
- type ExpressResponse = {
593
- setHeader(name: string, value: string | number): void;
594
- flushHeaders?(): void;
595
- write(chunk: Uint8Array): void;
596
- flush?(): void;
597
- end(): void;
598
- status(code: number): ExpressResponse;
599
- send(body: string): void;
600
- };
601
- /** Express route handler signature */
602
- type ExpressHandler = (req: ExpressRequest, res: ExpressResponse) => void | Promise<void>;
603
- /**
604
- * Adapter for Express. Maps an ExposedAPI to an Express route handler
605
- * that streams events as SSE.
606
- *
607
- * @example
608
- * const api = agentNetwork.expose({ protocol: "sse", auth, select });
609
- * app.get("/events", ExpressEndpoint.from(api, {
610
- * requestToContextId: (req) => req.headers?.['x-correlation-id'] ?? crypto.randomUUID(),
611
- * requestToRunId: () => crypto.randomUUID(),
612
- * }).handler());
613
- */
614
- declare const ExpressEndpoint: {
615
- from(api: ExposedAPI, options: ExpressEndpointOptions): {
616
- handler(): ExpressHandler;
617
- };
618
- };
619
-
620
- /**
621
- * A Tracer that logs spans to console when they end. No optional dependencies
622
- * required. Use `consoleTracerLayer` when running your program to enable.
623
- *
624
- * @example
625
- * ```ts
626
- * import { Effect } from 'effect';
627
- * import { AgentNetwork, consoleTracerLayer } from '@m4trix/core/matrix';
628
- *
629
- * const network = AgentNetwork.setup(({ ... }) => { ... });
630
- * const program = network.run().pipe(
631
- * Effect.provide(consoleTracerLayer),
632
- * Effect.scoped
633
- * );
634
- * Effect.runPromise(program);
635
- * ```
636
- */
637
- declare const consoleTracer: Tracer.Tracer;
638
- /**
639
- * Layer that provides the console tracer. Pipe your program with
640
- * `Effect.provide(consoleTracerLayer)` before running to see spans in stdout.
641
- */
642
- declare const consoleTracerLayer: Layer.Layer<never>;
643
-
644
646
  export { Agent, AgentBinding, AgentFactory, AgentNetwork, AgentNetworkEvent, AgentNetworkEventDef, AnyAgent, AuthResult, Channel, ChannelDef, ChannelName, ConfiguredChannel, ContextEvents, DepedencyLayer, DepedencyLayerDef, Done, EmitPayload$1 as EmitPayload, EnvelopeLike, EventAggregator, EventAggregatorInstance, EventEnvelope$1 as 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 };