graphor 0.6.0 → 0.8.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/CHANGELOG.md +16 -0
- package/LICENSE +1 -1
- package/client.d.mts +9 -9
- package/client.d.mts.map +1 -1
- package/client.d.ts +9 -9
- package/client.d.ts.map +1 -1
- package/client.js +34 -34
- package/client.js.map +1 -1
- package/client.mjs +32 -32
- package/client.mjs.map +1 -1
- package/core/api-promise.d.mts +2 -2
- package/core/api-promise.d.mts.map +1 -1
- package/core/api-promise.d.ts +2 -2
- package/core/api-promise.d.ts.map +1 -1
- package/core/api-promise.js.map +1 -1
- package/core/api-promise.mjs.map +1 -1
- package/core/error.d.mts +2 -2
- package/core/error.d.mts.map +1 -1
- package/core/error.d.ts +2 -2
- package/core/error.d.ts.map +1 -1
- package/core/error.js +4 -4
- package/core/error.js.map +1 -1
- package/core/error.mjs +2 -2
- package/core/error.mjs.map +1 -1
- package/core/resource.d.mts +3 -3
- package/core/resource.d.mts.map +1 -1
- package/core/resource.d.ts +3 -3
- package/core/resource.d.ts.map +1 -1
- package/core/resource.js.map +1 -1
- package/core/resource.mjs.map +1 -1
- package/index.d.mts +3 -3
- package/index.d.mts.map +1 -1
- package/index.d.ts +3 -3
- package/index.d.ts.map +1 -1
- package/index.js +4 -4
- package/index.js.map +1 -1
- package/index.mjs +3 -3
- package/index.mjs.map +1 -1
- package/internal/parse.d.mts +2 -2
- package/internal/parse.d.mts.map +1 -1
- package/internal/parse.d.ts +2 -2
- package/internal/parse.d.ts.map +1 -1
- package/internal/parse.js.map +1 -1
- package/internal/parse.mjs.map +1 -1
- package/internal/shims.js +1 -1
- package/internal/shims.js.map +1 -1
- package/internal/shims.mjs +1 -1
- package/internal/shims.mjs.map +1 -1
- package/internal/uploads.d.mts +4 -4
- package/internal/uploads.d.mts.map +1 -1
- package/internal/uploads.d.ts +4 -4
- package/internal/uploads.d.ts.map +1 -1
- package/internal/uploads.js.map +1 -1
- package/internal/uploads.mjs.map +1 -1
- package/internal/utils/base64.js +2 -2
- package/internal/utils/base64.js.map +1 -1
- package/internal/utils/base64.mjs +3 -3
- package/internal/utils/base64.mjs.map +1 -1
- package/internal/utils/log.d.mts +3 -3
- package/internal/utils/log.d.mts.map +1 -1
- package/internal/utils/log.d.ts +3 -3
- package/internal/utils/log.d.ts.map +1 -1
- package/internal/utils/log.js.map +1 -1
- package/internal/utils/log.mjs.map +1 -1
- package/internal/utils/path.js +1 -1
- package/internal/utils/path.js.map +1 -1
- package/internal/utils/path.mjs +2 -2
- package/internal/utils/path.mjs.map +1 -1
- package/internal/utils/values.js +5 -5
- package/internal/utils/values.js.map +1 -1
- package/internal/utils/values.mjs +6 -6
- package/internal/utils/values.mjs.map +1 -1
- package/package.json +3 -3
- package/resources/sources.d.mts +418 -60
- package/resources/sources.d.mts.map +1 -1
- package/resources/sources.d.ts +418 -60
- package/resources/sources.d.ts.map +1 -1
- package/resources/sources.js +348 -19
- package/resources/sources.js.map +1 -1
- package/resources/sources.mjs +348 -19
- package/resources/sources.mjs.map +1 -1
- package/src/client.ts +16 -16
- package/src/core/api-promise.ts +4 -4
- package/src/core/error.ts +2 -2
- package/src/core/resource.ts +3 -3
- package/src/index.ts +3 -3
- package/src/internal/parse.ts +2 -2
- package/src/internal/shims.ts +1 -1
- package/src/internal/uploads.ts +5 -5
- package/src/internal/utils/base64.ts +3 -3
- package/src/internal/utils/log.ts +3 -3
- package/src/internal/utils/path.ts +2 -2
- package/src/internal/utils/values.ts +6 -6
- package/src/resources/sources.ts +418 -60
- package/src/version.ts +1 -1
- package/version.d.mts +1 -1
- package/version.d.ts +1 -1
- package/version.js +1 -1
- package/version.mjs +1 -1
package/resources/sources.mjs
CHANGED
|
@@ -3,79 +3,408 @@ import { APIResource } from "../core/resource.mjs";
|
|
|
3
3
|
import { multipartFormRequestOptions } from "../internal/uploads.mjs";
|
|
4
4
|
export class Sources extends APIResource {
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
6
|
+
* List all sources in the project's knowledge graph.
|
|
7
|
+
*
|
|
8
|
+
* Returns every source node currently stored in the knowledge graph for the
|
|
9
|
+
* authenticated project. Each item includes the file metadata (ID, name, size,
|
|
10
|
+
* type, origin) along with its current processing status and a human-readable
|
|
11
|
+
* status message.
|
|
12
|
+
*
|
|
13
|
+
* **Status messages returned per source:**
|
|
14
|
+
*
|
|
15
|
+
* - `"completed"` → _"Source processed successfully"_
|
|
16
|
+
* - `"processing"` → _"Source is being processed"_
|
|
17
|
+
* - `"failed"` → _"Source processing failed"_
|
|
18
|
+
* - `"new"` → _"Source uploaded, awaiting processing"_
|
|
19
|
+
*
|
|
20
|
+
* **Returns** a JSON array of `PublicSourceResponse` objects.
|
|
21
|
+
*
|
|
22
|
+
* **Error responses:**
|
|
23
|
+
*
|
|
24
|
+
* - `500` — Unexpected internal error while retrieving sources.
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```ts
|
|
28
|
+
* const publicSources = await client.sources.list();
|
|
29
|
+
* ```
|
|
7
30
|
*/
|
|
8
31
|
list(options) {
|
|
9
32
|
return this._client.get('/sources', options);
|
|
10
33
|
}
|
|
11
34
|
/**
|
|
12
|
-
* Delete a source from the project
|
|
35
|
+
* Delete a source from the project's knowledge graph and all associated data.
|
|
36
|
+
*
|
|
37
|
+
* Removes the source node, its partitions/chunks, embeddings, and any stored files
|
|
38
|
+
* from the knowledge graph and object storage. The operation is irreversible.
|
|
39
|
+
*
|
|
40
|
+
* **Parameters (JSON body):**
|
|
41
|
+
*
|
|
42
|
+
* - **file_id** (str, optional — preferred): The unique identifier of the source
|
|
43
|
+
* to delete.
|
|
44
|
+
* - **file_name** (str, optional — deprecated): The display name of the source.
|
|
45
|
+
* Use `file_id` instead when possible. At least one of `file_id` or `file_name`
|
|
46
|
+
* must be provided.
|
|
13
47
|
*
|
|
14
|
-
*
|
|
48
|
+
* **Returns** a `PublicDeleteSourceResponse` with the deletion status, file ID,
|
|
49
|
+
* file name, project ID, and project name.
|
|
50
|
+
*
|
|
51
|
+
* **Error responses:**
|
|
52
|
+
*
|
|
53
|
+
* - `400` — Invalid input (e.g. neither identifier provided).
|
|
54
|
+
* - `403` — Permission denied.
|
|
55
|
+
* - `404` — Source not found.
|
|
56
|
+
* - `500` — Unexpected internal error.
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* ```ts
|
|
60
|
+
* const source = await client.sources.delete();
|
|
61
|
+
* ```
|
|
15
62
|
*/
|
|
16
63
|
delete(body, options) {
|
|
17
64
|
return this._client.delete('/sources/delete', { body, ...options });
|
|
18
65
|
}
|
|
19
66
|
/**
|
|
20
|
-
*
|
|
67
|
+
* Ask a natural-language question grounded on the project's ingested sources.
|
|
68
|
+
*
|
|
69
|
+
* This is the primary Q&A endpoint. It sends the question through the GenAI File
|
|
70
|
+
* Search pipeline, which retrieves relevant chunks from the knowledge graph,
|
|
71
|
+
* grounds the answer in the source documents, and returns a natural-language
|
|
72
|
+
* response. Optionally, you can request a structured JSON output by supplying an
|
|
73
|
+
* `output_schema`.
|
|
74
|
+
*
|
|
75
|
+
* Conversation memory is supported: pass a `conversation_id` to continue an
|
|
76
|
+
* existing conversation, or set `reset` to `true` to start fresh.
|
|
77
|
+
*
|
|
78
|
+
* **Parameters (JSON body):**
|
|
79
|
+
*
|
|
80
|
+
* - **question** (str, required): The question to ask about the sources.
|
|
81
|
+
* - **conversation_id** (str, optional): An existing conversation identifier to
|
|
82
|
+
* maintain context across multiple turns.
|
|
83
|
+
* - **reset** (bool, optional, default `false`): When `true`, starts a new
|
|
84
|
+
* conversation discarding any previous history.
|
|
85
|
+
* - **file_ids** (list[str], optional — preferred): Restrict the search scope to
|
|
86
|
+
* specific source file IDs.
|
|
87
|
+
* - **file_names** (list[str], optional — deprecated): Restrict the search scope
|
|
88
|
+
* to specific source file names. Use `file_ids` when possible.
|
|
89
|
+
* - **output_schema** (dict, optional): A JSON Schema for requesting structured
|
|
90
|
+
* output. When provided, the response includes a `structured_output` field
|
|
91
|
+
* validated against this schema and the `raw_json` produced by the model.
|
|
92
|
+
* - **thinking_level** (str, optional, default `"accurate"`): Controls the
|
|
93
|
+
* model/thinking budget — one of `"fast"`, `"balanced"`, or `"accurate"`.
|
|
94
|
+
*
|
|
95
|
+
* **Returns** a `PublicAskSourcesResponse` containing:
|
|
96
|
+
*
|
|
97
|
+
* - `answer` — the natural-language answer (or a status message when
|
|
98
|
+
* `output_schema` is provided).
|
|
99
|
+
* - `structured_output` — the validated structured object (when `output_schema` is
|
|
100
|
+
* provided).
|
|
101
|
+
* - `raw_json` — the raw JSON text before validation (when `output_schema` is
|
|
102
|
+
* provided).
|
|
103
|
+
* - `conversation_id` — the conversation identifier for follow-up questions.
|
|
104
|
+
*
|
|
105
|
+
* **Error responses:**
|
|
106
|
+
*
|
|
107
|
+
* - `500` — Unexpected internal error while asking sources.
|
|
108
|
+
*
|
|
109
|
+
* @example
|
|
110
|
+
* ```ts
|
|
111
|
+
* const response = await client.sources.ask({
|
|
112
|
+
* question: 'question',
|
|
113
|
+
* });
|
|
114
|
+
* ```
|
|
21
115
|
*/
|
|
22
116
|
ask(body, options) {
|
|
23
117
|
return this._client.post('/sources/ask-sources', { body, ...options });
|
|
24
118
|
}
|
|
25
119
|
/**
|
|
26
|
-
* Run a one-off
|
|
120
|
+
* Run a one-off structured data extraction against one or more sources.
|
|
121
|
+
*
|
|
122
|
+
* This endpoint uses the GenAI File Search pipeline to read the specified sources,
|
|
123
|
+
* apply the user-provided instruction, and return structured JSON output
|
|
124
|
+
* conforming to the supplied `output_schema`. Internally it builds a grounded
|
|
125
|
+
* prompt, queries the model, and validates/corrects the raw JSON against the
|
|
126
|
+
* schema.
|
|
127
|
+
*
|
|
128
|
+
* **Parameters (JSON body):**
|
|
129
|
+
*
|
|
130
|
+
* - **file_ids** (list[str], optional — preferred): List of source file IDs to
|
|
131
|
+
* extract from.
|
|
132
|
+
* - **file_names** (list[str], optional — deprecated): List of source file names
|
|
133
|
+
* to extract from. Use `file_ids` when possible. At least one of the two lists
|
|
134
|
+
* must be provided and non-empty.
|
|
135
|
+
* - **user_instruction** (str, required): A natural-language instruction that
|
|
136
|
+
* guides what information to extract from the documents.
|
|
137
|
+
* - **output_schema** (dict, required): A JSON Schema object describing the
|
|
138
|
+
* desired structured output shape. The model will produce data conforming to
|
|
139
|
+
* this schema.
|
|
140
|
+
* - **thinking_level** (str, optional, default `"accurate"`): Controls the
|
|
141
|
+
* model/thinking budget — one of `"fast"`, `"balanced"`, or `"accurate"`.
|
|
142
|
+
*
|
|
143
|
+
* **Returns** a `PublicRunExtractionResultResponse` containing:
|
|
144
|
+
*
|
|
145
|
+
* - `structured_output` — the validated structured object.
|
|
146
|
+
* - `raw_json` — the raw JSON text produced by the model before validation.
|
|
147
|
+
*
|
|
148
|
+
* **Error responses:**
|
|
149
|
+
*
|
|
150
|
+
* - `500` — Unexpected internal error during extraction.
|
|
151
|
+
*
|
|
152
|
+
* @example
|
|
153
|
+
* ```ts
|
|
154
|
+
* const response = await client.sources.extract({
|
|
155
|
+
* output_schema: { foo: 'bar' },
|
|
156
|
+
* user_instruction: 'user_instruction',
|
|
157
|
+
* });
|
|
158
|
+
* ```
|
|
27
159
|
*/
|
|
28
160
|
extract(body, options) {
|
|
29
161
|
return this._client.post('/sources/run-extraction', { body, ...options });
|
|
30
162
|
}
|
|
31
163
|
/**
|
|
32
|
-
*
|
|
164
|
+
* Retrieve the parsed elements (chunks/partitions) of a specific source with
|
|
165
|
+
* pagination.
|
|
33
166
|
*
|
|
34
|
-
*
|
|
167
|
+
* Returns the individual document partitions (text chunks) that were generated
|
|
168
|
+
* during ingestion for a given source. This is useful for inspecting how a file
|
|
169
|
+
* was segmented, reviewing chunk content, or building custom retrieval logic on
|
|
170
|
+
* top of the raw partitions.
|
|
171
|
+
*
|
|
172
|
+
* **Parameters (JSON body):**
|
|
173
|
+
*
|
|
174
|
+
* - **file_id** (str, optional — preferred): The unique identifier of the source
|
|
175
|
+
* whose elements to retrieve.
|
|
176
|
+
* - **file_name** (str, optional — deprecated): The display name of the source.
|
|
177
|
+
* Use `file_id` when possible. At least one of `file_id` or `file_name` must be
|
|
178
|
+
* provided.
|
|
179
|
+
* - **page** (int, optional): The 1-based page number for pagination.
|
|
180
|
+
* - **page_size** (int, optional): The number of elements per page. Both `page`
|
|
181
|
+
* and `page_size` must be provided together to enable pagination.
|
|
182
|
+
* - **filter** (object, optional): An optional filter object with:
|
|
183
|
+
* - `type` — filter by element type.
|
|
184
|
+
* - `page_numbers` — restrict to specific source page numbers.
|
|
185
|
+
* - `elementsToRemove` — list of element types to exclude.
|
|
186
|
+
*
|
|
187
|
+
* **Returns** a `PaginatedResponse[Document]` containing:
|
|
188
|
+
*
|
|
189
|
+
* - `items` — list of `Document` objects (LangChain format) with `page_content`
|
|
190
|
+
* and `metadata`.
|
|
191
|
+
* - `total` — total number of matching elements.
|
|
192
|
+
* - `page`, `page_size`, `total_pages` — pagination metadata.
|
|
193
|
+
*
|
|
194
|
+
* **Error responses:**
|
|
195
|
+
*
|
|
196
|
+
* - `400` — Invalid input (e.g. neither identifier provided).
|
|
197
|
+
* - `404` — Source file not found.
|
|
198
|
+
* - `500` — Unexpected internal error.
|
|
199
|
+
*
|
|
200
|
+
* @example
|
|
201
|
+
* ```ts
|
|
202
|
+
* const response = await client.sources.loadElements();
|
|
203
|
+
* ```
|
|
35
204
|
*/
|
|
36
205
|
loadElements(body, options) {
|
|
37
206
|
return this._client.post('/sources/elements', { body, ...options });
|
|
38
207
|
}
|
|
39
208
|
/**
|
|
40
|
-
*
|
|
209
|
+
* Re-process (re-parse) an existing source that has already been uploaded.
|
|
210
|
+
*
|
|
211
|
+
* Use this endpoint to re-run the data-ingestion pipeline on a source that is
|
|
212
|
+
* already present in the knowledge graph — for example, after changing the
|
|
213
|
+
* partitioning strategy. The endpoint locates the source node, sets its status to
|
|
214
|
+
* `PROCESSING`, applies the requested partition method, and executes the full
|
|
215
|
+
* ingestion pipeline synchronously (partitioning, chunking, embedding, and graph
|
|
216
|
+
* persistence).
|
|
217
|
+
*
|
|
218
|
+
* **Parameters (JSON body):**
|
|
41
219
|
*
|
|
42
|
-
*
|
|
220
|
+
* - **file_id** (str, optional — preferred): The unique identifier of the source
|
|
221
|
+
* to re-process.
|
|
222
|
+
* - **file_name** (str, optional — deprecated): The display name of the source.
|
|
223
|
+
* Use `file_id` instead when possible. At least one of `file_id` or `file_name`
|
|
224
|
+
* must be provided.
|
|
225
|
+
* - **partition_method** (str, default `"basic"`): The partitioning strategy to
|
|
226
|
+
* apply (e.g. `"basic"`, `"hi_res"`, `"fast"`).
|
|
227
|
+
*
|
|
228
|
+
* **Returns** a `PublicSourceResponse` with the updated source metadata.
|
|
229
|
+
*
|
|
230
|
+
* **Error responses:**
|
|
231
|
+
*
|
|
232
|
+
* - `404` — Source node not found for the given identifier.
|
|
233
|
+
* - `500` — Processing or unexpected internal error.
|
|
234
|
+
*
|
|
235
|
+
* @example
|
|
236
|
+
* ```ts
|
|
237
|
+
* const publicSource = await client.sources.parse();
|
|
238
|
+
* ```
|
|
43
239
|
*/
|
|
44
240
|
parse(body, options) {
|
|
45
241
|
return this._client.post('/sources/process', { body, ...options });
|
|
46
242
|
}
|
|
47
243
|
/**
|
|
48
|
-
*
|
|
49
|
-
*
|
|
244
|
+
* Retrieve relevant document chunks from the prebuilt RAG vector store.
|
|
245
|
+
*
|
|
246
|
+
* Performs a semantic similarity search over the project's prebuilt RAG store
|
|
247
|
+
* using Google File Search with grounding. Returns the most relevant text chunks
|
|
248
|
+
* along with their source metadata (file name, page number, relevance score). This
|
|
249
|
+
* is a pure retrieval endpoint — it does **not** generate an answer; use
|
|
250
|
+
* `/ask-sources` for Q&A.
|
|
251
|
+
*
|
|
252
|
+
* **Parameters (JSON body):**
|
|
253
|
+
*
|
|
254
|
+
* - **query** (str, required): The natural-language search query used to find
|
|
255
|
+
* relevant chunks.
|
|
256
|
+
* - **file_ids** (list[str], optional — preferred): Restrict retrieval to specific
|
|
257
|
+
* source file IDs.
|
|
258
|
+
* - **file_names** (list[str], optional — deprecated): Restrict retrieval to
|
|
259
|
+
* specific source file names. Use `file_ids` when possible.
|
|
260
|
+
*
|
|
261
|
+
* **Returns** a `PublicRetrieveResponse` containing:
|
|
262
|
+
*
|
|
263
|
+
* - `query` — the original search query.
|
|
264
|
+
* - `chunks` — a list of `PublicRetrieveChunk` objects, each with `text`,
|
|
265
|
+
* `file_name`, `page_number`, `score`, and additional `metadata`.
|
|
266
|
+
* - `total` — the total number of chunks returned.
|
|
267
|
+
*
|
|
268
|
+
* **Error responses:**
|
|
50
269
|
*
|
|
51
|
-
*
|
|
270
|
+
* - `500` — Unexpected internal error during retrieval.
|
|
271
|
+
*
|
|
272
|
+
* @example
|
|
273
|
+
* ```ts
|
|
274
|
+
* const response = await client.sources.retrieveChunks({
|
|
275
|
+
* query: 'query',
|
|
276
|
+
* });
|
|
277
|
+
* ```
|
|
52
278
|
*/
|
|
53
279
|
retrieveChunks(body, options) {
|
|
54
280
|
return this._client.post('/sources/prebuilt-rag', { body, ...options });
|
|
55
281
|
}
|
|
56
282
|
/**
|
|
57
|
-
* Upload
|
|
283
|
+
* Upload a local file and ingest it as a source into the project's knowledge
|
|
284
|
+
* graph.
|
|
285
|
+
*
|
|
286
|
+
* This endpoint accepts a multipart file upload, validates the file size (max 100
|
|
287
|
+
* MB) and extension against the list of allowed ingestion types, stores the file,
|
|
288
|
+
* and then runs the full data-ingestion pipeline synchronously — including
|
|
289
|
+
* partitioning, chunking, embedding, and graph persistence.
|
|
290
|
+
*
|
|
291
|
+
* **Parameters:**
|
|
292
|
+
*
|
|
293
|
+
* - **file** (multipart): The file to upload. Must include a `Content-Length`
|
|
294
|
+
* header and have a supported extension (e.g. pdf, docx, txt, csv, etc.).
|
|
295
|
+
* - **partition_method** (form, optional): The partitioning strategy to apply to
|
|
296
|
+
* the document. When omitted the system default is used.
|
|
297
|
+
*
|
|
298
|
+
* **Returns** a `PublicSourceResponse` with the resulting source metadata (file
|
|
299
|
+
* ID, name, size, type, source origin, partition method, and processing status).
|
|
300
|
+
*
|
|
301
|
+
* **Error responses:**
|
|
302
|
+
*
|
|
303
|
+
* - `400` — Unsupported file type or missing file name.
|
|
304
|
+
* - `411` — Missing `Content-Length` header (file size cannot be determined).
|
|
305
|
+
* - `413` — File exceeds the 100 MB size limit.
|
|
306
|
+
* - `403` — Permission denied.
|
|
307
|
+
* - `404` — File not found during processing.
|
|
308
|
+
* - `500` — Unexpected internal error.
|
|
309
|
+
*
|
|
310
|
+
* @example
|
|
311
|
+
* ```ts
|
|
312
|
+
* const publicSource = await client.sources.upload({
|
|
313
|
+
* file: fs.createReadStream('path/to/file'),
|
|
314
|
+
* });
|
|
315
|
+
* ```
|
|
58
316
|
*/
|
|
59
317
|
upload(body, options) {
|
|
60
318
|
return this._client.post('/sources/upload', multipartFormRequestOptions({ body, ...options }, this._client));
|
|
61
319
|
}
|
|
62
320
|
/**
|
|
63
|
-
*
|
|
64
|
-
*
|
|
321
|
+
* Ingest a GitHub repository as a source into the project's knowledge graph.
|
|
322
|
+
*
|
|
323
|
+
* The endpoint clones or fetches the repository at the given URL, extracts its
|
|
324
|
+
* text-based files, partitions them using the system default method, generates
|
|
325
|
+
* embeddings, and persists everything in the knowledge graph synchronously.
|
|
326
|
+
*
|
|
327
|
+
* **Parameters (JSON body):**
|
|
328
|
+
*
|
|
329
|
+
* - **url** (str, required): The GitHub repository URL to ingest (e.g.
|
|
330
|
+
* `https://github.com/owner/repo`).
|
|
331
|
+
*
|
|
332
|
+
* **Returns** a `PublicSourceResponse` with the resulting source metadata (file
|
|
333
|
+
* ID, name, size, type, source origin, partition method, and processing status).
|
|
334
|
+
*
|
|
335
|
+
* **Error responses:**
|
|
336
|
+
*
|
|
337
|
+
* - `500` — Unexpected internal error during GitHub source processing.
|
|
338
|
+
*
|
|
339
|
+
* @example
|
|
340
|
+
* ```ts
|
|
341
|
+
* const publicSource = await client.sources.uploadGitHub({
|
|
342
|
+
* url: 'url',
|
|
343
|
+
* });
|
|
344
|
+
* ```
|
|
65
345
|
*/
|
|
66
346
|
uploadGitHub(body, options) {
|
|
67
347
|
return this._client.post('/sources/upload-github-source', { body, ...options });
|
|
68
348
|
}
|
|
69
349
|
/**
|
|
70
|
-
*
|
|
71
|
-
*
|
|
350
|
+
* Ingest a web page (or a set of crawled pages) as a source into the project's
|
|
351
|
+
* knowledge graph.
|
|
352
|
+
*
|
|
353
|
+
* The endpoint fetches the content at the given URL, optionally crawls linked
|
|
354
|
+
* pages (when `crawlUrls` is `true`), partitions the resulting HTML/text,
|
|
355
|
+
* generates embeddings, and persists everything in the knowledge graph
|
|
356
|
+
* synchronously.
|
|
357
|
+
*
|
|
358
|
+
* **Parameters (JSON body):**
|
|
359
|
+
*
|
|
360
|
+
* - **url** (str, required): The web page URL to ingest.
|
|
361
|
+
* - **crawlUrls** (bool, optional, default `false`): When `true`, the system will
|
|
362
|
+
* also follow and ingest links found on the page.
|
|
363
|
+
* - **partition_method** (str, optional): The partitioning strategy to use. When
|
|
364
|
+
* omitted the system default is applied.
|
|
365
|
+
*
|
|
366
|
+
* **Returns** a `PublicSourceResponse` with the resulting source metadata (file
|
|
367
|
+
* ID, name, size, type, source origin, partition method, and processing status).
|
|
368
|
+
*
|
|
369
|
+
* **Error responses:**
|
|
370
|
+
*
|
|
371
|
+
* - `500` — Unexpected internal error during URL processing.
|
|
372
|
+
*
|
|
373
|
+
* @example
|
|
374
|
+
* ```ts
|
|
375
|
+
* const publicSource = await client.sources.uploadURL({
|
|
376
|
+
* url: 'url',
|
|
377
|
+
* });
|
|
378
|
+
* ```
|
|
72
379
|
*/
|
|
73
380
|
uploadURL(body, options) {
|
|
74
381
|
return this._client.post('/sources/upload-url-source', { body, ...options });
|
|
75
382
|
}
|
|
76
383
|
/**
|
|
77
|
-
*
|
|
78
|
-
*
|
|
384
|
+
* Ingest a YouTube video as a source into the project's knowledge graph.
|
|
385
|
+
*
|
|
386
|
+
* The endpoint downloads the transcript/captions of the given YouTube video,
|
|
387
|
+
* partitions the text using the system default method, generates embeddings, and
|
|
388
|
+
* persists everything in the knowledge graph synchronously.
|
|
389
|
+
*
|
|
390
|
+
* **Parameters (JSON body):**
|
|
391
|
+
*
|
|
392
|
+
* - **url** (str, required): The YouTube video URL to ingest (e.g.
|
|
393
|
+
* `https://www.youtube.com/watch?v=...`).
|
|
394
|
+
*
|
|
395
|
+
* **Returns** a `PublicSourceResponse` with the resulting source metadata (file
|
|
396
|
+
* ID, name, size, type, source origin, partition method, and processing status).
|
|
397
|
+
*
|
|
398
|
+
* **Error responses:**
|
|
399
|
+
*
|
|
400
|
+
* - `500` — Unexpected internal error during YouTube source processing.
|
|
401
|
+
*
|
|
402
|
+
* @example
|
|
403
|
+
* ```ts
|
|
404
|
+
* const publicSource = await client.sources.uploadYoutube({
|
|
405
|
+
* url: 'url',
|
|
406
|
+
* });
|
|
407
|
+
* ```
|
|
79
408
|
*/
|
|
80
409
|
uploadYoutube(body, options) {
|
|
81
410
|
return this._client.post('/sources/upload-youtube-source', { body, ...options });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sources.mjs","sourceRoot":"","sources":["../src/resources/sources.ts"],"names":[],"mappings":"AAAA,sFAAsF;OAE/E,EAAE,WAAW,EAAE;OAIf,EAAE,2BAA2B,EAAE;AAEtC,MAAM,OAAO,OAAQ,SAAQ,WAAW;IACtC
|
|
1
|
+
{"version":3,"file":"sources.mjs","sourceRoot":"","sources":["../src/resources/sources.ts"],"names":[],"mappings":"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"}
|
package/src/client.ts
CHANGED
|
@@ -59,7 +59,7 @@ export interface ClientOptions {
|
|
|
59
59
|
/**
|
|
60
60
|
* Override the default base URL for the API, e.g., "https://api.example.com/v2/"
|
|
61
61
|
*
|
|
62
|
-
* Defaults to process.env['
|
|
62
|
+
* Defaults to process.env['GRAPHOR_BASE_URL'].
|
|
63
63
|
*/
|
|
64
64
|
baseURL?: string | null | undefined;
|
|
65
65
|
|
|
@@ -113,7 +113,7 @@ export interface ClientOptions {
|
|
|
113
113
|
/**
|
|
114
114
|
* Set the log level.
|
|
115
115
|
*
|
|
116
|
-
* Defaults to process.env['
|
|
116
|
+
* Defaults to process.env['GRAPHOR_LOG'] or 'warn' if it isn't set.
|
|
117
117
|
*/
|
|
118
118
|
logLevel?: LogLevel | undefined;
|
|
119
119
|
|
|
@@ -126,9 +126,9 @@ export interface ClientOptions {
|
|
|
126
126
|
}
|
|
127
127
|
|
|
128
128
|
/**
|
|
129
|
-
* API Client for interfacing with the Graphor
|
|
129
|
+
* API Client for interfacing with the Graphor API.
|
|
130
130
|
*/
|
|
131
|
-
export class
|
|
131
|
+
export class Graphor {
|
|
132
132
|
apiKey: string;
|
|
133
133
|
|
|
134
134
|
baseURL: string;
|
|
@@ -144,10 +144,10 @@ export class GraphorPrd {
|
|
|
144
144
|
private _options: ClientOptions;
|
|
145
145
|
|
|
146
146
|
/**
|
|
147
|
-
* API Client for interfacing with the Graphor
|
|
147
|
+
* API Client for interfacing with the Graphor API.
|
|
148
148
|
*
|
|
149
149
|
* @param {string | undefined} [opts.apiKey=process.env['GRAPHOR_API_KEY'] ?? undefined]
|
|
150
|
-
* @param {string} [opts.baseURL=process.env['
|
|
150
|
+
* @param {string} [opts.baseURL=process.env['GRAPHOR_BASE_URL'] ?? https://api.graphorlm.com/api/public/v1] - Override the default base URL for the API.
|
|
151
151
|
* @param {number} [opts.timeout=10 minutes] - The maximum amount of time (in milliseconds) the client will wait for a response before timing out.
|
|
152
152
|
* @param {MergedRequestInit} [opts.fetchOptions] - Additional `RequestInit` options to be passed to `fetch` calls.
|
|
153
153
|
* @param {Fetch} [opts.fetch] - Specify a custom `fetch` function implementation.
|
|
@@ -156,13 +156,13 @@ export class GraphorPrd {
|
|
|
156
156
|
* @param {Record<string, string | undefined>} opts.defaultQuery - Default query parameters to include with every request to the API.
|
|
157
157
|
*/
|
|
158
158
|
constructor({
|
|
159
|
-
baseURL = readEnv('
|
|
159
|
+
baseURL = readEnv('GRAPHOR_BASE_URL'),
|
|
160
160
|
apiKey = readEnv('GRAPHOR_API_KEY'),
|
|
161
161
|
...opts
|
|
162
162
|
}: ClientOptions = {}) {
|
|
163
163
|
if (apiKey === undefined) {
|
|
164
|
-
throw new Errors.
|
|
165
|
-
"The GRAPHOR_API_KEY environment variable is missing or empty; either provide it, or instantiate the
|
|
164
|
+
throw new Errors.GraphorError(
|
|
165
|
+
"The GRAPHOR_API_KEY environment variable is missing or empty; either provide it, or instantiate the Graphor client with an apiKey option, like new Graphor({ apiKey: 'My API Key' }).",
|
|
166
166
|
);
|
|
167
167
|
}
|
|
168
168
|
|
|
@@ -173,14 +173,14 @@ export class GraphorPrd {
|
|
|
173
173
|
};
|
|
174
174
|
|
|
175
175
|
this.baseURL = options.baseURL!;
|
|
176
|
-
this.timeout = options.timeout ??
|
|
176
|
+
this.timeout = options.timeout ?? Graphor.DEFAULT_TIMEOUT /* 10 minutes */;
|
|
177
177
|
this.logger = options.logger ?? console;
|
|
178
178
|
const defaultLogLevel = 'warn';
|
|
179
179
|
// Set default logLevel early so that we can log a warning in parseLogLevel.
|
|
180
180
|
this.logLevel = defaultLogLevel;
|
|
181
181
|
this.logLevel =
|
|
182
182
|
parseLogLevel(options.logLevel, 'ClientOptions.logLevel', this) ??
|
|
183
|
-
parseLogLevel(readEnv('
|
|
183
|
+
parseLogLevel(readEnv('GRAPHOR_LOG'), "process.env['GRAPHOR_LOG']", this) ??
|
|
184
184
|
defaultLogLevel;
|
|
185
185
|
this.fetchOptions = options.fetchOptions;
|
|
186
186
|
this.maxRetries = options.maxRetries ?? 0;
|
|
@@ -243,7 +243,7 @@ export class GraphorPrd {
|
|
|
243
243
|
if (value === null) {
|
|
244
244
|
return `${encodeURIComponent(key)}=`;
|
|
245
245
|
}
|
|
246
|
-
throw new Errors.
|
|
246
|
+
throw new Errors.GraphorError(
|
|
247
247
|
`Cannot stringify type ${typeof value}; Expected string, number, boolean, or null. If you need to pass nested query parameters, you can manually encode them, e.g. { query: { 'foo[key1]': value1, 'foo[key2]': value2 } }, and please open a GitHub issue requesting better support for your use case.`,
|
|
248
248
|
);
|
|
249
249
|
})
|
|
@@ -722,10 +722,10 @@ export class GraphorPrd {
|
|
|
722
722
|
}
|
|
723
723
|
}
|
|
724
724
|
|
|
725
|
-
static
|
|
725
|
+
static Graphor = this;
|
|
726
726
|
static DEFAULT_TIMEOUT = 600000; // 10 minutes
|
|
727
727
|
|
|
728
|
-
static
|
|
728
|
+
static GraphorError = Errors.GraphorError;
|
|
729
729
|
static APIError = Errors.APIError;
|
|
730
730
|
static APIConnectionError = Errors.APIConnectionError;
|
|
731
731
|
static APIConnectionTimeoutError = Errors.APIConnectionTimeoutError;
|
|
@@ -744,9 +744,9 @@ export class GraphorPrd {
|
|
|
744
744
|
sources: API.Sources = new API.Sources(this);
|
|
745
745
|
}
|
|
746
746
|
|
|
747
|
-
|
|
747
|
+
Graphor.Sources = Sources;
|
|
748
748
|
|
|
749
|
-
export declare namespace
|
|
749
|
+
export declare namespace Graphor {
|
|
750
750
|
export type RequestOptions = Opts.RequestOptions;
|
|
751
751
|
|
|
752
752
|
export {
|
package/src/core/api-promise.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
2
2
|
|
|
3
|
-
import { type
|
|
3
|
+
import { type Graphor } from '../client';
|
|
4
4
|
|
|
5
5
|
import { type PromiseOrValue } from '../internal/types';
|
|
6
6
|
import { APIResponseProps, defaultParseResponse } from '../internal/parse';
|
|
@@ -11,13 +11,13 @@ import { APIResponseProps, defaultParseResponse } from '../internal/parse';
|
|
|
11
11
|
*/
|
|
12
12
|
export class APIPromise<T> extends Promise<T> {
|
|
13
13
|
private parsedPromise: Promise<T> | undefined;
|
|
14
|
-
#client:
|
|
14
|
+
#client: Graphor;
|
|
15
15
|
|
|
16
16
|
constructor(
|
|
17
|
-
client:
|
|
17
|
+
client: Graphor,
|
|
18
18
|
private responsePromise: Promise<APIResponseProps>,
|
|
19
19
|
private parseResponse: (
|
|
20
|
-
client:
|
|
20
|
+
client: Graphor,
|
|
21
21
|
props: APIResponseProps,
|
|
22
22
|
) => PromiseOrValue<T> = defaultParseResponse,
|
|
23
23
|
) {
|
package/src/core/error.ts
CHANGED
|
@@ -2,13 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
import { castToError } from '../internal/errors';
|
|
4
4
|
|
|
5
|
-
export class
|
|
5
|
+
export class GraphorError extends Error {}
|
|
6
6
|
|
|
7
7
|
export class APIError<
|
|
8
8
|
TStatus extends number | undefined = number | undefined,
|
|
9
9
|
THeaders extends Headers | undefined = Headers | undefined,
|
|
10
10
|
TError extends Object | undefined = Object | undefined,
|
|
11
|
-
> extends
|
|
11
|
+
> extends GraphorError {
|
|
12
12
|
/** HTTP status for the response that caused the error */
|
|
13
13
|
readonly status: TStatus;
|
|
14
14
|
/** HTTP headers for the response that caused the error */
|
package/src/core/resource.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
2
2
|
|
|
3
|
-
import type {
|
|
3
|
+
import type { Graphor } from '../client';
|
|
4
4
|
|
|
5
5
|
export abstract class APIResource {
|
|
6
|
-
protected _client:
|
|
6
|
+
protected _client: Graphor;
|
|
7
7
|
|
|
8
|
-
constructor(client:
|
|
8
|
+
constructor(client: Graphor) {
|
|
9
9
|
this._client = client;
|
|
10
10
|
}
|
|
11
11
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
2
2
|
|
|
3
|
-
export {
|
|
3
|
+
export { Graphor as default } from './client';
|
|
4
4
|
|
|
5
5
|
export { type Uploadable, toFile } from './core/uploads';
|
|
6
6
|
export { APIPromise } from './core/api-promise';
|
|
7
|
-
export {
|
|
7
|
+
export { Graphor, type ClientOptions } from './client';
|
|
8
8
|
export {
|
|
9
|
-
|
|
9
|
+
GraphorError,
|
|
10
10
|
APIError,
|
|
11
11
|
APIConnectionError,
|
|
12
12
|
APIConnectionTimeoutError,
|
package/src/internal/parse.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
2
2
|
|
|
3
3
|
import type { FinalRequestOptions } from './request-options';
|
|
4
|
-
import { type
|
|
4
|
+
import { type Graphor } from '../client';
|
|
5
5
|
import { formatRequestDetails, loggerFor } from './utils/log';
|
|
6
6
|
|
|
7
7
|
export type APIResponseProps = {
|
|
@@ -13,7 +13,7 @@ export type APIResponseProps = {
|
|
|
13
13
|
startTime: number;
|
|
14
14
|
};
|
|
15
15
|
|
|
16
|
-
export async function defaultParseResponse<T>(client:
|
|
16
|
+
export async function defaultParseResponse<T>(client: Graphor, props: APIResponseProps): Promise<T> {
|
|
17
17
|
const { response, requestLogID, retryOfRequestLogID, startTime } = props;
|
|
18
18
|
const body = await (async () => {
|
|
19
19
|
// fetch refuses to read the body when the status code is 204.
|
package/src/internal/shims.ts
CHANGED
|
@@ -16,7 +16,7 @@ export function getDefaultFetch(): Fetch {
|
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
throw new Error(
|
|
19
|
-
'`fetch` is not defined as a global; Either pass `fetch` to the client, `new
|
|
19
|
+
'`fetch` is not defined as a global; Either pass `fetch` to the client, `new Graphor({ fetch })` or polyfill the global, `globalThis.fetch = fetch`',
|
|
20
20
|
);
|
|
21
21
|
}
|
|
22
22
|
|