@arbidocs/react 0.1.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.
- package/README.md +162 -0
- package/dist/index.cjs +98 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +132 -0
- package/dist/index.d.ts +132 -0
- package/dist/index.js +81 -0
- package/dist/index.js.map +1 -0
- package/package.json +60 -0
package/README.md
ADDED
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
# @arbidocs/react
|
|
2
|
+
|
|
3
|
+
React hooks and provider for the ARBI SDK. Built on `@arbidocs/core` and `@tanstack/react-query`.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @arbidocs/react
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Quick Start
|
|
12
|
+
|
|
13
|
+
Wrap your app with `ArbiProvider` and a React Query `QueryClientProvider`:
|
|
14
|
+
|
|
15
|
+
```tsx
|
|
16
|
+
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
|
|
17
|
+
import { ArbiProvider } from '@arbidocs/react'
|
|
18
|
+
|
|
19
|
+
const queryClient = new QueryClient()
|
|
20
|
+
|
|
21
|
+
function App() {
|
|
22
|
+
return (
|
|
23
|
+
<QueryClientProvider client={queryClient}>
|
|
24
|
+
<ArbiProvider url="https://arbi.mycompany.com">
|
|
25
|
+
<MyApp />
|
|
26
|
+
</ArbiProvider>
|
|
27
|
+
</QueryClientProvider>
|
|
28
|
+
)
|
|
29
|
+
}
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
Then use the hooks in any component:
|
|
33
|
+
|
|
34
|
+
```tsx
|
|
35
|
+
import { useArbi, useWorkspaces, useDocuments } from '@arbidocs/react'
|
|
36
|
+
|
|
37
|
+
function WorkspaceView() {
|
|
38
|
+
const arbi = useArbi()
|
|
39
|
+
const { data: workspaces, isLoading } = useWorkspaces()
|
|
40
|
+
|
|
41
|
+
if (isLoading) return <div>Loading...</div>
|
|
42
|
+
|
|
43
|
+
return (
|
|
44
|
+
<ul>
|
|
45
|
+
{workspaces?.map((ws) => (
|
|
46
|
+
<li key={ws.external_id}>{ws.name}</li>
|
|
47
|
+
))}
|
|
48
|
+
</ul>
|
|
49
|
+
)
|
|
50
|
+
}
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## Hooks
|
|
54
|
+
|
|
55
|
+
### `useArbi()`
|
|
56
|
+
|
|
57
|
+
Returns the `Arbi` instance from context. Use this for imperative operations like login, workspace selection, and direct API calls.
|
|
58
|
+
|
|
59
|
+
```tsx
|
|
60
|
+
const arbi = useArbi()
|
|
61
|
+
|
|
62
|
+
await arbi.login('user@example.com', 'password')
|
|
63
|
+
await arbi.selectWorkspace('wrk-123')
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
### `useWorkspaces(options?)`
|
|
67
|
+
|
|
68
|
+
Fetches the user's workspaces. Automatically enabled when logged in.
|
|
69
|
+
|
|
70
|
+
```tsx
|
|
71
|
+
const { data, isLoading, error } = useWorkspaces()
|
|
72
|
+
const { data } = useWorkspaces({ enabled: false }) // manual control
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
### `useDocuments(workspaceId, options?)`
|
|
76
|
+
|
|
77
|
+
Fetches documents for a workspace. Automatically disabled when `workspaceId` is undefined.
|
|
78
|
+
|
|
79
|
+
```tsx
|
|
80
|
+
const { data: docs } = useDocuments('wrk-123')
|
|
81
|
+
const { data: docs } = useDocuments(undefined) // won't fetch
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
### `useConversations(workspaceId, options?)`
|
|
85
|
+
|
|
86
|
+
Fetches conversations for a workspace.
|
|
87
|
+
|
|
88
|
+
```tsx
|
|
89
|
+
const { data: conversations } = useConversations('wrk-123')
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
### `useTags(workspaceId, options?)`
|
|
93
|
+
|
|
94
|
+
Fetches tags for a workspace.
|
|
95
|
+
|
|
96
|
+
```tsx
|
|
97
|
+
const { data: tags } = useTags('wrk-123')
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
### `useHealth(options?)`
|
|
101
|
+
|
|
102
|
+
Checks backend health.
|
|
103
|
+
|
|
104
|
+
```tsx
|
|
105
|
+
const { data } = useHealth({ enabled: true })
|
|
106
|
+
// { status: 'ok' }
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
### `useAssistantQuery()`
|
|
110
|
+
|
|
111
|
+
Returns a React Query mutation for streaming AI queries.
|
|
112
|
+
|
|
113
|
+
```tsx
|
|
114
|
+
const mutation = useAssistantQuery()
|
|
115
|
+
|
|
116
|
+
const handleAsk = () => {
|
|
117
|
+
mutation.mutate({
|
|
118
|
+
question: 'What does section 3 say?',
|
|
119
|
+
docIds: ['doc-123'],
|
|
120
|
+
onToken: (token) => setResponse((prev) => prev + token),
|
|
121
|
+
onComplete: () => console.log('Done'),
|
|
122
|
+
})
|
|
123
|
+
}
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
## Query Keys
|
|
127
|
+
|
|
128
|
+
All hooks use the `arbiQueryKeys` factory for cache management:
|
|
129
|
+
|
|
130
|
+
```tsx
|
|
131
|
+
import { arbiQueryKeys } from '@arbidocs/react'
|
|
132
|
+
import { useQueryClient } from '@tanstack/react-query'
|
|
133
|
+
|
|
134
|
+
const queryClient = useQueryClient()
|
|
135
|
+
|
|
136
|
+
// Invalidate all documents
|
|
137
|
+
queryClient.invalidateQueries({ queryKey: arbiQueryKeys.documents('wrk-123') })
|
|
138
|
+
|
|
139
|
+
// Available keys:
|
|
140
|
+
arbiQueryKeys.workspaces() // ['arbi', 'workspaces']
|
|
141
|
+
arbiQueryKeys.documents(workspaceId) // ['arbi', 'documents', workspaceId]
|
|
142
|
+
arbiQueryKeys.conversations(workspaceId)
|
|
143
|
+
arbiQueryKeys.tags(workspaceId)
|
|
144
|
+
arbiQueryKeys.health()
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
## Re-exports
|
|
148
|
+
|
|
149
|
+
The package re-exports key types from `@arbidocs/core/browser` for convenience:
|
|
150
|
+
|
|
151
|
+
```tsx
|
|
152
|
+
import { Arbi, ArbiError } from '@arbidocs/react'
|
|
153
|
+
import type { ArbiOptions, QueryOptions, SSEStreamResult, SSEStreamCallbacks } from '@arbidocs/react'
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
## Examples
|
|
157
|
+
|
|
158
|
+
See the **[React Chat App](../../examples/react-chat/)** for a complete working example with login, workspace selection, document picker, and streaming chat.
|
|
159
|
+
|
|
160
|
+
## Peer Dependencies
|
|
161
|
+
|
|
162
|
+
- `react` >= 18
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var react = require('react');
|
|
4
|
+
var browser = require('@arbidocs/core/browser');
|
|
5
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
6
|
+
var reactQuery = require('@tanstack/react-query');
|
|
7
|
+
|
|
8
|
+
// src/ArbiProvider.tsx
|
|
9
|
+
var ArbiContext = react.createContext(null);
|
|
10
|
+
function ArbiProvider({ children, ...options }) {
|
|
11
|
+
const arbi = react.useMemo(
|
|
12
|
+
() => new browser.Arbi(options),
|
|
13
|
+
// Stable on url + deploymentDomain — re-creating the instance on every render would be wrong
|
|
14
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
15
|
+
[options.url, options.deploymentDomain, options.credentials]
|
|
16
|
+
);
|
|
17
|
+
return /* @__PURE__ */ jsxRuntime.jsx(ArbiContext.Provider, { value: arbi, children });
|
|
18
|
+
}
|
|
19
|
+
function useArbi() {
|
|
20
|
+
const arbi = react.useContext(ArbiContext);
|
|
21
|
+
if (!arbi) {
|
|
22
|
+
throw new Error("useArbi() must be used within an <ArbiProvider>");
|
|
23
|
+
}
|
|
24
|
+
return arbi;
|
|
25
|
+
}
|
|
26
|
+
var arbiQueryKeys = {
|
|
27
|
+
workspaces: () => ["arbi", "workspaces"],
|
|
28
|
+
documents: (workspaceId) => ["arbi", "documents", workspaceId],
|
|
29
|
+
conversations: (workspaceId) => ["arbi", "conversations", workspaceId],
|
|
30
|
+
tags: (workspaceId) => ["arbi", "tags", workspaceId],
|
|
31
|
+
health: () => ["arbi", "health"]
|
|
32
|
+
};
|
|
33
|
+
function useWorkspaces(options) {
|
|
34
|
+
const arbi = useArbi();
|
|
35
|
+
return reactQuery.useQuery({
|
|
36
|
+
queryKey: arbiQueryKeys.workspaces(),
|
|
37
|
+
queryFn: () => arbi.workspaces.list(),
|
|
38
|
+
enabled: options?.enabled ?? arbi.isLoggedIn
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
function useDocuments(workspaceId, options) {
|
|
42
|
+
const arbi = useArbi();
|
|
43
|
+
return reactQuery.useQuery({
|
|
44
|
+
queryKey: arbiQueryKeys.documents(workspaceId ?? ""),
|
|
45
|
+
queryFn: () => arbi.documents.list(workspaceId),
|
|
46
|
+
enabled: (options?.enabled ?? true) && !!workspaceId && arbi.hasWorkspace
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
function useConversations(workspaceId, options) {
|
|
50
|
+
const arbi = useArbi();
|
|
51
|
+
return reactQuery.useQuery({
|
|
52
|
+
queryKey: arbiQueryKeys.conversations(workspaceId ?? ""),
|
|
53
|
+
queryFn: () => arbi.conversations.list(workspaceId),
|
|
54
|
+
enabled: (options?.enabled ?? true) && !!workspaceId && arbi.hasWorkspace
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
function useTags(workspaceId, options) {
|
|
58
|
+
const arbi = useArbi();
|
|
59
|
+
return reactQuery.useQuery({
|
|
60
|
+
queryKey: arbiQueryKeys.tags(workspaceId ?? ""),
|
|
61
|
+
queryFn: () => arbi.tags.list(workspaceId),
|
|
62
|
+
enabled: (options?.enabled ?? true) && !!workspaceId && arbi.hasWorkspace
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
function useAssistantQuery() {
|
|
66
|
+
const arbi = useArbi();
|
|
67
|
+
return reactQuery.useMutation({
|
|
68
|
+
mutationFn: ({ question, ...options }) => arbi.assistant.query(question, options)
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
function useHealth(options) {
|
|
72
|
+
const arbi = useArbi();
|
|
73
|
+
return reactQuery.useQuery({
|
|
74
|
+
queryKey: arbiQueryKeys.health(),
|
|
75
|
+
queryFn: () => arbi.health.check(),
|
|
76
|
+
enabled: options?.enabled
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
Object.defineProperty(exports, "Arbi", {
|
|
81
|
+
enumerable: true,
|
|
82
|
+
get: function () { return browser.Arbi; }
|
|
83
|
+
});
|
|
84
|
+
Object.defineProperty(exports, "ArbiError", {
|
|
85
|
+
enumerable: true,
|
|
86
|
+
get: function () { return browser.ArbiError; }
|
|
87
|
+
});
|
|
88
|
+
exports.ArbiProvider = ArbiProvider;
|
|
89
|
+
exports.arbiQueryKeys = arbiQueryKeys;
|
|
90
|
+
exports.useArbi = useArbi;
|
|
91
|
+
exports.useAssistantQuery = useAssistantQuery;
|
|
92
|
+
exports.useConversations = useConversations;
|
|
93
|
+
exports.useDocuments = useDocuments;
|
|
94
|
+
exports.useHealth = useHealth;
|
|
95
|
+
exports.useTags = useTags;
|
|
96
|
+
exports.useWorkspaces = useWorkspaces;
|
|
97
|
+
//# sourceMappingURL=index.cjs.map
|
|
98
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/ArbiProvider.tsx","../src/useArbi.ts","../src/hooks.ts"],"names":["createContext","useMemo","Arbi","useContext","useQuery","useMutation"],"mappings":";;;;;;;;AAYO,IAAM,WAAA,GAAcA,oBAA2B,IAAI,CAAA;AAMnD,SAAS,YAAA,CAAa,EAAE,QAAA,EAAU,GAAG,SAAQ,EAAsB;AACxE,EAAA,MAAM,IAAA,GAAOC,aAAA;AAAA,IACX,MAAM,IAAIC,YAAA,CA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AA,MAAM,OAAO,OAAA,EAAQ;AACrB,EAAA,OAAOD,mBAAA,CAAS;AAAA,IACd,QAAA,EAAU,cAAc,MAAA,EAAO;AAAA,IAC/B,OAAA,EAAS,MAAM,IAAA,CAAK,MAAA,CAAO,KAAA,EAAM;AAAA,IACjC,SAAS,OAAA,EAAS;AAAA,GACnB,CAAA;AACH","file":"index.cjs","sourcesContent":["/**\n * ArbiProvider — React context that holds an Arbi instance.\n *\n * Usage:\n * <ArbiProvider url=\"https://arbi.mycompany.com\">\n * <App />\n * </ArbiProvider>\n */\n\nimport { createContext, useMemo, type ReactNode } from 'react'\nimport { Arbi, type ArbiOptions } from '@arbidocs/core/browser'\n\nexport const ArbiContext = createContext<Arbi | null>(null)\n\nexport interface ArbiProviderProps extends ArbiOptions {\n children: ReactNode\n}\n\nexport function ArbiProvider({ children, ...options }: ArbiProviderProps) {\n const arbi = useMemo(\n () => new Arbi(options),\n // Stable on url + deploymentDomain — re-creating the instance on every render would be wrong\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [options.url, options.deploymentDomain, options.credentials]\n )\n\n return <ArbiContext.Provider value={arbi}>{children}</ArbiContext.Provider>\n}\n","/**\n * Hook to access the Arbi instance from the nearest ArbiProvider.\n */\n\nimport { useContext } from 'react'\nimport type { Arbi } from '@arbidocs/core/browser'\nimport { ArbiContext } from './ArbiProvider'\n\nexport function useArbi(): Arbi {\n const arbi = useContext(ArbiContext)\n if (!arbi) {\n throw new Error('useArbi() must be used within an <ArbiProvider>')\n }\n return arbi\n}\n","/**\n * React Query hooks that use the Arbi instance from context.\n */\n\nimport { useQuery, useMutation } from '@tanstack/react-query'\nimport type { SSEStreamResult } from '@arbidocs/core/browser'\nimport { useArbi } from './useArbi'\n\n// ── Query keys ──────────────────────────────────────────────────────────────\n\nexport const arbiQueryKeys = {\n workspaces: () => ['arbi', 'workspaces'] as const,\n documents: (workspaceId: string) => ['arbi', 'documents', workspaceId] as const,\n conversations: (workspaceId: string) => ['arbi', 'conversations', workspaceId] as const,\n tags: (workspaceId: string) => ['arbi', 'tags', workspaceId] as const,\n health: () => ['arbi', 'health'] as const,\n}\n\n// ── Hooks ───────────────────────────────────────────────────────────────────\n\n/** List the logged-in user's workspaces. */\nexport function useWorkspaces(options?: { enabled?: boolean }) {\n const arbi = useArbi()\n return useQuery({\n queryKey: arbiQueryKeys.workspaces(),\n queryFn: () => arbi.workspaces.list(),\n enabled: options?.enabled ?? arbi.isLoggedIn,\n })\n}\n\n/** List documents in a workspace. */\nexport function useDocuments(workspaceId: string | undefined, options?: { enabled?: boolean }) {\n const arbi = useArbi()\n return useQuery({\n queryKey: arbiQueryKeys.documents(workspaceId ?? ''),\n queryFn: () => arbi.documents.list(workspaceId),\n enabled: (options?.enabled ?? true) && !!workspaceId && arbi.hasWorkspace,\n })\n}\n\n/** List conversations in a workspace. */\nexport function useConversations(workspaceId: string | undefined, options?: { enabled?: boolean }) {\n const arbi = useArbi()\n return useQuery({\n queryKey: arbiQueryKeys.conversations(workspaceId ?? ''),\n queryFn: () => arbi.conversations.list(workspaceId),\n enabled: (options?.enabled ?? true) && !!workspaceId && arbi.hasWorkspace,\n })\n}\n\n/** List tags in a workspace. */\nexport function useTags(workspaceId: string | undefined, options?: { enabled?: boolean }) {\n const arbi = useArbi()\n return useQuery({\n queryKey: arbiQueryKeys.tags(workspaceId ?? ''),\n queryFn: () => arbi.tags.list(workspaceId),\n enabled: (options?.enabled ?? true) && !!workspaceId && arbi.hasWorkspace,\n })\n}\n\n/** Send a streaming query to the RAG assistant. Returns a mutation. */\nexport function useAssistantQuery() {\n const arbi = useArbi()\n\n return useMutation<\n SSEStreamResult,\n Error,\n {\n question: string\n docIds: string[]\n parentMessageExtId?: string | null\n configExtId?: string\n onToken?: (content: string) => void\n onStreamStart?: (data: { assistant_message_ext_id?: string }) => void\n onAgentStep?: (data: { focus?: string; status?: string }) => void\n onError?: (message: string) => void\n onComplete?: () => void\n }\n >({\n mutationFn: ({ question, ...options }) => arbi.assistant.query(question, options),\n })\n}\n\n/** Check backend health. */\nexport function useHealth(options?: { enabled?: boolean }) {\n const arbi = useArbi()\n return useQuery({\n queryKey: arbiQueryKeys.health(),\n queryFn: () => arbi.health.check(),\n enabled: options?.enabled,\n })\n}\n"]}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import { ReactNode } from 'react';
|
|
3
|
+
import { ArbiOptions, Arbi, SSEStreamResult } from '@arbidocs/core/browser';
|
|
4
|
+
export { Arbi, ArbiError, ArbiOptions, QueryOptions, SSEStreamCallbacks, SSEStreamResult } from '@arbidocs/core/browser';
|
|
5
|
+
import * as _tanstack_react_query from '@tanstack/react-query';
|
|
6
|
+
import * as _arbidocs_sdk from '@arbidocs/sdk';
|
|
7
|
+
|
|
8
|
+
interface ArbiProviderProps extends ArbiOptions {
|
|
9
|
+
children: ReactNode;
|
|
10
|
+
}
|
|
11
|
+
declare function ArbiProvider({ children, ...options }: ArbiProviderProps): react_jsx_runtime.JSX.Element;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Hook to access the Arbi instance from the nearest ArbiProvider.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
declare function useArbi(): Arbi;
|
|
18
|
+
|
|
19
|
+
declare const arbiQueryKeys: {
|
|
20
|
+
workspaces: () => readonly ["arbi", "workspaces"];
|
|
21
|
+
documents: (workspaceId: string) => readonly ["arbi", "documents", string];
|
|
22
|
+
conversations: (workspaceId: string) => readonly ["arbi", "conversations", string];
|
|
23
|
+
tags: (workspaceId: string) => readonly ["arbi", "tags", string];
|
|
24
|
+
health: () => readonly ["arbi", "health"];
|
|
25
|
+
};
|
|
26
|
+
/** List the logged-in user's workspaces. */
|
|
27
|
+
declare function useWorkspaces(options?: {
|
|
28
|
+
enabled?: boolean;
|
|
29
|
+
}): _tanstack_react_query.UseQueryResult<{
|
|
30
|
+
external_id: string;
|
|
31
|
+
name: string;
|
|
32
|
+
description: string | null;
|
|
33
|
+
is_public: boolean;
|
|
34
|
+
created_by_ext_id: string;
|
|
35
|
+
updated_by_ext_id?: string | null;
|
|
36
|
+
created_at: string;
|
|
37
|
+
updated_at: string;
|
|
38
|
+
wrapped_key?: string | null;
|
|
39
|
+
shared_conversation_count: number;
|
|
40
|
+
private_conversation_count: number;
|
|
41
|
+
shared_document_count: number;
|
|
42
|
+
private_document_count: number;
|
|
43
|
+
user_files_mb: number;
|
|
44
|
+
users: _arbidocs_sdk.components["schemas"]["WorkspaceUserResponse"][];
|
|
45
|
+
}[], Error>;
|
|
46
|
+
/** List documents in a workspace. */
|
|
47
|
+
declare function useDocuments(workspaceId: string | undefined, options?: {
|
|
48
|
+
enabled?: boolean;
|
|
49
|
+
}): _tanstack_react_query.UseQueryResult<{
|
|
50
|
+
external_id: string;
|
|
51
|
+
workspace_ext_id: string;
|
|
52
|
+
file_name?: string | null;
|
|
53
|
+
status?: string | null;
|
|
54
|
+
n_pages?: number | null;
|
|
55
|
+
n_chunks?: number | null;
|
|
56
|
+
tokens?: number | null;
|
|
57
|
+
file_type?: string | null;
|
|
58
|
+
file_size?: number | null;
|
|
59
|
+
storage_type?: string | null;
|
|
60
|
+
storage_uri?: string | null;
|
|
61
|
+
content_hash?: string | null;
|
|
62
|
+
shared?: boolean | null;
|
|
63
|
+
re_ocred?: boolean | null;
|
|
64
|
+
config_ext_id?: string | null;
|
|
65
|
+
created_by_ext_id: string;
|
|
66
|
+
updated_by_ext_id?: string | null;
|
|
67
|
+
created_at: string;
|
|
68
|
+
updated_at: string;
|
|
69
|
+
wp_type?: string | null;
|
|
70
|
+
doctags: _arbidocs_sdk.components["schemas"]["DocTagResponse"][];
|
|
71
|
+
doc_metadata?: _arbidocs_sdk.components["schemas"]["DocMetadata"] | null;
|
|
72
|
+
}[], Error>;
|
|
73
|
+
/** List conversations in a workspace. */
|
|
74
|
+
declare function useConversations(workspaceId: string | undefined, options?: {
|
|
75
|
+
enabled?: boolean;
|
|
76
|
+
}): _tanstack_react_query.UseQueryResult<{
|
|
77
|
+
external_id: string;
|
|
78
|
+
title: string | null;
|
|
79
|
+
created_by_ext_id: string;
|
|
80
|
+
updated_by_ext_id?: string | null;
|
|
81
|
+
created_at: string;
|
|
82
|
+
updated_at: string;
|
|
83
|
+
is_shared: boolean;
|
|
84
|
+
message_count: number;
|
|
85
|
+
}[], Error>;
|
|
86
|
+
/** List tags in a workspace. */
|
|
87
|
+
declare function useTags(workspaceId: string | undefined, options?: {
|
|
88
|
+
enabled?: boolean;
|
|
89
|
+
}): _tanstack_react_query.UseQueryResult<{
|
|
90
|
+
external_id: string;
|
|
91
|
+
workspace_ext_id: string;
|
|
92
|
+
name: string;
|
|
93
|
+
instruction?: string | null;
|
|
94
|
+
tag_type: _arbidocs_sdk.components["schemas"]["TagFormat"];
|
|
95
|
+
shared: boolean;
|
|
96
|
+
parent_ext_id?: string | null;
|
|
97
|
+
doctag_count: number;
|
|
98
|
+
created_by_ext_id: string;
|
|
99
|
+
updated_by_ext_id?: string | null;
|
|
100
|
+
created_at: string;
|
|
101
|
+
updated_at: string;
|
|
102
|
+
}[], Error>;
|
|
103
|
+
/** Send a streaming query to the RAG assistant. Returns a mutation. */
|
|
104
|
+
declare function useAssistantQuery(): _tanstack_react_query.UseMutationResult<SSEStreamResult, Error, {
|
|
105
|
+
question: string;
|
|
106
|
+
docIds: string[];
|
|
107
|
+
parentMessageExtId?: string | null;
|
|
108
|
+
configExtId?: string;
|
|
109
|
+
onToken?: (content: string) => void;
|
|
110
|
+
onStreamStart?: (data: {
|
|
111
|
+
assistant_message_ext_id?: string;
|
|
112
|
+
}) => void;
|
|
113
|
+
onAgentStep?: (data: {
|
|
114
|
+
focus?: string;
|
|
115
|
+
status?: string;
|
|
116
|
+
}) => void;
|
|
117
|
+
onError?: (message: string) => void;
|
|
118
|
+
onComplete?: () => void;
|
|
119
|
+
}, unknown>;
|
|
120
|
+
/** Check backend health. */
|
|
121
|
+
declare function useHealth(options?: {
|
|
122
|
+
enabled?: boolean;
|
|
123
|
+
}): _tanstack_react_query.UseQueryResult<{
|
|
124
|
+
status: string;
|
|
125
|
+
backend_git_hash?: string | null;
|
|
126
|
+
frontend_docker_version?: string | null;
|
|
127
|
+
services: _arbidocs_sdk.components["schemas"]["ServiceStatus"][];
|
|
128
|
+
models_health?: _arbidocs_sdk.components["schemas"]["ModelsHealthStatus"] | null;
|
|
129
|
+
available_models: string[];
|
|
130
|
+
}, Error>;
|
|
131
|
+
|
|
132
|
+
export { ArbiProvider, type ArbiProviderProps, arbiQueryKeys, useArbi, useAssistantQuery, useConversations, useDocuments, useHealth, useTags, useWorkspaces };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import { ReactNode } from 'react';
|
|
3
|
+
import { ArbiOptions, Arbi, SSEStreamResult } from '@arbidocs/core/browser';
|
|
4
|
+
export { Arbi, ArbiError, ArbiOptions, QueryOptions, SSEStreamCallbacks, SSEStreamResult } from '@arbidocs/core/browser';
|
|
5
|
+
import * as _tanstack_react_query from '@tanstack/react-query';
|
|
6
|
+
import * as _arbidocs_sdk from '@arbidocs/sdk';
|
|
7
|
+
|
|
8
|
+
interface ArbiProviderProps extends ArbiOptions {
|
|
9
|
+
children: ReactNode;
|
|
10
|
+
}
|
|
11
|
+
declare function ArbiProvider({ children, ...options }: ArbiProviderProps): react_jsx_runtime.JSX.Element;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Hook to access the Arbi instance from the nearest ArbiProvider.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
declare function useArbi(): Arbi;
|
|
18
|
+
|
|
19
|
+
declare const arbiQueryKeys: {
|
|
20
|
+
workspaces: () => readonly ["arbi", "workspaces"];
|
|
21
|
+
documents: (workspaceId: string) => readonly ["arbi", "documents", string];
|
|
22
|
+
conversations: (workspaceId: string) => readonly ["arbi", "conversations", string];
|
|
23
|
+
tags: (workspaceId: string) => readonly ["arbi", "tags", string];
|
|
24
|
+
health: () => readonly ["arbi", "health"];
|
|
25
|
+
};
|
|
26
|
+
/** List the logged-in user's workspaces. */
|
|
27
|
+
declare function useWorkspaces(options?: {
|
|
28
|
+
enabled?: boolean;
|
|
29
|
+
}): _tanstack_react_query.UseQueryResult<{
|
|
30
|
+
external_id: string;
|
|
31
|
+
name: string;
|
|
32
|
+
description: string | null;
|
|
33
|
+
is_public: boolean;
|
|
34
|
+
created_by_ext_id: string;
|
|
35
|
+
updated_by_ext_id?: string | null;
|
|
36
|
+
created_at: string;
|
|
37
|
+
updated_at: string;
|
|
38
|
+
wrapped_key?: string | null;
|
|
39
|
+
shared_conversation_count: number;
|
|
40
|
+
private_conversation_count: number;
|
|
41
|
+
shared_document_count: number;
|
|
42
|
+
private_document_count: number;
|
|
43
|
+
user_files_mb: number;
|
|
44
|
+
users: _arbidocs_sdk.components["schemas"]["WorkspaceUserResponse"][];
|
|
45
|
+
}[], Error>;
|
|
46
|
+
/** List documents in a workspace. */
|
|
47
|
+
declare function useDocuments(workspaceId: string | undefined, options?: {
|
|
48
|
+
enabled?: boolean;
|
|
49
|
+
}): _tanstack_react_query.UseQueryResult<{
|
|
50
|
+
external_id: string;
|
|
51
|
+
workspace_ext_id: string;
|
|
52
|
+
file_name?: string | null;
|
|
53
|
+
status?: string | null;
|
|
54
|
+
n_pages?: number | null;
|
|
55
|
+
n_chunks?: number | null;
|
|
56
|
+
tokens?: number | null;
|
|
57
|
+
file_type?: string | null;
|
|
58
|
+
file_size?: number | null;
|
|
59
|
+
storage_type?: string | null;
|
|
60
|
+
storage_uri?: string | null;
|
|
61
|
+
content_hash?: string | null;
|
|
62
|
+
shared?: boolean | null;
|
|
63
|
+
re_ocred?: boolean | null;
|
|
64
|
+
config_ext_id?: string | null;
|
|
65
|
+
created_by_ext_id: string;
|
|
66
|
+
updated_by_ext_id?: string | null;
|
|
67
|
+
created_at: string;
|
|
68
|
+
updated_at: string;
|
|
69
|
+
wp_type?: string | null;
|
|
70
|
+
doctags: _arbidocs_sdk.components["schemas"]["DocTagResponse"][];
|
|
71
|
+
doc_metadata?: _arbidocs_sdk.components["schemas"]["DocMetadata"] | null;
|
|
72
|
+
}[], Error>;
|
|
73
|
+
/** List conversations in a workspace. */
|
|
74
|
+
declare function useConversations(workspaceId: string | undefined, options?: {
|
|
75
|
+
enabled?: boolean;
|
|
76
|
+
}): _tanstack_react_query.UseQueryResult<{
|
|
77
|
+
external_id: string;
|
|
78
|
+
title: string | null;
|
|
79
|
+
created_by_ext_id: string;
|
|
80
|
+
updated_by_ext_id?: string | null;
|
|
81
|
+
created_at: string;
|
|
82
|
+
updated_at: string;
|
|
83
|
+
is_shared: boolean;
|
|
84
|
+
message_count: number;
|
|
85
|
+
}[], Error>;
|
|
86
|
+
/** List tags in a workspace. */
|
|
87
|
+
declare function useTags(workspaceId: string | undefined, options?: {
|
|
88
|
+
enabled?: boolean;
|
|
89
|
+
}): _tanstack_react_query.UseQueryResult<{
|
|
90
|
+
external_id: string;
|
|
91
|
+
workspace_ext_id: string;
|
|
92
|
+
name: string;
|
|
93
|
+
instruction?: string | null;
|
|
94
|
+
tag_type: _arbidocs_sdk.components["schemas"]["TagFormat"];
|
|
95
|
+
shared: boolean;
|
|
96
|
+
parent_ext_id?: string | null;
|
|
97
|
+
doctag_count: number;
|
|
98
|
+
created_by_ext_id: string;
|
|
99
|
+
updated_by_ext_id?: string | null;
|
|
100
|
+
created_at: string;
|
|
101
|
+
updated_at: string;
|
|
102
|
+
}[], Error>;
|
|
103
|
+
/** Send a streaming query to the RAG assistant. Returns a mutation. */
|
|
104
|
+
declare function useAssistantQuery(): _tanstack_react_query.UseMutationResult<SSEStreamResult, Error, {
|
|
105
|
+
question: string;
|
|
106
|
+
docIds: string[];
|
|
107
|
+
parentMessageExtId?: string | null;
|
|
108
|
+
configExtId?: string;
|
|
109
|
+
onToken?: (content: string) => void;
|
|
110
|
+
onStreamStart?: (data: {
|
|
111
|
+
assistant_message_ext_id?: string;
|
|
112
|
+
}) => void;
|
|
113
|
+
onAgentStep?: (data: {
|
|
114
|
+
focus?: string;
|
|
115
|
+
status?: string;
|
|
116
|
+
}) => void;
|
|
117
|
+
onError?: (message: string) => void;
|
|
118
|
+
onComplete?: () => void;
|
|
119
|
+
}, unknown>;
|
|
120
|
+
/** Check backend health. */
|
|
121
|
+
declare function useHealth(options?: {
|
|
122
|
+
enabled?: boolean;
|
|
123
|
+
}): _tanstack_react_query.UseQueryResult<{
|
|
124
|
+
status: string;
|
|
125
|
+
backend_git_hash?: string | null;
|
|
126
|
+
frontend_docker_version?: string | null;
|
|
127
|
+
services: _arbidocs_sdk.components["schemas"]["ServiceStatus"][];
|
|
128
|
+
models_health?: _arbidocs_sdk.components["schemas"]["ModelsHealthStatus"] | null;
|
|
129
|
+
available_models: string[];
|
|
130
|
+
}, Error>;
|
|
131
|
+
|
|
132
|
+
export { ArbiProvider, type ArbiProviderProps, arbiQueryKeys, useArbi, useAssistantQuery, useConversations, useDocuments, useHealth, useTags, useWorkspaces };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { createContext, useMemo, useContext } from 'react';
|
|
2
|
+
import { Arbi } from '@arbidocs/core/browser';
|
|
3
|
+
export { Arbi, ArbiError } from '@arbidocs/core/browser';
|
|
4
|
+
import { jsx } from 'react/jsx-runtime';
|
|
5
|
+
import { useQuery, useMutation } from '@tanstack/react-query';
|
|
6
|
+
|
|
7
|
+
// src/ArbiProvider.tsx
|
|
8
|
+
var ArbiContext = createContext(null);
|
|
9
|
+
function ArbiProvider({ children, ...options }) {
|
|
10
|
+
const arbi = useMemo(
|
|
11
|
+
() => new Arbi(options),
|
|
12
|
+
// Stable on url + deploymentDomain — re-creating the instance on every render would be wrong
|
|
13
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
14
|
+
[options.url, options.deploymentDomain, options.credentials]
|
|
15
|
+
);
|
|
16
|
+
return /* @__PURE__ */ jsx(ArbiContext.Provider, { value: arbi, children });
|
|
17
|
+
}
|
|
18
|
+
function useArbi() {
|
|
19
|
+
const arbi = useContext(ArbiContext);
|
|
20
|
+
if (!arbi) {
|
|
21
|
+
throw new Error("useArbi() must be used within an <ArbiProvider>");
|
|
22
|
+
}
|
|
23
|
+
return arbi;
|
|
24
|
+
}
|
|
25
|
+
var arbiQueryKeys = {
|
|
26
|
+
workspaces: () => ["arbi", "workspaces"],
|
|
27
|
+
documents: (workspaceId) => ["arbi", "documents", workspaceId],
|
|
28
|
+
conversations: (workspaceId) => ["arbi", "conversations", workspaceId],
|
|
29
|
+
tags: (workspaceId) => ["arbi", "tags", workspaceId],
|
|
30
|
+
health: () => ["arbi", "health"]
|
|
31
|
+
};
|
|
32
|
+
function useWorkspaces(options) {
|
|
33
|
+
const arbi = useArbi();
|
|
34
|
+
return useQuery({
|
|
35
|
+
queryKey: arbiQueryKeys.workspaces(),
|
|
36
|
+
queryFn: () => arbi.workspaces.list(),
|
|
37
|
+
enabled: options?.enabled ?? arbi.isLoggedIn
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
function useDocuments(workspaceId, options) {
|
|
41
|
+
const arbi = useArbi();
|
|
42
|
+
return useQuery({
|
|
43
|
+
queryKey: arbiQueryKeys.documents(workspaceId ?? ""),
|
|
44
|
+
queryFn: () => arbi.documents.list(workspaceId),
|
|
45
|
+
enabled: (options?.enabled ?? true) && !!workspaceId && arbi.hasWorkspace
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
function useConversations(workspaceId, options) {
|
|
49
|
+
const arbi = useArbi();
|
|
50
|
+
return useQuery({
|
|
51
|
+
queryKey: arbiQueryKeys.conversations(workspaceId ?? ""),
|
|
52
|
+
queryFn: () => arbi.conversations.list(workspaceId),
|
|
53
|
+
enabled: (options?.enabled ?? true) && !!workspaceId && arbi.hasWorkspace
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
function useTags(workspaceId, options) {
|
|
57
|
+
const arbi = useArbi();
|
|
58
|
+
return useQuery({
|
|
59
|
+
queryKey: arbiQueryKeys.tags(workspaceId ?? ""),
|
|
60
|
+
queryFn: () => arbi.tags.list(workspaceId),
|
|
61
|
+
enabled: (options?.enabled ?? true) && !!workspaceId && arbi.hasWorkspace
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
function useAssistantQuery() {
|
|
65
|
+
const arbi = useArbi();
|
|
66
|
+
return useMutation({
|
|
67
|
+
mutationFn: ({ question, ...options }) => arbi.assistant.query(question, options)
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
function useHealth(options) {
|
|
71
|
+
const arbi = useArbi();
|
|
72
|
+
return useQuery({
|
|
73
|
+
queryKey: arbiQueryKeys.health(),
|
|
74
|
+
queryFn: () => arbi.health.check(),
|
|
75
|
+
enabled: options?.enabled
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export { ArbiProvider, arbiQueryKeys, useArbi, useAssistantQuery, useConversations, useDocuments, useHealth, useTags, useWorkspaces };
|
|
80
|
+
//# sourceMappingURL=index.js.map
|
|
81
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/ArbiProvider.tsx","../src/useArbi.ts","../src/hooks.ts"],"names":[],"mappings":";;;;;;;AAYO,IAAM,WAAA,GAAc,cAA2B,IAAI,CAAA;AAMnD,SAAS,YAAA,CAAa,EAAE,QAAA,EAAU,GAAG,SAAQ,EAAsB;AACxE,EAAA,MAAM,IAAA,GAAO,OAAA;AAAA,IACX,MAAM,IAAI,IAAA,CAAK,OAAO,CAAA;AAAA;AAAA;AAAA,IAGtB,CAAC,OAAA,CAAQ,GAAA,EAAK,OAAA,CAAQ,gBAAA,EAAkB,QAAQ,WAAW;AAAA,GAC7D;AAEA,EAAA,2BAAQ,WAAA,CAAY,QAAA,EAAZ,EAAqB,KAAA,EAAO,MAAO,QAAA,EAAS,CAAA;AACtD;ACn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**\n * ArbiProvider — React context that holds an Arbi instance.\n *\n * Usage:\n * <ArbiProvider url=\"https://arbi.mycompany.com\">\n * <App />\n * </ArbiProvider>\n */\n\nimport { createContext, useMemo, type ReactNode } from 'react'\nimport { Arbi, type ArbiOptions } from '@arbidocs/core/browser'\n\nexport const ArbiContext = createContext<Arbi | null>(null)\n\nexport interface ArbiProviderProps extends ArbiOptions {\n children: ReactNode\n}\n\nexport function ArbiProvider({ children, ...options }: ArbiProviderProps) {\n const arbi = useMemo(\n () => new Arbi(options),\n // Stable on url + deploymentDomain — re-creating the instance on every render would be wrong\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [options.url, options.deploymentDomain, options.credentials]\n )\n\n return <ArbiContext.Provider value={arbi}>{children}</ArbiContext.Provider>\n}\n","/**\n * Hook to access the Arbi instance from the nearest ArbiProvider.\n */\n\nimport { useContext } from 'react'\nimport type { Arbi } from '@arbidocs/core/browser'\nimport { ArbiContext } from './ArbiProvider'\n\nexport function useArbi(): Arbi {\n const arbi = useContext(ArbiContext)\n if (!arbi) {\n throw new Error('useArbi() must be used within an <ArbiProvider>')\n }\n return arbi\n}\n","/**\n * React Query hooks that use the Arbi instance from context.\n */\n\nimport { useQuery, useMutation } from '@tanstack/react-query'\nimport type { SSEStreamResult } from '@arbidocs/core/browser'\nimport { useArbi } from './useArbi'\n\n// ── Query keys ──────────────────────────────────────────────────────────────\n\nexport const arbiQueryKeys = {\n workspaces: () => ['arbi', 'workspaces'] as const,\n documents: (workspaceId: string) => ['arbi', 'documents', workspaceId] as const,\n conversations: (workspaceId: string) => ['arbi', 'conversations', workspaceId] as const,\n tags: (workspaceId: string) => ['arbi', 'tags', workspaceId] as const,\n health: () => ['arbi', 'health'] as const,\n}\n\n// ── Hooks ───────────────────────────────────────────────────────────────────\n\n/** List the logged-in user's workspaces. */\nexport function useWorkspaces(options?: { enabled?: boolean }) {\n const arbi = useArbi()\n return useQuery({\n queryKey: arbiQueryKeys.workspaces(),\n queryFn: () => arbi.workspaces.list(),\n enabled: options?.enabled ?? arbi.isLoggedIn,\n })\n}\n\n/** List documents in a workspace. */\nexport function useDocuments(workspaceId: string | undefined, options?: { enabled?: boolean }) {\n const arbi = useArbi()\n return useQuery({\n queryKey: arbiQueryKeys.documents(workspaceId ?? ''),\n queryFn: () => arbi.documents.list(workspaceId),\n enabled: (options?.enabled ?? true) && !!workspaceId && arbi.hasWorkspace,\n })\n}\n\n/** List conversations in a workspace. */\nexport function useConversations(workspaceId: string | undefined, options?: { enabled?: boolean }) {\n const arbi = useArbi()\n return useQuery({\n queryKey: arbiQueryKeys.conversations(workspaceId ?? ''),\n queryFn: () => arbi.conversations.list(workspaceId),\n enabled: (options?.enabled ?? true) && !!workspaceId && arbi.hasWorkspace,\n })\n}\n\n/** List tags in a workspace. */\nexport function useTags(workspaceId: string | undefined, options?: { enabled?: boolean }) {\n const arbi = useArbi()\n return useQuery({\n queryKey: arbiQueryKeys.tags(workspaceId ?? ''),\n queryFn: () => arbi.tags.list(workspaceId),\n enabled: (options?.enabled ?? true) && !!workspaceId && arbi.hasWorkspace,\n })\n}\n\n/** Send a streaming query to the RAG assistant. Returns a mutation. */\nexport function useAssistantQuery() {\n const arbi = useArbi()\n\n return useMutation<\n SSEStreamResult,\n Error,\n {\n question: string\n docIds: string[]\n parentMessageExtId?: string | null\n configExtId?: string\n onToken?: (content: string) => void\n onStreamStart?: (data: { assistant_message_ext_id?: string }) => void\n onAgentStep?: (data: { focus?: string; status?: string }) => void\n onError?: (message: string) => void\n onComplete?: () => void\n }\n >({\n mutationFn: ({ question, ...options }) => arbi.assistant.query(question, options),\n })\n}\n\n/** Check backend health. */\nexport function useHealth(options?: { enabled?: boolean }) {\n const arbi = useArbi()\n return useQuery({\n queryKey: arbiQueryKeys.health(),\n queryFn: () => arbi.health.check(),\n enabled: options?.enabled,\n })\n}\n"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@arbidocs/react",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "React hooks and provider for the ARBI SDK",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.cjs",
|
|
7
|
+
"module": "dist/index.js",
|
|
8
|
+
"types": "dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"import": "./dist/index.js",
|
|
13
|
+
"require": "./dist/index.cjs"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"dist"
|
|
18
|
+
],
|
|
19
|
+
"scripts": {
|
|
20
|
+
"build": "tsup",
|
|
21
|
+
"test": "vitest run",
|
|
22
|
+
"typecheck": "tsc --noEmit"
|
|
23
|
+
},
|
|
24
|
+
"dependencies": {
|
|
25
|
+
"@arbidocs/core": "^0.2.0",
|
|
26
|
+
"@arbidocs/sdk": "^0.1.0",
|
|
27
|
+
"@tanstack/react-query": ">=5"
|
|
28
|
+
},
|
|
29
|
+
"peerDependencies": {
|
|
30
|
+
"react": ">=18"
|
|
31
|
+
},
|
|
32
|
+
"devDependencies": {
|
|
33
|
+
"@tanstack/react-query": "^5.90.5",
|
|
34
|
+
"@testing-library/react": "^16.3.0",
|
|
35
|
+
"@types/react": "^19.2.2",
|
|
36
|
+
"@types/react-dom": "^19.2.2",
|
|
37
|
+
"jsdom": "^27.0.1",
|
|
38
|
+
"react": "^19.2.0",
|
|
39
|
+
"react-dom": "^19.2.0",
|
|
40
|
+
"tsup": "^8.5.1",
|
|
41
|
+
"typescript": "^5.9.3",
|
|
42
|
+
"vitest": "^4.0.18"
|
|
43
|
+
},
|
|
44
|
+
"license": "MIT",
|
|
45
|
+
"publishConfig": {
|
|
46
|
+
"access": "public"
|
|
47
|
+
},
|
|
48
|
+
"repository": {
|
|
49
|
+
"type": "git",
|
|
50
|
+
"url": "git+https://github.com/arbitrationcity/ARBI-frontend.git",
|
|
51
|
+
"directory": "packages/arbi-react"
|
|
52
|
+
},
|
|
53
|
+
"keywords": [
|
|
54
|
+
"arbi",
|
|
55
|
+
"react",
|
|
56
|
+
"hooks",
|
|
57
|
+
"sdk",
|
|
58
|
+
"typescript"
|
|
59
|
+
]
|
|
60
|
+
}
|