@erllecta/coding-helper 1.0.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.
@@ -0,0 +1,12 @@
1
+ import type { Assistant, AssistantWithTools, KnowledgeBase, PaginatedResponse, SearchGroup } from '../types.js';
2
+ export declare function validateApiKey(apiKey: string): Promise<boolean>;
3
+ export interface GetAssistantsOptions {
4
+ limit?: number;
5
+ cursor?: string;
6
+ search?: string;
7
+ group?: SearchGroup;
8
+ }
9
+ export declare function getAssistants(apiKey: string, options?: GetAssistantsOptions): Promise<PaginatedResponse<Assistant>>;
10
+ export declare function getAssistant(apiKey: string, id: string): Promise<AssistantWithTools>;
11
+ export declare function getAnthropicBaseUrl(assistantId?: string): string;
12
+ export declare function getKnowledgeBase(apiKey: string, id: string): Promise<KnowledgeBase>;
@@ -0,0 +1,48 @@
1
+ const API_BASE = 'https://api.er-gpt.ru';
2
+ async function request(path, apiKey, options) {
3
+ const response = await fetch(`${API_BASE}${path}`, {
4
+ method: options?.method ?? 'GET',
5
+ headers: {
6
+ Authorization: `Bearer ${apiKey}`,
7
+ 'Content-Type': 'application/json',
8
+ },
9
+ body: options?.body ? JSON.stringify(options.body) : undefined,
10
+ });
11
+ if (!response.ok) {
12
+ const error = await response.text();
13
+ throw new Error(`API Error: ${response.status} - ${error}`);
14
+ }
15
+ return response.json();
16
+ }
17
+ export async function validateApiKey(apiKey) {
18
+ try {
19
+ await request('/api/assistant?limit=1', apiKey);
20
+ return true;
21
+ }
22
+ catch {
23
+ return false;
24
+ }
25
+ }
26
+ export async function getAssistants(apiKey, options) {
27
+ const params = new URLSearchParams();
28
+ params.set('limit', String(options?.limit ?? 50));
29
+ if (options?.cursor)
30
+ params.set('cursor', options.cursor);
31
+ if (options?.search)
32
+ params.set('search', options.search);
33
+ if (options?.group)
34
+ params.set('group', options.group);
35
+ return request(`/api/assistant?${params}`, apiKey);
36
+ }
37
+ export async function getAssistant(apiKey, id) {
38
+ return request(`/api/assistant/${id}`, apiKey);
39
+ }
40
+ export function getAnthropicBaseUrl(assistantId) {
41
+ if (assistantId) {
42
+ return `${API_BASE}/api/anthropic/assistant/${assistantId}`;
43
+ }
44
+ return `${API_BASE}/api/anthropic`;
45
+ }
46
+ export async function getKnowledgeBase(apiKey, id) {
47
+ return request(`/api/knowledge/${id}`, apiKey);
48
+ }