Files changed (7) hide show
  1. Model.json +50 -0
  2. Model.jsonl +172 -0
  3. Usr.tsx +13 -0
  4. model.ts +258 -0
  5. models.json +212 -0
  6. models.service.ts +195 -0
  7. models.ts +243 -0
Model.json ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [
2
+ {
3
+ "text": "Next.js and Supabase Starter Kit\n\nNext steps\n\n 1. Create Supabase project\n \n Head over to database.new and create a new Supabase project.\n\n 2. Declare environment variables\n \n Rename the .env.example file in your Next.js app to .env.local and populate with values from your Supabase project's API Settings.\n\n 3. Restart your Next.js development server\n \n You may need to quit your Next.js development server and run npm run dev again to load the new environment variables.\n\n 4. Refresh the page\n \n You may need to refresh the page for Next.js to load the new environment variables.",
4
+ "metadata": {
5
+ "title": "Next.js and Supabase Starter Kit",
6
+ "description": "The fastest way to build apps with Next.js and Supabase",
7
+ "og:title": "Next.js and Supabase Starter Kit",
8
+ "og:description": "The fastest way to build apps with Next.js and Supabase",
9
+ "og:image:type": "image/png",
10
+ "og:image:width": "1200",
11
+ "og:image:height": "600",
12
+ "og:image": "https://web4app-4qbc-jmjfa06vw-web4s-projects-1b8287a0.vercel.app/opengraph-image.png?2e0bc232e210f89d",
13
+ "twitter:title": "Next.js and Supabase Starter Kit",
14
+ "twitter:description": "The fastest way to build apps with Next.js and Supabase"
15
+ },
16
+ "credits": 2
17
+ },
18
+ {
19
+ "text": "Next.js and Supabase Starter Kit\n\nNext steps\n\n 1. Create Supabase project\n \n Head over to database.new and create a new Supabase project.\n\n 2. Declare environment variables\n \n Rename the .env.example file in your Next.js app to .env.local and populate with values from your Supabase project's API Settings.\n\n 3. Restart your Next.js development server\n \n You may need to quit your Next.js development server and run npm run dev again to load the new environment variables.\n\n 4. Refresh the page\n \n You may need to refresh the page for Next.js to load the new environment variables.",
20
+ "metadata": {
21
+ "title": "Next.js and Supabase Starter Kit",
22
+ "description": "The fastest way to build apps with Next.js and Supabase",
23
+ "og:title": "Next.js and Supabase Starter Kit",
24
+ "og:description": "The fastest way to build apps with Next.js and Supabase",
25
+ "og:image:type": "image/png",
26
+ "og:image:width": "1200",
27
+ "og:image:height": "600",
28
+ "og:image": "https://web4app-4qbc-jmjfa06vw-web4s-projects-1b8287a0.vercel.app/opengraph-image.png?2e0bc232e210f89d",
29
+ "twitter:title": "Next.js and Supabase Starter Kit",
30
+ "twitter:description": "The fastest way to build apps with Next.js and Supabase"
31
+ },
32
+ "credits": 2
33
+ },
34
+ {
35
+ "text": "Next.js and Supabase Starter Kit\n\nNext steps\n\n 1. Create Supabase project\n \n Head over to database.new and create a new Supabase project.\n\n 2. Declare environment variables\n \n Rename the .env.example file in your Next.js app to .env.local and populate with values from your Supabase project's API Settings.\n\n 3. Restart your Next.js development server\n \n You may need to quit your Next.js development server and run npm run dev again to load the new environment variables.\n\n 4. Refresh the page\n \n You may need to refresh the page for Next.js to load the new environment variables.",
36
+ "metadata": {
37
+ "title": "Next.js and Supabase Starter Kit",
38
+ "description": "The fastest way to build apps with Next.js and Supabase",
39
+ "og:title": "Next.js and Supabase Starter Kit",
40
+ "og:description": "The fastest way to build apps with Next.js and Supabase",
41
+ "og:image:type": "image/png",
42
+ "og:image:width": "1200",
43
+ "og:image:height": "600",
44
+ "og:image": "https://web4app-4qbc-jmjfa06vw-web4s-projects-1b8287a0.vercel.app/opengraph-image.png?2e0bc232e210f89d",
45
+ "twitter:title": "Next.js and Supabase Starter Kit",
46
+ "twitter:description": "The fastest way to build apps with Next.js and Supabase"
47
+ },
48
+ "credits": 2
49
+ }
50
+ ]
Model.jsonl ADDED
@@ -0,0 +1,172 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "$schema": "http://json-schema.org/draft-07/schema",
3
+ "$id": "https://github.com/unicode-org/message-format-wg/blob/main/spec/data-model/message.json",
4
+
5
+ "oneOf": [{ "$ref": "#/$defs/message" }, { "$ref": "#/$defs/select" }],
6
+
7
+ "$defs": {
8
+ "literal": {
9
+ "type": "object",
10
+ "properties": {
11
+ "type": { "const": "literal" },
12
+ "value": { "type": "string" }
13
+ },
14
+ "required": ["type", "value"]
15
+ },
16
+ "variable": {
17
+ "type": "object",
18
+ "properties": {
19
+ "type": { "const": "variable" },
20
+ "name": { "type": "string" }
21
+ },
22
+ "required": ["type", "name"]
23
+ },
24
+ "literal-or-variable": {
25
+ "oneOf": [{ "$ref": "#/$defs/literal" }, { "$ref": "#/$defs/variable" }]
26
+ },
27
+
28
+ "options": {
29
+ "type": "object",
30
+ "additionalProperties": { "$ref": "#/$defs/literal-or-variable" }
31
+ },
32
+ "attributes": {
33
+ "type": "object",
34
+ "additionalProperties": {
35
+ "oneOf": [{ "$ref": "#/$defs/literal" }, { "const": true }]
36
+ }
37
+ },
38
+
39
+ "function": {
40
+ "type": "object",
41
+ "properties": {
42
+ "type": { "const": "function" },
43
+ "name": { "type": "string" },
44
+ "options": { "$ref": "#/$defs/options" }
45
+ },
46
+ "required": ["type", "name"]
47
+ },
48
+ "expression": {
49
+ "type": "object",
50
+ "properties": {
51
+ "type": { "const": "expression" },
52
+ "arg": { "$ref": "#/$defs/literal-or-variable" },
53
+ "function": { "$ref": "#/$defs/function" },
54
+ "attributes": { "$ref": "#/$defs/attributes" }
55
+ },
56
+ "anyOf": [
57
+ { "required": ["type", "arg"] },
58
+ { "required": ["type", "function"] }
59
+ ]
60
+ },
61
+
62
+ "markup": {
63
+ "type": "object",
64
+ "properties": {
65
+ "type": { "const": "markup" },
66
+ "kind": { "enum": ["open", "standalone", "close"] },
67
+ "name": { "type": "string" },
68
+ "options": { "$ref": "#/$defs/options" },
69
+ "attributes": { "$ref": "#/$defs/attributes" }
70
+ },
71
+ "required": ["type", "kind", "name"]
72
+ },
73
+
74
+ "pattern": {
75
+ "type": "array",
76
+ "items": {
77
+ "oneOf": [
78
+ { "type": "string" },
79
+ { "$ref": "#/$defs/expression" },
80
+ { "$ref": "#/$defs/markup" }
81
+ ]
82
+ }
83
+ },
84
+
85
+ "input-declaration": {
86
+ "type": "object",
87
+ "properties": {
88
+ "type": { "const": "input" },
89
+ "name": { "type": "string" },
90
+ "value": {
91
+ "allOf": [
92
+ { "$ref": "#/$defs/expression" },
93
+ {
94
+ "properties": {
95
+ "arg": { "$ref": "#/$defs/variable" }
96
+ },
97
+ "required": ["arg"]
98
+ }
99
+ ]
100
+ }
101
+ },
102
+ "required": ["type", "name", "value"]
103
+ },
104
+ "local-declaration": {
105
+ "type": "object",
106
+ "properties": {
107
+ "type": { "const": "local" },
108
+ "name": { "type": "string" },
109
+ "value": { "$ref": "#/$defs/expression" }
110
+ },
111
+ "required": ["type", "name", "value"]
112
+ },
113
+ "declarations": {
114
+ "type": "array",
115
+ "items": {
116
+ "oneOf": [
117
+ { "$ref": "#/$defs/input-declaration" },
118
+ { "$ref": "#/$defs/local-declaration" }
119
+ ]
120
+ }
121
+ },
122
+
123
+ "variant-key": {
124
+ "oneOf": [
125
+ { "$ref": "#/$defs/literal" },
126
+ {
127
+ "type": "object",
128
+ "properties": {
129
+ "type": { "const": "*" },
130
+ "value": { "type": "string" }
131
+ },
132
+ "required": ["type"]
133
+ }
134
+ ]
135
+ },
136
+ "message": {
137
+ "type": "object",
138
+ "properties": {
139
+ "type": { "const": "message" },
140
+ "declarations": { "$ref": "#/$defs/declarations" },
141
+ "pattern": { "$ref": "#/$defs/pattern" }
142
+ },
143
+ "required": ["type", "declarations", "pattern"]
144
+ },
145
+ "select": {
146
+ "type": "object",
147
+ "properties": {
148
+ "type": { "const": "select" },
149
+ "declarations": { "$ref": "#/$defs/declarations" },
150
+ "selectors": {
151
+ "type": "array",
152
+ "items": { "$ref": "#/$defs/variable" }
153
+ },
154
+ "variants": {
155
+ "type": "array",
156
+ "items": {
157
+ "type": "object",
158
+ "properties": {
159
+ "keys": {
160
+ "type": "array",
161
+ "items": { "$ref": "#/$defs/variant-key" }
162
+ },
163
+ "value": { "$ref": "#/$defs/pattern" }
164
+ },
165
+ "required": ["keys", "value"]
166
+ }
167
+ }
168
+ },
169
+ "required": ["type", "declarations", "selectors", "variants"]
170
+ }
171
+ }
172
+ }
Usr.tsx ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { PaletteColors } from '@blockchain-com/constellation'
2
+ import styled from 'styled-components'
3
+
4
+ export const CloseIconContainer = styled.div`
5
+ display: flex;
6
+ align-items: center;
7
+ cursor: pointer;
8
+ justify-content: center;
9
+ width: 32px;
10
+ height: 32px;
11
+ border-radius: 50%;
12
+ background: ${PaletteColors['grey-000']};
13
+ `
model.ts ADDED
@@ -0,0 +1,258 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { DEFAULT_MODELS, ServiceProvider } from "../constant";
2
+ import { LLMModel } from "../client/api";
3
+
4
+ const CustomSeq = {
5
+ val: -1000, //To ensure the custom model located at front, start from -1000, refer to constant.ts
6
+ cache: new Map<string, number>(),
7
+ next: (id: string) => {
8
+ if (CustomSeq.cache.has(id)) {
9
+ return CustomSeq.cache.get(id) as number;
10
+ } else {
11
+ let seq = CustomSeq.val++;
12
+ CustomSeq.cache.set(id, seq);
13
+ return seq;
14
+ }
15
+ },
16
+ };
17
+
18
+ const customProvider = (providerName: string) => ({
19
+ id: providerName.toLowerCase(),
20
+ providerName: providerName,
21
+ providerType: "custom",
22
+ sorted: CustomSeq.next(providerName),
23
+ });
24
+
25
+ /**
26
+ * Sorts an array of models based on specified rules.
27
+ *
28
+ * First, sorted by provider; if the same, sorted by model
29
+ */
30
+ const sortModelTable = (models: ReturnType<typeof collectModels>) =>
31
+ models.sort((a, b) => {
32
+ if (a.provider && b.provider) {
33
+ let cmp = a.provider.sorted - b.provider.sorted;
34
+ return cmp === 0 ? a.sorted - b.sorted : cmp;
35
+ } else {
36
+ return a.sorted - b.sorted;
37
+ }
38
+ });
39
+
40
+ /**
41
+ * get model name and provider from a formatted string,
42
+ * e.g. `gpt-4@OpenAi` or `claude-3-5-sonnet@20240620@Google`
43
+ * @param modelWithProvider model name with provider separated by last `@` char,
44
+ * @returns [model, provider] tuple, if no `@` char found, provider is undefined
45
+ */
46
+ export function getModelProvider(modelWithProvider: string): [string, string?] {
47
+ const [model, provider] = modelWithProvider.split(/@(?!.*@)/);
48
+ return [model, provider];
49
+ }
50
+
51
+ export function collectModelTable(
52
+ models: readonly LLMModel[],
53
+ customModels: string,
54
+ ) {
55
+ const modelTable: Record<
56
+ string,
57
+ {
58
+ available: boolean;
59
+ name: string;
60
+ displayName: string;
61
+ sorted: number;
62
+ provider?: LLMModel["provider"]; // Marked as optional
63
+ isDefault?: boolean;
64
+ }
65
+ > = {};
66
+
67
+ // default models
68
+ models.forEach((m) => {
69
+ // using <modelName>@<providerId> as fullName
70
+ modelTable[`${m.name}@${m?.provider?.id}`] = {
71
+ ...m,
72
+ displayName: m.name, // 'provider' is copied over if it exists
73
+ };
74
+ });
75
+
76
+ // server custom models
77
+ customModels
78
+ .split(",")
79
+ .filter((v) => !!v && v.length > 0)
80
+ .forEach((m) => {
81
+ const available = !m.startsWith("-");
82
+ const nameConfig =
83
+ m.startsWith("+") || m.startsWith("-") ? m.slice(1) : m;
84
+ let [name, displayName] = nameConfig.split("=");
85
+
86
+ // enable or disable all models
87
+ if (name === "all") {
88
+ Object.values(modelTable).forEach(
89
+ (model) => (model.available = available),
90
+ );
91
+ } else {
92
+ // 1. find model by name, and set available value
93
+ const [customModelName, customProviderName] = getModelProvider(name);
94
+ let count = 0;
95
+ for (const fullName in modelTable) {
96
+ const [modelName, providerName] = getModelProvider(fullName);
97
+ if (
98
+ customModelName == modelName &&
99
+ (customProviderName === undefined ||
100
+ customProviderName === providerName)
101
+ ) {
102
+ count += 1;
103
+ modelTable[fullName]["available"] = available;
104
+ // swap name and displayName for bytedance
105
+ if (providerName === "bytedance") {
106
+ [name, displayName] = [displayName, modelName];
107
+ modelTable[fullName]["name"] = name;
108
+ }
109
+ if (displayName) {
110
+ modelTable[fullName]["displayName"] = displayName;
111
+ }
112
+ }
113
+ }
114
+ // 2. if model not exists, create new model with available value
115
+ if (count === 0) {
116
+ let [customModelName, customProviderName] = getModelProvider(name);
117
+ const provider = customProvider(
118
+ customProviderName || customModelName,
119
+ );
120
+ // swap name and displayName for bytedance
121
+ if (displayName && provider.providerName == "ByteDance") {
122
+ [customModelName, displayName] = [displayName, customModelName];
123
+ }
124
+ modelTable[`${customModelName}@${provider?.id}`] = {
125
+ name: customModelName,
126
+ displayName: displayName || customModelName,
127
+ available,
128
+ provider, // Use optional chaining
129
+ sorted: CustomSeq.next(`${customModelName}@${provider?.id}`),
130
+ };
131
+ }
132
+ }
133
+ });
134
+
135
+ return modelTable;
136
+ }
137
+
138
+ export function collectModelTableWithDefaultModel(
139
+ models: readonly LLMModel[],
140
+ customModels: string,
141
+ defaultModel: string,
142
+ ) {
143
+ let modelTable = collectModelTable(models, customModels);
144
+ if (defaultModel && defaultModel !== "") {
145
+ if (defaultModel.includes("@")) {
146
+ if (defaultModel in modelTable) {
147
+ modelTable[defaultModel].isDefault = true;
148
+ }
149
+ } else {
150
+ for (const key of Object.keys(modelTable)) {
151
+ if (
152
+ modelTable[key].available &&
153
+ getModelProvider(key)[0] == defaultModel
154
+ ) {
155
+ modelTable[key].isDefault = true;
156
+ break;
157
+ }
158
+ }
159
+ }
160
+ }
161
+ return modelTable;
162
+ }
163
+
164
+ /**
165
+ * Generate full model table.
166
+ */
167
+ export function collectModels(
168
+ models: readonly LLMModel[],
169
+ customModels: string,
170
+ ) {
171
+ const modelTable = collectModelTable(models, customModels);
172
+ let allModels = Object.values(modelTable);
173
+
174
+ allModels = sortModelTable(allModels);
175
+
176
+ return allModels;
177
+ }
178
+
179
+ export function collectModelsWithDefaultModel(
180
+ models: readonly LLMModel[],
181
+ customModels: string,
182
+ defaultModel: string,
183
+ ) {
184
+ const modelTable = collectModelTableWithDefaultModel(
185
+ models,
186
+ customModels,
187
+ defaultModel,
188
+ );
189
+ let allModels = Object.values(modelTable);
190
+
191
+ allModels = sortModelTable(allModels);
192
+
193
+ return allModels;
194
+ }
195
+
196
+ export function isModelAvailableInServer(
197
+ customModels: string,
198
+ modelName: string,
199
+ providerName: string,
200
+ ) {
201
+ const fullName = `${modelName}@${providerName}`;
202
+ const modelTable = collectModelTable(DEFAULT_MODELS, customModels);
203
+ return modelTable[fullName]?.available === false;
204
+ }
205
+
206
+ /**
207
+ * Check if the model name is a GPT-4 related model
208
+ *
209
+ * @param modelName The name of the model to check
210
+ * @returns True if the model is a GPT-4 related model (excluding gpt-4o-mini)
211
+ */
212
+ export function isGPT4Model(modelName: string): boolean {
213
+ return (
214
+ (modelName.startsWith("gpt-4") ||
215
+ modelName.startsWith("chatgpt-4o") ||
216
+ modelName.startsWith("o1")) &&
217
+ !modelName.startsWith("gpt-4o-mini")
218
+ );
219
+ }
220
+
221
+ /**
222
+ * Checks if a model is not available on any of the specified providers in the server.
223
+ *
224
+ * @param {string} customModels - A string of custom models, comma-separated.
225
+ * @param {string} modelName - The name of the model to check.
226
+ * @param {string|string[]} providerNames - A string or array of provider names to check against.
227
+ *
228
+ * @returns {boolean} True if the model is not available on any of the specified providers, false otherwise.
229
+ */
230
+ export function isModelNotavailableInServer(
231
+ customModels: string,
232
+ modelName: string,
233
+ providerNames: string | string[],
234
+ ): boolean {
235
+ // Check DISABLE_GPT4 environment variable
236
+ if (
237
+ process.env.DISABLE_GPT4 === "1" &&
238
+ isGPT4Model(modelName.toLowerCase())
239
+ ) {
240
+ return true;
241
+ }
242
+
243
+ const modelTable = collectModelTable(DEFAULT_MODELS, customModels);
244
+
245
+ const providerNamesArray = Array.isArray(providerNames)
246
+ ? providerNames
247
+ : [providerNames];
248
+ for (const providerName of providerNamesArray) {
249
+ // if model provider is bytedance, use model config name to check if not avaliable
250
+ if (providerName === ServiceProvider.ByteDance) {
251
+ return !Object.values(modelTable).filter((v) => v.name === modelName)?.[0]
252
+ ?.available;
253
+ }
254
+ const fullName = `${modelName}@${providerName.toLowerCase()}`;
255
+ if (modelTable?.[fullName]?.available === true) return false;
256
+ }
257
+ return true;
258
+ }
models.json ADDED
@@ -0,0 +1,212 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "models": [
3
+ {
4
+ "id": "gpt-4.1",
5
+ "name": "GPT-4.1",
6
+ "provider": "OpenAI",
7
+ "providerId": "openai",
8
+ "enabled": true,
9
+ "toolCallType": "native"
10
+ },
11
+ {
12
+ "id": "gpt-4.1-mini",
13
+ "name": "GPT-4.1 mini",
14
+ "provider": "OpenAI",
15
+ "providerId": "openai",
16
+ "enabled": true,
17
+ "toolCallType": "native"
18
+ },
19
+ {
20
+ "id": "gpt-4.1-nano",
21
+ "name": "GPT-4.1 nano",
22
+ "provider": "OpenAI",
23
+ "providerId": "openai",
24
+ "enabled": true,
25
+ "toolCallType": "native"
26
+ },
27
+ {
28
+ "id": "o3-mini",
29
+ "name": "o3 mini",
30
+ "provider": "OpenAI",
31
+ "providerId": "openai",
32
+ "enabled": true,
33
+ "toolCallType": "native"
34
+ },
35
+ {
36
+ "id": "gpt-4o",
37
+ "name": "GPT-4o",
38
+ "provider": "OpenAI",
39
+ "providerId": "openai",
40
+ "enabled": true,
41
+ "toolCallType": "native"
42
+ },
43
+ {
44
+ "id": "gpt-4o-mini",
45
+ "name": "GPT-4o mini",
46
+ "provider": "OpenAI",
47
+ "providerId": "openai",
48
+ "enabled": true,
49
+ "toolCallType": "native"
50
+ },
51
+ {
52
+ "id": "claude-3-7-sonnet-20250219",
53
+ "name": "Claude 3.7 Sonnet",
54
+ "provider": "Anthropic",
55
+ "providerId": "anthropic",
56
+ "enabled": true,
57
+ "toolCallType": "native"
58
+ },
59
+ {
60
+ "id": "claude-3-5-sonnet-latest",
61
+ "name": "Claude 3.5 Sonnet",
62
+ "provider": "Anthropic",
63
+ "providerId": "anthropic",
64
+ "enabled": true,
65
+ "toolCallType": "native"
66
+ },
67
+ {
68
+ "id": "claude-3-5-haiku-20241022",
69
+ "name": "Claude 3.5 Haiku",
70
+ "provider": "Anthropic",
71
+ "providerId": "anthropic",
72
+ "enabled": true,
73
+ "toolCallType": "native"
74
+ },
75
+ {
76
+ "id": "<AZURE_DEPLOYMENT_NAME>",
77
+ "name": "<AZURE_DEPLOYMENT_NAME>",
78
+ "provider": "Azure",
79
+ "providerId": "azure",
80
+ "enabled": true,
81
+ "toolCallType": "native"
82
+ },
83
+ {
84
+ "id": "gemini-2.0-flash",
85
+ "name": "Gemini 2.0 Flash",
86
+ "provider": "Google Generative AI",
87
+ "providerId": "google",
88
+ "enabled": true,
89
+ "toolCallType": "manual"
90
+ },
91
+ {
92
+ "id": "gemini-2.0-flash-thinking-exp-01-21",
93
+ "name": "Gemini 2.0 Flash Thinking (Exp)",
94
+ "provider": "Google Generative AI",
95
+ "providerId": "google",
96
+ "enabled": true,
97
+ "toolCallType": "manual",
98
+ "toolCallModel": "gemini-2.0-flash"
99
+ },
100
+ {
101
+ "id": "gemini-2.5-pro-exp-03-25",
102
+ "name": "Gemini 2.5 Pro (Exp)",
103
+ "provider": "Google Generative AI",
104
+ "providerId": "google",
105
+ "enabled": true,
106
+ "toolCallType": "manual",
107
+ "toolCallModel": "gemini-2.0-flash"
108
+ },
109
+ {
110
+ "id": "accounts/fireworks/models/deepseek-r1",
111
+ "name": "DeepSeek R1",
112
+ "provider": "Fireworks",
113
+ "providerId": "fireworks",
114
+ "enabled": true,
115
+ "toolCallType": "manual",
116
+ "toolCallModel": "accounts/fireworks/models/llama-v3p1-8b-instruct"
117
+ },
118
+ {
119
+ "id": "accounts/fireworks/models/llama4-maverick-instruct-basic",
120
+ "name": "Llama 4 Maverick",
121
+ "provider": "Fireworks",
122
+ "providerId": "fireworks",
123
+ "enabled": true,
124
+ "toolCallType": "manual",
125
+ "toolCallModel": "accounts/fireworks/models/llama-v3p1-8b-instruct"
126
+ },
127
+ {
128
+ "id": "deepseek-reasoner",
129
+ "name": "DeepSeek R1",
130
+ "provider": "DeepSeek",
131
+ "providerId": "deepseek",
132
+ "enabled": true,
133
+ "toolCallType": "manual",
134
+ "toolCallModel": "deepseek-chat"
135
+ },
136
+ {
137
+ "id": "deepseek-chat",
138
+ "name": "DeepSeek V3",
139
+ "provider": "DeepSeek",
140
+ "providerId": "deepseek",
141
+ "enabled": true,
142
+ "toolCallType": "manual"
143
+ },
144
+ {
145
+ "id": "deepseek-r1-distill-llama-70b",
146
+ "name": "DeepSeek R1 Distill Llama 70B",
147
+ "provider": "Groq",
148
+ "providerId": "groq",
149
+ "enabled": true,
150
+ "toolCallType": "manual",
151
+ "toolCallModel": "llama-3.1-8b-instant"
152
+ },
153
+ {
154
+ "id": "meta-llama/llama-4-maverick-17b-128e-instruct",
155
+ "name": "Llama 4 Maverick 17B",
156
+ "provider": "Groq",
157
+ "providerId": "groq",
158
+ "enabled": true,
159
+ "toolCallType": "native"
160
+ },
161
+ {
162
+ "id": "deepseek-r1",
163
+ "name": "DeepSeek R1",
164
+ "provider": "Ollama",
165
+ "providerId": "ollama",
166
+ "enabled": true,
167
+ "toolCallType": "manual",
168
+ "toolCallModel": "phi4"
169
+ },
170
+ {
171
+ "id": "<OLLAMA_MODEL_ID>",
172
+ "name": "<OLLAMA_MODEL_NAME>",
173
+ "provider": "Ollama",
174
+ "providerId": "ollama",
175
+ "enabled": true,
176
+ "toolCallType": "manual",
177
+ "toolCallModel": "<OLLAMA_MODEL_ID>"
178
+ },
179
+ {
180
+ "id": "grok-2-1212",
181
+ "name": "Grok 2",
182
+ "provider": "xAI",
183
+ "providerId": "xai",
184
+ "enabled": true,
185
+ "toolCallType": "native"
186
+ },
187
+ {
188
+ "id": "grok-2-vision-1212",
189
+ "name": "Grok 2 Vision",
190
+ "provider": "xAI",
191
+ "providerId": "xai",
192
+ "enabled": true,
193
+ "toolCallType": "native"
194
+ },
195
+ {
196
+ "id": "grok-3-beta",
197
+ "name": "Grok 3 Beta",
198
+ "provider": "xAI",
199
+ "providerId": "xai",
200
+ "enabled": true,
201
+ "toolCallType": "native"
202
+ },
203
+ {
204
+ "id": "<OPENAI_COMPATIBLE_MODEL>",
205
+ "name": "<OPENAI_COMPATIBLE_MODEL>",
206
+ "provider": "OpenAI Compatible",
207
+ "providerId": "openai-compatible",
208
+ "enabled": true,
209
+ "toolCallType": "native"
210
+ }
211
+ ]
212
+ }
models.service.ts ADDED
@@ -0,0 +1,195 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { ServerModelStatus } from '$lib/enums';
2
+ import { apiFetch, apiPost } from '$lib/utils';
3
+ import type { ParsedModelId } from '$lib/types/models';
4
+ import {
5
+ MODEL_FORMAT_SEGMENT_RE,
6
+ MODEL_PARAMS_RE,
7
+ MODEL_ACTIVATED_PARAMS_RE,
8
+ MODEL_ID_NOT_FOUND,
9
+ MODEL_ID_ORG_SEPARATOR,
10
+ MODEL_ID_SEGMENT_SEPARATOR,
11
+ MODEL_ID_QUANTIZATION_SEPARATOR,
12
+ API_MODELS
13
+ } from '$lib/constants';
14
+
15
+ export class ModelsService {
16
+ /**
17
+ *
18
+ *
19
+ * Listing
20
+ *
21
+ *
22
+ */
23
+
24
+ /**
25
+ * Fetch list of models from OpenAI-compatible endpoint.
26
+ * Works in both MODEL and ROUTER modes.
27
+ *
28
+ * @returns List of available models with basic metadata
29
+ */
30
+ static async list(): Promise<ApiModelListResponse> {
31
+ return apiFetch<ApiModelListResponse>(API_MODELS.LIST);
32
+ }
33
+
34
+ /**
35
+ * Fetch list of all models with detailed metadata (ROUTER mode).
36
+ * Returns models with load status, paths, and other metadata
37
+ * beyond what the OpenAI-compatible endpoint provides.
38
+ *
39
+ * @returns List of models with detailed status and configuration info
40
+ */
41
+ static async listRouter(): Promise<ApiRouterModelsListResponse> {
42
+ return apiFetch<ApiRouterModelsListResponse>(API_MODELS.LIST);
43
+ }
44
+
45
+ /**
46
+ *
47
+ *
48
+ * Load/Unload
49
+ *
50
+ *
51
+ */
52
+
53
+ /**
54
+ * Load a model (ROUTER mode only).
55
+ * Sends POST request to `/models/load`. Note: the endpoint returns success
56
+ * before loading completes — use polling to await actual load status.
57
+ *
58
+ * @param modelId - Model identifier to load
59
+ * @param extraArgs - Optional additional arguments to pass to the model instance
60
+ * @returns Load response from the server
61
+ */
62
+ static async load(modelId: string, extraArgs?: string[]): Promise<ApiRouterModelsLoadResponse> {
63
+ const payload: { model: string; extra_args?: string[] } = { model: modelId };
64
+ if (extraArgs && extraArgs.length > 0) {
65
+ payload.extra_args = extraArgs;
66
+ }
67
+
68
+ return apiPost<ApiRouterModelsLoadResponse>(API_MODELS.LOAD, payload);
69
+ }
70
+
71
+ /**
72
+ * Unload a model (ROUTER mode only).
73
+ * Sends POST request to `/models/unload`. Note: the endpoint returns success
74
+ * before unloading completes — use polling to await actual unload status.
75
+ *
76
+ * @param modelId - Model identifier to unload
77
+ * @returns Unload response from the server
78
+ */
79
+ static async unload(modelId: string): Promise<ApiRouterModelsUnloadResponse> {
80
+ return apiPost<ApiRouterModelsUnloadResponse>(API_MODELS.UNLOAD, { model: modelId });
81
+ }
82
+
83
+ /**
84
+ *
85
+ *
86
+ * Status
87
+ *
88
+ *
89
+ */
90
+
91
+ /**
92
+ * Check if a model is loaded based on its metadata.
93
+ *
94
+ * @param model - Model data entry from the API response
95
+ * @returns True if the model status is LOADED
96
+ */
97
+ static isModelLoaded(model: ApiModelDataEntry): boolean {
98
+ return model.status.value === ServerModelStatus.LOADED;
99
+ }
100
+
101
+ /**
102
+ * Check if a model is currently loading.
103
+ *
104
+ * @param model - Model data entry from the API response
105
+ * @returns True if the model status is LOADING
106
+ */
107
+ static isModelLoading(model: ApiModelDataEntry): boolean {
108
+ return model.status.value === ServerModelStatus.LOADING;
109
+ }
110
+
111
+ /**
112
+ *
113
+ *
114
+ * Parsing
115
+ *
116
+ *
117
+ */
118
+
119
+ /**
120
+ * Parse a model ID string into its structured components.
121
+ *
122
+ * Handles the convention:
123
+ * `<org>/<ModelName>-<Parameters>(-<ActivatedParameters>)-<Format>:<QuantizationType>`
124
+ *
125
+ * @param modelId - Raw model identifier string
126
+ * @returns Structured {@link ParsedModelId} with all detected fields
127
+ */
128
+ static parseModelId(modelId: string): ParsedModelId {
129
+ const result: ParsedModelId = {
130
+ raw: modelId,
131
+ orgName: null,
132
+ modelName: null,
133
+ params: null,
134
+ activatedParams: null,
135
+ format: null,
136
+ quantization: null,
137
+ tags: []
138
+ };
139
+
140
+ const colonIdx = modelId.indexOf(MODEL_ID_QUANTIZATION_SEPARATOR);
141
+ let modelPath: string;
142
+
143
+ if (colonIdx !== MODEL_ID_NOT_FOUND) {
144
+ result.quantization = modelId.slice(colonIdx + 1) || null;
145
+ modelPath = modelId.slice(0, colonIdx);
146
+ } else {
147
+ modelPath = modelId;
148
+ }
149
+
150
+ const slashIdx = modelPath.indexOf(MODEL_ID_ORG_SEPARATOR);
151
+ let modelStr: string;
152
+
153
+ if (slashIdx !== MODEL_ID_NOT_FOUND) {
154
+ result.orgName = modelPath.slice(0, slashIdx);
155
+ modelStr = modelPath.slice(slashIdx + 1);
156
+ } else {
157
+ modelStr = modelPath;
158
+ }
159
+
160
+ const segments = modelStr.split(MODEL_ID_SEGMENT_SEPARATOR);
161
+
162
+ if (segments.length > 0 && MODEL_FORMAT_SEGMENT_RE.test(segments[segments.length - 1])) {
163
+ result.format = segments.pop()!;
164
+ }
165
+
166
+ const paramsRe = MODEL_PARAMS_RE;
167
+ const activatedParamsRe = MODEL_ACTIVATED_PARAMS_RE;
168
+
169
+ let paramsIdx = MODEL_ID_NOT_FOUND;
170
+ let activatedParamsIdx = MODEL_ID_NOT_FOUND;
171
+
172
+ for (let i = 0; i < segments.length; i++) {
173
+ const seg = segments[i];
174
+ if (paramsIdx === -1 && paramsRe.test(seg)) {
175
+ paramsIdx = i;
176
+ result.params = seg.toUpperCase();
177
+ } else if (activatedParamsRe.test(seg)) {
178
+ activatedParamsIdx = i;
179
+ result.activatedParams = seg.toUpperCase();
180
+ }
181
+ }
182
+
183
+ const pivotIdx = paramsIdx !== MODEL_ID_NOT_FOUND ? paramsIdx : segments.length;
184
+
185
+ result.modelName = segments.slice(0, pivotIdx).join(MODEL_ID_SEGMENT_SEPARATOR) || null;
186
+
187
+ if (paramsIdx !== MODEL_ID_NOT_FOUND) {
188
+ result.tags = segments
189
+ .slice(paramsIdx + 1)
190
+ .filter((_, relIdx) => paramsIdx + 1 + relIdx !== activatedParamsIdx);
191
+ }
192
+
193
+ return result;
194
+ }
195
+ }
models.ts ADDED
@@ -0,0 +1,243 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * The version of the OpenAPI document: v68
3
+ *
4
+ *
5
+ * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
6
+ * https://openapi-generator.tech
7
+ * Do not edit this class manually.
8
+ */
9
+
10
+
11
+ export * from './address';
12
+ export * from './amount';
13
+ export * from './bankAccount';
14
+ export * from './card';
15
+ export * from './fraudCheckResult';
16
+ export * from './fraudCheckResultWrapper';
17
+ export * from './fraudResult';
18
+ export * from './fundSource';
19
+ export * from './modifyRequest';
20
+ export * from './modifyResponse';
21
+ export * from './name';
22
+ export * from './payoutRequest';
23
+ export * from './payoutResponse';
24
+ export * from './recurring';
25
+ export * from './responseAdditionalData3DSecure';
26
+ export * from './responseAdditionalDataBillingAddress';
27
+ export * from './responseAdditionalDataCard';
28
+ export * from './responseAdditionalDataCommon';
29
+ export * from './responseAdditionalDataDomesticError';
30
+ export * from './responseAdditionalDataInstallments';
31
+ export * from './responseAdditionalDataNetworkTokens';
32
+ export * from './responseAdditionalDataOpi';
33
+ export * from './responseAdditionalDataSepa';
34
+ export * from './serviceError';
35
+ export * from './storeDetailAndSubmitRequest';
36
+ export * from './storeDetailAndSubmitResponse';
37
+ export * from './storeDetailRequest';
38
+ export * from './storeDetailResponse';
39
+ export * from './submitRequest';
40
+ export * from './submitResponse';
41
+
42
+
43
+ import { Address } from './address';
44
+ import { Amount } from './amount';
45
+ import { BankAccount } from './bankAccount';
46
+ import { Card } from './card';
47
+ import { FraudCheckResult } from './fraudCheckResult';
48
+ import { FraudCheckResultWrapper } from './fraudCheckResultWrapper';
49
+ import { FraudResult } from './fraudResult';
50
+ import { FundSource } from './fundSource';
51
+ import { ModifyRequest } from './modifyRequest';
52
+ import { ModifyResponse } from './modifyResponse';
53
+ import { Name } from './name';
54
+ import { PayoutRequest } from './payoutRequest';
55
+ import { PayoutResponse } from './payoutResponse';
56
+ import { Recurring } from './recurring';
57
+ import { ResponseAdditionalData3DSecure } from './responseAdditionalData3DSecure';
58
+ import { ResponseAdditionalDataBillingAddress } from './responseAdditionalDataBillingAddress';
59
+ import { ResponseAdditionalDataCard } from './responseAdditionalDataCard';
60
+ import { ResponseAdditionalDataCommon } from './responseAdditionalDataCommon';
61
+ import { ResponseAdditionalDataDomesticError } from './responseAdditionalDataDomesticError';
62
+ import { ResponseAdditionalDataInstallments } from './responseAdditionalDataInstallments';
63
+ import { ResponseAdditionalDataNetworkTokens } from './responseAdditionalDataNetworkTokens';
64
+ import { ResponseAdditionalDataOpi } from './responseAdditionalDataOpi';
65
+ import { ResponseAdditionalDataSepa } from './responseAdditionalDataSepa';
66
+ import { ServiceError } from './serviceError';
67
+ import { StoreDetailAndSubmitRequest } from './storeDetailAndSubmitRequest';
68
+ import { StoreDetailAndSubmitResponse } from './storeDetailAndSubmitResponse';
69
+ import { StoreDetailRequest } from './storeDetailRequest';
70
+ import { StoreDetailResponse } from './storeDetailResponse';
71
+ import { SubmitRequest } from './submitRequest';
72
+ import { SubmitResponse } from './submitResponse';
73
+
74
+ /* tslint:disable:no-unused-variable */
75
+ let primitives = [
76
+ "string",
77
+ "boolean",
78
+ "double",
79
+ "integer",
80
+ "long",
81
+ "float",
82
+ "number",
83
+ "any"
84
+ ];
85
+
86
+ let enumsMap: {[index: string]: any} = {
87
+ "PayoutRequest.ShopperInteractionEnum": PayoutRequest.ShopperInteractionEnum,
88
+ "PayoutResponse.ResultCodeEnum": PayoutResponse.ResultCodeEnum,
89
+ "Recurring.ContractEnum": Recurring.ContractEnum,
90
+ "Recurring.TokenServiceEnum": Recurring.TokenServiceEnum,
91
+ "ResponseAdditionalDataCommon.FraudResultTypeEnum": ResponseAdditionalDataCommon.FraudResultTypeEnum,
92
+ "ResponseAdditionalDataCommon.RecurringProcessingModelEnum": ResponseAdditionalDataCommon.RecurringProcessingModelEnum,
93
+ "StoreDetailAndSubmitRequest.EntityTypeEnum": StoreDetailAndSubmitRequest.EntityTypeEnum,
94
+ "StoreDetailRequest.EntityTypeEnum": StoreDetailRequest.EntityTypeEnum,
95
+ "SubmitRequest.EntityTypeEnum": SubmitRequest.EntityTypeEnum,
96
+ }
97
+
98
+ let typeMap: {[index: string]: any} = {
99
+ "Address": Address,
100
+ "Amount": Amount,
101
+ "BankAccount": BankAccount,
102
+ "Card": Card,
103
+ "FraudCheckResult": FraudCheckResult,
104
+ "FraudCheckResultWrapper": FraudCheckResultWrapper,
105
+ "FraudResult": FraudResult,
106
+ "FundSource": FundSource,
107
+ "ModifyRequest": ModifyRequest,
108
+ "ModifyResponse": ModifyResponse,
109
+ "Name": Name,
110
+ "PayoutRequest": PayoutRequest,
111
+ "PayoutResponse": PayoutResponse,
112
+ "Recurring": Recurring,
113
+ "ResponseAdditionalData3DSecure": ResponseAdditionalData3DSecure,
114
+ "ResponseAdditionalDataBillingAddress": ResponseAdditionalDataBillingAddress,
115
+ "ResponseAdditionalDataCard": ResponseAdditionalDataCard,
116
+ "ResponseAdditionalDataCommon": ResponseAdditionalDataCommon,
117
+ "ResponseAdditionalDataDomesticError": ResponseAdditionalDataDomesticError,
118
+ "ResponseAdditionalDataInstallments": ResponseAdditionalDataInstallments,
119
+ "ResponseAdditionalDataNetworkTokens": ResponseAdditionalDataNetworkTokens,
120
+ "ResponseAdditionalDataOpi": ResponseAdditionalDataOpi,
121
+ "ResponseAdditionalDataSepa": ResponseAdditionalDataSepa,
122
+ "ServiceError": ServiceError,
123
+ "StoreDetailAndSubmitRequest": StoreDetailAndSubmitRequest,
124
+ "StoreDetailAndSubmitResponse": StoreDetailAndSubmitResponse,
125
+ "StoreDetailRequest": StoreDetailRequest,
126
+ "StoreDetailResponse": StoreDetailResponse,
127
+ "SubmitRequest": SubmitRequest,
128
+ "SubmitResponse": SubmitResponse,
129
+ }
130
+
131
+ export class ObjectSerializer {
132
+ public static findCorrectType(data: any, expectedType: string) {
133
+ if (data == undefined) {
134
+ return expectedType;
135
+ } else if (primitives.indexOf(expectedType.toLowerCase()) !== -1) {
136
+ return expectedType;
137
+ } else if (expectedType === "Date") {
138
+ return expectedType;
139
+ } else {
140
+ if (enumsMap[expectedType]) {
141
+ return expectedType;
142
+ }
143
+
144
+ if (!typeMap[expectedType]) {
145
+ return expectedType; // w/e we don't know the type
146
+ }
147
+
148
+ // Check the discriminator
149
+ let discriminatorProperty = typeMap[expectedType].discriminator;
150
+ if (discriminatorProperty == null) {
151
+ return expectedType; // the type does not have a discriminator. use it.
152
+ } else {
153
+ if (data[discriminatorProperty]) {
154
+ var discriminatorType = data[discriminatorProperty];
155
+ if(typeMap[discriminatorType]){
156
+ return discriminatorType; // use the type given in the discriminator
157
+ } else {
158
+ return expectedType; // discriminator did not map to a type
159
+ }
160
+ } else {
161
+ return expectedType; // discriminator was not present (or an empty string)
162
+ }
163
+ }
164
+ }
165
+ }
166
+
167
+ public static serialize(data: any, type: string) {
168
+ if (data == undefined) {
169
+ return data;
170
+ } else if (primitives.indexOf(type.toLowerCase()) !== -1) {
171
+ return data;
172
+ } else if (type.lastIndexOf("Array<", 0) === 0) { // string.startsWith pre es6
173
+ let subType: string = type.replace("Array<", ""); // Array<Type> => Type>
174
+ subType = subType.substring(0, subType.length - 1); // Type> => Type
175
+ let transformedData: any[] = [];
176
+ for (let index = 0; index < data.length; index++) {
177
+ let datum = data[index];
178
+ transformedData.push(ObjectSerializer.serialize(datum, subType));
179
+ }
180
+ return transformedData;
181
+ } else if (type === "Date") {
182
+ return data.toISOString();
183
+ } else if (type === "SaleToAcquirerData") {
184
+ const dataString = JSON.stringify(data);
185
+ return Buffer.from(dataString).toString("base64");
186
+ } else {
187
+ if (enumsMap[type]) {
188
+ return data;
189
+ }
190
+ if (!typeMap[type]) { // in case we dont know the type
191
+ return data;
192
+ }
193
+
194
+ // Get the actual type of this object
195
+ type = this.findCorrectType(data, type);
196
+
197
+ // get the map for the correct type.
198
+ let attributeTypes = typeMap[type].getAttributeTypeMap();
199
+ let instance: {[index: string]: any} = {};
200
+ for (let index = 0; index < attributeTypes.length; index++) {
201
+ let attributeType = attributeTypes[index];
202
+ instance[attributeType.baseName] = ObjectSerializer.serialize(data[attributeType.name], attributeType.type);
203
+ }
204
+ return instance;
205
+ }
206
+ }
207
+
208
+ public static deserialize(data: any, type: string) {
209
+ // polymorphism may change the actual type.
210
+ type = ObjectSerializer.findCorrectType(data, type);
211
+ if (data == undefined) {
212
+ return data;
213
+ } else if (primitives.indexOf(type.toLowerCase()) !== -1) {
214
+ return data;
215
+ } else if (type.lastIndexOf("Array<", 0) === 0) { // string.startsWith pre es6
216
+ let subType: string = type.replace("Array<", ""); // Array<Type> => Type>
217
+ subType = subType.substring(0, subType.length - 1); // Type> => Type
218
+ let transformedData: any[] = [];
219
+ for (let index = 0; index < data.length; index++) {
220
+ let datum = data[index];
221
+ transformedData.push(ObjectSerializer.deserialize(datum, subType));
222
+ }
223
+ return transformedData;
224
+ } else if (type === "Date") {
225
+ return new Date(data);
226
+ } else {
227
+ if (enumsMap[type]) {// is Enum
228
+ return data;
229
+ }
230
+
231
+ if (!typeMap[type]) { // dont know the type
232
+ return data;
233
+ }
234
+ let instance = new typeMap[type]();
235
+ let attributeTypes = typeMap[type].getAttributeTypeMap();
236
+ for (let index = 0; index < attributeTypes.length; index++) {
237
+ let attributeType = attributeTypes[index];
238
+ instance[attributeType.name] = ObjectSerializer.deserialize(data[attributeType.baseName], attributeType.type);
239
+ }
240
+ return instance;
241
+ }
242
+ }
243
+ }