ai.matey.frontend 0.2.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/LICENSE +21 -0
- package/dist/cjs/adapters/anthropic.js +328 -0
- package/dist/cjs/adapters/anthropic.js.map +1 -0
- package/dist/cjs/adapters/chrome-ai.js +55 -0
- package/dist/cjs/adapters/chrome-ai.js.map +1 -0
- package/dist/cjs/adapters/gemini.js +95 -0
- package/dist/cjs/adapters/gemini.js.map +1 -0
- package/dist/cjs/adapters/generic.js +165 -0
- package/dist/cjs/adapters/generic.js.map +1 -0
- package/dist/cjs/adapters/mistral.js +87 -0
- package/dist/cjs/adapters/mistral.js.map +1 -0
- package/dist/cjs/adapters/ollama.js +73 -0
- package/dist/cjs/adapters/ollama.js.map +1 -0
- package/dist/cjs/adapters/openai.js +287 -0
- package/dist/cjs/adapters/openai.js.map +1 -0
- package/dist/cjs/index.js +34 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/esm/adapters/anthropic.js +324 -0
- package/dist/esm/adapters/anthropic.js.map +1 -0
- package/dist/esm/adapters/chrome-ai.js +51 -0
- package/dist/esm/adapters/chrome-ai.js.map +1 -0
- package/dist/esm/adapters/gemini.js +91 -0
- package/dist/esm/adapters/gemini.js.map +1 -0
- package/dist/esm/adapters/generic.js +160 -0
- package/dist/esm/adapters/generic.js.map +1 -0
- package/dist/esm/adapters/mistral.js +83 -0
- package/dist/esm/adapters/mistral.js.map +1 -0
- package/dist/esm/adapters/ollama.js +69 -0
- package/dist/esm/adapters/ollama.js.map +1 -0
- package/dist/esm/adapters/openai.js +283 -0
- package/dist/esm/adapters/openai.js.map +1 -0
- package/dist/esm/index.js +18 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/types/adapters/anthropic.d.ts +149 -0
- package/dist/types/adapters/anthropic.d.ts.map +1 -0
- package/dist/types/adapters/chrome-ai.d.ts +25 -0
- package/dist/types/adapters/chrome-ai.d.ts.map +1 -0
- package/dist/types/adapters/gemini.d.ts +55 -0
- package/dist/types/adapters/gemini.d.ts.map +1 -0
- package/dist/types/adapters/generic.d.ts +122 -0
- package/dist/types/adapters/generic.d.ts.map +1 -0
- package/dist/types/adapters/mistral.d.ts +47 -0
- package/dist/types/adapters/mistral.d.ts.map +1 -0
- package/dist/types/adapters/ollama.d.ts +44 -0
- package/dist/types/adapters/ollama.d.ts.map +1 -0
- package/dist/types/adapters/openai.d.ts +116 -0
- package/dist/types/adapters/openai.d.ts.map +1 -0
- package/dist/types/index.d.ts +17 -0
- package/dist/types/index.d.ts.map +1 -0
- package/package.json +144 -0
- package/readme.md +62 -0
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Gemini Frontend Adapter
|
|
3
|
+
*
|
|
4
|
+
* Adapts Google Gemini API format to Universal IR.
|
|
5
|
+
* Handles Gemini's systemInstruction field and content array format.
|
|
6
|
+
*
|
|
7
|
+
* @module
|
|
8
|
+
*/
|
|
9
|
+
import type { FrontendAdapter, AdapterMetadata } from 'ai.matey.types';
|
|
10
|
+
import type { IRChatRequest, IRChatResponse, IRStreamChunk } from 'ai.matey.types';
|
|
11
|
+
import type { StreamConversionOptions } from 'ai.matey.types';
|
|
12
|
+
export interface GeminiContent {
|
|
13
|
+
role: 'user' | 'model';
|
|
14
|
+
parts: Array<{
|
|
15
|
+
text: string;
|
|
16
|
+
} | {
|
|
17
|
+
inlineData: {
|
|
18
|
+
mimeType: string;
|
|
19
|
+
data: string;
|
|
20
|
+
};
|
|
21
|
+
}>;
|
|
22
|
+
}
|
|
23
|
+
export interface GeminiRequest {
|
|
24
|
+
contents: GeminiContent[];
|
|
25
|
+
systemInstruction?: {
|
|
26
|
+
parts: Array<{
|
|
27
|
+
text: string;
|
|
28
|
+
}>;
|
|
29
|
+
};
|
|
30
|
+
generationConfig?: {
|
|
31
|
+
temperature?: number;
|
|
32
|
+
topP?: number;
|
|
33
|
+
topK?: number;
|
|
34
|
+
maxOutputTokens?: number;
|
|
35
|
+
stopSequences?: string[];
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
export interface GeminiResponse {
|
|
39
|
+
candidates: Array<{
|
|
40
|
+
content: GeminiContent;
|
|
41
|
+
finishReason: 'STOP' | 'MAX_TOKENS' | 'SAFETY' | 'RECITATION' | 'OTHER';
|
|
42
|
+
}>;
|
|
43
|
+
usageMetadata?: {
|
|
44
|
+
promptTokenCount: number;
|
|
45
|
+
candidatesTokenCount: number;
|
|
46
|
+
totalTokenCount: number;
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
export declare class GeminiFrontendAdapter implements FrontendAdapter<GeminiRequest, GeminiResponse> {
|
|
50
|
+
readonly metadata: AdapterMetadata;
|
|
51
|
+
toIR(request: GeminiRequest): Promise<IRChatRequest>;
|
|
52
|
+
fromIR(response: IRChatResponse): Promise<GeminiResponse>;
|
|
53
|
+
fromIRStream(stream: AsyncGenerator<IRStreamChunk>, _options?: StreamConversionOptions): AsyncGenerator<string>;
|
|
54
|
+
}
|
|
55
|
+
//# sourceMappingURL=gemini.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gemini.d.ts","sourceRoot":"","sources":["../../../src/adapters/gemini.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACvE,OAAO,KAAK,EAAE,aAAa,EAAE,cAAc,EAAE,aAAa,EAAa,MAAM,gBAAgB,CAAC;AAC9F,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,gBAAgB,CAAC;AAM9D,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC;IACvB,KAAK,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,GAAG;QAAE,UAAU,EAAE;YAAE,QAAQ,EAAE,MAAM,CAAC;YAAC,IAAI,EAAE,MAAM,CAAA;SAAE,CAA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end adapter that accepts and returns IR format directly.
|
|
5
|
+
* Use this when you want to work with the universal IR format without
|
|
6
|
+
* any provider-specific conversions.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* import { GenericFrontendAdapter } from 'ai.matey.frontend/generic';
|
|
11
|
+
* import { Bridge } from 'ai.matey.core';
|
|
12
|
+
*
|
|
13
|
+
* const frontend = new GenericFrontendAdapter();
|
|
14
|
+
* const bridge = new Bridge(frontend, backend);
|
|
15
|
+
*
|
|
16
|
+
* // Request and response are both in IR format
|
|
17
|
+
* const response = await bridge.chat({
|
|
18
|
+
* messages: [{ role: 'user', content: 'Hello!' }],
|
|
19
|
+
* parameters: { model: 'gpt-4' },
|
|
20
|
+
* metadata: { requestId: 'req_123', timestamp: Date.now(), provenance: {} },
|
|
21
|
+
* });
|
|
22
|
+
* ```
|
|
23
|
+
*
|
|
24
|
+
* @module
|
|
25
|
+
*/
|
|
26
|
+
import type { FrontendAdapter, AdapterMetadata } from 'ai.matey.types';
|
|
27
|
+
import type { IRChatRequest, IRChatResponse, IRChatStream, IRStreamChunk, StreamConversionOptions } from 'ai.matey.types';
|
|
28
|
+
/**
|
|
29
|
+
* Configuration options for the Generic Frontend Adapter.
|
|
30
|
+
*/
|
|
31
|
+
export interface GenericFrontendConfig {
|
|
32
|
+
/**
|
|
33
|
+
* Custom adapter name for provenance tracking.
|
|
34
|
+
* @default 'generic-frontend'
|
|
35
|
+
*/
|
|
36
|
+
readonly name?: string;
|
|
37
|
+
/**
|
|
38
|
+
* Whether to validate requests before passing through.
|
|
39
|
+
* @default false
|
|
40
|
+
*/
|
|
41
|
+
readonly validateRequests?: boolean;
|
|
42
|
+
/**
|
|
43
|
+
* Whether to add/update provenance information.
|
|
44
|
+
* @default true
|
|
45
|
+
*/
|
|
46
|
+
readonly trackProvenance?: boolean;
|
|
47
|
+
/**
|
|
48
|
+
* Maximum context tokens (for capability reporting).
|
|
49
|
+
* @default undefined (unlimited)
|
|
50
|
+
*/
|
|
51
|
+
readonly maxContextTokens?: number;
|
|
52
|
+
/**
|
|
53
|
+
* Supported models (for capability reporting).
|
|
54
|
+
*/
|
|
55
|
+
readonly supportedModels?: readonly string[];
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Passthrough frontend adapter for IR format.
|
|
59
|
+
*
|
|
60
|
+
* This adapter accepts IR requests directly and returns IR responses without
|
|
61
|
+
* any conversion. It's useful for:
|
|
62
|
+
*
|
|
63
|
+
* - **Direct IR access**: Work with the universal format without provider wrappers
|
|
64
|
+
* - **Testing**: Test bridges and backends without conversion overhead
|
|
65
|
+
* - **Custom integrations**: Build tools that operate at the IR level
|
|
66
|
+
* - **Format normalization**: Use when your application already produces IR
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* ```typescript
|
|
70
|
+
* // Basic usage
|
|
71
|
+
* const frontend = new GenericFrontendAdapter();
|
|
72
|
+
*
|
|
73
|
+
* // With custom configuration
|
|
74
|
+
* const frontend = new GenericFrontendAdapter({
|
|
75
|
+
* name: 'my-app-frontend',
|
|
76
|
+
* trackProvenance: true,
|
|
77
|
+
* maxContextTokens: 128000,
|
|
78
|
+
* });
|
|
79
|
+
* ```
|
|
80
|
+
*/
|
|
81
|
+
export declare class GenericFrontendAdapter implements FrontendAdapter<IRChatRequest, IRChatResponse, IRStreamChunk> {
|
|
82
|
+
readonly metadata: AdapterMetadata;
|
|
83
|
+
private readonly config;
|
|
84
|
+
constructor(config?: GenericFrontendConfig);
|
|
85
|
+
/**
|
|
86
|
+
* Pass through IR request (no conversion needed).
|
|
87
|
+
*
|
|
88
|
+
* Optionally adds provenance tracking if enabled.
|
|
89
|
+
*/
|
|
90
|
+
toIR(request: IRChatRequest): Promise<IRChatRequest>;
|
|
91
|
+
/**
|
|
92
|
+
* Pass through IR response (no conversion needed).
|
|
93
|
+
*/
|
|
94
|
+
fromIR(response: IRChatResponse): Promise<IRChatResponse>;
|
|
95
|
+
/**
|
|
96
|
+
* Pass through IR stream chunks (no conversion needed).
|
|
97
|
+
*/
|
|
98
|
+
fromIRStream(stream: IRChatStream, _options?: StreamConversionOptions): AsyncGenerator<IRStreamChunk, void, undefined>;
|
|
99
|
+
/**
|
|
100
|
+
* Validate IR request structure.
|
|
101
|
+
*
|
|
102
|
+
* Only performs validation if `validateRequests` is enabled in config.
|
|
103
|
+
*/
|
|
104
|
+
validate(request: IRChatRequest): Promise<void>;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Create a new Generic Frontend Adapter instance.
|
|
108
|
+
*
|
|
109
|
+
* @example
|
|
110
|
+
* ```typescript
|
|
111
|
+
* const frontend = createGenericFrontend();
|
|
112
|
+
*
|
|
113
|
+
* // Or with configuration
|
|
114
|
+
* const frontend = createGenericFrontend({
|
|
115
|
+
* name: 'my-frontend',
|
|
116
|
+
* trackProvenance: true,
|
|
117
|
+
* });
|
|
118
|
+
* ```
|
|
119
|
+
*/
|
|
120
|
+
export declare function createGenericFrontend(config?: GenericFrontendConfig): GenericFrontendAdapter;
|
|
121
|
+
export default GenericFrontendAdapter;
|
|
122
|
+
//# sourceMappingURL=generic.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generic.d.ts","sourceRoot":"","sources":["../../../src/adapters/generic.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACvE,OAAO,KAAK,EACV,aAAa,EACb,cAAc,EACd,YAAY,EACZ,aAAa,EACb,uBAAuB,EACxB,MAAM,gBAAgB,CAAC;AAMxB;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC;;;OAGG;IACH,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IAEvB;;;OAGG;IACH,QAAQ,CAAC,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAEpC;;;OAGG;IACH,QAAQ,CAAC,eAAe,CAAC,EAAE,OAAO,CAAC;IAEnC;;;OAGG;IACH,QAAQ,CAAC,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAEnC;;OAEG;IACH,QAAQ,CAAC,eAAe,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;CAC9C;AAMD;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,qBAAa,sBAAuB,YAAW,eAAe,CAC5D,aAAa,EACb,cAAc,EACd,aAAa,CACd;IACC,QAAQ,CAAC,QAAQ,EAAE,eAAe,CAAC;IACnC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAwB;gBAEnC,MAAM,GAAE,qBAA0B;IAyB9C;;;;OAIG;IACH,IAAI,CAAC,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,aAAa,CAAC;IAkBpD;;OAEG;IACH,MAAM,CAAC,QAAQ,EAAE,cAAc,GAAG,OAAO,CAAC,cAAc,CAAC;IAIzD;;OAEG;IACI,YAAY,CACjB,MAAM,EAAE,YAAY,EACpB,QAAQ,CAAC,EAAE,uBAAuB,GACjC,cAAc,CAAC,aAAa,EAAE,IAAI,EAAE,SAAS,CAAC;IAMjD;;;;OAIG;IACH,QAAQ,CAAC,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC;CAoBhD;AAMD;;;;;;;;;;;;;GAaG;AACH,wBAAgB,qBAAqB,CAAC,MAAM,CAAC,EAAE,qBAAqB,GAAG,sBAAsB,CAE5F;AAMD,eAAe,sBAAsB,CAAC"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Mistral Frontend Adapter
|
|
3
|
+
*
|
|
4
|
+
* Pass-through adapter for Mistral format.
|
|
5
|
+
*
|
|
6
|
+
* @module
|
|
7
|
+
*/
|
|
8
|
+
import type { FrontendAdapter, AdapterMetadata } from 'ai.matey.types';
|
|
9
|
+
import type { IRChatRequest, IRChatResponse, IRStreamChunk } from 'ai.matey.types';
|
|
10
|
+
import type { StreamConversionOptions } from 'ai.matey.types';
|
|
11
|
+
export interface MistralMessage {
|
|
12
|
+
role: 'system' | 'user' | 'assistant';
|
|
13
|
+
content: string;
|
|
14
|
+
}
|
|
15
|
+
export interface MistralRequest {
|
|
16
|
+
model: string;
|
|
17
|
+
messages: MistralMessage[];
|
|
18
|
+
temperature?: number;
|
|
19
|
+
max_tokens?: number;
|
|
20
|
+
top_p?: number;
|
|
21
|
+
stream?: boolean;
|
|
22
|
+
safe_mode?: boolean;
|
|
23
|
+
random_seed?: number;
|
|
24
|
+
}
|
|
25
|
+
export interface MistralResponse {
|
|
26
|
+
id: string;
|
|
27
|
+
object: 'chat.completion';
|
|
28
|
+
created: number;
|
|
29
|
+
model: string;
|
|
30
|
+
choices: Array<{
|
|
31
|
+
index: number;
|
|
32
|
+
message: MistralMessage;
|
|
33
|
+
finish_reason: 'stop' | 'length' | 'model_length' | null;
|
|
34
|
+
}>;
|
|
35
|
+
usage: {
|
|
36
|
+
prompt_tokens: number;
|
|
37
|
+
completion_tokens: number;
|
|
38
|
+
total_tokens: number;
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
export declare class MistralFrontendAdapter implements FrontendAdapter<MistralRequest, MistralResponse> {
|
|
42
|
+
readonly metadata: AdapterMetadata;
|
|
43
|
+
toIR(request: MistralRequest): Promise<IRChatRequest>;
|
|
44
|
+
fromIR(response: IRChatResponse): Promise<MistralResponse>;
|
|
45
|
+
fromIRStream(stream: AsyncGenerator<IRStreamChunk>, _options?: StreamConversionOptions): AsyncGenerator<string>;
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=mistral.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mistral.d.ts","sourceRoot":"","sources":["../../../src/adapters/mistral.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACvE,OAAO,KAAK,EAAE,aAAa,EAAE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BnD,YAAY,CACjB,MAAM,EAAE,cAAc,CAAC,aAAa,CAAC,EACrC,QAAQ,CAAC,EAAE,uBAAuB,GACjC,cAAc,CAAC,MAAM,CAAC;CAS1B"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Ollama Frontend Adapter
|
|
3
|
+
*
|
|
4
|
+
* Adapts Ollama API format to Universal IR.
|
|
5
|
+
* Ollama uses a local server with OpenAI-compatible chat format.
|
|
6
|
+
*
|
|
7
|
+
* @module
|
|
8
|
+
*/
|
|
9
|
+
import type { FrontendAdapter, AdapterMetadata } from 'ai.matey.types';
|
|
10
|
+
import type { IRChatRequest, IRChatResponse, IRStreamChunk } from 'ai.matey.types';
|
|
11
|
+
import type { StreamConversionOptions } from 'ai.matey.types';
|
|
12
|
+
export interface OllamaMessage {
|
|
13
|
+
role: 'system' | 'user' | 'assistant';
|
|
14
|
+
content: string;
|
|
15
|
+
}
|
|
16
|
+
export interface OllamaRequest {
|
|
17
|
+
model: string;
|
|
18
|
+
messages: OllamaMessage[];
|
|
19
|
+
options?: {
|
|
20
|
+
temperature?: number;
|
|
21
|
+
top_p?: number;
|
|
22
|
+
top_k?: number;
|
|
23
|
+
num_predict?: number;
|
|
24
|
+
stop?: string[];
|
|
25
|
+
};
|
|
26
|
+
stream?: boolean;
|
|
27
|
+
}
|
|
28
|
+
export interface OllamaResponse {
|
|
29
|
+
model: string;
|
|
30
|
+
created_at: string;
|
|
31
|
+
message: OllamaMessage;
|
|
32
|
+
done: boolean;
|
|
33
|
+
total_duration?: number;
|
|
34
|
+
load_duration?: number;
|
|
35
|
+
prompt_eval_count?: number;
|
|
36
|
+
eval_count?: number;
|
|
37
|
+
}
|
|
38
|
+
export declare class OllamaFrontendAdapter implements FrontendAdapter<OllamaRequest, OllamaResponse> {
|
|
39
|
+
readonly metadata: AdapterMetadata;
|
|
40
|
+
toIR(request: OllamaRequest): Promise<IRChatRequest>;
|
|
41
|
+
fromIR(response: IRChatResponse): Promise<OllamaResponse>;
|
|
42
|
+
fromIRStream(stream: AsyncGenerator<IRStreamChunk>, _options?: StreamConversionOptions): AsyncGenerator<string>;
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=ollama.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ollama.d.ts","sourceRoot":"","sources":["../../../src/adapters/ollama.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACvE,OAAO,KAAK,EAAE,aAAa,EAAE,cAAc,EAAE,aAAa,EAAa,MAAM,gBAAgB,CAAC;AAC9F,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,gBAAgB,CAAC;AAM9D,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,QAAQ,GAAG,MAAM,GAAG,WAAW,CAAC;IACtC,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,aAAa;IAC5B,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,aAAa,EAAE,CAAC;IAC1B,OAAO,CAAC,EAAE;QACR,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;KACjB,CAAC;IACF,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB;AAED,MAAM,WAAW,cAAc;IAC7B,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,aAAa,CAAC;IACvB,IAAI,EAAE,OAAO,CAAC;IACd,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,qBAAa,qBAAsB,YAAW,eAAe,CAAC,aAAa,EAAE,cAAc,CAAC;IAC1F,QAAQ,CAAC,QAAQ,EAAE,eAAe,CAWhC;IAEF,IAAI,CAAC,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,aAAa,CAAC;IAyBpD,MAAM,CAAC,QAAQ,EAAE,cAAc,GAAG,OAAO,CAAC,cAAc,CAAC;IAclD,YAAY,CACjB,MAAM,EAAE,cAAc,CAAC,aAAa,CAAC,EACrC,QAAQ,CAAC,EAAE,uBAAuB,GACjC,cAAc,CAAC,MAAM,CAAC;CAS1B"}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OpenAI Frontend Adapter
|
|
3
|
+
*
|
|
4
|
+
* Adapts OpenAI Chat Completions API format to Universal IR.
|
|
5
|
+
* Since OpenAI format is similar to IR, this is mostly a pass-through adapter.
|
|
6
|
+
*
|
|
7
|
+
* @module
|
|
8
|
+
*/
|
|
9
|
+
import type { FrontendAdapter, AdapterMetadata } from 'ai.matey.types';
|
|
10
|
+
import type { IRChatRequest, IRChatResponse, IRChatStream } from 'ai.matey.types';
|
|
11
|
+
import type { StreamConversionOptions } from 'ai.matey.types';
|
|
12
|
+
/**
|
|
13
|
+
* OpenAI message content.
|
|
14
|
+
*/
|
|
15
|
+
export type OpenAIMessageContent = string | Array<{
|
|
16
|
+
type: 'text';
|
|
17
|
+
text: string;
|
|
18
|
+
} | {
|
|
19
|
+
type: 'image_url';
|
|
20
|
+
image_url: {
|
|
21
|
+
url: string;
|
|
22
|
+
detail?: 'auto' | 'low' | 'high';
|
|
23
|
+
};
|
|
24
|
+
}>;
|
|
25
|
+
/**
|
|
26
|
+
* OpenAI message.
|
|
27
|
+
*/
|
|
28
|
+
export interface OpenAIMessage {
|
|
29
|
+
role: 'system' | 'user' | 'assistant' | 'tool';
|
|
30
|
+
content: OpenAIMessageContent;
|
|
31
|
+
name?: string;
|
|
32
|
+
tool_call_id?: string;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* OpenAI Chat Completions API request.
|
|
36
|
+
*/
|
|
37
|
+
export interface OpenAIRequest {
|
|
38
|
+
model: string;
|
|
39
|
+
messages: OpenAIMessage[];
|
|
40
|
+
temperature?: number;
|
|
41
|
+
max_tokens?: number;
|
|
42
|
+
top_p?: number;
|
|
43
|
+
frequency_penalty?: number;
|
|
44
|
+
presence_penalty?: number;
|
|
45
|
+
stop?: string | string[];
|
|
46
|
+
stream?: boolean;
|
|
47
|
+
user?: string;
|
|
48
|
+
seed?: number;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* OpenAI Chat Completions API response.
|
|
52
|
+
*/
|
|
53
|
+
export interface OpenAIResponse {
|
|
54
|
+
id: string;
|
|
55
|
+
object: 'chat.completion';
|
|
56
|
+
created: number;
|
|
57
|
+
model: string;
|
|
58
|
+
choices: Array<{
|
|
59
|
+
index: number;
|
|
60
|
+
message: OpenAIMessage;
|
|
61
|
+
finish_reason: 'stop' | 'length' | 'tool_calls' | 'content_filter' | null;
|
|
62
|
+
}>;
|
|
63
|
+
usage?: {
|
|
64
|
+
prompt_tokens: number;
|
|
65
|
+
completion_tokens: number;
|
|
66
|
+
total_tokens: number;
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* OpenAI streaming chunk.
|
|
71
|
+
*/
|
|
72
|
+
export interface OpenAIStreamChunk {
|
|
73
|
+
id: string;
|
|
74
|
+
object: 'chat.completion.chunk';
|
|
75
|
+
created: number;
|
|
76
|
+
model: string;
|
|
77
|
+
choices: Array<{
|
|
78
|
+
index: number;
|
|
79
|
+
delta: {
|
|
80
|
+
role?: 'assistant';
|
|
81
|
+
content?: string;
|
|
82
|
+
};
|
|
83
|
+
finish_reason: 'stop' | 'length' | 'tool_calls' | 'content_filter' | null;
|
|
84
|
+
}>;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Frontend adapter for OpenAI Chat Completions API.
|
|
88
|
+
*/
|
|
89
|
+
export declare class OpenAIFrontendAdapter implements FrontendAdapter<OpenAIRequest, OpenAIResponse, OpenAIStreamChunk> {
|
|
90
|
+
readonly metadata: AdapterMetadata;
|
|
91
|
+
/**
|
|
92
|
+
* Convert OpenAI request to Universal IR.
|
|
93
|
+
*/
|
|
94
|
+
toIR(request: OpenAIRequest): Promise<IRChatRequest>;
|
|
95
|
+
/**
|
|
96
|
+
* Convert Universal IR response to OpenAI format.
|
|
97
|
+
*/
|
|
98
|
+
fromIR(response: IRChatResponse): Promise<OpenAIResponse>;
|
|
99
|
+
/**
|
|
100
|
+
* Convert Universal IR stream to OpenAI SSE format.
|
|
101
|
+
*/
|
|
102
|
+
fromIRStream(stream: IRChatStream, options?: StreamConversionOptions): AsyncGenerator<OpenAIStreamChunk, void, undefined>;
|
|
103
|
+
/**
|
|
104
|
+
* Convert OpenAI message to IR message.
|
|
105
|
+
*/
|
|
106
|
+
private convertMessageToIR;
|
|
107
|
+
/**
|
|
108
|
+
* Convert IR message to OpenAI message.
|
|
109
|
+
*/
|
|
110
|
+
private convertMessageFromIR;
|
|
111
|
+
/**
|
|
112
|
+
* Map IR finish reason to OpenAI finish reason.
|
|
113
|
+
*/
|
|
114
|
+
private mapFinishReason;
|
|
115
|
+
}
|
|
116
|
+
//# sourceMappingURL=openai.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"openai.d.ts","sourceRoot":"","sources":["../../../src/adapters/openai.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACvE,OAAO,KAAK,EACV,aAAa,EACb,cAAc,EACd,YAAY,EAGb,MAAM,gBAAgB,CAAC;AACxB,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,gBAAgB,CAAC;AAQ9D;;GAEG;AACH,MAAM,MAAM,oBAAoB,GAC5B,MAAM,GAC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
|
|
3
|
+
*
|
|
4
|
+
* Consolidated package containing all frontend adapters.
|
|
5
|
+
* Each frontend adapter handles converting provider-specific
|
|
6
|
+
* request/response formats to Universal IR and vice versa.
|
|
7
|
+
*
|
|
8
|
+
* @module ai.matey.frontend
|
|
9
|
+
*/
|
|
10
|
+
export * from './adapters/openai.js';
|
|
11
|
+
export * from './adapters/anthropic.js';
|
|
12
|
+
export * from './adapters/gemini.js';
|
|
13
|
+
export * from './adapters/mistral.js';
|
|
14
|
+
export * from './adapters/ollama.js';
|
|
15
|
+
export * from './adapters/chrome-ai.js';
|
|
16
|
+
export * from './adapters/generic.js';
|
|
17
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAGH,cAAc,sBAAsB,CAAC;AACrC,cAAc,yBAAyB,CAAC;AACxC,cAAc,sBAAsB,CAAC;AACrC,cAAc,uBAAuB,CAAC;AACtC,cAAc,sBAAsB,CAAC;AACrC,cAAc,yBAAyB,CAAC;AACxC,cAAc,uBAAuB,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "ai.matey.frontend",
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "Frontend adapters for AI Matey - Universal AI Adapter System",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/cjs/index.js",
|
|
7
|
+
"module": "./dist/esm/index.js",
|
|
8
|
+
"types": "./dist/types/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"import": {
|
|
12
|
+
"types": "./dist/types/index.d.ts",
|
|
13
|
+
"default": "./dist/esm/index.js"
|
|
14
|
+
},
|
|
15
|
+
"require": {
|
|
16
|
+
"types": "./dist/types/index.d.ts",
|
|
17
|
+
"default": "./dist/cjs/index.js"
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
"./openai": {
|
|
21
|
+
"import": {
|
|
22
|
+
"types": "./dist/types/adapters/openai.d.ts",
|
|
23
|
+
"default": "./dist/esm/adapters/openai.js"
|
|
24
|
+
},
|
|
25
|
+
"require": {
|
|
26
|
+
"types": "./dist/types/adapters/openai.d.ts",
|
|
27
|
+
"default": "./dist/cjs/adapters/openai.js"
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
"./anthropic": {
|
|
31
|
+
"import": {
|
|
32
|
+
"types": "./dist/types/adapters/anthropic.d.ts",
|
|
33
|
+
"default": "./dist/esm/adapters/anthropic.js"
|
|
34
|
+
},
|
|
35
|
+
"require": {
|
|
36
|
+
"types": "./dist/types/adapters/anthropic.d.ts",
|
|
37
|
+
"default": "./dist/cjs/adapters/anthropic.js"
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
"./gemini": {
|
|
41
|
+
"import": {
|
|
42
|
+
"types": "./dist/types/adapters/gemini.d.ts",
|
|
43
|
+
"default": "./dist/esm/adapters/gemini.js"
|
|
44
|
+
},
|
|
45
|
+
"require": {
|
|
46
|
+
"types": "./dist/types/adapters/gemini.d.ts",
|
|
47
|
+
"default": "./dist/cjs/adapters/gemini.js"
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
"./generic": {
|
|
51
|
+
"import": {
|
|
52
|
+
"types": "./dist/types/adapters/generic.d.ts",
|
|
53
|
+
"default": "./dist/esm/adapters/generic.js"
|
|
54
|
+
},
|
|
55
|
+
"require": {
|
|
56
|
+
"types": "./dist/types/adapters/generic.d.ts",
|
|
57
|
+
"default": "./dist/cjs/adapters/generic.js"
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
"./mistral": {
|
|
61
|
+
"import": {
|
|
62
|
+
"types": "./dist/types/adapters/mistral.d.ts",
|
|
63
|
+
"default": "./dist/esm/adapters/mistral.js"
|
|
64
|
+
},
|
|
65
|
+
"require": {
|
|
66
|
+
"types": "./dist/types/adapters/mistral.d.ts",
|
|
67
|
+
"default": "./dist/cjs/adapters/mistral.js"
|
|
68
|
+
}
|
|
69
|
+
},
|
|
70
|
+
"./ollama": {
|
|
71
|
+
"import": {
|
|
72
|
+
"types": "./dist/types/adapters/ollama.d.ts",
|
|
73
|
+
"default": "./dist/esm/adapters/ollama.js"
|
|
74
|
+
},
|
|
75
|
+
"require": {
|
|
76
|
+
"types": "./dist/types/adapters/ollama.d.ts",
|
|
77
|
+
"default": "./dist/cjs/adapters/ollama.js"
|
|
78
|
+
}
|
|
79
|
+
},
|
|
80
|
+
"./chrome-ai": {
|
|
81
|
+
"import": {
|
|
82
|
+
"types": "./dist/types/adapters/chrome-ai.d.ts",
|
|
83
|
+
"default": "./dist/esm/adapters/chrome-ai.js"
|
|
84
|
+
},
|
|
85
|
+
"require": {
|
|
86
|
+
"types": "./dist/types/adapters/chrome-ai.d.ts",
|
|
87
|
+
"default": "./dist/cjs/adapters/chrome-ai.js"
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
},
|
|
91
|
+
"files": [
|
|
92
|
+
"dist",
|
|
93
|
+
"readme.md",
|
|
94
|
+
"CHANGELOG.md",
|
|
95
|
+
"LICENSE"
|
|
96
|
+
],
|
|
97
|
+
"scripts": {
|
|
98
|
+
"build": "npm run build:esm && npm run build:cjs && npm run build:types",
|
|
99
|
+
"build:esm": "tsc -p tsconfig.esm.json",
|
|
100
|
+
"build:cjs": "tsc -p tsconfig.cjs.json",
|
|
101
|
+
"build:types": "tsc -p tsconfig.types.json",
|
|
102
|
+
"clean": "rm -rf dist",
|
|
103
|
+
"typecheck": "tsc --noEmit",
|
|
104
|
+
"lint": "eslint src --ext .ts",
|
|
105
|
+
"lint:fix": "eslint src --ext .ts --fix",
|
|
106
|
+
"test": "vitest run",
|
|
107
|
+
"test:watch": "vitest"
|
|
108
|
+
},
|
|
109
|
+
"dependencies": {
|
|
110
|
+
"ai.matey.types": "*",
|
|
111
|
+
"ai.matey.errors": "*",
|
|
112
|
+
"ai.matey.utils": "*",
|
|
113
|
+
"ai.matey.backend": "*"
|
|
114
|
+
},
|
|
115
|
+
"devDependencies": {
|
|
116
|
+
"ai.matey.testing": "*",
|
|
117
|
+
"typescript": "^5.9.3",
|
|
118
|
+
"vitest": "^3.2.4"
|
|
119
|
+
},
|
|
120
|
+
"keywords": [
|
|
121
|
+
"ai",
|
|
122
|
+
"llm",
|
|
123
|
+
"frontend",
|
|
124
|
+
"adapter",
|
|
125
|
+
"openai",
|
|
126
|
+
"anthropic",
|
|
127
|
+
"gemini",
|
|
128
|
+
"ai-matey"
|
|
129
|
+
],
|
|
130
|
+
"author": "AI Matey",
|
|
131
|
+
"license": "MIT",
|
|
132
|
+
"homepage": "https://github.com/johnhenry/ai.matey#readme",
|
|
133
|
+
"bugs": {
|
|
134
|
+
"url": "https://github.com/johnhenry/ai.matey/issues"
|
|
135
|
+
},
|
|
136
|
+
"repository": {
|
|
137
|
+
"type": "git",
|
|
138
|
+
"url": "git+https://github.com/johnhenry/ai.matey.git",
|
|
139
|
+
"directory": "packages/frontend"
|
|
140
|
+
},
|
|
141
|
+
"engines": {
|
|
142
|
+
"node": ">=18.0.0"
|
|
143
|
+
}
|
|
144
|
+
}
|
package/readme.md
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
# ai.matey.frontend
|
|
2
|
+
|
|
3
|
+
Frontend adapters for AI Matey - Universal AI Adapter System.
|
|
4
|
+
|
|
5
|
+
Part of the [ai.matey](https://github.com/johnhenry/ai.matey) monorepo.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install ai.matey.frontend
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Overview
|
|
14
|
+
|
|
15
|
+
Frontend adapters convert provider-specific request formats to the Universal IR (Intermediate Representation) format used internally by AI Matey. This allows your application to accept requests in any provider's format and route them to any backend.
|
|
16
|
+
|
|
17
|
+
## Included Adapters
|
|
18
|
+
|
|
19
|
+
- **OpenAI** - OpenAI Chat Completions API format
|
|
20
|
+
- **Anthropic** - Anthropic Messages API format
|
|
21
|
+
- **Gemini** - Google Gemini API format
|
|
22
|
+
- **Mistral** - Mistral API format
|
|
23
|
+
- **Ollama** - Ollama API format
|
|
24
|
+
- **Chrome AI** - Chrome AI format
|
|
25
|
+
- **Generic** - Passthrough adapter for IR format
|
|
26
|
+
|
|
27
|
+
## Usage
|
|
28
|
+
|
|
29
|
+
```typescript
|
|
30
|
+
import { OpenAIFrontendAdapter, AnthropicFrontendAdapter } from 'ai.matey.frontend';
|
|
31
|
+
import { Bridge } from 'ai.matey.core';
|
|
32
|
+
|
|
33
|
+
// Accept OpenAI-formatted requests
|
|
34
|
+
const openAIFrontend = new OpenAIFrontendAdapter();
|
|
35
|
+
|
|
36
|
+
// Accept Anthropic-formatted requests
|
|
37
|
+
const anthropicFrontend = new AnthropicFrontendAdapter();
|
|
38
|
+
|
|
39
|
+
// Create a bridge that accepts OpenAI format
|
|
40
|
+
const bridge = new Bridge({
|
|
41
|
+
frontend: openAIFrontend,
|
|
42
|
+
backend: yourBackend,
|
|
43
|
+
});
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## Generic Adapter
|
|
47
|
+
|
|
48
|
+
The Generic adapter passes IR format directly without conversion:
|
|
49
|
+
|
|
50
|
+
```typescript
|
|
51
|
+
import { GenericFrontendAdapter, createGenericFrontend } from 'ai.matey.frontend';
|
|
52
|
+
|
|
53
|
+
const frontend = createGenericFrontend();
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
## API Reference
|
|
57
|
+
|
|
58
|
+
See the TypeScript definitions for detailed API documentation.
|
|
59
|
+
|
|
60
|
+
## License
|
|
61
|
+
|
|
62
|
+
MIT - see [LICENSE](./LICENSE) for details.
|