@qozara/ai-client 0.0.0-stage → 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.
- package/dist/AgentClient.d.ts +21 -0
- package/dist/AgentClient.d.ts.map +1 -0
- package/dist/AgentClient.js +63 -0
- package/dist/AgentClient.js.map +1 -0
- package/dist/index.d.ts +107 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +381 -0
- package/dist/index.js.map +1 -0
- package/dist/providers/AiProviderFactory.d.ts +16 -0
- package/dist/providers/AiProviderFactory.d.ts.map +1 -0
- package/dist/providers/AiProviderFactory.js +81 -0
- package/dist/providers/AiProviderFactory.js.map +1 -0
- package/dist/providers/LocalOllamaProvider.d.ts +12 -0
- package/dist/providers/LocalOllamaProvider.d.ts.map +1 -0
- package/dist/providers/LocalOllamaProvider.js +121 -0
- package/dist/providers/LocalOllamaProvider.js.map +1 -0
- package/dist/providers/ProxyAiProvider.d.ts +14 -0
- package/dist/providers/ProxyAiProvider.d.ts.map +1 -0
- package/dist/providers/ProxyAiProvider.js +69 -0
- package/dist/providers/ProxyAiProvider.js.map +1 -0
- package/dist/providers/WindowAiProvider.d.ts +10 -0
- package/dist/providers/WindowAiProvider.d.ts.map +1 -0
- package/dist/providers/WindowAiProvider.js +68 -0
- package/dist/providers/WindowAiProvider.js.map +1 -0
- package/dist/providers/types.d.ts +38 -0
- package/dist/providers/types.d.ts.map +1 -0
- package/dist/providers/types.js +2 -0
- package/dist/providers/types.js.map +1 -0
- package/package.json +36 -4
- package/README.md +0 -3
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { AgentChatRequest, AgentChatResponse, AuthTokenGetter } from './providers/types.js';
|
|
2
|
+
export interface AgentClientChatOptions extends AgentChatRequest {
|
|
3
|
+
ciphertext?: string;
|
|
4
|
+
byokProvider?: string;
|
|
5
|
+
}
|
|
6
|
+
export declare class AgentClient {
|
|
7
|
+
private getAuthToken?;
|
|
8
|
+
private base;
|
|
9
|
+
constructor(baseUrl?: string, getAuthToken?: AuthTokenGetter | undefined);
|
|
10
|
+
/**
|
|
11
|
+
* Encrypts a personal API key using the edge proxy's KMS_SECRET.
|
|
12
|
+
* Works completely unauthenticated (zero login required).
|
|
13
|
+
*/
|
|
14
|
+
encryptApiKey(apiKey: string): Promise<string>;
|
|
15
|
+
/**
|
|
16
|
+
* Sends a chat request to the edge proxy.
|
|
17
|
+
* Auth token is optional (unauthenticated clients can use BYOK or anonymous tier).
|
|
18
|
+
*/
|
|
19
|
+
chat(request: AgentClientChatOptions): Promise<AgentChatResponse>;
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=AgentClient.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AgentClient.d.ts","sourceRoot":"","sources":["../src/AgentClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAE5F,MAAM,WAAW,sBAAuB,SAAQ,gBAAgB;IAC5D,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,YAAY,CAAC,EAAE,MAAM,CAAC;CACzB;AAED,qBAAa,WAAW;IAKhB,OAAO,CAAC,YAAY,CAAC;IAJzB,OAAO,CAAC,IAAI,CAAS;gBAGjB,OAAO,GAAE,MAAW,EACZ,YAAY,CAAC,EAAE,eAAe,YAAA;IAK1C;;;OAGG;IACG,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IA2BpD;;;OAGG;IACG,IAAI,CAAC,OAAO,EAAE,sBAAsB,GAAG,OAAO,CAAC,iBAAiB,CAAC;CA4B1E"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
export class AgentClient {
|
|
2
|
+
getAuthToken;
|
|
3
|
+
base;
|
|
4
|
+
constructor(baseUrl = '', getAuthToken) {
|
|
5
|
+
this.getAuthToken = getAuthToken;
|
|
6
|
+
this.base = (baseUrl || '').replace(/\/$/, '');
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Encrypts a personal API key using the edge proxy's KMS_SECRET.
|
|
10
|
+
* Works completely unauthenticated (zero login required).
|
|
11
|
+
*/
|
|
12
|
+
async encryptApiKey(apiKey) {
|
|
13
|
+
const headers = {
|
|
14
|
+
'Content-Type': 'application/json',
|
|
15
|
+
};
|
|
16
|
+
if (this.getAuthToken) {
|
|
17
|
+
const token = await this.getAuthToken();
|
|
18
|
+
if (token) {
|
|
19
|
+
headers['Authorization'] = `Bearer ${token}`;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
const response = await fetch(`${this.base}/api/v1/agent/encrypt`, {
|
|
23
|
+
method: 'POST',
|
|
24
|
+
headers,
|
|
25
|
+
body: JSON.stringify({ apiKey }),
|
|
26
|
+
});
|
|
27
|
+
if (!response.ok) {
|
|
28
|
+
const error = await response.json().catch(() => ({}));
|
|
29
|
+
throw new Error(error.message || error.error || `Encryption failed (${response.status})`);
|
|
30
|
+
}
|
|
31
|
+
const result = await response.json();
|
|
32
|
+
return result.ciphertext;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Sends a chat request to the edge proxy.
|
|
36
|
+
* Auth token is optional (unauthenticated clients can use BYOK or anonymous tier).
|
|
37
|
+
*/
|
|
38
|
+
async chat(request) {
|
|
39
|
+
const headers = {
|
|
40
|
+
'Content-Type': 'application/json',
|
|
41
|
+
};
|
|
42
|
+
if (this.getAuthToken) {
|
|
43
|
+
const token = await this.getAuthToken();
|
|
44
|
+
if (token) {
|
|
45
|
+
headers['Authorization'] = `Bearer ${token}`;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
const response = await fetch(`${this.base}/api/v1/agent/chat`, {
|
|
49
|
+
method: 'POST',
|
|
50
|
+
headers,
|
|
51
|
+
body: JSON.stringify(request),
|
|
52
|
+
});
|
|
53
|
+
if (!response.ok) {
|
|
54
|
+
const error = await response.json().catch(() => ({}));
|
|
55
|
+
return {
|
|
56
|
+
type: 'text',
|
|
57
|
+
error: error.code || error.message || error.error || `AI proxy request failed (${response.status})`,
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
return await response.json();
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
//# sourceMappingURL=AgentClient.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AgentClient.js","sourceRoot":"","sources":["../src/AgentClient.ts"],"names":[],"mappings":"AAOA,MAAM,OAAO,WAAW;IAKR;IAJJ,IAAI,CAAS;IAErB,YACI,UAAkB,EAAE,EACZ,YAA8B;QAA9B,iBAAY,GAAZ,YAAY,CAAkB;QAEtC,IAAI,CAAC,IAAI,GAAG,CAAC,OAAO,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;IACnD,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,aAAa,CAAC,MAAc;QAC9B,MAAM,OAAO,GAA2B;YACpC,cAAc,EAAE,kBAAkB;SACrC,CAAC;QAEF,IAAI,IAAI,CAAC,YAAY,EAAE,CAAC;YACpB,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,YAAY,EAAE,CAAC;YACxC,IAAI,KAAK,EAAE,CAAC;gBACR,OAAO,CAAC,eAAe,CAAC,GAAG,UAAU,KAAK,EAAE,CAAC;YACjD,CAAC;QACL,CAAC;QAED,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,IAAI,CAAC,IAAI,uBAAuB,EAAE;YAC9D,MAAM,EAAE,MAAM;YACd,OAAO;YACP,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;SACnC,CAAC,CAAC;QAEH,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;YACf,MAAM,KAAK,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,CAAC,EAAE,CAAC,CAAy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,0 +1,107 @@
|
|
|
1
|
+
interface AgentChatMessage {
|
|
2
|
+
role: string;
|
|
3
|
+
content: string;
|
|
4
|
+
}
|
|
5
|
+
interface AgentChatTool {
|
|
6
|
+
name: string;
|
|
7
|
+
description: string;
|
|
8
|
+
parameters: any;
|
|
9
|
+
}
|
|
10
|
+
interface AgentChatRequest {
|
|
11
|
+
messages: AgentChatMessage[];
|
|
12
|
+
systemPrompt?: string;
|
|
13
|
+
tools?: AgentChatTool[] | any[];
|
|
14
|
+
}
|
|
15
|
+
interface AgentChatResponse {
|
|
16
|
+
type: 'text' | 'tool_call';
|
|
17
|
+
content?: string;
|
|
18
|
+
tool?: string;
|
|
19
|
+
arguments?: any;
|
|
20
|
+
error?: string;
|
|
21
|
+
}
|
|
22
|
+
interface AiProvider {
|
|
23
|
+
readonly id: string;
|
|
24
|
+
readonly mode: 'byok' | 'cloud' | 'local-browser' | 'local-ollama' | 'disabled';
|
|
25
|
+
chat(request: AgentChatRequest): Promise<AgentChatResponse>;
|
|
26
|
+
checkAvailability(): Promise<boolean>;
|
|
27
|
+
getSetupMessage(): string | null;
|
|
28
|
+
}
|
|
29
|
+
interface AiFactoryConfig {
|
|
30
|
+
providerPreference: 'auto' | 'byok' | 'local' | 'local-browser' | 'cloud' | 'disabled';
|
|
31
|
+
encryptedApiKey?: string;
|
|
32
|
+
baseUrl?: string;
|
|
33
|
+
proxyUrl?: string;
|
|
34
|
+
ollamaModel?: string;
|
|
35
|
+
byokProvider?: string;
|
|
36
|
+
}
|
|
37
|
+
type AuthTokenGetter = () => string | null | undefined | Promise<string | null | undefined>;
|
|
38
|
+
|
|
39
|
+
declare class ProxyAiProvider implements AiProvider {
|
|
40
|
+
private getAuthToken?;
|
|
41
|
+
private encryptedApiKey?;
|
|
42
|
+
private byokProvider?;
|
|
43
|
+
readonly id = "cloud-proxy";
|
|
44
|
+
private base;
|
|
45
|
+
get mode(): 'byok' | 'cloud';
|
|
46
|
+
constructor(proxyUrl?: string, getAuthToken?: AuthTokenGetter | undefined, encryptedApiKey?: string | undefined, byokProvider?: string | undefined);
|
|
47
|
+
chat(request: AgentChatRequest): Promise<AgentChatResponse>;
|
|
48
|
+
checkAvailability(): Promise<boolean>;
|
|
49
|
+
getSetupMessage(): string | null;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
declare class WindowAiProvider implements AiProvider {
|
|
53
|
+
readonly id = "window-ai";
|
|
54
|
+
readonly mode = "local-browser";
|
|
55
|
+
chat(request: AgentChatRequest): Promise<AgentChatResponse>;
|
|
56
|
+
checkAvailability(): Promise<boolean>;
|
|
57
|
+
getSetupMessage(): string | null;
|
|
58
|
+
private isSupported;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
declare class LocalOllamaProvider implements AiProvider {
|
|
62
|
+
readonly id = "local-ollama";
|
|
63
|
+
readonly mode = "local-ollama";
|
|
64
|
+
private model;
|
|
65
|
+
private base;
|
|
66
|
+
constructor(baseUrl?: string, model?: string);
|
|
67
|
+
chat(request: AgentChatRequest): Promise<AgentChatResponse>;
|
|
68
|
+
checkAvailability(): Promise<boolean>;
|
|
69
|
+
getSetupMessage(): string | null;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
declare class DisabledAiProvider implements AiProvider {
|
|
73
|
+
readonly id = "disabled";
|
|
74
|
+
readonly mode = "disabled";
|
|
75
|
+
chat(): Promise<{
|
|
76
|
+
type: "text";
|
|
77
|
+
error: string;
|
|
78
|
+
}>;
|
|
79
|
+
checkAvailability(): Promise<boolean>;
|
|
80
|
+
getSetupMessage(): null;
|
|
81
|
+
}
|
|
82
|
+
declare class AiProviderFactory {
|
|
83
|
+
static createProvider(config: AiFactoryConfig, getAuthToken?: AuthTokenGetter): Promise<AiProvider>;
|
|
84
|
+
static getSetupMessage(providerId: string, config?: Partial<AiFactoryConfig>): string | null;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
interface AgentClientChatOptions extends AgentChatRequest {
|
|
88
|
+
ciphertext?: string;
|
|
89
|
+
byokProvider?: string;
|
|
90
|
+
}
|
|
91
|
+
declare class AgentClient {
|
|
92
|
+
private getAuthToken?;
|
|
93
|
+
private base;
|
|
94
|
+
constructor(baseUrl?: string, getAuthToken?: AuthTokenGetter | undefined);
|
|
95
|
+
/**
|
|
96
|
+
* Encrypts a personal API key using the edge proxy's KMS_SECRET.
|
|
97
|
+
* Works completely unauthenticated (zero login required).
|
|
98
|
+
*/
|
|
99
|
+
encryptApiKey(apiKey: string): Promise<string>;
|
|
100
|
+
/**
|
|
101
|
+
* Sends a chat request to the edge proxy.
|
|
102
|
+
* Auth token is optional (unauthenticated clients can use BYOK or anonymous tier).
|
|
103
|
+
*/
|
|
104
|
+
chat(request: AgentClientChatOptions): Promise<AgentChatResponse>;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export { type AgentChatMessage, type AgentChatRequest, type AgentChatResponse, type AgentChatTool, AgentClient, type AgentClientChatOptions, type AiFactoryConfig, type AiProvider, AiProviderFactory, type AuthTokenGetter, DisabledAiProvider, LocalOllamaProvider, ProxyAiProvider, WindowAiProvider };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,sBAAsB,CAAC;AACrC,cAAc,gCAAgC,CAAC;AAC/C,cAAc,iCAAiC,CAAC;AAChD,cAAc,oCAAoC,CAAC;AACnD,cAAc,kCAAkC,CAAC;AACjD,cAAc,kBAAkB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,381 @@
|
|
|
1
|
+
// src/providers/ProxyAiProvider.ts
|
|
2
|
+
var ProxyAiProvider = class {
|
|
3
|
+
constructor(proxyUrl = "", getAuthToken, encryptedApiKey, byokProvider) {
|
|
4
|
+
this.getAuthToken = getAuthToken;
|
|
5
|
+
this.encryptedApiKey = encryptedApiKey;
|
|
6
|
+
this.byokProvider = byokProvider;
|
|
7
|
+
this.base = (proxyUrl || "").replace(/\/$/, "");
|
|
8
|
+
}
|
|
9
|
+
getAuthToken;
|
|
10
|
+
encryptedApiKey;
|
|
11
|
+
byokProvider;
|
|
12
|
+
id = "cloud-proxy";
|
|
13
|
+
base;
|
|
14
|
+
get mode() {
|
|
15
|
+
return this.encryptedApiKey ? "byok" : "cloud";
|
|
16
|
+
}
|
|
17
|
+
async chat(request) {
|
|
18
|
+
try {
|
|
19
|
+
const headers = {
|
|
20
|
+
"Content-Type": "application/json"
|
|
21
|
+
};
|
|
22
|
+
if (this.getAuthToken) {
|
|
23
|
+
const token = await this.getAuthToken();
|
|
24
|
+
if (token) {
|
|
25
|
+
headers["Authorization"] = `Bearer ${token}`;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
const response = await fetch(`${this.base}/api/v1/agent/chat`, {
|
|
29
|
+
method: "POST",
|
|
30
|
+
headers,
|
|
31
|
+
body: JSON.stringify({
|
|
32
|
+
messages: request.messages,
|
|
33
|
+
systemPrompt: request.systemPrompt,
|
|
34
|
+
tools: request.tools,
|
|
35
|
+
ciphertext: this.encryptedApiKey,
|
|
36
|
+
byokProvider: this.byokProvider
|
|
37
|
+
})
|
|
38
|
+
});
|
|
39
|
+
if (!response.ok) {
|
|
40
|
+
const error = await response.json().catch(() => ({}));
|
|
41
|
+
return {
|
|
42
|
+
type: "text",
|
|
43
|
+
error: error.code || error.message || error.error || `Proxy request failed (${response.status})`
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
return await response.json();
|
|
47
|
+
} catch (error) {
|
|
48
|
+
return { type: "text", error: error.message || "Network error communicating with AI proxy" };
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
async checkAvailability() {
|
|
52
|
+
if (!this.base) return false;
|
|
53
|
+
try {
|
|
54
|
+
const controller = new AbortController();
|
|
55
|
+
const id = setTimeout(() => controller.abort(), 3e3);
|
|
56
|
+
const response = await fetch(`${this.base}/health`, { signal: controller.signal });
|
|
57
|
+
clearTimeout(id);
|
|
58
|
+
return response.ok;
|
|
59
|
+
} catch {
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
getSetupMessage() {
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
// src/providers/WindowAiProvider.ts
|
|
69
|
+
var WindowAiProvider = class {
|
|
70
|
+
id = "window-ai";
|
|
71
|
+
mode = "local-browser";
|
|
72
|
+
async chat(request) {
|
|
73
|
+
try {
|
|
74
|
+
if (!this.isSupported()) {
|
|
75
|
+
return { type: "text", error: "window.ai not supported" };
|
|
76
|
+
}
|
|
77
|
+
const capabilities = await globalThis.window?.ai.languageModel.capabilities();
|
|
78
|
+
if (capabilities.available !== "readily") {
|
|
79
|
+
return { type: "text", error: "window.ai model not ready" };
|
|
80
|
+
}
|
|
81
|
+
const session = await globalThis.window?.ai.languageModel.create({
|
|
82
|
+
systemPrompt: request.systemPrompt
|
|
83
|
+
});
|
|
84
|
+
const prompt = request.messages.map((m) => `${m.role === "user" ? "User" : "Assistant"}: ${m.content}`).join("\n") + "\nAssistant:";
|
|
85
|
+
const response = await session.prompt(prompt);
|
|
86
|
+
session.destroy();
|
|
87
|
+
let cleanResponse = response.trim();
|
|
88
|
+
if (cleanResponse.includes("```json")) {
|
|
89
|
+
cleanResponse = cleanResponse.split("```json")[1].split("```")[0].trim();
|
|
90
|
+
} else if (cleanResponse.includes("```")) {
|
|
91
|
+
cleanResponse = cleanResponse.split("```")[1].split("```")[0].trim();
|
|
92
|
+
}
|
|
93
|
+
try {
|
|
94
|
+
const parsed = JSON.parse(cleanResponse);
|
|
95
|
+
if (parsed.tool && parsed.arguments) {
|
|
96
|
+
return {
|
|
97
|
+
type: "tool_call",
|
|
98
|
+
tool: parsed.tool,
|
|
99
|
+
arguments: parsed.arguments
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
if (parsed.type === "tool_call") {
|
|
103
|
+
return parsed;
|
|
104
|
+
}
|
|
105
|
+
return { type: "text", content: response };
|
|
106
|
+
} catch {
|
|
107
|
+
return { type: "text", content: response };
|
|
108
|
+
}
|
|
109
|
+
} catch (error) {
|
|
110
|
+
return { type: "text", error: error.message || "Window AI error" };
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
async checkAvailability() {
|
|
114
|
+
if (!this.isSupported()) return false;
|
|
115
|
+
try {
|
|
116
|
+
const capabilities = await globalThis.window?.ai.languageModel.capabilities();
|
|
117
|
+
return capabilities.available === "readily";
|
|
118
|
+
} catch {
|
|
119
|
+
return false;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
getSetupMessage() {
|
|
123
|
+
if (this.isSupported()) return null;
|
|
124
|
+
return "To enable Local Browser AI: 1. Use Chrome Dev/Canary. 2. Enable 'Prompt API for Gemini Nano' in chrome://flags. 3. Enable 'Enables optimization guide on device' in chrome://flags. 4. Relaunch and wait for model download in chrome://components.";
|
|
125
|
+
}
|
|
126
|
+
isSupported() {
|
|
127
|
+
return typeof globalThis !== "undefined" && !!globalThis.window?.ai?.languageModel;
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
// src/providers/LocalOllamaProvider.ts
|
|
132
|
+
var LocalOllamaProvider = class {
|
|
133
|
+
id = "local-ollama";
|
|
134
|
+
mode = "local-ollama";
|
|
135
|
+
model;
|
|
136
|
+
base;
|
|
137
|
+
constructor(baseUrl = "http://localhost:11434/api", model = "qwen2.5:0.5b") {
|
|
138
|
+
this.base = (baseUrl || "http://localhost:11434/api").replace(/\/$/, "");
|
|
139
|
+
this.model = model;
|
|
140
|
+
}
|
|
141
|
+
async chat(request) {
|
|
142
|
+
try {
|
|
143
|
+
const bodyPayload = {
|
|
144
|
+
model: this.model,
|
|
145
|
+
messages: [
|
|
146
|
+
{ role: "system", content: request.systemPrompt },
|
|
147
|
+
...request.messages
|
|
148
|
+
],
|
|
149
|
+
stream: false
|
|
150
|
+
};
|
|
151
|
+
if (request.tools && request.tools.length > 0) {
|
|
152
|
+
bodyPayload.tools = request.tools.map((t) => ({
|
|
153
|
+
type: "function",
|
|
154
|
+
function: {
|
|
155
|
+
name: t.name,
|
|
156
|
+
description: t.description,
|
|
157
|
+
parameters: t.parameters
|
|
158
|
+
}
|
|
159
|
+
}));
|
|
160
|
+
} else {
|
|
161
|
+
bodyPayload.format = "json";
|
|
162
|
+
}
|
|
163
|
+
const chatUrl = this.base.endsWith("/api") ? `${this.base}/chat` : `${this.base}/api/chat`;
|
|
164
|
+
const response = await fetch(chatUrl, {
|
|
165
|
+
method: "POST",
|
|
166
|
+
headers: {
|
|
167
|
+
"Content-Type": "application/json"
|
|
168
|
+
},
|
|
169
|
+
body: JSON.stringify(bodyPayload)
|
|
170
|
+
});
|
|
171
|
+
if (!response.ok) {
|
|
172
|
+
let errorMsg = `Ollama failed (${response.status})`;
|
|
173
|
+
try {
|
|
174
|
+
const errBody = await response.json();
|
|
175
|
+
if (errBody.error) errorMsg += `: ${errBody.error}`;
|
|
176
|
+
} catch {
|
|
177
|
+
}
|
|
178
|
+
return { type: "text", error: errorMsg };
|
|
179
|
+
}
|
|
180
|
+
const data = await response.json();
|
|
181
|
+
if (data.message?.tool_calls && data.message.tool_calls.length > 0) {
|
|
182
|
+
const call = data.message.tool_calls[0].function;
|
|
183
|
+
return {
|
|
184
|
+
type: "tool_call",
|
|
185
|
+
tool: call.name,
|
|
186
|
+
arguments: call.arguments
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
const content = data.message?.content || "";
|
|
190
|
+
try {
|
|
191
|
+
const parsed = JSON.parse(content);
|
|
192
|
+
const toolName = parsed.tool || parsed.action || parsed.type || parsed.tool_used;
|
|
193
|
+
if (toolName) {
|
|
194
|
+
const args = parsed.arguments || { ...parsed };
|
|
195
|
+
if (args === parsed) {
|
|
196
|
+
delete args.tool;
|
|
197
|
+
delete args.action;
|
|
198
|
+
delete args.type;
|
|
199
|
+
delete args.tool_used;
|
|
200
|
+
}
|
|
201
|
+
return {
|
|
202
|
+
type: "tool_call",
|
|
203
|
+
tool: toolName,
|
|
204
|
+
arguments: args
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
const requestedTools = (request.tools || []).map((t) => t.name);
|
|
208
|
+
for (const tool of requestedTools) {
|
|
209
|
+
const key = Object.keys(parsed).find((k) => k.toLowerCase() === tool.toLowerCase());
|
|
210
|
+
if (key) {
|
|
211
|
+
return {
|
|
212
|
+
type: "tool_call",
|
|
213
|
+
tool,
|
|
214
|
+
arguments: parsed[key]
|
|
215
|
+
};
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
return { type: "text", content };
|
|
219
|
+
} catch {
|
|
220
|
+
return { type: "text", content };
|
|
221
|
+
}
|
|
222
|
+
} catch (error) {
|
|
223
|
+
return { type: "text", error: error.message || "Local Ollama error" };
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
async checkAvailability() {
|
|
227
|
+
try {
|
|
228
|
+
const controller = new AbortController();
|
|
229
|
+
const id = setTimeout(() => controller.abort(), 2e3);
|
|
230
|
+
const tagsUrl = this.base.endsWith("/api") ? `${this.base}/tags` : `${this.base}/api/tags`;
|
|
231
|
+
const response = await fetch(tagsUrl, { signal: controller.signal });
|
|
232
|
+
clearTimeout(id);
|
|
233
|
+
return response.ok;
|
|
234
|
+
} catch {
|
|
235
|
+
return false;
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
getSetupMessage() {
|
|
239
|
+
return `Note: Start Ollama with OLLAMA_ORIGINS="*" ollama serve to allow browser connections. Make sure you have pulled the model '${this.model}'.`;
|
|
240
|
+
}
|
|
241
|
+
};
|
|
242
|
+
|
|
243
|
+
// src/providers/AiProviderFactory.ts
|
|
244
|
+
var DisabledAiProvider = class {
|
|
245
|
+
id = "disabled";
|
|
246
|
+
mode = "disabled";
|
|
247
|
+
async chat() {
|
|
248
|
+
return { type: "text", error: "AI is disabled" };
|
|
249
|
+
}
|
|
250
|
+
async checkAvailability() {
|
|
251
|
+
return false;
|
|
252
|
+
}
|
|
253
|
+
getSetupMessage() {
|
|
254
|
+
return null;
|
|
255
|
+
}
|
|
256
|
+
};
|
|
257
|
+
var AiProviderFactory = class {
|
|
258
|
+
static async createProvider(config, getAuthToken) {
|
|
259
|
+
const { providerPreference, encryptedApiKey, baseUrl, proxyUrl, byokProvider } = config;
|
|
260
|
+
if (providerPreference === "disabled") {
|
|
261
|
+
return new DisabledAiProvider();
|
|
262
|
+
}
|
|
263
|
+
if (providerPreference === "byok" && encryptedApiKey && proxyUrl) {
|
|
264
|
+
return new ProxyAiProvider(proxyUrl, getAuthToken, encryptedApiKey, byokProvider);
|
|
265
|
+
}
|
|
266
|
+
if (providerPreference === "local") {
|
|
267
|
+
return new LocalOllamaProvider(baseUrl, config.ollamaModel);
|
|
268
|
+
}
|
|
269
|
+
if (providerPreference === "local-browser") {
|
|
270
|
+
return new WindowAiProvider();
|
|
271
|
+
}
|
|
272
|
+
if (providerPreference === "cloud" && proxyUrl) {
|
|
273
|
+
return new ProxyAiProvider(proxyUrl, getAuthToken, encryptedApiKey, byokProvider);
|
|
274
|
+
}
|
|
275
|
+
if (providerPreference === "auto") {
|
|
276
|
+
if (encryptedApiKey && proxyUrl) {
|
|
277
|
+
return new ProxyAiProvider(proxyUrl, getAuthToken, encryptedApiKey, byokProvider);
|
|
278
|
+
}
|
|
279
|
+
const windowProvider = new WindowAiProvider();
|
|
280
|
+
if (await windowProvider.checkAvailability()) {
|
|
281
|
+
return windowProvider;
|
|
282
|
+
}
|
|
283
|
+
const localProvider = new LocalOllamaProvider(baseUrl, config.ollamaModel);
|
|
284
|
+
if (await localProvider.checkAvailability()) {
|
|
285
|
+
return localProvider;
|
|
286
|
+
}
|
|
287
|
+
if (proxyUrl) {
|
|
288
|
+
return new ProxyAiProvider(proxyUrl, getAuthToken, void 0, byokProvider);
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
return new DisabledAiProvider();
|
|
292
|
+
}
|
|
293
|
+
static getSetupMessage(providerId, config) {
|
|
294
|
+
switch (providerId) {
|
|
295
|
+
case "local":
|
|
296
|
+
case "local-ollama":
|
|
297
|
+
return new LocalOllamaProvider(config?.baseUrl, config?.ollamaModel).getSetupMessage();
|
|
298
|
+
case "local-browser":
|
|
299
|
+
case "window-ai":
|
|
300
|
+
return new WindowAiProvider().getSetupMessage();
|
|
301
|
+
case "byok":
|
|
302
|
+
return "Enter your Gemini API key below. It will be encrypted and stored solely in your personal storage.";
|
|
303
|
+
case "cloud":
|
|
304
|
+
return "Using Qozara Intelligence (Rate-limited).";
|
|
305
|
+
default:
|
|
306
|
+
return null;
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
};
|
|
310
|
+
|
|
311
|
+
// src/AgentClient.ts
|
|
312
|
+
var AgentClient = class {
|
|
313
|
+
constructor(baseUrl = "", getAuthToken) {
|
|
314
|
+
this.getAuthToken = getAuthToken;
|
|
315
|
+
this.base = (baseUrl || "").replace(/\/$/, "");
|
|
316
|
+
}
|
|
317
|
+
getAuthToken;
|
|
318
|
+
base;
|
|
319
|
+
/**
|
|
320
|
+
* Encrypts a personal API key using the edge proxy's KMS_SECRET.
|
|
321
|
+
* Works completely unauthenticated (zero login required).
|
|
322
|
+
*/
|
|
323
|
+
async encryptApiKey(apiKey) {
|
|
324
|
+
const headers = {
|
|
325
|
+
"Content-Type": "application/json"
|
|
326
|
+
};
|
|
327
|
+
if (this.getAuthToken) {
|
|
328
|
+
const token = await this.getAuthToken();
|
|
329
|
+
if (token) {
|
|
330
|
+
headers["Authorization"] = `Bearer ${token}`;
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
const response = await fetch(`${this.base}/api/v1/agent/encrypt`, {
|
|
334
|
+
method: "POST",
|
|
335
|
+
headers,
|
|
336
|
+
body: JSON.stringify({ apiKey })
|
|
337
|
+
});
|
|
338
|
+
if (!response.ok) {
|
|
339
|
+
const error = await response.json().catch(() => ({}));
|
|
340
|
+
throw new Error(error.message || error.error || `Encryption failed (${response.status})`);
|
|
341
|
+
}
|
|
342
|
+
const result = await response.json();
|
|
343
|
+
return result.ciphertext;
|
|
344
|
+
}
|
|
345
|
+
/**
|
|
346
|
+
* Sends a chat request to the edge proxy.
|
|
347
|
+
* Auth token is optional (unauthenticated clients can use BYOK or anonymous tier).
|
|
348
|
+
*/
|
|
349
|
+
async chat(request) {
|
|
350
|
+
const headers = {
|
|
351
|
+
"Content-Type": "application/json"
|
|
352
|
+
};
|
|
353
|
+
if (this.getAuthToken) {
|
|
354
|
+
const token = await this.getAuthToken();
|
|
355
|
+
if (token) {
|
|
356
|
+
headers["Authorization"] = `Bearer ${token}`;
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
const response = await fetch(`${this.base}/api/v1/agent/chat`, {
|
|
360
|
+
method: "POST",
|
|
361
|
+
headers,
|
|
362
|
+
body: JSON.stringify(request)
|
|
363
|
+
});
|
|
364
|
+
if (!response.ok) {
|
|
365
|
+
const error = await response.json().catch(() => ({}));
|
|
366
|
+
return {
|
|
367
|
+
type: "text",
|
|
368
|
+
error: error.code || error.message || error.error || `AI proxy request failed (${response.status})`
|
|
369
|
+
};
|
|
370
|
+
}
|
|
371
|
+
return await response.json();
|
|
372
|
+
}
|
|
373
|
+
};
|
|
374
|
+
export {
|
|
375
|
+
AgentClient,
|
|
376
|
+
AiProviderFactory,
|
|
377
|
+
DisabledAiProvider,
|
|
378
|
+
LocalOllamaProvider,
|
|
379
|
+
ProxyAiProvider,
|
|
380
|
+
WindowAiProvider
|
|
381
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,sBAAsB,CAAC;AACrC,cAAc,gCAAgC,CAAC;AAC/C,cAAc,iCAAiC,CAAC;AAChD,cAAc,oCAAoC,CAAC;AACnD,cAAc,kCAAkC,CAAC;AACjD,cAAc,kBAAkB,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { AiFactoryConfig, AiProvider, AuthTokenGetter } from './types.js';
|
|
2
|
+
export declare class DisabledAiProvider implements AiProvider {
|
|
3
|
+
readonly id = "disabled";
|
|
4
|
+
readonly mode = "disabled";
|
|
5
|
+
chat(): Promise<{
|
|
6
|
+
type: "text";
|
|
7
|
+
error: string;
|
|
8
|
+
}>;
|
|
9
|
+
checkAvailability(): Promise<boolean>;
|
|
10
|
+
getSetupMessage(): null;
|
|
11
|
+
}
|
|
12
|
+
export declare class AiProviderFactory {
|
|
13
|
+
static createProvider(config: AiFactoryConfig, getAuthToken?: AuthTokenGetter): Promise<AiProvider>;
|
|
14
|
+
static getSetupMessage(providerId: string, config?: Partial<AiFactoryConfig>): string | null;
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=AiProviderFactory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AiProviderFactory.d.ts","sourceRoot":"","sources":["../../src/providers/AiProviderFactory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAK1E,qBAAa,kBAAmB,YAAW,UAAU;IACjD,QAAQ,CAAC,EAAE,cAAc;IACzB,QAAQ,CAAC,IAAI,cAAc;IACrB,IAAI;;;;IAGJ,iBAAiB;IAGvB,eAAe;CAGlB;AAED,qBAAa,iBAAiB;WACb,cAAc,CAAC,MAAM,EAAE,eAAe,EAAE,YAAY,CAAC,EAAE,eAAe,GAAG,OAAO,CAAC,UAAU,CAAC;IAyDzG,MAAM,CAAC,eAAe,CAAC,UAAU,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,OAAO,CAAC,eAAe,CAAC,GAAG,MAAM,GAAG,IAAI;CAgB/F"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { ProxyAiProvider } from './ProxyAiProvider.js';
|
|
2
|
+
import { WindowAiProvider } from './WindowAiProvider.js';
|
|
3
|
+
import { LocalOllamaProvider } from './LocalOllamaProvider.js';
|
|
4
|
+
export class DisabledAiProvider {
|
|
5
|
+
id = 'disabled';
|
|
6
|
+
mode = 'disabled';
|
|
7
|
+
async chat() {
|
|
8
|
+
return { type: 'text', error: 'AI is disabled' };
|
|
9
|
+
}
|
|
10
|
+
async checkAvailability() {
|
|
11
|
+
return false;
|
|
12
|
+
}
|
|
13
|
+
getSetupMessage() {
|
|
14
|
+
return null;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
export class AiProviderFactory {
|
|
18
|
+
static async createProvider(config, getAuthToken) {
|
|
19
|
+
const { providerPreference, encryptedApiKey, baseUrl, proxyUrl, byokProvider } = config;
|
|
20
|
+
// Forced Disable
|
|
21
|
+
if (providerPreference === 'disabled') {
|
|
22
|
+
return new DisabledAiProvider();
|
|
23
|
+
}
|
|
24
|
+
// 1. Explicit Selection: BYOK Cloud
|
|
25
|
+
if (providerPreference === 'byok' && encryptedApiKey && proxyUrl) {
|
|
26
|
+
return new ProxyAiProvider(proxyUrl, getAuthToken, encryptedApiKey, byokProvider);
|
|
27
|
+
}
|
|
28
|
+
// 2. Explicit Selection: Local Ollama
|
|
29
|
+
if (providerPreference === 'local') {
|
|
30
|
+
return new LocalOllamaProvider(baseUrl, config.ollamaModel);
|
|
31
|
+
}
|
|
32
|
+
// 3. Explicit Selection: Local Browser AI
|
|
33
|
+
if (providerPreference === 'local-browser') {
|
|
34
|
+
return new WindowAiProvider();
|
|
35
|
+
}
|
|
36
|
+
// 4. Explicit Selection: Cloud (Qozara Intelligence / BYOK based on config)
|
|
37
|
+
if (providerPreference === 'cloud' && proxyUrl) {
|
|
38
|
+
return new ProxyAiProvider(proxyUrl, getAuthToken, encryptedApiKey, byokProvider);
|
|
39
|
+
}
|
|
40
|
+
// 5. "Auto" Mode Polymorphic Fallback Waterfall:
|
|
41
|
+
// BYOK -> window.ai -> Local Ollama -> Qozara Intelligence Cloud Proxy
|
|
42
|
+
if (providerPreference === 'auto') {
|
|
43
|
+
// a) If BYOK ciphertext exists and proxy is set, prioritize user's own key
|
|
44
|
+
if (encryptedApiKey && proxyUrl) {
|
|
45
|
+
return new ProxyAiProvider(proxyUrl, getAuthToken, encryptedApiKey, byokProvider);
|
|
46
|
+
}
|
|
47
|
+
// b) If Window AI (Gemini Nano on-device) is available
|
|
48
|
+
const windowProvider = new WindowAiProvider();
|
|
49
|
+
if (await windowProvider.checkAvailability()) {
|
|
50
|
+
return windowProvider;
|
|
51
|
+
}
|
|
52
|
+
// c) If Local Ollama daemon is active
|
|
53
|
+
const localProvider = new LocalOllamaProvider(baseUrl, config.ollamaModel);
|
|
54
|
+
if (await localProvider.checkAvailability()) {
|
|
55
|
+
return localProvider;
|
|
56
|
+
}
|
|
57
|
+
// d) Last resort: Qozara Intelligence edge proxy
|
|
58
|
+
if (proxyUrl) {
|
|
59
|
+
return new ProxyAiProvider(proxyUrl, getAuthToken, undefined, byokProvider);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return new DisabledAiProvider();
|
|
63
|
+
}
|
|
64
|
+
static getSetupMessage(providerId, config) {
|
|
65
|
+
switch (providerId) {
|
|
66
|
+
case 'local':
|
|
67
|
+
case 'local-ollama':
|
|
68
|
+
return new LocalOllamaProvider(config?.baseUrl, config?.ollamaModel).getSetupMessage();
|
|
69
|
+
case 'local-browser':
|
|
70
|
+
case 'window-ai':
|
|
71
|
+
return new WindowAiProvider().getSetupMessage();
|
|
72
|
+
case 'byok':
|
|
73
|
+
return 'Enter your Gemini API key below. It will be encrypted and stored solely in your personal storage.';
|
|
74
|
+
case 'cloud':
|
|
75
|
+
return 'Using Qozara Intelligence (Rate-limited).';
|
|
76
|
+
default:
|
|
77
|
+
return null;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
//# sourceMappingURL=AiProviderFactory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AiProviderFactory.js","sourceRoot":"","sources":["../../src/providers/AiProviderFactory.ts"],"names":[],"mappings":"AACA,OAAO,E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Ae,EAAE,CAAC;YACpD,KAAK,MAAM;gBACP,OAAO,mGAAmG,CAAC;YAC/G,KAAK,OAAO;gBACR,OAAO,2CAA2C,CAAC;YACvD;gBACI,OAAO,IAAI,CAAC;QACpB,CAAC;IACL,CAAC;CACJ"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { AiProvider, AgentChatRequest, AgentChatResponse } from './types.js';
|
|
2
|
+
export declare class LocalOllamaProvider implements AiProvider {
|
|
3
|
+
readonly id = "local-ollama";
|
|
4
|
+
readonly mode = "local-ollama";
|
|
5
|
+
private model;
|
|
6
|
+
private base;
|
|
7
|
+
constructor(baseUrl?: string, model?: string);
|
|
8
|
+
chat(request: AgentChatRequest): Promise<AgentChatResponse>;
|
|
9
|
+
checkAvailability(): Promise<boolean>;
|
|
10
|
+
getSetupMessage(): string | null;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=LocalOllamaProvider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LocalOllamaProvider.d.ts","sourceRoot":"","sources":["../../src/providers/LocalOllamaProvider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAE7E,qBAAa,mBAAoB,YAAW,UAAU;IAClD,QAAQ,CAAC,EAAE,kBAAkB;IAC7B,QAAQ,CAAC,IAAI,kBAAkB;IAC/B,OAAO,CAAC,KAAK,CAAS;IACtB,OAAO,CAAC,IAAI,CAAS;gBAGjB,OAAO,GAAE,MAAqC,EAC9C,KAAK,GAAE,MAAuB;IAM5B,IAAI,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,iBAAiB,CAAC;IAqG3D,iBAAiB,IAAI,OAAO,CAAC,OAAO,CAAC;IAa3C,eAAe,IAAI,MAAM,GAAG,IAAI;CAGnC"}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
export class LocalOllamaProvider {
|
|
2
|
+
id = 'local-ollama';
|
|
3
|
+
mode = 'local-ollama';
|
|
4
|
+
model;
|
|
5
|
+
base;
|
|
6
|
+
constructor(baseUrl = 'http://localhost:11434/api', model = 'qwen2.5:0.5b') {
|
|
7
|
+
this.base = (baseUrl || 'http://localhost:11434/api').replace(/\/$/, '');
|
|
8
|
+
this.model = model;
|
|
9
|
+
}
|
|
10
|
+
async chat(request) {
|
|
11
|
+
try {
|
|
12
|
+
const bodyPayload = {
|
|
13
|
+
model: this.model,
|
|
14
|
+
messages: [
|
|
15
|
+
{ role: 'system', content: request.systemPrompt },
|
|
16
|
+
...request.messages
|
|
17
|
+
],
|
|
18
|
+
stream: false
|
|
19
|
+
};
|
|
20
|
+
if (request.tools && request.tools.length > 0) {
|
|
21
|
+
bodyPayload.tools = request.tools.map((t) => ({
|
|
22
|
+
type: 'function',
|
|
23
|
+
function: {
|
|
24
|
+
name: t.name,
|
|
25
|
+
description: t.description,
|
|
26
|
+
parameters: t.parameters
|
|
27
|
+
}
|
|
28
|
+
}));
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
bodyPayload.format = 'json';
|
|
32
|
+
}
|
|
33
|
+
const chatUrl = this.base.endsWith('/api') ? `${this.base}/chat` : `${this.base}/api/chat`;
|
|
34
|
+
const response = await fetch(chatUrl, {
|
|
35
|
+
method: 'POST',
|
|
36
|
+
headers: {
|
|
37
|
+
'Content-Type': 'application/json',
|
|
38
|
+
},
|
|
39
|
+
body: JSON.stringify(bodyPayload)
|
|
40
|
+
});
|
|
41
|
+
if (!response.ok) {
|
|
42
|
+
let errorMsg = `Ollama failed (${response.status})`;
|
|
43
|
+
try {
|
|
44
|
+
const errBody = await response.json();
|
|
45
|
+
if (errBody.error)
|
|
46
|
+
errorMsg += `: ${errBody.error}`;
|
|
47
|
+
}
|
|
48
|
+
catch {
|
|
49
|
+
// Ignore JSON parse error in error handler
|
|
50
|
+
}
|
|
51
|
+
return { type: 'text', error: errorMsg };
|
|
52
|
+
}
|
|
53
|
+
const data = await response.json();
|
|
54
|
+
// Native Ollama tool calling format
|
|
55
|
+
if (data.message?.tool_calls && data.message.tool_calls.length > 0) {
|
|
56
|
+
const call = data.message.tool_calls[0].function;
|
|
57
|
+
return {
|
|
58
|
+
type: 'tool_call',
|
|
59
|
+
tool: call.name,
|
|
60
|
+
arguments: call.arguments
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
const content = data.message?.content || '';
|
|
64
|
+
try {
|
|
65
|
+
const parsed = JSON.parse(content);
|
|
66
|
+
// Pattern 1 & 2: { tool: "name", arguments: { ... } } or { action/type/tool_used: "name", ...args }
|
|
67
|
+
const toolName = parsed.tool || parsed.action || parsed.type || parsed.tool_used;
|
|
68
|
+
if (toolName) {
|
|
69
|
+
const args = parsed.arguments || { ...parsed };
|
|
70
|
+
if (args === parsed) {
|
|
71
|
+
delete args.tool;
|
|
72
|
+
delete args.action;
|
|
73
|
+
delete args.type;
|
|
74
|
+
delete args.tool_used;
|
|
75
|
+
}
|
|
76
|
+
return {
|
|
77
|
+
type: 'tool_call',
|
|
78
|
+
tool: toolName,
|
|
79
|
+
arguments: args
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
// Dynamic Pattern 3: Match root key against any registered tool from request
|
|
83
|
+
const requestedTools = (request.tools || []).map((t) => t.name);
|
|
84
|
+
for (const tool of requestedTools) {
|
|
85
|
+
const key = Object.keys(parsed).find(k => k.toLowerCase() === tool.toLowerCase());
|
|
86
|
+
if (key) {
|
|
87
|
+
return {
|
|
88
|
+
type: 'tool_call',
|
|
89
|
+
tool: tool,
|
|
90
|
+
arguments: parsed[key]
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
return { type: 'text', content };
|
|
95
|
+
}
|
|
96
|
+
catch {
|
|
97
|
+
return { type: 'text', content };
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
catch (error) {
|
|
101
|
+
return { type: 'text', error: error.message || 'Local Ollama error' };
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
async checkAvailability() {
|
|
105
|
+
try {
|
|
106
|
+
const controller = new AbortController();
|
|
107
|
+
const id = setTimeout(() => controller.abort(), 2000);
|
|
108
|
+
const tagsUrl = this.base.endsWith('/api') ? `${this.base}/tags` : `${this.base}/api/tags`;
|
|
109
|
+
const response = await fetch(tagsUrl, { signal: controller.signal });
|
|
110
|
+
clearTimeout(id);
|
|
111
|
+
return response.ok;
|
|
112
|
+
}
|
|
113
|
+
catch {
|
|
114
|
+
return false;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
getSetupMessage() {
|
|
118
|
+
return `Note: Start Ollama with OLLAMA_ORIGINS="*" ollama serve to allow browser connections. Make sure you have pulled the model '${this.model}'.`;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
//# sourceMappingURL=LocalOllamaProvider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LocalOllamaProvider.js","sourceRoot":"","sources":["../../src/providers/LocalOllamaProvider.ts"],"names":[],"mappings":"AAEA,MAAM,OAAO,mBAAmB;IACnB,EAAE,GAAG,cAAc,CAAC;IACpB,IAAI,GAAG,cAAc,CAAC;IACvB,KAAK,CAAS;IACd,IAAI,CAAS;IAErB,YACI,UAAkB,4BAA4B,EAC9C,QAAgB,cAAc;QAE9B,IAAI,CAAC,IAAI,GAAG,CAAC,OAAO,IAAI,4BAA4B,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;QACzE,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACvB,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,OAAyB;QAChC,IAAI,CAAC;YACD,MAAM,WAAW,GAAQ;gBACrB,KAAK,EAAE,IAAI,CAAC,KAAK;gBACjB,QAAQ,EAAE;oBACN,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,OAAO,CAAC,YAAY,EAAE;oBACjD,GAAG,OAAO,CAAC,QAAQ;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AI,CAAC,IAAI,WAAW,CAAC;YAC3F,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,OAAO,EAAE,EAAE,MAAM,EAAE,UAAU,CAAC,MAAM,EAAE,CAAC,CAAC;YACrE,YAAY,CAAC,EAAE,CAAC,CAAC;YACjB,OAAO,QAAQ,CAAC,EAAE,CAAC;QACvB,CAAC;QAAC,MAAM,CAAC;YACL,OAAO,KAAK,CAAC;QACjB,CAAC;IACL,CAAC;IAED,eAAe;QACX,OAAO,8HAA8H,IAAI,CAAC,KAAK,IAAI,CAAC;IACxJ,CAAC;CACJ"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { AiProvider, AgentChatRequest, AgentChatResponse, AuthTokenGetter } from './types.js';
|
|
2
|
+
export declare class ProxyAiProvider implements AiProvider {
|
|
3
|
+
private getAuthToken?;
|
|
4
|
+
private encryptedApiKey?;
|
|
5
|
+
private byokProvider?;
|
|
6
|
+
readonly id = "cloud-proxy";
|
|
7
|
+
private base;
|
|
8
|
+
get mode(): 'byok' | 'cloud';
|
|
9
|
+
constructor(proxyUrl?: string, getAuthToken?: AuthTokenGetter | undefined, encryptedApiKey?: string | undefined, byokProvider?: string | undefined);
|
|
10
|
+
chat(request: AgentChatRequest): Promise<AgentChatResponse>;
|
|
11
|
+
checkAvailability(): Promise<boolean>;
|
|
12
|
+
getSetupMessage(): string | null;
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=ProxyAiProvider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ProxyAiProvider.d.ts","sourceRoot":"","sources":["../../src/providers/ProxyAiProvider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAE9F,qBAAa,eAAgB,YAAW,UAAU;IAU1C,OAAO,CAAC,YAAY,CAAC;IACrB,OAAO,CAAC,eAAe,CAAC;IACxB,OAAO,CAAC,YAAY,CAAC;IAXzB,QAAQ,CAAC,EAAE,iBAAiB;IAC5B,OAAO,CAAC,IAAI,CAAS;IAErB,IAAI,IAAI,IAAI,MAAM,GAAG,OAAO,CAE3B;gBAGG,QAAQ,GAAE,MAAW,EACb,YAAY,CAAC,EAAE,eAAe,YAAA,EAC9B,eAAe,CAAC,EAAE,MAAM,YAAA,EACxB,YAAY,CAAC,EAAE,MAAM,YAAA;IAK3B,IAAI,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,iBAAiB,CAAC;IAuC3D,iBAAiB,IAAI,OAAO,CAAC,OAAO,CAAC;IAa3C,eAAe,IAAI,MAAM,GAAG,IAAI;CAGnC"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
export class ProxyAiProvider {
|
|
2
|
+
getAuthToken;
|
|
3
|
+
encryptedApiKey;
|
|
4
|
+
byokProvider;
|
|
5
|
+
id = 'cloud-proxy';
|
|
6
|
+
base;
|
|
7
|
+
get mode() {
|
|
8
|
+
return this.encryptedApiKey ? 'byok' : 'cloud';
|
|
9
|
+
}
|
|
10
|
+
constructor(proxyUrl = '', getAuthToken, encryptedApiKey, byokProvider) {
|
|
11
|
+
this.getAuthToken = getAuthToken;
|
|
12
|
+
this.encryptedApiKey = encryptedApiKey;
|
|
13
|
+
this.byokProvider = byokProvider;
|
|
14
|
+
this.base = (proxyUrl || '').replace(/\/$/, '');
|
|
15
|
+
}
|
|
16
|
+
async chat(request) {
|
|
17
|
+
try {
|
|
18
|
+
const headers = {
|
|
19
|
+
'Content-Type': 'application/json',
|
|
20
|
+
};
|
|
21
|
+
if (this.getAuthToken) {
|
|
22
|
+
const token = await this.getAuthToken();
|
|
23
|
+
if (token) {
|
|
24
|
+
headers['Authorization'] = `Bearer ${token}`;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
const response = await fetch(`${this.base}/api/v1/agent/chat`, {
|
|
28
|
+
method: 'POST',
|
|
29
|
+
headers,
|
|
30
|
+
body: JSON.stringify({
|
|
31
|
+
messages: request.messages,
|
|
32
|
+
systemPrompt: request.systemPrompt,
|
|
33
|
+
tools: request.tools,
|
|
34
|
+
ciphertext: this.encryptedApiKey,
|
|
35
|
+
byokProvider: this.byokProvider,
|
|
36
|
+
}),
|
|
37
|
+
});
|
|
38
|
+
if (!response.ok) {
|
|
39
|
+
const error = await response.json().catch(() => ({}));
|
|
40
|
+
return {
|
|
41
|
+
type: 'text',
|
|
42
|
+
error: error.code || error.message || error.error || `Proxy request failed (${response.status})`,
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
return await response.json();
|
|
46
|
+
}
|
|
47
|
+
catch (error) {
|
|
48
|
+
return { type: 'text', error: error.message || 'Network error communicating with AI proxy' };
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
async checkAvailability() {
|
|
52
|
+
if (!this.base)
|
|
53
|
+
return false;
|
|
54
|
+
try {
|
|
55
|
+
const controller = new AbortController();
|
|
56
|
+
const id = setTimeout(() => controller.abort(), 3000);
|
|
57
|
+
const response = await fetch(`${this.base}/health`, { signal: controller.signal });
|
|
58
|
+
clearTimeout(id);
|
|
59
|
+
return response.ok;
|
|
60
|
+
}
|
|
61
|
+
catch {
|
|
62
|
+
return false;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
getSetupMessage() {
|
|
66
|
+
return null;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
//# sourceMappingURL=ProxyAiProvider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ProxyAiProvider.js","sourceRoot":"","sources":["../../src/providers/ProxyAiProvider.ts"],"names":[],"mappings":"AAEA,MAAM,OAAO,eAAe;IAUZ;IACA;IACA;IAXH,EAAE,GAAG,aAAa,CAAC;IACpB,IAAI,CAAS;IAErB,IAAI,IAAI;QACJ,OAAO,IAAI,CAAC,eAAe,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC;IACnD,CAAC;IA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AAK,CAAC,IAAI,IAAI,KAAK,CAAC,OAAO,IAAI,KAAK,CAAC,KAAK,IAAI,yBAAyB,QAAQ,CAAC,MAAM,GAAG;iBACnG,CAAC;YACN,CAAC;YAED,OAAO,MAAM,QAAQ,CAAC,IAAI,EAAuB,CAAC;QACtD,CAAC;QAAC,OAAO,KAAU,EAAE,CAAC;YAClB,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,CAAC,OAAO,IAAI,2CAA2C,EAAE,CAAC;QACjG,CAAC;IACL,CAAC;IAED,KAAK,CAAC,iBAAiB;QACnB,IAAI,CAAC,IAAI,CAAC,IAAI;YAAE,OAAO,KAAK,CAAC;QAC7B,IAAI,CAAC;YACD,MAAM,UAAU,GAAG,IAAI,eAAe,EAAE,CAAC;YACzC,MAAM,EAAE,GAAG,UAAU,CAAC,GAAG,EAAE,CAAC,UAAU,CAAC,KAAK,EAAE,EAAE,IAAI,CAAC,CAAC;YACtD,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,IAAI,CAAC,IAAI,SAAS,EAAE,EAAE,MAAM,EAAE,UAAU,CAAC,MAAM,EAAE,CAAC,CAAC;YACnF,YAAY,CAAC,EAAE,CAAC,CAAC;YACjB,OAAO,QAAQ,CAAC,EAAE,CAAC;QACvB,CAAC;QAAC,MAAM,CAAC;YACL,OAAO,KAAK,CAAC;QACjB,CAAC;IACL,CAAC;IAED,eAAe;QACX,OAAO,IAAI,CAAC;IAChB,CAAC;CACJ"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { AiProvider, AgentChatRequest, AgentChatResponse } from './types.js';
|
|
2
|
+
export declare class WindowAiProvider implements AiProvider {
|
|
3
|
+
readonly id = "window-ai";
|
|
4
|
+
readonly mode = "local-browser";
|
|
5
|
+
chat(request: AgentChatRequest): Promise<AgentChatResponse>;
|
|
6
|
+
checkAvailability(): Promise<boolean>;
|
|
7
|
+
getSetupMessage(): string | null;
|
|
8
|
+
private isSupported;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=WindowAiProvider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"WindowAiProvider.d.ts","sourceRoot":"","sources":["../../src/providers/WindowAiProvider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAE7E,qBAAa,gBAAiB,YAAW,UAAU;IAC/C,QAAQ,CAAC,EAAE,eAAe;IAC1B,QAAQ,CAAC,IAAI,mBAAmB;IAE1B,IAAI,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,iBAAiB,CAAC;IAgD3D,iBAAiB,IAAI,OAAO,CAAC,OAAO,CAAC;IAU3C,eAAe,IAAI,MAAM,GAAG,IAAI;IAKhC,OAAO,CAAC,WAAW;CAGtB"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
export class WindowAiProvider {
|
|
2
|
+
id = 'window-ai';
|
|
3
|
+
mode = 'local-browser';
|
|
4
|
+
async chat(request) {
|
|
5
|
+
try {
|
|
6
|
+
if (!this.isSupported()) {
|
|
7
|
+
return { type: 'text', error: 'window.ai not supported' };
|
|
8
|
+
}
|
|
9
|
+
const capabilities = await globalThis.window?.ai.languageModel.capabilities();
|
|
10
|
+
if (capabilities.available !== 'readily') {
|
|
11
|
+
return { type: 'text', error: 'window.ai model not ready' };
|
|
12
|
+
}
|
|
13
|
+
const session = await globalThis.window?.ai.languageModel.create({
|
|
14
|
+
systemPrompt: request.systemPrompt
|
|
15
|
+
});
|
|
16
|
+
const prompt = request.messages.map(m => `${m.role === 'user' ? 'User' : 'Assistant'}: ${m.content}`).join('\n') + '\nAssistant:';
|
|
17
|
+
const response = await session.prompt(prompt);
|
|
18
|
+
session.destroy();
|
|
19
|
+
let cleanResponse = response.trim();
|
|
20
|
+
if (cleanResponse.includes('```json')) {
|
|
21
|
+
cleanResponse = cleanResponse.split('```json')[1].split('```')[0].trim();
|
|
22
|
+
}
|
|
23
|
+
else if (cleanResponse.includes('```')) {
|
|
24
|
+
cleanResponse = cleanResponse.split('```')[1].split('```')[0].trim();
|
|
25
|
+
}
|
|
26
|
+
try {
|
|
27
|
+
const parsed = JSON.parse(cleanResponse);
|
|
28
|
+
if (parsed.tool && parsed.arguments) {
|
|
29
|
+
return {
|
|
30
|
+
type: 'tool_call',
|
|
31
|
+
tool: parsed.tool,
|
|
32
|
+
arguments: parsed.arguments
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
if (parsed.type === 'tool_call') {
|
|
36
|
+
return parsed;
|
|
37
|
+
}
|
|
38
|
+
return { type: 'text', content: response };
|
|
39
|
+
}
|
|
40
|
+
catch {
|
|
41
|
+
return { type: 'text', content: response };
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
catch (error) {
|
|
45
|
+
return { type: 'text', error: error.message || 'Window AI error' };
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
async checkAvailability() {
|
|
49
|
+
if (!this.isSupported())
|
|
50
|
+
return false;
|
|
51
|
+
try {
|
|
52
|
+
const capabilities = await globalThis.window?.ai.languageModel.capabilities();
|
|
53
|
+
return capabilities.available === 'readily';
|
|
54
|
+
}
|
|
55
|
+
catch {
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
getSetupMessage() {
|
|
60
|
+
if (this.isSupported())
|
|
61
|
+
return null;
|
|
62
|
+
return "To enable Local Browser AI: 1. Use Chrome Dev/Canary. 2. Enable 'Prompt API for Gemini Nano' in chrome://flags. 3. Enable 'Enables optimization guide on device' in chrome://flags. 4. Relaunch and wait for model download in chrome://components.";
|
|
63
|
+
}
|
|
64
|
+
isSupported() {
|
|
65
|
+
return typeof globalThis !== 'undefined' && !!globalThis.window?.ai?.languageModel;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
//# sourceMappingURL=WindowAiProvider.js.map
|
|
@@ -0,0 +1 @@
|
|
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YACD,MAAM,YAAY,GAAG,MAAO,UAAkB,CAAC,MAAM,EAAE,EAAE,CAAC,aAAa,CAAC,YAAY,EAAE,CAAC;YACvF,OAAO,YAAY,CAAC,SAAS,KAAK,SAAS,CAAC;QAChD,CAAC;QAAC,MAAM,CAAC;YACL,OAAO,KAAK,CAAC;QACjB,CAAC;IACL,CAAC;IAED,eAAe;QACX,IAAI,IAAI,CAAC,WAAW,EAAE;YAAE,OAAO,IAAI,CAAC;QACpC,OAAO,qPAAqP,CAAC;IACjQ,CAAC;IAEO,WAAW;QACf,OAAO,OAAO,UAAU,KAAK,WAAW,IAAI,CAAC,CAAE,UAAkB,CAAC,MAAM,EAAE,EAAE,EAAE,aAAa,CAAC;IAChG,CAAC;CACJ"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
export interface AgentChatMessage {
|
|
2
|
+
role: string;
|
|
3
|
+
content: string;
|
|
4
|
+
}
|
|
5
|
+
export interface AgentChatTool {
|
|
6
|
+
name: string;
|
|
7
|
+
description: string;
|
|
8
|
+
parameters: any;
|
|
9
|
+
}
|
|
10
|
+
export interface AgentChatRequest {
|
|
11
|
+
messages: AgentChatMessage[];
|
|
12
|
+
systemPrompt?: string;
|
|
13
|
+
tools?: AgentChatTool[] | any[];
|
|
14
|
+
}
|
|
15
|
+
export interface AgentChatResponse {
|
|
16
|
+
type: 'text' | 'tool_call';
|
|
17
|
+
content?: string;
|
|
18
|
+
tool?: string;
|
|
19
|
+
arguments?: any;
|
|
20
|
+
error?: string;
|
|
21
|
+
}
|
|
22
|
+
export interface AiProvider {
|
|
23
|
+
readonly id: string;
|
|
24
|
+
readonly mode: 'byok' | 'cloud' | 'local-browser' | 'local-ollama' | 'disabled';
|
|
25
|
+
chat(request: AgentChatRequest): Promise<AgentChatResponse>;
|
|
26
|
+
checkAvailability(): Promise<boolean>;
|
|
27
|
+
getSetupMessage(): string | null;
|
|
28
|
+
}
|
|
29
|
+
export interface AiFactoryConfig {
|
|
30
|
+
providerPreference: 'auto' | 'byok' | 'local' | 'local-browser' | 'cloud' | 'disabled';
|
|
31
|
+
encryptedApiKey?: string;
|
|
32
|
+
baseUrl?: string;
|
|
33
|
+
proxyUrl?: string;
|
|
34
|
+
ollamaModel?: string;
|
|
35
|
+
byokProvider?: string;
|
|
36
|
+
}
|
|
37
|
+
export type AuthTokenGetter = () => string | null | undefined | Promise<string | null | undefined>;
|
|
38
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/providers/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,gBAAgB;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,aAAa;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,GAAG,CAAC;CACnB;AAED,MAAM,WAAW,gBAAgB;IAC7B,QAAQ,EAAE,gBAAgB,EAAE,CAAC;IAC7B,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,KAAK,CAAC,EAAE,aAAa,EAAE,GAAG,GAAG,EAAE,CAAC;CACnC;AAED,MAAM,WAAW,iBAAiB;IAC9B,IAAI,EAAE,MAAM,GAAG,WAAW,CAAC;IAC3B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,EAAE,GAAG,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,UAAU;IACvB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,GAAG,eAAe,GAAG,cAAc,GAAG,UAAU,CAAC;IAChF,IAAI,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAAC;IAC5D,iBAAiB,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC;IACtC,eAAe,IAAI,MAAM,GAAG,IAAI,CAAC;CACpC;AAED,MAAM,WAAW,eAAe;IAC5B,kBAAkB,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,eAAe,GAAG,OAAO,GAAG,UAAU,CAAC;IACvF,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,YAAY,CAAC,EAAE,MAAM,CAAC;CACzB;AAED,MAAM,MAAM,eAAe,GAAG,MAAM,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/providers/types.ts"],"names":[],"mappings":""}
|
package/package.json
CHANGED
|
@@ -1,6 +1,38 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@qozara/ai-client",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Isomorphic AI client SDK for Qozara ecosystem with polymorphic fallback and KMS envelope encryption support",
|
|
5
|
+
"files": [
|
|
6
|
+
"dist"
|
|
7
|
+
],
|
|
8
|
+
"publishConfig": {
|
|
9
|
+
"access": "public"
|
|
10
|
+
},
|
|
11
|
+
"repository": {
|
|
12
|
+
"type": "git",
|
|
13
|
+
"url": "git+https://github.com/qozara/ai-proxy.git",
|
|
14
|
+
"directory": "packages/client"
|
|
15
|
+
},
|
|
16
|
+
"type": "module",
|
|
17
|
+
"main": "./dist/index.js",
|
|
18
|
+
"module": "./dist/index.js",
|
|
19
|
+
"types": "./dist/index.d.ts",
|
|
20
|
+
"exports": {
|
|
21
|
+
".": {
|
|
22
|
+
"types": "./dist/index.d.ts",
|
|
23
|
+
"import": "./dist/index.js",
|
|
24
|
+
"default": "./dist/index.js"
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
"scripts": {
|
|
28
|
+
"build": "tsup src/index.ts --format esm --dts",
|
|
29
|
+
"dev": "tsup src/index.ts --format esm --watch --dts",
|
|
30
|
+
"test": "vitest run",
|
|
31
|
+
"check": "tsc --noEmit"
|
|
32
|
+
},
|
|
33
|
+
"devDependencies": {
|
|
34
|
+
"tsup": "^8.3.0",
|
|
35
|
+
"typescript": "5.6.3",
|
|
36
|
+
"vitest": "^4.1.11"
|
|
37
|
+
}
|
|
38
|
+
}
|
package/README.md
DELETED