@olane/o-node 0.7.34 → 0.7.35

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.
@@ -4,6 +4,5 @@ export interface oNodeConnectionManagerConfig extends oConnectionManagerConfig {
4
4
  p2pNode: Libp2p;
5
5
  runOnLimitedConnection?: boolean;
6
6
  originAddress?: string;
7
- useLengthPrefixing?: boolean;
8
7
  }
9
8
  //# sourceMappingURL=o-node-connection-manager.config.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"o-node-connection-manager.config.d.ts","sourceRoot":"","sources":["../../../../src/connection/interfaces/o-node-connection-manager.config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,eAAe,CAAC;AACzD,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAEzC,MAAM,WAAW,4BAA6B,SAAQ,wBAAwB;IAC5E,OAAO,EAAE,MAAM,CAAC;IAChB,sBAAsB,CAAC,EAAE,OAAO,CAAC;IACjC,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,kBAAkB,CAAC,EAAE,OAAO,CAAC;CAC9B"}
1
+ {"version":3,"file":"o-node-connection-manager.config.d.ts","sourceRoot":"","sources":["../../../../src/connection/interfaces/o-node-connection-manager.config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,eAAe,CAAC;AACzD,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAEzC,MAAM,WAAW,4BAA6B,SAAQ,wBAAwB;IAC5E,OAAO,EAAE,MAAM,CAAC;IAChB,sBAAsB,CAAC,EAAE,OAAO,CAAC;IACjC,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB"}
@@ -3,10 +3,5 @@ import { oConnectionConfig } from '@olane/o-core';
3
3
  export interface oNodeConnectionConfig extends oConnectionConfig {
4
4
  p2pConnection: Connection;
5
5
  runOnLimitedConnection?: boolean;
6
- /**
7
- * Enable length-prefixed streaming (libp2p v3 best practice)
8
- * @default false (for backward compatibility)
9
- */
10
- useLengthPrefixing?: boolean;
11
6
  }
12
7
  //# sourceMappingURL=o-node-connection.config.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"o-node-connection.config.d.ts","sourceRoot":"","sources":["../../../../src/connection/interfaces/o-node-connection.config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAElD,MAAM,WAAW,qBAAsB,SAAQ,iBAAiB;IAC9D,aAAa,EAAE,UAAU,CAAC;IAC1B,sBAAsB,CAAC,EAAE,OAAO,CAAC;IACjC;;;OAGG;IACH,kBAAkB,CAAC,EAAE,OAAO,CAAC;CAC9B"}
1
+ {"version":3,"file":"o-node-connection.config.d.ts","sourceRoot":"","sources":["../../../../src/connection/interfaces/o-node-connection.config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAElD,MAAM,WAAW,qBAAsB,SAAQ,iBAAiB;IAC9D,aAAa,EAAE,UAAU,CAAC;IAC1B,sBAAsB,CAAC,EAAE,OAAO,CAAC;CAClC"}
@@ -1 +1 @@
1
- {"version":3,"file":"o-node-connection.d.ts","sourceRoot":"","sources":["../../../src/connection/o-node-connection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AACrD,OAAO,EAEL,WAAW,EAGX,QAAQ,EACR,SAAS,EACV,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,qBAAqB,EAAE,MAAM,0CAA0C,CAAC;AACjF,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAGpD,qBAAa,eAAgB,SAAQ,WAAW;IAIlC,SAAS,CAAC,QAAQ,CAAC,MAAM,EAAE,qBAAqB;IAHrD,aAAa,EAAE,UAAU,CAAC;IACjC,SAAS,CAAC,aAAa,EAAE,aAAa,CAAC;gBAER,MAAM,EAAE,qBAAqB;IAM5D,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM;IAmBlB,iBAAiB,IAAI,OAAO,CAAC,MAAM,CAAC;IAmBpC,QAAQ,CAAC,OAAO,EAAE,QAAQ,GAAG,OAAO,CAAC,SAAS,CAAC;IAkD/C,YAAY,CAAC,MAAM,EAAE,MAAM;IAQ3B,KAAK,CAAC,KAAK,EAAE,KAAK;IAMlB,KAAK;CAKZ"}
1
+ {"version":3,"file":"o-node-connection.d.ts","sourceRoot":"","sources":["../../../src/connection/o-node-connection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AACrD,OAAO,EAEL,WAAW,EAGX,QAAQ,EACR,SAAS,EACV,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,qBAAqB,EAAE,MAAM,0CAA0C,CAAC;AACjF,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAGpD,qBAAa,eAAgB,SAAQ,WAAW;IAIlC,SAAS,CAAC,QAAQ,CAAC,MAAM,EAAE,qBAAqB;IAHrD,aAAa,EAAE,UAAU,CAAC;IACjC,SAAS,CAAC,aAAa,EAAE,aAAa,CAAC;gBAER,MAAM,EAAE,qBAAqB;IAM5D,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM;IAmBlB,iBAAiB,IAAI,OAAO,CAAC,MAAM,CAAC;IAkBpC,QAAQ,CAAC,OAAO,EAAE,QAAQ,GAAG,OAAO,CAAC,SAAS,CAAC;IA6C/C,YAAY,CAAC,MAAM,EAAE,MAAM;IAQ3B,KAAK,CAAC,KAAK,EAAE,KAAK;IAMlB,KAAK;CAKZ"}
@@ -28,7 +28,6 @@ export class oNodeConnection extends oConnection {
28
28
  runOnLimitedConnection: this.config.runOnLimitedConnection ?? true,
29
29
  reusePolicy: 'none', // Default policy, can be overridden in subclasses
30
30
  drainTimeoutMs: this.config.drainTimeoutMs,
31
- useLengthPrefixing: this.config.useLengthPrefixing ?? true,
32
31
  };
33
32
  return this.streamHandler.getOrCreateStream(this.p2pConnection, this.nextHopAddress.protocol, streamConfig);
34
33
  }
@@ -43,18 +42,12 @@ export class oNodeConnection extends oConnection {
43
42
  signal: this.abortSignal,
44
43
  drainTimeoutMs: this.config.drainTimeoutMs,
45
44
  reusePolicy: 'none', // Default policy
46
- useLengthPrefixing: this.config.useLengthPrefixing ?? true,
47
45
  };
48
46
  // Send the request with backpressure handling
49
47
  const data = new TextEncoder().encode(request.toString());
50
- // Use length-prefixed encoding if enabled
51
- if (streamConfig.useLengthPrefixing) {
52
- this.logger.info('Length prefix enabled...');
53
- await this.streamHandler.sendLengthPrefixed(stream, data, streamConfig);
54
- }
55
- else {
56
- await this.streamHandler.send(stream, data, streamConfig);
57
- }
48
+ // Send using length-prefixed encoding
49
+ this.logger.info('Sending length-prefixed message...');
50
+ await this.streamHandler.sendLengthPrefixed(stream, data, streamConfig);
58
51
  // Handle response using StreamHandler
59
52
  // Pass request handler if configured to enable bidirectional stream processing
60
53
  // Pass request ID to enable proper response correlation on shared streams
@@ -1 +1 @@
1
- {"version":3,"file":"o-node-connection.manager.d.ts","sourceRoot":"","sources":["../../../src/connection/o-node-connection.manager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAChF,OAAO,EAAE,MAAM,EAAE,UAAU,EAAU,MAAM,iBAAiB,CAAC;AAC7D,OAAO,EAAE,4BAA4B,EAAE,MAAM,kDAAkD,CAAC;AAEhG,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAGzD,qBAAa,sBAAuB,SAAQ,kBAAkB;IAQhD,QAAQ,CAAC,MAAM,EAAE,4BAA4B;IAPzD,SAAS,CAAC,OAAO,EAAE,MAAM,CAAC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AAwB,CAAC;AAGzD,qBAAa,sBAAuB,SAAQ,kBAAkB;IAQhD,QAAQ,CAAC,MAAM,EAAE,4BAA4B;IAPzD,SAAS,CAAC,OAAO,EAAE,MAAM,CAAC;IAC1B,OAAO,CAAC,oBAAoB,CAAC,CAAS;IACtC,OAAO,CAAC,qBAAqB,CAAC,CAAS;IACvC,OAAO,CAAC,yBAAyB,CAAsC;IACvE,OAAO,CAAC,0BAA0B,CACtB;gBAES,MAAM,EAAE,4BAA4B;IAWzD;;OAEG;IACH,OAAO,CAAC,wBAAwB;IAsBhC;;;;;;OAMG;IACH,OAAO,CAAC,0BAA0B;IAiBlC;;;;OAIG;IACH,OAAO,CAAC,oBAAoB;IAatB,qBAAqB,CACzB,cAAc,EAAE,QAAQ,EACxB,OAAO,EAAE,QAAQ,GAChB,OAAO,CAAC,UAAU,CAAC;YA+DR,WAAW;IAwBzB;;;;OAIG;IACG,OAAO,CAAC,MAAM,EAAE,iBAAiB,GAAG,OAAO,CAAC,eAAe,CAAC;IA8BlE;;;;OAIG;IACH,QAAQ,CAAC,OAAO,EAAE,QAAQ,GAAG,OAAO;IAwCpC;;;;OAIG;IACH,yBAAyB,CAAC,OAAO,EAAE,QAAQ,GAAG,UAAU,GAAG,IAAI;IA+C/D;;;OAGG;IACH,aAAa,IAAI;QACf,iBAAiB,EAAE,MAAM,CAAC;QAC1B,YAAY,EAAE,MAAM,CAAC;QACrB,iBAAiB,EAAE,KAAK,CAAC;YAAE,MAAM,EAAE,MAAM,CAAC;YAAC,MAAM,EAAE,MAAM,CAAA;SAAE,CAAC,CAAC;KAC9D;IAaD;;;OAGG;IACH,uBAAuB,IAAI,MAAM;CAgBlC"}
@@ -148,7 +148,6 @@ export class oNodeConnectionManager extends oConnectionManager {
148
148
  isStream: config.isStream ?? false,
149
149
  abortSignal: config.abortSignal,
150
150
  runOnLimitedConnection: this.config.runOnLimitedConnection ?? false,
151
- useLengthPrefixing: this.config.useLengthPrefixing,
152
151
  requestHandler: config.requestHandler ?? undefined,
153
152
  });
154
153
  return connection;
@@ -34,19 +34,6 @@ export interface StreamHandlerConfig {
34
34
  * AbortSignal for cancellation
35
35
  */
36
36
  signal?: AbortSignal;
37
- /**
38
- * Enable length-prefixed streaming (libp2p v3 best practice)
39
- * When enabled, all messages are prefixed with a varint indicating message length
40
- * This provides proper message boundaries and eliminates concatenation issues
41
- * @default false (for backward compatibility)
42
- */
43
- useLengthPrefixing?: boolean;
44
- /**
45
- * Auto-detect protocol (length-prefixed vs raw JSON)
46
- * When enabled, automatically detects the protocol by examining first byte
47
- * @default false
48
- */
49
- autoDetectProtocol?: boolean;
50
37
  }
51
38
  /**
52
39
  * Context for stream lifecycle operations
@@ -1 +1 @@
1
- {"version":3,"file":"stream-handler.config.d.ts","sourceRoot":"","sources":["../../../src/connection/stream-handler.config.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAEhD;;GAEG;AACH,MAAM,MAAM,iBAAiB,GAAG,MAAM,GAAG,OAAO,GAAG,MAAM,CAAC;AAE1D;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC;;;;;OAKG;IACH,WAAW,CAAC,EAAE,iBAAiB,CAAC;IAEhC;;;OAGG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;IAExB;;;OAGG;IACH,sBAAsB,CAAC,EAAE,OAAO,CAAC;IAEjC;;;OAGG;IACH,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAE5B;;OAEG;IACH,MAAM,CAAC,EAAE,WAAW,CAAC;IAErB;;;;;OAKG;IACH,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAE7B;;;;OAIG;IACH,kBAAkB,CAAC,EAAE,OAAO,CAAC;CAC9B;AAED;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,mBAAmB,CAAC;CAC7B"}
1
+ {"version":3,"file":"stream-handler.config.d.ts","sourceRoot":"","sources":["../../../src/connection/stream-handler.config.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAEhD;;GAEG;AACH,MAAM,MAAM,iBAAiB,GAAG,MAAM,GAAG,OAAO,GAAG,MAAM,CAAC;AAE1D;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC;;;;;OAKG;IACH,WAAW,CAAC,EAAE,iBAAiB,CAAC;IAEhC;;;OAGG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;IAExB;;;OAGG;IACH,sBAAsB,CAAC,EAAE,OAAO,CAAC;IAEjC;;;OAGG;IACH,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAE5B;;OAEG;IACH,MAAM,CAAC,EAAE,WAAW,CAAC;CACtB;AAED;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,mBAAmB,CAAC;CAC7B"}
@@ -28,9 +28,18 @@ export declare class StreamHandler {
28
28
  */
29
29
  isResponse(message: any): boolean;
30
30
  /**
31
- * Decodes a stream message event into a JSON object
31
+ * Extracts and parses JSON from various formats including:
32
+ * - Already parsed objects
33
+ * - Plain JSON
34
+ * - Markdown code blocks (```json ... ``` or ``` ... ```)
35
+ * - Mixed content with explanatory text
36
+ * - JSON5 format (trailing commas, comments, unquoted keys, etc.)
37
+ *
38
+ * @param decoded - The decoded string that may contain JSON, or an already parsed object
39
+ * @returns Parsed JSON object
40
+ * @throws Error if JSON parsing fails even with JSON5 fallback
32
41
  */
33
- decodeMessage(event: any): Promise<any>;
42
+ private extractAndParseJSON;
34
43
  /**
35
44
  * Gets an existing open stream or creates a new one based on reuse policy
36
45
  *
@@ -39,14 +48,6 @@ export declare class StreamHandler {
39
48
  * @param config - Stream handler configuration
40
49
  */
41
50
  getOrCreateStream(connection: Connection, protocol: string, config?: StreamHandlerConfig): Promise<Stream>;
42
- /**
43
- * Sends data through a stream with backpressure handling
44
- *
45
- * @param stream - The stream to send data through
46
- * @param data - The data to send
47
- * @param config - Configuration for timeout and other options
48
- */
49
- send(stream: Stream, data: Uint8Array, config?: StreamHandlerConfig): Promise<void>;
50
51
  /**
51
52
  * Sends data through a stream using length-prefixed encoding (libp2p v3 best practice)
52
53
  * Each message is automatically prefixed with a varint indicating the message length
@@ -73,25 +74,13 @@ export declare class StreamHandler {
73
74
  * @param connection - The connection the stream belongs to
74
75
  * @param toolExecutor - Function to execute tools for requests
75
76
  */
76
- handleIncomingStreamLP(stream: Stream, connection: Connection, toolExecutor: (request: oRequest, stream: Stream) => Promise<RunResult>): Promise<void>;
77
- /**
78
- * Handles an incoming stream on the server side
79
- * Attaches message listener immediately (libp2p v3 best practice)
80
- * Routes requests or executes tools based on the message
81
- *
82
- * @param stream - The incoming stream
83
- * @param connection - The connection the stream belongs to
84
- * @param toolExecutor - Function to execute tools for requests
85
- * @param config - Configuration to determine protocol handling
86
- */
87
- handleIncomingStream(stream: Stream, connection: Connection, toolExecutor: (request: oRequest, stream: Stream) => Promise<RunResult>, config?: StreamHandlerConfig): Promise<void>;
77
+ handleIncomingStream(stream: Stream, connection: Connection, toolExecutor: (request: oRequest, stream: Stream) => Promise<RunResult>): Promise<void>;
88
78
  /**
89
79
  * Handles a request message by executing the tool and sending response
90
80
  *
91
81
  * @param message - The decoded request message
92
82
  * @param stream - The stream to send the response on
93
83
  * @param toolExecutor - Function to execute the tool
94
- * @param useLengthPrefixing - Whether to use length-prefixed response encoding
95
84
  */
96
85
  private handleRequestMessage;
97
86
  /**
@@ -105,19 +94,6 @@ export declare class StreamHandler {
105
94
  * @param requestId - Optional request ID to filter responses (for stream reuse scenarios)
106
95
  * @returns Promise that resolves with the final response
107
96
  */
108
- handleOutgoingStreamLP(stream: Stream, emitter: EventEmitter, config?: StreamHandlerConfig, requestHandler?: (request: oRequest, stream: Stream) => Promise<RunResult>, requestId?: string | number): Promise<oResponse>;
109
- /**
110
- * Handles an outgoing stream on the client side
111
- * Listens for response messages and emits them via the event emitter
112
- * If requestHandler is provided, also processes incoming router requests
113
- *
114
- * @param stream - The outgoing stream
115
- * @param emitter - Event emitter for chunk events
116
- * @param config - Configuration including abort signal
117
- * @param requestHandler - Optional handler for processing router requests received on this stream
118
- * @param requestId - Optional request ID to filter responses (for stream reuse scenarios)
119
- * @returns Promise that resolves with the final response
120
- */
121
97
  handleOutgoingStream(stream: Stream, emitter: EventEmitter, config?: StreamHandlerConfig, requestHandler?: (request: oRequest, stream: Stream) => Promise<RunResult>, requestId?: string | number): Promise<oResponse>;
122
98
  /**
123
99
  * Forwards a request to the next hop and relays response chunks back
@@ -1 +1 @@
1
- {"version":3,"file":"stream-handler.d.ts","sourceRoot":"","sources":["../../../src/connection/stream-handler.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAC5D,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AACtC,OAAO,EACL,QAAQ,EACR,SAAS,EAIT,MAAM,EAEP,MAAM,eAAe,CAAC;AACvB,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AACpD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AACjD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAC/C,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AAGtE;;;;;;;GAOG;AACH,qBAAa,aAAa;IACxB,OAAO,CAAC,MAAM,CAAS;gBAEX,MAAM,CAAC,EAAE,MAAM;IAI3B;;;OAGG;IACH,SAAS,CAAC,OAAO,EAAE,GAAG,GAAG,OAAO;IAIhC;;;OAGG;IACH,UAAU,CAAC,OAAO,EAAE,GAAG,GAAG,OAAO;IAIjC;;OAEG;IACG,aAAa,CAAC,KAAK,EAAE,GAAG,GAAG,OAAO,CAAC,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
1
1
  import { oRequest, oResponse, CoreUtils, oError, oErrorCodes, Logger, ResponseBuilder, } from '@olane/o-core';
2
2
  import { lpStream } from '@olane/o-config';
3
+ import JSON5 from 'json5';
3
4
  /**
4
5
  * StreamHandler centralizes all stream-related functionality including:
5
6
  * - Message type detection (request vs response)
@@ -27,10 +28,61 @@ export class StreamHandler {
27
28
  return message?.result !== undefined && message.method === undefined;
28
29
  }
29
30
  /**
30
- * Decodes a stream message event into a JSON object
31
+ * Extracts and parses JSON from various formats including:
32
+ * - Already parsed objects
33
+ * - Plain JSON
34
+ * - Markdown code blocks (```json ... ``` or ``` ... ```)
35
+ * - Mixed content with explanatory text
36
+ * - JSON5 format (trailing commas, comments, unquoted keys, etc.)
37
+ *
38
+ * @param decoded - The decoded string that may contain JSON, or an already parsed object
39
+ * @returns Parsed JSON object
40
+ * @throws Error if JSON parsing fails even with JSON5 fallback
31
41
  */
32
- async decodeMessage(event) {
33
- return CoreUtils.processStream(event);
42
+ extractAndParseJSON(decoded) {
43
+ // If already an object (not a string), return it directly
44
+ if (typeof decoded !== 'string') {
45
+ return decoded;
46
+ }
47
+ let jsonString = decoded.trim();
48
+ // Strip markdown code blocks (```json ... ``` or ``` ... ```)
49
+ if (jsonString.includes('```')) {
50
+ const codeBlockMatch = jsonString.match(/```(?:json)?\s*\n?([\s\S]*?)\n?```/);
51
+ if (codeBlockMatch) {
52
+ jsonString = codeBlockMatch[1].trim();
53
+ }
54
+ }
55
+ // Extract JSON from mixed content (find first { to last })
56
+ const firstBrace = jsonString.indexOf('{');
57
+ const lastBrace = jsonString.lastIndexOf('}');
58
+ if (firstBrace !== -1 && lastBrace !== -1 && lastBrace > firstBrace) {
59
+ jsonString = jsonString.substring(firstBrace, lastBrace + 1);
60
+ }
61
+ // Attempt standard JSON.parse first
62
+ try {
63
+ return JSON.parse(jsonString);
64
+ }
65
+ catch (jsonError) {
66
+ this.logger.debug('Standard JSON parse failed, trying JSON5', {
67
+ error: jsonError.message,
68
+ position: jsonError.message.match(/position (\d+)/)?.[1],
69
+ preview: jsonString.substring(0, 200),
70
+ });
71
+ // Fallback to JSON5 for more relaxed parsing
72
+ try {
73
+ return JSON5.parse(jsonString);
74
+ }
75
+ catch (json5Error) {
76
+ // Enhanced error with context
77
+ this.logger.error('JSON5 parse also failed', {
78
+ originalError: jsonError.message,
79
+ json5Error: json5Error.message,
80
+ preview: jsonString.substring(0, 200),
81
+ length: jsonString.length,
82
+ });
83
+ throw new Error(`Failed to parse JSON: ${jsonError.message}\nJSON5 also failed: ${json5Error.message}\nPreview: ${jsonString.substring(0, 200)}${jsonString.length > 200 ? '...' : ''}`);
84
+ }
85
+ }
34
86
  }
35
87
  /**
36
88
  * Gets an existing open stream or creates a new one based on reuse policy
@@ -63,26 +115,6 @@ export class StreamHandler {
63
115
  });
64
116
  return stream;
65
117
  }
66
- /**
67
- * Sends data through a stream with backpressure handling
68
- *
69
- * @param stream - The stream to send data through
70
- * @param data - The data to send
71
- * @param config - Configuration for timeout and other options
72
- */
73
- async send(stream, data, config = {}) {
74
- // Send the data with backpressure handling (libp2p v3 best practice)
75
- const sent = stream.send(data);
76
- // If send() returns false, buffer is full - wait for drain
77
- if (!sent) {
78
- this.logger.debug('Stream buffer full, waiting for drain...');
79
- const drainTimeout = config.drainTimeoutMs ?? 30000;
80
- await stream.onDrain({
81
- signal: AbortSignal.timeout(drainTimeout),
82
- });
83
- this.logger.debug('Stream drained successfully');
84
- }
85
- }
86
118
  /**
87
119
  * Sends data through a stream using length-prefixed encoding (libp2p v3 best practice)
88
120
  * Each message is automatically prefixed with a varint indicating the message length
@@ -127,20 +159,17 @@ export class StreamHandler {
127
159
  * @param connection - The connection the stream belongs to
128
160
  * @param toolExecutor - Function to execute tools for requests
129
161
  */
130
- async handleIncomingStreamLP(stream, connection, toolExecutor) {
162
+ async handleIncomingStream(stream, connection, toolExecutor) {
131
163
  const lp = lpStream(stream);
132
164
  try {
133
165
  while (stream.status === 'open') {
134
166
  // Read complete length-prefixed message
135
167
  const messageBytes = await lp.read();
136
168
  const decoded = new TextDecoder().decode(messageBytes.subarray());
137
- // Ignore non-JSON messages
138
- if (!decoded.startsWith('{')) {
139
- continue;
140
- }
141
- const message = JSON.parse(decoded);
169
+ // Parse JSON (handles markdown blocks, mixed content, and JSON5)
170
+ const message = this.extractAndParseJSON(decoded);
142
171
  if (this.isRequest(message)) {
143
- await this.handleRequestMessage(message, stream, toolExecutor, true);
172
+ await this.handleRequestMessage(message, stream, toolExecutor);
144
173
  }
145
174
  else if (this.isResponse(message)) {
146
175
  this.logger.warn('Received response message on server-side stream, ignoring', message);
@@ -157,63 +186,14 @@ export class StreamHandler {
157
186
  }
158
187
  }
159
188
  }
160
- /**
161
- * Handles an incoming stream on the server side
162
- * Attaches message listener immediately (libp2p v3 best practice)
163
- * Routes requests or executes tools based on the message
164
- *
165
- * @param stream - The incoming stream
166
- * @param connection - The connection the stream belongs to
167
- * @param toolExecutor - Function to execute tools for requests
168
- * @param config - Configuration to determine protocol handling
169
- */
170
- async handleIncomingStream(stream, connection, toolExecutor, config = {}) {
171
- // Route to length-prefixed handler if enabled
172
- if (config.useLengthPrefixing) {
173
- return this.handleIncomingStreamLP(stream, connection, toolExecutor);
174
- }
175
- // CRITICAL: Attach message listener immediately to prevent buffer overflow (libp2p v3)
176
- const messageHandler = async (event) => {
177
- try {
178
- // avoid processing non-olane messages
179
- if (!event.data) {
180
- return;
181
- }
182
- const message = await this.decodeMessage(event);
183
- if (typeof message === 'string') {
184
- return;
185
- }
186
- if (this.isRequest(message)) {
187
- await this.handleRequestMessage(message, stream, toolExecutor);
188
- }
189
- else if (this.isResponse(message)) {
190
- this.logger.warn('Received response message on server-side stream, ignoring', message);
191
- }
192
- else {
193
- this.logger.warn('Received unknown message type', message);
194
- }
195
- }
196
- catch (error) {
197
- this.logger.error('Error handling stream message:', error);
198
- // Error already logged, stream will be closed by remote peer or timeout
199
- }
200
- };
201
- const closeHandler = () => {
202
- stream.removeEventListener('message', messageHandler);
203
- stream.removeEventListener('close', closeHandler);
204
- };
205
- stream.addEventListener('message', messageHandler);
206
- stream.addEventListener('close', closeHandler);
207
- }
208
189
  /**
209
190
  * Handles a request message by executing the tool and sending response
210
191
  *
211
192
  * @param message - The decoded request message
212
193
  * @param stream - The stream to send the response on
213
194
  * @param toolExecutor - Function to execute the tool
214
- * @param useLengthPrefixing - Whether to use length-prefixed response encoding
215
195
  */
216
- async handleRequestMessage(message, stream, toolExecutor, useLengthPrefixing = false) {
196
+ async handleRequestMessage(message, stream, toolExecutor) {
217
197
  const request = new oRequest(message);
218
198
  const responseBuilder = ResponseBuilder.create();
219
199
  try {
@@ -222,25 +202,13 @@ export class StreamHandler {
222
202
  // );
223
203
  const result = await toolExecutor(request, stream);
224
204
  const response = await responseBuilder.build(request, result, null);
225
- // Use length-prefixed encoding if enabled
226
- if (useLengthPrefixing) {
227
- await CoreUtils.sendResponseLP(response, stream);
228
- }
229
- else {
230
- await CoreUtils.sendResponse(response, stream);
231
- }
205
+ await CoreUtils.sendResponse(response, stream);
232
206
  this.logger.debug(`Successfully processed request: method=${request.method}, id=${request.id}`);
233
207
  }
234
208
  catch (error) {
235
209
  this.logger.error(`Error processing request: method=${request.method}, id=${request.id}`, error);
236
210
  const errorResponse = await responseBuilder.buildError(request, error);
237
- // Use length-prefixed encoding if enabled
238
- if (useLengthPrefixing) {
239
- await CoreUtils.sendResponseLP(errorResponse, stream);
240
- }
241
- else {
242
- await CoreUtils.sendResponse(errorResponse, stream);
243
- }
211
+ await CoreUtils.sendResponse(errorResponse, stream);
244
212
  }
245
213
  }
246
214
  /**
@@ -254,18 +222,17 @@ export class StreamHandler {
254
222
  * @param requestId - Optional request ID to filter responses (for stream reuse scenarios)
255
223
  * @returns Promise that resolves with the final response
256
224
  */
257
- async handleOutgoingStreamLP(stream, emitter, config = {}, requestHandler, requestId) {
225
+ async handleOutgoingStream(stream, emitter, config = {}, requestHandler, requestId) {
258
226
  const lp = lpStream(stream);
259
227
  try {
260
228
  while (stream.status === 'open') {
229
+ this.logger.debug('Waiting for response...');
261
230
  // Read complete length-prefixed message
262
231
  const messageBytes = await lp.read({ signal: config.signal });
263
232
  const decoded = new TextDecoder().decode(messageBytes.subarray());
264
- // Ignore non-JSON messages
265
- if (!decoded.startsWith('{')) {
266
- continue;
267
- }
268
- const message = JSON.parse(decoded);
233
+ // Parse JSON (handles markdown blocks, mixed content, and JSON5)
234
+ this.logger.debug('handleOutgoing raw decoded:', decoded);
235
+ const message = this.extractAndParseJSON(decoded);
269
236
  if (this.isResponse(message)) {
270
237
  const response = new oResponse({
271
238
  ...message.result,
@@ -287,7 +254,7 @@ export class StreamHandler {
287
254
  // Process incoming router requests if handler is provided
288
255
  if (requestHandler) {
289
256
  this.logger.debug('Received router request on client-side stream, processing...', message);
290
- await this.handleRequestMessage(message, stream, requestHandler, true);
257
+ await this.handleRequestMessage(message, stream, requestHandler);
291
258
  }
292
259
  else {
293
260
  this.logger.warn('Received request message on client-side stream, ignoring (no handler)', message);
@@ -306,110 +273,6 @@ export class StreamHandler {
306
273
  throw error;
307
274
  }
308
275
  }
309
- /**
310
- * Handles an outgoing stream on the client side
311
- * Listens for response messages and emits them via the event emitter
312
- * If requestHandler is provided, also processes incoming router requests
313
- *
314
- * @param stream - The outgoing stream
315
- * @param emitter - Event emitter for chunk events
316
- * @param config - Configuration including abort signal
317
- * @param requestHandler - Optional handler for processing router requests received on this stream
318
- * @param requestId - Optional request ID to filter responses (for stream reuse scenarios)
319
- * @returns Promise that resolves with the final response
320
- */
321
- async handleOutgoingStream(stream, emitter, config = {}, requestHandler, requestId) {
322
- // Route to length-prefixed handler if enabled
323
- if (config.useLengthPrefixing) {
324
- return this.handleOutgoingStreamLP(stream, emitter, config, requestHandler, requestId);
325
- }
326
- return new Promise((resolve, reject) => {
327
- let lastResponse;
328
- const messageHandler = async (event) => {
329
- // avoid processing non-olane messages
330
- if (!event.data) {
331
- return;
332
- }
333
- try {
334
- const message = await this.decodeMessage(event);
335
- if (typeof message === 'string') {
336
- // this.logger.warn(
337
- // 'Received string message on server-side stream, ignoring',
338
- // message,
339
- // );
340
- return;
341
- }
342
- if (this.isResponse(message)) {
343
- const response = await CoreUtils.processStreamResponse(event);
344
- // If requestId is provided, filter responses to only process those matching our request
345
- // This prevents premature termination when multiple requests share the same stream
346
- if (requestId !== undefined && response.id !== requestId) {
347
- this.logger.debug(`Ignoring response for different request (expected: ${requestId}, received: ${response.id})`);
348
- return;
349
- }
350
- // Emit chunk for streaming responses
351
- emitter.emit('chunk', response);
352
- // Check if this is the last chunk for THIS request
353
- if (response.result._last || !response.result._isStreaming) {
354
- lastResponse = response;
355
- cleanup();
356
- resolve(response);
357
- }
358
- }
359
- else if (this.isRequest(message)) {
360
- // Process incoming router requests if handler is provided
361
- if (requestHandler) {
362
- this.logger.debug('Received router request on client-side stream, processing...', message);
363
- await this.handleRequestMessage(message, stream, requestHandler);
364
- }
365
- else {
366
- this.logger.warn('Received request message on client-side stream, ignoring (no handler)', message);
367
- }
368
- }
369
- else {
370
- this.logger.warn('Received unknown message type', message);
371
- }
372
- }
373
- catch (error) {
374
- this.logger.error('Error handling response message:', error);
375
- cleanup();
376
- reject(error);
377
- }
378
- };
379
- const closeHandler = () => {
380
- cleanup();
381
- if (lastResponse) {
382
- resolve(lastResponse);
383
- }
384
- else {
385
- reject(new oError(oErrorCodes.TIMEOUT, 'Stream closed before response received'));
386
- }
387
- };
388
- const abortHandler = () => {
389
- this.logger.debug('Request aborted');
390
- cleanup();
391
- try {
392
- stream.abort(new Error('Request aborted'));
393
- }
394
- catch (error) {
395
- this.logger.debug('Error aborting stream:', error.message);
396
- }
397
- reject(new oError(oErrorCodes.TIMEOUT, 'Request aborted'));
398
- };
399
- const cleanup = () => {
400
- stream.removeEventListener('message', messageHandler);
401
- stream.removeEventListener('close', closeHandler);
402
- if (config.signal) {
403
- config.signal.removeEventListener('abort', abortHandler);
404
- }
405
- };
406
- stream.addEventListener('message', messageHandler);
407
- stream.addEventListener('close', closeHandler);
408
- if (config.signal) {
409
- config.signal.addEventListener('abort', abortHandler);
410
- }
411
- });
412
- }
413
276
  /**
414
277
  * Forwards a request to the next hop and relays response chunks back
415
278
  * This implements the middleware/proxy pattern for intermediate nodes
@@ -425,7 +288,7 @@ export class StreamHandler {
425
288
  // Set up chunk relay - forward responses from next hop back to incoming stream
426
289
  nextHopConnection.onChunk(async (response) => {
427
290
  try {
428
- await CoreUtils.sendStreamResponse(response, incomingStream);
291
+ await CoreUtils.sendResponse(response, incomingStream);
429
292
  }
430
293
  catch (error) {
431
294
  this.logger.error('Error forwarding chunk:', error);
@@ -32,12 +32,5 @@ export interface oNodeConfig extends oCoreConfig {
32
32
  drainTimeoutMs?: number;
33
33
  };
34
34
  runOnLimitedConnection?: boolean;
35
- /**
36
- * Enable length-prefixed streaming (libp2p v3 best practice)
37
- * When enabled, all messages are prefixed with a varint indicating message length
38
- * This provides proper message boundaries and eliminates concatenation issues
39
- * @default false (for backward compatibility)
40
- */
41
- useLengthPrefixing?: boolean;
42
35
  }
43
36
  //# sourceMappingURL=o-node.config.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"o-node.config.d.ts","sourceRoot":"","sources":["../../../src/interfaces/o-node.config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAE3D,MAAM,WAAW,WAAY,SAAQ,WAAW;IAC9C,MAAM,EAAE,YAAY,GAAG,IAAI,CAAC;IAC5B,MAAM,EAAE,YAAY,GAAG,IAAI,CAAC;IAE5B;;;OAGG;IACH,mBAAmB,CAAC,EAAE;QACpB,OAAO,CAAC,EAAE,OAAO,CAAC;QAClB,UAAU,CAAC,EAAE,MAAM,CAAC;QACpB,gBAAgB,CAAC,EAAE,MAAM,CAAC;QAC1B,aAAa,CAAC,EAAE,OAAO,CAAC;QACxB,WAAW,CAAC,EAAE,OAAO,CAAC;QACtB,WAAW,CAAC,EAAE,OAAO,CAAC;KACvB,CAAC;IAEF;;;OAGG;IACH,kBAAkB,CAAC,EAAE;QACnB;;;WAGG;QACH,aAAa,CAAC,EAAE,MAAM,CAAC;QACvB;;;WAGG;QACH,cAAc,CAAC,EAAE,MAAM,CAAC;KACzB,CAAC;IAEF,sBAAsB,CAAC,EAAE,OAAO,CAAC;IAEjC;;;;;OAKG;IACH,kBAAkB,CAAC,EAAE,OAAO,CAAC;CAC9B"}
1
+ {"version":3,"file":"o-node.config.d.ts","sourceRoot":"","sources":["../../../src/interfaces/o-node.config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAE3D,MAAM,WAAW,WAAY,SAAQ,WAAW;IAC9C,MAAM,EAAE,YAAY,GAAG,IAAI,CAAC;IAC5B,MAAM,EAAE,YAAY,GAAG,IAAI,CAAC;IAE5B;;;OAGG;IACH,mBAAmB,CAAC,EAAE;QACpB,OAAO,CAAC,EAAE,OAAO,CAAC;QAClB,UAAU,CAAC,EAAE,MAAM,CAAC;QACpB,gBAAgB,CAAC,EAAE,MAAM,CAAC;QAC1B,aAAa,CAAC,EAAE,OAAO,CAAC;QACxB,WAAW,CAAC,EAAE,OAAO,CAAC;QACtB,WAAW,CAAC,EAAE,OAAO,CAAC;KACvB,CAAC;IAEF;;;OAGG;IACH,kBAAkB,CAAC,EAAE;QACnB;;;WAGG;QACH,aAAa,CAAC,EAAE,MAAM,CAAC;QACvB;;;WAGG;QACH,cAAc,CAAC,EAAE,MAAM,CAAC;KACzB,CAAC;IAEF,sBAAsB,CAAC,EAAE,OAAO,CAAC;CAClC"}
@@ -1 +1 @@
1
- {"version":3,"file":"o-node.d.ts","sourceRoot":"","sources":["../../src/o-node.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,MAAM,EACN,YAAY,EAEb,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EAAE,MAAM,EAAE,MAA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,MAAM,CAAC;IAMvC,OAAO,CAAC,MAAM,EAAE,qBAAqB,GAAG,OAAO,CAAC,eAAe,CAAC;IAsBhE,qBAAqB,IAAI,OAAO,CAAC,IAAI,CAAC;cAU5B,sBAAsB,IAAI,OAAO,CAAC,IAAI,CAAC;IAavD,cAAc,CAAC,EAAE,EAAE,QAAQ;IAI3B,eAAe,CAAC,EAAE,EAAE,QAAQ;cAIZ,iBAAiB,IAAI,OAAO,CAAC,IAAI,CAAC;IAgClD;;;;OAIG;YACW,wBAAwB;IA2BtC;;;;;;OAMG;cACa,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;IAInC,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IA6DjC;;OAEG;IAiBG,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;IAgB/B;;;OAGG;IACH,SAAS,CAAC,UAAU,IAAI,IAAI;IAgC5B,UAAU,IAAI,YAAY,EAAE;IAI5B,UAAU,IAAI,YAAY,EAAE;IAI5B,WAAW,IAAI,YAAY,EAAE;IAI7B,WAAW,CAAC,YAAY,EAAE,YAAY,GAAG,IAAI;IAI7C;;;OAGG;IACH,cAAc,IAAI,MAAM;IAUxB;;;OAGG;IACG,wBAAwB,CAAC,OAAO,EAAE,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAC;CAwEhE"}
@@ -353,7 +353,6 @@ export class oNode extends oToolBase {
353
353
  defaultDrainTimeoutMs: this.config.connectionTimeouts?.drainTimeoutMs,
354
354
  runOnLimitedConnection: this.config.runOnLimitedConnection ?? false,
355
355
  originAddress: this.address?.value,
356
- useLengthPrefixing: this.config.useLengthPrefixing ?? true,
357
356
  });
358
357
  }
359
358
  async hookInitializeFinished() {
@@ -1 +1 @@
1
- {"version":3,"file":"o-node.tool.d.ts","sourceRoot":"","sources":["../../src/o-node.tool.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAoB,MAAM,eAAe,CAAC;AAErE,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;;AAKrD;;;;GAIG;AACH,qBAAa,SAAU,SAAQ,cAAkB;IAC/C,OAAO,CAAC,aAAa,CAAiB;IAEhC,cAAc,CAAC,OAAO,EAAE,QAAQ;IAehC,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAY3B,YAAY,CAAC,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC;IA2BnE,cAAc,IAAI,OAAO,CAAC,GAAG,CAAC;IAQ9B,oBAAoB,CAAC,OAAO,EAAE,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAC;CAiC5D"}
1
+ {"version":3,"file":"o-node.tool.d.ts","sourceRoot":"","sources":["../../src/o-node.tool.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAoB,MAAM,eAAe,CAAC;AAErE,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;;AAKrD;;;;GAIG;AACH,qBAAa,SAAU,SAAQ,cAAkB;IAC/C,OAAO,CAAC,aAAa,CAAiB;IAEhC,cAAc,CAAC,OAAO,EAAE,QAAQ;IAehC,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAY3B,YAAY,CAAC,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC;IAwBnE,cAAc,IAAI,OAAO,CAAC,GAAG,CAAC;IAQ9B,oBAAoB,CAAC,OAAO,EAAE,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAC;CAiC5D"}
@@ -35,7 +35,7 @@ export class oNodeTool extends oTool(oServerNode) {
35
35
  }
36
36
  async handleStream(stream, connection) {
37
37
  // Use StreamHandler for consistent stream handling
38
- // This follows libp2p v3 best practices for immediate message listener attachment
38
+ // This follows libp2p v3 best practices for length-prefixed streaming
39
39
  await this.streamHandler.handleIncomingStream(stream, connection, async (request, stream) => {
40
40
  try {
41
41
  const result = await this.execute(request, stream);
@@ -46,8 +46,6 @@ export class oNodeTool extends oTool(oServerNode) {
46
46
  this.logger.error('Error executing tool: ', request.toString(), error, typeof error);
47
47
  throw error; // StreamHandler will handle error response building
48
48
  }
49
- }, {
50
- useLengthPrefixing: this.config.useLengthPrefixing ?? true,
51
49
  });
52
50
  }
53
51
  async _tool_identify() {
@@ -1 +1 @@
1
- {"version":3,"file":"o-node.router.d.ts","sourceRoot":"","sources":["../../../src/router/o-node.router.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAML,cAAc,EAGd,aAAa,EACd,MAAM,eAAe,CAAC;AACvB,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAM5C,qBAAa,WAAY,SAAQ,WAAW;IAC1C,OAAO,CAAC,aAAa,CAAqB;;IAO1C;;;;;;;;OAQG;cACa,OAAO,CACrB,OAAO,EAAE,YAAY,EACrB,OAAO,EAAE,cAAc,EACvB,IAAI,EAAE,KAAK,GACV,OAAO,CAAC,GAAG,CAAC;IA6Bf;;;OAGG;YACW,kBAAkB;IA8DhC;;OAEG;IACH,OAAO,CAAC,oBAAoB;IAS5B;;OAEG;IACH,OAAO,CAAC,wBAAwB;IAWhC;;OAEG;YACW,eAAe;IAuC7B;;;OAGG;IACG,SAAS,CAAC,OAAO,EAAE,YAAY,EAAE,IAAI,EAAE,KAAK,GAAG,OAAO,CAAC,aAAa,CAAC;IA+B3E;;;OAGG;IACH,UAAU,CAAC,qBAAqB,EAAE,YAAY,EAAE,IAAI,EAAE,KAAK,GAAG,OAAO;CAGtE"}
1
+ {"version":3,"file":"o-node.router.d.ts","sourceRoot":"","sources":["../../../src/router/o-node.router.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAML,cAAc,EAGd,aAAa,EACd,MAAM,eAAe,CAAC;AACvB,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAM5C,qBAAa,WAAY,SAAQ,WAAW;IAC1C,OAAO,CAAC,aAAa,CAAqB;;IAO1C;;;;;;;;OAQG;cACa,OAAO,CACrB,OAAO,EAAE,YAAY,EACrB,OAAO,EAAE,cAAc,EACvB,IAAI,EAAE,KAAK,GACV,OAAO,CAAC,GAAG,CAAC;IA6Bf;;;OAGG;YACW,kBAAkB;IA8DhC;;OAEG;IACH,OAAO,CAAC,oBAAoB;IAS5B;;OAEG;IACH,OAAO,CAAC,wBAAwB;IAWhC;;OAEG;YACW,eAAe;IA4C7B;;;OAGG;IACG,SAAS,CAAC,OAAO,EAAE,YAAY,EAAE,IAAI,EAAE,KAAK,GAAG,OAAO,CAAC,aAAa,CAAC;IA+B3E;;;OAGG;IACH,UAAU,CAAC,qBAAqB,EAAE,YAAY,EAAE,IAAI,EAAE,KAAK,GAAG,OAAO;CAGtE"}
@@ -132,7 +132,7 @@ export class oNodeRouter extends oToolRouter {
132
132
  throw new oError(oErrorCodes.INVALID_REQUEST, 'Stream is required');
133
133
  }
134
134
  nodeConnection.onChunk(async (response) => {
135
- CoreUtils.sendStreamResponse(response, routeRequest.stream);
135
+ CoreUtils.sendResponse(response, routeRequest.stream);
136
136
  });
137
137
  // allow this to continue as we will tell the transmitter to stream the response and we will intercept via the above listener
138
138
  }
@@ -12,7 +12,7 @@ export class StreamUtils extends oObject {
12
12
  aggregatedResult += result.delta;
13
13
  }
14
14
  const chunkResponse = await responseBuilder.buildChunk(request, result);
15
- await CoreUtils.sendStreamResponse(chunkResponse, stream);
15
+ await CoreUtils.sendResponse(chunkResponse, stream);
16
16
  }
17
17
  return {
18
18
  message: aggregatedResult,
@@ -24,7 +24,7 @@ export class StreamUtils extends oObject {
24
24
  isStream: true,
25
25
  isLast: true,
26
26
  });
27
- await CoreUtils.sendStreamResponse(errorResponse, stream);
27
+ await CoreUtils.sendResponse(errorResponse, stream);
28
28
  throw error;
29
29
  }
30
30
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@olane/o-node",
3
- "version": "0.7.34",
3
+ "version": "0.7.35",
4
4
  "type": "module",
5
5
  "main": "dist/src/index.js",
6
6
  "types": "dist/src/index.d.ts",
@@ -40,9 +40,10 @@
40
40
  "devDependencies": {
41
41
  "@eslint/eslintrc": "^3.3.1",
42
42
  "@eslint/js": "^9.29.0",
43
- "@olane/o-test": "0.7.34",
43
+ "@olane/o-test": "0.7.35",
44
44
  "@tsconfig/node20": "^20.1.6",
45
45
  "@types/jest": "^30.0.0",
46
+ "@types/json5": "^2.2.0",
46
47
  "@typescript-eslint/eslint-plugin": "^8.34.1",
47
48
  "@typescript-eslint/parser": "^8.34.1",
48
49
  "aegir": "^47.0.21",
@@ -59,12 +60,13 @@
59
60
  "typescript": "5.4.5"
60
61
  },
61
62
  "dependencies": {
62
- "@olane/o-config": "0.7.34",
63
- "@olane/o-core": "0.7.34",
64
- "@olane/o-protocol": "0.7.34",
65
- "@olane/o-tool": "0.7.34",
63
+ "@olane/o-config": "0.7.35",
64
+ "@olane/o-core": "0.7.35",
65
+ "@olane/o-protocol": "0.7.35",
66
+ "@olane/o-tool": "0.7.35",
66
67
  "debug": "^4.4.1",
67
- "dotenv": "^16.5.0"
68
+ "dotenv": "^16.5.0",
69
+ "json5": "^2.2.3"
68
70
  },
69
- "gitHead": "f5c2e654d18505174074f2df972c1e4851eb7ea3"
71
+ "gitHead": "4969788a907bb3a8705c84d42f461403a0194283"
70
72
  }