@trustgraph/client 0.2.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/LICENSE +176 -0
- package/README.md +319 -0
- package/dist/__tests__/flows-api.test.d.ts +2 -0
- package/dist/__tests__/flows-api.test.d.ts.map +1 -0
- package/dist/__tests__/messages.test.d.ts +2 -0
- package/dist/__tests__/messages.test.d.ts.map +1 -0
- package/dist/__tests__/service-call-multi.test.d.ts +2 -0
- package/dist/__tests__/service-call-multi.test.d.ts.map +1 -0
- package/dist/__tests__/service-call.test.d.ts +2 -0
- package/dist/__tests__/service-call.test.d.ts.map +1 -0
- package/dist/api/authenticated-fetch.d.ts +18 -0
- package/dist/api/authenticated-fetch.d.ts.map +1 -0
- package/dist/api/trustgraph/SocketContext.d.ts +2 -0
- package/dist/api/trustgraph/SocketContext.d.ts.map +1 -0
- package/dist/api/trustgraph/SocketProvider.d.ts +21 -0
- package/dist/api/trustgraph/SocketProvider.d.ts.map +1 -0
- package/dist/api/trustgraph/Triple.d.ts +17 -0
- package/dist/api/trustgraph/Triple.d.ts.map +1 -0
- package/dist/api/trustgraph/messages.d.ts +205 -0
- package/dist/api/trustgraph/messages.d.ts.map +1 -0
- package/dist/api/trustgraph/service-call-multi.d.ts +17 -0
- package/dist/api/trustgraph/service-call-multi.d.ts.map +1 -0
- package/dist/api/trustgraph/service-call.d.ts +57 -0
- package/dist/api/trustgraph/service-call.d.ts.map +1 -0
- package/dist/api/trustgraph/socket.d.ts +2 -0
- package/dist/api/trustgraph/socket.d.ts.map +1 -0
- package/dist/api/trustgraph/trustgraph-socket.d.ts +429 -0
- package/dist/api/trustgraph/trustgraph-socket.d.ts.map +1 -0
- package/dist/index.cjs +1370 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.esm.js +1361 -0
- package/dist/index.esm.js.map +1 -0
- package/dist/index.js +1375 -0
- package/dist/index.js.map +1 -0
- package/dist/models/Triple.d.ts +17 -0
- package/dist/models/Triple.d.ts.map +1 -0
- package/dist/models/messages.d.ts +215 -0
- package/dist/models/messages.d.ts.map +1 -0
- package/dist/socket/service-call-multi.d.ts +30 -0
- package/dist/socket/service-call-multi.d.ts.map +1 -0
- package/dist/socket/service-call.d.ts +69 -0
- package/dist/socket/service-call.d.ts.map +1 -0
- package/dist/socket/trustgraph-socket.d.ts +433 -0
- package/dist/socket/trustgraph-socket.d.ts.map +1 -0
- package/dist/types.d.ts +2 -0
- package/dist/types.d.ts.map +1 -0
- package/package.json +68 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
package/README.md
ADDED
|
@@ -0,0 +1,319 @@
|
|
|
1
|
+
# @trustgraph/client
|
|
2
|
+
|
|
3
|
+
TypeScript/JavaScript client library for TrustGraph WebSocket API. This package provides a framework-agnostic client for communicating with TrustGraph services.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- 🌐 **WebSocket-based** - Real-time communication with TrustGraph services
|
|
8
|
+
- 📦 **Zero Dependencies** - No external runtime dependencies
|
|
9
|
+
- 🔐 **Authentication Support** - Optional API key authentication
|
|
10
|
+
- 🔄 **Auto-reconnection** - Handles connection failures gracefully
|
|
11
|
+
- 📝 **Full TypeScript Support** - Complete type definitions
|
|
12
|
+
- 🎯 **Framework Agnostic** - Works with any JavaScript framework or vanilla JS
|
|
13
|
+
|
|
14
|
+
## Installation
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
npm install @trustgraph/client
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Quick Start
|
|
21
|
+
|
|
22
|
+
```typescript
|
|
23
|
+
import { createTrustGraphSocket } from "@trustgraph/client";
|
|
24
|
+
|
|
25
|
+
// Create a socket connection
|
|
26
|
+
const socket = createTrustGraphSocket("your-username");
|
|
27
|
+
|
|
28
|
+
// Query triples from the knowledge graph
|
|
29
|
+
const triples = await socket.triplesQuery(
|
|
30
|
+
{ v: "http://example.org/subject", e: true },
|
|
31
|
+
{ v: "http://example.org/predicate", e: true },
|
|
32
|
+
undefined,
|
|
33
|
+
10, // limit
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
console.log(triples);
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## With Authentication
|
|
40
|
+
|
|
41
|
+
```typescript
|
|
42
|
+
const socket = createTrustGraphSocket("your-username", "your-api-key");
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## Core APIs
|
|
46
|
+
|
|
47
|
+
### Knowledge Graph Operations
|
|
48
|
+
|
|
49
|
+
**Query Triples**
|
|
50
|
+
|
|
51
|
+
```typescript
|
|
52
|
+
const triples = await socket.triplesQuery(
|
|
53
|
+
subject?: Value, // Optional subject filter
|
|
54
|
+
predicate?: Value, // Optional predicate filter
|
|
55
|
+
object?: Value, // Optional object filter
|
|
56
|
+
limit: number, // Maximum results
|
|
57
|
+
collection?: string // Optional collection name
|
|
58
|
+
);
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
**Graph Embeddings Query**
|
|
62
|
+
|
|
63
|
+
```typescript
|
|
64
|
+
const entities = await socket.graphEmbeddingsQuery(
|
|
65
|
+
vectors: number[][], // Embedding vectors
|
|
66
|
+
limit: number, // Maximum results
|
|
67
|
+
collection?: string // Optional collection name
|
|
68
|
+
);
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### Text & LLM Operations
|
|
72
|
+
|
|
73
|
+
**Text Completion**
|
|
74
|
+
|
|
75
|
+
```typescript
|
|
76
|
+
const response = await socket.textCompletion(
|
|
77
|
+
system: string, // System prompt
|
|
78
|
+
prompt: string, // User prompt
|
|
79
|
+
temperature?: number
|
|
80
|
+
);
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
**Graph RAG**
|
|
84
|
+
|
|
85
|
+
```typescript
|
|
86
|
+
const answer = await socket.graphRag(
|
|
87
|
+
query: string,
|
|
88
|
+
options?: {
|
|
89
|
+
'entity-limit'?: number,
|
|
90
|
+
'triple-limit'?: number,
|
|
91
|
+
'max-subgraph-size'?: number,
|
|
92
|
+
'max-path-length'?: number
|
|
93
|
+
},
|
|
94
|
+
collection?: string
|
|
95
|
+
);
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
**Agent**
|
|
99
|
+
|
|
100
|
+
```typescript
|
|
101
|
+
socket.agent(
|
|
102
|
+
question: string,
|
|
103
|
+
think: (thought: string) => void, // Called when agent is thinking
|
|
104
|
+
observe: (observation: string) => void, // Called on observations
|
|
105
|
+
answer: (answer: string) => void, // Called with final answer
|
|
106
|
+
error: (error: string) => void, // Called on errors
|
|
107
|
+
collection?: string
|
|
108
|
+
);
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
**Embeddings**
|
|
112
|
+
|
|
113
|
+
```typescript
|
|
114
|
+
const vectors = await socket.embeddings(text: string);
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
### Document Operations
|
|
118
|
+
|
|
119
|
+
**Load Document**
|
|
120
|
+
|
|
121
|
+
```typescript
|
|
122
|
+
await socket.loadDocument(
|
|
123
|
+
id: string, // Document ID
|
|
124
|
+
data: string, // Base64-encoded document
|
|
125
|
+
metadata: Triple[], // Document metadata as triples
|
|
126
|
+
collection?: string
|
|
127
|
+
);
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
**Load Text**
|
|
131
|
+
|
|
132
|
+
```typescript
|
|
133
|
+
await socket.loadText(
|
|
134
|
+
id: string, // Document ID
|
|
135
|
+
text: string, // Plain text content
|
|
136
|
+
charset: string, // Character encoding (e.g., 'utf-8')
|
|
137
|
+
metadata: Triple[], // Document metadata as triples
|
|
138
|
+
collection?: string
|
|
139
|
+
);
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
### Library Operations
|
|
143
|
+
|
|
144
|
+
**List Documents**
|
|
145
|
+
|
|
146
|
+
```typescript
|
|
147
|
+
const docs = await socket.library.listDocuments(
|
|
148
|
+
user?: string,
|
|
149
|
+
collection?: string
|
|
150
|
+
);
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
**Get Document**
|
|
154
|
+
|
|
155
|
+
```typescript
|
|
156
|
+
const doc = await socket.library.getDocument(
|
|
157
|
+
id: string,
|
|
158
|
+
user?: string,
|
|
159
|
+
collection?: string
|
|
160
|
+
);
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
**Delete Document**
|
|
164
|
+
|
|
165
|
+
```typescript
|
|
166
|
+
await socket.library.deleteDocument(
|
|
167
|
+
id: string,
|
|
168
|
+
user?: string,
|
|
169
|
+
collection?: string
|
|
170
|
+
);
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
### Flow Operations
|
|
174
|
+
|
|
175
|
+
Flows represent processing pipelines for documents and queries.
|
|
176
|
+
|
|
177
|
+
**Create Flow API**
|
|
178
|
+
|
|
179
|
+
```typescript
|
|
180
|
+
const flowApi = socket.flow("flow-id");
|
|
181
|
+
// flowApi has same methods as socket but scoped to this flow
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
**Start Flow**
|
|
185
|
+
|
|
186
|
+
```typescript
|
|
187
|
+
await socket.flows.startFlow(
|
|
188
|
+
flowId: string,
|
|
189
|
+
className: string,
|
|
190
|
+
description: string
|
|
191
|
+
);
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
**Stop Flow**
|
|
195
|
+
|
|
196
|
+
```typescript
|
|
197
|
+
await socket.flows.stopFlow(flowId: string);
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
**List Flows**
|
|
201
|
+
|
|
202
|
+
```typescript
|
|
203
|
+
const flowIds = await socket.flows.getFlows();
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
**Get Flow Definition**
|
|
207
|
+
|
|
208
|
+
```typescript
|
|
209
|
+
const flowDef = await socket.flows.getFlow(flowId: string);
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
**List Flow Classes**
|
|
213
|
+
|
|
214
|
+
```typescript
|
|
215
|
+
const classes = await socket.flows.getFlowClasses();
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
**Get Flow Class**
|
|
219
|
+
|
|
220
|
+
```typescript
|
|
221
|
+
const classDef = await socket.flows.getFlowClass(className: string);
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
## Connection State Monitoring
|
|
225
|
+
|
|
226
|
+
```typescript
|
|
227
|
+
// Subscribe to connection state changes
|
|
228
|
+
const unsubscribe = socket.onConnectionStateChange((state) => {
|
|
229
|
+
console.log("Status:", state.status); // 'connecting' | 'connected' | 'authenticated' | 'disconnected' | 'error'
|
|
230
|
+
console.log("Authenticated:", state.authenticated);
|
|
231
|
+
console.log("Error:", state.error);
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
// Unsubscribe when done
|
|
235
|
+
unsubscribe();
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
## Data Types
|
|
239
|
+
|
|
240
|
+
### Value
|
|
241
|
+
|
|
242
|
+
Represents a subject, predicate, or object in a triple:
|
|
243
|
+
|
|
244
|
+
```typescript
|
|
245
|
+
interface Value {
|
|
246
|
+
v: string; // Value (URI or literal)
|
|
247
|
+
e: boolean; // Is entity (true) or literal (false)
|
|
248
|
+
label?: string; // Optional human-readable label
|
|
249
|
+
}
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
### Triple
|
|
253
|
+
|
|
254
|
+
Represents a subject-predicate-object relationship:
|
|
255
|
+
|
|
256
|
+
```typescript
|
|
257
|
+
interface Triple {
|
|
258
|
+
s: Value; // Subject
|
|
259
|
+
p: Value; // Predicate
|
|
260
|
+
o: Value; // Object
|
|
261
|
+
}
|
|
262
|
+
```
|
|
263
|
+
|
|
264
|
+
## Advanced Usage
|
|
265
|
+
|
|
266
|
+
### Custom Timeout and Retries
|
|
267
|
+
|
|
268
|
+
Most methods accept optional timeout and retry parameters:
|
|
269
|
+
|
|
270
|
+
```typescript
|
|
271
|
+
await socket.triplesQuery(
|
|
272
|
+
subject,
|
|
273
|
+
predicate,
|
|
274
|
+
object,
|
|
275
|
+
limit,
|
|
276
|
+
collection,
|
|
277
|
+
30000, // timeout in ms
|
|
278
|
+
5, // retry attempts
|
|
279
|
+
);
|
|
280
|
+
```
|
|
281
|
+
|
|
282
|
+
### Closing the Connection
|
|
283
|
+
|
|
284
|
+
```typescript
|
|
285
|
+
socket.close();
|
|
286
|
+
```
|
|
287
|
+
|
|
288
|
+
## Error Handling
|
|
289
|
+
|
|
290
|
+
All async methods return Promises that reject on error:
|
|
291
|
+
|
|
292
|
+
```typescript
|
|
293
|
+
try {
|
|
294
|
+
const result = await socket.triplesQuery(...);
|
|
295
|
+
} catch (error) {
|
|
296
|
+
console.error('Query failed:', error);
|
|
297
|
+
}
|
|
298
|
+
```
|
|
299
|
+
|
|
300
|
+
## React Integration
|
|
301
|
+
|
|
302
|
+
For React applications, use the companion package:
|
|
303
|
+
|
|
304
|
+
```bash
|
|
305
|
+
npm install @trustgraph/react-provider
|
|
306
|
+
```
|
|
307
|
+
|
|
308
|
+
See [@trustgraph/react-provider](https://github.com/trustgraph-ai/trustgraph-client) for React-specific hooks and providers.
|
|
309
|
+
|
|
310
|
+
## API Reference
|
|
311
|
+
|
|
312
|
+
Full API documentation is available in the TypeScript definitions. Your IDE will provide autocomplete and inline documentation for all methods.
|
|
313
|
+
|
|
314
|
+
## License
|
|
315
|
+
|
|
316
|
+
Apache 2.0
|
|
317
|
+
|
|
318
|
+
(c) KnowNext Inc., KnowNext Limited 2025
|
|
319
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"flows-api.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/flows-api.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"messages.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/messages.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"service-call-multi.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/service-call-multi.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"service-call.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/service-call.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Authenticated fetch utility
|
|
3
|
+
*
|
|
4
|
+
* Provides fetch functions that automatically include Bearer token authentication
|
|
5
|
+
* when an API key is configured in settings.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Creates an authenticated fetch function that includes Bearer token when available
|
|
9
|
+
* @param apiKey - Optional API key for authentication
|
|
10
|
+
* @returns Fetch function with automatic auth headers
|
|
11
|
+
*/
|
|
12
|
+
export declare const createAuthenticatedFetch: (apiKey?: string) => (url: string, options?: RequestInit) => Promise<Response>;
|
|
13
|
+
/**
|
|
14
|
+
* Hook-based authenticated fetch that uses current settings
|
|
15
|
+
* This is a React hook that must be called from within a component
|
|
16
|
+
*/
|
|
17
|
+
export declare const useAuthenticatedFetch: () => never;
|
|
18
|
+
//# sourceMappingURL=authenticated-fetch.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"authenticated-fetch.d.ts","sourceRoot":"","sources":["../../src/api/authenticated-fetch.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;;;GAIG;AACH,eAAO,MAAM,wBAAwB,GAAI,SAAS,MAAM,MAC9C,KAAK,MAAM,EAAE,UAAS,WAAgB,sBAe/C,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,qBAAqB,aAMjC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SocketContext.d.ts","sourceRoot":"","sources":["../../../src/api/trustgraph/SocketContext.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,aAAa,+DAAwB,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { type ConnectionState } from "./trustgraph-socket";
|
|
3
|
+
import type { Socket } from "./trustgraph-socket";
|
|
4
|
+
export declare const SocketContext: React.Context<Socket | null>;
|
|
5
|
+
export declare const ConnectionStateContext: React.Context<ConnectionState | null>;
|
|
6
|
+
export declare const useSocket: () => Socket;
|
|
7
|
+
export declare const useConnectionState: () => ConnectionState;
|
|
8
|
+
interface SocketProviderProps {
|
|
9
|
+
children: React.ReactNode;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* SocketProvider - Manages WebSocket connection with authentication
|
|
13
|
+
*
|
|
14
|
+
* Critical requirements:
|
|
15
|
+
* 1. Wait for settings to load before creating socket
|
|
16
|
+
* 2. Create socket with user and token if apiKey is present
|
|
17
|
+
* 3. Reconnect when user or authentication settings change
|
|
18
|
+
*/
|
|
19
|
+
export declare const SocketProvider: React.FC<SocketProviderProps>;
|
|
20
|
+
export {};
|
|
21
|
+
//# sourceMappingURL=SocketProvider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SocketProvider.d.ts","sourceRoot":"","sources":["../../../src/api/trustgraph/SocketProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAyD,MAAM,OAAO,CAAC;AAE9E,OAAO,EAEL,KAAK,eAAe,EACrB,MAAM,qBAAqB,CAAC;AAG7B,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAGlD,eAAO,MAAM,aAAa,8BAAqC,CAAC;AAChE,eAAO,MAAM,sBAAsB,uCAElC,CAAC;AAGF,eAAO,MAAM,SAAS,cAQrB,CAAC;AAGF,eAAO,MAAM,kBAAkB,uBAU9B,CAAC;AAEF,UAAU,mBAAmB;IAC3B,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;CAC3B;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,cAAc,EAAE,KAAK,CAAC,EAAE,CAAC,mBAAmB,CAoFxD,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export interface Value {
|
|
2
|
+
v: string;
|
|
3
|
+
e: boolean;
|
|
4
|
+
label?: string;
|
|
5
|
+
}
|
|
6
|
+
export interface PartialTriple {
|
|
7
|
+
s?: Value;
|
|
8
|
+
p?: Value;
|
|
9
|
+
o?: Value;
|
|
10
|
+
}
|
|
11
|
+
export interface Triple {
|
|
12
|
+
s: Value;
|
|
13
|
+
p: Value;
|
|
14
|
+
o: Value;
|
|
15
|
+
direc?: string;
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=Triple.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Triple.d.ts","sourceRoot":"","sources":["../../../src/api/trustgraph/Triple.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,KAAK;IACpB,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,OAAO,CAAC;IACX,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,aAAa;IAC5B,CAAC,CAAC,EAAE,KAAK,CAAC;IACV,CAAC,CAAC,EAAE,KAAK,CAAC;IACV,CAAC,CAAC,EAAE,KAAK,CAAC;CACX;AAED,MAAM,WAAW,MAAM;IACrB,CAAC,EAAE,KAAK,CAAC;IACT,CAAC,EAAE,KAAK,CAAC;IACT,CAAC,EAAE,KAAK,CAAC;IACT,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB"}
|