listpage-next-ai 0.0.271 → 0.0.273

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.
@@ -3,12 +3,15 @@ import { BaseMessage } from 'langchain';
3
3
  import { BaseMessageChunk } from 'langchain';
4
4
  import { ChatOpenAICallOptions } from '@langchain/openai';
5
5
  import { ChatOpenAICompletions } from '@langchain/openai';
6
+ import { IterableReadableStream } from '@langchain/core/utils/stream';
6
7
  import { LanguageModelLike } from '@langchain/core/language_models/base';
7
8
  import { MessageStructure } from '@langchain/core/messages';
8
9
  import { MessageType } from '@langchain/core/messages';
9
10
  import { OpenAIClient } from '@langchain/openai';
10
11
  import { ReactAgent } from 'langchain';
12
+ import { ReplaySubject } from 'rxjs';
11
13
  import { ResponseFormatUndefined } from 'langchain';
14
+ import { StreamEvent } from '@langchain/core/tracers/log_stream';
12
15
 
13
16
  export declare interface AgentOptions {
14
17
  features: {
@@ -100,6 +103,28 @@ declare interface KnowledgeToolOptions {
100
103
  onRetrieveFullDocs: (index: string, title: string) => Promise<string>;
101
104
  }
102
105
 
106
+ export declare function simplifyStreamEvents(events: IterableReadableStream<StreamEvent>): Promise<AsyncGenerator<{
107
+ type: string;
108
+ data: any;
109
+ }, void, unknown>>;
110
+
111
+ export declare function streamEvents2Subject<Event = any>(events: IterableReadableStream<Event>, transform?: (event: Event) => {
112
+ type: string;
113
+ data: any;
114
+ }, callbacks?: {
115
+ before?: (subject: ReplaySubject<{
116
+ type: string;
117
+ data: any;
118
+ }>) => Promise<void>;
119
+ after?: (subject: ReplaySubject<{
120
+ type: string;
121
+ data: any;
122
+ }>) => Promise<void>;
123
+ }): ReplaySubject<{
124
+ type: string;
125
+ data: any;
126
+ }>;
127
+
103
128
  declare interface WordToolOptions {
104
129
  glossry: {
105
130
  name: string;
package/dist/cjs/index.js CHANGED
@@ -25,6 +25,8 @@ var __webpack_exports__ = {};
25
25
  __webpack_require__.r(__webpack_exports__);
26
26
  __webpack_require__.d(__webpack_exports__, {
27
27
  createReactAgent: ()=>createReactAgent,
28
+ simplifyStreamEvents: ()=>simplifyStreamEvents,
29
+ streamEvents2Subject: ()=>streamEvents2Subject,
28
30
  ChatVolcengine: ()=>ChatVolcengine,
29
31
  AgentOptions: ()=>types_namespaceObject.AgentOptions
30
32
  });
@@ -499,13 +501,91 @@ class ChatVolcengine extends openai_namespaceObject.ChatOpenAICompletions {
499
501
  return langChainMessage;
500
502
  }
501
503
  }
504
+ const external_rxjs_namespaceObject = require("rxjs");
505
+ async function simplifyStreamEvents(events) {
506
+ return async function*() {
507
+ for await (const event of events){
508
+ const { event: type, data, name } = event;
509
+ if ('on_chat_model_stream' === type) {
510
+ const chunk = data?.chunk;
511
+ if (chunk) {
512
+ const reasoning = chunk.additional_kwargs?.reasoning_content;
513
+ if (reasoning) yield {
514
+ type: 'thinking',
515
+ data: reasoning
516
+ };
517
+ const content = chunk.content;
518
+ if (content && 'string' == typeof content) yield {
519
+ type: 'chunk',
520
+ data: content
521
+ };
522
+ }
523
+ } else if ('on_tool_start' === type) {
524
+ if ('write_todos' !== name) yield {
525
+ type: 'tool_start',
526
+ data: {
527
+ name: name,
528
+ input: data?.input?.input,
529
+ start_timestamp: +Date.now()
530
+ }
531
+ };
532
+ } else if ('on_tool_end' === type) switch(name){
533
+ case 'write_todos':
534
+ yield {
535
+ type: 'write_todos',
536
+ data: data?.output?.update?.todos
537
+ };
538
+ break;
539
+ case 'generate_chart':
540
+ yield {
541
+ type: 'chunk',
542
+ data: `\n<chart-view data-view="${data?.output?.content}"></chart-view>\n`
543
+ };
544
+ yield {
545
+ type: 'tool_end',
546
+ data: {
547
+ name: name,
548
+ output: data?.output?.content,
549
+ end_timestamp: +Date.now()
550
+ }
551
+ };
552
+ break;
553
+ default:
554
+ yield {
555
+ type: 'tool_end',
556
+ data: {
557
+ name: name,
558
+ output: data?.output?.content,
559
+ end_timestamp: +Date.now()
560
+ }
561
+ };
562
+ }
563
+ }
564
+ }();
565
+ }
566
+ function streamEvents2Subject(events, transform, callbacks) {
567
+ const subject = new external_rxjs_namespaceObject.ReplaySubject();
568
+ (async ()=>{
569
+ await callbacks?.before?.(subject);
570
+ for await (const event of events){
571
+ const transformedEvent = transform?.(event) || event;
572
+ subject.next(transformedEvent);
573
+ }
574
+ await callbacks?.after?.(subject);
575
+ })();
576
+ return subject;
577
+ }
502
578
  exports.AgentOptions = __webpack_exports__.AgentOptions;
503
579
  exports.ChatVolcengine = __webpack_exports__.ChatVolcengine;
504
580
  exports.createReactAgent = __webpack_exports__.createReactAgent;
581
+ exports.simplifyStreamEvents = __webpack_exports__.simplifyStreamEvents;
582
+ exports.streamEvents2Subject = __webpack_exports__.streamEvents2Subject;
505
583
  for(var __webpack_i__ in __webpack_exports__)if (-1 === [
506
584
  "AgentOptions",
507
585
  "ChatVolcengine",
508
- "createReactAgent"
586
+ "createReactAgent",
587
+ "simplifyStreamEvents",
588
+ "streamEvents2Subject"
509
589
  ].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
510
590
  Object.defineProperty(exports, '__esModule', {
511
591
  value: true
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "listpage-next-ai",
3
- "version": "0.0.271",
3
+ "version": "0.0.273",
4
4
  "description": "A React component library for creating filter forms with Ant Design",
5
5
  "main": "./dist/cjs/index.js",
6
6
  "module": "./dist/esm/index.js",