@qafka/react-native 2.0.0

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.
Files changed (178) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/CONTRIBUTING.md +92 -0
  3. package/LICENSE +22 -0
  4. package/README.md +109 -0
  5. package/SECURITY.md +67 -0
  6. package/android/build.gradle +35 -0
  7. package/android/src/main/AndroidManifest.xml +2 -0
  8. package/android/src/main/java/com/qafka/attestation/QafkaAttestationModule.kt +92 -0
  9. package/android/src/main/java/com/qafka/attestation/QafkaAttestationPackage.kt +22 -0
  10. package/android/src/main/java/com/qafka/audio/QafkaAudioModule.kt +290 -0
  11. package/android/src/main/java/com/qafka/clipboard/QafkaClipboardModule.kt +28 -0
  12. package/android/src/main/java/com/qafka/storage/QafkaStorageModule.kt +80 -0
  13. package/app.plugin.js +1 -0
  14. package/dist/QafkaSDK.d.ts +174 -0
  15. package/dist/QafkaSDK.js +461 -0
  16. package/dist/cards/bindings/resolveFieldName.d.ts +25 -0
  17. package/dist/cards/bindings/resolveFieldName.js +82 -0
  18. package/dist/cards/cta/CardContext.d.ts +16 -0
  19. package/dist/cards/cta/CardContext.js +58 -0
  20. package/dist/cards/cta/dispatcher.d.ts +7 -0
  21. package/dist/cards/cta/dispatcher.js +90 -0
  22. package/dist/cards/cta/types.d.ts +66 -0
  23. package/dist/cards/cta/types.js +2 -0
  24. package/dist/cards/index.d.ts +20 -0
  25. package/dist/cards/index.js +34 -0
  26. package/dist/cards/primitives/QButton.d.ts +10 -0
  27. package/dist/cards/primitives/QButton.js +115 -0
  28. package/dist/cards/primitives/QDivider.d.ts +7 -0
  29. package/dist/cards/primitives/QDivider.js +17 -0
  30. package/dist/cards/primitives/QIcon.d.ts +13 -0
  31. package/dist/cards/primitives/QIcon.js +26 -0
  32. package/dist/cards/primitives/QImage.d.ts +9 -0
  33. package/dist/cards/primitives/QImage.js +22 -0
  34. package/dist/cards/primitives/QText.d.ts +9 -0
  35. package/dist/cards/primitives/QText.js +30 -0
  36. package/dist/cards/primitives/QView.d.ts +8 -0
  37. package/dist/cards/primitives/QView.js +19 -0
  38. package/dist/cards/renderer/CardRenderer.d.ts +19 -0
  39. package/dist/cards/renderer/CardRenderer.js +64 -0
  40. package/dist/cards/renderer/renderNode.d.ts +13 -0
  41. package/dist/cards/renderer/renderNode.js +42 -0
  42. package/dist/cards/types.d.ts +110 -0
  43. package/dist/cards/types.js +6 -0
  44. package/dist/components/ActionResultBadge.d.ts +12 -0
  45. package/dist/components/ActionResultBadge.js +58 -0
  46. package/dist/components/ChatPage.d.ts +44 -0
  47. package/dist/components/ChatPage.js +84 -0
  48. package/dist/components/DataChip.d.ts +8 -0
  49. package/dist/components/DataChip.js +80 -0
  50. package/dist/components/DataChipList.d.ts +13 -0
  51. package/dist/components/DataChipList.js +21 -0
  52. package/dist/components/FloatingButton.d.ts +11 -0
  53. package/dist/components/FloatingButton.js +162 -0
  54. package/dist/components/InputArea.d.ts +57 -0
  55. package/dist/components/InputArea.js +142 -0
  56. package/dist/components/MarkdownText.d.ts +15 -0
  57. package/dist/components/MarkdownText.js +283 -0
  58. package/dist/components/MessageBubble.d.ts +134 -0
  59. package/dist/components/MessageBubble.js +384 -0
  60. package/dist/components/NavigationSuggestion.d.ts +11 -0
  61. package/dist/components/NavigationSuggestion.js +109 -0
  62. package/dist/components/Qafka.d.ts +39 -0
  63. package/dist/components/Qafka.handlers.d.ts +21 -0
  64. package/dist/components/Qafka.handlers.js +54 -0
  65. package/dist/components/Qafka.js +493 -0
  66. package/dist/components/Qafka.styles.d.ts +19 -0
  67. package/dist/components/Qafka.styles.js +101 -0
  68. package/dist/components/Qafka.types.d.ts +744 -0
  69. package/dist/components/Qafka.types.js +2 -0
  70. package/dist/components/Qafka.utils.d.ts +7 -0
  71. package/dist/components/Qafka.utils.js +34 -0
  72. package/dist/components/QafkaProvider.d.ts +12 -0
  73. package/dist/components/QafkaProvider.js +87 -0
  74. package/dist/components/QuickReplies.d.ts +14 -0
  75. package/dist/components/QuickReplies.js +48 -0
  76. package/dist/components/StepProgressIndicator.d.ts +12 -0
  77. package/dist/components/StepProgressIndicator.js +48 -0
  78. package/dist/components/SuggestionButton.d.ts +42 -0
  79. package/dist/components/SuggestionButton.js +67 -0
  80. package/dist/components/ToolStatusPill.d.ts +20 -0
  81. package/dist/components/ToolStatusPill.js +43 -0
  82. package/dist/components/TypingIndicator.d.ts +28 -0
  83. package/dist/components/TypingIndicator.js +109 -0
  84. package/dist/components/VoicePage.d.ts +48 -0
  85. package/dist/components/VoicePage.js +683 -0
  86. package/dist/components/defaults/DefaultCard.d.ts +14 -0
  87. package/dist/components/defaults/DefaultCard.js +156 -0
  88. package/dist/components/defaults/DefaultDetail.d.ts +14 -0
  89. package/dist/components/defaults/DefaultDetail.js +138 -0
  90. package/dist/components/defaults/DefaultList.d.ts +12 -0
  91. package/dist/components/defaults/DefaultList.js +98 -0
  92. package/dist/components/defaults/DefaultTable.d.ts +14 -0
  93. package/dist/components/defaults/DefaultTable.js +204 -0
  94. package/dist/components/defaults/index.d.ts +14 -0
  95. package/dist/components/defaults/index.js +25 -0
  96. package/dist/components/index.d.ts +22 -0
  97. package/dist/components/index.js +36 -0
  98. package/dist/constants.d.ts +10 -0
  99. package/dist/constants.js +13 -0
  100. package/dist/hooks/useChatMessages.d.ts +72 -0
  101. package/dist/hooks/useChatMessages.js +505 -0
  102. package/dist/hooks/useContextManager.d.ts +12 -0
  103. package/dist/hooks/useContextManager.js +46 -0
  104. package/dist/hooks/useProjectTheme.d.ts +19 -0
  105. package/dist/hooks/useProjectTheme.js +163 -0
  106. package/dist/hooks/useSDK.d.ts +31 -0
  107. package/dist/hooks/useSDK.js +103 -0
  108. package/dist/hooks/useVoiceChat.d.ts +110 -0
  109. package/dist/hooks/useVoiceChat.js +436 -0
  110. package/dist/index.d.ts +13 -0
  111. package/dist/index.js +59 -0
  112. package/dist/native/QafkaAttestation.d.ts +23 -0
  113. package/dist/native/QafkaAttestation.js +70 -0
  114. package/dist/native/QafkaAudio.d.ts +14 -0
  115. package/dist/native/QafkaAudio.js +31 -0
  116. package/dist/native/QafkaClipboard.d.ts +11 -0
  117. package/dist/native/QafkaClipboard.js +14 -0
  118. package/dist/native/QafkaStorage.d.ts +15 -0
  119. package/dist/native/QafkaStorage.js +12 -0
  120. package/dist/resolve-project-config.d.ts +35 -0
  121. package/dist/resolve-project-config.js +41 -0
  122. package/dist/runtime-config-loader.d.ts +37 -0
  123. package/dist/runtime-config-loader.js +53 -0
  124. package/dist/services/AttestationManager.d.ts +38 -0
  125. package/dist/services/AttestationManager.js +296 -0
  126. package/dist/services/BackendService.d.ts +156 -0
  127. package/dist/services/BackendService.js +755 -0
  128. package/dist/services/ConversationManager.d.ts +43 -0
  129. package/dist/services/ConversationManager.js +96 -0
  130. package/dist/services/NavigationHandler.d.ts +29 -0
  131. package/dist/services/NavigationHandler.js +70 -0
  132. package/dist/services/RealtimeService.d.ts +83 -0
  133. package/dist/services/RealtimeService.js +203 -0
  134. package/dist/services/storage.d.ts +11 -0
  135. package/dist/services/storage.js +15 -0
  136. package/dist/services/storageCore.d.ts +17 -0
  137. package/dist/services/storageCore.js +46 -0
  138. package/dist/themes/dark.d.ts +5 -0
  139. package/dist/themes/dark.js +129 -0
  140. package/dist/themes/index.d.ts +12 -0
  141. package/dist/themes/index.js +33 -0
  142. package/dist/themes/light.d.ts +5 -0
  143. package/dist/themes/light.js +129 -0
  144. package/dist/themes/types.d.ts +155 -0
  145. package/dist/themes/types.js +5 -0
  146. package/dist/types/chat.d.ts +126 -0
  147. package/dist/types/chat.js +5 -0
  148. package/dist/types/components.d.ts +56 -0
  149. package/dist/types/components.js +16 -0
  150. package/dist/types/external-navigation.d.ts +19 -0
  151. package/dist/types/external-navigation.js +8 -0
  152. package/dist/types/index.d.ts +9 -0
  153. package/dist/types/index.js +25 -0
  154. package/dist/types/navigation.d.ts +86 -0
  155. package/dist/types/navigation.js +5 -0
  156. package/dist/types/sdk.d.ts +36 -0
  157. package/dist/types/sdk.js +5 -0
  158. package/dist/utils/deepMerge.d.ts +46 -0
  159. package/dist/utils/deepMerge.js +70 -0
  160. package/dist/utils/fontUtils.d.ts +8 -0
  161. package/dist/utils/fontUtils.js +16 -0
  162. package/dist/validate-end-user.d.ts +18 -0
  163. package/dist/validate-end-user.js +74 -0
  164. package/expo-plugin/withQafkaAttestation.js +57 -0
  165. package/ios/QafkaAttestation.m +25 -0
  166. package/ios/QafkaAttestation.swift +128 -0
  167. package/ios/QafkaAudio.m +23 -0
  168. package/ios/QafkaAudio.swift +519 -0
  169. package/ios/QafkaClipboard.m +10 -0
  170. package/ios/QafkaClipboard.swift +21 -0
  171. package/ios/QafkaReactImports.h +2 -0
  172. package/ios/QafkaStorage.m +26 -0
  173. package/ios/QafkaStorage.swift +118 -0
  174. package/package.json +82 -0
  175. package/qafka.config.d.ts +9 -0
  176. package/qafka.config.js +9 -0
  177. package/react-native-qafka.podspec +28 -0
  178. package/react-native.config.js +14 -0
@@ -0,0 +1,156 @@
1
+ import { ChatResponse } from '../types';
2
+ /**
3
+ * Backend API Service using native fetch
4
+ */
5
+ export declare class BackendService {
6
+ private baseURL;
7
+ private apiKey;
8
+ private subProjectId;
9
+ private endUserId;
10
+ private endUserData;
11
+ private timeout;
12
+ private bundleId;
13
+ private appVersion;
14
+ private deviceModel;
15
+ private sessionTokenGetter;
16
+ private attestationManager;
17
+ private refreshing;
18
+ private locale;
19
+ private onToolDataRequested;
20
+ private readonly toolDataResolvedFor;
21
+ private static readonly RESOLVER_TIMEOUT_MS;
22
+ constructor(apiKey: string | null, apiUrl?: string, subProjectId?: string);
23
+ setSessionTokenGetter(getter: () => Promise<string | null>): void;
24
+ /**
25
+ * Store the validated end-user identity for subsequent chat requests.
26
+ * Called by the React component on mount and whenever the `endUserId` /
27
+ * `endUserData` props change. Validation happens upstream
28
+ * (`validate-end-user.ts`) so this method only persists the result.
29
+ */
30
+ setEndUser(endUserId: string, endUserData?: Record<string, unknown>): void;
31
+ setAttestationManager(am: {
32
+ refresh(): Promise<string | null>;
33
+ }): void;
34
+ /**
35
+ * Single-flight refresh: concurrent callers share the same in-flight promise.
36
+ * Prevents multiple parallel re-attests when several requests fail simultaneously.
37
+ */
38
+ private refreshSession;
39
+ /**
40
+ * fetch() with automatic session refresh when the backend signals it —
41
+ * reactively on a 429 refresh hint, proactively when the budget header is
42
+ * low. Caller passes an init that already has Authorization/x-api-key set;
43
+ * on retry, only the Bearer header is swapped.
44
+ */
45
+ private fetchWithRefresh;
46
+ /**
47
+ * Tool Data Channel: register the partner-provided resolver that
48
+ * supplies transient PII (`{{tooldata.X}}` substitution) bags. Called from
49
+ * QafkaSDK with the `onToolDataRequested` prop. Pass `null` to clear.
50
+ */
51
+ setOnToolDataRequested(resolver: ((tool: {
52
+ key: string;
53
+ name: string;
54
+ }) => Record<string, unknown> | Promise<Record<string, unknown>>) | null): void;
55
+ /**
56
+ * explicit-intent locale. Only included in sdkContext when set —
57
+ * Qafka.tsx wires this from the `locale` prop. Developer can also call
58
+ * directly via QafkaSDK.setLocale().
59
+ */
60
+ setLocale(locale: string | null): void;
61
+ /**
62
+ * Build the SDK context attached to every request: universal temporal
63
+ * fields plus locale when the developer has set it.
64
+ */
65
+ private buildSdkContext;
66
+ /**
67
+ * Get security headers for API requests
68
+ */
69
+ private getSecurityHeaders;
70
+ /**
71
+ * Tool Data Channel: invokes the partner resolver, POSTs the
72
+ * opaque bag to /chat/tool-data. Per-execId dedupe, soft timeout, fail-soft.
73
+ * Called by the tool_suggestions SSE handler when `needData=true`.
74
+ */
75
+ private resolveAndPostToolData;
76
+ /**
77
+ * POST tooldata bag to backend. Uses the standard SDK auth headers (API key
78
+ * + device attestation session token) — same chain as sendMessageStream.
79
+ * No retry, no body persistence; 64KB cap enforced server-side.
80
+ */
81
+ private postToolData;
82
+ /**
83
+ * Make HTTP request with timeout
84
+ */
85
+ private fetchWithTimeout;
86
+ /**
87
+ * Handle response errors with detailed messages
88
+ */
89
+ private handleResponse;
90
+ /**
91
+ * Send chat message to backend
92
+ */
93
+ sendMessage(message: string, sessionId: string, context?: Record<string, any>, contextDescription?: string, isInitialMessage?: boolean): Promise<ChatResponse>;
94
+ /**
95
+ * Get conversation history
96
+ */
97
+ getHistory(sessionId: string, limit?: number): Promise<any>;
98
+ /**
99
+ * Delete conversation
100
+ */
101
+ deleteConversation(sessionId: string): Promise<void>;
102
+ /**
103
+ * Get project theme
104
+ */
105
+ getTheme(): Promise<any>;
106
+ /**
107
+ * Send message with streaming response
108
+ * React Native compatible version using XMLHttpRequest
109
+ */
110
+ sendMessageStream(message: string, sessionId: string, onChunk: (chunk: string) => void, onComplete: (response: ChatResponse) => void, onError: (error: Error) => void, context?: Record<string, any>, contextDescription?: string, onToolSuggestions?: (tools: any[], conversationId?: string, messageId?: string) => void, // Tool suggestions callback
111
+ isInitialMessage?: boolean, onActionResult?: (results: Array<{
112
+ actionType: string;
113
+ success: boolean;
114
+ message: string;
115
+ }>) => void, // Action result callback
116
+ onStepCompleted?: (result: {
117
+ tool: string;
118
+ step: string;
119
+ data: Record<string, any>;
120
+ actionResults?: Array<{
121
+ actionType: string;
122
+ success: boolean;
123
+ message: string;
124
+ }>;
125
+ }) => void, // Step completed callback
126
+ onFileUploadRequest?: (request: any) => void, onExtractionResult?: (result: any) => void, onToolStatus?: (event: {
127
+ toolKey: string;
128
+ message: string;
129
+ stage: string;
130
+ }) => void, onToolResultPayload?: (event: {
131
+ toolKey: string;
132
+ data: unknown;
133
+ uiConfig?: any;
134
+ }) => void, onFinalChunk?: (content: string) => void): Promise<void>;
135
+ /**
136
+ * Post a tool result back to the backend so the AI can continue its turn.
137
+ * Streams back `final_chunk` and `done` events.
138
+ */
139
+ postToolResult(payload: {
140
+ conversationId: string;
141
+ messageId: string;
142
+ toolKey: string;
143
+ data: unknown;
144
+ sdkContext?: Record<string, unknown>;
145
+ }, onFinalChunk: (content: string) => void, onDone: () => void, onError: (err: Error) => void, onCard?: (card: {
146
+ templateId: string;
147
+ templateSlug: string;
148
+ definition: any;
149
+ data: any;
150
+ }) => void): Promise<void>;
151
+ uploadFile(toolId: string, file: {
152
+ uri: string;
153
+ name: string;
154
+ type: string;
155
+ }, conversationId?: string): Promise<any>;
156
+ }