mirror of
https://github.com/Azure/cosmos-explorer.git
synced 2025-12-27 04:41:48 +00:00
* Implement copilot for user database * Fix minor bugs * fix bugs * Add user database copilot * Add placeholder text on copilot * Add AFEC adn killswitch * Add new v2 sampledatabase endpoint * Add telemetry * fix telemetry bug * Add query edited telemetry * add authorization header * Add back to the staging env for phoenix * point to stage for phoenix * Preview commit for test env * Preview link for staging * change the staging url * fix lint, unit tests * fix lint, unit tests * fix formatting
57 lines
2.2 KiB
TypeScript
57 lines
2.2 KiB
TypeScript
import { FeedOptions, Item, ItemDefinition, QueryIterator, Resource } from "@azure/cosmos";
|
|
import { QueryCopilotSampleContainerId, QueryCopilotSampleDatabaseId } from "Common/Constants";
|
|
import { handleError } from "Common/ErrorHandlingUtils";
|
|
import { sampleDataClient } from "Common/SampleDataClient";
|
|
import { getPartitionKeyValue } from "Common/dataAccess/getPartitionKeyValue";
|
|
import { getCommonQueryOptions } from "Common/dataAccess/queryDocuments";
|
|
import DocumentId from "Explorer/Tree/DocumentId";
|
|
import { logConsoleProgress } from "Utils/NotificationConsoleUtils";
|
|
|
|
export interface SuggestedPrompt {
|
|
id: number;
|
|
text: string;
|
|
}
|
|
|
|
export const querySampleDocuments = (query: string, options: FeedOptions): QueryIterator<ItemDefinition & Resource> => {
|
|
options = getCommonQueryOptions(options);
|
|
return sampleDataClient()
|
|
.database(QueryCopilotSampleDatabaseId)
|
|
.container(QueryCopilotSampleContainerId)
|
|
.items.query(query, options);
|
|
};
|
|
|
|
export const readSampleDocument = async (documentId: DocumentId): Promise<Item> => {
|
|
const clearMessage = logConsoleProgress(`Reading item ${documentId.id()}`);
|
|
|
|
try {
|
|
const response = await sampleDataClient()
|
|
.database(QueryCopilotSampleDatabaseId)
|
|
.container(QueryCopilotSampleContainerId)
|
|
.item(documentId.id(), getPartitionKeyValue(documentId))
|
|
.read();
|
|
|
|
return response?.resource;
|
|
} catch (error) {
|
|
handleError(error, "ReadDocument", `Failed to read item ${documentId.id()}`);
|
|
throw error;
|
|
} finally {
|
|
clearMessage();
|
|
}
|
|
};
|
|
|
|
export const getSampleDatabaseSuggestedPrompts = (): SuggestedPrompt[] => {
|
|
return [
|
|
{ id: 1, text: 'Show all products that have the word "ultra" in the name or description' },
|
|
{ id: 2, text: "What are all of the possible categories for the products, and their counts?" },
|
|
{ id: 3, text: 'Show me all products that have been reviewed by someone with a username that contains "bob"' },
|
|
];
|
|
};
|
|
|
|
export const getSuggestedPrompts = (): SuggestedPrompt[] => {
|
|
return [
|
|
{ id: 1, text: "Show the first 10 items" },
|
|
{ id: 2, text: 'Count all the items in my data as "numItems"' },
|
|
{ id: 3, text: "Find the oldest item added to my collection" },
|
|
];
|
|
};
|