@agent-garden/provider-definition 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/caption.d.ts ADDED
@@ -0,0 +1,17 @@
1
+ import { Field } from "./provider";
2
+
3
+ export type CaptionCallbacks = {
4
+ onUpdate: (chunk: string) => void;
5
+ onFinish: (result: string) => void;
6
+ onError: (error: Error) => void;
7
+ onController: (controller: AbortController) => void;
8
+ };
9
+
10
+ export interface CaptionApi {
11
+ fields: { [key: string]: Field };
12
+ name: string;
13
+ icon: string;
14
+ minSize: { width: number, height: number };
15
+ maxSize: { width: number, height: number };
16
+ request: (props: { image: string, prompt?: string, callbacks: CaptionCallbacks }) => Promise<void>;
17
+ }
package/embed.d.ts ADDED
@@ -0,0 +1,16 @@
1
+ import OpenAI from "openai";
2
+ import { Field } from "./provider";
3
+
4
+ type EmbedFeature = 'vision' | 'audio'
5
+
6
+ export type EmbedItem = string | OpenAI.Chat.Completions.ChatCompletionContentPart[];
7
+
8
+ export interface EmbedApi {
9
+ fields: { [key: string]: Field };
10
+ name: string;
11
+ icon: string;
12
+ modelId: string;
13
+ dimension: number;
14
+ features: EmbedFeature[];
15
+ request: (props: { items: EmbedItem[] }) => Promise<{ item: EmbedItem, modelId: string, embedding: number[] }[]>;
16
+ }
package/index.d.ts ADDED
@@ -0,0 +1,9 @@
1
+
2
+ export * from './provider'
3
+
4
+ export * from './caption'
5
+ export * from './embed'
6
+ export * from './llm'
7
+ export * from './paint'
8
+ export * from './rerank'
9
+ export * from './translate'
package/llm.d.ts ADDED
@@ -0,0 +1,54 @@
1
+
2
+ import OpenAI from "openai";
3
+ import { Field } from "./provider";
4
+
5
+ export type LlmMessage = OpenAI.Chat.Completions.ChatCompletionMessageParam;
6
+
7
+ export type LlmMediaHandle = (
8
+ callbacks: {
9
+ onUpdate: (progress: number) => void;
10
+ onFinish: (result: string) => void;
11
+ onError: (error: Error) => void;
12
+ onController: (controller: AbortController) => void;
13
+ }
14
+ ) => void;
15
+
16
+ export type LlmChunk = string | {
17
+ type: 'reasoning';
18
+ text: string;
19
+ } | {
20
+ type: 'function';
21
+ text: string;
22
+ } | {
23
+ type: 'image';
24
+ handle: LlmMediaHandle;
25
+ } | {
26
+ type: 'audio';
27
+ handle: LlmMediaHandle;
28
+ };
29
+
30
+ export type LlmCallbacks = {
31
+ onUpdate: (chunk: string | LlmChunk) => void;
32
+ onFinish: (result: LlmMessage) => void;
33
+ onError: (error: Error) => void;
34
+ onController: (controller: AbortController) => void;
35
+ };
36
+
37
+ type LlmFeature = 'vision' | 'audio' | 'reasoning' | 'togglable_reasoning' | 'web_search' | 'function_call' | 'structured_output' | 'cache';
38
+
39
+ export interface LlmFeatureParams {
40
+ reasoning?: boolean;
41
+ webSearch?: boolean;
42
+ functions?: OpenAI.Chat.Completions.ChatCompletionTool[];
43
+ structuredOutput?: boolean;
44
+ }
45
+
46
+ export interface LlmApi {
47
+ fields: { [key: string]: Field };
48
+ name: string;
49
+ icon: string;
50
+ features: LlmFeature[];
51
+ maxTokens: number;
52
+ estimateTokens: (messages: LlmMessage[]) => number;
53
+ request: (props: { messages: LlmMessage[], features: LlmFeatureParams, callbacks: LlmCallbacks }) => Promise<void>;
54
+ }
package/package.json ADDED
@@ -0,0 +1,15 @@
1
+ {
2
+ "dependencies": {
3
+ "openai": "^6.3.0"
4
+ },
5
+ "name": "@agent-garden/provider-definition",
6
+ "version": "1.0.0",
7
+ "main": "index.d.ts",
8
+ "devDependencies": {},
9
+ "scripts": {
10
+ "test": "echo \"Error: no test specified\" && exit 1"
11
+ },
12
+ "author": "ZeeChung",
13
+ "license": "MIT",
14
+ "description": ""
15
+ }
package/paint.d.ts ADDED
@@ -0,0 +1,19 @@
1
+ import { Field } from "./provider";
2
+
3
+ export type PaintCallbacks = {
4
+ onUpdate: (progress: number) => void;
5
+ onFinish: (result: string) => void;
6
+ onError: (error: Error) => void;
7
+ onController: (controller: AbortController) => void;
8
+ }
9
+
10
+ type PaintFeature = 'text2img' | 'img2img' | 'repaint';
11
+
12
+ export interface PaintApi {
13
+ fields: { [key: string]: Field };
14
+ name: string;
15
+ icon: string;
16
+ features: PaintFeature[];
17
+ outputSizes: { width: number, height: number }[];
18
+ request: (props: { prompt: string, reference?: string, size: { width: number, height: number }, callbacks: PaintCallbacks }) => Promise<void>;
19
+ }
package/provider.d.ts ADDED
@@ -0,0 +1,59 @@
1
+
2
+ import { LlmApi } from "./llm";
3
+ import { CaptionApi } from "./caption";
4
+ import { PaintApi } from "./paint";
5
+ import { RerankApi } from "./rerank";
6
+ import { EmbedApi } from "./embed";
7
+ import { TranslateApi } from "./translate";
8
+
9
+
10
+ export type ProviderApis = {
11
+ postStream: (url: string, body: string, headers: { [key: string]: string }) => Promise<AsyncIterable<string>>;
12
+ post: (url: string, body: string, headers: { [key: string]: string }) => Promise<string>;
13
+ };
14
+
15
+
16
+ export type Field = StringField | NumberField | SelectionField;
17
+
18
+ interface StringField {
19
+ type: 'string' | 'password';
20
+ current?: string;
21
+ }
22
+
23
+ interface NumberField {
24
+ type: 'number';
25
+ current?: number;
26
+ maxValue?: number;
27
+ minValue?: number;
28
+ step?: number;
29
+ }
30
+
31
+ type SelectionField = {
32
+ type: 'selection';
33
+ current?: string;
34
+ options: { [key: string]: string }
35
+ multiple?: false;
36
+ } | {
37
+ type: 'selection';
38
+ current?: string[];
39
+ options: { [key: string]: string }
40
+ multiple: true;
41
+ };
42
+
43
+
44
+ export interface Provider {
45
+ schema: 'provider';
46
+ init: (apis: ProviderApis) => Promise<void>;
47
+ name: string;
48
+ fields: { [key: string]: Field };
49
+ icon: string;
50
+ domains: string[]; // trusted domains
51
+ apis: {
52
+ llm?: LlmApi;
53
+ caption?: CaptionApi;
54
+ paint?: PaintApi;
55
+ rerank?: RerankApi;
56
+ embed?: EmbedApi;
57
+ translate?: TranslateApi;
58
+ };
59
+ }
package/rerank.d.ts ADDED
@@ -0,0 +1,8 @@
1
+ import { Field } from "./provider";
2
+
3
+ export interface RerankApi {
4
+ fields: { [key: string]: Field };
5
+ name: string;
6
+ icon: string;
7
+ request: (props: { items: string[], prompt: string }) => Promise<{ item: string, score?: number }[]>;
8
+ }
package/translate.d.ts ADDED
@@ -0,0 +1,8 @@
1
+ import { Field } from "./provider";
2
+
3
+ export interface TranslateApi { // TODO: regularize language codes
4
+ fields: { [key: string]: Field };
5
+ sources: string[];
6
+ targets: string[];
7
+ request: (props: { text: string, source: string, target: string }) => Promise<string>;
8
+ }