@fencyai/react 0.1.45 → 0.1.46

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.
@@ -14,6 +14,7 @@ export interface UseChatCompletions {
14
14
  basic: SynchronousChatCompletion | null;
15
15
  structured: StructuredChatCompletion<ZodTypeAny> | null;
16
16
  streaming: StreamingChatCompletion | null;
17
+ response: string | null;
17
18
  };
18
19
  chatCompletions: CombinedChatCompletion[];
19
20
  createChatCompletion: (params: CreateSynchronousChatCompletionParams) => Promise<SynchronousChatCompletionResponse>;
@@ -47,6 +47,13 @@ export function useChatCompletions() {
47
47
  streaming: lastCompletion?.type === 'streaming'
48
48
  ? lastCompletion.chatCompletion
49
49
  : null,
50
+ response: lastCompletion?.type === 'synchronous'
51
+ ? lastCompletion.chatCompletion.data?.response ?? null
52
+ : lastCompletion?.type === 'structured'
53
+ ? JSON.stringify(lastCompletion.chatCompletion.data?.structuredResponse)
54
+ : lastCompletion?.type === 'streaming'
55
+ ? lastCompletion.chatCompletion.response
56
+ : null,
50
57
  };
51
58
  }, [combinedChatCompletions]);
52
59
  return {
@@ -1,4 +1,4 @@
1
- import { createChatCompletion } from '@fencyai/js';
1
+ import { createChatCompletion, } from '@fencyai/js';
2
2
  import { useCallback, useEffect, useState } from 'react';
3
3
  import { useStream } from '../useStream';
4
4
  export const useStreamingChatCompletions = (context) => {
@@ -20,9 +20,10 @@ export const useStreamingChatCompletions = (context) => {
20
20
  if (!existing)
21
21
  return prev;
22
22
  return [
23
- ...prev.filter((c) => c.streamId !== error.streamId),
23
+ ...prev.filter((c) => c.streamId === error.streamId),
24
24
  {
25
25
  ...existing,
26
+ loading: false,
26
27
  error: error.error,
27
28
  },
28
29
  ];
@@ -8,9 +8,7 @@ export function useFileUploads(props) {
8
8
  const { createStream } = useStream({
9
9
  onFileUploadCompleted: (streamData) => {
10
10
  props.onUploadComplete?.(streamData);
11
- console.log('streamData', streamData.fileId);
12
11
  setFileUploads((prev) => prev.map((fileUpload) => {
13
- console.log('fileUpload.upload.id', fileUpload.file?.id);
14
12
  return fileUpload.upload.id === streamData.uploadId
15
13
  ? { ...fileUpload, status: 'upload_complete' }
16
14
  : fileUpload;
@@ -8,6 +8,13 @@ export const useStream = (props) => {
8
8
  const eventSource = useEventSource({
9
9
  onError: (url) => {
10
10
  console.error('Stream error:', url);
11
+ props?.onStreamError?.({
12
+ streamId: url,
13
+ error: {
14
+ code: 'UnknownError',
15
+ message: 'Unknown error in useStream',
16
+ },
17
+ });
11
18
  },
12
19
  onMessage: (message) => {
13
20
  const streamData = toStreamData(message.data);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fencyai/react",
3
- "version": "0.1.45",
3
+ "version": "0.1.46",
4
4
  "description": "> TODO: description",
5
5
  "author": "staklau <steinaageklaussen@gmail.com>",
6
6
  "homepage": "",
@@ -36,7 +36,7 @@
36
36
  "zod": "^4.0.5"
37
37
  },
38
38
  "devDependencies": {
39
- "@fencyai/js": "^0.1.45",
39
+ "@fencyai/js": "^0.1.46",
40
40
  "@types/jest": "^29.5.11",
41
41
  "@types/node": "^20.10.5",
42
42
  "@types/react": "^18.2.45",
@@ -45,8 +45,8 @@
45
45
  "typescript": "^5.3.3"
46
46
  },
47
47
  "peerDependencies": {
48
- "@fencyai/js": "^0.1.45",
48
+ "@fencyai/js": "^0.1.46",
49
49
  "react": ">=16.8.0"
50
50
  },
51
- "gitHead": "6b5884d658d97cfb972ec31f2fc8b79b111053b5"
51
+ "gitHead": "1abe0a7b18e0145880247c29517b487dc775b1ab"
52
52
  }