@llamaindex/ui
Version:
A comprehensive UI component library built with React, TypeScript, and Tailwind CSS for LlamaIndex applications
103 lines (99 loc) • 3.07 kB
JavaScript
var api = require('llama-cloud-services/api');
var workflowsClient = require('@llamaindex/workflows-client');
var agent = require('llama-cloud-services/beta/agent');
var react = require('react');
var jsxRuntime = require('react/jsx-runtime');
// src/lib/clients.ts
var ApiContext = react.createContext(null);
function ApiProvider({ children, clients, project }) {
const contextValue = react.useMemo(
() => ({
clients,
project
}),
[clients, project]
);
return /* @__PURE__ */ jsxRuntime.jsx(ApiContext.Provider, { value: contextValue, children });
}
function createMockClients() {
return {
workflowsClient: workflowsClient.client,
cloudApiClient: api.client,
agentDataClient: agent.createAgentDataClient({
agentUrlId: "your-agent-url-id",
collection: "your-collection"
})
};
}
function useApiContext() {
const context = react.useContext(ApiContext);
if (!context) {
throw new Error(
"useApiContext must be used within an ApiProvider. Please wrap your component tree with <ApiProvider>."
);
}
return context;
}
function useWorkflowsClient() {
const { clients } = useApiContext();
if (!clients.workflowsClient) {
throw new Error(
"No workflows client configured. Please ensure workflowsClient is configured in ApiProvider."
);
}
return clients.workflowsClient;
}
function useCloudApiClient() {
const { clients } = useApiContext();
if (!clients.cloudApiClient) {
throw new Error(
"No cloud api client configured. Please ensure cloudApiClient is configured in ApiProvider."
);
}
return clients.cloudApiClient;
}
function useAgentDataClient() {
const { clients } = useApiContext();
if (!clients.agentDataClient) {
throw new Error(
"No agent data client configured. Please ensure agentDataClient is configured in ApiProvider."
);
}
return clients.agentDataClient;
}
function useApiClients() {
const { clients } = useApiContext();
return clients;
}
function useProject() {
const { project } = useApiContext();
return project != null ? project : {};
}
Object.defineProperty(exports, "cloudApiClient", {
enumerable: true,
get: function () { return api.client; }
});
Object.defineProperty(exports, "createClient", {
enumerable: true,
get: function () { return workflowsClient.createClient; }
});
Object.defineProperty(exports, "createConfig", {
enumerable: true,
get: function () { return workflowsClient.createConfig; }
});
Object.defineProperty(exports, "workflowsClient", {
enumerable: true,
get: function () { return workflowsClient.client; }
});
Object.defineProperty(exports, "createAgentDataClient", {
enumerable: true,
get: function () { return agent.createAgentDataClient; }
});
exports.ApiProvider = ApiProvider;
exports.createMockClients = createMockClients;
exports.useAgentDataClient = useAgentDataClient;
exports.useApiClients = useApiClients;
exports.useCloudApiClient = useCloudApiClient;
exports.useProject = useProject;
exports.useWorkflowsClient = useWorkflowsClient;
;