ai 2.2.34 → 2.2.36

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
@@ -826,6 +826,17 @@ declare function GoogleGenerativeAIStream(response: {
826
826
 
827
827
  declare function HuggingFaceStream(res: AsyncGenerator<any>, callbacks?: AIStreamCallbacksAndOptions): ReadableStream;
828
828
 
829
+ type InkeepOnFinalMetadata = {
830
+ chat_session_id: string;
831
+ records_cited: any;
832
+ };
833
+ type InkeepChatResultCallbacks = {
834
+ onFinal?: (completion: string, metadata?: InkeepOnFinalMetadata) => Promise<void> | void;
835
+ onRecordsCited?: (records_cited: InkeepOnFinalMetadata['records_cited']) => void;
836
+ };
837
+ type InkeepAIStreamCallbacksAndOptions = AIStreamCallbacksAndOptions & InkeepChatResultCallbacks;
838
+ declare function InkeepStream(res: Response, callbacks?: InkeepAIStreamCallbacksAndOptions): ReadableStream;
839
+
829
840
  declare function LangChainStream(callbacks?: AIStreamCallbacksAndOptions): {
830
841
  stream: ReadableStream<any>;
831
842
  writer: WritableStreamDefaultWriter<any>;
@@ -958,4 +969,4 @@ declare function streamToResponse(res: ReadableStream, response: ServerResponse,
958
969
  status?: number;
959
970
  }): void;
960
971
 
961
- export { AIStream, AIStreamCallbacksAndOptions, AIStreamParser, AIStreamParserOptions, AWSBedrockAnthropicStream, AWSBedrockCohereStream, AWSBedrockLlama2Stream, AWSBedrockStream, AnthropicStream, AssistantMessage, COMPLEX_HEADER, ChatRequest, ChatRequestOptions, CohereStream, CompletionUsage, CreateMessage, DataMessage, Function, FunctionCall, FunctionCallHandler, FunctionCallPayload, GoogleGenerativeAIStream, HuggingFaceStream, IdGenerator, JSONValue, LangChainStream, Message$1 as Message, OpenAIStream, OpenAIStreamCallbacks, ReactResponseRow, ReplicateStream, RequestOptions, StreamString, StreamingTextResponse, Tool, ToolCall, ToolCallHandler, ToolCallPayload, ToolChoice, UseChatOptions, UseCompletionOptions, createCallbacksTransformer, createChunkDecoder, createEventStreamTransformer, createStreamDataTransformer, experimental_AssistantResponse, experimental_StreamData, experimental_StreamingReactResponse, isStreamStringEqualToType, nanoid, readableFromAsyncIterable, streamToResponse, trimStartOfStreamHelper };
972
+ export { AIStream, AIStreamCallbacksAndOptions, AIStreamParser, AIStreamParserOptions, AWSBedrockAnthropicStream, AWSBedrockCohereStream, AWSBedrockLlama2Stream, AWSBedrockStream, AnthropicStream, AssistantMessage, COMPLEX_HEADER, ChatRequest, ChatRequestOptions, CohereStream, CompletionUsage, CreateMessage, DataMessage, Function, FunctionCall, FunctionCallHandler, FunctionCallPayload, GoogleGenerativeAIStream, HuggingFaceStream, IdGenerator, InkeepAIStreamCallbacksAndOptions, InkeepChatResultCallbacks, InkeepOnFinalMetadata, InkeepStream, JSONValue, LangChainStream, Message$1 as Message, OpenAIStream, OpenAIStreamCallbacks, ReactResponseRow, ReplicateStream, RequestOptions, StreamString, StreamingTextResponse, Tool, ToolCall, ToolCallHandler, ToolCallPayload, ToolChoice, UseChatOptions, UseCompletionOptions, createCallbacksTransformer, createChunkDecoder, createEventStreamTransformer, createStreamDataTransformer, experimental_AssistantResponse, experimental_StreamData, experimental_StreamingReactResponse, isStreamStringEqualToType, nanoid, readableFromAsyncIterable, streamToResponse, trimStartOfStreamHelper };
package/dist/index.js CHANGED
@@ -30,6 +30,7 @@ __export(streams_exports, {
30
30
  CohereStream: () => CohereStream,
31
31
  GoogleGenerativeAIStream: () => GoogleGenerativeAIStream,
32
32
  HuggingFaceStream: () => HuggingFaceStream,
33
+ InkeepStream: () => InkeepStream,
33
34
  LangChainStream: () => LangChainStream,
34
35
  OpenAIStream: () => OpenAIStream,
35
36
  ReplicateStream: () => ReplicateStream,
@@ -730,6 +731,44 @@ function HuggingFaceStream(res, callbacks) {
730
731
  );
731
732
  }
732
733
 
734
+ // streams/inkeep-stream.ts
735
+ function InkeepStream(res, callbacks) {
736
+ if (!res.body) {
737
+ throw new Error("Response body is null");
738
+ }
739
+ let chat_session_id = "";
740
+ let records_cited;
741
+ const inkeepEventParser = (data, options) => {
742
+ var _a, _b;
743
+ const { event } = options;
744
+ if (event === "records_cited") {
745
+ records_cited = JSON.parse(data);
746
+ (_a = callbacks == null ? void 0 : callbacks.onRecordsCited) == null ? void 0 : _a.call(callbacks, records_cited);
747
+ }
748
+ if (event === "message_chunk") {
749
+ const inkeepMessageChunk = JSON.parse(data);
750
+ chat_session_id = (_b = inkeepMessageChunk.chat_session_id) != null ? _b : chat_session_id;
751
+ return inkeepMessageChunk.content_chunk;
752
+ }
753
+ return;
754
+ };
755
+ let { onRecordsCited, ...passThroughCallbacks } = callbacks || {};
756
+ passThroughCallbacks = {
757
+ ...passThroughCallbacks,
758
+ onFinal: (completion) => {
759
+ var _a;
760
+ const inkeepOnFinalMetadata = {
761
+ chat_session_id,
762
+ records_cited
763
+ };
764
+ (_a = callbacks == null ? void 0 : callbacks.onFinal) == null ? void 0 : _a.call(callbacks, completion, inkeepOnFinalMetadata);
765
+ }
766
+ };
767
+ return AIStream(res, inkeepEventParser, passThroughCallbacks).pipeThrough(
768
+ createStreamDataTransformer(passThroughCallbacks == null ? void 0 : passThroughCallbacks.experimental_streamData)
769
+ );
770
+ }
771
+
733
772
  // streams/langchain-stream.ts
734
773
  function LangChainStream(callbacks) {
735
774
  const stream = new TransformStream();
@@ -1061,6 +1100,7 @@ function createFunctionCallTransformer(callbacks) {
1061
1100
  controller.enqueue(
1062
1101
  isComplexMode ? textEncoder.encode(formatStreamPart("text", functionResponse)) : textEncoder.encode(functionResponse)
1063
1102
  );
1103
+ aggregatedFinalCompletionResponse = functionResponse;
1064
1104
  return;
1065
1105
  }
1066
1106
  const filteredCallbacks = {
@@ -1389,6 +1429,7 @@ function streamToResponse(res, response, init) {
1389
1429
  CohereStream,
1390
1430
  GoogleGenerativeAIStream,
1391
1431
  HuggingFaceStream,
1432
+ InkeepStream,
1392
1433
  LangChainStream,
1393
1434
  OpenAIStream,
1394
1435
  ReplicateStream,