graphlit-client
Version:
Graphlit API Client for TypeScript
1,279 lines (1,278 loc) • 149 kB
JavaScript
import jwt from "jsonwebtoken";
// Apollo core (React-free) - ESM import
import { ApolloClient, InMemoryCache, createHttpLink, ApolloLink, ApolloError, } from "@apollo/client/core/index.js";
// Apollo retry link for resilient error handling
import { RetryLink } from "@apollo/client/link/retry/index.js";
import * as Types from "./generated/graphql-types.js";
import * as Documents from "./generated/graphql-documents.js";
import * as dotenv from "dotenv";
import { getServiceType, getModelName } from "./model-mapping.js";
import { UIEventAdapter } from "./streaming/ui-event-adapter.js";
import { formatMessagesForOpenAI, formatMessagesForAnthropic, formatMessagesForGoogle, formatMessagesForMistral, formatMessagesForBedrock, } from "./streaming/llm-formatters.js";
import { streamWithOpenAI, streamWithAnthropic, streamWithGoogle, streamWithGroq, streamWithCerebras, streamWithCohere, streamWithMistral, streamWithBedrock, streamWithDeepseek, streamWithXai, } from "./streaming/providers.js";
// Optional imports for streaming LLM clients
// These are peer dependencies and may not be installed
// We need to use createRequire for optional dependencies to avoid build errors
import { createRequire } from "node:module";
const optionalRequire = createRequire(import.meta.url);
let OpenAI;
let Anthropic;
let GoogleGenerativeAI;
let Groq;
let CohereClient;
let CohereClientV2;
let Mistral;
let BedrockRuntimeClient;
let Cerebras;
try {
OpenAI = optionalRequire("openai").default || optionalRequire("openai");
if (process.env.DEBUG_GRAPHLIT_SDK_INITIALIZATION) {
console.log("[SDK Loading] OpenAI SDK loaded successfully");
}
}
catch (e) {
// OpenAI not installed
if (process.env.DEBUG_GRAPHLIT_SDK_INITIALIZATION) {
console.log("[SDK Loading] OpenAI SDK not found:", e.message);
}
}
try {
Anthropic =
optionalRequire("@anthropic-ai/sdk").default ||
optionalRequire("@anthropic-ai/sdk");
if (process.env.DEBUG_GRAPHLIT_SDK_INITIALIZATION) {
console.log("[SDK Loading] Anthropic SDK loaded successfully");
}
}
catch (e) {
// Anthropic SDK not installed
if (process.env.DEBUG_GRAPHLIT_SDK_INITIALIZATION) {
console.log("[SDK Loading] Anthropic SDK not found:", e.message);
}
}
try {
GoogleGenerativeAI = optionalRequire("@google/generative-ai").GoogleGenerativeAI;
if (process.env.DEBUG_GRAPHLIT_SDK_INITIALIZATION) {
console.log("[SDK Loading] Google Generative AI SDK loaded successfully");
}
}
catch (e) {
// Google Generative AI not installed
if (process.env.DEBUG_GRAPHLIT_SDK_INITIALIZATION) {
console.log("[SDK Loading] Google Generative AI SDK not found:", e.message);
}
}
try {
Groq = optionalRequire("groq-sdk").default || optionalRequire("groq-sdk");
if (process.env.DEBUG_GRAPHLIT_SDK_INITIALIZATION) {
console.log("[SDK Loading] Groq SDK loaded successfully");
}
}
catch (e) {
// Groq SDK not installed
if (process.env.DEBUG_GRAPHLIT_SDK_INITIALIZATION) {
console.log("[SDK Loading] Groq SDK not found:", e.message);
}
}
try {
CohereClient = optionalRequire("cohere-ai").CohereClient;
CohereClientV2 = optionalRequire("cohere-ai").CohereClientV2;
if (process.env.DEBUG_GRAPHLIT_SDK_INITIALIZATION) {
console.log("[SDK Loading] Cohere SDK loaded successfully");
}
}
catch (e) {
// Cohere SDK not installed
if (process.env.DEBUG_GRAPHLIT_SDK_INITIALIZATION) {
console.log("[SDK Loading] Cohere SDK not found:", e.message);
}
}
try {
Mistral = optionalRequire("@mistralai/mistralai").Mistral;
if (process.env.DEBUG_GRAPHLIT_SDK_INITIALIZATION) {
console.log("[SDK Loading] Mistral SDK loaded successfully");
}
}
catch (e) {
// Mistral SDK not installed
if (process.env.DEBUG_GRAPHLIT_SDK_INITIALIZATION) {
console.log("[SDK Loading] Mistral SDK not found:", e.message);
}
}
try {
BedrockRuntimeClient = optionalRequire("@aws-sdk/client-bedrock-runtime").BedrockRuntimeClient;
if (process.env.DEBUG_GRAPHLIT_SDK_INITIALIZATION) {
console.log("[SDK Loading] Bedrock SDK loaded successfully");
}
}
catch (e) {
// Bedrock SDK not installed
if (process.env.DEBUG_GRAPHLIT_SDK_INITIALIZATION) {
console.log("[SDK Loading] Bedrock SDK not found:", e.message);
}
}
try {
Cerebras =
optionalRequire("@cerebras/cerebras_cloud_sdk").default ||
optionalRequire("@cerebras/cerebras_cloud_sdk");
if (process.env.DEBUG_GRAPHLIT_SDK_INITIALIZATION) {
console.log("[SDK Loading] Cerebras SDK loaded successfully");
}
}
catch (e) {
// Cerebras SDK not installed
if (process.env.DEBUG_GRAPHLIT_SDK_INITIALIZATION) {
console.log("[SDK Loading] Cerebras SDK not found:", e.message);
}
}
const DEFAULT_MAX_TOOL_ROUNDS = 1000;
// Helper function to validate GUID format
function isValidGuid(guid) {
if (!guid)
return false;
// GUID regex pattern: 8-4-4-4-12 hexadecimal characters
const guidRegex = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
return guidRegex.test(guid);
}
// Define the Graphlit class
class Graphlit {
client;
token;
apiUri;
organizationId;
environmentId;
ownerId;
userId;
jwtSecret;
retryConfig;
// Streaming client instances (optional - can be provided by user)
openaiClient;
anthropicClient;
googleClient;
groqClient;
cerebrasClient;
cohereClient;
mistralClient;
bedrockClient;
deepseekClient;
xaiClient;
constructor(organizationIdOrOptions, environmentId, jwtSecret, ownerId, userId, apiUri) {
// Handle both old constructor signature and new options object
let options;
if (typeof organizationIdOrOptions === "object" &&
organizationIdOrOptions !== null) {
// New constructor with options object
options = organizationIdOrOptions;
}
else {
// Legacy constructor with individual parameters
options = {
organizationId: organizationIdOrOptions,
environmentId,
jwtSecret,
ownerId,
userId,
apiUri,
};
}
this.apiUri =
options.apiUri ||
(typeof process !== "undefined"
? process.env.GRAPHLIT_API_URL
: undefined) ||
"https://data-scus.graphlit.io/api/v1/graphql";
if (typeof process !== "undefined") {
dotenv.config();
this.organizationId =
options.organizationId || process.env.GRAPHLIT_ORGANIZATION_ID;
this.environmentId =
options.environmentId || process.env.GRAPHLIT_ENVIRONMENT_ID;
this.jwtSecret = options.jwtSecret || process.env.GRAPHLIT_JWT_SECRET;
// optional: for multi-tenant support
this.ownerId = options.ownerId || process.env.GRAPHLIT_OWNER_ID;
this.userId = options.userId || process.env.GRAPHLIT_USER_ID;
}
else {
this.organizationId = options.organizationId;
this.environmentId = options.environmentId;
this.jwtSecret = options.jwtSecret;
// optional: for multi-tenant support
this.ownerId = options.ownerId;
this.userId = options.userId;
}
// Set default retry configuration
this.retryConfig = {
maxAttempts: 5,
initialDelay: 300,
maxDelay: 30000,
retryableStatusCodes: [429, 502, 503, 504],
jitter: true,
...options.retryConfig,
};
if (!this.organizationId) {
throw new Error("Graphlit organization identifier is required.");
}
if (!isValidGuid(this.organizationId)) {
throw new Error(`Invalid organization ID format. Expected a valid GUID, but received: '${this.organizationId}'. ` +
"A valid GUID should be in the format: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx");
}
if (!this.environmentId) {
throw new Error("Graphlit environment identifier is required.");
}
if (!isValidGuid(this.environmentId)) {
throw new Error(`Invalid environment ID format. Expected a valid GUID, but received: '${this.environmentId}'. ` +
"A valid GUID should be in the format: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx");
}
if (!this.jwtSecret) {
throw new Error("Graphlit environment JWT secret is required.");
}
// Validate optional userId if provided (ownerId can be any format)
if (this.userId && !isValidGuid(this.userId)) {
throw new Error(`Invalid user ID format. Expected a valid GUID, but received: '${this.userId}'. ` +
"A valid GUID should be in the format: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx");
}
this.refreshClient();
}
refreshClient() {
this.client = undefined;
this.generateToken();
const httpLink = createHttpLink({
uri: this.apiUri,
});
// Create retry link with configuration
const retryLink = new RetryLink({
delay: {
initial: this.retryConfig.initialDelay || 300,
max: this.retryConfig.maxDelay || 30000,
jitter: this.retryConfig.jitter !== false,
},
attempts: {
max: this.retryConfig.maxAttempts || 5,
retryIf: (error, _operation) => {
// Check if we should retry this error
if (!error)
return false;
// Check for network errors
const hasNetworkError = !!error.networkError;
if (!hasNetworkError)
return false;
// Get status code from different possible locations
const statusCode = error.networkError?.statusCode ||
error.networkError?.response?.status ||
error.statusCode;
// Check if status code is retryable
if (statusCode && this.retryConfig.retryableStatusCodes) {
const shouldRetry = this.retryConfig.retryableStatusCodes.includes(statusCode);
// Call onRetry callback if provided
if (shouldRetry &&
this.retryConfig.onRetry &&
_operation.getContext().retryCount !== undefined) {
const attempt = _operation.getContext().retryCount + 1;
this.retryConfig.onRetry(attempt, error, _operation);
}
return shouldRetry;
}
// Default: retry on network errors without specific status codes
return true;
},
},
});
const authLink = new ApolloLink((operation, forward) => {
operation.setContext({
headers: {
Authorization: this.token ? `Bearer ${this.token}` : "",
},
});
return forward(operation);
});
// Chain links: retry -> auth -> http
this.client = new ApolloClient({
link: ApolloLink.from([retryLink, authLink, httpLink]),
cache: new InMemoryCache(),
defaultOptions: {
watchQuery: {
errorPolicy: "all",
fetchPolicy: "no-cache",
},
query: {
errorPolicy: "all",
fetchPolicy: "no-cache",
},
mutate: {
errorPolicy: "all",
fetchPolicy: "no-cache",
},
},
});
}
/**
* Set a custom OpenAI client instance for streaming
* @param client - OpenAI client instance (e.g., new OpenAI({ apiKey: "..." }))
*/
setOpenAIClient(client) {
this.openaiClient = client;
}
/**
* Set a custom Anthropic client instance for streaming
* @param client - Anthropic client instance (e.g., new Anthropic({ apiKey: "..." }))
*/
setAnthropicClient(client) {
this.anthropicClient = client;
}
/**
* Set a custom Google Generative AI client instance for streaming
* @param client - Google GenerativeAI client instance (e.g., new GoogleGenerativeAI(apiKey))
*/
setGoogleClient(client) {
this.googleClient = client;
}
/**
* Set a custom Groq client instance for streaming
* @param client - Groq client instance (e.g., new Groq({ apiKey: "..." }))
*/
setGroqClient(client) {
this.groqClient = client;
}
/**
* Set a custom Cerebras client instance for streaming
* @param client - Cerebras client instance (e.g., new Cerebras({ apiKey: "..." }))
*/
setCerebrasClient(client) {
this.cerebrasClient = client;
}
/**
* Set a custom Cohere client instance for streaming
* @param client - Cohere client instance (e.g., new CohereClient({ token: "..." }))
*/
setCohereClient(client) {
this.cohereClient = client;
}
/**
* Set a custom Mistral client instance for streaming
* @param client - Mistral client instance (e.g., new Mistral({ apiKey: "..." }))
*/
setMistralClient(client) {
this.mistralClient = client;
}
/**
* Set a custom Bedrock client instance for streaming
* @param client - BedrockRuntimeClient instance (e.g., new BedrockRuntimeClient({ region: "us-east-2" }))
*/
setBedrockClient(client) {
this.bedrockClient = client;
}
/**
* Set a custom Deepseek client instance for streaming
* @param client - OpenAI client instance configured for Deepseek (e.g., new OpenAI({ baseURL: "https://api.deepseek.com", apiKey: "..." }))
*/
setDeepseekClient(client) {
this.deepseekClient = client;
}
/**
* Set a custom xAI client instance for streaming
* @param client - OpenAI client instance configured for xAI (e.g., new OpenAI({ baseURL: "https://api.x.ai/v1", apiKey: "..." }))
*/
setXaiClient(client) {
this.xaiClient = client;
}
/**
* Update retry configuration and refresh the Apollo client
* @param retryConfig - New retry configuration
*/
setRetryConfig(retryConfig) {
this.retryConfig = {
...this.retryConfig,
...retryConfig,
};
// Refresh client to apply new retry configuration
this.refreshClient();
}
generateToken() {
if (!this.jwtSecret) {
throw new Error("Graphlit environment JWT secret is required.");
}
const expiration = Math.floor(Date.now() / 1000) + 24 * 60 * 60; // one day from now
const payload = {
"https://graphlit.io/jwt/claims": {
"x-graphlit-organization-id": this.organizationId,
"x-graphlit-environment-id": this.environmentId,
...(this.ownerId && { "x-graphlit-owner-id": this.ownerId }),
...(this.userId && { "x-graphlit-user-id": this.userId }),
"x-graphlit-role": "Owner",
},
exp: expiration,
iss: "graphlit",
aud: "https://portal.graphlit.io",
};
this.token = jwt.sign(payload, this.jwtSecret, { algorithm: "HS256" });
}
async getProject() {
return this.queryAndCheckError(Documents.GetProject, {});
}
async updateProject(project) {
return this.mutateAndCheckError(Documents.UpdateProject, { project: project });
}
async lookupProjectUsage(correlationId, startDate, duration) {
return this.queryAndCheckError(Documents.LookupUsage, {
correlationId: correlationId,
startDate: startDate,
duration: duration,
});
}
async lookupProjectCredits(correlationId, startDate, duration) {
return this.queryAndCheckError(Documents.LookupCredits, {
correlationId: correlationId,
startDate: startDate,
duration: duration,
});
}
async queryProjectTokens(startDate, duration) {
return this.queryAndCheckError(Documents.QueryTokens, { startDate: startDate, duration: duration });
}
async queryProjectUsage(startDate, duration, names, excludedNames, offset, limit) {
return this.queryAndCheckError(Documents.QueryUsage, {
startDate: startDate,
duration: duration,
names: names,
excludedNames: excludedNames,
offset: offset,
limit: limit,
});
}
async queryProjectCredits(startDate, duration) {
return this.queryAndCheckError(Documents.QueryCredits, { startDate: startDate, duration: duration });
}
async sendNotification(connector, text, textType) {
return this.mutateAndCheckError(Documents.SendNotification, {
connector: connector,
text: text,
textType: textType,
});
}
async mapWeb(uri, allowedPaths, excludedPaths, correlationId) {
return this.queryAndCheckError(Documents.MapWeb, {
uri: uri,
allowedPaths: allowedPaths,
excludedPaths: excludedPaths,
correlationId: correlationId,
});
}
async searchWeb(text, service, limit, correlationId) {
return this.queryAndCheckError(Documents.SearchWeb, {
text: text,
service: service,
limit: limit,
correlationId: correlationId,
});
}
async createAlert(alert, correlationId) {
return this.mutateAndCheckError(Documents.CreateAlert, { alert: alert, correlationId: correlationId });
}
async updateAlert(alert) {
return this.mutateAndCheckError(Documents.UpdateAlert, { alert: alert });
}
async deleteAlert(id) {
return this.mutateAndCheckError(Documents.DeleteAlert, { id: id });
}
async deleteAlerts(ids, isSynchronous) {
return this.mutateAndCheckError(Documents.DeleteAlerts, { ids: ids, isSynchronous: isSynchronous });
}
async deleteAllAlerts(filter, isSynchronous, correlationId) {
return this.mutateAndCheckError(Documents.DeleteAllAlerts, {
filter: filter,
isSynchronous: isSynchronous,
correlationId: correlationId,
});
}
async enableAlert(id) {
return this.mutateAndCheckError(Documents.EnableAlert, { id: id });
}
async disableAlert(id) {
return this.mutateAndCheckError(Documents.DisableAlert, { id: id });
}
async getAlert(id) {
return this.queryAndCheckError(Documents.GetAlert, { id: id });
}
async queryAlerts(filter) {
return this.queryAndCheckError(Documents.QueryAlerts, { filter: filter });
}
async countAlerts(filter) {
return this.queryAndCheckError(Documents.CountAlerts, { filter: filter });
}
async createCollection(collection) {
return this.mutateAndCheckError(Documents.CreateCollection, { collection: collection });
}
async updateCollection(collection) {
return this.mutateAndCheckError(Documents.UpdateCollection, { collection: collection });
}
async deleteCollection(id) {
return this.mutateAndCheckError(Documents.DeleteCollection, { id: id });
}
async deleteCollections(ids, isSynchronous) {
return this.mutateAndCheckError(Documents.DeleteCollections, { ids: ids, isSynchronous: isSynchronous });
}
async deleteAllCollections(filter, isSynchronous, correlationId) {
return this.mutateAndCheckError(Documents.DeleteAllCollections, {
filter: filter,
isSynchronous: isSynchronous,
correlationId: correlationId,
});
}
async addContentsToCollections(contents, collections) {
return this.mutateAndCheckError(Documents.AddContentsToCollections, {
contents: contents,
collections: collections,
});
}
async removeContentsFromCollection(contents, collection) {
return this.mutateAndCheckError(Documents.RemoveContentsFromCollection, {
contents: contents,
collection: collection,
});
}
async getCollection(id) {
return this.queryAndCheckError(Documents.GetCollection, { id: id });
}
async queryCollections(filter) {
return this.queryAndCheckError(Documents.QueryCollections, { filter: filter });
}
async countCollections(filter) {
return this.queryAndCheckError(Documents.CountCollections, { filter: filter });
}
async describeImage(prompt, uri, specification, correlationId) {
return this.mutateAndCheckError(Documents.DescribeImage, {
prompt: prompt,
uri: uri,
specification: specification,
correlationId: correlationId,
});
}
async describeEncodedImage(prompt, mimeType, data, specification, correlationId) {
return this.mutateAndCheckError(Documents.DescribeEncodedImage, {
prompt: prompt,
mimeType: mimeType,
data: data,
specification: specification,
correlationId: correlationId,
});
}
async screenshotPage(uri, maximumHeight, isSynchronous, workflow, collections, correlationId) {
return this.mutateAndCheckError(Documents.ScreenshotPage, {
uri: uri,
maximumHeight: maximumHeight,
isSynchronous: isSynchronous,
workflow: workflow,
collections: collections,
correlationId: correlationId,
});
}
async ingestTextBatch(batch, textType, collections, observations, correlationId) {
return this.mutateAndCheckError(Documents.IngestTextBatch, {
batch: batch,
textType: textType,
collections: collections,
observations: observations,
correlationId: correlationId,
});
}
async ingestBatch(uris, workflow, collections, observations, correlationId) {
return this.mutateAndCheckError(Documents.IngestBatch, {
uris: uris,
workflow: workflow,
collections: collections,
observations: observations,
correlationId: correlationId,
});
}
async ingestUri(uri, name, id, identifier, isSynchronous, workflow, collections, observations, correlationId) {
return this.mutateAndCheckError(Documents.IngestUri, {
uri: uri,
name: name,
id: id,
identifier: identifier,
isSynchronous: isSynchronous,
workflow: workflow,
collections: collections,
observations: observations,
correlationId: correlationId,
});
}
async ingestText(text, name, textType, uri, id, identifier, isSynchronous, workflow, collections, observations, correlationId) {
return this.mutateAndCheckError(Documents.IngestText, {
name: name,
text: text,
textType: textType,
uri: uri,
id: id,
identifier: identifier,
isSynchronous: isSynchronous,
workflow: workflow,
collections: collections,
observations: observations,
correlationId: correlationId,
});
}
async ingestMemory(text, name, textType, id, identifier, collections, correlationId) {
return this.mutateAndCheckError(Documents.IngestMemory, {
name: name,
text: text,
textType: textType,
id: id,
identifier: identifier,
collections: collections,
correlationId: correlationId,
});
}
async ingestEvent(markdown, name, description, eventDate, id, identifier, collections, correlationId) {
return this.mutateAndCheckError(Documents.IngestEvent, {
name: name,
markdown: markdown,
description: description,
eventDate: eventDate,
id: id,
identifier: identifier,
collections: collections,
correlationId: correlationId,
});
}
async ingestEncodedFile(name, data, mimeType, fileCreationDate, fileModifiedDate, id, identifier, isSynchronous, workflow, collections, observations, correlationId) {
return this.mutateAndCheckError(Documents.IngestEncodedFile, {
name: name,
data: data,
mimeType: mimeType,
fileCreationDate: fileCreationDate,
fileModifiedDate: fileModifiedDate,
id: id,
identifier: identifier,
isSynchronous: isSynchronous,
workflow: workflow,
collections: collections,
observations: observations,
correlationId: correlationId,
});
}
async updateContent(content) {
return this.mutateAndCheckError(Documents.UpdateContent, { content: content });
}
async deleteContent(id) {
return this.mutateAndCheckError(Documents.DeleteContent, { id: id });
}
async deleteContents(ids, isSynchronous) {
return this.mutateAndCheckError(Documents.DeleteContents, { ids: ids, isSynchronous: isSynchronous });
}
async deleteAllContents(filter, isSynchronous, correlationId) {
return this.mutateAndCheckError(Documents.DeleteAllContents, {
filter: filter,
isSynchronous: isSynchronous,
correlationId: correlationId,
});
}
async summarizeText(summarization, text, textType, correlationId) {
return this.mutateAndCheckError(Documents.SummarizeText, {
summarization: summarization,
text: text,
textType: textType,
correlationId: correlationId,
});
}
async summarizeContents(summarizations, filter, correlationId) {
return this.mutateAndCheckError(Documents.SummarizeContents, {
summarizations: summarizations,
filter: filter,
correlationId: correlationId,
});
}
async extractText(prompt, text, tools, specification, textType, correlationId) {
return this.mutateAndCheckError(Documents.ExtractText, {
prompt: prompt,
text: text,
textType: textType,
specification: specification,
tools: tools,
correlationId: correlationId,
});
}
async extractContents(prompt, tools, specification, filter, correlationId) {
return this.mutateAndCheckError(Documents.ExtractContents, {
prompt: prompt,
filter: filter,
specification: specification,
tools: tools,
correlationId: correlationId,
});
}
async publishContents(publishPrompt, connector, summaryPrompt, summarySpecification, publishSpecification, name, filter, workflow, isSynchronous, includeDetails, correlationId) {
return this.mutateAndCheckError(Documents.PublishContents, {
summaryPrompt: summaryPrompt,
summarySpecification: summarySpecification,
connector: connector,
publishPrompt: publishPrompt,
publishSpecification: publishSpecification,
name: name,
filter: filter,
workflow: workflow,
isSynchronous: isSynchronous,
includeDetails: includeDetails,
correlationId: correlationId,
});
}
async publishText(text, textType, connector, name, workflow, isSynchronous, correlationId) {
return this.mutateAndCheckError(Documents.PublishText, {
text: text,
textType: textType,
connector: connector,
name: name,
workflow: workflow,
isSynchronous: isSynchronous,
correlationId: correlationId,
});
}
async getContent(id) {
return this.queryAndCheckError(Documents.GetContent, { id: id });
}
async lookupContents(ids) {
return this.queryAndCheckError(Documents.LookupContents, { ids: ids });
}
async queryObservables(filter) {
return this.queryAndCheckError(Documents.QueryObservables, { filter: filter });
}
async queryContents(filter) {
return this.queryAndCheckError(Documents.QueryContents, { filter: filter });
}
async queryContentsObservations(filter) {
return this.queryAndCheckError(Documents.QueryContentsObservations, { filter: filter });
}
async queryContentsFacets(filter) {
return this.queryAndCheckError(Documents.QueryContentsFacets, { filter: filter });
}
async queryContentsGraph(filter) {
return this.queryAndCheckError(Documents.QueryContentsGraph, {
filter: filter,
graph: {
/* return everything */
},
});
}
async countContents(filter) {
return this.queryAndCheckError(Documents.CountContents, { filter: filter });
}
async isContentDone(id) {
return this.queryAndCheckError(Documents.IsContentDone, { id: id });
}
async createConversation(conversation, correlationId) {
return this.mutateAndCheckError(Documents.CreateConversation, {
conversation: conversation,
correlationId: correlationId,
});
}
async updateConversation(conversation) {
return this.mutateAndCheckError(Documents.UpdateConversation, { conversation: conversation });
}
async deleteConversation(id) {
return this.mutateAndCheckError(Documents.DeleteConversation, { id: id });
}
async deleteConversations(ids, isSynchronous) {
return this.mutateAndCheckError(Documents.DeleteConversations, {
ids: ids,
isSynchronous: isSynchronous,
});
}
async deleteAllConversations(filter, isSynchronous, correlationId) {
return this.mutateAndCheckError(Documents.DeleteAllConversations, {
filter: filter,
isSynchronous: isSynchronous,
correlationId: correlationId,
});
}
async clearConversation(id) {
return this.mutateAndCheckError(Documents.ClearConversation, { id: id });
}
async closeConversation(id) {
return this.mutateAndCheckError(Documents.CloseConversation, { id: id });
}
async getConversation(id) {
return this.queryAndCheckError(Documents.GetConversation, { id: id });
}
async queryConversations(filter) {
return this.queryAndCheckError(Documents.QueryConversations, { filter: filter });
}
async countConversations(filter) {
return this.queryAndCheckError(Documents.CountConversations, { filter: filter });
}
async reviseImage(prompt, uri, id, specification, correlationId) {
return this.mutateAndCheckError(Documents.ReviseImage, {
prompt: prompt,
uri: uri,
id: id,
specification: specification,
correlationId: correlationId,
});
}
async reviseEncodedImage(prompt, mimeType, data, id, specification, correlationId) {
return this.mutateAndCheckError(Documents.ReviseEncodedImage, {
prompt: prompt,
mimeType: mimeType,
data: data,
id: id,
specification: specification,
correlationId: correlationId,
});
}
async reviseText(prompt, text, id, specification, correlationId) {
return this.mutateAndCheckError(Documents.ReviseText, {
prompt: prompt,
text: text,
id: id,
specification: specification,
correlationId: correlationId,
});
}
async reviseContent(prompt, content, id, specification, correlationId) {
return this.mutateAndCheckError(Documents.ReviseContent, {
prompt: prompt,
content: content,
id: id,
specification: specification,
correlationId: correlationId,
});
}
async prompt(prompt, mimeType, data, specification, messages, correlationId) {
return this.mutateAndCheckError(Documents.Prompt, {
prompt: prompt,
mimeType: mimeType,
data: data,
specification: specification,
messages: messages,
correlationId: correlationId,
});
}
async retrieveView(prompt, id, retrievalStrategy, rerankingStrategy, correlationId) {
return this.mutateAndCheckError(Documents.RetrieveView, {
prompt: prompt,
id: id,
retrievalStrategy: retrievalStrategy,
rerankingStrategy: rerankingStrategy,
correlationId: correlationId,
});
}
async retrieveSources(prompt, filter, augmentedFilter, retrievalStrategy, rerankingStrategy, correlationId) {
return this.mutateAndCheckError(Documents.RetrieveSources, {
prompt: prompt,
filter: filter,
augmentedFilter: augmentedFilter,
retrievalStrategy: retrievalStrategy,
rerankingStrategy: rerankingStrategy,
correlationId: correlationId,
});
}
async formatConversation(prompt, id, specification, tools, systemPrompt, includeDetails, correlationId) {
return this.mutateAndCheckError(Documents.FormatConversation, {
prompt: prompt,
id: id,
specification: specification,
tools: tools,
systemPrompt: systemPrompt,
includeDetails: includeDetails,
correlationId: correlationId,
});
}
async completeConversation(completion, id, completionTime, ttft, throughput, correlationId) {
return this.mutateAndCheckError(Documents.CompleteConversation, {
completion: completion,
id: id,
completionTime: completionTime,
ttft: ttft,
throughput: throughput,
correlationId: correlationId,
});
}
async askGraphlit(prompt, type, id, specification, correlationId) {
return this.mutateAndCheckError(Documents.AskGraphlit, {
prompt: prompt,
type: type,
id: id,
specification: specification,
correlationId: correlationId,
});
}
async branchConversation(id) {
return this.mutateAndCheckError(Documents.BranchConversation, {
id: id,
});
}
async promptConversation(prompt, id, specification, mimeType, data, tools, requireTool, systemPrompt, includeDetails, correlationId) {
return this.mutateAndCheckError(Documents.PromptConversation, {
prompt: prompt,
id: id,
specification: specification,
mimeType: mimeType,
data: data,
tools: tools,
requireTool: requireTool,
systemPrompt: systemPrompt,
includeDetails: includeDetails,
correlationId: correlationId,
});
}
async continueConversation(id, responses, correlationId) {
return this.mutateAndCheckError(Documents.ContinueConversation, {
id: id,
responses: responses,
correlationId: correlationId,
});
}
async publishConversation(id, connector, name, workflow, isSynchronous, correlationId) {
return this.mutateAndCheckError(Documents.PublishConversation, {
id: id,
connector: connector,
name: name,
workflow: workflow,
isSynchronous: isSynchronous,
correlationId: correlationId,
});
}
async suggestConversation(id, count, correlationId) {
return this.mutateAndCheckError(Documents.SuggestConversation, {
id: id,
count: count,
correlationId: correlationId,
});
}
async queryMicrosoftCalendars(properties) {
return this.queryAndCheckError(Documents.QueryMicrosoftCalendars, {
properties: properties,
});
}
async queryGoogleCalendars(properties) {
return this.queryAndCheckError(Documents.QueryGoogleCalendars, {
properties: properties,
});
}
async queryBoxFolders(properties, folderId) {
return this.queryAndCheckError(Documents.QueryBoxFolders, {
properties: properties,
folderId: folderId,
});
}
async queryDropboxFolders(properties, folderPath) {
return this.queryAndCheckError(Documents.QueryDropboxFolders, {
properties: properties,
folderPath: folderPath,
});
}
async queryGoogleDriveFolders(properties, folderId) {
return this.queryAndCheckError(Documents.QueryGoogleDriveFolders, {
properties: properties,
folderId: folderId,
});
}
async queryOneDriveFolders(properties, folderId) {
return this.queryAndCheckError(Documents.QueryOneDriveFolders, {
properties: properties,
folderId: folderId,
});
}
async querySharePointFolders(properties, libraryId, folderId) {
return this.queryAndCheckError(Documents.QuerySharePointFolders, {
properties: properties,
libraryId: libraryId,
folderId: folderId,
});
}
async querySharePointLibraries(properties) {
return this.queryAndCheckError(Documents.QuerySharePointLibraries, { properties: properties });
}
async queryMicrosoftTeamsTeams(properties) {
return this.queryAndCheckError(Documents.QueryMicrosoftTeamsTeams, { properties: properties });
}
async queryMicrosoftTeamsChannels(properties, teamId) {
return this.queryAndCheckError(Documents.QueryMicrosoftTeamsChannels, {
properties: properties,
teamId: teamId,
});
}
async queryDiscordGuilds(properties) {
return this.queryAndCheckError(Documents.QueryDiscordGuilds, { properties: properties });
}
async queryDiscordChannels(properties) {
return this.queryAndCheckError(Documents.QueryDiscordChannels, { properties: properties });
}
async querySlackChannels(properties) {
return this.queryAndCheckError(Documents.QuerySlackChannels, { properties: properties });
}
async queryLinearProjects(properties) {
return this.queryAndCheckError(Documents.QueryLinearProjects, { properties: properties });
}
async queryNotionDatabases(properties) {
return this.queryAndCheckError(Documents.QueryNotionDatabases, { properties: properties });
}
async queryNotionPages(properties, identifier) {
return this.queryAndCheckError(Documents.QueryNotionPages, {
properties: properties,
identifier: identifier,
});
}
async createFeed(feed, correlationId) {
return this.mutateAndCheckError(Documents.CreateFeed, { feed: feed, correlationId: correlationId });
}
async updateFeed(feed) {
return this.mutateAndCheckError(Documents.UpdateFeed, { feed: feed });
}
async deleteFeed(id) {
return this.mutateAndCheckError(Documents.DeleteFeed, { id: id });
}
async deleteFeeds(ids, isSynchronous) {
return this.mutateAndCheckError(Documents.DeleteFeeds, { ids: ids, isSynchronous: isSynchronous });
}
async deleteAllFeeds(filter, isSynchronous, correlationId) {
return this.mutateAndCheckError(Documents.DeleteAllFeeds, {
filter: filter,
isSynchronous: isSynchronous,
correlationId: correlationId,
});
}
async enableFeed(id) {
return this.mutateAndCheckError(Documents.EnableFeed, { id: id });
}
async disableFeed(id) {
return this.mutateAndCheckError(Documents.DisableFeed, { id: id });
}
async getFeed(id) {
return this.queryAndCheckError(Documents.GetFeed, { id: id });
}
async queryFeeds(filter) {
return this.queryAndCheckError(Documents.QueryFeeds, { filter: filter });
}
async countFeeds(filter) {
return this.queryAndCheckError(Documents.CountFeeds, { filter: filter });
}
async feedExists(filter) {
return this.queryAndCheckError(Documents.FeedExists, { filter: filter });
}
async isFeedDone(id) {
return this.queryAndCheckError(Documents.IsFeedDone, { id: id });
}
async promptSpecifications(prompt, ids) {
return this.mutateAndCheckError(Documents.PromptSpecifications, { prompt: prompt, ids: ids });
}
async createSpecification(specification) {
return this.mutateAndCheckError(Documents.CreateSpecification, { specification: specification });
}
async updateSpecification(specification) {
return this.mutateAndCheckError(Documents.UpdateSpecification, { specification: specification });
}
async upsertSpecification(specification) {
return this.mutateAndCheckError(Documents.UpsertSpecification, { specification: specification });
}
async deleteSpecification(id) {
return this.mutateAndCheckError(Documents.DeleteSpecification, { id: id });
}
async deleteSpecifications(ids, isSynchronous) {
return this.mutateAndCheckError(Documents.DeleteSpecifications, {
ids: ids,
isSynchronous: isSynchronous,
});
}
async deleteAllSpecifications(filter, isSynchronous, correlationId) {
return this.mutateAndCheckError(Documents.DeleteAllSpecifications, {
filter: filter,
isSynchronous: isSynchronous,
correlationId: correlationId,
});
}
async getSpecification(id) {
return this.queryAndCheckError(Documents.GetSpecification, { id: id });
}
async querySpecifications(filter) {
return this.queryAndCheckError(Documents.QuerySpecifications, { filter: filter });
}
async countSpecifications(filter) {
return this.queryAndCheckError(Documents.CountSpecifications, { filter: filter });
}
async specificationExists(filter) {
return this.queryAndCheckError(Documents.SpecificationExists, { filter: filter });
}
async queryModels(filter) {
return this.queryAndCheckError(Documents.QueryModels, { filter: filter });
}
async createConnector(connector) {
return this.mutateAndCheckError(Documents.CreateConnector, { connector: connector });
}
async updateConnector(connector) {
return this.mutateAndCheckError(Documents.UpdateConnector, { connector: connector });
}
/*
public async upsertConnector(
connector: Types.ConnectorInput
): Promise<Types.UpsertConnectorMutation> {
return this.mutateAndCheckError<
Types.UpsertConnectorMutation,
{ connector: Types.ConnectorInput }
>(Documents.UpsertConnector, { connector: connector });
}
*/
async deleteConnector(id) {
return this.mutateAndCheckError(Documents.DeleteConnector, { id: id });
}
/*
public async deleteConnectors(
ids: string[],
isSynchronous?: boolean
): Promise<Types.DeleteConnectorsMutation> {
return this.mutateAndCheckError<
Types.DeleteConnectorsMutation,
{ ids: string[]; isSynchronous?: boolean }
>(Documents.DeleteConnectors, { ids: ids, isSynchronous: isSynchronous });
}
public async deleteAllConnectors(
filter?: Types.ConnectorFilter,
isSynchronous?: boolean,
correlationId?: string
): Promise<Types.DeleteAllConnectorsMutation> {
return this.mutateAndCheckError<
Types.DeleteAllConnectorsMutation,
{
filter?: Types.ConnectorFilter;
isSynchronous?: boolean;
correlationId?: string;
}
>(Documents.DeleteAllConnectors, {
filter: filter,
isSynchronous: isSynchronous,
correlationId: correlationId,
});
}
*/
async getConnector(id) {
return this.queryAndCheckError(Documents.GetConnector, { id: id });
}
async queryConnectors(filter) {
return this.queryAndCheckError(Documents.QueryConnectors, { filter: filter });
}
async countConnectors(filter) {
return this.queryAndCheckError(Documents.CountConnectors, { filter: filter });
}
/*
public async connectorExists(
filter?: Types.ConnectorFilter
): Promise<Types.ConnectorExistsQuery> {
return this.queryAndCheckError<
Types.QueryConnectorsQuery,
{ filter?: Types.ConnectorFilter }
>(Documents.ConnectorExists, { filter: filter });
}
*/
async createView(view) {
return this.mutateAndCheckError(Documents.CreateView, { view: view });
}
async updateView(view) {
return this.mutateAndCheckError(Documents.UpdateView, { view: view });
}
async upsertView(view) {
return this.mutateAndCheckError(Documents.UpsertView, { view: view });
}
async deleteView(id) {
return this.mutateAndCheckError(Documents.DeleteView, { id: id });
}
async deleteViews(ids, isSynchronous) {
return this.mutateAndCheckError(Documents.DeleteViews, { ids: ids, isSynchronous: isSynchronous });
}
async deleteAllViews(filter, isSynchronous, correlationId) {
return this.mutateAndCheckError(Documents.DeleteAllViews, {
filter: filter,
isSynchronous: isSynchronous,
correlationId: correlationId,
});
}
async getView(id) {
return this.queryAndCheckError(Documents.GetView, { id: id });
}
async queryViews(filter) {
return this.queryAndCheckError(Documents.QueryViews, { filter: filter });
}
async countViews(filter) {
return this.queryAndCheckError(Documents.CountViews, { filter: filter });
}
async viewExists(filter) {
return this.queryAndCheckError(Documents.ViewExists, { filter: filter });
}
async createWorkflow(workflow) {
return this.mutateAndCheckError(Documents.CreateWorkflow, { workflow: workflow });
}
async updateWorkflow(workflow) {
return this.mutateAndCheckError(Documents.UpdateWorkflow, { workflow: workflow });
}
async upsertWorkflow(workflow) {
return this.mutateAndCheckError(Documents.UpsertWorkflow, { workflow: workflow });
}
async deleteWorkflow(id) {
return this.mutateAndCheckError(Documents.DeleteWorkflow, { id: id });
}
async deleteWorkflows(ids, isSynchronous) {
return this.mutateAndCheckError(Documents.DeleteWorkflows, { ids: ids, isSynchronous: isSynchronous });
}
async deleteAllWorkflows(filter, isSynchronous, correlationId) {
return this.mutateAndCheckError(Documents.DeleteAllWorkflows, {
filter: filter,
isSynchronous: isSynchronous,
correlationId: correlationId,
});
}
async getWorkflow(id) {
return this.queryAndCheckError(Documents.GetWorkflow, { id: id });
}
async queryWorkflows(filter) {
return this.queryAndCheckError(Documents.QueryWorkflows, { filter: filter });
}
async countWorkflows(filter) {
return this.queryAndCheckError(Documents.CountWorkflows, { filter: filter });
}
async workflowExists(filter) {
return this.queryAndCheckError(Documents.WorkflowExists, { filter: filter });
}
async createUser(user) {
return this.mutateAndCheckError(Documents.CreateUser, { user: user });
}
async updateUser(user) {
return this.mutateAndCheckError(Documents.UpdateUser, { user: user });
}
async deleteUser(id) {
return this.mutateAndCheckError(Documents.DeleteUser, { id: id });
}
async getUserByIdentifier(identifier) {
return this.queryAndCheckError(Documents.GetUserByIdentifier, { identifier: identifier });
}
async getUser() {
return this.queryAndCheckError(Documents.GetUser, {});
}
async queryUsers(filter) {
return this.queryAndCheckError(Documents.QueryUsers, { filter: filter });
}
async countUsers(filter) {
return this.queryAndCheckError(Documents.CountUsers, { filter: filter });
}
async enableUser(id) {
return this.mutateAndCheckError(Documents.EnableUser, { id: id });
}
async disableUser(id) {
return this.mutateAndCheckError(Documents.DisableUser, { id: id });
}
async createCategory(category) {
return this.mutateAndCheckError(Documents.CreateCategory, { category: category });
}
async updateCategory(category) {
return this.mutateAndCheckError(Documents.UpdateCategory, { category: category });
}
async upsertCategory(category) {
return this.mutateAndCheckError(Documents.UpsertCategory, { category: category });
}
async deleteCategory(id) {
return this.mutateAndCheckError(Documents.DeleteCategory, { id: id });
}
async deleteCategories(ids, isSynchronous) {
return this.mutateAndCheckError(Documents.DeleteCategories, { ids: ids, isSynchronous: isSynchronous });
}
async deleteAllCategories(filter, isSynchronous, correlationId) {
return this.mutateAndCheckError(Documents.DeleteAllCategories, {
filter: filter,
isSyn